BondingCurveRegistry

Git Source

Inherits: IBondingCurveRegistry

Author: 0xIntuition

Registry contract for the Intuition protocol Bonding Curves. Routes access to the curves associated with atoms & triples. Does not maintain any economic state -- this merely performs computations based on the provided economic state.

An administrator may add new bonding curves to this registry, including those submitted by community members, once they are verified to be safe, and conform to the BaseCurve interface. The EthMultiVault supports a growing registry of curves, with each curve supplying a new "vault" for each term (atom or triple).

The registry is responsible for interacting with the curves, to fetch the mathematical computations given the provided economic state and the desired curve implementation. You can think of the registry as a concierge the EthMultiVault uses to access various economic incentive patterns.

State Variables

count

uint256 public count;

curveAddresses

mapping(uint256 => address) public curveAddresses;

curveIds

mapping(address => uint256) public curveIds;

registeredCurveNames

mapping(string => bool) public registeredCurveNames;

admin

address public admin;

Functions

constructor

Constructor for the BondingCurveRegistry contract

constructor(address _admin);

Parameters

NameTypeDescription
_adminaddressAddress who may add curves to the registry

addBondingCurve

Add a new bonding curve to the registry

function addBondingCurve(address bondingCurve) external;

Parameters

NameTypeDescription
bondingCurveaddressAddress of the new bonding curve

transferOwnership

Transfer the admin role to a new address

function transferOwnership(address newOwner) external;

Parameters

NameTypeDescription
newOwneraddressThe new admin address

previewDeposit

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

function previewDeposit(uint256 assets, uint256 totalAssets, uint256 totalShares, uint256 id)
    external
    view
    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
iduint256Curve ID to use for the calculation

Returns

NameTypeDescription
sharesuint256The number of shares that would be minted

previewRedeem

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

function previewRedeem(uint256 shares, uint256 totalShares, uint256 totalAssets, uint256 id)
    external
    view
    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
iduint256Curve ID to use for the calculation

Returns

NameTypeDescription
assetsuint256The number of assets that would be returned

previewWithdraw

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

function previewWithdraw(uint256 assets, uint256 totalAssets, uint256 totalShares, uint256 id)
    external
    view
    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
iduint256Curve ID to use for the calculation

Returns

NameTypeDescription
sharesuint256The number of shares that would need to be redeemed

previewMint

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

function previewMint(uint256 shares, uint256 totalShares, uint256 totalAssets, uint256 id)
    external
    view
    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
iduint256Curve ID to use for the calculation

Returns

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

convertToShares

Convert assets to shares at a specific point on the curve

function convertToShares(uint256 assets, uint256 totalAssets, uint256 totalShares, uint256 id)
    external
    view
    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
iduint256Curve ID to use for the calculation

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, uint256 id)
    external
    view
    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
iduint256Curve ID to use for the calculation

Returns

NameTypeDescription
assetsuint256The number of assets equivalent to the given shares

currentPrice

Get the current price of a share

function currentPrice(uint256 totalShares, uint256 id) external view returns (uint256 sharePrice);

Parameters

NameTypeDescription
totalSharesuint256Total quantity of shares already awarded by the curve
iduint256Curve ID to use for the calculation

Returns

NameTypeDescription
sharePriceuint256The current price of a share

getCurveName

Get the name of a curve

function getCurveName(uint256 id) external view returns (string memory name);

Parameters

NameTypeDescription
iduint256Curve ID to query

Returns

NameTypeDescription
namestringThe name of the curve

getCurveMaxShares

Get the maximum number of shares a curve can handle. Curves compute this ceiling based on their constructor arguments, to avoid overflow.

function getCurveMaxShares(uint256 id) external view returns (uint256 maxShares);

Parameters

NameTypeDescription
iduint256Curve ID to query

Returns

NameTypeDescription
maxSharesuint256The maximum number of shares

getCurveMaxAssets

Get the maximum number of assets a curve can handle. Curves compute this ceiling based on their constructor arguments, to avoid overflow.

function getCurveMaxAssets(uint256 id) external view returns (uint256 maxAssets);

Parameters

NameTypeDescription
iduint256Curve ID to query

Returns

NameTypeDescription
maxAssetsuint256The maximum number of assets

Events

BondingCurveAdded

Emitted when a new curve is added to the registry

event BondingCurveAdded(uint256 indexed curveId, address indexed curveAddress, string indexed curveName);

Parameters

NameTypeDescription
curveIduint256The ID of the curve
curveAddressaddressThe address of the curve
curveNamestringThe name of the curve

OwnershipTransferred

Emitted when the admin role is transferred

event OwnershipTransferred(address indexed oldAdmin, address indexed newAdmin);

Parameters

NameTypeDescription
oldAdminaddressThe previous admin address
newAdminaddressThe new admin address