Skip to content

Commit 449486d

Browse files
authored
Feat: Use new tokenlist (#1827)
* use new tokenlist and simplify getting the underlying * includes instead of startswith * fix lint * underlying asset best effort for all trades
1 parent a191c63 commit 449486d

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@heroicons/react": "^2.1.3",
3030
"@indexcoop/analytics-sdk": "0.29.0",
3131
"@indexcoop/flash-mint-sdk": "3.24.0",
32-
"@indexcoop/tokenlists": "3.11.1",
32+
"@indexcoop/tokenlists": "4.0.0",
3333
"@next/third-parties": "15.1.7",
3434
"@reown/appkit": "1.6.9",
3535
"@reown/appkit-adapter-wagmi": "1.6.9",

src/lib/utils/api/database.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import {
2+
getTokenByChainAndAddress,
3+
getUnderlyingToken,
4+
isLeverageToken,
5+
} from '@indexcoop/tokenlists'
16
import { formatUnits } from 'viem'
27

38
import { UtmParam } from '@/app/store/utm-atoms'
@@ -52,15 +57,19 @@ export const mapQuoteToTrade = (
5257
})
5358

5459
const getUnderlyingAssetSymbol = (quote: Quote) => {
55-
const symbol = (
56-
quote.isMinting ? quote.outputToken : quote.inputToken
57-
).symbol.toUpperCase()
60+
const possible = ['ETH', 'BTC', 'SUI', 'SOL', 'MATIC']
5861

59-
if (symbol.startsWith('ETH') || symbol.startsWith('IETH')) return 'ETH'
60-
if (symbol.startsWith('BTC') || symbol.startsWith('IBTC')) return 'BTC'
61-
if (symbol.startsWith('WSTETH')) return 'WSTETH'
62-
if (symbol.startsWith('USUI')) return 'SUI'
63-
if (symbol.startsWith('USOL')) return 'SOL'
62+
const address = quote.isMinting
63+
? quote.outputToken.address
64+
: quote.inputToken.address
6465

65-
return ''
66+
const token = getTokenByChainAndAddress(quote.chainId, address)
67+
68+
if (isLeverageToken(token)) {
69+
const { symbol } = getUnderlyingToken(token)
70+
71+
return possible.find((p) => symbol.includes(p)) ?? ''
72+
}
73+
74+
return possible.find((p) => token?.symbol.includes(p)) ?? ''
6675
}

0 commit comments

Comments
 (0)