tokenised_fund.asseto.backfill
Documentation for eth_defi.tokenised_fund.asseto.backfill Python module.
Backfill historical Asseto vault data into the shared vault pipeline.
This is a targeted production tool for the EVM products currently published by
Asseto’s public product registry. It does not rediscover whole chains and
updates only the selected Asseto vault identifiers. Historical rows combine
on-chain ERC-20 supply with Asseto’s verified Pricer NAV/share where
available, or its public daily display-NAV history for other products.
Usage:
source .local-test.env
export JSON_RPC_ETHEREUM="https://your-archive-ethereum-rpc"
PROTOCOLS=asseto poetry run python scripts/backfill-tokenised-funds.py
Useful environment variables:
Variable |
Description |
|---|---|
|
If |
|
Optional comma-separated chain ids or known names, e.g. |
|
Archive-capable RPC URL for each selected supported chain, e.g.
|
|
Required for cached HyperSync block-timestamp reads during price backfill. |
|
Optional comma-separated Asseto symbols, e.g. |
|
If |
|
If |
|
Historical multicall worker count. Default: |
|
Historical price frequency. Asseto supports daily |
|
Optional global scan range overrides. |
|
Optional production database path overrides. |
|
Optional cleaned price and reader-state path overrides. |
The backfill removes stale reader state only for selected Asseto vaults. This is required because the targeted scanner replaces those rows from its explicit start block onwards; retained later state would otherwise skip the rewrite. Only chains registered by the shared project registry and supported by HyperSync are included. Asseto products on unsupported chains, such as HashKey or Pharos until they are added to the project, are reported and skipped.
Functions
|
Backfill one Asseto EVM chain. |
|
Build Asseto vault adapters and attach deployment block hints. |
|
Create a synthetic shared scanner detection for an Asseto product. |
|
Create a synthetic discovery lead for an Asseto product. |
|
Convert one public registry entry to a temporary scanner product. |
|
Find the first block containing runtime code for an Asseto token. |
|
Return the normal RPC environment variable for a supported chain. |
|
Return accepted |
|
Check whether a chain is eligible for the shared Asseto backfill. |
Iterate current eligible Asseto registry products filtered by environment. |
|
|
Run the targeted Asseto historical backfill. |
|
Parse a boolean environment variable. |
|
Parse a comma-separated environment variable. |
|
Parse an optional integer environment variable. |
|
Parse an optional filesystem path environment variable. |
|
Read the script-local Asseto JSON-RPC URL from its environment variable. |
|
Read trusted local historical reader states. |
|
Read or initialise the vault metadata database. |
Resolve the daily historical sampling frequency for Asseto. |
|
|
Resolve the earliest history start for selected Asseto products. |
|
Select Asseto histories supported by the stablecoin-only cleaner. |
|
Atomically write historical reader state. |
- parse_bool_env(name, *, default=False)
Parse a boolean environment variable.
- parse_csv_env(name)
Parse a comma-separated environment variable.
- parse_optional_int_env(name)
Parse an optional integer environment variable.
- parse_path_env(name, default)
Parse an optional filesystem path environment variable.
- Parameters
name (str) – Environment variable name.
default (pathlib.Path) – Default production path.
- Returns
Expanded selected path.
- Return type
- resolve_frequency()
Resolve the daily historical sampling frequency for Asseto.
Asseto’s public NAV history contains daily observations. The scanner must therefore not generate artificial hourly rows by carrying a daily value forward between price publications.
- Returns
The required daily sampling interval.
- Raises
ValueError – If an hourly or other unsupported frequency is requested.
- Return type
Literal[‘1h’, ‘1d’]
- get_chain_selector_names(chain_id)
Return accepted
NETWORKSselector names for a chain.
- is_supported_asseto_chain(chain_id)
Check whether a chain is eligible for the shared Asseto backfill.
- get_asseto_rpc_env(chain_id)
Return the normal RPC environment variable for a supported chain.
- read_asseto_json_rpc_url(chain_id)
Read the script-local Asseto JSON-RPC URL from its environment variable.
- Parameters
chain_id (int) – Asseto product chain id.
- Returns
Configured archive-capable RPC URL for a supported chain.
- Raises
ValueError – If the standard RPC variable is unset.
- Return type
- iter_selected_products()
Iterate current eligible Asseto registry products filtered by environment.
- Returns
Unique registry products on supported chains with configured RPC URLs.
- Return type
collections.abc.Iterable[eth_defi.tokenised_fund.asseto.offchain_api.AssetoOffchainProduct]
- resolve_price_scan_start_block(products)
Resolve the earliest history start for selected Asseto products.
The normal scanner’s incremental reader state must not decide the start of a targeted rewrite. Begin at the earliest Asseto deployment unless the operator supplied
START_BLOCK. HyperSync populates any missing block timestamps, so an existing local timestamp cache must never truncate the requested history.- Parameters
products (list[eth_defi.tokenised_fund.asseto.constants.AssetoProduct]) – Selected products on one EVM chain.
- Returns
Explicit override or the earliest deployment block.
- Return type
- create_asseto_detection(product)
Create a synthetic shared scanner detection for an Asseto product.
- Parameters
product (eth_defi.tokenised_fund.asseto.constants.AssetoProduct) – Asseto product metadata.
- Returns
Detection compatible with metadata scan record generation.
- Return type
- create_asseto_lead(product)
Create a synthetic discovery lead for an Asseto product.
- Parameters
product (eth_defi.tokenised_fund.asseto.constants.AssetoProduct) – Asseto product metadata.
- Returns
Lead compatible with the vault metadata database.
- Return type
- read_vault_database(path)
Read or initialise the vault metadata database.
- Parameters
path (pathlib.Path) – Vault metadata database path.
- Returns
Existing or empty database.
- Return type
- read_reader_states(path)
Read trusted local historical reader states.
- Parameters
path (pathlib.Path) – Reader-state pickle file path.
- Returns
Existing states, or an empty mapping when the file does not exist.
- Return type
- write_reader_states(path, states)
Atomically write historical reader state.
- Parameters
path (pathlib.Path) – Reader-state pickle file path.
states (dict[eth_defi.vault.base.VaultSpec, dict]) – Reader state mapping returned by the historical scanner.
- Return type
None
- build_vaults(web3, products, token_cache)
Build Asseto vault adapters and attach deployment block hints.
- Parameters
web3 (web3.main.Web3) – Connected chain Web3 instance.
products (list[eth_defi.tokenised_fund.asseto.constants.AssetoProduct]) – Selected products on this chain.
token_cache (eth_defi.token.TokenDiskCache) – Shared token metadata cache.
- Returns
Configured Asseto vault adapters.
- Return type
- select_cleanable_vault_ids(products, rows)
Select Asseto histories supported by the stablecoin-only cleaner.
Asseto publishes products denominated in currencies such as HKD. Their raw NAV histories are valid, but the shared cleaned-price pipeline deliberately filters out denominations not recognised by
is_stablecoin_like(). Passing those identifiers to the strict replacement helper would make it interpret the expected filtering as accidental data loss.- Parameters
products (collections.abc.Iterable[eth_defi.tokenised_fund.asseto.constants.AssetoProduct]) – Asseto products whose raw histories were scanned.
rows (dict[eth_defi.vault.base.VaultSpec, dict]) – Fresh vault metadata rows keyed by vault specification.
- Returns
Canonical vault identifiers eligible for cleaned-history replacement.
- Return type
- fetch_contract_deployment_block(web3, address, end_block)
Find the first block containing runtime code for an Asseto token.
- Parameters
web3 (web3.main.Web3) – Archive-capable connection for the product chain.
address (eth_typing.evm.HexAddress) – Asseto ERC-20 token address.
end_block (int) – Highest block that may be checked.
- Returns
First block containing contract code.
- Raises
ValueError – If the public registry address has no contract code on this chain.
- Return type
- create_runtime_product(product, deployment_block, first_seen_at)
Convert one public registry entry to a temporary scanner product.
Public registry products do not all expose Asseto’s request/claim manager and
Pricercontracts. The generic adapter therefore uses their published daily NAV history, while preserving the exact token identity and deployment information read from the configured archive RPC.- Parameters
product (eth_defi.tokenised_fund.asseto.offchain_api.AssetoOffchainProduct) – Asseto public EVM product entry.
deployment_block (int) – First token-code block found on-chain.
first_seen_at (datetime.datetime) – Naive UTC deployment timestamp.
- Returns
Runtime Asseto adapter product metadata.
- Return type
- backfill_chain(chain_id, products, *, dry_run, scan_prices, clean_prices, frequency, vault_db, vault_db_path, price_database_path, cleaned_price_database_path, reader_state_database_path, token_cache)
Backfill one Asseto EVM chain.
Metadata and historical writes use the same shared database and scanner paths as the normal vault pipeline, but both are limited to selected Asseto identifiers.
- Parameters
chain_id (int) – EVM chain id.
products (list[eth_defi.tokenised_fund.asseto.offchain_api.AssetoOffchainProduct]) – Selected Asseto products on this chain.
dry_run (bool) – Whether filesystem/database writes are disabled.
scan_prices (bool) – Whether to scan supply, NAV, and TVL history.
clean_prices (bool) – Whether to replace selected cleaned price histories.
frequency (Literal['1h', '1d']) – Historical sampling interval.
vault_db (eth_defi.vault.vaultdb.VaultDatabase) – In-memory metadata database.
vault_db_path (pathlib.Path) – Metadata database output path.
price_database_path (pathlib.Path) – Uncleaned historical price parquet path.
cleaned_price_database_path (pathlib.Path) – Cleaned historical price parquet path.
reader_state_database_path (pathlib.Path) – Reader-state pickle path.
token_cache (eth_defi.token.TokenDiskCache) – Shared token metadata cache.
- Returns
Summary row for operator output.
- Return type
- main()
Run the targeted Asseto historical backfill.
- Return type
None