Repository navigation
fix(0329): scale soroban amm legs by each token's decimals - #395
stkrolikiewicz merged 13 commits into
Conversation
The ingest needs decimals() from the same simulateTransaction call the asset-discovery symbol stage makes. Move the envelope builder and the Absent/Transient classification into prices_ingest_core::soroban_rpc so both readers share one boundary. symbols.rs re-exports the old names.
amm_trade_to_tick scaled both legs at a fixed 7, so a contract token with d decimals priced at 10^(7 - d) of market. Classic identities and their SACs stay at 7; a pure Soroban token uses its decimals() from the asset registry, and a token whose decimals are unknown yields no tick and is reported in LedgerSoroban::missing_decimals instead of being guessed.
Add prices.asset_decimals and a DecimalsResolver that asks a token's SEP-41 decimals() by simulation, rejects anything above rust_decimal's scale, and leaves a failed contract alone for ten minutes. The writer loads the table into the asset registry and writes new answers.
The live processor, events-backfill and sdex-backfill (combined mode) now resolve the tokens a decode reported missing, persist them, and decode that ledger again. Cold starts load prices.asset_decimals first. events-backfill prints the trades it still could not reprice.
Schema overview gains section 3.10b, amm-trades-schema closes its open decimals question, and the 0286 re-ingest runbook explains the new trades dropped (decimals) line events-backfill prints.
The decode now counts trades (not legs) dropped for unknown decimals. The live processor puts them on RunStats, WARNs with the contracts and publishes TradesMissingDecimals, alarmed like UnregisteredPoolEvents; sdex-backfill prints them in its summary like events-backfill.
A contract that answers with no usable scale is not asked again by the process; a Transient failure still retries after ten minutes. The calls for one ledger run concurrently, so N new tokens cost one RPC timeout.
Per-token decimals move contract-token volumes by design, so the reconcile compares volumes on the other candles and trades on all. The script now requires and gates on events-backfill's decimals line.
|
Review at 2b70318. These are new findings; none of them repeats Oskar's comments. Items 2 and 4 are new defects in the fix commits for his points (de3ae5a, c1e0fb1/34152397). 1.
|
- checked_div on the AMM quotient: per-token scales can push it past Decimal::MAX, where the plain division panicked and stalled ingest. - A contract error from a node behind the decoded ledger (latestLedger) is Behind, asked again next trade, not parked as Absent. - Backfills retry a Transient failure inline (1/5/20 s) instead of parking it for ten minutes of wall clock. - One decode_resolving for all three callers, tested with a fake resolver; reconcile tests inject an offline resolver. - The alarm says a hand-inserted row needs a cold start.
--amm wait recorded only the fallbacks, so a hand run with dropped trades could be marked done. amm-done now requires --decimals and the script refuses an amm.done without it.
|
Thanks, all eight addressed in 0731c6e / a2bdd1a / f44ced6:
|
First post-deploy prices match the market. All 46 historical contract tokens are seeded and Hetzner's events-backfill is the #395 build, so 0286 phase 3 needs no redo; Oskar restarts on the new script before 2025-07.
Summary
decimals(). This fixes contract-token prices that were off by 10^(7 − decimals): SolvBTC at a tenth of its price, the 18-decimal tokens 10^11 too low. A price pastDecimal::MAXdrops the trade instead of panicking.decode_resolvingstep resolves the token over Soroban RPC, persists it to the newprices.asset_decimals, records it, and decodes the ledger again. It is shared by the live ledger processor,events-backfillandsdex-backfill(combined mode). Lookups run concurrently. Absent is terminal per process. A node behind the decoded ledger is retried on the next trade. Transient parks the token for 10 min live and retries inline in backfills.TradesMissingDecimalswith a new alarm, and both backfills printtrades dropped (decimals): N. ThesimulateTransactionenvelope and its classification move from asset-discovery intoprices_ingest_core::soroban_rpc, shared bysymbol()anddecimals().reingest_0286.pycompares volumes only on candles without a contract-token leg, because their volume moves by design. It marks a month with dropped decimals trades DEFECT, refuses anevents-backfillbinary without the new line, and takesamm-done --decimalsin--amm wait. Docs updated: schema §3.10b, theamm-trades-schemadecimals question closed, and the 0286 runbook.init.sql(createsprices.asset_decimals) before the ingest; the live processor's init fails without it.events-backfillon the CH host before phase 3 uses the new script.