From f97ef8023efafe361fa5b9eea585b21424ff0759 Mon Sep 17 00:00:00 2001
From: rustin01 <141540002+rustin01@users.noreply.github.com>
Date: Wed, 13 Nov 2024 10:09:52 +0800
Subject: [PATCH] Feat/swan chain (#203)
---
apps/wallet/public/chain-icons/Swan.svg | 19 +++++++
.../wallet/src/pages/select-network/index.tsx | 6 +--
apps/wallet/src/utils/basicEnums.ts | 10 ++++
apps/wallet/src/utils/basicTypes.ts | 4 ++
apps/wallet/src/utils/chain/chain-list.ts | 53 ++++++++++++++++++-
apps/wallet/src/utils/chain/index.ts | 4 +-
6 files changed, 91 insertions(+), 5 deletions(-)
create mode 100644 apps/wallet/public/chain-icons/Swan.svg
diff --git a/apps/wallet/public/chain-icons/Swan.svg b/apps/wallet/public/chain-icons/Swan.svg
new file mode 100644
index 0000000..bde8b71
--- /dev/null
+++ b/apps/wallet/public/chain-icons/Swan.svg
@@ -0,0 +1,19 @@
+
diff --git a/apps/wallet/src/pages/select-network/index.tsx b/apps/wallet/src/pages/select-network/index.tsx
index b440b13..efbe36a 100644
--- a/apps/wallet/src/pages/select-network/index.tsx
+++ b/apps/wallet/src/pages/select-network/index.tsx
@@ -16,10 +16,10 @@ const SelectNetworkPage: FC = observer(() => {
const chainsMap: Record = {}
const supportedChains = getSupportedChains()
supportedChains.forEach((chain) => {
- if (!chainsMap[chain.chainId.type.name]) {
- chainsMap[chain.chainId.type.name] = []
+ if (!chainsMap[chain.ecosystem]) {
+ chainsMap[chain.ecosystem] = []
}
- chainsMap[chain.chainId.type.name].push(chain)
+ chainsMap[chain.ecosystem].push(chain)
})
return chainsMap
}, [])
diff --git a/apps/wallet/src/utils/basicEnums.ts b/apps/wallet/src/utils/basicEnums.ts
index f9929d8..3cf5626 100644
--- a/apps/wallet/src/utils/basicEnums.ts
+++ b/apps/wallet/src/utils/basicEnums.ts
@@ -25,3 +25,13 @@ export enum WalletSignatureSchema {
SolanaEddsa = '0x7da',
IcpEddsa = '0x7e4'
}
+
+// TODO: Add support for other ecosystems
+export enum Ecosystem {
+ EVM = 'EVM',
+ Bitcoin = 'Bitcoin',
+ Solana = 'Solana',
+ Tron = 'Tron',
+ Ton = 'Ton',
+ IC = 'Internet Computer'
+}
diff --git a/apps/wallet/src/utils/basicTypes.ts b/apps/wallet/src/utils/basicTypes.ts
index 1d4e792..8fd35eb 100644
--- a/apps/wallet/src/utils/basicTypes.ts
+++ b/apps/wallet/src/utils/basicTypes.ts
@@ -1,6 +1,7 @@
import BigNumber from 'bignumber.js';
import { Transform, Type } from 'class-transformer';
import { WalletSignatureSchema } from './basicEnums';
+import { Ecosystem } from './basicEnums';
export class AssetId {
value: BigNumber;
@@ -193,6 +194,8 @@ export class ChainNetwork {
static EvmScrollSepoliaNet = new ChainNetwork(new BigNumber(534351));
static EvmBitlayerNet = new ChainNetwork(new BigNumber(200901));
static EvmBitlayerTestNet = new ChainNetwork(new BigNumber(200810));
+ static EvmSwanNet = new ChainNetwork(new BigNumber(254));
+ static EvmSwanTestNet = new ChainNetwork(new BigNumber(20241133));
static SolanaMainNet = new ChainNetwork(new BigNumber(0x3));
static SolanaTestNet = new ChainNetwork(new BigNumber(0x2));
@@ -280,6 +283,7 @@ export class ChainInfo {
rpcUrls!: string[];
isMainnet!: boolean
isNativeGas!: boolean;
+ ecosystem!: Ecosystem;
caseSensitiveAddress?: boolean;
getServerFormatAddress?: (address: string) => string | null
getTxLink?: (txId: string) => string
diff --git a/apps/wallet/src/utils/chain/chain-list.ts b/apps/wallet/src/utils/chain/chain-list.ts
index f0792ee..52cab6a 100644
--- a/apps/wallet/src/utils/chain/chain-list.ts
+++ b/apps/wallet/src/utils/chain/chain-list.ts
@@ -1,4 +1,4 @@
-import { WalletSignatureSchema } from "../basicEnums";
+import { Ecosystem, WalletSignatureSchema } from "../basicEnums";
import { ChainInfo, ChainId, Chain, ChainNetwork } from "../basicTypes";
import { clusterApiUrl } from '@solana/web3.js';
import { getHttpEndpoint } from "@orbs-network/ton-access";
@@ -13,6 +13,7 @@ export const Ethereum: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://etherscan.io',
rpcUrls: ['https://ethereum.blockpi.network/v1/rpc/public']
@@ -26,6 +27,7 @@ export const EthereumSepolia: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://sepolia.etherscan.io',
rpcUrls: ['https://ethereum-sepolia.blockpi.network/v1/rpc/public ']
@@ -40,6 +42,7 @@ export const EthereumBsc: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://bscscan.com',
rpcUrls: ['https://bsc-dataseed.binance.org']
@@ -53,6 +56,7 @@ export const EthereumBscTestnet: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://testnet.bscscan.com',
rpcUrls: ['https://bsc-testnet.publicnode.com']
@@ -67,6 +71,7 @@ export const EthereumScroll: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://scroll.l2scan.co',
rpcUrls: ['https://rpc.scroll.io']
@@ -80,6 +85,7 @@ export const EthereumScrollSepolia: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://scroll-sepolia.l2scan.co',
rpcUrls: ['https://sepolia-rpc.scroll.io']
@@ -94,6 +100,7 @@ export const EthereumBase: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://basescan.org',
rpcUrls: ['https://mainnet.base.org']
@@ -107,6 +114,7 @@ export const EthereumBaseSepolia: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://sepolia.basescan.org',
rpcUrls: ['https://sepolia.base.org']
@@ -121,6 +129,7 @@ export const EthereumAvalanche: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://snowtrace.io',
rpcUrls: ['https://api.avax.network/ext/bc/C/rpc']
@@ -134,6 +143,7 @@ export const EthereumAvalancheFuji: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://subnets-test.avax.network/c-chain',
rpcUrls: ['https://api.avax-test.network/ext/bc/C/rpc']
@@ -148,6 +158,7 @@ export const EthereumBitlayer: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.Bitcoin,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://btrscan.com',
rpcUrls: ['https://rpc.bitlayer.org']
@@ -161,11 +172,41 @@ export const EthereumBitlayerTestnet: ChainInfo = {
nativeAssetDecimals: 18,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.Bitcoin,
supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
explorer: 'https://testnet.btrscan.com',
rpcUrls: ['https://testnet-rpc.bitlayer.org']
};
+export const EthereumSwan: ChainInfo = {
+ chainId: new ChainId(Chain.Ethereum, ChainNetwork.EvmSwanNet),
+ name: 'Swan',
+ fullName: 'Swan Mainnet',
+ icon: '/chain-icons/Swan.svg',
+ nativeAssetSymbol: 'ETH',
+ nativeAssetDecimals: 18,
+ isMainnet: true,
+ isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
+ supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
+ explorer: 'https://swanscan.io',
+ rpcUrls: ['https://mainnet-rpc.swanchain.org']
+};
+export const EthereumSwanTestnet: ChainInfo = {
+ chainId: new ChainId(Chain.Ethereum, ChainNetwork.EvmSwanTestNet),
+ name: 'Swan Testnet',
+ fullName: 'Swan Proxima Testnet',
+ icon: '/chain-icons/Swan.svg',
+ nativeAssetSymbol: 'ETH',
+ nativeAssetDecimals: 18,
+ isMainnet: false,
+ isNativeGas: true,
+ ecosystem: Ecosystem.EVM,
+ supportedSignaturesSchemas: [WalletSignatureSchema.EvmEcdsa],
+ explorer: 'https://proxima-explorer.swanchain.io',
+ rpcUrls: ['https://rpc-proxima.swanchain.io']
+};
+
export const Bitcoin: ChainInfo = {
chainId: new ChainId(Chain.Bitcoin, ChainNetwork.BtcMainNet),
name: 'Bitcoin',
@@ -175,6 +216,7 @@ export const Bitcoin: ChainInfo = {
nativeAssetDecimals: 8,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.Bitcoin,
supportedSignaturesSchemas: [WalletSignatureSchema.BtcEcdsa],
explorer: 'https://blockstream.info',
rpcUrls: []
@@ -188,6 +230,7 @@ export const BitcoinTestnet: ChainInfo = {
nativeAssetDecimals: 8,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.Bitcoin,
supportedSignaturesSchemas: [WalletSignatureSchema.BtcEcdsa],
explorer: 'https://blockstream.info/testnet',
rpcUrls: []
@@ -202,6 +245,7 @@ export const Solana: ChainInfo = {
nativeAssetDecimals: 9,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.Solana,
supportedSignaturesSchemas: [WalletSignatureSchema.SolanaEddsa],
explorer: 'https://explorer.solana.com',
rpcUrls: [clusterApiUrl('mainnet-beta')],
@@ -216,6 +260,7 @@ export const SolanaTestnet: ChainInfo = {
nativeAssetDecimals: 9,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.Solana,
supportedSignaturesSchemas: [WalletSignatureSchema.SolanaEddsa],
explorer: 'https://explorer.solana.com?cluster=testnet',
rpcUrls: [clusterApiUrl('testnet')],
@@ -231,6 +276,7 @@ export const Ton: ChainInfo = {
nativeAssetDecimals: 9,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.Ton,
supportedSignaturesSchemas: [WalletSignatureSchema.TonEddsaOpenMask],
explorer: 'https://tonviewer.com',
rpcUrls: [],
@@ -282,6 +328,7 @@ export const TonTestnet: ChainInfo = {
nativeAssetDecimals: 9,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.Ton,
supportedSignaturesSchemas: [WalletSignatureSchema.TonEddsaOpenMask],
explorer: 'https://testnet.tonviewer.com',
rpcUrls: [],
@@ -342,6 +389,7 @@ export const Tron: ChainInfo = {
nativeAssetDecimals: 6,
isMainnet: true,
isNativeGas: true,
+ ecosystem: Ecosystem.Tron,
supportedSignaturesSchemas: [WalletSignatureSchema.TronEcdsa],
explorer: 'https://tronscan.org',
rpcUrls: ['https://rpc.trongrid.io'],
@@ -369,6 +417,7 @@ export const TronShasta: ChainInfo = {
nativeAssetDecimals: 6,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.Tron,
supportedSignaturesSchemas: [WalletSignatureSchema.TronEcdsa],
explorer: 'https://shasta.tronscan.org',
rpcUrls: ['https://api.shasta.trongrid.io'],
@@ -396,6 +445,7 @@ export const TronNile: ChainInfo = {
nativeAssetDecimals: 6,
isMainnet: false,
isNativeGas: true,
+ ecosystem: Ecosystem.Tron,
supportedSignaturesSchemas: [WalletSignatureSchema.TronEcdsa],
explorer: 'https://nile.tronscan.org',
rpcUrls: ['https://api.nileex.io'],
@@ -424,6 +474,7 @@ export const Dfinity: ChainInfo = {
nativeAssetDecimals: 8,
isMainnet: true,
isNativeGas: false,
+ ecosystem: Ecosystem.IC,
supportedSignaturesSchemas: [WalletSignatureSchema.IcpEddsa],
explorer: 'https://dashboard.internetcomputer.org',
rpcUrls: ['https://ic0.app'],
diff --git a/apps/wallet/src/utils/chain/index.ts b/apps/wallet/src/utils/chain/index.ts
index 33cce76..f57f453 100644
--- a/apps/wallet/src/utils/chain/index.ts
+++ b/apps/wallet/src/utils/chain/index.ts
@@ -1,5 +1,5 @@
import { Chain, ChainId } from '../basicTypes';
-import { Ethereum, EthereumAvalanche, EthereumAvalancheFuji, EthereumBase, EthereumBaseSepolia, EthereumBsc, EthereumBscTestnet, EthereumScroll, EthereumScrollSepolia, EthereumSepolia, EthereumBitlayer, EthereumBitlayerTestnet, Ton, TonTestnet, Dfinity } from './chain-list';
+import { Ethereum, EthereumAvalanche, EthereumAvalancheFuji, EthereumBase, EthereumBaseSepolia, EthereumBsc, EthereumBscTestnet, EthereumScroll, EthereumScrollSepolia, EthereumSepolia, EthereumBitlayer, EthereumBitlayerTestnet, Ton, TonTestnet, Dfinity, EthereumSwan, EthereumSwanTestnet } from './chain-list';
import { ChainInfo } from '../basicTypes';
import { RUNTIME_SUPPORTED_CHAIN_IDS } from '../runtime';
import hibitIdSession from '../../stores/session';
@@ -14,6 +14,7 @@ const SupportedChainsForMainnet = [
EthereumScroll,
EthereumAvalanche,
EthereumBitlayer,
+ EthereumSwan,
// Bitcoin,
// Solana,
Ton,
@@ -27,6 +28,7 @@ const SupportedChainsForTestnet = [
EthereumScrollSepolia,
EthereumAvalancheFuji,
EthereumBitlayerTestnet,
+ EthereumSwanTestnet,
// BitcoinTestnet,
// SolanaTestnet,
TonTestnet,