-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
fix: multichainToken rate for non evm #5175
Open
salimtb
wants to merge
11
commits into
main
Choose a base branch
from
salim/solana-tokens-rate-controller-non-evm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+976
−0
Conversation
This file contains 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
salimtb
force-pushed
the
salim/solana-tokens-rate-controller-non-evm
branch
from
January 20, 2025 13:01
51c3893
to
ac5d0e4
Compare
salimtb
commented
Jan 20, 2025
packages/assets-controllers/src/RatesController/multichain-rates/util.ts
Outdated
Show resolved
Hide resolved
darkwing
reviewed
Jan 22, 2025
packages/assets-controllers/src/RatesController/multichain-rates/util.ts
Outdated
Show resolved
Hide resolved
salimtb
force-pushed
the
salim/solana-tokens-rate-controller-non-evm
branch
4 times, most recently
from
February 3, 2025 09:35
659ace0
to
b000312
Compare
salimtb
commented
Feb 3, 2025
} | ||
|
||
// Retrieve assets from the assets controller. | ||
const assets = await this.#getAssetsList( |
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.
TODO: Once merged, replace this function with a call to MultichainAssetsController
.getState to retrieve the list of assets by account.
salimtb
force-pushed
the
salim/solana-tokens-rate-controller-non-evm
branch
from
February 3, 2025 09:38
b000312
to
da502e6
Compare
salimtb
force-pushed
the
salim/solana-tokens-rate-controller-non-evm
branch
from
February 3, 2025 10:22
da502e6
to
46d8b64
Compare
aganglada
reviewed
Feb 3, 2025
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
aganglada
reviewed
Feb 3, 2025
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
aganglada
reviewed
Feb 3, 2025
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
aganglada
reviewed
Feb 3, 2025
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
GuillaumeRx
requested changes
Feb 3, 2025
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
GuillaumeRx
requested changes
Feb 3, 2025
packages/assets-controllers/src/MultichainTokensRatesController/types.ts
Outdated
Show resolved
Hide resolved
packages/assets-controllers/src/MultichainTokensRatesController/types.ts
Outdated
Show resolved
Hide resolved
GuillaumeRx
requested changes
Feb 3, 2025
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
aganglada
reviewed
Feb 3, 2025
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
GuillaumeRx
requested changes
Feb 3, 2025
packages/assets-controllers/src/MultichainTokensRatesController/constant.ts
Outdated
Show resolved
Hide resolved
GuillaumeRx
reviewed
Feb 4, 2025
...es/assets-controllers/src/MultichainTokensRatesController/MultichainTokensRatesController.ts
Outdated
Show resolved
Hide resolved
GuillaumeRx
requested changes
Feb 4, 2025
packages/assets-controllers/src/MultichainTokensRatesController/types.ts
Outdated
Show resolved
Hide resolved
salimtb
force-pushed
the
salim/solana-tokens-rate-controller-non-evm
branch
from
February 5, 2025 21:37
9747ebd
to
4165b5e
Compare
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.
Explanation
This pull request introduces the
MultiChainTokensRatesController
, a new controller that manages multi‑chain token conversion rates within MetaMask. Its primary goal is to periodically poll for updated conversion rates of tokens associated with non‑EVM accounts (those using Snap metadata), ensuring that the conversion data remains up‑to‑date across supported chains.Key changes and features include:
Polling Mechanism:
The controller extends
StaticIntervalPollingController
to run periodic polls (default interval of 3 min). During each poll, it triggers an update of token conversion rates for the currently selected account if it is active (i.e. if the keyring is unlocked).State Management & Mutex Locking:
The controller stores conversion rates in its state (
conversionRates
), which is updated atomically using a mutex (fromasync-mutex
) to prevent race conditions during concurrent updates.Event Subscriptions:
KeyringController:lock
andKeyringController:unlock
events to track if the keyring is active.AccountsController:selectedAccountChange
to update the current account and trigger a conversion rate update, and toAccountsController:accountRemoved
to clean up any state associated with a removed account.Account Filtering:
The controller retrieves all multichain accounts from the AccountsController and filters out non‑EVM accounts that have Snap metadata. Currently, only accounts of type
'solana:data-account'
are supported for conversion updates, with a TODO note indicating future Snap support enhancements.Integration with Snap:
Conversion updates involve sending a Snap request using a helper method (
#handleSnapRequest
) to the SnapController. It builds a list of asset conversion pairs (from asset to USD via the Swift ISO4217 code) and then updates its state with the returned conversion rates.Keyring Client Support:
A dedicated helper (
#getClient
) instantiates aKeyringClient
to route keyring-related JSON-RPC requests through the SnapController, ensuring a consistent integration with MetaMask’s underlying snap infrastructure.Type Safety & Messaging:
Comprehensive TypeScript types are provided for controller state, actions, events, and the messenger interface. This guarantees that interactions with other controllers (such as the AccountsController, KeyringController, and Snaps-related modules) are type‑safe and well‑documented.
Overall, this controller enhances the MetaMask architecture by adding robust support for multi‑chain tokens, ensuring that users with non‑EVM accounts receive updated conversion rate information in a timely and thread‑safe manner.
References
Changelog
@metamask/multi-chain-tokens-rates-controller
MultiChainTokensRatesController
to manage and update token conversion rates for non‑EVM accounts with Snap metadata.Checklist
Feel free to adjust any section to better match the specifics of your implementation and project requirements.