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
18 changes: 15 additions & 3 deletions packages/public-api/src/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { getBaseAsset } from '@shapeshiftoss/utils'
import fs from 'fs'
import path from 'path'

import { SUPPORTED_CHAIN_IDS_SET } from './constants'

let assetsById: AssetsById = {}
let assetIds: AssetId[] = []
let assets: Asset[] = []
Expand Down Expand Up @@ -49,8 +51,10 @@ export const initAssets = (): Promise<void> => {
}

assetsById = enrichedAssetsById
assetIds = sortedAssetIds
assets = sortedAssetIds.map((id: AssetId) => enrichedAssetsById[id]).filter(Boolean) as Asset[]
assetIds = sortedAssetIds.filter(id =>
SUPPORTED_CHAIN_IDS_SET.has(enrichedAssetsById[id]?.chainId),
)
assets = assetIds.map((id: AssetId) => enrichedAssetsById[id]).filter(Boolean) as Asset[]

console.log(`Loaded ${assetIds.length} assets from ${assetDataPath}`)
initialized = true
Expand All @@ -61,7 +65,15 @@ export const initAssets = (): Promise<void> => {
}
}

// Full asset map (all chains) for swapper deps only — e.g. NearIntents denominates
// its affiliate fee in NEAR's fee asset (buildAffiliateFee silently returns undefined
// if the asset is missing), so filtering this to supported chains would drop
// affiliate fee metadata from NearIntents rates/quotes
export const getAssetsById = (): AssetsById => assetsById
export const getAssetIds = (): AssetId[] => assetIds
export const getAllAssets = (): Asset[] => assets
export const getAsset = (assetId: AssetId): Asset | undefined => assetsById[assetId]
export const getAsset = (assetId: AssetId): Asset | undefined => {
const asset = assetsById[assetId]
if (!asset || !SUPPORTED_CHAIN_IDS_SET.has(asset.chainId)) return undefined
return asset
}
26 changes: 26 additions & 0 deletions packages/public-api/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
import { SwapperName } from '@shapeshiftoss/swapper'
import { KnownChainIds } from '@shapeshiftoss/types'

export const SUPPORTED_CHAIN_IDS: readonly KnownChainIds[] = [
// EVM
KnownChainIds.ArbitrumMainnet,
KnownChainIds.AvalancheMainnet,
KnownChainIds.BaseMainnet,
KnownChainIds.BnbSmartChainMainnet,
KnownChainIds.EthereumMainnet,
KnownChainIds.GnosisMainnet,
KnownChainIds.OptimismMainnet,
KnownChainIds.PolygonMainnet,
// UTXO
KnownChainIds.BitcoinCashMainnet,
KnownChainIds.BitcoinMainnet,
KnownChainIds.DogecoinMainnet,
KnownChainIds.LitecoinMainnet,
// Cosmos SDK
KnownChainIds.CosmosMainnet,
KnownChainIds.MayachainMainnet,
KnownChainIds.ThorchainMainnet,
// Solana
KnownChainIds.SolanaMainnet,
]

export const SUPPORTED_CHAIN_IDS_SET: ReadonlySet<string> = new Set(SUPPORTED_CHAIN_IDS)

export const ENABLED_SWAPPER_NAMES: readonly SwapperName[] = [
SwapperName.Bebop,
Expand Down
32 changes: 14 additions & 18 deletions packages/public-api/src/routes/chains/utils.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
import { fromChainId } from '@shapeshiftoss/caip'
import { KnownChainIds } from '@shapeshiftoss/types'
import type { ChainNamespace } from '@shapeshiftoss/caip'
import { CHAIN_NAMESPACE, fromChainId } from '@shapeshiftoss/caip'
import { getBaseAsset } from '@shapeshiftoss/utils'

import { SUPPORTED_CHAIN_IDS } from '../../constants'
import type { Chain, ChainType } from './types'

const chainNamespaceToType: Record<string, ChainType> = {
eip155: 'evm',
bip122: 'utxo',
cosmos: 'cosmos',
solana: 'solana',
tron: 'tron',
sui: 'sui',
near: 'near',
starknet: 'starknet',
ton: 'ton',
const chainNamespaceToType: Record<ChainNamespace, ChainType> = {
[CHAIN_NAMESPACE.Evm]: 'evm',
[CHAIN_NAMESPACE.Utxo]: 'utxo',
[CHAIN_NAMESPACE.CosmosSdk]: 'cosmos',
[CHAIN_NAMESPACE.Solana]: 'solana',
[CHAIN_NAMESPACE.Tron]: 'tron',
[CHAIN_NAMESPACE.Sui]: 'sui',
[CHAIN_NAMESPACE.Near]: 'near',
[CHAIN_NAMESPACE.Starknet]: 'starknet',
[CHAIN_NAMESPACE.Ton]: 'ton',
}
Comment thread
kaladinlight marked this conversation as resolved.

const buildChainList = (): Chain[] => {
const chains: Chain[] = []

for (const chainId of Object.values(KnownChainIds)) {
for (const chainId of SUPPORTED_CHAIN_IDS) {
try {
const baseAsset = getBaseAsset(chainId)
const { chainNamespace } = fromChainId(chainId)
const chainType = chainNamespaceToType[chainNamespace]

if (!chainType) {
console.warn(`Unknown chain namespace: ${chainNamespace} for chainId: ${chainId}`)
continue
}

chains.push({
chainId,
name: baseAsset.networkName ?? baseAsset.name,
Expand Down
10 changes: 0 additions & 10 deletions packages/swap-widget/src/config/appkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,10 @@ import {
bitcoin,
bsc,
gnosis,
hyperEvm,
katana,
mainnet,
monad,
optimism,
plasma,
polygon,
solana,
worldchain,
} from '@reown/appkit/networks'
import { createAppKit } from '@reown/appkit/react'
import { BitcoinAdapter } from '@reown/appkit-adapter-bitcoin'
Expand All @@ -31,11 +26,6 @@ const EVM_NETWORKS: readonly AppKitNetwork[] = [
avalanche,
bsc,
gnosis,
monad,
hyperEvm,
plasma,
worldchain,
katana,
]

const ALL_NETWORKS: readonly AppKitNetwork[] = [...EVM_NETWORKS, bitcoin, solana]
Expand Down
10 changes: 0 additions & 10 deletions packages/swap-widget/src/constants/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,12 @@ import {
dogecoin,
ethereum,
gnosis,
hyperevm,
katana,
litecoin,
mayachain,
monad,
optimism,
plasma,
polygon,
solana,
thorchain,
worldchain,
} from '@shapeshiftoss/utils'

import type { ChainId } from '../types'
Expand All @@ -34,11 +29,6 @@ const BASE_ASSETS_BY_CHAIN_ID: Record<ChainId, Asset> = {
[avax.chainId]: avax,
[bnbsmartchain.chainId]: bnbsmartchain,
[gnosis.chainId]: gnosis,
[monad.chainId]: monad,
[hyperevm.chainId]: hyperevm,
[plasma.chainId]: plasma,
[worldchain.chainId]: worldchain,
[katana.chainId]: katana,
[bitcoin.chainId]: bitcoin,
[bitcoincash.chainId]: bitcoincash,
[dogecoin.chainId]: dogecoin,
Expand Down
40 changes: 9 additions & 31 deletions packages/swap-widget/src/constants/viemChains.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,39 @@
import type { Chain, WalletClient } from 'viem'
import {
arbitrum,
avalanche,
base,
bsc,
gnosis,
hyperEvm,
katana,
mainnet,
monad,
optimism,
plasma,
polygon,
worldchain,
} from 'viem/chains'
import { arbitrum, avalanche, base, bsc, gnosis, mainnet, optimism, polygon } from 'viem/chains'

export const VIEM_CHAINS_BY_ID: Record<number, Chain> = {
1: {
[mainnet.id]: {
...mainnet,
rpcUrls: { default: { http: ['https://api.ethereum.shapeshift.com/api/v1/jsonrpc'] } },
},
10: {
[optimism.id]: {
...optimism,
rpcUrls: { default: { http: ['https://api.optimism.shapeshift.com/api/v1/jsonrpc'] } },
},
56: {
[bsc.id]: {
...bsc,
rpcUrls: { default: { http: ['https://api.bnbsmartchain.shapeshift.com/api/v1/jsonrpc'] } },
},
100: {
[gnosis.id]: {
...gnosis,
rpcUrls: { default: { http: ['https://api.gnosis.shapeshift.com/api/v1/jsonrpc'] } },
},
137: {
[polygon.id]: {
...polygon,
rpcUrls: { default: { http: ['https://api.polygon.shapeshift.com/api/v1/jsonrpc'] } },
},
143: { ...monad, rpcUrls: { default: { http: ['https://rpc.monad.xyz'] } } },
480: {
...worldchain,
rpcUrls: { default: { http: ['https://worldchain-mainnet.g.alchemy.com/public'] } },
},
999: { ...hyperEvm, rpcUrls: { default: { http: ['https://rpc.hyperliquid.xyz/evm'] } } },
8453: {
[base.id]: {
...base,
rpcUrls: { default: { http: ['https://api.base.shapeshift.com/api/v1/jsonrpc'] } },
},
9745: { ...plasma, rpcUrls: { default: { http: ['https://rpc.plasma.to'] } } },
42161: {
[arbitrum.id]: {
...arbitrum,
rpcUrls: { default: { http: ['https://api.arbitrum.shapeshift.com/api/v1/jsonrpc'] } },
},
43114: {
[avalanche.id]: {
...avalanche,
rpcUrls: { default: { http: ['https://api.avalanche.shapeshift.com/api/v1/jsonrpc'] } },
},
747474: { ...katana, rpcUrls: { default: { http: ['https://rpc.katana.network'] } } },
}

export const addChainToWallet = async (client: WalletClient, chain: Chain): Promise<void> => {
Expand Down
10 changes: 0 additions & 10 deletions packages/swap-widget/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ import {
ethChainId,
fromChainId,
gnosisChainId,
hyperEvmChainId,
katanaChainId,
ltcChainId,
mayachainChainId,
monadChainId,
optimismChainId,
plasmaChainId,
polygonChainId,
solanaChainId,
thorchainChainId,
worldChainChainId,
} from '@shapeshiftoss/caip'
import type { TransactionData } from '@shapeshiftoss/types'
import { BigAmount } from '@shapeshiftoss/utils'
Expand Down Expand Up @@ -234,11 +229,6 @@ export const EVM_CHAIN_IDS = {
avalanche: avalancheChainId,
bsc: bscChainId,
gnosis: gnosisChainId,
monad: monadChainId,
hyperEvm: hyperEvmChainId,
plasma: plasmaChainId,
worldChain: worldChainChainId,
katana: katanaChainId,
} as const

export const UTXO_CHAIN_IDS = {
Expand Down
Loading