@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,19 +1,11 @@
|
|
|
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_SOURCES = void 0;
|
|
13
4
|
exports.getQuote = getQuote;
|
|
14
5
|
const utils_1 = require("@mysten/sui/utils");
|
|
15
|
-
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
16
6
|
const fetchClient_1 = require("../../config/fetchClient");
|
|
7
|
+
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
8
|
+
const aggregator_1 = require("../../types/aggregator");
|
|
17
9
|
exports.DEFAULT_SOURCES = [
|
|
18
10
|
"suiswap",
|
|
19
11
|
"turbos",
|
|
@@ -22,7 +14,6 @@ exports.DEFAULT_SOURCES = [
|
|
|
22
14
|
"kriya",
|
|
23
15
|
"kriya_v3",
|
|
24
16
|
"aftermath",
|
|
25
|
-
"deepbook",
|
|
26
17
|
"deepbook_v3",
|
|
27
18
|
"flowx",
|
|
28
19
|
"flowx_v3",
|
|
@@ -31,27 +22,46 @@ exports.DEFAULT_SOURCES = [
|
|
|
31
22
|
"obric",
|
|
32
23
|
"stsui",
|
|
33
24
|
"steamm",
|
|
25
|
+
"steamm_oracle_quoter",
|
|
34
26
|
"magma",
|
|
27
|
+
"haedal_pmm",
|
|
28
|
+
"momentum",
|
|
35
29
|
];
|
|
36
|
-
function getQuote(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
sources: sources.join(","),
|
|
43
|
-
});
|
|
44
|
-
if (targetPools === null || targetPools === void 0 ? void 0 : targetPools.length) {
|
|
45
|
-
params.append("target_pools", targetPools.map((v) => (0, utils_1.normalizeSuiObjectId)(v)).join(","));
|
|
46
|
-
}
|
|
47
|
-
if (excludedPools === null || excludedPools === void 0 ? void 0 : excludedPools.length) {
|
|
48
|
-
params.append("excluded_pools", excludedPools.map((v) => (0, utils_1.normalizeSuiObjectId)(v)).join(","));
|
|
49
|
-
}
|
|
50
|
-
const response = yield (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.MAIN}/quote?${params}`);
|
|
51
|
-
if (!response.ok) {
|
|
52
|
-
throw new Error("Failed to fetch aggregator quote");
|
|
53
|
-
}
|
|
54
|
-
const quoteResponse = (yield response.json());
|
|
55
|
-
return quoteResponse;
|
|
30
|
+
async function getQuote({ tokenIn, tokenOut, amountIn, sources = exports.DEFAULT_SOURCES, commissionBps, targetPools, excludedPools, taker, }) {
|
|
31
|
+
const params = new URLSearchParams({
|
|
32
|
+
amount: amountIn,
|
|
33
|
+
from: (0, utils_1.normalizeStructTag)(tokenIn),
|
|
34
|
+
to: (0, utils_1.normalizeStructTag)(tokenOut),
|
|
35
|
+
sources: sources.join(","),
|
|
56
36
|
});
|
|
37
|
+
if (targetPools?.length) {
|
|
38
|
+
params.append("target_pools", targetPools.map((v) => (0, utils_1.normalizeSuiObjectId)(v)).join(","));
|
|
39
|
+
}
|
|
40
|
+
if (excludedPools?.length) {
|
|
41
|
+
params.append("excluded_pools", excludedPools.map((v) => (0, utils_1.normalizeSuiObjectId)(v)).join(","));
|
|
42
|
+
}
|
|
43
|
+
if (taker) {
|
|
44
|
+
params.append("taker", taker);
|
|
45
|
+
}
|
|
46
|
+
const response = await (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.MAIN}/quote?${params}`);
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
throw new Error("Failed to fetch aggregator quote");
|
|
49
|
+
}
|
|
50
|
+
const quoteResponse = (await response.json());
|
|
51
|
+
computeReturnAmountAfterCommission(quoteResponse, commissionBps);
|
|
52
|
+
return quoteResponse;
|
|
57
53
|
}
|
|
54
|
+
const computeReturnAmountAfterCommission = (quoteResponse, commissionBps) => {
|
|
55
|
+
const _commissionBps = (0, aggregator_1.isBluefinXRouting)(quoteResponse) ? 0 : commissionBps;
|
|
56
|
+
if (quoteResponse.returnAmount && +quoteResponse.returnAmount > 0) {
|
|
57
|
+
quoteResponse.returnAmountAfterCommissionWithDecimal = ((BigInt(quoteResponse.returnAmountWithDecimal || 0) *
|
|
58
|
+
BigInt(10000 - (_commissionBps ?? 0))) /
|
|
59
|
+
BigInt(10000)).toString(10);
|
|
60
|
+
const exp = Math.round(+quoteResponse.returnAmountWithDecimal / +quoteResponse.returnAmount);
|
|
61
|
+
quoteResponse.returnAmountAfterCommission = (+quoteResponse.returnAmountAfterCommissionWithDecimal / exp).toString(10);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
quoteResponse.returnAmountAfterCommission = "";
|
|
65
|
+
quoteResponse.returnAmountAfterCommissionWithDecimal = "";
|
|
66
|
+
}
|
|
67
|
+
};
|
|
@@ -1,32 +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.getSwapHistory = getSwapHistory;
|
|
13
4
|
const fetchClient_1 = require("../../config/fetchClient");
|
|
14
5
|
const apiEndpoints_1 = require("../../constants/apiEndpoints");
|
|
15
6
|
const url_1 = require("../../libs/url");
|
|
16
|
-
function getSwapHistory(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return orders;
|
|
31
|
-
});
|
|
7
|
+
async function getSwapHistory({ owner, offset = 0, limit = 10, tokenPair, }) {
|
|
8
|
+
const queryParams = {
|
|
9
|
+
addr: owner,
|
|
10
|
+
offset,
|
|
11
|
+
limit,
|
|
12
|
+
token_pair: tokenPair,
|
|
13
|
+
};
|
|
14
|
+
const paramsStr = (0, url_1.formatQueryParams)(queryParams);
|
|
15
|
+
const response = await (0, fetchClient_1.fetchClient)(`${apiEndpoints_1.API_ENDPOINTS.STATISTIC}/trading-history?${paramsStr}`);
|
|
16
|
+
if (!response.ok) {
|
|
17
|
+
throw new Error("Failed to fetch open limit orders");
|
|
18
|
+
}
|
|
19
|
+
const orders = (await response.json());
|
|
20
|
+
return orders;
|
|
32
21
|
}
|
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./buildTx"), exports);
|
|
18
18
|
__exportStar(require("./estimateGasFee"), exports);
|
|
19
|
+
__exportStar(require("./executeTx"), exports);
|
|
19
20
|
__exportStar(require("./getQuote"), exports);
|
|
20
21
|
__exportStar(require("./getSwapHistory"), exports);
|
package/lib/cjs/index.js
CHANGED
|
@@ -14,30 +14,34 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.getDcaOrderExecutions = exports.getClosedDcaOrders = exports.cancelDcaOrder = exports.getOpenDcaOrders = exports.placeDcaOrder = exports.getClosedLimitOrders = exports.claimExpiredLimitOrder = exports.cancelLimitOrder = exports.getOpenLimitOrders = exports.placeLimitOrder = exports.getSwapHistory = exports.buildTx = exports.estimateGasFee = exports.getQuote = exports.getSuiPrice = exports.getTokenPrices = exports.getTokenPrice = exports.setSuiClient = exports.getSuiClient = exports.Config = void 0;
|
|
17
|
+
exports.getDcaOrderExecutions = exports.getClosedDcaOrders = exports.cancelDcaOrder = exports.getOpenDcaOrders = exports.placeDcaOrder = exports.getClosedLimitOrders = exports.claimExpiredLimitOrder = exports.cancelLimitOrder = exports.getOpenLimitOrders = exports.placeLimitOrder = exports.DEFAULT_SOURCES = exports.executeBluefinTx = exports.executeTx = exports.getSwapHistory = exports.buildTx = exports.estimateGasFee = exports.getQuote = exports.getSuiPrice = exports.getTokenPrices = exports.getTokenPrice = exports.setSuiClient = exports.getSuiClient = exports.Config = void 0;
|
|
18
18
|
__exportStar(require("./types/aggregator"), exports);
|
|
19
19
|
const config_1 = require("./config");
|
|
20
20
|
Object.defineProperty(exports, "Config", { enumerable: true, get: function () { return config_1.Config; } });
|
|
21
21
|
const prices_1 = require("./features/prices");
|
|
22
|
+
Object.defineProperty(exports, "getSuiPrice", { enumerable: true, get: function () { return prices_1.getSuiPrice; } });
|
|
22
23
|
Object.defineProperty(exports, "getTokenPrice", { enumerable: true, get: function () { return prices_1.getTokenPrice; } });
|
|
23
24
|
Object.defineProperty(exports, "getTokenPrices", { enumerable: true, get: function () { return prices_1.getTokenPrices; } });
|
|
24
|
-
|
|
25
|
+
const client_1 = require("./libs/protocols/bluefinx/client");
|
|
26
|
+
Object.defineProperty(exports, "executeBluefinTx", { enumerable: true, get: function () { return client_1.executeBluefinTx; } });
|
|
25
27
|
const swap_1 = require("./features/swap");
|
|
26
28
|
Object.defineProperty(exports, "buildTx", { enumerable: true, get: function () { return swap_1.buildTx; } });
|
|
27
|
-
Object.defineProperty(exports, "getQuote", { enumerable: true, get: function () { return swap_1.getQuote; } });
|
|
28
29
|
Object.defineProperty(exports, "estimateGasFee", { enumerable: true, get: function () { return swap_1.estimateGasFee; } });
|
|
30
|
+
Object.defineProperty(exports, "executeTx", { enumerable: true, get: function () { return swap_1.executeTx; } });
|
|
31
|
+
Object.defineProperty(exports, "getQuote", { enumerable: true, get: function () { return swap_1.getQuote; } });
|
|
29
32
|
Object.defineProperty(exports, "getSwapHistory", { enumerable: true, get: function () { return swap_1.getSwapHistory; } });
|
|
33
|
+
Object.defineProperty(exports, "DEFAULT_SOURCES", { enumerable: true, get: function () { return swap_1.DEFAULT_SOURCES; } });
|
|
30
34
|
const limitDca_1 = require("./features/limitDca");
|
|
31
|
-
Object.defineProperty(exports, "
|
|
32
|
-
Object.defineProperty(exports, "getOpenLimitOrders", { enumerable: true, get: function () { return limitDca_1.getOpenLimitOrders; } });
|
|
35
|
+
Object.defineProperty(exports, "cancelDcaOrder", { enumerable: true, get: function () { return limitDca_1.cancelDcaOrder; } });
|
|
33
36
|
Object.defineProperty(exports, "cancelLimitOrder", { enumerable: true, get: function () { return limitDca_1.cancelLimitOrder; } });
|
|
34
37
|
Object.defineProperty(exports, "claimExpiredLimitOrder", { enumerable: true, get: function () { return limitDca_1.claimExpiredLimitOrder; } });
|
|
35
|
-
Object.defineProperty(exports, "getClosedLimitOrders", { enumerable: true, get: function () { return limitDca_1.getClosedLimitOrders; } });
|
|
36
|
-
Object.defineProperty(exports, "placeDcaOrder", { enumerable: true, get: function () { return limitDca_1.placeDcaOrder; } });
|
|
37
|
-
Object.defineProperty(exports, "getOpenDcaOrders", { enumerable: true, get: function () { return limitDca_1.getOpenDcaOrders; } });
|
|
38
|
-
Object.defineProperty(exports, "cancelDcaOrder", { enumerable: true, get: function () { return limitDca_1.cancelDcaOrder; } });
|
|
39
38
|
Object.defineProperty(exports, "getClosedDcaOrders", { enumerable: true, get: function () { return limitDca_1.getClosedDcaOrders; } });
|
|
39
|
+
Object.defineProperty(exports, "getClosedLimitOrders", { enumerable: true, get: function () { return limitDca_1.getClosedLimitOrders; } });
|
|
40
40
|
Object.defineProperty(exports, "getDcaOrderExecutions", { enumerable: true, get: function () { return limitDca_1.getDcaOrderExecutions; } });
|
|
41
|
+
Object.defineProperty(exports, "getOpenDcaOrders", { enumerable: true, get: function () { return limitDca_1.getOpenDcaOrders; } });
|
|
42
|
+
Object.defineProperty(exports, "getOpenLimitOrders", { enumerable: true, get: function () { return limitDca_1.getOpenLimitOrders; } });
|
|
43
|
+
Object.defineProperty(exports, "placeDcaOrder", { enumerable: true, get: function () { return limitDca_1.placeDcaOrder; } });
|
|
44
|
+
Object.defineProperty(exports, "placeLimitOrder", { enumerable: true, get: function () { return limitDca_1.placeLimitOrder; } });
|
|
41
45
|
// avoid breaking changes
|
|
42
46
|
const getSuiClient = config_1.Config.getSuiClient;
|
|
43
47
|
exports.getSuiClient = getSuiClient;
|
|
@@ -58,6 +62,9 @@ exports.default = {
|
|
|
58
62
|
estimateGasFee: swap_1.estimateGasFee,
|
|
59
63
|
buildTx: swap_1.buildTx,
|
|
60
64
|
getSwapHistory: swap_1.getSwapHistory,
|
|
65
|
+
executeTx: swap_1.executeTx,
|
|
66
|
+
executeBluefinTx: client_1.executeBluefinTx,
|
|
67
|
+
DEFAULT_SOURCES: swap_1.DEFAULT_SOURCES,
|
|
61
68
|
// limit order
|
|
62
69
|
placeLimitOrder: limitDca_1.placeLimitOrder,
|
|
63
70
|
getOpenLimitOrders: limitDca_1.getOpenLimitOrders,
|
|
@@ -1,30 +1,18 @@
|
|
|
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.getCoinOjectIdsByAmount = void 0;
|
|
16
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
17
4
|
const config_1 = require("../config");
|
|
18
5
|
const orderByKey = (array, key, sortBy) => {
|
|
19
|
-
if (!
|
|
6
|
+
if (!array?.length) {
|
|
20
7
|
return;
|
|
21
8
|
}
|
|
22
9
|
let swapped;
|
|
23
|
-
const compareFunctionName = sortBy === "desc" ? "isLessThan" : "isGreaterThan";
|
|
24
10
|
do {
|
|
25
11
|
swapped = false;
|
|
26
12
|
for (let i = 0; i < array.length - 1; i++) {
|
|
27
|
-
|
|
13
|
+
const a = BigInt(array[i][key]);
|
|
14
|
+
const b = BigInt(array[i + 1][key]);
|
|
15
|
+
if (sortBy === "desc" ? a < b : a > b) {
|
|
28
16
|
const temp = array[i];
|
|
29
17
|
array[i] = array[i + 1];
|
|
30
18
|
array[i + 1] = temp;
|
|
@@ -34,13 +22,13 @@ const orderByKey = (array, key, sortBy) => {
|
|
|
34
22
|
} while (swapped);
|
|
35
23
|
return array;
|
|
36
24
|
};
|
|
37
|
-
const getCoinOjectIdsByAmount = (address, amount, coinType) =>
|
|
25
|
+
const getCoinOjectIdsByAmount = async (address, amount, coinType) => {
|
|
38
26
|
let coinBalances = [];
|
|
39
27
|
let hasNextPage = true;
|
|
40
28
|
let nextCursor = undefined;
|
|
41
29
|
while (hasNextPage) {
|
|
42
30
|
try {
|
|
43
|
-
const coins =
|
|
31
|
+
const coins = await config_1.Config.getSuiClient().getCoins({
|
|
44
32
|
owner: address,
|
|
45
33
|
coinType,
|
|
46
34
|
cursor: nextCursor,
|
|
@@ -56,19 +44,22 @@ const getCoinOjectIdsByAmount = (address, amount, coinType) => __awaiter(void 0,
|
|
|
56
44
|
}
|
|
57
45
|
// sort coin balance before get object id
|
|
58
46
|
const coinObj = orderByKey(coinBalances.map((item) => {
|
|
59
|
-
return
|
|
60
|
-
|
|
47
|
+
return {
|
|
48
|
+
...item,
|
|
49
|
+
balance: item.balance,
|
|
50
|
+
};
|
|
51
|
+
}), "balance", "desc") ?? [];
|
|
61
52
|
let balance = "0";
|
|
62
53
|
const objectIds = [];
|
|
63
54
|
const objectCoins = [];
|
|
64
|
-
for (const coin of coinObj
|
|
65
|
-
balance =
|
|
55
|
+
for (const coin of coinObj) {
|
|
56
|
+
balance = (BigInt(coin.balance) + BigInt(balance)).toString(10);
|
|
66
57
|
objectIds.push(coin.coinObjectId);
|
|
67
58
|
objectCoins.push(coin);
|
|
68
|
-
if (
|
|
59
|
+
if (BigInt(balance) >= BigInt(amount)) {
|
|
69
60
|
break;
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
return { objectIds, balance, objectCoins };
|
|
73
|
-
}
|
|
64
|
+
};
|
|
74
65
|
exports.getCoinOjectIdsByAmount = getCoinOjectIdsByAmount;
|
|
@@ -1,23 +1,16 @@
|
|
|
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.getSplitCoinForTx = void 0;
|
|
13
4
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
14
|
-
const
|
|
5
|
+
const utils_1 = require("@mysten/sui/utils");
|
|
15
6
|
const tokens_1 = require("../constants/tokens");
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const
|
|
7
|
+
const getCoinOjectIdsByAmount_1 = require("./getCoinOjectIdsByAmount");
|
|
8
|
+
const getSplitCoinForTx = async (account, amount, splits, coinType, inheritTx, inspecTransaction, isSponsored = false) => {
|
|
9
|
+
const tx = inheritTx ?? new transactions_1.Transaction();
|
|
10
|
+
const { objectIds } = await (0, getCoinOjectIdsByAmount_1.getCoinOjectIdsByAmount)(account, amount, coinType);
|
|
19
11
|
const coinObjectId = objectIds[0];
|
|
20
|
-
if (coinType === tokens_1.SUI_TYPE &&
|
|
12
|
+
if ((0, utils_1.normalizeStructTag)(coinType) === (0, utils_1.normalizeStructTag)(tokens_1.SUI_TYPE) &&
|
|
13
|
+
!isSponsored) {
|
|
21
14
|
let coin;
|
|
22
15
|
if (inspecTransaction) {
|
|
23
16
|
if (objectIds.length > 1) {
|
|
@@ -36,5 +29,5 @@ const getSplitCoinForTx = (account_1, amount_1, splits_1, coinType_1, inheritTx_
|
|
|
36
29
|
// split correct amount to swap
|
|
37
30
|
const coinData = tx.splitCoins(tx.object(coinObjectId), splits);
|
|
38
31
|
return { tx, coinData };
|
|
39
|
-
}
|
|
32
|
+
};
|
|
40
33
|
exports.getSplitCoinForTx = getSplitCoinForTx;
|
|
@@ -1,10 +1,6 @@
|
|
|
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.groupSwapRoutes = groupSwapRoutes;
|
|
7
|
-
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
4
|
const token_1 = require("../utils/token");
|
|
9
5
|
function groupSwapRoutes(quoteResponse) {
|
|
10
6
|
if (!quoteResponse.routes || !quoteResponse.swaps) {
|
|
@@ -18,7 +14,7 @@ function groupSwapRoutes(quoteResponse) {
|
|
|
18
14
|
const item = items[i];
|
|
19
15
|
currentGroup.push(item);
|
|
20
16
|
const nextItem = items[i + 1];
|
|
21
|
-
if (!nextItem ||
|
|
17
|
+
if (!nextItem || BigInt(nextItem.amount) > 0n) {
|
|
22
18
|
groupedItems.push(currentGroup);
|
|
23
19
|
currentGroup = [];
|
|
24
20
|
}
|
|
@@ -39,24 +35,26 @@ function mapPoolIdsToDetails(routes) {
|
|
|
39
35
|
}
|
|
40
36
|
function getTxSorSwaps(swaps, poolDetails) {
|
|
41
37
|
return swaps.map((swap) => {
|
|
42
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
43
38
|
const pool = poolDetails[swap.poolId];
|
|
44
39
|
const assetIn = (0, token_1.denormalizeTokenType)(swap.assetIn);
|
|
45
40
|
const assetOut = (0, token_1.denormalizeTokenType)(swap.assetOut);
|
|
46
41
|
const coinX = {
|
|
47
|
-
type: (0, token_1.denormalizeTokenType)(
|
|
48
|
-
decimals:
|
|
42
|
+
type: (0, token_1.denormalizeTokenType)(pool?.allTokens?.[0]?.address),
|
|
43
|
+
decimals: pool?.allTokens?.[0]?.decimal,
|
|
49
44
|
};
|
|
50
45
|
const coinY = {
|
|
51
|
-
type: (0, token_1.denormalizeTokenType)(
|
|
52
|
-
decimals:
|
|
46
|
+
type: (0, token_1.denormalizeTokenType)(pool?.allTokens?.[1]?.address),
|
|
47
|
+
decimals: pool?.allTokens?.[0]?.decimal,
|
|
53
48
|
};
|
|
54
49
|
const swapXtoY = assetIn === coinX.type;
|
|
55
|
-
return
|
|
50
|
+
return {
|
|
51
|
+
...swap,
|
|
52
|
+
pool,
|
|
56
53
|
assetIn,
|
|
57
54
|
assetOut,
|
|
58
55
|
coinX,
|
|
59
56
|
coinY,
|
|
60
|
-
swapXtoY
|
|
57
|
+
swapXtoY,
|
|
58
|
+
};
|
|
61
59
|
});
|
|
62
60
|
}
|
|
@@ -1,46 +1,35 @@
|
|
|
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.AfterMathContract = void 0;
|
|
13
4
|
const base_1 = require("../base");
|
|
14
5
|
const token_1 = require("../../../utils/token");
|
|
15
6
|
class AfterMathContract 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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
],
|
|
41
|
-
});
|
|
42
|
-
return tokenOut;
|
|
7
|
+
async swap(tx) {
|
|
8
|
+
const poolId = this.swapInfo.poolId;
|
|
9
|
+
const returnAmount = this.swapInfo.returnAmount;
|
|
10
|
+
const coinInType = (0, token_1.normalizeTokenType)(this.swapInfo.assetIn);
|
|
11
|
+
const coinOutType = (0, token_1.normalizeTokenType)(this.swapInfo.assetOut);
|
|
12
|
+
const inputCoinObject = this.inputCoinObject;
|
|
13
|
+
const [lpCoinType] = this.getTypeParams();
|
|
14
|
+
if (!lpCoinType)
|
|
15
|
+
throw new Error("lpCoinType is not defined");
|
|
16
|
+
const config = this.config.aftermath;
|
|
17
|
+
const [tokenOut] = tx.moveCall({
|
|
18
|
+
target: `${config.package}::swap::swap_exact_in`,
|
|
19
|
+
typeArguments: [lpCoinType, coinInType, coinOutType],
|
|
20
|
+
arguments: [
|
|
21
|
+
tx.object(poolId),
|
|
22
|
+
tx.object(config.poolRegistry),
|
|
23
|
+
tx.object(config.protocolFeeVault),
|
|
24
|
+
tx.object(config.treasury),
|
|
25
|
+
tx.object(config.insuranceFund),
|
|
26
|
+
tx.object(config.referralVault),
|
|
27
|
+
inputCoinObject,
|
|
28
|
+
tx.pure.u64(returnAmount),
|
|
29
|
+
tx.pure.u64("1000000000000000000"), // slippage
|
|
30
|
+
],
|
|
43
31
|
});
|
|
32
|
+
return tokenOut;
|
|
44
33
|
}
|
|
45
34
|
}
|
|
46
35
|
exports.AfterMathContract = AfterMathContract;
|
|
@@ -4,18 +4,25 @@ exports.BaseContract = void 0;
|
|
|
4
4
|
const utils_1 = require("@mysten/sui/utils");
|
|
5
5
|
const sui_1 = require("../../utils/sui");
|
|
6
6
|
class BaseContract {
|
|
7
|
-
constructor({ swapInfo, inputCoinObject, currentAccount, config, }) {
|
|
7
|
+
constructor({ swapInfo, inputCoinObject, currentAccount, config, pythMap, }) {
|
|
8
8
|
this.swapInfo = swapInfo;
|
|
9
9
|
this.inputCoinObject = inputCoinObject;
|
|
10
10
|
this.currentAccount = currentAccount;
|
|
11
11
|
this.config = config;
|
|
12
|
+
this.pythMap = pythMap;
|
|
12
13
|
}
|
|
13
14
|
getInputCoinValue(tx) {
|
|
14
15
|
return sui_1.SuiUtils.getCoinValue(this.swapInfo.assetIn, this.inputCoinObject, tx);
|
|
15
16
|
}
|
|
16
17
|
getTypeParams() {
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
return (0, utils_1.parseStructTag)(this.swapInfo.extra?.poolStructTag || "").typeParams.map(utils_1.normalizeStructTag);
|
|
19
|
+
}
|
|
20
|
+
get extra() {
|
|
21
|
+
const extra = this.swapInfo.extra;
|
|
22
|
+
if (!extra) {
|
|
23
|
+
throw new Error(`Invalid extra info for getExtra`);
|
|
24
|
+
}
|
|
25
|
+
return extra;
|
|
19
26
|
}
|
|
20
27
|
}
|
|
21
28
|
exports.BaseContract = BaseContract;
|
|
@@ -1,55 +1,38 @@
|
|
|
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.BluefinContract = void 0;
|
|
16
4
|
const base_1 = require("../base");
|
|
17
5
|
const utils_1 = require("@mysten/sui/utils");
|
|
18
6
|
const utils_2 = require("../utils");
|
|
19
|
-
const bn_js_1 = __importDefault(require("bn.js"));
|
|
20
7
|
const sui_1 = require("../../../utils/sui");
|
|
21
8
|
class BluefinContract extends base_1.BaseContract {
|
|
22
|
-
swap(tx) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.add(swapXtoY ? new bn_js_1.default(1) : new bn_js_1.default(-1))
|
|
45
|
-
.toString(10)),
|
|
46
|
-
],
|
|
47
|
-
});
|
|
48
|
-
const coinOutX = sui_1.SuiUtils.coinFromBalance(tx, coinX.address, balanceOutX);
|
|
49
|
-
const coinOutY = sui_1.SuiUtils.coinFromBalance(tx, coinY.address, balanceOutY);
|
|
50
|
-
sui_1.SuiUtils.transferOrDestroyZeroCoin(tx, this.swapInfo.assetIn, swapXtoY ? coinOutX : coinOutY, this.currentAccount);
|
|
51
|
-
return swapXtoY ? coinOutY : coinOutX;
|
|
9
|
+
async swap(tx) {
|
|
10
|
+
const [coinX, coinY] = this.swapInfo.pool.allTokens;
|
|
11
|
+
const swapXtoY = this.swapInfo.swapXtoY;
|
|
12
|
+
const amountIn = this.getInputCoinValue(tx);
|
|
13
|
+
const coinInBalance = sui_1.SuiUtils.coinIntoBalance(tx, this.swapInfo.assetIn, this.inputCoinObject);
|
|
14
|
+
const coinOutBalance = sui_1.SuiUtils.zeroBalance(tx, this.swapInfo.assetOut);
|
|
15
|
+
const config = this.config.bluefin;
|
|
16
|
+
const [balanceOutX, balanceOutY] = tx.moveCall({
|
|
17
|
+
target: `${config.package}::pool::swap`,
|
|
18
|
+
typeArguments: [coinX.address, coinY.address],
|
|
19
|
+
arguments: [
|
|
20
|
+
tx.object(utils_1.SUI_CLOCK_OBJECT_ID),
|
|
21
|
+
tx.object(config.globalConfig),
|
|
22
|
+
tx.object(this.swapInfo.poolId),
|
|
23
|
+
swapXtoY ? coinInBalance : coinOutBalance,
|
|
24
|
+
swapXtoY ? coinOutBalance : coinInBalance,
|
|
25
|
+
tx.pure.bool(swapXtoY),
|
|
26
|
+
tx.pure.bool(true),
|
|
27
|
+
amountIn,
|
|
28
|
+
tx.pure.u64(0),
|
|
29
|
+
tx.pure.u128((0, utils_2.getDefaultSqrtPriceLimit)(swapXtoY) + (swapXtoY ? 1n : -1n)),
|
|
30
|
+
],
|
|
52
31
|
});
|
|
32
|
+
const coinOutX = sui_1.SuiUtils.coinFromBalance(tx, coinX.address, balanceOutX);
|
|
33
|
+
const coinOutY = sui_1.SuiUtils.coinFromBalance(tx, coinY.address, balanceOutY);
|
|
34
|
+
sui_1.SuiUtils.collectDust(tx, this.swapInfo.assetIn, swapXtoY ? coinOutX : coinOutY);
|
|
35
|
+
return swapXtoY ? coinOutY : coinOutX;
|
|
53
36
|
}
|
|
54
37
|
}
|
|
55
38
|
exports.BluefinContract = BluefinContract;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.executeBluefinTx = exports.sponsorBluefinX = void 0;
|
|
4
|
+
const apiEndpoints_1 = require("../../../constants/apiEndpoints");
|
|
5
|
+
const request = async (path, body) => {
|
|
6
|
+
const res = await fetch(`${apiEndpoints_1.API_ENDPOINTS.MAIN}/${path}`, {
|
|
7
|
+
method: "POST",
|
|
8
|
+
body: JSON.stringify(body),
|
|
9
|
+
headers: {
|
|
10
|
+
"Content-Type": "application/json",
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
return res.json();
|
|
14
|
+
};
|
|
15
|
+
const sponsorBluefinX = async (body) => {
|
|
16
|
+
return await request("bluefinx/sponsor", body);
|
|
17
|
+
};
|
|
18
|
+
exports.sponsorBluefinX = sponsorBluefinX;
|
|
19
|
+
/**
|
|
20
|
+
* Request BluefinX for signing sponsored tx and execute it
|
|
21
|
+
*
|
|
22
|
+
* @Warning
|
|
23
|
+
* User must use this function to execute BluefinX tx, otherwise the tx will be rejected by BluefinX contract
|
|
24
|
+
* @param tx - BluefinX tx which is generated by `buildTx`
|
|
25
|
+
* @param signature - user signature after signing the transaction
|
|
26
|
+
* @returns `SwapResponse`
|
|
27
|
+
*/
|
|
28
|
+
const executeBluefinTx = async (tx, signature) => {
|
|
29
|
+
return await request("bluefinx/swap", {
|
|
30
|
+
quoteId: tx.quoteId,
|
|
31
|
+
txBytes: tx.txBytes,
|
|
32
|
+
signature,
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.executeBluefinTx = executeBluefinTx;
|