Utils
This guide covers additional helper methods for calculations and state checks, such as coin purchase/sale estimation, Bonding Curve progress and etc. These method shall execute through individual coin's Bonding Curve contract.
Estimate Receiving Amount with Fixed Input Amount
The getAmountOutAndFee
method estimate the amount to be receive and fee to be paid by specifying an exact input amount. For example, estimating coin amount to be receive with a fixed collateral amount or collateral amount to be receive with specific coin amount.
This method usually used in conjunction with buyExactIn
and sellExactIn
method during trading action in Bonding Curve stage.
Method Interface
// solidity interface
/// @notice Estimate amount to receive & fee to pay for an fixed input amount during Bonding Curve stage
///
/// @param _amountIn The fixed input amount of coin/collateral
/// @param _reserveIn The virtual reserve amount of input type
/// @param _reserveOut The virtual reserve amount of output type
/// @param _paymentTokenIsIn The _amountIn is collateral or not
///
/// @return amountOut The estimated return coin/collateral amount
/// @return fee The platform fee charged
function getAmountOutAndFee(
uint256 _amountIn,
uint256 _reserveIn,
uint256 _reserveOut,
bool _paymentTokenIsIn
) external view returns (uint256 amountOut, uint256 fee);
Estimate Input Amount with Fixed Receiving Amount
The getAmountInAndFee
method estimate the input amount and fee to be paid by specifying an exact output amount. For example, estimating collateral amount to be pay with a fixed coin amount to be receive.
This method usually used in conjunction with buyExactOut
and sellExactOut
method during trading action in Bonding Curve stage.
Method Interface
// solidity interface
/// @notice Estimate input amount & fee to pay for an fixed output amount during Bonding Curve stage
///
/// @param _amountOut The fixed output amount of coin/collateral
/// @param _reserveIn The virtual reserve amount of output type
/// @param _reserveOut The virtual reserve amount of input type
/// @param _paymentTokenIsIn The _amountIn is collateral or not
///
/// @return amountIn The requred input coin/collateral amount
/// @return fee The platform fee charged
function getAmountInAndFee(
uint256 _amountOut,
uint256 _reserveIn,
uint256 _reserveOut,
bool _paymentTokenIsOut
) external view returns (uint256 amountIn, uint256 fee);
Check Coin Bonding Curve Progress
The getCurveProgressBps
method check coin's current Bonding Curve progress and return in basis point form.
Method Interface
// solidity interface
/// @notice Get coin current bonding curve progress
///
/// @return progress BPS
function getCurveProgressBps() external view returns (uint256);
Check Coin Market Cap
The getMarketCap
method calculate and return coin's current market cap calculated in respective collateral token value. The market cap is only applicable to Bonding Curve stage.
Method Interface
// solidity interface
/// @notice Get coin current market cap in bonding curve
///
/// @return market cap in collateral token value
function getMarketCap() external view returns (uint256);
Last updated