@pendle/core-v2 1.4.0-mainnet → 2.0.0-mainnet

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 (357) 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/PendleMsgReceiverAppUpg.sol/PendleMsgReceiverAppUpg.json +1 -1
  5. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgSendEndpointUpg.sol/PendleMsgSendEndpointUpg.dbg.json +1 -1
  6. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgSendEndpointUpg.sol/PendleMsgSendEndpointUpg.json +2 -2
  7. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgSenderAppUpg.sol/PendleMsgSenderAppUpg.dbg.json +1 -1
  8. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerBaseUpg.sol/PendleGaugeControllerBaseUpg.dbg.json +1 -1
  9. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerMainchainUpg.sol/PendleGaugeControllerMainchainUpg.dbg.json +1 -1
  10. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerMainchainUpg.sol/PendleGaugeControllerMainchainUpg.json +2 -2
  11. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerSidechainUpg.sol/PendleGaugeControllerSidechainUpg.dbg.json +1 -1
  12. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerSidechainUpg.sol/PendleGaugeControllerSidechainUpg.json +3 -3
  13. package/build/artifacts/contracts/LiquidityMining/VeDistributor/PendleFeeDistributor.sol/PendleFeeDistributor.dbg.json +1 -1
  14. package/build/artifacts/contracts/LiquidityMining/VeDistributor/PendleFeeDistributor.sol/PendleFeeDistributor.json +2 -2
  15. package/build/artifacts/contracts/LiquidityMining/VotingController/PendleVotingControllerUpg.sol/PendleVotingControllerUpg.dbg.json +1 -1
  16. package/build/artifacts/contracts/LiquidityMining/VotingController/PendleVotingControllerUpg.sol/PendleVotingControllerUpg.json +2 -2
  17. package/build/artifacts/contracts/LiquidityMining/VotingController/VotingControllerStorageUpg.sol/VotingControllerStorageUpg.dbg.json +1 -1
  18. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleMainchain.sol/VotingEscrowPendleMainchain.dbg.json +1 -1
  19. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleMainchain.sol/VotingEscrowPendleMainchain.json +2 -2
  20. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleSidechain.sol/VotingEscrowPendleSidechain.dbg.json +1 -1
  21. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleSidechain.sol/VotingEscrowPendleSidechain.json +3 -3
  22. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowTokenBase.sol/VotingEscrowTokenBase.dbg.json +1 -1
  23. package/build/artifacts/contracts/LiquidityMining/libraries/VeBalanceLib.sol/VeBalanceLib.dbg.json +1 -1
  24. package/build/artifacts/contracts/LiquidityMining/libraries/VeBalanceLib.sol/VeBalanceLib.json +2 -2
  25. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/CheckpointHelper.dbg.json +1 -1
  26. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/CheckpointHelper.json +2 -2
  27. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/Checkpoints.dbg.json +1 -1
  28. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/Checkpoints.json +2 -2
  29. package/build/artifacts/contracts/core/BulkSeller/BulkSeller.sol/BulkSeller.dbg.json +1 -1
  30. package/build/artifacts/contracts/core/BulkSeller/BulkSeller.sol/BulkSeller.json +2 -2
  31. package/build/artifacts/contracts/core/BulkSeller/BulkSellerFactory.sol/BulkSellerFactory.dbg.json +1 -1
  32. package/build/artifacts/contracts/core/BulkSeller/BulkSellerFactory.sol/BulkSellerFactory.json +2 -2
  33. package/build/artifacts/contracts/core/BulkSeller/BulkSellerMathCore.sol/BulkSellerMathCore.dbg.json +1 -1
  34. package/build/artifacts/contracts/core/BulkSeller/BulkSellerMathCore.sol/BulkSellerMathCore.json +2 -2
  35. package/build/artifacts/contracts/core/Market/MarketMathCore.sol/MarketMathCore.dbg.json +1 -1
  36. package/build/artifacts/contracts/core/Market/MarketMathCore.sol/MarketMathCore.json +2 -2
  37. package/build/artifacts/contracts/core/Market/OracleLib.sol/OracleLib.dbg.json +1 -1
  38. package/build/artifacts/contracts/core/Market/OracleLib.sol/OracleLib.json +2 -2
  39. package/build/artifacts/contracts/core/Market/PendleGauge.sol/PendleGauge.dbg.json +1 -1
  40. package/build/artifacts/contracts/core/Market/PendleMarket.sol/PendleMarket.dbg.json +1 -1
  41. package/build/artifacts/contracts/core/Market/PendleMarket.sol/PendleMarket.json +2 -2
  42. package/build/artifacts/contracts/core/Market/PendleMarketFactory.sol/PendleMarketFactory.dbg.json +1 -1
  43. package/build/artifacts/contracts/core/Market/PendleMarketFactory.sol/PendleMarketFactory.json +2 -2
  44. package/build/artifacts/contracts/core/RewardManager/RewardManager.sol/RewardManager.dbg.json +1 -1
  45. package/build/artifacts/contracts/core/RewardManager/RewardManagerAbstract.sol/RewardManagerAbstract.dbg.json +1 -1
  46. package/build/artifacts/contracts/core/StandardizedYield/SYBase.sol/SYBase.dbg.json +1 -1
  47. package/build/artifacts/contracts/core/StandardizedYield/SYBaseWithRewards.sol/SYBaseWithRewards.dbg.json +1 -1
  48. package/build/artifacts/contracts/core/StandardizedYield/StEthHelper.sol/StEthHelper.dbg.json +1 -1
  49. package/build/artifacts/contracts/core/StandardizedYield/implementations/Ape/sAPE.sol/sAPE.dbg.json +1 -1
  50. package/build/artifacts/contracts/core/StandardizedYield/implementations/Ape/sAPE.sol/sAPE.json +2 -2
  51. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAura3EthSY.sol/PendleAura3EthSY.dbg.json +1 -1
  52. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAura3EthSY.sol/PendleAura3EthSY.json +2 -2
  53. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraCbethWstethSY.sol/PendleAuraCbethWstethSY.dbg.json +1 -1
  54. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraCbethWstethSY.sol/PendleAuraCbethWstethSY.json +2 -2
  55. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethRethSY.sol/PendleAuraWethRethSY.dbg.json +1 -1
  56. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethRethSY.sol/PendleAuraWethRethSY.json +2 -2
  57. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethWstethSY.sol/PendleAuraWethWstethSY.dbg.json +1 -1
  58. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethWstethSY.sol/PendleAuraWethWstethSY.json +2 -2
  59. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/PendleAuraBalancerStableLPSY.sol/PendleAuraBalancerStableLPSY.dbg.json +1 -1
  60. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenHelper.sol/PendleQiTokenHelper.dbg.json +1 -1
  61. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenHelper.sol/PendleQiTokenHelper.json +2 -2
  62. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenSY.sol/PendleQiTokenSY.dbg.json +1 -1
  63. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenSY.sol/PendleQiTokenSY.json +2 -2
  64. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveFraxUsdcSY.sol/PendleCurveFraxUsdcSY.dbg.json +1 -1
  65. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveFraxUsdcSY.sol/PendleCurveFraxUsdcSY.json +2 -2
  66. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveUsdd3CrvSY.sol/PendleCurveUsdd3CrvSY.dbg.json +1 -1
  67. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveUsdd3CrvSY.sol/PendleCurveUsdd3CrvSY.json +2 -2
  68. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/base/PendleConvexLPSY.sol/PendleConvexLPSY.dbg.json +1 -1
  69. package/build/artifacts/contracts/core/StandardizedYield/implementations/GLP/GLPPreviewHelper.sol/GLPPreviewHelper.dbg.json +4 -0
  70. package/build/artifacts/contracts/core/StandardizedYield/implementations/GLP/GLPPreviewHelper.sol/GLPPreviewHelper.json +50 -0
  71. package/build/artifacts/contracts/core/StandardizedYield/implementations/GLP/PendleGlpSY.sol/PendleGlpSY.dbg.json +4 -0
  72. package/build/artifacts/contracts/core/StandardizedYield/implementations/GLP/PendleGlpSY.sol/PendleGlpSY.json +1163 -0
  73. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleLooksStakingSY.sol/PendleLooksStakingSY.dbg.json +1 -1
  74. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleLooksStakingSY.sol/PendleLooksStakingSY.json +2 -2
  75. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleWstEthSY.sol/PendleWstEthSY.dbg.json +1 -1
  76. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleWstEthSY.sol/PendleWstEthSY.json +2 -2
  77. package/build/artifacts/contracts/core/YieldContracts/InterestManagerYT.sol/InterestManagerYT.dbg.json +1 -1
  78. package/build/artifacts/contracts/core/YieldContracts/PendlePrincipalToken.sol/PendlePrincipalToken.dbg.json +1 -1
  79. package/build/artifacts/contracts/core/YieldContracts/PendlePrincipalToken.sol/PendlePrincipalToken.json +2 -2
  80. package/build/artifacts/contracts/core/YieldContracts/PendleYieldContractFactory.sol/PendleYieldContractFactory.dbg.json +1 -1
  81. package/build/artifacts/contracts/core/YieldContracts/PendleYieldContractFactory.sol/PendleYieldContractFactory.json +2 -2
  82. package/build/artifacts/contracts/core/YieldContracts/PendleYieldToken.sol/PendleYieldToken.dbg.json +1 -1
  83. package/build/artifacts/contracts/core/YieldContracts/PendleYieldToken.sol/PendleYieldToken.json +2 -2
  84. package/build/artifacts/contracts/core/YieldContractsV2/InterestManagerYTV2.sol/InterestManagerYTV2.dbg.json +4 -0
  85. package/build/artifacts/contracts/core/YieldContractsV2/InterestManagerYTV2.sol/InterestManagerYTV2.json +66 -0
  86. package/build/artifacts/contracts/core/YieldContractsV2/PendlePrincipalTokenV2.sol/PendlePrincipalTokenV2.dbg.json +4 -0
  87. package/build/artifacts/contracts/core/YieldContractsV2/PendlePrincipalTokenV2.sol/PendlePrincipalTokenV2.json +476 -0
  88. package/build/artifacts/contracts/core/YieldContractsV2/PendleYieldContractFactoryV2.sol/PendleYieldContractFactoryV2.dbg.json +4 -0
  89. package/build/artifacts/contracts/core/YieldContractsV2/PendleYieldContractFactoryV2.sol/PendleYieldContractFactoryV2.json +590 -0
  90. package/build/artifacts/contracts/core/YieldContractsV2/PendleYieldTokenV2.sol/PendleYieldTokenV2.dbg.json +4 -0
  91. package/build/artifacts/contracts/core/YieldContractsV2/PendleYieldTokenV2.sol/PendleYieldTokenV2.json +1017 -0
  92. package/build/artifacts/contracts/core/libraries/Errors.sol/Errors.dbg.json +1 -1
  93. package/build/artifacts/contracts/core/libraries/Errors.sol/Errors.json +50 -2
  94. package/build/artifacts/contracts/core/libraries/TokenHelper.sol/TokenHelper.dbg.json +1 -1
  95. package/build/artifacts/contracts/interfaces/GMX/IGMXVault.sol/IGMXVault.dbg.json +4 -0
  96. package/build/artifacts/contracts/interfaces/GMX/IGMXVault.sol/IGMXVault.json +308 -0
  97. package/build/artifacts/contracts/interfaces/GMX/IGlpManager.sol/IGlpManager.dbg.json +4 -0
  98. package/build/artifacts/contracts/interfaces/GMX/IGlpManager.sol/IGlpManager.json +43 -0
  99. package/build/artifacts/contracts/interfaces/GMX/IRewardRouterV2.sol/IRewardRouterV2.dbg.json +4 -0
  100. package/build/artifacts/contracts/interfaces/GMX/IRewardRouterV2.sol/IRewardRouterV2.json +201 -0
  101. package/build/artifacts/contracts/interfaces/GMX/IVaultPriceFeed.sol/IVaultPriceFeed.dbg.json +4 -0
  102. package/build/artifacts/contracts/interfaces/GMX/IVaultPriceFeed.sol/IVaultPriceFeed.json +45 -0
  103. package/build/artifacts/contracts/interfaces/IAddressProvider.sol/IAddressProvider.dbg.json +4 -0
  104. package/build/artifacts/contracts/interfaces/IAddressProvider.sol/IAddressProvider.json +48 -0
  105. package/build/artifacts/contracts/interfaces/IDiamondCut.sol/IDiamondCut.dbg.json +4 -0
  106. package/build/artifacts/contracts/interfaces/IDiamondCut.sol/IDiamondCut.json +93 -0
  107. package/build/artifacts/contracts/interfaces/IDiamondLoupe.sol/IDiamondLoupe.dbg.json +4 -0
  108. package/build/artifacts/contracts/interfaces/IDiamondLoupe.sol/IDiamondLoupe.json +87 -0
  109. package/build/artifacts/contracts/interfaces/IPActionAddRemoveLiq.sol/IPActionAddRemoveLiq.dbg.json +1 -1
  110. package/build/artifacts/contracts/interfaces/IPActionAddRemoveLiq.sol/IPActionAddRemoveLiq.json +338 -16
  111. package/build/artifacts/contracts/interfaces/IPActionMintRedeem.sol/IPActionMintRedeem.dbg.json +1 -1
  112. package/build/artifacts/contracts/interfaces/IPActionMintRedeem.sol/IPActionMintRedeem.json +105 -224
  113. package/build/artifacts/contracts/interfaces/IPActionMisc.sol/IPActionMisc.dbg.json +1 -1
  114. package/build/artifacts/contracts/interfaces/IPActionMisc.sol/IPActionMisc.json +56 -12
  115. package/build/artifacts/contracts/interfaces/IPActionSwapPT.sol/IPActionSwapPT.dbg.json +1 -1
  116. package/build/artifacts/contracts/interfaces/IPActionSwapPT.sol/IPActionSwapPT.json +52 -8
  117. package/build/artifacts/contracts/interfaces/IPActionSwapYT.sol/IPActionSwapYT.dbg.json +1 -1
  118. package/build/artifacts/contracts/interfaces/IPActionSwapYT.sol/IPActionSwapYT.json +231 -8
  119. package/build/artifacts/contracts/interfaces/IPAllAction.sol/IPAllAction.dbg.json +1 -1
  120. package/build/artifacts/contracts/interfaces/IPAllAction.sol/IPAllAction.json +675 -241
  121. package/build/artifacts/contracts/interfaces/IPBulkSeller.sol/IPBulkSeller.dbg.json +1 -1
  122. package/build/artifacts/contracts/interfaces/IPInterestManagerYTV2.sol/IPInterestManagerYTV2.dbg.json +4 -0
  123. package/build/artifacts/contracts/interfaces/IPInterestManagerYTV2.sol/IPInterestManagerYTV2.json +40 -0
  124. package/build/artifacts/contracts/interfaces/IPMarket.sol/IPMarket.dbg.json +1 -1
  125. package/build/artifacts/contracts/interfaces/IPMsgReceiverApp.sol/IPMsgReceiverApp.dbg.json +1 -1
  126. package/build/artifacts/contracts/interfaces/IPMsgReceiverApp.sol/IPMsgReceiverApp.json +1 -1
  127. package/build/artifacts/contracts/interfaces/IPVotingController.sol/IPVotingController.dbg.json +1 -1
  128. package/build/artifacts/contracts/interfaces/IPVotingEscrowMainchain.sol/IPVotingEscrowMainchain.dbg.json +1 -1
  129. package/build/artifacts/contracts/interfaces/IPYieldTokenV2.sol/IPYieldTokenV2.dbg.json +4 -0
  130. package/build/artifacts/contracts/interfaces/IPYieldTokenV2.sol/IPYieldTokenV2.json +679 -0
  131. package/build/artifacts/contracts/offchain-helpers/AddressProvider.sol/AddressProvider.dbg.json +4 -0
  132. package/build/artifacts/contracts/offchain-helpers/AddressProvider.sol/AddressProvider.json +143 -0
  133. package/build/artifacts/contracts/offchain-helpers/BulkSellerOffchain.sol/BulkSellerOffchain.dbg.json +1 -1
  134. package/build/artifacts/contracts/offchain-helpers/BulkSellerOffchain.sol/BulkSellerOffchain.json +2 -2
  135. package/build/artifacts/contracts/offchain-helpers/MarketMathStatic.sol/MarketMathStatic.dbg.json +1 -1
  136. package/build/artifacts/contracts/offchain-helpers/MarketMathStatic.sol/MarketMathStatic.json +2 -28
  137. package/build/artifacts/contracts/offchain-helpers/PendleMulticall.sol/PendleMulticall.dbg.json +1 -1
  138. package/build/artifacts/contracts/offchain-helpers/RouterStatic.sol/RouterStatic.dbg.json +1 -1
  139. package/build/artifacts/contracts/offchain-helpers/RouterStatic.sol/RouterStatic.json +144 -60
  140. package/build/artifacts/contracts/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.dbg.json +1 -1
  141. package/build/artifacts/contracts/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.json +345 -62
  142. package/build/artifacts/contracts/router/ActionMintRedeem.sol/ActionMintRedeem.dbg.json +1 -1
  143. package/build/artifacts/contracts/router/ActionMintRedeem.sol/ActionMintRedeem.json +107 -260
  144. package/build/artifacts/contracts/router/ActionMisc.sol/ActionMisc.dbg.json +1 -1
  145. package/build/artifacts/contracts/router/ActionMisc.sol/ActionMisc.json +57 -18
  146. package/build/artifacts/contracts/router/ActionSwapPT.sol/ActionSwapPT.dbg.json +1 -1
  147. package/build/artifacts/contracts/router/ActionSwapPT.sol/ActionSwapPT.json +54 -65
  148. package/build/artifacts/contracts/router/ActionSwapYT.sol/ActionSwapYT.dbg.json +1 -1
  149. package/build/artifacts/contracts/router/ActionSwapYT.sol/ActionSwapYT.json +342 -44
  150. package/build/artifacts/contracts/router/PendleRouter.sol/PendleRouter.dbg.json +1 -1
  151. package/build/artifacts/contracts/router/PendleRouter.sol/PendleRouter.json +76 -67
  152. package/build/artifacts/contracts/router/base/ActionBaseCallback.sol/ActionBaseCallback.dbg.json +4 -0
  153. package/build/artifacts/contracts/router/base/ActionBaseCallback.sol/ActionBaseCallback.json +141 -0
  154. package/build/artifacts/contracts/router/base/ActionBaseMintRedeem.sol/ActionBaseMintRedeem.dbg.json +1 -1
  155. package/build/artifacts/contracts/router/base/ActionBaseMintRedeem.sol/ActionBaseMintRedeem.json +1 -15
  156. package/build/artifacts/contracts/router/base/CallbackHelper.sol/CallbackHelper.dbg.json +1 -1
  157. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtInLib.dbg.json +1 -1
  158. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtInLib.json +2 -2
  159. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtOutLib.dbg.json +1 -1
  160. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtOutLib.json +2 -2
  161. package/build/artifacts/contracts/router/swap-aggregator/1inch/I1inchAggregationRouterV5.sol/I1inchAggregationRouterV5.dbg.json +4 -0
  162. package/build/artifacts/contracts/router/swap-aggregator/1inch/I1inchAggregationRouterV5.sol/I1inchAggregationRouterV5.json +160 -0
  163. package/build/artifacts/contracts/router/swap-aggregator/1inch/OneInchAggregationRouterHelper.sol/OneInchAggregationRouterHelper.dbg.json +4 -0
  164. package/build/artifacts/contracts/router/swap-aggregator/1inch/OneInchAggregationRouterHelper.sol/OneInchAggregationRouterHelper.json +10 -0
  165. package/build/artifacts/contracts/router/swap-aggregator/IPSwapAggregator.sol/IPSwapAggregator.dbg.json +4 -0
  166. package/build/artifacts/contracts/router/swap-aggregator/IPSwapAggregator.sol/IPSwapAggregator.json +56 -0
  167. package/build/artifacts/contracts/router/swap-aggregator/PendleSwapAggregator.sol/PendleSwapAggregator.dbg.json +4 -0
  168. package/build/artifacts/contracts/router/swap-aggregator/PendleSwapAggregator.sol/PendleSwapAggregator.json +72 -0
  169. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/KyberAggregationRouterHelper.sol/KyberAggregationRouterHelper.dbg.json +4 -0
  170. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/KyberAggregationRouterHelper.sol/KyberAggregationRouterHelper.json +10 -0
  171. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ScaleDataHelperEthereum1.sol/ScaleDataHelperEthereum1.dbg.json +4 -0
  172. package/build/artifacts/contracts/router/{kyberswap → swap-aggregator/kyberswap}/ScaleDataHelperEthereum1.sol/ScaleDataHelperEthereum1.json +3 -3
  173. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IAggregationExecutor.sol/IAggregationExecutor.dbg.json +4 -0
  174. package/build/artifacts/contracts/router/{kyberswap → swap-aggregator/kyberswap}/interfaces/IAggregationExecutor.sol/IAggregationExecutor.json +1 -1
  175. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelperEthereum1.sol/IExecutorHelperEthereum1.dbg.json +4 -0
  176. package/build/artifacts/contracts/router/{kyberswap → swap-aggregator/kyberswap}/interfaces/IExecutorHelperEthereum1.sol/IExecutorHelperEthereum1.json +30 -1
  177. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IHashflow.sol/IHashflow.dbg.json +4 -0
  178. package/build/artifacts/contracts/router/{kyberswap → swap-aggregator/kyberswap}/interfaces/IHashflow.sol/IHashflow.json +1 -1
  179. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/interfaces/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.dbg.json +4 -0
  180. package/build/artifacts/contracts/router/{kyberswap → swap-aggregator/kyberswap}/interfaces/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.json +1 -1
  181. package/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiverAppUpg.sol +0 -1
  182. package/contracts/core/StandardizedYield/implementations/GLP/GLPPreviewHelper.sol +142 -0
  183. package/contracts/core/StandardizedYield/implementations/GLP/PendleGlpSY.sol +222 -0
  184. package/contracts/core/StandardizedYield/implementations/GLP/README.md +61 -0
  185. package/contracts/core/YieldContractsV2/InterestManagerYTV2.sol +114 -0
  186. package/contracts/core/YieldContractsV2/PendlePrincipalTokenV2.sol +63 -0
  187. package/contracts/core/YieldContractsV2/PendleYieldContractFactoryV2.sol +200 -0
  188. package/contracts/core/YieldContractsV2/PendleYieldTokenV2.sol +485 -0
  189. package/contracts/core/libraries/Errors.sol +5 -0
  190. package/contracts/core/libraries/TokenHelper.sol +10 -0
  191. package/contracts/interfaces/GMX/IGMXVault.sol +47 -0
  192. package/contracts/interfaces/GMX/IGlpManager.sol +8 -0
  193. package/contracts/interfaces/GMX/IRewardRouterV2.sol +43 -0
  194. package/contracts/interfaces/GMX/IVaultPriceFeed.sol +11 -0
  195. package/contracts/interfaces/IAddressProvider.sol +7 -0
  196. package/contracts/interfaces/IDiamondCut.sol +36 -0
  197. package/contracts/interfaces/IDiamondLoupe.sol +38 -0
  198. package/contracts/interfaces/IPActionAddRemoveLiq.sol +36 -1
  199. package/contracts/interfaces/IPActionMintRedeem.sol +2 -55
  200. package/contracts/interfaces/IPActionMisc.sol +18 -4
  201. package/contracts/interfaces/IPActionSwapPT.sol +1 -1
  202. package/contracts/interfaces/IPActionSwapYT.sol +28 -4
  203. package/contracts/interfaces/IPAllAction.sol +5 -3
  204. package/contracts/interfaces/IPInterestManagerYTV2.sol +13 -0
  205. package/contracts/interfaces/IPMsgReceiverApp.sol +1 -1
  206. package/contracts/interfaces/IPYieldTokenV2.sol +66 -0
  207. package/contracts/offchain-helpers/AddressProvider.sol +16 -0
  208. package/contracts/offchain-helpers/MarketMathStatic.sol +15 -0
  209. package/contracts/offchain-helpers/RouterStatic.sol +22 -0
  210. package/contracts/router/ActionAddRemoveLiq.sol +116 -6
  211. package/contracts/router/ActionMintRedeem.sol +12 -202
  212. package/contracts/router/ActionMisc.sol +45 -19
  213. package/contracts/router/ActionSwapPT.sol +0 -5
  214. package/contracts/router/ActionSwapYT.sol +103 -13
  215. package/contracts/router/PendleRouter.sol +211 -72
  216. package/contracts/router/{ActionCallback.sol → base/ActionBaseCallback.sol} +47 -47
  217. package/contracts/router/base/ActionBaseMintRedeem.sol +105 -60
  218. package/contracts/router/base/CallbackHelper.sol +137 -44
  219. package/contracts/router/base/MarketApproxLib.sol +227 -350
  220. package/contracts/router/swap-aggregator/1inch/I1inchAggregationRouterV5.sol +45 -0
  221. package/contracts/router/swap-aggregator/1inch/OneInchAggregationRouterHelper.sol +69 -0
  222. package/contracts/router/swap-aggregator/IPSwapAggregator.sol +25 -0
  223. package/contracts/router/swap-aggregator/PendleSwapAggregator.sol +47 -0
  224. package/contracts/router/{kyberswap/AggregationRouterHelper.sol → swap-aggregator/kyberswap/KyberAggregationRouterHelper.sol} +5 -108
  225. package/contracts/router/{kyberswap → swap-aggregator/kyberswap}/ScaleDataHelperEthereum1.sol +13 -0
  226. package/contracts/router/{kyberswap → swap-aggregator/kyberswap}/interfaces/IAggregationExecutor.sol +0 -0
  227. package/contracts/router/{kyberswap → swap-aggregator/kyberswap}/interfaces/IExecutorHelperEthereum1.sol +6 -0
  228. package/contracts/router/{kyberswap → swap-aggregator/kyberswap}/interfaces/IHashflow.sol +0 -0
  229. package/contracts/router/{kyberswap → swap-aggregator/kyberswap}/interfaces/IMetaAggregationRouterV2.sol +0 -0
  230. package/deployments/1-core.json +2 -1
  231. package/deployments/1-markets/BALANCER-LP-AURA-WSTETH-WETH-JUN272024.json +2 -1
  232. package/deployments/42161-core.json +26 -0
  233. package/deployments/42161-markets/GLP-28MARCH2024.json +10 -0
  234. package/deployments/42161-offchain-helper.json +4 -0
  235. package/package.json +1 -1
  236. package/typechain-types/ActionAddRemoveLiq.ts +203 -23
  237. package/typechain-types/ActionBaseCallback.ts +115 -0
  238. package/typechain-types/ActionMintRedeem.ts +29 -230
  239. package/typechain-types/ActionMisc.ts +77 -27
  240. package/typechain-types/ActionSwapPT.ts +26 -31
  241. package/typechain-types/ActionSwapYT.ts +202 -21
  242. package/typechain-types/AddressProvider.ts +280 -0
  243. package/typechain-types/GLPPreviewHelper.ts +121 -0
  244. package/typechain-types/GMXPreviewHelper.ts +40 -0
  245. package/typechain-types/IAddressProvider.ts +123 -0
  246. package/typechain-types/IDiamondCut.ts +152 -0
  247. package/typechain-types/IDiamondLoupe.ts +190 -0
  248. package/typechain-types/IExecutorHelperEthereum1.ts +44 -0
  249. package/typechain-types/IPActionAddRemoveLiq.ts +213 -14
  250. package/typechain-types/IPActionMintRedeem.ts +29 -211
  251. package/typechain-types/IPActionMisc.ts +77 -27
  252. package/typechain-types/IPActionSwapPT.ts +26 -12
  253. package/typechain-types/IPActionSwapYT.ts +168 -12
  254. package/typechain-types/IPAllAction.ts +445 -227
  255. package/typechain-types/IPInterestManagerYTV2.ts +117 -0
  256. package/typechain-types/IPMsgReceiverApp.ts +5 -5
  257. package/typechain-types/IPSwapAggregator.ts +126 -0
  258. package/typechain-types/IPYieldTokenV2.ts +9 -23
  259. package/typechain-types/IRewardRouterV2.ts +60 -17
  260. package/typechain-types/InterestManagerYTV2.ts +36 -3
  261. package/typechain-types/PendleGaugeControllerSidechainUpg.ts +4 -4
  262. package/typechain-types/PendleGlpSY.ts +67 -0
  263. package/typechain-types/PendleMsgReceiverAppUpg.ts +5 -5
  264. package/typechain-types/PendleRouter.ts +109 -131
  265. package/typechain-types/PendleSwapAggregator.ts +126 -0
  266. package/typechain-types/PendleYieldTokenV2.ts +70 -76
  267. package/typechain-types/RouterStatic.ts +92 -0
  268. package/typechain-types/VotingEscrowPendleSidechain.ts +4 -5
  269. package/typechain-types/factories/ActionAddRemoveLiq__factory.ts +346 -68
  270. package/typechain-types/factories/ActionBaseCallback__factory.ts +156 -0
  271. package/typechain-types/factories/ActionMintRedeem__factory.ts +108 -266
  272. package/typechain-types/factories/ActionMisc__factory.ts +56 -17
  273. package/typechain-types/factories/ActionSwapPT__factory.ts +55 -71
  274. package/typechain-types/factories/ActionSwapYT__factory.ts +356 -48
  275. package/typechain-types/factories/AddressProvider__factory.ts +196 -0
  276. package/typechain-types/factories/BulkSellerFactory__factory.ts +1 -1
  277. package/typechain-types/factories/BulkSellerOffchain__factory.ts +1 -1
  278. package/typechain-types/factories/BulkSeller__factory.ts +1 -1
  279. package/typechain-types/factories/Errors__factory.ts +49 -1
  280. package/typechain-types/factories/GLPPreviewHelper__factory.ts +65 -0
  281. package/typechain-types/factories/GMXPreviewHelper__factory.ts +26 -0
  282. package/typechain-types/factories/IAddressProvider__factory.ts +63 -0
  283. package/typechain-types/factories/IDiamondCut__factory.ts +105 -0
  284. package/typechain-types/factories/IDiamondLoupe__factory.ts +99 -0
  285. package/typechain-types/factories/IExecutorHelperEthereum1__factory.ts +29 -0
  286. package/typechain-types/factories/IPActionAddRemoveLiq__factory.ts +338 -16
  287. package/typechain-types/factories/IPActionMintRedeem__factory.ts +105 -224
  288. package/typechain-types/factories/IPActionMisc__factory.ts +55 -11
  289. package/typechain-types/factories/IPActionSwapPT__factory.ts +52 -8
  290. package/typechain-types/factories/IPActionSwapYT__factory.ts +231 -8
  291. package/typechain-types/factories/IPAllAction__factory.ts +675 -241
  292. package/typechain-types/factories/IPInterestManagerYTV2__factory.ts +59 -0
  293. package/typechain-types/factories/IPMsgReceiverApp__factory.ts +1 -1
  294. package/typechain-types/factories/IPSwapAggregator__factory.ts +71 -0
  295. package/typechain-types/factories/IPYieldTokenV2__factory.ts +6 -14
  296. package/typechain-types/factories/IRewardRouterV2__factory.ts +43 -7
  297. package/typechain-types/factories/InterestManagerYTV2__factory.ts +18 -0
  298. package/typechain-types/factories/MarketMathStatic__factory.ts +1 -27
  299. package/typechain-types/factories/OracleLib__factory.ts +1 -1
  300. package/typechain-types/factories/PendleAura3EthSY__factory.ts +1 -1
  301. package/typechain-types/factories/PendleAuraCbethWstethSY__factory.ts +1 -1
  302. package/typechain-types/factories/PendleAuraWethRethSY__factory.ts +1 -1
  303. package/typechain-types/factories/PendleAuraWethWstethSY__factory.ts +1 -1
  304. package/typechain-types/factories/PendleCurveFraxUsdcSY__factory.ts +1 -1
  305. package/typechain-types/factories/PendleCurveUsdd3CrvSY__factory.ts +1 -1
  306. package/typechain-types/factories/PendleFeeDistributor__factory.ts +1 -1
  307. package/typechain-types/factories/PendleGaugeControllerMainchainUpg__factory.ts +1 -1
  308. package/typechain-types/factories/PendleGaugeControllerSidechainUpg__factory.ts +2 -2
  309. package/typechain-types/factories/PendleGlpSY__factory.ts +34 -1
  310. package/typechain-types/factories/PendleLooksStakingSY__factory.ts +1 -1
  311. package/typechain-types/factories/PendleMarketFactory__factory.ts +1 -1
  312. package/typechain-types/factories/PendleMarket__factory.ts +1 -1
  313. package/typechain-types/factories/PendleMsgReceiveEndpointUpg__factory.ts +1 -1
  314. package/typechain-types/factories/PendleMsgReceiverAppUpg__factory.ts +1 -1
  315. package/typechain-types/factories/PendleMsgSendEndpointUpg__factory.ts +1 -1
  316. package/typechain-types/factories/PendlePrincipalTokenV2__factory.ts +1 -1
  317. package/typechain-types/factories/PendlePrincipalToken__factory.ts +1 -1
  318. package/typechain-types/factories/PendleQiTokenHelper__factory.ts +1 -1
  319. package/typechain-types/factories/PendleQiTokenSY__factory.ts +1 -1
  320. package/typechain-types/factories/PendleRouter__factory.ts +75 -74
  321. package/typechain-types/factories/PendleSwapAggregator__factory.ts +129 -0
  322. package/typechain-types/factories/PendleVotingControllerUpg__factory.ts +1 -1
  323. package/typechain-types/factories/PendleWstEthSY__factory.ts +1 -1
  324. package/typechain-types/factories/PendleYieldContractFactoryV2__factory.ts +1 -1
  325. package/typechain-types/factories/PendleYieldContractFactory__factory.ts +1 -1
  326. package/typechain-types/factories/PendleYieldTokenV2__factory.ts +35 -48
  327. package/typechain-types/factories/PendleYieldToken__factory.ts +1 -1
  328. package/typechain-types/factories/RouterStatic__factory.ts +69 -1
  329. package/typechain-types/factories/SAPE__factory.ts +1 -1
  330. package/typechain-types/factories/VotingEscrowPendleMainchain__factory.ts +1 -1
  331. package/typechain-types/factories/VotingEscrowPendleSidechain__factory.ts +2 -2
  332. package/typechain-types/hardhat.d.ts +118 -64
  333. package/typechain-types/index.ts +32 -20
  334. package/build/artifacts/contracts/interfaces/IPActionSwapPTYT.sol/IPActionSwapPTYT.dbg.json +0 -4
  335. package/build/artifacts/contracts/interfaces/IPActionSwapPTYT.sol/IPActionSwapPTYT.json +0 -190
  336. package/build/artifacts/contracts/router/ActionCallback.sol/ActionCallback.dbg.json +0 -4
  337. package/build/artifacts/contracts/router/ActionCallback.sol/ActionCallback.json +0 -165
  338. package/build/artifacts/contracts/router/ActionSwapPTYT.sol/ActionSwapPTYT.dbg.json +0 -4
  339. package/build/artifacts/contracts/router/ActionSwapPTYT.sol/ActionSwapPTYT.json +0 -343
  340. package/build/artifacts/contracts/router/kyberswap/AggregationRouterHelper.sol/AggregationRouterHelper.dbg.json +0 -4
  341. package/build/artifacts/contracts/router/kyberswap/AggregationRouterHelper.sol/AggregationRouterHelper.json +0 -224
  342. package/build/artifacts/contracts/router/kyberswap/IAggregatorRouterHelper.sol/IAggregationRouterHelper.dbg.json +0 -4
  343. package/build/artifacts/contracts/router/kyberswap/IAggregatorRouterHelper.sol/IAggregationRouterHelper.json +0 -35
  344. package/build/artifacts/contracts/router/kyberswap/KyberSwapHelper.sol/KyberSwapHelper.dbg.json +0 -4
  345. package/build/artifacts/contracts/router/kyberswap/KyberSwapHelper.sol/KyberSwapHelper.json +0 -24
  346. package/build/artifacts/contracts/router/kyberswap/ScaleDataHelperEthereum1.sol/ScaleDataHelperEthereum1.dbg.json +0 -4
  347. package/build/artifacts/contracts/router/kyberswap/interfaces/IAggregationExecutor.sol/IAggregationExecutor.dbg.json +0 -4
  348. package/build/artifacts/contracts/router/kyberswap/interfaces/IExecutorHelperEthereum1.sol/IExecutorHelperEthereum1.dbg.json +0 -4
  349. package/build/artifacts/contracts/router/kyberswap/interfaces/IHashflow.sol/IHashflow.dbg.json +0 -4
  350. package/build/artifacts/contracts/router/kyberswap/interfaces/IMetaAggregationRouter.sol/IMetaAggregationRouter.dbg.json +0 -4
  351. package/build/artifacts/contracts/router/kyberswap/interfaces/IMetaAggregationRouter.sol/IMetaAggregationRouter.json +0 -183
  352. package/build/artifacts/contracts/router/kyberswap/interfaces/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.dbg.json +0 -4
  353. package/contracts/interfaces/IPActionSwapPTYT.sol +0 -31
  354. package/contracts/router/ActionSwapPTYT.sol +0 -108
  355. package/contracts/router/kyberswap/IAggregatorRouterHelper.sol +0 -10
  356. package/contracts/router/kyberswap/KyberSwapHelper.sol +0 -79
  357. package/contracts/router/kyberswap/interfaces/IMetaAggregationRouter.sol +0 -33
@@ -0,0 +1,142 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.17;
3
+
4
+ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
+ import "../../../../interfaces/GMX/IGMXVault.sol";
6
+ import "../../../../interfaces/GMX/IVaultPriceFeed.sol";
7
+
8
+ abstract contract GLPPreviewHelper {
9
+ // Based on Vault functions
10
+
11
+ IGMXVault public immutable vault;
12
+ address internal immutable usdg;
13
+ uint256 public constant PRICE_PRECISION = 10**30;
14
+ uint256 public constant BASIS_POINTS_DIVISOR = 10000;
15
+
16
+ constructor(address _vaultAddress) {
17
+ vault = IGMXVault(_vaultAddress);
18
+ usdg = vault.usdg();
19
+ }
20
+
21
+ function _buyUSDG(address _token, uint256 tokenAmount) internal view returns (uint256) {
22
+ tokenAmount = __transferIn(_token, tokenAmount);
23
+ assert(tokenAmount > 0);
24
+
25
+ uint256 price = vault.getMinPrice(_token);
26
+
27
+ uint256 usdgAmount = (tokenAmount * price) / PRICE_PRECISION;
28
+ usdgAmount = vault.adjustForDecimals(usdgAmount, _token, usdg);
29
+ require(usdgAmount > 0, "preview buyUSDG: usdgAmount must be > 0");
30
+
31
+ uint256 feeBasisPoints = __getFeeBasisPoints(
32
+ _token,
33
+ usdgAmount,
34
+ 0,
35
+ vault.mintBurnFeeBasisPoints(),
36
+ vault.taxBasisPoints(),
37
+ true
38
+ );
39
+ uint256 amountAfterFees = __collectSwapFees(_token, tokenAmount, feeBasisPoints);
40
+ uint256 mintAmount = (amountAfterFees * price) / PRICE_PRECISION;
41
+ mintAmount = vault.adjustForDecimals(mintAmount, _token, usdg);
42
+
43
+ return mintAmount;
44
+ }
45
+
46
+ function _sellUSDG(address _token, uint256 usdgAmount) internal view returns (uint256) {
47
+ usdgAmount = __transferIn(usdg, usdgAmount);
48
+ assert(usdgAmount > 0);
49
+
50
+ uint256 redemptionAmount = vault.getRedemptionAmount(_token, usdgAmount);
51
+ require(redemptionAmount > 0, "preview sellUSDG: redemptionAmount must be > 0");
52
+
53
+ uint256 feeBasisPoints = __getFeeBasisPoints(
54
+ _token,
55
+ usdgAmount,
56
+ usdgAmount,
57
+ vault.mintBurnFeeBasisPoints(),
58
+ vault.taxBasisPoints(),
59
+ false
60
+ );
61
+ uint256 amountOut = __collectSwapFees(_token, redemptionAmount, feeBasisPoints);
62
+ require(amountOut > 0, "preview sellUSDG: amountOut must be > 0");
63
+
64
+ return amountOut;
65
+ }
66
+
67
+ function __transferIn(address _token, uint256 _amount) private view returns (uint256) {
68
+ uint256 prevBalance = vault.tokenBalances(_token);
69
+ uint256 nextBalance = IERC20(_token).balanceOf(address(vault)) + _amount;
70
+
71
+ return nextBalance - prevBalance;
72
+ }
73
+
74
+ function __collectSwapFees(
75
+ address, /*_token*/
76
+ uint256 _amount,
77
+ uint256 _feeBasisPoints
78
+ ) private pure returns (uint256) {
79
+ uint256 afterFeeAmount = (_amount * (BASIS_POINTS_DIVISOR - _feeBasisPoints)) /
80
+ (BASIS_POINTS_DIVISOR);
81
+ return afterFeeAmount;
82
+ }
83
+
84
+ function __getFeeBasisPoints(
85
+ address _token,
86
+ uint256 _usdgDelta,
87
+ uint256 _burnedUsdg,
88
+ uint256 _feeBasisPoints,
89
+ uint256 _taxBasisPoints,
90
+ bool _increment
91
+ ) private view returns (uint256) {
92
+ if (!vault.hasDynamicFees()) {
93
+ return _feeBasisPoints;
94
+ }
95
+
96
+ uint256 initialAmount = vault.usdgAmounts(_token);
97
+ initialAmount = (initialAmount >= _burnedUsdg) ? initialAmount - _burnedUsdg : 0;
98
+
99
+ uint256 nextAmount = initialAmount + _usdgDelta;
100
+ if (!_increment) {
101
+ nextAmount = _usdgDelta > initialAmount ? 0 : initialAmount - _usdgDelta;
102
+ }
103
+
104
+ uint256 targetAmount = __getTargetUsdgAmount(_token, _burnedUsdg);
105
+ if (targetAmount == 0) {
106
+ return _feeBasisPoints;
107
+ }
108
+
109
+ uint256 initialDiff = initialAmount > targetAmount
110
+ ? initialAmount - targetAmount
111
+ : targetAmount - initialAmount;
112
+ uint256 nextDiff = nextAmount > targetAmount
113
+ ? nextAmount - targetAmount
114
+ : targetAmount - nextAmount;
115
+
116
+ // action improves relative asset balance
117
+ if (nextDiff < initialDiff) {
118
+ uint256 rebateBps = (_taxBasisPoints * initialDiff) / targetAmount;
119
+ return rebateBps > _feeBasisPoints ? 0 : _feeBasisPoints - rebateBps;
120
+ }
121
+
122
+ uint256 averageDiff = (initialDiff + nextDiff) / 2;
123
+ if (averageDiff > targetAmount) {
124
+ averageDiff = targetAmount;
125
+ }
126
+ uint256 taxBps = (_taxBasisPoints * averageDiff) / targetAmount;
127
+ return _feeBasisPoints + taxBps;
128
+ }
129
+
130
+ function __getTargetUsdgAmount(address _token, uint256 _burnedUsdg)
131
+ private
132
+ view
133
+ returns (uint256)
134
+ {
135
+ uint256 supply = IERC20(usdg).totalSupply() - _burnedUsdg;
136
+ if (supply == 0) {
137
+ return 0;
138
+ }
139
+ uint256 weight = vault.tokenWeights(_token);
140
+ return (weight * supply) / vault.totalTokenWeights();
141
+ }
142
+ }
@@ -0,0 +1,222 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.17;
3
+
4
+ import "../../SYBaseWithRewards.sol";
5
+ import "./GLPPreviewHelper.sol";
6
+ import "../../../libraries/ArrayLib.sol";
7
+ import "../../../../interfaces/GMX/IRewardRouterV2.sol";
8
+ import "../../../../interfaces/GMX/IGlpManager.sol";
9
+ import "../../../../interfaces/GMX/IGMXVault.sol";
10
+
11
+ contract PendleGlpSY is SYBaseWithRewards, GLPPreviewHelper {
12
+ using ArrayLib for address[];
13
+
14
+ address public immutable glp;
15
+ address public immutable stakedGlp;
16
+ address public immutable rewardRouter;
17
+ address public immutable glpRouter;
18
+ address public immutable glpManager;
19
+ address public immutable weth;
20
+
21
+ constructor(
22
+ string memory _name,
23
+ string memory _symbol,
24
+ address _glp,
25
+ address _fsGlp,
26
+ address _stakedGlp,
27
+ address _rewardRouter,
28
+ address _glpRouter,
29
+ address _vault
30
+ ) SYBaseWithRewards(_name, _symbol, _fsGlp) GLPPreviewHelper(_vault) {
31
+ glp = _glp;
32
+ stakedGlp = _stakedGlp;
33
+ rewardRouter = _rewardRouter;
34
+ glpRouter = _glpRouter;
35
+ glpManager = IRewardRouterV2(glpRouter).glpManager();
36
+ weth = IRewardRouterV2(glpRouter).weth();
37
+
38
+ approveAllWhitelisted();
39
+ }
40
+
41
+ function approveAllWhitelisted() public {
42
+ uint256 length = vault.allWhitelistedTokensLength();
43
+ for (uint256 i = 0; i < length; ++i) {
44
+ address token = vault.allWhitelistedTokens(i);
45
+ if (vault.whitelistedTokens(token)) {
46
+ _safeApproveInf(token, glpManager);
47
+ }
48
+ }
49
+ }
50
+
51
+ /*///////////////////////////////////////////////////////////////
52
+ DEPOSIT/REDEEM USING BASE TOKENS
53
+ //////////////////////////////////////////////////////////////*/
54
+
55
+ /**
56
+ * @dev See {SYBase-_deposit}
57
+ */
58
+ function _deposit(address tokenIn, uint256 amountDeposited)
59
+ internal
60
+ virtual
61
+ override
62
+ returns (uint256 amountSharesOut)
63
+ {
64
+ if (tokenIn == stakedGlp) {
65
+ // GLP is already staked in stakedGlp's transferFrom, called in _transferIn()
66
+ amountSharesOut = amountDeposited;
67
+ } else if (tokenIn == NATIVE) {
68
+ amountSharesOut = IRewardRouterV2(glpRouter).mintAndStakeGlpETH{ value: msg.value }(
69
+ 0,
70
+ 0
71
+ );
72
+ } else {
73
+ amountSharesOut = IRewardRouterV2(glpRouter).mintAndStakeGlp(
74
+ tokenIn,
75
+ amountDeposited,
76
+ 0,
77
+ 0
78
+ );
79
+ }
80
+ }
81
+
82
+ /**
83
+ * @dev See {SYBase-_redeem}
84
+ */
85
+ function _redeem(
86
+ address receiver,
87
+ address tokenOut,
88
+ uint256 amountSharesToRedeem
89
+ ) internal virtual override returns (uint256 amountTokenOut) {
90
+ if (tokenOut == stakedGlp) {
91
+ amountTokenOut = amountSharesToRedeem;
92
+ _transferOut(tokenOut, receiver, amountTokenOut);
93
+ } else if (tokenOut == NATIVE) {
94
+ amountTokenOut = IRewardRouterV2(glpRouter).unstakeAndRedeemGlpETH(
95
+ amountSharesToRedeem,
96
+ 0,
97
+ payable(receiver)
98
+ );
99
+ } else {
100
+ amountTokenOut = IRewardRouterV2(glpRouter).unstakeAndRedeemGlp(
101
+ tokenOut,
102
+ amountSharesToRedeem,
103
+ 0,
104
+ receiver
105
+ );
106
+ }
107
+ }
108
+
109
+ /*///////////////////////////////////////////////////////////////
110
+ EXCHANGE-RATE
111
+ //////////////////////////////////////////////////////////////*/
112
+
113
+ /**
114
+ * @notice Calculates and updates the exchange rate of shares to underlying asset token
115
+ * @dev 1 SY = 1 GLP
116
+ */
117
+ function exchangeRate() public view virtual override returns (uint256) {
118
+ return Math.ONE;
119
+ }
120
+
121
+ /*///////////////////////////////////////////////////////////////
122
+ REWARDS-RELATED
123
+ //////////////////////////////////////////////////////////////*/
124
+
125
+ /**
126
+ * @dev See {IStandardizedYield-getRewardTokens}
127
+ */
128
+ function _getRewardTokens() internal view override returns (address[] memory res) {
129
+ res = new address[](1);
130
+ res[0] = weth;
131
+ }
132
+
133
+ function _redeemExternalReward() internal override {
134
+ IRewardRouterV2(rewardRouter).handleRewards(false, false, true, true, false, true, false);
135
+ }
136
+
137
+ /*///////////////////////////////////////////////////////////////
138
+ MISC FUNCTIONS FOR METADATA
139
+ //////////////////////////////////////////////////////////////*/
140
+
141
+ function _previewDeposit(address tokenIn, uint256 amountTokenToDeposit)
142
+ internal
143
+ view
144
+ override
145
+ returns (uint256 amountSharesOut)
146
+ {
147
+ if (tokenIn == stakedGlp) amountSharesOut = amountTokenToDeposit;
148
+ else {
149
+ if (tokenIn == NATIVE) tokenIn = weth;
150
+
151
+ // Based on GlpManager's _addLiquidity
152
+ uint256 aumInUsdg = IGlpManager(glpManager).getAumInUsdg(true);
153
+ uint256 glpSupply = IERC20(glp).totalSupply();
154
+ uint256 usdgAmount = super._buyUSDG(tokenIn, amountTokenToDeposit);
155
+
156
+ uint256 mintAmount = aumInUsdg == 0
157
+ ? usdgAmount
158
+ : (usdgAmount * glpSupply) / aumInUsdg;
159
+ amountSharesOut = mintAmount;
160
+ }
161
+ }
162
+
163
+ function _previewRedeem(address tokenOut, uint256 amountSharesToRedeem)
164
+ internal
165
+ view
166
+ override
167
+ returns (uint256 amountTokenOut)
168
+ {
169
+ if (tokenOut == stakedGlp) amountTokenOut = amountSharesToRedeem;
170
+ else {
171
+ if (tokenOut == NATIVE) tokenOut = weth;
172
+
173
+ // Based on GlpManager's _removeLiquidity
174
+ uint256 aumInUsdg = IGlpManager(glpManager).getAumInUsdg(false);
175
+ uint256 glpSupply = IERC20(glp).totalSupply();
176
+
177
+ uint256 usdgAmount = (amountSharesToRedeem * aumInUsdg) / glpSupply;
178
+ uint256 amountOut = super._sellUSDG(tokenOut, usdgAmount);
179
+
180
+ amountTokenOut = amountOut;
181
+ }
182
+ }
183
+
184
+ function _getGlpWhitelistedTokens() internal view returns (address[] memory res) {
185
+ res = new address[](0);
186
+ uint256 length = vault.allWhitelistedTokensLength();
187
+ for(uint256 i = 0; i < length; ++i) {
188
+ address token = vault.allWhitelistedTokens(i);
189
+ if (vault.whitelistedTokens(token) && !res.contains(token)) {
190
+ res = res.append(token);
191
+ }
192
+ }
193
+ }
194
+
195
+ function getTokensIn() public view virtual override returns (address[] memory res) {
196
+ return _getGlpWhitelistedTokens();
197
+ }
198
+
199
+ function getTokensOut() public view virtual override returns (address[] memory res) {
200
+ return _getGlpWhitelistedTokens();
201
+ }
202
+
203
+ function isValidTokenIn(address token) public view virtual override returns (bool) {
204
+ return token == stakedGlp || token == NATIVE || vault.whitelistedTokens(token);
205
+ }
206
+
207
+ function isValidTokenOut(address token) public view virtual override returns (bool) {
208
+ return token == stakedGlp || token == NATIVE || vault.whitelistedTokens(token);
209
+ }
210
+
211
+ function assetInfo()
212
+ external
213
+ view
214
+ returns (
215
+ AssetType assetType,
216
+ address assetAddress,
217
+ uint8 assetDecimals
218
+ )
219
+ {
220
+ return (AssetType.LIQUIDITY, glp, IERC20Metadata(glp).decimals());
221
+ }
222
+ }
@@ -0,0 +1,61 @@
1
+ # Audit note GLP SY
2
+
3
+ Our goal is to support SY for the GLP token of GMX.
4
+
5
+ The SY supports mint-and-staking GLP with a whitelisted token (ETH, WBTC, etc) or receiving staked GLP from user.
6
+
7
+ ## Overview
8
+
9
+ + _The main contract_ for the SY is: `PendleGlpSY.sol`.
10
+ This contract contains the main logic ofk all SY operations, except GMX's Vault-related logic for preview functions. This part is contained in the abstract preview contract, which is inherited by the main contract.
11
+
12
+ - _The preview contract_ is: `GMXPreviewHelper.sol`.
13
+ This contract simulates the logic of GMX's Vault to preview buying/selling USDG during deposit/redeem.
14
+
15
+ ## About PendleGlpSY
16
+
17
+ A typical, ordinary SY contract.
18
+
19
+ - _Constructor_: Initialize global variables and approve whitelisted tokens to GMX's GlpManager, which would pull tokens in from the SY contract when minting GLP.
20
+ - There are two routers: _rewardRouter_ is used for claiming rewards,, _glpRouter_ is used to deposit/redeem; hence the two global router variables.
21
+ - _Deposit_:
22
+ - In case of receiving staked GLP, then staked GLP is already pulled in with _transferIn() in SYBase.
23
+ **Note:** StakedGLP (sGLP) is a helper contract by GMX for users to transfer their staked GLP between each other, where staking and unstaking happen behind the scenes. It is not an ERC20 token, but it behaves similar enough to one so that we treat it is ERC20 in the contract.
24
+ - Otherwise, use GlpRewardRouter to mint and stake.
25
+ - _Redeem_: Same as deposit, reversed. If user redeems in staked GLP, _transferOut() is used for staked GLP.
26
+ - _Exchange rate_: The SY directly wraps GLP, so the exchange rate is always 1.
27
+ - _Preview deposit_: Mimics the logic of _\_addLiquidity()_ in GMX's GlpManager. The functions needs to preview _buyUSDG()_ of GMX's Vault, which is mimicked in GMXPreviewHelper.
28
+ - _Preview redeem_: Mimics the logic of _\_removeLiquidity()_ in GMX's GlpManager. The functions needs to preview _sellUSDG()_ of GMX's Vault, which is also mimicked in GMXPreviewHelper.
29
+ - _Get tokens in/out_: Queries whitelisted tokens from GMX's Vault, then return them along with staked GLP and native ETH.
30
+ - _Check valid token in/out_: Calls _whitelistedTokens()_ from GMX's Vault to check.
31
+
32
+ ## About GMXPreviewHelper
33
+
34
+ This contract's purpose is to support preview for _buyUSDG()_ and _sellUSDG()_ functions from GMX's Vault. The contracts has two view functions _buyUSDG()_ and _sellUSDG()_ which mimics their respective Vault counterpart's logic.
35
+
36
+ About _buyUSDG()_:
37
+ - First, _tokenAmount_ is calculated with _transferIn(), which should give the same as the corresponding Vault function.
38
+ - _updateCumulativeFundingRate()_ in Vault should not impact amount out, so this is ignored.
39
+ - For _price_ and _usdgAmount_, the Vault view functions used in Vault's buyUSDG() should behave the same as during actual redeeming, so they are called directly from Vault.
40
+ - For _feeBasisPoints_, _getFeeBasisPoints()_ also behave the same as Vault, becacuse the extra parameter _\_burnedUsdg_ = 0 which has no affect on the return value.
41
+ - For _amountAfterFees_, see _\_collectSwapFees()_ below.
42
+ - Finally, _mintAmount_ is calculated normally.
43
+
44
+ About _sellUSDG()_:
45
+ - Again, first _usdgAmount_ is calculated.
46
+ - _updateCumulativeFundingRate()_ in Vault should not impact amount out, so this is ignored.
47
+ - We directly call Vault's getRedemptionAmount() to calculate _redemptionAmount_. Although _useSwapPricing_ is set to true earlier in Vault's _sellUSDG()_, and _getRedemptionAmount()_ calls _getMaxPrice()_, which then calls priceFeed's _getPrice()_ with _useSwapPricing_ as a parameter, this parameter is then ignored in _getPrice()_. So we can ignore _useSwapPricing_, and Vault's _getRedemptionAmount()_ called in preview should behave the same as actual redeem.
48
+ - Next, _decreaseUsdgAmount() and USDG's _burn()_ are called. This affects USDG balances, which would later affect _getFeeBasisPoints()_.
49
+ - _poolAmounts_ and _tokenBalances_ should not affect the amount out, so _\_decreasePoolAmount()_ and _\_updateTokenBalance()_ are ignored.
50
+ - For _feeBasisPoints_, we need _getFeeBasisPoints()_. But _usdgAmounts[\_token]_ has been decreased by _usdgAmount_, so we account for this by adding parameter _\_burnedUsdg_ in our "fake" _getFeeBasisPoints()_.
51
+ - Finally, _amountOut_ is calculated with _\_collectSwapFees()_.
52
+
53
+ Other helper functions:
54
+ - _\_transferIn()_: Mimics Vault's counterpart, should return the same value.
55
+ - _\_collectSwapFees()_: In Vault, this function only changes _feeReserves_ which does not affect deposit/redeem, so we only need the _afterFeeAmount_.
56
+ - _getFeeBasisPoints()_: Since USDG balances are affected in _sellUSDG()_, another parameter _\_burnedUsdg_ is introduced to account for this decrease in USDG. Namely, this affects:
57
+ - _initialAmount_: The new _usdgAmount[\_token]_ is different, which is calculated here similar to Vault's decreaseUsdgAmount().
58
+ - _getTargetUsdgAmount()_: The formula for the target amount concerns the total supply of USDG, which is affected by _burn()_ in _sellUSDG()_. This is accounted for in our "fake" _getTargetUsdgAmount()_, which takes _\_burnedUsdg_ as parameter and uses it to calculate the real _supply_.
59
+
60
+ In our tests, all - intermediate and final return - values perfectly matches between Vault's functions and our replicas.
61
+
@@ -0,0 +1,114 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.17;
3
+
4
+ import "../../interfaces/IPYieldToken.sol";
5
+ import "../../interfaces/IPPrincipalToken.sol";
6
+ import "../../interfaces/IPInterestManagerYTV2.sol";
7
+ import "../../interfaces/IPYieldContractFactory.sol";
8
+
9
+ import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
10
+
11
+ import "../libraries/math/Math.sol";
12
+ import "../libraries/TokenHelper.sol";
13
+ import "../StandardizedYield/SYUtils.sol";
14
+
15
+ /*
16
+ With YT yielding more SYs overtime, which is allowed to be redeemed by users, the reward distribution should
17
+ be based on the amount of SYs that their YT currently represent, plus with their dueInterest.
18
+
19
+ It has been proven and tested that totalSyRedeemable will not change over time, unless users redeem their interest or redeemPY.
20
+
21
+ Due to this, it is required to update users' accruedReward STRICTLY BEFORE redeeming their interest.
22
+ */
23
+ abstract contract InterestManagerYTV2 is TokenHelper, IPInterestManagerYTV2 {
24
+ using Math for uint256;
25
+
26
+ struct UserInterest {
27
+ uint128 index;
28
+ uint128 accrued;
29
+ uint256 pyIndex;
30
+ }
31
+
32
+ uint256 public lastInterestBlock;
33
+
34
+ uint256 public globalInterestIndex;
35
+
36
+ mapping(address => UserInterest) public userInterest;
37
+
38
+ uint256 internal constant INITIAL_INTEREST_INDEX = 1;
39
+
40
+ function _updateAndDistributeInterest(address user) internal virtual {
41
+ _updateAndDistributeInterestForTwo(user, address(0));
42
+ }
43
+
44
+ function _updateAndDistributeInterestForTwo(address user1, address user2) internal virtual {
45
+ (uint256 index, uint256 pyIndex) = _updateInterestIndex();
46
+
47
+ if (user1 != address(0) && user1 != address(this))
48
+ _distributeInterestPrivate(user1, index, pyIndex);
49
+ if (user2 != address(0) && user2 != address(this))
50
+ _distributeInterestPrivate(user2, index, pyIndex);
51
+ }
52
+
53
+ function _doTransferOutInterest(address user, address SY)
54
+ internal
55
+ returns (uint256 interestAmount)
56
+ {
57
+ interestAmount = userInterest[user].accrued;
58
+ userInterest[user].accrued = 0;
59
+ _transferOut(SY, user, interestAmount);
60
+ }
61
+
62
+ // should only be callable from `_distributeInterestForTwo` & make sure user != address(0) && user != address(this)
63
+ function _distributeInterestPrivate(
64
+ address user,
65
+ uint256 currentIndex,
66
+ uint256 pyIndex
67
+ ) private {
68
+ assert(user != address(0) && user != address(this));
69
+
70
+ uint256 prevIndex = userInterest[user].index;
71
+ // uint256 interestFeeRate = _getInterestFeeRate();
72
+
73
+ if (prevIndex == currentIndex) return;
74
+
75
+ if (prevIndex == 0) {
76
+ userInterest[user].index = currentIndex.Uint128();
77
+ userInterest[user].pyIndex = pyIndex;
78
+ return;
79
+ }
80
+
81
+ userInterest[user].accrued += _YTbalance(user).mulDown(currentIndex - prevIndex).Uint128();
82
+ userInterest[user].index = currentIndex.Uint128();
83
+ userInterest[user].pyIndex = pyIndex;
84
+ }
85
+
86
+ function _updateInterestIndex() internal returns (uint256 index, uint256 pyIndex) {
87
+ if (lastInterestBlock != block.number) {
88
+ // if we have not yet update the index for this block
89
+ lastInterestBlock = block.number;
90
+
91
+ uint256 totalShares = _YTSupply();
92
+ uint256 accrued;
93
+
94
+ (accrued, pyIndex) = _collectInterest();
95
+ index = globalInterestIndex;
96
+
97
+ if (index == 0) index = INITIAL_INTEREST_INDEX;
98
+ if (totalShares != 0) index += accrued.divDown(totalShares);
99
+
100
+ globalInterestIndex = index;
101
+ } else {
102
+ index = globalInterestIndex;
103
+ pyIndex = _getGlobalPYIndex();
104
+ }
105
+ }
106
+
107
+ function _getGlobalPYIndex() internal view virtual returns (uint256);
108
+
109
+ function _collectInterest() internal virtual returns (uint256, uint256);
110
+
111
+ function _YTbalance(address user) internal view virtual returns (uint256);
112
+
113
+ function _YTSupply() internal view virtual returns (uint256);
114
+ }
@@ -0,0 +1,63 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.17;
3
+
4
+ import "../../interfaces/IPPrincipalToken.sol";
5
+ import "../../interfaces/IPYieldToken.sol";
6
+
7
+ import "../libraries/MiniHelpers.sol";
8
+ import "../libraries/Errors.sol";
9
+
10
+ import "../erc20/PendleERC20Permit.sol";
11
+
12
+ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
13
+
14
+ contract PendlePrincipalTokenV2 is PendleERC20Permit, Initializable, IPPrincipalToken {
15
+ address public immutable SY;
16
+ address public immutable factory;
17
+ uint256 public immutable expiry;
18
+ address public YT;
19
+
20
+ modifier onlyYT() {
21
+ if (msg.sender != YT) revert Errors.OnlyYT();
22
+ _;
23
+ }
24
+
25
+ modifier onlyYieldFactory() {
26
+ if (msg.sender != factory) revert Errors.OnlyYCFactory();
27
+ _;
28
+ }
29
+
30
+ constructor(
31
+ address _SY,
32
+ string memory _name,
33
+ string memory _symbol,
34
+ uint8 __decimals,
35
+ uint256 _expiry
36
+ ) PendleERC20Permit(_name, _symbol, __decimals) {
37
+ SY = _SY;
38
+ expiry = _expiry;
39
+ factory = msg.sender;
40
+ }
41
+
42
+ function initialize(address _YT) external initializer onlyYieldFactory {
43
+ YT = _YT;
44
+ }
45
+
46
+ /**
47
+ * @dev only callable by the YT correspond to this PT
48
+ */
49
+ function burnByYT(address user, uint256 amount) external onlyYT {
50
+ _burn(user, amount);
51
+ }
52
+
53
+ /**
54
+ * @dev only callable by the YT correspond to this PT
55
+ */
56
+ function mintByYT(address user, uint256 amount) external onlyYT {
57
+ _mint(user, amount);
58
+ }
59
+
60
+ function isExpired() public view returns (bool) {
61
+ return MiniHelpers.isCurrentlyExpired(expiry);
62
+ }
63
+ }