@cetusprotocol/aggregator-sdk 0.0.0-experimental-20240819211521 → 0.0.0-experimental-20240822190000
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 +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +109 -3
- package/dist/index.mjs +108 -5
- package/dist/src/client.d.ts +3 -0
- package/dist/src/transaction/afsui.d.ts +10 -0
- package/dist/src/transaction/haedal.d.ts +7 -0
- package/dist/src/transaction/volo.d.ts +8 -0
- package/package.json +1 -1
- package/src/client.ts +12 -1
- package/src/transaction/afsui.ts +60 -0
- package/src/transaction/haedal.ts +49 -0
- package/src/transaction/swap.ts +5 -3
- package/src/transaction/volo.ts +52 -0
- package/tests/router.test.ts +24 -18
package/dist/index.d.mts
CHANGED
|
@@ -67,6 +67,9 @@ declare const FLOWXV2 = "FLOWX";
|
|
|
67
67
|
declare const KRIYAV3 = "KRIYAV3";
|
|
68
68
|
declare const TURBOS = "TURBOS";
|
|
69
69
|
declare const AFTERMATH = "AFTERMATH";
|
|
70
|
+
declare const HAEDAL = "HAEDAL";
|
|
71
|
+
declare const VOLO = "VOLO";
|
|
72
|
+
declare const AFSUI = "AFSUI";
|
|
70
73
|
type BuildRouterSwapParams = {
|
|
71
74
|
routers: Router[];
|
|
72
75
|
byAmountIn: boolean;
|
|
@@ -264,4 +267,4 @@ declare enum Env {
|
|
|
264
267
|
Testnet = 1
|
|
265
268
|
}
|
|
266
269
|
|
|
267
|
-
export { AFTERMATH, AFTERMATH_MODULE, AggregatorClient, type AggregatorResponse, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOKV2, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWX_AMM_MODULE, type FindRouterParams, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, JOIN_FUNC, KRIYA, KRIYAV3, 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 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, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, ZERO, composeType, createTarget, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
|
270
|
+
export { AFSUI, AFTERMATH, AFTERMATH_MODULE, AggregatorClient, type AggregatorResponse, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOKV2, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWX_AMM_MODULE, type FindRouterParams, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, HAEDAL, JOIN_FUNC, KRIYA, KRIYAV3, 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 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, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, composeType, createTarget, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
package/dist/index.d.ts
CHANGED
|
@@ -67,6 +67,9 @@ declare const FLOWXV2 = "FLOWX";
|
|
|
67
67
|
declare const KRIYAV3 = "KRIYAV3";
|
|
68
68
|
declare const TURBOS = "TURBOS";
|
|
69
69
|
declare const AFTERMATH = "AFTERMATH";
|
|
70
|
+
declare const HAEDAL = "HAEDAL";
|
|
71
|
+
declare const VOLO = "VOLO";
|
|
72
|
+
declare const AFSUI = "AFSUI";
|
|
70
73
|
type BuildRouterSwapParams = {
|
|
71
74
|
routers: Router[];
|
|
72
75
|
byAmountIn: boolean;
|
|
@@ -264,4 +267,4 @@ declare enum Env {
|
|
|
264
267
|
Testnet = 1
|
|
265
268
|
}
|
|
266
269
|
|
|
267
|
-
export { AFTERMATH, AFTERMATH_MODULE, AggregatorClient, type AggregatorResponse, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOKV2, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWX_AMM_MODULE, type FindRouterParams, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, JOIN_FUNC, KRIYA, KRIYAV3, 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 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, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, ZERO, composeType, createTarget, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
|
270
|
+
export { AFSUI, AFTERMATH, AFTERMATH_MODULE, AggregatorClient, type AggregatorResponse, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOKV2, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWX_AMM_MODULE, type FindRouterParams, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, HAEDAL, JOIN_FUNC, KRIYA, KRIYAV3, 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 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, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, composeType, createTarget, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
package/dist/index.js
CHANGED
|
@@ -5814,6 +5814,7 @@ function swapInPools(client, params, sender) {
|
|
|
5814
5814
|
}
|
|
5815
5815
|
}
|
|
5816
5816
|
const event = valueData[tempIndex].parsedJson.data;
|
|
5817
|
+
console.log("event", JSON.stringify(event, null, 2));
|
|
5817
5818
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price;
|
|
5818
5819
|
const [decimalA, decimalB] = yield Promise.all([
|
|
5819
5820
|
client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
|
|
@@ -5842,9 +5843,9 @@ function swapInPools(client, params, sender) {
|
|
|
5842
5843
|
provider: "CETUS",
|
|
5843
5844
|
from: fromCoin,
|
|
5844
5845
|
target: targetCoin,
|
|
5845
|
-
feeRate:
|
|
5846
|
-
amountIn:
|
|
5847
|
-
amountOut:
|
|
5846
|
+
feeRate: event.fee_rate,
|
|
5847
|
+
amountIn: event.amount_in,
|
|
5848
|
+
amountOut: event.amount_out
|
|
5848
5849
|
}
|
|
5849
5850
|
],
|
|
5850
5851
|
amountIn: new import_bn4.BN((_d = event.amount_in) != null ? _d : 0),
|
|
@@ -5889,6 +5890,99 @@ var KriyaV3 = class {
|
|
|
5889
5890
|
});
|
|
5890
5891
|
}
|
|
5891
5892
|
};
|
|
5893
|
+
var Haedal = class {
|
|
5894
|
+
constructor(env) {
|
|
5895
|
+
if (env !== 0 /* Mainnet */) {
|
|
5896
|
+
throw new Error("Haedal only supported on mainnet");
|
|
5897
|
+
}
|
|
5898
|
+
this.stake = "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca";
|
|
5899
|
+
}
|
|
5900
|
+
swap(client, txb, path, inputCoin) {
|
|
5901
|
+
return __async(this, null, function* () {
|
|
5902
|
+
const { direction, from, target } = path;
|
|
5903
|
+
if (!direction) {
|
|
5904
|
+
throw new Error("Haedal not support b2a swap");
|
|
5905
|
+
}
|
|
5906
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target];
|
|
5907
|
+
const args = [
|
|
5908
|
+
txb.pure.address(utils.SUI_SYSTEM_ADDRESS),
|
|
5909
|
+
txb.object(this.stake),
|
|
5910
|
+
inputCoin,
|
|
5911
|
+
txb.pure.address("0x0")
|
|
5912
|
+
];
|
|
5913
|
+
const res = txb.moveCall({
|
|
5914
|
+
target: `${client.publishedAt()}::haedal::${func}`,
|
|
5915
|
+
typeArguments: [coinAType, coinBType],
|
|
5916
|
+
arguments: args
|
|
5917
|
+
});
|
|
5918
|
+
return res;
|
|
5919
|
+
});
|
|
5920
|
+
}
|
|
5921
|
+
};
|
|
5922
|
+
var Afsui = class {
|
|
5923
|
+
constructor(env) {
|
|
5924
|
+
if (env !== 0 /* Mainnet */) {
|
|
5925
|
+
throw new Error("Afsui only supported on mainnet");
|
|
5926
|
+
}
|
|
5927
|
+
this.stakedSuiVault = "0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d";
|
|
5928
|
+
this.safe = "0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610";
|
|
5929
|
+
this.referVault = "0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef";
|
|
5930
|
+
this.validator = "0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2";
|
|
5931
|
+
}
|
|
5932
|
+
swap(client, txb, path, inputCoin) {
|
|
5933
|
+
return __async(this, null, function* () {
|
|
5934
|
+
const { direction, from, target } = path;
|
|
5935
|
+
if (!direction) {
|
|
5936
|
+
throw new Error("Afsui not support b2a swap");
|
|
5937
|
+
}
|
|
5938
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target];
|
|
5939
|
+
const args = [
|
|
5940
|
+
txb.object(this.stakedSuiVault),
|
|
5941
|
+
txb.object(this.safe),
|
|
5942
|
+
txb.pure.address(utils.SUI_SYSTEM_ADDRESS),
|
|
5943
|
+
txb.object(this.referVault),
|
|
5944
|
+
inputCoin,
|
|
5945
|
+
txb.object(this.validator)
|
|
5946
|
+
];
|
|
5947
|
+
const res = txb.moveCall({
|
|
5948
|
+
target: `${client.publishedAt()}::afsui::${func}`,
|
|
5949
|
+
typeArguments: [coinAType, coinBType],
|
|
5950
|
+
arguments: args
|
|
5951
|
+
});
|
|
5952
|
+
return res;
|
|
5953
|
+
});
|
|
5954
|
+
}
|
|
5955
|
+
};
|
|
5956
|
+
var Volo = class {
|
|
5957
|
+
constructor(env) {
|
|
5958
|
+
if (env !== 0 /* Mainnet */) {
|
|
5959
|
+
throw new Error("Volo only supported on mainnet");
|
|
5960
|
+
}
|
|
5961
|
+
this.nativePool = "0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf";
|
|
5962
|
+
this.metadata = "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60";
|
|
5963
|
+
}
|
|
5964
|
+
swap(client, txb, path, inputCoin) {
|
|
5965
|
+
return __async(this, null, function* () {
|
|
5966
|
+
const { direction, from, target } = path;
|
|
5967
|
+
if (!direction) {
|
|
5968
|
+
throw new Error("Volo not support b2a swap");
|
|
5969
|
+
}
|
|
5970
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target];
|
|
5971
|
+
const args = [
|
|
5972
|
+
txb.object(this.nativePool),
|
|
5973
|
+
txb.object(this.metadata),
|
|
5974
|
+
txb.pure.address(utils.SUI_SYSTEM_ADDRESS),
|
|
5975
|
+
inputCoin
|
|
5976
|
+
];
|
|
5977
|
+
const res = txb.moveCall({
|
|
5978
|
+
target: `${client.publishedAt()}::volo::${func}`,
|
|
5979
|
+
typeArguments: [coinAType, coinBType],
|
|
5980
|
+
arguments: args
|
|
5981
|
+
});
|
|
5982
|
+
return res;
|
|
5983
|
+
});
|
|
5984
|
+
}
|
|
5985
|
+
};
|
|
5892
5986
|
|
|
5893
5987
|
// src/client.ts
|
|
5894
5988
|
var CETUS = "CETUS";
|
|
@@ -5898,6 +5992,9 @@ var FLOWXV2 = "FLOWX";
|
|
|
5898
5992
|
var KRIYAV3 = "KRIYAV3";
|
|
5899
5993
|
var TURBOS = "TURBOS";
|
|
5900
5994
|
var AFTERMATH = "AFTERMATH";
|
|
5995
|
+
var HAEDAL = "HAEDAL";
|
|
5996
|
+
var VOLO = "VOLO";
|
|
5997
|
+
var AFSUI = "AFSUI";
|
|
5901
5998
|
var AggregatorClient5 = class {
|
|
5902
5999
|
constructor(endpoint, signer, client, env) {
|
|
5903
6000
|
this.endpoint = endpoint;
|
|
@@ -6181,6 +6278,12 @@ var AggregatorClient5 = class {
|
|
|
6181
6278
|
return new Turbos(this.env);
|
|
6182
6279
|
case AFTERMATH:
|
|
6183
6280
|
return new Aftermath(this.env);
|
|
6281
|
+
case HAEDAL:
|
|
6282
|
+
return new Haedal(this.env);
|
|
6283
|
+
case AFSUI:
|
|
6284
|
+
return new Afsui(this.env);
|
|
6285
|
+
case VOLO:
|
|
6286
|
+
return new Volo(this.env);
|
|
6184
6287
|
default:
|
|
6185
6288
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6186
6289
|
}
|
|
@@ -6351,6 +6454,7 @@ decimal.js/decimal.mjs:
|
|
|
6351
6454
|
*)
|
|
6352
6455
|
*/
|
|
6353
6456
|
|
|
6457
|
+
exports.AFSUI = AFSUI;
|
|
6354
6458
|
exports.AFTERMATH = AFTERMATH;
|
|
6355
6459
|
exports.AFTERMATH_MODULE = AFTERMATH_MODULE;
|
|
6356
6460
|
exports.AggregatorClient = AggregatorClient5;
|
|
@@ -6376,6 +6480,7 @@ exports.FlashSwapFunc = FlashSwapFunc;
|
|
|
6376
6480
|
exports.FlashSwapWithPartnerA2BFunc = FlashSwapWithPartnerA2BFunc;
|
|
6377
6481
|
exports.FlashSwapWithPartnerB2AFunc = FlashSwapWithPartnerB2AFunc;
|
|
6378
6482
|
exports.FlashSwapWithPartnerFunc = FlashSwapWithPartnerFunc;
|
|
6483
|
+
exports.HAEDAL = HAEDAL;
|
|
6379
6484
|
exports.JOIN_FUNC = JOIN_FUNC;
|
|
6380
6485
|
exports.KRIYA = KRIYA;
|
|
6381
6486
|
exports.KRIYAV3 = KRIYAV3;
|
|
@@ -6417,6 +6522,7 @@ exports.U128 = U128;
|
|
|
6417
6522
|
exports.U64_MAX = U64_MAX;
|
|
6418
6523
|
exports.U64_MAX_BN = U64_MAX_BN;
|
|
6419
6524
|
exports.UTILS_MODULE = UTILS_MODULE;
|
|
6525
|
+
exports.VOLO = VOLO;
|
|
6420
6526
|
exports.ZERO = ZERO;
|
|
6421
6527
|
exports.composeType = composeType;
|
|
6422
6528
|
exports.createTarget = createTarget;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS } from '@mysten/sui/utils';
|
|
1
|
+
import { normalizeSuiObjectId, SUI_FRAMEWORK_ADDRESS, SUI_SYSTEM_ADDRESS } from '@mysten/sui/utils';
|
|
2
2
|
import { Transaction } from '@mysten/sui/transactions';
|
|
3
3
|
|
|
4
4
|
var __create = Object.create;
|
|
@@ -5812,6 +5812,7 @@ function swapInPools(client, params, sender) {
|
|
|
5812
5812
|
}
|
|
5813
5813
|
}
|
|
5814
5814
|
const event = valueData[tempIndex].parsedJson.data;
|
|
5815
|
+
console.log("event", JSON.stringify(event, null, 2));
|
|
5815
5816
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price;
|
|
5816
5817
|
const [decimalA, decimalB] = yield Promise.all([
|
|
5817
5818
|
client.getCoinMetadata({ coinType: coinA }).then((metadata) => metadata == null ? void 0 : metadata.decimals),
|
|
@@ -5840,9 +5841,9 @@ function swapInPools(client, params, sender) {
|
|
|
5840
5841
|
provider: "CETUS",
|
|
5841
5842
|
from: fromCoin,
|
|
5842
5843
|
target: targetCoin,
|
|
5843
|
-
feeRate:
|
|
5844
|
-
amountIn:
|
|
5845
|
-
amountOut:
|
|
5844
|
+
feeRate: event.fee_rate,
|
|
5845
|
+
amountIn: event.amount_in,
|
|
5846
|
+
amountOut: event.amount_out
|
|
5846
5847
|
}
|
|
5847
5848
|
],
|
|
5848
5849
|
amountIn: new import_bn4.BN((_d = event.amount_in) != null ? _d : 0),
|
|
@@ -5887,6 +5888,99 @@ var KriyaV3 = class {
|
|
|
5887
5888
|
});
|
|
5888
5889
|
}
|
|
5889
5890
|
};
|
|
5891
|
+
var Haedal = class {
|
|
5892
|
+
constructor(env) {
|
|
5893
|
+
if (env !== 0 /* Mainnet */) {
|
|
5894
|
+
throw new Error("Haedal only supported on mainnet");
|
|
5895
|
+
}
|
|
5896
|
+
this.stake = "0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca";
|
|
5897
|
+
}
|
|
5898
|
+
swap(client, txb, path, inputCoin) {
|
|
5899
|
+
return __async(this, null, function* () {
|
|
5900
|
+
const { direction, from, target } = path;
|
|
5901
|
+
if (!direction) {
|
|
5902
|
+
throw new Error("Haedal not support b2a swap");
|
|
5903
|
+
}
|
|
5904
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target];
|
|
5905
|
+
const args = [
|
|
5906
|
+
txb.pure.address(SUI_SYSTEM_ADDRESS),
|
|
5907
|
+
txb.object(this.stake),
|
|
5908
|
+
inputCoin,
|
|
5909
|
+
txb.pure.address("0x0")
|
|
5910
|
+
];
|
|
5911
|
+
const res = txb.moveCall({
|
|
5912
|
+
target: `${client.publishedAt()}::haedal::${func}`,
|
|
5913
|
+
typeArguments: [coinAType, coinBType],
|
|
5914
|
+
arguments: args
|
|
5915
|
+
});
|
|
5916
|
+
return res;
|
|
5917
|
+
});
|
|
5918
|
+
}
|
|
5919
|
+
};
|
|
5920
|
+
var Afsui = class {
|
|
5921
|
+
constructor(env) {
|
|
5922
|
+
if (env !== 0 /* Mainnet */) {
|
|
5923
|
+
throw new Error("Afsui only supported on mainnet");
|
|
5924
|
+
}
|
|
5925
|
+
this.stakedSuiVault = "0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d";
|
|
5926
|
+
this.safe = "0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610";
|
|
5927
|
+
this.referVault = "0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef";
|
|
5928
|
+
this.validator = "0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2";
|
|
5929
|
+
}
|
|
5930
|
+
swap(client, txb, path, inputCoin) {
|
|
5931
|
+
return __async(this, null, function* () {
|
|
5932
|
+
const { direction, from, target } = path;
|
|
5933
|
+
if (!direction) {
|
|
5934
|
+
throw new Error("Afsui not support b2a swap");
|
|
5935
|
+
}
|
|
5936
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target];
|
|
5937
|
+
const args = [
|
|
5938
|
+
txb.object(this.stakedSuiVault),
|
|
5939
|
+
txb.object(this.safe),
|
|
5940
|
+
txb.pure.address(SUI_SYSTEM_ADDRESS),
|
|
5941
|
+
txb.object(this.referVault),
|
|
5942
|
+
inputCoin,
|
|
5943
|
+
txb.object(this.validator)
|
|
5944
|
+
];
|
|
5945
|
+
const res = txb.moveCall({
|
|
5946
|
+
target: `${client.publishedAt()}::afsui::${func}`,
|
|
5947
|
+
typeArguments: [coinAType, coinBType],
|
|
5948
|
+
arguments: args
|
|
5949
|
+
});
|
|
5950
|
+
return res;
|
|
5951
|
+
});
|
|
5952
|
+
}
|
|
5953
|
+
};
|
|
5954
|
+
var Volo = class {
|
|
5955
|
+
constructor(env) {
|
|
5956
|
+
if (env !== 0 /* Mainnet */) {
|
|
5957
|
+
throw new Error("Volo only supported on mainnet");
|
|
5958
|
+
}
|
|
5959
|
+
this.nativePool = "0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf";
|
|
5960
|
+
this.metadata = "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60";
|
|
5961
|
+
}
|
|
5962
|
+
swap(client, txb, path, inputCoin) {
|
|
5963
|
+
return __async(this, null, function* () {
|
|
5964
|
+
const { direction, from, target } = path;
|
|
5965
|
+
if (!direction) {
|
|
5966
|
+
throw new Error("Volo not support b2a swap");
|
|
5967
|
+
}
|
|
5968
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target];
|
|
5969
|
+
const args = [
|
|
5970
|
+
txb.object(this.nativePool),
|
|
5971
|
+
txb.object(this.metadata),
|
|
5972
|
+
txb.pure.address(SUI_SYSTEM_ADDRESS),
|
|
5973
|
+
inputCoin
|
|
5974
|
+
];
|
|
5975
|
+
const res = txb.moveCall({
|
|
5976
|
+
target: `${client.publishedAt()}::volo::${func}`,
|
|
5977
|
+
typeArguments: [coinAType, coinBType],
|
|
5978
|
+
arguments: args
|
|
5979
|
+
});
|
|
5980
|
+
return res;
|
|
5981
|
+
});
|
|
5982
|
+
}
|
|
5983
|
+
};
|
|
5890
5984
|
|
|
5891
5985
|
// src/client.ts
|
|
5892
5986
|
var CETUS = "CETUS";
|
|
@@ -5896,6 +5990,9 @@ var FLOWXV2 = "FLOWX";
|
|
|
5896
5990
|
var KRIYAV3 = "KRIYAV3";
|
|
5897
5991
|
var TURBOS = "TURBOS";
|
|
5898
5992
|
var AFTERMATH = "AFTERMATH";
|
|
5993
|
+
var HAEDAL = "HAEDAL";
|
|
5994
|
+
var VOLO = "VOLO";
|
|
5995
|
+
var AFSUI = "AFSUI";
|
|
5899
5996
|
var AggregatorClient5 = class {
|
|
5900
5997
|
constructor(endpoint, signer, client, env) {
|
|
5901
5998
|
this.endpoint = endpoint;
|
|
@@ -6179,6 +6276,12 @@ var AggregatorClient5 = class {
|
|
|
6179
6276
|
return new Turbos(this.env);
|
|
6180
6277
|
case AFTERMATH:
|
|
6181
6278
|
return new Aftermath(this.env);
|
|
6279
|
+
case HAEDAL:
|
|
6280
|
+
return new Haedal(this.env);
|
|
6281
|
+
case AFSUI:
|
|
6282
|
+
return new Afsui(this.env);
|
|
6283
|
+
case VOLO:
|
|
6284
|
+
return new Volo(this.env);
|
|
6182
6285
|
default:
|
|
6183
6286
|
throw new Error(`Unsupported dex ${provider}`);
|
|
6184
6287
|
}
|
|
@@ -6349,4 +6452,4 @@ decimal.js/decimal.mjs:
|
|
|
6349
6452
|
*)
|
|
6350
6453
|
*/
|
|
6351
6454
|
|
|
6352
|
-
export { AFTERMATH, AFTERMATH_MODULE, AggregatorClient5 as AggregatorClient, CETUS, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOKV2, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID2 as DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, Env, FLOWXV2, FLOWX_AMM_MODULE, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, JOIN_FUNC, KRIYA, KRIYAV3, 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, 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, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, 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, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, ZERO, composeType, createTarget, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
|
6455
|
+
export { AFSUI, AFTERMATH, AFTERMATH_MODULE, AggregatorClient5 as AggregatorClient, CETUS, CETUS_MODULE, CETUS_PUBLISHED_AT, CHECK_COINS_THRESHOLD_FUNC, CLOCK_ADDRESS, CoinInfoAddress, CoinStoreAddress, DEEPBOOKV2, DEEPBOOK_CLOB_V2_MODULE, DEEPBOOK_CUSTODIAN_V2_MODULE, DEEPBOOK_MODULE, DEEPBOOK_PACKAGE_ID2 as DEEPBOOK_PACKAGE_ID, DEEPBOOK_PUBLISHED_AT, Env, FLOWXV2, FLOWX_AMM_MODULE, FlashSwapA2BFunc, FlashSwapB2AFunc, FlashSwapFunc, FlashSwapWithPartnerA2BFunc, FlashSwapWithPartnerB2AFunc, FlashSwapWithPartnerFunc, HAEDAL, JOIN_FUNC, KRIYA, KRIYAV3, 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, 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, SWAP_A2B_FUNC, SWAP_B2A_FUNC, SuiZeroCoinFn, 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, TURBOS_MODULE, TURBOS_VERSIONED, TWO, U128, U64_MAX, U64_MAX_BN, UTILS_MODULE, VOLO, ZERO, composeType, createTarget, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getRouterResult, isSortedSymbols, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId };
|
package/dist/src/client.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export declare const FLOWXV2 = "FLOWX";
|
|
|
11
11
|
export declare const KRIYAV3 = "KRIYAV3";
|
|
12
12
|
export declare const TURBOS = "TURBOS";
|
|
13
13
|
export declare const AFTERMATH = "AFTERMATH";
|
|
14
|
+
export declare const HAEDAL = "HAEDAL";
|
|
15
|
+
export declare const VOLO = "VOLO";
|
|
16
|
+
export declare const AFSUI = "AFSUI";
|
|
14
17
|
export type BuildRouterSwapParams = {
|
|
15
18
|
routers: Router[];
|
|
16
19
|
byAmountIn: boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Afsui implements Dex {
|
|
4
|
+
private stakedSuiVault;
|
|
5
|
+
private safe;
|
|
6
|
+
private referVault;
|
|
7
|
+
private validator;
|
|
8
|
+
constructor(env: Env);
|
|
9
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Haedal implements Dex {
|
|
4
|
+
private stake;
|
|
5
|
+
constructor(env: Env);
|
|
6
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Transaction, TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import { AggregatorClient, Dex, Env, Path } from "..";
|
|
3
|
+
export declare class Volo implements Dex {
|
|
4
|
+
private nativePool;
|
|
5
|
+
private metadata;
|
|
6
|
+
constructor(env: Env);
|
|
7
|
+
swap(client: AggregatorClient, txb: Transaction, path: Path, inputCoin: TransactionObjectArgument): Promise<TransactionObjectArgument>;
|
|
8
|
+
}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -2,7 +2,6 @@ import Decimal from "decimal.js"
|
|
|
2
2
|
import { SuiClient } from "@mysten/sui/client"
|
|
3
3
|
import {
|
|
4
4
|
Transaction,
|
|
5
|
-
TransactionArgument,
|
|
6
5
|
TransactionObjectArgument,
|
|
7
6
|
} from "@mysten/sui/transactions"
|
|
8
7
|
import { Signer } from "@mysten/sui/dist/cjs/cryptography"
|
|
@@ -28,6 +27,9 @@ import { CalculateAmountLimit } from "./math"
|
|
|
28
27
|
import { buildInputCoin } from "./utils/coin"
|
|
29
28
|
import { CoinAsset } from "./types/sui"
|
|
30
29
|
import { KriyaV3 } from "./transaction/kriya_v3"
|
|
30
|
+
import { Haedal } from "./transaction/haedal"
|
|
31
|
+
import { Afsui } from "./transaction/afsui"
|
|
32
|
+
import { Volo } from "./transaction/volo"
|
|
31
33
|
|
|
32
34
|
export const CETUS = "CETUS"
|
|
33
35
|
export const DEEPBOOKV2 = "DEEPBOOK"
|
|
@@ -36,6 +38,9 @@ export const FLOWXV2 = "FLOWX"
|
|
|
36
38
|
export const KRIYAV3 = "KRIYAV3"
|
|
37
39
|
export const TURBOS = "TURBOS"
|
|
38
40
|
export const AFTERMATH = "AFTERMATH"
|
|
41
|
+
export const HAEDAL = "HAEDAL"
|
|
42
|
+
export const VOLO = "VOLO"
|
|
43
|
+
export const AFSUI = "AFSUI"
|
|
39
44
|
|
|
40
45
|
export type BuildRouterSwapParams = {
|
|
41
46
|
routers: Router[]
|
|
@@ -387,6 +392,12 @@ export class AggregatorClient {
|
|
|
387
392
|
return new Turbos(this.env)
|
|
388
393
|
case AFTERMATH:
|
|
389
394
|
return new Aftermath(this.env)
|
|
395
|
+
case HAEDAL:
|
|
396
|
+
return new Haedal(this.env)
|
|
397
|
+
case AFSUI:
|
|
398
|
+
return new Afsui(this.env)
|
|
399
|
+
case VOLO:
|
|
400
|
+
return new Volo(this.env)
|
|
390
401
|
default:
|
|
391
402
|
throw new Error(`Unsupported dex ${provider}`)
|
|
392
403
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionObjectArgument,
|
|
4
|
+
} from "@mysten/sui/transactions"
|
|
5
|
+
import { AggregatorClient, Dex, Env, Path } from ".."
|
|
6
|
+
import { SUI_SYSTEM_ADDRESS } from "@mysten/sui/utils"
|
|
7
|
+
|
|
8
|
+
export class Afsui implements Dex {
|
|
9
|
+
private stakedSuiVault: string
|
|
10
|
+
private safe: string
|
|
11
|
+
private referVault: string
|
|
12
|
+
private validator: string
|
|
13
|
+
|
|
14
|
+
constructor(env: Env) {
|
|
15
|
+
if (env !== Env.Mainnet) {
|
|
16
|
+
throw new Error("Afsui only supported on mainnet")
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
this.stakedSuiVault =
|
|
20
|
+
"0x2f8f6d5da7f13ea37daa397724280483ed062769813b6f31e9788e59cc88994d"
|
|
21
|
+
this.safe =
|
|
22
|
+
"0xeb685899830dd5837b47007809c76d91a098d52aabbf61e8ac467c59e5cc4610"
|
|
23
|
+
this.referVault =
|
|
24
|
+
"0x4ce9a19b594599536c53edb25d22532f82f18038dc8ef618afd00fbbfb9845ef"
|
|
25
|
+
this.validator =
|
|
26
|
+
"0xd30018ec3f5ff1a3c75656abf927a87d7f0529e6dc89c7ddd1bd27ecb05e3db2"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async swap(
|
|
30
|
+
client: AggregatorClient,
|
|
31
|
+
txb: Transaction,
|
|
32
|
+
path: Path,
|
|
33
|
+
inputCoin: TransactionObjectArgument
|
|
34
|
+
): Promise<TransactionObjectArgument> {
|
|
35
|
+
const { direction, from, target } = path
|
|
36
|
+
|
|
37
|
+
if (!direction) {
|
|
38
|
+
throw new Error("Afsui not support b2a swap")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target]
|
|
42
|
+
|
|
43
|
+
const args = [
|
|
44
|
+
txb.object(this.stakedSuiVault),
|
|
45
|
+
txb.object(this.safe),
|
|
46
|
+
txb.pure.address(SUI_SYSTEM_ADDRESS),
|
|
47
|
+
txb.object(this.referVault),
|
|
48
|
+
inputCoin,
|
|
49
|
+
txb.object(this.validator),
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
const res = txb.moveCall({
|
|
53
|
+
target: `${client.publishedAt()}::afsui::${func}`,
|
|
54
|
+
typeArguments: [coinAType, coinBType],
|
|
55
|
+
arguments: args,
|
|
56
|
+
}) as TransactionObjectArgument
|
|
57
|
+
|
|
58
|
+
return res
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionObjectArgument,
|
|
4
|
+
} from "@mysten/sui/transactions"
|
|
5
|
+
import { AggregatorClient, Dex, Env, Path } from ".."
|
|
6
|
+
import { SUI_SYSTEM_ADDRESS } from "@mysten/sui/utils"
|
|
7
|
+
|
|
8
|
+
export class Haedal implements Dex {
|
|
9
|
+
private stake: string
|
|
10
|
+
|
|
11
|
+
constructor(env: Env) {
|
|
12
|
+
if (env !== Env.Mainnet) {
|
|
13
|
+
throw new Error("Haedal only supported on mainnet")
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
this.stake =
|
|
17
|
+
"0x47b224762220393057ebf4f70501b6e657c3e56684737568439a04f80849b2ca"
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async swap(
|
|
21
|
+
client: AggregatorClient,
|
|
22
|
+
txb: Transaction,
|
|
23
|
+
path: Path,
|
|
24
|
+
inputCoin: TransactionObjectArgument
|
|
25
|
+
): Promise<TransactionObjectArgument> {
|
|
26
|
+
const { direction, from, target } = path
|
|
27
|
+
|
|
28
|
+
if (!direction) {
|
|
29
|
+
throw new Error("Haedal not support b2a swap")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target]
|
|
33
|
+
|
|
34
|
+
const args = [
|
|
35
|
+
txb.pure.address(SUI_SYSTEM_ADDRESS),
|
|
36
|
+
txb.object(this.stake),
|
|
37
|
+
inputCoin,
|
|
38
|
+
txb.pure.address("0x0"),
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
const res = txb.moveCall({
|
|
42
|
+
target: `${client.publishedAt()}::haedal::${func}`,
|
|
43
|
+
typeArguments: [coinAType, coinBType],
|
|
44
|
+
arguments: args,
|
|
45
|
+
}) as TransactionObjectArgument
|
|
46
|
+
|
|
47
|
+
return res
|
|
48
|
+
}
|
|
49
|
+
}
|
package/src/transaction/swap.ts
CHANGED
|
@@ -91,6 +91,8 @@ export async function swapInPools(
|
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
const event = valueData[tempIndex].parsedJson.data
|
|
94
|
+
console.log("event", JSON.stringify(event, null, 2))
|
|
95
|
+
|
|
94
96
|
const currentSqrtPrice = event.step_results[0].current_sqrt_price
|
|
95
97
|
|
|
96
98
|
const [decimalA, decimalB] = await Promise.all([
|
|
@@ -126,9 +128,9 @@ export async function swapInPools(
|
|
|
126
128
|
provider: "CETUS",
|
|
127
129
|
from: fromCoin,
|
|
128
130
|
target: targetCoin,
|
|
129
|
-
feeRate:
|
|
130
|
-
amountIn:
|
|
131
|
-
amountOut:
|
|
131
|
+
feeRate: event.fee_rate,
|
|
132
|
+
amountIn: event.amount_in,
|
|
133
|
+
amountOut: event.amount_out,
|
|
132
134
|
},
|
|
133
135
|
],
|
|
134
136
|
amountIn: new BN(event.amount_in ?? 0),
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Transaction,
|
|
3
|
+
TransactionObjectArgument,
|
|
4
|
+
} from "@mysten/sui/transactions"
|
|
5
|
+
import { AggregatorClient, Dex, Env, Path } from ".."
|
|
6
|
+
import { SUI_SYSTEM_ADDRESS } from "@mysten/sui/utils"
|
|
7
|
+
|
|
8
|
+
export class Volo implements Dex {
|
|
9
|
+
private nativePool: string
|
|
10
|
+
private metadata: string
|
|
11
|
+
|
|
12
|
+
constructor(env: Env) {
|
|
13
|
+
if (env !== Env.Mainnet) {
|
|
14
|
+
throw new Error("Volo only supported on mainnet")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.nativePool =
|
|
18
|
+
"0x7fa2faa111b8c65bea48a23049bfd81ca8f971a262d981dcd9a17c3825cb5baf"
|
|
19
|
+
this.metadata =
|
|
20
|
+
"0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async swap(
|
|
24
|
+
client: AggregatorClient,
|
|
25
|
+
txb: Transaction,
|
|
26
|
+
path: Path,
|
|
27
|
+
inputCoin: TransactionObjectArgument
|
|
28
|
+
): Promise<TransactionObjectArgument> {
|
|
29
|
+
const { direction, from, target } = path
|
|
30
|
+
|
|
31
|
+
if (!direction) {
|
|
32
|
+
throw new Error("Volo not support b2a swap")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const [func, coinAType, coinBType] = ["swap_a2b", from, target]
|
|
36
|
+
|
|
37
|
+
const args = [
|
|
38
|
+
txb.object(this.nativePool),
|
|
39
|
+
txb.object(this.metadata),
|
|
40
|
+
txb.pure.address(SUI_SYSTEM_ADDRESS),
|
|
41
|
+
inputCoin,
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
const res = txb.moveCall({
|
|
45
|
+
target: `${client.publishedAt()}::volo::${func}`,
|
|
46
|
+
typeArguments: [coinAType, coinBType],
|
|
47
|
+
arguments: args,
|
|
48
|
+
}) as TransactionObjectArgument
|
|
49
|
+
|
|
50
|
+
return res
|
|
51
|
+
}
|
|
52
|
+
}
|
package/tests/router.test.ts
CHANGED
|
@@ -27,18 +27,11 @@ describe("router module", () => {
|
|
|
27
27
|
const aggregatorURL = process.env.CETUS_AGGREGATOR!
|
|
28
28
|
const secret = process.env.SUI_WALLET_SECRET!
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const u8Array = new Uint8Array(byte)
|
|
36
|
-
const secretKey = fromB64(secret)
|
|
37
|
-
|
|
38
|
-
// keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
|
|
39
|
-
keypair = secret
|
|
40
|
-
? Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
|
|
41
|
-
: buildTestAccount()
|
|
30
|
+
if (secret) {
|
|
31
|
+
keypair = Ed25519Keypair.fromSecretKey(fromB64(secret).slice(1, 33))
|
|
32
|
+
} else {
|
|
33
|
+
keypair = buildTestAccount()
|
|
34
|
+
}
|
|
42
35
|
|
|
43
36
|
const wallet = keypair.getPublicKey().toSuiAddress()
|
|
44
37
|
|
|
@@ -85,12 +78,13 @@ describe("router module", () => {
|
|
|
85
78
|
|
|
86
79
|
test("Downgrade swap in route", async () => {
|
|
87
80
|
const amount = 1000000
|
|
81
|
+
const byAmountIn = false
|
|
88
82
|
|
|
89
|
-
const res = await client.swapInPools({
|
|
83
|
+
const res: any = await client.swapInPools({
|
|
90
84
|
from: M_USDC,
|
|
91
85
|
target: M_SUI,
|
|
92
86
|
amount: new BN(amount),
|
|
93
|
-
byAmountIn
|
|
87
|
+
byAmountIn,
|
|
94
88
|
pools: [
|
|
95
89
|
"0xcf994611fd4c48e277ce3ffd4d4364c914af2c3cbb05f7bf6facd371de688630",
|
|
96
90
|
],
|
|
@@ -98,8 +92,20 @@ describe("router module", () => {
|
|
|
98
92
|
|
|
99
93
|
if (res != null) {
|
|
100
94
|
console.log(JSON.stringify(res, null, 2))
|
|
95
|
+
const txb = new Transaction()
|
|
96
|
+
await client.fastRouterSwap({
|
|
97
|
+
routers: res.routeData.routes,
|
|
98
|
+
byAmountIn,
|
|
99
|
+
txb,
|
|
100
|
+
slippage: 0.01,
|
|
101
|
+
isMergeTragetCoin: false,
|
|
102
|
+
refreshAllCoins: true,
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
let result = await client.devInspectTransactionBlock(txb)
|
|
106
|
+
console.log("🚀 ~ file: router.test.ts:114 ~ test ~ result:", result)
|
|
101
107
|
}
|
|
102
|
-
})
|
|
108
|
+
}, 10000)
|
|
103
109
|
|
|
104
110
|
test("Find router", async () => {
|
|
105
111
|
const amount = "4239267610000000000"
|
|
@@ -122,10 +128,10 @@ describe("router module", () => {
|
|
|
122
128
|
|
|
123
129
|
test("Build router tx", async () => {
|
|
124
130
|
const byAmountIn = true
|
|
125
|
-
const amount = "
|
|
131
|
+
const amount = "100000"
|
|
126
132
|
|
|
127
|
-
const from =
|
|
128
|
-
const target =
|
|
133
|
+
const from = M_USDC
|
|
134
|
+
const target = M_SUI
|
|
129
135
|
|
|
130
136
|
const res = await client.findRouters({
|
|
131
137
|
from,
|