e3-g3: real, live bridge-threshold-check script (dynamic, gas-aware) - #56
Merged
Conversation
…3 (BION-DIRECTIVE-117) Real, read-only, no-key, no-signing script deciding whether bridging Gnosis's Tier B balance back to Base (via Ethereum) is currently economical -- using live gas prices and live ETH/USD on every run, not a fixed dollar figure. BION-DIRECTIVE-109 found the real two-hop cost was ~$5-15 at ~3 gwei Ethereum gas; re-measured live during this directive at ~0.1-0.14 gwei, the identical two-hop cost came out to ~$0.18-0.23 -- a >20x swing from gas price alone. Ethereum gas is routinely 1-100+ gwei depending on network conditions, so a threshold pinned to either snapshot would be wrong within days. This script computes the real cost live every time it runs and triggers only when the accumulated balance clears a configurable safety margin (default 10x) over TODAY's real cost. Real primary-source mechanism this cost model is based on (fetched the actual real OmniBridge implementation contract's ABI directly, not guessed): Gnosis's OmniBridge/xDai Bridge bridges native xDAI via its wrapped ERC20 form, WXDAI (0xe91D15...463a97d) -- confirmed live, isRegisteredAsNativeToken(WXDAI) == true on the real home mediator (0xf6A780...e268d). Real flow: WXDAI.deposit() (wrap), approve the mediator, then relayTokens(WXDAI, amount). Second leg reuses BION-DIRECTIVE-109's real, live-confirmed L1StandardBridge address (0x3154Cf...F2C35) and bridgeETHTo function. Live-run right now (today's real numbers): Tier B balance $6.00, real total bridging cost ~$0.18, 10x safety threshold $1.82 -- balance clears it, real recommendation is BRIDGE NOW. A genuinely different conclusion than D-109's original "uneconomical" finding, entirely because of today's unusually cheap Ethereum gas -- exactly the volatility this script's dynamic-threshold design exists to handle correctly either way. Scope boundary, stated plainly: this script only DECIDES, it never wraps, approves, relays, or bridges anything for real. The actual execution pipeline (a real, multi-step, two-chain state machine with AMB finality waits) is a real next build step needing its own fork-proof first, same discipline as every other real-money script this arc has shipped -- not silently left undone, named as the concrete next task. tsc --noEmit clean on all three gated configs. vitest run: 91 passed, 2 skipped, 0 failed (branch cut from main post-e3-g2-merge, unrelated to this script).
… via LI.FI (BION-DIRECTIVE-118/119) D-118 originally scoped this as OmniBridge (Gnosis->Ethereum DAI) + swap + L1StandardBridge (Ethereum->Base ETH), but real research found the OmniBridge mediator releases DAI, not ETH, and Base has no real, liquid, canonical bridged-DAI to land it in. Per D-119's decision (option 4 first), real research into bridge aggregators found LI.FI (li.quest) offers a real, live, single-hop route from Gnosis native xDAI directly to Base native ETH -- routed via real, non-custodial aggregators (Relay Protocol, ~$20B+ real volume; sometimes Stargate V2, LI.FI's routing choice varies per-quote). Real quote at the actual current Tier B balance (6 xDAI): ~$0.06 total cost (~1%), ~3s execution when routed via Relay -- dramatically simpler and cheaper than the original multi-leg design, and sidesteps the DAI/no-Base-liquidity dead end entirely. Adds scripts/bridge-execute.ts: same operator-runs-this/Kov-builds-this split as register-live.ts/self-test-request.ts -- interactive-TTY-only passphrase, preflight estimateGas before any broadcast, typed confirmation, a fresh re-quote immediately before the real broadcast (quotes are time-sensitive), then polls Base for the real cross-chain delivery. New test/fork/bridgeExecute.forkcheck.ts: real Hardhat fork proof against current Gnosis state, using a real, live LI.FI quote (not stubbed) -- proves the script's request/response/transaction-construction plumbing is real and correctly wired. Real, structural limitation found and documented directly, not glossed over: this operation's calldata depends on moment-of-execution DEX/pool liquidity state at the aggregator's quote time, which drifts from a fork pinned at a fixed historical block -- two separate real runs both reverted (once via an internal Balancer route overflowing, once likewise) purely from that drift, not from a script or routing bug. Kept as a real best-effort check; the actual verification path for this leg is the script's own live preflight estimateGas immediately before Forces' first real run, same "first real X" precedent as every other external-relay-dependent step this arc has needed (D-32, D-59). Bumped the Gnosis fork pin (hardhat.config.cts) to current chain state for the real BASE_MECH_POOL_WALLET balance to be visible on the fork. tsc --noEmit clean on all three gated configs. vitest run: 91 passed, 2 skipped, 0 failed (pre-existing Base fork-test EDR issue in marketplaceRead/serviceRegistryWrite.forkcheck.ts is unrelated, unaffected, and out of this directive's scope).
…xclude Paraswap routing (BION-DIRECTIVE-120)
Forces' real preflight (against real current mainnet state, not a fork)
reverted: panic: arithmetic underflow or overflow (0x11), on a real,
successfully-generated LI.FI quote (5.5 xDAI, real cost ~$0.05 quoted fine).
Nothing broadcast -- the script's own preflight caught it exactly as
designed. This directive corrects an earlier, incomplete conclusion (in
this same file's own prior header) that had attributed a similar revert
purely to fork/quote-timing drift.
Root-caused via a real debug_traceCall against live mainnet state, not
guessed: the revert originates deep inside Balancer's real Vault
(0xBA1333...ba9), reached through a Paraswap-orchestrated swap step LI.FI's
default routing included for this quote (feeCollection -> paraswap ->
relaydepository). Reproduced consistently across 3 independent real RPC
providers (rpc.gnosischain.com, publicnode, drpc) and multiple amounts
(5.5, 1, 100 xDAI) -- ruling out a flaky-RPC cause and an amount-too-small
cause, both explicitly checked per D-120's own suggested angles. Also
independently re-confirmed the native-token sentinel address
(0x000...000) is correct against LI.FI's own real token list -- not the bug.
Fix: request `denyExchanges=paraswap` from LI.FI's quote API. The
resulting route (feeCollection -> nordstern -> relaydepository)
estimates gas cleanly, repeatedly, across multiple fresh quotes and
amounts, on both a real fork and real live mainnet state.
Real, honest finding while re-verifying via fork: the underlying bug (and
the fix's own success) are BOTH non-deterministic -- they depend on
real-time DEX/pool liquidity state. A later run hit a different, entirely
legitimate revert ("Insufficient output", a real slippage guard, not a
bug) on a stargateV2-routed quote -- exactly the kind of live-market
outcome the script's own preflight check exists to catch before broadcast,
not a residual defect. Softened the fork test's own negative control from
a hard assertion to an informational, non-failing check accordingly --
forcing a deterministic pass/fail onto an inherently non-deterministic
real-world condition would be dishonest, not rigorous.
tsc --noEmit clean on all three gated configs. vitest run: 91 passed, 2
skipped, 0 failed. New fork-proof re-run clean: 2 passed.
…s as toToken, not native ETH (BION-DIRECTIVE-121) Forces' real run succeeded on both chains (Gnosis deposit and Base delivery both status: 0x1) but Step 4 reported "NOT YET DELIVERED" on a real success. Root cause: 0x4200...0006 is WETH9's real deployed CONTRACT address (the OP-stack predeploy) -- not a "give me native currency" sentinel -- so the script asked LI.FI for real wrapped WETH, which is exactly what got delivered (confirmed via balanceOf: 0.00223728 WETH, funds safe). Step 4 only polled native ETH balance, which never moved. Fix: toToken now requests the real native-ETH sentinel, confirmed live against LI.FI's own token list for Base -- the same zero address already correctly used for native xDAI on the Gnosis (fromToken) side, not 0xEeee...EEeE. A fresh quote with the corrected address shows action.toToken.symbol: "ETH" (not "WETH"), and estimateGas succeeds cleanly against real live state. Also hardened Step 4 as a real safety net, not just a one-line swap: watches BOTH native ETH and WETH balances now, reporting whichever real asset actually arrives -- Forces' own real run already proved the underlying route can deliver WETH even when native ETH is requested, so this script's job is to detect what really happened, not assume the request was honored. tsc --noEmit clean on all three gated configs. vitest run: 91 passed, 2 skipped, 0 failed. Fork-proof re-run clean: 2 passed (this run routed via yet another tool, "near" -- LI.FI's non-determinism keeps confirming itself is real and broad, not a one-off).
…onfig.cts fork-block pin + package.json script conflicts)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
deposit()->approve()->relayTokens(WXDAI, amount).Test plan
tsc --noEmitclean on all three gated configsvitest run: 91 passed, 2 skipped, 0 failedHeld for arc-end review, not merged.
🤖 Generated with Claude Code
https://claude.ai/code/session_01LoiqDXzQQeejwguqcQFzBL