Skip to content

fix: check for all native assetIds in isNativeAddress util #6076

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
merged 9 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/bridge-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Include EVM assetIds in `isNativeAddress` util when checking whether an address string is a native token ([#6076](https://github.com/MetaMask/core/pull/6076))

## [36.0.0]

### Changed
Expand Down
9 changes: 5 additions & 4 deletions packages/bridge-controller/src/utils/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,11 @@ export const isNativeAddress = (address?: string | null) =>
address === AddressZero || // bridge and swap apis set the native asset address to zero
address === '' || // assets controllers set the native asset address to an empty string
!address ||
address.endsWith('11111111111111111111111111111111') || // token-api and bridge-api use this as the solana native assetId
[getNativeAssetForChainId(ChainId.SOLANA).assetId].some(
(assetId) => assetId.includes(address) && !isStrictHexString(address),
); // solana native assetId used in the extension client
(!isStrictHexString(address) &&
Object.values(SYMBOL_TO_SLIP44_MAP).some(
// check if it matches any supported SLIP44 references
(reference) => address.includes(reference) || reference.endsWith(address),
));

/**
* Checks whether the chainId matches Solana in CaipChainId or number format
Expand Down
20 changes: 16 additions & 4 deletions packages/bridge-controller/src/utils/caip-formatters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,25 @@ describe('CAIP Formatters', () => {
});

it('should return native asset for chainId when address is Solana native asset', () => {
const result = formatAddressToAssetId(
'11111111111111111111111111111111',
SolScope.Mainnet,
);
const result = formatAddressToAssetId('501', SolScope.Mainnet);
expect(result).toBe('solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp/slip44:501');
});

it('should return native asset for chainId when address is BSC native asset', () => {
const result = formatAddressToAssetId('714', '0x38');
expect(result).toBe('eip155:56/slip44:714');
});

it('should return native asset for chainId when address is BSC native assetId', () => {
const result = formatAddressToAssetId('slip44:714', 56);
expect(result).toBe('eip155:56/slip44:714');
});

it('should return native asset for chainId=BSC when address is zero address', () => {
const result = formatAddressToAssetId(AddressZero, 56);
expect(result).toBe('eip155:56/slip44:714');
});

it('should create Solana token asset type when chainId is Solana', () => {
const tokenAddress = '7dHbWXmci3dT8UF5YZ5ppK9w4ppCH654F4H1Fp16m6Fn';
const expectedAssetType = `${SolScope.Mainnet}/token:${tokenAddress}`;
Expand Down
Loading