@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
|
@@ -1,582 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
-
pragma solidity ^0.8.17;
|
|
3
|
-
|
|
4
|
-
import "../../../interfaces/IPMarket.sol";
|
|
5
|
-
import "../../../interfaces/IPRouterStatic.sol";
|
|
6
|
-
import "./StorageLayout.sol";
|
|
7
|
-
|
|
8
|
-
contract ActionMarketCoreStatic is StorageLayout, IPActionMarketCoreStatic {
|
|
9
|
-
using PMath for uint256;
|
|
10
|
-
using PMath for int256;
|
|
11
|
-
|
|
12
|
-
using LogExpMath for int256;
|
|
13
|
-
using PYIndexLib for PYIndex;
|
|
14
|
-
using PYIndexLib for IPYieldToken;
|
|
15
|
-
using MarketApproxPtInLib for MarketState;
|
|
16
|
-
using MarketApproxPtOutLib for MarketState;
|
|
17
|
-
using MarketMathCore for MarketState;
|
|
18
|
-
|
|
19
|
-
// ============ ADD REMOVE LIQUIDITY ============
|
|
20
|
-
|
|
21
|
-
function addLiquidityDualSyAndPtStatic(address market, uint256 netSyDesired, uint256 netPtDesired)
|
|
22
|
-
public
|
|
23
|
-
view
|
|
24
|
-
returns (uint256 netLpOut, uint256 netSyUsed, uint256 netPtUsed)
|
|
25
|
-
{
|
|
26
|
-
MarketState memory state = _readState(market);
|
|
27
|
-
(, netLpOut, netSyUsed, netPtUsed) = state.addLiquidity(netSyDesired, netPtDesired, block.timestamp);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function addLiquidityDualTokenAndPtStatic(
|
|
31
|
-
address market,
|
|
32
|
-
address tokenIn,
|
|
33
|
-
uint256 netTokenDesired,
|
|
34
|
-
uint256 netPtDesired
|
|
35
|
-
)
|
|
36
|
-
public
|
|
37
|
-
view
|
|
38
|
-
returns (
|
|
39
|
-
uint256 netLpOut,
|
|
40
|
-
uint256 netTokenUsed,
|
|
41
|
-
uint256 netPtUsed,
|
|
42
|
-
// extra-info
|
|
43
|
-
uint256 netSyUsed,
|
|
44
|
-
uint256 netSyDesired
|
|
45
|
-
)
|
|
46
|
-
{
|
|
47
|
-
netSyDesired = _mintSyFromTokenStatic(market, tokenIn, netTokenDesired);
|
|
48
|
-
|
|
49
|
-
(netLpOut, netSyUsed, netPtUsed) = addLiquidityDualSyAndPtStatic(market, netSyDesired, netPtDesired);
|
|
50
|
-
|
|
51
|
-
if (netSyUsed != netSyDesired) revert Errors.RouterNotAllSyUsed(netSyDesired, netSyUsed);
|
|
52
|
-
|
|
53
|
-
netTokenUsed = netTokenDesired;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/// @dev netPtToSwap is the parameter to approx
|
|
57
|
-
function addLiquiditySinglePtStatic(address market, uint256 netPtIn)
|
|
58
|
-
public
|
|
59
|
-
view
|
|
60
|
-
returns (
|
|
61
|
-
uint256 netLpOut,
|
|
62
|
-
uint256 netPtToSwap,
|
|
63
|
-
uint256 netSyFee,
|
|
64
|
-
uint256 priceImpact,
|
|
65
|
-
uint256 exchangeRateAfter,
|
|
66
|
-
// extra-info
|
|
67
|
-
uint256 netSyFromSwap
|
|
68
|
-
)
|
|
69
|
-
{
|
|
70
|
-
MarketState memory state = _readState(market);
|
|
71
|
-
|
|
72
|
-
(netPtToSwap,,) =
|
|
73
|
-
state.approxSwapPtToAddLiquidity(_pyIndex(market), netPtIn, 0, block.timestamp, defaultApproxParams);
|
|
74
|
-
|
|
75
|
-
state = _readState(market); // re-read
|
|
76
|
-
|
|
77
|
-
(netSyFromSwap, netSyFee,) = state.swapExactPtForSy(_pyIndex(market), netPtToSwap, block.timestamp);
|
|
78
|
-
(, netLpOut,,) = state.addLiquidity(netSyFromSwap, netPtIn - netPtToSwap, block.timestamp);
|
|
79
|
-
|
|
80
|
-
priceImpact = _calcPriceImpactPt(market, netPtToSwap.neg());
|
|
81
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/// @dev netPtFromSwap is the parameter to approx
|
|
85
|
-
function addLiquiditySingleSyStatic(address market, uint256 netSyIn)
|
|
86
|
-
public
|
|
87
|
-
view
|
|
88
|
-
returns (
|
|
89
|
-
uint256 netLpOut,
|
|
90
|
-
uint256 netPtFromSwap,
|
|
91
|
-
uint256 netSyFee,
|
|
92
|
-
uint256 priceImpact,
|
|
93
|
-
uint256 exchangeRateAfter,
|
|
94
|
-
// extra-info
|
|
95
|
-
uint256 netSyToSwap
|
|
96
|
-
)
|
|
97
|
-
{
|
|
98
|
-
MarketState memory state = _readState(market);
|
|
99
|
-
|
|
100
|
-
(netPtFromSwap,,) =
|
|
101
|
-
state.approxSwapSyToAddLiquidity(_pyIndex(market), netSyIn, 0, block.timestamp, defaultApproxParams);
|
|
102
|
-
|
|
103
|
-
state = _readState(market); // re-read
|
|
104
|
-
|
|
105
|
-
(netSyToSwap, netSyFee,) = state.swapSyForExactPt(_pyIndex(market), netPtFromSwap, block.timestamp);
|
|
106
|
-
(, netLpOut,,) = state.addLiquidity(netSyIn - netSyToSwap, netPtFromSwap, block.timestamp);
|
|
107
|
-
|
|
108
|
-
priceImpact = _calcPriceImpactPt(market, netPtFromSwap.Int());
|
|
109
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function addLiquiditySingleTokenStatic(address market, address tokenIn, uint256 netTokenIn)
|
|
113
|
-
public
|
|
114
|
-
view
|
|
115
|
-
returns (
|
|
116
|
-
uint256 netLpOut,
|
|
117
|
-
uint256 netPtFromSwap,
|
|
118
|
-
uint256 netSyFee,
|
|
119
|
-
uint256 priceImpact,
|
|
120
|
-
uint256 exchangeRateAfter,
|
|
121
|
-
// extra-info
|
|
122
|
-
uint256 netSyMinted,
|
|
123
|
-
uint256 netSyToSwap
|
|
124
|
-
)
|
|
125
|
-
{
|
|
126
|
-
netSyMinted = _mintSyFromTokenStatic(market, tokenIn, netTokenIn);
|
|
127
|
-
(netLpOut, netPtFromSwap, netSyFee, priceImpact, exchangeRateAfter, netSyToSwap) =
|
|
128
|
-
addLiquiditySingleSyStatic(market, netSyMinted);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function addLiquiditySingleTokenKeepYtStatic(address market, address tokenIn, uint256 netTokenIn)
|
|
132
|
-
public
|
|
133
|
-
view
|
|
134
|
-
returns (
|
|
135
|
-
uint256 netLpOut,
|
|
136
|
-
uint256 netYtOut,
|
|
137
|
-
// extra-info
|
|
138
|
-
uint256 netSyMinted,
|
|
139
|
-
uint256 netSyToPY
|
|
140
|
-
)
|
|
141
|
-
{
|
|
142
|
-
netSyMinted = _mintSyFromTokenStatic(market, tokenIn, netTokenIn);
|
|
143
|
-
(netLpOut, netYtOut, netSyToPY) = addLiquiditySingleSyKeepYtStatic(market, netSyMinted);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function addLiquiditySingleSyKeepYtStatic(address market, uint256 netSyIn)
|
|
147
|
-
public
|
|
148
|
-
view
|
|
149
|
-
returns (
|
|
150
|
-
uint256 netLpOut,
|
|
151
|
-
uint256 netYtOut,
|
|
152
|
-
// extra-info
|
|
153
|
-
uint256 netSyToPY
|
|
154
|
-
)
|
|
155
|
-
{
|
|
156
|
-
MarketState memory state = _readState(market);
|
|
157
|
-
PYIndex index = _pyIndex(market);
|
|
158
|
-
|
|
159
|
-
netSyToPY = (netSyIn * state.totalPt.Uint()) / (state.totalPt.Uint() + index.syToAsset(state.totalSy.Uint()));
|
|
160
|
-
|
|
161
|
-
netYtOut = index.syToAsset(netSyToPY);
|
|
162
|
-
|
|
163
|
-
(, netLpOut,,) = state.addLiquidity(netSyIn - netSyToPY, netYtOut, block.timestamp);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function removeLiquidityDualSyAndPtStatic(address market, uint256 netLpToRemove)
|
|
167
|
-
public
|
|
168
|
-
view
|
|
169
|
-
returns (uint256 netSyOut, uint256 netPtOut)
|
|
170
|
-
{
|
|
171
|
-
MarketState memory state = _readState(market);
|
|
172
|
-
(netSyOut, netPtOut) = state.removeLiquidity(netLpToRemove);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
function removeLiquidityDualTokenAndPtStatic(address market, uint256 netLpToRemove, address tokenOut)
|
|
176
|
-
public
|
|
177
|
-
view
|
|
178
|
-
returns (uint256 netTokenOut, uint256 netPtOut, uint256 netSyToRedeem)
|
|
179
|
-
{
|
|
180
|
-
(netSyToRedeem, netPtOut) = removeLiquidityDualSyAndPtStatic(market, netLpToRemove);
|
|
181
|
-
netTokenOut = _redeemSyToTokenStatic(market, tokenOut, netSyToRedeem);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
/// @dev netPtFromSwap is the parameter to approx
|
|
185
|
-
/// @notice should revert post-expiry
|
|
186
|
-
function removeLiquiditySinglePtStatic(address market, uint256 netLpToRemove)
|
|
187
|
-
public
|
|
188
|
-
view
|
|
189
|
-
returns (
|
|
190
|
-
uint256 netPtOut,
|
|
191
|
-
uint256 netPtFromSwap,
|
|
192
|
-
uint256 netSyFee,
|
|
193
|
-
uint256 priceImpact,
|
|
194
|
-
uint256 exchangeRateAfter,
|
|
195
|
-
// extra-info
|
|
196
|
-
uint256 netSyFromBurn,
|
|
197
|
-
uint256 netPtFromBurn
|
|
198
|
-
)
|
|
199
|
-
{
|
|
200
|
-
MarketState memory state = _readState(market);
|
|
201
|
-
|
|
202
|
-
(netSyFromBurn, netPtFromBurn) = state.removeLiquidity(netLpToRemove);
|
|
203
|
-
(netPtFromSwap, netSyFee) =
|
|
204
|
-
state.approxSwapExactSyForPt(_pyIndex(market), netSyFromBurn, block.timestamp, defaultApproxParams);
|
|
205
|
-
|
|
206
|
-
netPtOut = netPtFromBurn + netPtFromSwap;
|
|
207
|
-
priceImpact = _calcPriceImpactPt(market, netPtFromSwap.Int());
|
|
208
|
-
|
|
209
|
-
// Execute swap to calculate exchangeRateAfter
|
|
210
|
-
state.swapSyForExactPt(_pyIndex(market), netPtFromSwap, block.timestamp);
|
|
211
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function removeLiquiditySingleSyStatic(address market, uint256 netLpToRemove)
|
|
215
|
-
public
|
|
216
|
-
view
|
|
217
|
-
returns (
|
|
218
|
-
uint256 netSyOut,
|
|
219
|
-
uint256 netSyFee,
|
|
220
|
-
uint256 priceImpact,
|
|
221
|
-
uint256 exchangeRateAfter,
|
|
222
|
-
// extra-info
|
|
223
|
-
uint256 netSyFromBurn,
|
|
224
|
-
uint256 netPtFromBurn,
|
|
225
|
-
uint256 netSyFromSwap
|
|
226
|
-
)
|
|
227
|
-
{
|
|
228
|
-
MarketState memory state = _readState(market);
|
|
229
|
-
|
|
230
|
-
(netSyFromBurn, netPtFromBurn) = state.removeLiquidity(netLpToRemove);
|
|
231
|
-
|
|
232
|
-
if (IPMarket(market).isExpired()) {
|
|
233
|
-
netSyOut = netSyFromBurn + _pyIndex(market).assetToSy(netPtFromBurn);
|
|
234
|
-
netSyFee = 0;
|
|
235
|
-
priceImpact = 0;
|
|
236
|
-
exchangeRateAfter = PMath.ONE;
|
|
237
|
-
} else {
|
|
238
|
-
(netSyFromSwap, netSyFee,) = state.swapExactPtForSy(_pyIndex(market), netPtFromBurn, block.timestamp);
|
|
239
|
-
|
|
240
|
-
netSyOut = netSyFromBurn + netSyFromSwap;
|
|
241
|
-
priceImpact = _calcPriceImpactPt(market, netPtFromBurn.neg());
|
|
242
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function removeLiquiditySingleTokenStatic(address market, uint256 netLpToRemove, address tokenOut)
|
|
247
|
-
public
|
|
248
|
-
view
|
|
249
|
-
returns (
|
|
250
|
-
uint256 netTokenOut,
|
|
251
|
-
uint256 netSyFee,
|
|
252
|
-
uint256 priceImpact,
|
|
253
|
-
uint256 exchangeRateAfter,
|
|
254
|
-
// extra-info
|
|
255
|
-
uint256 netSyOut,
|
|
256
|
-
uint256 netSyFromBurn,
|
|
257
|
-
uint256 netPtFromBurn,
|
|
258
|
-
uint256 netSyFromSwap
|
|
259
|
-
)
|
|
260
|
-
{
|
|
261
|
-
(netSyOut, netSyFee, priceImpact, exchangeRateAfter, netSyFromBurn, netPtFromBurn, netSyFromSwap) =
|
|
262
|
-
removeLiquiditySingleSyStatic(market, netLpToRemove);
|
|
263
|
-
|
|
264
|
-
netTokenOut = _redeemSyToTokenStatic(market, tokenOut, netSyOut);
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
// ============ SWAP PT ============
|
|
268
|
-
|
|
269
|
-
function swapExactPtForSyStatic(address market, uint256 exactPtIn)
|
|
270
|
-
public
|
|
271
|
-
view
|
|
272
|
-
returns (uint256 netSyOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)
|
|
273
|
-
{
|
|
274
|
-
MarketState memory state = _readState(market);
|
|
275
|
-
(netSyOut, netSyFee,) = state.swapExactPtForSy(_pyIndex(market), exactPtIn, block.timestamp);
|
|
276
|
-
priceImpact = _calcPriceImpactPt(market, exactPtIn.neg());
|
|
277
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function swapSyForExactPtStatic(address market, uint256 exactPtOut)
|
|
281
|
-
public
|
|
282
|
-
view
|
|
283
|
-
returns (uint256 netSyIn, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)
|
|
284
|
-
{
|
|
285
|
-
MarketState memory state = _readState(market);
|
|
286
|
-
(netSyIn, netSyFee,) = state.swapSyForExactPt(_pyIndex(market), exactPtOut, block.timestamp);
|
|
287
|
-
priceImpact = _calcPriceImpactPt(market, exactPtOut.Int());
|
|
288
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/// @dev netPtOut is the parameter to approx
|
|
292
|
-
function swapExactSyForPtStatic(address market, uint256 exactSyIn)
|
|
293
|
-
public
|
|
294
|
-
view
|
|
295
|
-
returns (uint256 netPtOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)
|
|
296
|
-
{
|
|
297
|
-
MarketState memory state = _readState(market);
|
|
298
|
-
(netPtOut, netSyFee) =
|
|
299
|
-
state.approxSwapExactSyForPt(_pyIndex(market), exactSyIn, block.timestamp, defaultApproxParams);
|
|
300
|
-
priceImpact = _calcPriceImpactPt(market, netPtOut.Int());
|
|
301
|
-
|
|
302
|
-
// Execute swap to calculate exchangeRateAfter
|
|
303
|
-
state.swapSyForExactPt(_pyIndex(market), netPtOut, block.timestamp);
|
|
304
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/// @dev netPtIn is the parameter to approx
|
|
308
|
-
function swapPtForExactSyStatic(address market, uint256 exactSyOut)
|
|
309
|
-
public
|
|
310
|
-
view
|
|
311
|
-
returns (uint256 netPtIn, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)
|
|
312
|
-
{
|
|
313
|
-
MarketState memory state = _readState(market);
|
|
314
|
-
|
|
315
|
-
(netPtIn,, netSyFee) =
|
|
316
|
-
state.approxSwapPtForExactSy(_pyIndex(market), exactSyOut, block.timestamp, defaultApproxParams);
|
|
317
|
-
priceImpact = _calcPriceImpactPt(market, netPtIn.neg());
|
|
318
|
-
|
|
319
|
-
// Execute swap to calculate exchangeRateAfter
|
|
320
|
-
state.swapExactPtForSy(_pyIndex(market), netPtIn, block.timestamp);
|
|
321
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
function swapExactTokenForPtStatic(address market, address tokenIn, uint256 amountTokenIn)
|
|
325
|
-
public
|
|
326
|
-
view
|
|
327
|
-
returns (
|
|
328
|
-
uint256 netPtOut,
|
|
329
|
-
uint256 netSyMinted,
|
|
330
|
-
uint256 netSyFee,
|
|
331
|
-
uint256 priceImpact,
|
|
332
|
-
uint256 exchangeRateAfter
|
|
333
|
-
)
|
|
334
|
-
{
|
|
335
|
-
netSyMinted = _mintSyFromTokenStatic(market, tokenIn, amountTokenIn);
|
|
336
|
-
|
|
337
|
-
(netPtOut, netSyFee, priceImpact, exchangeRateAfter) = swapExactSyForPtStatic(market, netSyMinted);
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
function swapExactPtForTokenStatic(address market, uint256 exactPtIn, address tokenOut)
|
|
341
|
-
public
|
|
342
|
-
view
|
|
343
|
-
returns (
|
|
344
|
-
uint256 netTokenOut,
|
|
345
|
-
uint256 netSyToRedeem,
|
|
346
|
-
uint256 netSyFee,
|
|
347
|
-
uint256 priceImpact,
|
|
348
|
-
uint256 exchangeRateAfter
|
|
349
|
-
)
|
|
350
|
-
{
|
|
351
|
-
(netSyToRedeem, netSyFee, priceImpact, exchangeRateAfter) = swapExactPtForSyStatic(market, exactPtIn);
|
|
352
|
-
|
|
353
|
-
netTokenOut = _redeemSyToTokenStatic(market, tokenOut, netSyToRedeem);
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
// ============ SWAP YT ============
|
|
357
|
-
|
|
358
|
-
function swapSyForExactYtStatic(address market, uint256 exactYtOut)
|
|
359
|
-
public
|
|
360
|
-
view
|
|
361
|
-
returns (
|
|
362
|
-
uint256 netSyIn,
|
|
363
|
-
uint256 netSyFee,
|
|
364
|
-
uint256 priceImpact,
|
|
365
|
-
uint256 exchangeRateAfter,
|
|
366
|
-
// extra-info
|
|
367
|
-
uint256 netSyReceivedInt,
|
|
368
|
-
uint256 totalSyNeedInt
|
|
369
|
-
)
|
|
370
|
-
{
|
|
371
|
-
priceImpact = _calcPriceImpactYt(market, exactYtOut.neg());
|
|
372
|
-
|
|
373
|
-
MarketState memory state = _readState(market);
|
|
374
|
-
PYIndex index = _pyIndex(market);
|
|
375
|
-
|
|
376
|
-
(netSyReceivedInt, netSyFee,) = state.swapExactPtForSy(_pyIndex(market), exactYtOut, block.timestamp);
|
|
377
|
-
|
|
378
|
-
totalSyNeedInt = index.assetToSyUp(exactYtOut);
|
|
379
|
-
netSyIn = totalSyNeedInt.subMax0(netSyReceivedInt);
|
|
380
|
-
|
|
381
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/// @dev netYtOut is the parameter to approx
|
|
385
|
-
function swapExactSyForYtStatic(address market, uint256 exactSyIn)
|
|
386
|
-
public
|
|
387
|
-
view
|
|
388
|
-
returns (uint256 netYtOut, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)
|
|
389
|
-
{
|
|
390
|
-
MarketState memory state = _readState(market);
|
|
391
|
-
PYIndex index = _pyIndex(market);
|
|
392
|
-
|
|
393
|
-
(netYtOut, netSyFee) = state.approxSwapExactSyForYt(index, exactSyIn, block.timestamp, defaultApproxParams);
|
|
394
|
-
|
|
395
|
-
priceImpact = _calcPriceImpactYt(market, netYtOut.neg());
|
|
396
|
-
|
|
397
|
-
// Execute swap to calculate exchangeRateAfter
|
|
398
|
-
state.swapExactPtForSy(index, netYtOut, block.timestamp);
|
|
399
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
function swapExactYtForSyStatic(address market, uint256 exactYtIn)
|
|
403
|
-
public
|
|
404
|
-
view
|
|
405
|
-
returns (
|
|
406
|
-
uint256 netSyOut,
|
|
407
|
-
uint256 netSyFee,
|
|
408
|
-
uint256 priceImpact,
|
|
409
|
-
uint256 exchangeRateAfter,
|
|
410
|
-
// extra-info
|
|
411
|
-
uint256 netSyOwedInt,
|
|
412
|
-
uint256 netPYToRepaySyOwedInt,
|
|
413
|
-
uint256 netPYToRedeemSyOutInt
|
|
414
|
-
)
|
|
415
|
-
{
|
|
416
|
-
priceImpact = _calcPriceImpactYt(market, exactYtIn.Int());
|
|
417
|
-
|
|
418
|
-
MarketState memory state = _readState(market);
|
|
419
|
-
|
|
420
|
-
PYIndex index = _pyIndex(market);
|
|
421
|
-
|
|
422
|
-
(netSyOwedInt, netSyFee,) = state.swapSyForExactPt(index, exactYtIn, block.timestamp);
|
|
423
|
-
|
|
424
|
-
netPYToRepaySyOwedInt = index.syToAssetUp(netSyOwedInt);
|
|
425
|
-
netPYToRedeemSyOutInt = exactYtIn - netPYToRepaySyOwedInt;
|
|
426
|
-
|
|
427
|
-
netSyOut = index.assetToSy(netPYToRedeemSyOutInt);
|
|
428
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function swapExactYtForTokenStatic(address market, uint256 exactYtIn, address tokenOut)
|
|
432
|
-
public
|
|
433
|
-
view
|
|
434
|
-
returns (
|
|
435
|
-
uint256 netTokenOut,
|
|
436
|
-
uint256 netSyFee,
|
|
437
|
-
uint256 priceImpact,
|
|
438
|
-
uint256 exchangeRateAfter,
|
|
439
|
-
// extra-info
|
|
440
|
-
uint256 netSyOut,
|
|
441
|
-
uint256 netSyOwedInt,
|
|
442
|
-
uint256 netPYToRepaySyOwedInt,
|
|
443
|
-
uint256 netPYToRedeemSyOutInt
|
|
444
|
-
)
|
|
445
|
-
{
|
|
446
|
-
(netSyOut, netSyFee, priceImpact, exchangeRateAfter, netSyOwedInt, netPYToRepaySyOwedInt, netPYToRedeemSyOutInt)
|
|
447
|
-
= swapExactYtForSyStatic(market, exactYtIn);
|
|
448
|
-
|
|
449
|
-
netTokenOut = _redeemSyToTokenStatic(market, tokenOut, netSyOut);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
/// @dev netYtIn is the parameter to approx
|
|
453
|
-
function swapYtForExactSyStatic(address market, uint256 exactSyOut)
|
|
454
|
-
public
|
|
455
|
-
view
|
|
456
|
-
returns (uint256 netYtIn, uint256 netSyFee, uint256 priceImpact, uint256 exchangeRateAfter)
|
|
457
|
-
{
|
|
458
|
-
MarketState memory state = _readState(market);
|
|
459
|
-
|
|
460
|
-
PYIndex index = _pyIndex(market);
|
|
461
|
-
|
|
462
|
-
(netYtIn,, netSyFee) = state.approxSwapYtForExactSy(index, exactSyOut, block.timestamp, defaultApproxParams);
|
|
463
|
-
priceImpact = _calcPriceImpactYt(market, netYtIn.Int());
|
|
464
|
-
|
|
465
|
-
// Execute swap to calculate exchangeRateAfter
|
|
466
|
-
state.swapSyForExactPt(index, netYtIn, block.timestamp);
|
|
467
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
function swapExactTokenForYtStatic(address market, address tokenIn, uint256 amountTokenIn)
|
|
471
|
-
public
|
|
472
|
-
view
|
|
473
|
-
returns (
|
|
474
|
-
uint256 netYtOut,
|
|
475
|
-
uint256 netSyMinted,
|
|
476
|
-
uint256 netSyFee,
|
|
477
|
-
uint256 priceImpact,
|
|
478
|
-
uint256 exchangeRateAfter
|
|
479
|
-
)
|
|
480
|
-
{
|
|
481
|
-
netSyMinted = _mintSyFromTokenStatic(market, tokenIn, amountTokenIn);
|
|
482
|
-
(netYtOut, netSyFee, priceImpact, exchangeRateAfter) = swapExactSyForYtStatic(market, netSyMinted);
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// totalPtToSwap is the param to approx
|
|
486
|
-
function swapExactPtForYtStatic(address market, uint256 exactPtIn)
|
|
487
|
-
public
|
|
488
|
-
view
|
|
489
|
-
returns (
|
|
490
|
-
uint256 netYtOut,
|
|
491
|
-
uint256 totalPtToSwap,
|
|
492
|
-
uint256 netSyFee,
|
|
493
|
-
uint256 priceImpact,
|
|
494
|
-
uint256 exchangeRateAfter
|
|
495
|
-
)
|
|
496
|
-
{
|
|
497
|
-
MarketState memory state = _readState(market);
|
|
498
|
-
PYIndex index = _pyIndex(market);
|
|
499
|
-
|
|
500
|
-
(netYtOut, totalPtToSwap, netSyFee) =
|
|
501
|
-
state.approxSwapExactPtForYt(index, exactPtIn, block.timestamp, defaultApproxParams);
|
|
502
|
-
priceImpact = _calcPriceImpactPY(market, totalPtToSwap.neg());
|
|
503
|
-
|
|
504
|
-
// Execute swap to calculate exchangeRateAfter
|
|
505
|
-
state.swapExactPtForSy(index, totalPtToSwap, block.timestamp);
|
|
506
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// totalPtSwapped is the param to approx
|
|
510
|
-
function swapExactYtForPtStatic(address market, uint256 exactYtIn)
|
|
511
|
-
public
|
|
512
|
-
view
|
|
513
|
-
returns (
|
|
514
|
-
uint256 netPtOut,
|
|
515
|
-
uint256 totalPtSwapped,
|
|
516
|
-
uint256 netSyFee,
|
|
517
|
-
uint256 priceImpact,
|
|
518
|
-
uint256 exchangeRateAfter
|
|
519
|
-
)
|
|
520
|
-
{
|
|
521
|
-
MarketState memory state = _readState(market);
|
|
522
|
-
PYIndex index = _pyIndex(market);
|
|
523
|
-
|
|
524
|
-
(netPtOut, totalPtSwapped, netSyFee) =
|
|
525
|
-
state.approxSwapExactYtForPt(index, exactYtIn, block.timestamp, defaultApproxParams);
|
|
526
|
-
|
|
527
|
-
priceImpact = _calcPriceImpactPY(market, totalPtSwapped.Int());
|
|
528
|
-
|
|
529
|
-
// Execute swap to calculate exchangeRateAfter
|
|
530
|
-
state.swapSyForExactPt(index, totalPtSwapped, block.timestamp);
|
|
531
|
-
exchangeRateAfter = _getTradeExchangeRateExcludeFee(market, state);
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
function _calcPriceImpactPY(address market, int256 netPtOut) internal view returns (uint256) {
|
|
535
|
-
return IPRouterStatic(address(this)).calcPriceImpactPY(market, netPtOut);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
function _calcPriceImpactPt(address market, int256 netPtOut) internal view returns (uint256) {
|
|
539
|
-
return IPRouterStatic(address(this)).calcPriceImpactPt(market, netPtOut);
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
function _calcPriceImpactYt(address market, int256 netPtOut) internal view returns (uint256) {
|
|
543
|
-
return IPRouterStatic(address(this)).calcPriceImpactYt(market, netPtOut);
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
function _mintSyFromTokenStatic(address market, address tokenIn, uint256 netTokenToDeposit)
|
|
547
|
-
internal
|
|
548
|
-
view
|
|
549
|
-
returns (uint256)
|
|
550
|
-
{
|
|
551
|
-
return IPRouterStatic(address(this)).mintSyFromTokenStatic(_getSyMarket(market), tokenIn, netTokenToDeposit);
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
function _redeemSyToTokenStatic(address market, address tokenOut, uint256 netSyToRedeem)
|
|
555
|
-
internal
|
|
556
|
-
view
|
|
557
|
-
returns (uint256)
|
|
558
|
-
{
|
|
559
|
-
return IPRouterStatic(address(this)).redeemSyToTokenStatic(_getSyMarket(market), tokenOut, netSyToRedeem);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
function _getTradeExchangeRateExcludeFee(address market, MarketState memory state)
|
|
563
|
-
internal
|
|
564
|
-
view
|
|
565
|
-
returns (uint256)
|
|
566
|
-
{
|
|
567
|
-
return IPRouterStatic(address(this)).getTradeExchangeRateExcludeFee(market, state);
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
function _readState(address market) internal view returns (MarketState memory) {
|
|
571
|
-
return IPMarket(market).readState(address(this));
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
function _pyIndex(address market) private view returns (PYIndex) {
|
|
575
|
-
return PYIndex.wrap(IPRouterStatic(address(this)).pyIndexCurrentViewMarket(market));
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
function _getSyMarket(address market) internal view returns (address) {
|
|
579
|
-
(IStandardizedYield SY,,) = IPMarket(market).readTokens();
|
|
580
|
-
return address(SY);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
-
pragma solidity ^0.8.17;
|
|
3
|
-
|
|
4
|
-
import "../../../interfaces/IPRouterStatic.sol";
|
|
5
|
-
import "./StorageLayout.sol";
|
|
6
|
-
|
|
7
|
-
contract ActionMintRedeemStatic is StorageLayout, IPActionMintRedeemStatic {
|
|
8
|
-
using PMath for uint256;
|
|
9
|
-
|
|
10
|
-
function mintPyFromSyStatic(address YT, uint256 netSyToMint) public view returns (uint256 netPYOut) {
|
|
11
|
-
if (IPYieldToken(YT).isExpired()) revert Errors.YCExpired();
|
|
12
|
-
return netSyToMint.mulDown(pyIndexCurrentViewYt(YT));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function redeemPyToSyStatic(address YT, uint256 netPYToRedeem) public view returns (uint256 netSyOut) {
|
|
16
|
-
return netPYToRedeem.divDown(pyIndexCurrentViewYt(YT));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function mintPyFromTokenStatic(address YT, address tokenIn, uint256 netTokenIn)
|
|
20
|
-
external
|
|
21
|
-
view
|
|
22
|
-
returns (uint256 netPyOut)
|
|
23
|
-
{
|
|
24
|
-
address SY = IPYieldToken(YT).SY();
|
|
25
|
-
uint256 netSyReceived = mintSyFromTokenStatic(SY, tokenIn, netTokenIn);
|
|
26
|
-
netPyOut = mintPyFromSyStatic(YT, netSyReceived);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function redeemPyToTokenStatic(address YT, uint256 netPYToRedeem, address tokenOut)
|
|
30
|
-
external
|
|
31
|
-
view
|
|
32
|
-
returns (uint256 netTokenOut)
|
|
33
|
-
{
|
|
34
|
-
address SY = IPYieldToken(YT).SY();
|
|
35
|
-
uint256 netSyReceived = redeemPyToSyStatic(YT, netPYToRedeem);
|
|
36
|
-
netTokenOut = redeemSyToTokenStatic(SY, tokenOut, netSyReceived);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function mintSyFromTokenStatic(address SY, address tokenIn, uint256 netTokenIn)
|
|
40
|
-
public
|
|
41
|
-
view
|
|
42
|
-
returns (uint256 netSyOut)
|
|
43
|
-
{
|
|
44
|
-
return IStandardizedYield(SY).previewDeposit(tokenIn, netTokenIn);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function redeemSyToTokenStatic(address SY, address tokenOut, uint256 netSyIn)
|
|
48
|
-
public
|
|
49
|
-
view
|
|
50
|
-
returns (uint256 netTokenOut)
|
|
51
|
-
{
|
|
52
|
-
return IStandardizedYield(SY).previewRedeem(tokenOut, netSyIn);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function getAmountTokenToMintSy(address SY, address tokenIn, uint256 netSyOut)
|
|
56
|
-
external
|
|
57
|
-
view
|
|
58
|
-
returns (uint256 netTokenIn)
|
|
59
|
-
{
|
|
60
|
-
uint256 pivotAmount;
|
|
61
|
-
|
|
62
|
-
if (tokenIn == address(0)) pivotAmount = 1e18;
|
|
63
|
-
else pivotAmount = 10 ** IStandardizedYield(SY).decimals();
|
|
64
|
-
|
|
65
|
-
uint256 low = pivotAmount;
|
|
66
|
-
{
|
|
67
|
-
while (true) {
|
|
68
|
-
uint256 lowSyOut = mintSyFromTokenStatic(SY, tokenIn, low);
|
|
69
|
-
if (lowSyOut >= netSyOut) low /= 10;
|
|
70
|
-
else break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
uint256 high = pivotAmount;
|
|
75
|
-
{
|
|
76
|
-
while (true) {
|
|
77
|
-
uint256 highSyOut = mintSyFromTokenStatic(SY, tokenIn, high);
|
|
78
|
-
if (highSyOut < netSyOut) high *= 10;
|
|
79
|
-
else break;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
while (low <= high) {
|
|
84
|
-
uint256 mid = (low + high) / 2;
|
|
85
|
-
uint256 syOut = mintSyFromTokenStatic(SY, tokenIn, mid);
|
|
86
|
-
|
|
87
|
-
if (syOut >= netSyOut) {
|
|
88
|
-
netTokenIn = mid;
|
|
89
|
-
high = mid - 1;
|
|
90
|
-
} else {
|
|
91
|
-
low = mid + 1;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
assert(netTokenIn > 0);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function pyIndexCurrentViewMarket(address market) public view returns (uint256) {
|
|
99
|
-
(,, IPYieldToken YT) = IPMarket(market).readTokens();
|
|
100
|
-
return pyIndexCurrentViewYt(address(YT));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function pyIndexCurrentViewYt(address yt) public view returns (uint256) {
|
|
104
|
-
IPYieldToken YT = IPYieldToken(yt);
|
|
105
|
-
IStandardizedYield SY = IStandardizedYield(YT.SY());
|
|
106
|
-
|
|
107
|
-
uint256 syIndex = SY.exchangeRate();
|
|
108
|
-
uint256 pyIndexStored = YT.pyIndexStored();
|
|
109
|
-
|
|
110
|
-
if (YT.doCacheIndexSameBlock() && YT.pyIndexLastUpdatedBlock() == block.number) {
|
|
111
|
-
return pyIndexStored;
|
|
112
|
-
} else {
|
|
113
|
-
return PMath.max(syIndex, pyIndexStored);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|