Skip to content

Commit

Permalink
fix: env config
Browse files Browse the repository at this point in the history
  • Loading branch information
DiRaiks committed Nov 1, 2024
1 parent f4592b2 commit c9ee2a5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion configs/deployed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
10 changes: 10 additions & 0 deletions configs/envs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 1 addition & 2 deletions contracts/vault-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
9 changes: 3 additions & 6 deletions providers/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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`);
Expand All @@ -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({
Expand Down

0 comments on commit c9ee2a5

Please sign in to comment.