EnzymeVaultSyncModel#
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 partsync_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:
Creates a transaction builder instance to make trades against this asset management model.
Read the reserve asset from the vault data.
Get the vault address we are using.
get_related_position
(portfolio, asset)Map a redemption event asset to an underlying position.
Get the vault address we are using
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.
Re-read hot wallet nonce before trade execution.
sync_initial
(state, **kwargs)Get the deployment event by scanning the whole chain from the start.
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 partsync_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)[source]#
Translate Enzyme SharesBought event to our internal deposit storage format.
- Parameters:
- Return type:
- process_redemption(portfolio, event)[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) –
- Return type:
- translate_and_apply_event(state, event)[source]#
Translate on-chain event data to our persistent format.
- Parameters:
state (State) –
event (EnzymeBalanceEvent) –
- Return type:
- sync_initial(state, **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_treasury(strategy_cycle_ts, state, supported_reserves=None)[source]#
Apply the balance sync before each strategy cycle.
Deposits by shareholders
Redemptions
- Returns:
List of new treasury balance events
- Raises:
ChainReorganisationDetected – When any if the block data in our internal buffer does not match those provided by events.
- Parameters:
strategy_cycle_ts (datetime) –
state (State) –
supported_reserves (Optional[List[AssetIdentifier]]) –
- Return type: