@raac/rpc 1.2.0-beta.10 → 1.2.0-beta.11

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 (243) hide show
  1. package/dist/RPCLibrary.js +2 -0
  2. package/dist/artifacts/core/governance/gauges/BaseGauge.sol/BaseGauge.json +113 -20
  3. package/dist/artifacts/core/governance/gauges/GaugeController.sol/GaugeController.json +259 -31
  4. package/dist/artifacts/core/governance/gauges/GaugeRewardsDistributor.sol/GaugeRewardsDistributor.json +159 -31
  5. package/dist/artifacts/core/governance/gauges/RAACGauge.sol/RAACGauge.json +115 -22
  6. package/dist/artifacts/core/governance/gauges/RWAGauge.sol/RWAGauge.json +115 -22
  7. package/dist/configs/chains/1.json +22 -25
  8. package/dist/configs/chains/11155111.json +56 -71
  9. package/dist/configs/chains/17000.json +22 -25
  10. package/dist/configs/chains/18453.json +22 -25
  11. package/dist/configs/chains/8453.json +61 -31
  12. package/dist/contracts/findContract.js +11 -4
  13. package/dist/contracts/getContractAddress.js +0 -1
  14. package/dist/contracts/governance/distributor/claimAll.js +18 -11
  15. package/dist/contracts/governance/distributor/claimForGauge.js +18 -12
  16. package/dist/contracts/governance/distributor/deposit.js +17 -12
  17. package/dist/contracts/governance/distributor/getClaimableForGauge.js +10 -9
  18. package/dist/contracts/governance/distributor/getClaimedAtEpoch.js +11 -10
  19. package/dist/contracts/governance/distributor/getDepositedAtEpoch.js +8 -8
  20. package/dist/contracts/governance/distributor/getDustLastProcessedEpoch.js +28 -0
  21. package/dist/contracts/governance/distributor/getGaugeController.js +7 -7
  22. package/dist/contracts/governance/distributor/getLastClaimedEpoch.js +10 -9
  23. package/dist/contracts/governance/distributor/getMaxClaimBound.js +29 -0
  24. package/dist/contracts/governance/distributor/getPeriodDuration.js +7 -7
  25. package/dist/contracts/governance/distributor/getRewardToken.js +7 -7
  26. package/dist/contracts/governance/distributor/getRewardTokenInfo.js +7 -7
  27. package/dist/contracts/governance/distributor/getRewardTokenStats.js +7 -7
  28. package/dist/contracts/governance/distributor/index.js +5 -2
  29. package/dist/contracts/governance/distributor/setController.js +17 -12
  30. package/dist/contracts/governance/distributor/setLastClaimedEpoch.js +32 -0
  31. package/dist/contracts/governance/distributor/setMaxClaimBound.js +31 -0
  32. package/dist/contracts/governance/distributor/withdrawDust.js +31 -0
  33. package/dist/contracts/governance/distributor/withdrawRemovedGaugeRewards.js +19 -13
  34. package/dist/contracts/governance/gauge/_apy.js +122 -0
  35. package/dist/contracts/governance/gauge/_tokens.js +36 -0
  36. package/dist/contracts/governance/gauge/addRewardToken.js +2 -12
  37. package/dist/contracts/governance/gauge/approveGaugeToken.js +31 -0
  38. package/dist/contracts/governance/gauge/claimExtraReward.js +2 -12
  39. package/dist/contracts/governance/gauge/claimExtraRewards.js +2 -12
  40. package/dist/contracts/governance/gauge/claimOnBehalfOf.js +2 -12
  41. package/dist/contracts/governance/gauge/claimRewardToken.js +3 -13
  42. package/dist/contracts/governance/gauge/claimRewardsFor.js +2 -12
  43. package/dist/contracts/governance/gauge/depositRewardToken.js +2 -12
  44. package/dist/contracts/governance/gauge/getAllPendingExtraRewards.js +2 -9
  45. package/dist/contracts/governance/gauge/getApy.js +44 -0
  46. package/dist/contracts/governance/gauge/getBalanceOf.js +2 -15
  47. package/dist/contracts/governance/gauge/getControllerAddress.js +2 -9
  48. package/dist/contracts/governance/gauge/getDecimalAdjustment.js +2 -9
  49. package/dist/contracts/governance/gauge/getDepositRAACOnClaim.js +2 -9
  50. package/dist/contracts/governance/gauge/getDistributorData.js +2 -9
  51. package/dist/contracts/governance/gauge/getDistributors.js +2 -9
  52. package/dist/contracts/governance/gauge/getEarnedExtraReward.js +30 -0
  53. package/dist/contracts/governance/gauge/getEarnedReward.js +8 -14
  54. package/dist/contracts/governance/gauge/getExtraRewardTokens.js +2 -9
  55. package/dist/contracts/governance/gauge/getGaugeData.js +39 -0
  56. package/dist/contracts/governance/gauge/getGaugeRewardTokenData.js +2 -9
  57. package/dist/contracts/governance/gauge/getPauseStatus.js +31 -0
  58. package/dist/contracts/governance/gauge/getPendingExtraRewards.js +2 -9
  59. package/dist/contracts/governance/gauge/getPendingRewards.js +8 -14
  60. package/dist/contracts/governance/gauge/getPeriodBoundaries.js +2 -15
  61. package/dist/contracts/governance/gauge/getPeriodDuration.js +2 -15
  62. package/dist/contracts/governance/gauge/getRaacAutolockMin.js +2 -9
  63. package/dist/contracts/governance/gauge/getRawBalanceOf.js +2 -15
  64. package/dist/contracts/governance/gauge/getRawTotalSupply.js +2 -15
  65. package/dist/contracts/governance/gauge/getRewardTokens.js +28 -0
  66. package/dist/contracts/governance/gauge/getTotalSupply.js +2 -15
  67. package/dist/contracts/governance/gauge/getUserApy.js +71 -0
  68. package/dist/contracts/governance/gauge/getUserClaimableRewards.js +21 -73
  69. package/dist/contracts/governance/gauge/getUserGaugeState.js +44 -0
  70. package/dist/contracts/governance/gauge/getUserRewardTokenData.js +2 -9
  71. package/dist/contracts/governance/gauge/getUserWeight.js +2 -9
  72. package/dist/contracts/governance/gauge/index.js +11 -1
  73. package/dist/contracts/governance/gauge/isPaused.js +4 -11
  74. package/dist/contracts/governance/gauge/manageDistributor.js +2 -12
  75. package/dist/contracts/governance/gauge/pullRewardsFromDistributor.js +30 -0
  76. package/dist/contracts/governance/gauge/setController.js +2 -12
  77. package/dist/contracts/governance/gauge/setDepositRAACOnClaim.js +2 -12
  78. package/dist/contracts/governance/gauge/setEmergencyPaused.js +2 -12
  79. package/dist/contracts/governance/gauge/setGaugeRewardDistributor.js +2 -12
  80. package/dist/contracts/governance/gauge/setRaacAutolockMin.js +2 -12
  81. package/dist/contracts/governance/gauge/stake.js +2 -18
  82. package/dist/contracts/governance/gauge/unwrapStakingToken.js +28 -0
  83. package/dist/contracts/governance/gauge/updateUserRewards.js +2 -18
  84. package/dist/contracts/governance/gauge/withdraw.js +2 -18
  85. package/dist/contracts/governance/gauge/wrapStakingToken.js +28 -0
  86. package/dist/contracts/governance/gaugeController/addGauge.js +19 -11
  87. package/dist/contracts/governance/gaugeController/batchVote.js +20 -12
  88. package/dist/contracts/governance/gaugeController/calculateBoost.js +20 -23
  89. package/dist/contracts/governance/gaugeController/forceCompleteCheckpoint.js +19 -11
  90. package/dist/contracts/governance/gaugeController/getActiveGaugeCount.js +28 -0
  91. package/dist/contracts/governance/gaugeController/getActiveGauges.js +10 -13
  92. package/dist/contracts/governance/gaugeController/getConstants.js +10 -18
  93. package/dist/contracts/governance/gaugeController/getCurrentEpoch.js +8 -7
  94. package/dist/contracts/governance/gaugeController/getExpiredGaugeVotePower.js +30 -0
  95. package/dist/contracts/governance/gaugeController/getGauge.js +11 -9
  96. package/dist/contracts/governance/gaugeController/getGaugeDistributor.js +28 -0
  97. package/dist/contracts/governance/gaugeController/getGaugeEmissions.js +15 -9
  98. package/dist/contracts/governance/gaugeController/getGaugeRelativeWeight.js +19 -15
  99. package/dist/contracts/governance/gaugeController/getGaugeRelativeWeightView.js +12 -10
  100. package/dist/contracts/governance/gaugeController/getGaugeWeight.js +10 -8
  101. package/dist/contracts/governance/gaugeController/getLastVoteTime.js +11 -9
  102. package/dist/contracts/governance/gaugeController/getMaxVoteBuckets.js +28 -0
  103. package/dist/contracts/governance/gaugeController/getNextEpoch.js +8 -7
  104. package/dist/contracts/governance/gaugeController/getRegisteredGaugeList.js +28 -0
  105. package/dist/contracts/governance/gaugeController/getTotalWeight.js +8 -7
  106. package/dist/contracts/governance/gaugeController/getUserGaugeVotePower.js +11 -9
  107. package/dist/contracts/governance/gaugeController/getUserVotePowerRemaining.js +10 -9
  108. package/dist/contracts/governance/gaugeController/getVeToken.js +8 -7
  109. package/dist/contracts/governance/gaugeController/getVoteUserLocks.js +32 -0
  110. package/dist/contracts/governance/gaugeController/getVoteUserPower.js +8 -7
  111. package/dist/contracts/governance/gaugeController/getVoteUserSlope.js +12 -10
  112. package/dist/contracts/governance/gaugeController/index.js +10 -1
  113. package/dist/contracts/governance/gaugeController/isGaugeActive.js +11 -9
  114. package/dist/contracts/governance/gaugeController/isPaused.js +9 -8
  115. package/dist/contracts/governance/gaugeController/kick.js +17 -10
  116. package/dist/contracts/governance/gaugeController/removeGauge.js +20 -11
  117. package/dist/contracts/governance/gaugeController/removePowerFromGauge.js +19 -11
  118. package/dist/contracts/governance/gaugeController/setBoostAmplificationEnabled.js +20 -12
  119. package/dist/contracts/governance/gaugeController/setDistributor.js +31 -0
  120. package/dist/contracts/governance/gaugeController/setEmergencyGaugePause.js +20 -12
  121. package/dist/contracts/governance/gaugeController/setEmergencyGaugePauseBatch.js +33 -0
  122. package/dist/contracts/governance/gaugeController/setEmergencyPause.js +18 -11
  123. package/dist/contracts/governance/gaugeController/setMaxVoteBuckets.js +31 -0
  124. package/dist/contracts/governance/gaugeController/vote.js +15 -16
  125. package/dist/contracts/governance/gaugeSystems/_helpers.js +123 -0
  126. package/dist/contracts/governance/gaugeSystems/findGauge.js +14 -0
  127. package/dist/contracts/governance/gaugeSystems/getGaugeSystem.js +14 -0
  128. package/dist/contracts/governance/gaugeSystems/getGaugeSystems.js +13 -0
  129. package/dist/contracts/governance/gaugeSystems/getGauges.js +15 -0
  130. package/dist/contracts/governance/gaugeSystems/index.js +21 -0
  131. package/dist/types/RPCLibrary.d.ts +2 -0
  132. package/dist/types/configs/chains/index.d.ts +36 -46
  133. package/dist/types/configs/index.d.ts +18 -23
  134. package/dist/types/contracts/governance/distributor/claimAll.d.ts +7 -5
  135. package/dist/types/contracts/governance/distributor/claimForGauge.d.ts +7 -6
  136. package/dist/types/contracts/governance/distributor/deposit.d.ts +7 -6
  137. package/dist/types/contracts/governance/distributor/getClaimableForGauge.d.ts +6 -4
  138. package/dist/types/contracts/governance/distributor/getClaimedAtEpoch.d.ts +7 -5
  139. package/dist/types/contracts/governance/distributor/getDepositedAtEpoch.d.ts +6 -4
  140. package/dist/types/contracts/governance/distributor/getDustLastProcessedEpoch.d.ts +12 -0
  141. package/dist/types/contracts/governance/distributor/getGaugeController.d.ts +5 -3
  142. package/dist/types/contracts/governance/distributor/getLastClaimedEpoch.d.ts +6 -4
  143. package/dist/types/contracts/governance/distributor/getMaxClaimBound.d.ts +15 -0
  144. package/dist/types/contracts/governance/distributor/getPeriodDuration.d.ts +5 -3
  145. package/dist/types/contracts/governance/distributor/getRewardToken.d.ts +5 -3
  146. package/dist/types/contracts/governance/distributor/getRewardTokenInfo.d.ts +5 -3
  147. package/dist/types/contracts/governance/distributor/getRewardTokenStats.d.ts +5 -3
  148. package/dist/types/contracts/governance/distributor/index.d.ts +5 -2
  149. package/dist/types/contracts/governance/distributor/setController.d.ts +7 -6
  150. package/dist/types/contracts/governance/distributor/setLastClaimedEpoch.d.ts +13 -0
  151. package/dist/types/contracts/governance/distributor/setMaxClaimBound.d.ts +13 -0
  152. package/dist/types/contracts/governance/distributor/withdrawDust.d.ts +13 -0
  153. package/dist/types/contracts/governance/distributor/withdrawRemovedGaugeRewards.d.ts +8 -7
  154. package/dist/types/contracts/governance/gauge/_apy.d.ts +61 -0
  155. package/dist/types/contracts/governance/gauge/_tokens.d.ts +14 -0
  156. package/dist/types/contracts/governance/gauge/approveGaugeToken.d.ts +14 -0
  157. package/dist/types/contracts/governance/gauge/claimRewardToken.d.ts +1 -1
  158. package/dist/types/contracts/governance/gauge/getApy.d.ts +41 -0
  159. package/dist/types/contracts/governance/gauge/getEarnedExtraReward.d.ts +13 -0
  160. package/dist/types/contracts/governance/gauge/getEarnedReward.d.ts +3 -2
  161. package/dist/types/contracts/governance/gauge/getGaugeData.d.ts +23 -0
  162. package/dist/types/contracts/governance/gauge/getPauseStatus.d.ts +19 -0
  163. package/dist/types/contracts/governance/gauge/getPendingRewards.d.ts +3 -2
  164. package/dist/types/contracts/governance/gauge/getRewardTokens.d.ts +11 -0
  165. package/dist/types/contracts/governance/gauge/getUserApy.d.ts +44 -0
  166. package/dist/types/contracts/governance/gauge/getUserClaimableRewards.d.ts +14 -12
  167. package/dist/types/contracts/governance/gauge/getUserGaugeState.d.ts +31 -0
  168. package/dist/types/contracts/governance/gauge/index.d.ts +11 -1
  169. package/dist/types/contracts/governance/gauge/isPaused.d.ts +1 -1
  170. package/dist/types/contracts/governance/gauge/pullRewardsFromDistributor.d.ts +11 -0
  171. package/dist/types/contracts/governance/gauge/unwrapStakingToken.d.ts +12 -0
  172. package/dist/types/contracts/governance/gauge/wrapStakingToken.d.ts +13 -0
  173. package/dist/types/contracts/governance/gaugeController/addGauge.d.ts +8 -5
  174. package/dist/types/contracts/governance/gaugeController/batchVote.d.ts +9 -6
  175. package/dist/types/contracts/governance/gaugeController/calculateBoost.d.ts +10 -8
  176. package/dist/types/contracts/governance/gaugeController/forceCompleteCheckpoint.d.ts +8 -5
  177. package/dist/types/contracts/governance/gaugeController/getActiveGaugeCount.d.ts +12 -0
  178. package/dist/types/contracts/governance/gaugeController/getActiveGauges.d.ts +7 -3
  179. package/dist/types/contracts/governance/gaugeController/getConstants.d.ts +6 -4
  180. package/dist/types/contracts/governance/gaugeController/getCurrentEpoch.d.ts +6 -3
  181. package/dist/types/contracts/governance/gaugeController/getExpiredGaugeVotePower.d.ts +16 -0
  182. package/dist/types/contracts/governance/gaugeController/getGauge.d.ts +7 -4
  183. package/dist/types/contracts/governance/gaugeController/getGaugeDistributor.d.ts +12 -0
  184. package/dist/types/contracts/governance/gaugeController/getGaugeEmissions.d.ts +6 -3
  185. package/dist/types/contracts/governance/gaugeController/getGaugeRelativeWeight.d.ts +8 -9
  186. package/dist/types/contracts/governance/gaugeController/getGaugeRelativeWeightView.d.ts +8 -5
  187. package/dist/types/contracts/governance/gaugeController/getGaugeWeight.d.ts +6 -4
  188. package/dist/types/contracts/governance/gaugeController/getLastVoteTime.d.ts +7 -4
  189. package/dist/types/contracts/governance/gaugeController/getMaxVoteBuckets.d.ts +12 -0
  190. package/dist/types/contracts/governance/gaugeController/getNextEpoch.d.ts +6 -3
  191. package/dist/types/contracts/governance/gaugeController/getRegisteredGaugeList.d.ts +12 -0
  192. package/dist/types/contracts/governance/gaugeController/getTotalWeight.d.ts +5 -3
  193. package/dist/types/contracts/governance/gaugeController/getUserGaugeVotePower.d.ts +7 -4
  194. package/dist/types/contracts/governance/gaugeController/getUserVotePowerRemaining.d.ts +6 -4
  195. package/dist/types/contracts/governance/gaugeController/getVeToken.d.ts +6 -3
  196. package/dist/types/contracts/governance/gaugeController/getVoteUserLocks.d.ts +17 -0
  197. package/dist/types/contracts/governance/gaugeController/getVoteUserPower.d.ts +6 -3
  198. package/dist/types/contracts/governance/gaugeController/getVoteUserSlope.d.ts +8 -5
  199. package/dist/types/contracts/governance/gaugeController/index.d.ts +10 -1
  200. package/dist/types/contracts/governance/gaugeController/isGaugeActive.d.ts +6 -4
  201. package/dist/types/contracts/governance/gaugeController/isPaused.d.ts +6 -3
  202. package/dist/types/contracts/governance/gaugeController/kick.d.ts +7 -4
  203. package/dist/types/contracts/governance/gaugeController/removeGauge.d.ts +9 -5
  204. package/dist/types/contracts/governance/gaugeController/removePowerFromGauge.d.ts +8 -5
  205. package/dist/types/contracts/governance/gaugeController/setBoostAmplificationEnabled.d.ts +9 -6
  206. package/dist/types/contracts/governance/gaugeController/setDistributor.d.ts +13 -0
  207. package/dist/types/contracts/governance/gaugeController/setEmergencyGaugePause.d.ts +9 -6
  208. package/dist/types/contracts/governance/gaugeController/setEmergencyGaugePauseBatch.d.ts +14 -0
  209. package/dist/types/contracts/governance/gaugeController/setEmergencyPause.d.ts +8 -5
  210. package/dist/types/contracts/governance/gaugeController/setMaxVoteBuckets.d.ts +13 -0
  211. package/dist/types/contracts/governance/gaugeController/vote.d.ts +9 -7
  212. package/dist/types/contracts/governance/gaugeSystems/_helpers.d.ts +71 -0
  213. package/dist/types/contracts/governance/gaugeSystems/findGauge.d.ts +11 -0
  214. package/dist/types/contracts/governance/gaugeSystems/getGaugeSystem.d.ts +11 -0
  215. package/dist/types/contracts/governance/gaugeSystems/getGaugeSystems.d.ts +10 -0
  216. package/dist/types/contracts/governance/gaugeSystems/getGauges.d.ts +13 -0
  217. package/dist/types/contracts/governance/gaugeSystems/index.d.ts +5 -0
  218. package/dist/types/typechain-types/contracts/core/governance/gauges/BaseGauge.d.ts +176 -105
  219. package/dist/types/typechain-types/contracts/core/governance/gauges/GaugeController.d.ts +260 -213
  220. package/dist/types/typechain-types/contracts/core/governance/gauges/GaugeRewardsDistributor.d.ts +173 -212
  221. package/dist/types/typechain-types/contracts/core/governance/gauges/RAACGauge.d.ts +176 -105
  222. package/dist/types/typechain-types/contracts/core/governance/gauges/RWAGauge.d.ts +176 -105
  223. package/dist/types/typechain-types/contracts/interfaces/core/governance/gauges/IBaseGauge.d.ts +111 -108
  224. package/dist/types/typechain-types/contracts/interfaces/core/governance/gauges/IGaugeController.d.ts +210 -34
  225. package/dist/types/typechain-types/contracts/interfaces/core/governance/gauges/IGaugeRewardsDistributor.d.ts +112 -151
  226. package/dist/types/typechain-types/factories/contracts/core/governance/gauges/BaseGauge__factory.d.ts +174 -95
  227. package/dist/types/typechain-types/factories/contracts/core/governance/gauges/GaugeController__factory.d.ts +243 -227
  228. package/dist/types/typechain-types/factories/contracts/core/governance/gauges/GaugeRewardsDistributor__factory.d.ts +164 -232
  229. package/dist/types/typechain-types/factories/contracts/core/governance/gauges/RAACGauge__factory.d.ts +185 -98
  230. package/dist/types/typechain-types/factories/contracts/core/governance/gauges/RWAGauge__factory.d.ts +185 -98
  231. package/dist/types/typechain-types/factories/contracts/interfaces/core/governance/gauges/IBaseGauge__factory.d.ts +104 -95
  232. package/dist/types/typechain-types/factories/contracts/interfaces/core/governance/gauges/IGaugeController__factory.d.ts +241 -22
  233. package/dist/types/typechain-types/factories/contracts/interfaces/core/governance/gauges/IGaugeRewardsDistributor__factory.d.ts +72 -158
  234. package/dist/types/utils/artifacts.d.ts +40 -0
  235. package/dist/types/utils/contracts.d.ts +34 -44
  236. package/dist/utils/contracts.js +1 -1
  237. package/package.json +1 -1
  238. package/dist/contracts/governance/distributor/getStartEpoch.js +0 -28
  239. package/dist/contracts/governance/distributor/withdrawUnallocatedRewards.js +0 -26
  240. package/dist/contracts/governance/gauge/setDistributorApproval.js +0 -35
  241. package/dist/types/contracts/governance/distributor/getStartEpoch.d.ts +0 -10
  242. package/dist/types/contracts/governance/distributor/withdrawUnallocatedRewards.d.ts +0 -12
  243. package/dist/types/contracts/governance/gauge/setDistributorApproval.d.ts +0 -11
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getGaugeData = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const chains_1 = __importDefault(require("../../../configs/chains"));
9
+ const artifacts_1 = require("../../../utils/artifacts");
10
+ const _helpers_1 = require("../gaugeSystems/_helpers");
11
+ /**
12
+ * Reads a gauge's `gaugeData` struct: its staking and reward tokens, distributor, supplies and period state.
13
+ *
14
+ * @param chainId - The chain/network to use.
15
+ * @param gaugeAddressOrId - Address of the gauge contract or its config ID.
16
+ * @param provider - Optional ethers.js Provider instance.
17
+ * @returns The gauge data.
18
+ */
19
+ const getGaugeData = async (chainId, gaugeAddressOrId, provider) => {
20
+ if (!provider) {
21
+ const rpc = chains_1.default[chainId].rpcs[0];
22
+ provider = new ethers_1.ethers.JsonRpcProvider(rpc);
23
+ }
24
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
25
+ const contract = new ethers_1.ethers.Contract(gaugeAddress, (0, artifacts_1.getABI)("basegauge"), provider);
26
+ const [gaugeInitialStartTime, periodDuration, periodIndex, stakingToken, totalSupply, workingSupply, rewardDistributor, rewardToken, lastUpdateTime,] = await contract.gaugeData();
27
+ return {
28
+ gaugeInitialStartTime,
29
+ periodDuration,
30
+ periodIndex,
31
+ stakingToken,
32
+ totalSupply,
33
+ workingSupply,
34
+ rewardDistributor,
35
+ rewardToken,
36
+ lastUpdateTime,
37
+ };
38
+ };
39
+ exports.getGaugeData = getGaugeData;
@@ -7,7 +7,7 @@ exports.getGaugeRewardTokenData = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
9
  const artifacts_1 = require("../../../utils/artifacts");
10
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
10
+ const _helpers_1 = require("../gaugeSystems/_helpers");
11
11
  /**
12
12
  * Gets the gauge-level reward accounting data for a specific token.
13
13
  * @param chainId - The chain/network to use.
@@ -20,14 +20,7 @@ const getGaugeRewardTokenData = async (chainId, gaugeAddressOrId, token, provide
20
20
  const rpc = chains_1.default[chainId].rpcs[0];
21
21
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
22
22
  }
23
- let gaugeAddress;
24
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
25
- gaugeAddress = gaugeAddressOrId;
26
- }
27
- else {
28
- // @ts-ignore
29
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
30
- }
23
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
31
24
  const abi = (0, artifacts_1.getABI)("basegauge");
32
25
  const contract = new ethers_1.ethers.Contract(gaugeAddress, abi, provider);
33
26
  const [isActive, decimals, rate, integral, lastUpdateTime, distributed, leftoverRewards,] = await contract.getGaugeRewardTokenData(token);
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getPauseStatus = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const chains_1 = __importDefault(require("../../../configs/chains"));
9
+ const artifacts_1 = require("../../../utils/artifacts");
10
+ const _helpers_1 = require("../gaugeSystems/_helpers");
11
+ /**
12
+ * Reads both pause switches that gate a gauge, mirroring the contract's `whenGaugeLive` check.
13
+ *
14
+ * @param chainId - The chain/network to use.
15
+ * @param gaugeAddressOrId - Address of the gauge contract or its config ID.
16
+ * @param provider - Optional ethers.js Provider instance.
17
+ * @returns The gauge's and its controller's pause flags, and whether the gauge is live.
18
+ */
19
+ const getPauseStatus = async (chainId, gaugeAddressOrId, provider) => {
20
+ if (!provider) {
21
+ const rpc = chains_1.default[chainId].rpcs[0];
22
+ provider = new ethers_1.ethers.JsonRpcProvider(rpc);
23
+ }
24
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
25
+ const gauge = new ethers_1.ethers.Contract(gaugeAddress, (0, artifacts_1.getABI)("basegauge"), provider);
26
+ const [gaugePaused, controllerAddress] = await Promise.all([gauge.isPaused(), gauge.gaugeController()]);
27
+ const controller = new ethers_1.ethers.Contract(controllerAddress, (0, artifacts_1.getABI)("gaugecontroller"), provider);
28
+ const controllerPaused = await controller.isPaused();
29
+ return { gaugePaused, controllerPaused, live: !gaugePaused && !controllerPaused };
30
+ };
31
+ exports.getPauseStatus = getPauseStatus;
@@ -7,7 +7,7 @@ exports.getPendingExtraRewards = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
9
  const artifacts_1 = require("../../../utils/artifacts");
10
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
10
+ const _helpers_1 = require("../gaugeSystems/_helpers");
11
11
  /**
12
12
  * Gets the pending extra rewards for a user for a specific token.
13
13
  * @param chainId - The chain/network to use.
@@ -21,14 +21,7 @@ const getPendingExtraRewards = async (chainId, gaugeAddressOrId, token, user, pr
21
21
  const rpc = chains_1.default[chainId].rpcs[0];
22
22
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
23
23
  }
24
- let gaugeAddress;
25
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
26
- gaugeAddress = gaugeAddressOrId;
27
- }
28
- else {
29
- // @ts-ignore
30
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
31
- }
24
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
32
25
  const abi = (0, artifacts_1.getABI)("basegauge");
33
26
  const contract = new ethers_1.ethers.Contract(gaugeAddress, abi, provider);
34
27
  return contract.pendingExtraRewards(token, user);
@@ -6,31 +6,25 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getPendingRewards = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
10
- const PENDING_REWARDS_ABI = "function pendingRewards(address account) view returns (uint256)";
9
+ const artifacts_1 = require("../../../utils/artifacts");
10
+ const _helpers_1 = require("../gaugeSystems/_helpers");
11
11
  /**
12
- * Gets the pending (unclaimed) main-reward-token amount for a user on a gauge.
12
+ * Gets the rewards a user can claim from a gauge for one reward token. Only counts rewards already pulled into the gauge, which is everything a user can claim right now; `getUserClaimableRewards` adds the extra reward tokens.
13
13
  *
14
14
  * @param chainId - The chain/network to use.
15
15
  * @param gaugeAddressOrId - Address of the gauge contract or its config ID.
16
+ * @param token - The gauge's main reward token (`getGaugeData().rewardToken`). Any other token reverts with NotSupportedToken; use `getPendingExtraRewards` for extra reward tokens.
16
17
  * @param accountAddress - Address of the user.
17
18
  * @param provider - Optional ethers.js Provider instance.
18
19
  * @returns The pending reward amount (raw, base units).
19
20
  */
20
- const getPendingRewards = async (chainId, gaugeAddressOrId, accountAddress, provider) => {
21
+ const getPendingRewards = async (chainId, gaugeAddressOrId, token, accountAddress, provider) => {
21
22
  if (!provider) {
22
23
  const rpc = chains_1.default[chainId].rpcs[0];
23
24
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
24
25
  }
25
- let gaugeAddress;
26
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
27
- gaugeAddress = gaugeAddressOrId;
28
- }
29
- else {
30
- // @ts-ignore
31
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
32
- }
33
- const contract = new ethers_1.ethers.Contract(gaugeAddress, [PENDING_REWARDS_ABI], provider);
34
- return contract.pendingRewards(accountAddress);
26
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
27
+ const contract = new ethers_1.ethers.Contract(gaugeAddress, (0, artifacts_1.getABI)("basegauge"), provider);
28
+ return contract.pendingRewards(token, accountAddress);
35
29
  };
36
30
  exports.getPendingRewards = getPendingRewards;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getPeriodBoundaries = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
9
+ const _helpers_1 = require("../gaugeSystems/_helpers");
10
10
  const GET_PERIOD_BOUNDARIES_ABI = "function getPeriodBoundaries() view returns (uint256 periodStartTime, uint256 periodEndTime)";
11
11
  /**
12
12
  * Gets the start and end time of the current period.
@@ -21,20 +21,7 @@ const getPeriodBoundaries = async (chainId, gaugeAddressOrId, provider) => {
21
21
  const rpc = chains_1.default[chainId].rpcs[0];
22
22
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
23
23
  }
24
- let gaugeAddress;
25
- try {
26
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
27
- gaugeAddress = gaugeAddressOrId;
28
- }
29
- else {
30
- // @ts-ignore
31
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
32
- }
33
- }
34
- catch (error) {
35
- console.error("Error getting period boundaries:", error);
36
- throw new Error(`Failed to get period boundaries from gauge ${gaugeAddress}: ${error.message}`);
37
- }
24
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
38
25
  const contract = new ethers_1.ethers.Contract(gaugeAddress, [GET_PERIOD_BOUNDARIES_ABI], provider);
39
26
  const [periodStartTime, periodEndTime] = await contract.getPeriodBoundaries();
40
27
  return {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getPeriodDuration = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
9
+ const _helpers_1 = require("../gaugeSystems/_helpers");
10
10
  const PERIOD_DURATION_ABI = "function periodDuration() view returns (uint256)";
11
11
  /**
12
12
  * Gets the period duration for the gauge.
@@ -21,20 +21,7 @@ const getPeriodDuration = async (chainId, gaugeAddressOrId, provider) => {
21
21
  const rpc = chains_1.default[chainId].rpcs[0];
22
22
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
23
23
  }
24
- let gaugeAddress;
25
- try {
26
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
27
- gaugeAddress = gaugeAddressOrId;
28
- }
29
- else {
30
- // @ts-ignore
31
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
32
- }
33
- }
34
- catch (error) {
35
- console.error("Error getting period duration:", error);
36
- throw new Error(`Failed to get period duration from gauge ${gaugeAddress}: ${error.message}`);
37
- }
24
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
38
25
  const contract = new ethers_1.ethers.Contract(gaugeAddress, [PERIOD_DURATION_ABI], provider);
39
26
  const periodDuration = await contract.periodDuration();
40
27
  return Number(periodDuration);
@@ -7,7 +7,7 @@ exports.getRaacAutolockMin = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
9
  const artifacts_1 = require("../../../utils/artifacts");
10
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
10
+ const _helpers_1 = require("../gaugeSystems/_helpers");
11
11
  /**
12
12
  * Gets the minimum RAAC amount required to trigger an autolock on claim.
13
13
  * @param chainId - The chain/network to use.
@@ -19,14 +19,7 @@ const getRaacAutolockMin = async (chainId, gaugeAddressOrId, provider) => {
19
19
  const rpc = chains_1.default[chainId].rpcs[0];
20
20
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
21
21
  }
22
- let gaugeAddress;
23
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
24
- gaugeAddress = gaugeAddressOrId;
25
- }
26
- else {
27
- // @ts-ignore
28
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
29
- }
22
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
30
23
  const abi = (0, artifacts_1.getABI)("basegauge");
31
24
  const contract = new ethers_1.ethers.Contract(gaugeAddress, abi, provider);
32
25
  return contract.raacAutolockMin();
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getRawBalanceOf = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
9
+ const _helpers_1 = require("../gaugeSystems/_helpers");
10
10
  const RAW_BALANCE_OF_ABI = "function rawBalanceOf(address account) view returns (uint256)";
11
11
  /**
12
12
  * Gets the raw balance of an account (without boost).
@@ -22,20 +22,7 @@ const getRawBalanceOf = async (chainId, gaugeAddressOrId, accountAddress, provid
22
22
  const rpc = chains_1.default[chainId].rpcs[0];
23
23
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
24
24
  }
25
- let gaugeAddress;
26
- try {
27
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
28
- gaugeAddress = gaugeAddressOrId;
29
- }
30
- else {
31
- // @ts-ignore
32
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
33
- }
34
- }
35
- catch (error) {
36
- console.error("Error getting raw balance of:", error);
37
- throw new Error(`Failed to get raw balance of from gauge ${gaugeAddress}: ${error.message}`);
38
- }
25
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
39
26
  const contract = new ethers_1.ethers.Contract(gaugeAddress, [RAW_BALANCE_OF_ABI], provider);
40
27
  const balance = await contract.rawBalanceOf(accountAddress);
41
28
  return ethers_1.ethers.formatEther(balance);
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getRawTotalSupply = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
9
+ const _helpers_1 = require("../gaugeSystems/_helpers");
10
10
  const RAW_TOTAL_SUPPLY_ABI = "function rawTotalSupply() view returns (uint256)";
11
11
  /**
12
12
  * Gets the raw total supply of the gauge (without boost).
@@ -21,20 +21,7 @@ const getRawTotalSupply = async (chainId, gaugeAddressOrId, provider) => {
21
21
  const rpc = chains_1.default[chainId].rpcs[0];
22
22
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
23
23
  }
24
- let gaugeAddress;
25
- try {
26
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
27
- gaugeAddress = gaugeAddressOrId;
28
- }
29
- else {
30
- // @ts-ignore
31
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
32
- }
33
- }
34
- catch (error) {
35
- console.error("Error getting raw total supply:", error);
36
- throw new Error(`Failed to get raw total supply from gauge ${gaugeAddress}: ${error.message}`);
37
- }
24
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
38
25
  const contract = new ethers_1.ethers.Contract(gaugeAddress, [RAW_TOTAL_SUPPLY_ABI], provider);
39
26
  const rawTotalSupply = await contract.rawTotalSupply();
40
27
  return ethers_1.ethers.formatEther(rawTotalSupply);
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getRewardTokens = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const chains_1 = __importDefault(require("../../../configs/chains"));
9
+ const artifacts_1 = require("../../../utils/artifacts");
10
+ const _helpers_1 = require("../gaugeSystems/_helpers");
11
+ /**
12
+ * Gets every reward token of a gauge: the main reward token first, then the extra reward tokens.
13
+ *
14
+ * @param chainId - The chain/network to use.
15
+ * @param gaugeAddressOrId - Address of the gauge contract or its config ID.
16
+ * @param provider - Optional ethers.js Provider instance.
17
+ * @returns The reward token addresses.
18
+ */
19
+ const getRewardTokens = async (chainId, gaugeAddressOrId, provider) => {
20
+ if (!provider) {
21
+ const rpc = chains_1.default[chainId].rpcs[0];
22
+ provider = new ethers_1.ethers.JsonRpcProvider(rpc);
23
+ }
24
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
25
+ const contract = new ethers_1.ethers.Contract(gaugeAddress, (0, artifacts_1.getABI)("basegauge"), provider);
26
+ return [...(await contract.getRewardTokens())];
27
+ };
28
+ exports.getRewardTokens = getRewardTokens;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getTotalSupply = void 0;
7
7
  const ethers_1 = require("ethers");
8
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
9
- const getContractAddress_1 = __importDefault(require("../../getContractAddress"));
9
+ const _helpers_1 = require("../gaugeSystems/_helpers");
10
10
  const TOTAL_SUPPLY_ABI = "function totalSupply() view returns (uint256)";
11
11
  /**
12
12
  * Gets the working supply of the gauge (includes boost).
@@ -21,20 +21,7 @@ const getTotalSupply = async (chainId, gaugeAddressOrId, provider) => {
21
21
  const rpc = chains_1.default[chainId].rpcs[0];
22
22
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
23
23
  }
24
- let gaugeAddress;
25
- try {
26
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
27
- gaugeAddress = gaugeAddressOrId;
28
- }
29
- else {
30
- // @ts-ignore
31
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
32
- }
33
- }
34
- catch (error) {
35
- console.error("Error getting total supply:", error);
36
- throw new Error(`Failed to get total supply from gauge ${gaugeAddress}: ${error.message}`);
37
- }
24
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
38
25
  const contract = new ethers_1.ethers.Contract(gaugeAddress, [TOTAL_SUPPLY_ABI], provider);
39
26
  const totalSupply = await contract.totalSupply();
40
27
  return ethers_1.ethers.formatEther(totalSupply);
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getUserApy = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const _apy_1 = require("./_apy");
6
+ const toPosition = (balance, working, workingSupply, totalSupply, decimals, maxBoost, mainYearlyUSD, extraYearlyUSD, price) => {
7
+ const balanceUnits = Number(ethers_1.ethers.formatUnits(balance, decimals));
8
+ const workingUnits = Number(ethers_1.ethers.formatUnits(working, decimals));
9
+ const workingSupplyUnits = Number(ethers_1.ethers.formatUnits(workingSupply, decimals));
10
+ const userMainUSD = workingSupplyUnits > 0 ? (mainYearlyUSD * workingUnits) / workingSupplyUnits : 0;
11
+ const mainApy = (0, _apy_1.toApyPct)(userMainUSD, balanceUnits, price);
12
+ const extraApy = balance > 0n ? (0, _apy_1.toApyPct)(extraYearlyUSD, Number(ethers_1.ethers.formatUnits(totalSupply, decimals)), price) : null;
13
+ return {
14
+ balance: ethers_1.ethers.formatUnits(balance, decimals),
15
+ workingBalance: ethers_1.ethers.formatUnits(working, decimals),
16
+ boost: balance > 0n ? (workingUnits / balanceUnits) * (Number(maxBoost) / 10000) : null,
17
+ mainApy,
18
+ extraApy,
19
+ apy: mainApy === null && extraApy === null ? null : (mainApy ?? 0) + (extraApy ?? 0),
20
+ };
21
+ };
22
+ /**
23
+ * Calculates a user's APY on a gauge: what they earn now, and what they would earn after their boost is re-checkpointed, optionally with extra stake. Figures are simple annualized rates in percent, not compounded.
24
+ *
25
+ * The user's share of main rewards is workingBalance / workingSupply; extra rewards are shared by raw balance. The stored working balance only changes when the user's position is checkpointed, so `current` can lag their veRAAC: `projected` recomputes it with the controller's `calculateBoost` and adjusts workingSupply and totalSupply for the change, holding every other staker fixed.
26
+ *
27
+ * @param chainId - The chain/network to use.
28
+ * @param gaugeAddressOrId - Address of the gauge contract or its config ID.
29
+ * @param user - Address of the user.
30
+ * @param prices - USD price of the staking token and of each reward token (see `getRewardTokens`).
31
+ * @param options - Optional reward source ("epoch" default, or "stream") and `additionalStake`, a staking token amount in base units to add in the projection.
32
+ * @param provider - Optional ethers.js Provider instance.
33
+ * @returns The user's current and projected position and APY, with the gauge's min and max APY. An APY is null when the position has no stake.
34
+ */
35
+ const getUserApy = async (chainId, gaugeAddressOrId, user, prices, options = {}, provider) => {
36
+ if (!ethers_1.ethers.isAddress(user)) {
37
+ throw new Error(`Invalid user address: ${user}`);
38
+ }
39
+ const state = await (0, _apy_1.loadGaugeApyState)(chainId, gaugeAddressOrId, prices, options, provider);
40
+ const additionalStake = BigInt(options.additionalStake ?? 0);
41
+ if (additionalStake < 0n) {
42
+ throw new Error("additionalStake cannot be negative");
43
+ }
44
+ const [balance, working] = await Promise.all([state.gaugeContract.rawBalanceOf(user), state.gaugeContract.balanceOf(user)]);
45
+ const projectedBalance = balance + additionalStake;
46
+ let boostBps = state.minBoost;
47
+ if (projectedBalance > 0n) {
48
+ // Mirrors BaseGauge._applyBoost, which falls back to MIN_BOOST when calculateBoost reverts (removed gauge).
49
+ boostBps = await state.controller
50
+ .calculateBoost(user, state.gauge, projectedBalance)
51
+ .then(([bps]) => bps)
52
+ .catch(() => state.minBoost);
53
+ }
54
+ let projectedWorking = (projectedBalance * boostBps) / state.maxBoost;
55
+ if (projectedWorking > projectedBalance)
56
+ projectedWorking = projectedBalance;
57
+ const price = prices.stakingTokenPriceUSD;
58
+ const d = state.stakingDecimals;
59
+ const current = toPosition(balance, working, state.workingSupply, state.totalSupply, d, state.maxBoost, state.mainYearlyUSD, state.extraYearlyUSD, price);
60
+ const projected = toPosition(projectedBalance, projectedWorking, state.workingSupply - working + projectedWorking, state.totalSupply + additionalStake, d, state.maxBoost, state.mainYearlyUSD, state.extraYearlyUSD, price);
61
+ const gaugeMaxApy = (0, _apy_1.toApyPct)(state.mainYearlyUSD, Number(ethers_1.ethers.formatUnits(state.workingSupply, d)), price);
62
+ return {
63
+ gauge: state.gauge,
64
+ user: ethers_1.ethers.getAddress(user),
65
+ current,
66
+ projected,
67
+ gaugeMinApy: gaugeMaxApy === null ? null : (gaugeMaxApy * Number(state.minBoost)) / Number(state.maxBoost),
68
+ gaugeMaxApy,
69
+ };
70
+ };
71
+ exports.getUserApy = getUserApy;
@@ -1,37 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
36
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
37
4
  };
@@ -39,27 +6,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
6
  exports.getUserClaimableRewards = void 0;
40
7
  const ethers_1 = require("ethers");
41
8
  const chains_1 = __importDefault(require("../../../configs/chains"));
42
- const getContractAddress_1 = __importStar(require("../../getContractAddress"));
9
+ const _helpers_1 = require("../gaugeSystems/_helpers");
43
10
  const GAUGE_ABI = [
44
- "function pendingRewards(address account) view returns (uint256)",
45
- "function balanceOf(address account) view returns (uint256)", // boosted working balance
46
- "function totalSupply() view returns (uint256)", // working supply
11
+ "function gaugeData() view returns (uint256 gaugeInitialStartTime, uint256 periodDuration, uint256 periodIndex, address stakingToken, uint256 totalSupply, uint256 workingSupply, address rewardDistributor, address rewardToken, uint256 lastUpdateTime)",
12
+ "function pendingRewards(address token, address account) view returns (uint256)",
47
13
  "function getExtraRewardTokens() view returns (address[])",
48
14
  "function pendingExtraRewards(address token, address account) view returns (uint256)",
49
15
  ];
50
- const DISTRIBUTOR_ABI = ["function getClaimableForGauge(address gauge) view returns (uint256)"];
51
16
  const ERC20_META_ABI = [
52
17
  "function symbol() view returns (string)",
53
18
  "function decimals() view returns (uint8)",
54
19
  ];
55
20
  /**
56
- * The user's TRUE claimable rewards on a gauge.
21
+ * What a user can claim from a gauge right now: the main reward already accrued to them inside the gauge, plus any
22
+ * extra reward tokens.
57
23
  *
58
- * The gauge's `pendingRewards()` view only reflects RAAC already pulled into the gauge.
59
- * RAAC emitted to the gauge sits in the GaugeRewardsDistributor until a claim pulls it in
60
- * (`claimRewardToken`/`claimRewardsFor` call `_pullRewardsFromDistributor` first). So a
61
- * user's real claimable also includes their working-balance share of the distributor's
62
- * `getClaimableForGauge(gauge)`. This helper combines both, plus any extra reward tokens.
24
+ * Rewards still held by the GaugeRewardsDistributor are not included. They are not the user's yet: a pull
25
+ * (`pullRewardsFromDistributor`, or the pull every claim makes first) streams them to everyone staked over the rest of
26
+ * the reward period, so any per-user share of them would change with every stake, unstake and pull. Read the gauge's
27
+ * total still in the distributor with `governance.distributor.getClaimableForGauge` when it is needed.
28
+ * The distributor is read from the gauge itself, so RAAC and RWA gauges both resolve to their own system's distributor.
63
29
  *
64
30
  * @param chainId - The chain/network to use.
65
31
  * @param gaugeAddressOrId - Address of the gauge contract or its config ID.
@@ -71,35 +37,16 @@ const getUserClaimableRewards = async (chainId, gaugeAddressOrId, accountAddress
71
37
  const rpc = chains_1.default[chainId].rpcs[0];
72
38
  provider = new ethers_1.ethers.JsonRpcProvider(rpc);
73
39
  }
74
- let gaugeAddress;
75
- if ((0, ethers_1.isAddress)(gaugeAddressOrId)) {
76
- gaugeAddress = gaugeAddressOrId;
77
- }
78
- else {
79
- // @ts-ignore
80
- gaugeAddress = (0, getContractAddress_1.default)(chainId, gaugeAddressOrId.toLowerCase());
81
- }
40
+ const gaugeAddress = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
82
41
  const gauge = new ethers_1.ethers.Contract(gaugeAddress, GAUGE_ABI, provider);
83
- const [inGauge, working, supply, extraTokens] = await Promise.all([
84
- gauge.pendingRewards(accountAddress).then((v) => BigInt(v)).catch(() => 0n),
85
- gauge.balanceOf(accountAddress).then((v) => BigInt(v)).catch(() => 0n),
86
- gauge.totalSupply().then((v) => BigInt(v)).catch(() => 0n),
42
+ const [rewardToken, distributorAddr] = await gauge
43
+ .gaugeData()
44
+ .then((d) => [d.rewardToken, d.rewardDistributor]);
45
+ const [inGauge, rewardDecimals, extraTokens] = await Promise.all([
46
+ gauge.pendingRewards(rewardToken, accountAddress).then((v) => BigInt(v)).catch(() => 0n),
47
+ new ethers_1.ethers.Contract(rewardToken, ERC20_META_ABI, provider).decimals().then((d) => Number(d)).catch(() => 18),
87
48
  gauge.getExtraRewardTokens().catch(() => []),
88
49
  ]);
89
- // User's share of RAAC still held by the distributor for this gauge.
90
- let inDistributor = 0n;
91
- try {
92
- const distributorAddr = (0, getContractAddress_1.getContractAddress)(chainId, "gaugerewardsdistributor");
93
- const distributor = new ethers_1.ethers.Contract(distributorAddr, DISTRIBUTOR_ABI, provider);
94
- const gaugeClaimable = BigInt(await distributor.getClaimableForGauge(gaugeAddress));
95
- if (supply > 0n && working > 0n && gaugeClaimable > 0n) {
96
- inDistributor = (gaugeClaimable * working) / supply;
97
- }
98
- }
99
- catch {
100
- /* distributor not configured / no pending */
101
- }
102
- const raac = inGauge + inDistributor;
103
50
  const extras = [];
104
51
  for (const token of extraTokens) {
105
52
  try {
@@ -125,10 +72,11 @@ const getUserClaimableRewards = async (chainId, gaugeAddressOrId, accountAddress
125
72
  }
126
73
  return {
127
74
  gauge: gaugeAddress,
75
+ rewardToken,
76
+ distributor: distributorAddr,
128
77
  inGauge,
129
- inDistributor,
130
- raac,
131
- raacFormatted: ethers_1.ethers.formatEther(raac),
78
+ raac: inGauge,
79
+ raacFormatted: ethers_1.ethers.formatUnits(inGauge, rewardDecimals),
132
80
  extras,
133
81
  };
134
82
  };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getUserGaugeState = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const chains_1 = __importDefault(require("../../../configs/chains"));
9
+ const _helpers_1 = require("../gaugeSystems/_helpers");
10
+ const _tokens_1 = require("./_tokens");
11
+ const RAW_BALANCE_OF_ABI = ["function rawBalanceOf(address account) view returns (uint256)"];
12
+ const tokenState = async (token, user, spender, provider) => {
13
+ const contract = new ethers_1.ethers.Contract(token, _tokens_1.ERC20_ABI, provider);
14
+ const [symbol, decimals, balance, allowance] = await Promise.all([
15
+ contract.symbol(),
16
+ contract.decimals(),
17
+ contract.balanceOf(user),
18
+ contract.allowance(user, spender),
19
+ ]);
20
+ return { address: ethers_1.ethers.getAddress(token), symbol, decimals: Number(decimals), balance, allowance, spender: ethers_1.ethers.getAddress(spender) };
21
+ };
22
+ /**
23
+ * What a wallet needs to stake in, wrap for, or unstake from a gauge: its stake, its balance of the staking token and its
24
+ * allowance to the gauge, and for a wrapped gauge its balance of the underlying and allowance to the wrapper.
25
+ *
26
+ * @param chainId - The chain/network to use.
27
+ * @param gaugeAddressOrId - Address of the gauge contract or its config ID.
28
+ * @param user - The wallet.
29
+ * @param provider - Optional ethers.js Provider instance.
30
+ */
31
+ const getUserGaugeState = async (chainId, gaugeAddressOrId, user, provider) => {
32
+ if (!provider) {
33
+ provider = new ethers_1.ethers.JsonRpcProvider(chains_1.default[chainId].rpcs[0]);
34
+ }
35
+ const gauge = (0, _helpers_1.resolveGauge)(chainId, gaugeAddressOrId);
36
+ const { stakingToken, underlying } = await (0, _tokens_1.getGaugeTokens)(gauge, provider);
37
+ const [staked, staking, wrappable] = await Promise.all([
38
+ new ethers_1.ethers.Contract(gauge, RAW_BALANCE_OF_ABI, provider).rawBalanceOf(user),
39
+ tokenState(stakingToken, user, gauge, provider),
40
+ underlying ? tokenState(underlying, user, stakingToken, provider) : Promise.resolve(null),
41
+ ]);
42
+ return { gauge, staked, stakingToken: staking, underlying: wrappable };
43
+ };
44
+ exports.getUserGaugeState = getUserGaugeState;