Skip to content

Commit

Permalink
Add Base/B3 Sepolia Testnets. (#1269)
Browse files Browse the repository at this point in the history
  • Loading branch information
sentilesdal authored Jul 15, 2024
1 parent 70a4868 commit f4a2cb0
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 29 deletions.
2 changes: 2 additions & 0 deletions apps/hyperdrive-trading/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ VITE_CAPSULE_ENV=
#
# Sepolia, or
VITE_SEPOLIA_RPC_URL=
VITE_BASE_SEPOLIA_RPC_URL=
VITE_B3_SEPOLIA_RPC_URL=
#
# Mainnet
VITE_MAINNET_RPC_URL=
Expand Down
7 changes: 6 additions & 1 deletion apps/hyperdrive-trading/src/blockexplorer/makeAddressUrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assertNever from "assert-never";
import { SupportedChainId } from "src/chains/supportedChains";
import { foundry, mainnet, sepolia } from "viem/chains";
import { b3Sepolia } from "src/network/b3Sepolia";
import { baseSepolia, foundry, mainnet, sepolia } from "viem/chains";

export function makeAddressUrl(
address: string,
Expand All @@ -11,6 +12,10 @@ export function makeAddressUrl(
return `https://etherscan.io/address/${address}`;
case sepolia.id:
return `https://sepolia.etherscan.io/address/${address}`;
case baseSepolia.id:
return `https://sepolia.basescan.org/address/${address}`;
case b3Sepolia.id:
return `https://sepolia.explorer.b3.fun/address/${address}`;
case foundry.id:
return `#`;
case 42069: // Cloudchain
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assertNever from "assert-never";
import { SupportedChainId } from "src/chains/supportedChains";
import { foundry, mainnet, sepolia } from "viem/chains";
import { b3Sepolia } from "src/network/b3Sepolia";
import { baseSepolia, foundry, mainnet, sepolia } from "viem/chains";

export function makeTransactionURL(
transactionHash: string | undefined,
Expand All @@ -11,6 +12,10 @@ export function makeTransactionURL(
return `https://etherscan.io/tx/${transactionHash}`;
case sepolia.id:
return `https://sepolia.etherscan.io/tx/${transactionHash}`;
case baseSepolia.id:
return `https://sepolia.basescan.org/tx/${transactionHash}`;
case b3Sepolia.id:
return `https://sepolia.explorer.b3.fun/tx/${transactionHash}`;
case foundry.id:
return `#`;
case 42069: // cloud chain
Expand Down
5 changes: 4 additions & 1 deletion apps/hyperdrive-trading/src/chains/supportedChains.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { foundry, mainnet, sepolia } from "viem/chains";
import { b3Sepolia } from "src/network/b3Sepolia";
import { baseSepolia, foundry, mainnet, sepolia } from "viem/chains";

export const supportedChainIds = [
42069, // cloud chain
foundry.id,
mainnet.id,
sepolia.id,
baseSepolia.id,
b3Sepolia.id,
] as const;

export type SupportedChainId = (typeof supportedChainIds)[number];
28 changes: 28 additions & 0 deletions apps/hyperdrive-trading/src/network/b3Sepolia.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { defineChain } from "viem";
import { chainConfig } from "viem/op-stack";

const sourceId = 11155111;
export const b3Sepolia = defineChain({
...chainConfig,
id: 1993,
network: "b3-sepolia",
name: "B3 Sepolia",
nativeCurrency: { name: "Sepolia Ether", symbol: "ETH", decimals: 18 },
rpcUrls: {
default: {
http: ["https://b3sepolia-rpc.publicnode.com"],
},
},
blockExplorers: {
default: {
name: "Sepolia B3 Explorer",
url: "https://sepolia.explorer.b3.fun/",
apiUrl: "https://sepolia-explorer.b3.fun/api/v2/",
},
},
contracts: {
...chainConfig.contracts,
},
testnet: true,
sourceId,
});
18 changes: 16 additions & 2 deletions apps/hyperdrive-trading/src/network/wagmiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ import {
import { http } from "@wagmi/core";
import { Chain } from "@wagmi/core/chains";
import { cloudChain } from "src/chains/cloudChain";
import { b3Sepolia } from "src/network/b3Sepolia";
import { CreateWalletFn } from "src/wallets/CreateWalletFn";
import { capsuleWallet } from "src/wallets/capsule";
import { Transport } from "viem";
import { foundry, mainnet, sepolia } from "wagmi/chains";
import { baseSepolia, foundry, mainnet, sepolia } from "wagmi/chains";

const {
VITE_LOCALHOST_NODE_RPC_URL,
VITE_CUSTOM_CHAIN_NODE_RPC_URL,
VITE_CUSTOM_CHAIN_ADDRESSES_URL,
VITE_CUSTOM_CHAIN_CHAIN_ID,
VITE_WALLET_CONNECT_PROJECT_ID,
VITE_SEPOLIA_RPC_URL,
VITE_BASE_SEPOLIA_RPC_URL,
VITE_B3_SEPOLIA_RPC_URL,
VITE_MAINNET_RPC_URL,
} = import.meta.env;

Expand Down Expand Up @@ -63,6 +65,18 @@ if (VITE_SEPOLIA_RPC_URL) {
}
}

// Base Sepolia
if (VITE_BASE_SEPOLIA_RPC_URL) {
chains.push(baseSepolia);
transports[baseSepolia.id] = http(VITE_BASE_SEPOLIA_RPC_URL);
}

// B3 Sepolia
if (VITE_B3_SEPOLIA_RPC_URL) {
chains.push(b3Sepolia);
transports[b3Sepolia.id] = http(VITE_B3_SEPOLIA_RPC_URL);
}

if (VITE_MAINNET_RPC_URL) {
chains.push(mainnet);
transports[mainnet.id] = http(VITE_MAINNET_RPC_URL);
Expand Down
29 changes: 28 additions & 1 deletion apps/hyperdrive-trading/src/ui/appconfig/useAppConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,31 @@ import {
sepoliaAppConfig,
} from "@hyperdrive/appconfig";
import assertNever from "assert-never";
import { ZERO_ADDRESS } from "src/base/constants";
import { SupportedChainId } from "src/chains/supportedChains";
import { foundry, mainnet, sepolia } from "viem/chains";
import { b3Sepolia } from "src/network/b3Sepolia";
import { baseSepolia, foundry, mainnet, sepolia } from "viem/chains";
import { useChainId } from "wagmi";

const emptyAppConfig: AppConfig = {
chainId: 0,
tags: [],
registryAddress: ZERO_ADDRESS,
hyperdrives: [],
tokens: [],
protocols: {},
};

const baseSepoliaAppConfig: AppConfig = {
...emptyAppConfig,
chainId: baseSepolia.id,
};

const b3SepoliaAppConfig: AppConfig = {
...emptyAppConfig,
chainId: b3Sepolia.id,
};

export function useAppConfig(): AppConfig {
const chainId = useChainId() as SupportedChainId;
switch (chainId) {
Expand All @@ -25,6 +46,12 @@ export function useAppConfig(): AppConfig {
case sepolia.id:
return sepoliaAppConfig;

case baseSepolia.id:
return baseSepoliaAppConfig;

case b3Sepolia.id:
return b3SepoliaAppConfig;

default:
assertNever(chainId);
}
Expand Down
12 changes: 4 additions & 8 deletions packages/hyperdrive-appconfig/src/chains/cloudChain.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { Chain } from "viem";
import { defineChain } from "viem";

export const cloudChain: Chain = {
export const cloudChain = defineChain({
id: +(process.env.CLOUDCHAIN_CHAIN_ID as string),
name: "☁️ \u00A0 Chain",
nativeCurrency: {
decimals: 18,
name: "Ether",
symbol: "ETH",
},
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
rpcUrls: {
public: { http: [process.env.CLOUDCHAIN_NODE_RPC_URL as string] },
default: { http: [process.env.CLOUDCHAIN_NODE_RPC_URL as string] },
},
};
});
66 changes: 51 additions & 15 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@
"$schema": "https://turborepo.org/schema.json",
"tasks": {
"build:crates": {
"dependsOn": ["^build"],
"outputs": ["packages/hyperdrive-wasm/**", "packages/fixed-point-wasm/**"]
"dependsOn": [
"^build"
],
"outputs": [
"packages/hyperdrive-wasm/**",
"packages/fixed-point-wasm/**"
]
},
"build": {
"dependsOn": ["build:crates", "^build"],
"outputs": ["dist/**", ".next/**"]
"dependsOn": [
"build:crates",
"^build"
],
"outputs": [
"dist/**",
".next/**"
]
},
"hyperdrive-trading#build": {
"dependsOn": ["^build"],
"dependsOn": [
"^build"
],
"env": [
"DEV",
"VITE_CUSTOM_CHAIN_NODE_RPC_URL",
Expand All @@ -19,35 +32,58 @@
"VITE_CUSTOM_CHAIN_ADDRESSES_URL",
"VITE_WALLET_CONNECT_PROJECT_ID",
"VITE_SEPOLIA_RPC_URL",
"VITE_BASE_SEPOLIA_RPC_URL",
"VITE_B3_SEPOLIA_RPC_URL",
"VITE_MAINNET_RPC_URL",
"VITE_CAPSULE_API_KEY",
"VITE_CAPSULE_ENV",
"VITE_ADDRESS_SCREEN_URL",
"VITE_ROLLBAR_ACCESS_TOKEN",
"VITE_ROLLBAR_ENV"
],
"outputs": ["dist/**", ".next/**"]
"outputs": [
"dist/**",
".next/**"
]
},
"lint": {
"dependsOn": ["^build"],
"dependsOn": [
"^build"
],
"outputs": []
},
"typecheck": {
"dependsOn": ["^build"],
"dependsOn": [
"^build"
],
"outputs": []
},
"dev": {
"cache": false
},
"format": { "outputs": [] },
"format:check": { "outputs": [] },
"format": {
"outputs": []
},
"format:check": {
"outputs": []
},
"test": {
"dependsOn": ["build"],
"inputs": ["test/**/*.ts", "test/**/*.tsx"]
"dependsOn": [
"build"
],
"inputs": [
"test/**/*.ts",
"test/**/*.tsx"
]
},
"test:run": {
"dependsOn": ["build"],
"inputs": ["test/**/*.ts", "test/**/*.tsx"]
"dependsOn": [
"build"
],
"inputs": [
"test/**/*.ts",
"test/**/*.tsx"
]
}
}
}
}

0 comments on commit f4a2cb0

Please sign in to comment.