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
@@ -20,10 +20,21 @@ const duration_1 = __importDefault(require("dayjs/plugin/duration"));
20
20
  const fixedUtils_1 = require("../../general/utils/fixedUtils");
21
21
  const coin_1 = require("../coin/coin");
22
22
  const farms_1 = require("./farms");
23
+ /**
24
+ * The `FarmsStakingPool` class represents a staking pool (also referred
25
+ * to as a "vault" in some contexts). It allows reading details about
26
+ * emission schedules, reward tokens, stake coin type, and lock durations,
27
+ * as well as constructing transactions to stake, harvest, and mutate the
28
+ * pool parameters if the user has the correct admin privileges.
29
+ */
23
30
  class FarmsStakingPool extends caller_1.Caller {
24
- // =========================================================================
25
- // Constructor
26
- // =========================================================================
31
+ /**
32
+ * Creates a `FarmsStakingPool` instance based on on-chain pool data.
33
+ *
34
+ * @param stakingPool - The on-chain data object describing the pool.
35
+ * @param config - An optional `CallerConfig` for network settings.
36
+ * @param Provider - An optional `AftermathApi` for transaction building.
37
+ */
27
38
  constructor(stakingPool, config, Provider) {
28
39
  super(config, "farms");
29
40
  this.stakingPool = stakingPool;
@@ -31,35 +42,70 @@ class FarmsStakingPool extends caller_1.Caller {
31
42
  // =========================================================================
32
43
  // Getters
33
44
  // =========================================================================
45
+ /**
46
+ * Retrieves the version of this staking pool (1 or 2).
47
+ */
34
48
  this.version = () => {
35
49
  return this.stakingPool.version;
36
50
  };
51
+ /**
52
+ * Lists all reward coin types offered by this staking pool.
53
+ *
54
+ * @returns An array of `CoinType` strings.
55
+ */
37
56
  this.rewardCoinTypes = () => {
38
57
  return this.stakingPool.rewardCoins.map((coin) => coin.coinType);
39
58
  };
59
+ /**
60
+ * Lists all reward coin types for which this pool currently has a non-zero actual reward balance.
61
+ *
62
+ * @returns An array of `CoinType` strings that have > 0 actual rewards.
63
+ */
40
64
  this.nonZeroRewardCoinTypes = () => {
41
65
  return this.stakingPool.rewardCoins
42
66
  .filter((coin) => coin.emissionRate <= coin.actualRewards &&
43
67
  coin.actualRewards > BigInt(0))
44
68
  .map((coin) => coin.coinType);
45
69
  };
70
+ /**
71
+ * Retrieves the on-chain record for a specific reward coin type in this pool.
72
+ *
73
+ * @param inputs - Contains the `coinType` to look up.
74
+ * @throws If the specified coinType is not found in `rewardCoins`.
75
+ * @returns A `FarmsStakingPoolRewardCoin` object.
76
+ */
46
77
  this.rewardCoin = (inputs) => {
47
78
  const foundCoin = this.stakingPool.rewardCoins.find((coin) => coin.coinType === inputs.coinType);
48
79
  if (!foundCoin)
49
80
  throw new Error("Invalid coin type");
50
81
  return foundCoin;
51
82
  };
83
+ /**
84
+ * Computes the maximum lock duration (in ms) that remains valid in this staking pool,
85
+ * factoring in the current time and the pool's emission end.
86
+ *
87
+ * @returns The maximum possible lock duration in milliseconds, or 0 if the pool is effectively closed.
88
+ */
52
89
  this.maxLockDurationMs = () => {
53
90
  return Math.max(Math.min(this.stakingPool.maxLockDurationMs, this.stakingPool.emissionEndTimestamp - (0, dayjs_1.default)().valueOf()), 0);
54
91
  };
55
92
  // =========================================================================
56
93
  // Calculations
57
94
  // =========================================================================
58
- // Calculates the amount of rewards that have emitted since the last time this function has been
59
- // called. Updates `rewards_accumulated_per_share`.
95
+ /**
96
+ * Calculates and applies newly emitted rewards for each reward coin in this pool,
97
+ * updating the `rewardsAccumulatedPerShare`. This simulates the on-chain
98
+ * `emitRewards` logic.
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * someFarmsPool.emitRewards();
103
+ * // The pool's rewardsAccumulatedPerShare fields are now updated.
104
+ * ```
105
+ */
60
106
  this.emitRewards = () => {
61
107
  const currentTimestamp = (0, dayjs_1.default)().valueOf();
62
- // ia. Check that the vault has deposits.
108
+ // If no staked amount, no distribution
63
109
  if (this.stakingPool.stakedAmount === BigInt(0))
64
110
  return;
65
111
  const rewardCoins = utils_1.Helpers.deepCopy(this.stakingPool.rewardCoins);
@@ -87,27 +133,45 @@ class FarmsStakingPool extends caller_1.Caller {
87
133
  numberOfEmissions * rewardCoin.emissionSchedulesMs;
88
134
  }
89
135
  };
136
+ /**
137
+ * Computes an approximate APR for a specific reward coin, based on the current
138
+ * emission rate, coin price, pool TVL, and the lock multiplier range. This assumes
139
+ * maximum lock multiplier for the final APR result.
140
+ *
141
+ * @param inputs - Includes the `coinType`, its `price` and `decimals`, plus the total `tvlUsd` in the pool.
142
+ * @returns A numeric APR (0.05 = 5%).
143
+ */
90
144
  this.calcApr = (inputs) => {
91
145
  const { coinType, price, decimals, tvlUsd } = inputs;
92
146
  if (price <= 0 || tvlUsd <= 0)
93
147
  return 0;
94
- // this.emitRewards();
95
148
  const rewardCoin = this.rewardCoin({ coinType });
96
149
  const currentTimestamp = (0, dayjs_1.default)().valueOf();
150
+ // If the current emission rate is below the actual supply, or if the pool hasn't started or is ended, yield 0
97
151
  if (rewardCoin.emissionRate > rewardCoin.actualRewards)
98
152
  return 0;
99
153
  if (rewardCoin.emissionStartTimestamp > currentTimestamp ||
100
- currentTimestamp > this.stakingPool.emissionEndTimestamp)
154
+ currentTimestamp > this.stakingPool.emissionEndTimestamp) {
101
155
  return 0;
102
- const emissionRateUsd = coin_1.Coin.balanceWithDecimals(rewardCoin.emissionRate, decimals) * price;
156
+ }
157
+ const emissionRateTokens = rewardCoin.emissionRate;
158
+ const emissionRateUsd = coin_1.Coin.balanceWithDecimals(emissionRateTokens, decimals) * price;
103
159
  dayjs_1.default.extend(duration_1.default);
104
160
  const oneYearMs = dayjs_1.default.duration(1, "year").asMilliseconds();
105
161
  const rewardsUsdOneYear = emissionRateUsd * (oneYearMs / rewardCoin.emissionSchedulesMs);
162
+ // The final APR is normalized by total staked value and the maximum lock multiplier
106
163
  const apr = rewardsUsdOneYear /
107
164
  tvlUsd /
108
165
  utils_1.Casting.bigIntToFixedNumber(this.stakingPool.maxLockMultiplier);
109
166
  return apr < 0 ? 0 : isNaN(apr) ? 0 : apr;
110
167
  };
168
+ /**
169
+ * Computes the total APR contributed by all reward coin types in this pool, summing
170
+ * up the individual APR for each coin type. This also assumes max lock multiplier.
171
+ *
172
+ * @param inputs - Contains price data (`coinsToPrice`), decimal data (`coinsToDecimals`), and the total TVL in USD.
173
+ * @returns The sum of all coin APRs (0.10 = 10%).
174
+ */
111
175
  this.calcTotalApr = (inputs) => {
112
176
  const { coinsToPrice, coinsToDecimals, tvlUsd } = inputs;
113
177
  const aprs = this.rewardCoinTypes().map((coinType) => this.calcApr({
@@ -118,6 +182,14 @@ class FarmsStakingPool extends caller_1.Caller {
118
182
  }));
119
183
  return utils_1.Helpers.sum(aprs);
120
184
  };
185
+ /**
186
+ * Given a lock duration in ms, calculates the lock multiplier to be used by staked positions.
187
+ * This function clamps the input duration between the pool's `minLockDurationMs` and
188
+ * `maxLockDurationMs`.
189
+ *
190
+ * @param inputs - An object containing the `lockDurationMs` for which to calculate a multiplier.
191
+ * @returns A `FarmsMultiplier` (bigint) representing the scaled factor (1.0 = 1e9 if using fixedOneB).
192
+ */
121
193
  this.calcMultiplier = (inputs) => {
122
194
  const lockDurationMs = inputs.lockDurationMs > this.stakingPool.maxLockDurationMs
123
195
  ? this.stakingPool.maxLockDurationMs
@@ -141,6 +213,9 @@ class FarmsStakingPool extends caller_1.Caller {
141
213
  // =========================================================================
142
214
  // Helpers
143
215
  // =========================================================================
216
+ /**
217
+ * Provides access to the farm-specific provider methods for building transactions.
218
+ */
144
219
  this.useProvider = () => {
145
220
  var _a;
146
221
  const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Farms();
@@ -149,7 +224,6 @@ class FarmsStakingPool extends caller_1.Caller {
149
224
  return provider;
150
225
  };
151
226
  this.stakingPool = stakingPool;
152
- // this.emitRewards();
153
227
  }
154
228
  // =========================================================================
155
229
  // Public
@@ -157,6 +231,17 @@ class FarmsStakingPool extends caller_1.Caller {
157
231
  // =========================================================================
158
232
  // Stats
159
233
  // =========================================================================
234
+ /**
235
+ * Fetches the total value locked (TVL) for this staking pool alone.
236
+ *
237
+ * @returns A `number` representing this pool's TVL in USD (or another currency).
238
+ *
239
+ * @example
240
+ * ```typescript
241
+ * const poolTvl = await someFarmsPool.getTVL();
242
+ * console.log(poolTvl);
243
+ * ```
244
+ */
160
245
  getTVL() {
161
246
  return __awaiter(this, void 0, void 0, function* () {
162
247
  return new farms_1.Farms(this.config, this.Provider).getTVL({
@@ -164,6 +249,17 @@ class FarmsStakingPool extends caller_1.Caller {
164
249
  });
165
250
  });
166
251
  }
252
+ /**
253
+ * Fetches the total value locked (TVL) of the reward coins in this specific staking pool.
254
+ *
255
+ * @returns A `number` representing this pool's reward TVL.
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * const rewardTvl = await someFarmsPool.getRewardsTVL();
260
+ * console.log(rewardTvl);
261
+ * ```
262
+ */
167
263
  getRewardsTVL() {
168
264
  return __awaiter(this, void 0, void 0, function* () {
169
265
  return new farms_1.Farms(this.config, this.Provider).getRewardsTVL({
@@ -171,63 +267,35 @@ class FarmsStakingPool extends caller_1.Caller {
171
267
  });
172
268
  });
173
269
  }
174
- // public calc_emitted_rewards(): bigint[] {
175
- // let emitted_rewards: bigint[] = [];
176
- // let length = this.stakingPool.rewardCoins.length;
177
- // let index = 0;
178
- // while (index < length) {
179
- // let emission_start_timestamp_ms =
180
- // this.stakingPool.rewardCoins[index].emissionStartTimestamp;
181
- // let last_reward_timestamp_ms =
182
- // this.stakingPool.rewardCoins[index].lastRewardTimestamp;
183
- // emitted_rewards.push(
184
- // this.calcRewardsEmittedFromTimeTmToTn({
185
- // timestampTm: emission_start_timestamp_ms,
186
- // timestampTn: last_reward_timestamp_ms,
187
- // rewardCoin: this.stakingPool.rewardCoins[index],
188
- // })
189
- // );
190
- // index = index + 1;
191
- // }
192
- // return emitted_rewards;
193
- // }
194
- // public calc_emitted_rewards_for(inputs: {
195
- // rewardCoinIndex: number;
196
- // }): bigint {
197
- // let reward_index = inputs.rewardCoinIndex;
198
- // let emission_start_timestamp_ms =
199
- // this.stakingPool.rewardCoins[reward_index].emissionStartTimestamp;
200
- // let last_reward_timestamp_ms =
201
- // this.stakingPool.rewardCoins[reward_index].lastRewardTimestamp;
202
- // return this.calcRewardsEmittedFromTimeTmToTn({
203
- // timestampTm: emission_start_timestamp_ms,
204
- // timestampTn: last_reward_timestamp_ms,
205
- // rewardCoin: this.stakingPool.rewardCoins[reward_index],
206
- // });
207
- // }
208
270
  // =========================================================================
209
271
  // Transactions
210
272
  // =========================================================================
211
273
  // =========================================================================
212
274
  // Staking Transactions
213
275
  // =========================================================================
276
+ /**
277
+ * Builds a transaction to stake tokens into this pool, optionally locking them.
278
+ *
279
+ * @param inputs - Contains `stakeAmount`, `lockDurationMs`, `walletAddress`, and optional sponsorship.
280
+ * @returns A transaction object (or bytes) that can be signed and executed to create a staked position.
281
+ */
214
282
  getStakeTransaction(inputs) {
215
283
  return __awaiter(this, void 0, void 0, function* () {
216
284
  const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
217
285
  return this.version() === 1
218
286
  ? this.useProvider().fetchBuildStakeTxV1(args)
219
- : (() => {
220
- // if (!inputs.lockEnforcement)
221
- // throw new Error(
222
- // "`lockEnforcement` argument required for V2 transaction"
223
- // );
224
- return this.useProvider().fetchBuildStakeTxV2(Object.assign({}, args));
225
- })();
287
+ : this.useProvider().fetchBuildStakeTxV2(Object.assign({}, args));
226
288
  });
227
289
  }
228
290
  // =========================================================================
229
291
  // Reward Harvesting Transactions
230
292
  // =========================================================================
293
+ /**
294
+ * Builds a transaction to harvest rewards from multiple staked positions in this pool.
295
+ *
296
+ * @param inputs - Contains `stakedPositionIds`, the `walletAddress`, and optionally any others.
297
+ * @returns A transaction that can be signed and executed to claim rewards from multiple positions.
298
+ */
231
299
  getHarvestRewardsTransaction(inputs) {
232
300
  return __awaiter(this, void 0, void 0, function* () {
233
301
  const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId, rewardCoinTypes: this.nonZeroRewardCoinTypes() });
@@ -239,6 +307,12 @@ class FarmsStakingPool extends caller_1.Caller {
239
307
  // =========================================================================
240
308
  // Mutation/Creation Transactions (Owner Only)
241
309
  // =========================================================================
310
+ /**
311
+ * Builds a transaction to increase the emission rate (or schedule) for specific reward coins.
312
+ *
313
+ * @param inputs - Contains the `ownerCapId` that authorizes changes, plus an array of `rewards` with new emission details.
314
+ * @returns A transaction to be signed and executed by the owner cap holder.
315
+ */
242
316
  getIncreaseRewardsEmissionsTransaction(inputs) {
243
317
  return __awaiter(this, void 0, void 0, function* () {
244
318
  const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
@@ -247,6 +321,12 @@ class FarmsStakingPool extends caller_1.Caller {
247
321
  : this.useProvider().fetchIncreaseStakingPoolRewardsEmissionsTxV2(args);
248
322
  });
249
323
  }
324
+ /**
325
+ * Builds a transaction to update the pool's minimum stake amount, only authorized by the `ownerCapId`.
326
+ *
327
+ * @param inputs - Contains the new `minStakeAmount`, the `ownerCapId`, and the calling `walletAddress`.
328
+ * @returns A transaction that can be signed and executed to change the minimum stake requirement.
329
+ */
250
330
  getUpdateMinStakeAmountTransaction(inputs) {
251
331
  return __awaiter(this, void 0, void 0, function* () {
252
332
  const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
@@ -255,6 +335,13 @@ class FarmsStakingPool extends caller_1.Caller {
255
335
  : this.useProvider().buildSetStakingPoolMinStakeAmountTxV2(args);
256
336
  });
257
337
  }
338
+ /**
339
+ * Builds a transaction granting a one-time admin cap to another address, allowing them to perform specific
340
+ * one-time administrative actions (like initializing a reward).
341
+ *
342
+ * @param inputs - Body containing the `ownerCapId`, the `recipientAddress`, and the `rewardCoinType`.
343
+ * @returns A transaction to be executed by the current pool owner.
344
+ */
258
345
  getGrantOneTimeAdminCapTransaction(inputs) {
259
346
  return this.version() === 1
260
347
  ? this.useProvider().buildGrantOneTimeAdminCapTxV1(inputs)
@@ -263,6 +350,13 @@ class FarmsStakingPool extends caller_1.Caller {
263
350
  // =========================================================================
264
351
  // Mutation Transactions (Owner/Admin Only)
265
352
  // =========================================================================
353
+ /**
354
+ * Builds a transaction to initialize a new reward coin in this pool, specifying the amount, emission rate,
355
+ * and schedule parameters. This can be done by either the `ownerCapId` or a `oneTimeAdminCapId`.
356
+ *
357
+ * @param inputs - Contains emission info (rate, schedule) and which cap is used (`ownerCapId` or `oneTimeAdminCapId`).
358
+ * @returns A transaction object for the reward initialization.
359
+ */
266
360
  getInitializeRewardTransaction(inputs) {
267
361
  return __awaiter(this, void 0, void 0, function* () {
268
362
  const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
@@ -271,6 +365,13 @@ class FarmsStakingPool extends caller_1.Caller {
271
365
  : this.useProvider().fetchBuildInitializeStakingPoolRewardTxV2(args);
272
366
  });
273
367
  }
368
+ /**
369
+ * Builds a transaction to add more reward coins (top-up) to an existing reward
370
+ * coin configuration, either as the owner or via a one-time admin cap.
371
+ *
372
+ * @param inputs - Contains an array of reward objects, each specifying amount and coin type.
373
+ * @returns A transaction that can be signed and executed to increase the reward distribution pool.
374
+ */
274
375
  getTopUpRewardsTransaction(inputs) {
275
376
  return __awaiter(this, void 0, void 0, function* () {
276
377
  const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
@@ -285,27 +386,28 @@ class FarmsStakingPool extends caller_1.Caller {
285
386
  // =========================================================================
286
387
  // Calculations
287
388
  // =========================================================================
389
+ /**
390
+ * Updates `rewardsAccumulatedPerShare` by distributing `rewardsToEmit` among
391
+ * the total staked amount with multiplier. This mimics on-chain distribution logic.
392
+ *
393
+ * @param inputs - Contains the `rewardsToEmit` and which `rewardCoinIndex` to update.
394
+ */
288
395
  increaseRewardsAccumulatedPerShare(inputs) {
289
396
  const { rewardsToEmit, rewardCoinIndex } = inputs;
290
- // i. Calculate the pro-rata amount of rewards allocated to each staked amount.
397
+ const stakedWithMultiplier = this.stakingPool.stakedAmountWithMultiplier;
398
+ if (stakedWithMultiplier === BigInt(0))
399
+ return;
400
+ // Distribute proportionally
291
401
  const newRewardsAccumulatedPerShare = (rewardsToEmit * BigInt(1000000000000000000)) /
292
- this.stakingPool.stakedAmountWithMultiplier;
402
+ stakedWithMultiplier;
293
403
  if (newRewardsAccumulatedPerShare === BigInt(0))
294
404
  return;
295
- // ii. Increase the amount of rewards emitted per share.
296
405
  this.stakingPool.rewardCoins[rewardCoinIndex].rewardsAccumulatedPerShare += newRewardsAccumulatedPerShare;
297
406
  }
298
- rewardsRemaining(inputs) {
299
- const rewardCoin = this.stakingPool.rewardCoins[inputs.rewardCoinIndex];
300
- const currentTimestamp = (0, dayjs_1.default)().valueOf();
301
- const numberOfEmissions = BigInt(Math.floor((currentTimestamp - rewardCoin.emissionStartTimestamp) /
302
- rewardCoin.emissionSchedulesMs));
303
- const emittedRewards = rewardCoin.emissionRate * numberOfEmissions;
304
- const totalRewards = rewardCoin.rewards;
305
- if (totalRewards <= emittedRewards)
306
- return BigInt(0);
307
- return totalRewards - emittedRewards;
308
- }
407
+ /**
408
+ * Computes how many rewards to emit based on the time since `lastRewardTimestamp` and
409
+ * the pool's emission schedule, clamped by the total `rewardsRemaining`.
410
+ */
309
411
  calcRewardsToEmit(inputs) {
310
412
  const { rewardCoin } = inputs;
311
413
  const currentTimestamp = (0, dayjs_1.default)().valueOf();
@@ -315,18 +417,22 @@ class FarmsStakingPool extends caller_1.Caller {
315
417
  timestampTn: currentTimestamp,
316
418
  rewardCoin,
317
419
  });
318
- const rewardsRemaining = rewardCoin.rewardsRemaining;
420
+ const { rewardsRemaining } = rewardCoin;
319
421
  // IMPORTANT: Cap the amount of rewards to emit by the amount of remaining rewards.
320
- //
321
422
  return rewardsRemaining < rewardsToEmit
322
423
  ? rewardsRemaining
323
424
  : rewardsToEmit;
324
425
  }
426
+ /**
427
+ * Calculates how many tokens were emitted between two timestamps (Tm and Tn) for a given reward coin,
428
+ * based on the discrete `emissionRate` and `emissionSchedulesMs`.
429
+ *
430
+ * @param inputs - Contains `timestampTm`, `timestampTn`, and the relevant `rewardCoin`.
431
+ * @returns The total number of tokens emitted in that time window.
432
+ */
325
433
  calcRewardsEmittedFromTimeTmToTn(inputs) {
326
434
  const { timestampTm, timestampTn, rewardCoin } = inputs;
327
- const numberOfEmissionsFromTimeTmToTn = (timestampTn - timestampTm) /
328
- // -----------------------------------------------
329
- rewardCoin.emissionSchedulesMs;
435
+ const numberOfEmissionsFromTimeTmToTn = (timestampTn - timestampTm) / rewardCoin.emissionSchedulesMs;
330
436
  return (BigInt(Math.floor(numberOfEmissionsFromTimeTmToTn)) *
331
437
  rewardCoin.emissionRate);
332
438
  }