Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move all config values to config file #165

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import axios from "axios";
import { getFnftsForOwner } from "./lib/fnfts";
import { getPoints } from "./points";
import { handleGetReduxStatistics, handleUpdateReduxStatistics } from "./lib/redux";
import { AUTH_KEY, PORT } from "./config";

const app = express();
const port = process.env.PORT || 3333;

app.use(express.json());
app.use(express.raw({ type: "application/vnd.custom-type" }));
Expand Down Expand Up @@ -273,7 +273,7 @@ app.get("/points", async (req, res) => {
function isAuthorized(request: any): boolean {
const auth = request.headers.authorization;

return !!auth && auth === process.env.AUTH_KEY;
return !!auth && auth === AUTH_KEY;
}

app.post("/redux", async (req, res) => {
Expand All @@ -291,6 +291,6 @@ app.get("/redux", async (req, res) => {
return res.status(200).json(data);
});

app.listen(port, () => {
console.log(`Server is listening at http://localhost:${port}`);
app.listen(PORT, () => {
console.log(`Server is listening at http://localhost:${PORT}`);
});
19 changes: 19 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import dotenv from "dotenv";

dotenv.config();

export const PORT = parseInt(process.env.PORT || "3333");

export const AUTH_KEY = process.env.AUTH_KEY!;

export const MYSQLHOST = process.env.MYSQLHOST!;
export const MYSQLUSER = process.env.MYSQLUSER!;
export const MYSQLPASSWORD = process.env.MYSQLPASSWORD!;
export const MYSQLDATABASE = process.env.MYSQLDATABASE!;
export const MYSQLPORT = parseInt(process.env.MYSQLPORT!);

export const MAINNET_RPC_URL = process.env.MAINNET_RPC_URL!;
export const OPTIMISM_RPC_URL = process.env.OPTIMISM_RPC_URL!;
export const POLYGON_RPC_URL = process.env.POLYGON_RPC_URL!;
export const FANTOM_RPC_URL = process.env.FANTOM_RPC_URL!;
export const ARBITRUM_RPC_URL = process.env.ARBITRUM_RPC_URL!;
21 changes: 11 additions & 10 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios from "axios";
import { JsonRpcProvider, getAddress } from "ethers";
import { Pool } from "./interfaces";
import { BigNumber } from "ethers-v5";
import { ARBITRUM_RPC_URL, FANTOM_RPC_URL, MAINNET_RPC_URL, OPTIMISM_RPC_URL, POLYGON_RPC_URL } from "../config";

export const ZERO = BigNumber.from(0);
export const ONE = BigNumber.from(1);
Expand All @@ -20,19 +21,19 @@ export const SUBGRAPH_URLS: { [chainid: number]: string } = {
};

export const PROVIDER_STRING: { [chainid: number]: string } = {
1: process.env.MAINNET_RPC_URL as string,
10: process.env.OPTIMISM_RPC_URL as string,
137: process.env.POLYGON_RPC_URL as string,
250: process.env.FANTOM_RPC_URL as string,
42161: process.env.ARBITRUM_RPC_URL as string,
1: MAINNET_RPC_URL,
10: OPTIMISM_RPC_URL,
137: POLYGON_RPC_URL,
250: FANTOM_RPC_URL,
42161: ARBITRUM_RPC_URL,
};

export const PROVIDERS: { [chainId: number]: JsonRpcProvider } = {
1: new JsonRpcProvider(process.env.MAINNET_RPC_URL),
10: new JsonRpcProvider(process.env.OPTIMISM_RPC_URL),
137: new JsonRpcProvider(process.env.POLYGON_RPC_URL),
250: new JsonRpcProvider(process.env.FANTOM_RPC_URL),
42161: new JsonRpcProvider(process.env.ARBITRUM_RPC_URL),
1: new JsonRpcProvider(MAINNET_RPC_URL),
10: new JsonRpcProvider(OPTIMISM_RPC_URL),
137: new JsonRpcProvider(POLYGON_RPC_URL),
250: new JsonRpcProvider(FANTOM_RPC_URL),
42161: new JsonRpcProvider(ARBITRUM_RPC_URL),
31337: new JsonRpcProvider("http://localhost:8545"),
};

Expand Down
11 changes: 6 additions & 5 deletions src/lib/db.api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Client } from "pg";
import { MYSQLDATABASE, MYSQLHOST, MYSQLPASSWORD, MYSQLPORT, MYSQLUSER } from "../config";
import { Adapter, Oracle, Pool, VaultInfo, XRATE } from "./interfaces";
import { ReduxPerformanceEntry, ReduxStatisticsRequest } from "./redux";

const client = new Client({
host: process.env.MYSQLHOST,
user: process.env.MYSQLUSER,
password: process.env.MYSQLPASSWORD,
database: process.env.MYSQLDATABASE,
port: parseInt(process.env.MYSQLPORT!),
host: MYSQLHOST,
user: MYSQLUSER,
password: MYSQLPASSWORD,
database: MYSQLDATABASE,
port: MYSQLPORT,
});

client.connect();
Expand Down
Loading