diff --git a/api/_cache.ts b/api/_cache.ts index 1c730e1a6..b22cdd2b7 100644 --- a/api/_cache.ts +++ b/api/_cache.ts @@ -10,6 +10,7 @@ const { UPSTASH_REDIS_REST_TOKEN, UPSTASH_REDIS_READ_ONLY_TOKEN, } = getEnvs(); + const isRedisCacheEnabled = (KV_REST_API_URL && (KV_REST_API_TOKEN || KV_REST_API_READ_ONLY_TOKEN)) || (UPSTASH_REDIS_REST_URL && diff --git a/api/_dexes/1inch.ts b/api/_dexes/1inch.ts index 98b47026e..2d867d70b 100644 --- a/api/_dexes/1inch.ts +++ b/api/_dexes/1inch.ts @@ -2,6 +2,12 @@ import axios from "axios"; import { AcrossSwap, SwapQuoteAndCalldata } from "./types"; import { getSwapAndBridgeAddress } from "./utils"; +import { getEnvs } from "../_env"; + +const { + ONEINCH_API_KEY, +} = getEnvs(); + export async function get1inchQuoteAndCalldata( swap: AcrossSwap @@ -12,7 +18,7 @@ export async function get1inchQuoteAndCalldata( ); const apiBaseUrl = `https://api.1inch.dev/swap/v6.0/${swap.swapToken.chainId}`; const apiHeaders = { - Authorization: `Bearer ${process.env.ONEINCH_API_KEY}`, + Authorization: `Bearer ${ONEINCH_API_KEY}`, accept: "application/json", }; diff --git a/api/_utils.ts b/api/_utils.ts index 7fa3fd543..8bda89ca1 100644 --- a/api/_utils.ts +++ b/api/_utils.ts @@ -34,8 +34,6 @@ import { Struct, } from "superstruct"; -import { getEnvs } from "./_env"; - import enabledMainnetRoutesAsJson from "../src/data/routes_1_0xc186fA914353c44b2E33eBE05f21846F1048bEda.json"; import enabledSepoliaRoutesAsJson from "../src/data/routes_11155111_0x14224e63716afAcE30C9a417E0542281869f7d9e.json"; import rpcProvidersJson from "../src/data/rpc-providers.json"; @@ -77,11 +75,7 @@ import { InvalidParamError, RouteNotEnabledError, } from "./_errors"; - -export { InputError, handleErrorCondition } from "./_errors"; - -type LoggingUtility = sdk.relayFeeCalculator.Logger; -type RpcProviderName = keyof typeof rpcProvidersJson.providers.urls; +import { getEnvs } from "./_env"; const { REACT_APP_HUBPOOL_CHAINID, @@ -91,8 +85,19 @@ const { PRIORITY_FEE_MARKUP, VERCEL_ENV, LOG_LEVEL, + REACT_APP_DISABLED_CHAINS, + REACT_APP_DISABLED_CHAINS_FOR_AVAILABLE_ROUTES, + REACT_APP_DISABLED_TOKENS_FOR_AVAILABLE_ROUTES, + VERCEL_URL, } = getEnvs(); + +export { InputError, handleErrorCondition } from "./_errors"; + +type LoggingUtility = sdk.relayFeeCalculator.Logger; +type RpcProviderName = keyof typeof rpcProvidersJson.providers.urls; + + export const baseFeeMarkup: { [chainId: string]: number; } = JSON.parse(BASE_FEE_MARKUP || "{}"); @@ -117,7 +122,7 @@ export const DISABLED_ROUTE_TOKENS = ( // temporarily without having to redeploy the app or change core config // data (e.g. the ENABLED_ROUTES object and the data/routes.json files). export const DISABLED_CHAINS = ( - process.env.REACT_APP_DISABLED_CHAINS || "" + REACT_APP_DISABLED_CHAINS || "" ).split(","); // This is an array of chainIds that should be disabled. In contrast to the @@ -125,11 +130,11 @@ export const DISABLED_CHAINS = ( // only for the `/available-routes` endpoint and DOES NOT affect the // `ENABLED_ROUTES` object. export const DISABLED_CHAINS_FOR_AVAILABLE_ROUTES = ( - process.env.REACT_APP_DISABLED_CHAINS_FOR_AVAILABLE_ROUTES || "" + REACT_APP_DISABLED_CHAINS_FOR_AVAILABLE_ROUTES || "" ).split(","); export const DISABLED_TOKENS_FOR_AVAILABLE_ROUTES = ( - process.env.REACT_APP_DISABLED_TOKENS_FOR_AVAILABLE_ROUTES || "" + REACT_APP_DISABLED_TOKENS_FOR_AVAILABLE_ROUTES || "" ).split(","); const _ENABLED_ROUTES = @@ -198,8 +203,8 @@ export const getLogger = (): LoggingUtility => { * @returns A valid URL of the current endpoint in vercel */ export const resolveVercelEndpoint = () => { - const url = process.env.VERCEL_URL ?? "across.to"; - const env = process.env.VERCEL_ENV ?? "development"; + const url = VERCEL_URL ?? "across.to"; + const env = VERCEL_ENV ?? "development"; switch (env) { case "preview": case "production": diff --git a/api/coingecko.ts b/api/coingecko.ts index 5fe4d58f5..ea5edc833 100644 --- a/api/coingecko.ts +++ b/api/coingecko.ts @@ -24,11 +24,13 @@ import { InvalidParamError } from "./_errors"; import { coingecko } from "@across-protocol/sdk"; const { Coingecko } = coingecko; + +import { getEnvs } from "./_env"; const { REACT_APP_COINGECKO_PRO_API_KEY, REDIRECTED_TOKEN_PRICE_LOOKUP_ADDRESSES, BALANCER_V2_TOKENS, -} = process.env; +} = getEnvs(); const CoingeckoQueryParamsSchema = object({ l1Token: optional(validAddress()), diff --git a/api/cron-cache-balances.ts b/api/cron-cache-balances.ts index 4618e6098..0093d48b8 100644 --- a/api/cron-cache-balances.ts +++ b/api/cron-cache-balances.ts @@ -13,6 +13,8 @@ import { UnauthorizedError } from "./_errors"; import mainnetChains from "../src/data/chains_1.json"; +import { getEnvs } from "./_env"; + const handler = async ( request: TypedVercelRequest>, response: VercelResponse @@ -34,7 +36,7 @@ const handler = async ( const { REACT_APP_FULL_RELAYERS, // These are relayers running a full auto-rebalancing strategy. REACT_APP_TRANSFER_RESTRICTED_RELAYERS, // These are relayers whose funds stay put. - } = process.env; + } = getEnvs(); const fullRelayers = !REACT_APP_FULL_RELAYERS ? [] diff --git a/api/limits.ts b/api/limits.ts index fcfc29a33..643e08187 100644 --- a/api/limits.ts +++ b/api/limits.ts @@ -4,6 +4,7 @@ import { BigNumber, ethers } from "ethers"; import { CHAIN_IDs, DEFAULT_SIMULATED_RECIPIENT_ADDRESS } from "./_constants"; import { TokenInfo, TypedVercelRequest } from "./_types"; import { object, assert, Infer, optional, string } from "superstruct"; +import { getEnvs } from "./_env"; import { ENABLED_ROUTES, @@ -67,7 +68,7 @@ const handler = async ( REACT_APP_TRANSFER_RESTRICTED_RELAYERS, // These are relayers whose funds stay put. MIN_DEPOSIT_USD, // The global minimum deposit in USD for all destination chains. The minimum deposit // returned by the relayerFeeDetails() call will be floor'd with this value (after converting to token units). - } = process.env; + } = getEnvs(); const provider = getProvider(HUB_POOL_CHAIN_ID); const fullRelayers = !REACT_APP_FULL_RELAYERS diff --git a/api/suggested-fees.ts b/api/suggested-fees.ts index a1ad89a28..97d4c28b3 100644 --- a/api/suggested-fees.ts +++ b/api/suggested-fees.ts @@ -39,6 +39,7 @@ import { AmountTooHighError, AmountTooLowError, } from "./_errors"; +import { getEnvs } from "./_env"; const { BigNumber } = ethers; @@ -70,7 +71,7 @@ const handler = async ( query, }); try { - const { QUOTE_BLOCK_BUFFER, QUOTE_BLOCK_PRECISION } = process.env; + const { QUOTE_BLOCK_BUFFER, QUOTE_BLOCK_PRECISION } = getEnvs(); const provider = getProvider(HUB_POOL_CHAIN_ID, { useSpeedProvider: true,