From 555d49b961d5b64b00ca2479f523cc18fa09e7ce Mon Sep 17 00:00:00 2001 From: jaxperro Date: Fri, 10 Jul 2026 00:32:04 -0400 Subject: [PATCH] =?UTF-8?q?wrap=5Fvia=5Fbridge:=20delivery=20is=20pUSD=20?= =?UTF-8?q?=E2=80=94=20the=20bridge=20wraps=20on=20deposit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The $3 test slice landed as pUSD 3.00 (bridge did native→USDC.e swap then the wrap itself, zero fees). Watch pUSD+USDC.e for delivery; zero USDC.e residue is the success case (manual wrap kept only as fallback). Co-Authored-By: Claude Fable 5 --- host/wrap_via_bridge.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/host/wrap_via_bridge.py b/host/wrap_via_bridge.py index c37685a4..e7e9e392 100644 --- a/host/wrap_via_bridge.py +++ b/host/wrap_via_bridge.py @@ -71,10 +71,18 @@ def wait_handle(label, h): return out +def delivered_units(): + """pUSD + USDC.e at the wallet — the $3 test slice (2026-07-10) proved the + bridge wraps on delivery (native → USDC.e swap, then pUSD credited), so + delivery must be measured on pUSD; USDC.e is counted in case a future + bridge change stops short of the wrap (the wrap step below picks it up).""" + return bal(PUSD) + bal(USDCE) + + def bridge_leg(client, calls_mod, amount, bridge_addr, label): """Gasless-transfer `amount` native USDC to the bridge and wait until the - deposit wallet's USDC.e balance rises by ~amount. Returns True on delivery.""" - before = bal(USDCE) + deposit wallet's pUSD/USDC.e rises by ~amount. Returns True on delivery.""" + before = delivered_units() print(f"\n[{label}] sending {fmt(amount)} native USDC → bridge {bridge_addr}") t = calls_mod.erc20_transfer_call(token_address=USDC, recipient=bridge_addr, amount=amount) @@ -87,14 +95,14 @@ def bridge_leg(client, calls_mod, amount, bridge_addr, label): deadline = time.time() + DELIVER_TIMEOUT_S while time.time() < deadline: time.sleep(POLL_S) - now = bal(USDCE) + now = delivered_units() try: st = http(f"{BRIDGE}/status/{bridge_addr}") txs = st.get("transactions") or [] latest = txs[0].get("status") if txs else "none" except Exception as e: latest = f"status err {e}" - print(f" USDC.e {fmt(now)} (Δ{fmt(now-before)}) · bridge status: {latest}") + print(f" pUSD+USDC.e {fmt(now)} (Δ{fmt(now-before)}) · bridge: {latest}", flush=True) # bridge swap costs a few tenths of a cent — 1% tolerance is generous if now - before >= amount * 0.99: print(f" [{label}] DELIVERED") @@ -152,7 +160,15 @@ def main(): usdce = bal(USDCE) if usdce == 0: - sys.exit("no USDC.e at the wallet — nothing to wrap, aborting") + # normal: the bridge wraps on delivery, so everything is already pUSD + print(f"\nno USDC.e residue — bridge delivered wrapped. " + f"pUSD {fmt(bal(PUSD))}") + try: + b = client.get_balance_allowance(asset_type="COLLATERAL") + print("exchange-view COLLATERAL:", str(b)[:220]) + except Exception as e: + print("balance check raised:", type(e).__name__, str(e)[:150]) + return print(f"\n[wrap] approve onramp + wrap {fmt(usdce)} USDC.e → pUSD") appr = pmcalls.erc20_approval_call(token_address=USDCE, spender=ONRAMP, amount=usdce)