/** * Types */ /** * IDs of Currently Supported Chains */ export enum ChainId { Celo = 42220, Alfajores = 44787, } /** * Represents an Etherem 20B address */ export type Address = string; export type BigNumberString = string; export interface TransactionOptions { feeCurrency?: Address; } /** * Interval type used for historical queries */ export enum Interval { FiveMinute = 0, FifteenMinute = 1, ThirtyMinute = 2, Hour = 3, Day = 4, } export interface CustomRPC { http?: string; wss?: string; } type Time = "hour" | "day" | "week" | "month" | "year"; /** * Timeframe type used for historical queries */ export type TimeFrame = Time | `${number} ${Time}s` | "all"; export enum Rounding { ROUND_DOWN, ROUND_HALF_UP, ROUND_UP, } export interface PageInfo { currentPage: number; totalPages: number; perPage: number; total: number; } export enum DateRange { "1H" = 0, "1D" = 1, "1W" = 7, "1M" = 30, "1Y" = 365, ALL = -1, } /** * API Endpoints */ export const API_BASE = "https://us-central1-node-wallet.cloudfunctions.net"; export const WALLET_SERVICE_URL = process.env.NODE_ENV === "sdk_development" ? "http://localhost:8080/" : "https://wallets.nodefinance.org/"; const SWAP_API_BASE = "https://router.nodefinance.org"; export const formatAllPricesQuery = () => `${API_BASE}/api/Prices`; export const formatHistoricalPricesQuery = ( address: string, interval: number, timeframe: string, currency: string ) => `${API_BASE}/api/Prices/${address}?interval=${interval}&period=${timeframe}¤cy=${currency}`; export const formatHeader = (apiKey: string) => ({ "x-api-key": apiKey, }); export const formatRouteRequest = () => `${SWAP_API_BASE}/routes`; export const formatDepositRequest = ( tokenIn: Address, amountIn: BigNumberString, tokenOut: Address ) => `${SWAP_API_BASE}/earn/deposit?tokenIn=${tokenIn}&tokenOut=${tokenOut}&amountIn=${amountIn}`; export const formatWithdrawRequest = ( tokenIn: Address, amountIn: BigNumberString, tokenOut?: Address ) => `${SWAP_API_BASE}/earn/withdraw?tokenIn=${tokenIn}&amountIn=${amountIn}${ tokenOut ? `&tokenOut=${tokenOut}` : "" }`; export const chainsSupportingAlternateGas = new Set([ ChainId.Alfajores, ChainId.Celo, ]); /** * Chain-Specific Values */ export const DEFAULT_RPC = "https://necessary-muddy-research.celo-mainnet.discover.quiknode.pro/3577f3bb994031ee8c5dfa75313b24bfa4cffd1e/"; export const DEFAULT_CHAIN = ChainId.Celo; /** * RPC Links for a given chain */ export const CHAINS_TO_RPC: { [id in ChainId]: { http: string; wss?: string; }; } = { [ChainId.Celo]: { http: "https://necessary-muddy-research.celo-mainnet.discover.quiknode.pro/3577f3bb994031ee8c5dfa75313b24bfa4cffd1e/", wss: "wss://necessary-muddy-research.celo-mainnet.discover.quiknode.pro/3577f3bb994031ee8c5dfa75313b24bfa4cffd1e/", }, [ChainId.Alfajores]: { http: "https://alfajores-forno.celo-testnet.org", wss: "wss://alfajores-forno.celo-testnet.org/ws", }, }; /** * Overrides the RPC for a given chain * * @param chain ChainId to override the RPC for * @param rpc https and wss rpc endpoints to override * @returns */ export const OverrideRPC = (chain: ChainId, rpc: Partial) => (CHAINS_TO_RPC[chain] = { ...CHAINS_TO_RPC[chain], ...rpc }); export const MULTICALL_NETWORKS: Record = { [ChainId.Celo]: "0x75f59534dd892c1f8a7b172d639fa854d529ada3", [ChainId.Alfajores]: "0x75f59534dd892c1f8a7b172d639fa854d529ada3", }; export const WALLET_FACTORY_ADDRESS: { [chain in ChainId]: Address } = { [ChainId.Celo]: "0x7cEEa70d90DCaF872b53861Cc53Bf3009e4a3a7D", [ChainId.Alfajores]: "0x1838A442Bc805D887dEfd5fF58E75ff820F673c2", }; /** * Type Translations */ export const dateRangeToReadable: { [range in DateRange]: string } = { [DateRange["1D"]]: "day", [DateRange["1H"]]: "hour", [DateRange["1M"]]: "month", [DateRange["1W"]]: "week", [DateRange["1Y"]]: "year", [DateRange.ALL]: "all", }; export const dateRangeToDefaultInterval: { [range in DateRange]: number } = { [DateRange["1D"]]: 1, [DateRange["1H"]]: 0, [DateRange["1M"]]: 3, [DateRange["1W"]]: 1, [DateRange["1Y"]]: 4, [DateRange.ALL]: 4, }; /** * Makes API Key Globally Accessible */ let NODE_API_KEY = ""; export const getNodeApiKey = () => NODE_API_KEY; export const setNodeApiKey = (s: string) => (NODE_API_KEY = s);