xerberus.vault_export
Documentation for eth_defi.xerberus.vault_export Python module.
Export helpers for Xerberus risk data into vault metrics JSON.
Builds:
Preloaded pool lookup map for O(1) per-vault resolve
Compact
XerberusVaultSectionon each vault rowTop-level
XerberusProtocolExportRecordmap (likecore3_protocols)
Functions
|
Build a |
|
Build protocol-slug-keyed Xerberus records for top-level JSON export. |
|
Compute coverage stats from exported vault records. |
|
Resolve compact per-vault Xerberus section using canonical lookup order. |
Classes
Optional coverage summary for the exported vault list. |
|
Preloaded per-vault score row for O(1) resolve during metrics export. |
|
Top-level protocol metadata in |
|
Compact per-vault Xerberus risk summary on each vault metrics row. |
- class XerberusPoolLookupRow
Bases:
TypedDictPreloaded per-vault score row for O(1) resolve during metrics export.
- source: Literal['registry', 'vault_list']
Which table supplied this row.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- clear()
Remove all items from the dict.
- copy()
Return a shallow copy of the dict.
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- class XerberusVaultSection
Bases:
TypedDictCompact per-vault Xerberus risk summary on each vault metrics row.
- score_scale: str
Always
XERBERUS_SCORE_SCALE.
- entity_type: Literal['pool', 'protocol']
poolwhen vault-specific;protocolon fallback.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- clear()
Remove all items from the dict.
- copy()
Return a shallow copy of the dict.
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- class XerberusProtocolExportRecord
Bases:
TypedDictTop-level protocol metadata in
xerberus_protocols(like Core3).- score_scale: str
Always
XERBERUS_SCORE_SCALE.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- clear()
Remove all items from the dict.
- copy()
Return a shallow copy of the dict.
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- class XerberusExportStats
Bases:
TypedDictOptional coverage summary for the exported vault list.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- clear()
Remove all items from the dict.
- copy()
Return a shallow copy of the dict.
- fromkeys(value=None, /)
Create a new dictionary with keys from iterable and values set to value.
- get(key, default=None, /)
Return the value for key if key is in the dictionary, else default.
- items()
Return a set-like object providing a view on the dict’s items.
- keys()
Return a set-like object providing a view on the dict’s keys.
- pop(k[, d]) v, remove specified key and return the corresponding value.
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- setdefault(key, default=None, /)
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- values()
Return an object providing a view on the dict’s values.
- build_xerberus_pool_lookup(db, max_age_days=30)
Build a
(chain_id, address)→ score map for per-vault export.Merge precedence:
Registry pool with non-null score always wins.
Vault list is used only when the key is missing or registry score is null.
- Parameters
db (eth_defi.xerberus.database.XerberusDatabase) – Open Xerberus database (preferably read-only).
max_age_days (Optional[int]) – Drop snapshots older than this many days.
- Returns
Lookup dict keyed by
(chain_id, address_lower).- Return type
dict[tuple[int, str], eth_defi.xerberus.vault_export.XerberusPoolLookupRow]
- build_xerberus_protocols_for_export(db, protocol_slugs, max_age_days=30)
Build protocol-slug-keyed Xerberus records for top-level JSON export.
- Parameters
db (eth_defi.xerberus.database.XerberusDatabase) – Open Xerberus database.
protocol_slugs (collections.abc.Iterable[str]) – Our vault protocol slugs to look up.
- Returns
Dict mapping our protocol slug to export records. Unmapped / missing / stale slugs are excluded.
- Return type
dict[str, eth_defi.xerberus.vault_export.XerberusProtocolExportRecord]
- resolve_xerberus_vault_section(chain_id, address, protocol_slug, pools, protocols)
Resolve compact per-vault Xerberus section using canonical lookup order.
Pool map hit with non-null score (or any pool hit with entity id)
Protocol fallback via
protocols[protocol_slug]
- Parameters
chain_id (int) – Vault chain id.
address (str) – Vault address (any case).
protocol_slug (Optional[str]) – Our protocol slug for fallback.
pools (dict[tuple[int, str], eth_defi.xerberus.vault_export.XerberusPoolLookupRow]) – Preloaded pool lookup from
build_xerberus_pool_lookup().protocols (dict[str, eth_defi.xerberus.vault_export.XerberusProtocolExportRecord]) – Preloaded protocol export map.
- Returns
Compact section, or
Noneif nothing matched.- Return type
Optional[eth_defi.xerberus.vault_export.XerberusVaultSection]