Skip to content

Commit

Permalink
feat: add computeSpotPrice
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlak committed Nov 16, 2023
1 parent acb1b38 commit 465021a
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions contracts/strategies/G3MStrategyLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,32 @@ library G3MStrategyLib {
)
);
}

/**
* @dev Computes the spot price of a pool using the following formula:
*
* rO
* ──
* wO
* p = ────
* rI
* ──
* wI
*
* @param reserveOut Reserve of the output token
* @param weightOut Weight of the output token
* @param reserveIn Reserve of the input token
* @param weightIn Weight of the input token
* @return p Spot price of the pool
*/
function computeSpotPrice(
uint256 reserveIn,
uint256 weightIn,
uint256 reserveOut,
uint256 weightOut
) internal pure returns (uint256 p) {
p = reserveOut.divWadDown(weightOut).divWadDown(
reserveIn.divWadDown(weightIn)
);
}
}

0 comments on commit 465021a

Please sign in to comment.