derive.v3_vault_metrics
Documentation for eth_defi.derive.v3_vault_metrics Python module.
Persist public Derive v3 vault observations in DuckDB.
The collector keeps testnet and mainnet in separate databases. It uses Derive’s public vault listing and performance history.
Functions
|
Fetch all public v3 vaults and persist their daily price history. |
Classes
File-backed public vault metadata and daily performance observations. |
- class DeriveV3VaultDatabase
Bases:
objectFile-backed public vault metadata and daily performance observations.
Metadata is keyed by
(network, subaccount_id); prices also includetimestamp. Amounts are stored as decimal strings. Ingestion handles duplicate keys without unique constraints because large ART indexes have caused native DuckDB crashes under Python 3.14 in this repository.- Parameters
path – Destination DuckDB file.
- __init__(path)
- Parameters
path (pathlib.Path) –
- store_vault(network, vault, prices)
Replace one vault’s metadata and fetched history transactionally.
A fetched point replaces the stored point at the same timestamp. All other timestamps survive, including gaps within the fetched range.
observed_atretains the first scan time when metadata is refreshed.- Parameters
network (str) – Source deployment name.
vault (eth_defi.derive.v3_vaults.DeriveV3Vault) – Fresh public vault metadata.
prices (list[eth_defi.derive.v3_vaults.DeriveV3VaultPrice]) – Fetched performance points.
- Returns
None.- Return type
None
- get_vault_metadata(network)
Read current vault metadata for one deployment.
Includes previously stored vaults that no longer appear in the API listing.
first_price_atcomes from the earliest stored price.- Parameters
network (str) –
testnetormainnet.- Returns
DataFrame with the
vault_metadatacolumns and nullablefirst_price_atas a naive UTC timestamp. One row per vault.- Return type
- get_vault_prices(network)
Read sampled vault prices for one deployment.
Rows are ordered by subaccount ID, then observation timestamp.
- Parameters
network (str) –
testnetormainnet.- Returns
DataFrame with integer
subaccount_id, naive UTCtimestampandwritten_at, stringnetwork, and decimal stringsshare_price,nav_usd(nullable) andtotal_shares.- Return type
- close()
Close the file-backed database connection.
- Returns
None.- Return type
None
- scan_derive_v3_vaults(client, db_path, vault_ids=None)
Fetch all public v3 vaults and persist their daily price history.
Fetches the full available daily history on every run. Each vault commits separately; a fetch failure stops the scan and leaves earlier commits intact. An empty listing succeeds without deleting stored observations.
- Parameters
client (eth_defi.derive.v3_vaults.DeriveV3VaultClient) – Public API client with a selected deployment.
db_path (pathlib.Path) – Destination DuckDB file.
vault_ids (Optional[set[int]]) – Optional native subaccount ID filter.
- Returns
Vaults processed and performance points fetched this run. These counts include replacements of previously stored records.
- Return type