-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
535 additions
and
480 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity 0.8.6; | ||
|
||
import "@openzeppelin/contracts/utils/math/SafeMath.sol"; | ||
|
||
library CpmmLib { | ||
using SafeMath for uint256; | ||
|
||
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset | ||
function getAmountOut(uint256 amountIn, uint256 reserveIn, uint256 reserveOut) internal pure returns (uint256 amountOut) { | ||
// require(amountIn > 0, "CpmmLib: INSUFFICIENT_INPUT_AMOUNT"); | ||
require(reserveIn > 0 && reserveOut > 0, "CpmmLib: INSUFFICIENT_LIQUIDITY"); | ||
uint256 numerator = amountIn.mul(reserveOut); | ||
uint256 denominator = reserveIn.add(amountIn); | ||
return numerator / denominator; | ||
} | ||
|
||
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset | ||
function getAmountIn(uint256 amountOut, uint256 reserveIn, uint256 reserveOut) internal pure returns (uint256 amountIn) { | ||
// require(amountOut > 0, "CpmmLib: INSUFFICIENT_OUTPUT_AMOUNT"); | ||
require(reserveIn > 0 && reserveOut > 0, "CpmmLib: INSUFFICIENT_LIQUIDITY"); | ||
uint256 numerator = reserveIn.mul(amountOut); | ||
uint256 denominator = reserveOut.sub(amountOut); | ||
amountIn = (numerator / denominator); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.