Skip to content

Commit

Permalink
feat(common): add indexer URL to chain configs (latticexyz#2771)
Browse files Browse the repository at this point in the history
Co-authored-by: Kevin Ingersoll <[email protected]>
  • Loading branch information
2 people authored and dhvanipa committed May 24, 2024
1 parent 556fc72 commit 55a9714
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: {
...chainConfig.contracts,
multicall3: {
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: {
...chainConfig.contracts,
multicall3: {
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/chains/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type RpcUrls = {
};

export type MUDChain = Chain & {
indexerUrl?: string;
faucetUrl?: string;
iconUrls?: readonly string[];
rpcUrls?: Chain["rpcUrls"] & {
Expand Down
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 55a9714

Please sign in to comment.