feat(usdt-bridge): migrate custody from single hot key to 3-of-5 multisig

The single-key custodial model (see prior commit's own doc comment:
"Custodial: A single keypair controls both sides") was replaced with
a 3-of-5 multisig spanning the Serok/SerokiMeclise/Xezinedar/Berdevk/
Noter tiki role-holders (full record in res/validators-tiki.md,
outside this repo). Discovered along the way: wUSDT's ~100M supply
had zero real USDT backing on Polkadot Asset Hub - Treasury_1 (the
actual asset owner, not the seed_path wallet this tool assumed) held
0 USDT/DOT there, with ~99M of the 100M supply sitting undistributed
in Treasury_1's own account. Migrated Pezkuwi Asset Hub custody in one
atomic batch (transfer 1M wUSDT to the multisig, set_team, then
transfer_ownership last) signed by Treasury_1 - tx
0xd5dc550c5cf04f323e5c1d9c13f2056acafc9f56404c657b9743c15ff3a3aacb,
verified on-chain.

listen_deposits/listen_withdrawals no longer sign and submit
mint/burn/transfer - no key this process holds has authority over the
multisig account. They now only detect on-chain events and record
status=pending_multisig_approval with the exact call parameters an
operator needs; actual approval happens through pwap-web's existing
multisig UI (shared/lib/multisig.ts, shared/lib/usdt.ts), not this
relayer. BridgeConfig gained custody_multisig_polkadot/_pezkuwi
fields.

Added pezkuwi-subxt/pezkuwi-subxt-signer alongside the existing
vanilla subxt dependency: vanilla subxt's codegen hardcodes the
`sp_runtime` module path and its default signed-extension handling
produced "bad signature" on submission against this chain's actual
metadata - pezkuwi-subxt (following vendor/pezkuwi-subxt's own
grant_noter_tiki.rs example: PezkuwiConfig, XCM v3, sudo_unchecked_weight)
is what actually signs and submits successfully. Also used to grant
the Xezinedar and Berdevk tiki roles (previously missing signatories
for the multisig) to two validators via a relay-chain sudo XCM Transact,
since the People chain has no local Sudo pallet.
This commit is contained in:
Satoshi Qazi Muhammed committed 2026-07-13 16:59:20 -07:00
1 parent cc246664ee
commit 45e4b26068
6 files changed
+1224 -7021

No files matched your search

+102 -127
View File
@@ -7,8 +7,22 @@
//! Backing:
//! - 1:1 backed by real USDT on Polkadot Asset Hub
//!
//! Architecture:
//! - Custodial: A single keypair controls both sides
//! Architecture (updated 2026-07-13 - see /home/myhez/res/validators-tiki.md for the full
//! migration record):
//! - Custody is a 3-of-5 multisig, NOT a single keypair. On Pezkuwi Asset Hub the multisig
//! (5GvwxmCDp3PC33KHoeWSgj3S7ocE7nzk1jiCCZMPSDBFeNcj) now owns wUSDT (asset 1000) - it holds
//! a seed pool of 1,000,000 wUSDT and is the sole issuer/admin/freezer. On Polkadot Asset Hub
//! the same account (15sF76THfpefUaKomHZSpssayRbsp6Yt6ESgMrLjzJCmpe66) is the designated
//! deposit address, though it currently holds no real USDT - nobody has deposited real value
//! into this bridge yet.
//! - Because of this, `listen_deposits`/`listen_withdrawals` below can no longer sign and
//! submit mint/transfer calls automatically - no key this process holds has authority over
//! the multisig account. They now only DETECT on-chain events and record them as
//! pending_multisig_approval; an actual release requires 3 of the 5 signatories (Serok,
//! SerokiMeclise, Xezinedar, Berdevk, Noter - see res/validators-tiki.md) to approve via
//! `Multisig.approveAsMulti`/`asMulti`, which is expected to happen through pwap-web's
//! existing multisig UI (shared/lib/multisig.ts, shared/lib/usdt.ts, MultisigMembers.tsx),
//! not this relayer.
//! - Minimum deposit/withdraw: 10 USDT
//! - Fees: Configurable (default 0.1%)
@@ -52,12 +66,27 @@ pub struct BridgeConfig {
/// of a single bad event (bug, reorg, compromised sender) instead of relaying it blindly.
#[serde(default = "default_max_single_tx")]
pub max_single_tx: u128,
/// The 3-of-5 multisig custody account, Polkadot Asset Hub SS58 encoding. Deposits are
/// watched for transfers TO this address - it replaced the old single-key custody address.
#[serde(default = "default_multisig_polkadot")]
pub custody_multisig_polkadot: String,
/// Same multisig account, Pezkuwi Asset Hub SS58 encoding (it owns wUSDT asset 1000).
#[serde(default = "default_multisig_pezkuwi")]
pub custody_multisig_pezkuwi: String,
}
fn default_max_single_tx() -> u128 {
5_000_000_000 // 5,000 USDT (6 decimals) - conservative pilot-stage cap
}
fn default_multisig_polkadot() -> String {
"15sF76THfpefUaKomHZSpssayRbsp6Yt6ESgMrLjzJCmpe66".to_string()
}
fn default_multisig_pezkuwi() -> String {
"5GvwxmCDp3PC33KHoeWSgj3S7ocE7nzk1jiCCZMPSDBFeNcj".to_string()
}
impl Default for BridgeConfig {
fn default() -> Self {
Self {
@@ -71,6 +100,8 @@ impl Default for BridgeConfig {
seed_path: PathBuf::from("bridge_seed.json"),
db_path: PathBuf::from("bridge_db.json"),
max_single_tx: default_max_single_tx(),
custody_multisig_polkadot: default_multisig_polkadot(),
custody_multisig_pezkuwi: default_multisig_pezkuwi(),
}
}
}
@@ -835,19 +866,21 @@ async fn cmd_transfer_usdt(config: &BridgeConfig, to: &str, amount: u128) -> Res
}
async fn listen_deposits(config: &BridgeConfig) -> Result<()> {
let (polkadot_addr, _) = load_wallet_addresses(&config.seed_path)?;
let polkadot_addr = &config.custody_multisig_polkadot;
println!("╔══════════════════════════════════════════════════════════════╗");
println!("║ DEPOSIT LISTENER ║");
println!("║ DEPOSIT LISTENER (detect-only) ║");
println!("╚══════════════════════════════════════════════════════════════╝\n");
println!("Bridge Address (Polkadot): {}", polkadot_addr);
println!("Bridge Address (Polkadot, 3-of-5 multisig): {}", polkadot_addr);
println!("USDT Asset ID: {}", config.polkadot_usdt_asset_id);
println!("Min Deposit: {} USDT", config.min_deposit as f64 / 1_000_000.0);
println!("\nListening for deposits...\n");
println!("\nNo key held by this process can mint on the multisig's behalf -");
println!("detected deposits are recorded as pending_multisig_approval. An actual");
println!("mint requires 3 of the 5 signatories to approve via pwap-web.\n");
println!("Listening for deposits...\n");
let client = connect_to_chain(&config.polkadot_rpc).await?;
let keypair = load_keypair(&config.seed_path)?;
// Subscribe to new blocks
let mut blocks = client.blocks().subscribe_finalized().await?;
@@ -913,59 +946,39 @@ async fn listen_deposits(config: &BridgeConfig) -> Result<()> {
config.max_single_tx as f64 / 1_000_000.0
);
} else if amount >= config.min_deposit {
// Process deposit
let fee = calculate_fee(amount, config.fee_basis_points);
let net_amount = amount - fee;
info!(" Processing... Fee: {} USDT, Net: {} USDT",
fee as f64 / 1_000_000.0,
net_amount as f64 / 1_000_000.0
);
// Same AccountId32, re-encoded under Pezkuwi's SS58 prefix -
// see convert_ss58_prefix's doc comment for why this is
// correct rather than a placeholder.
match convert_ss58_prefix(&from_str, 42) {
Ok(pezkuwi_recipient) => {
info!(" ⏳ AWAITING MULTISIG APPROVAL - not auto-minting.");
info!(
" 3 of 5 signatories must approve: Assets.transfer({}, {}, {}) from the multisig's seed pool",
config.pezkuwi_wusdt_asset_id, pezkuwi_recipient, net_amount
);
info!(" (fee: {} USDT, net: {} USDT) - use pwap-web's multisig UI.",
fee as f64 / 1_000_000.0, net_amount as f64 / 1_000_000.0);
// Connect to Pezkuwi and mint
match connect_to_chain(&config.pezkuwi_rpc).await {
Ok(pezkuwi_client) => {
// Same AccountId32, re-encoded under Pezkuwi's SS58 prefix -
// see convert_ss58_prefix's doc comment for why this is
// correct rather than a placeholder.
match convert_ss58_prefix(&from_str, 42) {
Ok(pezkuwi_recipient) => {
match mint_wusdt(
&pezkuwi_client,
&keypair,
config.pezkuwi_wusdt_asset_id,
&pezkuwi_recipient,
net_amount,
).await {
Ok(tx) => {
info!(" ✅ Minted wUSDT to {}! TX: {}", pezkuwi_recipient, tx);
db.add_deposit(DepositRecord {
id: db.next_deposit_id(),
polkadot_tx_hash: tx_hash.clone(),
polkadot_block: block_number as u64,
sender_address: from_str.clone(),
amount,
fee,
net_amount,
pezkuwi_tx_hash: Some(tx),
status: "completed".to_string(),
created_at: chrono::Utc::now().to_rfc3339(),
processed_at: Some(chrono::Utc::now().to_rfc3339()),
});
db.save(&config.db_path)?;
}
Err(e) => {
error!(" ❌ Mint failed: {}", e);
}
}
}
Err(e) => {
error!(" ❌ Could not derive Pezkuwi recipient from sender {}: {}", from_str, e);
}
}
db.add_deposit(DepositRecord {
id: db.next_deposit_id(),
polkadot_tx_hash: tx_hash.clone(),
polkadot_block: block_number as u64,
sender_address: from_str.clone(),
amount,
fee,
net_amount,
pezkuwi_tx_hash: None,
status: "pending_multisig_approval".to_string(),
created_at: chrono::Utc::now().to_rfc3339(),
processed_at: None,
});
db.save(&config.db_path)?;
}
Err(e) => {
error!(" ❌ Failed to connect to Pezkuwi: {}", e);
error!(" ❌ Could not derive Pezkuwi recipient from sender {}: {}", from_str, e);
}
}
} else {
@@ -989,19 +1002,21 @@ async fn listen_deposits(config: &BridgeConfig) -> Result<()> {
/// not silently short-pay a user), then release on Polkadot. Mirrors listen_deposits() and
/// shares its event-matching caveat - see the comment there.
async fn listen_withdrawals(config: &BridgeConfig) -> Result<()> {
let (polkadot_bridge_addr, pezkuwi_bridge_addr) = load_wallet_addresses(&config.seed_path)?;
let polkadot_bridge_addr = &config.custody_multisig_polkadot;
let pezkuwi_bridge_addr = &config.custody_multisig_pezkuwi;
println!("╔══════════════════════════════════════════════════════════════╗");
println!("║ WITHDRAWAL LISTENER ║");
println!("║ WITHDRAWAL LISTENER (detect-only) ║");
println!("╚══════════════════════════════════════════════════════════════╝\n");
println!("Bridge Address (Pezkuwi): {}", pezkuwi_bridge_addr);
println!("Bridge Address (Pezkuwi, 3-of-5 multisig): {}", pezkuwi_bridge_addr);
println!("wUSDT Asset ID: {}", config.pezkuwi_wusdt_asset_id);
println!("Min Withdraw: {} USDT", config.min_withdraw as f64 / 1_000_000.0);
println!("\nListening for withdrawals...\n");
println!("\nNo key held by this process can burn/release on the multisig's behalf -");
println!("detected withdrawal requests are recorded as pending_multisig_approval.\n");
println!("Listening for withdrawals...\n");
let pezkuwi_client = connect_to_chain(&config.pezkuwi_rpc).await?;
let keypair = load_keypair(&config.seed_path)?;
let mut blocks = pezkuwi_client.blocks().subscribe_finalized().await?;
@@ -1079,87 +1094,47 @@ async fn listen_withdrawals(config: &BridgeConfig) -> Result<()> {
let reserve = get_asset_balance(
&polkadot_client,
config.polkadot_usdt_asset_id,
&polkadot_bridge_addr,
polkadot_bridge_addr,
).await.unwrap_or(0);
if reserve < net_amount {
error!(
" 🚨 RESERVE SHORTFALL: custody holds {} USDT, need {} USDT to honor this withdrawal. \
HALTING this withdrawal and NOT burning wUSDT - page the on-call operator, do not retry blindly.",
This must be flagged to the signatories, not approved as-is.",
reserve as f64 / 1_000_000.0,
net_amount as f64 / 1_000_000.0
);
continue;
}
match convert_ss58_prefix(&from_str, 0) {
Ok(polkadot_recipient) => {
// Burn first: if release then fails, we've under-counted
// supply rather than double-released against one burn -
// the safer direction to fail in for a 1:1-backed peg.
match burn_wusdt(
&pezkuwi_client,
&keypair,
config.pezkuwi_wusdt_asset_id,
&pezkuwi_bridge_addr,
amount,
).await {
Ok(burn_tx) => {
info!(" 🔥 Burned {} wUSDT! TX: {}", amount as f64 / 1_000_000.0, burn_tx);
info!(" ⏳ AWAITING MULTISIG APPROVAL - not auto-burning/releasing.");
info!(
" 3 of 5 signatories must approve: burn {} wUSDT, then Assets.transfer({}, {}, {}) on Polkadot",
amount as f64 / 1_000_000.0, config.polkadot_usdt_asset_id, polkadot_recipient, net_amount
);
info!(" Reserve check at detection time: {} USDT available. Use pwap-web's multisig UI.",
reserve as f64 / 1_000_000.0);
match transfer_usdt(
&polkadot_client,
&keypair,
config.polkadot_usdt_asset_id,
&polkadot_recipient,
net_amount,
).await {
Ok(release_tx) => {
info!(" ✅ Released {} USDT to {}! TX: {}", net_amount as f64 / 1_000_000.0, polkadot_recipient, release_tx);
db.add_withdrawal(WithdrawalRecord {
id: db.next_withdrawal_id(),
pezkuwi_tx_hash: tx_hash.clone(),
pezkuwi_block: block_number as u64,
sender_address: from_str.clone(),
destination_address: polkadot_recipient,
amount,
fee,
net_amount,
polkadot_tx_hash: Some(release_tx),
status: "completed".to_string(),
created_at: chrono::Utc::now().to_rfc3339(),
processed_at: Some(chrono::Utc::now().to_rfc3339()),
});
db.save(&config.db_path)?;
}
Err(e) => {
error!(
" 🚨 Burned wUSDT but release FAILED: {}. Funds are now burned without release - \
requires manual operator intervention, recorded as failed for follow-up.",
e
);
db.add_withdrawal(WithdrawalRecord {
id: db.next_withdrawal_id(),
pezkuwi_tx_hash: tx_hash.clone(),
pezkuwi_block: block_number as u64,
sender_address: from_str.clone(),
destination_address: "UNRESOLVED".to_string(),
amount,
fee,
net_amount,
polkadot_tx_hash: None,
status: "burned_release_failed".to_string(),
created_at: chrono::Utc::now().to_rfc3339(),
processed_at: None,
});
db.save(&config.db_path)?;
}
}
}
Err(e) => {
error!(" ❌ Burn failed: {} - withdrawal left unprocessed, safe to retry", e);
}
}
db.add_withdrawal(WithdrawalRecord {
id: db.next_withdrawal_id(),
pezkuwi_tx_hash: tx_hash.clone(),
pezkuwi_block: block_number as u64,
sender_address: from_str.clone(),
destination_address: polkadot_recipient,
amount,
fee,
net_amount,
polkadot_tx_hash: None,
status: if reserve < net_amount {
"pending_multisig_approval_reserve_shortfall".to_string()
} else {
"pending_multisig_approval".to_string()
},
created_at: chrono::Utc::now().to_rfc3339(),
processed_at: None,
});
db.save(&config.db_path)?;
}
Err(e) => {
error!(" ❌ Could not derive Polkadot recipient from sender {}: {}", from_str, e);