UNPKG

@bluefin-exchange/bluefin7k-aggregator-sdk

Version:
34 lines (33 loc) 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HaedalPMMContract = void 0; const utils_1 = require("@mysten/sui/utils"); const base_1 = require("../base"); const sui_1 = require("../../../utils/sui"); class HaedalPMMContract extends base_1.BaseContract { async swap(tx) { const [coinX, coinY] = this.swapInfo.pool.allTokens; const xToY = this.swapInfo.swapXtoY; const { x_price_id, y_price_id } = this.swapInfo.extra || {}; if (!x_price_id || !y_price_id) { throw new Error("x_price_id and y_price_id are required"); } const config = this.config.haedal_pmm; const [coinOut] = tx.moveCall({ target: `${config.package}::trader::${xToY ? "sell_base_coin" : "sell_quote_coin"}`, typeArguments: [coinX.address, coinY.address], arguments: [ tx.object(this.swapInfo.poolId), tx.object(utils_1.SUI_CLOCK_OBJECT_ID), tx.object(x_price_id), // pyth pricefeed for x tx.object(y_price_id), // pyth pricefeed for y this.inputCoinObject, // mutable coin this.getInputCoinValue(tx), // swap amount tx.pure.u64(0), // min output amount ], }); sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, this.inputCoinObject); return coinOut; } } exports.HaedalPMMContract = HaedalPMMContract;