From 313ab05801eb243a34de77766a51c65f81ab3bac Mon Sep 17 00:00:00 2001 From: Layne Haber Date: Thu, 4 Jul 2024 11:00:37 +0200 Subject: [PATCH] feat: use process.env var for RPC --- adapters/connext/package.json | 3 ++- adapters/connext/src/utils/assets.ts | 8 ++++---- adapters/connext/src/utils/index.ts | 2 ++ adapters/connext/src/utils/rpc.ts | 8 ++++++++ adapters/connext/src/utils/subgraph.ts | 5 ++--- adapters/connext/yarn.lock | 9 +++++++-- 6 files changed, 25 insertions(+), 10 deletions(-) create mode 100644 adapters/connext/src/utils/rpc.ts diff --git a/adapters/connext/package.json b/adapters/connext/package.json index 9f3910ca..ff795c65 100644 --- a/adapters/connext/package.json +++ b/adapters/connext/package.json @@ -17,7 +17,8 @@ "dependencies": { "@connext/nxtp-utils": "2.4.1", "fast-csv": "5.0.1", - "csv-parser": "^3.0.0", + "csv-parser": "3.0.0", + "dotenv": "16.4.5", "viem": "2.8.16" }, "devDependencies": { diff --git a/adapters/connext/src/utils/assets.ts b/adapters/connext/src/utils/assets.ts index bae33991..fff00c2d 100644 --- a/adapters/connext/src/utils/assets.ts +++ b/adapters/connext/src/utils/assets.ts @@ -1,8 +1,8 @@ -import { createPublicClient, http, parseUnits } from "viem"; -import { linea } from "viem/chains"; +import { parseUnits } from "viem"; import { getPoolInformationFromLpToken, poolInfo } from "./cartographer"; import { LINEA_CHAIN_ID, CONNEXT_LINEA_ADDRESS } from "./subgraph"; -import { LpAccountBalanceHourly, RouterEventResponse } from "./types"; +import { LpAccountBalanceHourly } from "./types"; +import { getClient } from "./rpc"; type CompositeBalanceHourly = LpAccountBalanceHourly & { underlyingTokens: string[]; @@ -43,7 +43,7 @@ export const getCompositeBalances = async (amms: LpAccountBalanceHourly[]): Prom } // get contract interface - const client = createPublicClient({ chain: linea, transport: http() }); + const client = getClient(); // get composite balances for amms (underlying tokens and balances) const balances = await Promise.all(amms.map(async ({ token, amount, block }) => { diff --git a/adapters/connext/src/utils/index.ts b/adapters/connext/src/utils/index.ts index 7745adbe..6b602e25 100644 --- a/adapters/connext/src/utils/index.ts +++ b/adapters/connext/src/utils/index.ts @@ -1,4 +1,6 @@ export * from "./cartographer"; export * from "./csv"; export * from "./getUserTvlByBlock"; +export * from "./rpc"; +export * from "./subgraph"; export * from "./types"; \ No newline at end of file diff --git a/adapters/connext/src/utils/rpc.ts b/adapters/connext/src/utils/rpc.ts new file mode 100644 index 00000000..35063d97 --- /dev/null +++ b/adapters/connext/src/utils/rpc.ts @@ -0,0 +1,8 @@ +import { createPublicClient, http } from "viem"; +import { linea } from "viem/chains"; +import { config } from "dotenv"; + +export const getClient = () => { + config(); + return createPublicClient({ chain: linea, transport: http(process.env.CONNEXT_LINEA_RPC) }); +} \ No newline at end of file diff --git a/adapters/connext/src/utils/subgraph.ts b/adapters/connext/src/utils/subgraph.ts index bf7ed83a..e8b4a87c 100644 --- a/adapters/connext/src/utils/subgraph.ts +++ b/adapters/connext/src/utils/subgraph.ts @@ -1,6 +1,5 @@ +import { getClient } from "./rpc"; import { LpAccountBalanceHourly, SubgraphResult } from "./types"; -import { linea } from "viem/chains"; -import { createPublicClient, http } from "viem"; export const CONNEXT_SUBGRAPH_QUERY_URL = "https://api.goldsky.com/api/public/project_clssc64y57n5r010yeoly05up/subgraphs/connext/stableswap-analytics-linea-0.0.1/gn"; export const LINEA_CHAIN_ID = 59144; @@ -146,7 +145,7 @@ const appendSubgraphData = (data: LpAccountBalanceHourly[], existing: Map { - const client = createPublicClient({ chain: linea, transport: http() }); + const client = getClient(); const block = await client.getBlock({ blockNumber: BigInt(blockNumber) }); return block; } \ No newline at end of file diff --git a/adapters/connext/yarn.lock b/adapters/connext/yarn.lock index 8d2e75f2..0b2e7696 100644 --- a/adapters/connext/yarn.lock +++ b/adapters/connext/yarn.lock @@ -1177,9 +1177,9 @@ crypto-js@^3.1.9-1: resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-3.3.0.tgz" integrity sha512-DIT51nX0dCfKltpRiXV+/TVZq+Qq2NgF4644+K7Ttnla7zEzqc+kjJyiB96BHNyUTBxyjzRcZYpUdZa+QAqi6Q== -csv-parser@^3.0.0: +csv-parser@3.0.0: version "3.0.0" - resolved "https://registry.npmjs.org/csv-parser/-/csv-parser-3.0.0.tgz" + resolved "https://registry.yarnpkg.com/csv-parser/-/csv-parser-3.0.0.tgz#b88a6256d79e090a97a1b56451f9327b01d710e7" integrity sha512-s6OYSXAK3IdKqYO33y09jhypG/bSDHPuyCme/IdEHfWpLf/jKcpitVFyOC6UemgGk8v7Q5u2XE0vvwmanxhGlQ== dependencies: minimist "^1.2.0" @@ -1279,6 +1279,11 @@ dom-walk@^0.1.0: resolved "https://registry.npmjs.org/dom-walk/-/dom-walk-0.1.2.tgz" integrity sha512-6QvTW9mrGeIegrFXdtQi9pk7O/nSK6lSdXW2eqUspN5LWD7UTji2Fqw5V2YLjBpHEoU9Xl/eUWNpDeZvoyOv2w== +dotenv@16.4.5: + version "16.4.5" + resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f" + integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg== + ecc-jsbn@~0.1.1: version "0.1.2" resolved "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz"