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

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

address

The address of the vault contract.

asset_manager

If this vault has a dedicated asset manager address set for it.

denomination_token

Get the denominator token for withdrawal/deposit.

deployed_at_block

What was the block number when this vault was deployed

deployer_hot_wallet

Drag the deployer hot wallet along

generic_adapter

guard_contract

Generic adapter guard contract

nominated_owner

If this vault was set to be transferred to a owner multisig after the deployment.

payment_forwarder

Our custom EIP-3009 payment forwarder for the vault

shares_token

Get the shares token for withdrawal/deposit.

terms_of_service_contract

Terms of service contract.

web3

Web3 connection.

vault

Vault smart contract

comptroller

Comptroller smart contract

deployment

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.

fetch_denomination_token_usd_exchange_rate()

Get the exchange rate between token/USD.

fetch_deployment_event(reader[, start_block])

Get when the vault was deployed.

get_decimals()

Get the ERC-20 decimals of the shares.

get_denomination_asset()

Get the reserve ERC-20 asset for this vault.

get_deployment_info()

Get vault contract addresses to be saved as a deployment info.

get_gross_asset_value()

Calculate the gross asset value (GAV) of the fund.

get_name()

Get the name of the share token.

get_owner()

Who is the vault owner.

get_share_count_for_user(user)

How mayn shares a user has.

get_share_gross_asset_value()

Calculate the one share unit gross asset value (GAV) on the smart contract side.

get_shares_asset()

Get the shares ERC-20 token for this vault.

get_symbol()

Get the symbol of share tokens.

get_total_supply()

Get the number of share tokens.

get_tracked_assets()

Get the list of assets this vault tracks.

is_supported_asset(address)

Does the vault support a particular asset.

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.

guard_contract: Optional[web3.contract.contract.Contract] = None

Generic adapter guard contract

  • Generic adapter must be GuardedGenericAdapter

  • Resolved from GuardedGenericAdapter.guard() accessor

terms_of_service_contract: Optional[web3.contract.contract.Contract] = None

Terms of service contract.

  • We must have a TermedVaultUSDCPaymentForwarder

  • Resolved from TermedVaultUSDCPaymentForwarder.termsOfService() accessor

deployed_at_block: int | None = None

What was the block number when this vault was deployed

asset_manager: str | None = None

If this vault has a dedicated asset manager address set for it.

Vaults can have multiple asset managers, but it is rare.

nominated_owner: str | None = None

If this vault was set to be transferred to a owner multisig after the deployment.

The owner needs to confirm the transfer.

deployer_hot_wallet: eth_defi.hotwallet.HotWallet | None = None

Drag the deployer hot wallet along

Used for unit testing and such, so that we can easily configure guard with the same account that deployed it.

get_deployment_info()[source]

Get vault contract addresses to be saved as a deployment info.

Useful for shell scripting.

Returns

Bunch of env mappings

Return type

dict

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

property shares_token: eth_defi.token.TokenDetails

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_name()[source]

Get the name of the share token.

See SharesTokenBase.sol.

Return type

str

get_symbol()[source]

Get the symbol of share tokens.

See SharesTokenBase.sol.

Return type

str

get_total_supply()[source]

Get the number of share tokens.

See SharesTokenBase.sol.

Return type

int

get_decimals()[source]

Get the ERC-20 decimals of the shares.

See SharesTokenBase.sol.

Return type

int

get_denomination_asset()[source]

Get the reserve ERC-20 asset for this vault.

Return type

eth_typing.evm.HexAddress

get_shares_asset()[source]

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

The gross assets in the denominated token.

Return type

int

get_share_gross_asset_value()[source]

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

int

get_share_count_for_user(user)[source]

How mayn shares a user has.

Returns

Raw token amount

Parameters

user (eth_typing.evm.HexAddress) –

Return type

int

is_supported_asset(address)[source]

Does the vault support a particular asset.

If the asset is not supported, policy manager

At the moment, assets are whitelisted on Enzyme protocol level.

Parameters

address (eth_typing.evm.HexAddress) –

Return type

bool

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
Returns

Event log details

Raises

AssertionError – If blockchain does not have an event for the deplyoed vault

Return type

dict

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

decimal.Decimal

static fetch(web3, vault_address, generic_adapter_address=None, payment_forwarder=None, deployed_at_block=None, asset_manager=None)[source]

Fetch Enzyme vault and deployment information based only on the vault address.

Because vault does not have a way to cross-reference its contracts, we are now manually passing around a bunch of contracts and addresses.

Returns

Enzyme vault instance with all the information populated in

Parameters
  • web3 (web3.main.Web3) –

  • vault_address (Union[str, eth_typing.evm.HexAddress]) –

  • generic_adapter_address (Optional[Union[eth_typing.evm.HexAddress, str]]) –

  • payment_forwarder (Optional[Union[eth_typing.evm.HexAddress, str]]) –

  • deployed_at_block (Optional[int]) –

  • asset_manager (Optional[eth_typing.evm.HexAddress]) –

Return type

eth_defi.enzyme.vault.Vault

__init__(vault, comptroller, deployment, generic_adapter=None, payment_forwarder=None, guard_contract=None, terms_of_service_contract=None, deployed_at_block=None, asset_manager=None, nominated_owner=None, deployer_hot_wallet=None)
Parameters
Return type

None