-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: changes to support non EVM chains (#59)
* feat: initial changes to support non EVM chains * fix(typealias): added type alias => EVMChain = Chain * fix: added legacy supprotedChains export * feat: added chainType to the _Chain object
- Loading branch information
Showing
9 changed files
with
164 additions
and
50 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ChainKey, CoinKey } from '../base' | ||
|
||
export enum ChainType { | ||
EVM = 'EVM', | ||
Solana = 'SOLANA', | ||
} | ||
|
||
export interface _Chain { | ||
key: ChainKey | ||
chainType: ChainType | ||
name: string | ||
coin: CoinKey | ||
id: number | ||
mainnet: boolean | ||
logoURI?: string | ||
// faucetUrls is DEPRECATED - will be removed in the next breaking release | ||
faucetUrls?: string[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { BigNumber } from 'ethers' | ||
import { _Chain } from './Chain' | ||
|
||
export interface EVMChain extends _Chain { | ||
// tokenlistUrl is DEPRECATED - will be removed in the next breaking release | ||
tokenlistUrl?: string | ||
metamask: AddEthereumChainParameter | ||
multicallAddress?: string | ||
} | ||
|
||
export interface AddEthereumChainParameter { | ||
chainId: string | ||
blockExplorerUrls: string[] | ||
chainName: string | ||
nativeCurrency: { | ||
name: string | ||
symbol: string | ||
decimals: number | ||
} | ||
rpcUrls: string[] | ||
} | ||
|
||
export const prefixChainId = (chainId: number): string => { | ||
return '0x' + BigNumber.from(chainId)._hex.split('0x')[1].replace(/\b0+/g, '') | ||
} | ||
|
||
// This type alias is required to avoid breaking | ||
// changes with the new non EVM support types release | ||
// This will be removed in the future in favour of _Chain | ||
export type Chain = EVMChain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { _Chain } from './Chain' | ||
|
||
export type SolanaChain = _Chain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ChainKey } from '../base' | ||
import { Chain } from './EVMChain' | ||
import { EVMChain } from './EVMChain' | ||
import { SolanaChain } from './SolanaChain' | ||
import { supportedEVMChains, supportedSolanaChains } from './supported.chains' | ||
|
||
const supportedChains: Chain[] = [ | ||
// This will be added in the future | ||
// ...supportedSolanaChains, | ||
...supportedEVMChains, | ||
] | ||
|
||
export const getChainByKey = (chainKey: ChainKey): Chain => { | ||
const chain = supportedChains.find((c) => c.key === chainKey) | ||
if (!chain) { | ||
throw new Error('Invalid chainKey') | ||
} | ||
return chain | ||
} | ||
|
||
export const getChainById = (chainId: number): Chain => { | ||
const chain = supportedChains.find((c) => c.id === chainId) | ||
if (!chain) { | ||
throw new Error('Invalid chainId') | ||
} | ||
return chain | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export * from './Chain' | ||
export * from './EVMChain' | ||
export * from './SolanaChain' | ||
export * from './supported.chains' | ||
export * from './chain.utils' |
Oops, something went wrong.