Skip to content

improve(NetworkUtils): Use constants CCTP information #959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { constants as ethersConstants } from "ethers";
import { CHAIN_IDs, TOKEN_SYMBOLS_MAP } from "@across-protocol/constants";

export {
CCTP_NO_DOMAIN,
ChainFamily,
CHAIN_IDs,
MAINNET_CHAIN_IDs,
PUBLIC_NETWORKS,
PRODUCTION_NETWORKS,
TESTNET_CHAIN_IDs,
TOKEN_SYMBOLS_MAP,
} from "@across-protocol/constants";
Expand Down
45 changes: 13 additions & 32 deletions src/utils/NetworkUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { ChainFamily, CHAIN_IDs, MAINNET_CHAIN_IDs, PUBLIC_NETWORKS, TESTNET_CHAIN_IDs } from "../constants";
import {
CCTP_NO_DOMAIN,
ChainFamily,
CHAIN_IDs,
MAINNET_CHAIN_IDs,
PRODUCTION_NETWORKS,
PUBLIC_NETWORKS,
TESTNET_CHAIN_IDs,
} from "../constants";

export const hreNetworks: Record<number, string> = {
666: "Hardhat1",
Expand Down Expand Up @@ -88,24 +96,6 @@ export function chainIsArbitrum(chainId: number): boolean {
return [CHAIN_IDs.ARBITRUM, CHAIN_IDs.ARBITRUM_SEPOLIA].includes(chainId);
}

/**
* Determines whether a chain ID is an Aleph0 implementation
* @param chainId Chain ID to evaluate
* @returns True if chainId is an Aleph0 chain, otherwise false.
*/
export function chainIsAlephZero(chainId: number): boolean {
return [CHAIN_IDs.ALEPH_ZERO].includes(chainId);
}

/**
* Determines whether a chain ID is a Lens implementation
* @param chainId Chain ID to evaluate
* @returns True if chainId is a Lens chain, otherwise false.
*/
export function chainIsLens(chainId: number): boolean {
return [CHAIN_IDs.LENS_SEPOLIA].includes(chainId);
}

/**
* Determines whether a chain ID is a Linea implementation.
* @param chainId Chain ID to evaluate.
Expand Down Expand Up @@ -149,19 +139,10 @@ export function chainIsSvm(chainId: number): boolean {
* @returns True if chainId is a CCTP-bridging enabled chain, otherwise false.
*/
export function chainIsCCTPEnabled(chainId: number): boolean {
return [
// Mainnets
CHAIN_IDs.ARBITRUM,
CHAIN_IDs.BASE,
CHAIN_IDs.OPTIMISM,
CHAIN_IDs.POLYGON,
CHAIN_IDs.UNICHAIN,
// Testnets
CHAIN_IDs.BASE_SEPOLIA,
CHAIN_IDs.OPTIMISM_SEPOLIA,
CHAIN_IDs.ARBITRUM_SEPOLIA,
CHAIN_IDs.POLYGON_AMOY,
].includes(chainId);
// Add chainIds to cctpExceptions to administratively disable CCTP on a chain.
// This is useful if constants has been updated to specify a CCTP domain in advance of it being activated.
const cctpExceptions: number[] = [];
return PRODUCTION_NETWORKS[chainId]?.cctpDomain !== CCTP_NO_DOMAIN && !cctpExceptions.includes(chainId);
}

/**
Expand Down