@cetusprotocol/aggregator-sdk 0.3.16 → 0.3.18

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 (51) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.mts +33 -11
  3. package/dist/index.d.ts +33 -11
  4. package/dist/index.js +209 -89
  5. package/dist/index.mjs +204 -89
  6. package/dist/src/api.d.ts +2 -0
  7. package/dist/src/client.d.ts +25 -9
  8. package/dist/src/transaction/afsui.d.ts +1 -1
  9. package/dist/src/transaction/aftermath.d.ts +1 -1
  10. package/dist/src/transaction/alphafi.d.ts +7 -0
  11. package/dist/src/transaction/bluefin.d.ts +1 -1
  12. package/dist/src/transaction/bluemove.d.ts +1 -1
  13. package/dist/src/transaction/cetus.d.ts +3 -3
  14. package/dist/src/transaction/deepbook_v2.d.ts +1 -1
  15. package/dist/src/transaction/deepbook_v3.d.ts +1 -1
  16. package/dist/src/transaction/flowx_v2.d.ts +1 -1
  17. package/dist/src/transaction/flowx_v3.d.ts +1 -1
  18. package/dist/src/transaction/haedal.d.ts +1 -1
  19. package/dist/src/transaction/haedal_pmm.d.ts +1 -1
  20. package/dist/src/transaction/index.d.ts +5 -1
  21. package/dist/src/transaction/kriya_v2.d.ts +1 -1
  22. package/dist/src/transaction/kriya_v3.d.ts +1 -1
  23. package/dist/src/transaction/scallop.d.ts +1 -1
  24. package/dist/src/transaction/suilend.d.ts +1 -2
  25. package/dist/src/transaction/turbos.d.ts +1 -1
  26. package/dist/src/transaction/volo.d.ts +1 -1
  27. package/package.json +1 -1
  28. package/src/api.ts +7 -3
  29. package/src/client.ts +129 -42
  30. package/src/transaction/afsui.ts +6 -3
  31. package/src/transaction/aftermath.ts +6 -3
  32. package/src/transaction/alphafi.ts +50 -0
  33. package/src/transaction/bluefin.ts +6 -3
  34. package/src/transaction/bluemove.ts +5 -4
  35. package/src/transaction/cetus.ts +13 -7
  36. package/src/transaction/deepbook_v2.ts +5 -4
  37. package/src/transaction/deepbook_v3.ts +5 -3
  38. package/src/transaction/flowx_v2.ts +5 -4
  39. package/src/transaction/flowx_v3.ts +5 -3
  40. package/src/transaction/haedal.ts +5 -3
  41. package/src/transaction/haedal_pmm.ts +5 -3
  42. package/src/transaction/index.ts +20 -1
  43. package/src/transaction/kriya_v2.ts +5 -4
  44. package/src/transaction/kriya_v3.ts +5 -4
  45. package/src/transaction/scallop.ts +5 -4
  46. package/src/transaction/suilend.ts +6 -10
  47. package/src/transaction/swap.ts +1 -0
  48. package/src/transaction/turbos.ts +5 -4
  49. package/src/transaction/volo.ts +5 -3
  50. package/src/utils/coin.ts +20 -8
  51. package/tests/router.test.ts +15 -22
package/README.md CHANGED
@@ -104,7 +104,7 @@ if (routerRes != null) {
104
104
  // you can use this target coin object argument to build your ptb.
105
105
  const client.transferOrDestoryCoin(
106
106
  txb,
107
- targetCoinRes.targetCoin,
107
+ targetCoin,
108
108
  targetCoinType
109
109
  )
110
110
 
package/dist/index.d.mts CHANGED
@@ -77,6 +77,7 @@ declare const SCALLOP = "SCALLOP";
77
77
  declare const SUILEND = "SUILEND";
78
78
  declare const BLUEFIN = "BLUEFIN";
79
79
  declare const HAEDALPMM = "HAEDALPMM";
80
+ declare const ALPHAFI = "ALPHAFI";
80
81
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
81
82
  type BuildRouterSwapParams = {
82
83
  routers: Router[];
@@ -93,7 +94,22 @@ type BuildFastRouterSwapParams = {
93
94
  slippage: number;
94
95
  txb: Transaction;
95
96
  partner?: string;
96
- isMergeTragetCoin?: boolean;
97
+ refreshAllCoins?: boolean;
98
+ payDeepFeeAmount?: number;
99
+ };
100
+ type BuildRouterSwapParamsV2 = {
101
+ routers: RouterData;
102
+ inputCoin: TransactionObjectArgument;
103
+ slippage: number;
104
+ txb: Transaction;
105
+ partner?: string;
106
+ deepbookv3DeepFee?: TransactionObjectArgument;
107
+ };
108
+ type BuildFastRouterSwapParamsV2 = {
109
+ routers: RouterData;
110
+ slippage: number;
111
+ txb: Transaction;
112
+ partner?: string;
97
113
  refreshAllCoins?: boolean;
98
114
  payDeepFeeAmount?: number;
99
115
  };
@@ -117,27 +133,31 @@ declare class AggregatorClient {
117
133
  constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
118
134
  getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
119
135
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
120
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
121
- expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
136
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
137
+ expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
122
138
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
123
- routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
124
- fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
125
- publishedAt(): string;
139
+ routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
140
+ fastRouterSwap(params: BuildFastRouterSwapParams | BuildFastRouterSwapParamsV2): Promise<void>;
126
141
  publishedAtV2(): string;
142
+ publishedAtV2Extend(): string;
127
143
  deepbookv3DeepFeeType(): string;
128
- transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
129
- checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
144
+ transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string, aggregatorV2PublishedAt: string): void;
145
+ checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN, aggregatorV2PublishedAt: string): TransactionObjectArgument;
130
146
  newDex(provider: string, partner?: string): Dex;
131
147
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
132
148
  devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
133
149
  sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
134
150
  getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
135
151
  }
136
- declare function parseRouterResponse(data: any): RouterData;
152
+ declare function parseRouterResponse(data: any, byAmountIn: boolean): RouterData;
137
153
 
138
154
  declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
155
+ declare const AGGREGATOR_V2 = "aggregator_v2";
156
+ declare const AGGREGATOR_V2_EXTEND = "aggregator_v2_extend";
157
+ declare function getAggregatorV2PublishedAt(aggregatorV2PublishedAt: string, packages?: Map<string, string> | Record<string, string>): string;
158
+ declare function getAggregatorV2ExtendPublishedAt(aggregatorV2ExtendPublishedAt: string, packages?: Map<string, string> | Record<string, string>): string;
139
159
  interface Dex {
140
- swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
160
+ swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, packages?: Map<string, string>, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
141
161
  }
142
162
 
143
163
  declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
@@ -235,8 +255,10 @@ type RouterError = {
235
255
  type RouterData = {
236
256
  amountIn: BN;
237
257
  amountOut: BN;
258
+ byAmountIn: boolean;
238
259
  routes: Router[];
239
260
  insufficientLiquidity: boolean;
261
+ packages?: Map<string, string>;
240
262
  totalDeepFee?: number;
241
263
  error?: RouterError;
242
264
  };
@@ -270,4 +292,4 @@ declare enum Env {
270
292
  Testnet = 1
271
293
  }
272
294
 
273
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
295
+ export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
package/dist/index.d.ts CHANGED
@@ -77,6 +77,7 @@ declare const SCALLOP = "SCALLOP";
77
77
  declare const SUILEND = "SUILEND";
78
78
  declare const BLUEFIN = "BLUEFIN";
79
79
  declare const HAEDALPMM = "HAEDALPMM";
80
+ declare const ALPHAFI = "ALPHAFI";
80
81
  declare const DEFAULT_ENDPOINT = "https://api-sui.cetus.zone/router_v2";
81
82
  type BuildRouterSwapParams = {
82
83
  routers: Router[];
@@ -93,7 +94,22 @@ type BuildFastRouterSwapParams = {
93
94
  slippage: number;
94
95
  txb: Transaction;
95
96
  partner?: string;
96
- isMergeTragetCoin?: boolean;
97
+ refreshAllCoins?: boolean;
98
+ payDeepFeeAmount?: number;
99
+ };
100
+ type BuildRouterSwapParamsV2 = {
101
+ routers: RouterData;
102
+ inputCoin: TransactionObjectArgument;
103
+ slippage: number;
104
+ txb: Transaction;
105
+ partner?: string;
106
+ deepbookv3DeepFee?: TransactionObjectArgument;
107
+ };
108
+ type BuildFastRouterSwapParamsV2 = {
109
+ routers: RouterData;
110
+ slippage: number;
111
+ txb: Transaction;
112
+ partner?: string;
97
113
  refreshAllCoins?: boolean;
98
114
  payDeepFeeAmount?: number;
99
115
  };
@@ -117,27 +133,31 @@ declare class AggregatorClient {
117
133
  constructor(endpoint?: string, signer?: string, client?: SuiClient, env?: Env);
118
134
  getCoins(coinType: string, refresh?: boolean): Promise<CoinAsset[]>;
119
135
  findRouters(params: FindRouterParams): Promise<RouterData | null>;
120
- expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
121
- expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string): Promise<TransactionObjectArgument>;
136
+ expectInputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], amountOutLimit: BN, partner?: string, deepbookv3DeepFee?: TransactionObjectArgument, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
137
+ expectOutputSwap(txb: Transaction, inputCoin: TransactionObjectArgument, routers: Router[], partner?: string, packages?: Map<string, string>): Promise<TransactionObjectArgument>;
122
138
  swapInPools(params: SwapInPoolsParams): Promise<SwapInPoolsResult | null>;
123
- routerSwap(params: BuildRouterSwapParams): Promise<TransactionObjectArgument>;
124
- fastRouterSwap(params: BuildFastRouterSwapParams): Promise<void>;
125
- publishedAt(): string;
139
+ routerSwap(params: BuildRouterSwapParams | BuildRouterSwapParamsV2): Promise<TransactionObjectArgument>;
140
+ fastRouterSwap(params: BuildFastRouterSwapParams | BuildFastRouterSwapParamsV2): Promise<void>;
126
141
  publishedAtV2(): string;
142
+ publishedAtV2Extend(): string;
127
143
  deepbookv3DeepFeeType(): string;
128
- transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string): void;
129
- checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN): TransactionObjectArgument;
144
+ transferOrDestoryCoin(txb: Transaction, coin: TransactionObjectArgument, coinType: string, aggregatorV2PublishedAt: string): void;
145
+ checkCoinThresholdAndMergeCoin(txb: Transaction, coins: TransactionObjectArgument[], coinType: string, amountLimit: BN, aggregatorV2PublishedAt: string): TransactionObjectArgument;
130
146
  newDex(provider: string, partner?: string): Dex;
131
147
  signAndExecuteTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
132
148
  devInspectTransactionBlock(txb: Transaction): Promise<_mysten_sui_client.DevInspectResults>;
133
149
  sendTransaction(txb: Transaction, signer: Signer): Promise<_mysten_sui_client.SuiTransactionBlockResponse>;
134
150
  getDeepbookV3Config(): Promise<DeepbookV3Config | null>;
135
151
  }
136
- declare function parseRouterResponse(data: any): RouterData;
152
+ declare function parseRouterResponse(data: any, byAmountIn: boolean): RouterData;
137
153
 
138
154
  declare const CLOCK_ADDRESS = "0x0000000000000000000000000000000000000000000000000000000000000006";
155
+ declare const AGGREGATOR_V2 = "aggregator_v2";
156
+ declare const AGGREGATOR_V2_EXTEND = "aggregator_v2_extend";
157
+ declare function getAggregatorV2PublishedAt(aggregatorV2PublishedAt: string, packages?: Map<string, string> | Record<string, string>): string;
158
+ declare function getAggregatorV2ExtendPublishedAt(aggregatorV2ExtendPublishedAt: string, packages?: Map<string, string> | Record<string, string>): string;
139
159
  interface Dex {
140
- swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
160
+ swap(client: AggregatorClient, ptb: Transaction, path: Path, inputCoin: TransactionObjectArgument, packages?: Map<string, string>, deepbookv3DeepFee?: TransactionObjectArgument): Promise<TransactionObjectArgument>;
141
161
  }
142
162
 
143
163
  declare function isSortedSymbols(symbolX: string, symbolY: string): boolean;
@@ -235,8 +255,10 @@ type RouterError = {
235
255
  type RouterData = {
236
256
  amountIn: BN;
237
257
  amountOut: BN;
258
+ byAmountIn: boolean;
238
259
  routes: Router[];
239
260
  insufficientLiquidity: boolean;
261
+ packages?: Map<string, string>;
240
262
  totalDeepFee?: number;
241
263
  error?: RouterError;
242
264
  };
@@ -270,4 +292,4 @@ declare enum Env {
270
292
  Testnet = 1
271
293
  }
272
294
 
273
- export { AFSUI, AFTERMATH, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildRouterSwapParams, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };
295
+ export { AFSUI, AFTERMATH, AGGREGATOR_V2, AGGREGATOR_V2_EXTEND, ALPHAFI, AggregatorClient, type AggregatorResponse, BLUEFIN, BLUEMOVE, type BuildCoinResult, type BuildFastRouterSwapParams, type BuildFastRouterSwapParamsV2, type BuildRouterSwapParams, type BuildRouterSwapParamsV2, CETUS, CLOCK_ADDRESS, DEEPBOOKV2, DEEPBOOKV3, DEFAULT_ENDPOINT, type DeepbookV3Config, type DeepbookV3ConfigResponse, type Dex, Env, type ExtendedDetails, FLOWXV2, FLOWXV3, type FindRouterParams, HAEDAL, HAEDALPMM, KRIYA, KRIYAV3, ONE, type Path, type PreSwapLpChangeParams, type Router, type RouterData, type RouterError, SCALLOP, SUILEND, type SwapInPoolsParams, type SwapInPoolsResult, TEN_POW_NINE, TURBOS, TWO, U128, U64_MAX, U64_MAX_BN, VOLO, ZERO, buildInputCoin, checkInvalidSuiAddress, compareCoins, completionCoin, composeType, createTarget, dealWithFastRouterSwapParamsForMsafe, extractAddressFromType, extractStructTagFromType, fixSuiObjectId, getAggregatorV2ExtendPublishedAt, getAggregatorV2PublishedAt, getDeepbookV3Config, getRouterResult, isSortedSymbols, mintZeroCoin, normalizeCoinType, parseRouterResponse, patchFixSuiObjectId, printTransaction, processEndpoint, restituteMsafeFastRouterSwapParams };