@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.
- package/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiveEndpointUpg.sol +5 -23
- package/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiverAppUpg.sol +2 -5
- package/contracts/LiquidityMining/CrossChainMsg/PendleMsgSendEndpointUpg.sol +6 -20
- package/contracts/LiquidityMining/CrossChainMsg/PendleMsgSenderAppUpg.sol +6 -27
- package/contracts/LiquidityMining/CrossChainMsg/libraries/ExcessivelySafeCall.sol +1 -2
- package/contracts/LiquidityMining/CrossChainMsg/libraries/LayerZeroHelper.sol +1 -1
- package/contracts/LiquidityMining/GaugeController/PendleGaugeControllerBaseUpg.sol +16 -17
- package/contracts/LiquidityMining/GaugeController/PendleGaugeControllerMainchainUpg.sol +6 -7
- package/contracts/LiquidityMining/GaugeController/PendleGaugeControllerSidechainUpg.sol +7 -8
- package/contracts/LiquidityMining/PendleMerkleDistributor.sol +2 -11
- package/contracts/LiquidityMining/VeDistributor/PendleFeeDistributor.sol +14 -37
- package/contracts/LiquidityMining/VeDistributor/PendleFeeDistributorV2.sol +19 -34
- package/contracts/LiquidityMining/VotingController/PendleVotingControllerUpg.sol +4 -14
- package/contracts/LiquidityMining/VotingController/VotingControllerStorageUpg.sol +4 -16
- package/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleMainchain.sol +11 -39
- package/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleSidechain.sol +3 -10
- package/contracts/LiquidityMining/VotingEscrow/VotingEscrowTokenBase.sol +1 -1
- package/contracts/LiquidityMining/libraries/VeBalanceLib.sol +5 -20
- package/contracts/LiquidityMining/libraries/VeHistoryLib.sol +1 -3
- package/contracts/core/Market/MarketMathCore.sol +12 -37
- package/contracts/core/Market/OracleLib.sol +6 -24
- package/contracts/core/Market/PendleExternalRewardDistributor.sol +4 -10
- package/contracts/core/Market/PendleGauge.sol +3 -9
- package/contracts/core/Market/PendleMarket.sol +14 -39
- package/contracts/core/Market/PendleMarketFactory.sol +14 -21
- package/contracts/core/Market/v2/PendleGaugeV2.sol +8 -24
- package/contracts/core/Market/v2/PendleMarketFactoryV2.sol +7 -27
- package/contracts/core/Market/v2/PendleMarketV2.sol +13 -36
- package/contracts/core/Market/v3/PendleMarketFactoryV3.sol +137 -0
- package/contracts/core/Market/v3/PendleMarketV3.sol +360 -0
- package/contracts/core/RewardManager/PendleLinearDistributor.sol +143 -0
- package/contracts/core/RewardManager/RewardManager.sol +14 -7
- package/contracts/core/RewardManager/RewardManagerAbstract.sol +5 -17
- package/contracts/core/StandardizedYield/SYBase.sol +10 -40
- package/contracts/core/StandardizedYield/SYBaseUpg.sol +197 -0
- package/contracts/core/StandardizedYield/SYBaseWithRewards.sol +9 -41
- package/contracts/core/StandardizedYield/SYBaseWithRewardsUpg.sol +88 -0
- package/contracts/core/StandardizedYield/SYUtils.sol +1 -4
- package/contracts/core/StandardizedYield/StEthHelper.sol +3 -9
- package/contracts/core/StandardizedYield/implementations/AaveV3/PendleAaveV3SY.sol +94 -0
- package/contracts/core/StandardizedYield/implementations/AaveV3/libraries/AaveAdapterLib.sol +19 -0
- package/contracts/core/StandardizedYield/implementations/AaveV3/libraries/WadRayMath.sol +126 -0
- package/contracts/core/StandardizedYield/implementations/Ankr/PendleAnkrBNBSY.sol +4 -12
- package/contracts/core/StandardizedYield/implementations/Ape/sAPE.sol +5 -19
- package/contracts/core/StandardizedYield/implementations/BalancerStable/AuraEthxBbAWethSY.sol +4 -14
- package/contracts/core/StandardizedYield/implementations/BalancerStable/AuraSwEthBbAWethSYV2.sol +4 -14
- package/contracts/core/StandardizedYield/implementations/BalancerStable/{PendleAuraWethVethSY.sol → AuraWethVethSYUpg.sol} +13 -20
- package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraBbAWethSwethSY.sol +3 -7
- package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethAnkrethSYV2.sol +12 -29
- package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethRocketEthSYV2.sol +12 -29
- package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethStafiEthSY.sol +12 -29
- package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethWstethSYV2.sol +14 -39
- package/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWstethAnkreth.sol +7 -28
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStableMath.sol +13 -30
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStablePreviewProxy.sol +1 -1
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStablePreviewV4.sol +50 -153
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStablePreviewV5.sol +50 -157
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/BbAPoolHelper.sol +4 -16
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/LinearMath.sol +6 -25
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/LinearPreview.sol +36 -34
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/MetaStable/MetaStableMath.sol +4 -13
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/MetaStable/MetaStablePreview.sol +20 -58
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/PendleAuraBalancerStableLPSYV2.sol +28 -79
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/PendleAuraBalancerStableLPSYV3Upg.sol +310 -0
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/StablePoolUserData.sol +1 -3
- package/contracts/core/StandardizedYield/implementations/BalancerStable/base/StablePreviewBase.sol +2 -6
- package/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenHelper.sol +5 -13
- package/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenSY.sol +9 -29
- package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotRewardHelper.sol +2 -8
- package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatileCommon.sol +1 -5
- package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatileLpHelper.sol +8 -19
- package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatilePreview.sol +7 -25
- package/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/PendleCamelotV1VolatileSY.sol +8 -27
- package/contracts/core/StandardizedYield/implementations/ChainlinkRelayer/PendleChainlinkReceiver.sol +2 -2
- package/contracts/core/StandardizedYield/implementations/ChainlinkRelayer/PendleChainlinkRelayer.sol +4 -9
- package/contracts/core/StandardizedYield/implementations/Convex/PendleCurveFraxUsdcSY.sol +3 -15
- package/contracts/core/StandardizedYield/implementations/Convex/PendleCurveUsdd3CrvSY.sol +5 -23
- package/contracts/core/StandardizedYield/implementations/Convex/base/Curve3CrvPoolHelper.sol +10 -40
- package/contracts/core/StandardizedYield/implementations/Convex/base/CurveFraxUsdcPoolHelper.sol +2 -8
- package/contracts/core/StandardizedYield/implementations/Convex/base/CurveUsdd3CrvPoolHelper.sol +2 -7
- package/contracts/core/StandardizedYield/implementations/Convex/base/PendleConvexLPSY.sol +5 -20
- package/contracts/core/StandardizedYield/implementations/Flux/FluxTokenLib.sol +6 -4
- package/contracts/core/StandardizedYield/implementations/Flux/PendleFluxLendingSY.sol +3 -11
- package/contracts/core/StandardizedYield/implementations/GLP/GLPPreviewHelper.sol +3 -9
- package/contracts/core/StandardizedYield/implementations/GLP/GMTokenPricingHelper.sol +115 -0
- package/contracts/core/StandardizedYield/implementations/GLP/PendleGMV2TokenSY.sol +134 -0
- package/contracts/core/StandardizedYield/implementations/GLP/PendleGlpSY.sol +5 -19
- package/contracts/core/StandardizedYield/implementations/HMX/HLPPricingHelper.sol +3 -4
- package/contracts/core/StandardizedYield/implementations/HMX/PendleHlpSY.sol +18 -25
- package/contracts/core/StandardizedYield/implementations/Kyber/KyberMathHelper.sol +425 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/KyberNftManagerBaseUpg.sol +438 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/PendleKyberElasticSYUpg.sol +155 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/FullMath.sol +123 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/LiqDeltaMath.sol +17 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/LiquidityMath.sol +74 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/MathConstants.sol +19 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/QtyDeltaMath.sol +103 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/QuadMath.sol +31 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/ReinvestmentMath.sol +26 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/SafeCast.sol +73 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/SwapMath.sol +272 -0
- package/contracts/core/StandardizedYield/implementations/Kyber/libraries/TickMath.sol +223 -0
- package/contracts/core/StandardizedYield/implementations/MUX/MlpPricingHelper.sol +26 -0
- package/contracts/core/StandardizedYield/implementations/MUX/PendleMlpSY.sol +195 -0
- package/contracts/core/StandardizedYield/implementations/MantleStakedEth/PendleMantleStakedEthSY.sol +12 -41
- package/contracts/core/StandardizedYield/implementations/MantleStakedEth/PendleOracleForSyProxy.sol +1 -1
- package/contracts/core/StandardizedYield/implementations/PendleArbitrumStakedEthSY.sol +13 -42
- package/contracts/core/StandardizedYield/implementations/PendleBridgedLSDSY.sol +4 -11
- package/contracts/core/StandardizedYield/implementations/PendleERC4626SY.sol +4 -16
- package/contracts/core/StandardizedYield/implementations/PendleEUSDSY.sol +3 -11
- package/contracts/core/StandardizedYield/implementations/PendleGdaiSY.sol +3 -11
- package/contracts/core/StandardizedYield/implementations/PendleLooksStakingSY.sol +5 -18
- package/contracts/core/StandardizedYield/implementations/PendleSfrxEthSY.sol +3 -7
- package/contracts/core/StandardizedYield/implementations/PendleStargateLPSY.sol +5 -18
- package/contracts/core/StandardizedYield/implementations/PendleWbEthSY.sol +3 -10
- package/contracts/core/StandardizedYield/implementations/PendleWstEthSY.sol +4 -12
- package/contracts/core/StandardizedYield/implementations/Silo/PendleSiloWithIncentiveSY.sol +157 -0
- package/contracts/core/StandardizedYield/implementations/Stader/PendleETHXSY.sol +4 -12
- package/contracts/core/StandardizedYield/implementations/Swell/PendleSwETH.sol +4 -12
- package/contracts/core/StandardizedYield/implementations/Thena/PendleThenaSY.sol +9 -29
- package/contracts/core/StandardizedYield/implementations/Thena/ThenaLpHelper.sol +3 -10
- package/contracts/core/StandardizedYield/implementations/Thena/ThenaMath.sol +9 -30
- package/contracts/core/StandardizedYield/implementations/Thena/ThenaPreview.sol +10 -40
- package/contracts/core/YieldContracts/InterestManagerYT.sol +6 -8
- package/contracts/core/YieldContracts/PendlePrincipalToken.sol +1 -1
- package/contracts/core/YieldContracts/PendleYieldContractFactory.sol +2 -3
- package/contracts/core/YieldContracts/PendleYieldToken.sol +17 -44
- package/contracts/core/YieldContractsV2/InterestManagerYTV2.sol +5 -14
- package/contracts/core/YieldContractsV2/PendlePrincipalTokenV2.sol +1 -1
- package/contracts/core/YieldContractsV2/PendleYieldContractFactoryV2.sol +2 -3
- package/contracts/core/YieldContractsV2/PendleYieldTokenV2.sol +13 -48
- package/contracts/core/erc20/PendleERC20.sol +2 -8
- package/contracts/core/erc20/PendleERC20Permit.sol +2 -6
- package/contracts/core/erc20/PendleERC20PermitUpg.sol +82 -0
- package/contracts/core/erc20/PendleERC20Upg.sol +334 -0
- package/contracts/core/libraries/ArrayLib.sol +7 -8
- package/contracts/core/libraries/BaseSplitCodeFactory.sol +1 -6
- package/contracts/core/libraries/Errors.sol +19 -1
- package/contracts/core/libraries/ExpiryUtilsLib.sol +3 -26
- package/contracts/core/libraries/StringLib.sol +5 -21
- package/contracts/core/libraries/TokenHelper.sol +3 -3
- package/contracts/core/libraries/math/LogExpMath.sol +1 -4
- package/contracts/core/libraries/math/PMath.sol +13 -15
- package/contracts/interfaces/AaveV3/IAaveV3AToken.sol +15 -0
- package/contracts/interfaces/AaveV3/IAaveV3Pool.sol +11 -0
- package/contracts/interfaces/Balancer/IComposableStable.sol +3 -4
- package/contracts/interfaces/Balancer/IERC4626LinearPool.sol +2 -10
- package/contracts/interfaces/Balancer/IMetaStablePool.sol +3 -11
- package/contracts/interfaces/Balancer/IVault.sol +3 -8
- package/contracts/interfaces/BinanceEth/IWBETH.sol +1 -1
- package/contracts/interfaces/Camelot/ICamelotNFTFactory.sol +1 -3
- package/contracts/interfaces/Camelot/ICamelotNFTHandler.sol +2 -10
- package/contracts/interfaces/Camelot/ICamelotNitroPool.sol +0 -1
- package/contracts/interfaces/Camelot/ICamelotNitroPoolFactory.sol +3 -12
- package/contracts/interfaces/Camelot/ICamelotPair.sol +5 -25
- package/contracts/interfaces/Camelot/ICamelotRouter.sol +1 -5
- package/contracts/interfaces/Camelot/IXGrail.sol +3 -11
- package/contracts/interfaces/ConvexCurve/IBooster.sol +1 -3
- package/contracts/interfaces/Curve/ICrvPool.sol +3 -12
- package/contracts/interfaces/Curve/ITriCrvPool.sol +2 -9
- package/contracts/interfaces/Flux/IFluxErc20.sol +1 -1
- package/contracts/interfaces/Flux/IFluxInterestRateModel.sol +1 -5
- package/contracts/interfaces/GMX/IGMXPriceHelper.sol +6 -0
- package/contracts/interfaces/GMX/IGMXVault.sol +2 -9
- package/contracts/interfaces/GMX/IRewardRouterV2.sol +1 -4
- package/contracts/interfaces/HMX/IHLPStaking.sol +1 -1
- package/contracts/interfaces/HMX/IHMXCalculator.sol +1 -1
- package/contracts/interfaces/HMX/IHMXCompounder.sol +1 -1
- package/contracts/interfaces/HMX/IHMXStaking.sol +1 -1
- package/contracts/interfaces/HMX/IHMXVester.sol +1 -1
- package/contracts/interfaces/IApeStaking.sol +3 -9
- package/contracts/interfaces/IBenQiInterestRateModel.sol +1 -5
- package/contracts/interfaces/IDiamondCut.sol +1 -5
- package/contracts/interfaces/IDiamondLoupe.sol +1 -3
- package/contracts/interfaces/ILayerZeroReceiver.sol +1 -6
- package/contracts/interfaces/IPActionAddRemoveLiqV3.sol +10 -2
- package/contracts/interfaces/IPActionInfoStatic.sol +4 -7
- package/contracts/interfaces/IPActionMarketAuxStatic.sol +5 -9
- package/contracts/interfaces/IPActionMarketCoreStatic.sol +118 -58
- package/contracts/interfaces/IPActionMintRedeemStatic.sol +38 -21
- package/contracts/interfaces/IPActionMiscV3.sol +51 -26
- package/contracts/interfaces/IPActionStorageStatic.sol +5 -1
- package/contracts/interfaces/IPAllActionTypeV3.sol +1 -0
- package/contracts/interfaces/IPBulkSeller.sol +49 -0
- package/contracts/interfaces/IPBulkSellerFactory.sol +12 -0
- package/contracts/interfaces/IPBulkSellerSYCallback.sol +6 -0
- package/contracts/interfaces/IPFeeDistributor.sol +1 -3
- package/contracts/interfaces/IPFeeDistributorV2.sol +8 -7
- package/contracts/interfaces/IPGaugeController.sol +2 -8
- package/contracts/interfaces/IPGaugeControllerMainchain.sol +1 -5
- package/contracts/interfaces/IPInterestManagerYT.sol +3 -3
- package/contracts/interfaces/IPInterestManagerYTV2.sol +1 -4
- package/contracts/interfaces/IPLimitRouter.sol +24 -19
- package/contracts/interfaces/IPLinearDistributor.sol +21 -0
- package/contracts/interfaces/IPMarket.sol +4 -17
- package/contracts/interfaces/IPMarketFactory.sol +2 -13
- package/contracts/interfaces/IPMarketFactoryV3.sol +24 -0
- package/contracts/interfaces/IPMarketV3.sol +8 -0
- package/contracts/interfaces/IPOffchainStorage.sol +11 -0
- package/contracts/interfaces/IPPriceFeed.sol +6 -0
- package/contracts/interfaces/IPPtOracle.sol +2 -9
- package/contracts/interfaces/IPRouterHelper.sol +11 -7
- package/contracts/interfaces/IPRouterStatic.sol +1 -3
- package/contracts/interfaces/IPVotingController.sol +7 -19
- package/contracts/interfaces/IPVotingEscrowMainchain.sol +2 -8
- package/contracts/interfaces/IPYieldToken.sol +2 -8
- package/contracts/interfaces/IPYieldTokenV2.sol +1 -6
- package/contracts/interfaces/IPendlePreviewHelper.sol +2 -8
- package/contracts/interfaces/IRewardManager.sol +1 -4
- package/contracts/interfaces/IStETH.sol +1 -4
- package/contracts/interfaces/IStandardizedYield.sol +9 -16
- package/contracts/interfaces/IStargateLP.sol +0 -3
- package/contracts/interfaces/IStargateRouter.sol +1 -5
- package/contracts/interfaces/Kyber/IKyberElasticFactory.sol +157 -0
- package/contracts/interfaces/Kyber/IKyberElasticPool.sol +101 -0
- package/contracts/interfaces/Kyber/IKyberElasticRouter.sol +98 -0
- package/contracts/interfaces/Kyber/IKyberLiquidityMining.sol +209 -0
- package/contracts/interfaces/Kyber/IKyberMathHelper.sol +28 -0
- package/contracts/interfaces/Kyber/IKyberPositionManager.sol +179 -0
- package/contracts/interfaces/Lybra/IEUSD.sol +1 -1
- package/contracts/interfaces/MUX/IMUXRewardRouter.sol +139 -0
- package/contracts/interfaces/Silo/ISilo.sol +298 -0
- package/contracts/interfaces/Silo/ISiloIncentiveController.sol +16 -0
- package/contracts/interfaces/Silo/ISiloLens.sol +6 -0
- package/contracts/interfaces/Stader/IStaderStakeManager.sol +2 -2
- package/contracts/interfaces/Thena/IThenaFactory.sol +1 -5
- package/contracts/interfaces/Thena/IThenaGaugeV2.sol +1 -2
- package/contracts/interfaces/Thena/IThenaPair.sol +3 -5
- package/contracts/limit/LimitMathCore.sol +69 -60
- package/contracts/limit/{PendleOrderMixin.sol → LimitRouterBase.sol} +96 -79
- package/contracts/limit/PendleLimitRouter.sol +9 -13
- package/contracts/offchain-helpers/AutomateReady.sol +17 -32
- package/contracts/offchain-helpers/BaseSplitCodeFactoryContract.sol +6 -3
- package/contracts/offchain-helpers/BoringLpSeller.sol +4 -17
- package/contracts/offchain-helpers/BoringPtSeller.sol +2 -7
- package/contracts/offchain-helpers/Broadcaster.sol +1 -1
- package/contracts/offchain-helpers/BytesLib.sol +26 -14
- package/contracts/offchain-helpers/EmptyUUPS.sol +0 -1
- package/contracts/offchain-helpers/LegacyNFTHelper.sol +4 -23
- package/contracts/offchain-helpers/LimitBackendHelper.sol +25 -16
- package/contracts/offchain-helpers/MarketExchangeRateLib.sol +2 -13
- package/contracts/offchain-helpers/Multicall2.sol +2 -7
- package/contracts/offchain-helpers/PendleMulticallV1.sol +7 -7
- package/contracts/offchain-helpers/PendleMulticallV2.sol +12 -13
- package/contracts/offchain-helpers/PendleOffchainStorage.sol +59 -0
- package/contracts/offchain-helpers/SimulateHelper.sol +6 -7
- package/contracts/offchain-helpers/errors/SDKErrorsDirectory.sol +15 -1
- package/contracts/oracles/PendleLpOracleLib.sol +9 -10
- package/contracts/oracles/PendlePtOracle.sol +8 -19
- package/contracts/oracles/PendlePtOracleLib.sol +8 -13
- package/contracts/oracles/samples/PendleLpGlpOracle.sol +6 -10
- package/contracts/oracles/samples/PendlePtGlpOracle.sol +6 -10
- package/contracts/oracles/samples/PendlePtUsdChainlinkOracle.sol +8 -15
- package/contracts/router/ActionAddRemoveLiqV3.sol +147 -52
- package/contracts/router/ActionCallbackV3.sol +11 -4
- package/contracts/router/ActionMiscV3.sol +43 -33
- package/contracts/router/ActionSwapPTV3.sol +18 -6
- package/contracts/router/ActionSwapYTV3.sol +42 -14
- package/contracts/router/PendleRouterHelper.sol +72 -40
- package/contracts/router/PendleRouterV3.sol +50 -50
- package/contracts/router/base/ActionBase.sol +86 -43
- package/contracts/router/base/CallbackHelper.sol +18 -20
- package/contracts/router/base/MarketApproxLib.sol +36 -32
- package/contracts/router/swap-aggregator/PendleSwap.sol +31 -7
- package/contracts/router/swap-aggregator/kyberswap/interfaces/IAggregationExecutorOptimistic.sol +63 -0
- package/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelper.sol +314 -0
- package/contracts/router/swap-aggregator/kyberswap/interfaces/IExecutorHelperL2.sol +560 -0
- package/contracts/router/swap-aggregator/kyberswap/{IMetaAggregationRouterV2.sol → interfaces/IMetaAggregationRouterV2.sol} +11 -6
- package/contracts/router/swap-aggregator/kyberswap/{KyberInputScalingHelper.sol → l1-contracts/InputScalingHelper.sol} +70 -19
- package/contracts/router/swap-aggregator/kyberswap/{ScalingDataLib.sol → l1-contracts/ScalingDataLib.sol} +111 -53
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/BytesHelper.sol +29 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataReader.sol +149 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/CalldataWriter.sol +118 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/Common.sol +42 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/DexScaler.sol +382 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/ExecutorReader.sol +61 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/InputScalingHelperL2.sol +329 -0
- package/contracts/router/swap-aggregator/kyberswap/l2-contracts/ScalingDataL2Lib.sol +173 -0
- package/contracts/router/swap-aggregator/oneinch/I1inchAggregationRouterV5.sol +4 -10
- package/contracts/router/swap-aggregator/oneinch/OneInchAggregationRouterHelper.sol +20 -14
- package/deployments/1-core.json +5 -2
- package/deployments/1-markets/EPENDLE-SEP2024.json +12 -0
- package/deployments/1-markets/SFRAX-MARCH2024.json +10 -0
- package/deployments/1-markets/SILO-CRVUSD-MARCH2024.json +10 -0
- package/deployments/10-core.json +6 -3
- package/deployments/42161-core.json +5 -2
- package/deployments/42161-markets/AAVE-USDC-JUNE2024.json +11 -0
- package/deployments/42161-markets/ARBSILO-USDC-FEB2024.json +10 -0
- package/deployments/42161-markets/GM-ARB-USDC-MARCH2024.json +10 -0
- package/deployments/42161-markets/KYBER-AXLWSTETH-WSTETH-MARCH2024.json +10 -0
- package/deployments/42161-markets/MLP-MARCH2024.json +10 -0
- package/deployments/42161-markets/WSTETH-ARBITRUM-MARCH2024.json +11 -0
- package/deployments/42161-markets/WSTETHSILO-ETH-MARCH2024.json +11 -0
- package/deployments/56-core.json +5 -2
- package/deployments/merkle-distribution/2023-10-26.json +7300 -0
- package/deployments/merkle-distribution/2023-11-30.json +7730 -0
- package/package.json +8 -8
- package/contracts/limit/helpers/ArgumentsDecoder.sol +0 -47
- package/contracts/limit/helpers/Permitable.sol +0 -48
- package/contracts/limit/helpers/RevertReasonParser.sol +0 -75
- package/contracts/offchain-helpers/ChainlinkRelayerGelato.sol +0 -37
- package/contracts/offchain-helpers/PtAndLpToAsset.sol +0 -62
- package/contracts/offchain-helpers/router-static/PendleRouterStatic.sol +0 -19
- package/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol +0 -112
- package/contracts/offchain-helpers/router-static/base/ActionLimitOrdersStatic.sol +0 -145
- package/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol +0 -171
- package/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol +0 -582
- package/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol +0 -116
- package/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol +0 -64
- package/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol +0 -53
- package/contracts/offchain-helpers/router-static/base/StorageLayout.sol +0 -18
- package/contracts/router/swap-aggregator/kyberswap/IExecutorHelper.sol +0 -231
- package/deployments/1-markets/BALANCER-LP-AURA-VETH-WETH-SEP2024.json +0 -8
- /package/contracts/router/swap-aggregator/kyberswap/{IAggregationExecutor.sol → interfaces/IAggregationExecutor.sol} +0 -0
- /package/deployments/1-markets/{BALANCER-LP-AURA-BBAWETHSWETH-SEP-26-2024.json → deprecated/BALANCER-LP-AURA-BBAWETHSWETH-SEP-26-2024.json} +0 -0
- /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,438 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";
|
|
5
|
+
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
|
|
6
|
+
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
|
|
7
|
+
import "../../../../interfaces/Kyber/IKyberLiquidityMining.sol";
|
|
8
|
+
import "../../../../interfaces/Kyber/IKyberElasticPool.sol";
|
|
9
|
+
import "../../../../interfaces/Kyber/IKyberElasticRouter.sol";
|
|
10
|
+
import "../../../../interfaces/Kyber/IKyberElasticFactory.sol";
|
|
11
|
+
import "../../../../interfaces/Kyber/IKyberPositionManager.sol";
|
|
12
|
+
import "../../../../interfaces/Kyber/IKyberMathHelper.sol";
|
|
13
|
+
import "../../../libraries/TokenHelper.sol";
|
|
14
|
+
import "../../../libraries/ArrayLib.sol";
|
|
15
|
+
import "../../../libraries/math/PMath.sol";
|
|
16
|
+
|
|
17
|
+
abstract contract KyberNftManagerBaseUpg is Initializable, TokenHelper, IERC721Receiver {
|
|
18
|
+
using PMath for uint256;
|
|
19
|
+
|
|
20
|
+
enum KyberLiquidityMiningStatus {
|
|
21
|
+
ACTIVE,
|
|
22
|
+
INACTIVE, // phase settled or range removed
|
|
23
|
+
EMERGENCY
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
error InvalidNft(uint256 tokenId);
|
|
27
|
+
|
|
28
|
+
uint256 internal constant MINIMUM_LIQUIDITY = 10 ** 3;
|
|
29
|
+
uint256 internal constant DEFAULT_POSITION_TOKEN_ID = type(uint256).max;
|
|
30
|
+
|
|
31
|
+
address internal immutable pool;
|
|
32
|
+
int24 internal immutable tickLower;
|
|
33
|
+
int24 internal immutable tickUpper;
|
|
34
|
+
|
|
35
|
+
address internal immutable positionManager;
|
|
36
|
+
address internal immutable router;
|
|
37
|
+
address internal immutable factory;
|
|
38
|
+
|
|
39
|
+
address internal immutable liquidityMining;
|
|
40
|
+
uint256 internal immutable farmId;
|
|
41
|
+
uint256 internal immutable rangeId;
|
|
42
|
+
|
|
43
|
+
address internal immutable token0;
|
|
44
|
+
address internal immutable token1;
|
|
45
|
+
uint24 internal immutable fee;
|
|
46
|
+
|
|
47
|
+
address internal immutable kyberMathHelper;
|
|
48
|
+
|
|
49
|
+
uint256 public positionTokenId;
|
|
50
|
+
|
|
51
|
+
uint256[100] private __gap;
|
|
52
|
+
|
|
53
|
+
struct KyberNftManagerImmutableParams {
|
|
54
|
+
address pool;
|
|
55
|
+
int24 tickLower;
|
|
56
|
+
int24 tickUpper;
|
|
57
|
+
// position related
|
|
58
|
+
address positionManager;
|
|
59
|
+
address router;
|
|
60
|
+
address factory;
|
|
61
|
+
// farming related
|
|
62
|
+
address liquidityMining;
|
|
63
|
+
uint256 farmId;
|
|
64
|
+
uint256 rangeId;
|
|
65
|
+
// math helper
|
|
66
|
+
address kyberMathHelper;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
constructor(KyberNftManagerImmutableParams memory params) {
|
|
70
|
+
pool = params.pool;
|
|
71
|
+
tickLower = params.tickLower;
|
|
72
|
+
tickUpper = params.tickUpper;
|
|
73
|
+
|
|
74
|
+
positionManager = params.positionManager;
|
|
75
|
+
router = params.router;
|
|
76
|
+
factory = params.factory;
|
|
77
|
+
|
|
78
|
+
liquidityMining = params.liquidityMining;
|
|
79
|
+
farmId = params.farmId;
|
|
80
|
+
rangeId = params.rangeId;
|
|
81
|
+
|
|
82
|
+
kyberMathHelper = params.kyberMathHelper;
|
|
83
|
+
|
|
84
|
+
token0 = IKyberElasticPool(pool).token0();
|
|
85
|
+
token1 = IKyberElasticPool(pool).token1();
|
|
86
|
+
fee = IKyberElasticPool(pool).swapFeeUnits();
|
|
87
|
+
|
|
88
|
+
_validateFarmInfo(pool, tickLower, tickUpper, liquidityMining, farmId, rangeId);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function __KyberNftManagerBaseUpg_init() internal onlyInitializing {
|
|
92
|
+
_safeApproveInf(token0, positionManager);
|
|
93
|
+
_safeApproveInf(token1, positionManager);
|
|
94
|
+
_safeApproveInf(token0, router);
|
|
95
|
+
_safeApproveInf(token1, router);
|
|
96
|
+
positionTokenId = DEFAULT_POSITION_TOKEN_ID;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/*///////////////////////////////////////////////////////////////
|
|
100
|
+
NFT RELATED
|
|
101
|
+
//////////////////////////////////////////////////////////////*/
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
*
|
|
105
|
+
* @param tokenId The tokenId of the position to be deposited
|
|
106
|
+
* @dev in case position not initialized, a minimum amount of liquidity will be locked
|
|
107
|
+
* to prevent Kyber pool ticks from being deleted
|
|
108
|
+
*/
|
|
109
|
+
function _depositNft(uint256 tokenId) internal returns (uint256 sharesMinted) {
|
|
110
|
+
uint128 liquidity = _validateTokenIdAndGetLiquidity(tokenId);
|
|
111
|
+
IERC721(positionManager).safeTransferFrom(msg.sender, address(this), tokenId);
|
|
112
|
+
|
|
113
|
+
if (positionTokenId == DEFAULT_POSITION_TOKEN_ID) {
|
|
114
|
+
positionTokenId = tokenId;
|
|
115
|
+
require(liquidity > MINIMUM_LIQUIDITY, "minimum liquidity not met");
|
|
116
|
+
sharesMinted = liquidity - MINIMUM_LIQUIDITY;
|
|
117
|
+
|
|
118
|
+
// It's okay to revert due to Kyber emergency or inactive farm in this initialization step
|
|
119
|
+
_depositNftToFarm();
|
|
120
|
+
} else {
|
|
121
|
+
// Tho most of the case sharesMinted = liquidity
|
|
122
|
+
// should re-calc it to prevent any precision issue
|
|
123
|
+
sharesMinted = _mergeNft(tokenId, liquidity);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function _withdrawNft(uint256 amountSharesToWithdraw, address recipient) internal returns (uint256 tokenId) {
|
|
128
|
+
(uint256 amount0, uint256 amount1) = _removeLiquidity(amountSharesToWithdraw.Uint128());
|
|
129
|
+
return _mintKyberNft(amount0, amount1, recipient);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function _mergeNft(uint256 tokenId, uint128 liquidity) private returns (uint256 sharesMinted) {
|
|
133
|
+
(uint256 amount0, uint256 amount1, ) = IKyberPositionManager(positionManager).removeLiquidity(
|
|
134
|
+
IKyberPositionManager.RemoveLiquidityParams({
|
|
135
|
+
tokenId: tokenId,
|
|
136
|
+
liquidity: liquidity,
|
|
137
|
+
amount0Min: 0,
|
|
138
|
+
amount1Min: 0,
|
|
139
|
+
deadline: type(uint256).max
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
_collectPositionManagerFloatingTokens(address(this));
|
|
144
|
+
|
|
145
|
+
// Kyber position is now updated with latest rTokenOwed
|
|
146
|
+
// We will now burn the rewards back to users
|
|
147
|
+
if (_getRTokenOwed(tokenId) > 0) _burnRToken(tokenId, msg.sender);
|
|
148
|
+
|
|
149
|
+
IKyberPositionManager(positionManager).burn(tokenId);
|
|
150
|
+
return _addLiquidity(amount0, amount1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/*///////////////////////////////////////////////////////////////
|
|
154
|
+
ZAP RELATED
|
|
155
|
+
//////////////////////////////////////////////////////////////*/
|
|
156
|
+
|
|
157
|
+
function _zapIn(address tokenIn, uint256 amountTokenIn) internal returns (uint256 amountSharesOut) {
|
|
158
|
+
uint256 amountToSwap = IKyberMathHelper(kyberMathHelper).getSingleSidedSwapAmount(
|
|
159
|
+
pool,
|
|
160
|
+
amountTokenIn,
|
|
161
|
+
tokenIn == token0,
|
|
162
|
+
tickLower,
|
|
163
|
+
tickUpper
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
address tokenOut = tokenIn == token0 ? token1 : token0;
|
|
167
|
+
uint256 amountOut = _swap(tokenIn, tokenOut, amountToSwap);
|
|
168
|
+
|
|
169
|
+
(uint256 amount0, uint256 amount1) = tokenIn == token0
|
|
170
|
+
? (amountTokenIn - amountToSwap, amountOut)
|
|
171
|
+
: (amountOut, amountTokenIn - amountToSwap);
|
|
172
|
+
|
|
173
|
+
return _addLiquidity(amount0, amount1);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function _zapOut(address tokenOut, uint256 amountSharesToRedeem) internal returns (uint256 amountTokenOut) {
|
|
177
|
+
(uint256 amount0, uint256 amount1) = _removeLiquidity(amountSharesToRedeem.Uint128());
|
|
178
|
+
bool isToken0 = tokenOut == token0;
|
|
179
|
+
address tokenIn = isToken0 ? token1 : token0;
|
|
180
|
+
uint256 amountIn = isToken0 ? amount1 : amount0;
|
|
181
|
+
uint256 amountOut = _swap(tokenIn, tokenOut, amountIn);
|
|
182
|
+
|
|
183
|
+
return amountOut + (isToken0 ? amount0 : amount1);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/*///////////////////////////////////////////////////////////////
|
|
187
|
+
REWARD RELATED
|
|
188
|
+
//////////////////////////////////////////////////////////////*/
|
|
189
|
+
|
|
190
|
+
function _claimKyberRewards() internal {
|
|
191
|
+
uint256 tokenId = positionTokenId;
|
|
192
|
+
|
|
193
|
+
// NOTE: Kyber LM reverts if there's no rTOKEN to be burned
|
|
194
|
+
// Kyber also doesnt allow calling syncFee() for unauthorized address so there is no good way to check if there's any rTOKEN to be burned
|
|
195
|
+
// Thus IKyberLiquidityMining.claimFee() should only be called after this painful process of [withdraw nft -> syncFee -> deposit -> claimFee]
|
|
196
|
+
// smh very gas-inefficient
|
|
197
|
+
|
|
198
|
+
KyberLiquidityMiningStatus status = _getKyberLiquidityMiningStatus();
|
|
199
|
+
bool nftInLm = _isNftInLiquidityMining();
|
|
200
|
+
|
|
201
|
+
if (nftInLm) {
|
|
202
|
+
_withdrawNftFromFarm(status); // withdraw nft (without emergency) should also claim reward
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
bool shouldBurnRToken = IKyberPositionManager(positionManager).syncFeeGrowth(tokenId) > 0;
|
|
206
|
+
|
|
207
|
+
if (!shouldBurnRToken) {
|
|
208
|
+
shouldBurnRToken = _getRTokenOwed(tokenId) > 0;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
if (shouldBurnRToken) {
|
|
212
|
+
_burnRToken(tokenId, address(this));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (status == KyberLiquidityMiningStatus.ACTIVE) {
|
|
216
|
+
_depositNftToFarm();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function _depositNftToFarm() internal {
|
|
221
|
+
uint256 tokenId = positionTokenId;
|
|
222
|
+
IERC721(positionManager).approve(liquidityMining, tokenId);
|
|
223
|
+
IKyberLiquidityMining(liquidityMining).deposit(farmId, rangeId, ArrayLib.create(tokenId), address(this));
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function _withdrawNftFromFarm(KyberLiquidityMiningStatus status) internal {
|
|
227
|
+
if (status == KyberLiquidityMiningStatus.EMERGENCY) {
|
|
228
|
+
IKyberLiquidityMining(liquidityMining).withdrawEmergency(ArrayLib.create(positionTokenId));
|
|
229
|
+
} else {
|
|
230
|
+
IKyberLiquidityMining(liquidityMining).withdraw(farmId, ArrayLib.create(positionTokenId));
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/*///////////////////////////////////////////////////////////////
|
|
235
|
+
BASE FUNCTIONS
|
|
236
|
+
//////////////////////////////////////////////////////////////*/
|
|
237
|
+
|
|
238
|
+
function _addLiquidity(uint256 amount0, uint256 amount1) private returns (uint128 liquidity) {
|
|
239
|
+
uint256 tokenId = positionTokenId;
|
|
240
|
+
assert(tokenId != DEFAULT_POSITION_TOKEN_ID);
|
|
241
|
+
|
|
242
|
+
(liquidity, , , ) = IKyberPositionManager(positionManager).addLiquidity(
|
|
243
|
+
IKyberPositionManager.IncreaseLiquidityParams({
|
|
244
|
+
tokenId: tokenId,
|
|
245
|
+
amount0Desired: amount0,
|
|
246
|
+
amount1Desired: amount1,
|
|
247
|
+
amount0Min: 0,
|
|
248
|
+
amount1Min: 0,
|
|
249
|
+
deadline: type(uint256).max,
|
|
250
|
+
ticksPrevious: [tickLower, tickUpper] // doesnt matter as the ticks should always be initialized
|
|
251
|
+
})
|
|
252
|
+
);
|
|
253
|
+
|
|
254
|
+
if (_isAddLiquidityValid()) {
|
|
255
|
+
IKyberLiquidityMining(liquidityMining).addLiquidity(farmId, rangeId, ArrayLib.create(tokenId));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function _removeLiquidity(uint128 liquidity) private returns (uint256 amount0, uint256 amount1) {
|
|
260
|
+
uint256 tokenId = positionTokenId;
|
|
261
|
+
assert(tokenId != DEFAULT_POSITION_TOKEN_ID);
|
|
262
|
+
|
|
263
|
+
if (_isNftInLiquidityMining()) {
|
|
264
|
+
uint256 prevBalance0 = _selfBalance(token0);
|
|
265
|
+
uint256 prevBalance1 = _selfBalance(token1);
|
|
266
|
+
IKyberLiquidityMining(liquidityMining).removeLiquidity(
|
|
267
|
+
tokenId,
|
|
268
|
+
liquidity,
|
|
269
|
+
0,
|
|
270
|
+
0,
|
|
271
|
+
type(uint256).max,
|
|
272
|
+
false,
|
|
273
|
+
false
|
|
274
|
+
);
|
|
275
|
+
amount0 = _selfBalance(token0) - prevBalance0;
|
|
276
|
+
amount1 = _selfBalance(token1) - prevBalance1;
|
|
277
|
+
} else {
|
|
278
|
+
(amount0, amount1, ) = IKyberPositionManager(positionManager).removeLiquidity(
|
|
279
|
+
IKyberPositionManager.RemoveLiquidityParams({
|
|
280
|
+
tokenId: tokenId,
|
|
281
|
+
liquidity: liquidity,
|
|
282
|
+
amount0Min: 0,
|
|
283
|
+
amount1Min: 0,
|
|
284
|
+
deadline: type(uint256).max
|
|
285
|
+
})
|
|
286
|
+
);
|
|
287
|
+
_collectPositionManagerFloatingTokens(address(this));
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function _mintKyberNft(uint256 amount0, uint256 amount1, address recipient) private returns (uint256 tokenId) {
|
|
292
|
+
(tokenId, , , ) = IKyberPositionManager(positionManager).mint(
|
|
293
|
+
IKyberPositionManager.MintParams({
|
|
294
|
+
token0: token0,
|
|
295
|
+
token1: token1,
|
|
296
|
+
fee: fee,
|
|
297
|
+
tickLower: tickLower,
|
|
298
|
+
tickUpper: tickUpper,
|
|
299
|
+
ticksPrevious: [tickLower, tickUpper], // does matter, explained in _addLiquidity
|
|
300
|
+
amount0Desired: amount0,
|
|
301
|
+
amount1Desired: amount1,
|
|
302
|
+
amount0Min: 0,
|
|
303
|
+
amount1Min: 0,
|
|
304
|
+
recipient: recipient,
|
|
305
|
+
deadline: type(uint256).max
|
|
306
|
+
})
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function _swap(address tokenIn, address tokenOut, uint256 amountIn) private returns (uint256) {
|
|
311
|
+
if (amountIn == 0) return 0;
|
|
312
|
+
return
|
|
313
|
+
IKyberElasticRouter(router).swapExactInputSingle(
|
|
314
|
+
IKyberElasticRouter.ExactInputSingleParams({
|
|
315
|
+
tokenIn: tokenIn,
|
|
316
|
+
tokenOut: tokenOut,
|
|
317
|
+
fee: fee,
|
|
318
|
+
recipient: address(this),
|
|
319
|
+
deadline: type(uint256).max,
|
|
320
|
+
amountIn: amountIn,
|
|
321
|
+
minAmountOut: 0,
|
|
322
|
+
limitSqrtP: 0 // Kyber router shall assign the appropriate inf price limit if set to 0
|
|
323
|
+
})
|
|
324
|
+
);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function _burnRToken(uint256 tokenId, address receiver) private {
|
|
328
|
+
IKyberPositionManager(positionManager).burnRTokens(
|
|
329
|
+
IKyberPositionManager.BurnRTokenParams({
|
|
330
|
+
tokenId: tokenId,
|
|
331
|
+
amount0Min: 0,
|
|
332
|
+
amount1Min: 0,
|
|
333
|
+
deadline: type(uint256).max
|
|
334
|
+
})
|
|
335
|
+
);
|
|
336
|
+
_collectPositionManagerFloatingTokens(receiver);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
function _getRTokenOwed(uint256 tokenId) private view returns (uint256) {
|
|
340
|
+
(IKyberPositionManager.Position memory position, ) = IKyberPositionManager(positionManager).positions(tokenId);
|
|
341
|
+
return position.rTokenOwed;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/*///////////////////////////////////////////////////////////////
|
|
345
|
+
VALIDATION FUNCTIONS
|
|
346
|
+
//////////////////////////////////////////////////////////////*/
|
|
347
|
+
|
|
348
|
+
function _validateFarmInfo(
|
|
349
|
+
address _pool,
|
|
350
|
+
int24 _tickLower,
|
|
351
|
+
int24 _tickUpper,
|
|
352
|
+
address _liquidityMining,
|
|
353
|
+
uint256 _farmId,
|
|
354
|
+
uint256 _rangeId
|
|
355
|
+
) private view {
|
|
356
|
+
(address farmPool, IKyberLiquidityMining.RangeInfo[] memory farmRanges, , , , , ) = IKyberLiquidityMining(
|
|
357
|
+
_liquidityMining
|
|
358
|
+
).getFarm(_farmId);
|
|
359
|
+
|
|
360
|
+
require(
|
|
361
|
+
_pool == farmPool &&
|
|
362
|
+
_tickLower == farmRanges[_rangeId].tickLower &&
|
|
363
|
+
_tickUpper == farmRanges[_rangeId].tickUpper,
|
|
364
|
+
"invalid pool info"
|
|
365
|
+
);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function _getKyberLiquidityMiningStatus() private view returns (KyberLiquidityMiningStatus) {
|
|
369
|
+
if (IKyberLiquidityMining(liquidityMining).emergencyEnabled()) {
|
|
370
|
+
return KyberLiquidityMiningStatus.EMERGENCY;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
(
|
|
374
|
+
,
|
|
375
|
+
IKyberLiquidityMining.RangeInfo[] memory ranges,
|
|
376
|
+
IKyberLiquidityMining.PhaseInfo memory phase,
|
|
377
|
+
,
|
|
378
|
+
,
|
|
379
|
+
,
|
|
380
|
+
|
|
381
|
+
) = IKyberLiquidityMining(liquidityMining).getFarm(farmId); // expensive call urg... but no other way
|
|
382
|
+
|
|
383
|
+
if (rangeId >= ranges.length || ranges[rangeId].isRemoved) {
|
|
384
|
+
return KyberLiquidityMiningStatus.INACTIVE;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
if (phase.endTime < block.timestamp || phase.isSettled) {
|
|
388
|
+
return KyberLiquidityMiningStatus.INACTIVE;
|
|
389
|
+
}
|
|
390
|
+
return KyberLiquidityMiningStatus.ACTIVE;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
function _isNftInLiquidityMining() private view returns (bool) {
|
|
394
|
+
return IERC721(positionManager).ownerOf(positionTokenId) == liquidityMining;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function _isAddLiquidityValid() private view returns (bool) {
|
|
398
|
+
return _getKyberLiquidityMiningStatus() == KyberLiquidityMiningStatus.ACTIVE && _isNftInLiquidityMining();
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
function _validateTokenIdAndGetLiquidity(uint256 tokenId) private view returns (uint128 liquidity) {
|
|
402
|
+
(
|
|
403
|
+
IKyberPositionManager.Position memory position,
|
|
404
|
+
IKyberPositionManager.PoolInfo memory poolInfo
|
|
405
|
+
) = IKyberPositionManager(positionManager).positions(tokenId);
|
|
406
|
+
|
|
407
|
+
if (IKyberElasticFactory(factory).getPool(poolInfo.token0, poolInfo.token1, poolInfo.fee) != pool) {
|
|
408
|
+
revert InvalidNft(tokenId);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (position.tickLower != tickLower || position.tickUpper != tickUpper) {
|
|
412
|
+
revert InvalidNft(tokenId);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
return position.liquidity;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/*///////////////////////////////////////////////////////////////
|
|
419
|
+
MISC FUNCTIONS
|
|
420
|
+
//////////////////////////////////////////////////////////////*/
|
|
421
|
+
|
|
422
|
+
function _collectPositionManagerFloatingTokens(address receiver) private {
|
|
423
|
+
IKyberPositionManager(positionManager).transferAllTokens(
|
|
424
|
+
token0,
|
|
425
|
+
IERC20(token0).balanceOf(positionManager),
|
|
426
|
+
receiver
|
|
427
|
+
);
|
|
428
|
+
IKyberPositionManager(positionManager).transferAllTokens(
|
|
429
|
+
token1,
|
|
430
|
+
IERC20(token1).balanceOf(positionManager),
|
|
431
|
+
receiver
|
|
432
|
+
);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
function onERC721Received(address, address, uint256, bytes calldata) external pure returns (bytes4) {
|
|
436
|
+
return IERC721Receiver.onERC721Received.selector;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "./KyberNftManagerBaseUpg.sol";
|
|
5
|
+
import "../../SYBaseWithRewardsUpg.sol";
|
|
6
|
+
|
|
7
|
+
contract PendleKyberElasticSYUpg is SYBaseWithRewardsUpg, KyberNftManagerBaseUpg {
|
|
8
|
+
using ArrayLib for address[];
|
|
9
|
+
|
|
10
|
+
event DepositNft(address indexed user, uint256 indexed tokenId, uint256 amountSharesOut);
|
|
11
|
+
|
|
12
|
+
event WithdrawNft(address indexed user, uint256 indexed tokenId, uint256 amountSharesToWithdraw);
|
|
13
|
+
|
|
14
|
+
address[] internal allRewardTokens;
|
|
15
|
+
|
|
16
|
+
constructor(
|
|
17
|
+
KyberNftManagerImmutableParams memory params
|
|
18
|
+
) KyberNftManagerBaseUpg(params) SYBaseUpg(params.pool) initializer {}
|
|
19
|
+
|
|
20
|
+
function initialize(
|
|
21
|
+
string memory _name,
|
|
22
|
+
string memory _symbol,
|
|
23
|
+
address[] memory _initialRewardTokens
|
|
24
|
+
) external initializer {
|
|
25
|
+
allRewardTokens = _initialRewardTokens;
|
|
26
|
+
__SYBaseUpg_init(_name, _symbol);
|
|
27
|
+
__KyberNftManagerBaseUpg_init();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function depositNft(uint256 tokenId) external returns (uint256 amountSharesOut) {
|
|
31
|
+
amountSharesOut = _depositNft(tokenId);
|
|
32
|
+
_mint(msg.sender, amountSharesOut);
|
|
33
|
+
emit DepositNft(msg.sender, tokenId, amountSharesOut);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function withdrawNft(uint256 amountSharesToWithdraw) external returns (uint256 tokenId) {
|
|
37
|
+
_burn(msg.sender, amountSharesToWithdraw);
|
|
38
|
+
tokenId = _withdrawNft(amountSharesToWithdraw, msg.sender);
|
|
39
|
+
emit WithdrawNft(msg.sender, tokenId, amountSharesToWithdraw);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/*///////////////////////////////////////////////////////////////
|
|
43
|
+
DEPOSIT/REDEEM USING BASE TOKENS
|
|
44
|
+
//////////////////////////////////////////////////////////////*/
|
|
45
|
+
|
|
46
|
+
function _deposit(
|
|
47
|
+
address tokenIn,
|
|
48
|
+
uint256 amountDeposited
|
|
49
|
+
) internal virtual override returns (uint256 amountSharesOut) {
|
|
50
|
+
return _zapIn(tokenIn, amountDeposited);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function _redeem(
|
|
54
|
+
address receiver,
|
|
55
|
+
address tokenOut,
|
|
56
|
+
uint256 amountSharesToRedeem
|
|
57
|
+
) internal virtual override returns (uint256 amountTokenOut) {
|
|
58
|
+
amountTokenOut = _zapOut(tokenOut, amountSharesToRedeem);
|
|
59
|
+
_transferOut(tokenOut, receiver, amountTokenOut);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/*///////////////////////////////////////////////////////////////
|
|
63
|
+
EXCHANGE-RATE
|
|
64
|
+
//////////////////////////////////////////////////////////////*/
|
|
65
|
+
|
|
66
|
+
function exchangeRate() public view virtual override returns (uint256) {
|
|
67
|
+
return PMath.ONE;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/*///////////////////////////////////////////////////////////////
|
|
71
|
+
REWARDS-RELATED
|
|
72
|
+
//////////////////////////////////////////////////////////////*/
|
|
73
|
+
|
|
74
|
+
function addRewardToken(address rewardToken) external onlyOwner {
|
|
75
|
+
require(!allRewardTokens.contains(rewardToken), "rewardToken already existed");
|
|
76
|
+
allRewardTokens.push(rewardToken);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* @dev See {IStandardizedYield-getRewardTokens}
|
|
81
|
+
*/
|
|
82
|
+
function _getRewardTokens() internal view override returns (address[] memory res) {
|
|
83
|
+
return allRewardTokens;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function _redeemExternalReward() internal override {
|
|
87
|
+
_claimKyberRewards();
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/*///////////////////////////////////////////////////////////////
|
|
91
|
+
MISC FUNCTIONS FOR METADATA
|
|
92
|
+
//////////////////////////////////////////////////////////////*/
|
|
93
|
+
|
|
94
|
+
function _previewDeposit(
|
|
95
|
+
address tokenIn,
|
|
96
|
+
uint256 amountTokenToDeposit
|
|
97
|
+
) internal view override returns (uint256 amountSharesOut) {
|
|
98
|
+
return
|
|
99
|
+
IKyberMathHelper(kyberMathHelper).previewDeposit(
|
|
100
|
+
pool,
|
|
101
|
+
tickLower,
|
|
102
|
+
tickUpper,
|
|
103
|
+
tokenIn == token0,
|
|
104
|
+
amountTokenToDeposit
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function _previewRedeem(
|
|
109
|
+
address tokenOut,
|
|
110
|
+
uint256 amountSharesToRedeem
|
|
111
|
+
) internal view override returns (uint256 amountTokenOut) {
|
|
112
|
+
return
|
|
113
|
+
IKyberMathHelper(kyberMathHelper).previewRedeem(
|
|
114
|
+
pool,
|
|
115
|
+
tickLower,
|
|
116
|
+
tickUpper,
|
|
117
|
+
tokenOut == token0,
|
|
118
|
+
amountSharesToRedeem
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function getTokensIn() public view virtual override returns (address[] memory res) {
|
|
123
|
+
res = new address[](2);
|
|
124
|
+
res[0] = token0;
|
|
125
|
+
res[1] = token1;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getTokensOut() public view virtual override returns (address[] memory res) {
|
|
129
|
+
res = new address[](2);
|
|
130
|
+
res[0] = token0;
|
|
131
|
+
res[1] = token1;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function isValidTokenIn(address token) public view virtual override returns (bool) {
|
|
135
|
+
return token == token0 || token == token1;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function isValidTokenOut(address token) public view virtual override returns (bool) {
|
|
139
|
+
return token == token0 || token == token1;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function assetInfo() external view returns (AssetType assetType, address assetAddress, uint8 assetDecimals) {
|
|
143
|
+
return (AssetType.TOKEN, pool, 18);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/*///////////////////////////////////////////////////////////////
|
|
147
|
+
POC for Emergency functions
|
|
148
|
+
//////////////////////////////////////////////////////////////*/
|
|
149
|
+
|
|
150
|
+
// function toggleEmergencyStatus() external {
|
|
151
|
+
// // This function only acts as a POC. Any other call to this SY should also execute the withdraw emergency
|
|
152
|
+
// require(IKyberLiquidityMining(liquidityMining).emergencyEnabled(), "not emergency");
|
|
153
|
+
// _withdrawNftFromFarm(KyberLiquidityMiningStatus.EMERGENCY);
|
|
154
|
+
// }
|
|
155
|
+
}
|