You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Fungible Vault Token implements the ERC-4626 tokenized vault standard,
7
+
The Fungible Token Vault extends the [Fungible Token](/stellar-contracts/tokens/fungible/fungible) and implements the ERC-4626 tokenized vault standard,
8
8
enabling fungible tokens to represent shares in an underlying asset pool. The tokenized vault standard
9
9
is the formalized interface for yield-bearing vaults that hold underlying assets. Vault shares enable
10
-
hyperfungible collaterals in DeFi.
10
+
hyperfungible collaterals in DeFi and remain fully compatible with standard fungible token operations.
11
11
12
12
This module allows users to deposit underlying assets in exchange for vault shares, and later redeem
13
13
those shares for the underlying assets. The vault maintains a dynamic conversion rate between shares and
14
14
assets based on the total supply of shares and total assets held by the vault contract.
15
15
16
16
## Overview
17
17
18
-
The [Vault](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/tokens/src/fungible/extensions/vault) module provides a complete implementation of tokenized vaults following the ERC-4626 standard. Vaults are useful for:
18
+
The [Vault](https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/tokens/src/fungible/vault) module provides a complete implementation of tokenized vaults following the ERC-4626 standard. Vaults are useful for:
19
19
20
20
-**Yield-bearing tokens**: Represent shares in a yield-generating strategy
21
21
-**Liquidity pools**: Pool assets together with automatic share calculation
@@ -33,7 +33,7 @@ The vault automatically handles:
33
33
### Shares vs Assets
34
34
35
35
-**Assets**: The underlying token that the vault manages (e.g., USDC, XLM)
36
-
-**Shares**: The vault tokens that represent proportional ownership of the assets
36
+
-**Shares**: The Token Vaults that represent proportional ownership of the assets
37
37
38
38
When assets are deposited into a vault, shares are minted to the depositor.
39
39
The number of shares minted depends on the current exchange rate, which is determined by:
@@ -105,12 +110,14 @@ If a higher offset is required, a custom version of `set_decimals_offset()` must
105
110
The virtual decimals offset helps protect against inflation attacks where an attacker:
106
111
1. Deposits 1 stroop to get the first share (becoming the sole shareholder)
107
112
2.**Donates** (not deposits) an enormous amount of assets directly to the vault contract via a direct transfer, without receiving any shares in return. This inflates the vault's total assets while keeping total shares at 1, making that single share worth an enormous amount
108
-
3. When a legitimate user tries to deposit a normal amount (e.g., 1000 stroops), the share calculation rounds down to 0 shares because their deposit is negligible compared to the inflated vault balance. The user loses their deposit while receiving nothing
113
+
3. When a legitimate user tries to deposit (e.g., 1000 stroops), the share calculation rounds down to 0 shares because their deposit is negligible compared to the inflated vault balance. The user loses their deposit while receiving nothing
109
114
110
115
For example: If the attacker donates 1,000,000 stroops after their initial 1 stroop deposit, the vault has 1,000,001 total assets and 1 total share. A user depositing 1000 stroops would receive `(1000 × 1) / 1,000,001 = 0.000999` shares, which rounds down to 0.
111
116
112
117
The offset adds virtual shares and assets to the conversion formula, making such attacks economically infeasible by ensuring the denominator is never so small that legitimate deposits round to zero.
113
118
119
+
For more details about the mechanics of this attack, see the [OpenZeppelin ERC-4626 security documentation](https://docs.openzeppelin.com/contracts/5.x/erc4626#security-concern-inflation-attack).
120
+
114
121
### Custom Authorization
115
122
116
123
Custom authorization logic can be implemented as needed:
0 commit comments