Skip to content

Commit

Permalink
Inherit Testnet Field from Viem (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith authored Oct 11, 2024
1 parent 1493cc5 commit 38d3446
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
13 changes: 0 additions & 13 deletions src/network/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
interface ChainInfo {
currencyIcon?: string;
icon?: string;
testnet: boolean;
wrappedToken: string;
}

Expand All @@ -28,82 +27,70 @@ export const CHAIN_INFO: Record<number, ChainInfo> = {
1: {
currencyIcon: ETHER,
icon: ETHEREUM_ICON,
testnet: false,
wrappedToken: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
},
// Optimism
10: {
currencyIcon: ETHER,
icon: OPTIMISM_ICON,
testnet: false,
wrappedToken: "0x4200000000000000000000000000000000000006",
},
// Binance Smart Chain
56: {
icon: BINANCE_ICON,
testnet: false,
wrappedToken: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
},
// Binance Testnet
97: {
icon: BINANCE_ICON,
testnet: true,
wrappedToken: "0x094616f0bdfb0b526bd735bf66eca0ad254ca81f",
},
// Gnosis Chain
100: {
currencyIcon: XDAI,
icon: GNOSIS_ICON,
testnet: false,
wrappedToken: "0x6a023ccd1ff6f2045c3309768ead9e68f978f6e1",
},
// Polygon
137: {
icon: POLYGON_ICON,
currencyIcon: POL,
testnet: false,
wrappedToken: "0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0",
},
// Base
8453: {
currencyIcon: ETHER,
icon: BASE_ICON,
testnet: false,
wrappedToken: "0x4200000000000000000000000000000000000006",
},
// Gnosis Chiado Testnet
10200: {
currencyIcon: XDAI,
icon: GNOSIS_ICON,
testnet: true,
wrappedToken: "0xb2D0d7aD1D4b2915390Dc7053b9421F735A723E7",
},
// Arbitrum
42161: {
currencyIcon: ETHER,
icon: ARBITRUM_ICON,
wrappedToken: "0x82af49447d8a07e3bd95bd0d56f35241523fbab1",
testnet: false,
},
// Base Sepolia
84532: {
currencyIcon: ETHER,
icon: BASE_ICON,
wrappedToken: "0x4200000000000000000000000000000000000006",
testnet: true,
},
// Arbitrum Sepolia
421614: {
currencyIcon: ETHER,
icon: ARBITRUM_ICON,
testnet: true,
wrappedToken: "0x980b62da83eff3d4576c647993b0c1d7faf17c73",
},
// Sepolia
11155111: {
currencyIcon: ETHER,
icon: ETHEREUM_ICON,
testnet: true,
wrappedToken: "0xD0A1E359811322d97991E03f863a0C30C2cF029C",
},
};
8 changes: 8 additions & 0 deletions src/network/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface NetworkFields {
chainId: number;
scanUrl: string;
icon: string | undefined;
testnet: boolean;
nativeCurrency: {
decimals: number;
name: string;
Expand All @@ -31,6 +32,7 @@ export class Network implements NetworkFields {
scanUrl: string;
client: PublicClient;
icon: string | undefined;
testnet: boolean;
nativeCurrency: {
decimals: number;
name: string;
Expand All @@ -56,6 +58,7 @@ export class Network implements NetworkFields {
this.client = createPublicClient({
transport: http(network.rpcUrl),
});
this.testnet = network.testnet;
this.nativeCurrency = nativeCurrency;
this.icon = icon;
}
Expand Down Expand Up @@ -86,6 +89,7 @@ function createNetworkMap(supportedNetworks: Chain[]): NetworkMap {
chainId: network.id,
scanUrl: network.blockExplorers?.default.url || "",
icon,
testnet: network.testnet || false,
nativeCurrency: {
...network.nativeCurrency,
wrappedAddress: chainInfo?.wrappedToken,
Expand All @@ -96,3 +100,7 @@ function createNetworkMap(supportedNetworks: Chain[]): NetworkMap {

return networkMap;
}

export function isTestnet(chainId: number): boolean {
return Network.fromChainId(chainId).testnet;
}
14 changes: 14 additions & 0 deletions tests/unit/network.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { isTestnet } from "../../src/";
describe("network", () => {
it("isTestnet", async () => {
expect(isTestnet(1)).toBe(false);
expect(isTestnet(10)).toBe(false);
expect(isTestnet(97)).toBe(true);
expect(isTestnet(100)).toBe(false);
expect(isTestnet(137)).toBe(false);
expect(isTestnet(10200)).toBe(true);
expect(isTestnet(84532)).toBe(true);
expect(isTestnet(421614)).toBe(true);
expect(isTestnet(11155111)).toBe(true);
});
});

0 comments on commit 38d3446

Please sign in to comment.