Interactive Learn

Vault Fundamentals

v0.1.0Available

Block-composed Learn

What Is a Vault?

Learning progress is session-only in this preview.
Chapter 1 · Section 1

What Is a Vault?

Start with the simplest Vault model

A Vault is a smart contract that receives an asset from one or more users and keeps track of each user’s claim on the assets it manages.

For example, users may deposit USDC into a Vault. The Vault can hold that USDC directly or use it inside another strategy to generate yield.

The important point is that users do not lose their economic claim on the value they deposited. Instead, the Vault records how much of the shared pool belongs to each user.

Assets and shares are not the same thing

The asset is the token that users deposit into the Vault. For example, the asset may be USDC.

A share is the accounting token that represents a user’s portion of the Vault. Shares tell the Vault how much of the shared asset pool belongs to each user.

Suppose Alice deposits 100 USDC into an empty Vault and receives 100 shares. At that moment, each share represents 1 USDC.

However, assets and shares do not always remain equal. If the Vault later earns 20 USDC, it may hold 120 USDC while only 100 shares still exist. Each share would then represent 1.2 USDC.

What changes during a deposit?

When Alice deposits 100 USDC, two important state changes occur.

First, the Vault’s USDC balance increases by 100. The assets are transferred from Alice’s wallet into the Vault.

Second, the Vault creates shares for Alice. In this simple example, Alice receives 100 shares.

After the deposit:

• Alice holds 100 fewer USDC.

• The Vault holds 100 more USDC.

• Alice owns 100 Vault shares.

• The total share supply increases by 100.

The asset transfer and the share minting belong to the same deposit operation. If either part fails, the deposit must not be considered complete.

A minimal deposit functionOriginal educational source authored for TraceFi.
SimpleVault.solSolidity · Read-only
  1. function deposit(uint256 assets) external returns (uint256 shares) {
  2. shares = assets; // Simplified 1 asset = 1 share model
  3. asset.safeTransferFrom(msg.sender, address(this), assets);
  4. _mint(msg.sender, shares);
  5. }
Loading SimpleVault.sol source

This simplified function performs the two state changes described above: it transfers assets from the user into the Vault and mints shares to represent the user’s claim. For now, the example assumes that one asset always creates one share.

Read the deposit function in three steps

The Vault first decides how many shares Alice should receive. In this introductory example, the calculation uses a simple one-to-one relationship between assets and shares.

1. Calculate the sharesOriginal educational source authored for TraceFi.
SimpleVault.solSolidity · Read-only
  1. shares = assets;
Loading SimpleVault.sol source

Next, the Vault transfers the requested amount of USDC from Alice’s wallet into the Vault. Alice must first approve the Vault to spend her tokens.

2. Transfer the assetOriginal educational source authored for TraceFi.
SimpleVault.solSolidity · Read-only
  1. asset.safeTransferFrom(msg.sender, address(this), assets);
Loading SimpleVault.sol source

Finally, the Vault mints the calculated shares to Alice. This increases both Alice’s share balance and the Vault’s total share supply.

3. Mint the sharesOriginal educational source authored for TraceFi.
SimpleVault.solSolidity · Read-only
  1. _mint(msg.sender, shares);
Loading SimpleVault.sol source

These three changes occur inside one transaction. If the asset transfer or share minting fails, the entire transaction reverts and the deposit is not recorded.