Skip to content

Commit

Permalink
Update env var method
Browse files Browse the repository at this point in the history
Signed-off-by: Evaldo Felipe <[email protected]>
  • Loading branch information
evaldofelipe committed Jan 22, 2025
1 parent 80994e6 commit 565bf16
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 17 deletions.
1 change: 1 addition & 0 deletions api/_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
8 changes: 7 additions & 1 deletion api/_dexes/1inch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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",
};

Expand Down
29 changes: 17 additions & 12 deletions api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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 || "{}");
Expand All @@ -117,19 +122,19 @@ 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
// above constant `DISABLED_CHAINS`, this constant is used to disable 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 =
Expand Down Expand Up @@ -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":
Expand Down
4 changes: 3 additions & 1 deletion api/coingecko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
4 changes: 3 additions & 1 deletion api/cron-cache-balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Record<string, never>>,
response: VercelResponse
Expand All @@ -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
? []
Expand Down
3 changes: 2 additions & 1 deletion api/limits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion api/suggested-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
AmountTooHighError,
AmountTooLowError,
} from "./_errors";
import { getEnvs } from "./_env";

const { BigNumber } = ethers;

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 565bf16

Please sign in to comment.