@@ -6,7 +6,7 @@ import { bnOrZero, isToken } from '@shapeshiftoss/utils'
66import type { TransactionInstruction } from '@solana/web3.js'
77import { zeroAddress } from 'viem'
88
9- import type { GetExecutionStatusResponse } from '../../types'
9+ import type { GetExecutionStatusResponse , TokenResponse } from '../../types'
1010import { chainIdToNearIntentsChain } from '../../types'
1111import { OneClickService } from '../oneClickService'
1212
@@ -39,6 +39,8 @@ export const getNearIntentsAsset = ({
3939 return `nep141:${ nearNetwork } -${ contractAddress . toLowerCase ( ) } .omft.near`
4040}
4141
42+ const NEP245_CHAINS = [ 'bsc' , 'pol' , 'avax' , 'op' ] as const
43+
4244export const assetToNearIntentsAsset = async ( asset : Asset ) : Promise < string > => {
4345 const nearNetwork =
4446 chainIdToNearIntentsChain [ asset . chainId as keyof typeof chainIdToNearIntentsChain ]
@@ -47,22 +49,34 @@ export const assetToNearIntentsAsset = async (asset: Asset): Promise<string> =>
4749 throw new Error ( `Unsupported chain for NEAR Intents: ${ asset . chainId } ` )
4850 }
4951
50- // Solana tokens need lookup from /v0/tokens
51- // Unlike other chains, Solana token IDs can't be generated from contract addresses
52- // because NEAR Intents uses their own internal token registry for Solana SPL tokens
53- if ( asset . chainId === solanaChainId && isToken ( asset . assetId ) ) {
52+ // NEP-245 chains (BSC, Polygon, Avalanche, Optimism) and Solana require token lookup
53+ // Asset IDs use hashed format that can't be generated from contract addresses
54+ const requiresLookup =
55+ NEP245_CHAINS . includes ( nearNetwork as any ) || asset . chainId === solanaChainId
56+
57+ if ( requiresLookup ) {
5458 const tokens = await OneClickService . getTokens ( )
55- const solanaAddress = fromAssetId ( asset . assetId ) . assetReference
56- const match = tokens . find ( t => t . blockchain === 'sol' && t . contractAddress === solanaAddress )
59+ const contractAddress = isToken ( asset . assetId )
60+ ? fromAssetId ( asset . assetId ) . assetReference . toLowerCase ( )
61+ : null
62+
63+ const match = tokens . find ( ( t : TokenResponse ) => {
64+ if ( t . blockchain !== nearNetwork ) return false
65+ return contractAddress
66+ ? t . contractAddress ?. toLowerCase ( ) === contractAddress
67+ : ! t . contractAddress
68+ } )
5769
5870 if ( ! match ) {
59- throw new Error ( `Solana token not found in NEAR Intents: ${ solanaAddress } ` )
71+ throw new Error (
72+ `Token not found in NEAR Intents: ${ asset . chainId } ${ contractAddress || 'native' } ` ,
73+ )
6074 }
6175
6276 return match . assetId
6377 }
6478
65- // For all other chains : use predictable NEP-141 format
79+ // NEP-141 chains (ETH, ARB, BASE, GNOSIS, BTC, DOGE) : use predictable format
6680 const contractAddress = isToken ( asset . assetId )
6781 ? fromAssetId ( asset . assetId ) . assetReference
6882 : zeroAddress
0 commit comments