@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,5 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
2
|
-
pragma solidity 0.8.17;
|
|
2
|
+
pragma solidity ^0.8.17;
|
|
3
3
|
|
|
4
4
|
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
5
5
|
import "../../../../../../interfaces/Balancer/IComposableStable.sol";
|
|
@@ -145,17 +145,10 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
145
145
|
uint256 preJoinExitInvariant
|
|
146
146
|
) = _beforeJoinExit(registeredBalances, imd, caches);
|
|
147
147
|
|
|
148
|
-
function(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
uint256,
|
|
152
|
-
uint256,
|
|
153
|
-
uint256[] memory,
|
|
154
|
-
bytes memory,
|
|
155
|
-
ImmutableData memory
|
|
156
|
-
) internal view returns (uint256, uint256[] memory) _doJoinOrExit = (
|
|
157
|
-
isJoin ? _doJoin : _doExit
|
|
158
|
-
);
|
|
148
|
+
function(uint256[] memory, uint256, uint256, uint256, uint256[] memory, bytes memory, ImmutableData memory)
|
|
149
|
+
internal
|
|
150
|
+
view
|
|
151
|
+
returns (uint256, uint256[] memory) _doJoinOrExit = (isJoin ? _doJoin : _doExit);
|
|
159
152
|
|
|
160
153
|
(bptAmount, amountsDelta) = _doJoinOrExit(
|
|
161
154
|
balances,
|
|
@@ -180,9 +173,7 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
180
173
|
) internal pure returns (uint256[] memory registeredTokenAmounts) {
|
|
181
174
|
registeredTokenAmounts = new uint256[](amounts.length + 1);
|
|
182
175
|
for (uint256 i = 0; i < registeredTokenAmounts.length; i++) {
|
|
183
|
-
registeredTokenAmounts[i] = i == imd.bptIndex
|
|
184
|
-
? bptAmount
|
|
185
|
-
: amounts[i < imd.bptIndex ? i : i - 1];
|
|
176
|
+
registeredTokenAmounts[i] = i == imd.bptIndex ? bptAmount : amounts[i < imd.bptIndex ? i : i - 1];
|
|
186
177
|
}
|
|
187
178
|
}
|
|
188
179
|
|
|
@@ -237,20 +228,12 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
237
228
|
uint256 currentAmp,
|
|
238
229
|
uint256 preJoinExitSupply,
|
|
239
230
|
uint256 preJoinExitInvariant,
|
|
240
|
-
uint256[] memory
|
|
231
|
+
uint256[] memory /*scalingFactors*/,
|
|
241
232
|
bytes memory userData,
|
|
242
233
|
ImmutableData memory imd
|
|
243
234
|
) internal view returns (uint256, uint256[] memory) {
|
|
244
235
|
// this is always true given Pendle SY context
|
|
245
|
-
return
|
|
246
|
-
_exitExactBPTInForTokenOut(
|
|
247
|
-
preJoinExitSupply,
|
|
248
|
-
preJoinExitInvariant,
|
|
249
|
-
currentAmp,
|
|
250
|
-
balances,
|
|
251
|
-
userData,
|
|
252
|
-
imd
|
|
253
|
-
);
|
|
236
|
+
return _exitExactBPTInForTokenOut(preJoinExitSupply, preJoinExitInvariant, currentAmp, balances, userData, imd);
|
|
254
237
|
}
|
|
255
238
|
|
|
256
239
|
function _exitExactBPTInForTokenOut(
|
|
@@ -281,30 +264,14 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
281
264
|
uint256[] memory registeredBalances,
|
|
282
265
|
ImmutableData memory imd,
|
|
283
266
|
TokenRateCache[] memory caches
|
|
284
|
-
)
|
|
285
|
-
|
|
286
|
-
view
|
|
287
|
-
returns (
|
|
288
|
-
uint256,
|
|
289
|
-
uint256[] memory,
|
|
290
|
-
uint256,
|
|
291
|
-
uint256
|
|
292
|
-
)
|
|
293
|
-
{
|
|
294
|
-
(uint256 lastJoinExitAmp, uint256 lastPostJoinExitInvariant) = IComposableStable(imd.LP)
|
|
295
|
-
.getLastJoinExitData();
|
|
267
|
+
) internal view returns (uint256, uint256[] memory, uint256, uint256) {
|
|
268
|
+
(uint256 lastJoinExitAmp, uint256 lastPostJoinExitInvariant) = IComposableStable(imd.LP).getLastJoinExitData();
|
|
296
269
|
|
|
297
270
|
(
|
|
298
271
|
uint256 preJoinExitSupply,
|
|
299
272
|
uint256[] memory balances,
|
|
300
273
|
uint256 oldAmpPreJoinExitInvariant
|
|
301
|
-
) = _payProtocolFeesBeforeJoinExit(
|
|
302
|
-
registeredBalances,
|
|
303
|
-
lastJoinExitAmp,
|
|
304
|
-
lastPostJoinExitInvariant,
|
|
305
|
-
imd,
|
|
306
|
-
caches
|
|
307
|
-
);
|
|
274
|
+
) = _payProtocolFeesBeforeJoinExit(registeredBalances, lastJoinExitAmp, lastPostJoinExitInvariant, imd, caches);
|
|
308
275
|
|
|
309
276
|
(uint256 currentAmp, , ) = IComposableStable(imd.LP).getAmplificationParameter();
|
|
310
277
|
uint256 preJoinExitInvariant = currentAmp == lastJoinExitAmp
|
|
@@ -320,30 +287,13 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
320
287
|
uint256 lastPostJoinExitInvariant,
|
|
321
288
|
ImmutableData memory imd,
|
|
322
289
|
TokenRateCache[] memory caches
|
|
323
|
-
)
|
|
324
|
-
|
|
325
|
-
view
|
|
326
|
-
returns (
|
|
327
|
-
uint256,
|
|
328
|
-
uint256[] memory,
|
|
329
|
-
uint256
|
|
330
|
-
)
|
|
331
|
-
{
|
|
332
|
-
(uint256 virtualSupply, uint256[] memory balances) = _dropBptItemFromBalances(
|
|
333
|
-
imd,
|
|
334
|
-
registeredBalances
|
|
335
|
-
);
|
|
290
|
+
) internal view returns (uint256, uint256[] memory, uint256) {
|
|
291
|
+
(uint256 virtualSupply, uint256[] memory balances) = _dropBptItemFromBalances(imd, registeredBalances);
|
|
336
292
|
|
|
337
293
|
(
|
|
338
294
|
uint256 expectedProtocolOwnershipPercentage,
|
|
339
295
|
uint256 currentInvariantWithLastJoinExitAmp
|
|
340
|
-
) = _getProtocolPoolOwnershipPercentage(
|
|
341
|
-
balances,
|
|
342
|
-
lastJoinExitAmp,
|
|
343
|
-
lastPostJoinExitInvariant,
|
|
344
|
-
imd,
|
|
345
|
-
caches
|
|
346
|
-
);
|
|
296
|
+
) = _getProtocolPoolOwnershipPercentage(balances, lastJoinExitAmp, lastPostJoinExitInvariant, imd, caches);
|
|
347
297
|
|
|
348
298
|
uint256 protocolFeeAmount = _calculateAdjustedProtocolFeeAmount(
|
|
349
299
|
virtualSupply,
|
|
@@ -366,33 +316,22 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
366
316
|
uint256 swapFeeGrowthInvariant,
|
|
367
317
|
uint256 totalNonExemptGrowthInvariant,
|
|
368
318
|
uint256 totalGrowthInvariant
|
|
369
|
-
) = _getGrowthInvariants(
|
|
370
|
-
balances,
|
|
371
|
-
lastJoinExitAmp,
|
|
372
|
-
lastPostJoinExitInvariant,
|
|
373
|
-
imd,
|
|
374
|
-
caches
|
|
375
|
-
);
|
|
319
|
+
) = _getGrowthInvariants(balances, lastJoinExitAmp, lastPostJoinExitInvariant, imd, caches);
|
|
376
320
|
|
|
377
321
|
if (totalGrowthInvariant <= lastPostJoinExitInvariant) {
|
|
378
322
|
return (0, totalGrowthInvariant);
|
|
379
323
|
}
|
|
380
324
|
|
|
381
325
|
uint256 swapFeeGrowthInvariantDelta = swapFeeGrowthInvariant - lastPostJoinExitInvariant;
|
|
382
|
-
uint256 nonExemptYieldGrowthInvariantDelta = totalNonExemptGrowthInvariant -
|
|
383
|
-
swapFeeGrowthInvariant;
|
|
326
|
+
uint256 nonExemptYieldGrowthInvariantDelta = totalNonExemptGrowthInvariant - swapFeeGrowthInvariant;
|
|
384
327
|
|
|
385
|
-
uint256 protocolSwapFeePercentage = swapFeeGrowthInvariantDelta
|
|
386
|
-
.
|
|
387
|
-
|
|
388
|
-
IComposableStable(imd.LP).getProtocolFeePercentageCache(0) // ProtocolFeeType.SWAP // can't get better
|
|
389
|
-
);
|
|
328
|
+
uint256 protocolSwapFeePercentage = swapFeeGrowthInvariantDelta.divDown(totalGrowthInvariant).mulDown(
|
|
329
|
+
IComposableStable(imd.LP).getProtocolFeePercentageCache(0) // ProtocolFeeType.SWAP // can't get better
|
|
330
|
+
);
|
|
390
331
|
|
|
391
|
-
uint256 protocolYieldPercentage = nonExemptYieldGrowthInvariantDelta
|
|
392
|
-
.
|
|
393
|
-
|
|
394
|
-
IComposableStable(imd.LP).getProtocolFeePercentageCache(2) // ProtocolFeeType.YIELD // can't get better
|
|
395
|
-
);
|
|
332
|
+
uint256 protocolYieldPercentage = nonExemptYieldGrowthInvariantDelta.divDown(totalGrowthInvariant).mulDown(
|
|
333
|
+
IComposableStable(imd.LP).getProtocolFeePercentageCache(2) // ProtocolFeeType.YIELD // can't get better
|
|
334
|
+
);
|
|
396
335
|
|
|
397
336
|
// These percentages can then be simply added to compute the total protocol Pool ownership percentage.
|
|
398
337
|
// This is naturally bounded above by FixedPoint.ONE so this addition cannot overflow.
|
|
@@ -408,11 +347,7 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
408
347
|
)
|
|
409
348
|
internal
|
|
410
349
|
pure
|
|
411
|
-
returns (
|
|
412
|
-
uint256 swapFeeGrowthInvariant,
|
|
413
|
-
uint256 totalNonExemptGrowthInvariant,
|
|
414
|
-
uint256 totalGrowthInvariant
|
|
415
|
-
)
|
|
350
|
+
returns (uint256 swapFeeGrowthInvariant, uint256 totalNonExemptGrowthInvariant, uint256 totalGrowthInvariant)
|
|
416
351
|
{
|
|
417
352
|
// Total growth invariant is always calculated with the current (scaled / unadjusted) balances.
|
|
418
353
|
totalGrowthInvariant = lastJoinExitAmp._calculateInvariant(balances);
|
|
@@ -467,19 +402,14 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
467
402
|
return adjustedBalances;
|
|
468
403
|
}
|
|
469
404
|
|
|
470
|
-
function _adjustedBalance(uint256 balance, TokenRateCache memory cache)
|
|
471
|
-
private
|
|
472
|
-
pure
|
|
473
|
-
returns (uint256)
|
|
474
|
-
{
|
|
405
|
+
function _adjustedBalance(uint256 balance, TokenRateCache memory cache) private pure returns (uint256) {
|
|
475
406
|
return (balance * cache.oldRate) / cache.currentRate;
|
|
476
407
|
}
|
|
477
408
|
|
|
478
|
-
function _calculateAdjustedProtocolFeeAmount(
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
{
|
|
409
|
+
function _calculateAdjustedProtocolFeeAmount(
|
|
410
|
+
uint256 supply,
|
|
411
|
+
uint256 basePercentage
|
|
412
|
+
) internal pure returns (uint256) {
|
|
483
413
|
return supply.mulDown(basePercentage).divDown(basePercentage.complement());
|
|
484
414
|
}
|
|
485
415
|
|
|
@@ -487,17 +417,10 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
487
417
|
ImmutableData memory imd,
|
|
488
418
|
uint256[] memory registeredBalances
|
|
489
419
|
) internal view returns (uint256, uint256[] memory) {
|
|
490
|
-
return (
|
|
491
|
-
_getVirtualSupply(imd, registeredBalances[imd.bptIndex]),
|
|
492
|
-
_dropBptItem(imd, registeredBalances)
|
|
493
|
-
);
|
|
420
|
+
return (_getVirtualSupply(imd, registeredBalances[imd.bptIndex]), _dropBptItem(imd, registeredBalances));
|
|
494
421
|
}
|
|
495
422
|
|
|
496
|
-
function _dropBptItem(ImmutableData memory imd, uint256[] memory amounts)
|
|
497
|
-
internal
|
|
498
|
-
pure
|
|
499
|
-
returns (uint256[] memory)
|
|
500
|
-
{
|
|
423
|
+
function _dropBptItem(ImmutableData memory imd, uint256[] memory amounts) internal pure returns (uint256[] memory) {
|
|
501
424
|
uint256[] memory amountsWithoutBpt = new uint256[](amounts.length - 1);
|
|
502
425
|
for (uint256 i = 0; i < amountsWithoutBpt.length; i++) {
|
|
503
426
|
amountsWithoutBpt[i] = amounts[i < imd.bptIndex ? i : i + 1];
|
|
@@ -506,27 +429,19 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
506
429
|
return amountsWithoutBpt;
|
|
507
430
|
}
|
|
508
431
|
|
|
509
|
-
function _getVirtualSupply(ImmutableData memory imd, uint256 bptBalance)
|
|
510
|
-
internal
|
|
511
|
-
view
|
|
512
|
-
returns (uint256)
|
|
513
|
-
{
|
|
432
|
+
function _getVirtualSupply(ImmutableData memory imd, uint256 bptBalance) internal view returns (uint256) {
|
|
514
433
|
return (IERC20(imd.LP).totalSupply()).sub(bptBalance); // can't get better
|
|
515
434
|
}
|
|
516
435
|
|
|
517
|
-
function _beforeSwapJoinExit(
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
returns (TokenRateCache[] memory tokenRateCaches)
|
|
521
|
-
{
|
|
436
|
+
function _beforeSwapJoinExit(
|
|
437
|
+
ImmutableData memory imd
|
|
438
|
+
) internal view returns (TokenRateCache[] memory tokenRateCaches) {
|
|
522
439
|
return _cacheTokenRatesIfNecessary(imd);
|
|
523
440
|
}
|
|
524
441
|
|
|
525
|
-
function _cacheTokenRatesIfNecessary(
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
returns (TokenRateCache[] memory tokenRateCaches)
|
|
529
|
-
{
|
|
442
|
+
function _cacheTokenRatesIfNecessary(
|
|
443
|
+
ImmutableData memory imd
|
|
444
|
+
) internal view returns (TokenRateCache[] memory tokenRateCaches) {
|
|
530
445
|
tokenRateCaches = new TokenRateCache[](imd.totalTokens);
|
|
531
446
|
|
|
532
447
|
for (uint256 i = 0; i < imd.totalTokens; ++i) {
|
|
@@ -537,11 +452,10 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
537
452
|
/**
|
|
538
453
|
* @dev Caches the rate for a token if necessary. It ignores the call if there is no provider set.
|
|
539
454
|
*/
|
|
540
|
-
function _cacheTokenRateIfNecessary(
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
{
|
|
455
|
+
function _cacheTokenRateIfNecessary(
|
|
456
|
+
uint256 index,
|
|
457
|
+
ImmutableData memory imd
|
|
458
|
+
) internal view returns (TokenRateCache memory res) {
|
|
545
459
|
if (index == imd.bptIndex || !_hasRateProvider(imd, index)) return res;
|
|
546
460
|
|
|
547
461
|
uint256 expires;
|
|
@@ -554,12 +468,10 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
554
468
|
}
|
|
555
469
|
}
|
|
556
470
|
|
|
557
|
-
function _scalingFactors(
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
returns (uint256[] memory)
|
|
562
|
-
{
|
|
471
|
+
function _scalingFactors(
|
|
472
|
+
ImmutableData memory imd,
|
|
473
|
+
TokenRateCache[] memory caches
|
|
474
|
+
) internal view virtual returns (uint256[] memory) {
|
|
563
475
|
// There is no need to check the arrays length since both are based on `_getTotalTokens`
|
|
564
476
|
uint256[] memory scalingFactors = new uint256[](imd.totalTokens);
|
|
565
477
|
|
|
@@ -570,12 +482,7 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
570
482
|
return scalingFactors;
|
|
571
483
|
}
|
|
572
484
|
|
|
573
|
-
function _getTokenRate(TokenRateCache[] memory caches, uint256 index)
|
|
574
|
-
internal
|
|
575
|
-
view
|
|
576
|
-
virtual
|
|
577
|
-
returns (uint256)
|
|
578
|
-
{
|
|
485
|
+
function _getTokenRate(TokenRateCache[] memory caches, uint256 index) internal view virtual returns (uint256) {
|
|
579
486
|
return caches[index].currentRate == 0 ? FixedPoint.ONE : caches[index].currentRate;
|
|
580
487
|
}
|
|
581
488
|
|
|
@@ -583,39 +490,25 @@ contract ComposableStablePreviewV5 is ComposableStablePreview {
|
|
|
583
490
|
Helpers functions
|
|
584
491
|
//////////////////////////////////////////////////////////////*/
|
|
585
492
|
|
|
586
|
-
function _upscaleArray(uint256[] memory amounts, uint256[] memory scalingFactors)
|
|
587
|
-
internal
|
|
588
|
-
pure
|
|
589
|
-
{
|
|
493
|
+
function _upscaleArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal pure {
|
|
590
494
|
uint256 length = amounts.length;
|
|
591
495
|
for (uint256 i = 0; i < length; ++i) {
|
|
592
496
|
amounts[i] = FixedPoint.mulDown(amounts[i], scalingFactors[i]);
|
|
593
497
|
}
|
|
594
498
|
}
|
|
595
499
|
|
|
596
|
-
function _downscaleDownArray(uint256[] memory amounts, uint256[] memory scalingFactors)
|
|
597
|
-
internal
|
|
598
|
-
pure
|
|
599
|
-
{
|
|
500
|
+
function _downscaleDownArray(uint256[] memory amounts, uint256[] memory scalingFactors) internal pure {
|
|
600
501
|
uint256 length = amounts.length;
|
|
601
502
|
for (uint256 i = 0; i < length; ++i) {
|
|
602
503
|
amounts[i] = FixedPoint.divDown(amounts[i], scalingFactors[i]);
|
|
603
504
|
}
|
|
604
505
|
}
|
|
605
506
|
|
|
606
|
-
function _hasRateProvider(ImmutableData memory imd, uint256 index)
|
|
607
|
-
internal
|
|
608
|
-
pure
|
|
609
|
-
returns (bool)
|
|
610
|
-
{
|
|
507
|
+
function _hasRateProvider(ImmutableData memory imd, uint256 index) internal pure returns (bool) {
|
|
611
508
|
return address(imd.rateProviders[index]) != address(0);
|
|
612
509
|
}
|
|
613
510
|
|
|
614
|
-
function _isTokenExemptFromYieldProtocolFee(ImmutableData memory imd, uint256 index)
|
|
615
|
-
internal
|
|
616
|
-
pure
|
|
617
|
-
returns (bool)
|
|
618
|
-
{
|
|
511
|
+
function _isTokenExemptFromYieldProtocolFee(ImmutableData memory imd, uint256 index) internal pure returns (bool) {
|
|
619
512
|
return imd.isExemptFromYieldProtocolFee[index];
|
|
620
513
|
}
|
|
621
514
|
}
|
|
@@ -27,7 +27,7 @@ abstract contract BbAPoolHelper is TokenHelper {
|
|
|
27
27
|
uint256 amountIn
|
|
28
28
|
) internal returns (uint256 amountOut) {
|
|
29
29
|
return
|
|
30
|
-
IVault(BALANCER_VAULT).swap{
|
|
30
|
+
IVault(BALANCER_VAULT).swap{value: (tokenIn == NATIVE ? amountIn : 0)}(
|
|
31
31
|
IVault.SingleSwap({
|
|
32
32
|
poolId: poolId,
|
|
33
33
|
kind: IVault.SwapKind.GIVEN_IN,
|
|
@@ -68,10 +68,7 @@ abstract contract BbAWethHelper is BbAPoolHelper {
|
|
|
68
68
|
_safeApproveInfVault(WA_WETH);
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
function _depositBbAWeth(
|
|
72
|
-
address tokenIn,
|
|
73
|
-
uint256 amountDep
|
|
74
|
-
) internal virtual returns (uint256 amountOut) {
|
|
71
|
+
function _depositBbAWeth(address tokenIn, uint256 amountDep) internal virtual returns (uint256 amountOut) {
|
|
75
72
|
amountOut = joinExitPool(address(this), BB_A_WETH_POOL_ID, tokenIn, BB_A_WETH, amountDep);
|
|
76
73
|
}
|
|
77
74
|
|
|
@@ -80,13 +77,7 @@ abstract contract BbAWethHelper is BbAPoolHelper {
|
|
|
80
77
|
address tokenOut,
|
|
81
78
|
uint256 amountRedeem
|
|
82
79
|
) internal virtual returns (uint256 amountTokenOut) {
|
|
83
|
-
amountTokenOut = joinExitPool(
|
|
84
|
-
receiver,
|
|
85
|
-
BB_A_WETH_POOL_ID,
|
|
86
|
-
BB_A_WETH,
|
|
87
|
-
tokenOut,
|
|
88
|
-
amountRedeem
|
|
89
|
-
);
|
|
80
|
+
amountTokenOut = joinExitPool(receiver, BB_A_WETH_POOL_ID, BB_A_WETH, tokenOut, amountRedeem);
|
|
90
81
|
}
|
|
91
82
|
|
|
92
83
|
function _previewDepositBbAWeth(
|
|
@@ -102,10 +93,7 @@ abstract contract BbAWethHelper is BbAPoolHelper {
|
|
|
102
93
|
);
|
|
103
94
|
}
|
|
104
95
|
|
|
105
|
-
function _previewRedeemBbAWeth(
|
|
106
|
-
address tokenOut,
|
|
107
|
-
uint256 amountRedeem
|
|
108
|
-
) internal view returns (uint256 amountOut) {
|
|
96
|
+
function _previewRedeemBbAWeth(address tokenOut, uint256 amountRedeem) internal view returns (uint256 amountOut) {
|
|
109
97
|
return
|
|
110
98
|
linearPreviewHelper.joinExitPoolPreview(
|
|
111
99
|
BB_A_WETH_POOL_ID,
|
package/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/LinearMath.sol
CHANGED
|
@@ -234,9 +234,7 @@ library LinearMath {
|
|
|
234
234
|
uint256 previousInvariant = _calcInvariant(nominalMain, wrappedBalance);
|
|
235
235
|
|
|
236
236
|
uint256 newBptBalance = bptSupply.add(bptOut);
|
|
237
|
-
uint256 newWrappedBalance = divUp(mul(newBptBalance, previousInvariant), bptSupply).sub(
|
|
238
|
-
nominalMain
|
|
239
|
-
);
|
|
237
|
+
uint256 newWrappedBalance = divUp(mul(newBptBalance, previousInvariant), bptSupply).sub(nominalMain);
|
|
240
238
|
|
|
241
239
|
return newWrappedBalance.sub(wrappedBalance);
|
|
242
240
|
}
|
|
@@ -254,18 +252,12 @@ library LinearMath {
|
|
|
254
252
|
uint256 previousInvariant = _calcInvariant(nominalMain, wrappedBalance);
|
|
255
253
|
|
|
256
254
|
uint256 newBptBalance = bptSupply.sub(bptIn);
|
|
257
|
-
uint256 newWrappedBalance = divUp(mul(newBptBalance, previousInvariant), bptSupply).sub(
|
|
258
|
-
nominalMain
|
|
259
|
-
);
|
|
255
|
+
uint256 newWrappedBalance = divUp(mul(newBptBalance, previousInvariant), bptSupply).sub(nominalMain);
|
|
260
256
|
|
|
261
257
|
return wrappedBalance.sub(newWrappedBalance);
|
|
262
258
|
}
|
|
263
259
|
|
|
264
|
-
function _calcInvariant(uint256 nominalMainBalance, uint256 wrappedBalance)
|
|
265
|
-
internal
|
|
266
|
-
pure
|
|
267
|
-
returns (uint256)
|
|
268
|
-
{
|
|
260
|
+
function _calcInvariant(uint256 nominalMainBalance, uint256 wrappedBalance) internal pure returns (uint256) {
|
|
269
261
|
return nominalMainBalance.add(wrappedBalance);
|
|
270
262
|
}
|
|
271
263
|
|
|
@@ -291,18 +283,11 @@ library LinearMath {
|
|
|
291
283
|
// Since real = nominal + fees, rounding down fees is equivalent to rounding down real.
|
|
292
284
|
|
|
293
285
|
if (nominal < params.lowerTarget) {
|
|
294
|
-
return
|
|
295
|
-
(nominal.add(params.fee.mulDown(params.lowerTarget))).divDown(
|
|
296
|
-
FixedPoint.ONE.add(params.fee)
|
|
297
|
-
);
|
|
286
|
+
return (nominal.add(params.fee.mulDown(params.lowerTarget))).divDown(FixedPoint.ONE.add(params.fee));
|
|
298
287
|
} else if (nominal <= params.upperTarget) {
|
|
299
288
|
return nominal;
|
|
300
289
|
} else {
|
|
301
|
-
return (
|
|
302
|
-
nominal.sub(params.fee.mulDown(params.upperTarget)).divDown(
|
|
303
|
-
FixedPoint.ONE.sub(params.fee)
|
|
304
|
-
)
|
|
305
|
-
);
|
|
290
|
+
return (nominal.sub(params.fee.mulDown(params.upperTarget)).divDown(FixedPoint.ONE.sub(params.fee)));
|
|
306
291
|
}
|
|
307
292
|
}
|
|
308
293
|
}
|
|
@@ -352,11 +337,7 @@ library LinearMath {
|
|
|
352
337
|
}
|
|
353
338
|
}
|
|
354
339
|
|
|
355
|
-
function div(
|
|
356
|
-
uint256 a,
|
|
357
|
-
uint256 b,
|
|
358
|
-
bool roundUp
|
|
359
|
-
) internal pure returns (uint256) {
|
|
340
|
+
function div(uint256 a, uint256 b, bool roundUp) internal pure returns (uint256) {
|
|
360
341
|
return roundUp ? divUp(a, b) : divDown(a, b);
|
|
361
342
|
}
|
|
362
343
|
|
|
@@ -30,11 +30,12 @@ contract LinearPreview is BoringOwnableUpgradeable, UUPSUpgradeable {
|
|
|
30
30
|
|
|
31
31
|
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
|
|
32
32
|
|
|
33
|
-
function joinExitPoolPreview(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
function joinExitPoolPreview(
|
|
34
|
+
bytes32 poolId,
|
|
35
|
+
address tokenIn,
|
|
36
|
+
address tokenOut,
|
|
37
|
+
uint256 amountIn
|
|
38
|
+
) external view returns (uint256 amountOut) {
|
|
38
39
|
IVault.SwapRequest memory request = IVault.SwapRequest({
|
|
39
40
|
kind: IVault.SwapKind.GIVEN_IN,
|
|
40
41
|
tokenIn: IERC20(tokenIn),
|
|
@@ -48,7 +49,7 @@ contract LinearPreview is BoringOwnableUpgradeable, UUPSUpgradeable {
|
|
|
48
49
|
userData: EMPTY_BYTES
|
|
49
50
|
});
|
|
50
51
|
|
|
51
|
-
(IERC20[] memory tokens, uint256[] memory balances,) = IVault(BALANCER_VAULT).getPoolTokens(poolId);
|
|
52
|
+
(IERC20[] memory tokens, uint256[] memory balances, ) = IVault(BALANCER_VAULT).getPoolTokens(poolId);
|
|
52
53
|
address pool = address(uint160(uint256(poolId) >> (12 * 8)));
|
|
53
54
|
IERC20 mainToken = IERC20(IERC4626LinearPool(pool).getMainToken());
|
|
54
55
|
|
|
@@ -56,7 +57,7 @@ contract LinearPreview is BoringOwnableUpgradeable, UUPSUpgradeable {
|
|
|
56
57
|
uint256 indexOut;
|
|
57
58
|
ImmutableData memory imd;
|
|
58
59
|
|
|
59
|
-
for (uint256 i = 0; i < tokens.length;) {
|
|
60
|
+
for (uint256 i = 0; i < tokens.length; ) {
|
|
60
61
|
if (tokens[i] == mainToken) {
|
|
61
62
|
imd._mainToken = mainToken;
|
|
62
63
|
imd._mainIndex = i;
|
|
@@ -135,15 +136,14 @@ contract LinearPreview is BoringOwnableUpgradeable, UUPSUpgradeable {
|
|
|
135
136
|
// request.tokenOut == _mainToken || request.tokenOut == _wrappedToken,
|
|
136
137
|
// Errors.INVALID_TOKEN
|
|
137
138
|
// );
|
|
138
|
-
return
|
|
139
|
-
request.tokenOut == imd._mainToken ? LinearMath._calcMainOutPerBptIn : LinearMath._calcWrappedOutPerBptIn
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
);
|
|
139
|
+
return
|
|
140
|
+
(request.tokenOut == imd._mainToken ? LinearMath._calcMainOutPerBptIn : LinearMath._calcWrappedOutPerBptIn)(
|
|
141
|
+
request.amount,
|
|
142
|
+
balances[imd._mainIndex],
|
|
143
|
+
balances[imd._wrappedIndex],
|
|
144
|
+
_getVirtualSupply(balances[imd._BPT_INDEX], imd.pool),
|
|
145
|
+
params
|
|
146
|
+
);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
149
|
function _swapGivenMainIn(
|
|
@@ -156,15 +156,16 @@ contract LinearPreview is BoringOwnableUpgradeable, UUPSUpgradeable {
|
|
|
156
156
|
// request.tokenOut == _wrappedToken || request.tokenOut == this,
|
|
157
157
|
// Errors.INVALID_TOKEN
|
|
158
158
|
// );
|
|
159
|
-
return
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
return
|
|
160
|
+
request.tokenOut == IERC20(imd.pool)
|
|
161
|
+
? LinearMath._calcBptOutPerMainIn(
|
|
162
|
+
request.amount,
|
|
163
|
+
balances[imd._mainIndex],
|
|
164
|
+
balances[imd._wrappedIndex],
|
|
165
|
+
_getVirtualSupply(balances[imd._BPT_INDEX], imd.pool),
|
|
166
|
+
params
|
|
167
|
+
)
|
|
168
|
+
: LinearMath._calcWrappedOutPerMainIn(request.amount, balances[imd._mainIndex], params);
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
function _swapGivenWrappedIn(
|
|
@@ -174,15 +175,16 @@ contract LinearPreview is BoringOwnableUpgradeable, UUPSUpgradeable {
|
|
|
174
175
|
ImmutableData memory imd
|
|
175
176
|
) internal view returns (uint256) {
|
|
176
177
|
// _require(request.tokenOut == _mainToken || request.tokenOut == this, Errors.INVALID_TOKEN);
|
|
177
|
-
return
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
178
|
+
return
|
|
179
|
+
request.tokenOut == IERC20(imd.pool)
|
|
180
|
+
? LinearMath._calcBptOutPerWrappedIn(
|
|
181
|
+
request.amount,
|
|
182
|
+
balances[imd._mainIndex],
|
|
183
|
+
balances[imd._wrappedIndex],
|
|
184
|
+
_getVirtualSupply(balances[imd._BPT_INDEX], imd.pool),
|
|
185
|
+
params
|
|
186
|
+
)
|
|
187
|
+
: LinearMath._calcMainOutPerWrappedIn(request.amount, balances[imd._mainIndex], params);
|
|
186
188
|
}
|
|
187
189
|
|
|
188
190
|
function _getVirtualSupply(uint256 bptBalance, address pool) internal view returns (uint256) {
|
|
@@ -94,9 +94,7 @@ library MetaStableMath {
|
|
|
94
94
|
for (uint256 i = 0; i < balances.length; i++) {
|
|
95
95
|
uint256 currentWeight = balances[i].divDown(sumBalances);
|
|
96
96
|
balanceRatiosWithFee[i] = balances[i].add(amountsIn[i]).divDown(balances[i]);
|
|
97
|
-
invariantRatioWithFees = invariantRatioWithFees.add(
|
|
98
|
-
balanceRatiosWithFee[i].mulDown(currentWeight)
|
|
99
|
-
);
|
|
97
|
+
invariantRatioWithFees = invariantRatioWithFees.add(balanceRatiosWithFee[i].mulDown(currentWeight));
|
|
100
98
|
}
|
|
101
99
|
|
|
102
100
|
// Second loop calculates new amounts in, taking into account the fee on the percentage excess
|
|
@@ -106,9 +104,7 @@ library MetaStableMath {
|
|
|
106
104
|
|
|
107
105
|
// Check if the balance ratio is greater than the ideal ratio to charge fees or not
|
|
108
106
|
if (balanceRatiosWithFee[i] > invariantRatioWithFees) {
|
|
109
|
-
uint256 nonTaxableAmount = balances[i].mulDown(
|
|
110
|
-
invariantRatioWithFees.sub(FixedPoint.ONE)
|
|
111
|
-
);
|
|
107
|
+
uint256 nonTaxableAmount = balances[i].mulDown(invariantRatioWithFees.sub(FixedPoint.ONE));
|
|
112
108
|
uint256 taxableAmount = amountsIn[i].sub(nonTaxableAmount);
|
|
113
109
|
// No need to use checked arithmetic for the swap fee, it is guaranteed to be lower than 50%
|
|
114
110
|
amountInWithoutFee = nonTaxableAmount.add(
|
|
@@ -148,9 +144,7 @@ library MetaStableMath {
|
|
|
148
144
|
|
|
149
145
|
// Get the current and new invariants. Since we need a bigger new invariant, we round the current one up.
|
|
150
146
|
uint256 currentInvariant = _calculateInvariant(amp, balances, true);
|
|
151
|
-
uint256 newInvariant = bptTotalSupply.sub(bptAmountIn).divUp(bptTotalSupply).mulUp(
|
|
152
|
-
currentInvariant
|
|
153
|
-
);
|
|
147
|
+
uint256 newInvariant = bptTotalSupply.sub(bptAmountIn).divUp(bptTotalSupply).mulUp(currentInvariant);
|
|
154
148
|
|
|
155
149
|
// Calculate amount out without fee
|
|
156
150
|
uint256 newBalanceTokenIndex = _getTokenBalanceGivenInvariantAndAllOtherBalances(
|
|
@@ -248,10 +242,7 @@ library MetaStableMath {
|
|
|
248
242
|
|
|
249
243
|
uint256 inv2 = mul(invariant, invariant);
|
|
250
244
|
// We remove the balance from c by multiplying it
|
|
251
|
-
uint256 c = mul(
|
|
252
|
-
mul(divUp(inv2, mul(ampTimesTotal, P_D)), _AMP_PRECISION),
|
|
253
|
-
balances[tokenIndex]
|
|
254
|
-
);
|
|
245
|
+
uint256 c = mul(mul(divUp(inv2, mul(ampTimesTotal, P_D)), _AMP_PRECISION), balances[tokenIndex]);
|
|
255
246
|
uint256 b = sum.add(mul(divDown(invariant, ampTimesTotal), _AMP_PRECISION));
|
|
256
247
|
|
|
257
248
|
// We iterate to find the balance
|