VaultReaderState
Documentation for eth_defi.erc_4626.vault.VaultReaderState Python class.
- class VaultReaderState
Bases:
eth_defi.event_reader.multicall_batcher.BatchCallStateAdaptive reading frequency for vaults.
This class maintains the per-vault state of reading between different eth_call reads over time
Most vaults are uninteresting, but we do not know ahead of time which ones
We need 1h data for interesting vaults to make good trade decisions
We switch to 1h scanning if the TVL is above a threshold, otherwise we read it once per day
Note
Due to filtering, only handles stablecoin vaults correctly at the moment. Lacks exchange rate support.
- Parameters
vault – The vault we are reading historical data for
tvl_threshold_1d_read – If the TVL is below this threshold, we will not read it more than once per day, otherwise hourly.
down_hard – Stop reading the vault if the TVL is down by this percentage from the peak.
min_tvl_threshold – If the vault never reaches this TVL, we stop reading it after the traction period.
traction_period – How long we wait for the vault to get traction before we stop reading it.
- Parm peaked_tvl_threshold
The TVL value we first need to reach to trigger down hard condition.
Attributes summary
SERIALISABLE_ATTRIBUTESGet the exchange rate for TVL estimation
Methods summary
__init__(vault[, tvl_threshold_1d_read, ...])- param vault
Get all calls marked as broken.
get_call_status(function_name)Get the status of a function call.
How fast we are reading this vault or should the further reading be skipped.
load(data)Load the state from a dictionary.
on_called(result[, total_assets, share_price])- param result
pformat()Pretty print the current state.
save()Persist state across multiple runs.
set_call_status(function_name, check_block, ...)Record the status of a function call.
should_invoke(call, block_identifier, timestamp)Check the condition if this multicall is good to go.
should_skip_call(function_name)Check if a specific function call should be skipped for this vault.
- __init__(vault, tvl_threshold_1d_read=Decimal('10000'), tiny_tvl_threshold_rare_read=Decimal('1000'), peaked_tvl_threshold=Decimal('200000'), min_tvl_threshold=Decimal('1500'), down_hard=0.98, traction_period=datetime.timedelta(days=60))
- Parameters
vault (eth_defi.erc_4626.vault.ERC4626Vault) – The vault we are reading historical data for
tvl_threshold_1d_read – If the TVL is below this threshold, we will not read it more than once per day, otherwise hourly.
down_hard – Stop reading the vault if the TVL is down by this percentage from the peak.
min_tvl_threshold – If the vault never reaches this TVL, we stop reading it after the traction period.
traction_period (datetime.timedelta) – How long we wait for the vault to get traction before we stop reading it.
- Parm peaked_tvl_threshold
The TVL value we first need to reach to trigger down hard condition.
- property exchange_rate: decimal.Decimal
Get the exchange rate for TVL estimation
- get_broken_calls()
Get all calls marked as broken.
- get_call_status(function_name)
Get the status of a function call.
- get_frequency()
How fast we are reading this vault or should the further reading be skipped.
- load(data)
Load the state from a dictionary.
- Parameters
data (dict) –
- on_called(result, total_assets=None, share_price=None)
- Parameters
result (eth_defi.event_reader.multicall_batcher.EncodedCallResult) – Result of convertToAssets() call
total_assets (Optional[decimal.Decimal]) –
share_price (Optional[decimal.Decimal]) –
- pformat()
Pretty print the current state.
- Return type
- save()
Persist state across multiple runs.
- Returns
Pickleable Python object
- Return type
- set_call_status(function_name, check_block, reverts)
Record the status of a function call.
- should_invoke(call, block_identifier, timestamp)
Check the condition if this multicall is good to go.
- Parameters
call (eth_defi.event_reader.multicall_batcher.EncodedCall) –
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]) –
timestamp (datetime.datetime) –
- Return type
- should_skip_call(function_name)
Check if a specific function call should be skipped for this vault.
Part of the warmup system to detect and skip broken contract calls. See README-reader-states.md for documentation.