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
7 changes: 7 additions & 0 deletions .changeset/rotten-rules-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@latticexyz/common": patch
---

Added an optional `indexerUrl` property to `MUDChain` which is used as the default indexer URL in `createStoreSync`.

Also added indexer URL's to the Redstone and Garnet chain configs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a changelog for store-sync that talks about createStoreSync defaulting to chain.indexerUrl (or false to intentionally unset/not default)

and then this one can just focus on adding indexerUrl to MUDChain and filling it in for redstone, garnet chains

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: "indexer.mud.garnetchain.com",
yonadaaa marked this conversation as resolved.
Show resolved Hide resolved
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: "indexer.mud.redstonechain.com",
yonadaaa marked this conversation as resolved.
Show resolved Hide resolved
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;
};
3 changes: 2 additions & 1 deletion packages/store-sync/src/createStoreSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { bigIntMax, chunk, isDefined, waitForIdle } from "@latticexyz/common/uti
import { getSnapshot } from "./getSnapshot";
import { fetchAndStoreLogs } from "./fetchAndStoreLogs";
import { Store as StoreConfig } from "@latticexyz/store";
import { MUDChain } from "@latticexyz/common/chains";

const debug = parentDebug.extend("createStoreSync");

Expand Down Expand Up @@ -96,7 +97,7 @@ export async function createStoreSync<config extends StoreConfig = StoreConfig>(
filters,
initialState,
initialBlockLogs,
indexerUrl,
indexerUrl: indexerUrl ?? (publicClient.chain as MUDChain).indexerUrl,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to pass the chain more explicitly to avoid this cast?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, I don't want to have a potential deviation between publicClient's chain and a chain passed in

this cast is fine but you could be super defensive with something like

"indexerUrl" in publicClient.chain && typeof publicClient.chain.indexerUrl === 'string' ? publicClient.chain.indexerUrl : undefined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we prob also still want some way to turn off the indexer if needed

maybe we also allow indexerUrl: false here?

});

onProgress?.({
Expand Down
Loading