Skip to content

Feat/migrate wallet library - #300

Merged
brunomenezes merged 10 commits into
mainfrom
feat/migrate-wallet-library
Oct 20, 2026
Merged

brunomenezes merged 10 commits into
mainfrom
feat/migrate-wallet-library

Conversation

@brunomenezes

Copy link
Copy Markdown
Member

Summary

@web3-onboard/* has had no release since Dec 2024 and nobody ships fixes for it. Also, ethers v5 is a legacy branch that carries the unpatchable elliptic advisory; eth-chains serves 2023 chain data; eth-rpc-errors was renamed upstream.

One migration closes all four audit findings. No user-facing changes beyond the connect modal, which is now RainbowKit's.

Changes:

Wallet layer — src/components/wallet/ is the only place that imports RainbowKit and wagmi; the rest of the app keeps consuming useWallet(), which now exposes viem clients instead of an ethers provider.

connect button → RainbowKit modal → wagmi connector → useWallet() → services (viem)

Wallets: MetaMask, WalletConnect (Ledger Live, Rainbow, Trust), Base and Safe, which connects automatically when the explorer is opened as a Safe App.

Contracts on viem — ABIs and deployment addresses are generated from the @cartesi contract packages by @wagmi/cli into a gitignored file:

pnpm codegen = run-p chakra-types gen:abi → src/services/contracts/generated.ts → useContract() → read.* / write.*

dev, build and both CI workflows run codegen first. Writes are simulated before signing, so a revert surfaces with the contract's reason before the wallet opens, as the previous gas estimation did. ethers and @cartesi/* become devDependencies used only by the generator. I added an ESLint rules rejects importing them from src/.

Numbers — BigNumber → bigint; FixedNumber divisions (rates, shares, percentages) → ratio() in src/utils/bigint.ts. Characterization tests captured from the ethers implementation pin the reward and pool-balance maths.

Server ENS — avatar lookups go through viem's universal resolver (one eth_call); benchmarked at ~70 ms vs ~320 ms for the ethers path on the same RPC, identical results.

Package Change
@rainbow-me/rainbowkit, wagmi, viem, @tanstack/react-query, @wagmi/cli added
@web3-onboard/* (7), eth-chains, eth-rpc-errors, @ethersproject/*, direct @safe-global/* removed
ethers, @cartesi/* moved to devDependencies

Notable finding

RainbowKit 2 pins wagmi to the 2.x line, which froze when wagmi 3 shipped (Nov 2025), so the bundled WalletConnect and MetaMask SDK versions move only when RainbowKit adds wagmi 3 support. Accepted trade-off; overrides in pnpm-workspace.yaml pin the patched minors of the transitive advisories that tree brings (ws, h3, picomatch, preact, defu, bn.js, uuid, form-data, decode-uri-component) and qr to ~0.5.5, which cuer@0.0.3 (pinned by RainbowKit) needs until RainbowKit ships cuer@0.0.4.

Notes

  • next.config.js externalises @coinbase/cdp-sdk on the server: it imports optional @x402/* peers that Turbopack otherwise tries to resolve.
  • Contract<T> in src/services/contracts/index.ts spells out the ABI-typed read/write surface because viem's GetContractReturnType only resolves under strictNullChecks, which this project does not enable.
  • src/services/contracts/localhost.json stays: it is the only source of the chain-31337 addresses for the generator.
  • Manual QA done on Sepolia: MetaMask connect/reconnect, unsupported network, WalletConnect to Ledger Live (icon shown), stake, withdraw revert reason, pool creation, ENS cron route. Pending on a preview deployment: Safe App auto-connect and the mobile wallet list. The preview must run on a domain allow-listed in the WalletConnect (Reown) project, otherwise the relay and explorer APIs answer 401/403, and Vercel deployment protection must be off for the Safe iframe to load it.

@brunomenezes brunomenezes self-assigned this Oct 20, 2026
@brunomenezes brunomenezes added staking Changes targeted to the Staking platform type:chore It is not a new feature or bug fix. e.g. update dependencies, change repository configurations labels Oct 20, 2026
@vercel

vercel Bot commented Oct 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
staking Ready Ready Preview Oct 20, 2026 10:41am UTC

Request Review

@brunomenezes
brunomenezes requested a review from tuler October 20, 2026 10:41
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​wagmi/​cli@​2.10.0771007789100
Addedwagmi@​2.19.51001007891100
Added@​rainbow-me/​rainbowkit@​2.2.11961009187100
Added@​tanstack/​react-query@​5.104.0991009198100
Updatedviem@​2.22.8 ⏵ 2.57.297 +1310010098 +1100

View full report

@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 39409688171

Coverage increased (+2.2%) to 68.596%

Details

  • Coverage increased (+2.2%) from the base build.
  • Patch coverage: 65 uncovered changes across 21 files (335 of 400 lines covered, 83.75%).
  • 7 coverage regressions across 6 files.

Uncovered Changes

Top 10 Files by Coverage Impact Changed Covered %
src/services/contracts/index.ts 32 16 50.0%
src/components/wallet/config.ts 13 0 0.0%
src/components/Web3Container.tsx 6 0 0.0%
src/services/contracts/pool.ts 17 13 76.47%
src/components/node/NodeManage.tsx 3 0 0.0%
src/components/node/modals/NodeStakeModal.tsx 3 0 0.0%
src/components/node/modals/NodeUnstakeModal.tsx 3 0 0.0%
src/components/header/menu/WalletMenu.tsx 2 0 0.0%
src/graphql/hooks/useNodes.ts 2 0 0.0%
src/services/pool.ts 54 52 96.3%
Total (59 files) 400 335 83.75%

Coverage Regressions

7 previously-covered lines in 6 files lost coverage.

File Lines Losing Coverage Coverage
src/services/node.ts 2 91.21%
src/components/BigNumberText.tsx 1 63.04%
src/components/CTSIText.tsx 1 61.7%
src/components/node/NodeManage.tsx 1 0.0%
src/components/Web3Container.tsx 1 0.0%
src/services/contracts/index.ts 1 49.09%

Coverage Stats

Coverage Status
Relevant Lines: 3727
Covered Lines: 2676
Line Coverage: 71.8%
Relevant Branches: 1957
Covered Branches: 1223
Branch Coverage: 62.49%
Branches in Coverage %: Yes
Coverage Strength: 29.91 hits per line

💛 - Coveralls

@brunomenezes
brunomenezes merged commit 726d6d6 into main Oct 20, 2026
8 of 9 checks passed
@brunomenezes
brunomenezes deleted the feat/migrate-wallet-library branch October 20, 2026 13:39

This branch was successfully deployed

1 active deployment
Preview — 64186476 Deployed Oct 19, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

staking Changes targeted to the Staking platform type:chore It is not a new feature or bug fix. e.g. update dependencies, change repository configurations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants