Skip to content

Commit 07db0f4

Browse files
authored
fix: check for all native assetIds in isNativeAddress util (#6076)
## Explanation This change updates the isNativeAddress` util so that it returns `true` when the address is a native EVM assetId <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> Related to https://consensyssoftware.atlassian.net/browse/SWAPS-2601 ## Changelog <!-- THIS SECTION IS NO LONGER NEEDED. The process for updating changelogs has changed. Please consult the "Updating changelogs" section of the Contributing doc for more. --> ## Checklist - [ ] I've updated the test suite for new or updated code as appropriate - [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [ ] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs), highlighting breaking changes as necessary - [ ] I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes
1 parent 7154771 commit 07db0f4

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

packages/bridge-controller/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Include EVM assetIds in `isNativeAddress` util when checking whether an address string is a native token ([#6076](https://github.com/MetaMask/core/pull/6076))
13+
1014
## [36.0.0]
1115

1216
### Changed

packages/bridge-controller/src/utils/bridge.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ export const isNativeAddress = (address?: string | null) =>
160160
address === AddressZero || // bridge and swap apis set the native asset address to zero
161161
address === '' || // assets controllers set the native asset address to an empty string
162162
!address ||
163-
address.endsWith('11111111111111111111111111111111') || // token-api and bridge-api use this as the solana native assetId
164-
[getNativeAssetForChainId(ChainId.SOLANA).assetId].some(
165-
(assetId) => assetId.includes(address) && !isStrictHexString(address),
166-
); // solana native assetId used in the extension client
163+
(!isStrictHexString(address) &&
164+
Object.values(SYMBOL_TO_SLIP44_MAP).some(
165+
// check if it matches any supported SLIP44 references
166+
(reference) => address.includes(reference) || reference.endsWith(address),
167+
));
167168

168169
/**
169170
* Checks whether the chainId matches Solana in CaipChainId or number format

packages/bridge-controller/src/utils/caip-formatters.test.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,25 @@ describe('CAIP Formatters', () => {
127127
});
128128

129129
it('should return native asset for chainId when address is Solana native asset', () => {
130-
const result = formatAddressToAssetId(
131-
'11111111111111111111111111111111',
132-
SolScope.Mainnet,
133-
);
130+
const result = formatAddressToAssetId('501', SolScope.Mainnet);
134131
expect(result).toBe('solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501');
135132
});
136133

134+
it('should return native asset for chainId when address is BSC native asset', () => {
135+
const result = formatAddressToAssetId('714', '0x38');
136+
expect(result).toBe('eip155:56/slip44:714');
137+
});
138+
139+
it('should return native asset for chainId when address is BSC native assetId', () => {
140+
const result = formatAddressToAssetId('slip44:714', 56);
141+
expect(result).toBe('eip155:56/slip44:714');
142+
});
143+
144+
it('should return native asset for chainId=BSC when address is zero address', () => {
145+
const result = formatAddressToAssetId(AddressZero, 56);
146+
expect(result).toBe('eip155:56/slip44:714');
147+
});
148+
137149
it('should create Solana token asset type when chainId is Solana', () => {
138150
const tokenAddress = '7dHbWXmci3dT8UF5YZ5ppK9w4ppCH654F4H1Fp16m6Fn';
139151
const expectedAssetType = `${SolScope.Mainnet}/token:${tokenAddress}`;

0 commit comments

Comments
 (0)