Skip to content

Feat/sushi gnosis solution#130

Merged
0xCardiE merged 7 commits into
mainfrom
feat/sushi_gnosis
Apr 8, 2026
Merged

Feat/sushi gnosis solution#130
0xCardiE merged 7 commits into
mainfrom
feat/sushi_gnosis

Conversation

@0xCardiE
Copy link
Copy Markdown
Collaborator

@0xCardiE 0xCardiE commented Apr 7, 2026

Replaced the Relay bridge path for Gnosis-native swaps with a direct SushiSwap V3 integration. A new Solidity smart contract (SushiSwapStampsRouter) was written and deployed on Gnosis — it accepts any ERC-20 token (or native xDAI), swaps it to BZZ via SushiSwap V3, and atomically creates or tops up a Swarm postage stamp batch in a single transaction.

0xCardiE added 7 commits April 7, 2026 20:22
Add SushiSwapStampsRouter contract that swaps any Gnosis token → BZZ
via SushiSwap V3 and atomically creates/tops up a Swarm stamp batch in
a single transaction. Eliminates Relay dependency for same-chain swaps.

- contracts/SushiSwapStampsRouter.sol: new router with single-hop,
  multi-hop (callback chaining), native xDAI support, and quote
  functions callable via eth_call
- deploy/02_deploy_sushi_stamps_router.ts: deploy + auto-verify script
  (GnosisScan + Sourcify v2)
- scripts/verify_router.ts, verify_registry.ts: standalone post-deploy
  verification scripts for both contracts
- SushiQuotes.ts: frontend module for route discovery, quoting, and
  execution via the new router
- constants.ts: add SUSHI_STAMPS_ROUTER_ADDRESS, SUSHI_FACTORY_ABI,
  SUSHI_STAMPS_ROUTER_ABI, GNOSIS_USDC_ADDRESS
- SwapComponent.tsx: add Branch 2 (Gnosis + non-BZZ → SushiSwap);
  cross-chain traffic stays on Relay unchanged
- hardhat.config.ts: enable viaIR and Sourcify v2 verification
The BZZ/USDC pool fee was hardcoded as 10000 (1%) which caused
quoteSingleHop to revert because the Quoter looks up the pool via
factory.getPool(tokenIn, BZZ, fee) — wrong fee = pool not found.

- Read pool.fee() directly from the known pool address at runtime
- Keep the pool address constant (BZZ_USDC_POOL_ADDRESS) but never
  assume the fee tier
- Fall back to factory scan if the known address doesn't respond
- Reorder FEE_TIERS to try 3000/500 before 10000 (more common tiers first)
- Fix fee display: divide by 10000 not 100 (10000 bps = 1%, not 100%)
Two bugs in findSushiRoute broke non-BZZ Gnosis token routing:

1. ReferenceError: KNOWN_BZZ_POOLS reference was missed when renaming
   to bzzPoolCache in the previous commit — crashed immediately for
   any two-hop route (e.g. GBPe).

2. Case 3 (tokenIn → WXDAI → BZZ) used findWxdaiUsdcPool() for the
   tokenIn→WXDAI leg, which looked up a WXDAI/USDC pool instead of
   a tokenIn/WXDAI pool — completely wrong fee and path for any token
   that isn't USDC.

- Replace findWxdaiUsdcPool() with generic findPoolBetween(tokenA, tokenB)
  that scans all fee tiers for any pair, with pair-keyed caching
- Case 2: use findPoolBetween(tokenIn, USDC) + findDirectBzzPool(USDC)
  in parallel — both legs discovered correctly
- Case 3: use findPoolBetween(tokenIn, WXDAI) + findDirectBzzPool(WXDAI)
  in parallel — both legs discovered correctly
- Tokens like GBPe that route through WXDAI or USDC now work properly
The project tsconfig.json uses moduleResolution: bundler (Next.js),
which ts-node can't handle, causing all `hardhat run scripts/*.ts`
commands to fail with ERR_UNKNOWN_FILE_EXTENSION on Node 22.

- Add tsconfig.hardhat.json with module: CommonJS / moduleResolution: node
  scoped to deploy/ and scripts/ only, leaving the Next.js tsconfig untouched
- Set ts-node.project in package.json to point at the new tsconfig
- Add npm scripts (verify:router, verify:registry, deploy:router) that
  set TS_NODE_PROJECT=tsconfig.hardhat.json automatically so plain
  `npm run verify:router` just works
- Update script usage comments to show both the npm shortcut and the
  direct command with the required env var
- Filter Gnosis "from" tokens with findSushiRoute after LiFi balances; clear
  selection when nothing spendable remains.
- Require V3 pool liquidity() > 0 in discovery so empty pools (e.g. COW/USDC)
  are not treated as routable; Quoter no longer reverts on those paths.
- Add findSushiRoutes and try each candidate in getSushiQuote until a quote
  succeeds.
- Export gnosisFromTokenCanReachBzz (BZZ direct or Sushi path to BZZ).
@0xCardiE 0xCardiE merged commit 55b5d29 into main Apr 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant