@cetusprotocol/aggregator-sdk 0.3.8 → 0.3.10
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/dist/index.js +71 -15
- package/dist/{index.cjs → index.mjs} +24 -62
- package/dist/src/math.d.ts +1 -0
- package/package.json +1 -2
- package/src/api.ts +1 -1
- package/src/client.ts +3 -3
- package/src/math.ts +19 -0
- package/tests/router.test.ts +14 -21
- package/test.json +0 -5
- /package/dist/{index.d.cts → index.d.mts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@mysten/sui/client');
|
|
4
|
+
var utils = require('@mysten/sui/utils');
|
|
5
|
+
var transactions = require('@mysten/sui/transactions');
|
|
4
6
|
|
|
5
7
|
var __create = Object.create;
|
|
6
8
|
var __defProp = Object.defineProperty;
|
|
@@ -47,7 +49,7 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
47
49
|
// file that has been converted to a CommonJS file using a Babel-
|
|
48
50
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
49
51
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
50
|
-
__defProp(target, "default", { value: mod2, enumerable: true }) ,
|
|
52
|
+
!mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
51
53
|
mod2
|
|
52
54
|
));
|
|
53
55
|
var __async = (__this, __arguments, generator) => {
|
|
@@ -5388,7 +5390,7 @@ function extractStructTagFromType(type) {
|
|
|
5388
5390
|
const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG;
|
|
5389
5391
|
const structTag = {
|
|
5390
5392
|
full_address: _type,
|
|
5391
|
-
address: isSuiCoin ? "0x2" : normalizeSuiObjectId(parts[0]),
|
|
5393
|
+
address: isSuiCoin ? "0x2" : utils.normalizeSuiObjectId(parts[0]),
|
|
5392
5394
|
module: parts[1],
|
|
5393
5395
|
name: parts[2],
|
|
5394
5396
|
type_arguments: [],
|
|
@@ -5413,7 +5415,7 @@ function normalizeCoinType(coinType) {
|
|
|
5413
5415
|
}
|
|
5414
5416
|
function fixSuiObjectId(value) {
|
|
5415
5417
|
if (value.toLowerCase().startsWith("0x")) {
|
|
5416
|
-
return normalizeSuiObjectId(value);
|
|
5418
|
+
return utils.normalizeSuiObjectId(value);
|
|
5417
5419
|
}
|
|
5418
5420
|
return value;
|
|
5419
5421
|
}
|
|
@@ -5756,6 +5758,15 @@ function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
|
|
|
5756
5758
|
}
|
|
5757
5759
|
return Number(amountLimit.toString());
|
|
5758
5760
|
}
|
|
5761
|
+
function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
|
|
5762
|
+
let amountLimit = ZERO;
|
|
5763
|
+
if (byAmountIn) {
|
|
5764
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE - slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5765
|
+
} else {
|
|
5766
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE + slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5767
|
+
}
|
|
5768
|
+
return amountLimit;
|
|
5769
|
+
}
|
|
5759
5770
|
function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
|
|
5760
5771
|
const sqrtPriceX64 = new decimal_default(sqrtPriceStr).mul(decimal_default.pow(2, -64));
|
|
5761
5772
|
return sqrtPriceX64.pow(2).mul(decimal_default.pow(10, decimalsA - decimalsB));
|
|
@@ -5768,7 +5779,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5768
5779
|
const { from, target, amount, byAmountIn, pools } = params;
|
|
5769
5780
|
const fromCoin = completionCoin(from);
|
|
5770
5781
|
const targetCoin = completionCoin(target);
|
|
5771
|
-
const tx = new Transaction();
|
|
5782
|
+
const tx = new transactions.Transaction();
|
|
5772
5783
|
const direction = compareCoins(fromCoin, targetCoin);
|
|
5773
5784
|
const integratePublishedAt = env === 0 /* Mainnet */ ? "0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10" : "0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293";
|
|
5774
5785
|
const coinA = direction ? fromCoin : targetCoin;
|
|
@@ -6118,9 +6129,9 @@ var SCALLOP = "SCALLOP";
|
|
|
6118
6129
|
var SUILEND = "SUILEND";
|
|
6119
6130
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6120
6131
|
var AggregatorClient8 = class {
|
|
6121
|
-
constructor(endpoint, signer, client, env) {
|
|
6132
|
+
constructor(endpoint, signer, client$1, env) {
|
|
6122
6133
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6123
|
-
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
6134
|
+
this.client = client$1 || new client.SuiClient({ url: client.getFullnodeUrl("mainnet") });
|
|
6124
6135
|
this.signer = signer || "";
|
|
6125
6136
|
this.env = env || 0 /* Mainnet */;
|
|
6126
6137
|
this.allCoins = /* @__PURE__ */ new Map();
|
|
@@ -6238,7 +6249,7 @@ var AggregatorClient8 = class {
|
|
|
6238
6249
|
if (targetCoins.length > 1) {
|
|
6239
6250
|
const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
|
|
6240
6251
|
txb.moveCall({
|
|
6241
|
-
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6252
|
+
target: `${utils.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6242
6253
|
typeArguments: [routers[0].path[routers[0].path.length - 1].target],
|
|
6243
6254
|
arguments: [targetCoins[0], vec]
|
|
6244
6255
|
});
|
|
@@ -6277,7 +6288,7 @@ var AggregatorClient8 = class {
|
|
|
6277
6288
|
(acc, router) => acc.add(router.amountOut),
|
|
6278
6289
|
new import_bn5.default(0)
|
|
6279
6290
|
);
|
|
6280
|
-
const amountLimit =
|
|
6291
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
6281
6292
|
byAmountIn ? amountOut : amountIn,
|
|
6282
6293
|
byAmountIn,
|
|
6283
6294
|
slippage
|
|
@@ -6287,7 +6298,7 @@ var AggregatorClient8 = class {
|
|
|
6287
6298
|
txb,
|
|
6288
6299
|
inputCoin,
|
|
6289
6300
|
routers,
|
|
6290
|
-
|
|
6301
|
+
amountLimit,
|
|
6291
6302
|
partner,
|
|
6292
6303
|
deepbookv3DeepFee
|
|
6293
6304
|
);
|
|
@@ -6418,7 +6429,7 @@ var AggregatorClient8 = class {
|
|
|
6418
6429
|
if (coins.length > 1) {
|
|
6419
6430
|
let vec = txb.makeMoveVec({ elements: coins.slice(1) });
|
|
6420
6431
|
txb.moveCall({
|
|
6421
|
-
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6432
|
+
target: `${utils.SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6422
6433
|
typeArguments: [coinType],
|
|
6423
6434
|
arguments: [coins[0], vec]
|
|
6424
6435
|
});
|
|
@@ -6680,7 +6691,7 @@ function getRouter(endpoint, params) {
|
|
|
6680
6691
|
url += `&providers=${providers.join(",")}`;
|
|
6681
6692
|
}
|
|
6682
6693
|
}
|
|
6683
|
-
url += "&v=
|
|
6694
|
+
url += "&v=1000309";
|
|
6684
6695
|
const response = yield fetch(url);
|
|
6685
6696
|
return response;
|
|
6686
6697
|
} catch (error) {
|
|
@@ -6770,4 +6781,49 @@ decimal.js/decimal.mjs:
|
|
|
6770
6781
|
*)
|
|
6771
6782
|
*/
|
|
6772
6783
|
|
|
6773
|
-
|
|
6784
|
+
exports.AFSUI = AFSUI;
|
|
6785
|
+
exports.AFTERMATH = AFTERMATH;
|
|
6786
|
+
exports.AggregatorClient = AggregatorClient8;
|
|
6787
|
+
exports.BLUEMOVE = BLUEMOVE;
|
|
6788
|
+
exports.CETUS = CETUS;
|
|
6789
|
+
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
6790
|
+
exports.DEEPBOOKV2 = DEEPBOOKV2;
|
|
6791
|
+
exports.DEEPBOOKV3 = DEEPBOOKV3;
|
|
6792
|
+
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
6793
|
+
exports.Env = Env;
|
|
6794
|
+
exports.FLOWXV2 = FLOWXV2;
|
|
6795
|
+
exports.FLOWXV3 = FLOWXV3;
|
|
6796
|
+
exports.HAEDAL = HAEDAL;
|
|
6797
|
+
exports.KRIYA = KRIYA;
|
|
6798
|
+
exports.KRIYAV3 = KRIYAV3;
|
|
6799
|
+
exports.ONE = ONE;
|
|
6800
|
+
exports.SCALLOP = SCALLOP;
|
|
6801
|
+
exports.SUILEND = SUILEND;
|
|
6802
|
+
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
6803
|
+
exports.TURBOS = TURBOS;
|
|
6804
|
+
exports.TWO = TWO;
|
|
6805
|
+
exports.U128 = U128;
|
|
6806
|
+
exports.U64_MAX = U64_MAX;
|
|
6807
|
+
exports.U64_MAX_BN = U64_MAX_BN;
|
|
6808
|
+
exports.VOLO = VOLO;
|
|
6809
|
+
exports.ZERO = ZERO;
|
|
6810
|
+
exports.buildInputCoin = buildInputCoin;
|
|
6811
|
+
exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
|
|
6812
|
+
exports.compareCoins = compareCoins;
|
|
6813
|
+
exports.completionCoin = completionCoin;
|
|
6814
|
+
exports.composeType = composeType;
|
|
6815
|
+
exports.createTarget = createTarget;
|
|
6816
|
+
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
6817
|
+
exports.extractAddressFromType = extractAddressFromType;
|
|
6818
|
+
exports.extractStructTagFromType = extractStructTagFromType;
|
|
6819
|
+
exports.fixSuiObjectId = fixSuiObjectId;
|
|
6820
|
+
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
6821
|
+
exports.getRouterResult = getRouterResult;
|
|
6822
|
+
exports.isSortedSymbols = isSortedSymbols;
|
|
6823
|
+
exports.mintZeroCoin = mintZeroCoin;
|
|
6824
|
+
exports.normalizeCoinType = normalizeCoinType;
|
|
6825
|
+
exports.parseRouterResponse = parseRouterResponse;
|
|
6826
|
+
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
6827
|
+
exports.printTransaction = printTransaction;
|
|
6828
|
+
exports.processEndpoint = processEndpoint;
|
|
6829
|
+
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var utils = require('@mysten/sui/utils');
|
|
5
|
-
var transactions = require('@mysten/sui/transactions');
|
|
1
|
+
import { SuiClient, getFullnodeUrl } from '@mysten/sui/client';
|
|
2
|
+
import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
|
|
3
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
6
4
|
|
|
7
5
|
var __create = Object.create;
|
|
8
6
|
var __defProp = Object.defineProperty;
|
|
@@ -49,7 +47,7 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
|
49
47
|
// file that has been converted to a CommonJS file using a Babel-
|
|
50
48
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
51
49
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
52
|
-
__defProp(target, "default", { value: mod2, enumerable: true }) ,
|
|
50
|
+
!mod2 || !mod2.__esModule ? __defProp(target, "default", { value: mod2, enumerable: true }) : target,
|
|
53
51
|
mod2
|
|
54
52
|
));
|
|
55
53
|
var __async = (__this, __arguments, generator) => {
|
|
@@ -5390,7 +5388,7 @@ function extractStructTagFromType(type) {
|
|
|
5390
5388
|
const isSuiCoin = _type === GAS_TYPE_ARG || _type === GAS_TYPE_ARG_LONG;
|
|
5391
5389
|
const structTag = {
|
|
5392
5390
|
full_address: _type,
|
|
5393
|
-
address: isSuiCoin ? "0x2" :
|
|
5391
|
+
address: isSuiCoin ? "0x2" : normalizeSuiObjectId(parts[0]),
|
|
5394
5392
|
module: parts[1],
|
|
5395
5393
|
name: parts[2],
|
|
5396
5394
|
type_arguments: [],
|
|
@@ -5415,7 +5413,7 @@ function normalizeCoinType(coinType) {
|
|
|
5415
5413
|
}
|
|
5416
5414
|
function fixSuiObjectId(value) {
|
|
5417
5415
|
if (value.toLowerCase().startsWith("0x")) {
|
|
5418
|
-
return
|
|
5416
|
+
return normalizeSuiObjectId(value);
|
|
5419
5417
|
}
|
|
5420
5418
|
return value;
|
|
5421
5419
|
}
|
|
@@ -5758,6 +5756,15 @@ function CalculateAmountLimit(expectAmount, byAmountIn, slippage) {
|
|
|
5758
5756
|
}
|
|
5759
5757
|
return Number(amountLimit.toString());
|
|
5760
5758
|
}
|
|
5759
|
+
function CalculateAmountLimitBN(expectAmount, byAmountIn, slippage) {
|
|
5760
|
+
let amountLimit = ZERO;
|
|
5761
|
+
if (byAmountIn) {
|
|
5762
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE - slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5763
|
+
} else {
|
|
5764
|
+
amountLimit = expectAmount.mul(new import_bn3.default(TEN_POW_NINE + slippage * TEN_POW_NINE)).div(new import_bn3.default(TEN_POW_NINE));
|
|
5765
|
+
}
|
|
5766
|
+
return amountLimit;
|
|
5767
|
+
}
|
|
5761
5768
|
function sqrtPriceX64ToPrice(sqrtPriceStr, decimalsA, decimalsB) {
|
|
5762
5769
|
const sqrtPriceX64 = new decimal_default(sqrtPriceStr).mul(decimal_default.pow(2, -64));
|
|
5763
5770
|
return sqrtPriceX64.pow(2).mul(decimal_default.pow(10, decimalsA - decimalsB));
|
|
@@ -5770,7 +5777,7 @@ function swapInPools(client, params, sender, env) {
|
|
|
5770
5777
|
const { from, target, amount, byAmountIn, pools } = params;
|
|
5771
5778
|
const fromCoin = completionCoin(from);
|
|
5772
5779
|
const targetCoin = completionCoin(target);
|
|
5773
|
-
const tx = new
|
|
5780
|
+
const tx = new Transaction();
|
|
5774
5781
|
const direction = compareCoins(fromCoin, targetCoin);
|
|
5775
5782
|
const integratePublishedAt = env === 0 /* Mainnet */ ? "0x3a5aa90ffa33d09100d7b6941ea1c0ffe6ab66e77062ddd26320c1b073aabb10" : "0x19dd42e05fa6c9988a60d30686ee3feb776672b5547e328d6dab16563da65293";
|
|
5776
5783
|
const coinA = direction ? fromCoin : targetCoin;
|
|
@@ -6120,9 +6127,9 @@ var SCALLOP = "SCALLOP";
|
|
|
6120
6127
|
var SUILEND = "SUILEND";
|
|
6121
6128
|
var DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
|
|
6122
6129
|
var AggregatorClient8 = class {
|
|
6123
|
-
constructor(endpoint, signer, client
|
|
6130
|
+
constructor(endpoint, signer, client, env) {
|
|
6124
6131
|
this.endpoint = endpoint ? processEndpoint(endpoint) : DEFAULT_ENDPOINT;
|
|
6125
|
-
this.client = client
|
|
6132
|
+
this.client = client || new SuiClient({ url: getFullnodeUrl("mainnet") });
|
|
6126
6133
|
this.signer = signer || "";
|
|
6127
6134
|
this.env = env || 0 /* Mainnet */;
|
|
6128
6135
|
this.allCoins = /* @__PURE__ */ new Map();
|
|
@@ -6240,7 +6247,7 @@ var AggregatorClient8 = class {
|
|
|
6240
6247
|
if (targetCoins.length > 1) {
|
|
6241
6248
|
const vec = txb.makeMoveVec({ elements: targetCoins.slice(1) });
|
|
6242
6249
|
txb.moveCall({
|
|
6243
|
-
target: `${
|
|
6250
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6244
6251
|
typeArguments: [routers[0].path[routers[0].path.length - 1].target],
|
|
6245
6252
|
arguments: [targetCoins[0], vec]
|
|
6246
6253
|
});
|
|
@@ -6279,7 +6286,7 @@ var AggregatorClient8 = class {
|
|
|
6279
6286
|
(acc, router) => acc.add(router.amountOut),
|
|
6280
6287
|
new import_bn5.default(0)
|
|
6281
6288
|
);
|
|
6282
|
-
const amountLimit =
|
|
6289
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
6283
6290
|
byAmountIn ? amountOut : amountIn,
|
|
6284
6291
|
byAmountIn,
|
|
6285
6292
|
slippage
|
|
@@ -6289,7 +6296,7 @@ var AggregatorClient8 = class {
|
|
|
6289
6296
|
txb,
|
|
6290
6297
|
inputCoin,
|
|
6291
6298
|
routers,
|
|
6292
|
-
|
|
6299
|
+
amountLimit,
|
|
6293
6300
|
partner,
|
|
6294
6301
|
deepbookv3DeepFee
|
|
6295
6302
|
);
|
|
@@ -6420,7 +6427,7 @@ var AggregatorClient8 = class {
|
|
|
6420
6427
|
if (coins.length > 1) {
|
|
6421
6428
|
let vec = txb.makeMoveVec({ elements: coins.slice(1) });
|
|
6422
6429
|
txb.moveCall({
|
|
6423
|
-
target: `${
|
|
6430
|
+
target: `${SUI_FRAMEWORK_ADDRESS}::pay::join_vec`,
|
|
6424
6431
|
typeArguments: [coinType],
|
|
6425
6432
|
arguments: [coins[0], vec]
|
|
6426
6433
|
});
|
|
@@ -6682,7 +6689,7 @@ function getRouter(endpoint, params) {
|
|
|
6682
6689
|
url += `&providers=${providers.join(",")}`;
|
|
6683
6690
|
}
|
|
6684
6691
|
}
|
|
6685
|
-
url += "&v=
|
|
6692
|
+
url += "&v=1000309";
|
|
6686
6693
|
const response = yield fetch(url);
|
|
6687
6694
|
return response;
|
|
6688
6695
|
} catch (error) {
|
|
@@ -6772,49 +6779,4 @@ decimal.js/decimal.mjs:
|
|
|
6772
6779
|
*)
|
|
6773
6780
|
*/
|
|
6774
6781
|
|
|
6775
|
-
|
|
6776
|
-
exports.AFTERMATH = AFTERMATH;
|
|
6777
|
-
exports.AggregatorClient = AggregatorClient8;
|
|
6778
|
-
exports.BLUEMOVE = BLUEMOVE;
|
|
6779
|
-
exports.CETUS = CETUS;
|
|
6780
|
-
exports.CLOCK_ADDRESS = CLOCK_ADDRESS;
|
|
6781
|
-
exports.DEEPBOOKV2 = DEEPBOOKV2;
|
|
6782
|
-
exports.DEEPBOOKV3 = DEEPBOOKV3;
|
|
6783
|
-
exports.DEFAULT_ENDPOINT = DEFAULT_ENDPOINT;
|
|
6784
|
-
exports.Env = Env;
|
|
6785
|
-
exports.FLOWXV2 = FLOWXV2;
|
|
6786
|
-
exports.FLOWXV3 = FLOWXV3;
|
|
6787
|
-
exports.HAEDAL = HAEDAL;
|
|
6788
|
-
exports.KRIYA = KRIYA;
|
|
6789
|
-
exports.KRIYAV3 = KRIYAV3;
|
|
6790
|
-
exports.ONE = ONE;
|
|
6791
|
-
exports.SCALLOP = SCALLOP;
|
|
6792
|
-
exports.SUILEND = SUILEND;
|
|
6793
|
-
exports.TEN_POW_NINE = TEN_POW_NINE;
|
|
6794
|
-
exports.TURBOS = TURBOS;
|
|
6795
|
-
exports.TWO = TWO;
|
|
6796
|
-
exports.U128 = U128;
|
|
6797
|
-
exports.U64_MAX = U64_MAX;
|
|
6798
|
-
exports.U64_MAX_BN = U64_MAX_BN;
|
|
6799
|
-
exports.VOLO = VOLO;
|
|
6800
|
-
exports.ZERO = ZERO;
|
|
6801
|
-
exports.buildInputCoin = buildInputCoin;
|
|
6802
|
-
exports.checkInvalidSuiAddress = checkInvalidSuiAddress;
|
|
6803
|
-
exports.compareCoins = compareCoins;
|
|
6804
|
-
exports.completionCoin = completionCoin;
|
|
6805
|
-
exports.composeType = composeType;
|
|
6806
|
-
exports.createTarget = createTarget;
|
|
6807
|
-
exports.dealWithFastRouterSwapParamsForMsafe = dealWithFastRouterSwapParamsForMsafe;
|
|
6808
|
-
exports.extractAddressFromType = extractAddressFromType;
|
|
6809
|
-
exports.extractStructTagFromType = extractStructTagFromType;
|
|
6810
|
-
exports.fixSuiObjectId = fixSuiObjectId;
|
|
6811
|
-
exports.getDeepbookV3Config = getDeepbookV3Config;
|
|
6812
|
-
exports.getRouterResult = getRouterResult;
|
|
6813
|
-
exports.isSortedSymbols = isSortedSymbols;
|
|
6814
|
-
exports.mintZeroCoin = mintZeroCoin;
|
|
6815
|
-
exports.normalizeCoinType = normalizeCoinType;
|
|
6816
|
-
exports.parseRouterResponse = parseRouterResponse;
|
|
6817
|
-
exports.patchFixSuiObjectId = patchFixSuiObjectId;
|
|
6818
|
-
exports.printTransaction = printTransaction;
|
|
6819
|
-
exports.processEndpoint = processEndpoint;
|
|
6820
|
-
exports.restituteMsafeFastRouterSwapParams = restituteMsafeFastRouterSwapParams;
|
|
6782
|
+
export { AFSUI, AFTERMATH, AggregatorClient8 as AggregatorClient, BLUEMOVE, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, Env, FLOWXV2, FLOWXV3, HAEDAL, KRIYA, KRIYAV3, ONE, SCALLOP, SUILEND, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
|
package/dist/src/math.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import BN from "bn.js";
|
|
2
2
|
import Decimal from "decimal.js";
|
|
3
3
|
export declare function CalculateAmountLimit(expectAmount: BN, byAmountIn: boolean, slippage: number): number;
|
|
4
|
+
export declare function CalculateAmountLimitBN(expectAmount: BN, byAmountIn: boolean, slippage: number): BN;
|
|
4
5
|
export declare function GetDefaultSqrtPriceLimit(a2b: boolean): BN;
|
|
5
6
|
export declare function sqrtPriceX64ToPrice(sqrtPriceStr: string, decimalsA: number, decimalsB: number): Decimal;
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
package/src/client.ts
CHANGED
|
@@ -28,7 +28,7 @@ import { FlowxV3 } from "./transaction/flowx_v3"
|
|
|
28
28
|
import { Turbos } from "./transaction/turbos"
|
|
29
29
|
import { Cetus } from "./transaction/cetus"
|
|
30
30
|
import { swapInPools } from "./transaction/swap"
|
|
31
|
-
import { CalculateAmountLimit } from "./math"
|
|
31
|
+
import { CalculateAmountLimit, CalculateAmountLimitBN } from "./math"
|
|
32
32
|
import { Haedal } from "./transaction/haedal"
|
|
33
33
|
import { Afsui } from "./transaction/afsui"
|
|
34
34
|
import { Volo } from "./transaction/volo"
|
|
@@ -284,7 +284,7 @@ export class AggregatorClient {
|
|
|
284
284
|
(acc, router) => acc.add(router.amountOut),
|
|
285
285
|
new BN(0)
|
|
286
286
|
)
|
|
287
|
-
const amountLimit =
|
|
287
|
+
const amountLimit = CalculateAmountLimitBN(
|
|
288
288
|
byAmountIn ? amountOut : amountIn,
|
|
289
289
|
byAmountIn,
|
|
290
290
|
slippage
|
|
@@ -295,7 +295,7 @@ export class AggregatorClient {
|
|
|
295
295
|
txb,
|
|
296
296
|
inputCoin,
|
|
297
297
|
routers,
|
|
298
|
-
|
|
298
|
+
amountLimit,
|
|
299
299
|
partner,
|
|
300
300
|
deepbookv3DeepFee
|
|
301
301
|
)
|
package/src/math.ts
CHANGED
|
@@ -26,6 +26,25 @@ export function CalculateAmountLimit(
|
|
|
26
26
|
return Number(amountLimit.toString())
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
export function CalculateAmountLimitBN(
|
|
30
|
+
expectAmount: BN,
|
|
31
|
+
byAmountIn: boolean,
|
|
32
|
+
slippage: number
|
|
33
|
+
): BN {
|
|
34
|
+
let amountLimit = ZERO
|
|
35
|
+
if (byAmountIn) {
|
|
36
|
+
amountLimit = expectAmount
|
|
37
|
+
.mul(new BN(TEN_POW_NINE - slippage * TEN_POW_NINE))
|
|
38
|
+
.div(new BN(TEN_POW_NINE))
|
|
39
|
+
} else {
|
|
40
|
+
amountLimit = expectAmount
|
|
41
|
+
.mul(new BN(TEN_POW_NINE + slippage * TEN_POW_NINE))
|
|
42
|
+
.div(new BN(TEN_POW_NINE))
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return amountLimit
|
|
46
|
+
}
|
|
47
|
+
|
|
29
48
|
const MAX_SQER_PRICE_X64 = "79226673515401279992447579055"
|
|
30
49
|
const MIN_SQER_PRICE_X64 = "4295048016"
|
|
31
50
|
|
package/tests/router.test.ts
CHANGED
|
@@ -112,9 +112,9 @@ describe("router module", () => {
|
|
|
112
112
|
|
|
113
113
|
test("Build router tx", async () => {
|
|
114
114
|
const byAmountIn = true
|
|
115
|
-
const amount = "
|
|
115
|
+
const amount = "400000000000"
|
|
116
116
|
const from = "0x2::sui::SUI"
|
|
117
|
-
const target = "
|
|
117
|
+
const target = "0xaf3aae4940a248739ce4964857381fc3f3149a6d05375bfbb2118592907e3bbb::dam::DAM"
|
|
118
118
|
|
|
119
119
|
const res = await client.findRouters({
|
|
120
120
|
from,
|
|
@@ -122,17 +122,6 @@ describe("router module", () => {
|
|
|
122
122
|
amount: new BN(amount),
|
|
123
123
|
byAmountIn,
|
|
124
124
|
depth: 3,
|
|
125
|
-
providers: [
|
|
126
|
-
"SUILEND",
|
|
127
|
-
// "CETUS",
|
|
128
|
-
// "DEEPBOOKV3",
|
|
129
|
-
// "DEEPBOOK",
|
|
130
|
-
// "AFTERMATH",
|
|
131
|
-
// "FLOWX",
|
|
132
|
-
// "KRIYA",
|
|
133
|
-
// "KRIYAV3",
|
|
134
|
-
// "TURBOS",
|
|
135
|
-
],
|
|
136
125
|
})
|
|
137
126
|
|
|
138
127
|
if (res != null) {
|
|
@@ -152,7 +141,7 @@ describe("router module", () => {
|
|
|
152
141
|
txb,
|
|
153
142
|
slippage: 0.01,
|
|
154
143
|
isMergeTragetCoin: false,
|
|
155
|
-
partner: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5",
|
|
144
|
+
// partner: "0x1f5fa5c820f40d43fc47815ad06d95e40a1942ff72a732a92e8ef4aa8cde70a5",
|
|
156
145
|
refreshAllCoins: true,
|
|
157
146
|
payDeepFeeAmount: 0,
|
|
158
147
|
})
|
|
@@ -161,14 +150,18 @@ describe("router module", () => {
|
|
|
161
150
|
|
|
162
151
|
let result = await client.devInspectTransactionBlock(txb)
|
|
163
152
|
console.log("🚀 ~ file: router.test.ts:180 ~ test ~ result:", result)
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
// console.log("Sim exec transaction success")
|
|
167
|
-
const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
168
|
-
console.log("result", result)
|
|
169
|
-
} else {
|
|
170
|
-
console.log("result", result)
|
|
153
|
+
for (const event of result.events) {
|
|
154
|
+
console.log("event", JSON.stringify(event, null, 2))
|
|
171
155
|
}
|
|
156
|
+
console.log("txb", )
|
|
157
|
+
|
|
158
|
+
// if (result.effects.status.status === "success") {
|
|
159
|
+
// // console.log("Sim exec transaction success")
|
|
160
|
+
// const result = await client.signAndExecuteTransaction(txb, keypair)
|
|
161
|
+
// console.log("result", result)
|
|
162
|
+
// } else {
|
|
163
|
+
// console.log("result", result)
|
|
164
|
+
// }
|
|
172
165
|
}
|
|
173
166
|
}, 600000)
|
|
174
167
|
|
package/test.json
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
[Path { id: "0x0d1b1746d220bd5ebac5231c7685480a16f1c707a46306095a4c67dc7ce4dcae", edge_id: "0x0d1b1746d220bd5ebac5231c7685480a16f1c707a46306095a4c67dc7ce4dcae", provider: "DEEPBOOKV3", from: "0x36dbef866a1d62bf7328989a10fb2f07d769f4ee587c0de4a0a256e57e0a58a8::deep::DEEP", target: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI", direction: true, fee_rate: Decimal(0), lot_size: 1000000, amount_in: 0, amount_out: 0, max_depth: 3, extended_details: None, allow_bidirection: true
|
|
3
|
-
}
|
|
4
|
-
]
|
|
5
|
-
]
|
|
File without changes
|