Skip to content

Commit

Permalink
feat: move contract variables to env
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkenj1 committed Aug 22, 2024
1 parent 9c67f9a commit 7526e66
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
9 changes: 7 additions & 2 deletions apps/api/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
PORT=3000 # Port to run the API server on
L1_RPC_URLS="" #CSV list of L2 RPC URLs
L2_RPC_URLS="" #CSV list of L1 RPC URLs

BRIDGE_HUB_ADDRESS=""
SHARED_BRIDGE_ADDRESS=""
STATE_MANAGER_ADDRESSES="" #CSV list of State managers addresses

L1_RPC_URLS="" #CSV list of L1 RPC URLs
L2_RPC_URLS="" #CSV list of L2 RPC URLs

COINGECKO_API_KEY='' # CoinGecko API key
COINGECKO_BASE_URL='' # CoinGecko API base URL for the API version you are using
Expand Down
21 changes: 17 additions & 4 deletions apps/api/src/common/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dotenv from "dotenv";
import { Address } from "viem";
import { Address, isAddress } from "viem";
import { mainnet, zksync } from "viem/chains";
import { z } from "zod";

Expand All @@ -9,6 +9,16 @@ dotenv.config();

const logger = Logger.getInstance();

const addressArraySchema = z
.string()
.transform((str) => str.split(","))
.refine((addresses) => addresses.every((address) => isAddress(address)), {
message: "Must be a comma-separated list of valid Addresses",
});
const addressSchema = z.string().refine((address) => isAddress(address), {
message: "Must be a valid Address",
});

const urlArraySchema = z
.string()
.transform((str) => str.split(","))
Expand All @@ -18,6 +28,9 @@ const urlArraySchema = z

const validationSchema = z.object({
PORT: z.coerce.number().positive().default(3000),
BRIDGE_HUB_ADDRESS: addressSchema,
SHARED_BRIDGE_ADDRESS: addressSchema,
STATE_MANAGER_ADDRESSES: addressArraySchema,
L1_RPC_URLS: urlArraySchema,
L2_RPC_URLS: z
.union([z.literal(""), urlArraySchema])
Expand Down Expand Up @@ -54,9 +67,9 @@ export const config = {
chain: zksync,
}
: undefined,
bridgeHubAddress: "0x303a465B659cBB0ab36eE643eA362c509EEb5213" as Address,
sharedBridgeAddress: "0xD7f9f54194C633F36CCD5F3da84ad4a1c38cB2cB" as Address,
stateTransitionManagerAddresses: ["0xc2eE6b6af7d616f6e27ce7F4A451Aedc2b0F5f5C"] as Address[],
bridgeHubAddress: envData.BRIDGE_HUB_ADDRESS as Address,
sharedBridgeAddress: envData.SHARED_BRIDGE_ADDRESS as Address,
stateTransitionManagerAddresses: envData.STATE_MANAGER_ADDRESSES as Address[],
pricing: {
cacheOptions: {
ttl: envData.CACHE_TTL,
Expand Down

0 comments on commit 7526e66

Please sign in to comment.