@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,425 @@
|
|
|
1
|
+
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
+
pragma solidity ^0.8.0;
|
|
3
|
+
|
|
4
|
+
import "../../../../interfaces/Kyber/IKyberElasticPool.sol";
|
|
5
|
+
import "../../../../interfaces/Kyber/IKyberElasticFactory.sol";
|
|
6
|
+
import "./libraries/ReinvestmentMath.sol";
|
|
7
|
+
import "./libraries/TickMath.sol";
|
|
8
|
+
import "./libraries/SwapMath.sol";
|
|
9
|
+
import "./libraries/LiqDeltaMath.sol";
|
|
10
|
+
import "./libraries/LiquidityMath.sol";
|
|
11
|
+
import "./libraries/QtyDeltaMath.sol";
|
|
12
|
+
import {MathConstants as C} from "./libraries/MathConstants.sol";
|
|
13
|
+
import "../../../libraries/math/PMath.sol";
|
|
14
|
+
|
|
15
|
+
import "../../../libraries/BoringOwnableUpgradeable.sol";
|
|
16
|
+
import "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
|
|
17
|
+
|
|
18
|
+
contract KyberMathHelper is BoringOwnableUpgradeable, UUPSUpgradeable {
|
|
19
|
+
using SafeCast for uint256;
|
|
20
|
+
using SafeCast for int256;
|
|
21
|
+
using SafeCast for int128;
|
|
22
|
+
using PMath for int24;
|
|
23
|
+
using PMath for int256;
|
|
24
|
+
using PMath for uint256;
|
|
25
|
+
|
|
26
|
+
uint256 public constant DEFAULT_NUMBER_OF_ITERS = 30;
|
|
27
|
+
|
|
28
|
+
address public immutable factory;
|
|
29
|
+
|
|
30
|
+
uint256 public numBinarySearchIter;
|
|
31
|
+
|
|
32
|
+
constructor(address _factory) initializer {
|
|
33
|
+
factory = _factory;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function _authorizeUpgrade(address) internal virtual override onlyOwner {}
|
|
37
|
+
|
|
38
|
+
function initialize() external initializer {
|
|
39
|
+
__BoringOwnable_init();
|
|
40
|
+
numBinarySearchIter = DEFAULT_NUMBER_OF_ITERS;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function setNumBinarySearchIter(uint256 newNumBinarySearchIter) external onlyOwner {
|
|
44
|
+
numBinarySearchIter = newNumBinarySearchIter;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
struct BinarySearchParams {
|
|
48
|
+
uint256 low;
|
|
49
|
+
uint256 high;
|
|
50
|
+
uint160 lowerSqrtP;
|
|
51
|
+
uint160 upperSqrtP;
|
|
52
|
+
uint256 guess;
|
|
53
|
+
uint256 amountOut;
|
|
54
|
+
int24 newTick;
|
|
55
|
+
uint160 currentSqrtP;
|
|
56
|
+
uint128 liq0;
|
|
57
|
+
uint128 liq1;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function previewDeposit(
|
|
61
|
+
address kyberPool,
|
|
62
|
+
int24 tickLower,
|
|
63
|
+
int24 tickUpper,
|
|
64
|
+
bool isToken0,
|
|
65
|
+
uint256 amountIn
|
|
66
|
+
) external view returns (uint256) {
|
|
67
|
+
uint256 amountToSwap = getSingleSidedSwapAmount(kyberPool, amountIn, isToken0, tickLower, tickUpper);
|
|
68
|
+
(uint256 amountOut, , uint160 newSqrtP) = _simulateSwapExactIn(
|
|
69
|
+
kyberPool,
|
|
70
|
+
amountToSwap,
|
|
71
|
+
_getExtCache(kyberPool, isToken0)
|
|
72
|
+
);
|
|
73
|
+
return
|
|
74
|
+
LiquidityMath.getLiquidityFromQties(
|
|
75
|
+
newSqrtP,
|
|
76
|
+
TickMath.getSqrtRatioAtTick(tickLower),
|
|
77
|
+
TickMath.getSqrtRatioAtTick(tickUpper),
|
|
78
|
+
amountIn - amountToSwap,
|
|
79
|
+
amountOut
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @dev preview redeem function is intentionally left incorrect
|
|
85
|
+
* as it uses the old state of the pool to calculate the final swap
|
|
86
|
+
* instead of the state of the pool after removing liquidity
|
|
87
|
+
*/
|
|
88
|
+
function previewRedeem(
|
|
89
|
+
address kyberPool,
|
|
90
|
+
int24 tickLower,
|
|
91
|
+
int24 tickUpper,
|
|
92
|
+
bool isToken0,
|
|
93
|
+
uint256 amountShares
|
|
94
|
+
) external view returns (uint256) {
|
|
95
|
+
(uint256 amount0, uint256 amount1) = _simulateBurn(kyberPool, tickLower, tickUpper, amountShares);
|
|
96
|
+
|
|
97
|
+
(uint256 amountOut, , ) = _simulateSwapExactIn(
|
|
98
|
+
kyberPool,
|
|
99
|
+
isToken0 ? amount1 : amount0,
|
|
100
|
+
_getExtCache(kyberPool, isToken0)
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
return (isToken0 ? amount0 : amount1) + amountOut;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function getSingleSidedSwapAmount(
|
|
107
|
+
address kyberPool,
|
|
108
|
+
uint256 startAmount,
|
|
109
|
+
bool isToken0,
|
|
110
|
+
int24 tickLower,
|
|
111
|
+
int24 tickUpper
|
|
112
|
+
) public view returns (uint256 amountToSwap) {
|
|
113
|
+
BinarySearchParams memory params;
|
|
114
|
+
|
|
115
|
+
params.low = 0;
|
|
116
|
+
params.high = startAmount;
|
|
117
|
+
params.lowerSqrtP = TickMath.getSqrtRatioAtTick(tickLower);
|
|
118
|
+
params.upperSqrtP = TickMath.getSqrtRatioAtTick(tickUpper);
|
|
119
|
+
ExternalCache memory ext = _getExtCache(kyberPool, isToken0);
|
|
120
|
+
|
|
121
|
+
for (uint256 iter = 0; iter < numBinarySearchIter && params.low != params.high; ++iter) {
|
|
122
|
+
// First 2 iterations are reserved for 2 bounds (0) and (startAmount)
|
|
123
|
+
// If either of the bounds satisfies, the loop should ends itself with low != high condition
|
|
124
|
+
if (iter == 0) {
|
|
125
|
+
params.guess = 0;
|
|
126
|
+
} else if (iter == 1) {
|
|
127
|
+
params.guess = startAmount;
|
|
128
|
+
} else {
|
|
129
|
+
params.guess = (params.low + params.high) / 2;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
(params.amountOut, params.newTick, params.currentSqrtP) = _simulateSwapExactIn(
|
|
133
|
+
kyberPool,
|
|
134
|
+
params.guess,
|
|
135
|
+
ext
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
if (isToken0) {
|
|
139
|
+
if (params.newTick < tickLower) {
|
|
140
|
+
params.high = params.guess;
|
|
141
|
+
} else if (params.newTick >= tickUpper) {
|
|
142
|
+
params.low = params.guess;
|
|
143
|
+
} else {
|
|
144
|
+
uint128 liq0 = LiquidityMath.getLiquidityFromQty0(
|
|
145
|
+
params.currentSqrtP,
|
|
146
|
+
params.upperSqrtP,
|
|
147
|
+
startAmount - params.guess
|
|
148
|
+
);
|
|
149
|
+
uint128 liq1 = LiquidityMath.getLiquidityFromQty1(
|
|
150
|
+
params.lowerSqrtP,
|
|
151
|
+
params.currentSqrtP,
|
|
152
|
+
params.amountOut
|
|
153
|
+
);
|
|
154
|
+
if (liq0 < liq1) {
|
|
155
|
+
params.high = params.guess;
|
|
156
|
+
} else {
|
|
157
|
+
params.low = params.guess;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
} else {
|
|
161
|
+
if (params.newTick < tickLower) {
|
|
162
|
+
params.low = params.guess;
|
|
163
|
+
} else if (params.newTick >= tickUpper) {
|
|
164
|
+
params.high = params.guess;
|
|
165
|
+
} else {
|
|
166
|
+
uint128 liq0 = LiquidityMath.getLiquidityFromQty0(
|
|
167
|
+
params.currentSqrtP,
|
|
168
|
+
params.upperSqrtP,
|
|
169
|
+
params.amountOut
|
|
170
|
+
);
|
|
171
|
+
uint128 liq1 = LiquidityMath.getLiquidityFromQty1(
|
|
172
|
+
params.lowerSqrtP,
|
|
173
|
+
params.currentSqrtP,
|
|
174
|
+
startAmount - params.guess
|
|
175
|
+
);
|
|
176
|
+
if (liq1 < liq0) {
|
|
177
|
+
params.high = params.guess;
|
|
178
|
+
} else {
|
|
179
|
+
params.low = params.guess;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
amountToSwap = params.high;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// temporary swap variables, some of which will be used to update the pool state
|
|
188
|
+
struct SwapData {
|
|
189
|
+
int256 specifiedAmount; // the specified amount (could be tokenIn or tokenOut)
|
|
190
|
+
int256 returnedAmount; // the opposite amout of sourceQty
|
|
191
|
+
uint160 sqrtP; // current sqrt(price), multiplied by 2^96
|
|
192
|
+
int24 currentTick; // the tick associated with the current price
|
|
193
|
+
int24 nextTick; // the next initialized tick
|
|
194
|
+
uint160 nextSqrtP; // the price of nextTick
|
|
195
|
+
bool isToken0; // true if specifiedAmount is in token0, false if in token1
|
|
196
|
+
bool isExactInput; // true = input qty, false = output qty
|
|
197
|
+
uint128 baseL; // the cached base pool liquidity without reinvestment liquidity
|
|
198
|
+
uint128 reinvestL; // the cached reinvestment liquidity
|
|
199
|
+
uint160 startSqrtP; // the start sqrt price before each iteration
|
|
200
|
+
/// ---------------- PENDLE additional data --------------------------
|
|
201
|
+
uint256 feeUnit;
|
|
202
|
+
uint256 reinvestLLast;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// variables below are loaded only when crossing a tick
|
|
206
|
+
struct SwapCache {
|
|
207
|
+
uint256 rTotalSupply; // cache of total reinvestment token supply
|
|
208
|
+
uint128 reinvestLLast; // collected liquidity
|
|
209
|
+
uint256 feeGrowthGlobal; // cache of fee growth of the reinvestment token, multiplied by 2^96
|
|
210
|
+
uint128 secondsPerLiquidityGlobal; // all-time seconds per liquidity, multiplied by 2^96
|
|
211
|
+
uint24 governmentFeeUnits; // governmentFeeUnits to be charged
|
|
212
|
+
uint256 governmentFee; // qty of reinvestment token for government fee
|
|
213
|
+
uint256 lpFee; // qty of reinvestment token for liquidity provider
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
struct ExternalCache {
|
|
217
|
+
uint256 rTotalSupply;
|
|
218
|
+
uint256 feeGrowthGlobal;
|
|
219
|
+
uint24 governmentFeeUnits; // governmentFeeUnits to be charged
|
|
220
|
+
uint256 governmentFee; // qty of reinvestment token for government fee
|
|
221
|
+
uint128 baseL;
|
|
222
|
+
uint128 reinvestL;
|
|
223
|
+
uint128 reinvestLLast;
|
|
224
|
+
uint160 sqrtP;
|
|
225
|
+
int24 currentTick;
|
|
226
|
+
int24 nextTick;
|
|
227
|
+
uint256 feeUnit;
|
|
228
|
+
bool willUpTick;
|
|
229
|
+
bool isToken0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function _simulateSwapExactIn(
|
|
233
|
+
address kyberPool,
|
|
234
|
+
uint256 swapQty,
|
|
235
|
+
ExternalCache memory ext
|
|
236
|
+
) internal view returns (uint256 amountOut, int24 newTick, uint160 newSqrtP) {
|
|
237
|
+
SwapData memory swapData = SwapData({
|
|
238
|
+
specifiedAmount: swapQty.Int(),
|
|
239
|
+
returnedAmount: 0,
|
|
240
|
+
sqrtP: ext.sqrtP,
|
|
241
|
+
currentTick: ext.currentTick,
|
|
242
|
+
nextTick: ext.nextTick,
|
|
243
|
+
nextSqrtP: 0,
|
|
244
|
+
isToken0: ext.isToken0,
|
|
245
|
+
isExactInput: true,
|
|
246
|
+
baseL: ext.baseL,
|
|
247
|
+
reinvestL: ext.reinvestL,
|
|
248
|
+
startSqrtP: 0,
|
|
249
|
+
feeUnit: ext.feeUnit,
|
|
250
|
+
reinvestLLast: ext.reinvestLLast
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
bool willUpTick = ext.willUpTick;
|
|
254
|
+
|
|
255
|
+
SwapCache memory cache;
|
|
256
|
+
while (swapData.specifiedAmount != 0) {
|
|
257
|
+
int24 tempNextTick = swapData.nextTick;
|
|
258
|
+
if (willUpTick && tempNextTick > C.MAX_TICK_DISTANCE + swapData.currentTick) {
|
|
259
|
+
tempNextTick = swapData.currentTick + C.MAX_TICK_DISTANCE;
|
|
260
|
+
} else if (!willUpTick && tempNextTick < swapData.currentTick - C.MAX_TICK_DISTANCE) {
|
|
261
|
+
tempNextTick = swapData.currentTick - C.MAX_TICK_DISTANCE;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
swapData.startSqrtP = swapData.sqrtP;
|
|
265
|
+
swapData.nextSqrtP = TickMath.getSqrtRatioAtTick(tempNextTick);
|
|
266
|
+
|
|
267
|
+
{
|
|
268
|
+
uint160 targetSqrtP = swapData.nextSqrtP;
|
|
269
|
+
|
|
270
|
+
int256 usedAmount;
|
|
271
|
+
int256 returnedAmount;
|
|
272
|
+
uint256 deltaL;
|
|
273
|
+
(usedAmount, returnedAmount, deltaL, swapData.sqrtP) = SwapMath.computeSwapStep(
|
|
274
|
+
swapData.baseL + swapData.reinvestL,
|
|
275
|
+
swapData.sqrtP,
|
|
276
|
+
targetSqrtP,
|
|
277
|
+
swapData.feeUnit,
|
|
278
|
+
swapData.specifiedAmount,
|
|
279
|
+
swapData.isExactInput,
|
|
280
|
+
swapData.isToken0
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
swapData.specifiedAmount -= usedAmount;
|
|
284
|
+
swapData.returnedAmount += returnedAmount;
|
|
285
|
+
swapData.reinvestL += deltaL.toUint128();
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// if price has not reached the next sqrt price
|
|
289
|
+
if (swapData.sqrtP != swapData.nextSqrtP) {
|
|
290
|
+
if (swapData.sqrtP != swapData.startSqrtP) {
|
|
291
|
+
// update the current tick data in case the sqrtP has changed
|
|
292
|
+
swapData.currentTick = TickMath.getTickAtSqrtRatio(swapData.sqrtP);
|
|
293
|
+
}
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
swapData.currentTick = willUpTick ? tempNextTick : tempNextTick - 1;
|
|
297
|
+
|
|
298
|
+
// if tempNextTick is not next initialized tick
|
|
299
|
+
if (tempNextTick != swapData.nextTick) continue;
|
|
300
|
+
|
|
301
|
+
if (cache.rTotalSupply == 0) {
|
|
302
|
+
// load variables that are only initialized when crossing a tick
|
|
303
|
+
cache.rTotalSupply = ext.rTotalSupply;
|
|
304
|
+
cache.reinvestLLast = swapData.reinvestLLast.toUint128();
|
|
305
|
+
cache.feeGrowthGlobal = ext.feeGrowthGlobal;
|
|
306
|
+
|
|
307
|
+
// not sure if this is necessary for the amount out & current tick computation
|
|
308
|
+
// let's ignore for now
|
|
309
|
+
// cache.secondsPerLiquidityGlobal = _syncSecondsPerLiquidity(
|
|
310
|
+
// poolData.secondsPerLiquidityGlobal,
|
|
311
|
+
// swapData.baseL
|
|
312
|
+
// );
|
|
313
|
+
cache.governmentFeeUnits = ext.governmentFeeUnits;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// update rTotalSupply, feeGrowthGlobal and reinvestL
|
|
317
|
+
uint256 rMintQty = ReinvestmentMath.calcrMintQty(
|
|
318
|
+
swapData.reinvestL,
|
|
319
|
+
cache.reinvestLLast,
|
|
320
|
+
swapData.baseL,
|
|
321
|
+
cache.rTotalSupply
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
if (rMintQty != 0) {
|
|
325
|
+
cache.rTotalSupply += rMintQty;
|
|
326
|
+
// overflow/underflow not possible bc governmentFeeUnits < 20000
|
|
327
|
+
unchecked {
|
|
328
|
+
uint256 governmentFee = (rMintQty * cache.governmentFeeUnits) / C.FEE_UNITS;
|
|
329
|
+
cache.governmentFee += governmentFee;
|
|
330
|
+
|
|
331
|
+
uint256 lpFee = rMintQty - governmentFee;
|
|
332
|
+
cache.lpFee += lpFee;
|
|
333
|
+
|
|
334
|
+
cache.feeGrowthGlobal += FullMath.mulDivFloor(lpFee, C.TWO_POW_96, swapData.baseL);
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
cache.reinvestLLast = swapData.reinvestL;
|
|
338
|
+
|
|
339
|
+
(swapData.baseL, swapData.nextTick) = _updateLiquidityAndCrossTick(
|
|
340
|
+
kyberPool,
|
|
341
|
+
swapData.nextTick,
|
|
342
|
+
swapData.baseL,
|
|
343
|
+
cache.feeGrowthGlobal,
|
|
344
|
+
cache.secondsPerLiquidityGlobal,
|
|
345
|
+
willUpTick
|
|
346
|
+
);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
amountOut = swapData.returnedAmount.abs();
|
|
350
|
+
newTick = swapData.currentTick;
|
|
351
|
+
newSqrtP = swapData.sqrtP;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function _simulateBurn(
|
|
355
|
+
address kyberPool,
|
|
356
|
+
int24 tickLower,
|
|
357
|
+
int24 tickUpper,
|
|
358
|
+
uint256 liquidity
|
|
359
|
+
) internal view returns (uint256 amount0, uint256 amount1) {
|
|
360
|
+
(uint160 sqrtP, int24 currentTick, , ) = IKyberElasticPool(kyberPool).getPoolState();
|
|
361
|
+
|
|
362
|
+
if (currentTick < tickLower) {
|
|
363
|
+
amount0 = QtyDeltaMath
|
|
364
|
+
.calcRequiredQty0(
|
|
365
|
+
TickMath.getSqrtRatioAtTick(tickLower),
|
|
366
|
+
TickMath.getSqrtRatioAtTick(tickUpper),
|
|
367
|
+
liquidity.Uint128(),
|
|
368
|
+
false
|
|
369
|
+
)
|
|
370
|
+
.abs();
|
|
371
|
+
} else if (currentTick >= tickUpper) {
|
|
372
|
+
amount1 = QtyDeltaMath
|
|
373
|
+
.calcRequiredQty1(
|
|
374
|
+
TickMath.getSqrtRatioAtTick(tickLower),
|
|
375
|
+
TickMath.getSqrtRatioAtTick(tickUpper),
|
|
376
|
+
liquidity.Uint128(),
|
|
377
|
+
false
|
|
378
|
+
)
|
|
379
|
+
.abs();
|
|
380
|
+
} else {
|
|
381
|
+
amount0 = QtyDeltaMath
|
|
382
|
+
.calcRequiredQty0(sqrtP, TickMath.getSqrtRatioAtTick(tickUpper), liquidity.Uint128(), false)
|
|
383
|
+
.abs();
|
|
384
|
+
amount1 = QtyDeltaMath
|
|
385
|
+
.calcRequiredQty1(TickMath.getSqrtRatioAtTick(tickLower), sqrtP, liquidity.Uint128(), false)
|
|
386
|
+
.abs();
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function _updateLiquidityAndCrossTick(
|
|
391
|
+
address kyberPool,
|
|
392
|
+
int24 nextTick,
|
|
393
|
+
uint128 currentLiquidity,
|
|
394
|
+
uint256,
|
|
395
|
+
uint128,
|
|
396
|
+
bool willUpTick
|
|
397
|
+
) internal view returns (uint128 newLiquidity, int24 newNextTick) {
|
|
398
|
+
(, int128 liquidityNet, , ) = IKyberElasticPool(kyberPool).ticks(nextTick);
|
|
399
|
+
if (willUpTick) {
|
|
400
|
+
(, newNextTick) = IKyberElasticPool(kyberPool).initializedTicks(nextTick);
|
|
401
|
+
} else {
|
|
402
|
+
(newNextTick, ) = IKyberElasticPool(kyberPool).initializedTicks(nextTick);
|
|
403
|
+
liquidityNet = -liquidityNet;
|
|
404
|
+
}
|
|
405
|
+
newLiquidity = LiqDeltaMath.applyLiquidityDelta(
|
|
406
|
+
currentLiquidity,
|
|
407
|
+
liquidityNet >= 0 ? uint128(liquidityNet) : liquidityNet.revToUint128(),
|
|
408
|
+
liquidityNet >= 0
|
|
409
|
+
);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function _getExtCache(address kyberPool, bool isToken0) internal view returns (ExternalCache memory ext) {
|
|
413
|
+
bool willUpTick = !isToken0;
|
|
414
|
+
(ext.baseL, ext.reinvestL, ext.reinvestLLast) = IKyberElasticPool(kyberPool).getLiquidityState();
|
|
415
|
+
(ext.sqrtP, ext.currentTick, ext.nextTick, ) = IKyberElasticPool(kyberPool).getPoolState();
|
|
416
|
+
if (willUpTick) {
|
|
417
|
+
(, ext.nextTick) = IKyberElasticPool(kyberPool).initializedTicks(ext.nextTick);
|
|
418
|
+
}
|
|
419
|
+
ext.feeUnit = IKyberElasticPool(kyberPool).swapFeeUnits();
|
|
420
|
+
|
|
421
|
+
ext.rTotalSupply = IKyberElasticPool(kyberPool).totalSupply();
|
|
422
|
+
ext.feeGrowthGlobal = IKyberElasticPool(kyberPool).getFeeGrowthGlobal();
|
|
423
|
+
(, ext.governmentFeeUnits) = IKyberElasticFactory(factory).feeConfiguration();
|
|
424
|
+
}
|
|
425
|
+
}
|