From 5fa4567da544a16d7227e096131a7dfc3be5d1bc Mon Sep 17 00:00:00 2001 From: clemlak Date: Thu, 16 Nov 2023 14:05:32 +0400 Subject: [PATCH] feat: add computeAmountInGivenAmountOut --- contracts/strategies/G3MStrategyLib.sol | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/contracts/strategies/G3MStrategyLib.sol b/contracts/strategies/G3MStrategyLib.sol index b57d74e3..979a97e6 100644 --- a/contracts/strategies/G3MStrategyLib.sol +++ b/contracts/strategies/G3MStrategyLib.sol @@ -117,4 +117,20 @@ library G3MStrategyLib { ) ); } + + function computeAmountInGivenAmountOut( + uint256 amountOut, + uint256 reserveIn, + uint256 weightIn, + uint256 reserveOut, + uint256 weightOut + ) internal pure returns (uint256 amountIn) { + amountIn = reserveIn.mulWadUp( + uint256( + int256(reserveOut.divWadUp(reserveOut - amountOut)).powWad( + int256(weightOut.divWadUp(weightIn)) + ) + ) - FixedPointMathLib.WAD + ); + } }