From 50ff6652bab0fc254d223be67a57ea90b9dd92df Mon Sep 17 00:00:00 2001 From: bitbeckers Date: Sat, 18 Jan 2025 11:27:10 +0100 Subject: [PATCH] feat(fvmcalibration): implement rpc auth and correct url Updates the chainsauce and rpc builder to correctly use the FVM api key to call on the calibration archive node. The max block range for requests was reduces to meet the FVM limitations. Additionally, the filecoin API key was added to constants. --- src/clients/evmClient.ts | 15 +++++++++++++-- src/indexer/chainsauce.ts | 19 +++++++++++++++++-- src/utils/constants.ts | 5 +++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/clients/evmClient.ts b/src/clients/evmClient.ts index 01fe34e..2de1fed 100644 --- a/src/clients/evmClient.ts +++ b/src/clients/evmClient.ts @@ -14,6 +14,7 @@ import { drpcApiPkey, environment, Environment, + filecoinApiKey, infuraApiKey, } from "@/utils/constants.js"; @@ -118,7 +119,7 @@ const drpcUrl = (chainId: number) => { const glifUrl = (chainId: number) => { switch (chainId) { case 314159: - return `https://api.calibration.node.glif.io/rpc/v1`; + return `https://calibration.node.glif.io/archive/lotus/rpc/v1`; default: return; } @@ -145,8 +146,18 @@ const fallBackProvider = (chainId: number) => { ? [http(drpcUrl(chainId), { timeout: rpc_timeout })] : []; const glif = glifUrl(chainId) - ? [http(glifUrl(chainId), { timeout: rpc_timeout })] + ? [ + http(glifUrl(chainId), { + timeout: rpc_timeout, + fetchOptions: { + headers: { + Authorization: `Bearer ${filecoinApiKey}`, + }, + }, + }), + ] : []; + return fallback([...alchemy, ...drpc, ...infura, ...glif], { retryCount: 5, }); diff --git a/src/indexer/chainsauce.ts b/src/indexer/chainsauce.ts index a482ad7..6b0098f 100644 --- a/src/indexer/chainsauce.ts +++ b/src/indexer/chainsauce.ts @@ -6,6 +6,7 @@ import { processEvent } from "@/indexer/eventHandlers.js"; import { Environment, environment, + filecoinApiKey, localCachingDbUrl, } from "@/utils/constants.js"; import { getContractEventsForChain } from "@/storage/getContractEventsForChain.js"; @@ -38,6 +39,18 @@ const MyContracts = { EAS: EasAbi, }; +const fetchWithAuth = (token: string) => { + return (url: string | URL | globalThis.Request, options: RequestInit = {}) => { + return fetch(url, { + ...options, + headers: { + ...options.headers, + 'Authorization': `Bearer ${token}`, + }, + }); + }; +}; + export const getIndexer = async ({ chainId, requestQueue, @@ -56,12 +69,14 @@ export const getIndexer = async ({ schemaName: `cache_${chainId}`, }); + const httpRpcClient = chainId === 314159 ? createHttpRpcClient({ url: rpcUrl, fetch: fetchWithAuth(filecoinApiKey) }) : createHttpRpcClient({ url: rpcUrl }); + const indexer = createIndexer({ cache, chain: { id: chainId, - maxBlockRange: 100000n, - rpcClient: createHttpRpcClient({ url: rpcUrl }), + maxBlockRange: 60480n, + rpcClient: httpRpcClient, pollingInterval: environment === Environment.TEST ? 10000 : 5000, }, contracts: MyContracts, diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 71310df..33f7bb2 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -22,6 +22,11 @@ export const drpcApiPkey = assertExists( "dRPC API KEY", ); +export const filecoinApiKey = assertExists( + process.env.FILECOIN_API_KEY, + "Filecoin API KEY", +); + export const port = Number(assertExists(process.env.PORT, "Port")); export const supabaseApiKey = assertExists(