feat(transaction): add useWalletRisk hook#2640
Open
lau90eth wants to merge 1 commit into
Open
Conversation
Adds wallet risk analysis to prevent sending funds to suspicious addresses. - useWalletRisk hook: analyzes wallet history, detects risk signals - getWalletRisk utility: Basescan API integration for tx history analysis - Detects: new wallet, never received, low activity, smart contract - Risk scoring: high for new/unused wallets, medium for contracts - 5 tests covering: empty state, new wallet, active wallet, contract, API error Refs: coinbase#2572
|
@lau90eth is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
🟡 Heimdall Review Status
|
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
Every day users send funds to wrong addresses, new wallets, or scam
accounts. One typo = lost forever. OnchainKit has zero wallet
verification before sending.
This PR adds
useWalletRisk, a hook that analyzes the destinationwallet before the user clicks "Send" — flagging new wallets,
contracts, and suspicious patterns.
What changed
useWalletRiskhook — analyzes a destination wallet addressand returns risk level, flags, contract status, and transaction
history summary
getWalletRiskutility — Basescan API integration that readstransaction history, detects new/unused wallets, and checks if
address is a smart contract
WalletRisktype — standardized shape including risk level,flags array, isContract, txCount, and date ranges
src/transaction/index.tsUsage
API
Risk scoring
highnew_wallethighnever_receivedmediumsmart_contractmediumlow_activitylowConservative by design: new wallet = high risk by default.
Better to warn unnecessarily than miss a real risk.
Notes to reviewers
txlistAPI — same pattern asuseContractVerification.If
apiKeyis present inOnchainKitProvider, passed for higherrate limits. Works without key for low-volume usage.
isContractcheck via Basescangetabiendpoint — distinguishesEOA from smart contract without additional RPC call.
useContractVerification— one analyzes destinationcontracts, the other destination wallets. Together they cover the
full security surface before sending.
{ risk: 'low', flags: [] }when no address provided —zero impact on existing flows.
Testing
useWalletRisk.test.ts— 5 testsgetWalletRisk.test.ts— utility unit testsTest cases covered:
risk: 'low',flags: [], no fetchrisk: 'high',flags: ['new_wallet']risk: 'low', txCount populatedrisk: 'medium',isContract: trueRisk
Low. Read-only hook. Basescan calls are GET requests with
zero side effects.
Returns default safe state
{ risk: 'low', flags: [] }whenno address is provided.
Does not modify any existing transaction, wallet, or API logic.