degenbot.curve.per_block_cache¶

Per-block on-chain cache for CurveStableswapPool.

Owns all BoundedCache instances and their accessor methods, extracting the cache subsystem from the pool class. Each accessor follows the pure try/cache/store/return pattern — no accessor mutates state read by another accessor. get_cached_virtual_price() resolves its own dependencies inline (calling get_cached_base_cache_updated() and get_cached_base_virtual_price()), eliminating the need for side-effect mirrors or call-ordering contracts.

Module Contents¶

class degenbot.curve.per_block_cache.PerBlockCache(data_provider: degenbot.curve.types.CurveDataProvider | None, address: degenbot.types.chain.ChecksummedAddress, *, base_pool_is_set: bool, state_cache_depth: int = 8)¶

Owns all per-block on-chain caches for a CurveStableswapPool.

Each accessor implements the try-cache → call-provider → store → return pattern. No accessor mutates state read by another accessor. get_cached_virtual_price() resolves its own dependencies internally, eliminating the need for side-effect mirrors or call-ordering contracts.

The pool holds one instance of this class instead of nine separate BoundedCache fields.

BASE_CACHE_EXPIRES: int = 600¶
get_cached_block_timestamp(block_number: degenbot.types.aliases.BlockNumber) → int¶

Fetch or retrieve cached block timestamp.

Returns:

The block timestamp as an integer.

Raises:

MissingCurveData – If the value is not cached and no provider is available.

get_cached_base_cache_updated(block_number: degenbot.types.aliases.BlockNumber) → int¶

Fetch or retrieve cached base_cache_updated block number.

Pure try/cache/store/return. No mirror side effect.

Returns:

The base_cache_updated timestamp as an integer.

Raises:

MissingCurveData – If the value is not cached and no provider is available.

get_cached_base_virtual_price(block_number: degenbot.types.aliases.BlockNumber) → int¶

Fetch or retrieve cached base pool virtual price.

Pure try/cache/store/return. No mirror side effect.

Returns:

The base pool virtual price as an integer.

Raises:

MissingCurveData – If the value is not cached and no provider is available.

get_cached_virtual_price(block_number: degenbot.types.aliases.BlockNumber) → int¶

Resolve virtual price with self-contained expiry logic.

For metapools, internally resolves base_cache_updated and base_virtual_price (calling their accessors) to determine whether to use the cached base_virtual_price or fetch live. No side-effect mirrors — all dependency resolution is inline.

Returns:

The virtual price as an integer.

Raises:

MissingCurveData – If the value is not cached and no provider is available.