-
-
Notifications
You must be signed in to change notification settings - Fork 242
perf!: Use single call to update native balances when enabled #6099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -38,22 +44,25 @@ import { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from './assetsUtil'; | |||
const controllerName = 'AccountTrackerController'; | |||
|
|||
/** | |||
* @type AccountInformation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran lint:fix
and modified a bunch of JSDocs like this, feel free to revert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Single-Call Balance Fetch Fails Without Fallback
The new single-call contract logic for fetching native account balances lacks error handling. If the contract.balances()
call fails (e.g., due to network issues, contract problems, or an individual address causing a revert), the entire balance refresh operation for that chain will fail. This reduces resilience compared to the previous implementation, which handled individual failures gracefully. The single-call logic should fall back to the individual query method on failure.
packages/assets-controllers/src/AccountTrackerController.ts#L376-L396
core/packages/assets-controllers/src/AccountTrackerController.ts
Lines 376 to 396 in 40c118c
if (hasProperty(SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID, chainId)) { | |
const contractAddress = SINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID[ | |
chainId | |
] as string; | |
const contract = new Contract( | |
contractAddress, | |
abiSingleCallBalancesContract, | |
new Web3Provider(provider), | |
); | |
const nativeBalances = await contract.balances(accountsToUpdate, [ | |
'0x0000000000000000000000000000000000000000', | |
]); | |
accountsToUpdate.forEach((address, index) => { | |
accountsForChain[address] = { | |
balance: (nativeBalances[index] as BigNumber).toHexString(), | |
}; | |
}); |
Was this report helpful? Give feedback by reacting with 👍 or 👎
Explanation
This PR modifies
AccountTrackerController.refresh
to use the contract fromSINGLE_CALL_BALANCES_ADDRESS_BY_CHAINID
used in other asset controllers when available. This reduces the amount of fetch calls made to update native balances drastically. If the contract is not available, we fall back to the previous behaviour.Additionally this PR refactors
getStakedBalanceForChain
to take multiple addresses and use multicall to fetch staked balances. This also drastically reduces the number of fetch calls used, but is a breaking change since the parameters and return value has changed forgetStakedBalanceForChain
.References
Checklist