@7kprotocol/sdk-ts 2.4.0 → 2.4.2-beta.0
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 +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 +36 -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 +5 -3
- 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 +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 +36 -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,33 +1,22 @@
|
|
|
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.placeLimitOrder = placeLimitOrder;
|
|
13
4
|
const getSplitCoinForTx_1 = require("../../libs/getSplitCoinForTx");
|
|
14
5
|
const token_1 = require("../../utils/token");
|
|
15
6
|
const constants_1 = require("./constants");
|
|
16
|
-
function placeLimitOrder(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
typeArguments: [payCoinType, targetCoinType],
|
|
30
|
-
});
|
|
31
|
-
return tx;
|
|
7
|
+
async function placeLimitOrder({ accountAddress, payCoinType, targetCoinType, payCoinAmount, rate, slippage, expireTs, devInspect, }) {
|
|
8
|
+
const { tx, coinData: payCoin } = await (0, getSplitCoinForTx_1.getSplitCoinForTx)(accountAddress, payCoinAmount.toString(), [payCoinAmount.toString()], (0, token_1.denormalizeTokenType)(payCoinType), undefined, devInspect);
|
|
9
|
+
tx.moveCall({
|
|
10
|
+
target: `${constants_1.LIMIT_ORDER_MODULE_ID}::place_limit_order`,
|
|
11
|
+
arguments: [
|
|
12
|
+
tx.object(constants_1.GLOBAL_CONFIG_ID),
|
|
13
|
+
payCoin,
|
|
14
|
+
tx.pure.u64(rate),
|
|
15
|
+
tx.pure.u64(slippage),
|
|
16
|
+
tx.pure.u64(expireTs),
|
|
17
|
+
tx.object.clock(),
|
|
18
|
+
],
|
|
19
|
+
typeArguments: [payCoinType, targetCoinType],
|
|
32
20
|
});
|
|
21
|
+
return tx;
|
|
33
22
|
}
|
|
@@ -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.getTokenPrice = getTokenPrice;
|
|
13
4
|
exports.getTokenPrices = getTokenPrices;
|
|
@@ -16,18 +7,15 @@ const fetchClient_1 = require("../../config/fetchClient");
|
|
|
16
7
|
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
17
8
|
const tokens_1 = require("../../constants/tokens");
|
|
18
9
|
const token_1 = require("../../utils/token");
|
|
19
|
-
function getTokenPrice(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
10
|
+
async function getTokenPrice(id, vsCoin = tokens_1.NATIVE_USDC_TOKEN_TYPE) {
|
|
11
|
+
try {
|
|
12
|
+
const response = await (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.PRICES}/price?ids=${(0, token_1.normalizeTokenType)(id)}&vsCoin=${vsCoin}`);
|
|
13
|
+
const pricesRes = (await response.json());
|
|
14
|
+
return Number(pricesRes?.[id]?.price || 0);
|
|
15
|
+
}
|
|
16
|
+
catch (_) {
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
31
19
|
}
|
|
32
20
|
const chunkArray = (array, chunkSize) => {
|
|
33
21
|
const chunks = [];
|
|
@@ -38,48 +26,43 @@ const chunkArray = (array, chunkSize) => {
|
|
|
38
26
|
};
|
|
39
27
|
const MAX_TOTAL_IDS = 500;
|
|
40
28
|
const MAX_IDS_PER_REQUEST = 100;
|
|
41
|
-
function getTokenPrices(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}, {});
|
|
78
|
-
}
|
|
79
|
-
});
|
|
29
|
+
async function getTokenPrices(ids, vsCoin = tokens_1.NATIVE_USDC_TOKEN_TYPE) {
|
|
30
|
+
try {
|
|
31
|
+
const limitedIds = ids.slice(0, MAX_TOTAL_IDS).map(token_1.normalizeTokenType);
|
|
32
|
+
const idChunks = chunkArray(limitedIds, MAX_IDS_PER_REQUEST);
|
|
33
|
+
const responses = await Promise.all(idChunks.map(async (chunk) => {
|
|
34
|
+
const response = await (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.PRICES}/price`, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "application/json",
|
|
38
|
+
},
|
|
39
|
+
body: JSON.stringify({
|
|
40
|
+
ids: chunk,
|
|
41
|
+
vsCoin,
|
|
42
|
+
}),
|
|
43
|
+
});
|
|
44
|
+
const pricesRes = (await response.json());
|
|
45
|
+
return pricesRes;
|
|
46
|
+
}));
|
|
47
|
+
const combinedPrices = responses.reduce((acc, pricesRes) => {
|
|
48
|
+
Object.keys(pricesRes).forEach((id) => {
|
|
49
|
+
acc[id] = Number(pricesRes[id]?.price || 0);
|
|
50
|
+
});
|
|
51
|
+
return acc;
|
|
52
|
+
}, {});
|
|
53
|
+
const finalPrices = limitedIds.reduce((acc, id) => {
|
|
54
|
+
acc[id] = combinedPrices[id] || 0;
|
|
55
|
+
return acc;
|
|
56
|
+
}, {});
|
|
57
|
+
return finalPrices;
|
|
58
|
+
}
|
|
59
|
+
catch (_) {
|
|
60
|
+
return ids.slice(0, MAX_TOTAL_IDS).reduce((acc, id) => {
|
|
61
|
+
acc[id] = 0;
|
|
62
|
+
return acc;
|
|
63
|
+
}, {});
|
|
64
|
+
}
|
|
80
65
|
}
|
|
81
|
-
function getSuiPrice() {
|
|
82
|
-
return
|
|
83
|
-
return yield getTokenPrice(tokens_1.SUI_FULL_TYPE);
|
|
84
|
-
});
|
|
66
|
+
async function getSuiPrice() {
|
|
67
|
+
return await getTokenPrice(tokens_1.SUI_FULL_TYPE);
|
|
85
68
|
}
|
|
@@ -1,31 +1,31 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.buildTx = void 0;
|
|
16
4
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
17
|
-
const
|
|
5
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
6
|
+
const config_1 = require("../../config");
|
|
7
|
+
const _7k_1 = require("../../constants/_7k");
|
|
18
8
|
const getSplitCoinForTx_1 = require("../../libs/getSplitCoinForTx");
|
|
19
9
|
const groupSwapRoutes_1 = require("../../libs/groupSwapRoutes");
|
|
10
|
+
const client_1 = require("../../libs/protocols/bluefinx/client");
|
|
11
|
+
const types_1 = require("../../libs/protocols/bluefinx/types");
|
|
20
12
|
const swapWithRoute_1 = require("../../libs/swapWithRoute");
|
|
21
|
-
const
|
|
13
|
+
const aggregator_1 = require("../../types/aggregator");
|
|
22
14
|
const sui_1 = require("../../utils/sui");
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const
|
|
15
|
+
const token_1 = require("../../utils/token");
|
|
16
|
+
const config_2 = require("./config");
|
|
17
|
+
const buildTx = async ({ quoteResponse, accountAddress, slippage, commission: __commission, devInspect, extendTx, isSponsored, }) => {
|
|
18
|
+
const isBluefinX = (0, aggregator_1.isBluefinXRouting)(quoteResponse);
|
|
19
|
+
const _commission = {
|
|
20
|
+
...__commission,
|
|
21
|
+
// commission is ignored for bluefinx
|
|
22
|
+
commissionBps: isBluefinX ? 0 : __commission.commissionBps,
|
|
23
|
+
};
|
|
27
24
|
const { tx: _tx, coinIn } = extendTx || {};
|
|
28
25
|
let coinOut;
|
|
26
|
+
if (isBluefinX && devInspect) {
|
|
27
|
+
throw new Error("BluefinX tx is sponsored, skip devInspect");
|
|
28
|
+
}
|
|
29
29
|
if (!accountAddress) {
|
|
30
30
|
throw new Error("Sender address is required");
|
|
31
31
|
}
|
|
@@ -37,45 +37,42 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteRespon
|
|
|
37
37
|
}
|
|
38
38
|
const tx = _tx || new transactions_1.Transaction();
|
|
39
39
|
const routes = (0, groupSwapRoutes_1.groupSwapRoutes)(quoteResponse);
|
|
40
|
-
const splits = routes.map((group) =>
|
|
40
|
+
const splits = routes.map((group) => group[0]?.amount ?? "0");
|
|
41
41
|
let coinData;
|
|
42
42
|
if (coinIn) {
|
|
43
43
|
coinData = tx.splitCoins(coinIn, splits);
|
|
44
|
-
sui_1.SuiUtils.
|
|
44
|
+
sui_1.SuiUtils.collectDust(tx, quoteResponse.tokenIn, coinIn);
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
-
const { coinData: _data } =
|
|
47
|
+
const { coinData: _data } = await (0, getSplitCoinForTx_1.getSplitCoinForTx)(accountAddress, quoteResponse.swapAmountWithDecimal, splits, (0, token_1.denormalizeTokenType)(quoteResponse.tokenIn), tx, devInspect, isSponsored || isBluefinX);
|
|
48
48
|
coinData = _data;
|
|
49
49
|
}
|
|
50
|
+
const pythMap = await updatePythPriceFeedsIfAny(tx, quoteResponse);
|
|
50
51
|
const coinObjects = [];
|
|
51
|
-
const config =
|
|
52
|
-
|
|
52
|
+
const config = await (0, config_2.getConfig)();
|
|
53
|
+
await Promise.all(routes.map(async (route, index) => {
|
|
53
54
|
const inputCoinObject = coinData[index];
|
|
54
|
-
const coinRes =
|
|
55
|
+
const coinRes = await (0, swapWithRoute_1.swapWithRoute)({
|
|
55
56
|
route,
|
|
56
57
|
inputCoinObject,
|
|
57
58
|
currentAccount: accountAddress,
|
|
58
59
|
tx,
|
|
59
60
|
config,
|
|
61
|
+
pythMap,
|
|
60
62
|
});
|
|
61
63
|
if (coinRes) {
|
|
62
64
|
coinObjects.push(coinRes);
|
|
63
65
|
}
|
|
64
|
-
}))
|
|
66
|
+
}));
|
|
65
67
|
if (coinObjects.length > 0) {
|
|
66
68
|
const mergeCoin = coinObjects.length > 1
|
|
67
69
|
? sui_1.SuiUtils.mergeCoins(coinObjects, tx)
|
|
68
70
|
: coinObjects[0];
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const [partner] = tx.moveCall({
|
|
75
|
-
target: "0x1::option::some",
|
|
76
|
-
typeArguments: [`address`],
|
|
77
|
-
arguments: [tx.pure.address(_commission.partner)],
|
|
78
|
-
});
|
|
71
|
+
const returnAmountAfterCommission = (BigInt(10000 - _commission.commissionBps) *
|
|
72
|
+
BigInt(quoteResponse.returnAmountWithDecimal)) /
|
|
73
|
+
BigInt(10000);
|
|
74
|
+
const minReceived = (BigInt(1e9 - +slippage * 1e9) * BigInt(returnAmountAfterCommission)) /
|
|
75
|
+
BigInt(1e9);
|
|
79
76
|
tx.moveCall({
|
|
80
77
|
target: `${_7k_1._7K_PACKAGE_ID}::settle::settle`,
|
|
81
78
|
typeArguments: [quoteResponse.tokenIn, quoteResponse.tokenOut],
|
|
@@ -84,16 +81,68 @@ const buildTx = (_a) => __awaiter(void 0, [_a], void 0, function* ({ quoteRespon
|
|
|
84
81
|
tx.object(_7k_1._7K_VAULT),
|
|
85
82
|
tx.pure.u64(quoteResponse.swapAmountWithDecimal),
|
|
86
83
|
mergeCoin,
|
|
87
|
-
tx.pure.u64(minReceived),
|
|
88
|
-
tx.pure.u64(
|
|
89
|
-
partner,
|
|
84
|
+
tx.pure.u64(minReceived), // minimum received
|
|
85
|
+
tx.pure.u64(returnAmountAfterCommission), // expected amount out
|
|
86
|
+
tx.pure.option("address", (0, utils_1.isValidSuiAddress)(_commission.partner) ? _commission.partner : null),
|
|
90
87
|
tx.pure.u64(_commission.commissionBps),
|
|
88
|
+
tx.pure.u64(0),
|
|
91
89
|
],
|
|
92
90
|
});
|
|
93
91
|
if (!extendTx) {
|
|
94
92
|
tx.transferObjects([mergeCoin], tx.pure.address(accountAddress));
|
|
95
93
|
}
|
|
94
|
+
else {
|
|
95
|
+
coinOut = mergeCoin;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (isBluefinX) {
|
|
99
|
+
const extra = quoteResponse.swaps[0].extra;
|
|
100
|
+
if (extra.quoteExpiresAtUtcMillis < Date.now()) {
|
|
101
|
+
throw new Error("Quote expired");
|
|
102
|
+
}
|
|
103
|
+
tx.setSenderIfNotSet(accountAddress);
|
|
104
|
+
const bytes = await tx.build({
|
|
105
|
+
client: config_1.Config.getSuiClient(),
|
|
106
|
+
onlyTransactionKind: true,
|
|
107
|
+
});
|
|
108
|
+
const res = await (0, client_1.sponsorBluefinX)({
|
|
109
|
+
quoteId: extra.quoteId,
|
|
110
|
+
txBytes: (0, utils_1.toBase64)(bytes),
|
|
111
|
+
sender: accountAddress,
|
|
112
|
+
});
|
|
113
|
+
if (!res.success) {
|
|
114
|
+
throw new Error("Sponsor failed");
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
tx: new types_1.BluefinXTx(res.quoteId, res.data.txBytes),
|
|
118
|
+
coinOut,
|
|
119
|
+
};
|
|
96
120
|
}
|
|
97
121
|
return { tx, coinOut };
|
|
98
|
-
}
|
|
122
|
+
};
|
|
99
123
|
exports.buildTx = buildTx;
|
|
124
|
+
const getPythPriceFeeds = (res) => {
|
|
125
|
+
const ids = [];
|
|
126
|
+
for (const s of res.swaps) {
|
|
127
|
+
for (const o of s.extra?.oracles || []) {
|
|
128
|
+
const bytes = o.Pyth?.price_identifier?.bytes;
|
|
129
|
+
if (bytes) {
|
|
130
|
+
ids.push("0x" + (0, utils_1.toHex)(Uint8Array.from(bytes)));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return ids;
|
|
135
|
+
};
|
|
136
|
+
const updatePythPriceFeedsIfAny = async (tx, quoteResponse) => {
|
|
137
|
+
// update oracles price if any
|
|
138
|
+
const pythMap = {};
|
|
139
|
+
const pythIds = getPythPriceFeeds(quoteResponse);
|
|
140
|
+
if (pythIds.length > 0) {
|
|
141
|
+
const prices = await config_1.Config.getPythConnection().getPriceFeedsUpdateData(pythIds);
|
|
142
|
+
const ids = await config_1.Config.getPythClient().updatePriceFeeds(tx, prices, pythIds);
|
|
143
|
+
pythIds.map((id, index) => {
|
|
144
|
+
pythMap[id] = ids[index];
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return pythMap;
|
|
148
|
+
};
|
|
@@ -1,20 +1,9 @@
|
|
|
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.DEFAULT_CONFIG = void 0;
|
|
13
4
|
exports.getConfig = getConfig;
|
|
14
5
|
const fetchClient_1 = require("../../config/fetchClient");
|
|
15
6
|
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
16
|
-
let config = null;
|
|
17
|
-
let configTs = 0;
|
|
18
7
|
exports.DEFAULT_CONFIG = {
|
|
19
8
|
aftermath: {
|
|
20
9
|
name: "Aftermath",
|
|
@@ -30,6 +19,11 @@ exports.DEFAULT_CONFIG = {
|
|
|
30
19
|
package: "0x6c796c3ab3421a68158e0df18e4657b2827b1f8fed5ed4b82dba9c935988711b",
|
|
31
20
|
globalConfig: "0x03db251ba509a8d5d8777b6338836082335d93eecbdd09a11e190a1cff51c352",
|
|
32
21
|
},
|
|
22
|
+
bluefinx: {
|
|
23
|
+
name: "BluefinX",
|
|
24
|
+
package: "0xf8870f988ab09be7c5820a856bd5e9da84fc7192e095a7a8829919293b00a36c",
|
|
25
|
+
globalConfig: "0xc6b29a60c3924776bedc78df72c127ea52b86aeb655432979a38f13d742dedaa",
|
|
26
|
+
},
|
|
33
27
|
bluemove: {
|
|
34
28
|
name: "Bluemove",
|
|
35
29
|
package: "0x08cd33481587d4c4612865b164796d937df13747d8c763b8a178c87e3244498f",
|
|
@@ -40,10 +34,6 @@ exports.DEFAULT_CONFIG = {
|
|
|
40
34
|
package: "0x6f5e582ede61fe5395b50c4a449ec11479a54d7ff8e0158247adfda60d98970b",
|
|
41
35
|
globalConfig: "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f",
|
|
42
36
|
},
|
|
43
|
-
deepbook: {
|
|
44
|
-
name: "Deepbook",
|
|
45
|
-
package: "0xdee9",
|
|
46
|
-
},
|
|
47
37
|
deepbook_v3: {
|
|
48
38
|
name: "Deepbook V3",
|
|
49
39
|
package: "",
|
|
@@ -96,28 +86,38 @@ exports.DEFAULT_CONFIG = {
|
|
|
96
86
|
name: "Steamm",
|
|
97
87
|
package: "0x4fb1cf45dffd6230305f1d269dd1816678cc8e3ba0b747a813a556921219f261",
|
|
98
88
|
script: "0x13bfc09cfc1bd922d3aa53fcf7b2cd510727ee65068ce136e2ebd5f3b213fdd2",
|
|
89
|
+
oracle: "0xe84b649199654d18c38e727212f5d8dacfc3cf78d60d0a7fc85fd589f280eb2b",
|
|
99
90
|
},
|
|
100
91
|
magma: {
|
|
101
92
|
name: "Magma",
|
|
102
93
|
package: "0x951d48bece7f6c2a3f4ba0b5791ba823c491e504feb4136497ee51331208ac33",
|
|
103
94
|
globalConfig: "0x4c4e1402401f72c7d8533d0ed8d5f8949da363c7a3319ccef261ffe153d32f8a",
|
|
104
95
|
},
|
|
96
|
+
haedal_pmm: {
|
|
97
|
+
name: "Haedal PMM",
|
|
98
|
+
package: "0xa0e3b011012b80af4957afa30e556486eb3da0a7d96eeb733cf16ccd3aec32e0",
|
|
99
|
+
},
|
|
100
|
+
momentum: {
|
|
101
|
+
name: "Momentum",
|
|
102
|
+
package: "0x70285592c97965e811e0c6f98dccc3a9c2b4ad854b3594faab9597ada267b860",
|
|
103
|
+
version: "0x2375a0b1ec12010aaea3b2545acfa2ad34cfbba03ce4b59f4c39e1e25eed1b2a",
|
|
104
|
+
},
|
|
105
105
|
};
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
106
|
+
let config = exports.DEFAULT_CONFIG;
|
|
107
|
+
let configTs = 0;
|
|
108
|
+
async function getConfig() {
|
|
109
|
+
const ttl = 60;
|
|
110
|
+
if (config && Date.now() - configTs < ttl * 1000) {
|
|
111
|
+
return config;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
const response = await (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.MAIN}/config`);
|
|
115
|
+
const quoteResponse = (await response.json());
|
|
116
|
+
config = { ...config, ...quoteResponse };
|
|
117
|
+
configTs = Date.now();
|
|
118
|
+
return config;
|
|
119
|
+
}
|
|
120
|
+
catch (_) {
|
|
121
|
+
return exports.DEFAULT_CONFIG;
|
|
122
|
+
}
|
|
123
123
|
}
|
|
@@ -1,54 +1,44 @@
|
|
|
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.estimateGasFee = estimateGasFee;
|
|
16
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
17
4
|
const utils_1 = require("@mysten/sui/utils");
|
|
18
|
-
const
|
|
5
|
+
const config_1 = require("../../config");
|
|
6
|
+
const aggregator_1 = require("../../types/aggregator");
|
|
19
7
|
const number_1 = require("../../utils/number");
|
|
20
8
|
const prices_1 = require("../prices");
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const fee = new bignumber_js_1.default(gasUsed.computationCost)
|
|
49
|
-
.plus(gasUsed.storageCost)
|
|
50
|
-
.minus(gasUsed.storageRebate);
|
|
51
|
-
const feeUsd = new bignumber_js_1.default(suiPrice).multipliedBy((0, number_1.formatBalance)(fee, suiDecimals));
|
|
52
|
-
return feeUsd.toNumber();
|
|
9
|
+
const buildTx_1 = require("./buildTx");
|
|
10
|
+
const types_1 = require("../../libs/protocols/bluefinx/types");
|
|
11
|
+
async function estimateGasFee({ quoteResponse, accountAddress, slippage, suiPrice: _suiPrice, extendTx, commission, }) {
|
|
12
|
+
if (!accountAddress)
|
|
13
|
+
return 0;
|
|
14
|
+
// BluefinX is sponsored, no need to estimate gas fee
|
|
15
|
+
if (!accountAddress || (0, aggregator_1.isBluefinXRouting)(quoteResponse))
|
|
16
|
+
return 0;
|
|
17
|
+
const result = await (0, buildTx_1.buildTx)({
|
|
18
|
+
extendTx,
|
|
19
|
+
quoteResponse,
|
|
20
|
+
accountAddress,
|
|
21
|
+
slippage,
|
|
22
|
+
commission,
|
|
23
|
+
devInspect: true,
|
|
24
|
+
}).catch((err) => {
|
|
25
|
+
console.log("build tx error: ", err);
|
|
26
|
+
return undefined;
|
|
27
|
+
});
|
|
28
|
+
const { tx } = result || {};
|
|
29
|
+
if (!tx || tx instanceof types_1.BluefinXTx)
|
|
30
|
+
return 0;
|
|
31
|
+
const suiPrice = _suiPrice || (await (0, prices_1.getSuiPrice)());
|
|
32
|
+
const suiDecimals = utils_1.SUI_DECIMALS;
|
|
33
|
+
const { effects: { gasUsed, status }, } = await config_1.Config.getSuiClient().devInspectTransactionBlock({
|
|
34
|
+
sender: accountAddress,
|
|
35
|
+
transactionBlock: tx,
|
|
53
36
|
});
|
|
37
|
+
if (status.status !== "success")
|
|
38
|
+
return 0;
|
|
39
|
+
const fee = BigInt(gasUsed.computationCost) +
|
|
40
|
+
BigInt(gasUsed.storageCost) -
|
|
41
|
+
BigInt(gasUsed.storageRebate);
|
|
42
|
+
const feeUsd = Number(suiPrice) * Number((0, number_1.formatBalance)(fee, suiDecimals));
|
|
43
|
+
return feeUsd;
|
|
54
44
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeTx = void 0;
|
|
4
|
+
const config_1 = require("../../config");
|
|
5
|
+
const client_1 = require("../../libs/protocols/bluefinx/client");
|
|
6
|
+
const types_1 = require("../../libs/protocols/bluefinx/types");
|
|
7
|
+
/**
|
|
8
|
+
* Execute a transaction after it is signed
|
|
9
|
+
*
|
|
10
|
+
* Automatically handle BluefinX transaction execution if needed
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const { mutateAsync: signTransaction } = useSignTransaction();
|
|
14
|
+
* const quoteResponse = await getQuote(...quoteParams);
|
|
15
|
+
* const { tx } = await buildTx(...buildTxParams);
|
|
16
|
+
* const {signature, bytes} = await signTransaction({
|
|
17
|
+
* transaction: tx instanceof BluefinXTx ? tx.txBytes : tx,
|
|
18
|
+
* });
|
|
19
|
+
* const res = await executeTx(tx, signature, bytes);
|
|
20
|
+
* ```
|
|
21
|
+
* @param tx - AggregatorTx - received from `buildTx`
|
|
22
|
+
* @param signature - User signature after signing the transaction
|
|
23
|
+
* @param signedTxBytes - Signed transaction bytes after signing the transaction
|
|
24
|
+
* @param options - Options for the transaction
|
|
25
|
+
* @returns `SuiTransactionBlockResponse`
|
|
26
|
+
*/
|
|
27
|
+
const executeTx = async (tx, signature, signedTxBytes, options) => {
|
|
28
|
+
const isBluefinTx = tx instanceof types_1.BluefinXTx;
|
|
29
|
+
const client = config_1.Config.getSuiClient();
|
|
30
|
+
let res;
|
|
31
|
+
if (isBluefinTx) {
|
|
32
|
+
try {
|
|
33
|
+
const result = await (0, client_1.executeBluefinTx)(tx, signature);
|
|
34
|
+
res = await client.waitForTransaction({
|
|
35
|
+
digest: result.txDigest,
|
|
36
|
+
options,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
throw Error(`Could not retrieve BluefinX transaction with quoteId: ${tx.quoteId} ${e}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
res = await client.executeTransactionBlock({
|
|
45
|
+
transactionBlock: signedTxBytes,
|
|
46
|
+
signature,
|
|
47
|
+
options,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return res;
|
|
51
|
+
};
|
|
52
|
+
exports.executeTx = executeTx;
|