aftermath-ts-sdk 1.2.51-temp.0 → 1.2.52-perps.3

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 (216) hide show
  1. package/README.md +61 -27
  2. package/dist/general/apiHelpers/eventsApiHelpers.d.ts +1 -1
  3. package/dist/general/apiHelpers/eventsApiHelpers.d.ts.map +1 -1
  4. package/dist/general/apiHelpers/eventsApiHelpers.js +4 -1
  5. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts +6 -0
  6. package/dist/general/apiHelpers/transactionsApiHelpers.d.ts.map +1 -1
  7. package/dist/general/apiHelpers/transactionsApiHelpers.js +46 -0
  8. package/dist/general/dynamicGas/dynamicGas.d.ts +34 -0
  9. package/dist/general/dynamicGas/dynamicGas.d.ts.map +1 -1
  10. package/dist/general/dynamicGas/dynamicGas.js +34 -0
  11. package/dist/general/dynamicGas/dynamicGasTypes.d.ts +25 -0
  12. package/dist/general/dynamicGas/dynamicGasTypes.d.ts.map +1 -1
  13. package/dist/general/prices/coinGeckoTypes.d.ts +2 -0
  14. package/dist/general/prices/coinGeckoTypes.d.ts.map +1 -1
  15. package/dist/general/prices/prices.d.ts +73 -0
  16. package/dist/general/prices/prices.d.ts.map +1 -1
  17. package/dist/general/prices/prices.js +73 -0
  18. package/dist/general/providers/aftermath.d.ts +107 -27
  19. package/dist/general/providers/aftermath.d.ts.map +1 -1
  20. package/dist/general/providers/aftermath.js +110 -30
  21. package/dist/general/providers/aftermathApi.d.ts +128 -10
  22. package/dist/general/providers/aftermathApi.d.ts.map +1 -1
  23. package/dist/general/providers/aftermathApi.js +133 -14
  24. package/dist/general/types/castingTypes.d.ts +15 -7
  25. package/dist/general/types/castingTypes.d.ts.map +1 -1
  26. package/dist/general/types/castingTypes.js +6 -0
  27. package/dist/general/types/configTypes.d.ts +14 -9
  28. package/dist/general/types/configTypes.d.ts.map +1 -1
  29. package/dist/general/types/generalTypes.d.ts +229 -7
  30. package/dist/general/types/generalTypes.d.ts.map +1 -1
  31. package/dist/general/types/moveErrorsInterface.d.ts +1 -1
  32. package/dist/general/types/moveErrorsInterface.d.ts.map +1 -1
  33. package/dist/general/types/suiTypes.d.ts +0 -16
  34. package/dist/general/types/suiTypes.d.ts.map +1 -1
  35. package/dist/general/types/suiTypes.js +3 -25
  36. package/dist/general/utils/caller.d.ts +5 -2
  37. package/dist/general/utils/caller.d.ts.map +1 -1
  38. package/dist/general/utils/caller.js +9 -1
  39. package/dist/general/utils/casting.d.ts +156 -7
  40. package/dist/general/utils/casting.d.ts.map +1 -1
  41. package/dist/general/utils/casting.js +159 -20
  42. package/dist/general/utils/fixedUtils.d.ts +89 -2
  43. package/dist/general/utils/fixedUtils.d.ts.map +1 -1
  44. package/dist/general/utils/fixedUtils.js +81 -4
  45. package/dist/general/utils/helpers.d.ts +327 -10
  46. package/dist/general/utils/helpers.d.ts.map +1 -1
  47. package/dist/general/utils/helpers.js +409 -91
  48. package/dist/general/utils/iFixedUtils.d.ts +64 -0
  49. package/dist/general/utils/iFixedUtils.d.ts.map +1 -1
  50. package/dist/general/utils/iFixedUtils.js +64 -0
  51. package/dist/general/wallet/wallet.d.ts +76 -1
  52. package/dist/general/wallet/wallet.d.ts.map +1 -1
  53. package/dist/general/wallet/wallet.js +75 -5
  54. package/dist/packages/auth/auth.d.ts +113 -4
  55. package/dist/packages/auth/auth.d.ts.map +1 -1
  56. package/dist/packages/auth/auth.js +190 -59
  57. package/dist/packages/auth/authTypes.d.ts +66 -0
  58. package/dist/packages/auth/authTypes.d.ts.map +1 -1
  59. package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
  60. package/dist/packages/coin/api/coinApi.js +29 -20
  61. package/dist/packages/coin/coin.d.ts +256 -1
  62. package/dist/packages/coin/coin.d.ts.map +1 -1
  63. package/dist/packages/coin/coin.js +246 -15
  64. package/dist/packages/coin/coinTypes.d.ts +95 -0
  65. package/dist/packages/coin/coinTypes.d.ts.map +1 -1
  66. package/dist/packages/dca/api/dcaApi.d.ts +2 -0
  67. package/dist/packages/dca/api/dcaApi.d.ts.map +1 -1
  68. package/dist/packages/dca/api/dcaApi.js +6 -3
  69. package/dist/packages/dca/dca.d.ts +125 -35
  70. package/dist/packages/dca/dca.d.ts.map +1 -1
  71. package/dist/packages/dca/dca.js +135 -43
  72. package/dist/packages/dca/dcaTypes.d.ts +217 -42
  73. package/dist/packages/dca/dcaTypes.d.ts.map +1 -1
  74. package/dist/packages/farms/api/farmsApi.d.ts +725 -58
  75. package/dist/packages/farms/api/farmsApi.d.ts.map +1 -1
  76. package/dist/packages/farms/api/farmsApi.js +1149 -153
  77. package/dist/packages/farms/api/farmsApiCasting.d.ts +34 -18
  78. package/dist/packages/farms/api/farmsApiCasting.d.ts.map +1 -1
  79. package/dist/packages/farms/api/farmsApiCasting.js +218 -17
  80. package/dist/packages/farms/api/farmsApiCastingTypes.d.ts +117 -21
  81. package/dist/packages/farms/api/farmsApiCastingTypes.d.ts.map +1 -1
  82. package/dist/packages/farms/farms.d.ts +188 -3
  83. package/dist/packages/farms/farms.d.ts.map +1 -1
  84. package/dist/packages/farms/farms.js +192 -12
  85. package/dist/packages/farms/farmsStakedPosition.d.ts +143 -8
  86. package/dist/packages/farms/farmsStakedPosition.d.ts.map +1 -1
  87. package/dist/packages/farms/farmsStakedPosition.js +243 -137
  88. package/dist/packages/farms/farmsStakingPool.d.ts +169 -3
  89. package/dist/packages/farms/farmsStakingPool.d.ts.map +1 -1
  90. package/dist/packages/farms/farmsStakingPool.js +212 -70
  91. package/dist/packages/farms/farmsTypes.d.ts +302 -2
  92. package/dist/packages/farms/farmsTypes.d.ts.map +1 -1
  93. package/dist/packages/farms/farmsTypes.js +18 -0
  94. package/dist/packages/faucet/api/faucetApi.d.ts +9 -17
  95. package/dist/packages/faucet/api/faucetApi.d.ts.map +1 -1
  96. package/dist/packages/faucet/api/faucetApi.js +44 -49
  97. package/dist/packages/faucet/api/faucetApiCasting.d.ts.map +1 -1
  98. package/dist/packages/faucet/api/faucetApiCasting.js +8 -5
  99. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts +1 -4
  100. package/dist/packages/faucet/api/faucetApiCastingTypes.d.ts.map +1 -1
  101. package/dist/packages/faucet/faucet.d.ts +1 -1
  102. package/dist/packages/faucet/faucet.d.ts.map +1 -1
  103. package/dist/packages/faucet/faucet.js +1 -1
  104. package/dist/packages/faucet/faucetTypes.d.ts +2 -3
  105. package/dist/packages/faucet/faucetTypes.d.ts.map +1 -1
  106. package/dist/packages/limitOrders/api/limitOrdersApi.d.ts +12 -0
  107. package/dist/packages/limitOrders/api/limitOrdersApi.d.ts.map +1 -0
  108. package/dist/packages/limitOrders/api/limitOrdersApi.js +25 -0
  109. package/dist/packages/limitOrders/index.d.ts +2 -0
  110. package/dist/packages/limitOrders/index.d.ts.map +1 -0
  111. package/dist/packages/limitOrders/index.js +17 -0
  112. package/dist/packages/limitOrders/limitOrders.d.ts +143 -0
  113. package/dist/packages/limitOrders/limitOrders.d.ts.map +1 -0
  114. package/dist/packages/limitOrders/limitOrders.js +190 -0
  115. package/dist/packages/limitOrders/limitOrdersTypes.d.ts +211 -0
  116. package/dist/packages/limitOrders/limitOrdersTypes.d.ts.map +1 -0
  117. package/dist/packages/multisig/multisig.d.ts +34 -5
  118. package/dist/packages/multisig/multisig.d.ts.map +1 -1
  119. package/dist/packages/multisig/multisig.js +33 -4
  120. package/dist/packages/multisig/multisigTypes.d.ts +17 -0
  121. package/dist/packages/multisig/multisigTypes.d.ts.map +1 -1
  122. package/dist/packages/nftAmm/nftAmm.d.ts +1 -1
  123. package/dist/packages/nftAmm/nftAmm.d.ts.map +1 -1
  124. package/dist/packages/perpetuals/api/perpetualsApi.d.ts +7 -16
  125. package/dist/packages/perpetuals/api/perpetualsApi.d.ts.map +1 -1
  126. package/dist/packages/perpetuals/api/perpetualsApi.js +318 -276
  127. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts +7 -7
  128. package/dist/packages/perpetuals/api/perpetualsApiCasting.d.ts.map +1 -1
  129. package/dist/packages/perpetuals/api/perpetualsApiCasting.js +71 -84
  130. package/dist/packages/perpetuals/perpetuals.d.ts +33 -4
  131. package/dist/packages/perpetuals/perpetuals.d.ts.map +1 -1
  132. package/dist/packages/perpetuals/perpetuals.js +105 -18
  133. package/dist/packages/perpetuals/perpetualsAccount.d.ts +87 -52
  134. package/dist/packages/perpetuals/perpetualsAccount.d.ts.map +1 -1
  135. package/dist/packages/perpetuals/perpetualsAccount.js +544 -91
  136. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts +55 -26
  137. package/dist/packages/perpetuals/perpetualsCastingTypes.d.ts.map +1 -1
  138. package/dist/packages/perpetuals/perpetualsMarket.d.ts +28 -4
  139. package/dist/packages/perpetuals/perpetualsMarket.d.ts.map +1 -1
  140. package/dist/packages/perpetuals/perpetualsMarket.js +75 -13
  141. package/dist/packages/perpetuals/perpetualsTypes.d.ts +263 -213
  142. package/dist/packages/perpetuals/perpetualsTypes.d.ts.map +1 -1
  143. package/dist/packages/perpetuals/perpetualsTypes.js +24 -77
  144. package/dist/packages/pools/pool.d.ts +328 -86
  145. package/dist/packages/pools/pool.d.ts.map +1 -1
  146. package/dist/packages/pools/pool.js +333 -91
  147. package/dist/packages/pools/pools.d.ts +300 -38
  148. package/dist/packages/pools/pools.d.ts.map +1 -1
  149. package/dist/packages/pools/pools.js +306 -52
  150. package/dist/packages/pools/poolsTypes.d.ts +267 -2
  151. package/dist/packages/pools/poolsTypes.d.ts.map +1 -1
  152. package/dist/packages/referralVault/referralVault.d.ts +38 -1
  153. package/dist/packages/referralVault/referralVault.d.ts.map +1 -1
  154. package/dist/packages/referralVault/referralVault.js +37 -0
  155. package/dist/packages/router/router.d.ts +213 -17
  156. package/dist/packages/router/router.d.ts.map +1 -1
  157. package/dist/packages/router/router.js +214 -18
  158. package/dist/packages/router/routerTypes.d.ts +199 -15
  159. package/dist/packages/router/routerTypes.d.ts.map +1 -1
  160. package/dist/packages/staking/staking.d.ts +302 -44
  161. package/dist/packages/staking/staking.d.ts.map +1 -1
  162. package/dist/packages/staking/staking.js +308 -51
  163. package/dist/packages/staking/stakingTypes.d.ts +426 -6
  164. package/dist/packages/staking/stakingTypes.d.ts.map +1 -1
  165. package/dist/packages/staking/stakingTypes.js +19 -0
  166. package/dist/packages/sui/sui.d.ts +40 -1
  167. package/dist/packages/sui/sui.d.ts.map +1 -1
  168. package/dist/packages/sui/sui.js +39 -0
  169. package/dist/packages/suiFrens/stakedSuiFren.d.ts +1 -1
  170. package/dist/packages/suiFrens/stakedSuiFren.d.ts.map +1 -1
  171. package/dist/packages/suiFrens/suiFren.d.ts +1 -1
  172. package/dist/packages/suiFrens/suiFren.d.ts.map +1 -1
  173. package/dist/packages/suiFrens/suiFrens.d.ts +1 -1
  174. package/dist/packages/suiFrens/suiFrens.d.ts.map +1 -1
  175. package/dist/packages/userData/api/userDataApi.d.ts +6 -0
  176. package/dist/packages/userData/api/userDataApi.d.ts.map +1 -0
  177. package/dist/packages/userData/api/userDataApi.js +12 -0
  178. package/dist/packages/userData/index.d.ts +2 -0
  179. package/dist/packages/userData/index.d.ts.map +1 -0
  180. package/dist/packages/userData/index.js +17 -0
  181. package/dist/packages/userData/userData.d.ts +89 -0
  182. package/dist/packages/userData/userData.d.ts.map +1 -0
  183. package/dist/packages/userData/userData.js +119 -0
  184. package/dist/packages/userData/userDataTypes.d.ts +29 -0
  185. package/dist/packages/userData/userDataTypes.d.ts.map +1 -0
  186. package/dist/types.d.ts +0 -1
  187. package/dist/types.d.ts.map +1 -1
  188. package/dist/types.js +0 -2
  189. package/package.json +1 -1
  190. package/dist/general/historicalData/historicalData.d.ts +0 -15
  191. package/dist/general/historicalData/historicalData.d.ts.map +0 -1
  192. package/dist/general/historicalData/historicalData.js +0 -45
  193. package/dist/general/historicalData/historicalDataTypes.d.ts +0 -10
  194. package/dist/general/historicalData/historicalDataTypes.d.ts.map +0 -1
  195. package/dist/packages/dca/api/dcaApiCasting.d.ts +0 -11
  196. package/dist/packages/dca/api/dcaApiCasting.d.ts.map +0 -1
  197. package/dist/packages/dca/api/dcaApiCasting.js +0 -186
  198. package/dist/packages/dca/api/dcaApiCastingTypes.d.ts +0 -142
  199. package/dist/packages/dca/api/dcaApiCastingTypes.d.ts.map +0 -1
  200. package/dist/packages/oracle/api/oracleApi.d.ts +0 -21
  201. package/dist/packages/oracle/api/oracleApi.d.ts.map +0 -1
  202. package/dist/packages/oracle/api/oracleApi.js +0 -76
  203. package/dist/packages/oracle/api/oracleApiCasting.d.ts +0 -6
  204. package/dist/packages/oracle/api/oracleApiCasting.d.ts.map +0 -1
  205. package/dist/packages/oracle/api/oracleApiCasting.js +0 -25
  206. package/dist/packages/oracle/oracle.d.ts +0 -15
  207. package/dist/packages/oracle/oracle.d.ts.map +0 -1
  208. package/dist/packages/oracle/oracle.js +0 -46
  209. package/dist/packages/oracle/oracleCastingTypes.d.ts +0 -11
  210. package/dist/packages/oracle/oracleCastingTypes.d.ts.map +0 -1
  211. package/dist/packages/oracle/oracleCastingTypes.js +0 -2
  212. package/dist/packages/oracle/oracleTypes.d.ts +0 -10
  213. package/dist/packages/oracle/oracleTypes.d.ts.map +0 -1
  214. package/dist/packages/oracle/oracleTypes.js +0 -2
  215. /package/dist/{general/historicalData/historicalDataTypes.js → packages/limitOrders/limitOrdersTypes.js} +0 -0
  216. /package/dist/packages/{dca/api/dcaApiCastingTypes.js → userData/userDataTypes.js} +0 -0
@@ -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,32 +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
+ */
48
+ this.version = () => {
49
+ return this.stakingPool.version;
50
+ };
51
+ /**
52
+ * Lists all reward coin types offered by this staking pool.
53
+ *
54
+ * @returns An array of `CoinType` strings.
55
+ */
34
56
  this.rewardCoinTypes = () => {
35
57
  return this.stakingPool.rewardCoins.map((coin) => coin.coinType);
36
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
+ */
37
64
  this.nonZeroRewardCoinTypes = () => {
38
65
  return this.stakingPool.rewardCoins
39
66
  .filter((coin) => coin.emissionRate <= coin.actualRewards &&
40
67
  coin.actualRewards > BigInt(0))
41
68
  .map((coin) => coin.coinType);
42
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
+ */
43
77
  this.rewardCoin = (inputs) => {
44
78
  const foundCoin = this.stakingPool.rewardCoins.find((coin) => coin.coinType === inputs.coinType);
45
79
  if (!foundCoin)
46
80
  throw new Error("Invalid coin type");
47
81
  return foundCoin;
48
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
+ */
49
89
  this.maxLockDurationMs = () => {
50
90
  return Math.max(Math.min(this.stakingPool.maxLockDurationMs, this.stakingPool.emissionEndTimestamp - (0, dayjs_1.default)().valueOf()), 0);
51
91
  };
52
92
  // =========================================================================
53
93
  // Calculations
54
94
  // =========================================================================
55
- // Calculates the amount of rewards that have emitted since the last time this function has been
56
- // 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
+ */
57
106
  this.emitRewards = () => {
58
107
  const currentTimestamp = (0, dayjs_1.default)().valueOf();
59
- // ia. Check that the vault has deposits.
108
+ // If no staked amount, no distribution
60
109
  if (this.stakingPool.stakedAmount === BigInt(0))
61
110
  return;
62
111
  const rewardCoins = utils_1.Helpers.deepCopy(this.stakingPool.rewardCoins);
@@ -84,27 +133,45 @@ class FarmsStakingPool extends caller_1.Caller {
84
133
  numberOfEmissions * rewardCoin.emissionSchedulesMs;
85
134
  }
86
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
+ */
87
144
  this.calcApr = (inputs) => {
88
145
  const { coinType, price, decimals, tvlUsd } = inputs;
89
146
  if (price <= 0 || tvlUsd <= 0)
90
147
  return 0;
91
- // this.emitRewards();
92
148
  const rewardCoin = this.rewardCoin({ coinType });
93
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
94
151
  if (rewardCoin.emissionRate > rewardCoin.actualRewards)
95
152
  return 0;
96
153
  if (rewardCoin.emissionStartTimestamp > currentTimestamp ||
97
- currentTimestamp > this.stakingPool.emissionEndTimestamp)
154
+ currentTimestamp > this.stakingPool.emissionEndTimestamp) {
98
155
  return 0;
99
- 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;
100
159
  dayjs_1.default.extend(duration_1.default);
101
160
  const oneYearMs = dayjs_1.default.duration(1, "year").asMilliseconds();
102
161
  const rewardsUsdOneYear = emissionRateUsd * (oneYearMs / rewardCoin.emissionSchedulesMs);
162
+ // The final APR is normalized by total staked value and the maximum lock multiplier
103
163
  const apr = rewardsUsdOneYear /
104
164
  tvlUsd /
105
165
  utils_1.Casting.bigIntToFixedNumber(this.stakingPool.maxLockMultiplier);
106
166
  return apr < 0 ? 0 : isNaN(apr) ? 0 : apr;
107
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
+ */
108
175
  this.calcTotalApr = (inputs) => {
109
176
  const { coinsToPrice, coinsToDecimals, tvlUsd } = inputs;
110
177
  const aprs = this.rewardCoinTypes().map((coinType) => this.calcApr({
@@ -115,6 +182,14 @@ class FarmsStakingPool extends caller_1.Caller {
115
182
  }));
116
183
  return utils_1.Helpers.sum(aprs);
117
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
+ */
118
193
  this.calcMultiplier = (inputs) => {
119
194
  const lockDurationMs = inputs.lockDurationMs > this.stakingPool.maxLockDurationMs
120
195
  ? this.stakingPool.maxLockDurationMs
@@ -133,11 +208,14 @@ class FarmsStakingPool extends caller_1.Caller {
133
208
  const multiplier = utils_1.Casting.numberToFixedBigInt(newMultiplier);
134
209
  return multiplier < fixedUtils_1.FixedUtils.fixedOneB
135
210
  ? fixedUtils_1.FixedUtils.fixedOneB
136
- : multiplier;
211
+ : utils_1.Helpers.minBigInt(multiplier, this.stakingPool.maxLockMultiplier);
137
212
  };
138
213
  // =========================================================================
139
214
  // Helpers
140
215
  // =========================================================================
216
+ /**
217
+ * Provides access to the farm-specific provider methods for building transactions.
218
+ */
141
219
  this.useProvider = () => {
142
220
  var _a;
143
221
  const provider = (_a = this.Provider) === null || _a === void 0 ? void 0 : _a.Farms();
@@ -146,7 +224,6 @@ class FarmsStakingPool extends caller_1.Caller {
146
224
  return provider;
147
225
  };
148
226
  this.stakingPool = stakingPool;
149
- // this.emitRewards();
150
227
  }
151
228
  // =========================================================================
152
229
  // Public
@@ -154,6 +231,17 @@ class FarmsStakingPool extends caller_1.Caller {
154
231
  // =========================================================================
155
232
  // Stats
156
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
+ */
157
245
  getTVL() {
158
246
  return __awaiter(this, void 0, void 0, function* () {
159
247
  return new farms_1.Farms(this.config, this.Provider).getTVL({
@@ -161,6 +249,17 @@ class FarmsStakingPool extends caller_1.Caller {
161
249
  });
162
250
  });
163
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
+ */
164
263
  getRewardsTVL() {
165
264
  return __awaiter(this, void 0, void 0, function* () {
166
265
  return new farms_1.Farms(this.config, this.Provider).getRewardsTVL({
@@ -168,81 +267,117 @@ class FarmsStakingPool extends caller_1.Caller {
168
267
  });
169
268
  });
170
269
  }
171
- // public calc_emitted_rewards(): bigint[] {
172
- // let emitted_rewards: bigint[] = [];
173
- // let length = this.stakingPool.rewardCoins.length;
174
- // let index = 0;
175
- // while (index < length) {
176
- // let emission_start_timestamp_ms =
177
- // this.stakingPool.rewardCoins[index].emissionStartTimestamp;
178
- // let last_reward_timestamp_ms =
179
- // this.stakingPool.rewardCoins[index].lastRewardTimestamp;
180
- // emitted_rewards.push(
181
- // this.calcRewardsEmittedFromTimeTmToTn({
182
- // timestampTm: emission_start_timestamp_ms,
183
- // timestampTn: last_reward_timestamp_ms,
184
- // rewardCoin: this.stakingPool.rewardCoins[index],
185
- // })
186
- // );
187
- // index = index + 1;
188
- // }
189
- // return emitted_rewards;
190
- // }
191
- // public calc_emitted_rewards_for(inputs: {
192
- // rewardCoinIndex: number;
193
- // }): bigint {
194
- // let reward_index = inputs.rewardCoinIndex;
195
- // let emission_start_timestamp_ms =
196
- // this.stakingPool.rewardCoins[reward_index].emissionStartTimestamp;
197
- // let last_reward_timestamp_ms =
198
- // this.stakingPool.rewardCoins[reward_index].lastRewardTimestamp;
199
- // return this.calcRewardsEmittedFromTimeTmToTn({
200
- // timestampTm: emission_start_timestamp_ms,
201
- // timestampTn: last_reward_timestamp_ms,
202
- // rewardCoin: this.stakingPool.rewardCoins[reward_index],
203
- // });
204
- // }
205
270
  // =========================================================================
206
271
  // Transactions
207
272
  // =========================================================================
208
273
  // =========================================================================
209
274
  // Staking Transactions
210
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
+ */
211
282
  getStakeTransaction(inputs) {
212
283
  return __awaiter(this, void 0, void 0, function* () {
213
- return this.useProvider().fetchBuildStakeTx(Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId }));
284
+ const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
285
+ return this.version() === 1
286
+ ? this.useProvider().fetchBuildStakeTxV1(args)
287
+ : this.useProvider().fetchBuildStakeTxV2(Object.assign({}, args));
214
288
  });
215
289
  }
216
290
  // =========================================================================
217
291
  // Reward Harvesting Transactions
218
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
+ */
219
299
  getHarvestRewardsTransaction(inputs) {
220
300
  return __awaiter(this, void 0, void 0, function* () {
221
- return this.useProvider().fetchBuildHarvestRewardsTx(Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId, rewardCoinTypes: this.nonZeroRewardCoinTypes() }));
301
+ const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId, rewardCoinTypes: this.nonZeroRewardCoinTypes() });
302
+ return this.version() === 1
303
+ ? this.useProvider().fetchBuildHarvestRewardsTxV1(args)
304
+ : this.useProvider().fetchBuildHarvestRewardsTxV2(args);
222
305
  });
223
306
  }
224
307
  // =========================================================================
225
308
  // Mutation/Creation Transactions (Owner Only)
226
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
+ */
227
316
  getIncreaseRewardsEmissionsTransaction(inputs) {
228
317
  return __awaiter(this, void 0, void 0, function* () {
229
- return this.useProvider().fetchIncreaseStakingPoolRewardsEmissionsTx(Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId }));
318
+ const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
319
+ return this.version() === 1
320
+ ? this.useProvider().fetchIncreaseStakingPoolRewardsEmissionsTxV1(args)
321
+ : this.useProvider().fetchIncreaseStakingPoolRewardsEmissionsTxV2(args);
322
+ });
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
+ */
330
+ getUpdateMinStakeAmountTransaction(inputs) {
331
+ return __awaiter(this, void 0, void 0, function* () {
332
+ const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
333
+ return this.version() === 1
334
+ ? this.useProvider().buildSetStakingPoolMinStakeAmountTxV1(args)
335
+ : this.useProvider().buildSetStakingPoolMinStakeAmountTxV2(args);
230
336
  });
231
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
+ */
232
345
  getGrantOneTimeAdminCapTransaction(inputs) {
233
- return this.useProvider().buildGrantOneTimeAdminCapTx(inputs);
346
+ return this.version() === 1
347
+ ? this.useProvider().buildGrantOneTimeAdminCapTxV1(inputs)
348
+ : this.useProvider().buildGrantOneTimeAdminCapTxV2(inputs);
234
349
  }
235
350
  // =========================================================================
236
351
  // Mutation Transactions (Owner/Admin Only)
237
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
+ */
238
360
  getInitializeRewardTransaction(inputs) {
239
361
  return __awaiter(this, void 0, void 0, function* () {
240
- return this.useProvider().fetchBuildInitializeStakingPoolRewardTx(Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId }));
362
+ const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
363
+ return this.version() === 1
364
+ ? this.useProvider().fetchBuildInitializeStakingPoolRewardTxV1(args)
365
+ : this.useProvider().fetchBuildInitializeStakingPoolRewardTxV2(args);
241
366
  });
242
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
+ */
243
375
  getTopUpRewardsTransaction(inputs) {
244
376
  return __awaiter(this, void 0, void 0, function* () {
245
- return this.useProvider().fetchBuildTopUpStakingPoolRewardsTx(Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId }));
377
+ const args = Object.assign(Object.assign({}, inputs), { stakeCoinType: this.stakingPool.stakeCoinType, stakingPoolId: this.stakingPool.objectId });
378
+ return this.version() === 1
379
+ ? this.useProvider().fetchBuildTopUpStakingPoolRewardsTxV1(args)
380
+ : this.useProvider().fetchBuildTopUpStakingPoolRewardsTxV2(args);
246
381
  });
247
382
  }
248
383
  // =========================================================================
@@ -251,27 +386,28 @@ class FarmsStakingPool extends caller_1.Caller {
251
386
  // =========================================================================
252
387
  // Calculations
253
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
+ */
254
395
  increaseRewardsAccumulatedPerShare(inputs) {
255
396
  const { rewardsToEmit, rewardCoinIndex } = inputs;
256
- // 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
257
401
  const newRewardsAccumulatedPerShare = (rewardsToEmit * BigInt(1000000000000000000)) /
258
- this.stakingPool.stakedAmountWithMultiplier;
402
+ stakedWithMultiplier;
259
403
  if (newRewardsAccumulatedPerShare === BigInt(0))
260
404
  return;
261
- // ii. Increase the amount of rewards emitted per share.
262
405
  this.stakingPool.rewardCoins[rewardCoinIndex].rewardsAccumulatedPerShare += newRewardsAccumulatedPerShare;
263
406
  }
264
- rewardsRemaining(inputs) {
265
- const rewardCoin = this.stakingPool.rewardCoins[inputs.rewardCoinIndex];
266
- const currentTimestamp = (0, dayjs_1.default)().valueOf();
267
- const numberOfEmissions = BigInt(Math.floor((currentTimestamp - rewardCoin.emissionStartTimestamp) /
268
- rewardCoin.emissionSchedulesMs));
269
- const emittedRewards = rewardCoin.emissionRate * numberOfEmissions;
270
- const totalRewards = rewardCoin.rewards;
271
- if (totalRewards <= emittedRewards)
272
- return BigInt(0);
273
- return totalRewards - emittedRewards;
274
- }
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
+ */
275
411
  calcRewardsToEmit(inputs) {
276
412
  const { rewardCoin } = inputs;
277
413
  const currentTimestamp = (0, dayjs_1.default)().valueOf();
@@ -281,18 +417,24 @@ class FarmsStakingPool extends caller_1.Caller {
281
417
  timestampTn: currentTimestamp,
282
418
  rewardCoin,
283
419
  });
284
- const rewardsRemaining = rewardCoin.rewardsRemaining;
420
+ const { rewardsRemaining } = rewardCoin;
285
421
  // IMPORTANT: Cap the amount of rewards to emit by the amount of remaining rewards.
286
- //
287
422
  return rewardsRemaining < rewardsToEmit
288
423
  ? rewardsRemaining
289
424
  : rewardsToEmit;
290
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
+ */
291
433
  calcRewardsEmittedFromTimeTmToTn(inputs) {
292
434
  const { timestampTm, timestampTn, rewardCoin } = inputs;
293
- const numberOfEmissionsFromTimeTmToTn = (timestampTn - timestampTm) /
294
- // -----------------------------------------------
295
- rewardCoin.emissionSchedulesMs;
435
+ const numberOfEmissionsFromTimeTmToTn = rewardCoin.emissionSchedulesMs === 0
436
+ ? 0
437
+ : (timestampTn - timestampTm) / rewardCoin.emissionSchedulesMs;
296
438
  return (BigInt(Math.floor(numberOfEmissionsFromTimeTmToTn)) *
297
439
  rewardCoin.emissionRate);
298
440
  }