Skip to content

Commit

Permalink
Merge pull request #128 from reservoirprotocol/idan/platf-3552-simpli…
Browse files Browse the repository at this point in the history
…fy-deployment-process-relayer-phase-1

feat: move network configs to env params
  • Loading branch information
ipeleg authored May 8, 2024
2 parents afe9850 + 6f9f985 commit a6445e5
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 368 deletions.
89 changes: 1 addition & 88 deletions src/common/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,94 +22,7 @@ for (const name of Object.keys(nets)) {
}

const log = (level: "debug" | "error" | "info" | "warn") => {
let network = "unknown";
switch (config.chainId) {
case 1:
network = "mainnet";
break;

case 5:
network = "goerli";
break;

case 10:
network = "optimism";
break;

case 56:
network = "bsc";
break;

case 137:
network = "polygon";
break;

case 42161:
network = "arbitrum";
break;

case 42170:
network = "arbitrum-nova";
break;

case 43114:
network = "avalanche";
break;

case 80001:
network = "mumbai";
break;

case 80002:
network = "amoy";
break;

case 8453:
network = "base";
break;

case 84531:
network = "base-goerli";
break;

case 7777777:
network = "zora";
break;

case 999:
network = "zora-testnet";
break;

case 11155111:
network = "sepolia";
break;

case 59144:
network = "linea";
break;

case 1101:
network = "polygon-zkevm";
break;

case 324:
network = "zksync";
break;

case 81457:
network = "blast";
break;

case 534352:
network = "scroll";
break;

case 204:
network = "opbnb";
break;
}

const service = `relayer-${network}`;
const service = `relayer-${config.chainName}`;

const logger = createLogger({
exitOnError: false,
Expand Down
89 changes: 1 addition & 88 deletions src/common/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,94 +3,7 @@ import tracer from "dd-trace";
import { config } from "../config";

if (process.env.DATADOG_AGENT_URL) {
let network = "unknown";
switch (config.chainId) {
case 1:
network = "mainnet";
break;

case 5:
network = "goerli";
break;

case 10:
network = "optimism";
break;

case 56:
network = "bsc";
break;

case 137:
network = "polygon";
break;

case 42161:
network = "arbitrum";
break;

case 42170:
network = "arbitrum-nova";
break;

case 43114:
network = "avalanche";
break;

case 80001:
network = "mumbai";
break;

case 80002:
network = "amoy";
break;

case 8453:
network = "base";
break;

case 84531:
network = "base-goerli";
break;

case 7777777:
network = "zora";
break;

case 999:
network = "zora-testnet";
break;

case 11155111:
network = "sepolia";
break;

case 59144:
network = "linea";
break;

case 1101:
network = "polygon-zkevm";
break;

case 324:
network = "zksync";
break;

case 81457:
network = "blast";
break;

case 534352:
network = "scroll";
break;

case 204:
network = "opbnb";
break;
}

const service = `relayer-${network}`;
const service = `relayer-${config.chainName}`;

// TODO: Disable Redis tracing since that generates
// a lot of traces which for now are not relevant
Expand Down
5 changes: 5 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
export const config = {
port: Number(process.env.PORT),
chainId: Number(process.env.CHAIN_ID),
chainName: String(process.env.CHAIN_NAME || "unknown"),
environment: String(process.env.ENVIRONMENT),

openseaHostname: process.env.OPENSEA_HOSTNAME,
openseaChainName: process.env.OPENSEA_CHAIN_NAME,
backfillOpenseaApiKey: process.env.BACKFILL_OPENSEA_API_KEY,
realtimeOpenseaApiKey: process.env.REALTIME_OPENSEA_API_KEY,
offersOpenseaApiKey: String(process.env.OFFERS_OPENSEA_API_KEY || ""),
Expand All @@ -12,11 +15,13 @@ export const config = {
x2y2ApiKey: String(process.env.X2Y2_API_KEY),
looksrareApiKey: String(process.env.LOOKSRARE_API_KEY),
elementApiKey: String(process.env.ELEMENT_API_KEY),
elementChainName: process.env.ELEMENT_CHAIN_NAME,
coinbaseApiKey: String(process.env.COINBASE_API_KEY),
blurApiKey: String(process.env.BLUR_API_KEY),
okxApiKey: String(process.env.OKX_API_KEY),
okxSecretKey: String(process.env.OKX_SECRET_KEY),
okxPassphrase: String(process.env.OKX_PASSPHRASE),
okxChainName: process.env.OKX_CHAIN_NAME,
openseaNftApiKey: String(process.env.OPENSEA_NFT_API_KEY),

blurUrl: String(process.env.BLUR_URL),
Expand Down
70 changes: 6 additions & 64 deletions src/jobs/sync-token/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,70 +64,12 @@ if (config.doBackgroundWork) {
const [contract, tokenId] = token.split(":");
let totalOrders = 0;

let hostname = "api.opensea.io";
let network = "ethereum";
switch (config.chainId) {
case 4:
hostname = "testnets-api.opensea.io";
network = "rinkeby";
break;

case 10:
network = "optimism";
break;

case 56:
network = "bsc";
break;

case 137:
network = "matic";
break;

case 42161:
network = "arbitrum";
break;

case 42170:
network = "arbitrum_nova";
break;

case 43114:
network = "avalanche";
break;

case 80001:
hostname = "testnets-api.opensea.io";
network = "mumbai";
break;

case 80002:
hostname = "testnets-api.opensea.io";
network = "amoy";
break;

case 8453:
network = "base";
break;

case 84531:
hostname = "testnets-api.opensea.io";
network = "base_goerli";
break;

case 7777777:
network = "zora";
break;

case 999:
hostname = "testnets-api.opensea.io";
network = "zora_testnet";
break;

case 11155111:
hostname = "testnets-api.opensea.io";
network = "sepolia";
break;
const hostname = config.openseaHostname;
const network = config.openseaChainName;

if (!hostname) {
logger.debug("fast_sync_token",`${config.chainId} not supported`);
return;
}

// Fetch recent listings
Expand Down
29 changes: 1 addition & 28 deletions src/utils/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,34 +55,7 @@ export enum SaleKind {

export class Element {
public getChainName() {
switch (config.chainId) {
case 1:
return "eth";
case 10:
return "optimism";
case 56:
return "bsc";
case 137:
return "polygon";
case 204:
return "opbnb";
case 324:
return "zksync";
case 8453:
return "base";
case 42161:
return "arbitrum";
case 43114:
return "avalanche";
case 59144:
return "linea";
case 81457:
return "blast";
// case 534352:
// return "scroll";
default:
return undefined;
}
return config.elementChainName;
}

// https://api.element.market/openapi/#/
Expand Down
27 changes: 1 addition & 26 deletions src/utils/okx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,7 @@ const BASE_OKX_URL = "https://www.okx.com";

export class Okx {
public getChainName() {
switch (config.chainId) {
case 1:
return "eth";
case 10:
return "optimism";
case 56:
return "bsc";
case 137:
return "polygon";
case 324:
return "zksync-era";
case 1101:
return "polygon-zkevm";
case 8453:
return "base";
case 42161:
return "arbitrum one";
case 42170:
return "arbitrum nova";
case 43114:
return "avax";
case 59144:
return "linea";
default:
return undefined;
}
return config.okxChainName;
}

public buildAuthHeaders(url: string, method: "GET" | "POST", data?: object) {
Expand Down
Loading

0 comments on commit a6445e5

Please sign in to comment.