Skip to content

feat(defi): source ERC20 total-supply from Alchemy RPC - #1453

Merged
tieubao merged 1 commit into
developfrom
feat/alchemy-token-supply
Jul 8, 2026
Merged

feat(defi): source ERC20 total-supply from Alchemy RPC#1453
tieubao merged 1 commit into
developfrom
feat/alchemy-token-supply

Conversation

@tieubao

@tieubao tieubao commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Consolidation follow-up. Moves getTokenTotalSupply (defi.go) off the Etherscan client onto Alchemy JSON-RPC eth_call of totalSupply() (0x18160ddd), via a new svc.Alchemy.GetTokenTotalSupply(network, contract).

  • Response shape/units identical (raw big.Int ÷ 10^decimals). Unsupported platform → 0 (same graceful degrade as before). eth-only today (matches the chains table; no base/ronin row).
  • Verify: build/vet green; 5 new alchemy unit tests (happy/invalid-addr/unsupported-chain/solana/provider-down); live probe USDC eth-mainnet → ~50.7B (correct order, 6 decimals).
  • ETHEREUM_SCAN_API_KEY is NOT retired yet: pkg/chain.erc20TokenBalance (chain.go:285, wallet balance checks) still uses the etherscan client (and reads its key from the DB chains.api_key column, not this env var). Only the supply path is migrated here; full retirement needs a separate follow-up on the balance path.

CI gitleaks/CI-testing baseline-broken (see #1438); 2 reproducible entities baseline fails, unrelated.

🤖 Generated with Claude Code

Add Service.GetTokenTotalSupply(network, contract) to pkg/service/alchemy,
implemented via eth_call to the totalSupply() selector (0x18160ddd) on the
per-network Alchemy JSON-RPC endpoint, returning the raw big.Int (unscaled
by decimals). Rewires entities.getTokenTotalSupply's EVM branch to call it
instead of the pkg/chain etherscan-api client, dropping the
repo.Chain.GetOne + dcwallet.Chain lookup entirely from that path.

Only "ethereum" maps to an Alchemy network today (no base/ronin row exists
in the `chains` table per a migration audit), matching current production
behavior. pkg/chain and its etherscan client are left in place since
erc20TokenBalance still depends on ch.scan; ETHEREUM_SCAN_API_KEY stays in
config.go pending a separate Vault-removal step.

Covered by a hermetic eth_call fixture test plus a provider-down negative
control, and verified live against USDC's real total supply on eth-mainnet.
@tieubao
tieubao merged commit 43a5960 into develop Jul 8, 2026
4 of 5 checks passed
@tieubao
tieubao deleted the feat/alchemy-token-supply branch July 8, 2026 20:05
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