Skip to content

Commit

Permalink
feat: add computeAmountInGivenAmountOut
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlak committed Nov 16, 2023
1 parent 9f88099 commit 5fa4567
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions contracts/strategies/G3MStrategyLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}

0 comments on commit 5fa4567

Please sign in to comment.