[SEP-56] Tokenized Vault Standard #1787
Replies: 4 comments 5 replies
-
|
Regarding the events:
|
Beta Was this translation helpful? Give feedback.
-
|
For reference, the SEP has been merged, the standard can be found here: SEP-56. |
Beta Was this translation helpful? Give feedback.
-
|
Hello there, I've made a contract following this standard but I also made some changes I think make more sense for Stellar and wanted to propose an update to this draft:
fn query_share(e: Env) -> Address;
fn preview_deposit(e: Env, assets: i128) -> (i128, i128);
fn deposit(e: Env, assets: i128, receiver: Address, from: Address, operator: Address) -> (i128, i128);
fn preview_mint(e: Env, shares: i128) -> (i128, i128);
fn mint(e: Env, shares: i128, receiver: Address, from: Address, operator: Address) -> (i128, i128);
fn preview_withdraw(e: Env, assets: i128) -> (i128, i128);
fn withdraw(e: Env, assets: i128, receiver: Address, owner: Address, operator: Address) -> (i128, i128);
fn preview_redeem(e: Env, shares: i128) -> (i128, i128);
fn redeem(e: Env, shares: i128, receiver: Address, owner: Address, operator: Address) -> (i128, i128); |
Beta Was this translation helpful? Give feedback.
-
|
What is the rationale for having the Apologies if this topic was discussed elsewhere. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Tokenized Vault Standard SEP
Preamble
Summary
This SEP introduces a standard for tokenized vault contracts on Stellar Soroban. A tokenized vault is a smart contract and DeFi primitive that pools funds by allowing users to deposit underlying assets (such as XLM or USDC) and mint a corresponding amount of shares (vault tokens) in return, representing their proportional ownership of the total vault pool. The assets locked in a vault can be utilized by the smart contract logic for yield generation, lending and borrowing, staking, insurance, prediction markets, and other use cases. When users withdraw their assets, their corresponding share tokens are burned.
Dependencies
Motivation
While the ERC-4626 standard has long existed in the EVM ecosystem, there is currently no standard defining tokenized vaults in Stellar Soroban. This standard is proposed to enable consistent integrations between DeFi projects, making it easier for protocols to interoperate and for developers to build composable DeFi applications using vaults.
Abstract
This proposal defines a standardized interface (trait) for tokenized vaults on Soroban.
The standard ensures that vaults expose a consistent interface for deposits, withdrawals, asset-to-share conversions, and other related functions. By requiring SEP-41 compliance for both underlying assets and vault tokens, it promotes interoperability across the ecosystem.
The vault standard extends the token interface standard for share tokenization. Any additional extensions implemented alongside this standard affect the "shares" token represented by this contract, not the underlying "assets" token, which remains an independent contract.
Interface
Events
Deposit Event
The deposit event is emitted when underlying assets are deposited into the vault in exchange for shares.
Withdraw Event
The withdraw event is emitted when shares are exchanged back for underlying assets and assets are withdrawn from the vault.
Design Rationale
This standard closely follows the ERC-4626 standard for tokenized vaults, allowing seamless interoperability across ecosystems.
Authorization Pattern
This standard does not enforce any specific authorization patterns for vault operations. Implementations are expected to add appropriate access controls based on their requirements, typically by:
operator.require_auth()to verify the caller's authorizationThis design choice provides maximum flexibility while maintaining security through explicit authorization handling at the implementation level.
ERC-4626 Deviation
query_asset()function will panic if the asset address is not set, whereas ERC-4626 requires it to never revert.Rationale: Soroban doesn't have a "zero address" concept like EVM. Returning
Option<Address>would break ERC-4626 compatibility.Mitigation: Always initialize the vault properly in the constructor. Once initialized,
query_asset()will never panic during normal operations. This also affectstotal_assets()and all conversion functions that depend on it.Security Concerns
Tokenized vault contracts involve pooling user funds, making them high-value targets for attackers. We strongly encourage the community to actively discuss and identify potential attack vectors to strengthen the overall security of the tokenized vault standard on Stellar Soroban.
Addressing several key security challenges with standard vault, concerning both the concrete implementations and the standard itself:
Notes On Decimals Offset
In empty (or nearly empty) standard vaults, deposits are at high risk of being stolen through front-running with a "donation" to the vault that inflates the price of a share. This is variously known as a donation or inflation attack and is essentially a problem of slippage.
Attack Mechanism:
Potential Solution: Configurable virtual decimals offset that allows vault implementers to set appropriate precision parameters based on their specific asset types and risk tolerance.
The decimals offset corresponds to an offset in the decimal representation between the underlying asset's decimals and the vault decimals. This offset also determines the rate of virtual shares to virtual assets in the vault, which itself determines the initial exchange rate. While not fully preventing the attack, analysis shows that the default offset (0) makes it non-profitable even if an attacker is able to capture value from multiple user deposits, as a result of the value being captured by the virtual shares (out of the attacker's donation) matching the attacker's expected gains. With a larger offset, the attack becomes orders of magnitude more expensive than it is profitable. The attack exploits share calculation mechanisms in empty or low-liquidity vaults.
References:
Notes On Extensibility
The standard provides essential building blocks for common vault functionality while maintaining flexibility for custom implementations. Trait functions can be overridden to implement custom logic. Certain implementation decisions are intentionally left to vault implementers to ensure optimal developer experience and accommodate diverse use cases.
Reference Implementation
The tokenized vault implementation, following this SEP standard, is available on GitHub, in the OpenZeppelin Stellar Soroban contracts library:
https://github.com/OpenZeppelin/stellar-contracts/tree/main/packages/tokens/src/vault
Implementation specifics:
Underlying asset interactions are handled through the
TokenClientstruct, which provides functionality to query balances and decimals, as well as execute asset transfers.Certain arithmetic operations, particularly
muldivcalculations, are implemented based on an open-source mathematical library developed by Script3. For reference: https://github.com/script3/soroban-fixed-point-math/Maximum decimals offset value: the OpenZeppelin implementation caps this value at 10 to balance security and user experience. Values above 10 offer negligible practical benefits, while values approaching 30 can cause overflow errors, depending on the base asset decimals, and amount of assets in the vault.
OpenZeppelin’s fungible token standard implementation (SEP-41), for reference: https://github.com/OpenZeppelin/stellar-contracts/blob/main/packages/tokens/src/fungible/mod.rs
Changelog
v0.1.0- Initial draftv0.1.1- Updated events representation with#[contractevent]v0.1.2- Remove textual event descriptionsBeta Was this translation helpful? Give feedback.
All reactions