BaseCurve

Git Source

Inherits: IBaseCurve

Author: 0xIntuition

Abstract contract for a bonding curve. Defines the interface for converting assets to shares and vice versa.

This contract is designed to be inherited by other bonding curve contracts, providing a common interface for converting between assets and shares.

These curves handle the pure mathematical relationship for share price. Pool ratio adjustments (such as accomodating for the effect of fees, supply burn, airdrops, etc) are handled by the EthMultiVault instead of the curves themselves.

State Variables

name

The name of the curve

string public name;

Functions

constructor

Construct the curve with a unique name

constructor(string memory _name);

Parameters

NameTypeDescription
_namestringUnique name for the curve

maxShares

The maximum number of shares that this curve can handle without overflowing.

Checked by the EthMultiVault before transacting

function maxShares() external view virtual returns (uint256);

maxAssets

The maximum number of assets that this curve can handle without overflowing.

Checked by the EthMultiVault before transacting

function maxAssets() external view virtual returns (uint256);

previewDeposit

Preview how many shares would be minted for a deposit of assets

function previewDeposit(uint256 assets, uint256 totalAssets, uint256 totalShares)
    external
    view
    virtual
    returns (uint256 shares);

Parameters

NameTypeDescription
assetsuint256Quantity of assets to deposit
totalAssetsuint256Total quantity of assets already staked into the curve
totalSharesuint256Total quantity of shares already awarded by the curve

Returns

NameTypeDescription
sharesuint256The number of shares that would be minted

previewMint

Preview how many assets would be required to mint a specific amount of shares

function previewMint(uint256 shares, uint256 totalShares, uint256 totalAssets)
    external
    view
    virtual
    returns (uint256 assets);

Parameters

NameTypeDescription
sharesuint256Quantity of shares to mint
totalSharesuint256Total quantity of shares already awarded by the curve
totalAssetsuint256Total quantity of assets already staked into the curve

Returns

NameTypeDescription
assetsuint256The number of assets that would be required to mint the shares

previewWithdraw

Preview how many shares would be redeemed for a withdrawal of assets

function previewWithdraw(uint256 assets, uint256 totalAssets, uint256 totalShares)
    external
    view
    virtual
    returns (uint256 shares);

Parameters

NameTypeDescription
assetsuint256Quantity of assets to withdraw
totalAssetsuint256Total quantity of assets already staked into the curve
totalSharesuint256Total quantity of shares already awarded by the curve

Returns

NameTypeDescription
sharesuint256The number of shares that would need to be redeemed

previewRedeem

Preview how many assets would be returned for burning a specific amount of shares

function previewRedeem(uint256 shares, uint256 totalShares, uint256 totalAssets)
    external
    view
    virtual
    returns (uint256 assets);

Parameters

NameTypeDescription
sharesuint256Quantity of shares to burn
totalSharesuint256Total quantity of shares already awarded by the curve
totalAssetsuint256Total quantity of assets already staked into the curve

Returns

NameTypeDescription
assetsuint256The number of assets that would be returned

convertToShares

Convert assets to shares at a specific point on the curve

function convertToShares(uint256 assets, uint256 totalAssets, uint256 totalShares)
    external
    view
    virtual
    returns (uint256 shares);

Parameters

NameTypeDescription
assetsuint256Quantity of assets to convert to shares
totalAssetsuint256Total quantity of assets already staked into the curve
totalSharesuint256Total quantity of shares already awarded by the curve

Returns

NameTypeDescription
sharesuint256The number of shares equivalent to the given assets

convertToAssets

Convert shares to assets at a specific point on the curve

function convertToAssets(uint256 shares, uint256 totalShares, uint256 totalAssets)
    external
    view
    virtual
    returns (uint256 assets);

Parameters

NameTypeDescription
sharesuint256Quantity of shares to convert to assets
totalSharesuint256Total quantity of shares already awarded by the curve
totalAssetsuint256Total quantity of assets already staked into the curve

Returns

NameTypeDescription
assetsuint256The number of assets equivalent to the given shares

currentPrice

Get the current price of a share

function currentPrice(uint256 totalShares) public view virtual returns (uint256 sharePrice);

Parameters

NameTypeDescription
totalSharesuint256Total quantity of shares already awarded by the curve

Returns

NameTypeDescription
sharePriceuint256The current price of a share, scaled by 1e18