Commit graph

32 commits

Author SHA1 Message Date
Dagur Valberg Johannsson
499275eaef moria v1-1: TEST18 categories and riftenlabs-defi 0.5.1
Switch the indexer off the local path dep onto crates.io 0.5.1 (75-byte
loan, 3-byte principal). Point chipnet deploy constants at TEST18 and
keep continuation UTXOs on partial redeem/repay.
2026-08-21 13:36:30 +02:00
Dagur Valberg Johannsson
a5e91afea8 Cut over to Moria v1-1; drop v1 indexing
Replace the v1 moria indexer with v1-1 tables and RPC. Chipnet tracks the
live deployment only; mainnet stays idle until a v1-1 deployment exists.

v1-1 rows carry delegate hash, borrow-time allowance deposits, crank fee
takes, and allowance-close recoveries. Policy lives on the parked
allowance (verified nSequence hint or first spend), not on the loan NFT.
Bar/pool history and realized NAV APR are confirmed-blocks only.

Bind the API before IBD so Rocket is up during sync. Empty electrum
header batches shrink the chain instead of panicking.

Depend on published riftenlabs-defi 0.4.6.
2026-08-18 09:15:19 +02:00
Hossein Zoda
dcebaf2648 tokentoken/tokenbch: index delegation pools, replace the pre-delegation AMM
Replace the old P2SH32/CONJURE TokenToken AMM indexer (never in
production; its tables are dropped by an always-run migration) with the
delegation-model indexers from riftenlabs-defi 0.4.5:

- tokentoken: two co-created bare-P2S UTXOs (thin main + storage
  sibling). tokenbch (new): single-UTXO token<->BCH pool with the
  runtime feePaidInToken fee side. Both admitted purely by the constant
  locking derived from the per-network delegation-pool platform NFTH.
- src/db/orbconstants.rs: ONE platform NFTH serves both contracts —
  chipnet pins the deployed ORB v0 value (libriften orb/v0/chipnet.ts),
  mainnet is the all-zero placeholder: while unconfigured NOTHING
  delegation-related is parsed, fetched or indexed (fail-closed).
- Schema: immutable config (nftOwner, tokens, poolFeeRate, minFee,
  virtualX/Y, tokenbch feePaidInToken) on the pool row; per-state
  history carries raw reserves, owed, platformFeeRate (both mutable by
  platform sweeps) and deltas. History rows now FK tx(txid) ON DELETE
  CASCADE, so evicted mempool txs clean up after themselves (the old
  tokentoken indexer leaked those).
- LP teardowns carry no pool output: ingestion probes every
  blob-presenting tx's spent outpoints against the recorded pool set
  and flags a known pool UTXO spent without successor as withdrawn
  (withdrawn_in_txid FK ON DELETE SET NULL reverts an evicted teardown;
  reorg undo reverts a confirmed one).
- electrum mempool filters: the combined logic blob (scriptsig; every
  spend incl. teardowns) + the constant thin-main locking (scriptpubkey;
  creations), per contract, skipped while unconfigured.
- RPC: /tokentoken responses gain owed_a, platform/pool fee rates,
  minFee and virtual offsets; new /tokenbch (pool/active?token, pools,
  tokens) mirrors it for BCH pairs.
- deps: bitcoincash 0.32.4 (token.amount -> .to_int() in the ido
  indexer), riftenlabs-defi 0.4.5. NOTE: 0.4.5 (rust-riftenlabs-defi
  7c65f66) is not on crates.io yet — until it is published, build with
  a local [patch.crates-io] pointing at the sibling checkout (the
  committed Cargo.lock carries the path-patched entry). Also fixes a
  latent test bug (ido_params_nft_commitment_roundtrip never wrote
  createExecutionFee after the 127-byte layout shift).

Verified: cargo build, test (232 passing), clippy (no new warnings)
and fmt all clean.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-12 10:06:13 +03:00
Hossein Zoda
c7a9e9bea6 ido: replace num-bigint with malachite
Migrate the ido module's arbitrary-precision math from num-bigint to
malachite (already a workspace dependency). BigInt becomes
malachite::Integer throughout; the VM-number byte codec uses
PowerOf2Digits, sign handling uses Integer::sign(), and primitive
conversions use try_from.

Add an IntegerAsStr serde adapter for string-serialized fields, since
malachite's FromStr::Err is () and does not satisfy DisplayFromStr's
Display bound. JSON output is unchanged.

Drop the now-unused num-bigint and num-traits dependencies.

Also fix all clippy warnings in the module surfaced by the migration
(unwrap-after-is_none control flow, a const->static LazyLock bug,
an oversized enum variant boxed, and assorted mechanical lints).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-22 10:41:39 +00:00
Hossein Zoda
988426e485 ido, compiles, with claude generated unittests 2026-06-21 01:44:39 +03:00
Dagur Valberg Johannsson
dc420424ac Update bitcoincash to 0.32.2 and riftenlabs-defi to 0.4.1
Fixes the indexer crash on chipnet: bitcoincash 0.32.1's
Opcode::classify panicked on BCH re-enabled opcodes (e.g. OP_SPLIT),
which riftenlabs-defi hit while parsing input scriptSigs in
parse_cauldrons_from_tx. bitcoincash 0.32.2 makes classify total and
panic-free (and adds the May 2026 upgrade opcodes); riftenlabs-defi
0.4.1 additionally hardens read_push_from_script to not classify
non-push opcodes at all.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 22:58:53 +02:00
Dagur Valberg Johannsson
1614b84674 Upgrade bitcoincash to 0.32 and add TokenToken AMM pool indexing
Migrate off the deprecated bitcoincash 0.29 API (Amount/Version types,
FromHex -> FromStr/parse, non-exhaustive Network) across the indexer and
tests.

Add indexing of native token-A <-> token-B (TokenToken) AMM pools:

- tokentoken_pool / tokentoken_pool_history_entry tables in cauldron.db,
  created via an always-run idempotent migration (no DB_VERSION bump, so
  existing databases upgrade in place)
- block-path indexing sharing the cauldron write transaction and reorg
  undo, with creation/swap/withdrawal state tracking and reserve deltas
- mempool indexing: electrum mempool.get filters on the tokentoken
  contract code (spends) and the CONJURE op_return hint (creations);
  first_seen_timestamp reconciles with mtp on confirmation
- RPC endpoints /tokentoken/pool/active (pair lookup, order-insensitive)
  and /tokentoken/tokens

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-10 16:18:35 +02:00
Dagur Valberg Johannsson
4d205cada4
Delphi v2 support
Same API from consumer-standpoint
2026-05-04 15:03:40 +02:00
Dagur Valberg Johannsson
c7eb5bcc36 Added support for indexing Moria contracts 2026-03-30 23:52:29 +02:00
Dagur Valberg Johannsson
527b9ba91c
Bump electrum dep to allow larger websocket msg
We need to allow larger messages to index large blocks via websocket
interface.
2026-02-24 10:33:39 +01:00
Dagur Valberg Johannsson
f421327a5d
Switch to tokio and sqlx
This makes the application fully async; freeing web server threads to
handle new connections when waiting on SQL queries.

Additionally sqlx will allow easier move to a different database if
needed in the future.

Includes some SQL optimizations as well (slow queries more easliy identifiable
with sqlx).
2026-02-18 10:16:51 +01:00
Dagur Valberg Johannsson
bac43bbb98
Make DB read pool size configurable 2026-02-10 14:49:28 +01:00
Dagur Valberg Johannsson
7ad0303209
Add WebSocket support 2026-02-03 09:39:12 +01:00
Dagur Valberg Johannsson
7d9352cf53
Fix clippy issues 2025-07-16 13:52:46 +02:00
Dagur Valberg Johannsson
460a1fc7f1
Add arbitrary int support 2025-07-16 09:30:17 +02:00
Dagur Valberg Johannsson
78e391560f
Added support for delphi oracle
This allows fetching historical asset prices from the blockchain.
2025-05-21 13:33:26 +02:00
Dagur Valberg Johannsson
33aebb0318
bug: Foreign keys not enforced
sqlite was not properly enforcing foreign keys, keeping conflicted
transactions in the database
2024-12-19 13:21:57 +01:00
Dagur Valberg Johannsson
d465c51480
missing build file 2024-10-25 15:28:40 +02:00
Dagur Valberg Johannsson
b4b9bf1eb5
Make rostrum server configurable
New default set to localhost
2024-10-25 15:22:44 +02:00
Dagur Valberg Johannsson
6cfd95dacf
Bump riftenlabs-defi dep 2024-10-24 11:52:11 +02:00
Dagur Valberg Johannsson
e4e7ec3b71
Add aggregated APY endpoint
Add an endpoint that gives a APY value across multiple micro-pools
2024-10-23 16:54:06 +02:00
Dagur Valberg Johannsson
5aebe7bdaf
Use package electrum-client-netagnostic
Replace package that pointed at a git repo with
electrum-client-netagnostic.
2024-10-08 22:15:46 +02:00
Dagur Valberg Johannsson
e38eaaa26c
Add BCMR indexer
This adds BCMR indexer, including downloading and parsing the actual
BCMR files.
2024-05-27 11:56:35 +02:00
Dagur Valberg Johannsson
519c442e34
rename binary 2024-04-02 14:07:30 +02:00
Dagur Valberg Johannsson
b80b1144da
api: current price 2024-04-02 13:17:25 +02:00
Dagur Valberg Johannsson
21a57554f8
Add sqlite connection pool 2024-03-14 12:14:55 +01:00
Dagur Valberg Johannsson
ca6fd42cbd
Fix wrong license in Cargo file
License was changed with commit b6eae5bdfa
2024-03-14 11:38:11 +01:00
Dagur Valberg Johannsson
1c817c8cfd
Add support for calculating pool APY 2024-03-14 10:54:33 +01:00
Dagur Valberg Johannsson
cd22aa8d70
Track transactions in the mempool 2024-02-16 14:18:41 +01:00
Dagur Valberg Johannsson
168670c9bf
Support block reorgs 2024-02-14 11:11:16 +01:00
Dagur Valberg Johannsson
b8943fb48d
Add CORS 2024-01-19 14:38:31 +01:00
Dagur Valberg Johannsson
69405d035a
Initial commit 2024-01-05 13:59:11 +01:00