@pendle/core-v2 0.18.0-testnet → 0.19.0-testnet

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 (174) hide show
  1. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiveEndpointUpg.sol/PendleMsgReceiveEndpointUpg.dbg.json +1 -1
  2. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiveEndpointUpg.sol/PendleMsgReceiveEndpointUpg.json +2 -2
  3. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiverAppUpg.sol/PendleMsgReceiverAppUpg.dbg.json +1 -1
  4. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgSendEndpointUpg.sol/PendleMsgSendEndpointUpg.dbg.json +1 -1
  5. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgSendEndpointUpg.sol/PendleMsgSendEndpointUpg.json +2 -2
  6. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgSenderAppUpg.sol/PendleMsgSenderAppUpg.dbg.json +1 -1
  7. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerBaseUpg.sol/PendleGaugeControllerBaseUpg.dbg.json +1 -1
  8. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerMainchainUpg.sol/PendleGaugeControllerMainchainUpg.dbg.json +1 -1
  9. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerMainchainUpg.sol/PendleGaugeControllerMainchainUpg.json +2 -2
  10. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerSidechainUpg.sol/PendleGaugeControllerSidechainUpg.dbg.json +1 -1
  11. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerSidechainUpg.sol/PendleGaugeControllerSidechainUpg.json +2 -2
  12. package/build/artifacts/contracts/LiquidityMining/VeDistributor/PendleFeeDistributor.sol/PendleFeeDistributor.dbg.json +4 -0
  13. package/build/artifacts/contracts/LiquidityMining/VeDistributor/PendleFeeDistributor.sol/PendleFeeDistributor.json +560 -0
  14. package/build/artifacts/contracts/LiquidityMining/VotingController/PendleVotingControllerUpg.sol/PendleVotingControllerUpg.dbg.json +1 -1
  15. package/build/artifacts/contracts/LiquidityMining/VotingController/PendleVotingControllerUpg.sol/PendleVotingControllerUpg.json +2 -2
  16. package/build/artifacts/contracts/LiquidityMining/VotingController/VotingControllerStorageUpg.sol/VotingControllerStorageUpg.dbg.json +1 -1
  17. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleMainchain.sol/VotingEscrowPendleMainchain.dbg.json +1 -1
  18. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleMainchain.sol/VotingEscrowPendleMainchain.json +2 -2
  19. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleSidechain.sol/VotingEscrowPendleSidechain.dbg.json +1 -1
  20. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleSidechain.sol/VotingEscrowPendleSidechain.json +2 -2
  21. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowTokenBase.sol/VotingEscrowTokenBase.dbg.json +1 -1
  22. package/build/artifacts/contracts/LiquidityMining/libraries/VeBalanceLib.sol/VeBalanceLib.dbg.json +1 -1
  23. package/build/artifacts/contracts/LiquidityMining/libraries/VeBalanceLib.sol/VeBalanceLib.json +2 -2
  24. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/CheckpointHelper.dbg.json +1 -1
  25. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/CheckpointHelper.json +2 -2
  26. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/Checkpoints.dbg.json +1 -1
  27. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/Checkpoints.json +2 -2
  28. package/build/artifacts/contracts/core/BulkSeller/BulkSeller.sol/BulkSeller.dbg.json +1 -1
  29. package/build/artifacts/contracts/core/BulkSeller/BulkSeller.sol/BulkSeller.json +2 -2
  30. package/build/artifacts/contracts/core/BulkSeller/BulkSellerFactory.sol/BulkSellerFactory.dbg.json +1 -1
  31. package/build/artifacts/contracts/core/BulkSeller/BulkSellerFactory.sol/BulkSellerFactory.json +2 -2
  32. package/build/artifacts/contracts/core/BulkSeller/BulkSellerMathCore.sol/BulkSellerMathCore.dbg.json +1 -1
  33. package/build/artifacts/contracts/core/BulkSeller/BulkSellerMathCore.sol/BulkSellerMathCore.json +2 -2
  34. package/build/artifacts/contracts/core/Market/MarketMathCore.sol/MarketMathCore.dbg.json +1 -1
  35. package/build/artifacts/contracts/core/Market/MarketMathCore.sol/MarketMathCore.json +2 -2
  36. package/build/artifacts/contracts/core/Market/OracleLib.sol/OracleLib.dbg.json +1 -1
  37. package/build/artifacts/contracts/core/Market/OracleLib.sol/OracleLib.json +2 -2
  38. package/build/artifacts/contracts/core/Market/PendleGauge.sol/PendleGauge.dbg.json +1 -1
  39. package/build/artifacts/contracts/core/Market/PendleMarket.sol/PendleMarket.dbg.json +1 -1
  40. package/build/artifacts/contracts/core/Market/PendleMarket.sol/PendleMarket.json +2 -2
  41. package/build/artifacts/contracts/core/Market/PendleMarketFactory.sol/PendleMarketFactory.dbg.json +1 -1
  42. package/build/artifacts/contracts/core/Market/PendleMarketFactory.sol/PendleMarketFactory.json +2 -2
  43. package/build/artifacts/contracts/core/RewardManager/RewardManager.sol/RewardManager.dbg.json +1 -1
  44. package/build/artifacts/contracts/core/RewardManager/RewardManagerAbstract.sol/RewardManagerAbstract.dbg.json +1 -1
  45. package/build/artifacts/contracts/core/StandardizedYield/SYBase.sol/SYBase.dbg.json +1 -1
  46. package/build/artifacts/contracts/core/StandardizedYield/SYBaseWithRewards.sol/SYBaseWithRewards.dbg.json +1 -1
  47. package/build/artifacts/contracts/core/StandardizedYield/implementations/Ape/sAPE.sol/sAPE.dbg.json +1 -1
  48. package/build/artifacts/contracts/core/StandardizedYield/implementations/Ape/sAPE.sol/sAPE.json +2 -2
  49. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenHelper.sol/PendleQiTokenHelper.dbg.json +1 -1
  50. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenHelper.sol/PendleQiTokenHelper.json +2 -2
  51. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenSY.sol/PendleQiTokenSY.dbg.json +1 -1
  52. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenSY.sol/PendleQiTokenSY.json +2 -2
  53. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveFraxUsdcSY.sol/PendleCurveFraxUsdcSY.dbg.json +1 -1
  54. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveFraxUsdcSY.sol/PendleCurveFraxUsdcSY.json +2 -2
  55. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveUsdd3CrvSY.sol/PendleCurveUsdd3CrvSY.dbg.json +1 -1
  56. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveUsdd3CrvSY.sol/PendleCurveUsdd3CrvSY.json +2 -2
  57. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/base/PendleConvexLPSY.sol/PendleConvexLPSY.dbg.json +1 -1
  58. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleLooksStakingSY.sol/PendleLooksStakingSY.dbg.json +1 -1
  59. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleLooksStakingSY.sol/PendleLooksStakingSY.json +2 -2
  60. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleWstEthSY.sol/PendleWstEthSY.dbg.json +1 -1
  61. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleWstEthSY.sol/PendleWstEthSY.json +2 -2
  62. package/build/artifacts/contracts/core/YieldContracts/PendlePrincipalToken.sol/PendlePrincipalToken.dbg.json +1 -1
  63. package/build/artifacts/contracts/core/YieldContracts/PendlePrincipalToken.sol/PendlePrincipalToken.json +2 -2
  64. package/build/artifacts/contracts/core/YieldContracts/PendleYieldContractFactory.sol/PendleYieldContractFactory.dbg.json +1 -1
  65. package/build/artifacts/contracts/core/YieldContracts/PendleYieldContractFactory.sol/PendleYieldContractFactory.json +2 -2
  66. package/build/artifacts/contracts/core/YieldContracts/PendleYieldToken.sol/PendleYieldToken.dbg.json +1 -1
  67. package/build/artifacts/contracts/core/YieldContracts/PendleYieldToken.sol/PendleYieldToken.json +2 -2
  68. package/build/artifacts/contracts/core/libraries/ArrayLib.sol/ArrayLib.dbg.json +1 -1
  69. package/build/artifacts/contracts/core/libraries/ArrayLib.sol/ArrayLib.json +2 -2
  70. package/build/artifacts/contracts/core/libraries/Errors.sol/Errors.dbg.json +1 -1
  71. package/build/artifacts/contracts/core/libraries/Errors.sol/Errors.json +86 -5
  72. package/build/artifacts/contracts/interfaces/IApeStaking.sol/IApeStaking.dbg.json +1 -1
  73. package/build/artifacts/contracts/interfaces/IPActionAddRemoveLiq.sol/IPActionAddRemoveLiq.dbg.json +1 -1
  74. package/build/artifacts/contracts/interfaces/IPActionMintRedeem.sol/IPActionMintRedeem.dbg.json +1 -1
  75. package/build/artifacts/contracts/interfaces/IPActionSwapPT.sol/IPActionSwapPT.dbg.json +1 -1
  76. package/build/artifacts/contracts/interfaces/IPActionSwapPTYT.sol/IPActionSwapPTYT.dbg.json +1 -1
  77. package/build/artifacts/contracts/interfaces/IPActionSwapYT.sol/IPActionSwapYT.dbg.json +1 -1
  78. package/build/artifacts/contracts/interfaces/IPAllAction.sol/IPAllAction.dbg.json +1 -1
  79. package/build/artifacts/contracts/interfaces/IPBulkSeller.sol/IPBulkSeller.dbg.json +1 -1
  80. package/build/artifacts/contracts/interfaces/IPFeeDistributor.sol/IPFeeDistributor.dbg.json +1 -1
  81. package/build/artifacts/contracts/interfaces/IPFeeDistributor.sol/IPFeeDistributor.json +24 -32
  82. package/build/artifacts/contracts/interfaces/IPMarket.sol/IPMarket.dbg.json +1 -1
  83. package/build/artifacts/contracts/interfaces/IPVotingController.sol/IPVotingController.dbg.json +1 -1
  84. package/build/artifacts/contracts/interfaces/IPVotingEscrowMainchain.sol/IPVotingEscrowMainchain.dbg.json +1 -1
  85. package/build/artifacts/contracts/offchain-helpers/BulkSellerOffchain.sol/BulkSellerOffchain.dbg.json +1 -1
  86. package/build/artifacts/contracts/offchain-helpers/BulkSellerOffchain.sol/BulkSellerOffchain.json +2 -2
  87. package/build/artifacts/contracts/offchain-helpers/MarketMathStatic.sol/MarketMathStatic.dbg.json +1 -1
  88. package/build/artifacts/contracts/offchain-helpers/MarketMathStatic.sol/MarketMathStatic.json +2 -2
  89. package/build/artifacts/contracts/offchain-helpers/RouterStatic.sol/RouterStatic.dbg.json +1 -1
  90. package/build/artifacts/contracts/offchain-helpers/RouterStatic.sol/RouterStatic.json +2 -2
  91. package/build/artifacts/contracts/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.dbg.json +1 -1
  92. package/build/artifacts/contracts/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.json +2 -2
  93. package/build/artifacts/contracts/router/ActionCallback.sol/ActionCallback.dbg.json +1 -1
  94. package/build/artifacts/contracts/router/ActionCallback.sol/ActionCallback.json +2 -2
  95. package/build/artifacts/contracts/router/ActionMintRedeem.sol/ActionMintRedeem.dbg.json +1 -1
  96. package/build/artifacts/contracts/router/ActionMintRedeem.sol/ActionMintRedeem.json +2 -2
  97. package/build/artifacts/contracts/router/ActionMisc.sol/ActionMisc.dbg.json +1 -1
  98. package/build/artifacts/contracts/router/ActionMisc.sol/ActionMisc.json +2 -2
  99. package/build/artifacts/contracts/router/ActionSwapPT.sol/ActionSwapPT.dbg.json +1 -1
  100. package/build/artifacts/contracts/router/ActionSwapPT.sol/ActionSwapPT.json +2 -2
  101. package/build/artifacts/contracts/router/ActionSwapPTYT.sol/ActionSwapPTYT.dbg.json +1 -1
  102. package/build/artifacts/contracts/router/ActionSwapPTYT.sol/ActionSwapPTYT.json +2 -2
  103. package/build/artifacts/contracts/router/ActionSwapYT.sol/ActionSwapYT.dbg.json +1 -1
  104. package/build/artifacts/contracts/router/ActionSwapYT.sol/ActionSwapYT.json +2 -2
  105. package/build/artifacts/contracts/router/PendleRouter.sol/PendleRouter.dbg.json +1 -1
  106. package/build/artifacts/contracts/router/PendleRouter.sol/PendleRouter.json +2 -2
  107. package/build/artifacts/contracts/router/base/ActionBaseMintRedeem.sol/ActionBaseMintRedeem.dbg.json +1 -1
  108. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtInLib.dbg.json +1 -1
  109. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtInLib.json +2 -2
  110. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtOutLib.dbg.json +1 -1
  111. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtOutLib.json +2 -2
  112. package/build/artifacts/contracts/router/kyberswap/AggregationRouterHelper.sol/AggregationRouterHelper.dbg.json +1 -1
  113. package/build/artifacts/contracts/router/kyberswap/IMultihopRouterEthereum.sol/IMultihopRouterEthereum.dbg.json +1 -1
  114. package/build/artifacts/contracts/router/kyberswap/KyberSwapHelper.sol/KyberSwapHelper.dbg.json +1 -1
  115. package/contracts/LiquidityMining/VeDistributor/PendleFeeDistributor.sol +214 -0
  116. package/contracts/core/libraries/ArrayLib.sol +9 -0
  117. package/contracts/core/libraries/Errors.sol +9 -2
  118. package/contracts/interfaces/IPFeeDistributor.sol +10 -10
  119. package/deployments/43113-core.json +9 -3
  120. package/package.json +1 -1
  121. package/typechain-types/IPFeeDistributor.ts +43 -78
  122. package/typechain-types/IPFeeDistributorFactory.ts +53 -139
  123. package/typechain-types/PendleFeeDistributor.ts +373 -118
  124. package/typechain-types/factories/ActionAddRemoveLiq__factory.ts +1 -1
  125. package/typechain-types/factories/ActionCallback__factory.ts +1 -1
  126. package/typechain-types/factories/ActionMintRedeem__factory.ts +1 -1
  127. package/typechain-types/factories/ActionMisc__factory.ts +1 -1
  128. package/typechain-types/factories/ActionSwapPTYT__factory.ts +1 -1
  129. package/typechain-types/factories/ActionSwapPT__factory.ts +1 -1
  130. package/typechain-types/factories/ActionSwapYT__factory.ts +1 -1
  131. package/typechain-types/factories/BulkSellerFactory__factory.ts +1 -1
  132. package/typechain-types/factories/BulkSellerOffchain__factory.ts +1 -1
  133. package/typechain-types/factories/BulkSeller__factory.ts +1 -1
  134. package/typechain-types/factories/Errors__factory.ts +85 -4
  135. package/typechain-types/factories/IPFeeDistributorFactory__factory.ts +25 -34
  136. package/typechain-types/factories/IPFeeDistributor__factory.ts +24 -32
  137. package/typechain-types/factories/MarketMathStatic__factory.ts +1 -1
  138. package/typechain-types/factories/OracleLib__factory.ts +1 -1
  139. package/typechain-types/factories/PendleCurveFraxUsdcSY__factory.ts +1 -1
  140. package/typechain-types/factories/PendleCurveUsdd3CrvSY__factory.ts +1 -1
  141. package/typechain-types/factories/PendleFeeDistributor__factory.ts +310 -67
  142. package/typechain-types/factories/PendleGaugeControllerMainchainUpg__factory.ts +1 -1
  143. package/typechain-types/factories/PendleGaugeControllerSidechainUpg__factory.ts +1 -1
  144. package/typechain-types/factories/PendleLooksStakingSY__factory.ts +1 -1
  145. package/typechain-types/factories/PendleMarketFactory__factory.ts +1 -1
  146. package/typechain-types/factories/PendleMarket__factory.ts +1 -1
  147. package/typechain-types/factories/PendleMsgReceiveEndpointUpg__factory.ts +1 -1
  148. package/typechain-types/factories/PendleMsgSendEndpointUpg__factory.ts +1 -1
  149. package/typechain-types/factories/PendlePrincipalToken__factory.ts +1 -1
  150. package/typechain-types/factories/PendleQiTokenHelper__factory.ts +1 -1
  151. package/typechain-types/factories/PendleQiTokenSY__factory.ts +1 -1
  152. package/typechain-types/factories/PendleRouter__factory.ts +1 -1
  153. package/typechain-types/factories/PendleVotingControllerUpg__factory.ts +1 -1
  154. package/typechain-types/factories/PendleWstEthSY__factory.ts +1 -1
  155. package/typechain-types/factories/PendleYieldContractFactory__factory.ts +1 -1
  156. package/typechain-types/factories/PendleYieldToken__factory.ts +1 -1
  157. package/typechain-types/factories/RouterStatic__factory.ts +1 -1
  158. package/typechain-types/factories/SAPE__factory.ts +1 -1
  159. package/typechain-types/factories/VotingEscrowPendleMainchain__factory.ts +1 -1
  160. package/typechain-types/factories/VotingEscrowPendleSidechain__factory.ts +1 -1
  161. package/typechain-types/hardhat.d.ts +4 -76
  162. package/typechain-types/index.ts +2 -14
  163. package/build/artifacts/contracts/LiquidityMining/FeeDistributor/EpochResultManager.sol/EpochResultManager.dbg.json +0 -4
  164. package/build/artifacts/contracts/LiquidityMining/FeeDistributor/EpochResultManager.sol/EpochResultManager.json +0 -131
  165. package/build/artifacts/contracts/LiquidityMining/FeeDistributor/PendleFeeDistributor.sol/PendleFeeDistributor.dbg.json +0 -4
  166. package/build/artifacts/contracts/LiquidityMining/FeeDistributor/PendleFeeDistributor.sol/PendleFeeDistributor.json +0 -310
  167. package/build/artifacts/contracts/LiquidityMining/FeeDistributor/PendleFeeDistributorFactory.sol/PendleFeeDistributorFactory.dbg.json +0 -4
  168. package/build/artifacts/contracts/LiquidityMining/FeeDistributor/PendleFeeDistributorFactory.sol/PendleFeeDistributorFactory.json +0 -389
  169. package/build/artifacts/contracts/interfaces/IPFeeDistributorFactory.sol/IPFeeDistributorFactory.dbg.json +0 -4
  170. package/build/artifacts/contracts/interfaces/IPFeeDistributorFactory.sol/IPFeeDistributorFactory.json +0 -76
  171. package/contracts/LiquidityMining/FeeDistributor/EpochResultManager.sol +0 -159
  172. package/contracts/LiquidityMining/FeeDistributor/PendleFeeDistributor.sol +0 -99
  173. package/contracts/LiquidityMining/FeeDistributor/PendleFeeDistributorFactory.sol +0 -70
  174. package/contracts/interfaces/IPFeeDistributorFactory.sol +0 -14
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../../build-info/cfaee2011af0cd925c44a0b8d7310816.json"
3
+ "buildInfo": "../../../../build-info/92ac36e978c82783b79c3f3381de5170.json"
4
4
  }
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "_format": "hh-sol-dbg-1",
3
- "buildInfo": "../../../../build-info/cfaee2011af0cd925c44a0b8d7310816.json"
3
+ "buildInfo": "../../../../build-info/92ac36e978c82783b79c3f3381de5170.json"
4
4
  }
@@ -0,0 +1,214 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.17;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
5
+ import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
6
+ import "../../core/libraries/BoringOwnableUpgradeable.sol";
7
+ import "../../core/libraries/Errors.sol";
8
+ import "../../interfaces/IPFeeDistributor.sol";
9
+ import "../../interfaces/IPVotingEscrowMainchain.sol";
10
+ import "../../interfaces/IPVotingController.sol";
11
+ import "../libraries/WeekMath.sol";
12
+ import "../libraries/VeHistoryLib.sol";
13
+ import "../../core/libraries/ArrayLib.sol";
14
+
15
+ contract PendleFeeDistributor is UUPSUpgradeable, BoringOwnableUpgradeable, IPFeeDistributor {
16
+ using SafeERC20 for IERC20;
17
+ using VeBalanceLib for VeBalance;
18
+ using ArrayLib for uint256[];
19
+
20
+ address public immutable votingController;
21
+ address public immutable vePendle;
22
+ address public immutable token;
23
+
24
+ address[] public allPools;
25
+
26
+ // [pool] => lastFundedWeek
27
+ mapping(address => uint256) public lastFundedWeek;
28
+
29
+ // [pool, user] => UserInfo
30
+ mapping(address => mapping(address => UserInfo)) public userInfo;
31
+
32
+ // [pool, epoch] => [fee]
33
+ mapping(address => mapping(uint256 => uint256)) public fees;
34
+
35
+ modifier ensureValidPool(address pool) {
36
+ if (lastFundedWeek[pool] == 0) revert Errors.FDInvalidPool(pool);
37
+ _;
38
+ }
39
+
40
+ constructor(
41
+ address _votingController,
42
+ address _vePendle,
43
+ address _rewardToken
44
+ ) initializer {
45
+ votingController = _votingController;
46
+ vePendle = _vePendle;
47
+ token = _rewardToken;
48
+ }
49
+
50
+ function addPool(address pool, uint256 _startWeek) external onlyOwner {
51
+ if (!WeekMath.isValidWTime(_startWeek) || _startWeek == 0)
52
+ revert Errors.FDInvalidStartEpoch(_startWeek);
53
+
54
+ if (lastFundedWeek[pool] != 0) revert Errors.FDPoolAlreadyExists(pool);
55
+
56
+ lastFundedWeek[pool] = _startWeek - WeekMath.WEEK;
57
+ allPools.push(pool);
58
+ }
59
+
60
+ function getAllPools() external view returns (address[] memory) {
61
+ return allPools;
62
+ }
63
+
64
+ function fund(
65
+ address[] calldata pools,
66
+ uint256[][] calldata wTimes,
67
+ uint256[][] calldata amounts,
68
+ uint256 totalAmountToFund
69
+ ) external onlyOwner {
70
+ uint256 length = pools.length;
71
+ if (wTimes.length != length || amounts.length != length)
72
+ revert Errors.ArrayLengthMismatch();
73
+
74
+ uint256 totalFunded = 0;
75
+ for (uint256 i = 0; i < length; ++i) {
76
+ _fund(pools[i], wTimes[i], amounts[i]);
77
+ totalFunded += amounts[i].sum();
78
+ }
79
+
80
+ if (totalFunded != totalAmountToFund)
81
+ revert Errors.FDTotalAmountFundedNotMatch(totalFunded, totalAmountToFund);
82
+
83
+ IERC20(token).transferFrom(msg.sender, address(this), totalFunded);
84
+ }
85
+
86
+ function _fund(
87
+ address pool,
88
+ uint256[] calldata wTimes,
89
+ uint256[] calldata amounts
90
+ ) internal ensureValidPool(pool) {
91
+ if (wTimes.length != amounts.length) revert Errors.FDEpochLengthMismatch();
92
+
93
+ uint256 lastFunded = lastFundedWeek[pool];
94
+
95
+ for (uint256 i = 0; i < amounts.length; ++i) {
96
+ uint256 wTime = wTimes[i];
97
+ uint256 amount = amounts[i];
98
+
99
+ if (wTime != lastFunded + WeekMath.WEEK)
100
+ revert Errors.FDInvalidWTimeFund(lastFunded, wTime);
101
+
102
+ fees[pool][wTime] += amount;
103
+ lastFunded += WeekMath.WEEK;
104
+
105
+ emit UpdateFee(pool, wTime, amount);
106
+ }
107
+
108
+ lastFundedWeek[pool] = lastFunded;
109
+ }
110
+
111
+ function claimReward(address user, address[] calldata pools)
112
+ external
113
+ returns (uint256[] memory amountRewardOut)
114
+ {
115
+ amountRewardOut = new uint256[](pools.length);
116
+ for (uint256 i = 0; i < pools.length; ) {
117
+ amountRewardOut[i] = _accumulateUserReward(pools[i], user);
118
+ unchecked {
119
+ i++;
120
+ }
121
+ }
122
+ IERC20(token).safeTransfer(user, amountRewardOut.sum());
123
+ }
124
+
125
+ function _accumulateUserReward(address pool, address user)
126
+ internal
127
+ ensureValidPool(pool)
128
+ returns (uint256 totalReward)
129
+ {
130
+ uint256 length = _getUserCheckpointLength(pool, user);
131
+ if (length == 0) return 0;
132
+
133
+ uint256 lastWeek = lastFundedWeek[pool];
134
+ uint256 curWeek = userInfo[pool][user].firstUnclaimedWeek;
135
+ uint256 iter = userInfo[pool][user].iter;
136
+
137
+ if (curWeek > lastWeek) return 0; // nothing to account
138
+
139
+ Checkpoint memory checkpoint = _getUserCheckpointAt(pool, user, iter);
140
+ Checkpoint memory nextCheckpoint = checkpoint;
141
+
142
+ if (curWeek == 0) curWeek = checkpoint.timestamp + WeekMath.WEEK;
143
+
144
+ while (curWeek <= lastWeek) {
145
+ // we have at most one checkpoint per week
146
+ if (iter + 1 < length) {
147
+ if (nextCheckpoint.timestamp == checkpoint.timestamp) {
148
+ // next have been assigned to current checkpoint, so we need to get the next one
149
+ nextCheckpoint = _getUserCheckpointAt(pool, user, iter + 1);
150
+ }
151
+
152
+ if (nextCheckpoint.timestamp < curWeek) {
153
+ iter++;
154
+ checkpoint = nextCheckpoint;
155
+ }
156
+ // Important invariant: checkpoint[iter] < curWeek <= checkpoint[iter+1]
157
+ }
158
+
159
+ // assert(checkpoint.timestamp < curWeek); should always hold
160
+
161
+ uint256 userShare = checkpoint.value.getValueAt(uint128(curWeek));
162
+ if (userShare != 0) {
163
+ uint256 totalShare = _getPoolTotalSharesAt(pool, uint128(curWeek));
164
+ // userShare != 0 => totalShare != 0
165
+ uint256 amountRewardOut = (userShare * fees[pool][curWeek]) / totalShare;
166
+ totalReward += amountRewardOut;
167
+ emit ClaimReward(pool, user, curWeek, amountRewardOut);
168
+ }
169
+
170
+ curWeek += WeekMath.WEEK;
171
+ }
172
+
173
+ userInfo[pool][user] = UserInfo({
174
+ firstUnclaimedWeek: uint128(curWeek),
175
+ iter: uint128(iter)
176
+ });
177
+ }
178
+
179
+ function _getPoolTotalSharesAt(address pool, uint128 wTime) internal view returns (uint256) {
180
+ if (pool == vePendle) {
181
+ return IPVotingEscrowMainchain(vePendle).totalSupplyAt(wTime);
182
+ } else {
183
+ return IPVotingController(votingController).getPoolTotalVoteAt(pool, wTime);
184
+ }
185
+ }
186
+
187
+ function _getUserCheckpointAt(
188
+ address pool,
189
+ address user,
190
+ uint256 index
191
+ ) internal view returns (Checkpoint memory) {
192
+ if (pool == vePendle) {
193
+ return IPVotingEscrowMainchain(vePendle).getUserHistoryAt(user, index);
194
+ } else {
195
+ return IPVotingController(votingController).getUserPoolHistoryAt(user, pool, index);
196
+ }
197
+ }
198
+
199
+ function _getUserCheckpointLength(address pool, address user) internal view returns (uint256) {
200
+ if (pool == vePendle) {
201
+ return IPVotingEscrowMainchain(vePendle).getUserHistoryLength(user);
202
+ } else {
203
+ return IPVotingController(votingController).getUserPoolHistoryLength(user, pool);
204
+ }
205
+ }
206
+
207
+ function initialize() external initializer {
208
+ __BoringOwnable_init();
209
+ }
210
+
211
+ // ----------------- upgrade-related -----------------
212
+
213
+ function _authorizeUpgrade(address) internal override onlyOwner {}
214
+ }
@@ -13,6 +13,15 @@ library ArrayLib {
13
13
  return value;
14
14
  }
15
15
 
16
+ function max(uint256[] memory input) internal pure returns (uint256 value) {
17
+ for (uint256 i = 0; i < input.length; ) {
18
+ if (input[i] > value) value = input[i];
19
+ unchecked {
20
+ i++;
21
+ }
22
+ }
23
+ }
24
+
16
25
  function contains(address[] memory array, address element) internal pure returns (bool) {
17
26
  uint256 length = array.length;
18
27
  for (uint256 i = 0; i < length; ) {
@@ -138,8 +138,15 @@ library Errors {
138
138
  error ExpiryInThePast(uint256 expiry);
139
139
  error ChainNotSupported(uint256 chainId);
140
140
 
141
- error FDCantFundFutureEpoch();
142
- error FDFactoryDistributorAlreadyExisted(address pool, address distributor);
141
+ error FDTotalAmountFundedNotMatch(uint256 actualTotalAmount, uint256 expectedTotalAmount);
142
+ error FDEpochLengthMismatch();
143
+ error FDInvalidPool(address pool);
144
+ error FDPoolAlreadyExists(address pool);
145
+ error FDInvalidNewFinishedEpoch(uint256 oldFinishedEpoch, uint256 newFinishedEpoch);
146
+ error FDInvalidStartEpoch(uint256 startEpoch);
147
+ error FDInvalidWTimeFund(uint256 lastFunded, uint256 wTime);
148
+
149
+ error BDInvalidEpoch(uint256 epoch, uint256 startTime);
143
150
 
144
151
  // Cross-Chain
145
152
  error MsgNotFromSendEndpoint(uint16 srcChainId, bytes path);
@@ -2,18 +2,18 @@
2
2
  pragma solidity 0.8.17;
3
3
 
4
4
  interface IPFeeDistributor {
5
- event Fund(uint256 indexed epoch, uint256 incentive);
5
+ event UpdateFee(address indexed pool, uint256 indexed wTime, uint256 amount);
6
6
 
7
- event ClaimReward(
8
- address indexed user,
9
- address indexed rewardToken,
10
- uint256 lastEpochClaimed,
11
- uint256 totalReward
12
- );
7
+ event ClaimReward(address indexed pool, address indexed user, uint256 wTime, uint256 amount);
13
8
 
14
- function fund(uint256[] calldata rewardsForEpoch) external;
9
+ struct UserInfo {
10
+ uint128 firstUnclaimedWeek;
11
+ uint128 iter;
12
+ }
15
13
 
16
- function claimReward(address user) external returns (uint256 amountRewardOut);
14
+ function claimReward(address user, address[] calldata pools)
15
+ external
16
+ returns (uint256[] memory amountRewardOut);
17
17
 
18
- function incentivesForEpoch(uint256 epoch) external returns (uint256);
18
+ function getAllPools() external view returns (address[] memory);
19
19
  }
@@ -6,9 +6,14 @@
6
6
  "governance": "0x1FcCC097db89A86Bfc474A1028F93958295b1Fb7",
7
7
  "pendle": "0xB7609dec1C926204c3B67345cbCd54bc4aa7a940",
8
8
  "lzEndpoint": "0x93f54D755A063cE7bB9e6Ac47Eccc8e33411d706",
9
- "wrappedNative": "0xe43a7aD7C09d8fAE3ADe7361f0b847b23adD5094"
9
+ "wrappedNative": "0xe43a7aD7C09d8fAE3ADe7361f0b847b23adD5094",
10
+ "initialRewardFee": "30000000000000000",
11
+ "initialInterestFee": "30000000000000000",
12
+ "initialFeeRateRoot": "999500333083533",
13
+ "initialReserveFeePercent": "80",
14
+ "initialPendlePerSec": "826719576719576719",
15
+ "safeWaitTime": 15000
10
16
  },
11
- "splitter": "0x315A059EB986507A2a6085726643228401ea5e78",
12
17
  "PENDLE": "0xB7609dec1C926204c3B67345cbCd54bc4aa7a940",
13
18
  "yieldContractFactory": "0xe189c0F1EABDD23AB7DcA0d7657FF60c8f137356",
14
19
  "marketFactory": "0x24265d37C87d3ffE64D6B0274c168945d44D1ba2",
@@ -19,5 +24,6 @@
19
24
  "vePendle": "0xB20E3c268C993BC3c9Bc1C1cc5D7491F2268cD91",
20
25
  "senderEndpoint": "0x86bD575c36e236386284C035ffeBE66CB6ecd2DD",
21
26
  "votingController": "0x40ea97a7E9A4A0520229d1bbdf4D82E36b1a5475",
22
- "gaugeController": "0x90Fa61ea34f61e31e9471CEB0ED22b12bBf4263E"
27
+ "gaugeController": "0x90Fa61ea34f61e31e9471CEB0ED22b12bBf4263E",
28
+ "feeDistributor": "0x40160f3439317bCD0ec8eB09545dD6A30771A7B6"
23
29
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@pendle/core-v2",
3
3
  "description": "Core smart contracts of Pendle Protocol.",
4
4
  "license": "BUSL-1.1",
5
- "version": "0.18.0-testnet",
5
+ "version": "0.19.0-testnet",
6
6
  "homepage": "https://pendle.finance",
7
7
  "keywords": [
8
8
  "pendle",
@@ -25,58 +25,50 @@ import type {
25
25
  export interface IPFeeDistributorInterface extends utils.Interface {
26
26
  contractName: "IPFeeDistributor";
27
27
  functions: {
28
- "claimReward(address)": FunctionFragment;
29
- "fund(uint256[])": FunctionFragment;
30
- "incentivesForEpoch(uint256)": FunctionFragment;
28
+ "claimReward(address,address[])": FunctionFragment;
29
+ "getAllPools()": FunctionFragment;
31
30
  };
32
31
 
33
- encodeFunctionData(functionFragment: "claimReward", values: [string]): string;
34
32
  encodeFunctionData(
35
- functionFragment: "fund",
36
- values: [BigNumberish[]]
33
+ functionFragment: "claimReward",
34
+ values: [string, string[]]
37
35
  ): string;
38
36
  encodeFunctionData(
39
- functionFragment: "incentivesForEpoch",
40
- values: [BigNumberish]
37
+ functionFragment: "getAllPools",
38
+ values?: undefined
41
39
  ): string;
42
40
 
43
41
  decodeFunctionResult(
44
42
  functionFragment: "claimReward",
45
43
  data: BytesLike
46
44
  ): Result;
47
- decodeFunctionResult(functionFragment: "fund", data: BytesLike): Result;
48
45
  decodeFunctionResult(
49
- functionFragment: "incentivesForEpoch",
46
+ functionFragment: "getAllPools",
50
47
  data: BytesLike
51
48
  ): Result;
52
49
 
53
50
  events: {
54
51
  "ClaimReward(address,address,uint256,uint256)": EventFragment;
55
- "Fund(uint256,uint256)": EventFragment;
52
+ "UpdateFee(address,uint256,uint256)": EventFragment;
56
53
  };
57
54
 
58
55
  getEvent(nameOrSignatureOrTopic: "ClaimReward"): EventFragment;
59
- getEvent(nameOrSignatureOrTopic: "Fund"): EventFragment;
56
+ getEvent(nameOrSignatureOrTopic: "UpdateFee"): EventFragment;
60
57
  }
61
58
 
62
59
  export type ClaimRewardEvent = TypedEvent<
63
60
  [string, string, BigNumber, BigNumber],
64
- {
65
- user: string;
66
- rewardToken: string;
67
- lastEpochClaimed: BigNumber;
68
- totalReward: BigNumber;
69
- }
61
+ { pool: string; user: string; wTime: BigNumber; amount: BigNumber }
70
62
  >;
71
63
 
72
64
  export type ClaimRewardEventFilter = TypedEventFilter<ClaimRewardEvent>;
73
65
 
74
- export type FundEvent = TypedEvent<
75
- [BigNumber, BigNumber],
76
- { epoch: BigNumber; incentive: BigNumber }
66
+ export type UpdateFeeEvent = TypedEvent<
67
+ [string, BigNumber, BigNumber],
68
+ { pool: string; wTime: BigNumber; amount: BigNumber }
77
69
  >;
78
70
 
79
- export type FundEventFilter = TypedEventFilter<FundEvent>;
71
+ export type UpdateFeeEventFilter = TypedEventFilter<UpdateFeeEvent>;
80
72
 
81
73
  export interface IPFeeDistributor extends BaseContract {
82
74
  contractName: "IPFeeDistributor";
@@ -108,101 +100,74 @@ export interface IPFeeDistributor extends BaseContract {
108
100
  functions: {
109
101
  claimReward(
110
102
  user: string,
103
+ pools: string[],
111
104
  overrides?: Overrides & { from?: string | Promise<string> }
112
105
  ): Promise<ContractTransaction>;
113
106
 
114
- fund(
115
- rewardsForEpoch: BigNumberish[],
116
- overrides?: Overrides & { from?: string | Promise<string> }
117
- ): Promise<ContractTransaction>;
118
-
119
- incentivesForEpoch(
120
- epoch: BigNumberish,
121
- overrides?: Overrides & { from?: string | Promise<string> }
122
- ): Promise<ContractTransaction>;
107
+ getAllPools(overrides?: CallOverrides): Promise<[string[]]>;
123
108
  };
124
109
 
125
110
  claimReward(
126
111
  user: string,
112
+ pools: string[],
127
113
  overrides?: Overrides & { from?: string | Promise<string> }
128
114
  ): Promise<ContractTransaction>;
129
115
 
130
- fund(
131
- rewardsForEpoch: BigNumberish[],
132
- overrides?: Overrides & { from?: string | Promise<string> }
133
- ): Promise<ContractTransaction>;
134
-
135
- incentivesForEpoch(
136
- epoch: BigNumberish,
137
- overrides?: Overrides & { from?: string | Promise<string> }
138
- ): Promise<ContractTransaction>;
116
+ getAllPools(overrides?: CallOverrides): Promise<string[]>;
139
117
 
140
118
  callStatic: {
141
- claimReward(user: string, overrides?: CallOverrides): Promise<BigNumber>;
142
-
143
- fund(
144
- rewardsForEpoch: BigNumberish[],
119
+ claimReward(
120
+ user: string,
121
+ pools: string[],
145
122
  overrides?: CallOverrides
146
- ): Promise<void>;
123
+ ): Promise<BigNumber[]>;
147
124
 
148
- incentivesForEpoch(
149
- epoch: BigNumberish,
150
- overrides?: CallOverrides
151
- ): Promise<BigNumber>;
125
+ getAllPools(overrides?: CallOverrides): Promise<string[]>;
152
126
  };
153
127
 
154
128
  filters: {
155
129
  "ClaimReward(address,address,uint256,uint256)"(
130
+ pool?: string | null,
156
131
  user?: string | null,
157
- rewardToken?: string | null,
158
- lastEpochClaimed?: null,
159
- totalReward?: null
132
+ wTime?: null,
133
+ amount?: null
160
134
  ): ClaimRewardEventFilter;
161
135
  ClaimReward(
136
+ pool?: string | null,
162
137
  user?: string | null,
163
- rewardToken?: string | null,
164
- lastEpochClaimed?: null,
165
- totalReward?: null
138
+ wTime?: null,
139
+ amount?: null
166
140
  ): ClaimRewardEventFilter;
167
141
 
168
- "Fund(uint256,uint256)"(
169
- epoch?: BigNumberish | null,
170
- incentive?: null
171
- ): FundEventFilter;
172
- Fund(epoch?: BigNumberish | null, incentive?: null): FundEventFilter;
142
+ "UpdateFee(address,uint256,uint256)"(
143
+ pool?: string | null,
144
+ wTime?: BigNumberish | null,
145
+ amount?: null
146
+ ): UpdateFeeEventFilter;
147
+ UpdateFee(
148
+ pool?: string | null,
149
+ wTime?: BigNumberish | null,
150
+ amount?: null
151
+ ): UpdateFeeEventFilter;
173
152
  };
174
153
 
175
154
  estimateGas: {
176
155
  claimReward(
177
156
  user: string,
157
+ pools: string[],
178
158
  overrides?: Overrides & { from?: string | Promise<string> }
179
159
  ): Promise<BigNumber>;
180
160
 
181
- fund(
182
- rewardsForEpoch: BigNumberish[],
183
- overrides?: Overrides & { from?: string | Promise<string> }
184
- ): Promise<BigNumber>;
185
-
186
- incentivesForEpoch(
187
- epoch: BigNumberish,
188
- overrides?: Overrides & { from?: string | Promise<string> }
189
- ): Promise<BigNumber>;
161
+ getAllPools(overrides?: CallOverrides): Promise<BigNumber>;
190
162
  };
191
163
 
192
164
  populateTransaction: {
193
165
  claimReward(
194
166
  user: string,
167
+ pools: string[],
195
168
  overrides?: Overrides & { from?: string | Promise<string> }
196
169
  ): Promise<PopulatedTransaction>;
197
170
 
198
- fund(
199
- rewardsForEpoch: BigNumberish[],
200
- overrides?: Overrides & { from?: string | Promise<string> }
201
- ): Promise<PopulatedTransaction>;
202
-
203
- incentivesForEpoch(
204
- epoch: BigNumberish,
205
- overrides?: Overrides & { from?: string | Promise<string> }
206
- ): Promise<PopulatedTransaction>;
171
+ getAllPools(overrides?: CallOverrides): Promise<PopulatedTransaction>;
207
172
  };
208
173
  }