Vault
Documentation for eth_defi.enzyme.vault.Vault Python class.
- class Vault[source]
Enzyme vault wrapper.
Vaults are Enzyme Protocol “funds” where you have investors and assets
Investors have ownership of vault assets with a share token
Each vault has its denomiation asset, e.g. USDC that you use for the buy in
You buy-in to a vault using buyShares
Redemption is “in-kind” and you swap your share tokens to the tokens of underlying open positions and other assets
A separate vault owner (fund owner) can make the vault to perform trades
Vault in Enzyme are presented by two smart contracts
Vault contract
Comptroller contract
See Enzyme documentation for general information about vaults.
Example:
vault = Vault(vault_contract, comptroller_contract, deployment) print(f"Vault name: {vault.get_name()}") print(f"Denominated in: {vault.denomination_token}") raw_gross_asset_value = vault.get_gross_asset_value() print(f"Gross asset value: {vault.denomination_token.convert_to_decimals(raw_gross_asset_value):.2f} {vault.denomination_token.symbol}")
Attributes summary
The address of the vault contract.
Get the denominator token for withdrawal/deposit.
Our custom EIP-3009 payment forwarder for the vault
Get the shares token for withdrawal/deposit.
Web3 connection.
Vault smart contract
Comptroller smart contract
Enzyme deployment reference
Methods summary
__init__
(vault, comptroller, deployment[, ...])fetch
(web3, vault_address[, ...])Fetch Enzyme vault and deployment information based only on the vault address.
Get the exchange rate between token/USD.
fetch_deployment_event
(reader[, start_block])Get when the vault was deployed.
Get the ERC-20 decimals of the shares.
Get the reserve ERC-20 asset for this vault.
Calculate the gross asset value (GAV) of the fund.
get_name
()Get the name of the share token.
Who is the vault owner.
get_share_count_for_user
(user)How mayn shares a user has.
Calculate the one share unit gross asset value (GAV) on the smart contract side.
Get the shares ERC-20 token for this vault.
Get the symbol of share tokens.
Get the number of share tokens.
Get the list of assets this vault tracks.
- vault: web3.contract.contract.Contract
Vault smart contract
The VaultLib contract contains the storage layout, event signatures, and logic for VaultProxy instances that are attached to this release.
- comptroller: web3.contract.contract.Contract
Comptroller smart contract
A ComptrollerProxy is deployed per-fund, and it is the canonical contract for interacting with a fund in this release. It stores core release-level configuration and is attached to a VaultProxy via the latter’s accessor role.
Emits important events like SharesBought, SharesRedeemed
- deployment: eth_defi.enzyme.deployment.EnzymeDeployment
Enzyme deployment reference
- generic_adapter: Optional[web3.contract.contract.Contract] = None
- payment_forwarder: Optional[web3.contract.contract.Contract] = None
Our custom EIP-3009 payment forwarder for the vault
See :py:mod:`~eth_defi.usdc.transfer_with_authorization.
Allows single click buy ins if there is no USDC in the vallet.
- property web3: web3.main.Web3
Web3 connection.
Used for reading JSON-RPC calls
- property address: eth_typing.evm.HexAddress
The address of the vault contract.
- property denomination_token: eth_defi.token.TokenDetails
Get the denominator token for withdrawal/deposit.
Read the token on-chain details.
Cache the results for the future calls
- Returns
Usually ERC-20 details for USDC
Get the shares token for withdrawal/deposit.
Read the token on-chain details.
Cache the results for the future calls
- Returns
ERC-20 details for a token with the fund name/symbol and 18 decimals.
- get_owner()[source]
Who is the vault owner.
Vault owner has special priviledges like calling the adapters.
See IVaultCore.sol.
- Return type
eth_typing.evm.HexAddress
- get_denomination_asset()[source]
Get the reserve ERC-20 asset for this vault.
- Return type
eth_typing.evm.HexAddress
Get the shares ERC-20 token for this vault.
Enzyme vault acts as ERC-20 contract as well.
- Return type
eth_typing.evm.HexAddress
- get_tracked_assets()[source]
Get the list of assets this vault tracks.
- Returns
List of ERC-20 addresses
- Return type
Collection[eth_typing.evm.HexAddress]
- get_gross_asset_value()[source]
Calculate the gross asset value (GAV) of the fund.
Call the Solidity function that does this on the smart contract side.
See ComptrollerLib.sol.
- Returns
TODO - no idea
- Return type
Calculate the one share unit gross asset value (GAV) on the smart contract side.
Call the Solidity function that does this on the smart contract side.
See ComptrollerLib.sol.
- Returns
TODO - no idea
- Return type
How mayn shares a user has.
- Returns
Raw token amount
- Parameters
user (eth_typing.evm.HexAddress) –
- Return type
- fetch_deployment_event(reader, start_block=1)[source]
Get when the vault was deployed.
Warning
Because Ethereum nodes do not have indexes to get events per contract, this scan is going to take forever.
- Parameters
start_block – The first block to scan
reader (eth_defi.event_reader.reader.Web3EventReader) – Event reader method used
- Returns
Event log details
- Raises
AssertionError – If blockchain does not have an event for the deplyoed vault
- Return type
- fetch_denomination_token_usd_exchange_rate()[source]
Get the exchange rate between token/USD.
Read the exchange rate using the configured Enzyme’s VaultInterpreter and its Chainlink aggregators.
- Returns
USD exchange rate
- Return type
- static fetch(web3, vault_address, generic_adapter_address=None, payment_forwarder=None)[source]
Fetch Enzyme vault and deployment information based only on the vault address.
- __init__(vault, comptroller, deployment, generic_adapter=None, payment_forwarder=None)
- Parameters
vault (web3.contract.contract.Contract) –
comptroller (web3.contract.contract.Contract) –
deployment (eth_defi.enzyme.deployment.EnzymeDeployment) –
generic_adapter (Optional[web3.contract.contract.Contract]) –
payment_forwarder (Optional[web3.contract.contract.Contract]) –
- Return type
None