EnzymeVaultSyncModel#
API documentation for tradeexecutor.ethereum.enzyme.vault.EnzymeVaultSyncModel Python class in Trading Strategy framework.
- class EnzymeVaultSyncModel[source]#
- Bases: - SyncModel- Update Enzyme vault balances. - __init__(web3, vault_address, reorg_mon, only_chain_listener=True, hot_wallet=None, generic_adapter_address=None, vault_payment_forwarder_address=None, scan_chunk_size=10000)[source]#
- Parameters:
- web3 (Web3) – Web3 
- vault_address (str) – The address of the vault 
- reorg_mon (ReorganisationMonitor) – How to deal with block updates 
- only_chain_listerer – - This is the only adapter using reorg_mon. - Will call - process_blocks()as the part- sync_treasury().
- hot_wallet (Optional[HotWallet]) – - Trade executor’s hot wallet used to create transactions. - Only needed when doing trades. 
- generic_adapter_address (Optional[str]) – - The vault specific deployed GenericAdapter smart contract. - Needed to make trades. 
- scan_chunk_size – Ethereum eth_getLogs JSON-RPC workaround for a horrible blockchain APIs. 
 
 
 - Methods - __init__(web3, vault_address, reorg_mon[, ...])- param web3:
 - Check that the hot wallet has the correct ownership rights to make trades through the vault. - Create event reader for vault deposit/redemption events. - Creates a transaction builder instance to make trades against this asset management model. - fetch_onchain_balances(assets[, ...])- Read the on-chain asset details. - Read the reserve asset from the vault data. - Get the vault address we are using. - Get the vault address we are using - get_related_position(portfolio, asset)- Map a redemption event asset to an underlying position. - Get the address where tokens are stored. - has_async_deposits()- Can deposit land only when we tell so. - has_position_sync()- Do we need to sync positions when we sync treasuty. - is_ready_for_live_trading(state)- Have we run init command on the vault. - Process the reorgsanisation monitor blocks. - process_deposit(portfolio, event, ...)- Translate Enzyme SharesBought event to our internal deposit storage format. - process_redemption(portfolio, event, ...)- Translate Enzyme SharesBought event to our internal deposit storage format. - reset_deposits(state)- Clear out pending withdrawals/deposits events. - Re-read hot wallet nonce before trade execution. - sync_initial(state[, allow_override])- Get the deployment event by scanning the whole chain from the start. - sync_interests(timestamp, state, universe, ...)- Sync interests events. - sync_positions(timestamp, state, ...)- Detect any position balance changes due to deposit/redemptions of vault users. - sync_reinit(state[, allow_override])- Reinitiliase the vault. - sync_treasury(strategy_cycle_ts, state[, ...])- Apply the balance sync before each strategy cycle. - translate_and_apply_event(state, event, ...)- Translate on-chain event data to our persistent format. - __init__(web3, vault_address, reorg_mon, only_chain_listener=True, hot_wallet=None, generic_adapter_address=None, vault_payment_forwarder_address=None, scan_chunk_size=10000)[source]#
- Parameters:
- web3 (Web3) – Web3 
- vault_address (str) – The address of the vault 
- reorg_mon (ReorganisationMonitor) – How to deal with block updates 
- only_chain_listerer – - This is the only adapter using reorg_mon. - Will call - process_blocks()as the part- sync_treasury().
- hot_wallet (Optional[HotWallet]) – - Trade executor’s hot wallet used to create transactions. - Only needed when doing trades. 
- generic_adapter_address (Optional[str]) – - The vault specific deployed GenericAdapter smart contract. - Needed to make trades. 
- scan_chunk_size – Ethereum eth_getLogs JSON-RPC workaround for a horrible blockchain APIs. 
 
 
 - resync_nonce()[source]#
- Re-read hot wallet nonce before trade execution. - Ensures that if the private key is used outside the trade executor, we are not getting wrong nonce error when broadcasting the transaction. 
 - Map a redemption event asset to an underlying position. - Raises:
- UnknownAsset – If we got a redemption event for an asset that does not belong to any of our positions 
- Parameters:
- portfolio (Portfolio) – 
- asset (AssetIdentifier) – 
 
- Return type:
- tradeexecutor.state.reserve.ReservePosition | tradeexecutor.state.position.TradingPosition 
 
 - process_deposit(portfolio, event, strategy_cycle_ts)[source]#
- Translate Enzyme SharesBought event to our internal deposit storage format. - Parameters:
- Return type:
 
 - process_redemption(portfolio, event, strategy_cycle_ts)[source]#
- Translate Enzyme SharesBought event to our internal deposit storage format. - In-kind redemption exchanges user share tokens to underlying assets. - User gets whatever strategy reserves there is 
- User gets share of whatever spot positions there are currently open 
 - Parameters:
- portfolio (Portfolio) – 
- event (Redemption) – 
- strategy_cycle_ts (datetime) – 
 
- Return type:
 
 - translate_and_apply_event(state, event, strategy_cycle_ts)[source]#
- Translate on-chain event data to our persistent format. - Parameters:
- state (State) – 
- event (EnzymeBalanceEvent) – 
- strategy_cycle_ts (datetime) – 
 
- Return type:
 
 - sync_initial(state, allow_override=False, **kwargs)[source]#
- Get the deployment event by scanning the whole chain from the start. - Updates state.sync.deployment structure. - Note - You need to give start_block hint of the scanning will take too long because Ethereum design flaws. - Example: - sync_model.sync_initial(state, start_block=35_123_123) - Parameters:
- state (State) – 
 
 - sync_interests(timestamp, state, universe, pricing_model)[source]#
- Sync interests events. - Read interest gained onchain 
- Apply it to your state 
 - Returns:
- The list of applied interest change events 
- Parameters:
- timestamp (datetime) – 
- state (State) – 
- universe (TradingStrategyUniverse) – 
- pricing_model (PricingModel) – 
 
- Return type:
 
 - fetch_onchain_balances(assets, filter_zero=True, block_identifier=None)[source]#
- Read the on-chain asset details. - Mark the block we are reading at the start 
- Asset list is sorted to be by address to make sure the return order is deterministic 
 - Parameters:
- filter_zero – Do not return zero balances 
- block_identifier (Union[Literal['latest', 'earliest', 'pending', 'safe', 'finalized'], ~eth_typing.evm.BlockNumber, ~eth_typing.evm.Hash32, ~eth_typing.encoding.HexStr, ~hexbytes.main.HexBytes, int]) – Cbeck at certain block height. 
- assets (List[AssetIdentifier]) – 
 
- Returns:
- Iterator for assets by the sort order. 
- Return type:
 
 - create_event_reader()[source]#
- Create event reader for vault deposit/redemption events. - Set up the reader interface for fetch_deployment_event() extract_timestamp is disabled to speed up the event reading, we handle it separately - Returns:
- Tuple (event reader, quick node workarounds). 
- Return type:
 
 - sync_treasury(strategy_cycle_ts, state, supported_reserves=None, end_block=None, post_valuation=False)[source]#
- Apply the balance sync before each strategy cycle. - Parameters:
- strategy_cycle_ts (datetime) – - The current strategy cycle. - Resevers are synced before executing the strategy cycle. 
- state (State) – Current state of the execution. 
- supported_reverses – - List of assets the strategy module wants to use as its reserves. - May be None in testing. 
- end_block (int | None) – Sync until this block. 
- post_valuation – - For models where we need to manage the deposit queue ourselves, like Lagoon, make onchain transaction to update the new onchain valuation. - Disabled by default as this needs gas fees. 
- supported_reserves (Optional[List[AssetIdentifier]]) – 
 
- Returns:
- List of balance updates detected. - Deposits 
- Redemptions 
 
- Return type:
 
 - sync_reinit(state, allow_override=False, **kwargs)[source]#
- Reinitiliase the vault. - Fixes broken accounting. Only needs to be used if internal state and blockchain state have somehow managed to get out of sync: internal state has closed positions that are not in blockchain state or vice versa. - Makes any token balances in the internal state to match the blockchain state. 
- Assumes all positions are closed (currently artificial limitation). 
- All position history is deleted, because we do not know whether positions closed for profit or loss. 
 - See - tradeexexcutor.cli.commands.reinitfor details.- Note - Currently quite a test code. Make support all positions, different sync models. - Parameters:
- state (State) – Empty state 
- allow_override – Allow init twice. 
- kwargs – - Initial sync hints. - Passed to - sync_initial().
 
 
 - create_transaction_builder()[source]#
- Creates a transaction builder instance to make trades against this asset management model. - Only needed when trades are being executed. - Returns:
- Depending on the asset management mode. 
- Return type:
 
 - check_ownership()[source]#
- Check that the hot wallet has the correct ownership rights to make trades through the vault. - Hot wallet must be registered either as - Vault owner 
- Vault asset manager 
 - Raises:
- AssertionError – If the hot wallet cannot perform trades for the vault