UNPKG

navi-sdk

Version:

The NAVI SDK Client provides tools for interacting with the Sui blockchain networks, designed for handling transactions, accounts, and smart contracts efficiently. This documentation covers the setup, account management, and transaction handling within th

97 lines (96 loc) 4.27 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeMomentumPTB = makeMomentumPTB; const utils_1 = require("@mysten/sui/utils"); const config_1 = require("../config"); function makeMomentumPTB(txb, poolId, pathTempCoin, amount, a2b, typeArguments) { return __awaiter(this, void 0, void 0, function* () { const LowLimitPrice = BigInt('4295048017'); const HighLimitPrice = BigInt('79226673515401279992447579050'); const limitSqrtPrice = a2b ? LowLimitPrice : HighLimitPrice; const poolObject = txb.object(poolId); const [receive_a, receive_b, flash_receipt] = txb.moveCall({ target: `${config_1.AggregatorConfig.momentumPackageId}::trade::flash_swap`, typeArguments, arguments: [ poolObject, txb.pure.bool(a2b), txb.pure.bool(true), amount, txb.pure.u128(limitSqrtPrice), txb.object((0, utils_1.normalizeSuiObjectId)('0x6')), txb.object(config_1.AggregatorConfig.momentumVersionId), ], }); txb.moveCall({ target: `0x2::balance::destroy_zero`, arguments: [a2b ? receive_a : receive_b], typeArguments: [a2b ? typeArguments[0] : typeArguments[1]], }); const [zeroCoin] = txb.moveCall({ target: `0x2::coin::zero`, arguments: [], typeArguments: [a2b ? typeArguments[1] : typeArguments[0]], }); const [coinADebt, coinBDebt] = txb.moveCall({ target: `${config_1.AggregatorConfig.momentumPackageId}::trade::swap_receipt_debts`, typeArguments: [], arguments: [flash_receipt], }); const pay_coin_a = a2b ? txb.moveCall({ target: `0x2::coin::split`, arguments: [pathTempCoin, coinADebt], typeArguments: [typeArguments[0]], }) : zeroCoin; const pay_coin_b = a2b ? zeroCoin : txb.moveCall({ target: `0x2::coin::split`, arguments: [pathTempCoin, coinBDebt], typeArguments: [typeArguments[1]], }); const pay_coin_a_balance = txb.moveCall({ target: `0x2::coin::into_balance`, typeArguments: [typeArguments[0]], arguments: [pay_coin_a], }); const pay_coin_b_balance = txb.moveCall({ target: `0x2::coin::into_balance`, typeArguments: [typeArguments[1]], arguments: [pay_coin_b], }); txb.moveCall({ target: `${config_1.AggregatorConfig.momentumPackageId}::trade::repay_flash_swap`, typeArguments, arguments: [ poolObject, flash_receipt, pay_coin_a_balance, pay_coin_b_balance, txb.object(config_1.AggregatorConfig.momentumVersionId), ], }); txb.moveCall({ target: `${config_1.AggregatorConfig.momentumSlippageCheckPackageId}::slippage_check::assert_slippage`, typeArguments, arguments: [poolObject, txb.pure.u128(limitSqrtPrice), txb.pure.bool(a2b)], }); const [outputCoin] = txb.moveCall({ target: `0x2::coin::from_balance`, typeArguments: [a2b ? typeArguments[1] : typeArguments[0]], arguments: [a2b ? receive_b : receive_a], }); return outputCoin; }); }