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
@@ -15,23 +15,51 @@ const caller_1 = require("../../general/utils/caller");
15
15
  const _1 = require(".");
16
16
  const utils_1 = require("../../general/utils");
17
17
  /**
18
- * Represents a pool object and provides methods for interacting with the pool.
19
- * @class
18
+ * The `Pool` class encapsulates all the functionality needed to interact
19
+ * with a specific AMM pool on the Aftermath platform. It allows you to
20
+ * calculate trade amounts, deposit/withdraw amounts, fetch transactions,
21
+ * and retrieve on-chain statistics and event data.
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * const afSdk = new Aftermath("MAINNET");
26
+ * await afSdk.init(); // initialize provider
27
+ *
28
+ * const pools = afSdk.Pools();
29
+ * const pool = await pools.getPool({ objectId: "0x..." });
30
+ *
31
+ * const stats = await pool.getStats();
32
+ * const tradeTx = await pool.getTradeTransaction({
33
+ * walletAddress: "0x...",
34
+ * coinInType: "0x2::sui::SUI",
35
+ * coinInAmount: BigInt(1e9),
36
+ * coinOutType: "0x<yourCoin>",
37
+ * slippage: 0.01,
38
+ * });
39
+ * ```
20
40
  */
21
41
  class Pool extends caller_1.Caller {
22
42
  /**
23
- * Creates a new instance of the Pool class.
24
- * @constructor
25
- * @param {PoolObject} pool - The pool object.
26
- * @param {SuiNetwork} [network] - The network to use.
43
+ * Creates a new instance of the `Pool` class for on-chain interaction.
44
+ *
45
+ * @param pool - The fetched `PoolObject` from Aftermath API or on-chain query.
46
+ * @param config - Optional caller configuration (e.g., network, access token).
47
+ * @param Provider - An optional `AftermathApi` instance for advanced transaction usage.
27
48
  */
28
49
  constructor(pool, config, Provider) {
29
50
  super(config, `pools/${pool.objectId}`);
30
51
  this.pool = pool;
31
52
  this.Provider = Provider;
32
53
  /**
33
- * Retrieves the volume in the last 24 hours for the pool.
34
- * @returns A promise that resolves to the volume in the last 24 hours.
54
+ * Retrieves the 24-hour volume for this specific pool.
55
+ *
56
+ * @returns A promise resolving to a number (volume in 24h).
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const vol24h = await pool.getVolume24hrs();
61
+ * console.log("Pool 24h Volume:", vol24h);
62
+ * ```
35
63
  */
36
64
  this.getVolume24hrs = () => __awaiter(this, void 0, void 0, function* () {
37
65
  return this.fetchApi("volume-24hrs");
@@ -40,28 +68,47 @@ class Pool extends caller_1.Caller {
40
68
  // Calculations
41
69
  // =========================================================================
42
70
  /**
43
- * Calculates the spot price for the pool.
44
- * @param {Object} inputs - The inputs for the method.
45
- * @param {CoinType} inputs.coinInType - The input coin type.
46
- * @param {CoinType} inputs.coinOutType - The output coin type.
47
- * @param {boolean} [inputs.withFees] - Whether to include fees in the calculation.
48
- * @returns {number} The spot price for the pool.
71
+ * Calculates the instantaneous spot price for swapping from `coinInType`
72
+ * to `coinOutType` within this pool. Optionally includes fees in the price.
73
+ *
74
+ * @param inputs - Object specifying input coin, output coin, and a boolean for `withFees`.
75
+ * @returns The numerical spot price (float).
76
+ *
77
+ * @example
78
+ * ```typescript
79
+ * const price = pool.getSpotPrice({
80
+ * coinInType: "0x<coinA>",
81
+ * coinOutType: "0x<coinB>",
82
+ * withFees: true,
83
+ * });
84
+ * console.log("Spot Price:", price);
85
+ * ```
49
86
  */
50
87
  this.getSpotPrice = (inputs) => {
51
88
  const spotPriceWithDecimals = cmmmCalculations_1.CmmmCalculations.calcSpotPriceWithFees(utils_1.Helpers.deepCopy(this.pool), inputs.coinInType, inputs.coinOutType, !inputs.withFees);
89
+ // Adjust for decimals difference
52
90
  return ((spotPriceWithDecimals *
53
91
  Number(this.pool.coins[inputs.coinOutType].decimalsScalar)) /
54
92
  Number(this.pool.coins[inputs.coinInType].decimalsScalar));
55
93
  };
56
94
  // TODO: account for referral discount for all calculations
57
95
  /**
58
- * Calculates the output amount for a trade.
59
- * @param {Object} inputs - The inputs for the method.
60
- * @param {CoinType} inputs.coinInType - The input coin type.
61
- * @param {Balance} inputs.coinInAmount - The input coin amount.
62
- * @param {CoinType} inputs.coinOutType - The output coin type.
63
- * @param {boolean} [inputs.referral] - Whether the trade includes a referral.
64
- * @returns {Balance} The output amount for the trade.
96
+ * Calculates how much output coin you would receive when trading
97
+ * a given input coin and amount in this pool, factoring in protocol
98
+ * and optional DAO fees.
99
+ *
100
+ * @param inputs - Includes `coinInType`, `coinInAmount`, and `coinOutType`.
101
+ * @returns A bigint representing how many output coins you'd get.
102
+ * @throws Error if the trade amount is too large relative to the pool balance.
103
+ *
104
+ * @example
105
+ * ```typescript
106
+ * const amountOut = pool.getTradeAmountOut({
107
+ * coinInType: "0x<coinA>",
108
+ * coinInAmount: BigInt(1000000),
109
+ * coinOutType: "0x<coinB>",
110
+ * });
111
+ * ```
65
112
  */
66
113
  this.getTradeAmountOut = (inputs) => {
67
114
  const pool = utils_1.Helpers.deepCopy(this.pool);
@@ -86,13 +133,21 @@ class Pool extends caller_1.Caller {
86
133
  return coinOutAmount;
87
134
  };
88
135
  /**
89
- * Calculates the input amount for a trade.
90
- * @param {Object} inputs - The inputs for the method.
91
- * @param {CoinType} inputs.coinInType - The input coin type.
92
- * @param {Balance} inputs.coinOutAmount - The output coin amount.
93
- * @param {CoinType} inputs.coinOutType - The output coin type.
94
- * @param {boolean} [inputs.referral] - Whether the trade includes a referral.
95
- * @returns {Balance} The input amount for the trade.
136
+ * Calculates how much input coin is required to obtain a certain output coin amount
137
+ * from this pool, factoring in fees.
138
+ *
139
+ * @param inputs - Includes `coinInType`, desired `coinOutAmount`, and `coinOutType`.
140
+ * @returns A bigint representing the needed input amount.
141
+ * @throws Error if the desired output is too large relative to pool balances.
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * const amountIn = pool.getTradeAmountIn({
146
+ * coinInType: "0x<coinA>",
147
+ * coinOutAmount: BigInt(1000000),
148
+ * coinOutType: "0x<coinB>"
149
+ * });
150
+ * ```
96
151
  */
97
152
  this.getTradeAmountIn = (inputs) => {
98
153
  const pool = utils_1.Helpers.deepCopy(this.pool);
@@ -117,11 +172,19 @@ class Pool extends caller_1.Caller {
117
172
  return coinInAmountWithoutFees;
118
173
  };
119
174
  /**
120
- * Calculates the LP amount and ratio for a deposit.
121
- * @param {Object} inputs - The inputs for the method.
122
- * @param {CoinsToBalance} inputs.amountsIn - The input amounts.
123
- * @param {boolean} [inputs.referral] - Whether the deposit includes a referral.
124
- * @returns {Object} The LP amount and ratio for the deposit.
175
+ * Calculates how many LP tokens you receive for providing liquidity
176
+ * in specific coin amounts. Also returns a ratio for reference.
177
+ *
178
+ * @param inputs - Contains the amounts in for each coin in the pool.
179
+ * @returns An object with `lpAmountOut` and `lpRatio`.
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * const depositCalc = pool.getDepositLpAmountOut({
184
+ * amountsIn: { "0x<coinA>": BigInt(1000000), "0x<coinB>": BigInt(500000) },
185
+ * });
186
+ * console.log(depositCalc.lpAmountOut, depositCalc.lpRatio);
187
+ * ```
125
188
  */
126
189
  this.getDepositLpAmountOut = (inputs) => {
127
190
  const calcedLpRatio = cmmmCalculations_1.CmmmCalculations.calcDepositFixedAmounts(this.pool, Object.entries(inputs.amountsIn).reduce((acc, [coin, amount]) => (Object.assign(Object.assign({}, acc), { [coin]: this.getAmountWithDAOFee({ amount }) })), {}));
@@ -135,12 +198,20 @@ class Pool extends caller_1.Caller {
135
198
  };
136
199
  };
137
200
  /**
138
- * Calculates the output amounts for a withdraw.
139
- * @param {Object} inputs - The inputs for the method.
140
- * @param {number} inputs.lpRatio - The LP ratio.
141
- * @param {CoinsToBalance} inputs.amountsOutDirection - The output amounts.
142
- * @param {boolean} [inputs.referral] - Whether the withdraw includes a referral.
143
- * @returns {CoinsToBalance} The output amounts for the withdraw.
201
+ * Calculates how many coins a user will receive when withdrawing a specific ratio or LP amount.
202
+ * This method is used in multi-coin withdrawals where you specify how much of each coin you want.
203
+ *
204
+ * @param inputs - The LP ratio and an object specifying direction amounts for each coin.
205
+ * @returns A `CoinsToBalance` object with final amounts out, factoring in DAO fees.
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * const outAmounts = pool.getWithdrawAmountsOut({
210
+ * lpRatio: 0.1,
211
+ * amountsOutDirection: { "0x<coinA>": BigInt(500000) },
212
+ * });
213
+ * console.log(outAmounts);
214
+ * ```
144
215
  */
145
216
  this.getWithdrawAmountsOut = (inputs) => {
146
217
  const amountsOut = cmmmCalculations_1.CmmmCalculations.calcWithdrawFlpAmountsOut(this.pool, inputs.amountsOutDirection, inputs.lpRatio);
@@ -149,17 +220,24 @@ class Pool extends caller_1.Caller {
149
220
  inputs.amountsOutDirection[coin] <= BigInt(0))
150
221
  continue;
151
222
  const amountOut = amountsOut[coin];
152
- if (amountOut <= BigInt(0))
153
- throw new Error(`amountsOut[${coin}] <= 0 `);
154
- if (amountOut / this.pool.coins[coin].balance >=
155
- _1.Pools.constants.bounds.maxWithdrawPercentageOfPoolBalance)
223
+ if (amountOut <= 0) {
224
+ throw new Error(`amountsOut[${coin}] <= 0`);
225
+ }
226
+ if (Number(amountOut) / Number(this.pool.coins[coin].balance) >=
227
+ _1.Pools.constants.bounds.maxWithdrawPercentageOfPoolBalance) {
156
228
  throw new Error("coinOutAmount / coinOutPoolBalance >= maxWithdrawPercentageOfPoolBalance");
157
- amountsOut[coin] = this.getAmountWithDAOFee({
158
- amount: amountOut,
159
- });
229
+ }
230
+ amountsOut[coin] = this.getAmountWithDAOFee({ amount: amountOut });
160
231
  }
161
232
  return amountsOut;
162
233
  };
234
+ /**
235
+ * A simplified multi-coin withdraw approach: calculates all outputs by proportion of the
236
+ * user's LP share among selected coin types. Useful for approximate or "blind" all-coin out logic.
237
+ *
238
+ * @param inputs - Contains the `lpCoinAmountIn` to burn, and which coin types to receive.
239
+ * @returns A record mapping coin type => final amounts out.
240
+ */
163
241
  this.getWithdrawAmountsOutSimple = (inputs) => {
164
242
  const { lpCoinAmountIn, coinTypesOut, referral } = inputs;
165
243
  const lpCoinSupply = this.pool.lpCoinSupply;
@@ -198,11 +276,17 @@ class Pool extends caller_1.Caller {
198
276
  return amountsOut;
199
277
  };
200
278
  /**
201
- * Calculates the output amounts for an all coin withdraw.
202
- * @param {Object} inputs - The inputs for the method.
203
- * @param {number} inputs.lpRatio - The LP ratio.
204
- * @param {boolean} [inputs.referral] - Whether the withdraw includes a referral.
205
- * @returns {CoinsToBalance} The output amounts for the all coin withdraw.
279
+ * Calculates how many coins you get when withdrawing **all** coin types from the pool,
280
+ * given a ratio. This is typically used for proportionate withdrawal.
281
+ *
282
+ * @param inputs - Includes `lpRatio`, the portion of your LP to burn (0 < ratio < 1).
283
+ * @returns A record of coin type => amounts out, after factoring in any fees.
284
+ *
285
+ * @example
286
+ * ```typescript
287
+ * const allOut = pool.getAllCoinWithdrawAmountsOut({ lpRatio: 0.1 });
288
+ * console.log(allOut); // amounts for each coin
289
+ * ```
206
290
  */
207
291
  this.getAllCoinWithdrawAmountsOut = (inputs) => {
208
292
  if (inputs.lpRatio >= 1)
@@ -215,39 +299,69 @@ class Pool extends caller_1.Caller {
215
299
  return amountsOut;
216
300
  };
217
301
  /**
218
- * Calculates the LP ratio for a multi-coin withdraw.
219
- * @param {Object} inputs - The inputs for the method.
220
- * @param {bigint} inputs.lpCoinAmountIn - The LP coin amount out.
221
- * @returns {number} The LP ratio for the multi-coin withdraw.
302
+ * For multi-coin withdraw, calculates the ratio of how much LP you are burning
303
+ * relative to the total supply. e.g. if user burns 100 of 1000 supply => ratio 0.1.
304
+ *
305
+ * @param inputs - Contains the `lpCoinAmountIn` to burn.
306
+ * @returns A float ratio (0 < ratio < 1).
222
307
  */
223
308
  this.getMultiCoinWithdrawLpRatio = (inputs) => Number(this.pool.lpCoinSupply - inputs.lpCoinAmountIn) /
224
309
  Number(this.pool.lpCoinSupply);
225
310
  /**
226
- * Calculates the LP ratio for an all coin withdraw.
227
- * @param {Object} inputs - The inputs for the method.
228
- * @param {bigint} inputs.lpCoinAmountIn - The LP coin amount out.
229
- * @returns {number} The LP ratio for the all coin withdraw.
311
+ * For an all-coin withdraw, calculates the ratio of how much LP is burned
312
+ * relative to total supply. e.g. if user burns 50 of 200 supply => ratio 0.25.
313
+ *
314
+ * @param inputs - Contains the `lpCoinAmountIn`.
315
+ * @returns A float ratio, typically 0 < ratio < 1.
230
316
  */
231
317
  this.getAllCoinWithdrawLpRatio = (inputs) => Number(inputs.lpCoinAmountIn) / Number(this.pool.lpCoinSupply);
232
318
  // =========================================================================
233
319
  // Getters
234
320
  // =========================================================================
321
+ /**
322
+ * Returns an array of coin types in ascending lexicographic order
323
+ * for the coins contained in this pool.
324
+ *
325
+ * @returns An array of coin type strings.
326
+ */
235
327
  this.coins = () => {
236
328
  return Object.keys(this.pool.coins).sort((a, b) => a.localeCompare(b));
237
329
  };
330
+ /**
331
+ * Returns an array of `PoolCoin` objects, one for each coin in this pool,
332
+ * sorted lexicographically by coin type.
333
+ *
334
+ * @returns An array of `PoolCoin`.
335
+ */
238
336
  this.poolCoins = () => {
239
337
  return Object.entries(this.pool.coins)
240
338
  .sort((a, b) => a[0].localeCompare(b[0]))
241
339
  .map((data) => data[1]);
242
340
  };
341
+ /**
342
+ * Returns an array of `[CoinType, PoolCoin]` pairs, sorted by coin type.
343
+ *
344
+ * @returns An array of coin-type => `PoolCoin` pairs.
345
+ */
243
346
  this.poolCoinEntries = () => {
244
347
  return Object.entries(this.pool.coins).sort((a, b) => a[0].localeCompare(b[0]));
245
348
  };
349
+ /**
350
+ * Returns the current DAO fee percentage, if configured (0 < fee <= 100%).
351
+ *
352
+ * @returns A decimal fraction representing the fee (e.g., 0.01 = 1%) or `undefined`.
353
+ */
246
354
  this.daoFeePercentage = () => {
247
355
  return this.pool.daoFeePoolObject
248
356
  ? utils_1.Casting.bpsToPercentage(this.pool.daoFeePoolObject.feeBps)
249
357
  : undefined;
250
358
  };
359
+ /**
360
+ * Returns the Sui address that currently receives the DAO fee portion of
361
+ * pool trades, or `undefined` if no DAO fee is configured.
362
+ *
363
+ * @returns The DAO fee recipient address.
364
+ */
251
365
  this.daoFeeRecipient = () => {
252
366
  var _a;
253
367
  return (_a = this.pool.daoFeePoolObject) === null || _a === void 0 ? void 0 : _a.feeRecipient;
@@ -255,18 +369,36 @@ class Pool extends caller_1.Caller {
255
369
  // =========================================================================
256
370
  // Private Helpers
257
371
  // =========================================================================
372
+ /**
373
+ * Applies the DAO fee (if present) to a given `amount`, effectively reducing
374
+ * that amount by the fee fraction. e.g. if fee is 2%, it returns 98% of the input.
375
+ *
376
+ * @param inputs - Contains `amount` as a bigint.
377
+ * @returns The post-fee amount as a bigint.
378
+ */
258
379
  this.getAmountWithDAOFee = (inputs) => {
259
380
  const daoFeePercentage = this.daoFeePercentage();
260
381
  if (!daoFeePercentage)
261
382
  return inputs.amount;
262
383
  return BigInt(Math.floor(Number(inputs.amount) * (1 - daoFeePercentage)));
263
384
  };
385
+ /**
386
+ * The inverse operation of `getAmountWithDAOFee`, used in internal calculations
387
+ * when we need to back out how much input was needed prior to the fee cut.
388
+ *
389
+ * @param inputs - Contains `amount` as a bigint.
390
+ * @returns The pre-fee amount as a bigint.
391
+ */
264
392
  this.getAmountWithoutDAOFee = (inputs) => {
265
393
  const daoFeePercentage = this.daoFeePercentage();
266
394
  if (!daoFeePercentage)
267
395
  return inputs.amount;
268
396
  return BigInt(Math.floor(Number(inputs.amount) * (1 / (1 - daoFeePercentage))));
269
397
  };
398
+ /**
399
+ * Provides an instance of the Pools provider from `AftermathApi`.
400
+ * Throws an error if not defined.
401
+ */
270
402
  this.useProvider = () => {
271
403
  var _a;
272
404
  const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Pools();
@@ -280,10 +412,20 @@ class Pool extends caller_1.Caller {
280
412
  // Transactions
281
413
  // =========================================================================
282
414
  /**
283
- * Fetches the deposit transaction for the pool.
284
- * @async
285
- * @param {ApiPoolDepositBody} inputs - The inputs for the method.
286
- * @returns {Promise<Transaction>} The deposit transaction for the pool.
415
+ * Builds or fetches a deposit transaction to add liquidity to this pool.
416
+ * The resulting `Transaction` can be signed and submitted by the user.
417
+ *
418
+ * @param inputs - The deposit parameters including coin amounts, slippage, etc.
419
+ * @returns A `Transaction` to deposit funds into the pool.
420
+ *
421
+ * @example
422
+ * ```typescript
423
+ * const depositTx = await pool.getDepositTransaction({
424
+ * walletAddress: "0x...",
425
+ * amountsIn: { "0x<coin>": BigInt(1000000) },
426
+ * slippage: 0.01,
427
+ * });
428
+ * ```
287
429
  */
288
430
  getDepositTransaction(inputs) {
289
431
  return __awaiter(this, void 0, void 0, function* () {
@@ -291,10 +433,22 @@ class Pool extends caller_1.Caller {
291
433
  });
292
434
  }
293
435
  /**
294
- * Fetches the withdraw transaction for the pool.
295
- * @async
296
- * @param {ApiPoolWithdrawBody} inputs - The inputs for the method.
297
- * @returns {Promise<Transaction>} The withdraw transaction for the pool.
436
+ * Builds or fetches a withdrawal transaction to remove liquidity from this pool.
437
+ *
438
+ * @param inputs - The parameters specifying how much LP is burned, desired coins out, slippage, etc.
439
+ * @returns A `Transaction` to withdraw funds from the pool.
440
+ *
441
+ * @example
442
+ * ```typescript
443
+ * const withdrawTx = await pool.getWithdrawTransaction({
444
+ * walletAddress: "0x...",
445
+ * amountsOutDirection: {
446
+ * "0x<coin>": BigInt(500000),
447
+ * },
448
+ * lpCoinAmount: BigInt(1000000),
449
+ * slippage: 0.01,
450
+ * });
451
+ * ```
298
452
  */
299
453
  getWithdrawTransaction(inputs) {
300
454
  return __awaiter(this, void 0, void 0, function* () {
@@ -302,10 +456,19 @@ class Pool extends caller_1.Caller {
302
456
  });
303
457
  }
304
458
  /**
305
- * Fetches the all coin withdraw transaction for the pool.
306
- * @async
307
- * @param {ApiPoolAllCoinWithdrawBody} inputs - The inputs for the method.
308
- * @returns {Promise<Transaction>} The all coin withdraw transaction for the pool.
459
+ * Builds or fetches a transaction to withdraw all coin types from this pool,
460
+ * effectively "burning" an LP position in exchange for multiple coin outputs.
461
+ *
462
+ * @param inputs - The parameters specifying how much LP to burn.
463
+ * @returns A `Transaction` to withdraw all coins from the pool in proportion.
464
+ *
465
+ * @example
466
+ * ```typescript
467
+ * const allCoinWithdrawTx = await pool.getAllCoinWithdrawTransaction({
468
+ * walletAddress: "0x...",
469
+ * lpCoinAmount: BigInt(500000),
470
+ * });
471
+ * ```
309
472
  */
310
473
  getAllCoinWithdrawTransaction(inputs) {
311
474
  return __awaiter(this, void 0, void 0, function* () {
@@ -313,16 +476,45 @@ class Pool extends caller_1.Caller {
313
476
  });
314
477
  }
315
478
  /**
316
- * Fetches the trade transaction for the pool.
317
- * @async
318
- * @param {ApiPoolTradeBody} inputs - The inputs for the method.
319
- * @returns {Promise<Transaction>} The trade transaction for the pool.
479
+ * Builds or fetches a trade transaction to swap between two coin types in this pool.
480
+ *
481
+ * @param inputs - The trade parameters including coin in/out, amounts, slippage, etc.
482
+ * @returns A `Transaction` that can be signed and executed for the swap.
483
+ *
484
+ * @example
485
+ * ```typescript
486
+ * const tradeTx = await pool.getTradeTransaction({
487
+ * walletAddress: "0x...",
488
+ * coinInType: "0x<coinA>",
489
+ * coinInAmount: BigInt(1000000),
490
+ * coinOutType: "0x<coinB>",
491
+ * slippage: 0.005,
492
+ * });
493
+ * ```
320
494
  */
321
495
  getTradeTransaction(inputs) {
322
496
  return __awaiter(this, void 0, void 0, function* () {
323
497
  return this.useProvider().fetchBuildTradeTx(Object.assign(Object.assign({}, inputs), { pool: this }));
324
498
  });
325
499
  }
500
+ /**
501
+ * Builds a transaction to update the DAO fee percentage for this pool,
502
+ * if it has a DAO fee configured. The user must own the appropriate
503
+ * `daoFeePoolOwnerCap`.
504
+ *
505
+ * @param inputs - Includes user wallet, `daoFeePoolOwnerCapId`, and the new fee percentage.
506
+ * @returns A `Transaction` that can be signed to update the DAO fee on chain.
507
+ * @throws If this pool has no DAO fee configuration.
508
+ *
509
+ * @example
510
+ * ```typescript
511
+ * const tx = await pool.getUpdateDaoFeeTransaction({
512
+ * walletAddress: "0x...",
513
+ * daoFeePoolOwnerCapId: "0x<capId>",
514
+ * newFeePercentage: 0.01, // 1%
515
+ * });
516
+ * ```
517
+ */
326
518
  getUpdateDaoFeeTransaction(inputs) {
327
519
  var _a;
328
520
  return __awaiter(this, void 0, void 0, function* () {
@@ -332,6 +524,24 @@ class Pool extends caller_1.Caller {
332
524
  return this.useProvider().buildDaoFeePoolUpdateFeeBpsTx(Object.assign(Object.assign({}, inputs), { daoFeePoolId, lpCoinType: this.pool.lpCoinType, newFeeBps: utils_1.Casting.percentageToBps(inputs.newFeePercentage) }));
333
525
  });
334
526
  }
527
+ /**
528
+ * Builds a transaction to update the DAO fee recipient for this pool,
529
+ * if it has a DAO fee configured. The user must own the appropriate
530
+ * `daoFeePoolOwnerCap`.
531
+ *
532
+ * @param inputs - Includes user wallet, `daoFeePoolOwnerCapId`, and the new fee recipient.
533
+ * @returns A `Transaction` that can be signed to update the DAO fee recipient on chain.
534
+ * @throws If this pool has no DAO fee configuration.
535
+ *
536
+ * @example
537
+ * ```typescript
538
+ * const tx = await pool.getUpdateDaoFeeRecipientTransaction({
539
+ * walletAddress: "0x...",
540
+ * daoFeePoolOwnerCapId: "0x<capId>",
541
+ * newFeeRecipient: "0x<recipient>",
542
+ * });
543
+ * ```
544
+ */
335
545
  getUpdateDaoFeeRecipientTransaction(inputs) {
336
546
  var _a;
337
547
  return __awaiter(this, void 0, void 0, function* () {
@@ -345,9 +555,16 @@ class Pool extends caller_1.Caller {
345
555
  // Inspections
346
556
  // =========================================================================
347
557
  /**
348
- * Fetches the pool statistics.
349
- * @async
350
- * @returns {Promise<PoolStats>} The pool statistics.
558
+ * Fetches comprehensive pool statistics (volume, TVL, fees, APR, etc.) from the Aftermath API.
559
+ * Also caches the result in `this.stats`.
560
+ *
561
+ * @returns A promise resolving to `PoolStats` object.
562
+ *
563
+ * @example
564
+ * ```typescript
565
+ * const stats = await pool.getStats();
566
+ * console.log(stats.volume, stats.fees, stats.apr);
567
+ * ```
351
568
  */
352
569
  getStats() {
353
570
  return __awaiter(this, void 0, void 0, function* () {
@@ -357,18 +574,25 @@ class Pool extends caller_1.Caller {
357
574
  });
358
575
  }
359
576
  /**
360
- * Sets the pool statistics.
361
- * @param {PoolStats} stats - The pool statistics.
577
+ * Caches the provided stats object into `this.stats`.
578
+ *
579
+ * @param stats - The `PoolStats` object to store.
362
580
  */
363
581
  setStats(stats) {
364
582
  this.stats = stats;
365
583
  }
366
584
  /**
367
- * Fetches the volume data for the pool.
368
- * @async
369
- * @param {Object} inputs - The inputs for the method.
370
- * @param {PoolGraphDataTimeframeKey} inputs.timeframe - The timeframe for the data.
371
- * @returns {Promise<PoolDataPoint[]>} The volume data for the pool.
585
+ * Fetches an array of volume data points for a specified timeframe.
586
+ * This is often used for charting or historical references.
587
+ *
588
+ * @param inputs - Contains a `timeframe` key, such as `"1D"` or `"1W"`.
589
+ * @returns A promise resolving to an array of `PoolDataPoint`.
590
+ *
591
+ * @example
592
+ * ```typescript
593
+ * const volumeData = await pool.getVolumeData({ timeframe: "1D" });
594
+ * console.log(volumeData); // e.g. [{ time: 1686000000, value: 123.45 }, ...]
595
+ * ```
372
596
  */
373
597
  getVolumeData(inputs) {
374
598
  return __awaiter(this, void 0, void 0, function* () {
@@ -376,11 +600,16 @@ class Pool extends caller_1.Caller {
376
600
  });
377
601
  }
378
602
  /**
379
- * Fetches the fee data for the pool.
380
- * @async
381
- * @param {Object} inputs - The inputs for the method.
382
- * @param {PoolGraphDataTimeframeKey} inputs.timeframe - The timeframe for the data.
383
- * @returns {Promise<PoolDataPoint[]>} The fee data for the pool.
603
+ * Fetches an array of fee data points for a specified timeframe.
604
+ *
605
+ * @param inputs - Contains a `timeframe` key, e.g., `"1D"` or `"1W"`.
606
+ * @returns A promise resolving to an array of `PoolDataPoint`.
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * const feeData = await pool.getFeeData({ timeframe: "1D" });
611
+ * console.log(feeData);
612
+ * ```
384
613
  */
385
614
  getFeeData(inputs) {
386
615
  return __awaiter(this, void 0, void 0, function* () {
@@ -390,6 +619,18 @@ class Pool extends caller_1.Caller {
390
619
  // =========================================================================
391
620
  // Events
392
621
  // =========================================================================
622
+ /**
623
+ * Fetches user interaction events (deposit/withdraw) with this pool, optionally paginated.
624
+ *
625
+ * @param inputs - Includes user `walletAddress` and optional pagination fields.
626
+ * @returns A promise that resolves to `PoolDepositEvent | PoolWithdrawEvent` objects with a cursor if more exist.
627
+ *
628
+ * @example
629
+ * ```typescript
630
+ * const events = await pool.getInteractionEvents({ walletAddress: "0x...", limit: 10 });
631
+ * console.log(events.events, events.nextCursor);
632
+ * ```
633
+ */
393
634
  getInteractionEvents(inputs) {
394
635
  return __awaiter(this, void 0, void 0, function* () {
395
636
  return this.fetchApiIndexerEvents("interaction-events-by-user", inputs);
@@ -398,7 +639,8 @@ class Pool extends caller_1.Caller {
398
639
  }
399
640
  exports.Pool = Pool;
400
641
  /**
401
- * Private constants used in the class.
642
+ * Internal margin of error used in trade calculations to prevent
643
+ * exceeding maximum allowed percentages of pool balances.
402
644
  */
403
645
  Pool.constants = {
404
646
  percentageBoundsMarginOfError: 0.001, // 0.1%