@cetusprotocol/aggregator-sdk 0.0.6 → 0.0.8
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.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +45 -13
- package/dist/index.mjs +45 -13
- package/dist/src/client.d.ts +5 -0
- package/dist/src/errors.d.ts +8 -1
- package/dist/src/transaction/turbos.d.ts +1 -1
- package/package.json +1 -1
- package/src/client.ts +38 -10
- package/src/errors.ts +28 -1
- package/src/transaction/common.ts +1 -1
- package/src/transaction/router.ts +2 -4
- package/src/transaction/swap.ts +1 -8
- package/src/transaction/turbos.ts +1 -1
- package/tests/router.test.ts +14 -16
package/dist/index.d.mts
CHANGED
|
@@ -110,11 +110,16 @@ type Router = {
|
|
|
110
110
|
amountOut: BN;
|
|
111
111
|
initialPrice: Decimal;
|
|
112
112
|
};
|
|
113
|
+
type RouterError = {
|
|
114
|
+
code: number;
|
|
115
|
+
msg: string;
|
|
116
|
+
};
|
|
113
117
|
type RouterData = {
|
|
114
118
|
amountIn: BN;
|
|
115
119
|
amountOut: BN;
|
|
116
120
|
routes: Router[];
|
|
117
121
|
insufficientLiquidity: boolean;
|
|
122
|
+
error?: RouterError;
|
|
118
123
|
};
|
|
119
124
|
type AggregatorResponse = {
|
|
120
125
|
code: number;
|
|
@@ -266,4 +271,4 @@ declare const TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
|
|
|
266
271
|
declare const MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
267
272
|
declare const TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
|
|
268
273
|
|
|
269
|
-
export { AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AggregatorClient, AggregatorConfig, type AggregatorResponse, type BuildRouterSwapParams, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, ENV, type ExtendedDetails, FLOWX_AMM, FLOWX_AMM_MODULE, type FindRouterParams, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, INTEGRATE, JOIN_FUNC, KRIYA_DEX, KRIYA_MODULE, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, ONE, PAY_MODULE, POOL_MODULT, type Package, type Path, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, type Router, type RouterData, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, ZERO, composeType, createTarget, expectInputRouterSwap, expectOutputRouterSwap, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
|
274
|
+
export { AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AggregatorClient, AggregatorConfig, type AggregatorResponse, type BuildRouterSwapParams, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, ENV, type ExtendedDetails, FLOWX_AMM, FLOWX_AMM_MODULE, type FindRouterParams, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, INTEGRATE, JOIN_FUNC, KRIYA_DEX, KRIYA_MODULE, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, ONE, PAY_MODULE, POOL_MODULT, type Package, type Path, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, type Router, type RouterData, type RouterError, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, ZERO, composeType, createTarget, expectInputRouterSwap, expectOutputRouterSwap, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
package/dist/index.d.ts
CHANGED
|
@@ -110,11 +110,16 @@ type Router = {
|
|
|
110
110
|
amountOut: BN;
|
|
111
111
|
initialPrice: Decimal;
|
|
112
112
|
};
|
|
113
|
+
type RouterError = {
|
|
114
|
+
code: number;
|
|
115
|
+
msg: string;
|
|
116
|
+
};
|
|
113
117
|
type RouterData = {
|
|
114
118
|
amountIn: BN;
|
|
115
119
|
amountOut: BN;
|
|
116
120
|
routes: Router[];
|
|
117
121
|
insufficientLiquidity: boolean;
|
|
122
|
+
error?: RouterError;
|
|
118
123
|
};
|
|
119
124
|
type AggregatorResponse = {
|
|
120
125
|
code: number;
|
|
@@ -266,4 +271,4 @@ declare const TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
|
|
|
266
271
|
declare const MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
267
272
|
declare const TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
|
|
268
273
|
|
|
269
|
-
export { AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AggregatorClient, AggregatorConfig, type AggregatorResponse, type BuildRouterSwapParams, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, ENV, type ExtendedDetails, FLOWX_AMM, FLOWX_AMM_MODULE, type FindRouterParams, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, INTEGRATE, JOIN_FUNC, KRIYA_DEX, KRIYA_MODULE, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, ONE, PAY_MODULE, POOL_MODULT, type Package, type Path, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, type Router, type RouterData, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, ZERO, composeType, createTarget, expectInputRouterSwap, expectOutputRouterSwap, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
|
274
|
+
export { AFTERMATH_AMM, AFTERMATH_MODULE, AGGREGATOR, AggregatorClient, AggregatorConfig, type AggregatorResponse, type BuildRouterSwapParams, CETUS_DEX, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_DEX, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, ENV, type ExtendedDetails, FLOWX_AMM, FLOWX_AMM_MODULE, type FindRouterParams, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, INTEGRATE, JOIN_FUNC, KRIYA_DEX, KRIYA_MODULE, MAINNET_AFTERMATH_INSURANCE_FUND_ID, MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, MAINNET_AFTERMATH_REFERRAL_VAULT_ID, MAINNET_AFTERMATH_REGISTRY_ID, MAINNET_AFTERMATH_TREASURY_ID, MAINNET_CETUS_GLOBAL_CONFIG_ID, MAINNET_FLOWX_AMM_CONTAINER_ID, ONE, PAY_MODULE, POOL_MODULT, type Package, type Path, REPAY_FLASH_SWAP_A2B_FUNC, REPAY_FLASH_SWAP_B2A_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC, REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC, RepayFalshSwapFunc, RepayFlashSwapWithPartnerFunc, type Router, type RouterData, type RouterError, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TESTNET_AFTERMATH_INSURANCE_FUND_ID, TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID, TESTNET_AFTERMATH_REFERRAL_VAULT_ID, TESTNET_AFTERMATH_REGISTRY_ID, TESTNET_AFTERMATH_TREASURY_ID, TESTNET_CETUS_GLOBAL_CONFIG_ID, TESTNET_FLOWX_AMM_CONTAINER_ID, TRANSFER_ACCOUNT_CAP, TRANSFER_OR_DESTORY_COIN_FUNC, TURBOS_DEX, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, ZERO, composeType, createTarget, expectInputRouterSwap, expectOutputRouterSwap, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
package/dist/index.js
CHANGED
|
@@ -5332,6 +5332,22 @@ var MAINNET_AFTERMATH_INSURANCE_FUND_ID = "0xf0c40d67b078000e18032334c3325c47b9e
|
|
|
5332
5332
|
var TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
|
|
5333
5333
|
var MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
5334
5334
|
var TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
|
|
5335
|
+
|
|
5336
|
+
// src/errors.ts
|
|
5337
|
+
function getAggregatorServerErrorMessage(code) {
|
|
5338
|
+
switch (code) {
|
|
5339
|
+
case 1e4 /* CalculateError */:
|
|
5340
|
+
return "Calculate error";
|
|
5341
|
+
case 10001 /* NumberTooLarge */:
|
|
5342
|
+
return "Input number too large can not fit in target type";
|
|
5343
|
+
case 10002 /* NoRouter */:
|
|
5344
|
+
return "No router";
|
|
5345
|
+
case 10003 /* InsufficientLiquidity */:
|
|
5346
|
+
return "Insufficient Liquidity";
|
|
5347
|
+
default:
|
|
5348
|
+
return "Unknown error";
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5335
5351
|
function mintZeroCoin(txb, coinType) {
|
|
5336
5352
|
return txb.moveCall({
|
|
5337
5353
|
target: SuiZeroCoinFn,
|
|
@@ -5355,7 +5371,7 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5355
5371
|
"InsufficientBalance" /* InsufficientBalance */
|
|
5356
5372
|
);
|
|
5357
5373
|
}
|
|
5358
|
-
if (CoinUtils.isSuiCoin(coinType)
|
|
5374
|
+
if (CoinUtils.isSuiCoin(coinType)) {
|
|
5359
5375
|
const resultCoin = txb.splitCoins(txb.gas, [
|
|
5360
5376
|
txb.pure.u64(amount.toString())
|
|
5361
5377
|
]);
|
|
@@ -5914,7 +5930,7 @@ function flowxAmmSwapMovecall(swapParams, txb, config2) {
|
|
|
5914
5930
|
}
|
|
5915
5931
|
|
|
5916
5932
|
// src/transaction/turbos.ts
|
|
5917
|
-
function
|
|
5933
|
+
function turbosClmmSwapMovecall(swapParams, txb, config2) {
|
|
5918
5934
|
return __async(this, null, function* () {
|
|
5919
5935
|
const aggregatorPackage = config2.getPackage(AGGREGATOR);
|
|
5920
5936
|
if (aggregatorPackage == null) {
|
|
@@ -6074,7 +6090,6 @@ function expectInputRouterSwap(client, params, txb, fromCoin, config2, partner)
|
|
|
6074
6090
|
coinAType: path.a2b ? path.from : path.target,
|
|
6075
6091
|
coinBType: path.a2b ? path.target : path.from
|
|
6076
6092
|
};
|
|
6077
|
-
firstPathPool && router.path.length > 1;
|
|
6078
6093
|
const swapResult = yield cetusSwapWithOutLimit(
|
|
6079
6094
|
swapParams,
|
|
6080
6095
|
nextFromCoin,
|
|
@@ -6179,7 +6194,7 @@ function expectInputRouterSwap(client, params, txb, fromCoin, config2, partner)
|
|
|
6179
6194
|
coinBType: path.a2b ? path.target : path.from,
|
|
6180
6195
|
feeType
|
|
6181
6196
|
};
|
|
6182
|
-
const swapResult = yield
|
|
6197
|
+
const swapResult = yield turbosClmmSwapMovecall(swapParams, txb, config2);
|
|
6183
6198
|
intermediateTargetCoin = swapResult.targetCoin;
|
|
6184
6199
|
nextFromCoin = intermediateTargetCoin;
|
|
6185
6200
|
nextFlashAmount = swapResult.amountOut;
|
|
@@ -6537,20 +6552,38 @@ var AggregatorClient = class {
|
|
|
6537
6552
|
}
|
|
6538
6553
|
}
|
|
6539
6554
|
const response = yield fetch(url);
|
|
6540
|
-
|
|
6541
|
-
if (data.data != null) {
|
|
6542
|
-
const res = parseRouterResponse(data.data);
|
|
6543
|
-
return res;
|
|
6544
|
-
}
|
|
6545
|
-
if (data.msg === "liquidity is not enough") {
|
|
6555
|
+
if (!response.ok) {
|
|
6546
6556
|
return {
|
|
6547
6557
|
amountIn: ZERO,
|
|
6548
6558
|
amountOut: ZERO,
|
|
6549
6559
|
routes: [],
|
|
6550
|
-
insufficientLiquidity:
|
|
6560
|
+
insufficientLiquidity: false,
|
|
6561
|
+
error: {
|
|
6562
|
+
code: 10001 /* NumberTooLarge */,
|
|
6563
|
+
msg: getAggregatorServerErrorMessage(
|
|
6564
|
+
10001 /* NumberTooLarge */
|
|
6565
|
+
)
|
|
6566
|
+
}
|
|
6551
6567
|
};
|
|
6552
6568
|
}
|
|
6553
|
-
|
|
6569
|
+
const data = yield response.json();
|
|
6570
|
+
if (data.data != null) {
|
|
6571
|
+
const res = parseRouterResponse(data.data);
|
|
6572
|
+
return res;
|
|
6573
|
+
}
|
|
6574
|
+
const insufficientLiquidity = data.msg === "liquidity is not enough";
|
|
6575
|
+
return {
|
|
6576
|
+
amountIn: ZERO,
|
|
6577
|
+
amountOut: ZERO,
|
|
6578
|
+
routes: [],
|
|
6579
|
+
insufficientLiquidity,
|
|
6580
|
+
error: {
|
|
6581
|
+
code: 10003 /* InsufficientLiquidity */,
|
|
6582
|
+
msg: getAggregatorServerErrorMessage(
|
|
6583
|
+
10003 /* InsufficientLiquidity */
|
|
6584
|
+
)
|
|
6585
|
+
}
|
|
6586
|
+
};
|
|
6554
6587
|
});
|
|
6555
6588
|
}
|
|
6556
6589
|
swapInPools(params) {
|
|
@@ -6677,7 +6710,6 @@ var AggregatorClient = class {
|
|
|
6677
6710
|
}
|
|
6678
6711
|
devInspectTransactionBlock(txb) {
|
|
6679
6712
|
return __async(this, null, function* () {
|
|
6680
|
-
console.log(this.wallet);
|
|
6681
6713
|
const res = yield this.client.devInspectTransactionBlock({
|
|
6682
6714
|
transactionBlock: txb,
|
|
6683
6715
|
sender: this.wallet
|
package/dist/index.mjs
CHANGED
|
@@ -5330,6 +5330,22 @@ var MAINNET_AFTERMATH_INSURANCE_FUND_ID = "0xf0c40d67b078000e18032334c3325c47b9e
|
|
|
5330
5330
|
var TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
|
|
5331
5331
|
var MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
|
|
5332
5332
|
var TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
|
|
5333
|
+
|
|
5334
|
+
// src/errors.ts
|
|
5335
|
+
function getAggregatorServerErrorMessage(code) {
|
|
5336
|
+
switch (code) {
|
|
5337
|
+
case 1e4 /* CalculateError */:
|
|
5338
|
+
return "Calculate error";
|
|
5339
|
+
case 10001 /* NumberTooLarge */:
|
|
5340
|
+
return "Input number too large can not fit in target type";
|
|
5341
|
+
case 10002 /* NoRouter */:
|
|
5342
|
+
return "No router";
|
|
5343
|
+
case 10003 /* InsufficientLiquidity */:
|
|
5344
|
+
return "Insufficient Liquidity";
|
|
5345
|
+
default:
|
|
5346
|
+
return "Unknown error";
|
|
5347
|
+
}
|
|
5348
|
+
}
|
|
5333
5349
|
function mintZeroCoin(txb, coinType) {
|
|
5334
5350
|
return txb.moveCall({
|
|
5335
5351
|
target: SuiZeroCoinFn,
|
|
@@ -5353,7 +5369,7 @@ function buildInputCoin(txb, allCoins, amount, coinType) {
|
|
|
5353
5369
|
"InsufficientBalance" /* InsufficientBalance */
|
|
5354
5370
|
);
|
|
5355
5371
|
}
|
|
5356
|
-
if (CoinUtils.isSuiCoin(coinType)
|
|
5372
|
+
if (CoinUtils.isSuiCoin(coinType)) {
|
|
5357
5373
|
const resultCoin = txb.splitCoins(txb.gas, [
|
|
5358
5374
|
txb.pure.u64(amount.toString())
|
|
5359
5375
|
]);
|
|
@@ -5912,7 +5928,7 @@ function flowxAmmSwapMovecall(swapParams, txb, config2) {
|
|
|
5912
5928
|
}
|
|
5913
5929
|
|
|
5914
5930
|
// src/transaction/turbos.ts
|
|
5915
|
-
function
|
|
5931
|
+
function turbosClmmSwapMovecall(swapParams, txb, config2) {
|
|
5916
5932
|
return __async(this, null, function* () {
|
|
5917
5933
|
const aggregatorPackage = config2.getPackage(AGGREGATOR);
|
|
5918
5934
|
if (aggregatorPackage == null) {
|
|
@@ -6072,7 +6088,6 @@ function expectInputRouterSwap(client, params, txb, fromCoin, config2, partner)
|
|
|
6072
6088
|
coinAType: path.a2b ? path.from : path.target,
|
|
6073
6089
|
coinBType: path.a2b ? path.target : path.from
|
|
6074
6090
|
};
|
|
6075
|
-
firstPathPool && router.path.length > 1;
|
|
6076
6091
|
const swapResult = yield cetusSwapWithOutLimit(
|
|
6077
6092
|
swapParams,
|
|
6078
6093
|
nextFromCoin,
|
|
@@ -6177,7 +6192,7 @@ function expectInputRouterSwap(client, params, txb, fromCoin, config2, partner)
|
|
|
6177
6192
|
coinBType: path.a2b ? path.target : path.from,
|
|
6178
6193
|
feeType
|
|
6179
6194
|
};
|
|
6180
|
-
const swapResult = yield
|
|
6195
|
+
const swapResult = yield turbosClmmSwapMovecall(swapParams, txb, config2);
|
|
6181
6196
|
intermediateTargetCoin = swapResult.targetCoin;
|
|
6182
6197
|
nextFromCoin = intermediateTargetCoin;
|
|
6183
6198
|
nextFlashAmount = swapResult.amountOut;
|
|
@@ -6535,20 +6550,38 @@ var AggregatorClient = class {
|
|
|
6535
6550
|
}
|
|
6536
6551
|
}
|
|
6537
6552
|
const response = yield fetch(url);
|
|
6538
|
-
|
|
6539
|
-
if (data.data != null) {
|
|
6540
|
-
const res = parseRouterResponse(data.data);
|
|
6541
|
-
return res;
|
|
6542
|
-
}
|
|
6543
|
-
if (data.msg === "liquidity is not enough") {
|
|
6553
|
+
if (!response.ok) {
|
|
6544
6554
|
return {
|
|
6545
6555
|
amountIn: ZERO,
|
|
6546
6556
|
amountOut: ZERO,
|
|
6547
6557
|
routes: [],
|
|
6548
|
-
insufficientLiquidity:
|
|
6558
|
+
insufficientLiquidity: false,
|
|
6559
|
+
error: {
|
|
6560
|
+
code: 10001 /* NumberTooLarge */,
|
|
6561
|
+
msg: getAggregatorServerErrorMessage(
|
|
6562
|
+
10001 /* NumberTooLarge */
|
|
6563
|
+
)
|
|
6564
|
+
}
|
|
6549
6565
|
};
|
|
6550
6566
|
}
|
|
6551
|
-
|
|
6567
|
+
const data = yield response.json();
|
|
6568
|
+
if (data.data != null) {
|
|
6569
|
+
const res = parseRouterResponse(data.data);
|
|
6570
|
+
return res;
|
|
6571
|
+
}
|
|
6572
|
+
const insufficientLiquidity = data.msg === "liquidity is not enough";
|
|
6573
|
+
return {
|
|
6574
|
+
amountIn: ZERO,
|
|
6575
|
+
amountOut: ZERO,
|
|
6576
|
+
routes: [],
|
|
6577
|
+
insufficientLiquidity,
|
|
6578
|
+
error: {
|
|
6579
|
+
code: 10003 /* InsufficientLiquidity */,
|
|
6580
|
+
msg: getAggregatorServerErrorMessage(
|
|
6581
|
+
10003 /* InsufficientLiquidity */
|
|
6582
|
+
)
|
|
6583
|
+
}
|
|
6584
|
+
};
|
|
6552
6585
|
});
|
|
6553
6586
|
}
|
|
6554
6587
|
swapInPools(params) {
|
|
@@ -6675,7 +6708,6 @@ var AggregatorClient = class {
|
|
|
6675
6708
|
}
|
|
6676
6709
|
devInspectTransactionBlock(txb) {
|
|
6677
6710
|
return __async(this, null, function* () {
|
|
6678
|
-
console.log(this.wallet);
|
|
6679
6711
|
const res = yield this.client.devInspectTransactionBlock({
|
|
6680
6712
|
transactionBlock: txb,
|
|
6681
6713
|
sender: this.wallet
|
package/dist/src/client.d.ts
CHANGED
|
@@ -27,11 +27,16 @@ export type Router = {
|
|
|
27
27
|
amountOut: BN;
|
|
28
28
|
initialPrice: Decimal;
|
|
29
29
|
};
|
|
30
|
+
export type RouterError = {
|
|
31
|
+
code: number;
|
|
32
|
+
msg: string;
|
|
33
|
+
};
|
|
30
34
|
export type RouterData = {
|
|
31
35
|
amountIn: BN;
|
|
32
36
|
amountOut: BN;
|
|
33
37
|
routes: Router[];
|
|
34
38
|
insufficientLiquidity: boolean;
|
|
39
|
+
error?: RouterError;
|
|
35
40
|
};
|
|
36
41
|
export type AggregatorResponse = {
|
|
37
42
|
code: number;
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare enum TransactionErrorCode {
|
|
|
16
16
|
MissTurbosFeeType = "MissTurbosFeeType",
|
|
17
17
|
MissAftermathLpSupplyType = "MissAftermathLpSupplyType"
|
|
18
18
|
}
|
|
19
|
-
export type AggregatorErrorCode = TypesErrorCode;
|
|
19
|
+
export type AggregatorErrorCode = TypesErrorCode | ConfigErrorCode | TransactionErrorCode;
|
|
20
20
|
/**
|
|
21
21
|
* AggregatorError is a custom error class that extends the built-in Error class. It is used to represent errors that occur during aggregation operations.
|
|
22
22
|
* The key functionality of this code includes:
|
|
@@ -29,3 +29,10 @@ export declare class AggregatorError extends Error {
|
|
|
29
29
|
constructor(message: string, errorCode?: AggregatorErrorCode);
|
|
30
30
|
static isAggregatorErrorCode(e: any, code: AggregatorErrorCode): boolean;
|
|
31
31
|
}
|
|
32
|
+
export declare enum AggregatorServerErrorCode {
|
|
33
|
+
CalculateError = 10000,
|
|
34
|
+
NumberTooLarge = 10001,
|
|
35
|
+
NoRouter = 10002,
|
|
36
|
+
InsufficientLiquidity = 10003
|
|
37
|
+
}
|
|
38
|
+
export declare function getAggregatorServerErrorMessage(code: AggregatorServerErrorCode): string;
|
|
@@ -19,4 +19,4 @@ export type TurbosSwapResult = {
|
|
|
19
19
|
amountOut: TransactionArgument;
|
|
20
20
|
txb: Transaction;
|
|
21
21
|
};
|
|
22
|
-
export declare function
|
|
22
|
+
export declare function turbosClmmSwapMovecall(swapParams: TurbosSwapParams, txb: Transaction, config: AggregatorConfig): Promise<TurbosSwapResult>;
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -17,6 +17,10 @@ import { swapInPools } from "./transaction/swap"
|
|
|
17
17
|
import { completionCoin } from "./utils/coin"
|
|
18
18
|
import { SUI_FRAMEWORK_ADDRESS } from "@mysten/sui/utils"
|
|
19
19
|
import { AFTERMATH_AMM, JOIN_FUNC, PAY_MODULE, TURBOS_DEX, ZERO } from "./const"
|
|
20
|
+
import {
|
|
21
|
+
AggregatorServerErrorCode,
|
|
22
|
+
getAggregatorServerErrorMessage,
|
|
23
|
+
} from "./errors"
|
|
20
24
|
|
|
21
25
|
export type ExtendedDetails = {
|
|
22
26
|
aftermathPoolFlatness?: number
|
|
@@ -44,11 +48,17 @@ export type Router = {
|
|
|
44
48
|
initialPrice: Decimal
|
|
45
49
|
}
|
|
46
50
|
|
|
51
|
+
export type RouterError = {
|
|
52
|
+
code: number
|
|
53
|
+
msg: string
|
|
54
|
+
}
|
|
55
|
+
|
|
47
56
|
export type RouterData = {
|
|
48
57
|
amountIn: BN
|
|
49
58
|
amountOut: BN
|
|
50
59
|
routes: Router[]
|
|
51
60
|
insufficientLiquidity: boolean
|
|
61
|
+
error?: RouterError
|
|
52
62
|
}
|
|
53
63
|
|
|
54
64
|
export type AggregatorResponse = {
|
|
@@ -184,6 +194,21 @@ export class AggregatorClient {
|
|
|
184
194
|
}
|
|
185
195
|
|
|
186
196
|
const response = await fetch(url)
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
return {
|
|
199
|
+
amountIn: ZERO,
|
|
200
|
+
amountOut: ZERO,
|
|
201
|
+
routes: [],
|
|
202
|
+
insufficientLiquidity: false,
|
|
203
|
+
error: {
|
|
204
|
+
code: AggregatorServerErrorCode.NumberTooLarge,
|
|
205
|
+
msg: getAggregatorServerErrorMessage(
|
|
206
|
+
AggregatorServerErrorCode.NumberTooLarge
|
|
207
|
+
),
|
|
208
|
+
},
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
187
212
|
const data = await response.json()
|
|
188
213
|
|
|
189
214
|
if (data.data != null) {
|
|
@@ -191,15 +216,20 @@ export class AggregatorClient {
|
|
|
191
216
|
return res
|
|
192
217
|
}
|
|
193
218
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
219
|
+
const insufficientLiquidity = data.msg === "liquidity is not enough"
|
|
220
|
+
|
|
221
|
+
return {
|
|
222
|
+
amountIn: ZERO,
|
|
223
|
+
amountOut: ZERO,
|
|
224
|
+
routes: [],
|
|
225
|
+
insufficientLiquidity,
|
|
226
|
+
error: {
|
|
227
|
+
code: AggregatorServerErrorCode.InsufficientLiquidity,
|
|
228
|
+
msg: getAggregatorServerErrorMessage(
|
|
229
|
+
AggregatorServerErrorCode.InsufficientLiquidity
|
|
230
|
+
),
|
|
231
|
+
},
|
|
201
232
|
}
|
|
202
|
-
return null
|
|
203
233
|
}
|
|
204
234
|
|
|
205
235
|
async swapInPools(
|
|
@@ -236,7 +266,6 @@ export class AggregatorClient {
|
|
|
236
266
|
)
|
|
237
267
|
|
|
238
268
|
const txb = new Transaction()
|
|
239
|
-
// txb.setGasBudget(42392686100000000)
|
|
240
269
|
|
|
241
270
|
if (refreshAllCoins || this.allCoins.length === 0) {
|
|
242
271
|
this.allCoins = await this.getAllCoins()
|
|
@@ -332,7 +361,6 @@ export class AggregatorClient {
|
|
|
332
361
|
}
|
|
333
362
|
|
|
334
363
|
async devInspectTransactionBlock(txb: Transaction) {
|
|
335
|
-
console.log(this.wallet)
|
|
336
364
|
const res = await this.client.devInspectTransactionBlock({
|
|
337
365
|
transactionBlock: txb,
|
|
338
366
|
sender: this.wallet,
|
package/src/errors.ts
CHANGED
|
@@ -19,7 +19,10 @@ export enum TransactionErrorCode {
|
|
|
19
19
|
MissAftermathLpSupplyType = `MissAftermathLpSupplyType`,
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export type AggregatorErrorCode =
|
|
22
|
+
export type AggregatorErrorCode =
|
|
23
|
+
| TypesErrorCode
|
|
24
|
+
| ConfigErrorCode
|
|
25
|
+
| TransactionErrorCode
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* AggregatorError is a custom error class that extends the built-in Error class. It is used to represent errors that occur during aggregation operations.
|
|
@@ -42,3 +45,27 @@ export class AggregatorError extends Error {
|
|
|
42
45
|
return e instanceof AggregatorError && e.errorCode === code
|
|
43
46
|
}
|
|
44
47
|
}
|
|
48
|
+
|
|
49
|
+
export enum AggregatorServerErrorCode {
|
|
50
|
+
CalculateError = 10000,
|
|
51
|
+
NumberTooLarge = 10001,
|
|
52
|
+
NoRouter = 10002,
|
|
53
|
+
InsufficientLiquidity = 10003,
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function getAggregatorServerErrorMessage(
|
|
57
|
+
code: AggregatorServerErrorCode
|
|
58
|
+
): string {
|
|
59
|
+
switch (code) {
|
|
60
|
+
case AggregatorServerErrorCode.CalculateError:
|
|
61
|
+
return "Calculate error"
|
|
62
|
+
case AggregatorServerErrorCode.NumberTooLarge:
|
|
63
|
+
return "Input number too large can not fit in target type"
|
|
64
|
+
case AggregatorServerErrorCode.NoRouter:
|
|
65
|
+
return "No router"
|
|
66
|
+
case AggregatorServerErrorCode.InsufficientLiquidity:
|
|
67
|
+
return "Insufficient Liquidity"
|
|
68
|
+
default:
|
|
69
|
+
return "Unknown error"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
import { transferOrDestoryCoin } from "./common"
|
|
26
26
|
import { GetDefaultSqrtPriceLimit } from "../math"
|
|
27
27
|
import { flowxAmmSwapMovecall } from "./flowx"
|
|
28
|
-
import {
|
|
28
|
+
import { turbosClmmSwapMovecall } from "./turbos"
|
|
29
29
|
import { AftermathAmmSwapMovecall } from "./aftermath"
|
|
30
30
|
import { TransactionErrorCode } from "~/errors"
|
|
31
31
|
|
|
@@ -47,7 +47,6 @@ export async function expectInputRouterSwap(
|
|
|
47
47
|
const router = params.routers[i]
|
|
48
48
|
let intermediateTargetCoin: TransactionObjectArgument
|
|
49
49
|
let nextFromCoin = fromCoins[i] as TransactionObjectArgument
|
|
50
|
-
|
|
51
50
|
let nextFlashAmount: TransactionArgument = txb.pure.u64(splitAmounts[i])
|
|
52
51
|
|
|
53
52
|
for (let j = 0; j < router.path.length; j++) {
|
|
@@ -67,7 +66,6 @@ export async function expectInputRouterSwap(
|
|
|
67
66
|
coinBType: path.a2b ? path.target : path.from,
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
const returnPayAmount = firstPathPool && router.path.length > 1
|
|
71
69
|
const swapResult = await cetusSwapWithOutLimit(
|
|
72
70
|
swapParams,
|
|
73
71
|
nextFromCoin,
|
|
@@ -192,7 +190,7 @@ export async function expectInputRouterSwap(
|
|
|
192
190
|
feeType,
|
|
193
191
|
}
|
|
194
192
|
|
|
195
|
-
const swapResult = await
|
|
193
|
+
const swapResult = await turbosClmmSwapMovecall(swapParams, txb, config)
|
|
196
194
|
|
|
197
195
|
intermediateTargetCoin = swapResult.targetCoin
|
|
198
196
|
nextFromCoin = intermediateTargetCoin
|
package/src/transaction/swap.ts
CHANGED
|
@@ -2,14 +2,7 @@ import { Transaction } from "@mysten/sui/transactions"
|
|
|
2
2
|
import { SwapInPoolsParams } from "~/client"
|
|
3
3
|
import { AggregatorConfig } from "~/config"
|
|
4
4
|
import { compareCoins, completionCoin } from "~/utils/coin"
|
|
5
|
-
import {
|
|
6
|
-
CETUS_DEX,
|
|
7
|
-
INTEGRATE,
|
|
8
|
-
RouterData,
|
|
9
|
-
SwapInPoolsResult,
|
|
10
|
-
U64_MAX_BN,
|
|
11
|
-
ZERO,
|
|
12
|
-
} from ".."
|
|
5
|
+
import { CETUS_DEX, INTEGRATE, SwapInPoolsResult, U64_MAX_BN, ZERO } from ".."
|
|
13
6
|
import { ConfigErrorCode, TransactionErrorCode } from "~/errors"
|
|
14
7
|
import { checkInvalidSuiAddress } from "~/utils/transaction"
|
|
15
8
|
import { SuiClient } from "@mysten/sui/client"
|
package/tests/router.test.ts
CHANGED
|
@@ -2,15 +2,7 @@ import { describe, expect, test } from "@jest/globals"
|
|
|
2
2
|
import dotenv from "dotenv"
|
|
3
3
|
import { AggregatorClient } from "~/client"
|
|
4
4
|
import { AggregatorConfig, ENV } from "~/config"
|
|
5
|
-
import {
|
|
6
|
-
M_CETUS,
|
|
7
|
-
M_HASUI,
|
|
8
|
-
M_NAVI,
|
|
9
|
-
M_SUI,
|
|
10
|
-
M_USDC,
|
|
11
|
-
M_VAPOR,
|
|
12
|
-
M_VSUI,
|
|
13
|
-
} from "../src/test_data.test"
|
|
5
|
+
import { M_CETUS, M_HASUI, M_NAVI, M_SUI, M_USDC } from "../src/test_data.test"
|
|
14
6
|
import { Ed25519Keypair } from "@mysten/sui/keypairs/ed25519"
|
|
15
7
|
import { printTransaction } from "~/utils/transaction"
|
|
16
8
|
import BN from "bn.js"
|
|
@@ -42,15 +34,19 @@ describe("router module", () => {
|
|
|
42
34
|
// : buildTestAccount()
|
|
43
35
|
const byte = Buffer.from(secret, "base64")
|
|
44
36
|
const u8Array = new Uint8Array(byte)
|
|
37
|
+
const secretKey = fromB64(secret)
|
|
38
|
+
console.log("secret key", secretKey.toString())
|
|
45
39
|
|
|
46
40
|
keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
|
|
47
41
|
|
|
48
|
-
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
49
|
-
|
|
42
|
+
// const wallet = keypair.getPublicKey().toSuiAddress()
|
|
43
|
+
|
|
44
|
+
// console.log("wallet", wallet, "\n", wallet.toString())
|
|
50
45
|
|
|
51
46
|
// const wallet =
|
|
52
|
-
// "
|
|
53
|
-
|
|
47
|
+
// "0xfba94aa36e93ccc7d84a6a57040fc51983223f1b522a8d0be3c3bf2c98977ebb"
|
|
48
|
+
const wallet =
|
|
49
|
+
"0xaabf2fedcb36146db164bec930b74a47969c4df98216e049342a3c49b6d11580"
|
|
54
50
|
// const wallet = "0x410456cfc689666936b6bf80fbec958b69499b9f7183ecba07de577c17248a44"
|
|
55
51
|
// const wallet = "0xca171941521153181ff729d53489eaae7e99c3f4692884afd7cca61154e4cec4"
|
|
56
52
|
// console.log("wallet: ", wallet)
|
|
@@ -111,7 +107,7 @@ describe("router module", () => {
|
|
|
111
107
|
})
|
|
112
108
|
|
|
113
109
|
test("Find router", async () => {
|
|
114
|
-
const amount = "
|
|
110
|
+
const amount = "423926761000000000000000000000"
|
|
115
111
|
|
|
116
112
|
const res = await client.findRouter({
|
|
117
113
|
from: M_SUI,
|
|
@@ -135,7 +131,7 @@ describe("router module", () => {
|
|
|
135
131
|
|
|
136
132
|
test("Build router tx", async () => {
|
|
137
133
|
const byAmountIn = true
|
|
138
|
-
const amount = "
|
|
134
|
+
const amount = "3000000000000"
|
|
139
135
|
|
|
140
136
|
const from = M_SUI
|
|
141
137
|
const target = M_USDC
|
|
@@ -149,7 +145,7 @@ describe("router module", () => {
|
|
|
149
145
|
splitAlgorithm: null,
|
|
150
146
|
splitFactor: null,
|
|
151
147
|
splitCount: null,
|
|
152
|
-
providers: ["CETUS"],
|
|
148
|
+
providers: ["CETUS", "DEEPBOOK", "AFTERMATH", "FLOWX", "KRIYA", "TURBOS"],
|
|
153
149
|
})
|
|
154
150
|
|
|
155
151
|
if (res != null) {
|
|
@@ -174,6 +170,8 @@ describe("router module", () => {
|
|
|
174
170
|
refreshAllCoins: true,
|
|
175
171
|
})
|
|
176
172
|
|
|
173
|
+
printTransaction(routerTx)
|
|
174
|
+
|
|
177
175
|
let result = await client.devInspectTransactionBlock(routerTx)
|
|
178
176
|
|
|
179
177
|
if (result.effects.status.status === "success") {
|