UNPKG

@bluefin-exchange/bluefin7k-aggregator-sdk

Version:
37 lines (36 loc) 1.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FlowxV3Contract = void 0; const utils_1 = require("@mysten/sui/utils"); const base_1 = require("../base"); const utils_2 = require("../utils"); class FlowxV3Contract extends base_1.BaseContract { async swap(tx) { const [coinX, coinY] = this.swapInfo.pool.allTokens; const swapXtoY = this.swapInfo.swapXtoY; const swapFeeRate = this.swapInfo.extra.swapFeeRate; if (!swapFeeRate) { throw new Error("swapFeeRate is required"); } const config = this.config.flowx_v3; const [coinOut] = tx.moveCall({ target: `${config.package}::swap_router::swap_exact_input`, typeArguments: [ swapXtoY ? coinX.address : coinY.address, swapXtoY ? coinY.address : coinX.address, ], arguments: [ tx.object(config.registry), tx.pure.u64(swapFeeRate), // swap fee rate to lookup pool in the registry this.inputCoinObject, tx.pure.u64(0), // min amount out tx.pure.u128((0, utils_2.getDefaultSqrtPriceLimit)(swapXtoY) + (swapXtoY ? 1n : -1n)), // sqrt price limit tx.pure.u64("18446744073709551615"), // u64 max value tx.object(config.version), tx.object(utils_1.SUI_CLOCK_OBJECT_ID), ], }); return coinOut; } } exports.FlowxV3Contract = FlowxV3Contract;