Aller au contenu principal

Overview

Core contract of the Intuition protocol that manages the creation and management of vaults associated with atoms & triples.

Author: 0xIntuition

Contract Inheritance

  • IEthMultiVault
  • Initializable, ReentrancyGuardUpgradeable & PausableUpgradeable (OpenZeppelin)

State Variables

Operation Identifiers

bytes32 constant public SET_ADMIN = keccak256("setAdmin");
bytes32 constant public SET_EXIT_FEE = keccak256("setExitFee");

Configuration Variables

  • generalConfig: General vault parameters (admin address, protocol vault address, etc.)
  • atomConfig: Atom-related parameters (creation cost, fees)
  • tripleConfig: Triple-related parameters (creation fee, deposit fraction)
  • walletConfig: Wallet parameters (Permit2, EntryPoint, AtomWallet Warden)
  • count: Tracks last vault ID created

Mappings

mapping(uint256 vaultId => VaultState vaultState) public vaults;
mapping(uint256 vaultId => VaultFees vaultFees) public vaultFees;
mapping(uint256 atomId => bytes atomData) public atoms;
mapping(bytes32 atomHash => uint256 atomId) public atomsByHash;
mapping(uint256 tripleId => uint256[3] tripleAtomIds) public triples;
mapping(bytes32 tripleHash => uint256 tripleId) public triplesByHash;
mapping(uint256 vaultId => bool isTriple) public isTriple;
mapping(uint256 tripleId => mapping(uint256 atomId => mapping(address account => uint256 balance))) public tripleAtomShares;
mapping(bytes32 operationHash => Timelock timelock) public timelocks;

Modifiers

onlyAdmin

Restricts function access to the contract admin only.

Core Functions

Initializer

function init(
GeneralConfig memory _generalConfig,
AtomConfig memory _atomConfig,
TripleConfig memory _tripleConfig,
WalletConfig memory _walletConfig,
VaultFees memory _defaultVaultFees
) external initializer

Atom Management

createAtom

function createAtom(
bytes calldata atomUri
) external payable nonReentrant whenNotPaused returns (uint256)

Creates new atom and returns vault ID.

deployAtomWallet

function deployAtomWallet(
uint256 atomId
) external whenNotPaused returns (address)

Deploys wallet for given atom.

Triple Management

createTriple

function createTriple(
uint256 subjectId,
uint256 predicateId,
uint256 objectId
) external payable nonReentrant whenNotPaused returns (uint256)

Creates new triple from three atoms.

Asset Management

depositAtom/depositTriple

function depositAtom(
address receiver,
uint256 id
) external payable nonReentrant whenNotPaused returns (uint256)

function depositTriple(
address receiver,
uint256 id
) external payable nonReentrant whenNotPaused returns (uint256)

Deposit ETH into atom/triple vaults.

redeemAtom/redeemTriple

function redeemAtom(
uint256 shares,
address receiver,
uint256 id
) external nonReentrant returns (uint256)

function redeemTriple(
uint256 shares,
address receiver,
uint256 id
) external nonReentrant returns (uint256)

Redeem shares from atom/triple vaults.

View Functions

Fee Calculations

  • getAtomCost(): Cost to create atom
  • getTripleCost(): Cost to create triple
  • getDepositFees(uint256 assets, uint256 id): Calculate deposit fees
  • getRedeemAssetsAndFees(uint256 shares, uint256 id): Calculate redemption amounts

Asset Conversions

  • convertToShares(uint256 assets, uint256 id): Convert assets to shares
  • convertToAssets(uint256 shares, uint256 id): Convert shares to assets
  • previewDeposit(uint256 assets, uint256 id): Simulate deposit
  • previewRedeem(uint256 shares, uint256 id): Simulate redemption

Triple Operations

  • tripleHash(uint256 id): Get triple hash
  • isTripleId(uint256 id): Check if ID is triple
  • getTripleAtoms(uint256 id): Get atoms in triple
  • getCounterIdFromTriple(uint256 id): Get counter ID

Admin Functions

Configuration

  • setAdmin(address admin)
  • setProtocolVault(address protocolVault)
  • setMinDeposit(uint256 minDeposit)
  • setMinShare(uint256 minShare)
  • setAtomUriMaxLength(uint256 atomUriMaxLength)
  • setAtomWalletInitialDepositAmount(uint256 amount)
  • setAtomCreationProtocolFee(uint256 fee)
  • setTripleCreationProtocolFee(uint256 fee)

Fee Management

  • setEntryFee(uint256 id, uint256 entryFee)
  • setExitFee(uint256 id, uint256 exitFee)
  • setProtocolFee(uint256 id, uint256 protocolFee)

Contract Control

  • pause()
  • unpause()
  • scheduleOperation(bytes32 operationId, bytes calldata data)
  • cancelOperation(bytes32 operationId, bytes calldata data)

Internal Functions

Asset Handling

  • _transferFeesToProtocolVault(uint256 value)
  • _depositAtomFraction(uint256 id, address receiver, uint256 amount)
  • _depositOnVaultCreation(uint256 id, address receiver, uint256 assets)
  • _deposit(address receiver, uint256 id, uint256 value)
  • _redeem(uint256 id, address owner, uint256 shares)

Share Management

  • _mint(address to, uint256 id, uint256 amount)
  • _burn(address from, uint256 id, uint256 amount)
  • _setVaultTotals(uint256 id, uint256 totalAssets, uint256 totalShares)
  • _createVault()