-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: read stablecoins from stable-tokens LD flag in useTokenFiatRates cp-8.3.0 #33251
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
Merged
+222
−123
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
459a2e5
feat: read stablecoins from stable-tokens LD flag in useTokenFiatRates
jpuri 4541783
refactor: replace isStablecoin with isRouteToken from relayFixedSpread
jpuri e79595e
chore: register stable-tokens in feature flag registry
jpuri 63797f3
test: add unit tests for selectStablecoins selector
jpuri 4bb0fbc
fix: use Json type in stableTokens test mock to satisfy FeatureFlags …
jpuri e691927
update @metamask/transaction-pay-controller
jpuri 2ea5442
yarn lock fix
OGPoyraz dec93b9
Fix lint
OGPoyraz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,111 +1,84 @@ | ||
| import { CHAIN_IDS } from '@metamask/transaction-controller'; | ||
| import { Hex } from '@metamask/utils'; | ||
| import { isStablecoin } from './token'; | ||
| import { RelayFixedSpreadConfig } from './relayFixedSpread'; | ||
| import { isRouteToken, RelayFixedSpreadConfig } from './relayFixedSpread'; | ||
|
|
||
| const MOCK_CONFIG: RelayFixedSpreadConfig = { | ||
| routes: [ | ||
| { | ||
| sourceChain: CHAIN_IDS.MAINNET as Hex, | ||
| sourceToken: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' as Hex, // USDC | ||
| sourceToken: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' as Hex, | ||
| targetChain: CHAIN_IDS.MAINNET as Hex, | ||
| targetToken: '0xdac17f958d2ee523a2206206994597c13d831ec7' as Hex, // USDT | ||
| targetToken: '0xdac17f958d2ee523a2206206994597c13d831ec7' as Hex, | ||
| }, | ||
| { | ||
| sourceChain: CHAIN_IDS.BSC as Hex, | ||
| sourceToken: '0x55d398326f99059ff775485246999027b3197955' as Hex, // USDT | ||
| sourceToken: '0x55d398326f99059ff775485246999027b3197955' as Hex, | ||
| targetChain: CHAIN_IDS.BSC as Hex, | ||
| targetToken: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d' as Hex, // USDC | ||
| targetToken: '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d' as Hex, | ||
| }, | ||
| { | ||
| sourceChain: CHAIN_IDS.LINEA_MAINNET as Hex, | ||
| sourceToken: '0x176211869ca2b568f2a7d4ee941e073a821ee1ff' as Hex, // USDC | ||
| sourceToken: '0x176211869ca2b568f2a7d4ee941e073a821ee1ff' as Hex, | ||
| targetChain: CHAIN_IDS.LINEA_MAINNET as Hex, | ||
| targetToken: '0xa219439258ca9da29e9cc4ce5596924745e12b93' as Hex, // USDT | ||
| targetToken: '0xa219439258ca9da29e9cc4ce5596924745e12b93' as Hex, | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| const EMPTY_CONFIG: RelayFixedSpreadConfig = { routes: [] }; | ||
|
|
||
| describe('isStablecoin', () => { | ||
| it('returns true for USDC on Ethereum (0x1)', () => { | ||
| describe('isRouteToken', () => { | ||
| it('returns true for a source token', () => { | ||
| expect( | ||
| isStablecoin( | ||
| '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', | ||
| CHAIN_IDS.MAINNET as Hex, | ||
| MOCK_CONFIG, | ||
| ), | ||
| isRouteToken(MOCK_CONFIG, { | ||
| chainId: CHAIN_IDS.MAINNET, | ||
| address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for USDT on BSC (0x38)', () => { | ||
| it('returns true for a target token', () => { | ||
| expect( | ||
| isStablecoin( | ||
| '0x55d398326f99059ff775485246999027b3197955', | ||
| CHAIN_IDS.BSC as Hex, | ||
| MOCK_CONFIG, | ||
| ), | ||
| isRouteToken(MOCK_CONFIG, { | ||
| chainId: CHAIN_IDS.MAINNET, | ||
| address: '0xdac17f958d2ee523a2206206994597c13d831ec7', | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true for a target token in a route', () => { | ||
| it('returns false for unknown address', () => { | ||
| expect( | ||
| isStablecoin( | ||
| '0xdac17f958d2ee523a2206206994597c13d831ec7', | ||
| CHAIN_IDS.MAINNET as Hex, | ||
| MOCK_CONFIG, | ||
| ), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for non-stablecoin address', () => { | ||
| expect( | ||
| isStablecoin( | ||
| '0x0000000000000000000000000000000000000001', | ||
| CHAIN_IDS.MAINNET as Hex, | ||
| MOCK_CONFIG, | ||
| ), | ||
| isRouteToken(MOCK_CONFIG, { | ||
| chainId: CHAIN_IDS.MAINNET, | ||
| address: '0x0000000000000000000000000000000000000001', | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false for unknown chainId', () => { | ||
| expect( | ||
| isStablecoin( | ||
| '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', | ||
| '0xfffff' as Hex, | ||
| MOCK_CONFIG, | ||
| ), | ||
| isRouteToken(MOCK_CONFIG, { | ||
| chainId: '0xfffff', | ||
| address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false with empty config', () => { | ||
| expect( | ||
| isStablecoin( | ||
| '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', | ||
| CHAIN_IDS.MAINNET as Hex, | ||
| EMPTY_CONFIG, | ||
| ), | ||
| isRouteToken(EMPTY_CONFIG, { | ||
| chainId: CHAIN_IDS.MAINNET, | ||
| address: '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', | ||
| }), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it('handles case-insensitive addresses (uppercase input)', () => { | ||
| expect( | ||
| isStablecoin( | ||
| '0xA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48', | ||
| CHAIN_IDS.MAINNET as Hex, | ||
| MOCK_CONFIG, | ||
| ), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it('matches lowercase route tokens against lowercase input', () => { | ||
| it('handles case-insensitive addresses', () => { | ||
| expect( | ||
| isStablecoin( | ||
| '0x176211869ca2b568f2a7d4ee941e073a821ee1ff', | ||
| CHAIN_IDS.LINEA_MAINNET as Hex, | ||
| MOCK_CONFIG, | ||
| ), | ||
| isRouteToken(MOCK_CONFIG, { | ||
| chainId: CHAIN_IDS.MAINNET, | ||
| address: '0xA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48', | ||
| }), | ||
| ).toBe(true); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.