@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
@@ -0,0 +1,123 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ /**
5
+ * --------- [DIRECT COPIED FROM KYBERSWAP] ---------
6
+ */
7
+
8
+ /// @title Contains 512-bit math functions
9
+ /// @notice Facilitates multiplication and division that can have overflow of an intermediate value without any loss of precision
10
+ /// @dev Handles "phantom overflow" i.e., allows multiplication and division where an intermediate value overflows 256 bits
11
+ /// @dev Code has been modified to be compatible with sol 0.8
12
+ library FullMath {
13
+ /// @notice Calculates floor(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
14
+ /// @param a The multiplicand
15
+ /// @param b The multiplier
16
+ /// @param denominator The divisor
17
+ /// @return result The 256-bit result
18
+ /// @dev Credit to Remco Bloemen under MIT license https://xn--2-umb.com/21/muldiv
19
+ function mulDivFloor(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
20
+ // 512-bit multiply [prod1 prod0] = a * b
21
+ // Compute the product mod 2**256 and mod 2**256 - 1
22
+ // then use the Chinese Remainder Theorem to reconstruct
23
+ // the 512 bit result. The result is stored in two 256
24
+ // variables such that product = prod1 * 2**256 + prod0
25
+ uint256 prod0; // Least significant 256 bits of the product
26
+ uint256 prod1; // Most significant 256 bits of the product
27
+ assembly {
28
+ let mm := mulmod(a, b, not(0))
29
+ prod0 := mul(a, b)
30
+ prod1 := sub(sub(mm, prod0), lt(mm, prod0))
31
+ }
32
+
33
+ // Handle non-overflow cases, 256 by 256 division
34
+ if (prod1 == 0) {
35
+ require(denominator > 0, "0 denom");
36
+ assembly {
37
+ result := div(prod0, denominator)
38
+ }
39
+ return result;
40
+ }
41
+
42
+ // Make sure the result is less than 2**256.
43
+ // Also prevents denominator == 0
44
+ require(denominator > prod1, "denom <= prod1");
45
+
46
+ ///////////////////////////////////////////////
47
+ // 512 by 256 division.
48
+ ///////////////////////////////////////////////
49
+
50
+ // Make division exact by subtracting the remainder from [prod1 prod0]
51
+ // Compute remainder using mulmod
52
+ uint256 remainder;
53
+ assembly {
54
+ remainder := mulmod(a, b, denominator)
55
+ }
56
+ // Subtract 256 bit number from 512 bit number
57
+ assembly {
58
+ prod1 := sub(prod1, gt(remainder, prod0))
59
+ prod0 := sub(prod0, remainder)
60
+ }
61
+
62
+ // Factor powers of two out of denominator
63
+ // Compute largest power of two divisor of denominator.
64
+ // Always >= 1.
65
+ uint256 twos = denominator & (~denominator + 1);
66
+ // Divide denominator by power of two
67
+ assembly {
68
+ denominator := div(denominator, twos)
69
+ }
70
+
71
+ // Divide [prod1 prod0] by the factors of two
72
+ assembly {
73
+ prod0 := div(prod0, twos)
74
+ }
75
+ // Shift in bits from prod1 into prod0. For this we need
76
+ // to flip `twos` such that it is 2**256 / twos.
77
+ // If twos is zero, then it becomes one
78
+ assembly {
79
+ twos := add(div(sub(0, twos), twos), 1)
80
+ }
81
+ unchecked {
82
+ prod0 |= prod1 * twos;
83
+
84
+ // Invert denominator mod 2**256
85
+ // Now that denominator is an odd number, it has an inverse
86
+ // modulo 2**256 such that denominator * inv = 1 mod 2**256.
87
+ // Compute the inverse by starting with a seed that is correct
88
+ // correct for four bits. That is, denominator * inv = 1 mod 2**4
89
+ uint256 inv = (3 * denominator) ^ 2;
90
+
91
+ // Now use Newton-Raphson iteration to improve the precision.
92
+ // Thanks to Hensel's lifting lemma, this also works in modular
93
+ // arithmetic, doubling the correct bits in each step.
94
+ inv *= 2 - denominator * inv; // inverse mod 2**8
95
+ inv *= 2 - denominator * inv; // inverse mod 2**16
96
+ inv *= 2 - denominator * inv; // inverse mod 2**32
97
+ inv *= 2 - denominator * inv; // inverse mod 2**64
98
+ inv *= 2 - denominator * inv; // inverse mod 2**128
99
+ inv *= 2 - denominator * inv; // inverse mod 2**256
100
+
101
+ // Because the division is now exact we can divide by multiplying
102
+ // with the modular inverse of denominator. This will give us the
103
+ // correct result modulo 2**256. Since the precoditions guarantee
104
+ // that the outcome is less than 2**256, this is the final result.
105
+ // We don't need to compute the high bits of the result and prod1
106
+ // is no longer required.
107
+ result = prod0 * inv;
108
+ }
109
+ return result;
110
+ }
111
+
112
+ /// @notice Calculates ceil(a×b÷denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
113
+ /// @param a The multiplicand
114
+ /// @param b The multiplier
115
+ /// @param denominator The divisor
116
+ /// @return result The 256-bit result
117
+ function mulDivCeiling(uint256 a, uint256 b, uint256 denominator) internal pure returns (uint256 result) {
118
+ result = mulDivFloor(a, b, denominator);
119
+ if (mulmod(a, b, denominator) > 0) {
120
+ result++;
121
+ }
122
+ }
123
+ }
@@ -0,0 +1,17 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ /**
5
+ * --------- [DIRECT COPIED FROM KYBERSWAP] ---------
6
+ */
7
+
8
+ /// @title Contains helper function to add or remove uint128 liquidityDelta to uint128 liquidity
9
+ library LiqDeltaMath {
10
+ function applyLiquidityDelta(
11
+ uint128 liquidity,
12
+ uint128 liquidityDelta,
13
+ bool isAddLiquidity
14
+ ) internal pure returns (uint128) {
15
+ return isAddLiquidity ? liquidity + liquidityDelta : liquidity - liquidityDelta;
16
+ }
17
+ }
@@ -0,0 +1,74 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.0;
3
+
4
+ import {MathConstants as C} from "./MathConstants.sol";
5
+ import {FullMath} from "./FullMath.sol";
6
+ import {SafeCast} from "./SafeCast.sol";
7
+
8
+ /**
9
+ * --------- [DIRECT COPIED FROM KYBERSWAP] ---------
10
+ */
11
+
12
+ library LiquidityMath {
13
+ using SafeCast for uint256;
14
+
15
+ /// @notice Gets liquidity from qty 0 and the price range
16
+ /// qty0 = liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))
17
+ /// => liquidity = qty0 * (sqrt(upper) * sqrt(lower)) / (sqrt(upper) - sqrt(lower))
18
+ /// @param lowerSqrtP A lower sqrt price
19
+ /// @param upperSqrtP An upper sqrt price
20
+ /// @param qty0 amount of token0
21
+ /// @return liquidity amount of returned liquidity to not exceed the qty0
22
+ function getLiquidityFromQty0(
23
+ uint160 lowerSqrtP,
24
+ uint160 upperSqrtP,
25
+ uint256 qty0
26
+ ) internal pure returns (uint128) {
27
+ uint256 liq = FullMath.mulDivFloor(lowerSqrtP, upperSqrtP, C.TWO_POW_96);
28
+ unchecked {
29
+ return FullMath.mulDivFloor(liq, qty0, upperSqrtP - lowerSqrtP).toUint128();
30
+ }
31
+ }
32
+
33
+ /// @notice Gets liquidity from qty 1 and the price range
34
+ /// @dev qty1 = liquidity * (sqrt(upper) - sqrt(lower))
35
+ /// thus, liquidity = qty1 / (sqrt(upper) - sqrt(lower))
36
+ /// @param lowerSqrtP A lower sqrt price
37
+ /// @param upperSqrtP An upper sqrt price
38
+ /// @param qty1 amount of token1
39
+ /// @return liquidity amount of returned liquidity to not exceed to qty1
40
+ function getLiquidityFromQty1(
41
+ uint160 lowerSqrtP,
42
+ uint160 upperSqrtP,
43
+ uint256 qty1
44
+ ) internal pure returns (uint128) {
45
+ unchecked {
46
+ return FullMath.mulDivFloor(qty1, C.TWO_POW_96, upperSqrtP - lowerSqrtP).toUint128();
47
+ }
48
+ }
49
+
50
+ /// @notice Gets liquidity given price range and 2 qties of token0 and token1
51
+ /// @param currentSqrtP current price
52
+ /// @param lowerSqrtP A lower sqrt price
53
+ /// @param upperSqrtP An upper sqrt price
54
+ /// @param qty0 amount of token0 - at most
55
+ /// @param qty1 amount of token1 - at most
56
+ /// @return liquidity amount of returned liquidity to not exceed the given qties
57
+ function getLiquidityFromQties(
58
+ uint160 currentSqrtP,
59
+ uint160 lowerSqrtP,
60
+ uint160 upperSqrtP,
61
+ uint256 qty0,
62
+ uint256 qty1
63
+ ) internal pure returns (uint128) {
64
+ if (currentSqrtP <= lowerSqrtP) {
65
+ return getLiquidityFromQty0(lowerSqrtP, upperSqrtP, qty0);
66
+ }
67
+ if (currentSqrtP >= upperSqrtP) {
68
+ return getLiquidityFromQty1(lowerSqrtP, upperSqrtP, qty1);
69
+ }
70
+ uint128 liq0 = getLiquidityFromQty0(currentSqrtP, upperSqrtP, qty0);
71
+ uint128 liq1 = getLiquidityFromQty1(lowerSqrtP, currentSqrtP, qty1);
72
+ return liq0 < liq1 ? liq0 : liq1;
73
+ }
74
+ }
@@ -0,0 +1,19 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ /**
5
+ * --------- [DIRECT COPIED FROM KYBERSWAP] ---------
6
+ */
7
+
8
+ /// @title Contains constants needed for math libraries
9
+ library MathConstants {
10
+ uint256 internal constant TWO_FEE_UNITS = 200_000;
11
+ uint256 internal constant TWO_POW_96 = 2 ** 96;
12
+ uint128 internal constant MIN_LIQUIDITY = 100;
13
+ uint8 internal constant RES_96 = 96;
14
+ uint24 internal constant FEE_UNITS = 100000;
15
+ // it is strictly less than 5% price movement if jumping MAX_TICK_DISTANCE ticks
16
+ int24 internal constant MAX_TICK_DISTANCE = 480;
17
+ // max number of tick travel when inserting if data changes
18
+ uint256 internal constant MAX_TICK_TRAVEL = 10;
19
+ }
@@ -0,0 +1,103 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ import {MathConstants as C} from "./MathConstants.sol";
5
+ import {TickMath} from "./TickMath.sol";
6
+ import {FullMath} from "./FullMath.sol";
7
+ import {SafeCast} from "./SafeCast.sol";
8
+
9
+ /**
10
+ * --------- [DIRECT COPIED FROM KYBERSWAP] ---------
11
+ */
12
+
13
+ /// @title Contains helper functions for calculating
14
+ /// token0 and token1 quantites from differences in prices
15
+ /// or from burning reinvestment tokens
16
+ library QtyDeltaMath {
17
+ using SafeCast for uint256;
18
+ using SafeCast for int128;
19
+
20
+ function calcUnlockQtys(uint160 initialSqrtP) internal pure returns (uint256 qty0, uint256 qty1) {
21
+ qty0 = FullMath.mulDivCeiling(C.MIN_LIQUIDITY, C.TWO_POW_96, initialSqrtP);
22
+ qty1 = FullMath.mulDivCeiling(C.MIN_LIQUIDITY, initialSqrtP, C.TWO_POW_96);
23
+ }
24
+
25
+ /// @notice Gets the qty0 delta between two prices
26
+ /// @dev Calculates liquidity / sqrt(lower) - liquidity / sqrt(upper),
27
+ /// i.e. liquidity * (sqrt(upper) - sqrt(lower)) / (sqrt(upper) * sqrt(lower))
28
+ /// rounds up if adding liquidity, rounds down if removing liquidity
29
+ /// @param lowerSqrtP The lower sqrt price.
30
+ /// @param upperSqrtP The upper sqrt price. Should be >= lowerSqrtP
31
+ /// @param liquidity Liquidity quantity
32
+ /// @param isAddLiquidity true = add liquidity, false = remove liquidity
33
+ /// @return token0 qty required for position with liquidity between the 2 sqrt prices
34
+ function calcRequiredQty0(
35
+ uint160 lowerSqrtP,
36
+ uint160 upperSqrtP,
37
+ uint128 liquidity,
38
+ bool isAddLiquidity
39
+ ) internal pure returns (int256) {
40
+ uint256 numerator1 = uint256(liquidity) << C.RES_96;
41
+ uint256 numerator2;
42
+ unchecked {
43
+ numerator2 = upperSqrtP - lowerSqrtP;
44
+ }
45
+ return
46
+ isAddLiquidity
47
+ ? (divCeiling(FullMath.mulDivCeiling(numerator1, numerator2, upperSqrtP), lowerSqrtP)).toInt256()
48
+ : (FullMath.mulDivFloor(numerator1, numerator2, upperSqrtP) / lowerSqrtP).revToInt256();
49
+ }
50
+
51
+ /// @notice Gets the token1 delta quantity between two prices
52
+ /// @dev Calculates liquidity * (sqrt(upper) - sqrt(lower))
53
+ /// rounds up if adding liquidity, rounds down if removing liquidity
54
+ /// @param lowerSqrtP The lower sqrt price.
55
+ /// @param upperSqrtP The upper sqrt price. Should be >= lowerSqrtP
56
+ /// @param liquidity Liquidity quantity
57
+ /// @param isAddLiquidity true = add liquidity, false = remove liquidity
58
+ /// @return token1 qty required for position with liquidity between the 2 sqrt prices
59
+ function calcRequiredQty1(
60
+ uint160 lowerSqrtP,
61
+ uint160 upperSqrtP,
62
+ uint128 liquidity,
63
+ bool isAddLiquidity
64
+ ) internal pure returns (int256) {
65
+ unchecked {
66
+ return
67
+ isAddLiquidity
68
+ ? (FullMath.mulDivCeiling(liquidity, upperSqrtP - lowerSqrtP, C.TWO_POW_96)).toInt256()
69
+ : (FullMath.mulDivFloor(liquidity, upperSqrtP - lowerSqrtP, C.TWO_POW_96)).revToInt256();
70
+ }
71
+ }
72
+
73
+ /// @notice Calculates the token0 quantity proportion to be sent to the user
74
+ /// for burning reinvestment tokens
75
+ /// @param sqrtP Current pool sqrt price
76
+ /// @param liquidity Difference in reinvestment liquidity due to reinvestment token burn
77
+ /// @return token0 quantity to be sent to the user
78
+ function getQty0FromBurnRTokens(uint160 sqrtP, uint256 liquidity) internal pure returns (uint256) {
79
+ return FullMath.mulDivFloor(liquidity, C.TWO_POW_96, sqrtP);
80
+ }
81
+
82
+ /// @notice Calculates the token1 quantity proportion to be sent to the user
83
+ /// for burning reinvestment tokens
84
+ /// @param sqrtP Current pool sqrt price
85
+ /// @param liquidity Difference in reinvestment liquidity due to reinvestment token burn
86
+ /// @return token1 quantity to be sent to the user
87
+ function getQty1FromBurnRTokens(uint160 sqrtP, uint256 liquidity) internal pure returns (uint256) {
88
+ return FullMath.mulDivFloor(liquidity, sqrtP, C.TWO_POW_96);
89
+ }
90
+
91
+ /// @notice Returns ceil(x / y)
92
+ /// @dev division by 0 has unspecified behavior, and must be checked externally
93
+ /// @param x The dividend
94
+ /// @param y The divisor
95
+ /// @return z The quotient, ceil(x / y)
96
+ function divCeiling(uint256 x, uint256 y) internal pure returns (uint256 z) {
97
+ // return x / y + ((x % y == 0) ? 0 : 1);
98
+ require(y > 0);
99
+ assembly {
100
+ z := add(div(x, y), gt(mod(x, y), 0))
101
+ }
102
+ }
103
+ }
@@ -0,0 +1,31 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ /**
5
+ * --------- [DIRECT COPIED FROM KYBERSWAP] ---------
6
+ */
7
+
8
+ library QuadMath {
9
+ // our equation is ax^2 - 2bx + c = 0, where a, b and c > 0
10
+ // the qudratic formula to obtain the smaller root is (2b - sqrt((2*b)^2 - 4ac)) / 2a
11
+ // which can be simplified to (b - sqrt(b^2 - ac)) / a
12
+ function getSmallerRootOfQuadEqn(uint256 a, uint256 b, uint256 c) internal pure returns (uint256 smallerRoot) {
13
+ smallerRoot = (b - sqrt(b * b - a * c)) / a;
14
+ }
15
+
16
+ // babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
17
+ function sqrt(uint256 y) internal pure returns (uint256 z) {
18
+ unchecked {
19
+ if (y > 3) {
20
+ z = y;
21
+ uint256 x = y / 2 + 1;
22
+ while (x < z) {
23
+ z = x;
24
+ x = (y / x + x) / 2;
25
+ }
26
+ } else if (y != 0) {
27
+ z = 1;
28
+ }
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,26 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ import {MathConstants as C} from "./MathConstants.sol";
5
+ import {FullMath} from "./FullMath.sol";
6
+
7
+ /**
8
+ * --------- [DIRECT COPIED FROM KYBERSWAP] ---------
9
+ */
10
+
11
+ /// @title Contains helper function to calculate the number of reinvestment tokens to be minted
12
+ library ReinvestmentMath {
13
+ /// @dev calculate the mint amount with given reinvestL, reinvestLLast, baseL and rTotalSupply
14
+ /// contribution of lp to the increment is calculated by the proportion of baseL with reinvestL + baseL
15
+ /// then rMintQty is calculated by mutiplying this with the liquidity per reinvestment token
16
+ /// rMintQty = rTotalSupply * (reinvestL - reinvestLLast) / reinvestLLast * baseL / (baseL + reinvestL)
17
+ function calcrMintQty(
18
+ uint256 reinvestL,
19
+ uint256 reinvestLLast,
20
+ uint128 baseL,
21
+ uint256 rTotalSupply
22
+ ) internal pure returns (uint256 rMintQty) {
23
+ uint256 lpContribution = FullMath.mulDivFloor(baseL, reinvestL - reinvestLLast, baseL + reinvestL);
24
+ rMintQty = FullMath.mulDivFloor(rTotalSupply, lpContribution, reinvestLLast);
25
+ }
26
+ }
@@ -0,0 +1,73 @@
1
+ // SPDX-License-Identifier: GPL-2.0-or-later
2
+ pragma solidity >=0.8.0;
3
+
4
+ /**
5
+ * --------- [DIRECT COPIED FROM KYBERSWAP] ---------
6
+ */
7
+
8
+ /// @title Safe casting methods
9
+ /// @notice Contains methods for safely casting between types
10
+ library SafeCast {
11
+ /// @notice Cast a uint256 to uint32, revert on overflow
12
+ /// @param y The uint256 to be downcasted
13
+ /// @return z The downcasted integer, now type uint32
14
+ function toUint32(uint256 y) internal pure returns (uint32 z) {
15
+ require((z = uint32(y)) == y);
16
+ }
17
+
18
+ /// @notice Cast a uint128 to a int128, revert on overflow
19
+ /// @param y The uint256 to be casted
20
+ /// @return z The casted integer, now type int256
21
+ function toInt128(uint128 y) internal pure returns (int128 z) {
22
+ require(y < 2 ** 127);
23
+ z = int128(y);
24
+ }
25
+
26
+ /// @notice Cast a uint256 to a uint128, revert on overflow
27
+ /// @param y the uint256 to be downcasted
28
+ /// @return z The downcasted integer, now type uint128
29
+ function toUint128(uint256 y) internal pure returns (uint128 z) {
30
+ require((z = uint128(y)) == y);
31
+ }
32
+
33
+ /// @notice Cast a int128 to a uint128 and reverses the sign.
34
+ /// @param y The int128 to be casted
35
+ /// @return z = -y, now type uint128
36
+ function revToUint128(int128 y) internal pure returns (uint128 z) {
37
+ unchecked {
38
+ return type(uint128).max - uint128(y) + 1;
39
+ }
40
+ }
41
+
42
+ /// @notice Cast a uint256 to a uint160, revert on overflow
43
+ /// @param y The uint256 to be downcasted
44
+ /// @return z The downcasted integer, now type uint160
45
+ function toUint160(uint256 y) internal pure returns (uint160 z) {
46
+ require((z = uint160(y)) == y);
47
+ }
48
+
49
+ /// @notice Cast a uint256 to a int256, revert on overflow
50
+ /// @param y The uint256 to be casted
51
+ /// @return z The casted integer, now type int256
52
+ function toInt256(uint256 y) internal pure returns (int256 z) {
53
+ require(y < 2 ** 255);
54
+ z = int256(y);
55
+ }
56
+
57
+ /// @notice Cast a uint256 to a int256 and reverses the sign, revert on overflow
58
+ /// @param y The uint256 to be casted
59
+ /// @return z = -y, now type int256
60
+ function revToInt256(uint256 y) internal pure returns (int256 z) {
61
+ require(y < 2 ** 255);
62
+ z = -int256(y);
63
+ }
64
+
65
+ /// @notice Cast a int256 to a uint256 and reverses the sign.
66
+ /// @param y The int256 to be casted
67
+ /// @return z = -y, now type uint256
68
+ function revToUint256(int256 y) internal pure returns (uint256 z) {
69
+ unchecked {
70
+ return type(uint256).max - uint256(y) + 1;
71
+ }
72
+ }
73
+ }