feat: link QTC bridge deposits and withdrawals across both chains
ci / gate (push) Successful in 4m32s
deploy / validate (push) Skipped
deploy / build (push) Successful in 10m22s
deploy / deploy-web (push) Successful in 12s
deploy / deploy-api (push) Successful in 30s

#44 part 3. A deposit is linked exactly: the NEAR mint is bridge-mng.near
calling omft.near.ft_deposit, whose arguments carry the Intents account
and BRIDGED_FROM's txHash — Blake2-256 of the depositor's Quantus
transfer into their deposit address, length prefix included (checked:
extrinsic 1 of block 180,029 hashes to 0xc4444afc…, the hash in mint
piPTXyoq…). `chain_extrinsic.hash` is stored from now on and filled for
the bridge's deposit transfers.

`bridgescan` reads mints from gargravarr (bridge-mng.near is on shard 8),
each confirmed executed before it is recorded. History before our nodes
is found by bisecting the token's supply — 16 changes before
gargravarr's oldest block, 204 archive calls — and a rise is accepted as
mints only when the mints around it sum to it exactly. Withdrawals
(ft_withdraw with WITHDRAW_TO) come from the intents scan, rewound to
frankie's oldest block (migration 0018); custody's payout is matched by
a strict, stated rule, as an inference, with the fee it implies — every
pre-node withdrawal paid exactly 0.002 QTC less. `/bridge/deposits` and
`/bridge/withdrawals`; a linked-transactions panel on the NEAR Intents
page.

Refs #44

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015pkwBsR54NRmZyU4QVhvfj
This commit is contained in:
2026-10-07 09:10:33 +03:00
co-authored by Claude Opus 5.5
parent 69050a45c1
commit 084fd5ba2c
30 changed files with 2228 additions and 32 deletions
@@ -0,0 +1,65 @@
{
"db_name": "PostgreSQL",
"query": "\n select e.height, e.extrinsic_index, e.event_index,\n e.fields->>'from' as \"from!\", e.fields->>'to' as \"to!\",\n (e.fields->>'amount')::numeric::text as \"amount!\", e.at, x.hash\n from chain_event e\n left join chain_extrinsic x\n on x.chain = e.chain and x.height = e.height and x.extrinsic_index = e.extrinsic_index\n where e.chain = $1\n and e.pallet = 'Balances' and e.variant = 'Transfer'\n and e.fields->>'to' = any($2)\n order by e.height, e.event_index\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "height",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "extrinsic_index",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "event_index",
"type_info": "Int4"
},
{
"ordinal": 3,
"name": "from!",
"type_info": "Text"
},
{
"ordinal": 4,
"name": "to!",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "amount!",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "at",
"type_info": "Timestamptz"
},
{
"ordinal": 7,
"name": "hash",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Text",
"TextArray"
]
},
"nullable": [
false,
true,
false,
null,
null,
null,
true,
true
]
},
"hash": "22b4f760af8f1d529266bffd3127a1e04dd4634d59448f78e5ce2b8e7f5c6a79"
}
@@ -0,0 +1,17 @@
{
"db_name": "PostgreSQL",
"query": "update chain_extrinsic set hash = $4 where chain = $1 and height = $2 and extrinsic_index = $3",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Int8",
"Int4",
"Text"
]
},
"nullable": []
},
"hash": "631de8790be6b9a0257382baa9808cabebf4933ed6e86cfcd4c0beb55f249e86"
}
@@ -0,0 +1,27 @@
{
"db_name": "PostgreSQL",
"query": "\n insert into chain_extrinsic\n (chain, height, extrinsic_index, pallet, call, signer, signature,\n signature_bytes, args, extra, success, accounts, at, hash)\n select chain, height, extrinsic_index, pallet, call, signer, signature,\n signature_bytes, args, extra, success,\n array(select jsonb_array_elements_text(accounts)), at, hash\n from unnest(\n $1::text[], $2::bigint[], $3::int[], $4::text[], $5::text[], $6::text[],\n $7::text[], $8::int[], $9::jsonb[], $10::jsonb[], $11::bool[], $12::jsonb[],\n $13::timestamptz[], $14::text[]\n ) as t(chain, height, extrinsic_index, pallet, call, signer, signature,\n signature_bytes, args, extra, success, accounts, at, hash)\n on conflict (chain, height, extrinsic_index) do update set\n pallet = excluded.pallet,\n call = excluded.call,\n signer = excluded.signer,\n signature = excluded.signature,\n signature_bytes = excluded.signature_bytes,\n args = excluded.args,\n extra = excluded.extra,\n success = coalesce(excluded.success, chain_extrinsic.success),\n accounts = excluded.accounts,\n at = coalesce(excluded.at, chain_extrinsic.at),\n hash = coalesce(excluded.hash, chain_extrinsic.hash)\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"TextArray",
"Int8Array",
"Int4Array",
"TextArray",
"TextArray",
"TextArray",
"TextArray",
"Int4Array",
"JsonbArray",
"JsonbArray",
"BoolArray",
"JsonbArray",
"TimestamptzArray",
"TextArray"
]
},
"nullable": []
},
"hash": "79816e82d765cdb43f1b27ed1340e8ee0e6e72c199b540788c3c756cefd23078"
}
@@ -0,0 +1,20 @@
{
"db_name": "PostgreSQL",
"query": "\n insert into bridge_mint (chain, near_height, tx_hash, at, account, amount, quantus_tx)\n values ($1, $2, $3, $4, $5, $6::text::numeric, $7)\n on conflict (chain, tx_hash) do nothing\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Int8",
"Text",
"Timestamptz",
"Text",
"Text",
"Text"
]
},
"nullable": []
},
"hash": "a94a6b768deecd017eabc7871aaa9377b3b405857c82e9db56a81d60e0fb070d"
}
@@ -1,26 +0,0 @@
{
"db_name": "PostgreSQL",
"query": "\n insert into chain_extrinsic\n (chain, height, extrinsic_index, pallet, call, signer, signature,\n signature_bytes, args, extra, success, accounts, at)\n select chain, height, extrinsic_index, pallet, call, signer, signature,\n signature_bytes, args, extra, success,\n array(select jsonb_array_elements_text(accounts)), at\n from unnest(\n $1::text[], $2::bigint[], $3::int[], $4::text[], $5::text[], $6::text[],\n $7::text[], $8::int[], $9::jsonb[], $10::jsonb[], $11::bool[], $12::jsonb[],\n $13::timestamptz[]\n ) as t(chain, height, extrinsic_index, pallet, call, signer, signature,\n signature_bytes, args, extra, success, accounts, at)\n on conflict (chain, height, extrinsic_index) do update set\n pallet = excluded.pallet,\n call = excluded.call,\n signer = excluded.signer,\n signature = excluded.signature,\n signature_bytes = excluded.signature_bytes,\n args = excluded.args,\n extra = excluded.extra,\n success = coalesce(excluded.success, chain_extrinsic.success),\n accounts = excluded.accounts,\n at = coalesce(excluded.at, chain_extrinsic.at)\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"TextArray",
"Int8Array",
"Int4Array",
"TextArray",
"TextArray",
"TextArray",
"TextArray",
"Int4Array",
"JsonbArray",
"JsonbArray",
"BoolArray",
"JsonbArray",
"TimestamptzArray"
]
},
"nullable": []
},
"hash": "c0bc24a0ac524e0ef577158d8d3159c6aadddc4cfb3b076fc417faf51d642c5d"
}
@@ -0,0 +1,21 @@
{
"db_name": "PostgreSQL",
"query": "\n insert into bridge_withdrawal\n (chain, near_height, tx_hash, intent_hash, at, account, destination, amount)\n values ($1, $2, $3, $4, $5, $6, $7, $8::text::numeric)\n on conflict (chain, tx_hash, intent_hash) do nothing\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Int8",
"Text",
"Text",
"Timestamptz",
"Text",
"Text",
"Text"
]
},
"nullable": []
},
"hash": "cd47ee8b3db65e3ca8ceec14ceb43489123e7cfd4939792d9c7f24265599d130"
}
@@ -0,0 +1,58 @@
{
"db_name": "PostgreSQL",
"query": "\n select near_height, tx_hash, intent_hash, at, account, destination,\n amount::text as \"amount!\"\n from bridge_withdrawal where chain = $1 order by near_height\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "near_height",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "tx_hash",
"type_info": "Text"
},
{
"ordinal": 2,
"name": "intent_hash",
"type_info": "Text"
},
{
"ordinal": 3,
"name": "at",
"type_info": "Timestamptz"
},
{
"ordinal": 4,
"name": "account",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "destination",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "amount!",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
false,
false,
false,
false,
null
]
},
"hash": "ec56841f812f415c544ddadbac99d0e85931f272fa56526fc1003fa036ac2bcc"
}
@@ -0,0 +1,52 @@
{
"db_name": "PostgreSQL",
"query": "\n select near_height, tx_hash, at, account, amount::text as \"amount!\", quantus_tx\n from bridge_mint where chain = $1 order by near_height\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "near_height",
"type_info": "Int8"
},
{
"ordinal": 1,
"name": "tx_hash",
"type_info": "Text"
},
{
"ordinal": 2,
"name": "at",
"type_info": "Timestamptz"
},
{
"ordinal": 3,
"name": "account",
"type_info": "Text"
},
{
"ordinal": 4,
"name": "amount!",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "quantus_tx",
"type_info": "Text"
}
],
"parameters": {
"Left": [
"Text"
]
},
"nullable": [
false,
false,
false,
false,
null,
false
]
},
"hash": "f85d5b62de5c5f4a088a4f9fed5f2703cf1fbe03b1f7b3741c4fad0307119911"
}