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

feat: Move subgraph endpoints to .env #147

Merged
merged 5 commits into from
Jun 11, 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
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ ARB_ONE_RPC="https://arbitrum.infura.io/v3/${INFURA_KEY}"
ARB_SEPOLIA_RPC="https://arbitrum-sepolia.infura.io/v3/${INFURA_KEY}"
MAINNET_RPC="https://mainnet.infura.io/v3/${INFURA_KEY}"
SEPOLIA_RPC="https://sepolia.infura.io/v3/${INFURA_KEY}"
L2_GATEWAY_SUBGRAPH_URL=
L2_GATEWAY_SEPOLIA_SUBGRAPH_URL=
l2NetworkID=42161
PORT=3000
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ jobs:
INFURA_KEY: '${{ secrets.INFURA_KEY }}'
MAINNET_RPC: 'https://mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}'
SEPOLIA_RPC: 'https://sepolia.infura.io/v3/${{ secrets.INFURA_KEY }}'
L2_GATEWAY_SUBGRAPH_URL: '${{ secrets.L2_GATEWAY_SUBGRAPH_URL }}'
L2_GATEWAY_SEPOLIA_SUBGRAPH_URL: '${{ secrets.L2_GATEWAY_SEPOLIA_SUBGRAPH_URL }}'

steps:
- uses: actions/checkout@v3
Expand All @@ -72,6 +74,8 @@ jobs:
INFURA_KEY: '${{ secrets.INFURA_KEY }}'
MAINNET_RPC: 'https://mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}'
SEPOLIA_RPC: 'https://sepolia.infura.io/v3/${{ secrets.INFURA_KEY }}'
L2_GATEWAY_SUBGRAPH_URL: '${{ secrets.L2_GATEWAY_SUBGRAPH_URL }}'
L2_GATEWAY_SEPOLIA_SUBGRAPH_URL: '${{ secrets.L2_GATEWAY_SEPOLIA_SUBGRAPH_URL }}'

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/generate-token-lists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ jobs:
SEPOLIA_RPC: 'https://sepolia.infura.io/v3/${{ secrets.INFURA_KEY }}'
ARB_ONE_RPC: 'https://arbitrum-mainnet.infura.io/v3/${{ secrets.INFURA_KEY }}'
ARB_SEPOLIA_RPC: 'https://arbitrum-sepolia.infura.io/v3/${{ secrets.INFURA_KEY }}'
L2_GATEWAY_SUBGRAPH_URL: '${{ secrets.L2_GATEWAY_SUBGRAPH_URL }}'
L2_GATEWAY_SEPOLIA_SUBGRAPH_URL: '${{ secrets.L2_GATEWAY_SEPOLIA_SUBGRAPH_URL }}'
steps:
- uses: actions/checkout@v3

Expand Down
6 changes: 6 additions & 0 deletions src/init.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import * as dotenv from 'dotenv';
import dotenvExpand from 'dotenv-expand';
import './customNetworks';

const myEnv = dotenv.config();
dotenvExpand.expand(myEnv);
31 changes: 13 additions & 18 deletions src/lib/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@ import { isNetwork } from './utils';
import { GraphTokenResult, GraphTokensResult } from './types';
import { excludeList } from './constants';

const apolloL2GatewaysRinkebyClient =
'https://api.thegraph.com/subgraphs/name/fredlacs/layer2-token-gateway-rinkeby';
const apolloL2GatewaysClient =
'https://api.thegraph.com/subgraphs/name/fredlacs/layer2-token-gateway';
if (!process.env.L2_GATEWAY_SUBGRAPH_URL) {
throw new Error('process.env.L2_GATEWAY_SUBGRAPH_URL is not defined');
}
const apolloL2GatewaysClient = process.env.L2_GATEWAY_SUBGRAPH_URL;

if (!process.env.L2_GATEWAY_SEPOLIA_SUBGRAPH_URL) {
throw new Error('process.env.L2_GATEWAY_SEPOLIA_SUBGRAPH_URL is not defined');
}
const apolloL2GatewaysSepoliaClient =
'https://api.thegraph.com/subgraphs/name/fionnachan/layer2-token-gateway-sepolia';
process.env.L2_GATEWAY_SEPOLIA_SUBGRAPH_URL;

const chainIdToGraphClientUrl = (chainID: string) => {
switch (chainID) {
case '42161':
return apolloL2GatewaysClient;
case '421611':
return apolloL2GatewaysRinkebyClient;
case '421614':
return apolloL2GatewaysSepoliaClient;
default:
Expand All @@ -42,11 +44,6 @@ const isGraphTokenResult = (obj: GraphTokenResult) => {
}
};

/** 421613 subgraph uses a different field name */
const graphGatewayBlockNumField = (networkID: string | number) => {
return +networkID === 421613 ? 'l2BlockNum' : 'blockNum';
};

export const getTokens = async (
tokenList: { addr: string; logo: string | undefined }[],
_networkID: string | number,
Expand Down Expand Up @@ -74,7 +71,6 @@ export const getTokens = async (
const formattedAddresses = tokenList
.map((token) => `"${token.addr}"`.toLowerCase())
.join(',');
const blockNumber = graphGatewayBlockNumField(_networkID);
const query = gql`
{
tokens(first: 500, skip: 0, where:{
Expand All @@ -83,11 +79,11 @@ export const getTokens = async (
l1TokenAddr: id
joinTableEntry: gateway(
first: 1
orderBy: ${blockNumber}
orderBy: l2BlockNum
orderDirection: desc
) {
id
${blockNumber}
l2BlockNum
token {
tokenAddr: id
}
Expand All @@ -113,18 +109,17 @@ export const getAllTokens = async (
const networkID =
typeof _networkID === 'number' ? _networkID.toString() : _networkID;
const clientUrl = chainIdToGraphClientUrl(networkID);
const blockNumber = graphGatewayBlockNumField(_networkID);
const query = gql`
{
tokens(first: 500, skip: 0) {
l1TokenAddr: id
joinTableEntry: gateway(
first: 1
orderBy: ${blockNumber}
orderBy: l2BlockNum
orderDirection: desc
) {
id
${blockNumber}
l2BlockNum
token {
tokenAddr: id
}
Expand Down
8 changes: 2 additions & 6 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import { yargsInstance } from './lib/options';
import * as dotenv from 'dotenv';
import dotenvExpand from 'dotenv-expand';

import './init';
import {
command as commandUpdate,
describe as describeUpdate,
Expand All @@ -22,10 +22,6 @@ import {
describe as describeAllTokensList,
handler as handlerAllTokensList,
} from './commands/allTokensList';
import './customNetworks';

const myEnv = dotenv.config();
dotenvExpand.expand(myEnv);

const update = yargsInstance.command(
commandUpdate,
Expand Down
Loading