aftermath-ts-sdk 1.2.63 → 1.2.64-docs.0

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 (117) hide show
  1. package/README.md +61 -27
  2. package/dist/general/dynamicGas/dynamicGas.d.ts +34 -0
  3. package/dist/general/dynamicGas/dynamicGas.d.ts.map +1 -1
  4. package/dist/general/dynamicGas/dynamicGas.js +34 -0
  5. package/dist/general/dynamicGas/dynamicGasTypes.d.ts +25 -0
  6. package/dist/general/dynamicGas/dynamicGasTypes.d.ts.map +1 -1
  7. package/dist/general/prices/prices.d.ts +73 -0
  8. package/dist/general/prices/prices.d.ts.map +1 -1
  9. package/dist/general/prices/prices.js +73 -0
  10. package/dist/general/providers/aftermath.d.ts +106 -25
  11. package/dist/general/providers/aftermath.d.ts.map +1 -1
  12. package/dist/general/providers/aftermath.js +108 -27
  13. package/dist/general/providers/aftermathApi.d.ts +127 -8
  14. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  15. package/dist/general/providers/aftermathApi.js +132 -12
  16. package/dist/general/types/castingTypes.d.ts +0 -7
  17. package/dist/general/types/castingTypes.d.ts.map +1 -1
  18. package/dist/general/types/castingTypes.js +6 -0
  19. package/dist/general/types/generalTypes.d.ts +228 -7
  20. package/dist/general/types/generalTypes.d.ts.map +1 -1
  21. package/dist/general/types/suiTypes.d.ts +0 -16
  22. package/dist/general/types/suiTypes.d.ts.map +1 -1
  23. package/dist/general/types/suiTypes.js +3 -25
  24. package/dist/general/utils/casting.d.ts +159 -3
  25. package/dist/general/utils/casting.d.ts.map +1 -1
  26. package/dist/general/utils/casting.js +162 -16
  27. package/dist/general/utils/fixedUtils.d.ts +89 -2
  28. package/dist/general/utils/fixedUtils.d.ts.map +1 -1
  29. package/dist/general/utils/fixedUtils.js +81 -4
  30. package/dist/general/utils/helpers.d.ts +320 -9
  31. package/dist/general/utils/helpers.d.ts.map +1 -1
  32. package/dist/general/utils/helpers.js +350 -89
  33. package/dist/general/utils/iFixedUtils.d.ts +64 -0
  34. package/dist/general/utils/iFixedUtils.d.ts.map +1 -1
  35. package/dist/general/utils/iFixedUtils.js +64 -0
  36. package/dist/general/wallet/wallet.d.ts +75 -0
  37. package/dist/general/wallet/wallet.d.ts.map +1 -1
  38. package/dist/general/wallet/wallet.js +75 -5
  39. package/dist/packages/auth/auth.d.ts +113 -0
  40. package/dist/packages/auth/auth.d.ts.map +1 -1
  41. package/dist/packages/auth/auth.js +129 -15
  42. package/dist/packages/auth/authTypes.d.ts +66 -0
  43. package/dist/packages/auth/authTypes.d.ts.map +1 -1
  44. package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
  45. package/dist/packages/coin/api/coinApi.js +28 -20
  46. package/dist/packages/coin/coin.d.ts +250 -0
  47. package/dist/packages/coin/coin.d.ts.map +1 -1
  48. package/dist/packages/coin/coin.js +238 -14
  49. package/dist/packages/coin/coinTypes.d.ts +93 -0
  50. package/dist/packages/coin/coinTypes.d.ts.map +1 -1
  51. package/dist/packages/dca/dca.d.ts +124 -35
  52. package/dist/packages/dca/dca.d.ts.map +1 -1
  53. package/dist/packages/dca/dca.js +127 -37
  54. package/dist/packages/dca/dcaTypes.d.ts +213 -28
  55. package/dist/packages/dca/dcaTypes.d.ts.map +1 -1
  56. package/dist/packages/farms/farms.d.ts +184 -1
  57. package/dist/packages/farms/farms.d.ts.map +1 -1
  58. package/dist/packages/farms/farms.js +185 -11
  59. package/dist/packages/farms/farmsStakedPosition.d.ts +140 -6
  60. package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
  61. package/dist/packages/farms/farmsStakedPosition.js +189 -144
  62. package/dist/packages/farms/farmsStakingPool.d.ts +161 -1
  63. package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
  64. package/dist/packages/farms/farmsStakingPool.js +176 -70
  65. package/dist/packages/farms/farmsTypes.d.ts +283 -2
  66. package/dist/packages/farms/farmsTypes.d.ts.map +1 -1
  67. package/dist/packages/farms/farmsTypes.js +18 -0
  68. package/dist/packages/limitOrders/limitOrders.d.ts +108 -21
  69. package/dist/packages/limitOrders/limitOrders.d.ts.map +1 -1
  70. package/dist/packages/limitOrders/limitOrders.js +110 -22
  71. package/dist/packages/limitOrders/limitOrdersTypes.d.ts +142 -0
  72. package/dist/packages/limitOrders/limitOrdersTypes.d.ts.map +1 -1
  73. package/dist/packages/multisig/multisig.d.ts +33 -4
  74. package/dist/packages/multisig/multisig.d.ts.map +1 -1
  75. package/dist/packages/multisig/multisig.js +33 -4
  76. package/dist/packages/multisig/multisigTypes.d.ts +17 -0
  77. package/dist/packages/multisig/multisigTypes.d.ts.map +1 -1
  78. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  79. package/dist/packages/pools/pool.d.ts +327 -85
  80. package/dist/packages/pools/pool.d.ts.map +1 -1
  81. package/dist/packages/pools/pool.js +333 -91
  82. package/dist/packages/pools/pools.d.ts +299 -37
  83. package/dist/packages/pools/pools.d.ts.map +1 -1
  84. package/dist/packages/pools/pools.js +306 -52
  85. package/dist/packages/pools/poolsTypes.d.ts +273 -8
  86. package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
  87. package/dist/packages/referralVault/referralVault.d.ts +37 -0
  88. package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
  89. package/dist/packages/referralVault/referralVault.js +37 -0
  90. package/dist/packages/router/router.d.ts +213 -17
  91. package/dist/packages/router/router.d.ts.map +1 -1
  92. package/dist/packages/router/router.js +214 -18
  93. package/dist/packages/router/routerTypes.d.ts +198 -14
  94. package/dist/packages/router/routerTypes.d.ts.map +1 -1
  95. package/dist/packages/staking/staking.d.ts +301 -43
  96. package/dist/packages/staking/staking.d.ts.map +1 -1
  97. package/dist/packages/staking/staking.js +308 -51
  98. package/dist/packages/staking/stakingTypes.d.ts +426 -6
  99. package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
  100. package/dist/packages/staking/stakingTypes.js +19 -0
  101. package/dist/packages/sui/sui.d.ts +39 -0
  102. package/dist/packages/sui/sui.d.ts.map +1 -1
  103. package/dist/packages/sui/sui.js +39 -0
  104. package/dist/packages/userData/userData.d.ts +66 -12
  105. package/dist/packages/userData/userData.d.ts.map +1 -1
  106. package/dist/packages/userData/userData.js +66 -12
  107. package/dist/packages/userData/userDataTypes.d.ts +19 -0
  108. package/dist/packages/userData/userDataTypes.d.ts.map +1 -1
  109. package/dist/types.d.ts.map +1 -1
  110. package/dist/types.js +0 -1
  111. package/package.json +1 -1
  112. package/dist/general/historicalData/historicalData.d.ts +0 -15
  113. package/dist/general/historicalData/historicalData.d.ts.map +0 -1
  114. package/dist/general/historicalData/historicalData.js +0 -45
  115. package/dist/general/historicalData/historicalDataTypes.d.ts +0 -10
  116. package/dist/general/historicalData/historicalDataTypes.d.ts.map +0 -1
  117. package/dist/general/historicalData/historicalDataTypes.js +0 -2
@@ -3,45 +3,114 @@ import { Caller } from "../../general/utils/caller";
3
3
  import { Transaction } from "@mysten/sui/transactions";
4
4
  import { TransactionBlock } from "@mysten/sui.js/transactions";
5
5
  /**
6
- * @class Router Provider
6
+ * The `Router` class provides a collection of methods to interact with Aftermath's
7
+ * smart order routing system on the Sui Network. It handles routing trades through
8
+ * various liquidity pools to achieve the best possible execution price, retrieving
9
+ * trade volume, managing supported coins, and more.
7
10
  *
8
11
  * @example
9
- * ```
12
+ * ```typescript
10
13
  * // Create provider
11
14
  * const router = (new Aftermath("MAINNET")).Router();
12
- * // Call sdk
15
+ * // Retrieve 24h volume
16
+ * const volume24h = await router.getVolume24hrs();
17
+ * // Get supported coins
13
18
  * const supportedCoins = await router.getSupportedCoins();
14
19
  * ```
15
20
  */
16
21
  export declare class Router extends Caller {
22
+ /**
23
+ * Contains static information about the router, such as the maximum
24
+ * allowable external fee percentage.
25
+ */
17
26
  static readonly constants: {
18
27
  /**
19
- * Max fee percentage that third parties can charge on router trades
28
+ * The maximum external fee percentage that a third party can charge on router trades.
29
+ * @remarks 0.5 = 50%
20
30
  */
21
31
  maxExternalFeePercentage: number;
22
32
  };
23
33
  /**
24
- * Creates `Router` provider to call api.
34
+ * Creates a new `Router` instance to perform router-related calls on the
35
+ * Aftermath platform.
25
36
  *
26
- * @param network - The Sui network to interact with
27
- * @returns New `Router` instance
37
+ * @param config - Optional configuration settings, including network and access token.
38
+ * @returns A new `Router` instance.
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * const afSdk = new Aftermath("MAINNET");
43
+ * await afSdk.init(); // initialize provider
44
+ *
45
+ * const router = afSdk.Router();
46
+ * ```
28
47
  */
29
48
  constructor(config?: CallerConfig);
30
49
  /**
31
- * Retrieves the total volume in the last 24 hours.
32
- * @returns A Promise that resolves to a number representing the total volume.
50
+ * Retrieves the total trading volume in the last 24 hours.
51
+ *
52
+ * @returns A promise that resolves to a `number` representing the total volume in the last 24 hours.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const volume = await router.getVolume24hrs();
57
+ * console.log(volume); // e.g. 1234567.89
58
+ * ```
33
59
  */
34
60
  getVolume24hrs: () => Promise<number>;
61
+ /**
62
+ * Fetches a list of all coin types that are supported for trading through the router.
63
+ *
64
+ * @returns A promise that resolves to an array of coin types (`CoinType[]`).
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const supportedCoins = await router.getSupportedCoins();
69
+ * console.log(supportedCoins); // ["0x2::sui::SUI", "0x<...>::coin::TOKEN", ...]
70
+ * ```
71
+ */
35
72
  getSupportedCoins(): Promise<string[]>;
73
+ /**
74
+ * Searches the supported coins by applying a filter string.
75
+ *
76
+ * @param inputs - An object containing a `filter` string to match against supported coins.
77
+ * @param abortSignal - An optional `AbortSignal` to cancel the request if needed.
78
+ * @returns A promise that resolves to an array of coin types matching the filter.
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * const searchResult = await router.searchSupportedCoins({ filter: "SUI" });
83
+ * console.log(searchResult); // e.g. ["0x2::sui::SUI"]
84
+ * ```
85
+ */
36
86
  searchSupportedCoins(inputs: {
37
87
  filter: string;
38
88
  }, abortSignal?: AbortSignal): Promise<string[]>;
39
89
  /**
40
- * Creates route across multiple pools and protocols for best trade execution price
90
+ * Creates an optimal trade route for a given token input (`coinInType`) with a
91
+ * specified input amount (`coinInAmount`). This route may consist of multiple
92
+ * swaps across different DEX protocols to achieve the best price.
93
+ *
94
+ * @param inputs - Details required to construct the trade route, including `coinInType`, `coinOutType`, and `coinInAmount`.
95
+ * @param abortSignal - An optional signal to abort the request if needed.
96
+ * @returns A promise resolving to a `RouterCompleteTradeRoute` object containing the full route details.
41
97
  *
42
- * @param inputs - Details for router to construct trade route
43
- * @param abortSignal - Optional signal to abort passed to fetch call
44
- * @returns Routes, paths, and amounts of each smaller trade within complete trade
98
+ * @example
99
+ * ```typescript
100
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({
101
+ * coinInType: "0x2::sui::SUI",
102
+ * coinOutType: "0x<...>::coin::TOKEN",
103
+ * coinInAmount: BigInt(10_000_000_000),
104
+ * // optional fields:
105
+ * referrer: "0x<referrer_address>",
106
+ * externalFee: {
107
+ * recipient: "0x<fee_collector>",
108
+ * feePercentage: 0.01
109
+ * },
110
+ * protocolBlacklist: ["Cetus", "BlueMove"]
111
+ * });
112
+ * console.log(route);
113
+ * ```
45
114
  */
46
115
  getCompleteTradeRouteGivenAmountIn(inputs: ApiRouterPartialCompleteTradeRouteBody & {
47
116
  /**
@@ -50,11 +119,25 @@ export declare class Router extends Caller {
50
119
  coinInAmount: Balance;
51
120
  }, abortSignal?: AbortSignal): Promise<RouterCompleteTradeRoute>;
52
121
  /**
53
- * Creates route across multiple pools and protocols for best trade execution price
122
+ * Creates an optimal trade route for a given token output (`coinOutType`) with a
123
+ * specified output amount (`coinOutAmount`). This route may consist of multiple
124
+ * swaps to achieve the target output amount, factoring in slippage.
125
+ *
126
+ * @param inputs - Details required to construct the trade route, including `coinInType`, `coinOutType`, `coinOutAmount`, and `slippage`.
127
+ * @param abortSignal - An optional signal to abort the request if needed.
128
+ * @returns A promise resolving to a `RouterCompleteTradeRoute` object containing the full route details.
54
129
  *
55
- * @param inputs - Details for router to construct trade route
56
- * @param abortSignal - Optional signal to abort passed to fetch call
57
- * @returns Routes, paths, and amounts of each smaller trade within complete trade
130
+ * @example
131
+ * ```typescript
132
+ * const route = await router.getCompleteTradeRouteGivenAmountOut({
133
+ * coinInType: "0x2::sui::SUI",
134
+ * coinOutType: "0x<...>::coin::TOKEN",
135
+ * coinOutAmount: BigInt(20_000_000),
136
+ * slippage: 0.01, // 1%
137
+ * protocolWhitelist: ["Aftermath", "Cetus"]
138
+ * });
139
+ * console.log(route);
140
+ * ```
58
141
  */
59
142
  getCompleteTradeRouteGivenAmountOut(inputs: ApiRouterPartialCompleteTradeRouteBody & {
60
143
  /**
@@ -63,20 +146,133 @@ export declare class Router extends Caller {
63
146
  coinOutAmount: Balance;
64
147
  slippage: Slippage;
65
148
  }, abortSignal?: AbortSignal): Promise<RouterCompleteTradeRoute>;
149
+ /**
150
+ * Generates a transaction to execute a previously calculated complete trade route.
151
+ * This transaction can then be signed and executed by the user.
152
+ *
153
+ * @param inputs - An object containing the wallet address, the complete trade route, slippage tolerance, and optional sponsorship settings.
154
+ * @returns A promise resolving to a `Uint8Array` representing the serialized transaction.
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
159
+ * const transactionBytes = await router.getTransactionForCompleteTradeRoute({
160
+ * walletAddress: "0x<your_address>",
161
+ * completeRoute: route,
162
+ * slippage: 0.01
163
+ * });
164
+ * // The returned bytes can now be signed and executed using your chosen wallet.
165
+ * ```
166
+ */
66
167
  getTransactionForCompleteTradeRoute(inputs: ApiRouterTransactionForCompleteTradeRouteBody): Promise<Transaction>;
168
+ /**
169
+ * **Legacy method** for generating a transaction to execute a complete trade route.
170
+ * Uses an older version of transaction serialization.
171
+ *
172
+ * @param inputs - Similar to `getTransactionForCompleteTradeRoute` but serialized using the legacy method.
173
+ * @returns A promise resolving to a `Uint8Array` representing the serialized transaction.
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
178
+ * const transactionBytesV0 = await router.getTransactionForCompleteTradeRouteV0({
179
+ * walletAddress: "0x<your_address>",
180
+ * completeRoute: route,
181
+ * slippage: 0.01
182
+ * });
183
+ * // Use this if your environment requires legacy transaction structure
184
+ * ```
185
+ */
67
186
  getTransactionForCompleteTradeRouteV0(inputs: ApiRouterTransactionForCompleteTradeRouteBody): Promise<TransactionBlock>;
187
+ /**
188
+ * Adds a trade route to an existing transaction, allowing you to build complex
189
+ * transactions containing multiple actions (swaps, transfers, etc.) in a single
190
+ * atomic transaction.
191
+ *
192
+ * @param inputs - Includes the existing `Transaction`, a complete route, slippage, wallet address, and an optional `coinInId`.
193
+ * @returns An object containing:
194
+ * - `tx`: The updated `Transaction` including the route instructions
195
+ * - `coinOutId`: A `TransactionObjectArgument` referencing the output coin after the swap
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * // 1) Create a route
200
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
201
+ *
202
+ * // 2) Initialize your transaction
203
+ * const tx = new Transaction();
204
+ *
205
+ * // 3) Add router instructions
206
+ * const { tx: updatedTx, coinOutId } =
207
+ * await router.addTransactionForCompleteTradeRoute({
208
+ * tx,
209
+ * completeRoute: route,
210
+ * slippage: 0.01,
211
+ * walletAddress: "0x<your_address>"
212
+ * });
213
+ *
214
+ * // 4) Continue building your transaction with the resulting coinOutId, if desired
215
+ * updatedTx.transferObjects([coinOutId!], "0x<your_address>");
216
+ * ```
217
+ */
68
218
  addTransactionForCompleteTradeRoute(inputs: Omit<ApiRouterAddTransactionForCompleteTradeRouteBody, "serializedTx"> & {
69
219
  tx: Transaction;
70
220
  }): Promise<{
71
221
  tx: Transaction;
72
222
  coinOutId: import("@mysten/sui/transactions").TransactionObjectArgument | undefined;
73
223
  }>;
224
+ /**
225
+ * **Legacy method** for adding a trade route to an existing transaction.
226
+ * Uses an older version of transaction serialization.
227
+ *
228
+ * @param inputs - Similar to `addTransactionForCompleteTradeRoute` but returns a `TransactionBlock`.
229
+ * @returns An object containing:
230
+ * - `tx`: The updated `TransactionBlock`
231
+ * - `coinOutId`: A `TransactionObjectArgumentV0` referencing the output coin
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * // 1) Create a route
236
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
237
+ *
238
+ * // 2) Initialize your transaction block
239
+ * const txBlock = new TransactionBlock();
240
+ *
241
+ * // 3) Add router instructions (legacy)
242
+ * const { tx: updatedTxBlock, coinOutId } =
243
+ * await router.addTransactionForCompleteTradeRouteV0({
244
+ * tx: txBlock,
245
+ * completeRoute: route,
246
+ * slippage: 0.01,
247
+ * walletAddress: "0x<your_address>"
248
+ * });
249
+ *
250
+ * // 4) Continue building your transaction with the resulting coinOutId
251
+ * updatedTxBlock.transferObjects([coinOutId!], "0x<your_address>");
252
+ * ```
253
+ */
74
254
  addTransactionForCompleteTradeRouteV0(inputs: Omit<ApiRouterAddTransactionForCompleteTradeRouteV0Body, "serializedTx"> & {
75
255
  tx: TransactionBlock;
76
256
  }): Promise<{
77
257
  tx: TransactionBlock;
78
258
  coinOutId: any;
79
259
  }>;
260
+ /**
261
+ * Retrieves trade events (interactions) for a given user based on router usage.
262
+ *
263
+ * @param inputs - Includes a `walletAddress`, cursor pagination, and limit.
264
+ * @returns A promise resolving to the user's `RouterTradeEvent`s, potentially paginated.
265
+ *
266
+ * @example
267
+ * ```typescript
268
+ * const events = await router.getInteractionEvents({
269
+ * walletAddress: "0x<your_address>",
270
+ * cursor: 0,
271
+ * limit: 10
272
+ * });
273
+ * console.log(events);
274
+ * ```
275
+ */
80
276
  getInteractionEvents(inputs: ApiRouterTradeEventsBody): Promise<import("../../types").IndexerEventsWithCursor<RouterTradeEvent>>;
81
277
  }
82
278
  //# sourceMappingURL=router.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../../src/packages/router/router.ts"],"names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,EAAE,QAAQ,CAAC;KACnB,EACD,WAAW,CAAC,EAAE,WAAW;IAY1B;;;;;;;;;;;;;;;;;OAiBG;IACU,mCAAmC,CAC/C,MAAM,EAAE,6CAA6C;IAQtD;;;;;;;;;;;;;;;;;OAiBG;IACU,qCAAqC,CACjD,MAAM,EAAE,6CAA6C;IAQtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACU,mCAAmC,CAC/C,MAAM,EAAE,IAAI,CACX,gDAAgD,EAChD,cAAc,CACd,GAAG;QACH,EAAE,EAAE,WAAW,CAAC;KAChB;;;;IAgBF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACU,qCAAqC,CACjD,MAAM,EAAE,IAAI,CACX,kDAAkD,EAClD,cAAc,CACd,GAAG;QACH,EAAE,EAAE,gBAAgB,CAAC;KACrB;;;;IAoBF;;;;;;;;;;;;;;;OAeG;IACU,oBAAoB,CAAC,MAAM,EAAE,wBAAwB;CAMlE"}
@@ -25,13 +25,18 @@ const caller_1 = require("../../general/utils/caller");
25
25
  const transactions_1 = require("@mysten/sui/transactions");
26
26
  const transactions_2 = require("@mysten/sui.js/transactions");
27
27
  /**
28
- * @class Router Provider
28
+ * The `Router` class provides a collection of methods to interact with Aftermath's
29
+ * smart order routing system on the Sui Network. It handles routing trades through
30
+ * various liquidity pools to achieve the best possible execution price, retrieving
31
+ * trade volume, managing supported coins, and more.
29
32
  *
30
33
  * @example
31
- * ```
34
+ * ```typescript
32
35
  * // Create provider
33
36
  * const router = (new Aftermath("MAINNET")).Router();
34
- * // Call sdk
37
+ * // Retrieve 24h volume
38
+ * const volume24h = await router.getVolume24hrs();
39
+ * // Get supported coins
35
40
  * const supportedCoins = await router.getSupportedCoins();
36
41
  * ```
37
42
  */
@@ -40,10 +45,19 @@ class Router extends caller_1.Caller {
40
45
  // Constructor
41
46
  // =========================================================================
42
47
  /**
43
- * Creates `Router` provider to call api.
48
+ * Creates a new `Router` instance to perform router-related calls on the
49
+ * Aftermath platform.
50
+ *
51
+ * @param config - Optional configuration settings, including network and access token.
52
+ * @returns A new `Router` instance.
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * const afSdk = new Aftermath("MAINNET");
57
+ * await afSdk.init(); // initialize provider
44
58
  *
45
- * @param network - The Sui network to interact with
46
- * @returns New `Router` instance
59
+ * const router = afSdk.Router();
60
+ * ```
47
61
  */
48
62
  constructor(config) {
49
63
  super(config, "router");
@@ -54,29 +68,79 @@ class Router extends caller_1.Caller {
54
68
  // Inspections
55
69
  // =========================================================================
56
70
  /**
57
- * Retrieves the total volume in the last 24 hours.
58
- * @returns A Promise that resolves to a number representing the total volume.
71
+ * Retrieves the total trading volume in the last 24 hours.
72
+ *
73
+ * @returns A promise that resolves to a `number` representing the total volume in the last 24 hours.
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const volume = await router.getVolume24hrs();
78
+ * console.log(volume); // e.g. 1234567.89
79
+ * ```
59
80
  */
60
81
  this.getVolume24hrs = () => __awaiter(this, void 0, void 0, function* () {
61
82
  return this.fetchApi("volume-24hrs");
62
83
  });
63
84
  }
85
+ /**
86
+ * Fetches a list of all coin types that are supported for trading through the router.
87
+ *
88
+ * @returns A promise that resolves to an array of coin types (`CoinType[]`).
89
+ *
90
+ * @example
91
+ * ```typescript
92
+ * const supportedCoins = await router.getSupportedCoins();
93
+ * console.log(supportedCoins); // ["0x2::sui::SUI", "0x<...>::coin::TOKEN", ...]
94
+ * ```
95
+ */
64
96
  getSupportedCoins() {
65
97
  return __awaiter(this, void 0, void 0, function* () {
66
98
  return this.fetchApi("supported-coins");
67
99
  });
68
100
  }
101
+ /**
102
+ * Searches the supported coins by applying a filter string.
103
+ *
104
+ * @param inputs - An object containing a `filter` string to match against supported coins.
105
+ * @param abortSignal - An optional `AbortSignal` to cancel the request if needed.
106
+ * @returns A promise that resolves to an array of coin types matching the filter.
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * const searchResult = await router.searchSupportedCoins({ filter: "SUI" });
111
+ * console.log(searchResult); // e.g. ["0x2::sui::SUI"]
112
+ * ```
113
+ */
69
114
  searchSupportedCoins(inputs, abortSignal) {
70
115
  return __awaiter(this, void 0, void 0, function* () {
71
116
  return this.fetchApi(`supported-coins/${inputs.filter}`, undefined, abortSignal);
72
117
  });
73
118
  }
74
119
  /**
75
- * Creates route across multiple pools and protocols for best trade execution price
120
+ * Creates an optimal trade route for a given token input (`coinInType`) with a
121
+ * specified input amount (`coinInAmount`). This route may consist of multiple
122
+ * swaps across different DEX protocols to achieve the best price.
76
123
  *
77
- * @param inputs - Details for router to construct trade route
78
- * @param abortSignal - Optional signal to abort passed to fetch call
79
- * @returns Routes, paths, and amounts of each smaller trade within complete trade
124
+ * @param inputs - Details required to construct the trade route, including `coinInType`, `coinOutType`, and `coinInAmount`.
125
+ * @param abortSignal - An optional signal to abort the request if needed.
126
+ * @returns A promise resolving to a `RouterCompleteTradeRoute` object containing the full route details.
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({
131
+ * coinInType: "0x2::sui::SUI",
132
+ * coinOutType: "0x<...>::coin::TOKEN",
133
+ * coinInAmount: BigInt(10_000_000_000),
134
+ * // optional fields:
135
+ * referrer: "0x<referrer_address>",
136
+ * externalFee: {
137
+ * recipient: "0x<fee_collector>",
138
+ * feePercentage: 0.01
139
+ * },
140
+ * protocolBlacklist: ["Cetus", "BlueMove"]
141
+ * });
142
+ * console.log(route);
143
+ * ```
80
144
  */
81
145
  getCompleteTradeRouteGivenAmountIn(inputs, abortSignal) {
82
146
  return __awaiter(this, void 0, void 0, function* () {
@@ -84,11 +148,25 @@ class Router extends caller_1.Caller {
84
148
  });
85
149
  }
86
150
  /**
87
- * Creates route across multiple pools and protocols for best trade execution price
151
+ * Creates an optimal trade route for a given token output (`coinOutType`) with a
152
+ * specified output amount (`coinOutAmount`). This route may consist of multiple
153
+ * swaps to achieve the target output amount, factoring in slippage.
154
+ *
155
+ * @param inputs - Details required to construct the trade route, including `coinInType`, `coinOutType`, `coinOutAmount`, and `slippage`.
156
+ * @param abortSignal - An optional signal to abort the request if needed.
157
+ * @returns A promise resolving to a `RouterCompleteTradeRoute` object containing the full route details.
88
158
  *
89
- * @param inputs - Details for router to construct trade route
90
- * @param abortSignal - Optional signal to abort passed to fetch call
91
- * @returns Routes, paths, and amounts of each smaller trade within complete trade
159
+ * @example
160
+ * ```typescript
161
+ * const route = await router.getCompleteTradeRouteGivenAmountOut({
162
+ * coinInType: "0x2::sui::SUI",
163
+ * coinOutType: "0x<...>::coin::TOKEN",
164
+ * coinOutAmount: BigInt(20_000_000),
165
+ * slippage: 0.01, // 1%
166
+ * protocolWhitelist: ["Aftermath", "Cetus"]
167
+ * });
168
+ * console.log(route);
169
+ * ```
92
170
  */
93
171
  getCompleteTradeRouteGivenAmountOut(inputs, abortSignal) {
94
172
  return __awaiter(this, void 0, void 0, function* () {
@@ -98,16 +176,83 @@ class Router extends caller_1.Caller {
98
176
  // =========================================================================
99
177
  // Transactions
100
178
  // =========================================================================
179
+ /**
180
+ * Generates a transaction to execute a previously calculated complete trade route.
181
+ * This transaction can then be signed and executed by the user.
182
+ *
183
+ * @param inputs - An object containing the wallet address, the complete trade route, slippage tolerance, and optional sponsorship settings.
184
+ * @returns A promise resolving to a `Uint8Array` representing the serialized transaction.
185
+ *
186
+ * @example
187
+ * ```typescript
188
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
189
+ * const transactionBytes = await router.getTransactionForCompleteTradeRoute({
190
+ * walletAddress: "0x<your_address>",
191
+ * completeRoute: route,
192
+ * slippage: 0.01
193
+ * });
194
+ * // The returned bytes can now be signed and executed using your chosen wallet.
195
+ * ```
196
+ */
101
197
  getTransactionForCompleteTradeRoute(inputs) {
102
198
  return __awaiter(this, void 0, void 0, function* () {
103
199
  return this.fetchApiTransaction("transactions/trade", inputs);
104
200
  });
105
201
  }
202
+ /**
203
+ * **Legacy method** for generating a transaction to execute a complete trade route.
204
+ * Uses an older version of transaction serialization.
205
+ *
206
+ * @param inputs - Similar to `getTransactionForCompleteTradeRoute` but serialized using the legacy method.
207
+ * @returns A promise resolving to a `Uint8Array` representing the serialized transaction.
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
212
+ * const transactionBytesV0 = await router.getTransactionForCompleteTradeRouteV0({
213
+ * walletAddress: "0x<your_address>",
214
+ * completeRoute: route,
215
+ * slippage: 0.01
216
+ * });
217
+ * // Use this if your environment requires legacy transaction structure
218
+ * ```
219
+ */
106
220
  getTransactionForCompleteTradeRouteV0(inputs) {
107
221
  return __awaiter(this, void 0, void 0, function* () {
108
222
  return this.fetchApiTransactionV0("transactions/trade-v0", inputs);
109
223
  });
110
224
  }
225
+ /**
226
+ * Adds a trade route to an existing transaction, allowing you to build complex
227
+ * transactions containing multiple actions (swaps, transfers, etc.) in a single
228
+ * atomic transaction.
229
+ *
230
+ * @param inputs - Includes the existing `Transaction`, a complete route, slippage, wallet address, and an optional `coinInId`.
231
+ * @returns An object containing:
232
+ * - `tx`: The updated `Transaction` including the route instructions
233
+ * - `coinOutId`: A `TransactionObjectArgument` referencing the output coin after the swap
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * // 1) Create a route
238
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
239
+ *
240
+ * // 2) Initialize your transaction
241
+ * const tx = new Transaction();
242
+ *
243
+ * // 3) Add router instructions
244
+ * const { tx: updatedTx, coinOutId } =
245
+ * await router.addTransactionForCompleteTradeRoute({
246
+ * tx,
247
+ * completeRoute: route,
248
+ * slippage: 0.01,
249
+ * walletAddress: "0x<your_address>"
250
+ * });
251
+ *
252
+ * // 4) Continue building your transaction with the resulting coinOutId, if desired
253
+ * updatedTx.transferObjects([coinOutId!], "0x<your_address>");
254
+ * ```
255
+ */
111
256
  addTransactionForCompleteTradeRoute(inputs) {
112
257
  return __awaiter(this, void 0, void 0, function* () {
113
258
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
@@ -118,6 +263,36 @@ class Router extends caller_1.Caller {
118
263
  };
119
264
  });
120
265
  }
266
+ /**
267
+ * **Legacy method** for adding a trade route to an existing transaction.
268
+ * Uses an older version of transaction serialization.
269
+ *
270
+ * @param inputs - Similar to `addTransactionForCompleteTradeRoute` but returns a `TransactionBlock`.
271
+ * @returns An object containing:
272
+ * - `tx`: The updated `TransactionBlock`
273
+ * - `coinOutId`: A `TransactionObjectArgumentV0` referencing the output coin
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * // 1) Create a route
278
+ * const route = await router.getCompleteTradeRouteGivenAmountIn({ ... });
279
+ *
280
+ * // 2) Initialize your transaction block
281
+ * const txBlock = new TransactionBlock();
282
+ *
283
+ * // 3) Add router instructions (legacy)
284
+ * const { tx: updatedTxBlock, coinOutId } =
285
+ * await router.addTransactionForCompleteTradeRouteV0({
286
+ * tx: txBlock,
287
+ * completeRoute: route,
288
+ * slippage: 0.01,
289
+ * walletAddress: "0x<your_address>"
290
+ * });
291
+ *
292
+ * // 4) Continue building your transaction with the resulting coinOutId
293
+ * updatedTxBlock.transferObjects([coinOutId!], "0x<your_address>");
294
+ * ```
295
+ */
121
296
  addTransactionForCompleteTradeRouteV0(inputs) {
122
297
  return __awaiter(this, void 0, void 0, function* () {
123
298
  const { tx } = inputs, otherInputs = __rest(inputs, ["tx"]);
@@ -131,6 +306,22 @@ class Router extends caller_1.Caller {
131
306
  // =========================================================================
132
307
  // Events
133
308
  // =========================================================================
309
+ /**
310
+ * Retrieves trade events (interactions) for a given user based on router usage.
311
+ *
312
+ * @param inputs - Includes a `walletAddress`, cursor pagination, and limit.
313
+ * @returns A promise resolving to the user's `RouterTradeEvent`s, potentially paginated.
314
+ *
315
+ * @example
316
+ * ```typescript
317
+ * const events = await router.getInteractionEvents({
318
+ * walletAddress: "0x<your_address>",
319
+ * cursor: 0,
320
+ * limit: 10
321
+ * });
322
+ * console.log(events);
323
+ * ```
324
+ */
134
325
  getInteractionEvents(inputs) {
135
326
  return __awaiter(this, void 0, void 0, function* () {
136
327
  return this.fetchApiIndexerEvents("events-by-user", inputs);
@@ -141,9 +332,14 @@ exports.Router = Router;
141
332
  // =========================================================================
142
333
  // Constants
143
334
  // =========================================================================
335
+ /**
336
+ * Contains static information about the router, such as the maximum
337
+ * allowable external fee percentage.
338
+ */
144
339
  Router.constants = {
145
340
  /**
146
- * Max fee percentage that third parties can charge on router trades
341
+ * The maximum external fee percentage that a third party can charge on router trades.
342
+ * @remarks 0.5 = 50%
147
343
  */
148
- maxExternalFeePercentage: 0.5, // 50%
344
+ maxExternalFeePercentage: 0.5,
149
345
  };