@7kprotocol/sdk-ts 2.4.1 → 2.4.2-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -3
- package/lib/cjs/config/fetchClient.js +11 -19
- package/lib/cjs/config/index.js +22 -0
- package/lib/cjs/constants/_7k.js +6 -3
- package/lib/cjs/features/limitDca/cancelDcaOrder.js +7 -18
- package/lib/cjs/features/limitDca/cancelLimitOrder.js +7 -18
- package/lib/cjs/features/limitDca/claimExpiredLimitOrder.js +7 -18
- package/lib/cjs/features/limitDca/constants.js +1 -5
- package/lib/cjs/features/limitDca/getClosedDcaOrders.js +16 -27
- package/lib/cjs/features/limitDca/getClosedLimitOrders.js +15 -26
- package/lib/cjs/features/limitDca/getDcaOrderExecutions.js +16 -27
- package/lib/cjs/features/limitDca/getOpenDcaOrders.js +15 -26
- package/lib/cjs/features/limitDca/getOpenLimitOrders.js +15 -26
- package/lib/cjs/features/limitDca/placeDcaOrder.js +25 -36
- package/lib/cjs/features/limitDca/placeLimitOrder.js +14 -25
- package/lib/cjs/features/prices/index.js +47 -64
- package/lib/cjs/features/swap/buildTx.js +88 -39
- package/lib/cjs/features/swap/config.js +32 -32
- package/lib/cjs/features/swap/estimateGasFee.js +36 -46
- package/lib/cjs/features/swap/executeTx.js +52 -0
- package/lib/cjs/features/swap/getQuote.js +41 -31
- package/lib/cjs/features/swap/getSwapHistory.js +14 -25
- package/lib/cjs/features/swap/index.js +1 -0
- package/lib/cjs/index.js +16 -9
- package/lib/cjs/libs/getCoinOjectIdsByAmount.js +15 -24
- package/lib/cjs/libs/getSplitCoinForTx.js +8 -15
- package/lib/cjs/libs/groupSwapRoutes.js +10 -12
- package/lib/cjs/libs/protocols/aftermath/index.js +25 -36
- package/lib/cjs/libs/protocols/base.js +10 -3
- package/lib/cjs/libs/protocols/bluefin/index.js +26 -43
- package/lib/cjs/libs/protocols/bluefinx/client.js +35 -0
- package/lib/cjs/libs/protocols/bluefinx/index.js +48 -0
- package/lib/cjs/libs/protocols/bluefinx/types.js +10 -0
- package/lib/cjs/libs/protocols/bluemove/index.js +14 -25
- package/lib/cjs/libs/protocols/cetus/index.js +32 -43
- package/lib/cjs/libs/protocols/deepbookV3/sponsored.js +19 -30
- package/lib/cjs/libs/protocols/flowx/index.js +9 -20
- package/lib/cjs/libs/protocols/flowxV3/index.js +25 -39
- package/lib/cjs/libs/protocols/haedal_pmm/index.js +33 -0
- package/lib/cjs/libs/protocols/index.js +7 -2
- package/lib/cjs/libs/protocols/kriya/index.js +20 -31
- package/lib/cjs/libs/protocols/kriyaV3/index.js +54 -65
- package/lib/cjs/libs/protocols/magma/index.js +28 -40
- package/lib/cjs/libs/protocols/momentum/index.js +49 -0
- package/lib/cjs/libs/protocols/obric/index.js +20 -31
- package/lib/cjs/libs/protocols/springsui/index.js +14 -25
- package/lib/cjs/libs/protocols/steamm/index.js +57 -58
- package/lib/cjs/libs/protocols/stsui/index.js +14 -25
- package/lib/cjs/libs/protocols/suiswap/index.js +23 -34
- package/lib/cjs/libs/protocols/turbos/index.js +23 -38
- package/lib/cjs/libs/protocols/utils.js +1 -5
- package/lib/cjs/libs/swapWithRoute.js +17 -27
- package/lib/cjs/types/aggregator.js +17 -0
- package/lib/cjs/types/config/index.d.ts +9 -0
- package/lib/cjs/types/config/index.d.ts.map +1 -1
- package/lib/cjs/types/constants/_7k.d.ts +3 -3
- package/lib/cjs/types/constants/_7k.d.ts.map +1 -1
- package/lib/cjs/types/features/limitDca/constants.d.ts +1 -2
- package/lib/cjs/types/features/limitDca/constants.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/buildTx.d.ts +2 -5
- package/lib/cjs/types/features/swap/buildTx.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/config.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/estimateGasFee.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/executeTx.d.ts +24 -0
- package/lib/cjs/types/features/swap/executeTx.d.ts.map +1 -0
- package/lib/cjs/types/features/swap/getQuote.d.ts +8 -1
- package/lib/cjs/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/cjs/types/features/swap/index.d.ts +1 -0
- package/lib/cjs/types/features/swap/index.d.ts.map +1 -1
- package/lib/cjs/types/index.d.ts +13 -8
- package/lib/cjs/types/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/getCoinOjectIdsByAmount.d.ts.map +1 -1
- package/lib/cjs/types/libs/getSplitCoinForTx.d.ts.map +1 -1
- package/lib/cjs/types/libs/groupSwapRoutes.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/base.d.ts +6 -2
- package/lib/cjs/types/libs/protocols/base.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/bluefin/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/bluefinx/client.d.ts +13 -0
- package/lib/cjs/types/libs/protocols/bluefinx/client.d.ts.map +1 -0
- package/lib/cjs/types/libs/protocols/bluefinx/index.d.ts +17 -0
- package/lib/cjs/types/libs/protocols/bluefinx/index.d.ts.map +1 -0
- package/lib/cjs/types/libs/protocols/bluefinx/types.d.ts +34 -0
- package/lib/cjs/types/libs/protocols/bluefinx/types.d.ts.map +1 -0
- package/lib/cjs/types/libs/protocols/cetus/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/deepbookV3/sponsored.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/flowxV3/index.d.ts.map +1 -1
- package/lib/{esm/types/libs/protocols/deepbook → cjs/types/libs/protocols/haedal_pmm}/index.d.ts +1 -3
- package/lib/cjs/types/libs/protocols/haedal_pmm/index.d.ts.map +1 -0
- package/lib/cjs/types/libs/protocols/index.d.ts +7 -2
- package/lib/cjs/types/libs/protocols/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/magma/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/{deepbook → momentum}/index.d.ts +1 -3
- package/lib/cjs/types/libs/protocols/momentum/index.d.ts.map +1 -0
- package/lib/cjs/types/libs/protocols/steamm/index.d.ts +13 -2
- package/lib/cjs/types/libs/protocols/steamm/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/suiswap/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/turbos/index.d.ts.map +1 -1
- package/lib/cjs/types/libs/protocols/utils.d.ts +1 -2
- package/lib/cjs/types/libs/protocols/utils.d.ts.map +1 -1
- package/lib/cjs/types/libs/swapWithRoute.d.ts +3 -1
- package/lib/cjs/types/libs/swapWithRoute.d.ts.map +1 -1
- package/lib/cjs/types/types/aggregator.d.ts +36 -2
- package/lib/cjs/types/types/aggregator.d.ts.map +1 -1
- package/lib/cjs/types/types/tx.d.ts +1 -2
- package/lib/cjs/types/types/tx.d.ts.map +1 -1
- package/lib/cjs/types/utils/number.d.ts +1 -3
- package/lib/cjs/types/utils/number.d.ts.map +1 -1
- package/lib/cjs/types/utils/sui.d.ts +1 -1
- package/lib/cjs/types/utils/sui.d.ts.map +1 -1
- package/lib/cjs/utils/number.js +4 -10
- package/lib/cjs/utils/sui.js +71 -80
- package/lib/esm/config/index.js +22 -0
- package/lib/esm/constants/_7k.js +6 -3
- package/lib/esm/features/limitDca/constants.js +1 -2
- package/lib/esm/features/swap/buildTx.js +81 -20
- package/lib/esm/features/swap/config.js +19 -8
- package/lib/esm/features/swap/estimateGasFee.js +13 -9
- package/lib/esm/features/swap/executeTx.js +48 -0
- package/lib/esm/features/swap/getQuote.js +24 -3
- package/lib/esm/features/swap/index.js +1 -0
- package/lib/esm/index.mjs +8 -4
- package/lib/esm/libs/getCoinOjectIdsByAmount.js +7 -7
- package/lib/esm/libs/getSplitCoinForTx.js +4 -2
- package/lib/esm/libs/groupSwapRoutes.js +1 -2
- package/lib/esm/libs/protocols/base.js +10 -1
- package/lib/esm/libs/protocols/bluefin/index.js +2 -5
- package/lib/esm/libs/protocols/bluefinx/client.js +30 -0
- package/lib/esm/libs/protocols/bluefinx/index.js +44 -0
- package/lib/esm/libs/protocols/bluefinx/types.js +8 -0
- package/lib/esm/libs/protocols/cetus/index.js +1 -1
- package/lib/esm/libs/protocols/deepbookV3/sponsored.js +1 -1
- package/lib/esm/libs/protocols/flowxV3/index.js +1 -4
- package/lib/esm/libs/protocols/haedal_pmm/index.js +29 -0
- package/lib/esm/libs/protocols/index.js +7 -2
- package/lib/esm/libs/protocols/magma/index.js +1 -2
- package/lib/esm/libs/protocols/momentum/index.js +45 -0
- package/lib/esm/libs/protocols/steamm/index.js +58 -48
- package/lib/esm/libs/protocols/suiswap/index.js +1 -1
- package/lib/esm/libs/protocols/turbos/index.js +2 -6
- package/lib/esm/libs/protocols/utils.js +1 -2
- package/lib/esm/libs/swapWithRoute.js +2 -1
- package/lib/esm/types/aggregator.js +14 -1
- package/lib/esm/types/config/index.d.ts +9 -0
- package/lib/esm/types/config/index.d.ts.map +1 -1
- package/lib/esm/types/constants/_7k.d.ts +3 -3
- package/lib/esm/types/constants/_7k.d.ts.map +1 -1
- package/lib/esm/types/features/limitDca/constants.d.ts +1 -2
- package/lib/esm/types/features/limitDca/constants.d.ts.map +1 -1
- package/lib/esm/types/features/swap/buildTx.d.ts +2 -5
- package/lib/esm/types/features/swap/buildTx.d.ts.map +1 -1
- package/lib/esm/types/features/swap/config.d.ts.map +1 -1
- package/lib/esm/types/features/swap/estimateGasFee.d.ts.map +1 -1
- package/lib/esm/types/features/swap/executeTx.d.ts +24 -0
- package/lib/esm/types/features/swap/executeTx.d.ts.map +1 -0
- package/lib/esm/types/features/swap/getQuote.d.ts +8 -1
- package/lib/esm/types/features/swap/getQuote.d.ts.map +1 -1
- package/lib/esm/types/features/swap/index.d.ts +1 -0
- package/lib/esm/types/features/swap/index.d.ts.map +1 -1
- package/lib/esm/types/index.d.ts +13 -8
- package/lib/esm/types/index.d.ts.map +1 -1
- package/lib/esm/types/libs/getCoinOjectIdsByAmount.d.ts.map +1 -1
- package/lib/esm/types/libs/getSplitCoinForTx.d.ts.map +1 -1
- package/lib/esm/types/libs/groupSwapRoutes.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/base.d.ts +6 -2
- package/lib/esm/types/libs/protocols/base.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/bluefin/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/bluefinx/client.d.ts +13 -0
- package/lib/esm/types/libs/protocols/bluefinx/client.d.ts.map +1 -0
- package/lib/esm/types/libs/protocols/bluefinx/index.d.ts +17 -0
- package/lib/esm/types/libs/protocols/bluefinx/index.d.ts.map +1 -0
- package/lib/esm/types/libs/protocols/bluefinx/types.d.ts +34 -0
- package/lib/esm/types/libs/protocols/bluefinx/types.d.ts.map +1 -0
- package/lib/esm/types/libs/protocols/cetus/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/deepbookV3/sponsored.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/flowxV3/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/haedal_pmm/index.d.ts +9 -0
- package/lib/esm/types/libs/protocols/haedal_pmm/index.d.ts.map +1 -0
- package/lib/esm/types/libs/protocols/index.d.ts +7 -2
- package/lib/esm/types/libs/protocols/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/magma/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/momentum/index.d.ts +9 -0
- package/lib/esm/types/libs/protocols/momentum/index.d.ts.map +1 -0
- package/lib/esm/types/libs/protocols/steamm/index.d.ts +13 -2
- package/lib/esm/types/libs/protocols/steamm/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/suiswap/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/turbos/index.d.ts.map +1 -1
- package/lib/esm/types/libs/protocols/utils.d.ts +1 -2
- package/lib/esm/types/libs/protocols/utils.d.ts.map +1 -1
- package/lib/esm/types/libs/swapWithRoute.d.ts +3 -1
- package/lib/esm/types/libs/swapWithRoute.d.ts.map +1 -1
- package/lib/esm/types/types/aggregator.d.ts +36 -2
- package/lib/esm/types/types/aggregator.d.ts.map +1 -1
- package/lib/esm/types/types/tx.d.ts +1 -2
- package/lib/esm/types/types/tx.d.ts.map +1 -1
- package/lib/esm/types/utils/number.d.ts +1 -3
- package/lib/esm/types/utils/number.d.ts.map +1 -1
- package/lib/esm/types/utils/sui.d.ts +1 -1
- package/lib/esm/types/utils/sui.d.ts.map +1 -1
- package/lib/esm/utils/number.js +4 -6
- package/lib/esm/utils/sui.js +4 -3
- package/package.json +14 -15
- package/lib/cjs/libs/protocols/deepbook/index.js +0 -96
- package/lib/cjs/types/libs/protocols/deepbook/index.d.ts.map +0 -1
- package/lib/esm/libs/protocols/deepbook/index.js +0 -80
- package/lib/esm/types/libs/protocols/deepbook/index.d.ts.map +0 -1
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.MagmaContract = void 0;
|
|
13
4
|
const base_1 = require("../base");
|
|
@@ -15,38 +6,35 @@ const utils_1 = require("@mysten/sui/utils");
|
|
|
15
6
|
const utils_2 = require("../utils");
|
|
16
7
|
const sui_1 = require("../../../utils/sui");
|
|
17
8
|
class MagmaContract extends base_1.BaseContract {
|
|
18
|
-
swap(tx) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
typeArguments: [swapXtoY ? coinY.address : coinX.address],
|
|
27
|
-
});
|
|
28
|
-
const amountIn = sui_1.SuiUtils.getCoinValue(swapXtoY ? coinX.address : coinY.address, this.inputCoinObject, tx);
|
|
29
|
-
const config = this.config.magma;
|
|
30
|
-
const [receiveA, receiveB] = tx.moveCall({
|
|
31
|
-
target: `${config.package}::router::swap`,
|
|
32
|
-
typeArguments,
|
|
33
|
-
arguments: [
|
|
34
|
-
tx.object(config.globalConfig),
|
|
35
|
-
tx.object(this.swapInfo.poolId),
|
|
36
|
-
swapXtoY ? this.inputCoinObject : zeroOut, // coin A
|
|
37
|
-
swapXtoY ? zeroOut : this.inputCoinObject, // coin B
|
|
38
|
-
tx.pure.bool(swapXtoY), // a to b or b to a
|
|
39
|
-
tx.pure.bool(true), // exact in or out
|
|
40
|
-
amountIn, // swap amount
|
|
41
|
-
tx.pure.u128(sqrtPriceLimit.toString()), // sqrt price limit
|
|
42
|
-
tx.pure.bool(false),
|
|
43
|
-
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
44
|
-
],
|
|
45
|
-
});
|
|
46
|
-
sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, swapXtoY ? receiveA : receiveB, this.currentAccount);
|
|
47
|
-
console.log(tx);
|
|
48
|
-
return swapXtoY ? receiveB : receiveA;
|
|
9
|
+
async swap(tx) {
|
|
10
|
+
const [coinX, coinY] = this.swapInfo.pool.allTokens;
|
|
11
|
+
const swapXtoY = this.swapInfo.swapXtoY;
|
|
12
|
+
const sqrtPriceLimit = (0, utils_2.getDefaultSqrtPriceLimit)(swapXtoY);
|
|
13
|
+
const typeArguments = [coinX.address, coinY.address];
|
|
14
|
+
const [zeroOut] = tx.moveCall({
|
|
15
|
+
target: "0x2::coin::zero",
|
|
16
|
+
typeArguments: [swapXtoY ? coinY.address : coinX.address],
|
|
49
17
|
});
|
|
18
|
+
const amountIn = sui_1.SuiUtils.getCoinValue(swapXtoY ? coinX.address : coinY.address, this.inputCoinObject, tx);
|
|
19
|
+
const config = this.config.magma;
|
|
20
|
+
const [receiveA, receiveB] = tx.moveCall({
|
|
21
|
+
target: `${config.package}::router::swap`,
|
|
22
|
+
typeArguments,
|
|
23
|
+
arguments: [
|
|
24
|
+
tx.object(config.globalConfig),
|
|
25
|
+
tx.object(this.swapInfo.poolId),
|
|
26
|
+
swapXtoY ? this.inputCoinObject : zeroOut, // coin A
|
|
27
|
+
swapXtoY ? zeroOut : this.inputCoinObject, // coin B
|
|
28
|
+
tx.pure.bool(swapXtoY), // a to b or b to a
|
|
29
|
+
tx.pure.bool(true), // exact in or out
|
|
30
|
+
amountIn, // swap amount
|
|
31
|
+
tx.pure.u128(sqrtPriceLimit.toString()), // sqrt price limit
|
|
32
|
+
tx.pure.bool(false),
|
|
33
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
34
|
+
],
|
|
35
|
+
});
|
|
36
|
+
sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, swapXtoY ? receiveA : receiveB);
|
|
37
|
+
return swapXtoY ? receiveB : receiveA;
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
exports.MagmaContract = MagmaContract;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MomentumContract = void 0;
|
|
4
|
+
const base_1 = require("../base");
|
|
5
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
+
const utils_2 = require("../utils");
|
|
7
|
+
const sui_1 = require("../../../utils/sui");
|
|
8
|
+
class MomentumContract extends base_1.BaseContract {
|
|
9
|
+
async swap(tx) {
|
|
10
|
+
const [coinX, coinY] = this.swapInfo.pool.allTokens;
|
|
11
|
+
const swapXtoY = this.swapInfo.swapXtoY;
|
|
12
|
+
const sqrtPriceLimit = (0, utils_2.getDefaultSqrtPriceLimit)(swapXtoY);
|
|
13
|
+
const typeArguments = [coinX.address, coinY.address];
|
|
14
|
+
const { package: packageId, version } = this.config.momentum;
|
|
15
|
+
const [receiveA, receiveB, debt] = tx.moveCall({
|
|
16
|
+
target: `${packageId}::trade::flash_swap`,
|
|
17
|
+
typeArguments,
|
|
18
|
+
arguments: [
|
|
19
|
+
tx.object(this.swapInfo.poolId),
|
|
20
|
+
tx.pure.bool(swapXtoY), // a2b
|
|
21
|
+
tx.pure.bool(true), // exact in
|
|
22
|
+
this.getInputCoinValue(tx),
|
|
23
|
+
tx.pure.u128(sqrtPriceLimit.toString()), // sqrt price limit
|
|
24
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
25
|
+
tx.object(version),
|
|
26
|
+
],
|
|
27
|
+
});
|
|
28
|
+
tx.moveCall({
|
|
29
|
+
target: `${packageId}::trade::repay_flash_swap`,
|
|
30
|
+
typeArguments,
|
|
31
|
+
arguments: [
|
|
32
|
+
tx.object(this.swapInfo.poolId),
|
|
33
|
+
debt,
|
|
34
|
+
swapXtoY
|
|
35
|
+
? sui_1.SuiUtils.coinIntoBalance(tx, coinX.address, this.inputCoinObject)
|
|
36
|
+
: sui_1.SuiUtils.zeroBalance(tx, coinX.address),
|
|
37
|
+
swapXtoY
|
|
38
|
+
? sui_1.SuiUtils.zeroBalance(tx, coinY.address)
|
|
39
|
+
: sui_1.SuiUtils.coinIntoBalance(tx, coinY.address, this.inputCoinObject),
|
|
40
|
+
tx.object(version),
|
|
41
|
+
],
|
|
42
|
+
});
|
|
43
|
+
const receiveACoin = sui_1.SuiUtils.coinFromBalance(tx, coinX.address, receiveA);
|
|
44
|
+
const receiveBCoin = sui_1.SuiUtils.coinFromBalance(tx, coinY.address, receiveB);
|
|
45
|
+
sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, swapXtoY ? receiveACoin : receiveBCoin);
|
|
46
|
+
return swapXtoY ? receiveBCoin : receiveACoin;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.MomentumContract = MomentumContract;
|
|
@@ -1,41 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ObricContract = void 0;
|
|
13
4
|
const utils_1 = require("@mysten/sui/utils");
|
|
14
5
|
const base_1 = require("../base");
|
|
15
6
|
class ObricContract extends base_1.BaseContract {
|
|
16
|
-
swap(tx) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
],
|
|
36
|
-
});
|
|
37
|
-
return coinOut;
|
|
7
|
+
async swap(tx) {
|
|
8
|
+
const [coinX, coinY] = this.swapInfo.pool.allTokens;
|
|
9
|
+
const xToY = this.swapInfo.swapXtoY;
|
|
10
|
+
const { x_price_id, y_price_id } = this.swapInfo.extra || {};
|
|
11
|
+
if (!x_price_id || !y_price_id) {
|
|
12
|
+
throw new Error("x_price_id and y_price_id are required");
|
|
13
|
+
}
|
|
14
|
+
const { package: PACKAGE_ID, pythState: PYTH_STATE } = this.config.obric;
|
|
15
|
+
const [coinOut] = tx.moveCall({
|
|
16
|
+
target: `${PACKAGE_ID}::v2::${xToY ? "swap_x_to_y" : "swap_y_to_x"}`,
|
|
17
|
+
typeArguments: [coinX.address, coinY.address],
|
|
18
|
+
arguments: [
|
|
19
|
+
tx.object(this.swapInfo.poolId),
|
|
20
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
21
|
+
tx.object(PYTH_STATE),
|
|
22
|
+
tx.object(x_price_id), // pyth pricefeed for x
|
|
23
|
+
tx.object(y_price_id), // pyth pricefeed for y
|
|
24
|
+
this.inputCoinObject,
|
|
25
|
+
],
|
|
38
26
|
});
|
|
27
|
+
return coinOut;
|
|
39
28
|
}
|
|
40
29
|
}
|
|
41
30
|
exports.ObricContract = ObricContract;
|
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SpringSuiContract = void 0;
|
|
13
4
|
const utils_1 = require("@mysten/sui/utils");
|
|
14
5
|
const base_1 = require("../base");
|
|
15
6
|
class SpringSuiContract extends base_1.BaseContract {
|
|
16
|
-
swap(tx) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
return coinOut;
|
|
7
|
+
async swap(tx) {
|
|
8
|
+
// coinX is always SUI
|
|
9
|
+
const coinY = this.swapInfo.pool.allTokens[1];
|
|
10
|
+
const isStake = this.swapInfo.swapXtoY;
|
|
11
|
+
const { package: PACKAGE_ID } = this.config.springsui;
|
|
12
|
+
const [coinOut] = tx.moveCall({
|
|
13
|
+
target: `${PACKAGE_ID}::liquid_staking::${isStake ? "mint" : "redeem"}`,
|
|
14
|
+
typeArguments: [coinY.address],
|
|
15
|
+
arguments: [
|
|
16
|
+
tx.object(this.swapInfo.poolId),
|
|
17
|
+
isStake ? tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID) : this.inputCoinObject,
|
|
18
|
+
isStake ? this.inputCoinObject : tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID),
|
|
19
|
+
],
|
|
32
20
|
});
|
|
21
|
+
return coinOut;
|
|
33
22
|
}
|
|
34
23
|
}
|
|
35
24
|
exports.SpringSuiContract = SpringSuiContract;
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SteammContract = void 0;
|
|
13
4
|
const base_1 = require("../base");
|
|
14
5
|
const utils_1 = require("@mysten/sui/utils");
|
|
15
6
|
const sui_1 = require("../../../utils/sui");
|
|
16
7
|
class SteammContract extends base_1.BaseContract {
|
|
17
|
-
swap(tx) {
|
|
18
|
-
|
|
8
|
+
async swap(tx) {
|
|
9
|
+
if (this.extra.poolStructTag.includes("omm::OracleQuoter")) {
|
|
10
|
+
return this.ommSwap(tx);
|
|
11
|
+
}
|
|
12
|
+
else if (this.extra.poolStructTag.includes("cpmm::CpQuoter")) {
|
|
19
13
|
return this.cpmmSwap(tx);
|
|
20
|
-
}
|
|
14
|
+
}
|
|
15
|
+
throw new Error(`Unsupported pool type: ${this.extra.poolStructTag}`);
|
|
21
16
|
}
|
|
22
17
|
cpmmSwap(tx) {
|
|
23
|
-
const extra = this.
|
|
18
|
+
const extra = this.extra;
|
|
24
19
|
if (!extra ||
|
|
25
20
|
!extra.bankAStructTag ||
|
|
26
21
|
!extra.bankBStructTag ||
|
|
@@ -70,10 +65,10 @@ class SteammContract extends base_1.BaseContract {
|
|
|
70
65
|
});
|
|
71
66
|
const coinIn = xToY ? coinA : coinB;
|
|
72
67
|
const coinOut = xToY ? coinB : coinA;
|
|
73
|
-
sui_1.SuiUtils.
|
|
68
|
+
sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, coinIn);
|
|
74
69
|
return coinOut;
|
|
75
70
|
}
|
|
76
|
-
|
|
71
|
+
ommSwap(tx) {
|
|
77
72
|
const extra = this.swapInfo.extra;
|
|
78
73
|
if (!extra ||
|
|
79
74
|
!extra.bankAStructTag ||
|
|
@@ -87,72 +82,76 @@ class SteammContract extends base_1.BaseContract {
|
|
|
87
82
|
}
|
|
88
83
|
// the pool script v1 only support same lending market
|
|
89
84
|
if (extra.lendingMarketA !== extra.lendingMarketB) {
|
|
90
|
-
throw new Error(`Invalid lending market for
|
|
85
|
+
throw new Error(`Invalid lending market for ommSwap`);
|
|
91
86
|
}
|
|
92
87
|
const [btokenA, bTokenB, _quoter, lp] = (0, utils_1.parseStructTag)(extra.poolStructTag).typeParams;
|
|
93
88
|
const [lendingMarket, coinTypeA, _bTokenA] = (0, utils_1.parseStructTag)(extra.bankAStructTag).typeParams;
|
|
94
89
|
const [_lendingMarket, coinTypeB, _bTokenB] = (0, utils_1.parseStructTag)(extra.bankBStructTag).typeParams;
|
|
95
|
-
const
|
|
96
|
-
const xToY = coinX.address === this.swapInfo.assetIn;
|
|
90
|
+
const xToY = this.swapInfo.swapXtoY;
|
|
97
91
|
const coinA = xToY
|
|
98
92
|
? this.inputCoinObject
|
|
99
93
|
: sui_1.SuiUtils.zeroCoin(tx, (0, utils_1.normalizeStructTag)(coinTypeA));
|
|
100
94
|
const coinB = !xToY
|
|
101
95
|
? this.inputCoinObject
|
|
102
96
|
: sui_1.SuiUtils.zeroCoin(tx, (0, utils_1.normalizeStructTag)(coinTypeB));
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
97
|
+
const [priceA, priceB] = this.getOraclePriceUpdate(tx);
|
|
98
|
+
tx.moveCall({
|
|
99
|
+
target: `${this.config.steamm.script}::pool_script_v2::omm_swap`,
|
|
100
|
+
typeArguments: [
|
|
101
|
+
lendingMarket,
|
|
102
|
+
coinTypeA,
|
|
103
|
+
coinTypeB,
|
|
104
|
+
btokenA,
|
|
105
|
+
bTokenB,
|
|
106
|
+
lp,
|
|
107
|
+
].map(utils_1.normalizeStructTag),
|
|
111
108
|
arguments: [
|
|
112
|
-
tx.object(
|
|
109
|
+
tx.object(this.swapInfo.poolId),
|
|
110
|
+
tx.object(extra.bankA),
|
|
111
|
+
tx.object(extra.bankB),
|
|
113
112
|
tx.object(extra.lendingMarketA),
|
|
114
|
-
|
|
113
|
+
priceA,
|
|
114
|
+
priceB,
|
|
115
|
+
coinA,
|
|
116
|
+
coinB,
|
|
117
|
+
tx.pure.bool(xToY),
|
|
115
118
|
this.getInputCoinValue(tx),
|
|
119
|
+
tx.pure.u64(0),
|
|
116
120
|
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
117
121
|
],
|
|
118
122
|
});
|
|
119
|
-
const
|
|
120
|
-
|
|
121
|
-
tx.
|
|
122
|
-
|
|
123
|
-
|
|
123
|
+
const coinIn = xToY ? coinA : coinB;
|
|
124
|
+
const coinOut = xToY ? coinB : coinA;
|
|
125
|
+
sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, coinIn);
|
|
126
|
+
return coinOut;
|
|
127
|
+
}
|
|
128
|
+
getOraclePriceUpdate(tx) {
|
|
129
|
+
const oracleA = this.extra.oracles?.[0]?.Pyth?.price_identifier?.bytes;
|
|
130
|
+
const oracleB = this.extra.oracles?.[1]?.Pyth?.price_identifier?.bytes;
|
|
131
|
+
const registry = this.extra.oracleRegistry;
|
|
132
|
+
const indexes = this.extra.oracleIndexes;
|
|
133
|
+
if (!oracleA || !oracleB || !registry || indexes?.length !== 2) {
|
|
134
|
+
throw new Error(`Invalid oracle info for getOraclePriceUpdate`);
|
|
135
|
+
}
|
|
136
|
+
const [a] = tx.moveCall({
|
|
137
|
+
target: `${this.config.steamm.oracle}::oracles::get_pyth_price`,
|
|
124
138
|
arguments: [
|
|
125
|
-
tx.object(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
tx.
|
|
129
|
-
sui_1.SuiUtils.getCoinValue((0, utils_1.normalizeStructTag)(xToY ? btokenA : bTokenB), bTokenIn, tx),
|
|
130
|
-
tx.pure.u64(0), // min output
|
|
139
|
+
tx.object(registry),
|
|
140
|
+
tx.object(this.pythMap["0x" + (0, utils_1.toHex)(Uint8Array.from(oracleA))]),
|
|
141
|
+
tx.pure.u64(indexes[0]),
|
|
142
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
131
143
|
],
|
|
132
144
|
});
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
target: `${this.config.steamm.package}::bank::burn_btokens`,
|
|
136
|
-
typeArguments: bankOutTypeArgs,
|
|
145
|
+
const [b] = tx.moveCall({
|
|
146
|
+
target: `${this.config.steamm.oracle}::oracles::get_pyth_price`,
|
|
137
147
|
arguments: [
|
|
138
|
-
tx.object(
|
|
139
|
-
tx.object(
|
|
140
|
-
|
|
141
|
-
sui_1.SuiUtils.getCoinValue((0, utils_1.normalizeStructTag)(xToY ? bTokenB : btokenA), bTokenOut, tx),
|
|
148
|
+
tx.object(registry),
|
|
149
|
+
tx.object(this.pythMap["0x" + (0, utils_1.toHex)(Uint8Array.from(oracleB))]),
|
|
150
|
+
tx.pure.u64(indexes[1]),
|
|
142
151
|
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
143
152
|
],
|
|
144
153
|
});
|
|
145
|
-
|
|
146
|
-
const coinOut = xToY ? coinB : coinA;
|
|
147
|
-
// the coinIn was mutated by mint_btokens above, but not consumed, so we need to transfer or destroy it
|
|
148
|
-
sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, coinIn, this.currentAccount);
|
|
149
|
-
// bTokenIn was mutated by cpmm::swap above, but not consumed, so we need to transfer or destroy it
|
|
150
|
-
sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, (0, utils_1.normalizeStructTag)(xToY ? btokenA : bTokenB), bTokenIn, this.currentAccount);
|
|
151
|
-
// bTokenOut was burned by burn_btokens above, but not consumed, so we need to transfer or destroy it
|
|
152
|
-
sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, (0, utils_1.normalizeStructTag)(xToY ? bTokenB : btokenA), bTokenOut, this.currentAccount);
|
|
153
|
-
// after all we need to merge the placeholder output coin (zero) with actual output coin from swap burn
|
|
154
|
-
tx.mergeCoins(coinOut, [outCoin]);
|
|
155
|
-
return coinOut;
|
|
154
|
+
return [a, b];
|
|
156
155
|
}
|
|
157
156
|
}
|
|
158
157
|
exports.SteammContract = SteammContract;
|
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.StSuiContract = void 0;
|
|
13
4
|
const utils_1 = require("@mysten/sui/utils");
|
|
14
5
|
const base_1 = require("../base");
|
|
15
6
|
class StSuiContract extends base_1.BaseContract {
|
|
16
|
-
swap(tx) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
return coinOut;
|
|
7
|
+
async swap(tx) {
|
|
8
|
+
// coinX is always SUI
|
|
9
|
+
const coinY = this.swapInfo.pool.allTokens[1];
|
|
10
|
+
const isStake = this.swapInfo.swapXtoY;
|
|
11
|
+
const { package: PACKAGE_ID } = this.config.stsui;
|
|
12
|
+
const [coinOut] = tx.moveCall({
|
|
13
|
+
target: `${PACKAGE_ID}::liquid_staking::${isStake ? "mint" : "redeem"}`,
|
|
14
|
+
typeArguments: [coinY.address],
|
|
15
|
+
arguments: [
|
|
16
|
+
tx.object(this.swapInfo.poolId),
|
|
17
|
+
isStake ? tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID) : this.inputCoinObject,
|
|
18
|
+
isStake ? this.inputCoinObject : tx.object(utils_1.SUI_SYSTEM_STATE_OBJECT_ID),
|
|
19
|
+
],
|
|
32
20
|
});
|
|
21
|
+
return coinOut;
|
|
33
22
|
}
|
|
34
23
|
}
|
|
35
24
|
exports.StSuiContract = StSuiContract;
|
|
@@ -1,45 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.SuiswapContract = void 0;
|
|
13
4
|
const utils_1 = require("@mysten/sui/utils");
|
|
14
5
|
const base_1 = require("../base");
|
|
15
6
|
const sui_1 = require("../../../utils/sui");
|
|
16
7
|
class SuiswapContract extends base_1.BaseContract {
|
|
17
|
-
swap(tx) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
],
|
|
39
|
-
});
|
|
40
|
-
sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, tokenIn, this.currentAccount);
|
|
41
|
-
return tokenOut;
|
|
8
|
+
async swap(tx) {
|
|
9
|
+
const poolId = this.swapInfo.poolId;
|
|
10
|
+
const swapXtoY = this.swapInfo.swapXtoY;
|
|
11
|
+
const inputCoin = this.inputCoinObject;
|
|
12
|
+
const typeArguments = [this.swapInfo.coinX.type, this.swapInfo.coinY.type];
|
|
13
|
+
const callFunc = swapXtoY
|
|
14
|
+
? "do_swap_x_to_y_direct"
|
|
15
|
+
: "do_swap_y_to_x_direct";
|
|
16
|
+
const { package: PACKAGE_ID } = this.config.suiswap;
|
|
17
|
+
const inputAmount = this.getInputCoinValue(tx);
|
|
18
|
+
const [tokenIn, tokenOut] = tx.moveCall({
|
|
19
|
+
target: `${PACKAGE_ID}::pool::${callFunc}`,
|
|
20
|
+
typeArguments,
|
|
21
|
+
arguments: [
|
|
22
|
+
tx.object(poolId),
|
|
23
|
+
tx.makeMoveVec({
|
|
24
|
+
elements: [inputCoin],
|
|
25
|
+
}),
|
|
26
|
+
inputAmount,
|
|
27
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
28
|
+
],
|
|
42
29
|
});
|
|
30
|
+
sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, tokenIn);
|
|
31
|
+
return tokenOut;
|
|
43
32
|
}
|
|
44
33
|
}
|
|
45
34
|
exports.SuiswapContract = SuiswapContract;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.TurbosContract = void 0;
|
|
13
4
|
const utils_1 = require("@mysten/sui/utils");
|
|
@@ -16,36 +7,30 @@ const utils_2 = require("../utils");
|
|
|
16
7
|
const sui_1 = require("../../../utils/sui");
|
|
17
8
|
const ONE_MINUTE = 60 * 1000;
|
|
18
9
|
class TurbosContract extends base_1.BaseContract {
|
|
19
|
-
swap(tx) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
tx.pure.address(this.currentAccount),
|
|
41
|
-
tx.pure.u64(Date.now() + ONE_MINUTE * 3),
|
|
42
|
-
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
43
|
-
tx.object(VERSION),
|
|
44
|
-
],
|
|
45
|
-
});
|
|
46
|
-
sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, tokenIn, address);
|
|
47
|
-
return tokenOut;
|
|
10
|
+
async swap(tx) {
|
|
11
|
+
const a2b = this.swapInfo.swapXtoY;
|
|
12
|
+
const { package: PACKAGE_ID, version: VERSION } = this.config.turbos;
|
|
13
|
+
const inputAmount = this.getInputCoinValue(tx);
|
|
14
|
+
const [tokenOut, tokenIn] = tx.moveCall({
|
|
15
|
+
target: `${PACKAGE_ID}::swap_router::swap_${a2b ? "a_b" : "b_a"}_with_return_`,
|
|
16
|
+
typeArguments: this.getTypeParams(),
|
|
17
|
+
arguments: [
|
|
18
|
+
tx.object(this.swapInfo.poolId),
|
|
19
|
+
tx.makeMoveVec({
|
|
20
|
+
elements: [this.inputCoinObject],
|
|
21
|
+
}),
|
|
22
|
+
inputAmount,
|
|
23
|
+
tx.pure.u64(0),
|
|
24
|
+
tx.pure.u128((0, utils_2.getDefaultSqrtPriceLimit)(this.swapInfo.swapXtoY).toString()),
|
|
25
|
+
tx.pure.bool(true),
|
|
26
|
+
tx.pure.address(this.currentAccount),
|
|
27
|
+
tx.pure.u64(Date.now() + ONE_MINUTE * 3),
|
|
28
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
29
|
+
tx.object(VERSION),
|
|
30
|
+
],
|
|
48
31
|
});
|
|
32
|
+
sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, tokenIn);
|
|
33
|
+
return tokenOut;
|
|
49
34
|
}
|
|
50
35
|
}
|
|
51
36
|
exports.TurbosContract = TurbosContract;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getDefaultSqrtPriceLimit = getDefaultSqrtPriceLimit;
|
|
7
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
8
4
|
const constants_1 = require("./constants");
|
|
9
5
|
function getDefaultSqrtPriceLimit(a2b) {
|
|
10
|
-
return
|
|
6
|
+
return BigInt(a2b ? constants_1.MIN_SQRT_PRICE : constants_1.MAX_SQRT_PRICE);
|
|
11
7
|
}
|