1- import { getAssetDecimals } from "@paraspell/assets"
1+ import { getAssetDecimals , getAssetsObject } from "@paraspell/assets"
22import type { TCurrency , TLocation , TNodeDotKsmWithRelayChains } from "@paraspell/sdk"
33import type {
44 RouterBuilderCore ,
@@ -11,8 +11,7 @@ import { RouterBuilder } from "@paraspell/xcm-router"
1111import { parseUnits } from "@polkadot-agent-kit/common"
1212import type { PolkadotSigner } from "polkadot-api/signer"
1313
14- import type { AssetInfo } from "../utils/assets"
15- import { getAllAssetsBySymbol } from "../utils/assets"
14+ import type { AssetInfo } from "../utils"
1615import { getPairSupported } from "../utils/defi"
1716
1817// Constants
@@ -78,24 +77,77 @@ function getAssetlocationWithSelection(
7877 chain : TNodeDotKsmWithRelayChains ,
7978 symbol : string
8079) : TLocation {
81- // Get all assets with this symbol
82- const assets = getAllAssetsBySymbol ( chain , symbol )
80+ const chainAssets = getAssetsObject ( chain )
81+ const nativeAssetSymbol = chainAssets . nativeAssetSymbol
82+
83+ let assetsInfo : AssetInfo [ ] = [ ]
84+
85+ // Check if symbol matches native asset symbol (case-insensitive comparison)
86+ if ( symbol . toUpperCase ( ) === nativeAssetSymbol ?. toUpperCase ( ) ) {
87+ // Return native asset info
88+ const nativeAssets = chainAssets . nativeAssets || [ ]
89+ const matchingNative = nativeAssets . find (
90+ ( asset : { symbol : string } ) => asset . symbol ?. toUpperCase ( ) === symbol . toUpperCase ( )
91+ )
92+
93+ if ( matchingNative && matchingNative . location ) {
94+ assetsInfo = [
95+ {
96+ symbol : matchingNative . symbol ,
97+ location : matchingNative . location ,
98+ decimals : matchingNative . decimals ,
99+ isNative : true ,
100+ isFeeAsset : matchingNative . isFeeAsset ,
101+ existentialDeposit : matchingNative . existentialDeposit
102+ }
103+ ]
104+ }
105+ }
106+
107+ // If not found in native assets, search in otherAssets
108+ if ( assetsInfo . length === 0 ) {
109+ const otherAssets = chainAssets . otherAssets || [ ]
110+ const matchingAssets = otherAssets . filter (
111+ ( asset : { symbol : string } ) => asset . symbol ?. toUpperCase ( ) === symbol . toUpperCase ( )
112+ )
113+
114+ assetsInfo = matchingAssets . map (
115+ ( asset : {
116+ symbol : string
117+ assetId ?: string
118+ decimals : number
119+ location ?: TLocation
120+ existentialDeposit ?: string
121+ isFeeAsset ?: boolean
122+ alias ?: string
123+ } ) => ( {
124+ symbol : asset . symbol ,
125+ assetId : asset . assetId ,
126+ decimals : asset . decimals ,
127+ location : asset . location ,
128+ existentialDeposit : asset . existentialDeposit ,
129+ isFeeAsset : asset . isFeeAsset ,
130+ alias : asset . alias ,
131+ isNative : false
132+ } )
133+ )
134+ }
83135
84136 // Handle no assets found
85- if ( ! assets || assets . length === 0 ) {
137+ if ( ! assetsInfo || assetsInfo . length === 0 ) {
86138 throw new Error ( `No asset found for symbol ${ symbol } on ${ chain } ` )
87139 }
88140
89141 // Handle single asset - return directly
90- if ( assets . length === 1 ) {
91- if ( ! assets [ 0 ] . location ) {
142+ if ( assetsInfo . length === 1 ) {
143+ if ( ! assetsInfo [ 0 ] . location ) {
92144 throw new Error ( `Asset ${ symbol } on ${ chain } does not have a location` )
93145 }
94- return assets [ 0 ] . location
146+ return assetsInfo [ 0 ] . location
95147 }
96148
97149 // Handle multiple assets - apply selection strategy
98- const selectedAsset = selectBestAsset ( assets , symbol , chain )
150+ const selectedAsset = selectBestAsset ( assetsInfo , symbol , chain )
99151
100152 if ( ! selectedAsset . location ) {
101153 throw new Error (
@@ -221,6 +273,7 @@ function getCrossChainlocations(args: SwapTokenArgs) {
221273 args . from as TNodeDotKsmWithRelayChains ,
222274 args . currencyFrom
223275 )
276+
224277 const locationTo = getAssetlocationWithSelection (
225278 args . to as TNodeDotKsmWithRelayChains ,
226279 args . currencyTo
0 commit comments