ChainedERC4626Oracle

Git Source

Inherits: BaseAdapter

Author: Storm Labs (https://storm-labs.xyz/)

A price oracle adapter for chained ERC4626 vault tokens

Handles price conversions between ERC4626 vault shares through multiple levels until reaching the target underlying asset. The oracle automatically converts between share and asset prices through the entire chain using each vault's convertToAssets/convertToShares functions. This oracle relies on the convertToAssets/convertToShares functions of the underlying ERC4626 vaults. If the dependent ERC4626 contracts do not implement sufficient protection against donation attacks, sudden price jumps may occur when large amounts of assets are donated to the vaults without a proportional increase in shares. Users should verify the security measures implemented by the underlying vaults. Due to this risk, this oracle should only be used when there is no direct price feed available for the vault tokens.

State Variables

name

The name of the oracle

string public constant override name = "ChainedERC4626Oracle";

base

The address of the base asset (first vault in chain)

address public immutable base;

quote

The address of the quote asset (final underlying asset)

address public immutable quote;

vaults

The array of vaults in the chain

address[] public vaults;

_MAX_CHAIN_LENGTH

Maximum allowed length for the vault chain

uint256 private constant _MAX_CHAIN_LENGTH = 10;

Functions

constructor

Constructor for the ChainedERC4626Oracle contract

constructor(IERC4626 _initialVault, address _targetAsset) payable;

Parameters

NameTypeDescription
_initialVaultIERC4626The starting ERC4626 vault in the chain
_targetAssetaddressThe final underlying asset to reach

_getQuote

Internal function to get quote through the vault chain

function _getQuote(uint256 inAmount, address _base, address _quote) internal view virtual override returns (uint256);

Parameters

NameTypeDescription
inAmountuint256The input amount to convert
_baseaddressThe base asset address
_quoteaddressThe quote asset address

Returns

NameTypeDescription
<none>uint256The converted amount

Errors

InvalidVaultChain

Thrown when a vault in the chain is invalid (zero address)

error InvalidVaultChain();

ChainTooLong

Thrown when the vault chain is either empty or exceeds the maximum allowed length

error ChainTooLong();

TargetAssetNotReached

Thrown when the chain cannot reach the target asset (e.g., invalid vault sequence)

error TargetAssetNotReached();