EthMultiVault

Git Source

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:

  1. 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.
  1. 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
  1. Security Features
  • Timelocked admin operations
  • Reentrancy protection
  • Pausable functionality
  • Granular fee controls with maximum caps
  • Approval system for delegated deposits
  1. Smart Account Integration
  • Deploys ERC4337-compatible atom wallets
  • BeaconProxy pattern for upgradeable wallet implementations
  • Maintains initialization deposits for wallet operations
  1. 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

NameTypeDescription
_generalConfigGeneralConfigGeneral configuration struct
_atomConfigAtomConfigAtom configuration struct
_tripleConfigTripleConfigTriple configuration struct
_walletConfigWalletConfigWallet configuration struct
_defaultVaultFeesVaultFeesDefault vault fees struct
_bondingCurveConfigBondingCurveConfig

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

NameTypeDescription
_bondingCurveConfigBondingCurveConfigBonding 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

NameTypeDescription
operationIdbytes32unique identifier for the operation
databytesdata to be executed

cancelOperation

cancel a scheduled operation

function cancelOperation(bytes32 operationId, bytes calldata data) external onlyAdmin;

Parameters

NameTypeDescription
operationIdbytes32unique identifier for the operation
databytesdata of the operation to be cancelled

setAdmin

Requires new admin to 'confirm' the timelocked operation

set admin

function setAdmin(address admin) external;

Parameters

NameTypeDescription
adminaddressaddress of the new admin

setProtocolMultisig

set protocol multisig

function setProtocolMultisig(address protocolMultisig) external onlyAdmin;

Parameters

NameTypeDescription
protocolMultisigaddressaddress of the new protocol multisig

setMinDeposit

sets the minimum deposit amount for atoms and triples

function setMinDeposit(uint256 minDeposit) external onlyAdmin;

Parameters

NameTypeDescription
minDeposituint256new minimum deposit amount

setMinShare

sets the minimum share amount for atoms and triples

function setMinShare(uint256 minShare) external onlyAdmin;

Parameters

NameTypeDescription
minShareuint256new minimum share amount

setAtomUriMaxLength

sets the atom URI max length

function setAtomUriMaxLength(uint256 atomUriMaxLength) external onlyAdmin;

Parameters

NameTypeDescription
atomUriMaxLengthuint256new atom URI max length

setAtomWalletInitialDepositAmount

sets the atom share lock fee

function setAtomWalletInitialDepositAmount(uint256 atomWalletInitialDepositAmount) external onlyAdmin;

Parameters

NameTypeDescription
atomWalletInitialDepositAmountuint256new atom share lock fee

setAtomCreationProtocolFee

sets the atom creation fee

function setAtomCreationProtocolFee(uint256 atomCreationProtocolFee) external onlyAdmin;

Parameters

NameTypeDescription
atomCreationProtocolFeeuint256new atom creation fee

setTripleCreationProtocolFee

sets fee charged in wei when creating a triple to protocol multisig

function setTripleCreationProtocolFee(uint256 tripleCreationProtocolFee) external onlyAdmin;

Parameters

NameTypeDescription
tripleCreationProtocolFeeuint256new 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

NameTypeDescription
totalAtomDepositsOnTripleCreationuint256new 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

NameTypeDescription
atomDepositFractionForTripleuint256new 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

NameTypeDescription
iduint256vault id to set entry fee for
entryFeeuint256entry 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

NameTypeDescription
iduint256vault id to set exit fee for
exitFeeuint256exit 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

NameTypeDescription
iduint256vault id to set protocol fee for
protocolFeeuint256protocol fee to set

setAtomWarden

sets the atomWarden address

function setAtomWarden(address atomWarden) external onlyAdmin;

Parameters

NameTypeDescription
atomWardenaddressaddress of the new atomWarden

setBondingCurveConfig

Sets the bonding curve configuration

function setBondingCurveConfig(address newRegistry, uint256 _defaultCurveId) external onlyAdmin;

Parameters

NameTypeDescription
newRegistryaddressAddress of the new bonding curve registry
_defaultCurveIduint256New 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

NameTypeDescription
atomIduint256vault id of atom

Returns

NameTypeDescription
<none>addressatomWallet 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

NameTypeDescription
senderaddressaddress to set approval for
approvalTypeApprovalTypestype 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

NameTypeDescription
atomUribytesatom data to create atom with

Returns

NameTypeDescription
<none>uint256id 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

NameTypeDescription
atomUrisbytes[]atom data array to create atoms with

Returns

NameTypeDescription
<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

NameTypeDescription
atomUribytesThe atom data to create an atom with
valueuint256The value sent with the transaction

Returns

NameTypeDescription
<none>uint256id 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

NameTypeDescription
subjectIduint256vault id of the subject atom
predicateIduint256vault id of the predicate atom
objectIduint256vault id of the object atom

Returns

NameTypeDescription
<none>uint256id 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

NameTypeDescription
subjectIdsuint256[]vault ids array of subject atoms
predicateIdsuint256[]vault ids array of predicate atoms
objectIdsuint256[]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

NameTypeDescription
subjectIduint256vault id of the subject atom
predicateIduint256vault id of the predicate atom
objectIduint256vault id of the object atom
valueuint256The amount of ETH the user has sent minus the base triple cost

Returns

NameTypeDescription
<none>uint256id The new vault ID of the created triple
<none>uint256protocolDepositFee 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

NameTypeDescription
receiveraddressthe address to receive the shares
iduint256the vault ID of the atom

Returns

NameTypeDescription
<none>uint256shares 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

NameTypeDescription
receiveraddressthe address to receive the shares
atomIduint256the vault ID of the atom
curveIduint256the vault ID of the curve

Returns

NameTypeDescription
<none>uint256shares 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

NameTypeDescription
sharesuint256the amount of shares to redeem
receiveraddressthe address to receiver the assets
iduint256the vault ID of the atom

Returns

NameTypeDescription
<none>uint256assets 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

NameTypeDescription
sharesuint256the amount of shares to redeem
receiveraddressthe address to receiver the assets
atomIduint256the vault ID of the atom
curveIduint256the vault ID of the curve

Returns

NameTypeDescription
<none>uint256assets 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

NameTypeDescription
receiveraddressthe address to receive the shares
iduint256the vault ID of the triple

Returns

NameTypeDescription
<none>uint256shares 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

NameTypeDescription
receiveraddressthe address to receive the shares
tripleIduint256the vault ID of the triple
curveIduint256the vault ID of the curve

Returns

NameTypeDescription
<none>uint256shares 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

NameTypeDescription
sharesuint256the amount of shares to redeem
receiveraddressthe address to receiver the assets
iduint256the vault ID of the triple

Returns

NameTypeDescription
<none>uint256assets 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

NameTypeDescription
sharesuint256the amount of shares to redeem
receiveraddressthe address to receiver the assets
tripleIduint256the vault ID of the triple
curveIduint256the vault ID of the curve

Returns

NameTypeDescription
<none>uint256assets 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

NameTypeDescription
receiveraddressthe address to receive the shares
termIdsuint256[]the IDs of the terms (atoms, triples, or counter-triples) to deposit into
amountsuint256[]array of the amount to deposit in each vault

Returns

NameTypeDescription
sharesuint256[]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

NameTypeDescription
receiveraddressthe address to receive the shares
termIdsuint256[]array of the vault IDs of the terms (atoms, triples, or counter-triples)
curveIdsuint256[]array of the vault IDs of the curves
amountsuint256[]array of the amount to deposit in each vault

Returns

NameTypeDescription
sharesuint256[]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

NameTypeDescription
percentageuint256the percentage of shares to redeem from each vault (10000 -> 100.00%, 5000 -> 50.00%, etc)
receiveraddressthe address to receiver the assets
idsuint256[]array of IDs of the term (atom, triple or counter-triple) to redeem from

Returns

NameTypeDescription
assetsuint256[]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

NameTypeDescription
percentageuint256the percentage of shares to redeem from the vaults (10000 -> 100.00%, 5000 -> 50.00%, etc)
receiveraddressthe address to receiver the assets
termIdsuint256[]array of the IDs of the terms (atoms, triples, or counter-triples)
curveIdsuint256[]array of the IDs of the curves for each term

Returns

NameTypeDescription
assetsuint256[]array of the amounts of assets/eth withdrawn

_transferFeesToProtocolMultisig

transfer fees to the protocol multisig

function _transferFeesToProtocolMultisig(uint256 value) internal;

Parameters

NameTypeDescription
valueuint256the 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

NameTypeDescription
iduint256the vault ID of the triple
receiveraddressthe address to receive the shares
amountuint256the 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

NameTypeDescription
iduint256the vault ID of the atom or triple
receiveraddressthe address to receive the shares
assetsuint256the 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

NameTypeDescription
receiveraddressthe address to receive the shares
iduint256the vault ID of the atom or triple
valueuint256the amount of eth to deposit

Returns

NameTypeDescription
<none>uint256sharesForReceiver 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

NameTypeDescription
iduint256the vault ID of the atom or triple
senderaddressthe address to redeem the shares from
receiveraddressthe address to receive the assets
sharesuint256the amount of shares to redeem

Returns

NameTypeDescription
<none>uint256assetsForReceiver the amount of assets/eth to be transferred to the receiver
<none>uint256protocolFee 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

NameTypeDescription
iduint256the vault ID of the atom or triple
curveIduint256the vault ID of the curve
senderaddressthe address to redeem the shares from
receiveraddressthe address to receive the assets
sharesuint256the amount of shares to redeem

Returns

NameTypeDescription
<none>uint256assetsForReceiver the amount of assets/eth to be transferred to the receiver
<none>uint256protocolFee 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

NameTypeDescription
toaddressaddress to mint shares to
iduint256vault ID to mint shares for
amountuint256amount 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

NameTypeDescription
fromaddressaddress to burn shares from
iduint256vault ID to burn shares from
amountuint256amount 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

NameTypeDescription
iduint256vault ID to set totals for
totalAssetsuint256new total assets for the vault
totalSharesuint256new 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

NameTypeDescription
iduint256the vault ID of the atom or triple
curveIduint256the vault ID of the curve
assetsDeltauint256the amount of assets to increase the total assets by
sharesDeltauint256the 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

NameTypeDescription
iduint256the vault ID of the atom or triple
curveIduint256the vault ID of the curve
assetsDeltauint256the amount of assets to decrease the total assets by
sharesDeltauint256the 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

NameTypeDescription
<none>uint256atomCost the cost of creating an atom

getTripleCost

returns the cost of creating a triple

function getTripleCost() public view returns (uint256);

Returns

NameTypeDescription
<none>uint256tripleCost 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

NameTypeDescription
assetsuint256amount of assets to calculate fees on
iduint256vault id to get corresponding fees for

Returns

NameTypeDescription
<none>uint256totalFees 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

NameTypeDescription
assetsuint256amount of assets to calculate fees on (should always be msg.value - protocolFee)
iduint256vault id to get corresponding fees for

Returns

NameTypeDescription
<none>uint256totalAssetsDelta changes in vault's total assets
<none>uint256sharesForReceiver changes in vault's total shares (shares owed to receiver)
<none>uint256userAssetsAfterTotalFees amount of assets that goes towards minting shares for the receiver
<none>uint256entryFee 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

NameTypeDescription
sharesuint256amount of shares to calculate fees on
iduint256vault id to get corresponding fees for

Returns

NameTypeDescription
<none>uint256totalUserAssets total amount of assets user would receive if redeeming 'shares', not including fees
<none>uint256assetsForReceiver amount of assets that is redeemable by the receiver
<none>uint256protocolFee amount of assets that would be sent to the protocol multisig
<none>uint256exitFee 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

NameTypeDescription
assetsuint256amount of assets to calculate fee on
iduint256vault id to get corresponding fees for

Returns

NameTypeDescription
<none>uint256feeAmount 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

NameTypeDescription
assetsuint256amount of assets to calculate fee on
iduint256vault id to get corresponding fees for

Returns

NameTypeDescription
<none>uint256feeAmount 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

NameTypeDescription
assetsuint256amount of assets to calculate fee on
iduint256vault id to get corresponding fees for

Returns

NameTypeDescription
<none>uint256feeAmount 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

NameTypeDescription
assetsuint256amount of assets to calculate fee on
iduint256vault id

Returns

NameTypeDescription
<none>uint256feeAmount 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

NameTypeDescription
amountuint256amount of assets to calculate fee on
feeuint256fee in %

Returns

NameTypeDescription
<none>uint256amount 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

NameTypeDescription
iduint256vault id to get corresponding share price for

Returns

NameTypeDescription
<none>uint256price 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

NameTypeDescription
iduint256vault id to get corresponding share price for
curveIduint256curve id to get corresponding share price for

Returns

NameTypeDescription
<none>uint256price 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

NameTypeDescription
<none>uint256maxDeposit 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

NameTypeDescription
curveIduint256the vault ID of the curve

Returns

NameTypeDescription
<none>uint256maxDepositCurve 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

NameTypeDescription
senderaddressaddress of the account to get max redeemable shares for
iduint256vault id to get corresponding shares for

Returns

NameTypeDescription
<none>uint256shares 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

NameTypeDescription
senderaddressthe address to redeem the shares from
iduint256the vault ID of the atom or triple
curveIduint256the vault ID of the curve

Returns

NameTypeDescription
<none>uint256shares 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

NameTypeDescription
assetsuint256amount of assets to calculate shares on
iduint256vault id to get corresponding shares for

Returns

NameTypeDescription
<none>uint256shares 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:

  1. 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

NameTypeDescription
assetsuint256amount of assets to calculate shares on
iduint256vault id to get corresponding shares for
curveIduint256vault id of the curve

Returns

NameTypeDescription
<none>uint256shares 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

NameTypeDescription
sharesuint256amount of shares to calculate assets on
iduint256vault id to get corresponding assets for

Returns

NameTypeDescription
<none>uint256assets 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:

  1. 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

NameTypeDescription
sharesuint256amount of shares to calculate assets on
iduint256vault id to get corresponding assets for
curveIduint256vault id of the curve

Returns

NameTypeDescription
<none>uint256assets 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

NameTypeDescription
assetsuint256amount of assets to calculate shares on
iduint256vault id to get corresponding shares for

Returns

NameTypeDescription
<none>uint256shares 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

NameTypeDescription
sharesuint256amount of shares to calculate assets on
iduint256vault id to get corresponding assets for

Returns

NameTypeDescription
<none>uint256assets 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

NameTypeDescription
iduint256vault id of the triple

Returns

NameTypeDescription
<none>bytes32hash 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

NameTypeDescription
iduint256vault id to check

Returns

NameTypeDescription
<none>boolbool 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

NameTypeDescription
iduint256vault id of the triple/counter-triple

Returns

NameTypeDescription
<none>uint256tuple(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

NameTypeDescription
subjectIduint256the subject atom's vault id
predicateIduint256the predicate atom's vault id
objectIduint256the object atom's vault id

Returns

NameTypeDescription
<none>bytes32hash 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

NameTypeDescription
iduint256vault id of the triple

Returns

NameTypeDescription
<none>uint256counterId 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

NameTypeDescription
vaultIduint256vault id of the vault
receiveraddressaddress of the receiver

Returns

NameTypeDescription
<none>uint256shares number of shares user has in the vault
<none>uint256assets 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

NameTypeDescription
iduint256vault id of the atom associated to the atom wallet

Returns

NameTypeDescription
<none>addressatomWallet 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

NameTypeDescription
senderaddressThe address of the sender
receiveraddressThe address of the receiver

Returns

NameTypeDescription
<none>boolbool 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

NameTypeDescription
senderaddressThe address of the sender
receiveraddressThe address of the receiver

Returns

NameTypeDescription
<none>boolbool 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

NameTypeDescription
iduint256the id of the vault to check
receiveraddressthe account to check

Returns

NameTypeDescription
<none>boolbool 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

NameTypeDescription
<none>bytesbytes 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

NameTypeDescription
operationHashbytes32hash of the operation

_registry

function _registry() internal view returns (IBondingCurveRegistry);