Deviant BCH wallet — CashTokens + covenants (Katalogos v1 · chipnet)
Root cause of the "returned me more BCH than I started with" bug:
1. User broadcasts BCH → ASM claim; applyOptimisticSwapDelta registers
a pending overlay { bchDelta: +1_013_000, preSwap: 100_000_000 }
and directly decrements bchRow.bal to 0.98987.
2. Electrum lags on mempool indexing longer than the 60 s hard
timeout → reapPendingSwaps drops the overlay entry.
3. paintBalance now runs with pending: [], effective = reported (still
stale = 100_000_000) → bchRow.bal snaps back to 1.0 (WRONG).
4. User broadcasts ASM → BCH redeem; applyOptimisticSwapDelta reads
currentBchSatsFromAssets = 100_000_000 (the inflated basis) and
directly adds the released BCH: bchRow.bal → 1.00987.
5. User sees more BCH than they started with.
Three-part fix:
(a) Hard timeout raised from 60 s → 30 min. Chipnet mempool inclusion
+ first-confirmation latency is comfortably inside that window; a
30-min-old pending is genuinely stuck and should age out.
(b) New reconcilePendingViaTxid pass runs on every refreshBalance:
calls blockchain.transaction.get(txid) for each unconfirmed entry;
if the endpoint returns a raw hex, the tx has landed (mempool or
block) → mark confirmed. reap then drops confirmed entries whether
or not the reported UTXO set has caught up.
(c) pendingSwaps persist to localStorage
(deviant.potidaea.pending-swaps.v1). A page reload mid-flight no
longer loses the overlay while electrum finishes syncing.
Also: manual refresh button — a small ⟳ pill on the Balances panel
title (od-botright) and a larger version on the v-balances view header.
Both fire refreshBalance() and spin briefly as feedback. Users who
suspect a stale balance can force a re-read from chipnet immediately.
Verified in deployed bundle: 30-min timeout literal present, txid
confirmation path present, localStorage key present, old 60_000 gone.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
|
||
|---|---|---|
| .claude | ||
| brand | ||
| contracts | ||
| design | ||
| docs | ||
| KnowledgeBase | ||
| Parameters | ||
| public | ||
| scripts | ||
| services | ||
| shells | ||
| site/deviant | ||
| snapshots | ||
| spike | ||
| src | ||
| telegram-orderbook | ||
| test | ||
| wiki | ||
| .calibration-sweep.json | ||
| .catalytic-sweep.json | ||
| .env.example | ||
| .gitignore | ||
| .kac-extract.txt | ||
| .sim-athenae.json | ||
| adaptive-data.json | ||
| bch-history.json | ||
| bch-market.json | ||
| BCH_Token_Economy_Concept_Paper.md | ||
| bch_wallet_architecture.svg | ||
| CLAUDE.md | ||
| deviant_technical_spec_v2.7.md | ||
| package-lock.json | ||
| package.json | ||
| project-context.md | ||
| README.md | ||
| tsconfig.json | ||
| usdm-historical.json | ||
Deviant
BCH two-tier token economy platform. Pre-implementation. See BCH_Token_Economy_Concept_Paper.md for the full design.
Status
Bootstrap snapshot — protocol swap mechanism is the validation target.
Project map
| Path | Purpose |
|---|---|
BCH_Token_Economy_Concept_Paper.md |
Architecture spec, all [PROPOSED] claims |
CLAUDE.md |
Working agreement for Claude sessions |
src/ |
TypeScript wallet + token logic |
contracts/ |
CashScript source for Architecture A contracts |
test/ |
Unit tests (regtest) + integration plan (chipnet, mainnet) |
scripts/ |
Code-scan, snapshot, compile helpers |
wiki/ |
Living docs: architecture, decisions, testing strategy, code map |
snapshots/ |
Numbered progress snapshots |
Quickstart
npm install
npm run compile:contracts # produces artifacts from contracts/*.cash
npm run test:regtest # runs regtest suite
npm run scan # regenerates wiki/code-map.md
npm run snapshot # appends a new snapshot
Build priorities (active)
- Protocol swap mechanism — most novel claim, needs validation first.
- CashScript enforcement on mainnet — not just theoretical verification.
- tokenId correlation across A/B tiers — edge cases expected.
See wiki/testing-strategy.md for the staged regtest → chipnet → mainnet plan.