@pendle/core-v2 2.17.7-tradingbot → 2.18.0-tradingbot

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (216) hide show
  1. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiveEndpointUpg.sol/PendleMsgReceiveEndpointUpg.dbg.json +1 -1
  2. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgReceiverAppUpg.sol/PendleMsgReceiverAppUpg.dbg.json +1 -1
  3. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgSendEndpointUpg.sol/PendleMsgSendEndpointUpg.dbg.json +1 -1
  4. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/PendleMsgSenderAppUpg.sol/PendleMsgSenderAppUpg.dbg.json +1 -1
  5. package/build/artifacts/contracts/LiquidityMining/CrossChainMsg/libraries/LayerZeroHelper.sol/LayerZeroHelper.dbg.json +1 -1
  6. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerBaseUpg.sol/PendleGaugeControllerBaseUpg.dbg.json +1 -1
  7. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerMainchainUpg.sol/PendleGaugeControllerMainchainUpg.dbg.json +1 -1
  8. package/build/artifacts/contracts/LiquidityMining/GaugeController/PendleGaugeControllerSidechainUpg.sol/PendleGaugeControllerSidechainUpg.dbg.json +1 -1
  9. package/build/artifacts/contracts/LiquidityMining/VeDistributor/PendleFeeDistributor.sol/PendleFeeDistributor.dbg.json +1 -1
  10. package/build/artifacts/contracts/LiquidityMining/VeDistributor/PendleFeeDistributorV2.sol/PendleFeeDistributorV2.dbg.json +1 -1
  11. package/build/artifacts/contracts/LiquidityMining/VotingController/PendleVotingControllerUpg.sol/PendleVotingControllerUpg.dbg.json +1 -1
  12. package/build/artifacts/contracts/LiquidityMining/VotingController/VotingControllerStorageUpg.sol/VotingControllerStorageUpg.dbg.json +1 -1
  13. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleMainchain.sol/VotingEscrowPendleMainchain.dbg.json +1 -1
  14. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowPendleSidechain.sol/VotingEscrowPendleSidechain.dbg.json +1 -1
  15. package/build/artifacts/contracts/LiquidityMining/VotingEscrow/VotingEscrowTokenBase.sol/VotingEscrowTokenBase.dbg.json +1 -1
  16. package/build/artifacts/contracts/LiquidityMining/libraries/VeBalanceLib.sol/VeBalanceLib.dbg.json +1 -1
  17. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/CheckpointHelper.dbg.json +1 -1
  18. package/build/artifacts/contracts/LiquidityMining/libraries/VeHistoryLib.sol/Checkpoints.dbg.json +1 -1
  19. package/build/artifacts/contracts/core/BulkSeller/BulkSeller.sol/BulkSeller.dbg.json +1 -1
  20. package/build/artifacts/contracts/core/BulkSeller/BulkSellerFactory.sol/BulkSellerFactory.dbg.json +1 -1
  21. package/build/artifacts/contracts/core/BulkSeller/BulkSellerMathCore.sol/BulkSellerMathCore.dbg.json +1 -1
  22. package/build/artifacts/contracts/core/Market/MarketMathCore.sol/MarketMathCore.dbg.json +1 -1
  23. package/build/artifacts/contracts/core/Market/OracleLib.sol/OracleLib.dbg.json +1 -1
  24. package/build/artifacts/contracts/core/Market/PendleGauge.sol/PendleGauge.dbg.json +1 -1
  25. package/build/artifacts/contracts/core/Market/PendleMarket.sol/PendleMarket.dbg.json +1 -1
  26. package/build/artifacts/contracts/core/Market/PendleMarketFactory.sol/PendleMarketFactory.dbg.json +1 -1
  27. package/build/artifacts/contracts/core/RewardManager/RewardManager.sol/RewardManager.dbg.json +1 -1
  28. package/build/artifacts/contracts/core/RewardManager/RewardManagerAbstract.sol/RewardManagerAbstract.dbg.json +1 -1
  29. package/build/artifacts/contracts/core/StandardizedYield/PYIndex.sol/PYIndexLib.dbg.json +1 -1
  30. package/build/artifacts/contracts/core/StandardizedYield/SYBase.sol/SYBase.dbg.json +1 -1
  31. package/build/artifacts/contracts/core/StandardizedYield/SYBaseWithRewards.sol/SYBaseWithRewards.dbg.json +1 -1
  32. package/build/artifacts/contracts/core/StandardizedYield/implementations/Ape/sAPE.sol/sAPE.dbg.json +1 -1
  33. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraBbAWethSwethSY.sol/PendleAuraBbAWethSwethSY.dbg.json +1 -1
  34. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethAnkrethSYV2.sol/PendleAuraWethAnkrethSYV2.dbg.json +1 -1
  35. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethRocketEthSYV2.sol/PendleAuraWethRocketEthSYV2.dbg.json +1 -1
  36. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethStafiEthSY.sol/PendleAuraWethStafiEthSY.dbg.json +1 -1
  37. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/PendleAuraWethWstethSYV2.sol/PendleAuraWethWstethSYV2.dbg.json +1 -1
  38. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStableMath.sol/ComposableStableMath.dbg.json +1 -1
  39. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/ComposableStable/ComposableStablePreview.sol/ComposableStablePreview.dbg.json +1 -1
  40. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/BbAPoolHelper.sol/BbAPoolHelper.dbg.json +1 -1
  41. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/BbAPoolHelper.sol/BbAWethHelper.dbg.json +1 -1
  42. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/LinearMath.sol/LinearMath.dbg.json +1 -1
  43. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/Linear/LinearPreview.sol/LinearPreview.dbg.json +1 -1
  44. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/MetaStable/MetaStablePreview.sol/MetaStablePreview.dbg.json +1 -1
  45. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/PendleAuraBalancerStableLPSYV2.sol/PendleAuraBalancerStableLPSYV2.dbg.json +1 -1
  46. package/build/artifacts/contracts/core/StandardizedYield/implementations/BalancerStable/base/StablePreviewBase.sol/StablePreviewBase.dbg.json +1 -1
  47. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenHelper.sol/PendleQiTokenHelper.dbg.json +1 -1
  48. package/build/artifacts/contracts/core/StandardizedYield/implementations/BenQi/PendleQiTokenSY.sol/PendleQiTokenSY.dbg.json +1 -1
  49. package/build/artifacts/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotRewardHelper.sol/CamelotRewardHelper.dbg.json +1 -1
  50. package/build/artifacts/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatileCommon.sol/CamelotV1VolatileCommon.dbg.json +1 -1
  51. package/build/artifacts/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatileLpHelper.sol/CamelotV1VolatileLpHelper.dbg.json +1 -1
  52. package/build/artifacts/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/CamelotV1VolatilePreview.sol/CamelotV1VolatilePreview.dbg.json +1 -1
  53. package/build/artifacts/contracts/core/StandardizedYield/implementations/CamelotV1Volatile/PendleCamelotV1VolatileSY.sol/PendleCamelotV1VolatileSY.dbg.json +1 -1
  54. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveFraxUsdcSY.sol/PendleCurveFraxUsdcSY.dbg.json +1 -1
  55. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/PendleCurveUsdd3CrvSY.sol/PendleCurveUsdd3CrvSY.dbg.json +1 -1
  56. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/base/Curve3CrvPoolHelper.sol/Curve3CrvPoolHelper.dbg.json +1 -1
  57. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/base/CurveFraxUsdcPoolHelper.sol/CurveFraxUsdcPoolHelper.dbg.json +1 -1
  58. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/base/CurveUsdd3CrvPoolHelper.sol/CurveUsdd3CrvPoolHelper.dbg.json +1 -1
  59. package/build/artifacts/contracts/core/StandardizedYield/implementations/Convex/base/PendleConvexLPSY.sol/PendleConvexLPSY.dbg.json +1 -1
  60. package/build/artifacts/contracts/core/StandardizedYield/implementations/GLP/PendleGlpSY.sol/PendleGlpSY.dbg.json +1 -1
  61. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleGdaiSY.sol/PendleGDaiSY.dbg.json +1 -1
  62. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleLooksStakingSY.sol/PendleLooksStakingSY.dbg.json +1 -1
  63. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleSfrxEthSY.sol/PendleSfrxEthSY.dbg.json +1 -1
  64. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleStargateLPSY.sol/PendleStargateLPSY.dbg.json +1 -1
  65. package/build/artifacts/contracts/core/StandardizedYield/implementations/PendleWstEthSY.sol/PendleWstEthSY.dbg.json +1 -1
  66. package/build/artifacts/contracts/core/TradingBot/BotActionCallback.sol/BotActionCallback.dbg.json +1 -1
  67. package/build/artifacts/contracts/core/TradingBot/BotActionCallback.sol/BotActionCallback.json +32 -17
  68. package/build/artifacts/contracts/core/TradingBot/BotActionHelper.sol/BotActionHelper.dbg.json +1 -1
  69. package/build/artifacts/contracts/core/TradingBot/BotActionHelper.sol/BotActionHelper.json +32 -17
  70. package/build/artifacts/contracts/core/TradingBot/BotSimulationLib.sol/BotSimulationLib.dbg.json +1 -1
  71. package/build/artifacts/contracts/core/TradingBot/BotSimulationLib.sol/BotSimulationLib.json +2 -2
  72. package/build/artifacts/contracts/core/TradingBot/LongYieldDecisionHelper.sol/LongYieldDecisionHelper.dbg.json +4 -0
  73. package/build/artifacts/contracts/core/TradingBot/LongYieldDecisionHelper.sol/LongYieldDecisionHelper.json +1190 -0
  74. package/build/artifacts/contracts/core/TradingBot/LongYieldTradingBot.sol/LongYieldTradingBot.dbg.json +1 -1
  75. package/build/artifacts/contracts/core/TradingBot/LongYieldTradingBot.sol/LongYieldTradingBot.json +301 -397
  76. package/build/artifacts/contracts/core/TradingBot/MarketExtLib.sol/MarketExtLib.dbg.json +1 -1
  77. package/build/artifacts/contracts/core/TradingBot/SpecSegmentLib.sol/SpecSegmentLib.dbg.json +4 -0
  78. package/build/artifacts/contracts/core/TradingBot/SpecSegmentLib.sol/SpecSegmentLib.json +10 -0
  79. package/build/artifacts/contracts/core/TradingBot/TradingBotBase.sol/TradingBotBase.dbg.json +1 -1
  80. package/build/artifacts/contracts/core/TradingBot/TradingBotBase.sol/TradingBotBase.json +32 -17
  81. package/build/artifacts/contracts/core/YieldContracts/InterestManagerYT.sol/InterestManagerYT.dbg.json +1 -1
  82. package/build/artifacts/contracts/core/YieldContracts/PendlePrincipalToken.sol/PendlePrincipalToken.dbg.json +1 -1
  83. package/build/artifacts/contracts/core/YieldContracts/PendleYieldContractFactory.sol/PendleYieldContractFactory.dbg.json +1 -1
  84. package/build/artifacts/contracts/core/YieldContracts/PendleYieldToken.sol/PendleYieldToken.dbg.json +1 -1
  85. package/build/artifacts/contracts/core/YieldContractsV2/InterestManagerYTV2.sol/InterestManagerYTV2.dbg.json +1 -1
  86. package/build/artifacts/contracts/core/YieldContractsV2/PendlePrincipalTokenV2.sol/PendlePrincipalTokenV2.dbg.json +1 -1
  87. package/build/artifacts/contracts/core/YieldContractsV2/PendleYieldContractFactoryV2.sol/PendleYieldContractFactoryV2.dbg.json +1 -1
  88. package/build/artifacts/contracts/core/YieldContractsV2/PendleYieldTokenV2.sol/PendleYieldTokenV2.dbg.json +1 -1
  89. package/build/artifacts/contracts/core/libraries/Errors.sol/Errors.dbg.json +1 -1
  90. package/build/artifacts/contracts/core/libraries/TokenAmountLib.sol/TokenAmountLib.dbg.json +1 -1
  91. package/build/artifacts/contracts/core/libraries/math/Math.sol/Math.dbg.json +1 -1
  92. package/build/artifacts/contracts/interfaces/Balancer/IBalancerStablePreview.sol/IBalancerStablePreview.dbg.json +1 -1
  93. package/build/artifacts/contracts/interfaces/Balancer/IERC4626LinearPool.sol/IERC4626LinearPool.dbg.json +1 -1
  94. package/build/artifacts/contracts/interfaces/Balancer/IVault.sol/IVault.dbg.json +1 -1
  95. package/build/artifacts/contracts/interfaces/Camelot/ICamelotNFTPool.sol/ICamelotNFTPool.dbg.json +1 -1
  96. package/build/artifacts/contracts/interfaces/Camelot/ICamelotNitroPool.sol/ICamelotNitroPool.dbg.json +1 -1
  97. package/build/artifacts/contracts/interfaces/Camelot/ICamelotPair.sol/ICamelotPair.dbg.json +1 -1
  98. package/build/artifacts/contracts/interfaces/IPActionAddRemoveLiq.sol/IPActionAddRemoveLiq.dbg.json +1 -1
  99. package/build/artifacts/contracts/interfaces/IPActionInfoStatic.sol/IPActionInfoStatic.dbg.json +1 -1
  100. package/build/artifacts/contracts/interfaces/IPActionMarketAuxStatic.sol/IPActionMarketAuxStatic.dbg.json +1 -1
  101. package/build/artifacts/contracts/interfaces/IPActionMarketCoreStatic.sol/IPActionMarketCoreStatic.dbg.json +1 -1
  102. package/build/artifacts/contracts/interfaces/IPActionMintRedeem.sol/IPActionMintRedeem.dbg.json +1 -1
  103. package/build/artifacts/contracts/interfaces/IPActionMintRedeemStatic.sol/IPActionMintRedeemStatic.dbg.json +1 -1
  104. package/build/artifacts/contracts/interfaces/IPActionStorageStatic.sol/IPActionStorageStatic.dbg.json +1 -1
  105. package/build/artifacts/contracts/interfaces/IPActionSwapPT.sol/IPActionSwapPT.dbg.json +1 -1
  106. package/build/artifacts/contracts/interfaces/IPActionSwapYT.sol/IPActionSwapYT.dbg.json +1 -1
  107. package/build/artifacts/contracts/interfaces/IPAllAction.sol/IPAllAction.dbg.json +1 -1
  108. package/build/artifacts/contracts/interfaces/IPBulkSeller.sol/IPBulkSeller.dbg.json +1 -1
  109. package/build/artifacts/contracts/interfaces/IPGauge.sol/IPGauge.dbg.json +1 -1
  110. package/build/artifacts/contracts/interfaces/IPMarket.sol/IPMarket.dbg.json +1 -1
  111. package/build/artifacts/contracts/interfaces/IPRouterHelper.sol/IPRouterHelper.dbg.json +1 -1
  112. package/build/artifacts/contracts/interfaces/IPRouterStatic.sol/IPRouterStatic.dbg.json +1 -1
  113. package/build/artifacts/contracts/interfaces/IPVotingController.sol/IPVotingController.dbg.json +1 -1
  114. package/build/artifacts/contracts/interfaces/IPVotingEscrowMainchain.sol/IPVotingEscrowMainchain.dbg.json +1 -1
  115. package/build/artifacts/contracts/interfaces/IPYieldContractFactory.sol/IPYieldContractFactory.dbg.json +1 -1
  116. package/build/artifacts/contracts/interfaces/IStandardizedYield.sol/IStandardizedYield.dbg.json +1 -1
  117. package/build/artifacts/contracts/interfaces/TradingBot/IBotDecisionHelper.sol/IBotDecisionHelper.dbg.json +1 -1
  118. package/build/artifacts/contracts/interfaces/TradingBot/IBotDecisionHelper.sol/IBotDecisionHelper.json +542 -581
  119. package/build/artifacts/contracts/interfaces/TradingBot/ILongYieldTradingBot.sol/ILongYieldTradingBot.dbg.json +1 -1
  120. package/build/artifacts/contracts/interfaces/TradingBot/ILongYieldTradingBot.sol/ILongYieldTradingBot.json +256 -325
  121. package/build/artifacts/contracts/interfaces/TradingBot/ITradingBotBase.sol/ITradingBotBase.dbg.json +1 -1
  122. package/build/artifacts/contracts/interfaces/TradingBot/ITradingBotBase.sol/ITradingBotBase.json +6 -17
  123. package/build/artifacts/contracts/offchain-helpers/BoringLpSeller.sol/BoringLpSeller.dbg.json +1 -1
  124. package/build/artifacts/contracts/offchain-helpers/BoringPtSeller.sol/BoringPtSeller.dbg.json +1 -1
  125. package/build/artifacts/contracts/offchain-helpers/Broadcaster.sol/Broadcaster.dbg.json +1 -1
  126. package/build/artifacts/contracts/offchain-helpers/BulkSellerOffchain.sol/BulkSellerOffchain.dbg.json +1 -1
  127. package/build/artifacts/contracts/offchain-helpers/MarketExchangeRateLib.sol/MarketExchangeRateLib.dbg.json +1 -1
  128. package/build/artifacts/contracts/offchain-helpers/router-static/PendleRouterStatic.sol/PendleRouterStatic.dbg.json +1 -1
  129. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionInfoStatic.sol/ActionInfoStatic.dbg.json +1 -1
  130. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketAuxStatic.sol/ActionMarketAuxStatic.dbg.json +1 -1
  131. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMarketCoreStatic.sol/ActionMarketCoreStatic.dbg.json +1 -1
  132. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionMintRedeemStatic.sol/ActionMintRedeemStatic.dbg.json +1 -1
  133. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionStorageStatic.sol/ActionStorageStatic.dbg.json +1 -1
  134. package/build/artifacts/contracts/offchain-helpers/router-static/base/ActionVePendleStatic.sol/ActionVePendleStatic.dbg.json +1 -1
  135. package/build/artifacts/contracts/offchain-helpers/router-static/base/StorageLayout.sol/StorageLayout.dbg.json +1 -1
  136. package/build/artifacts/contracts/oracles/PendleLpOracleLib.sol/PendleLpOracleLib.dbg.json +1 -1
  137. package/build/artifacts/contracts/oracles/PendlePtOracle.sol/PendlePtOracle.dbg.json +1 -1
  138. package/build/artifacts/contracts/oracles/PendlePtOracleLib.sol/PendlePtOracleLib.dbg.json +1 -1
  139. package/build/artifacts/contracts/oracles/samples/PendleLpGlpOracle.sol/PendleLpGlpOracle.dbg.json +1 -1
  140. package/build/artifacts/contracts/oracles/samples/PendlePtGlpOracle.sol/PendlePtGlpOracle.dbg.json +1 -1
  141. package/build/artifacts/contracts/oracles/samples/PendlePtUsdChainlinkOracle.sol/PendlePtUsdChainlinkOracle.dbg.json +1 -1
  142. package/build/artifacts/contracts/router/ActionAddRemoveLiq.sol/ActionAddRemoveLiq.dbg.json +1 -1
  143. package/build/artifacts/contracts/router/ActionMintRedeem.sol/ActionMintRedeem.dbg.json +1 -1
  144. package/build/artifacts/contracts/router/ActionSwapPT.sol/ActionSwapPT.dbg.json +1 -1
  145. package/build/artifacts/contracts/router/ActionSwapYT.sol/ActionSwapYT.dbg.json +1 -1
  146. package/build/artifacts/contracts/router/PendleRouter.sol/PendleRouter.dbg.json +1 -1
  147. package/build/artifacts/contracts/router/PendleRouterHelper.sol/PendleRouterHelper.dbg.json +1 -1
  148. package/build/artifacts/contracts/router/base/ActionBaseCallback.sol/ActionBaseCallback.dbg.json +1 -1
  149. package/build/artifacts/contracts/router/base/ActionBaseMintRedeem.sol/ActionBaseMintRedeem.dbg.json +1 -1
  150. package/build/artifacts/contracts/router/base/CallbackHelper.sol/CallbackHelper.dbg.json +1 -1
  151. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtInLib.dbg.json +1 -1
  152. package/build/artifacts/contracts/router/base/MarketApproxLib.sol/MarketApproxPtOutLib.dbg.json +1 -1
  153. package/build/artifacts/contracts/router/swap-aggregator/PendleSwap.sol/PendleSwap.dbg.json +1 -1
  154. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/IAggregationExecutor.sol/IAggregationExecutor.dbg.json +1 -1
  155. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/IExecutorHelper.sol/IExecutorHelper.dbg.json +1 -1
  156. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/IHashflow.sol/IHashflow.dbg.json +1 -1
  157. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/IMetaAggregationRouterV2.sol/IMetaAggregationRouterV2.dbg.json +1 -1
  158. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/KyberInputScalingHelper.sol/KyberInputScalingHelper.dbg.json +1 -1
  159. package/build/artifacts/contracts/router/swap-aggregator/kyberswap/ScalingDataLib.sol/ScalingDataLib.dbg.json +1 -1
  160. package/contracts/core/TradingBot/BotActionCallback.sol +1 -1
  161. package/contracts/core/TradingBot/BotActionHelper.sol +1 -3
  162. package/contracts/core/TradingBot/BotSimulationLib.sol +2 -1
  163. package/contracts/core/TradingBot/LongYieldDecisionHelper.sol +413 -0
  164. package/contracts/core/TradingBot/LongYieldTradingBot.sol +63 -91
  165. package/contracts/core/TradingBot/SpecSegmentLib.sol +62 -0
  166. package/contracts/core/TradingBot/TradingBotBase.sol +14 -9
  167. package/contracts/interfaces/TradingBot/IBotDecisionHelper.sol +41 -57
  168. package/contracts/interfaces/TradingBot/ILongYieldTradingBot.sol +24 -34
  169. package/contracts/interfaces/TradingBot/ITradingBotBase.sol +1 -3
  170. package/package.json +1 -1
  171. package/typechain-types/BotActionCallback.ts +40 -22
  172. package/typechain-types/BotActionHelper.ts +40 -22
  173. package/typechain-types/BotDecisionHelper.ts +221 -187
  174. package/typechain-types/IAnkrBNB.ts +150 -0
  175. package/typechain-types/IAnkrLiquidStaking.ts +253 -0
  176. package/typechain-types/IBotDecisionHelper.ts +142 -212
  177. package/typechain-types/ILongYieldTradingBot.ts +147 -230
  178. package/typechain-types/ISwETH.ts +123 -0
  179. package/typechain-types/ITradingBotBase.ts +14 -22
  180. package/typechain-types/LongYieldDecisionHelper.ts +598 -0
  181. package/typechain-types/LongYieldTradingBot.ts +191 -248
  182. package/typechain-types/PendleAnkrBNBSY.ts +1235 -0
  183. package/typechain-types/PendleAuraWstethAnkreth.ts +1511 -0
  184. package/typechain-types/PendleSwETH.ts +1216 -0
  185. package/typechain-types/PendleThenaSY.ts +153 -0
  186. package/typechain-types/PendleWbEthSY.ts +1229 -0
  187. package/typechain-types/ThenaLpHelper.ts +19 -0
  188. package/typechain-types/ThenaMath.ts +87 -0
  189. package/typechain-types/ThenaPreview.ts +19 -0
  190. package/typechain-types/TradingBotBase.ts +40 -22
  191. package/typechain-types/factories/BotActionCallback__factory.ts +31 -16
  192. package/typechain-types/factories/BotActionHelper__factory.ts +31 -16
  193. package/typechain-types/factories/BotDecisionHelper__factory.ts +490 -421
  194. package/typechain-types/factories/IAnkrBNB__factory.ts +74 -0
  195. package/typechain-types/factories/IAnkrLiquidStaking__factory.ts +123 -0
  196. package/typechain-types/factories/IBotDecisionHelper__factory.ts +540 -579
  197. package/typechain-types/factories/ILongYieldTradingBot__factory.ts +255 -324
  198. package/typechain-types/factories/ISwETH__factory.ts +53 -0
  199. package/typechain-types/factories/ITradingBotBase__factory.ts +6 -17
  200. package/typechain-types/factories/LongYieldDecisionHelper__factory.ts +1247 -0
  201. package/typechain-types/factories/LongYieldTradingBot__factory.ts +301 -393
  202. package/typechain-types/factories/PendleAnkrBNBSY__factory.ts +1100 -0
  203. package/typechain-types/factories/PendleAuraWstethAnkreth__factory.ts +1244 -0
  204. package/typechain-types/factories/PendleSwETH__factory.ts +1022 -0
  205. package/typechain-types/factories/PendleThenaSY__factory.ts +85 -1
  206. package/typechain-types/factories/PendleWbEthSY__factory.ts +1049 -0
  207. package/typechain-types/factories/PtAndLpToAsset__factory.ts +1 -1
  208. package/typechain-types/factories/ThenaLpHelper__factory.ts +13 -0
  209. package/typechain-types/factories/ThenaMath__factory.ts +36 -0
  210. package/typechain-types/factories/ThenaPreview__factory.ts +14 -1
  211. package/typechain-types/factories/TradingBotBase__factory.ts +31 -16
  212. package/typechain-types/hardhat.d.ts +4 -40
  213. package/typechain-types/index.ts +2 -10
  214. package/build/artifacts/contracts/core/TradingBot/BotDecisionHelper.sol/BotDecisionHelper.dbg.json +0 -4
  215. package/build/artifacts/contracts/core/TradingBot/BotDecisionHelper.sol/BotDecisionHelper.json +0 -1070
  216. package/contracts/core/TradingBot/BotDecisionHelper.sol +0 -306
@@ -0,0 +1,413 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity ^0.8.0;
3
+
4
+ import "./BotSimulationLib.sol";
5
+ import "../libraries/Errors.sol";
6
+ import "./SpecSegmentLib.sol";
7
+ import "../../interfaces/TradingBot/IBotDecisionHelper.sol";
8
+ import "../../interfaces/TradingBot/ILongYieldTradingBot.sol";
9
+
10
+ contract LongYieldDecisionHelper is IBotDecisionHelper {
11
+ using MarketExtLib for MarketExtState;
12
+ using MarketExtLib for ApproxParams;
13
+ using MarketMathCore for MarketState;
14
+ using MarketApproxPtInLib for MarketState;
15
+ using BotSimulationLib for BotState;
16
+ using PYIndexLib for PYIndex;
17
+ using Math for uint256;
18
+ using Math for int256;
19
+ using LogExpMath for uint256;
20
+ using SpecSegmentLib for LongTradingSpecs;
21
+
22
+ uint256 public constant MINIMAL_EPS = 100000000000000;
23
+ uint256 public constant INF = type(uint256).max;
24
+
25
+ function getAvailableZpiAmount(address botAddress) public returns (uint256 amountSyToZpi) {
26
+ StrategyData memory strategyData = ILongYieldTradingBot(botAddress).readStrategyData();
27
+ (uint256 tvlInSy, , uint256 syRatio, ) = _calcBotExtStats(
28
+ strategyData.botState,
29
+ strategyData.marketExt
30
+ );
31
+ if (syRatio < strategyData.specs.maxSyRatio) return 0;
32
+
33
+ return strategyData.botState.syBalance - tvlInSy.mulDown(strategyData.specs.targetSyRatio);
34
+ }
35
+
36
+ /**
37
+ * Return the current bin corresponds to market state
38
+ *
39
+ * Negative value -> buy bin, b_abs(currentBin)
40
+ * Positive value -> sell bin, s_abs(currentBin)
41
+ * Zero -> Do nothing
42
+ */
43
+ function getCurrentBin(StrategyData memory strategyData) public view returns (int256) {
44
+ return
45
+ _getCurrentBin(
46
+ strategyData.botState,
47
+ strategyData.specs,
48
+ strategyData.marketExt.impliedYield()
49
+ );
50
+ }
51
+
52
+ // We dont care about AddLiqKeepYt here
53
+ function getActionDetails(address botAddress) public returns (ActionToTakeResult memory res) {
54
+ StrategyData memory strategyData = ILongYieldTradingBot(botAddress).readStrategyData();
55
+ uint256 iy = strategyData.marketExt.impliedYield();
56
+
57
+ res.currentBin = _getCurrentBin(strategyData.botState, strategyData.specs, iy);
58
+ if (res.currentBin == 0) {
59
+ res.action = ActionType.NONE;
60
+ return res;
61
+ }
62
+ res.targetIy = _getTargetImpliedYieldForBin(
63
+ strategyData.botState,
64
+ strategyData.specs,
65
+ res.currentBin
66
+ );
67
+
68
+ uint256 maxAmountForAction = INF;
69
+ uint256 rebalanceAdditionalCheck;
70
+
71
+ if (res.currentBin < 0) {
72
+ res.action = ActionType.RemoveLiqToYt;
73
+ maxAmountForAction = _calcMaxAmountForAction(
74
+ strategyData.botState.lpBalance,
75
+ res.currentBin,
76
+ strategyData.botState.buyBins,
77
+ strategyData.specs.numOfBins
78
+ );
79
+
80
+ if (maxAmountForAction == 0) {
81
+ return res;
82
+ }
83
+ } else {
84
+ res.action = ActionType.AddLiqFromYt;
85
+ uint256 maxYtToAddLiq = _searchMaxYtToAddLiq(strategyData);
86
+
87
+ rebalanceAdditionalCheck = _calcMaxAmountForAction(
88
+ maxYtToAddLiq,
89
+ res.currentBin,
90
+ strategyData.botState.buyBins,
91
+ strategyData.specs.numOfBins
92
+ );
93
+
94
+ if (rebalanceAdditionalCheck == 0) {
95
+ return res;
96
+ }
97
+ }
98
+
99
+ res.guessBotParams = searchForBotParam(
100
+ strategyData,
101
+ res.action,
102
+ res.targetIy,
103
+ rebalanceAdditionalCheck,
104
+ _getMockApproxParamsWithGuessMax(maxAmountForAction),
105
+ _getMockApproxParams()
106
+ );
107
+ (res.amountOut, res.guessIntParams) = _calcAmountOutAndIntParams(
108
+ strategyData.marketExt,
109
+ res.action,
110
+ res.guessBotParams
111
+ );
112
+ }
113
+
114
+ /**
115
+ * Binary search for the smallest parameter `botParam` for the corresponding rebalancing action
116
+ * such that the bot reaches desired target, otherwise give the largest `botParam` possible
117
+ * that action doesn't revert.
118
+ *
119
+ * @param action Action to take, from which target is derived
120
+ * @param botParams ApproxParams for `botParam`
121
+ * @param intParams ApproxParams for internal action's approximation (e.g. for router's swap)
122
+ *
123
+ * For `botParams`, eps = the precision such that slightly lower
124
+ * (param = (return value) * (1 - eps)) does not reach target
125
+ *
126
+ * - Returns `botParams.guessOffchain` if it reaches target, and slightly lower does not
127
+ * - Reverts if `botParams.guessMin` is invalid, or returns `botParams.guessMin` if reaches
128
+ * target
129
+ * - Returns `botParams.guessMax` if it is valid & does not reach target
130
+ * - Otherwise, binary search for `guess` such that it reaches target, and slightly lower does
131
+ * not
132
+ *
133
+ */
134
+ function searchForBotParam(
135
+ StrategyData memory strategyData,
136
+ ActionType action,
137
+ uint256 targetIy,
138
+ uint256 rebalanceAdditionalCheck,
139
+ ApproxParams memory botParams,
140
+ ApproxParams memory intParams
141
+ ) public pure returns (uint256) {
142
+ RebalanceDetails memory rebalance = RebalanceDetails(strategyData, action, targetIy);
143
+ if (botParams.guessOffchain != 0) {
144
+ // guessoffchain is good
145
+ if (
146
+ _rebalanceResult(
147
+ rebalance,
148
+ botParams.guessOffchain,
149
+ rebalanceAdditionalCheck,
150
+ botParams.eps,
151
+ intParams
152
+ ) == RebalanceResult.SUCCESS
153
+ ) return botParams.guessOffchain;
154
+ }
155
+
156
+ {
157
+ // invalid range
158
+ uint256 guessUpperBound = _weakUpperBound(
159
+ strategyData.botState,
160
+ strategyData.marketExt,
161
+ action
162
+ );
163
+ if (botParams.guessMax > guessUpperBound) botParams.guessMax = guessUpperBound;
164
+ if (botParams.guessMin > botParams.guessMax)
165
+ revert Errors.BotBinarySearchInvalidRange(
166
+ uint256(action),
167
+ botParams.guessMin,
168
+ botParams.guessMax
169
+ );
170
+ }
171
+
172
+ {
173
+ // if botParams.guessMax is either success or unsatisfied (target_not_reached), then we'll just go with it
174
+ if (
175
+ _rebalanceResult(
176
+ rebalance,
177
+ botParams.guessMax,
178
+ rebalanceAdditionalCheck,
179
+ botParams.eps,
180
+ intParams
181
+ ) != RebalanceResult.FAIL_OR_TARGET_EXCEED
182
+ ) {
183
+ return botParams.guessMax;
184
+ }
185
+ }
186
+
187
+ for (uint256 iter = 0; iter < botParams.maxIteration; ++iter) {
188
+ uint256 guess = botParams.guessMin + (botParams.guessMax - botParams.guessMin) / 2;
189
+
190
+ RebalanceResult res = _rebalanceResult(
191
+ rebalance,
192
+ guess,
193
+ rebalanceAdditionalCheck,
194
+ botParams.eps,
195
+ intParams
196
+ );
197
+
198
+ if (res == RebalanceResult.SUCCESS) {
199
+ return guess;
200
+ } else if (res == RebalanceResult.TARGET_NOT_REACHED) {
201
+ botParams.guessMin = guess;
202
+ } else {
203
+ botParams.guessMax = guess;
204
+ }
205
+ }
206
+
207
+ revert Errors.BotBinarySearchFail();
208
+ }
209
+
210
+ /**
211
+ * Given the rebalancing action and its `botParam`, binary search for the optimal internal
212
+ * parameter `intParam` for the internal action's approximation (e.g. for router's swap)
213
+ */
214
+ function _calcAmountOutAndIntParams(
215
+ MarketExtState memory marketExt,
216
+ ActionType action,
217
+ uint256 botParam
218
+ ) public pure returns (uint256 amountOut, uint256 intParams) {
219
+ if (action == ActionType.RemoveLiqToYt) {
220
+ (amountOut, intParams) = marketExt.clone().removeLiqToYt(
221
+ botParam,
222
+ _getMockApproxParams()
223
+ );
224
+ } else {
225
+ (amountOut, ) = marketExt.clone().addLiqFromYt(botParam);
226
+ }
227
+ }
228
+
229
+ function _searchMaxYtToAddLiq(
230
+ StrategyData memory strategyData
231
+ ) internal pure returns (uint256) {
232
+ (, , , uint256 ytPtRatioAfter) = _calcBotExtStats(
233
+ strategyData.botState,
234
+ strategyData.marketExt
235
+ );
236
+ if (ytPtRatioAfter < strategyData.specs.minYtPtRatio) {
237
+ return 0;
238
+ }
239
+
240
+ ApproxParams memory guessParams = _getMockApproxParamsWithGuessMax(
241
+ strategyData.botState.ytBalance
242
+ );
243
+ ApproxParams memory mockSwapParams = _getMockApproxParams();
244
+ while (guessParams.guessMax > guessParams.guessMin + 1) {
245
+ uint256 guess = guessParams.guessMin +
246
+ (guessParams.guessMax - guessParams.guessMin) /
247
+ 2;
248
+
249
+ (
250
+ bool success,
251
+ BotState memory botStateAfter,
252
+ MarketExtState memory marketExtAfter
253
+ ) = previewAction(strategyData, ActionType.AddLiqFromYt, guess, mockSwapParams);
254
+
255
+ if (!success) {
256
+ guessParams.guessMax = guess - 1;
257
+ continue;
258
+ }
259
+
260
+ (, , , ytPtRatioAfter) = _calcBotExtStats(botStateAfter, marketExtAfter);
261
+ if (ytPtRatioAfter >= strategyData.specs.minYtPtRatio) {
262
+ guessParams.guessMin = guess;
263
+ } else {
264
+ guessParams.guessMax = guess - 1;
265
+ }
266
+ }
267
+ return guessParams.guessMin;
268
+ }
269
+
270
+ /// @dev Does not modify params, structs are cloned before simulation
271
+ function previewAction(
272
+ StrategyData memory strategyData,
273
+ ActionType action,
274
+ uint256 botParam,
275
+ ApproxParams memory intParams
276
+ ) public pure returns (bool success, BotState memory bot, MarketExtState memory marketExt) {
277
+ bot = strategyData.botState.clone();
278
+ marketExt = strategyData.marketExt.clone();
279
+
280
+ if (action == ActionType.AddLiqFromYt) {
281
+ success = bot.addLiqFromYt(marketExt, botParam);
282
+ } else if (action == ActionType.RemoveLiqToYt) {
283
+ success = bot.removeLiqToYt(marketExt, botParam, intParams);
284
+ } else {
285
+ success = false;
286
+ }
287
+ }
288
+
289
+ function _calcBotExtStats(
290
+ BotState memory botState,
291
+ MarketExtState memory marketExt
292
+ )
293
+ internal
294
+ pure
295
+ returns (uint256 tvlInSy, uint256 iy, uint256 currentSyRatio, uint256 currentYtPtRatio)
296
+ {
297
+ tvlInSy = botState.tvlInSy(marketExt);
298
+ iy = marketExt.impliedYield();
299
+ currentSyRatio = botState.syBalance.divDown(tvlInSy);
300
+ (, uint256 ptInLp) = marketExt.clone().removeLiqDual(botState.lpBalance);
301
+ currentYtPtRatio = (ptInLp == 0 ? type(uint256).max : botState.ytBalance.divDown(ptInLp));
302
+ }
303
+
304
+ function botExtStats(
305
+ StrategyData memory strategyData
306
+ )
307
+ external
308
+ pure
309
+ returns (uint256 tvlInSy, uint256 iy, uint256 currentSyRatio, uint256 currentYtPtRatio)
310
+ {
311
+ return _calcBotExtStats(strategyData.botState, strategyData.marketExt);
312
+ }
313
+
314
+ /// @dev Gives a weak upper bound so that MarketExtLib's simulation doesn't revert
315
+ function _weakUpperBound(
316
+ BotState memory bot,
317
+ MarketExtState memory marketExt,
318
+ ActionType action
319
+ ) private pure returns (uint256) {
320
+ if (action == ActionType.AddLiqFromYt) {
321
+ return marketExt.calcMaxPtOut();
322
+ } else {
323
+ return bot.lpBalance;
324
+ }
325
+ }
326
+
327
+ function _rebalanceResult(
328
+ RebalanceDetails memory rebalance,
329
+ uint256 botParam,
330
+ uint256 rebalanceAdditionalCheck,
331
+ uint256 eps,
332
+ ApproxParams memory intParams
333
+ ) private pure returns (RebalanceResult) {
334
+ (
335
+ bool success,
336
+ BotState memory newBotState,
337
+ MarketExtState memory marketExt
338
+ ) = previewAction(rebalance.strategyData, rebalance.action, botParam, intParams);
339
+
340
+ if (!success) return RebalanceResult.FAIL_OR_TARGET_EXCEED;
341
+ // return RebalanceResult.SUCCESS;
342
+
343
+ uint256 iy = marketExt.impliedYield();
344
+ if (rebalance.action == ActionType.AddLiqFromYt) {
345
+ uint256 netYtSwapped = rebalance.strategyData.botState.ytBalance -
346
+ newBotState.ytBalance;
347
+
348
+ if (netYtSwapped > rebalanceAdditionalCheck) {
349
+ return RebalanceResult.FAIL_OR_TARGET_EXCEED;
350
+ }
351
+ if (Math.isAGreaterApproxB(iy, rebalance.targetIy, eps)) {
352
+ return RebalanceResult.SUCCESS;
353
+ } else {
354
+ if (iy < rebalance.targetIy) return RebalanceResult.FAIL_OR_TARGET_EXCEED;
355
+ else return RebalanceResult.TARGET_NOT_REACHED;
356
+ }
357
+ } else {
358
+ if (Math.isASmallerApproxB(iy, rebalance.targetIy, eps)) {
359
+ return RebalanceResult.SUCCESS;
360
+ } else {
361
+ if (iy > rebalance.targetIy) return RebalanceResult.FAIL_OR_TARGET_EXCEED;
362
+ else return RebalanceResult.TARGET_NOT_REACHED;
363
+ }
364
+ }
365
+ }
366
+
367
+ function _getCurrentBin(
368
+ BotState memory botState,
369
+ LongTradingSpecs memory specs,
370
+ uint256 iy
371
+ ) internal view returns (int256) {
372
+ return specs.getBinIdForIy(botState, iy);
373
+ }
374
+
375
+ function _getTargetImpliedYieldForBin(
376
+ BotState memory botState,
377
+ LongTradingSpecs memory specs,
378
+ int256 binId
379
+ ) internal view returns (uint256) {
380
+ assert(binId != 0); // No action should be taken
381
+
382
+ uint256 segId = SpecSegmentLib.convertBinIdToSegId(botState, binId);
383
+
384
+ if (binId < 0) {
385
+ return specs.getMidIyOfSeg(segId + 1);
386
+ } else {
387
+ return specs.getMidIyOfSeg(segId - 1);
388
+ }
389
+ }
390
+
391
+ function _calcMaxAmountForAction(
392
+ uint256 amount,
393
+ int256 currentBin,
394
+ uint256 buyBins,
395
+ uint256 numOfBins
396
+ ) private pure returns (uint256) {
397
+ assert(currentBin != 0);
398
+ uint256 pressureDenom = currentBin < 0 ? buyBins : numOfBins * 2 - buyBins;
399
+ uint256 actionPressure = (currentBin.abs() * Math.ONE) / pressureDenom;
400
+ uint256 proportion = (Math.ONE + actionPressure).pow(actionPressure) - Math.ONE;
401
+ return amount.mulDown(proportion);
402
+ }
403
+
404
+ function _getMockApproxParamsWithGuessMax(
405
+ uint256 guessMax
406
+ ) private pure returns (ApproxParams memory) {
407
+ return ApproxParams(1, guessMax, 0, 256, MINIMAL_EPS);
408
+ }
409
+
410
+ function _getMockApproxParams() private pure returns (ApproxParams memory) {
411
+ return ApproxParams(1, INF, 0, 256, MINIMAL_EPS);
412
+ }
413
+ }
@@ -12,15 +12,20 @@ contract LongYieldTradingBot is
12
12
  ILongYieldTradingBot,
13
13
  UUPSUpgradeable
14
14
  {
15
+ using MarketExtLib for MarketExtState;
16
+ using Math for uint256;
17
+ using Math for int256;
18
+
15
19
  LongTradingSpecs public specs;
16
20
  IBotDecisionHelper public immutable decisionHelper;
17
21
 
18
22
  constructor(
19
23
  address _market,
24
+ address _router,
20
25
  address _PENDLE,
21
26
  address _decisionHelper
22
- ) TradingBotBase(_market, _PENDLE) {
23
- decisionHelper = BotDecisionHelper(_decisionHelper);
27
+ ) TradingBotBase(_market, _router, _PENDLE) {
28
+ decisionHelper = IBotDecisionHelper(_decisionHelper);
24
29
  }
25
30
 
26
31
  function _authorizeUpgrade(address) internal override onlyOwner {}
@@ -35,116 +40,83 @@ contract LongYieldTradingBot is
35
40
  }
36
41
 
37
42
  function _setSpecs(LongTradingSpecs memory _specs) internal {
38
- require(_specs.lowerIyLimit <= _specs.upperIyLimit, "INVALID_IY_LIMITS");
39
- require(
40
- _specs.floatingSyRatioLimit >= _specs.floatingSyRatioTarget,
41
- "INVALID_FLOATING_SY_RATIO"
42
- );
43
- require(_specs.ytPtRatioLimit >= _specs.ytPtRatioTarget, "INVALID_YT_PT_RATIO");
44
-
45
43
  specs = _specs;
46
- }
47
-
48
- function swapSyToYt(
49
- address router,
50
- ApproxParams calldata botParams,
51
- uint256 minYtOut,
52
- uint256 maxSyIn
53
- ) external onlyOwner returns (uint256 exactYtOut, uint256 netSyIn) {
54
- (exactYtOut, ) = decisionHelper.searchForBotParam(
55
- readBotState(),
56
- readMarketExtState(router),
57
- specs,
58
- ActionType.SwapSyToYt,
59
- botParams,
60
- botParams // only placeholder, value doesn't matter
61
- );
62
-
63
- if (exactYtOut < minYtOut) revert Errors.BotInsufficientYtOut(exactYtOut, minYtOut);
64
- netSyIn = _swapSyToYt(router, exactYtOut, maxSyIn);
65
-
66
- emit SwapSyToYt(botParams, maxSyIn, exactYtOut, netSyIn);
44
+ _setBuyBins(specs.numOfBins);
67
45
  }
68
46
 
69
47
  function addLiqKeepYt(
70
- address router,
71
- ApproxParams calldata botParams,
72
- uint256 maxSyIn,
48
+ uint256 netSyIn,
73
49
  uint256 minLpOut,
74
50
  uint256 minYtOut
75
- ) external onlyOwner returns (uint256 netSyIn, uint256 netLpOut, uint256 netYtOut) {
76
- (netSyIn, ) = decisionHelper.searchForBotParam(
77
- readBotState(),
78
- readMarketExtState(router),
79
- specs,
80
- ActionType.AddLiqKeepYt,
81
- botParams,
82
- botParams // only placeholder, value doesn't matter
83
- );
84
-
85
- if (netSyIn > maxSyIn) revert Errors.BotExceededLimitSyIn(netSyIn, maxSyIn);
51
+ ) external onlyOwner returns (uint256 netLpOut, uint256 netYtOut) {
86
52
  (netLpOut, netYtOut) = _addLiqKeepYt(router, netSyIn, minLpOut, minYtOut);
87
-
88
- emit AddLiqKeepYt(botParams, maxSyIn, netSyIn, netLpOut, netYtOut);
89
- }
90
-
91
- function addLiqFromSy(
92
- ApproxParams calldata botParams,
93
- uint256 minLpOut,
94
- uint256 maxSyIn
95
- ) external onlyOwner returns (uint256 netPtFromSwap, uint256 netLpOut, uint256 netSyIn) {
96
- (netPtFromSwap, ) = decisionHelper.searchForBotParam(
97
- readBotState(),
98
- readMarketExtState(address(this)),
99
- specs,
100
- ActionType.AddLiqFromSy,
101
- botParams,
102
- botParams // only placeholder, value doesn't matter
103
- );
104
-
105
- (netLpOut, netSyIn) = _addLiqFromSy(netPtFromSwap, minLpOut, maxSyIn);
106
-
107
- emit AddLiqFromSy(botParams, maxSyIn, netSyIn, netLpOut);
53
+ emit AddLiqKeepYt(netSyIn, netLpOut, netYtOut);
108
54
  }
109
55
 
110
56
  function addLiqFromYt(
111
- ApproxParams calldata botParams,
112
- uint256 minLpOut,
113
- uint256 maxYtIn
57
+ AddLiqFromYtInput calldata inputParams
114
58
  ) external onlyOwner returns (uint256 netPtFromSwap, uint256 netLpOut, uint256 netYtIn) {
115
- (netPtFromSwap, ) = decisionHelper.searchForBotParam(
116
- readBotState(),
117
- readMarketExtState(address(this)),
118
- specs,
59
+ StrategyData memory strategyData = readStrategyData();
60
+
61
+ require(
62
+ IBotDecisionHelper(decisionHelper).getCurrentBin(strategyData) ==
63
+ inputParams.currentBin,
64
+ "addLiqFromYt: bin state expired"
65
+ );
66
+ netPtFromSwap = decisionHelper.searchForBotParam(
67
+ readStrategyData(),
119
68
  ActionType.AddLiqFromYt,
120
- botParams,
121
- botParams // only placeholder, value doesn't matter
69
+ inputParams.targetIy,
70
+ type(uint256).max,
71
+ inputParams.botParams,
72
+ inputParams.botParams // only placeholder, value doesn't matter
122
73
  );
123
- (netLpOut, netYtIn) = _addLiqFromYt(netPtFromSwap, minLpOut, maxYtIn);
74
+ (netLpOut, netYtIn) = _addLiqFromYt(netPtFromSwap, inputParams.minLpOut);
75
+
76
+ _updateSellBinAfterTrade();
124
77
 
125
- emit AddLiqFromYt(botParams, maxYtIn, netYtIn, netLpOut);
78
+ emit AddLiqFromYt(inputParams.botParams, netYtIn, netLpOut);
126
79
  }
127
80
 
128
81
  function removeLiqToYt(
129
- ApproxParams calldata botParams,
130
- ApproxParams calldata guessTotalPtToSwap,
131
- uint256 maxLpRemoved,
132
- uint256 minYtOut
133
- ) external onlyOwner returns (uint256 netLpRemoved, uint256 netYtOut, uint256 totalPtToSwap) {
134
- (netLpRemoved, ) = decisionHelper.searchForBotParam(
135
- readBotState(),
136
- readMarketExtState(address(this)),
137
- specs,
82
+ RemoveLiqToYtInput calldata inputParams
83
+ ) external onlyOwner returns (uint256 netLpRemoved, uint256 netYtOut) {
84
+ StrategyData memory strategyData = readStrategyData();
85
+
86
+ require(
87
+ IBotDecisionHelper(decisionHelper).getCurrentBin(strategyData) ==
88
+ inputParams.currentBin,
89
+ "removeLiqToYt: bin state expired"
90
+ );
91
+
92
+ netLpRemoved = decisionHelper.searchForBotParam(
93
+ strategyData,
138
94
  ActionType.RemoveLiqToYt,
139
- botParams,
140
- guessTotalPtToSwap // value DOES matter
95
+ inputParams.targetIy,
96
+ type(uint256).max,
97
+ inputParams.botParams,
98
+ inputParams.guessTotalPtToSwap // value DOES matter
99
+ );
100
+
101
+ (netYtOut, ) = _removeLiqToYt(
102
+ netLpRemoved,
103
+ inputParams.guessTotalPtToSwap,
104
+ inputParams.minYtOut
141
105
  );
142
106
 
143
- if (netLpRemoved > maxLpRemoved)
144
- revert Errors.BotExceededLimitLpToRemove(netLpRemoved, maxLpRemoved);
107
+ _updateSellBinAfterTrade();
108
+
109
+ emit RemoveLiqToYt(inputParams.botParams, netLpRemoved, netYtOut);
110
+ }
145
111
 
146
- (netYtOut, totalPtToSwap) = _removeLiqToYt(netLpRemoved, guessTotalPtToSwap, minYtOut);
112
+ function _updateSellBinAfterTrade() internal {
113
+ int256 binShift = IBotDecisionHelper(decisionHelper).getCurrentBin(readStrategyData());
114
+ _setBuyBins((buyBins.Int() + binShift).Uint());
115
+ }
147
116
 
148
- emit RemoveLiqToYt(botParams, maxLpRemoved, netLpRemoved, netYtOut);
117
+ function readStrategyData() public returns (StrategyData memory strategyData) {
118
+ strategyData.botState = readBotState();
119
+ strategyData.marketExt = readMarketExtState();
120
+ strategyData.specs = specs;
149
121
  }
150
122
  }
@@ -0,0 +1,62 @@
1
+ // SPDX-License-Identifier: GPL-3.0-or-later
2
+ pragma solidity 0.8.17;
3
+
4
+ import "../../interfaces/TradingBot/IBotDecisionHelper.sol";
5
+ import "../../core/libraries/math/Math.sol";
6
+
7
+ library SpecSegmentLib {
8
+ using Math for uint256;
9
+ using Math for int256;
10
+
11
+ function getSegLength(LongTradingSpecs memory specs) internal pure returns (uint256) {
12
+ return (specs.sellYtIy - specs.buyYtIy) / (2 * specs.numOfBins);
13
+ }
14
+
15
+ function getMidIyOfSeg(
16
+ LongTradingSpecs memory specs,
17
+ uint256 segId
18
+ ) internal pure returns (uint256) {
19
+ assert(segId != 0 && segId != specs.numOfBins * 2);
20
+ uint256 length = getSegLength(specs);
21
+ return specs.buyYtIy + length * (segId - 1) + length / 2;
22
+ }
23
+
24
+ function getSegIdForIy(
25
+ LongTradingSpecs memory specs,
26
+ uint256 iy
27
+ ) internal pure returns (uint256) {
28
+ if (iy < specs.buyYtIy) {
29
+ return 0;
30
+ }
31
+ if (iy > specs.sellYtIy) {
32
+ return 2 * specs.numOfBins + 1;
33
+ }
34
+ return (iy - specs.buyYtIy) / getSegLength(specs) + 1;
35
+ }
36
+
37
+ function convertSegIdToBinId(
38
+ BotState memory botState,
39
+ uint256 segId
40
+ ) internal pure returns (int256) {
41
+ int256 binId = segId.Int() - botState.buyBins.Int();
42
+ if (binId >= 1) binId--;
43
+ return binId;
44
+ }
45
+
46
+ function convertBinIdToSegId(
47
+ BotState memory botState,
48
+ int256 binId
49
+ ) internal pure returns (uint256) {
50
+ assert(binId != 0);
51
+ if (binId >= 1) binId++;
52
+ return (binId + botState.buyBins.Int()).Uint();
53
+ }
54
+
55
+ function getBinIdForIy(
56
+ LongTradingSpecs memory specs,
57
+ BotState memory botState,
58
+ uint256 iy
59
+ ) internal pure returns (int256) {
60
+ return convertSegIdToBinId(botState, getSegIdForIy(specs, iy));
61
+ }
62
+ }