Skip to content

Commit

Permalink
feat(common): add indexer URL to chain configs (#2771)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
yonadaaa and holic authored Apr 30, 2024
1 parent 14cb092 commit 764ca0a
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-apples-march.md
Original file line number Diff line number Diff line change
@@ -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`.
5 changes: 5 additions & 0 deletions .changeset/rotten-rules-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/common": patch
---

Added an optional `indexerUrl` property to `MUDChain`, and populated it in the Redstone and Garnet chain configs.
1 change: 1 addition & 0 deletions packages/common/src/chains/garnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const garnet = {
url: "https://explorer.garnetchain.com",
},
},
indexerUrl: "https://indexer.mud.garnetchain.com",
contracts: {
multicall3: {
address: "0xca11bde05977b3631167028862be2a173976ca11",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/chains/redstone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const redstone = {
url: "https://explorer.redstone.xyz",
},
},
indexerUrl: "https://indexer.mud.redstonechain.com",
contracts: {
multicall3: {
address: "0xca11bde05977b3631167028862be2a173976ca11",
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/chains/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Chain } from "viem/chains";

export type MUDChain = Chain & {
indexerUrl?: string;
faucetUrl?: string;
};
2 changes: 1 addition & 1 deletion packages/store-sync/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export type SyncOptions<config extends StoreConfig = StoreConfig> = {
/**
* 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.
Expand Down
10 changes: 9 additions & 1 deletion packages/store-sync/src/createStoreSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ export async function createStoreSync<config extends StoreConfig = StoreConfig>(
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?.({
Expand Down

0 comments on commit 764ca0a

Please sign in to comment.