BondingCurveRegistry
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
Name | Type | Description |
---|---|---|
_admin | address | Address who may add curves to the registry |
addBondingCurve
Add a new bonding curve to the registry
function addBondingCurve(address bondingCurve) external;
Parameters
Name | Type | Description |
---|---|---|
bondingCurve | address | Address of the new bonding curve |
transferOwnership
Transfer the admin role to a new address
function transferOwnership(address newOwner) external;
Parameters
Name | Type | Description |
---|---|---|
newOwner | address | The 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
Name | Type | Description |
---|---|---|
assets | uint256 | Quantity of assets to deposit |
totalAssets | uint256 | Total quantity of assets already staked into the curve |
totalShares | uint256 | Total quantity of shares already awarded by the curve |
id | uint256 | Curve ID to use for the calculation |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The 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
Name | Type | Description |
---|---|---|
shares | uint256 | Quantity of shares to burn |
totalShares | uint256 | Total quantity of shares already awarded by the curve |
totalAssets | uint256 | Total quantity of assets already staked into the curve |
id | uint256 | Curve ID to use for the calculation |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The 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
Name | Type | Description |
---|---|---|
assets | uint256 | Quantity of assets to withdraw |
totalAssets | uint256 | Total quantity of assets already staked into the curve |
totalShares | uint256 | Total quantity of shares already awarded by the curve |
id | uint256 | Curve ID to use for the calculation |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The 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
Name | Type | Description |
---|---|---|
shares | uint256 | Quantity of shares to mint |
totalShares | uint256 | Total quantity of shares already awarded by the curve |
totalAssets | uint256 | Total quantity of assets already staked into the curve |
id | uint256 | Curve ID to use for the calculation |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The 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
Name | Type | Description |
---|---|---|
assets | uint256 | Quantity of assets to convert to shares |
totalAssets | uint256 | Total quantity of assets already staked into the curve |
totalShares | uint256 | Total quantity of shares already awarded by the curve |
id | uint256 | Curve ID to use for the calculation |
Returns
Name | Type | Description |
---|---|---|
shares | uint256 | The 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
Name | Type | Description |
---|---|---|
shares | uint256 | Quantity of shares to convert to assets |
totalShares | uint256 | Total quantity of shares already awarded by the curve |
totalAssets | uint256 | Total quantity of assets already staked into the curve |
id | uint256 | Curve ID to use for the calculation |
Returns
Name | Type | Description |
---|---|---|
assets | uint256 | The 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
Name | Type | Description |
---|---|---|
totalShares | uint256 | Total quantity of shares already awarded by the curve |
id | uint256 | Curve ID to use for the calculation |
Returns
Name | Type | Description |
---|---|---|
sharePrice | uint256 | The current price of a share |
getCurveName
Get the name of a curve
function getCurveName(uint256 id) external view returns (string memory name);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | Curve ID to query |
Returns
Name | Type | Description |
---|---|---|
name | string | The 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
Name | Type | Description |
---|---|---|
id | uint256 | Curve ID to query |
Returns
Name | Type | Description |
---|---|---|
maxShares | uint256 | The 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
Name | Type | Description |
---|---|---|
id | uint256 | Curve ID to query |
Returns
Name | Type | Description |
---|---|---|
maxAssets | uint256 | The 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
Name | Type | Description |
---|---|---|
curveId | uint256 | The ID of the curve |
curveAddress | address | The address of the curve |
curveName | string | The name of the curve |
OwnershipTransferred
Emitted when the admin role is transferred
event OwnershipTransferred(address indexed oldAdmin, address indexed newAdmin);
Parameters
Name | Type | Description |
---|---|---|
oldAdmin | address | The previous admin address |
newAdmin | address | The new admin address |