Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(common): add indexer URL to chain configs #2771

Merged
merged 13 commits into from
Apr 30, 2024
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
Loading