Skip to content

Commit 78053e8

Browse files
authored
[Eng-1179] RPC endpoint to use Alchemy. (#3240)
1 parent ad6b321 commit 78053e8

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

indexer/services/comlink/src/controllers/api/v4/skip-bridge-controller.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import {
4242
chains,
4343
getEOAAddressFromSmartAccountAddress,
4444
isSupportedEVMChainId,
45-
getRPCEndpoint,
45+
getZeroDevRPCEndpoint,
4646
publicClients,
4747
alchemyNetworkToChainIdMap,
4848
} from '../../../helpers/alchemy-helpers';
@@ -502,14 +502,14 @@ class BridgeController extends Controller {
502502

503503
const zerodevPaymaster = createZeroDevPaymasterClient({
504504
chain: chains[chainId],
505-
transport: http(getRPCEndpoint(chainId)),
505+
transport: http(getZeroDevRPCEndpoint(chainId)),
506506
});
507507

508508
const kernelClient = createKernelAccountClient({
509509
account,
510510
chain: chains[chainId],
511511
client: publicClients[chainId],
512-
bundlerTransport: http(getRPCEndpoint(chainId)),
512+
bundlerTransport: http(getZeroDevRPCEndpoint(chainId)),
513513
paymaster: zerodevPaymaster,
514514
userOperation: {
515515
estimateFeesPerGas: async ({ bundlerClient }) => {

indexer/services/comlink/src/helpers/alchemy-helpers.ts

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ export const chains: Record<string, Chain> = {
4747
[optimism.id.toString()]: optimism,
4848
};
4949

50+
export const chainInAlchemy: Record<string, string> = {
51+
[mainnet.id.toString()]: 'eth-mainnet',
52+
[arbitrum.id.toString()]: 'arb-mainnet',
53+
[avalanche.id.toString()]: 'avax-mainnet',
54+
[base.id.toString()]: 'base-mainnet',
55+
[optimism.id.toString()]: 'opt-mainnet',
56+
};
57+
5058
export const publicClients = Object.keys(chains).reduce((acc, chainId) => {
5159
acc[chainId] = createPublicClient({
52-
transport: http(getRPCEndpoint(chainId)),
60+
transport: http(getAlchemyRPCEndpoint(chainId)),
5361
chain: chains[chainId],
5462
});
5563
return acc;
@@ -216,7 +224,7 @@ async function registerAddressWithAlchemyWebhookWithRetry(
216224
*/
217225
export async function getSmartAccountAddress(address: string): Promise<string> {
218226
const publicAvalancheClient = createPublicClient({
219-
transport: http(getRPCEndpoint(avalanche.id.toString())),
227+
transport: http(getAlchemyRPCEndpoint(avalanche.id.toString())),
220228
chain: avalanche,
221229
});
222230

@@ -265,13 +273,20 @@ export function isSupportedEVMChainId(chainId: string): boolean {
265273
return Object.keys(chains).includes(chainId);
266274
}
267275

268-
export function getRPCEndpoint(chainId: string): string {
276+
export function getZeroDevRPCEndpoint(chainId: string): string {
269277
if (!isSupportedEVMChainId(chainId)) {
270278
throw new Error(`Unsupported chainId: ${chainId}`);
271279
}
272280
return `${config.ZERODEV_API_BASE_URL}/${config.ZERODEV_API_KEY}/chain/${chainId}`;
273281
}
274282

283+
export function getAlchemyRPCEndpoint(chainId: string): string {
284+
if (!isSupportedEVMChainId(chainId)) {
285+
throw new Error(`Unsupported chainId: ${chainId}`);
286+
}
287+
return `https://${chainInAlchemy[chainId]}.g.alchemy.com/v2/${config.ALCHEMY_API_KEY}`;
288+
}
289+
275290
// TODO: Verify that this function is 1000% correct. @RUI and @TYLER and @JARED
276291
export function getAddress(
277292
chainId: string,

0 commit comments

Comments
 (0)