Skip to content

Commit

Permalink
feat(fvmcalibration): implement rpc auth and correct url
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bitbeckers committed Jan 18, 2025
1 parent d562062 commit 50ff665
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
15 changes: 13 additions & 2 deletions src/clients/evmClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
drpcApiPkey,
environment,
Environment,
filecoinApiKey,
infuraApiKey,
} from "@/utils/constants.js";

Expand Down Expand Up @@ -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;
}
Expand All @@ -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,
});
Expand Down
19 changes: 17 additions & 2 deletions src/indexer/chainsauce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 50ff665

Please sign in to comment.