-
Notifications
You must be signed in to change notification settings - Fork 21
Networks: Networks
The Networks
namespace provides constants and functions for working with blockchain networks supported by the SDK.
The Networks namespace can be imported like so:
import { Networks } from "@synapseprotocol/sdk";
// or, for potentially better tree shaking:
import { Networks } from "@synapseprotocol/sdk/common";
import { Networks, ChainId } from "@synapseprotocol/sdk";
import { BigNumberish } from "@ethersproject/bignumber";
// Print the name of a network respective to the passed chainId param.
function printNetworkNameFromChainId(chainId: number) {
const n: Networks.Network = Networks.fromChainId(chainId);
console.log(n.name);
}
printNetworkNameFromChainId(ChainId.POLYGON); // outputs "Polygon"
const nativeCurrency: string = Networks.AVALANCHE.chainCurrency;
console.log(`The native currency symbol for the Avalanche network is ${nativeCurrency}`); // nativeCurrency will output as "AVAX"
The Network
class defined in Networks
is primarily used as a "data wrapper", in that each instance of a Network
is useful for retrieving information about the defined network, such as its name, nativee currency symbol, and Chain ID.
For 99.9% of use cases, SDK users should only ever need the provided, pre-defined Network
instances.
A network contains the following read-only attributes:
-
name
(string
) - The primary or official name of the network, for example "Binance Smart Chain" -
chainCurrency
(string
) - The native currency symbol for this network. Examples: "BNB" on Binance Smart Chain, "AVAX" on Avalanche. -
chainId
(number
) - The network's Chain ID. For pre-definedNetwork
instances, this will use a constant defined in the ChainId namespace. -
tokens
(Token[]
) - An array containing Token instances for all tokens which the Synapse Protocol supports on this network. -
tokenAddresses
(string[]
) - An array of strings containing the actual, on-chain address of all entries intokens
.
The Network
class also provides the following functions:
-
supportsToken
- Returns
true
if theToken
passed to it is supported by the Synapse Protocol on the given network. - Params:
-
token: Token
- A Token instance
-
- Returns:
boolean
-
true
iftoken
is supported for use on the network by the Synapse Protocol,false
otherwise
- Returns
-
zapIsL2BridgeZap
- Returns
true
if the Synapse Bridge Zap contract for this network is aL2BridgeZap
, rather than aNerveBridgeZap
. Currently, Bridge Zaps for all networks except the Ethereum mainnet areL2BridgeZap
contracts.
- Returns
All of the below are Network
instances, exported as constants from the Networks
namespace. All of these networks
are supported and useable on the Synapse Protocol.
-
ETH
- Constructor params:
name: "Ethereum Mainnet"
chainId: ChainId.ETH
chainCurrency: "ETH"
- Constructor params:
-
OPTIMISM
- Constructor params:
name: "Optimism"
chainId: ChainId.OPTIMISM
chainCurrency: "ETH"
- Constructor params:
-
BSC
- Constructor params:
name: "Binance Smart Chain"
chainId: ChainId.BSC
chainCurrency: "BNB"
- Constructor params:
-
POLYGON
- Constructor params:
name: "Polygon"
chainId: ChainId.POLYGON
chainCurrency: "MATIC"
- Constructor params:
-
FANTOM
- Constructor params:
name: "Fantom"
chainId: ChainId.FANTOM
chainCurrency: "FTM"
- Constructor params:
-
BOBA
- Constructor params:
name: "Boba Network"
chainId: ChainId.BOBA
chainCurrency: "ETH"
- Constructor params:
-
MOONBEAM
- Constructor params:
name: "Moonbeam"
chainId: ChainId.MOONBEAM
chainCurrency: "GLMR"
- Constructor params:
-
MOONRIVER
- Constructor params:
name: "Moonriver"
chainId: ChainId.MOONRIVER
chainCurrency: "MOVR"
- Constructor params:
-
ARBITRUM
- Constructor params:
name: "Arbitrum"
chainId: ChainId.ARBITRUM
chainCurrency: "ETH"
- Constructor params:
-
AVALANCHE
- Constructor params:
name: "Avalanche C-Chain"
chainId: ChainId.AVALANCHE
chainCurrency: "AVAX"
- Constructor params:
-
AURORA
- Constructor params:
name: "Aurora"
chainId: ChainId.AURORA
chainCurrency: "aETH"
- Constructor params:
-
HARMONY
- Constructor params:
name: "Harmony"
chainId: ChainId.HARMONY
chainCurrency: "ONE"
- Constructor params:
-
networkName
:- Returns the canonical name of the passed Chain ID, if supported by the SDK.
- Params:
chainId: number
- Returns:
-
string
- Canonical name of the passed Chain, if supported.
-
-
fromChainId
- Returns a
Network
instance based on the passed Chain ID, if it corresponds to a network which is known and supported by the Synapse Protocol. - Params:
chainId: number
- Returns:
-
Network
-
Network
instance if it corresponds to a supported network, or null.
-
-
- Returns a
-
tokensForNetwork
- Returns the array of
Token
s which are supported by the Synapse Protocol on a given network, based on the passed Chain ID. - Params:
chainId: number
- Returns:
-
Token[]
- Array of Tokens supported for use on the network respective to
chainId
(ifchainId
corresponds to a supported network), or null.
- Array of Tokens supported for use on the network respective to
-
- Returns the array of
-
networkSupportsToken
- Returns true if the passed token is supported by the Synapse Protocol on the passed network.
- Params:
-
network: Network | number
- This param can be either a Network instance, or the Chain ID of a Synapse Protocol-supported network.
-
token: Token
- A Token instance to check network support for.
-
- Returns:
-
boolean
-
true
iftoken
is supported by the Synapse Protocol onnetwork
,false
otherwise.
-
-
-
supportedNetworks
- Returns an array of
Network
instances corresponding to all networks supported by the Synapse Protocol. - Returns:
-
Network[]
- Array which contains the pre-defined
Network
ETH
,OPTIMISM
,CRONOS
,BSC
,POLYGON
,FANTOM
,BOBA
,METIS
,MOONBEAM
,MOONRIVER
,ARBITRUM
,AVALANCHE
,AURORA
, andHARMONY
.
- Array which contains the pre-defined
-
- Returns an array of