EthMultiVault
Inherits: IEthMultiVault, Initializable, ReentrancyGuardUpgradeable, PausableUpgradeable
Author: 0xIntuition
Core contract of the Intuition protocol. Manages the creation and management of vaults associated with atoms & triples.
A sophisticated vault management system that implements a dual-layer semantic data structure through "atoms" and "triples", reminiscent of RDF (Resource Description Framework) concepts.
Core protocol component managing the relationship between semantic data structures and their economic representations through vault mechanics. Implements ERC4626-style accounting with progressive bonding curves.
Key Components:
- Vault Management
- ETH deposits/withdrawals through ERC4626-style vault accounting
- Progressive bonding curves for price discovery
- Supports both standard pro-rata vaults and curve-specific vaults, for backwards compatibility.
- Semantic Structure
- Atoms: Base-level vaults representing individual semantic units
- Triples: Composite vaults linking three atoms in subject-predicate-object relationships
- Each vault type maintains independent state and fee structures
- Security Features
- Timelocked admin operations
- Reentrancy protection
- Pausable functionality
- Granular fee controls with maximum caps
- Approval system for delegated deposits
- Smart Account Integration
- Deploys ERC4337-compatible atom wallets
- BeaconProxy pattern for upgradeable wallet implementations
- Maintains initialization deposits for wallet operations
- Fee Structure
- Entry, exit, and protocol fees
- Configurable per vault
- Separate fee structures for atom/triple creation
- Proportional deposit distribution for triple-related operations
## Please note: This implementation of the EthMultiVault is messy for a reason. We wanted to keep all of the audited code in place, while also enabling users to interact with Bonding Curve vaults. For this reason, there are separate functions for all Bonding Curve related activity. While this bloats the code size, it ensures that users can still use the audited pathways in the code if they wish, while also enabling them to engage in more economically exciting activities like the Progressive Curve or Offset Curve.
The V2 of this contract will merge these pathways into one, providing a cleaner and more straightforward interface for depositing and redeeming.
State Variables
SET_ADMIN
bytes32 public constant SET_ADMIN = keccak256("setAdmin");
SET_EXIT_FEE
bytes32 public constant SET_EXIT_FEE = keccak256("setExitFee");
generalConfig
Configuration structs
GeneralConfig public generalConfig;
atomConfig
AtomConfig public atomConfig;
tripleConfig
TripleConfig public tripleConfig;
walletConfig
WalletConfig public walletConfig;
count
ID of the last vault to be created
uint256 public count;
vaults
Mapping of vault ID to vault state
mapping(uint256 vaultId => VaultState vaultState) public vaults;
vaultFees
Mapping of vault ID to vault fees
mapping(uint256 vaultId => VaultFees vaultFees) public vaultFees;
approvals
Mapping of receiver to sender to determine if a sender is allowed to deposit assets on behalf of a receiver
mapping(address receiver => mapping(address sender => uint8 approvalType)) public approvals;
atoms
RDF (Resource Description Framework)
mapping(uint256 atomId => bytes atomData) public atoms;
atomsByHash
mapping(bytes32 atomHash => uint256 atomId) public atomsByHash;
triples
mapping(uint256 tripleId => uint256[3] tripleAtomIds) public triples;
triplesByHash
mapping(bytes32 tripleHash => uint256 tripleId) public triplesByHash;
isTriple
mapping(uint256 vaultId => bool isTriple) public isTriple;
timelocks
Timelock mapping (operation hash -> timelock struct)
mapping(bytes32 operationHash => Timelock timelock) public timelocks;
bondingCurveVaults
Bonding Curve Vaults (termId -> curveId -> vaultState)
mapping(uint256 vaultId => mapping(uint256 curveId => VaultState vaultState)) public bondingCurveVaults;
bondingCurveConfig
Bonding Curve Configurations
BondingCurveConfig public bondingCurveConfig;
__gap
Gap for upgrade safety
uint256[47] private __gap;
Functions
onlyAdmin
Modifier to restrict a function to the admin
modifier onlyAdmin();
init
Initializes the EthMultiVault contract
This function is called only once (during contract deployment)
function init(
GeneralConfig memory _generalConfig,
AtomConfig memory _atomConfig,
TripleConfig memory _tripleConfig,
WalletConfig memory _walletConfig,
VaultFees memory _defaultVaultFees,
BondingCurveConfig memory _bondingCurveConfig
) external initializer;
Parameters
Name | Type | Description |
---|---|---|
_generalConfig | GeneralConfig | General configuration struct |
_atomConfig | AtomConfig | Atom configuration struct |
_tripleConfig | TripleConfig | Triple configuration struct |
_walletConfig | WalletConfig | Wallet configuration struct |
_defaultVaultFees | VaultFees | Default vault fees struct |
_bondingCurveConfig | BondingCurveConfig |
reinitialize
Reinitializes the EthMultiVault contract during an upgrade
This function can only be called once during a version upgrade
function reinitialize(BondingCurveConfig memory _bondingCurveConfig) external reinitializer(2);
Parameters
Name | Type | Description |
---|---|---|
_bondingCurveConfig | BondingCurveConfig | Bonding curve configuration struct |
constructor
Security measure for upgradeable contracts
Disables initializers on implementation contract to prevent direct initialization
(Security) Prevents attackers from initializing the implementation contract directly
constructor();
receive
contract does not accept ETH donations
receive() external payable;
fallback
fallback function to decompress the calldata and call the appropriate function
fallback() external payable;
pause
pauses the pausable contract methods
function pause() external onlyAdmin;
unpause
unpauses the pausable contract methods
function unpause() external onlyAdmin;
scheduleOperation
schedule an operation to be executed after a delay
function scheduleOperation(bytes32 operationId, bytes calldata data) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
operationId | bytes32 | unique identifier for the operation |
data | bytes | data to be executed |
cancelOperation
cancel a scheduled operation
function cancelOperation(bytes32 operationId, bytes calldata data) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
operationId | bytes32 | unique identifier for the operation |
data | bytes | data of the operation to be cancelled |
setAdmin
Requires new admin to 'confirm' the timelocked operation
set admin
function setAdmin(address admin) external;
Parameters
Name | Type | Description |
---|---|---|
admin | address | address of the new admin |
setProtocolMultisig
set protocol multisig
function setProtocolMultisig(address protocolMultisig) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
protocolMultisig | address | address of the new protocol multisig |
setMinDeposit
sets the minimum deposit amount for atoms and triples
function setMinDeposit(uint256 minDeposit) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
minDeposit | uint256 | new minimum deposit amount |
setMinShare
sets the minimum share amount for atoms and triples
function setMinShare(uint256 minShare) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
minShare | uint256 | new minimum share amount |
setAtomUriMaxLength
sets the atom URI max length
function setAtomUriMaxLength(uint256 atomUriMaxLength) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
atomUriMaxLength | uint256 | new atom URI max length |
setAtomWalletInitialDepositAmount
sets the atom share lock fee
function setAtomWalletInitialDepositAmount(uint256 atomWalletInitialDepositAmount) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
atomWalletInitialDepositAmount | uint256 | new atom share lock fee |
setAtomCreationProtocolFee
sets the atom creation fee
function setAtomCreationProtocolFee(uint256 atomCreationProtocolFee) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
atomCreationProtocolFee | uint256 | new atom creation fee |
setTripleCreationProtocolFee
sets fee charged in wei when creating a triple to protocol multisig
function setTripleCreationProtocolFee(uint256 tripleCreationProtocolFee) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
tripleCreationProtocolFee | uint256 | new fee in wei |
setTotalAtomDepositsOnTripleCreation
sets the atom deposit on triple creation used to increase the amount of assets in the underlying atom vaults on triple creation
function setTotalAtomDepositsOnTripleCreation(uint256 totalAtomDepositsOnTripleCreation) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
totalAtomDepositsOnTripleCreation | uint256 | new atom deposit on triple creation |
setAtomDepositFractionForTriple
sets the atom deposit percentage for atoms used in triples
(number to be divided by generalConfig.feeDenominator
)
function setAtomDepositFractionForTriple(uint256 atomDepositFractionForTriple) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
atomDepositFractionForTriple | uint256 | new atom deposit percentage |
setEntryFee
sets entry fees for the specified vault (id=0 sets the default fees for all vaults) id = 0 changes the default entry fee, id = n changes fees for vault n specifically
admin cannot set the entry fee to be greater than maxEntryFeePercentage
, which is
set to be the 10% of generalConfig.feeDenominator
(which represents 100%), to avoid
being able to prevent users from depositing assets with unreasonable fees
function setEntryFee(uint256 id, uint256 entryFee) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id to set entry fee for |
entryFee | uint256 | entry fee to set |
setExitFee
sets exit fees for the specified vault (id=0 sets the default fees for all vaults) id = 0 changes the default exit fee, id = n changes fees for vault n specifically
admin cannot set the exit fee to be greater than maxExitFeePercentage
, which is
set to be the 10% of generalConfig.feeDenominator
(which represents 100%), to avoid
being able to prevent users from withdrawing their assets
function setExitFee(uint256 id, uint256 exitFee) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id to set exit fee for |
exitFee | uint256 | exit fee to set |
setProtocolFee
sets protocol fees for the specified vault (id=0 sets the default fees for all vaults) id = 0 changes the default protocol fee, id = n changes fees for vault n specifically
admin cannot set the protocol fee to be greater than maxProtocolFeePercentage
, which is
set to be the 10% of generalConfig.feeDenominator
(which represents 100%), to avoid
being able to prevent users from depositing or withdrawing their assets with unreasonable fees
function setProtocolFee(uint256 id, uint256 protocolFee) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id to set protocol fee for |
protocolFee | uint256 | protocol fee to set |
setAtomWarden
sets the atomWarden address
function setAtomWarden(address atomWarden) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
atomWarden | address | address of the new atomWarden |
setBondingCurveConfig
Sets the bonding curve configuration
function setBondingCurveConfig(address newRegistry, uint256 _defaultCurveId) external onlyAdmin;
Parameters
Name | Type | Description |
---|---|---|
newRegistry | address | Address of the new bonding curve registry |
_defaultCurveId | uint256 | New default curve ID |
deployAtomWallet
deploy a given atom wallet
deploys an ERC4337 account (atom wallet) through a BeaconProxy. Reverts if the atom vault does not exist
function deployAtomWallet(uint256 atomId) external whenNotPaused returns (address);
Parameters
Name | Type | Description |
---|---|---|
atomId | uint256 | vault id of atom |
Returns
Name | Type | Description |
---|---|---|
<none> | address | atomWallet the address of the atom wallet |
approve
Set the approval type for a sender to act on behalf of the receiver
function approve(address sender, ApprovalTypes approvalType) external;
Parameters
Name | Type | Description |
---|---|---|
sender | address | address to set approval for |
approvalType | ApprovalTypes | type of approval to grant (NONE = 0, DEPOSIT = 1, REDEMPTION = 2, BOTH = 3) |
createAtom
Create an atom and return its vault id
This function will revert if called with less than getAtomCost()
in msg.value
function createAtom(bytes calldata atomUri) external payable nonReentrant whenNotPaused returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
atomUri | bytes | atom data to create atom with |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | id vault id of the atom |
batchCreateAtom
Batch create atoms and return their vault ids
This function will revert if called with less than getAtomCost()
* atomUris.length
in msg.value
function batchCreateAtom(bytes[] calldata atomUris)
external
payable
nonReentrant
whenNotPaused
returns (uint256[] memory);
Parameters
Name | Type | Description |
---|---|---|
atomUris | bytes[] | atom data array to create atoms with |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256[] | ids vault ids array of the atoms |
_createAtom
Internal utility function to create an atom and handle vault creation
function _createAtom(bytes calldata atomUri, uint256 value) internal returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
atomUri | bytes | The atom data to create an atom with |
value | uint256 | The value sent with the transaction |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | id The new vault ID created for the atom |
<none> | uint256 |
createTriple
create a triple and return its vault id
This function will revert if called with less than getTripleCost()
in msg.value
.
This function will revert if any of the atoms do not exist or if any ids are triple vaults.
function createTriple(uint256 subjectId, uint256 predicateId, uint256 objectId)
external
payable
nonReentrant
whenNotPaused
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
subjectId | uint256 | vault id of the subject atom |
predicateId | uint256 | vault id of the predicate atom |
objectId | uint256 | vault id of the object atom |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | id vault id of the triple |
batchCreateTriple
batch create triples and return their vault ids
This function will revert if called with less than getTripleCost()
* array.length
in msg.value
.
This function will revert if any of the atoms do not exist or if any ids are triple vaults.
function batchCreateTriple(uint256[] calldata subjectIds, uint256[] calldata predicateIds, uint256[] calldata objectIds)
external
payable
nonReentrant
whenNotPaused
returns (uint256[] memory);
Parameters
Name | Type | Description |
---|---|---|
subjectIds | uint256[] | vault ids array of subject atoms |
predicateIds | uint256[] | vault ids array of predicate atoms |
objectIds | uint256[] | vault ids array of object atoms |
_createTriple
Internal utility function to create a triple
function _createTriple(uint256 subjectId, uint256 predicateId, uint256 objectId, uint256 value)
internal
returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
subjectId | uint256 | vault id of the subject atom |
predicateId | uint256 | vault id of the predicate atom |
objectId | uint256 | vault id of the object atom |
value | uint256 | The amount of ETH the user has sent minus the base triple cost |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | id The new vault ID of the created triple |
<none> | uint256 | protocolDepositFee The calculated protocol fee for the deposit |
depositAtom
deposit eth into an atom vault and grant ownership of 'shares' to 'reciever' *payable msg.value amount of eth to deposit
assets parameter is omitted in favor of msg.value, unlike in ERC4626
this function will revert if the minimum deposit amount of eth is not met and if the vault ID does not exist/is not an atom.
function depositAtom(address receiver, uint256 id) external payable nonReentrant whenNotPaused returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
receiver | address | the address to receive the shares |
id | uint256 | the vault ID of the atom |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares the amount of shares minted |
depositAtomCurve
deposit eth into an atom vault and grant ownership of 'shares' to 'reciever' *payable msg.value amount of eth to deposit
assets parameter is omitted in favor of msg.value, unlike in ERC4626
this function will revert if the minimum deposit amount of eth is not met and if the vault ID does not exist/is not an atom.
This method is entirely separate from depositAtom, because we wanted to leave the audited pathways intact. This serves as an intermediary solution to enable users to interact with bonding curve vaults before performing an audit of the full refactor (V2).
function depositAtomCurve(address receiver, uint256 atomId, uint256 curveId)
external
payable
nonReentrant
whenNotPaused
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
receiver | address | the address to receive the shares |
atomId | uint256 | the vault ID of the atom |
curveId | uint256 | the vault ID of the curve |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares the amount of shares minted |
redeemAtom
redeem shares from an atom vault for assets
Emergency redemptions without any fees being charged are always possible, even if the contract is paused
See getRedeemAssetsAndFees
for more details on the fees charged
function redeemAtom(uint256 shares, address receiver, uint256 id) external nonReentrant returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | the amount of shares to redeem |
receiver | address | the address to receiver the assets |
id | uint256 | the vault ID of the atom |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assets the amount of assets/eth withdrawn |
redeemAtomCurve
redeem shares from a bonding curve atom vault for assets
This method is entirely separate from redeemAtom, because we wanted to leave the audited pathways intact. This serves as an intermediary solution to enable users to interact with bonding curve vaults before performing an audit of the full refactor (V2).
function redeemAtomCurve(uint256 shares, address receiver, uint256 atomId, uint256 curveId)
external
nonReentrant
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | the amount of shares to redeem |
receiver | address | the address to receiver the assets |
atomId | uint256 | the vault ID of the atom |
curveId | uint256 | the vault ID of the curve |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assets the amount of assets/eth withdrawn |
depositTriple
deposits assets of underlying tokens into a triple vault and grants ownership of 'shares' to 'receiver' *payable msg.value amount of eth to deposit
assets parameter is omitted in favor of msg.value, unlike in ERC4626
this function will revert if the minimum deposit amount of eth is not met and if the vault ID does not exist/is not a triple.
function depositTriple(address receiver, uint256 id) external payable nonReentrant whenNotPaused returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
receiver | address | the address to receive the shares |
id | uint256 | the vault ID of the triple |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares the amount of shares minted |
depositTripleCurve
deposit eth into a bonding curve triple vault and grant ownership of 'shares' to 'receiver' *payable msg.value amount of eth to deposit
assets parameter is omitted in favor of msg.value, unlike in ERC4626
This method is entirely separate from depositTriple, because we wanted to leave the audited pathways intact. This serves as an intermediary solution to enable users to interact with bonding curve vaults before performing an audit of the full refactor (V2).
function depositTripleCurve(address receiver, uint256 tripleId, uint256 curveId)
external
payable
nonReentrant
whenNotPaused
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
receiver | address | the address to receive the shares |
tripleId | uint256 | the vault ID of the triple |
curveId | uint256 | the vault ID of the curve |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares the amount of shares minted |
redeemTriple
redeems 'shares' number of shares from the triple vault and send 'assets' eth from the contract to 'reciever' factoring in exit fees
Emergency redemptions without any fees being charged are always possible, even if the contract is paused
See getRedeemAssetsAndFees
for more details on the fees charged
function redeemTriple(uint256 shares, address receiver, uint256 id) external nonReentrant returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | the amount of shares to redeem |
receiver | address | the address to receiver the assets |
id | uint256 | the vault ID of the triple |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assets the amount of assets/eth withdrawn |
redeemTripleCurve
redeem shares from a bonding curve triple vault for assets
This method is entirely separate from redeemTriple, because we wanted to leave the audited pathways intact. This serves as an intermediary solution to enable users to interact with bonding curve vaults before performing an audit of the full refactor (V2).
function redeemTripleCurve(uint256 shares, address receiver, uint256 tripleId, uint256 curveId)
external
nonReentrant
returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | the amount of shares to redeem |
receiver | address | the address to receiver the assets |
tripleId | uint256 | the vault ID of the triple |
curveId | uint256 | the vault ID of the curve |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assets the amount of assets/eth withdrawn |
batchDeposit
deposit eth into multiple terms and grant ownership of 'shares' to 'reciever' *payable msg.value amount of eth to deposit works with atoms, triples, and counter-triples
this function will revert if the minimum deposit amount of eth is not met and if a vault ID does not exist/is not an atom.
function batchDeposit(address receiver, uint256[] calldata termIds, uint256[] calldata amounts)
external
payable
nonReentrant
whenNotPaused
returns (uint256[] memory shares);
Parameters
Name | Type | Description |
---|---|---|
receiver | address | the address to receive the shares |
termIds | uint256[] | the IDs of the terms (atoms, triples, or counter-triples) to deposit into |
amounts | uint256[] | array of the amount to deposit in each vault |
Returns
Name | Type | Description |
---|---|---|
shares | uint256[] | the amount of shares minted for each atom |
batchDepositCurve
deposit eth into an atom vault and grant ownership of 'shares' to 'reciever' *payable msg.value amount of eth to deposit
assets parameter is omitted in favor of msg.value, unlike in ERC4626
this function will revert if the minimum deposit amount of eth is not met and if the vault ID does not exist/is not an atom.
This method is entirely separate from depositAtom, because we wanted to leave the audited pathways intact. This serves as an intermediary solution to enable users to interact with bonding curve vaults before performing an audit of the full refactor (V2).
function batchDepositCurve(
address receiver,
uint256[] calldata termIds,
uint256[] calldata curveIds,
uint256[] calldata amounts
) external payable nonReentrant whenNotPaused returns (uint256[] memory shares);
Parameters
Name | Type | Description |
---|---|---|
receiver | address | the address to receive the shares |
termIds | uint256[] | array of the vault IDs of the terms (atoms, triples, or counter-triples) |
curveIds | uint256[] | array of the vault IDs of the curves |
amounts | uint256[] | array of the amount to deposit in each vault |
Returns
Name | Type | Description |
---|---|---|
shares | uint256[] | array of the amount of shares minted in the specified vaults |
batchRedeem
redeem shares from an atom vault for assets -- works for atoms, triples and counter-triples
Emergency redemptions without any fees being charged are always possible, even if the contract is paused
See getRedeemAssetsAndFees
for more details on the fees charged
function batchRedeem(uint256 percentage, address receiver, uint256[] calldata ids)
external
nonReentrant
returns (uint256[] memory assets);
Parameters
Name | Type | Description |
---|---|---|
percentage | uint256 | the percentage of shares to redeem from each vault (10000 -> 100.00%, 5000 -> 50.00%, etc) |
receiver | address | the address to receiver the assets |
ids | uint256[] | array of IDs of the term (atom, triple or counter-triple) to redeem from |
Returns
Name | Type | Description |
---|---|---|
assets | uint256[] | the amount of assets/eth withdrawn |
batchRedeemCurve
redeem shares from bonding curve atom vaults for assets
function batchRedeemCurve(uint256 percentage, address receiver, uint256[] calldata termIds, uint256[] calldata curveIds)
external
nonReentrant
returns (uint256[] memory assets);
Parameters
Name | Type | Description |
---|---|---|
percentage | uint256 | the percentage of shares to redeem from the vaults (10000 -> 100.00%, 5000 -> 50.00%, etc) |
receiver | address | the address to receiver the assets |
termIds | uint256[] | array of the IDs of the terms (atoms, triples, or counter-triples) |
curveIds | uint256[] | array of the IDs of the curves for each term |
Returns
Name | Type | Description |
---|---|---|
assets | uint256[] | array of the amounts of assets/eth withdrawn |
_transferFeesToProtocolMultisig
transfer fees to the protocol multisig
function _transferFeesToProtocolMultisig(uint256 value) internal;
Parameters
Name | Type | Description |
---|---|---|
value | uint256 | the amount of eth to transfer |
_depositConstituentAtoms
divides amount across the three atoms composing the triple and issues shares to the receiver. Doesn't charge additional protocol fees, but it does charge entry fees on each deposit into an atom vault.
assumes funds have already been transferred to this contract
function _depositConstituentAtoms(uint256 id, address receiver, uint256 amount) internal;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | the vault ID of the triple |
receiver | address | the address to receive the shares |
amount | uint256 | the amount of eth to deposit |
_depositConstituentAtomsCurve
function _depositConstituentAtomsCurve(uint256 tripleId, uint256 curveId, address receiver, uint256 amount) internal;
_depositOnVaultCreation
deposit assets into a vault upon creation. Changes the vault's total assets, total shares and balanceOf mappings to reflect the deposit. Additionally, initializes a counter vault with ghost shares.
function _depositOnVaultCreation(uint256 id, address receiver, uint256 assets) internal;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | the vault ID of the atom or triple |
receiver | address | the address to receive the shares |
assets | uint256 | the amount of eth to deposit |
_deposit
Initialize the counter triple vault with ghost shares if it is a triple creation flow
Internal function to encapsulate the common deposit logic for both atoms and triples
function _deposit(address receiver, uint256 id, uint256 value) internal returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
receiver | address | the address to receive the shares |
id | uint256 | the vault ID of the atom or triple |
value | uint256 | the amount of eth to deposit |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | sharesForReceiver the amount of shares minted |
_depositCurve
function _depositCurve(address receiver, uint256 id, uint256 curveId, uint256 value) internal returns (uint256);
_redeem
redeem shares out of a given vault. Changes the vault's total assets, total shares and balanceOf mappings to reflect the withdrawal
function _redeem(uint256 id, address sender, address receiver, uint256 shares) internal returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | the vault ID of the atom or triple |
sender | address | the address to redeem the shares from |
receiver | address | the address to receive the assets |
shares | uint256 | the amount of shares to redeem |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assetsForReceiver the amount of assets/eth to be transferred to the receiver |
<none> | uint256 | protocolFee the amount of protocol fees deducted |
_redeemCurve
redeem shares out of a given bonding curve vault. Changes the vault's total assets, total shares and balanceOf mappings to reflect the withdrawal
function _redeemCurve(uint256 id, uint256 curveId, address sender, address receiver, uint256 shares)
internal
returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | the vault ID of the atom or triple |
curveId | uint256 | the vault ID of the curve |
sender | address | the address to redeem the shares from |
receiver | address | the address to receive the assets |
shares | uint256 | the amount of shares to redeem |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assetsForReceiver the amount of assets/eth to be transferred to the receiver |
<none> | uint256 | protocolFee the amount of protocol fees deducted |
_mint
mint vault shares of vault ID id
to address to
function _mint(address to, uint256 id, uint256 amount) internal;
Parameters
Name | Type | Description |
---|---|---|
to | address | address to mint shares to |
id | uint256 | vault ID to mint shares for |
amount | uint256 | amount of shares to mint |
_mintCurve
function _mintCurve(address to, uint256 id, uint256 curveId, uint256 amount) internal;
_burn
burn amount
vault shares of vault ID id
from address from
function _burn(address from, uint256 id, uint256 amount) internal;
Parameters
Name | Type | Description |
---|---|---|
from | address | address to burn shares from |
id | uint256 | vault ID to burn shares from |
amount | uint256 | amount of shares to burn |
_burnCurve
function _burnCurve(address from, uint256 id, uint256 curveId, uint256 amount) internal;
_setVaultTotals
set total assets and shares for a vault
function _setVaultTotals(uint256 id, uint256 totalAssets, uint256 totalShares) internal;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault ID to set totals for |
totalAssets | uint256 | new total assets for the vault |
totalShares | uint256 | new total shares for the vault |
_increaseCurveVaultTotals
increase the total assets and shares for a given bonding curve vault
emits an event, as this affects the share price of the specified bonding curve vault
function _increaseCurveVaultTotals(uint256 id, uint256 curveId, uint256 assetsDelta, uint256 sharesDelta) internal;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | the vault ID of the atom or triple |
curveId | uint256 | the vault ID of the curve |
assetsDelta | uint256 | the amount of assets to increase the total assets by |
sharesDelta | uint256 | the amount of shares to increase the total shares by |
_decreaseCurveVaultTotals
decrease the total assets and shares for a given bonding curve vault
emits an event, as this affects the share price of the specified bonding curve vault
function _decreaseCurveVaultTotals(uint256 id, uint256 curveId, uint256 assetsDelta, uint256 sharesDelta) internal;
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | the vault ID of the atom or triple |
curveId | uint256 | the vault ID of the curve |
assetsDelta | uint256 | the amount of assets to decrease the total assets by |
sharesDelta | uint256 | the amount of shares to decrease the total shares by |
_createVault
internal method for vault creation
function _createVault() internal returns (uint256);
getAtomCost
returns the cost of creating an atom
function getAtomCost() public view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | atomCost the cost of creating an atom |
getTripleCost
returns the cost of creating a triple
function getTripleCost() public view returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | tripleCost the cost of creating a triple |
getDepositFees
returns the total fees that would be charged for depositing 'assets' into a vault
function getDepositFees(uint256 assets, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate fees on |
id | uint256 | vault id to get corresponding fees for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | totalFees total fees that would be charged for depositing 'assets' into a vault |
getDepositSharesAndFees
returns the shares for recipient and other important values when depositing 'assets' into a vault
function getDepositSharesAndFees(uint256 assets, uint256 id) public view returns (uint256, uint256, uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate fees on (should always be msg.value - protocolFee) |
id | uint256 | vault id to get corresponding fees for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | totalAssetsDelta changes in vault's total assets |
<none> | uint256 | sharesForReceiver changes in vault's total shares (shares owed to receiver) |
<none> | uint256 | userAssetsAfterTotalFees amount of assets that goes towards minting shares for the receiver |
<none> | uint256 | entryFee amount of assets that would be charged for the entry fee |
getDepositSharesAndFeesCurve
function getDepositSharesAndFeesCurve(uint256 assets, uint256 id, uint256 curveId)
public
view
returns (uint256, uint256, uint256, uint256);
getRedeemAssetsAndFees
returns the assets for receiver and other important values when redeeming 'shares' from a vault
function getRedeemAssetsAndFees(uint256 shares, uint256 id) public view returns (uint256, uint256, uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | amount of shares to calculate fees on |
id | uint256 | vault id to get corresponding fees for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | totalUserAssets total amount of assets user would receive if redeeming 'shares', not including fees |
<none> | uint256 | assetsForReceiver amount of assets that is redeemable by the receiver |
<none> | uint256 | protocolFee amount of assets that would be sent to the protocol multisig |
<none> | uint256 | exitFee amount of assets that would be charged for the exit fee |
getRedeemAssetsAndFeesCurve
function getRedeemAssetsAndFeesCurve(uint256 shares, uint256 id, uint256 curveId)
public
view
returns (uint256, uint256, uint256, uint256);
entryFeeAmount
returns amount of assets that would be charged for the entry fee given an amount of 'assets' provided
if the vault being deposited on has a vault total shares of 0, the entry fee is not applied
function entryFeeAmount(uint256 assets, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate fee on |
id | uint256 | vault id to get corresponding fees for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | feeAmount amount of assets that would be charged for the entry fee |
exitFeeAmount
returns amount of assets that would be charged for the exit fee given an amount of 'assets' provided
if the vault being redeemed from given the shares to redeem results in a total shares after of 0, the exit fee is not applied
function exitFeeAmount(uint256 assets, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate fee on |
id | uint256 | vault id to get corresponding fees for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | feeAmount amount of assets that would be charged for the exit fee |
protocolFeeAmount
returns amount of assets that would be charged by a vault on protocol fee given amount of 'assets' provided
function protocolFeeAmount(uint256 assets, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate fee on |
id | uint256 | vault id to get corresponding fees for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | feeAmount amount of assets that would be charged by vault on protocol fee |
atomDepositsAmount
returns atom deposit given amount of 'assets' provided
only applies to triple vaults
function atomDepositsAmount(uint256 assets, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate fee on |
id | uint256 | vault id |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | feeAmount amount of assets that would be used as atom deposit |
_feeOnRaw
calculates fee on raw amount
function _feeOnRaw(uint256 amount, uint256 fee) internal view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
amount | uint256 | amount of assets to calculate fee on |
fee | uint256 | fee in % |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | amount of assets that would be charged as fee |
currentSharePrice
returns the current share price for the given vault id
function currentSharePrice(uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id to get corresponding share price for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | price current share price for the given vault id, scaled by 1e18 |
currentSharePriceCurve
returns the current share price for the given vault id and curve id
function currentSharePriceCurve(uint256 id, uint256 curveId) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id to get corresponding share price for |
curveId | uint256 | curve id to get corresponding share price for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | price current share price for the given vault id and curve id, scaled by 1e18 |
maxDeposit
returns max amount of eth that can be deposited into the vault
function maxDeposit() public pure returns (uint256);
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | maxDeposit max amount of eth that can be deposited into the vault |
maxDepositCurve
returns max amount of assets that can be deposited into a bonding curve vault
Tells the registry to ask the specified curve what its asset limits are.
function maxDepositCurve(uint256 curveId) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
curveId | uint256 | the vault ID of the curve |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | maxDepositCurve max amount of assets that can be deposited into the bonding curve vault |
maxRedeem
returns max amount of shares that can be redeemed from the 'sender' balance through a redeem call
function maxRedeem(address sender, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
sender | address | address of the account to get max redeemable shares for |
id | uint256 | vault id to get corresponding shares for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares amount of shares that can be redeemed from the 'sender' balance through a redeem call |
maxRedeemCurve
returns max amount of shares that can be redeemed from a bonding curve vault
function maxRedeemCurve(address sender, uint256 id, uint256 curveId) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
sender | address | the address to redeem the shares from |
id | uint256 | the vault ID of the atom or triple |
curveId | uint256 | the vault ID of the curve |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares the amount of shares that can be redeemed from the 'sender' balance through a redeem call |
convertToShares
returns amount of shares that would be exchanged by vault given amount of 'assets' provided
For regular vaults, shares maintain a linear relationship with assets: $shares = assets \cdot \frac{S_{total}}{A_{total}}$
Where:
$S_{total}$ = the total supply of shares $A_{total}$ = the total assets in the vault
TLDR: Since assets and shares maintain a 1:1 relationship, we only need simple proportion math. No domain conversion needed because 1 dollar worth of assets always equals 1 dollar worth of shares.
function convertToShares(uint256 assets, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate shares on |
id | uint256 | vault id to get corresponding shares for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares amount of shares that would be exchanged by vault given amount of 'assets' provided |
convertToSharesCurve
returns amount of shares that would be exchanged by vault given amount of 'assets' provided
The conversion happens in two steps:
- First, we get the base shares from the bonding curve: $$s_{base} = f_{curve}(assets)$$
function convertToSharesCurve(uint256 assets, uint256 id, uint256 curveId) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate shares on |
id | uint256 | vault id to get corresponding shares for |
curveId | uint256 | vault id of the curve |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares amount of shares that would be exchanged by vault given amount of 'assets' provided |
convertToAssets
returns amount of assets that would be exchanged by vault given amount of 'shares' provided
For regular vaults, assets maintain a linear relationship with shares: $assets = shares \cdot \frac{A_{total}}{S_{total}}$
Where:
- $S_{total}$ is the total supply of shares
- $A_{total}$ is the total assets in the vault
TLDR: Since assets and shares maintain a 1:1 relationship, we only need simple proportion math. No domain conversion needed because 1 dollar worth of shares always equals 1 dollar worth of assets.
function convertToAssets(uint256 shares, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | amount of shares to calculate assets on |
id | uint256 | vault id to get corresponding assets for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assets amount of assets that would be exchanged by vault given amount of 'shares' provided |
convertToAssetsCurve
returns amount of assets that would be exchanged by vault given amount of 'shares' provided
The conversion happens in two steps:
- First, we get the base assets from the bonding curve: $$a_{base} = f_{curve}^{-1}(shares)$$
function convertToAssetsCurve(uint256 shares, uint256 id, uint256 curveId) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | amount of shares to calculate assets on |
id | uint256 | vault id to get corresponding assets for |
curveId | uint256 | vault id of the curve |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assets amount of assets that would be exchanged by vault given amount of 'shares' provided |
previewDeposit
simulates the effects of the deposited amount of 'assets' and returns the estimated
amount of shares that would be minted from the deposit of assets
this function pessimistically estimates the amount of shares that would be minted from the input amount of assets so if the vault is empty before the deposit the caller receives more shares than returned by this function, reference internal _depositIntoVault logic for details
function previewDeposit(uint256 assets, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
assets | uint256 | amount of assets to calculate shares on |
id | uint256 | vault id to get corresponding shares for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares amount of shares that would be minted from the deposit of assets |
previewDepositCurve
function previewDepositCurve(uint256 assets, uint256 id, uint256 curveId) public view returns (uint256);
previewRedeem
simulates the effects of the redemption of shares
and returns the estimated
amount of assets estimated to be returned to the receiver of the redeem
function previewRedeem(uint256 shares, uint256 id) public view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
shares | uint256 | amount of shares to calculate assets on |
id | uint256 | vault id to get corresponding assets for |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | assets amount of assets estimated to be returned to the receiver |
previewRedeemCurve
function previewRedeemCurve(uint256 shares, uint256 id, uint256 curveId) public view returns (uint256);
tripleHash
returns the corresponding hash for the given RDF triple, given the triple vault id
only applies to triple vault IDs as input
function tripleHash(uint256 id) public view returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id of the triple |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | hash the corresponding hash for the given RDF triple |
isTripleId
returns whether the supplied vault id is a triple
function isTripleId(uint256 id) public view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id to check |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool whether the supplied vault id is a triple |
getTripleAtoms
returns the atoms that make up a triple/counter-triple
only applies to triple vault IDs as input
function getTripleAtoms(uint256 id) public view returns (uint256, uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id of the triple/counter-triple |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | tuple(atomIds) the atoms that make up the triple/counter-triple |
<none> | uint256 | |
<none> | uint256 |
tripleHashFromAtoms
returns the corresponding hash for the given RDF triple, given the atoms that make up the triple
function tripleHashFromAtoms(uint256 subjectId, uint256 predicateId, uint256 objectId) public pure returns (bytes32);
Parameters
Name | Type | Description |
---|---|---|
subjectId | uint256 | the subject atom's vault id |
predicateId | uint256 | the predicate atom's vault id |
objectId | uint256 | the object atom's vault id |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes32 | hash the corresponding hash for the given RDF triple based on the atom vault ids |
getCounterIdFromTriple
returns the counter id from the given triple id
only applies to triple vault IDs as input
function getCounterIdFromTriple(uint256 id) public pure returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id of the triple |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | counterId the counter vault id from the given triple id |
getAtomWarden
returns the address of the atom warden
function getAtomWarden() external view returns (address);
getVaultStateForUser
returns the number of shares and assets (less fees) user has in the vault
function getVaultStateForUser(uint256 vaultId, address receiver) external view returns (uint256, uint256);
Parameters
Name | Type | Description |
---|---|---|
vaultId | uint256 | vault id of the vault |
receiver | address | address of the receiver |
Returns
Name | Type | Description |
---|---|---|
<none> | uint256 | shares number of shares user has in the vault |
<none> | uint256 | assets number of assets user has in the vault |
getVaultStateForUserCurve
function getVaultStateForUserCurve(uint256 vaultId, uint256 curveId, address receiver)
external
view
returns (uint256, uint256);
getCurveVaultState
function getCurveVaultState(uint256 termId, uint256 curveId) external view returns (uint256, uint256);
computeAtomWalletAddr
returns the Atom Wallet address for the given atom data
the create2 salt is based off of the vault ID
function computeAtomWalletAddr(uint256 id) public view returns (address);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | vault id of the atom associated to the atom wallet |
Returns
Name | Type | Description |
---|---|---|
<none> | address | atomWallet the address of the atom wallet |
isApprovedDeposit
Check if a sender is approved to deposit on behalf of a receiver
function isApprovedDeposit(address sender, address receiver) public view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The address of the sender |
receiver | address | The address of the receiver |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool Whether the sender is approved to deposit |
isApprovedRedeem
Check if a sender is approved to redeem on behalf of a receiver
function isApprovedRedeem(address sender, address receiver) public view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The address of the sender |
receiver | address | The address of the receiver |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool Whether the sender is approved to redeem |
_hasCounterStake
checks if an account holds shares in the vault counter to the id provided
function _hasCounterStake(uint256 id, address receiver) internal view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
id | uint256 | the id of the vault to check |
receiver | address | the account to check |
Returns
Name | Type | Description |
---|---|---|
<none> | bool | bool whether the account holds shares in the counter vault to the id provided or not |
_hasCounterStakeCurve
function _hasCounterStakeCurve(uint256 id, uint256 curveId, address receiver) internal view returns (bool);
_getDeploymentData
returns the deployment data for the AtomWallet contract
function _getDeploymentData() internal view returns (bytes memory);
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | bytes memory the deployment data for the AtomWallet contract (using BeaconProxy pattern) |
_validateTimelock
internal method to validate the timelock constraints
function _validateTimelock(bytes32 operationHash) internal view;
Parameters
Name | Type | Description |
---|---|---|
operationHash | bytes32 | hash of the operation |
_registry
function _registry() internal view returns (IBondingCurveRegistry);