feat: MUSD-943 money-account-balance-service optimizations#9100
Conversation
…erlying token address from remote config; increased default staletime for on-chain reads to 60 seconds
|
@metamaskbot publish-previews |
|
Preview builds have been published. Learn how to use preview builds in other projects. Expand for full list of packages and versions. |
Jwhiles
left a comment
There was a problem hiding this comment.
Suggested a couple of minor tweaks - but generally happy to merge
| * is stored in `RemoteFeatureFlagController` state's `remoteFeatureFlags` map. | ||
| * Falls back to {@link DEFAULT_BALANCE_STALE_TIME} when absent or malformed. | ||
| */ | ||
| export const MONEY_ACCOUNT_BALANCE_STALETIME_FEATURE_FLAG_KEY = |
There was a problem hiding this comment.
I'm not sure it makes sense to store the feature flags in the core library. To me it feels more like a client concern, and in general most of feature flags seem to be defined in the clients - so defining some of them in core seems to make the situation more confusing.
I understand that VAULT_CONFIG_FEATURE_FLAG_KEY is already defined in this package, so I’m happy to approve - but IMO we should move away from this pattern
There was a problem hiding this comment.
Also, the changelog says it's moneyAccountBalanceStaleTime - note the capital T. Would be good to get them matching ;)
There was a problem hiding this comment.
Good catch. I've fixed the typo in the changelog!
As discussed, we'll open a separate PR if we decide to move feature flags to the client.
| }; | ||
| } | ||
|
|
||
| function mockMoneyAccountBalanceMulticall({ |
There was a problem hiding this comment.
This mocks out basically everything in getMoneyAccountBalance - and I think it takes away a bit of the value of the test.
For example, I think it would be nice to have at least one test actually exercise the decode/encode paths - cos at the moment we only know they work from manual testing.
8f1bdd7 to
d6a3b01
Compare
Explanation
The Money account balance service currently makes multiple sequential RPC calls to fetch a user's Money account balance (mUSD wallet balance + vault share value).
This PR addresses both issues:
Multicall batching: A new
getMoneyAccountBalancemethod fetches the mUSD wallet balance and the vmUSD (Veda vault tokens) in a single multicall. Previously, we needed 3 RPC calls each time we fetched the balance (getUnderlyingToken, getMusdBalance, getVmusdBalance).Configurable stale time: The balance cache
staleTimeis now driven by a remote feature flag (moneyAccountBalanceStaletime). The default balancestaleTimewas bumped from 30s to 60s.Underlying token from config: The vault config now accepts an optional
underlyingTokenaddress. When present, the service uses it directly instead of making an extraAccountant.base()on-chain read on every mUSD balance fetch. Falls back to the on-chain read when absent (backwards compatible with existing flag payloads).Rename mUSDSHFvd → vmUSD: The vault share token is called vmUSD everywhere else, so the public API now reflects that (
getMusdSHFvdBalance→getVmusdBalance, etc.). This is a breaking change.References
Checklist
Note
Medium Risk
Breaking public API renames require consumer updates; balance and vault config changes affect on-chain reads and caching behavior, though defaults and fallbacks limit rollout risk.
Overview
Adds
getMoneyAccountBalance, which batches mUSDbalanceOfand LensbalanceOfInAssetsin one Multicall3aggregate3call and returnsmusdBalance,vmusdValueInMusd, andtotalBalance.Breaking: Renames the vault-share API from
musdSHFvd/getMusdSHFvdBalanceto vmUSD /getVmusdBalance(including messenger action types).Vault config may include optional
underlyingTokenso mUSD reads skipAccountant.base()when set; behavior stays backward compatible when omitted.On-chain balance cache
staleTimedefaults to 60s (was 30s) and can be overridden at runtime via themoneyAccountBalanceStaletimeremote feature flag (init+RemoteFeatureFlagController:stateChange, with validation and fallback).Reviewed by Cursor Bugbot for commit d6a3b01. Bugbot is set up for automated code reviews on this repo. Configure here.