Skip to content

Commit

Permalink
feat: add G3MStrategyLib, computeInvariant
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlak committed Nov 16, 2023
1 parent 41b313b commit acb1b38
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions contracts/strategies/G3MStrategyLib.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.18;

import "solmate/utils/FixedPointMathLib.sol";

using FixedPointMathLib for uint256;
using FixedPointMathLib for int256;

library G3MStrategyLib {
/**
* @dev Computes the invariant of the pool (rounding down) using the
* following formula:
*
* ⎛ wX⎞ ⎛ wY⎞
* k = ⎝rX ⎠ ⋅ ⎝rY ⎠
*
* @param reserveX Reserve of token X
* @param weightX Weight of token X
* @param reserveY Reserve of token Y
* @param weightY Weight of token Y
* @return k Invariant of the pool
*/
function computeInvariant(
uint256 reserveX,
uint256 weightX,
uint256 reserveY,
uint256 weightY
) internal pure returns (uint256 k) {
k = uint256(
uint256(int256(reserveX).powWad(int256(weightX))).mulWadDown(
uint256(int256(reserveY).powWad(int256(weightY)))
)
);
}
}

0 comments on commit acb1b38

Please sign in to comment.