UNPKG

@bluefin-exchange/bluefin7k-aggregator-sdk

Version:
34 lines (33 loc) 1.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSplitCoinForTx = void 0; const transactions_1 = require("@mysten/sui/transactions"); const utils_1 = require("@mysten/sui/utils"); const tokens_1 = require("../constants/tokens"); const getCoinOjectIdsByAmount_1 = require("./getCoinOjectIdsByAmount"); const getSplitCoinForTx = async (account, amount, splits, coinType, inheritTx, inspecTransaction, isSponsored = false) => { const tx = inheritTx ?? new transactions_1.Transaction(); const { objectIds } = await (0, getCoinOjectIdsByAmount_1.getCoinOjectIdsByAmount)(account, amount, coinType); const coinObjectId = objectIds[0]; if ((0, utils_1.normalizeStructTag)(coinType) === (0, utils_1.normalizeStructTag)(tokens_1.SUI_TYPE) && !isSponsored) { let coin; if (inspecTransaction) { if (objectIds.length > 1) { tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item) => tx.object(item))); } coin = tx.splitCoins(tx.object(coinObjectId), splits); } else { coin = tx.splitCoins(tx.gas, splits); } return { tx, coinData: coin }; } if (objectIds.length > 1) { tx.mergeCoins(tx.object(coinObjectId), objectIds.slice(1).map((item) => tx.object(item))); } // split correct amount to swap const coinData = tx.splitCoins(tx.object(coinObjectId), splits); return { tx, coinData }; }; exports.getSplitCoinForTx = getSplitCoinForTx;