@cetusprotocol/aggregator-sdk 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/.env.example +4 -0
  2. package/README.md +128 -0
  3. package/bun.lockb +0 -0
  4. package/dist/index.d.mts +266 -0
  5. package/dist/index.d.ts +266 -0
  6. package/dist/index.js +6817 -0
  7. package/dist/index.mjs +6738 -0
  8. package/dist/src/client.d.ts +87 -0
  9. package/dist/src/config.d.ts +26 -0
  10. package/dist/src/const.d.ts +75 -0
  11. package/dist/src/errors.d.ts +31 -0
  12. package/dist/src/index.d.ts +5 -0
  13. package/dist/src/math.d.ts +5 -0
  14. package/dist/src/test_data.test.d.ts +8 -0
  15. package/dist/src/transaction/aftermath.d.ts +24 -0
  16. package/dist/src/transaction/cetus.d.ts +39 -0
  17. package/dist/src/transaction/common.d.ts +12 -0
  18. package/dist/src/transaction/deepbook.d.ts +21 -0
  19. package/dist/src/transaction/flowx.d.ts +20 -0
  20. package/dist/src/transaction/index.d.ts +1 -0
  21. package/dist/src/transaction/kriya.d.ts +21 -0
  22. package/dist/src/transaction/router.d.ts +6 -0
  23. package/dist/src/transaction/swap.d.ts +5 -0
  24. package/dist/src/transaction/turbos.d.ts +22 -0
  25. package/dist/src/types/CoinAssist.d.ts +122 -0
  26. package/dist/src/types/sui.d.ts +112 -0
  27. package/dist/src/utils/account_cap.d.ts +7 -0
  28. package/dist/src/utils/coin.d.ts +4 -0
  29. package/dist/src/utils/coin.spec.d.ts +1 -0
  30. package/dist/src/utils/contracts.d.ts +16 -0
  31. package/dist/src/utils/index.d.ts +1 -0
  32. package/dist/src/utils/transaction.d.ts +3 -0
  33. package/dist/tests/router.test.d.ts +2 -0
  34. package/dist/tests/wallet.test.d.ts +1 -0
  35. package/jest.config.mjs +13 -0
  36. package/package.json +41 -0
  37. package/src/client.ts +383 -0
  38. package/src/config.ts +65 -0
  39. package/src/const.ts +126 -0
  40. package/src/errors.ts +44 -0
  41. package/src/index.ts +5 -0
  42. package/src/math.ts +37 -0
  43. package/src/test_data.test.ts +17 -0
  44. package/src/transaction/aftermath.ts +143 -0
  45. package/src/transaction/cetus.ts +282 -0
  46. package/src/transaction/common.ts +169 -0
  47. package/src/transaction/deepbook.ts +126 -0
  48. package/src/transaction/flowx.ts +98 -0
  49. package/src/transaction/index.ts +1 -0
  50. package/src/transaction/kriya.ts +77 -0
  51. package/src/transaction/router.ts +345 -0
  52. package/src/transaction/swap.ts +163 -0
  53. package/src/transaction/turbos.ts +114 -0
  54. package/src/types/CoinAssist.ts +217 -0
  55. package/src/types/sui.ts +148 -0
  56. package/src/utils/account_cap.ts +62 -0
  57. package/src/utils/coin.spec.ts +10 -0
  58. package/src/utils/coin.ts +61 -0
  59. package/src/utils/contracts.ts +136 -0
  60. package/src/utils/index.ts +1 -0
  61. package/src/utils/transaction.ts +20 -0
  62. package/tests/router.test.ts +249 -0
  63. package/tests/wallet.test.ts +17 -0
  64. package/tsconfig.json +22 -0
  65. package/tsup.config.ts +23 -0
  66. package/version.mjs +28 -0
package/.env.example ADDED
@@ -0,0 +1,4 @@
1
+ SUI_PRC=
2
+ SUI_WALLET_SECRET=
3
+ SUI_WALLET_MNEMONICS=
4
+ CETUS_AGGREGATOR=
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # Cetus Aggregator Typescript SDK
2
+
3
+ Cetus plus swap aggregator is a high-speed and easy-to-integrate solution designed to optimize your trading experience on the Sui blockchain. This aggregator integrates multiple mainstream decentralized exchanges (DEX) on the Sui chain, including various types of trading platforms, providing users with the best trading prices and the lowest slippage.
4
+
5
+ Core Advantages:
6
+
7
+ High-Speed Transactions: Thanks to advanced algorithms and efficient architecture, our aggregator can execute transactions at lightning speed, ensuring users get the best opportunities in a rapidly changing market.
8
+
9
+ Easy Integration: The aggregator is designed to be simple and easy to integrate. Whether you are an individual developer or a large project team, you can quickly connect and deploy.
10
+
11
+ Multi-Platform Support: Currently, we have integrated multiple mainstream DEXs on the Sui chain, including cetus, deepbook, kriya, flowx, aftermath, turbos etc, allowing users to enjoy a diversified trading experience on a single platform.
12
+
13
+ By using our aggregator, you can trade more efficiently and securely on the Sui blockchain, fully leveraging the various opportunities brought by decentralized finance (DeFi).
14
+
15
+ # Install
16
+
17
+ The SDK is published to npm registry with experimental version. To use the SDK in your project, you can
18
+
19
+ ```
20
+ npm install aggregator-sdk@0.0.0-experimental-20240521171554
21
+ ```
22
+
23
+ # Usage
24
+
25
+ ## 1. Init client with rpc and package config
26
+
27
+ ```typescript
28
+ // used to do simulate swap and swap
29
+ const fullNodeURL = process.env.SUI_RPC!
30
+
31
+ // used to do swap
32
+ const secret = process.env.SUI_WALLET_SECRET!
33
+
34
+ // provider by cetus
35
+ const aggregatorURL = "https://api-sui.cetus.zone/router_v2"
36
+
37
+ // process wallet secret
38
+ const byte = Buffer.from(secret, "base64")
39
+ const u8Array = new Uint8Array(byte)
40
+ keypair = secret
41
+ ? Ed25519Keypair.fromSecretKey(u8Array.slice(1, 33))
42
+ : buildTestAccount()
43
+ const wallet = keypair.getPublicKey().toSuiAddress()
44
+
45
+ const aggregatorPackage = {
46
+ packageName: "aggregator",
47
+ packageId:
48
+ "0x640d44dbdc0ede165c7cc417d7f57f1b09648083109de7132c6b3fb15861f5ee",
49
+ publishedAt:
50
+ "0x640d44dbdc0ede165c7cc417d7f57f1b09648083109de7132c6b3fb15861f5ee",
51
+ }
52
+
53
+ const integratePackage = {
54
+ packageName: "integrate",
55
+ packageId:
56
+ "0x996c4d9480708fb8b92aa7acf819fb0497b5ec8e65ba06601cae2fb6db3312c3",
57
+ publishedAt:
58
+ "0x8faab90228e4c4df91c41626bbaefa19fc25c514405ac64de54578dec9e6f5ee",
59
+ }
60
+
61
+ const config = new AggregatorConfig(
62
+ aggregatorURL,
63
+ fullNodeURL,
64
+ wallet,
65
+ [aggregatorPackage, integratePackage],
66
+ ENV.MAINNET
67
+ )
68
+ const client = new AggregatorClient(config)
69
+ ```
70
+
71
+ ## 2. Get best router swap result from aggregator service
72
+
73
+ ```typescript
74
+ const amount = new BN(1000000)
75
+
76
+ const from = M_SUI // 0x2::sui::SUI
77
+ const target = M_CETUS // 0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS
78
+
79
+ const routerRes = await client.findRouter({
80
+ from,
81
+ target,
82
+ amount,
83
+ byAmountIn: true, // true means fix input amount, false means fix output amount
84
+ depth: 3, // max allow 3, means 3 hops
85
+ splitAlgorithm: null, // select split algotirhm, recommended default set null
86
+ splitFactor: null,
87
+ splitCount: 100, // set max expect split count
88
+ providers: [
89
+ "AFTERMATH",
90
+ "CETUS",
91
+ "DEEPBOOK",
92
+ "KRIYA",
93
+ "FLOWX",
94
+ "AFTERMATH",
95
+ "TRUBOS",
96
+ ], // now max support above seven platform.
97
+ })
98
+
99
+ if (routerRes != null) {
100
+ console.log(JSON.stringify(res, null, 2))
101
+ }
102
+ ```
103
+
104
+ ## 3. Confirm and do swap
105
+
106
+ ```typescript
107
+ if (routerRes != null) {
108
+ const routerTx = await client.routerSwap({
109
+ routers: res.routes,
110
+ amountIn: res.amountIn,
111
+ amountOut: res.amountOut,
112
+ byAmountIn,
113
+ slippage: 0.01,
114
+ fromCoinType: from,
115
+ targetCoinType: target,
116
+ partner: undefined,
117
+ isMergeTragetCoin: true,
118
+ })
119
+
120
+ let result = await client.devInspectTransactionBlock(routerTx, keypair)
121
+
122
+ if (result.effects.status.status === "success") {
123
+ console.log("Sim exec transaction success")
124
+ const result = await client.signAndExecuteTransaction(routerTx, keypair)
125
+ }
126
+ console.log("result", result)
127
+ }
128
+ ```
package/bun.lockb ADDED
Binary file
@@ -0,0 +1,266 @@
1
+ import * as _mysten_sui_client from '@mysten/sui/client';
2
+ import { SuiClient } from '@mysten/sui/client';
3
+ import Decimal from 'decimal.js';
4
+ import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
5
+ import { Signer } from '@mysten/sui/dist/cjs/cryptography';
6
+ import BN from 'bn.js';
7
+
8
+ type Package = {
9
+ packageName: string;
10
+ packageId: string;
11
+ publishedAt: string;
12
+ };
13
+ declare enum ENV {
14
+ MAINNET = 0,
15
+ TESTNET = 1
16
+ }
17
+ declare class AggregatorConfig {
18
+ private aggregatorUrl;
19
+ private fullNodeUrl;
20
+ private wallet;
21
+ private packages;
22
+ private env;
23
+ constructor(aggregatorUrl: string, fullNodeUrl: string, wallet: string, packages: Package[], env: ENV);
24
+ getAggregatorUrl(): string;
25
+ getFullNodeUrl(): string;
26
+ getWallet(): string;
27
+ getENV(): ENV;
28
+ getPackages(): Package[];
29
+ getPackage(packageName: string): Package | undefined;
30
+ addPackage(newPackage: Package): void;
31
+ removePackageById(packageId: string): void;
32
+ findPackageById(packageId: string): Package | undefined;
33
+ }
34
+
35
+ /**
36
+ * Represents a SUI address, which is a string.
37
+ */
38
+ type SuiAddress = string;
39
+ /**
40
+ * Represents a SUI object identifier, which is a string.
41
+ */
42
+ type SuiObjectIdType = string;
43
+ /**
44
+ * Represents a SUI struct tag.
45
+ */
46
+ type SuiStructTag = {
47
+ /**
48
+ * The full address of the struct.
49
+ */
50
+ full_address: string;
51
+ /**
52
+ * The source address of the struct.
53
+ */
54
+ source_address: string;
55
+ /**
56
+ * The address of the struct.
57
+ */
58
+ address: SuiAddress;
59
+ /**
60
+ * The module to which the struct belongs.
61
+ */
62
+ module: string;
63
+ /**
64
+ * The name of the struct.
65
+ */
66
+ name: string;
67
+ /**
68
+ * An array of type arguments (SUI addresses) for the struct.
69
+ */
70
+ type_arguments: SuiAddress[];
71
+ };
72
+ /**
73
+ * Represents a coin asset with address, object ID, and balance information.
74
+ */
75
+ type CoinAsset = {
76
+ /**
77
+ * The address type of the coin asset.
78
+ */
79
+ coinAddress: SuiAddress;
80
+ /**
81
+ * The object identifier of the coin asset.
82
+ */
83
+ coinObjectId: SuiObjectIdType;
84
+ /**
85
+ * The balance amount of the coin asset.
86
+ */
87
+ balance: bigint;
88
+ };
89
+
90
+ type ExtendedDetails = {
91
+ aftermathPoolFlatness?: number;
92
+ aftermathLpSupplyType?: string;
93
+ turbosFeeType?: string;
94
+ };
95
+ type Path = {
96
+ id: string;
97
+ a2b: boolean;
98
+ provider: string;
99
+ from: string;
100
+ target: string;
101
+ feeRate: number;
102
+ amountIn: number;
103
+ amountOut: number;
104
+ extendedDetails?: ExtendedDetails;
105
+ version?: string;
106
+ };
107
+ type Router = {
108
+ path: Path[];
109
+ amountIn: BN;
110
+ amountOut: BN;
111
+ initialPrice: Decimal;
112
+ };
113
+ type RouterData = {
114
+ amountIn: BN;
115
+ amountOut: BN;
116
+ routes: Router[];
117
+ };
118
+ type AggregatorResponse = {
119
+ code: number;
120
+ msg: string;
121
+ data: RouterData;
122
+ };
123
+ type BuildRouterSwapParams = {
124
+ routers: Router[];
125
+ amountIn: BN;
126
+ amountOut: BN;
127
+ byAmountIn: boolean;
128
+ slippage: number;
129
+ fromCoinType: string;
130
+ targetCoinType: string;
131
+ partner?: string;
132
+ isMergeTragetCoin?: boolean;
133
+ refreshAllCoins?: boolean;
134
+ };
135
+ interface FindRouterParams {
136
+ from: string;
137
+ target: string;
138
+ amount: BN;
139
+ byAmountIn: boolean;
140
+ depth: number | null;
141
+ splitAlgorithm: string | null;
142
+ splitFactor: number | null;
143
+ splitCount: number | null;
144
+ providers: string[] | null;
145
+ }
146
+ interface SwapInPoolsParams {
147
+ from: string;
148
+ target: string;
149
+ amount: BN;
150
+ byAmountIn: boolean;
151
+ pools: string[];
152
+ }
153
+ interface SwapInPoolsResult {
154
+ isExceed: boolean;
155
+ routeData?: RouterData;
156
+ }
157
+ declare class AggregatorClient {
158
+ private config;
159
+ private wallet;
160
+ private client;
161
+ private allCoins;
162
+ constructor(config: AggregatorConfig);
163
+ getAllCoins(): Promise<CoinAsset[]>;
164
+ findRouter(fromRouterParams: FindRouterParams): Promise<RouterData | null>;
165
+ swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
166
+ routerSwap(params: BuildRouterSwapParams): Promise<Transaction>;
167
+ signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
168
+ devInspectTransactionBlock(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.DevInspectResults>;
169
+ sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
170
+ }
171
+
172
+ declare function expectInputRouterSwap(client: SuiClient, params: BuildRouterSwapParams, txb: Transaction, fromCoin: TransactionObjectArgument, config: AggregatorConfig, partner?: string): Promise<TransactionObjectArgument[]>;
173
+ declare function expectOutputRouterSwap(params: BuildRouterSwapParams, txb: Transaction, fromCoin: TransactionObjectArgument, config: AggregatorConfig, partner?: string): Promise<TransactionObjectArgument[]>;
174
+
175
+ declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
176
+ declare function composeType(address: string, generics: SuiAddress[]): SuiAddress;
177
+ declare function composeType(address: string, struct: string, generics?: SuiAddress[]): SuiAddress;
178
+ declare function composeType(address: string, module: string, struct: string, generics?: SuiAddress[]): SuiAddress;
179
+ declare function extractAddressFromType(type: string): string;
180
+ declare function extractStructTagFromType(type: string): SuiStructTag;
181
+ declare function normalizeCoinType(coinType: string): string;
182
+ declare function fixSuiObjectId(value: string): string;
183
+ /**
184
+ * Recursively traverses the given data object and patches any string values that represent Sui object IDs.
185
+ *
186
+ * @param {any} data - The data object to be patched.
187
+ */
188
+ declare function patchFixSuiObjectId(data: any): void;
189
+ declare function createTarget(packageName: string, moduleName: string, functionName: string): `${string}::${string}::${string}`;
190
+
191
+ /**
192
+ * The address representing the clock in the system.
193
+ */
194
+ declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
195
+ /**
196
+ * The address for CoinInfo module.
197
+ */
198
+ declare const CoinInfoAddress = "0x1::coin::CoinInfo";
199
+ /**
200
+ * The address for CoinStore module.
201
+ */
202
+ declare const CoinStoreAddress = "0x1::coin::CoinStore";
203
+ declare const SuiZeroCoinFn = "0x2::coin::zero";
204
+ declare const AGGREGATOR = "aggregator";
205
+ declare const CETUS_DEX = "CETUS";
206
+ declare const DEEPBOOK_DEX = "DEEPBOOK";
207
+ declare const KRIYA_DEX = "KRIYA";
208
+ declare const FLOWX_AMM = "FLOWX";
209
+ declare const TURBOS_DEX = "TURBOS";
210
+ declare const AFTERMATH_AMM = "AFTERMATH";
211
+ declare const INTEGRATE = "integrate";
212
+ declare const CETUS_MODULE = "cetus";
213
+ declare const DEEPBOOK_MODULE = "deepbook";
214
+ declare const KRIYA_MODULE = "kriya";
215
+ declare const UTILS_MODULE = "utils";
216
+ declare const POOL_MODULT = "pool";
217
+ declare const PAY_MODULE = "pay";
218
+ declare const FLOWX_AMM_MODULE = "flowx_amm";
219
+ declare const TURBOS_MODULE = "turbos";
220
+ declare const AFTERMATH_MODULE = "aftermath";
221
+ declare const DEEPBOOK_CUSTODIAN_V2_MODULE = "custodian_v2";
222
+ declare const DEEPBOOK_CLOB_V2_MODULE = "clob_v2";
223
+ declare const FlashSwapFunc = "flash_swap";
224
+ declare const FlashSwapWithPartnerFunc = "flash_swap_with_partner";
225
+ declare const RepayFalshSwapFunc = "repay_flash_swap";
226
+ declare const RepayFlashSwapWithPartnerFunc = "repay_flash_swap_with_partner";
227
+ declare const FlashSwapA2BFunc = "flash_swap_a2b";
228
+ declare const FlashSwapB2AFunc = "flash_swap_b2a";
229
+ declare const FlashSwapWithPartnerA2BFunc = "flash_swap_with_partner_a2b";
230
+ declare const FlashSwapWithPartnerB2AFunc = "flash_swap_with_partner_b2a";
231
+ declare const REPAY_FLASH_SWAP_A2B_FUNC = "repay_flash_swap_a2b";
232
+ declare const REPAY_FLASH_SWAP_B2A_FUNC = "repay_flash_swap_b2a";
233
+ declare const REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC = "repay_flash_swap_with_partner_a2b";
234
+ declare const REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC = "repay_flash_swap_with_partner_b2a";
235
+ declare const SWAP_A2B_FUNC = "swap_a2b";
236
+ declare const SWAP_B2A_FUNC = "swap_b2a";
237
+ declare const TRANSFER_OR_DESTORY_COIN_FUNC = "transfer_or_destroy_coin";
238
+ declare const CHECK_COINS_THRESHOLD_FUNC = "check_coins_threshold";
239
+ declare const JOIN_FUNC = "join_vec";
240
+ declare const TRANSFER_ACCOUNT_CAP = "transfer_account_cap";
241
+ declare const DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
242
+ declare const DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
243
+ declare const CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
244
+ declare const MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
245
+ declare const TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
246
+ declare const ZERO: BN;
247
+ declare const ONE: BN;
248
+ declare const TWO: BN;
249
+ declare const U128: BN;
250
+ declare const U64_MAX_BN: BN;
251
+ declare const U64_MAX = "18446744073709551615";
252
+ declare const MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
253
+ declare const TESTNET_FLOWX_AMM_CONTAINER_ID = "";
254
+ declare const TURBOS_VERSIONED = "0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f";
255
+ declare const MAINNET_AFTERMATH_REGISTRY_ID = "0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae";
256
+ declare const TESTNET_AFTERMATH_REGISTRY_ID = "";
257
+ declare const MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4";
258
+ declare const TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "";
259
+ declare const MAINNET_AFTERMATH_TREASURY_ID = "0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce";
260
+ declare const TESTNET_AFTERMATH_TREASURY_ID = "";
261
+ declare const MAINNET_AFTERMATH_INSURANCE_FUND_ID = "0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b";
262
+ declare const TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
263
+ declare const MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
264
+ declare const TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
265
+
266
+ 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, 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, patchFixSuiObjectId };
@@ -0,0 +1,266 @@
1
+ import * as _mysten_sui_client from '@mysten/sui/client';
2
+ import { SuiClient } from '@mysten/sui/client';
3
+ import Decimal from 'decimal.js';
4
+ import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
5
+ import { Signer } from '@mysten/sui/dist/cjs/cryptography';
6
+ import BN from 'bn.js';
7
+
8
+ type Package = {
9
+ packageName: string;
10
+ packageId: string;
11
+ publishedAt: string;
12
+ };
13
+ declare enum ENV {
14
+ MAINNET = 0,
15
+ TESTNET = 1
16
+ }
17
+ declare class AggregatorConfig {
18
+ private aggregatorUrl;
19
+ private fullNodeUrl;
20
+ private wallet;
21
+ private packages;
22
+ private env;
23
+ constructor(aggregatorUrl: string, fullNodeUrl: string, wallet: string, packages: Package[], env: ENV);
24
+ getAggregatorUrl(): string;
25
+ getFullNodeUrl(): string;
26
+ getWallet(): string;
27
+ getENV(): ENV;
28
+ getPackages(): Package[];
29
+ getPackage(packageName: string): Package | undefined;
30
+ addPackage(newPackage: Package): void;
31
+ removePackageById(packageId: string): void;
32
+ findPackageById(packageId: string): Package | undefined;
33
+ }
34
+
35
+ /**
36
+ * Represents a SUI address, which is a string.
37
+ */
38
+ type SuiAddress = string;
39
+ /**
40
+ * Represents a SUI object identifier, which is a string.
41
+ */
42
+ type SuiObjectIdType = string;
43
+ /**
44
+ * Represents a SUI struct tag.
45
+ */
46
+ type SuiStructTag = {
47
+ /**
48
+ * The full address of the struct.
49
+ */
50
+ full_address: string;
51
+ /**
52
+ * The source address of the struct.
53
+ */
54
+ source_address: string;
55
+ /**
56
+ * The address of the struct.
57
+ */
58
+ address: SuiAddress;
59
+ /**
60
+ * The module to which the struct belongs.
61
+ */
62
+ module: string;
63
+ /**
64
+ * The name of the struct.
65
+ */
66
+ name: string;
67
+ /**
68
+ * An array of type arguments (SUI addresses) for the struct.
69
+ */
70
+ type_arguments: SuiAddress[];
71
+ };
72
+ /**
73
+ * Represents a coin asset with address, object ID, and balance information.
74
+ */
75
+ type CoinAsset = {
76
+ /**
77
+ * The address type of the coin asset.
78
+ */
79
+ coinAddress: SuiAddress;
80
+ /**
81
+ * The object identifier of the coin asset.
82
+ */
83
+ coinObjectId: SuiObjectIdType;
84
+ /**
85
+ * The balance amount of the coin asset.
86
+ */
87
+ balance: bigint;
88
+ };
89
+
90
+ type ExtendedDetails = {
91
+ aftermathPoolFlatness?: number;
92
+ aftermathLpSupplyType?: string;
93
+ turbosFeeType?: string;
94
+ };
95
+ type Path = {
96
+ id: string;
97
+ a2b: boolean;
98
+ provider: string;
99
+ from: string;
100
+ target: string;
101
+ feeRate: number;
102
+ amountIn: number;
103
+ amountOut: number;
104
+ extendedDetails?: ExtendedDetails;
105
+ version?: string;
106
+ };
107
+ type Router = {
108
+ path: Path[];
109
+ amountIn: BN;
110
+ amountOut: BN;
111
+ initialPrice: Decimal;
112
+ };
113
+ type RouterData = {
114
+ amountIn: BN;
115
+ amountOut: BN;
116
+ routes: Router[];
117
+ };
118
+ type AggregatorResponse = {
119
+ code: number;
120
+ msg: string;
121
+ data: RouterData;
122
+ };
123
+ type BuildRouterSwapParams = {
124
+ routers: Router[];
125
+ amountIn: BN;
126
+ amountOut: BN;
127
+ byAmountIn: boolean;
128
+ slippage: number;
129
+ fromCoinType: string;
130
+ targetCoinType: string;
131
+ partner?: string;
132
+ isMergeTragetCoin?: boolean;
133
+ refreshAllCoins?: boolean;
134
+ };
135
+ interface FindRouterParams {
136
+ from: string;
137
+ target: string;
138
+ amount: BN;
139
+ byAmountIn: boolean;
140
+ depth: number | null;
141
+ splitAlgorithm: string | null;
142
+ splitFactor: number | null;
143
+ splitCount: number | null;
144
+ providers: string[] | null;
145
+ }
146
+ interface SwapInPoolsParams {
147
+ from: string;
148
+ target: string;
149
+ amount: BN;
150
+ byAmountIn: boolean;
151
+ pools: string[];
152
+ }
153
+ interface SwapInPoolsResult {
154
+ isExceed: boolean;
155
+ routeData?: RouterData;
156
+ }
157
+ declare class AggregatorClient {
158
+ private config;
159
+ private wallet;
160
+ private client;
161
+ private allCoins;
162
+ constructor(config: AggregatorConfig);
163
+ getAllCoins(): Promise<CoinAsset[]>;
164
+ findRouter(fromRouterParams: FindRouterParams): Promise<RouterData | null>;
165
+ swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
166
+ routerSwap(params: BuildRouterSwapParams): Promise<Transaction>;
167
+ signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
168
+ devInspectTransactionBlock(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.DevInspectResults>;
169
+ sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
170
+ }
171
+
172
+ declare function expectInputRouterSwap(client: SuiClient, params: BuildRouterSwapParams, txb: Transaction, fromCoin: TransactionObjectArgument, config: AggregatorConfig, partner?: string): Promise<TransactionObjectArgument[]>;
173
+ declare function expectOutputRouterSwap(params: BuildRouterSwapParams, txb: Transaction, fromCoin: TransactionObjectArgument, config: AggregatorConfig, partner?: string): Promise<TransactionObjectArgument[]>;
174
+
175
+ declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
176
+ declare function composeType(address: string, generics: SuiAddress[]): SuiAddress;
177
+ declare function composeType(address: string, struct: string, generics?: SuiAddress[]): SuiAddress;
178
+ declare function composeType(address: string, module: string, struct: string, generics?: SuiAddress[]): SuiAddress;
179
+ declare function extractAddressFromType(type: string): string;
180
+ declare function extractStructTagFromType(type: string): SuiStructTag;
181
+ declare function normalizeCoinType(coinType: string): string;
182
+ declare function fixSuiObjectId(value: string): string;
183
+ /**
184
+ * Recursively traverses the given data object and patches any string values that represent Sui object IDs.
185
+ *
186
+ * @param {any} data - The data object to be patched.
187
+ */
188
+ declare function patchFixSuiObjectId(data: any): void;
189
+ declare function createTarget(packageName: string, moduleName: string, functionName: string): `${string}::${string}::${string}`;
190
+
191
+ /**
192
+ * The address representing the clock in the system.
193
+ */
194
+ declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
195
+ /**
196
+ * The address for CoinInfo module.
197
+ */
198
+ declare const CoinInfoAddress = "0x1::coin::CoinInfo";
199
+ /**
200
+ * The address for CoinStore module.
201
+ */
202
+ declare const CoinStoreAddress = "0x1::coin::CoinStore";
203
+ declare const SuiZeroCoinFn = "0x2::coin::zero";
204
+ declare const AGGREGATOR = "aggregator";
205
+ declare const CETUS_DEX = "CETUS";
206
+ declare const DEEPBOOK_DEX = "DEEPBOOK";
207
+ declare const KRIYA_DEX = "KRIYA";
208
+ declare const FLOWX_AMM = "FLOWX";
209
+ declare const TURBOS_DEX = "TURBOS";
210
+ declare const AFTERMATH_AMM = "AFTERMATH";
211
+ declare const INTEGRATE = "integrate";
212
+ declare const CETUS_MODULE = "cetus";
213
+ declare const DEEPBOOK_MODULE = "deepbook";
214
+ declare const KRIYA_MODULE = "kriya";
215
+ declare const UTILS_MODULE = "utils";
216
+ declare const POOL_MODULT = "pool";
217
+ declare const PAY_MODULE = "pay";
218
+ declare const FLOWX_AMM_MODULE = "flowx_amm";
219
+ declare const TURBOS_MODULE = "turbos";
220
+ declare const AFTERMATH_MODULE = "aftermath";
221
+ declare const DEEPBOOK_CUSTODIAN_V2_MODULE = "custodian_v2";
222
+ declare const DEEPBOOK_CLOB_V2_MODULE = "clob_v2";
223
+ declare const FlashSwapFunc = "flash_swap";
224
+ declare const FlashSwapWithPartnerFunc = "flash_swap_with_partner";
225
+ declare const RepayFalshSwapFunc = "repay_flash_swap";
226
+ declare const RepayFlashSwapWithPartnerFunc = "repay_flash_swap_with_partner";
227
+ declare const FlashSwapA2BFunc = "flash_swap_a2b";
228
+ declare const FlashSwapB2AFunc = "flash_swap_b2a";
229
+ declare const FlashSwapWithPartnerA2BFunc = "flash_swap_with_partner_a2b";
230
+ declare const FlashSwapWithPartnerB2AFunc = "flash_swap_with_partner_b2a";
231
+ declare const REPAY_FLASH_SWAP_A2B_FUNC = "repay_flash_swap_a2b";
232
+ declare const REPAY_FLASH_SWAP_B2A_FUNC = "repay_flash_swap_b2a";
233
+ declare const REPAY_FLASH_SWAP_WITH_PARTNER_A2B_FUNC = "repay_flash_swap_with_partner_a2b";
234
+ declare const REPAY_FLASH_SWAP_WITH_PARTNER_B2A_FUNC = "repay_flash_swap_with_partner_b2a";
235
+ declare const SWAP_A2B_FUNC = "swap_a2b";
236
+ declare const SWAP_B2A_FUNC = "swap_b2a";
237
+ declare const TRANSFER_OR_DESTORY_COIN_FUNC = "transfer_or_destroy_coin";
238
+ declare const CHECK_COINS_THRESHOLD_FUNC = "check_coins_threshold";
239
+ declare const JOIN_FUNC = "join_vec";
240
+ declare const TRANSFER_ACCOUNT_CAP = "transfer_account_cap";
241
+ declare const DEEPBOOK_PACKAGE_ID = "0x000000000000000000000000000000000000000000000000000000000000dee9";
242
+ declare const DEEPBOOK_PUBLISHED_AT = "0x000000000000000000000000000000000000000000000000000000000000dee9";
243
+ declare const CETUS_PUBLISHED_AT = "0x70968826ad1b4ba895753f634b0aea68d0672908ca1075a2abdf0fc9e0b2fc6a";
244
+ declare const MAINNET_CETUS_GLOBAL_CONFIG_ID = "0xdaa46292632c3c4d8f31f23ea0f9b36a28ff3677e9684980e4438403a67a3d8f";
245
+ declare const TESTNET_CETUS_GLOBAL_CONFIG_ID = "0x6f4149091a5aea0e818e7243a13adcfb403842d670b9a2089de058512620687a";
246
+ declare const ZERO: BN;
247
+ declare const ONE: BN;
248
+ declare const TWO: BN;
249
+ declare const U128: BN;
250
+ declare const U64_MAX_BN: BN;
251
+ declare const U64_MAX = "18446744073709551615";
252
+ declare const MAINNET_FLOWX_AMM_CONTAINER_ID = "0xb65dcbf63fd3ad5d0ebfbf334780dc9f785eff38a4459e37ab08fa79576ee511";
253
+ declare const TESTNET_FLOWX_AMM_CONTAINER_ID = "";
254
+ declare const TURBOS_VERSIONED = "0xf1cf0e81048df168ebeb1b8030fad24b3e0b53ae827c25053fff0779c1445b6f";
255
+ declare const MAINNET_AFTERMATH_REGISTRY_ID = "0xfcc774493db2c45c79f688f88d28023a3e7d98e4ee9f48bbf5c7990f651577ae";
256
+ declare const TESTNET_AFTERMATH_REGISTRY_ID = "";
257
+ declare const MAINNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "0xf194d9b1bcad972e45a7dd67dd49b3ee1e3357a00a50850c52cd51bb450e13b4";
258
+ declare const TESTNET_AFTERMATH_PROTOCOL_FEE_VAULT_ID = "";
259
+ declare const MAINNET_AFTERMATH_TREASURY_ID = "0x28e499dff5e864a2eafe476269a4f5035f1c16f338da7be18b103499abf271ce";
260
+ declare const TESTNET_AFTERMATH_TREASURY_ID = "";
261
+ declare const MAINNET_AFTERMATH_INSURANCE_FUND_ID = "0xf0c40d67b078000e18032334c3325c47b9ec9f3d9ae4128be820d54663d14e3b";
262
+ declare const TESTNET_AFTERMATH_INSURANCE_FUND_ID = "";
263
+ declare const MAINNET_AFTERMATH_REFERRAL_VAULT_ID = "0x35d35b0e5b177593d8c3a801462485572fc30861e6ce96a55af6dc4730709278";
264
+ declare const TESTNET_AFTERMATH_REFERRAL_VAULT_ID = "";
265
+
266
+ 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, 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, patchFixSuiObjectId };