@pendle/core-v2 3.0.0-beta-11 → 3.0.0-beta-12

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 (316) hide show
  1. package/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiveEndpointUpg.sol +5 -23
  2. package/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiverAppUpg.sol +2 -5
  3. package/contracts/LiquidityMining/CrossChainMsg/PendleMsgSendEndpointUpg.sol +6 -20
  4. package/contracts/LiquidityMining/CrossChainMsg/PendleMsgSenderAppUpg.sol +6 -27
  5. package/contracts/LiquidityMining/CrossChainMsg/libraries/ExcessivelySafeCall.sol +1 -2
  6. package/contracts/LiquidityMining/CrossChainMsg/libraries/LayerZeroHelper.sol +1 -1
  7. package/contracts/LiquidityMining/GaugeController/PendleGaugeControllerBaseUpg.sol +16 -17
  8. package/contracts/LiquidityMining/GaugeController/PendleGaugeControllerMainchainUpg.sol +6 -7
  9. package/contracts/LiquidityMining/GaugeController/PendleGaugeControllerSidechainUpg.sol +7 -8
  10. package/contracts/LiquidityMining/PendleMerkleDistributor.sol +2 -11
  11. package/contracts/LiquidityMining/VeDistributor/PendleFeeDistributor.sol +14 -37
  12. package/contracts/LiquidityMining/VeDistributor/PendleFeeDistributorV2.sol +19 -34
  13. package/contracts/LiquidityMining/VotingController/PendleVotingControllerUpg.sol +4 -14
  14. package/contracts/LiquidityMining/VotingController/VotingControllerStorageUpg.sol +4 -16
  15. package/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleMainchain.sol +11 -39
  16. package/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleSidechain.sol +3 -10
  17. package/contracts/LiquidityMining/VotingEscrow/VotingEscrowTokenBase.sol +1 -1
  18. package/contracts/LiquidityMining/libraries/VeBalanceLib.sol +5 -20
  19. package/contracts/LiquidityMining/libraries/VeHistoryLib.sol +1 -3
  20. package/contracts/core/Market/MarketMathCore.sol +12 -37
  21. package/contracts/core/Market/OracleLib.sol +6 -24
  22. package/contracts/core/Market/PendleExternalRewardDistributor.sol +4 -10
  23. package/contracts/core/Market/PendleGauge.sol +3 -9
  24. package/contracts/core/Market/PendleMarket.sol +14 -39
  25. package/contracts/core/Market/PendleMarketFactory.sol +14 -21
  26. package/contracts/core/Market/v2/PendleGaugeV2.sol +8 -24
  27. package/contracts/core/Market/v2/PendleMarketFactoryV2.sol +7 -27
  28. package/contracts/core/Market/v2/PendleMarketV2.sol +13 -36
  29. package/contracts/core/Market/v3/PendleMarketFactoryV3.sol +137 -0
  30. package/contracts/core/Market/v3/PendleMarketV3.sol +360 -0
  31. package/contracts/core/RewardManager/PendleLinearDistributor.sol +143 -0
  32. package/contracts/core/RewardManager/RewardManager.sol +14 -7
  33. package/contracts/core/RewardManager/RewardManagerAbstract.sol +5 -17
  34. package/contracts/core/StandardizedYield/SYBase.sol +10 -40
  35. package/contracts/core/StandardizedYield/SYBaseUpg.sol +197 -0
  36. package/contracts/core/StandardizedYield/SYBaseWithRewards.sol +9 -41
  37. package/contracts/core/StandardizedYield/SYBaseWithRewardsUpg.sol +88 -0
  38. package/contracts/core/StandardizedYield/SYUtils.sol +1 -4
  39. package/contracts/core/StandardizedYield/StEthHelper.sol +3 -9
  40. package/contracts/core/StandardizedYield/implementations/AaveV3/PendleAaveV3SY.sol +94 -0
  41. package/contracts/core/StandardizedYield/implementations/AaveV3/libraries/AaveAdapterLib.sol +19 -0
  42. package/contracts/core/StandardizedYield/implementations/AaveV3/libraries/WadRayMath.sol +126 -0
  43. package/contracts/core/StandardizedYield/implementations/Ankr/PendleAnkrBNBSY.sol +4 -12
  44. package/contracts/core/StandardizedYield/implementations/Ape/sAPE.sol +5 -19
  45. package/contracts/core/StandardizedYield/implementations/BalancerStable/AuraEthxBbAWethSY.sol +4 -14
  46. package/contracts/core/StandardizedYield/implementations/BalancerStable/AuraSwEthBbAWethSYV2.sol +4 -14
  47. package/contracts/core/StandardizedYield/implementations/BalancerStable/{PendleAuraWethVethSY.sol → AuraWethVethSYUpg.sol} +13 -20
  48. package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraBbAWethSwethSY.sol +3 -7
  49. package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethAnkrethSYV2.sol +12 -29
  50. package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethRocketEthSYV2.sol +12 -29
  51. package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethStafiEthSY.sol +12 -29
  52. package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethWstethSYV2.sol +14 -39
  53. package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWstethAnkreth.sol +7 -28
  54. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStableMath.sol +13 -30
  55. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStablePreviewProxy.sol +1 -1
  56. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStablePreviewV4.sol +50 -153
  57. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStablePreviewV5.sol +50 -157
  58. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/BbAPoolHelper.sol +4 -16
  59. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/LinearMath.sol +6 -25
  60. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/LinearPreview.sol +36 -34
  61. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/MetaStable/MetaStableMath.sol +4 -13
  62. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/MetaStable/MetaStablePreview.sol +20 -58
  63. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/PendleAuraBalancerStableLPSYV2.sol +28 -79
  64. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/PendleAuraBalancerStableLPSYV3Upg.sol +310 -0
  65. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/StablePoolUserData.sol +1 -3
  66. package/contracts/core/StandardizedYield/implementations/BalancerStable/base/StablePreviewBase.sol +2 -6
  67. package/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenHelper.sol +5 -13
  68. package/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenSY.sol +9 -29
  69. package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotRewardHelper.sol +2 -8
  70. package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatileCommon.sol +1 -5
  71. package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatileLpHelper.sol +8 -19
  72. package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatilePreview.sol +7 -25
  73. package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/PendleCamelotV1VolatileSY.sol +8 -27
  74. package/contracts/core/StandardizedYield/implementations/ChainlinkRelayer/PendleChainlinkReceiver.sol +2 -2
  75. package/contracts/core/StandardizedYield/implementations/ChainlinkRelayer/PendleChainlinkRelayer.sol +4 -9
  76. package/contracts/core/StandardizedYield/implementations/Convex/PendleCurveFraxUsdcSY.sol +3 -15
  77. package/contracts/core/StandardizedYield/implementations/Convex/PendleCurveUsdd3CrvSY.sol +5 -23
  78. package/contracts/core/StandardizedYield/implementations/Convex/base/Curve3CrvPoolHelper.sol +10 -40
  79. package/contracts/core/StandardizedYield/implementations/Convex/base/CurveFraxUsdcPoolHelper.sol +2 -8
  80. package/contracts/core/StandardizedYield/implementations/Convex/base/CurveUsdd3CrvPoolHelper.sol +2 -7
  81. package/contracts/core/StandardizedYield/implementations/Convex/base/PendleConvexLPSY.sol +5 -20
  82. package/contracts/core/StandardizedYield/implementations/Flux/FluxTokenLib.sol +6 -4
  83. package/contracts/core/StandardizedYield/implementations/Flux/PendleFluxLendingSY.sol +3 -11
  84. package/contracts/core/StandardizedYield/implementations/GLP/GLPPreviewHelper.sol +3 -9
  85. package/contracts/core/StandardizedYield/implementations/GLP/GMTokenPricingHelper.sol +115 -0
  86. package/contracts/core/StandardizedYield/implementations/GLP/PendleGMV2TokenSY.sol +134 -0
  87. package/contracts/core/StandardizedYield/implementations/GLP/PendleGlpSY.sol +5 -19
  88. package/contracts/core/StandardizedYield/implementations/HMX/HLPPricingHelper.sol +3 -4
  89. package/contracts/core/StandardizedYield/implementations/HMX/PendleHlpSY.sol +18 -25
  90. package/contracts/core/StandardizedYield/implementations/Kyber/KyberMathHelper.sol +425 -0
  91. package/contracts/core/StandardizedYield/implementations/Kyber/KyberNftManagerBaseUpg.sol +438 -0
  92. package/contracts/core/StandardizedYield/implementations/Kyber/PendleKyberElasticSYUpg.sol +155 -0
  93. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/FullMath.sol +123 -0
  94. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/LiqDeltaMath.sol +17 -0
  95. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/LiquidityMath.sol +74 -0
  96. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/MathConstants.sol +19 -0
  97. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/QtyDeltaMath.sol +103 -0
  98. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/QuadMath.sol +31 -0
  99. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/ReinvestmentMath.sol +26 -0
  100. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/SafeCast.sol +73 -0
  101. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/SwapMath.sol +272 -0
  102. package/contracts/core/StandardizedYield/implementations/Kyber/libraries/TickMath.sol +223 -0
  103. package/contracts/core/StandardizedYield/implementations/MUX/MlpPricingHelper.sol +26 -0
  104. package/contracts/core/StandardizedYield/implementations/MUX/PendleMlpSY.sol +195 -0
  105. package/contracts/core/StandardizedYield/implementations/MantleStakedEth/PendleMantleStakedEthSY.sol +12 -41
  106. package/contracts/core/StandardizedYield/implementations/MantleStakedEth/PendleOracleForSyProxy.sol +1 -1
  107. package/contracts/core/StandardizedYield/implementations/PendleArbitrumStakedEthSY.sol +13 -42
  108. package/contracts/core/StandardizedYield/implementations/PendleBridgedLSDSY.sol +4 -11
  109. package/contracts/core/StandardizedYield/implementations/PendleERC4626SY.sol +4 -16
  110. package/contracts/core/StandardizedYield/implementations/PendleEUSDSY.sol +3 -11
  111. package/contracts/core/StandardizedYield/implementations/PendleGdaiSY.sol +3 -11
  112. package/contracts/core/StandardizedYield/implementations/PendleLooksStakingSY.sol +5 -18
  113. package/contracts/core/StandardizedYield/implementations/PendleSfrxEthSY.sol +3 -7
  114. package/contracts/core/StandardizedYield/implementations/PendleStargateLPSY.sol +5 -18
  115. package/contracts/core/StandardizedYield/implementations/PendleWbEthSY.sol +3 -10
  116. package/contracts/core/StandardizedYield/implementations/PendleWstEthSY.sol +4 -12
  117. package/contracts/core/StandardizedYield/implementations/Silo/PendleSiloWithIncentiveSY.sol +157 -0
  118. package/contracts/core/StandardizedYield/implementations/Stader/PendleETHXSY.sol +4 -12
  119. package/contracts/core/StandardizedYield/implementations/Swell/PendleSwETH.sol +4 -12
  120. package/contracts/core/StandardizedYield/implementations/Thena/PendleThenaSY.sol +9 -29
  121. package/contracts/core/StandardizedYield/implementations/Thena/ThenaLpHelper.sol +3 -10
  122. package/contracts/core/StandardizedYield/implementations/Thena/ThenaMath.sol +9 -30
  123. package/contracts/core/StandardizedYield/implementations/Thena/ThenaPreview.sol +10 -40
  124. package/contracts/core/YieldContracts/InterestManagerYT.sol +6 -8
  125. package/contracts/core/YieldContracts/PendlePrincipalToken.sol +1 -1
  126. package/contracts/core/YieldContracts/PendleYieldContractFactory.sol +2 -3
  127. package/contracts/core/YieldContracts/PendleYieldToken.sol +17 -44
  128. package/contracts/core/YieldContractsV2/InterestManagerYTV2.sol +5 -14
  129. package/contracts/core/YieldContractsV2/PendlePrincipalTokenV2.sol +1 -1
  130. package/contracts/core/YieldContractsV2/PendleYieldContractFactoryV2.sol +2 -3
  131. package/contracts/core/YieldContractsV2/PendleYieldTokenV2.sol +13 -48
  132. package/contracts/core/erc20/PendleERC20.sol +2 -8
  133. package/contracts/core/erc20/PendleERC20Permit.sol +2 -6
  134. package/contracts/core/erc20/PendleERC20PermitUpg.sol +82 -0
  135. package/contracts/core/erc20/PendleERC20Upg.sol +334 -0
  136. package/contracts/core/libraries/ArrayLib.sol +7 -8
  137. package/contracts/core/libraries/BaseSplitCodeFactory.sol +1 -6
  138. package/contracts/core/libraries/Errors.sol +19 -1
  139. package/contracts/core/libraries/ExpiryUtilsLib.sol +3 -26
  140. package/contracts/core/libraries/StringLib.sol +5 -21
  141. package/contracts/core/libraries/TokenHelper.sol +3 -3
  142. package/contracts/core/libraries/math/LogExpMath.sol +1 -4
  143. package/contracts/core/libraries/math/PMath.sol +13 -15
  144. package/contracts/interfaces/AaveV3/IAaveV3AToken.sol +15 -0
  145. package/contracts/interfaces/AaveV3/IAaveV3Pool.sol +11 -0
  146. package/contracts/interfaces/Balancer/IComposableStable.sol +3 -4
  147. package/contracts/interfaces/Balancer/IERC4626LinearPool.sol +2 -10
  148. package/contracts/interfaces/Balancer/IMetaStablePool.sol +3 -11
  149. package/contracts/interfaces/Balancer/IVault.sol +3 -8
  150. package/contracts/interfaces/BinanceEth/IWBETH.sol +1 -1
  151. package/contracts/interfaces/Camelot/ICamelotNFTFactory.sol +1 -3
  152. package/contracts/interfaces/Camelot/ICamelotNFTHandler.sol +2 -10
  153. package/contracts/interfaces/Camelot/ICamelotNitroPool.sol +0 -1
  154. package/contracts/interfaces/Camelot/ICamelotNitroPoolFactory.sol +3 -12
  155. package/contracts/interfaces/Camelot/ICamelotPair.sol +5 -25
  156. package/contracts/interfaces/Camelot/ICamelotRouter.sol +1 -5
  157. package/contracts/interfaces/Camelot/IXGrail.sol +3 -11
  158. package/contracts/interfaces/ConvexCurve/IBooster.sol +1 -3
  159. package/contracts/interfaces/Curve/ICrvPool.sol +3 -12
  160. package/contracts/interfaces/Curve/ITriCrvPool.sol +2 -9
  161. package/contracts/interfaces/Flux/IFluxErc20.sol +1 -1
  162. package/contracts/interfaces/Flux/IFluxInterestRateModel.sol +1 -5
  163. package/contracts/interfaces/GMX/IGMXPriceHelper.sol +6 -0
  164. package/contracts/interfaces/GMX/IGMXVault.sol +2 -9
  165. package/contracts/interfaces/GMX/IRewardRouterV2.sol +1 -4
  166. package/contracts/interfaces/HMX/IHLPStaking.sol +1 -1
  167. package/contracts/interfaces/HMX/IHMXCalculator.sol +1 -1
  168. package/contracts/interfaces/HMX/IHMXCompounder.sol +1 -1
  169. package/contracts/interfaces/HMX/IHMXStaking.sol +1 -1
  170. package/contracts/interfaces/HMX/IHMXVester.sol +1 -1
  171. package/contracts/interfaces/IApeStaking.sol +3 -9
  172. package/contracts/interfaces/IBenQiInterestRateModel.sol +1 -5
  173. package/contracts/interfaces/IDiamondCut.sol +1 -5
  174. package/contracts/interfaces/IDiamondLoupe.sol +1 -3
  175. package/contracts/interfaces/ILayerZeroReceiver.sol +1 -6
  176. package/contracts/interfaces/IPActionAddRemoveLiqV3.sol +10 -2
  177. package/contracts/interfaces/IPActionInfoStatic.sol +4 -7
  178. package/contracts/interfaces/IPActionMarketAuxStatic.sol +5 -9
  179. package/contracts/interfaces/IPActionMarketCoreStatic.sol +118 -58
  180. package/contracts/interfaces/IPActionMintRedeemStatic.sol +38 -21
  181. package/contracts/interfaces/IPActionMiscV3.sol +51 -26
  182. package/contracts/interfaces/IPActionStorageStatic.sol +5 -1
  183. package/contracts/interfaces/IPAllActionTypeV3.sol +1 -0
  184. package/contracts/interfaces/IPBulkSeller.sol +49 -0
  185. package/contracts/interfaces/IPBulkSellerFactory.sol +12 -0
  186. package/contracts/interfaces/IPBulkSellerSYCallback.sol +6 -0
  187. package/contracts/interfaces/IPFeeDistributor.sol +1 -3
  188. package/contracts/interfaces/IPFeeDistributorV2.sol +8 -7
  189. package/contracts/interfaces/IPGaugeController.sol +2 -8
  190. package/contracts/interfaces/IPGaugeControllerMainchain.sol +1 -5
  191. package/contracts/interfaces/IPInterestManagerYT.sol +3 -3
  192. package/contracts/interfaces/IPInterestManagerYTV2.sol +1 -4
  193. package/contracts/interfaces/IPLimitRouter.sol +24 -19
  194. package/contracts/interfaces/IPLinearDistributor.sol +21 -0
  195. package/contracts/interfaces/IPMarket.sol +4 -17
  196. package/contracts/interfaces/IPMarketFactory.sol +2 -13
  197. package/contracts/interfaces/IPMarketFactoryV3.sol +24 -0
  198. package/contracts/interfaces/IPMarketV3.sol +8 -0
  199. package/contracts/interfaces/IPOffchainStorage.sol +11 -0
  200. package/contracts/interfaces/IPPriceFeed.sol +6 -0
  201. package/contracts/interfaces/IPPtOracle.sol +2 -9
  202. package/contracts/interfaces/IPRouterHelper.sol +11 -7
  203. package/contracts/interfaces/IPRouterStatic.sol +1 -3
  204. package/contracts/interfaces/IPVotingController.sol +7 -19
  205. package/contracts/interfaces/IPVotingEscrowMainchain.sol +2 -8
  206. package/contracts/interfaces/IPYieldToken.sol +2 -8
  207. package/contracts/interfaces/IPYieldTokenV2.sol +1 -6
  208. package/contracts/interfaces/IPendlePreviewHelper.sol +2 -8
  209. package/contracts/interfaces/IRewardManager.sol +1 -4
  210. package/contracts/interfaces/IStETH.sol +1 -4
  211. package/contracts/interfaces/IStandardizedYield.sol +9 -16
  212. package/contracts/interfaces/IStargateLP.sol +0 -3
  213. package/contracts/interfaces/IStargateRouter.sol +1 -5
  214. package/contracts/interfaces/Kyber/IKyberElasticFactory.sol +157 -0
  215. package/contracts/interfaces/Kyber/IKyberElasticPool.sol +101 -0
  216. package/contracts/interfaces/Kyber/IKyberElasticRouter.sol +98 -0
  217. package/contracts/interfaces/Kyber/IKyberLiquidityMining.sol +209 -0
  218. package/contracts/interfaces/Kyber/IKyberMathHelper.sol +28 -0
  219. package/contracts/interfaces/Kyber/IKyberPositionManager.sol +179 -0
  220. package/contracts/interfaces/Lybra/IEUSD.sol +1 -1
  221. package/contracts/interfaces/MUX/IMUXRewardRouter.sol +139 -0
  222. package/contracts/interfaces/Silo/ISilo.sol +298 -0
  223. package/contracts/interfaces/Silo/ISiloIncentiveController.sol +16 -0
  224. package/contracts/interfaces/Silo/ISiloLens.sol +6 -0
  225. package/contracts/interfaces/Stader/IStaderStakeManager.sol +2 -2
  226. package/contracts/interfaces/Thena/IThenaFactory.sol +1 -5
  227. package/contracts/interfaces/Thena/IThenaGaugeV2.sol +1 -2
  228. package/contracts/interfaces/Thena/IThenaPair.sol +3 -5
  229. package/contracts/limit/LimitMathCore.sol +69 -60
  230. package/contracts/limit/{PendleOrderMixin.sol → LimitRouterBase.sol} +96 -79
  231. package/contracts/limit/PendleLimitRouter.sol +9 -13
  232. package/contracts/offchain-helpers/AutomateReady.sol +17 -32
  233. package/contracts/offchain-helpers/BaseSplitCodeFactoryContract.sol +6 -3
  234. package/contracts/offchain-helpers/BoringLpSeller.sol +4 -17
  235. package/contracts/offchain-helpers/BoringPtSeller.sol +2 -7
  236. package/contracts/offchain-helpers/Broadcaster.sol +1 -1
  237. package/contracts/offchain-helpers/BytesLib.sol +26 -14
  238. package/contracts/offchain-helpers/EmptyUUPS.sol +0 -1
  239. package/contracts/offchain-helpers/LegacyNFTHelper.sol +4 -23
  240. package/contracts/offchain-helpers/LimitBackendHelper.sol +25 -16
  241. package/contracts/offchain-helpers/MarketExchangeRateLib.sol +2 -13
  242. package/contracts/offchain-helpers/Multicall2.sol +2 -7
  243. package/contracts/offchain-helpers/PendleMulticallV1.sol +7 -7
  244. package/contracts/offchain-helpers/PendleMulticallV2.sol +12 -13
  245. package/contracts/offchain-helpers/PendleOffchainStorage.sol +59 -0
  246. package/contracts/offchain-helpers/SimulateHelper.sol +6 -7
  247. package/contracts/offchain-helpers/errors/SDKErrorsDirectory.sol +15 -1
  248. package/contracts/oracles/PendleLpOracleLib.sol +9 -10
  249. package/contracts/oracles/PendlePtOracle.sol +8 -19
  250. package/contracts/oracles/PendlePtOracleLib.sol +8 -13
  251. package/contracts/oracles/samples/PendleLpGlpOracle.sol +6 -10
  252. package/contracts/oracles/samples/PendlePtGlpOracle.sol +6 -10
  253. package/contracts/oracles/samples/PendlePtUsdChainlinkOracle.sol +8 -15
  254. package/contracts/router/ActionAddRemoveLiqV3.sol +147 -52
  255. package/contracts/router/ActionCallbackV3.sol +11 -4
  256. package/contracts/router/ActionMiscV3.sol +43 -33
  257. package/contracts/router/ActionSwapPTV3.sol +18 -6
  258. package/contracts/router/ActionSwapYTV3.sol +42 -14
  259. package/contracts/router/PendleRouterHelper.sol +72 -40
  260. package/contracts/router/PendleRouterV3.sol +50 -50
  261. package/contracts/router/base/ActionBase.sol +86 -43
  262. package/contracts/router/base/CallbackHelper.sol +18 -20
  263. package/contracts/router/base/MarketApproxLib.sol +36 -32
  264. package/contracts/router/swap-aggregator/PendleSwap.sol +31 -7
  265. package/contracts/router/swap-aggregator/kyberswap/interfaces/IAggregationExecutorOptimistic.sol +63 -0
  266. package/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelper.sol +314 -0
  267. package/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelperL2.sol +560 -0
  268. package/contracts/router/swap-aggregator/kyberswap/{IMetaAggregationRouterV2.sol → interfaces/IMetaAggregationRouterV2.sol} +11 -6
  269. package/contracts/router/swap-aggregator/kyberswap/{KyberInputScalingHelper.sol → l1-contracts/InputScalingHelper.sol} +70 -19
  270. package/contracts/router/swap-aggregator/kyberswap/{ScalingDataLib.sol → l1-contracts/ScalingDataLib.sol} +111 -53
  271. package/contracts/router/swap-aggregator/kyberswap/l2-contracts/BytesHelper.sol +29 -0
  272. package/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataReader.sol +149 -0
  273. package/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataWriter.sol +118 -0
  274. package/contracts/router/swap-aggregator/kyberswap/l2-contracts/Common.sol +42 -0
  275. package/contracts/router/swap-aggregator/kyberswap/l2-contracts/DexScaler.sol +382 -0
  276. package/contracts/router/swap-aggregator/kyberswap/l2-contracts/ExecutorReader.sol +61 -0
  277. package/contracts/router/swap-aggregator/kyberswap/l2-contracts/InputScalingHelperL2.sol +329 -0
  278. package/contracts/router/swap-aggregator/kyberswap/l2-contracts/ScalingDataL2Lib.sol +173 -0
  279. package/contracts/router/swap-aggregator/oneinch/I1inchAggregationRouterV5.sol +4 -10
  280. package/contracts/router/swap-aggregator/oneinch/OneInchAggregationRouterHelper.sol +20 -14
  281. package/deployments/1-core.json +5 -2
  282. package/deployments/1-markets/EPENDLE-SEP2024.json +12 -0
  283. package/deployments/1-markets/SFRAX-MARCH2024.json +10 -0
  284. package/deployments/1-markets/SILO-CRVUSD-MARCH2024.json +10 -0
  285. package/deployments/10-core.json +6 -3
  286. package/deployments/42161-core.json +5 -2
  287. package/deployments/42161-markets/AAVE-USDC-JUNE2024.json +11 -0
  288. package/deployments/42161-markets/ARBSILO-USDC-FEB2024.json +10 -0
  289. package/deployments/42161-markets/GM-ARB-USDC-MARCH2024.json +10 -0
  290. package/deployments/42161-markets/KYBER-AXLWSTETH-WSTETH-MARCH2024.json +10 -0
  291. package/deployments/42161-markets/MLP-MARCH2024.json +10 -0
  292. package/deployments/42161-markets/WSTETH-ARBITRUM-MARCH2024.json +11 -0
  293. package/deployments/42161-markets/WSTETHSILO-ETH-MARCH2024.json +11 -0
  294. package/deployments/56-core.json +5 -2
  295. package/deployments/merkle-distribution/2023-10-26.json +7300 -0
  296. package/deployments/merkle-distribution/2023-11-30.json +7730 -0
  297. package/package.json +8 -8
  298. package/contracts/limit/helpers/ArgumentsDecoder.sol +0 -47
  299. package/contracts/limit/helpers/Permitable.sol +0 -48
  300. package/contracts/limit/helpers/RevertReasonParser.sol +0 -75
  301. package/contracts/offchain-helpers/ChainlinkRelayerGelato.sol +0 -37
  302. package/contracts/offchain-helpers/PtAndLpToAsset.sol +0 -62
  303. package/contracts/offchain-helpers/router-static/PendleRouterStatic.sol +0 -19
  304. package/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol +0 -112
  305. package/contracts/offchain-helpers/router-static/base/ActionLimitOrdersStatic.sol +0 -145
  306. package/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol +0 -171
  307. package/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol +0 -582
  308. package/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol +0 -116
  309. package/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol +0 -64
  310. package/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol +0 -53
  311. package/contracts/offchain-helpers/router-static/base/StorageLayout.sol +0 -18
  312. package/contracts/router/swap-aggregator/kyberswap/IExecutorHelper.sol +0 -231
  313. package/deployments/1-markets/BALANCER-LP-AURA-VETH-WETH-SEP2024.json +0 -8
  314. /package/contracts/router/swap-aggregator/kyberswap/{IAggregationExecutor.sol → interfaces/IAggregationExecutor.sol} +0 -0
  315. /package/deployments/1-markets/{BALANCER-LP-AURA-BBAWETHSWETH-SEP-26-2024.json → deprecated/BALANCER-LP-AURA-BBAWETHSWETH-SEP-26-2024.json} +0 -0
  316. /package/deployments/1-markets/{BALANCER-LP-AURA-ETHX-BBAWETH-SEP-26-2024.json → deprecated/BALANCER-LP-AURA-ETHX-BBAWETH-SEP-26-2024.json} +0 -0
@@ -1,5 +1,5 @@
1
1
  // SPDX-License-Identifier: GPL-3.0-or-later
2
- pragma solidity 0.8.17;
2
+ pragma solidity ^0.8.17;
3
3
 
4
4
  import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
5
5
  import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
@@ -123,19 +123,10 @@ contract MetaStablePreview is StablePreviewBase, BoringOwnableUpgradeable, UUPSU
123
123
  ) internal view returns (uint256, uint256[] memory, uint256[] memory) {
124
124
  // skip _updateOracle
125
125
 
126
- uint256[] memory dueProtocolFeeAmounts = _getDueProtocolFeeAmounts(
127
- balances,
128
- protocolSwapFeePercentage,
129
- imd
130
- );
126
+ uint256[] memory dueProtocolFeeAmounts = _getDueProtocolFeeAmounts(balances, protocolSwapFeePercentage, imd);
131
127
 
132
128
  _mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub);
133
- (uint256 bptAmountOut, uint256[] memory amountsIn) = _doJoin(
134
- balances,
135
- scalingFactors,
136
- userData,
137
- imd
138
- );
129
+ (uint256 bptAmountOut, uint256[] memory amountsIn) = _doJoin(balances, scalingFactors, userData, imd);
139
130
 
140
131
  // skip _updateInvariantAfterJoin
141
132
 
@@ -156,19 +147,11 @@ contract MetaStablePreview is StablePreviewBase, BoringOwnableUpgradeable, UUPSU
156
147
  internal
157
148
  view
158
149
  virtual
159
- returns (
160
- uint256 bptAmountIn,
161
- uint256[] memory amountsOut,
162
- uint256[] memory dueProtocolFeeAmounts
163
- )
150
+ returns (uint256 bptAmountIn, uint256[] memory amountsOut, uint256[] memory dueProtocolFeeAmounts)
164
151
  {
165
152
  // skip _updateOracle
166
153
 
167
- dueProtocolFeeAmounts = _getDueProtocolFeeAmounts(
168
- balances,
169
- protocolSwapFeePercentage,
170
- imd
171
- );
154
+ dueProtocolFeeAmounts = _getDueProtocolFeeAmounts(balances, protocolSwapFeePercentage, imd);
172
155
 
173
156
  _mutateAmounts(balances, dueProtocolFeeAmounts, FixedPoint.sub);
174
157
 
@@ -202,16 +185,14 @@ contract MetaStablePreview is StablePreviewBase, BoringOwnableUpgradeable, UUPSU
202
185
  }
203
186
  }
204
187
 
205
- (uint256 _lastInvariant, uint256 _lastInvariantAmp) = IMetaStablePool(imd.LP)
206
- .getLastInvariant();
207
- dueProtocolFeeAmounts[chosenTokenIndex] = MetaStableMath
208
- ._calcDueTokenProtocolSwapFeeAmount(
209
- _lastInvariantAmp,
210
- balances,
211
- _lastInvariant,
212
- chosenTokenIndex,
213
- protocolSwapFeePercentage
214
- );
188
+ (uint256 _lastInvariant, uint256 _lastInvariantAmp) = IMetaStablePool(imd.LP).getLastInvariant();
189
+ dueProtocolFeeAmounts[chosenTokenIndex] = MetaStableMath._calcDueTokenProtocolSwapFeeAmount(
190
+ _lastInvariantAmp,
191
+ balances,
192
+ _lastInvariant,
193
+ chosenTokenIndex,
194
+ protocolSwapFeePercentage
195
+ );
215
196
 
216
197
  return dueProtocolFeeAmounts;
217
198
  }
@@ -296,31 +277,21 @@ contract MetaStablePreview is StablePreviewBase, BoringOwnableUpgradeable, UUPSU
296
277
  return scalingFactors;
297
278
  }
298
279
 
299
- function _priceRate(
300
- uint256[] memory caches,
301
- uint256 index
302
- ) internal view virtual returns (uint256) {
280
+ function _priceRate(uint256[] memory caches, uint256 index) internal view virtual returns (uint256) {
303
281
  return caches[index] == 0 ? FixedPoint.ONE : caches[index];
304
282
  }
305
283
 
306
- function _cachePriceRatesIfNecessary(
307
- ImmutableData memory imd
308
- ) internal view returns (uint256[] memory res) {
284
+ function _cachePriceRatesIfNecessary(ImmutableData memory imd) internal view returns (uint256[] memory res) {
309
285
  res = new uint256[](2);
310
286
  res[0] = _cachePriceRateIfNecessary(0, imd);
311
287
  res[1] = _cachePriceRateIfNecessary(1, imd);
312
288
  }
313
289
 
314
- function _cachePriceRateIfNecessary(
315
- uint256 index,
316
- ImmutableData memory imd
317
- ) internal view returns (uint256 res) {
290
+ function _cachePriceRateIfNecessary(uint256 index, ImmutableData memory imd) internal view returns (uint256 res) {
318
291
  if (!_hasRateProvider(imd, index)) return res;
319
292
 
320
293
  uint256 expires;
321
- (res, , expires) = IMetaStablePool(imd.LP).getPriceRateCache(
322
- IERC20(imd.poolTokens[index])
323
- );
294
+ (res, , expires) = IMetaStablePool(imd.LP).getPriceRateCache(IERC20(imd.poolTokens[index]));
324
295
 
325
296
  if (block.timestamp > expires) {
326
297
  res = IRateProvider(imd.rateProviders[index]).getRate();
@@ -331,10 +302,7 @@ contract MetaStablePreview is StablePreviewBase, BoringOwnableUpgradeable, UUPSU
331
302
  Helpers functions
332
303
  //////////////////////////////////////////////////////////////*/
333
304
 
334
- function _upscaleArray(
335
- uint256[] memory amounts,
336
- uint256[] memory scalingFactors
337
- ) internal pure {
305
+ function _upscaleArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal pure {
338
306
  require(amounts.length == scalingFactors.length, "Array length mismatch");
339
307
 
340
308
  uint256 length = amounts.length;
@@ -343,10 +311,7 @@ contract MetaStablePreview is StablePreviewBase, BoringOwnableUpgradeable, UUPSU
343
311
  }
344
312
  }
345
313
 
346
- function _downscaleDownArray(
347
- uint256[] memory amounts,
348
- uint256[] memory scalingFactors
349
- ) internal pure {
314
+ function _downscaleDownArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal pure {
350
315
  require(amounts.length == scalingFactors.length, "Array length mismatch");
351
316
 
352
317
  uint256 length = amounts.length;
@@ -365,10 +330,7 @@ contract MetaStablePreview is StablePreviewBase, BoringOwnableUpgradeable, UUPSU
365
330
  }
366
331
  }
367
332
 
368
- function _hasRateProvider(
369
- ImmutableData memory imd,
370
- uint256 index
371
- ) internal pure returns (bool) {
333
+ function _hasRateProvider(ImmutableData memory imd, uint256 index) internal pure returns (bool) {
372
334
  return address(imd.rateProviders[index]) != address(0);
373
335
  }
374
336
  }
@@ -58,11 +58,7 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
58
58
  gasForReentrancyCheck = DEFAULT_GAS_REENTRANCY_CHECK;
59
59
  }
60
60
 
61
- function _getPoolInfo(uint256 _auraPid)
62
- internal
63
- view
64
- returns (address _auraLp, address _auraRewardManager)
65
- {
61
+ function _getPoolInfo(uint256 _auraPid) internal view returns (address _auraLp, address _auraRewardManager) {
66
62
  if (_auraPid > IBooster(AURA_BOOSTER).poolLength()) revert Errors.SYBalancerInvalidPid();
67
63
  (_auraLp, , , _auraRewardManager, , ) = IBooster(AURA_BOOSTER).poolInfo(_auraPid);
68
64
  }
@@ -74,12 +70,7 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
74
70
  /**
75
71
  * @notice Either wraps LP, or also joins pool using exact tokenIn
76
72
  */
77
- function _deposit(address tokenIn, uint256 amount)
78
- internal
79
- virtual
80
- override
81
- returns (uint256 amountSharesOut)
82
- {
73
+ function _deposit(address tokenIn, uint256 amount) internal virtual override returns (uint256 amountSharesOut) {
83
74
  if (tokenIn == balLp) {
84
75
  amountSharesOut = amount;
85
76
  } else {
@@ -134,13 +125,8 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
134
125
  function _checkBalancerReadOnlyReentrancy() internal view {
135
126
  IVault.UserBalanceOp[] memory noop = new IVault.UserBalanceOp[](0);
136
127
 
137
- (bool isSuccess, bytes memory response) = BALANCER_VAULT.staticcall{
138
- gas: gasForReentrancyCheck
139
- }(
140
- abi.encodeWithSignature(
141
- "manageUserBalance((uint8,address,uint256,address,address)[])",
142
- noop
143
- )
128
+ (bool isSuccess, bytes memory response) = BALANCER_VAULT.staticcall{gas: gasForReentrancyCheck}(
129
+ abi.encodeWithSignature("manageUserBalance((uint8,address,uint256,address,address)[])", noop)
144
130
  );
145
131
 
146
132
  assert(!isSuccess);
@@ -156,33 +142,22 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
156
142
  BALANCER-RELATED FUNCTIONS
157
143
  //////////////////////////////////////////////////////////////*/
158
144
 
159
- function _depositToBalancer(address tokenIn, uint256 amountTokenToDeposit)
160
- internal
161
- virtual
162
- returns (uint256)
163
- {
164
- IVault.JoinPoolRequest memory request = _assembleJoinRequest(
165
- tokenIn,
166
- amountTokenToDeposit
167
- );
145
+ function _depositToBalancer(address tokenIn, uint256 amountTokenToDeposit) internal virtual returns (uint256) {
146
+ IVault.JoinPoolRequest memory request = _assembleJoinRequest(tokenIn, amountTokenToDeposit);
168
147
  IVault(BALANCER_VAULT).joinPool(balPoolId, address(this), address(this), request);
169
148
 
170
149
  // amount shares out = amount LP received
171
150
  return _selfBalance(balLp);
172
151
  }
173
152
 
174
- function _assembleJoinRequest(address tokenIn, uint256 amountTokenToDeposit)
175
- internal
176
- view
177
- virtual
178
- returns (IVault.JoinPoolRequest memory request)
179
- {
153
+ function _assembleJoinRequest(
154
+ address tokenIn,
155
+ uint256 amountTokenToDeposit
156
+ ) internal view virtual returns (IVault.JoinPoolRequest memory request) {
180
157
  // max amounts in
181
158
  address[] memory assets = _getPoolTokenAddresses();
182
159
 
183
- uint256 amountsLength = _getBPTIndex() < type(uint256).max
184
- ? assets.length - 1
185
- : assets.length;
160
+ uint256 amountsLength = _getBPTIndex() < type(uint256).max ? assets.length - 1 : assets.length;
186
161
 
187
162
  uint256[] memory amountsIn = new uint256[](amountsLength);
188
163
  uint256[] memory maxAmountsIn = new uint256[](assets.length);
@@ -192,9 +167,7 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
192
167
  maxAmountsIn[index] = amountsIn[indexSkipBPT] = amountTokenToDeposit;
193
168
 
194
169
  // encode user data
195
- StablePoolUserData.JoinKind joinKind = StablePoolUserData
196
- .JoinKind
197
- .EXACT_TOKENS_IN_FOR_BPT_OUT;
170
+ StablePoolUserData.JoinKind joinKind = StablePoolUserData.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT;
198
171
  uint256 minimumBPT = 0;
199
172
 
200
173
  bytes memory userData = abi.encode(joinKind, amountsIn, minimumBPT);
@@ -218,19 +191,15 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
218
191
  return balanceAfter - balanceBefore;
219
192
  }
220
193
 
221
- function _assembleExitRequest(address tokenOut, uint256 amountLpToRedeem)
222
- internal
223
- view
224
- virtual
225
- returns (IVault.ExitPoolRequest memory request)
226
- {
194
+ function _assembleExitRequest(
195
+ address tokenOut,
196
+ uint256 amountLpToRedeem
197
+ ) internal view virtual returns (IVault.ExitPoolRequest memory request) {
227
198
  address[] memory assets = _getPoolTokenAddresses();
228
199
  uint256[] memory minAmountsOut = new uint256[](assets.length);
229
200
 
230
201
  // encode user data
231
- StablePoolUserData.ExitKind exitKind = StablePoolUserData
232
- .ExitKind
233
- .EXACT_BPT_IN_FOR_ONE_TOKEN_OUT;
202
+ StablePoolUserData.ExitKind exitKind = StablePoolUserData.ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT;
234
203
  uint256 bptAmountIn = amountLpToRedeem;
235
204
  uint256 exitTokenIndex = assets.find(tokenOut);
236
205
 
@@ -255,20 +224,14 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
255
224
  PREVIEW FUNCTIONS
256
225
  //////////////////////////////////////////////////////////////*/
257
226
 
258
- function _previewDeposit(address tokenIn, uint256 amountTokenToDeposit)
259
- internal
260
- view
261
- virtual
262
- override
263
- returns (uint256 amountSharesOut)
264
- {
227
+ function _previewDeposit(
228
+ address tokenIn,
229
+ uint256 amountTokenToDeposit
230
+ ) internal view virtual override returns (uint256 amountSharesOut) {
265
231
  if (tokenIn == balLp) {
266
232
  amountSharesOut = amountTokenToDeposit;
267
233
  } else {
268
- IVault.JoinPoolRequest memory request = _assembleJoinRequest(
269
- tokenIn,
270
- amountTokenToDeposit
271
- );
234
+ IVault.JoinPoolRequest memory request = _assembleJoinRequest(tokenIn, amountTokenToDeposit);
272
235
  amountSharesOut = previewHelper.joinPoolPreview(
273
236
  balPoolId,
274
237
  address(this),
@@ -279,20 +242,14 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
279
242
  }
280
243
  }
281
244
 
282
- function _previewRedeem(address tokenOut, uint256 amountSharesToRedeem)
283
- internal
284
- view
285
- virtual
286
- override
287
- returns (uint256 amountTokenOut)
288
- {
245
+ function _previewRedeem(
246
+ address tokenOut,
247
+ uint256 amountSharesToRedeem
248
+ ) internal view virtual override returns (uint256 amountTokenOut) {
289
249
  if (tokenOut == balLp) {
290
250
  amountTokenOut = amountSharesToRedeem;
291
251
  } else {
292
- IVault.ExitPoolRequest memory request = _assembleExitRequest(
293
- tokenOut,
294
- amountSharesToRedeem
295
- );
252
+ IVault.ExitPoolRequest memory request = _assembleExitRequest(tokenOut, amountSharesToRedeem);
296
253
 
297
254
  amountTokenOut = previewHelper.exitPoolPreview(
298
255
  balPoolId,
@@ -360,15 +317,7 @@ abstract contract PendleAuraBalancerStableLPSYV2 is SYBaseWithRewards {
360
317
 
361
318
  function isValidTokenOut(address token) public view virtual override returns (bool);
362
319
 
363
- function assetInfo()
364
- external
365
- view
366
- returns (
367
- AssetType assetType,
368
- address assetAddress,
369
- uint8 assetDecimals
370
- )
371
- {
320
+ function assetInfo() external view returns (AssetType assetType, address assetAddress, uint8 assetDecimals) {
372
321
  return (AssetType.LIQUIDITY, balLp, IERC20Metadata(balLp).decimals());
373
322
  }
374
323
  }
@@ -0,0 +1,310 @@
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
+
6
+ import "../../../../../interfaces/Balancer/IVault.sol";
7
+ import "../../../../../interfaces/Balancer/IRateProvider.sol";
8
+ import "../../../../../interfaces/Balancer/IBasePool.sol";
9
+ import "../../../../../interfaces/Balancer/IBalancerStablePreview.sol";
10
+ import "../../../../../interfaces/ConvexCurve/IBooster.sol";
11
+ import "../../../../../interfaces/ConvexCurve/IRewards.sol";
12
+
13
+ import "./StablePoolUserData.sol";
14
+ import "../../../../libraries/ArrayLib.sol";
15
+ import "../../../SYBaseWithRewardsUpg.sol";
16
+
17
+ abstract contract PendleAuraBalancerStableLPSYV3Upg is SYBaseWithRewardsUpg {
18
+ using ArrayLib for address[];
19
+
20
+ address internal constant BAL_TOKEN = 0xba100000625a3754423978a60c9317c58a424e3D;
21
+ address internal constant AURA_TOKEN = 0xC0c293ce456fF0ED870ADd98a0828Dd4d2903DBF;
22
+ address internal constant AURA_BOOSTER = 0xA57b8d98dAE62B26Ec3bcC4a365338157060B234;
23
+ address internal constant BALANCER_VAULT = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
24
+ uint256 internal constant DEFAULT_GAS_REENTRANCY_CHECK = 7000;
25
+
26
+ address public immutable balLp;
27
+ bytes32 public immutable balPoolId;
28
+
29
+ uint256 public immutable auraPid;
30
+ address public immutable auraRewardManager;
31
+
32
+ IBalancerStablePreview public immutable previewHelper;
33
+
34
+ uint256 public gasForReentrancyCheck;
35
+ address[] public extraRewards;
36
+
37
+ uint256[100] private __gap;
38
+
39
+ constructor(address _balLp, uint256 _auraPid, IBalancerStablePreview _previewHelper) SYBaseUpg(_balLp) {
40
+ balPoolId = IBasePool(_balLp).getPoolId();
41
+ auraPid = _auraPid;
42
+
43
+ (balLp, auraRewardManager) = _getPoolInfo(_auraPid);
44
+ if (balLp != _balLp) revert Errors.SYBalancerInvalidPid();
45
+
46
+ previewHelper = _previewHelper;
47
+ }
48
+
49
+ function __PendleAuraBalancerStableLPSYV3Upg_init(
50
+ string memory _name,
51
+ string memory _symbol
52
+ ) internal onlyInitializing {
53
+ __SYBaseUpg_init(_name, _symbol);
54
+
55
+ _safeApproveInf(balLp, AURA_BOOSTER);
56
+ address[] memory tokens = _getPoolTokenAddresses();
57
+ for (uint256 i = 0; i < tokens.length; ++i) {
58
+ _safeApproveInf(tokens[i], BALANCER_VAULT);
59
+ }
60
+ gasForReentrancyCheck = DEFAULT_GAS_REENTRANCY_CHECK;
61
+ }
62
+
63
+ function _getPoolInfo(uint256 _auraPid) internal view returns (address _auraLp, address _auraRewardManager) {
64
+ if (_auraPid > IBooster(AURA_BOOSTER).poolLength()) revert Errors.SYBalancerInvalidPid();
65
+ (_auraLp, , , _auraRewardManager, , ) = IBooster(AURA_BOOSTER).poolInfo(_auraPid);
66
+ }
67
+
68
+ /*///////////////////////////////////////////////////////////////
69
+ DEPOSIT/REDEEM USING BASE TOKENS
70
+ //////////////////////////////////////////////////////////////*/
71
+
72
+ /**
73
+ * @notice Either wraps LP, or also joins pool using exact tokenIn
74
+ */
75
+ function _deposit(address tokenIn, uint256 amount) internal virtual override returns (uint256 amountSharesOut) {
76
+ if (tokenIn == balLp) {
77
+ amountSharesOut = amount;
78
+ } else {
79
+ amountSharesOut = _depositToBalancer(tokenIn, amount);
80
+ }
81
+ IBooster(AURA_BOOSTER).deposit(auraPid, amountSharesOut, true);
82
+ }
83
+
84
+ /**
85
+ * @notice Either unwraps LP, or also exits pool using exact LP for only `tokenOut`
86
+ */
87
+ function _redeem(
88
+ address receiver,
89
+ address tokenOut,
90
+ uint256 amountSharesToRedeem
91
+ ) internal virtual override returns (uint256 amountTokenOut) {
92
+ IRewards(auraRewardManager).withdrawAndUnwrap(amountSharesToRedeem, false);
93
+
94
+ if (tokenOut == balLp) {
95
+ amountTokenOut = amountSharesToRedeem;
96
+ _transferOut(tokenOut, receiver, amountTokenOut);
97
+ } else {
98
+ amountTokenOut = _redeemFromBalancer(receiver, tokenOut, amountSharesToRedeem);
99
+ }
100
+ }
101
+
102
+ function exchangeRate() external view override returns (uint256) {
103
+ _checkBalancerReadOnlyReentrancy();
104
+ return IRateProvider(balLp).getRate();
105
+ }
106
+
107
+ /*
108
+ * The `manageUserBalance` function is a non-view function that includes a reentrancy guard
109
+ in the form of `_require(_status != _ENTERED, Errors.REENTRANCY);`. To prevent
110
+ read-only reentrancy, it's important to ensure that our `manageUserBalance` has enough gas
111
+ to reach this check, so that it can fail if necessary.
112
+
113
+ * On the way to the check, there's at most one `COLD_SLOAD` plus miscellaneous decoding &
114
+ require, which we've found through testing to cost no more than 3200 gas. Therefore,
115
+ attaching 7000 gas should guarantee that it's always possible to reach the check.
116
+
117
+ * Once we've reached the check, one of two scenarios can occur:
118
+ 1. The call doesn't pass the check, and reverts with error `BAL#400` ⇒ `response.length = 100`.
119
+ 2. The call passes the check. Then, the call can either:
120
+ a. continue on to set the `status` variable to 2, causing the EVM to revert (since
121
+ the sub-call is a `staticcall`), and `response.length == 0`
122
+ b. run out of gas, which will also lead to a revert with `response.length == 0`
123
+ In both cases, to differentiate between 1 and 2, we check `response.length != 0`. If it's
124
+ true, then it's a read-only reentrancy. Otherwise, we're good (and we can ignore
125
+ differentiating between 2a and 2b).
126
+ */
127
+ function _checkBalancerReadOnlyReentrancy() internal view {
128
+ IVault.UserBalanceOp[] memory noop = new IVault.UserBalanceOp[](0);
129
+
130
+ (bool isSuccess, bytes memory response) = BALANCER_VAULT.staticcall{gas: gasForReentrancyCheck}(
131
+ abi.encodeWithSignature("manageUserBalance((uint8,address,uint256,address,address)[])", noop)
132
+ );
133
+
134
+ assert(!isSuccess);
135
+ if (response.length != 0) revert Errors.SYBalancerReentrancy();
136
+ }
137
+
138
+ function setGasForReentrancyCheck(uint256 newGas) external onlyOwner {
139
+ require(newGas >= DEFAULT_GAS_REENTRANCY_CHECK, "lower than default");
140
+ gasForReentrancyCheck = newGas;
141
+ }
142
+
143
+ /*///////////////////////////////////////////////////////////////
144
+ BALANCER-RELATED FUNCTIONS
145
+ //////////////////////////////////////////////////////////////*/
146
+
147
+ function _depositToBalancer(address tokenIn, uint256 amountTokenToDeposit) internal virtual returns (uint256) {
148
+ IVault.JoinPoolRequest memory request = _assembleJoinRequest(tokenIn, amountTokenToDeposit);
149
+ IVault(BALANCER_VAULT).joinPool(balPoolId, address(this), address(this), request);
150
+
151
+ // amount shares out = amount LP received
152
+ return _selfBalance(balLp);
153
+ }
154
+
155
+ function _assembleJoinRequest(
156
+ address tokenIn,
157
+ uint256 amountTokenToDeposit
158
+ ) internal view virtual returns (IVault.JoinPoolRequest memory request) {
159
+ // max amounts in
160
+ address[] memory assets = _getPoolTokenAddresses();
161
+
162
+ uint256 amountsLength = _getBPTIndex() < type(uint256).max ? assets.length - 1 : assets.length;
163
+
164
+ uint256[] memory amountsIn = new uint256[](amountsLength);
165
+ uint256[] memory maxAmountsIn = new uint256[](assets.length);
166
+
167
+ uint256 index = assets.find(tokenIn);
168
+ uint256 indexSkipBPT = index > _getBPTIndex() ? index - 1 : index;
169
+ maxAmountsIn[index] = amountsIn[indexSkipBPT] = amountTokenToDeposit;
170
+
171
+ // encode user data
172
+ StablePoolUserData.JoinKind joinKind = StablePoolUserData.JoinKind.EXACT_TOKENS_IN_FOR_BPT_OUT;
173
+ uint256 minimumBPT = 0;
174
+
175
+ bytes memory userData = abi.encode(joinKind, amountsIn, minimumBPT);
176
+
177
+ // assemble joinpoolrequest
178
+ request = IVault.JoinPoolRequest(assets, maxAmountsIn, userData, false);
179
+ }
180
+
181
+ function _redeemFromBalancer(
182
+ address receiver,
183
+ address tokenOut,
184
+ uint256 amountLpToRedeem
185
+ ) internal virtual returns (uint256) {
186
+ uint256 balanceBefore = IERC20(tokenOut).balanceOf(receiver);
187
+
188
+ IVault.ExitPoolRequest memory request = _assembleExitRequest(tokenOut, amountLpToRedeem);
189
+ IVault(BALANCER_VAULT).exitPool(balPoolId, address(this), payable(receiver), request);
190
+
191
+ // calculate amount of tokens out
192
+ uint256 balanceAfter = IERC20(tokenOut).balanceOf(receiver);
193
+ return balanceAfter - balanceBefore;
194
+ }
195
+
196
+ function _assembleExitRequest(
197
+ address tokenOut,
198
+ uint256 amountLpToRedeem
199
+ ) internal view virtual returns (IVault.ExitPoolRequest memory request) {
200
+ address[] memory assets = _getPoolTokenAddresses();
201
+ uint256[] memory minAmountsOut = new uint256[](assets.length);
202
+
203
+ // encode user data
204
+ StablePoolUserData.ExitKind exitKind = StablePoolUserData.ExitKind.EXACT_BPT_IN_FOR_ONE_TOKEN_OUT;
205
+ uint256 bptAmountIn = amountLpToRedeem;
206
+ uint256 exitTokenIndex = assets.find(tokenOut);
207
+
208
+ // must drop BPT index as well
209
+ exitTokenIndex = _getBPTIndex() < exitTokenIndex ? exitTokenIndex - 1 : exitTokenIndex;
210
+
211
+ bytes memory userData = abi.encode(exitKind, bptAmountIn, exitTokenIndex);
212
+
213
+ // assemble exitpoolrequest
214
+ request = IVault.ExitPoolRequest(assets, minAmountsOut, userData, false);
215
+ }
216
+
217
+ /// @dev this should return tokens in the same order as `IVault.getPoolTokens()`
218
+ function _getPoolTokenAddresses() internal view virtual returns (address[] memory res);
219
+
220
+ /// @dev should be overriden if and only if BPT is one of the pool tokens
221
+ function _getBPTIndex() internal view virtual returns (uint256) {
222
+ return type(uint256).max;
223
+ }
224
+
225
+ /*///////////////////////////////////////////////////////////////
226
+ PREVIEW FUNCTIONS
227
+ //////////////////////////////////////////////////////////////*/
228
+
229
+ function _previewDeposit(
230
+ address tokenIn,
231
+ uint256 amountTokenToDeposit
232
+ ) internal view virtual override returns (uint256 amountSharesOut) {
233
+ if (tokenIn == balLp) {
234
+ amountSharesOut = amountTokenToDeposit;
235
+ } else {
236
+ IVault.JoinPoolRequest memory request = _assembleJoinRequest(tokenIn, amountTokenToDeposit);
237
+ amountSharesOut = previewHelper.joinPoolPreview(
238
+ balPoolId,
239
+ address(this),
240
+ address(this),
241
+ request,
242
+ _getImmutablePoolData()
243
+ );
244
+ }
245
+ }
246
+
247
+ function _previewRedeem(
248
+ address tokenOut,
249
+ uint256 amountSharesToRedeem
250
+ ) internal view virtual override returns (uint256 amountTokenOut) {
251
+ if (tokenOut == balLp) {
252
+ amountTokenOut = amountSharesToRedeem;
253
+ } else {
254
+ IVault.ExitPoolRequest memory request = _assembleExitRequest(tokenOut, amountSharesToRedeem);
255
+
256
+ amountTokenOut = previewHelper.exitPoolPreview(
257
+ balPoolId,
258
+ address(this),
259
+ address(this),
260
+ request,
261
+ _getImmutablePoolData()
262
+ );
263
+ }
264
+ }
265
+
266
+ function _getImmutablePoolData() internal view virtual returns (bytes memory);
267
+
268
+ /*///////////////////////////////////////////////////////////////
269
+ REWARDS-RELATED
270
+ //////////////////////////////////////////////////////////////*/
271
+
272
+ /// @notice allows owner to add new reward tokens in in case Aura does so with their pools
273
+ function addRewardTokens(address token) external virtual onlyOwner {
274
+ extraRewards.push(token);
275
+ }
276
+
277
+ function extraRewardsLength() external view virtual returns (uint256) {
278
+ return extraRewards.length;
279
+ }
280
+
281
+ function _getRewardTokens() internal view virtual override returns (address[] memory res) {
282
+ uint256 extraRewardsLen = extraRewards.length;
283
+ res = new address[](2 + extraRewardsLen);
284
+ res[0] = BAL_TOKEN;
285
+ res[1] = AURA_TOKEN;
286
+ for (uint256 i = 0; i < extraRewardsLen; i++) {
287
+ res[2 + i] = extraRewards[i];
288
+ }
289
+ }
290
+
291
+ function _redeemExternalReward() internal virtual override {
292
+ IRewards(auraRewardManager).getReward(address(this), true);
293
+ }
294
+
295
+ /*///////////////////////////////////////////////////////////////
296
+ MISC FUNCTIONS FOR METADATA
297
+ //////////////////////////////////////////////////////////////*/
298
+
299
+ function getTokensIn() public view virtual override returns (address[] memory res);
300
+
301
+ function getTokensOut() public view virtual override returns (address[] memory res);
302
+
303
+ function isValidTokenIn(address token) public view virtual override returns (bool);
304
+
305
+ function isValidTokenOut(address token) public view virtual override returns (bool);
306
+
307
+ function assetInfo() external view returns (AssetType assetType, address assetAddress, uint8 assetDecimals) {
308
+ return (AssetType.LIQUIDITY, balLp, IERC20Metadata(balLp).decimals());
309
+ }
310
+ }
@@ -18,9 +18,7 @@ library StablePoolUserData {
18
18
  (, amountsIn, minBPTAmountOut) = abi.decode(self, (JoinKind, uint256[], uint256));
19
19
  }
20
20
 
21
- function exactBptInForTokenOut(
22
- bytes memory self
23
- ) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) {
21
+ function exactBptInForTokenOut(bytes memory self) internal pure returns (uint256 bptAmountIn, uint256 tokenIndex) {
24
22
  (, bptAmountIn, tokenIndex) = abi.decode(self, (ExitKind, uint256, uint256));
25
23
  }
26
24
  }
@@ -66,10 +66,7 @@ abstract contract StablePreviewBase is IBalancerStablePreview {
66
66
  bytes memory data
67
67
  ) private view returns (uint256 amountBptOrTokensOut) {
68
68
  IERC20[] memory tokens = _translateToIERC20(change.assets);
69
- (uint256[] memory balances, uint256 lastChangeBlock) = _validateTokensAndGetBalances(
70
- poolId,
71
- tokens
72
- );
69
+ (uint256[] memory balances, uint256 lastChangeBlock) = _validateTokensAndGetBalances(poolId, tokens);
73
70
 
74
71
  amountBptOrTokensOut = _callPoolBalanceChange(
75
72
  kind,
@@ -126,8 +123,7 @@ abstract contract StablePreviewBase is IBalancerStablePreview {
126
123
  bytes32 poolId,
127
124
  IERC20[] memory //expectedTokens
128
125
  ) private view returns (uint256[] memory, uint256) {
129
- (, uint256[] memory balances, uint256 lastChangeBlock) = IVault(BALANCER_VAULT)
130
- .getPoolTokens(poolId);
126
+ (, uint256[] memory balances, uint256 lastChangeBlock) = IVault(BALANCER_VAULT).getPoolTokens(poolId);
131
127
  return (balances, lastChangeBlock);
132
128
  }
133
129