Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
111 changes: 49 additions & 62 deletions contracts/tasks/config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
// Define supported networks and their tokens
type NetworkTokens = {
[network: string]: {
tokens: {
symbol: string;
address: string;
faucetUrl?: string;
}[];
};
};
import { chainIds } from "../config/ChainConfig";

interface Token {
symbol: string;
address: string;
faucetUrl?: string;
}

interface NetworkConfig {
tokens: Token[];
adminAccount: string;
feeRecipient: string;
}

const NETWORK_TOKENS: NetworkTokens = {
const NETWORK_CONFIGS: Record<keyof typeof chainIds, NetworkConfig> = {
localhost: {
tokens: [
{ symbol: "ETH", address: "0x0000000000000000000000000000000000000000" },
{ symbol: "WETH", address: "0x7b79995e5f793A07Bc00c21412e50Ecae098E7f9" },
{ symbol: "DAI", address: "0x779877A7B0D9E8603169DdbD7836e478b4624789" },
{ symbol: "USDC", address: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238" },
],
adminAccount: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
feeRecipient: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
},
hardhat: {
tokens: [{ symbol: "ETH", address: "0x0000000000000000000000000000000000000000" }],
adminAccount: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
feeRecipient: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
},
sepolia: {
tokens: [
Expand All @@ -36,6 +43,8 @@ const NETWORK_TOKENS: NetworkTokens = {
faucetUrl: "https://faucet.circle.com/",
},
],
adminAccount: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
feeRecipient: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
},
"optimism-mainnet": {
tokens: [
Expand All @@ -44,6 +53,8 @@ const NETWORK_TOKENS: NetworkTokens = {
{ symbol: "DAI", address: "0xda10009cbd5d07dd0cecc66161fc93d7c9000da1" },
{ symbol: "USDC", address: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85" },
],
adminAccount: "0x560adA72a80b4707e493cA8c3B7B7528930E7Be5",
feeRecipient: "0xE7C4531ad8828794904D332a12702beC8ff1A498",
},
"base-sepolia": {
tokens: [
Expand All @@ -52,6 +63,8 @@ const NETWORK_TOKENS: NetworkTokens = {
{ symbol: "DAI", address: "0xE4aB69C077896252FAFBD49EFD26B5D171A32410" },
{ symbol: "USDC", address: "0x036CbD53842c5426634e7929541eC2318f3dCF7e" },
],
adminAccount: "0xA2Cb9D926b090577AD45fC0F40C753BF369B82Ff",
feeRecipient: "0xe518aED97D9d45174a06bB8EF663B4fB51330725",
},
"arb-sepolia": {
tokens: [
Expand All @@ -60,6 +73,8 @@ const NETWORK_TOKENS: NetworkTokens = {
{ symbol: "DAI", address: "0xb1D4538B4571d411F07960EF2838Ce337FE1E80E" },
{ symbol: "USDC", address: "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d" },
],
adminAccount: "0x5d36971451AE593685Cab8815d644f9B4B66Ec99",
feeRecipient: "0x5d36971451AE593685Cab8815d644f9B4B66Ec99",
},
arbitrumOne: {
tokens: [
Expand All @@ -68,9 +83,10 @@ const NETWORK_TOKENS: NetworkTokens = {
{ symbol: "DAI", address: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1" },
{ symbol: "USDC", address: "0xaf88d065e77c8cC2239327C5EDb3A432268e5831" },
],
adminAccount: "0x14ae502FEF3843fF3a1735B3209D39B320130af9",
feeRecipient: "0xE7C4531ad8828794904D332a12702beC8ff1A498",
},
"celo-mainnet": {
//https://docs.celo.org/cel2/fee-currencies
tokens: [
{
symbol: "CELO",
Expand All @@ -89,67 +105,38 @@ const NETWORK_TOKENS: NetworkTokens = {
address: "0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e",
},
],
adminAccount: "0x14ae502FEF3843fF3a1735B3209D39B320130af9",
feeRecipient: "0xE7C4531ad8828794904D332a12702beC8ff1A498",
},
};

// New helper functions
export const getSupportedTokens = (network: string) => {
const networkConfig = NETWORK_TOKENS[network];
if (!networkConfig) {
// Helper function to get network config
function getNetworkConfig(network: keyof typeof chainIds): NetworkConfig {
const config = NETWORK_CONFIGS[network];
if (!config) {
throw new Error(`Network "${network}" is not supported`);
}
return networkConfig.tokens;
};
return config;
}

// Public API
export function getSupportedTokens(network: keyof typeof chainIds): Token[] {
return getNetworkConfig(network).tokens;
}

export const getTokenAddress = (network: string, symbol: string) => {
export function getTokenAddress(network: keyof typeof chainIds, symbol: string): string {
const tokens = getSupportedTokens(network);
const token = tokens.find((t) => t.symbol === symbol);
if (!token) {
throw new Error(`Token "${symbol}" is not supported on network "${network}"`);
}
return token.address;
};

const ADMIN_ACCOUNT: { [key: string]: string } = {
localhost: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
hardhat: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
sepolia: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
"base-sepolia": "0xA2Cb9D926b090577AD45fC0F40C753BF369B82Ff",
"optimism-mainnet": "0x560adA72a80b4707e493cA8c3B7B7528930E7Be5",
"celo-mainnet": "0x14ae502FEF3843fF3a1735B3209D39B320130af9",
base: "0x14ae502FEF3843fF3a1735B3209D39B320130af9",
arbitrumOne: "0x14ae502FEF3843fF3a1735B3209D39B320130af9",
"arb-sepolia": "0x5d36971451AE593685Cab8815d644f9B4B66Ec99",
};

export const getAdminAccount = (network: string): string => {
const account = ADMIN_ACCOUNT[network];
}

if (!account || account === null || account.trim() === "") {
throw new Error(`Admin account for network "${network}" is not defined, null, or empty.`);
}

return account;
};

const FEE_RECIPIENT: { [key: string]: string } = {
localhost: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
hardhat: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
sepolia: "0x4f37308832c6eFE5A74737955cBa96257d76De17",
"base-sepolia": "0xe518aED97D9d45174a06bB8EF663B4fB51330725",
"optimism-mainnet": "0xE7C4531ad8828794904D332a12702beC8ff1A498",
"celo-mainnet": "0xE7C4531ad8828794904D332a12702beC8ff1A498",
base: "0xE7C4531ad8828794904D332a12702beC8ff1A498",
arbitrumOne: "0xE7C4531ad8828794904D332a12702beC8ff1A498",
"arb-sepolia": "0x5d36971451AE593685Cab8815d644f9B4B66Ec99",
};
export function getAdminAccount(network: keyof typeof chainIds): string {
return getNetworkConfig(network).adminAccount;
}

export const getFeeRecipient = (network: string): string => {
const recipient = FEE_RECIPIENT[network];

if (!recipient || recipient === null || recipient.trim() === "") {
throw new Error(`Fee recipient for network "${network}" is not defined, null, or empty.`);
}

return recipient;
};
export function getFeeRecipient(network: keyof typeof chainIds): string {
return getNetworkConfig(network).feeRecipient;
}
2 changes: 1 addition & 1 deletion contracts/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"target": "ES2022",
"outDir": "dist"
},
"include": ["./tasks", "./test", "./src", "./hardhat.config.cjs", "./types", "./utils"],
"include": ["./tasks", "./test", "./src", "./hardhat.config.cjs", "./types", "./utils", "./config"],
"ts-node": {
"experimentalResolver": true,
"files": true
Expand Down