Skip to content
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
22 changes: 18 additions & 4 deletions src/components/RouteIcons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@

import { type ComponentType, type SVGProps, useState } from 'react'
import { cx } from 'zyzz'
import LogoArbitrum from '~icons/token-branded/arbitrum-one'
import LogoAvalanche from '~icons/token-branded/avalanche'
import LogoBase from '~icons/token-branded/base'
import LogoBnb from '~icons/token-branded/bnb'
import LogoEthereum from '~icons/token-branded/ethereum'
import LogoHyperEvm from '~icons/token-branded/hyper-evm'
import LogoMonad from '~icons/token-branded/monad'
import LogoOptimism from '~icons/token-branded/optimism'
import LogoPolygon from '~icons/token-branded/polygon'
import LogoSolana from '~icons/token-branded/solana'
import LogoStellar from '~icons/token-branded/stellar'
import LogoTron from '~icons/token-branded/tron'
import LogoUsdc from '~icons/token-branded/usdc'
import LogoUsdt from '~icons/token-branded/usdt'
Expand All @@ -21,16 +25,24 @@ type Logo = ComponentType<SVGProps<SVGSVGElement>>
// Official chain marks (Web3 Icons) keyed by CAIP-2 id, matching the console's Routes map.
const chainLogos: Record<string, Logo> = {
'eip155:1': LogoEthereum,
'eip155:10': LogoOptimism,
'eip155:137': LogoPolygon,
'eip155:143': LogoMonad,
'eip155:42161': LogoArbitrum,
'eip155:43114': LogoAvalanche,
'eip155:56': LogoBnb,
'eip155:8453': LogoBase,
'eip155:999': LogoHyperEvm,
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': LogoSolana,
'stellar:pubnet': LogoStellar,
'tron:0x2b6653dc': LogoTron,
}
// Tempo chains whose tokens have icons in the token list service.
const tempoChainIds: Record<string, number> = { 'eip155:4217': 4217, 'eip155:42431': 42431 }
// Tempo-issued tokens bridged to other networks share their Tempo icon, keyed by symbol.
const tempoIssued: Record<string, string> = {
OUSD: '4217/0x20c0000000000000000000006a37da5c996874be',
}
// Off-Tempo stablecoins with an official mark, by symbol family.
const tokenLogo = (symbol: string): Logo | undefined =>
/^USDC/i.test(symbol) ? LogoUsdc : /^USDT/i.test(symbol) ? LogoUsdt : undefined
Expand Down Expand Up @@ -84,8 +96,9 @@ export function ChainLogo({
}

/**
* A token's icon: Tempo tokens load theirs from the token list service, other stablecoins use
* their official mark, and anything else falls back to a monogram.
* A token's icon: Tempo tokens, and Tempo-issued tokens on other networks, load theirs from the
* token list service, other stablecoins use their official mark, and anything else falls back to
* a monogram.
*/
export function TokenLogo({
chainId,
Expand All @@ -102,13 +115,14 @@ export function TokenLogo({
const [broken, setBroken] = useState(false)
const tempo = chainId ? tempoChainIds[chainId] : undefined
const address = tokenKey ? erc20Address(tokenKey) : undefined
if (symbol && tempo && address && !broken)
const icon = tempo && address ? `${tempo}/${address}` : symbol ? tempoIssued[symbol] : undefined
if (symbol && icon && !broken)
return (
<img
alt=""
{...cx(square({ size: `${size}px` }), round())}
onError={() => setBroken(true)}
src={`https://tokenlist.tempo.xyz/icon/${tempo}/${address}.svg`}
src={`https://tokenlist.tempo.xyz/icon/${icon}.svg`}
/>
)
const Logo = symbol ? tokenLogo(symbol) : undefined
Expand Down
15 changes: 15 additions & 0 deletions src/lib/routes-test.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,21 @@ describe('quickRoutes', () => {
]
expect(quickRoutes(routes).map((r) => r.id)).toEqual(['base', 'eth-usdt', 'arb'])
})
it('puts Solana USDC, then Ethereum USDC, to Tempo OUSD after Base', () => {
const ousd = (id: string, source: string) => ({
...make(id, source, 'eip155:4217'),
destinationToken: { tokenKey: 'eip155:4217/erc20:ousd', symbol: 'OUSD', decimals: 6 },
})
const routes = [
make('eth-usdt', 'eip155:1', 'eip155:4217', 'USDT'),
make('op', 'eip155:10', 'eip155:4217'),
make('base', 'eip155:8453', 'eip155:4217'),
make('solana-usdce', 'solana:mainnet', 'eip155:4217'),
ousd('solana-ousd', 'solana:mainnet'),
ousd('eth-ousd', 'eip155:1'),
]
expect(quickRoutes(routes).map((r) => r.id)).toEqual(['base', 'solana-ousd', 'eth-ousd'])
})
it('skips routes the demo cannot run and fills from the rest of the directory', () => {
const solanaTransferOnly = {
...make('solana', 'solana:mainnet', 'eip155:4217'),
Expand Down
12 changes: 8 additions & 4 deletions src/lib/routes-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,17 @@ export function routeTestRequest(route: TestRoute, input: RouteInput) {

/**
* Up to `limit` routes the demo can run, offered as one-click starts: Base USDC to Tempo USDC.e
* first, then other routes into Tempo, one per source network where possible.
* first, then Solana USDC and Ethereum USDC to Tempo OUSD, then other routes into Tempo, one per
* source network where possible.
*/
export function quickRoutes(routes: TestRoute[], limit = 3) {
const rank = (route: TestRoute) => {
if (!isTempo(route.destinationChain.id)) return 2
const baseUsdc = route.sourceChain.id === 'eip155:8453' && route.sourceToken.symbol === 'USDC'
return baseUsdc && route.destinationToken.symbol === 'USDC.e' ? 0 : 1
if (!isTempo(route.destinationChain.id)) return 4
if (route.sourceToken.symbol !== 'USDC') return 3
const [source, destination] = [route.sourceChain.id, route.destinationToken.symbol]
if (source === 'eip155:8453' && destination === 'USDC.e') return 0
if (source.startsWith('solana:') && destination === 'OUSD') return 1
return source === 'eip155:1' && destination === 'OUSD' ? 2 : 3
}
const ranked = routes
.filter((route) => demoMethods(route).length > 0)
Expand Down
Loading