diff --git a/configs/deployed.ts b/configs/deployed.ts index b2820fa..f894b03 100644 --- a/configs/deployed.ts +++ b/configs/deployed.ts @@ -17,7 +17,7 @@ export const importConfigFile = (path?: string) => { }; export const getContracts = () => { - const deployedFile = envs?.DEPLOYED || process.env.DEPLOYED; + const deployedFile = envs?.DEPLOYED; if (!deployedFile) { throw new Error("Deployed contracts file is not set, check .env file"); diff --git a/configs/envs.ts b/configs/envs.ts index 9682d1e..00df2fd 100644 --- a/configs/envs.ts +++ b/configs/envs.ts @@ -3,3 +3,13 @@ import * as dotenv from "dotenv"; const { parsed } = dotenv.config(); export const envs = parsed; +if (envs) { + envs.DEPLOYED = envs?.DEPLOYED || (process.env.DEPLOYED as string); + envs.RPC_URL_1 = envs?.RPC_URL_1 || (process.env.RPC_URL_1 as string); + envs.RPC_URL_17000 = envs?.RPC_URL_137 || (process.env.RPC_URL_137 as string); + + envs.PRIVATE_KEY_1 = + envs?.PRIVATE_KEY_1 || (process.env.PRIVATE_KEY_1 as string); + envs.PRIVATE_KEY_17000 = + envs?.PRIVATE_KEY_137 || (process.env.PRIVATE_KEY_137 as string); +} diff --git a/contracts/vault-hub.ts b/contracts/vault-hub.ts index 844b92a..4715734 100644 --- a/contracts/vault-hub.ts +++ b/contracts/vault-hub.ts @@ -3,8 +3,7 @@ import { VaultHubAbi } from "abi/VaultHub"; import { getDeployedAddress, envs } from "@configs"; export const getVaultHubContract = (chainId?: Chain) => { - const currentChainId = chainId ?? process.env.CHAIN_ID; - const rpcUrl = envs?.[`RPC_URL_${chainId || currentChainId}`]; + const rpcUrl = envs?.[`RPC_URL_${chainId || process.env.CHAIN_ID}`]; const vaultHubContract = getContract({ address: getDeployedAddress("accounting"), diff --git a/providers/wallet.ts b/providers/wallet.ts index ad318f9..48aa4eb 100644 --- a/providers/wallet.ts +++ b/providers/wallet.ts @@ -3,8 +3,7 @@ import { privateKeyToAccount } from "viem/accounts"; import { envs } from "@configs"; export const getWalletClient = (chainId?: Chain) => { - const currentChainId = chainId ?? process.env.CHAIN_ID; - const rpcUrl = envs?.[`RPC_URL_${currentChainId}`]; + const rpcUrl = envs?.[`RPC_URL_${chainId || process.env.CHAIN_ID}`]; const client = createWalletClient({ chain: chainId, @@ -15,8 +14,7 @@ export const getWalletClient = (chainId?: Chain) => { }; export const getAccount = (chainId?: Chain) => { - const currentChainId = chainId ?? process.env.CHAIN_ID; - const privateKey = envs?.[`PRIVATE_KEY_${currentChainId}`]; + const privateKey = envs?.[`PRIVATE_KEY_${chainId || process.env.CHAIN_ID}`]; if (!privateKey) { throw new Error(`PRIVATE_KEY_${chainId} is not set`); @@ -28,8 +26,7 @@ export const getAccount = (chainId?: Chain) => { }; export const getWalletWithAccount = (chainId?: Chain) => { - const currentChainId = chainId ?? process.env.CHAIN_ID; - const rpcUrl = envs?.[`RPC_URL_${currentChainId}`]; + const rpcUrl = envs?.[`RPC_URL_${chainId || process.env.CHAIN_ID}`]; const account = getAccount(chainId); const client = createWalletClient({