UNPKG

@bayswap/sdk

Version:

SDK for BaySwap smart contract

35 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SwapModule = void 0; const sui_js_1 = require("@mysten/sui.js"); class SwapModule { constructor(provider, globalStorage, txBuilderConfig) { this._provider = provider; this._globalStorage = globalStorage; this._txBuilderConfig = txBuilderConfig; } buildSwapUnsignedTx(type, param) { const tx = new sui_js_1.TransactionBlock(); if (param.coinID.length > 1 && param.coinInputType != sui_js_1.SUI_TYPE_ARG) { tx.mergeCoins(tx.object(param.coinID[0]), param.coinID.slice(1).map((id) => tx.object(id))); } const targetSplit = param.coinInputType == sui_js_1.SUI_TYPE_ARG ? tx.gas : tx.object(param.coinID[0]); const [used] = tx.splitCoins(targetSplit, [tx.pure(param.amount)]); let funcName = 'swap_from_x_to_y'; if (param.coinInputType == type.coinY) { funcName = 'swap_from_y_to_x'; } tx.moveCall({ target: `${param.packageObjectId}::entry::${funcName}`, typeArguments: [type.coinX, type.coinY, type.curve], arguments: [ tx.object(this._globalStorage), used, tx.pure(param.coinOutMin), ], }); return tx; } } exports.SwapModule = SwapModule; //# sourceMappingURL=swap.js.map