@bayswap/sdk
Version:
SDK for BaySwap smart contract
31 lines • 1.26 kB
JavaScript
import { SUI_TYPE_ARG, TransactionBlock, } from '@mysten/sui.js';
export class SwapModule {
constructor(provider, globalStorage, txBuilderConfig) {
this._provider = provider;
this._globalStorage = globalStorage;
this._txBuilderConfig = txBuilderConfig;
}
buildSwapUnsignedTx(type, param) {
const tx = new TransactionBlock();
if (param.coinID.length > 1 && param.coinInputType != SUI_TYPE_ARG) {
tx.mergeCoins(tx.object(param.coinID[0]), param.coinID.slice(1).map((id) => tx.object(id)));
}
const targetSplit = param.coinInputType == 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;
}
}
//# sourceMappingURL=swap.js.map