Skip to content

Commit

Permalink
TON client api factory (#1153)
Browse files Browse the repository at this point in the history
  • Loading branch information
KaiStevenson authored Jan 10, 2025
1 parent e455d72 commit de8f24f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-cows-boil.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/devtools-ton": minor
---

Added API key factory param to TON client factory
15 changes: 12 additions & 3 deletions packages/devtools-ton/src/omnigraph/coordinates.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TonClient } from '@ton/ton'
import pMemoize from 'p-memoize'

import { formatEid, OmniPoint, type RpcUrlFactory } from '@layerzerolabs/devtools'
import { EndpointBasedFactory, formatEid, OmniPoint, type RpcUrlFactory } from '@layerzerolabs/devtools'
import { ChainType, EndpointId, endpointIdToChainType } from '@layerzerolabs/lz-definitions'

import { TonClientFactory } from './types'
Expand Down Expand Up @@ -38,5 +38,14 @@ export const createRpcUrlFactory =
(eid) =>
overrides[eid] ?? defaultRpcUrlFactory(eid)

export const createTonClientFactory = (urlFactory: RpcUrlFactory = defaultRpcUrlFactory): TonClientFactory =>
pMemoize(async (eid) => new TonClient({ endpoint: await urlFactory(eid) }))
export const createTonClientFactory = (
urlFactory: RpcUrlFactory = defaultRpcUrlFactory,
apiKeyFactory?: EndpointBasedFactory<string>
): TonClientFactory =>
pMemoize(
async (eid) =>
new TonClient({
endpoint: await urlFactory(eid),
...(apiKeyFactory ? { apiKey: await apiKeyFactory(eid) } : {}),
})
)

0 comments on commit de8f24f

Please sign in to comment.