-
Notifications
You must be signed in to change notification settings - Fork 273
Expand file tree
/
Copy pathfactory.ts
More file actions
22 lines (19 loc) · 924 Bytes
/
factory.ts
File metadata and controls
22 lines (19 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pMemoize from 'p-memoize'
import { type RpcUrlFactory } from '@layerzerolabs/devtools'
import type { EndpointId } from '@layerzerolabs/lz-definitions'
import { RpcProvider } from 'starknet'
import type { ConnectionFactory } from './types'
export const defaultRpcUrlFactory: RpcUrlFactory = (eid) => {
throw new Error(
`No default Starknet RPC URL configured for eid ${eid}. Provide an override via createRpcUrlFactory().`
)
}
export const createRpcUrlFactory =
(overrides: Partial<Record<EndpointId, string | null>> = {}): RpcUrlFactory =>
(eid) =>
overrides[eid] ??
process.env.RPC_URL_STARKNET ??
process.env.RPC_URL_STARKNET_TESTNET ??
defaultRpcUrlFactory(eid)
export const createConnectionFactory = (urlFactory: RpcUrlFactory = defaultRpcUrlFactory): ConnectionFactory =>
pMemoize(async (eid) => new RpcProvider({ nodeUrl: await urlFactory(eid) }))