diff --git a/packages/swap/src/common/supportedNetworks.ts b/packages/swap/src/common/supportedNetworks.ts index e7a16d346..755303002 100644 --- a/packages/swap/src/common/supportedNetworks.ts +++ b/packages/swap/src/common/supportedNetworks.ts @@ -1,6 +1,9 @@ import { SignerType } from "@enkryptcom/types"; import { NetworkInfo, NetworkType, SupportedNetworkName } from "../types"; +/** + * Sometimes you can get decimals and token info from here `https://raw.githubusercontent.com/MyEtherWallet/ethereum-lists/master/dist/master-file.json` + */ const NetworkDetails: Record = { [SupportedNetworkName.Bitcoin]: { id: SupportedNetworkName.Bitcoin, @@ -239,6 +242,40 @@ const NetworkDetails: Record = { signerType: [SignerType.secp256k1btc], type: NetworkType.Bitcoin, }, + [SupportedNetworkName.Rootstock]: { + id: SupportedNetworkName.Rootstock, + decimals: 18, + logoURI: + "https://coin-images.coingecko.com/coins/images/5070/large/RBTC-logo.png?1718152038", + name: "Rootstock", + symbol: "RBTC", + cgId: "rootstock", + rank: 19, + signerType: [SignerType.secp256k1], + type: NetworkType.EVM, + }, + [SupportedNetworkName.Blast]: { + id: SupportedNetworkName.Blast, + decimals: 18, + logoURI: "https://assets.coingecko.com/coins/images/35494/standard/Blast.jpg", + name: "Blast", + symbol: "ETH", + cgId: "ethereum", + rank: 20, + signerType: [SignerType.secp256k1], + type: NetworkType.EVM, + }, + [SupportedNetworkName.Telos]: { + id: SupportedNetworkName.Telos, + decimals: 18, + logoURI: "https://assets.coingecko.com/coins/images/7588/standard/tlos_png.png", + name: "Telos", + symbol: "TLOS", + cgId: "telos", + rank: 21, + signerType: [SignerType.secp256k1], + type: NetworkType.EVM, + }, }; export const isSupportedNetwork = (networkName: SupportedNetworkName) => !!NetworkDetails[networkName]; diff --git a/packages/swap/src/configs.ts b/packages/swap/src/configs.ts index ded2ffc0b..432183689 100644 --- a/packages/swap/src/configs.ts +++ b/packages/swap/src/configs.ts @@ -63,6 +63,9 @@ const TOKEN_LISTS: { [NetworkNames.ZkSync]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Zksync}.json`, [NetworkNames.Base]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Base}.json`, [NetworkNames.MaticZK]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.MaticZK}.json`, + [NetworkNames.Rootstock]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Rootstock}.json`, + [NetworkNames.Blast]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Blast}.json`, + [NetworkNames.Telos]: `https://raw.githubusercontent.com/enkryptcom/dynamic-data/main/swaplists/${SupportedNetworkName.Telos}.json`, }; const CHANGELLY_LIST = diff --git a/packages/swap/src/providers/changelly/index.ts b/packages/swap/src/providers/changelly/index.ts index 7a82816b9..505dfefe3 100644 --- a/packages/swap/src/providers/changelly/index.ts +++ b/packages/swap/src/providers/changelly/index.ts @@ -49,6 +49,7 @@ class Changelly extends ProviderClass { toTokens: ProviderToTokenResponse; + /** Dynamically generated Changelly swap token data from the Enkrypt dynamic-lists repo {@link CHANGELLY_LIST} */ changellyList: ChangellyCurrency[]; contractToTicker: Record; @@ -66,16 +67,25 @@ class Changelly extends ProviderClass { async init(): Promise { if (!Changelly.isSupported(this.network)) return; this.changellyList = await fetch(CHANGELLY_LIST).then((res) => res.json()); + + /** changelly blockchain name -> enkrypt supported swap network name */ const changellyToNetwork: Record = {}; + // Generate mapping of changelly blockchain -> enkrypt blockchain Object.keys(supportedNetworks).forEach((net) => { changellyToNetwork[supportedNetworks[net].changellyName] = net as unknown as SupportedNetworkName; }); + + /** List of changelly blockchain names */ const supportedChangellyNames = Object.values(supportedNetworks).map( (s) => s.changellyName ); + this.changellyList.forEach((cur) => { + // We must support the changelly network if (!supportedChangellyNames.includes(cur.blockchain)) return; + + // Can currency can be swapped from? if ( cur.enabledFrom && cur.fixRateEnabled && @@ -84,6 +94,8 @@ class Changelly extends ProviderClass { ) { this.fromTokens[cur.token.address] = cur.token; } + + // Can currency can be swapped to? if (cur.enabledTo && cur.fixRateEnabled && cur.token) { if (!this.toTokens[changellyToNetwork[cur.blockchain]]) this.toTokens[changellyToNetwork[cur.blockchain]] = {}; diff --git a/packages/swap/src/providers/changelly/supported.ts b/packages/swap/src/providers/changelly/supported.ts index ac8d7fe4d..7cf74c22f 100644 --- a/packages/swap/src/providers/changelly/supported.ts +++ b/packages/swap/src/providers/changelly/supported.ts @@ -1,6 +1,11 @@ import { isPolkadotAddress, isEVMAddress } from "../../utils/common"; import { SupportedNetworkName } from "../../types"; +/** + * ```sh + * curl https://partners.mewapi.io/changelly-v2 -X POST -H Accept:application/json -H Content-Type:application/json --data '{"id":"1","jsonrpc":"2.0","method":"getCurrenciesFull","params":{}}' + * ```` + */ const supportedNetworks: { [key in SupportedNetworkName]?: { changellyName: string; @@ -50,6 +55,9 @@ const supportedNetworks: { [SupportedNetworkName.Dogecoin]: { changellyName: "doge", }, + [SupportedNetworkName.Rootstock]: { + changellyName: "rootstock", + }, }; export default supportedNetworks; diff --git a/packages/swap/src/providers/rango/index.ts b/packages/swap/src/providers/rango/index.ts index 71774e3e7..0af1968dd 100644 --- a/packages/swap/src/providers/rango/index.ts +++ b/packages/swap/src/providers/rango/index.ts @@ -43,8 +43,25 @@ import { isEVMAddress } from "../../utils/common"; const RANGO_PUBLIC_API_KEY = "ee7da377-0ed8-4d42-aaf9-fa978a32b18d"; const rangoClient = new RangoClient(RANGO_PUBLIC_API_KEY); + +/** + * `name` is the blockchain id on Rango + * + * You can use the Rango API to get a list of tokens to figure out the Rango name of a network + * + * @see https://rango-api.readme.io/reference/meta + * + * ```sh + * curl 'https://api.rango.exchange/basic/meta?apiKey=c6381a79-2817-4602-83bf-6a641a409e32' -H 'Accept:application/json' + * ``` + */ const supportedNetworks: { - [key in SupportedNetworkName]?: { chainId: string; name: string }; + [key in SupportedNetworkName]?: { + /** Standard base10 chain ID, can be obtained from `https://chainlist.org` */ + chainId: string; + /** Rango name (Rango's identifier for the chain) of a network */ + name: string; + }; } = { [SupportedNetworkName.Ethereum]: { chainId: "1", @@ -86,6 +103,14 @@ const supportedNetworks: { chainId: "1284", name: "MOONBEAM", }, + [SupportedNetworkName.Blast]: { + chainId: "81457", + name: "BLAST", + }, + [SupportedNetworkName.Telos]: { + chainId: "40", + name: "TELOS", + }, }; class Rango extends ProviderClass { @@ -142,16 +167,26 @@ class Rango extends ProviderClass { network: SupportedNetworkName, blockchains: BlockchainMeta[] ) { - if (!Object.keys(supportedNetworks).includes(network as unknown as string)) + // We must support this network + if (!Object.keys(supportedNetworks).includes(network as unknown as string)) { return false; + } + if (blockchains.length) { + // Join Rango networks and our supported networks by their chain id + + // Extract our info about this supported network const { chainId } = Object.entries(supportedNetworks).find( (chain) => chain[0] === (network as unknown as string) )[1]; + + // Does Rango support this chain id? return !!blockchains.find( (chain: BlockchainMeta) => Number(chain.chainId) === Number(chainId) )?.enabled; } + + // Rango didn't give us anything so just assume Rango supports this network return true; } diff --git a/packages/swap/src/types/index.ts b/packages/swap/src/types/index.ts index d4397e207..53034bc08 100644 --- a/packages/swap/src/types/index.ts +++ b/packages/swap/src/types/index.ts @@ -29,6 +29,10 @@ export enum SupportedNetworkName { Zksync = NetworkNames.ZkSync, Base = NetworkNames.Base, MaticZK = NetworkNames.MaticZK, + Blast = NetworkNames.Blast, + Telos = NetworkNames.Telos, + Rootstock = NetworkNames.Rootstock, + Solana = NetworkNames.Solana, } // eslint-disable-next-line no-shadow diff --git a/packages/types/src/networks.ts b/packages/types/src/networks.ts index 5f4ca8a5c..24a30c8f1 100644 --- a/packages/types/src/networks.ts +++ b/packages/types/src/networks.ts @@ -73,12 +73,12 @@ export enum NetworkNames { RolluxTest = "TRLX", Rollux = "RLX", CagaAnkara = "CagaAnkara", - Solana = "SOL", Telos = "TLOS", Blast = "blast", Sanko = "sanko", Degen = "degen", Ham = "ham", + Solana = "SOLANA", XLayer = "XLayer", ZChains = "ZCD", ImmutableZkevm = "ImmutableZkevm",