feat(defi): source ERC20 total-supply from Alchemy RPC - #1453
Merged
Conversation
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.
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.
Consolidation follow-up. Moves
getTokenTotalSupply(defi.go) off the Etherscan client onto Alchemy JSON-RPCeth_calloftotalSupply()(0x18160ddd), via a newsvc.Alchemy.GetTokenTotalSupply(network, contract).chainstable; no base/ronin row).pkg/chain.erc20TokenBalance(chain.go:285, wallet balance checks) still uses the etherscan client (and reads its key from the DBchains.api_keycolumn, 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