From 55a97144d7e08be6ce6772df2861b1132ca456d1 Mon Sep 17 00:00:00 2001 From: yonada Date: Tue, 30 Apr 2024 22:10:04 +0100 Subject: [PATCH] feat(common): add indexer URL to chain configs (#2771) Co-authored-by: Kevin Ingersoll --- .changeset/lemon-apples-march.md | 5 +++++ .changeset/rotten-rules-switch.md | 5 +++++ packages/common/src/chains/garnet.ts | 1 + packages/common/src/chains/redstone.ts | 1 + packages/common/src/chains/types.ts | 1 + packages/store-sync/src/common.ts | 2 +- packages/store-sync/src/createStoreSync.ts | 10 +++++++++- 7 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 .changeset/lemon-apples-march.md create mode 100644 .changeset/rotten-rules-switch.md diff --git a/.changeset/lemon-apples-march.md b/.changeset/lemon-apples-march.md new file mode 100644 index 0000000000..e694ed7ac5 --- /dev/null +++ b/.changeset/lemon-apples-march.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/store-sync": patch +--- + +Updated `createStoreSync` to default to the chain's indexer URL when no `indexerUrl` is passed in. To intentionally unset the value and not use the indexer at all, `indexerUrl` can now also be `false`. diff --git a/.changeset/rotten-rules-switch.md b/.changeset/rotten-rules-switch.md new file mode 100644 index 0000000000..c80e7d88bc --- /dev/null +++ b/.changeset/rotten-rules-switch.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/common": patch +--- + +Added an optional `indexerUrl` property to `MUDChain`, and populated it in the Redstone and Garnet chain configs. diff --git a/packages/common/src/chains/garnet.ts b/packages/common/src/chains/garnet.ts index 971e204cf7..e4e95141d8 100644 --- a/packages/common/src/chains/garnet.ts +++ b/packages/common/src/chains/garnet.ts @@ -22,6 +22,7 @@ export const garnet = { url: "https://explorer.garnetchain.com", }, }, + indexerUrl: "https://indexer.mud.garnetchain.com", contracts: { ...chainConfig.contracts, multicall3: { diff --git a/packages/common/src/chains/redstone.ts b/packages/common/src/chains/redstone.ts index 6936a6570e..99eccc0c37 100644 --- a/packages/common/src/chains/redstone.ts +++ b/packages/common/src/chains/redstone.ts @@ -21,6 +21,7 @@ export const redstone = { url: "https://explorer.redstone.xyz", }, }, + indexerUrl: "https://indexer.mud.redstonechain.com", contracts: { ...chainConfig.contracts, multicall3: { diff --git a/packages/common/src/chains/types.ts b/packages/common/src/chains/types.ts index ea38496759..5a35c275cf 100644 --- a/packages/common/src/chains/types.ts +++ b/packages/common/src/chains/types.ts @@ -8,6 +8,7 @@ export type RpcUrls = { }; export type MUDChain = Chain & { + indexerUrl?: string; faucetUrl?: string; iconUrls?: readonly string[]; rpcUrls?: Chain["rpcUrls"] & { diff --git a/packages/store-sync/src/common.ts b/packages/store-sync/src/common.ts index 72ccd53248..6d9c2a0eb8 100644 --- a/packages/store-sync/src/common.ts +++ b/packages/store-sync/src/common.ts @@ -95,7 +95,7 @@ export type SyncOptions = { /** * Optional MUD tRPC indexer URL to fetch initial state from. */ - indexerUrl?: string; + indexerUrl?: string | false; /** * Optional initial state to hydrate from. Useful if you're hydrating from an indexer or cache. * @deprecated Use `initialLogs` option instead. diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index c14f6e68fa..a359d8d813 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -96,7 +96,15 @@ export async function createStoreSync( filters, initialState, initialBlockLogs, - indexerUrl, + indexerUrl: + indexerUrl !== false + ? indexerUrl ?? + (publicClient.chain && + "indexerUrl" in publicClient.chain && + typeof publicClient.chain.indexerUrl === "string" + ? publicClient.chain.indexerUrl + : undefined) + : undefined, }); onProgress?.({