auradefi 0.1.2
PyPI GitHub

API reference

The surface a host actually touches, in the order it meets it. Signatures, types, defaults and field lists are generated from the code, so they cannot drift from it.

Getting started

The two factories and the object they return.

AuradefiThe library's public surface (SPEC §8).
UserHandleOne host user's slice of the library (SPEC §7.1, §8).
SettingsSettings(etherscan_api_key: 'str | None' = None, helius_api_key: 'str | None' = None, http_timeout_s: 'float' = 10.0, sync_min_interval_s: 'int' = 60, project_id: 'str' = 'embed', trusted_proxy_hops: 'int' = 0)

Ports you implement

Bring your own: each is a structural Protocol.

LedgerPortStructural contract for ledger persistence backends.
SyncStatePortStructural contract for embed sync-state persistence.
BalanceSourceStructural seam: typed balances for one (chain × address).
PageFetcherStructural seam: ONE page of raw explorer rows for one window.
PriceOracleStructural interface: current USD prices for CAIP-19 asset ids.

Ports we ship

Defaults, so you only implement what you want to.

EtherscanSourceBoth source seams over one Etherscan V2 client.
EtherscanV2Etherscan V2 balance source over an injected `httpx.Client`.
DefiLlamaOracleCurrent and past USD prices from the keyless `coins.llama.fi`.
InquirerFirst-wins USD price aggregation over an ordered oracle sequence.
MemoryLedgerDict-backed `LedgerPort` with hard per-tenant isolation.
SqlModelLedger`LedgerPort` over host-owned SQLModel sessions (SPEC §8).
MemorySyncStateDict-backed `SyncStatePort` with hard per-tenant isolation.
SystemClockThe wall clock, and the default when a host binds no other.
FrozenClockDeterministic clock for tests; moves only when advance() is called.

Reading a chain directly

One eth_call, five in one round trip, or a range of logs.

EvmRpcEVM JSON-RPC 2.0 over an injected `httpx.Client`.
EvmContractReaderOne `eth_call` per read, pinned at a block chosen at construction.
Multicall3Batched reads through one Multicall3 `aggregate3` call.
CallOne member of an `aggregate3` batch.
CallResultOne `aggregate3` answer: a value, or a DECLARED failure.
scan_logsTyped logs for the INCLUSIVE range, scanned one chunk at a time.
LogRecordOne typed `eth_getLogs` row.
keccak256Return the 32-byte keccak256 digest of `data`.
selectorThe four-byte function selector for a canonical `signature`.

Values on the wire

What you get back, field by field.

QuantityAn exact base-unit amount: `raw * 10**-decimals`.
MoneyAn exact amount denominated in one currency.
HoldingsReportAll holdings of one (address × chain) with an exact USD total.
HoldingOne asset balance on one account (≡ Plaid Holding).
SyncReportAggregate result of one `sync()` tick (SPEC §8).
ConnectionSyncReportWhat one connection's slice of a `sync()` call did (SPEC §8).
ConnectionRecordOne watched address bound to a tenant (SPEC §8, §3.1).
LedgerTransactionA persisted transaction: identity, timing, movements, bookkeeping.
EntryOne movement of a single asset inside a transaction.
SyncPageOne page of sync events, ordered by ascending last-modified seq.

Accounting

Cost basis and PnL at any instant.

pnl_atPnL at an ARBITRARY date. The thing Zerion cannot do (SPEC §9).
derive_eventsDistil ledger transactions into the taxable event stream (SPEC §9).
PnLReportPnL as of one instant, under one costing method.
TaxLotOne open lot in Plaid's `tax_lots[]` shape (SPEC §6.2, DECISIONS

Webhooks

Signing, delivery and replay.

signReturn the `X-Auradefi-Signature` value for `body`.
verify_signatureReturn `None` iff `signature` is valid AND fresh.
DelivererDrains due deliveries through an injected `httpx.Client`.
replayRe-arm one delivery; return the NEW PENDING row.

Testing offline

Record a real address once, then replay it forever.

RecorderWraps a real transport, saving each interaction for later replay.
CassetteA loaded cassette; `transport()` yields the replaying transport.
loadRead a cassette from disk, ready to replay.