From d5f1b30bede156d0f1f9ec8a360d01c165d0f9fd Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 13:29:14 +0100 Subject: [PATCH 01/12] feat(common): add indexer URL to chain configs --- packages/common/src/chains/garnet.ts | 1 + packages/common/src/chains/redstone.ts | 1 + packages/common/src/chains/types.ts | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/common/src/chains/garnet.ts b/packages/common/src/chains/garnet.ts index aaf958668f..19487aa747 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: "indexer.mud.garnetchain.com", contracts: { multicall3: { address: "0xca11bde05977b3631167028862be2a173976ca11", diff --git a/packages/common/src/chains/redstone.ts b/packages/common/src/chains/redstone.ts index bc56719612..718ae10e2d 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: "indexer.mud.garnetchain.com", contracts: { multicall3: { address: "0xca11bde05977b3631167028862be2a173976ca11", diff --git a/packages/common/src/chains/types.ts b/packages/common/src/chains/types.ts index e3e5376777..fcadfb423c 100644 --- a/packages/common/src/chains/types.ts +++ b/packages/common/src/chains/types.ts @@ -1,5 +1,6 @@ import type { Chain } from "viem/chains"; export type MUDChain = Chain & { + indexerUrl?: string; faucetUrl?: string; }; From 30add796dfc4f4c15efb1c6ef18054cfe11877c7 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 13:34:51 +0100 Subject: [PATCH 02/12] fix: redstone --- packages/common/src/chains/redstone.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/chains/redstone.ts b/packages/common/src/chains/redstone.ts index 718ae10e2d..d3f911f265 100644 --- a/packages/common/src/chains/redstone.ts +++ b/packages/common/src/chains/redstone.ts @@ -21,7 +21,7 @@ export const redstone = { url: "https://explorer.redstone.xyz", }, }, - indexerUrl: "indexer.mud.garnetchain.com", + indexerUrl: "indexer.mud.redstonechain.com", contracts: { multicall3: { address: "0xca11bde05977b3631167028862be2a173976ca11", From 6d41bce245736415c5b412cf8a47f8f8f23adcdd Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 13:37:22 +0100 Subject: [PATCH 03/12] feat: indexerUrl in network config --- e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts | 2 +- e2e/packages/client-vanilla/src/mud/setupNetwork.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts b/e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts index b5f06918e9..a74fde1085 100644 --- a/e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts +++ b/e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts @@ -28,7 +28,7 @@ export async function getNetworkConfig() { faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl, worldAddress, initialBlockNumber, - indexerUrl: params.get("indexerUrl"), + indexerUrl: params.get("indexerUrl") ?? chain.indexerUrl, rpcHttpUrl: params.get("rpcHttpUrl"), }; } diff --git a/e2e/packages/client-vanilla/src/mud/setupNetwork.ts b/e2e/packages/client-vanilla/src/mud/setupNetwork.ts index ea404d4344..cfc42f9bac 100644 --- a/e2e/packages/client-vanilla/src/mud/setupNetwork.ts +++ b/e2e/packages/client-vanilla/src/mud/setupNetwork.ts @@ -38,7 +38,7 @@ export async function setupNetwork() { address: networkConfig.worldAddress as Hex, publicClient, startBlock: BigInt(networkConfig.initialBlockNumber), - indexerUrl: networkConfig.indexerUrl ?? undefined, + indexerUrl: networkConfig.indexerUrl, filters: Object.entries(mudConfig.tables).map(([, table]) => { const tableId = table.tableId; if (table.name === mudConfig.tables.Position.name) { From 3bb765934c66cdae21a1c477dcb5fb2d974d55ba Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 13:39:21 +0100 Subject: [PATCH 04/12] chore: changeset --- .changeset/rotten-rules-switch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/rotten-rules-switch.md diff --git a/.changeset/rotten-rules-switch.md b/.changeset/rotten-rules-switch.md new file mode 100644 index 0000000000..cfff345939 --- /dev/null +++ b/.changeset/rotten-rules-switch.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/common": patch +--- + +Added an optional `indexerUrl` property to `MUDChain`, along with indexer URL's for the Redstone and Garnet chain configs. From 5ae4a48b7c75689da961812187e44426387e2734 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 14:21:14 +0100 Subject: [PATCH 05/12] refactor: default in createStoreSync --- e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts | 2 +- e2e/packages/client-vanilla/src/mud/setupNetwork.ts | 2 +- packages/store-sync/src/createStoreSync.ts | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts b/e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts index a74fde1085..b5f06918e9 100644 --- a/e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts +++ b/e2e/packages/client-vanilla/src/mud/getNetworkConfig.ts @@ -28,7 +28,7 @@ export async function getNetworkConfig() { faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl, worldAddress, initialBlockNumber, - indexerUrl: params.get("indexerUrl") ?? chain.indexerUrl, + indexerUrl: params.get("indexerUrl"), rpcHttpUrl: params.get("rpcHttpUrl"), }; } diff --git a/e2e/packages/client-vanilla/src/mud/setupNetwork.ts b/e2e/packages/client-vanilla/src/mud/setupNetwork.ts index cfc42f9bac..ea404d4344 100644 --- a/e2e/packages/client-vanilla/src/mud/setupNetwork.ts +++ b/e2e/packages/client-vanilla/src/mud/setupNetwork.ts @@ -38,7 +38,7 @@ export async function setupNetwork() { address: networkConfig.worldAddress as Hex, publicClient, startBlock: BigInt(networkConfig.initialBlockNumber), - indexerUrl: networkConfig.indexerUrl, + indexerUrl: networkConfig.indexerUrl ?? undefined, filters: Object.entries(mudConfig.tables).map(([, table]) => { const tableId = table.tableId; if (table.name === mudConfig.tables.Position.name) { diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index c14f6e68fa..99ad2fa466 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -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"); @@ -96,7 +97,7 @@ export async function createStoreSync( filters, initialState, initialBlockLogs, - indexerUrl, + indexerUrl: indexerUrl ?? (publicClient.chain as MUDChain).indexerUrl, }); onProgress?.({ From af77bb862027267411b27c98a6e1235c3a6206b6 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 14:24:57 +0100 Subject: [PATCH 06/12] chore: changeset --- .changeset/rotten-rules-switch.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.changeset/rotten-rules-switch.md b/.changeset/rotten-rules-switch.md index cfff345939..2041869a75 100644 --- a/.changeset/rotten-rules-switch.md +++ b/.changeset/rotten-rules-switch.md @@ -2,4 +2,6 @@ "@latticexyz/common": patch --- -Added an optional `indexerUrl` property to `MUDChain`, along with indexer URL's for the Redstone and Garnet chain configs. +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. From f96091f1a4fe1429f1f2d36137b982f91b7e9bc0 Mon Sep 17 00:00:00 2001 From: yonada Date: Tue, 30 Apr 2024 15:11:30 +0100 Subject: [PATCH 07/12] chore: garnet https Co-authored-by: Kevin Ingersoll --- packages/common/src/chains/garnet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/chains/garnet.ts b/packages/common/src/chains/garnet.ts index 19487aa747..1a09725a91 100644 --- a/packages/common/src/chains/garnet.ts +++ b/packages/common/src/chains/garnet.ts @@ -22,7 +22,7 @@ export const garnet = { url: "https://explorer.garnetchain.com", }, }, - indexerUrl: "indexer.mud.garnetchain.com", + indexerUrl: "https://indexer.mud.garnetchain.com", contracts: { multicall3: { address: "0xca11bde05977b3631167028862be2a173976ca11", From f00f16da23170e80b3974a20bf33b92ef310a741 Mon Sep 17 00:00:00 2001 From: yonada Date: Tue, 30 Apr 2024 15:11:40 +0100 Subject: [PATCH 08/12] chore: redstone https Co-authored-by: Kevin Ingersoll --- packages/common/src/chains/redstone.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/chains/redstone.ts b/packages/common/src/chains/redstone.ts index d3f911f265..6581b0362a 100644 --- a/packages/common/src/chains/redstone.ts +++ b/packages/common/src/chains/redstone.ts @@ -21,7 +21,7 @@ export const redstone = { url: "https://explorer.redstone.xyz", }, }, - indexerUrl: "indexer.mud.redstonechain.com", + indexerUrl: "https://indexer.mud.redstonechain.com", contracts: { multicall3: { address: "0xca11bde05977b3631167028862be2a173976ca11", From 0859b8492dd3714e9b888b3f3a7decf1d4bc58a5 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 15:23:58 +0100 Subject: [PATCH 09/12] refactor: defensive check --- packages/store-sync/src/createStoreSync.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/store-sync/src/createStoreSync.ts b/packages/store-sync/src/createStoreSync.ts index 99ad2fa466..36ed9ae862 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -34,7 +34,6 @@ 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"); @@ -97,7 +96,11 @@ export async function createStoreSync( filters, initialState, initialBlockLogs, - indexerUrl: indexerUrl ?? (publicClient.chain as MUDChain).indexerUrl, + indexerUrl: + indexerUrl ?? + (publicClient.chain && "indexerUrl" in publicClient.chain && typeof publicClient.chain.indexerUrl === "string" + ? publicClient.chain.indexerUrl + : undefined), }); onProgress?.({ From 3a8f5809319fc57859a58a4b6b25125e52b805cc Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 15:28:17 +0100 Subject: [PATCH 10/12] refactor indexer url can be false --- packages/store-sync/src/common.ts | 2 +- packages/store-sync/src/createStoreSync.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) 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 36ed9ae862..a359d8d813 100644 --- a/packages/store-sync/src/createStoreSync.ts +++ b/packages/store-sync/src/createStoreSync.ts @@ -97,10 +97,14 @@ export async function createStoreSync( initialState, initialBlockLogs, indexerUrl: - indexerUrl ?? - (publicClient.chain && "indexerUrl" in publicClient.chain && typeof publicClient.chain.indexerUrl === "string" - ? publicClient.chain.indexerUrl - : undefined), + indexerUrl !== false + ? indexerUrl ?? + (publicClient.chain && + "indexerUrl" in publicClient.chain && + typeof publicClient.chain.indexerUrl === "string" + ? publicClient.chain.indexerUrl + : undefined) + : undefined, }); onProgress?.({ From 0d975e75ae02c2080340974113426c488bcfa992 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 20:14:01 +0100 Subject: [PATCH 11/12] chore: simplify changeset --- .changeset/rotten-rules-switch.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.changeset/rotten-rules-switch.md b/.changeset/rotten-rules-switch.md index 2041869a75..c80e7d88bc 100644 --- a/.changeset/rotten-rules-switch.md +++ b/.changeset/rotten-rules-switch.md @@ -2,6 +2,4 @@ "@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. +Added an optional `indexerUrl` property to `MUDChain`, and populated it in the Redstone and Garnet chain configs. From 8dbaa346a143e3b73845391e00c858acd7c7b536 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Tue, 30 Apr 2024 20:17:33 +0100 Subject: [PATCH 12/12] chore: store-sync changeset --- .changeset/lemon-apples-march.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lemon-apples-march.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`.