From 9b65436d83a875e6f338ff18e985e70c4c784c06 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 9 Aug 2023 20:58:51 +0000 Subject: [PATCH] Version Packages (next) --- .changeset/pre.json | 22 +- CHANGELOG.md | 376 +++++++++++++++++++++++ packages/block-logs-stream/CHANGELOG.md | 9 + packages/block-logs-stream/package.json | 2 +- packages/cli/CHANGELOG.md | 219 +++++++++++++ packages/cli/package.json | 2 +- packages/common/CHANGELOG.md | 235 ++++++++++++++ packages/common/package.json | 2 +- packages/config/CHANGELOG.md | 8 + packages/config/package.json | 2 +- packages/create-mud/CHANGELOG.md | 191 ++++++++++++ packages/create-mud/package.json | 2 +- packages/dev-tools/CHANGELOG.md | 14 + packages/dev-tools/package.json | 10 +- packages/ecs-browser/CHANGELOG.md | 9 + packages/ecs-browser/package.json | 2 +- packages/gas-report/CHANGELOG.md | 2 + packages/gas-report/package.json | 2 +- packages/network/CHANGELOG.md | 16 + packages/network/package.json | 2 +- packages/noise/CHANGELOG.md | 2 + packages/noise/package.json | 2 +- packages/phaserx/CHANGELOG.md | 7 + packages/phaserx/package.json | 2 +- packages/protocol-parser/CHANGELOG.md | 8 + packages/protocol-parser/package.json | 2 +- packages/react/CHANGELOG.md | 9 + packages/react/package.json | 2 +- packages/recs/CHANGELOG.md | 205 ++++++++++++ packages/recs/package.json | 2 +- packages/schema-type/CHANGELOG.md | 6 + packages/schema-type/package.json | 2 +- packages/services/CHANGELOG.md | 6 + packages/services/package.json | 2 +- packages/solecs/CHANGELOG.md | 2 + packages/solecs/package.json | 2 +- packages/solhint-config-mud/CHANGELOG.md | 2 + packages/solhint-config-mud/package.json | 2 +- packages/solhint-plugin-mud/CHANGELOG.md | 2 + packages/solhint-plugin-mud/package.json | 2 +- packages/std-client/CHANGELOG.md | 30 ++ packages/std-client/package.json | 2 +- packages/std-contracts/CHANGELOG.md | 2 + packages/std-contracts/package.json | 2 +- packages/store-cache/CHANGELOG.md | 10 + packages/store-cache/package.json | 2 +- packages/store-indexer/CHANGELOG.md | 232 ++++++++++++++ packages/store-indexer/package.json | 2 +- packages/store-sync/CHANGELOG.md | 94 ++++++ packages/store-sync/package.json | 2 +- packages/store/CHANGELOG.md | 17 + packages/store/package.json | 2 +- packages/utils/CHANGELOG.md | 2 + packages/utils/package.json | 2 +- packages/world/CHANGELOG.md | 14 + packages/world/package.json | 2 +- 56 files changed, 1781 insertions(+), 32 deletions(-) create mode 100644 packages/store-indexer/CHANGELOG.md diff --git a/.changeset/pre.json b/.changeset/pre.json index 5184e96fad..69137299d8 100644 --- a/.changeset/pre.json +++ b/.changeset/pre.json @@ -31,15 +31,29 @@ "@latticexyz/world": "1.42.0" }, "changesets": [ + "afraid-hotels-bathe", + "big-goats-prove", + "brave-rings-tickle", + "dirty-items-retire", "eighty-tigers-argue", "fast-ears-hug", + "fifty-squids-eat", + "fluffy-moles-march", + "giant-masks-carry", + "great-cooks-dream", "itchy-kids-relax", + "itchy-shoes-appear", + "large-hats-walk", "many-phones-study", + "mean-pans-study", + "metal-cats-double", "modern-bikes-build", "nasty-waves-divide", + "nice-moose-love", "nice-pandas-knock", "olive-parrots-move", "perfect-mangos-cry", + "pink-horses-deny", "quick-numbers-flash", "rare-planes-draw", "selfish-cycles-retire", @@ -48,7 +62,13 @@ "stale-cooks-reflect", "strange-candles-shout", "strange-ducks-float", + "tame-lemons-play", "thin-buses-reply", - "tricky-frogs-beam" + "tricky-frogs-beam", + "tricky-kangaroos-love", + "tricky-olives-stare", + "tricky-oranges-pump", + "weak-mails-cross", + "witty-jokes-serve" ] } diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c8db7e3b2..19f32ab19a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,379 @@ +# Version 2.0.0-next.1 + +## Major changes + +**[chore: fix changeset type (#1220)](https://github.com/latticexyz/mud/commit/2f6cfef91daacf09db82a4b7c69cff3af583b8f6)** (@latticexyz/store-indexer, @latticexyz/store-sync) + +Adds store indexer service package with utils to query the indexer service. + +You can run the indexer locally by checking out the MUD monorepo, installing/building everything, and running `pnpm start:local` from `packages/store-indexer`. + +To query the indexer in the client, you can create a tRPC client with a URL pointing to the indexer service and call the available tRPC methods: + +```ts +import { createIndexerClient } from "@latticexyz/store-sync/trpc-indexer"; + +const indexer = createIndexerClient({ url: indexerUrl }); +const result = await indexer.findAll.query({ + chainId: publicClient.chain.id, + address, +}); +``` + +If you're using `syncToRecs`, you can just pass in the `indexerUrl` option as a shortcut to the above: + +```ts +import { syncToRecs } from "@latticexyz/store-sync/recs"; + +syncToRecs({ + ... + indexerUrl: "https://your.indexer.service", +}); +``` + +**[fix: changeset package name (#1270)](https://github.com/latticexyz/mud/commit/9a7c9009a43bc5691bb33996bcf669711cc51503)** (@latticexyz/cli, @latticexyz/common, @latticexyz/recs, @latticexyz/store-indexer, create-mud) + +Templates and examples now use MUD's new sync packages, all built on top of [viem](https://viem.sh/). This greatly speeds up and stabilizes our networking code and improves types throughout. + +These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys. + +If you're using `store-cache` and `useRow`/`useRows`, you should wait to upgrade until we have a suitable replacement for those libraries. We're working on a [sql.js](https://github.com/sql-js/sql.js/)-powered sync module that will replace `store-cache`. + +**Migrate existing RECS apps to new sync packages** + +As you migrate, you may find some features replaced, removed, or not included by default. Please [open an issue](https://github.com/latticexyz/mud/issues/new) and let us know if we missed anything. + +1. Add `@latticexyz/store-sync` package to your app's `client` package and make sure `viem` is pinned to version `1.3.1` (otherwise you may get type errors) + +2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain. + + ```diff + - import { foundry } from "viem/chains"; + - import { MUDChain, latticeTestnet } from "@latticexyz/common/chains"; + + import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains"; + + - export const supportedChains: MUDChain[] = [foundry, latticeTestnet]; + + export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet]; + ``` + +3. In `getNetworkConfig.ts`, remove the return type (to let TS infer it for now), remove now-unused config values, and add the viem `chain` object. + + ```diff + - export async function getNetworkConfig(): Promise { + + export async function getNetworkConfig() { + ``` + + ```diff + const initialBlockNumber = params.has("initialBlockNumber") + ? Number(params.get("initialBlockNumber")) + - : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC + + : world?.blockNumber ?? 0n; + ``` + + ```diff + + return { + + privateKey: getBurnerWallet().value, + + chain, + + worldAddress, + + initialBlockNumber, + + faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl, + + }; + ``` + +4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`. + + ```diff + - import { setupMUDV2Network } from "@latticexyz/std-client"; + - import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network"; + + import { createFaucetService } from "@latticexyz/network"; + + import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem"; + + import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs"; + + import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common"; + ``` + + ```diff + - const result = await setupMUDV2Network({ + - ... + - }); + + + const clientOptions = { + + chain: networkConfig.chain, + + transport: transportObserver(fallback([webSocket(), http()])), + + pollingInterval: 1000, + + } as const satisfies ClientConfig; + + + const publicClient = createPublicClient(clientOptions); + + + const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex); + + const burnerWalletClient = createWalletClient({ + + ...clientOptions, + + account: burnerAccount, + + }); + + + const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({ + + world, + + config: storeConfig, + + address: networkConfig.worldAddress as Hex, + + publicClient, + + components: contractComponents, + + startBlock: BigInt(networkConfig.initialBlockNumber), + + indexerUrl: networkConfig.indexerUrl ?? undefined, + + }); + + + const worldContract = createContract({ + + address: networkConfig.worldAddress as Hex, + + abi: IWorld__factory.abi, + + publicClient, + + walletClient: burnerWalletClient, + + }); + ``` + + ```diff + // Request drip from faucet + - const signer = result.network.signer.get(); + - if (networkConfig.faucetServiceUrl && signer) { + - const address = await signer.getAddress(); + + if (networkConfig.faucetServiceUrl) { + + const address = burnerAccount.address; + ``` + + ```diff + const requestDrip = async () => { + - const balance = await signer.getBalance(); + + const balance = await publicClient.getBalance({ address }); + console.info(`[Dev Faucet]: Player balance -> ${balance}`); + - const lowBalance = balance?.lte(utils.parseEther("1")); + + const lowBalance = balance < parseEther("1"); + ``` + + You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor. + + The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes. + + ```diff + + return { + + world, + + components, + + playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }), + + publicClient, + + walletClient: burnerWalletClient, + + latestBlock$, + + blockStorageOperations$, + + waitForTransaction, + + worldContract, + + }; + ``` + +5. Update `createSystemCalls` with the new return type of `setupNetwork`. + + ```diff + export function createSystemCalls( + - { worldSend, txReduced$, singletonEntity }: SetupNetworkResult, + + { worldContract, waitForTransaction }: SetupNetworkResult, + { Counter }: ClientComponents + ) { + const increment = async () => { + - const tx = await worldSend("increment", []); + - await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash); + + const tx = await worldContract.write.increment(); + + await waitForTransaction(tx); + return getComponentValue(Counter, singletonEntity); + }; + ``` + +6. (optional) If you still need a clock, you can create it with: + + ```ts + import { map, filter } from "rxjs"; + import { createClock } from "@latticexyz/network"; + + const clock = createClock({ + period: 1000, + initialTime: 0, + syncInterval: 5000, + }); + + world.registerDisposer(() => clock.dispose()); + + latestBlock$ + .pipe( + map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms + filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block + filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + ) + .subscribe(clock.update); // Update the local clock + ``` + +If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`: + +```ts +import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs"; + +const syncProgress = useComponentValue(SyncProgress, singletonEntity, { + message: "Connecting", + percentage: 0, + step: SyncStep.INITIALIZE, +}); + +if (syncProgress.step === SyncStep.LIVE) { + // we're live! +} +``` + +**[feat(common): replace TableId with tableIdToHex/hexToTableId (#1258)](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7)** (@latticexyz/cli, @latticexyz/common, @latticexyz/dev-tools, @latticexyz/network, @latticexyz/std-client, @latticexyz/store-sync) + +Add `tableIdToHex` and `hexToTableId` pure functions and move/deprecate `TableId`. + +**[feat(common): add createContract, createNonceManager utils (#1261)](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb)** (@latticexyz/common) + +Add utils for using viem with MUD + +- `createContract` is a wrapper around [viem's `getContract`](https://viem.sh/docs/contract/getContract.html) but with better nonce handling for faster executing of transactions. It has the same arguments and return type as `getContract`. +- `createNonceManager` helps track local nonces, used by `createContract`. + +Also renames `mudTransportObserver` to `transportObserver`. + +## Minor changes + +**[feat(common): add viem utils (#1245)](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50)** (@latticexyz/common) + +Add utils for using viem with MUD + +- `mudFoundry` chain with a transaction request formatter that temporarily removes max fees to work better with anvil `--base-fee 0` +- `createBurnerAccount` that also temporarily removes max fees during transaction signing to work better with anvil `--base-fee 0` +- `mudTransportObserver` that will soon let MUD Dev Tools observe transactions + +You can use them like: + +```ts +import { createBurnerAccount, mudTransportObserver } from "@latticexyz/common"; +import { mudFoundry } from "@latticexyz/common/chains"; + +createWalletClient({ + account: createBurnerAccount(privateKey), + chain: mudFoundry, + transport: mudTransportObserver(http()), + pollingInterval: 1000, +}); +``` + +**[feat(store-indexer,store-sync): make chain optional, configure indexer with RPC (#1234)](https://github.com/latticexyz/mud/commit/131c63e539a8e9947835dcc323c8b37562aed9ca)** (@latticexyz/store-indexer, @latticexyz/store-sync) + +- Accept a plain viem `PublicClient` (instead of requiring a `Chain` to be set) in `store-sync` and `store-indexer` functions. These functions now fetch chain ID using `publicClient.getChainId()` when no `publicClient.chain.id` is present. +- Allow configuring `store-indexer` with a set of RPC URLs (`RPC_HTTP_URL` and `RPC_WS_URL`) instead of `CHAIN_ID`. + +**[feat(store-sync): export singletonEntity as const, allow startBlock in syncToRecs (#1235)](https://github.com/latticexyz/mud/commit/582388ba5f95c3efde56779058220dbd7aedee0b)** (@latticexyz/store-sync) + +Export `singletonEntity` as const rather than within the `syncToRecs` result. + +```diff +- const { singletonEntity, ... } = syncToRecs({ ... }); ++ import { singletonEntity, syncToRecs } from "@latticexyz/store-sync/recs"; ++ const { ... } = syncToRecs({ ... }); +``` + +**[feat(schema-type): add type narrowing isStaticAbiType (#1196)](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07)** (@latticexyz/schema-type) + +add type narrowing `isStaticAbiType` + +**[feat(common): move zero gas fee override to `createContract` (#1266)](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983)** (@latticexyz/common) + +- Moves zero gas fee override to `createContract` until https://github.com/wagmi-dev/viem/pull/963 or similar feature lands +- Skip simulation if `gas` is provided + +## Patch changes + +**[fix(cli): add support for legacy transactions in deploy script (#1178)](https://github.com/latticexyz/mud/commit/168a4cb43ce4f7bfbdb7b1b9d4c305b912a0d3f2)** (@latticexyz/cli) + +Add support for legacy transactions in deploy script by falling back to `gasPrice` if `lastBaseFeePerGas` is not available + +**[feat: protocol-parser in go (#1116)](https://github.com/latticexyz/mud/commit/3236f799e501be227da6e42e7b41a4928750115c)** (@latticexyz/services) + +protocol-parser in Go + +**[refactor(store): optimize Storage library (#1194)](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021)** (@latticexyz/store) + +Optimize storage library + +**[feat(common): remove need for tx queue in `createContract` (#1271)](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb)** (@latticexyz/common) + +- Remove need for tx queue in `createContract` + +**[feat(store-sync): add block numbers to SyncProgress (#1228)](https://github.com/latticexyz/mud/commit/57a5260830401c9ad93196a895a50b0fc4a86183)** (@latticexyz/store-sync) + +Adds `latestBlockNumber` and `lastBlockNumberProcessed` to internal `SyncProgress` component + +**[feat(store-sync): sync to RECS (#1197)](https://github.com/latticexyz/mud/commit/9e5baf4fff0c60615b8f2b4645fb11cb78cb0bd8)** (@latticexyz/store-sync) + +Add RECS sync strategy and corresponding utils + +```ts +import { createPublicClient, http } from 'viem'; +import { syncToRecs } from '@latticexyz/store-sync'; +import storeConfig from 'contracts/mud.config'; +import { defineContractComponents } from './defineContractComponents'; + +const publicClient = createPublicClient({ + chain, + transport: http(), + pollingInterval: 1000, +}); + +const { components, singletonEntity, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({ + world, + config: storeConfig, + address: '0x...', + publicClient, + components: defineContractComponents(...), +}); +``` + +**[fix(store): align Store event names between IStoreWrite and StoreCore (#1237)](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206)** (@latticexyz/store) + +Align Store events parameter naming between IStoreWrite and StoreCore + +**[fix(cli): explicit import of world as type (#1206)](https://github.com/latticexyz/mud/commit/e259ef79f4d9026353176d0f74628cae50c2f69b)** (@latticexyz/cli, @latticexyz/std-client) + +Generated `contractComponents` now properly import `World` as type + +**[feat(store-sync): export singletonEntity as const, allow startBlock in syncToRecs (#1235)](https://github.com/latticexyz/mud/commit/582388ba5f95c3efde56779058220dbd7aedee0b)** (@latticexyz/store-sync) + +Add `startBlock` option to `syncToRecs`. + +```ts +import { syncToRecs } from "@latticexyz/store-sync/recs"; +import worlds from "contracts/worlds.json"; + +syncToRecs({ + startBlock: worlds['31337'].blockNumber, + ... +}); +``` + +**[chore: pin node to 18.16.1 (#1200)](https://github.com/latticexyz/mud/commit/0d1a7e03a0c8258c76d0b4b76a1a558ae07bbf85)** (@latticexyz/network) + +Remove devEmit function when sending network events from SyncWorker because they can't be serialized across the web worker boundary. + +**[feat(cli,recs,std-client): update RECS components with v2 key/value schemas (#1195)](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd)** (@latticexyz/cli, @latticexyz/recs, @latticexyz/std-client) + +Update RECS components with v2 key/value schemas. This helps with encoding/decoding composite keys and strong types for keys/values. + +This may break if you were previously dependent on `component.id`, `component.metadata.componentId`, or `component.metadata.tableId`: + +- `component.id` is now the on-chain `bytes32` hex representation of the table ID +- `component.metadata.componentName` is the table name (e.g. `Position`) +- `component.metadata.tableName` is the namespaced table name (e.g. `myworld:Position`) +- `component.metadata.keySchema` is an object with key names and their corresponding ABI types +- `component.metadata.valueSchema` is an object with field names and their corresponding ABI types + +**[refactor(store): update tightcoder codegen, optimize TightCoder library (#1210)](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)** (@latticexyz/common, @latticexyz/store, @latticexyz/world) + +- Refactor tightcoder to use typescript functions instead of ejs +- Optimize `TightCoder` library +- Add `isLeftAligned` and `getLeftPaddingBits` common codegen helpers + +--- + # Version 2.0.0-next.0 ## Minor changes diff --git a/packages/block-logs-stream/CHANGELOG.md b/packages/block-logs-stream/CHANGELOG.md index 170ff2344a..6ce48139d4 100644 --- a/packages/block-logs-stream/CHANGELOG.md +++ b/packages/block-logs-stream/CHANGELOG.md @@ -1,5 +1,14 @@ # @latticexyz/block-logs-stream +## 2.0.0-next.1 + +### Patch Changes + +- Updated dependencies [[`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + - @latticexyz/config@2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/block-logs-stream/package.json b/packages/block-logs-stream/package.json index c65a046ac3..a1f055f07e 100644 --- a/packages/block-logs-stream/package.json +++ b/packages/block-logs-stream/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/block-logs-stream", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Create a stream of EVM block logs for events", "repository": { "type": "git", diff --git a/packages/cli/CHANGELOG.md b/packages/cli/CHANGELOG.md index 8033dbe93a..c4a0afdcac 100644 --- a/packages/cli/CHANGELOG.md +++ b/packages/cli/CHANGELOG.md @@ -1,5 +1,224 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- [#1178](https://github.com/latticexyz/mud/pull/1178) [`168a4cb4`](https://github.com/latticexyz/mud/commit/168a4cb43ce4f7bfbdb7b1b9d4c305b912a0d3f2) Thanks [@TheGreatAxios](https://github.com/TheGreatAxios)! - Add support for legacy transactions in deploy script by falling back to `gasPrice` if `lastBaseFeePerGas` is not available + +- [#1206](https://github.com/latticexyz/mud/pull/1206) [`e259ef79`](https://github.com/latticexyz/mud/commit/e259ef79f4d9026353176d0f74628cae50c2f69b) Thanks [@holic](https://github.com/holic)! - Generated `contractComponents` now properly import `World` as type + +- [#1214](https://github.com/latticexyz/mud/pull/1214) [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9) Thanks [@holic](https://github.com/holic)! - Templates and examples now use MUD's new sync packages, all built on top of [viem](https://viem.sh/). This greatly speeds up and stabilizes our networking code and improves types throughout. + + These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys. + + If you're using `store-cache` and `useRow`/`useRows`, you should wait to upgrade until we have a suitable replacement for those libraries. We're working on a [sql.js](https://github.com/sql-js/sql.js/)-powered sync module that will replace `store-cache`. + + **Migrate existing RECS apps to new sync packages** + + As you migrate, you may find some features replaced, removed, or not included by default. Please [open an issue](https://github.com/latticexyz/mud/issues/new) and let us know if we missed anything. + + 1. Add `@latticexyz/store-sync` package to your app's `client` package and make sure `viem` is pinned to version `1.3.1` (otherwise you may get type errors) + + 2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain. + + ```diff + - import { foundry } from "viem/chains"; + - import { MUDChain, latticeTestnet } from "@latticexyz/common/chains"; + + import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains"; + + - export const supportedChains: MUDChain[] = [foundry, latticeTestnet]; + + export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet]; + ``` + + 3. In `getNetworkConfig.ts`, remove the return type (to let TS infer it for now), remove now-unused config values, and add the viem `chain` object. + + ```diff + - export async function getNetworkConfig(): Promise { + + export async function getNetworkConfig() { + ``` + + ```diff + const initialBlockNumber = params.has("initialBlockNumber") + ? Number(params.get("initialBlockNumber")) + - : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC + + : world?.blockNumber ?? 0n; + ``` + + ```diff + + return { + + privateKey: getBurnerWallet().value, + + chain, + + worldAddress, + + initialBlockNumber, + + faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl, + + }; + ``` + + 4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`. + + ```diff + - import { setupMUDV2Network } from "@latticexyz/std-client"; + - import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network"; + + import { createFaucetService } from "@latticexyz/network"; + + import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem"; + + import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs"; + + import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common"; + ``` + + ```diff + - const result = await setupMUDV2Network({ + - ... + - }); + + + const clientOptions = { + + chain: networkConfig.chain, + + transport: transportObserver(fallback([webSocket(), http()])), + + pollingInterval: 1000, + + } as const satisfies ClientConfig; + + + const publicClient = createPublicClient(clientOptions); + + + const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex); + + const burnerWalletClient = createWalletClient({ + + ...clientOptions, + + account: burnerAccount, + + }); + + + const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({ + + world, + + config: storeConfig, + + address: networkConfig.worldAddress as Hex, + + publicClient, + + components: contractComponents, + + startBlock: BigInt(networkConfig.initialBlockNumber), + + indexerUrl: networkConfig.indexerUrl ?? undefined, + + }); + + + const worldContract = createContract({ + + address: networkConfig.worldAddress as Hex, + + abi: IWorld__factory.abi, + + publicClient, + + walletClient: burnerWalletClient, + + }); + ``` + + ```diff + // Request drip from faucet + - const signer = result.network.signer.get(); + - if (networkConfig.faucetServiceUrl && signer) { + - const address = await signer.getAddress(); + + if (networkConfig.faucetServiceUrl) { + + const address = burnerAccount.address; + ``` + + ```diff + const requestDrip = async () => { + - const balance = await signer.getBalance(); + + const balance = await publicClient.getBalance({ address }); + console.info(`[Dev Faucet]: Player balance -> ${balance}`); + - const lowBalance = balance?.lte(utils.parseEther("1")); + + const lowBalance = balance < parseEther("1"); + ``` + + You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor. + + The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes. + + ```diff + + return { + + world, + + components, + + playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }), + + publicClient, + + walletClient: burnerWalletClient, + + latestBlock$, + + blockStorageOperations$, + + waitForTransaction, + + worldContract, + + }; + ``` + + 5. Update `createSystemCalls` with the new return type of `setupNetwork`. + + ```diff + export function createSystemCalls( + - { worldSend, txReduced$, singletonEntity }: SetupNetworkResult, + + { worldContract, waitForTransaction }: SetupNetworkResult, + { Counter }: ClientComponents + ) { + const increment = async () => { + - const tx = await worldSend("increment", []); + - await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash); + + const tx = await worldContract.write.increment(); + + await waitForTransaction(tx); + return getComponentValue(Counter, singletonEntity); + }; + ``` + + 6. (optional) If you still need a clock, you can create it with: + + ```ts + import { map, filter } from "rxjs"; + import { createClock } from "@latticexyz/network"; + + const clock = createClock({ + period: 1000, + initialTime: 0, + syncInterval: 5000, + }); + + world.registerDisposer(() => clock.dispose()); + + latestBlock$ + .pipe( + map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms + filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block + filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + ) + .subscribe(clock.update); // Update the local clock + ``` + + If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`: + + ```ts + import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs"; + + const syncProgress = useComponentValue(SyncProgress, singletonEntity, { + message: "Connecting", + percentage: 0, + step: SyncStep.INITIALIZE, + }); + + if (syncProgress.step === SyncStep.LIVE) { + // we're live! + } + ``` + +- [#1258](https://github.com/latticexyz/mud/pull/1258) [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7) Thanks [@holic](https://github.com/holic)! - Add `tableIdToHex` and `hexToTableId` pure functions and move/deprecate `TableId`. + +- [#1195](https://github.com/latticexyz/mud/pull/1195) [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd) Thanks [@holic](https://github.com/holic)! - Update RECS components with v2 key/value schemas. This helps with encoding/decoding composite keys and strong types for keys/values. + + This may break if you were previously dependent on `component.id`, `component.metadata.componentId`, or `component.metadata.tableId`: + + - `component.id` is now the on-chain `bytes32` hex representation of the table ID + - `component.metadata.componentName` is the table name (e.g. `Position`) + - `component.metadata.tableName` is the namespaced table name (e.g. `myworld:Position`) + - `component.metadata.keySchema` is an object with key names and their corresponding ABI types + - `component.metadata.valueSchema` is an object with field names and their corresponding ABI types + +- Updated dependencies [[`3236f799`](https://github.com/latticexyz/mud/commit/3236f799e501be227da6e42e7b41a4928750115c), [`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021), [`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/services@2.0.0-next.1 + - @latticexyz/store@2.0.0-next.1 + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + - @latticexyz/world@2.0.0-next.1 + - @latticexyz/config@2.0.0-next.1 + - @latticexyz/gas-report@2.0.0-next.1 + - @latticexyz/solecs@2.0.0-next.1 + - @latticexyz/std-contracts@2.0.0-next.1 + - @latticexyz/utils@2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/cli/package.json b/packages/cli/package.json index b7c959f0a1..9fea153713 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/cli", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Command line interface for mud", "repository": { "type": "git", diff --git a/packages/common/CHANGELOG.md b/packages/common/CHANGELOG.md index 8b0f96e90f..a0be1889a3 100644 --- a/packages/common/CHANGELOG.md +++ b/packages/common/CHANGELOG.md @@ -1,5 +1,240 @@ # Change Log +## 2.0.0-next.1 + +### Major Changes + +- [#1214](https://github.com/latticexyz/mud/pull/1214) [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9) Thanks [@holic](https://github.com/holic)! - Templates and examples now use MUD's new sync packages, all built on top of [viem](https://viem.sh/). This greatly speeds up and stabilizes our networking code and improves types throughout. + + These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys. + + If you're using `store-cache` and `useRow`/`useRows`, you should wait to upgrade until we have a suitable replacement for those libraries. We're working on a [sql.js](https://github.com/sql-js/sql.js/)-powered sync module that will replace `store-cache`. + + **Migrate existing RECS apps to new sync packages** + + As you migrate, you may find some features replaced, removed, or not included by default. Please [open an issue](https://github.com/latticexyz/mud/issues/new) and let us know if we missed anything. + + 1. Add `@latticexyz/store-sync` package to your app's `client` package and make sure `viem` is pinned to version `1.3.1` (otherwise you may get type errors) + + 2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain. + + ```diff + - import { foundry } from "viem/chains"; + - import { MUDChain, latticeTestnet } from "@latticexyz/common/chains"; + + import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains"; + + - export const supportedChains: MUDChain[] = [foundry, latticeTestnet]; + + export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet]; + ``` + + 3. In `getNetworkConfig.ts`, remove the return type (to let TS infer it for now), remove now-unused config values, and add the viem `chain` object. + + ```diff + - export async function getNetworkConfig(): Promise { + + export async function getNetworkConfig() { + ``` + + ```diff + const initialBlockNumber = params.has("initialBlockNumber") + ? Number(params.get("initialBlockNumber")) + - : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC + + : world?.blockNumber ?? 0n; + ``` + + ```diff + + return { + + privateKey: getBurnerWallet().value, + + chain, + + worldAddress, + + initialBlockNumber, + + faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl, + + }; + ``` + + 4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`. + + ```diff + - import { setupMUDV2Network } from "@latticexyz/std-client"; + - import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network"; + + import { createFaucetService } from "@latticexyz/network"; + + import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem"; + + import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs"; + + import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common"; + ``` + + ```diff + - const result = await setupMUDV2Network({ + - ... + - }); + + + const clientOptions = { + + chain: networkConfig.chain, + + transport: transportObserver(fallback([webSocket(), http()])), + + pollingInterval: 1000, + + } as const satisfies ClientConfig; + + + const publicClient = createPublicClient(clientOptions); + + + const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex); + + const burnerWalletClient = createWalletClient({ + + ...clientOptions, + + account: burnerAccount, + + }); + + + const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({ + + world, + + config: storeConfig, + + address: networkConfig.worldAddress as Hex, + + publicClient, + + components: contractComponents, + + startBlock: BigInt(networkConfig.initialBlockNumber), + + indexerUrl: networkConfig.indexerUrl ?? undefined, + + }); + + + const worldContract = createContract({ + + address: networkConfig.worldAddress as Hex, + + abi: IWorld__factory.abi, + + publicClient, + + walletClient: burnerWalletClient, + + }); + ``` + + ```diff + // Request drip from faucet + - const signer = result.network.signer.get(); + - if (networkConfig.faucetServiceUrl && signer) { + - const address = await signer.getAddress(); + + if (networkConfig.faucetServiceUrl) { + + const address = burnerAccount.address; + ``` + + ```diff + const requestDrip = async () => { + - const balance = await signer.getBalance(); + + const balance = await publicClient.getBalance({ address }); + console.info(`[Dev Faucet]: Player balance -> ${balance}`); + - const lowBalance = balance?.lte(utils.parseEther("1")); + + const lowBalance = balance < parseEther("1"); + ``` + + You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor. + + The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes. + + ```diff + + return { + + world, + + components, + + playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }), + + publicClient, + + walletClient: burnerWalletClient, + + latestBlock$, + + blockStorageOperations$, + + waitForTransaction, + + worldContract, + + }; + ``` + + 5. Update `createSystemCalls` with the new return type of `setupNetwork`. + + ```diff + export function createSystemCalls( + - { worldSend, txReduced$, singletonEntity }: SetupNetworkResult, + + { worldContract, waitForTransaction }: SetupNetworkResult, + { Counter }: ClientComponents + ) { + const increment = async () => { + - const tx = await worldSend("increment", []); + - await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash); + + const tx = await worldContract.write.increment(); + + await waitForTransaction(tx); + return getComponentValue(Counter, singletonEntity); + }; + ``` + + 6. (optional) If you still need a clock, you can create it with: + + ```ts + import { map, filter } from "rxjs"; + import { createClock } from "@latticexyz/network"; + + const clock = createClock({ + period: 1000, + initialTime: 0, + syncInterval: 5000, + }); + + world.registerDisposer(() => clock.dispose()); + + latestBlock$ + .pipe( + map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms + filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block + filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + ) + .subscribe(clock.update); // Update the local clock + ``` + + If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`: + + ```ts + import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs"; + + const syncProgress = useComponentValue(SyncProgress, singletonEntity, { + message: "Connecting", + percentage: 0, + step: SyncStep.INITIALIZE, + }); + + if (syncProgress.step === SyncStep.LIVE) { + // we're live! + } + ``` + +- [#1258](https://github.com/latticexyz/mud/pull/1258) [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7) Thanks [@holic](https://github.com/holic)! - Add `tableIdToHex` and `hexToTableId` pure functions and move/deprecate `TableId`. + +- [#1261](https://github.com/latticexyz/mud/pull/1261) [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb) Thanks [@holic](https://github.com/holic)! - Add utils for using viem with MUD + + - `createContract` is a wrapper around [viem's `getContract`](https://viem.sh/docs/contract/getContract.html) but with better nonce handling for faster executing of transactions. It has the same arguments and return type as `getContract`. + - `createNonceManager` helps track local nonces, used by `createContract`. + + Also renames `mudTransportObserver` to `transportObserver`. + +### Minor Changes + +- [#1245](https://github.com/latticexyz/mud/pull/1245) [`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50) Thanks [@holic](https://github.com/holic)! - Add utils for using viem with MUD + + - `mudFoundry` chain with a transaction request formatter that temporarily removes max fees to work better with anvil `--base-fee 0` + - `createBurnerAccount` that also temporarily removes max fees during transaction signing to work better with anvil `--base-fee 0` + - `mudTransportObserver` that will soon let MUD Dev Tools observe transactions + + You can use them like: + + ```ts + import { createBurnerAccount, mudTransportObserver } from "@latticexyz/common"; + import { mudFoundry } from "@latticexyz/common/chains"; + + createWalletClient({ + account: createBurnerAccount(privateKey), + chain: mudFoundry, + transport: mudTransportObserver(http()), + pollingInterval: 1000, + }); + ``` + +- [#1266](https://github.com/latticexyz/mud/pull/1266) [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983) Thanks [@holic](https://github.com/holic)! - - Moves zero gas fee override to `createContract` until https://github.com/wagmi-dev/viem/pull/963 or similar feature lands + - Skip simulation if `gas` is provided + +### Patch Changes + +- [#1271](https://github.com/latticexyz/mud/pull/1271) [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb) Thanks [@holic](https://github.com/holic)! - - Remove need for tx queue in `createContract` + +- [#1210](https://github.com/latticexyz/mud/pull/1210) [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3) Thanks [@dk1a](https://github.com/dk1a)! - - Refactor tightcoder to use typescript functions instead of ejs + - Optimize `TightCoder` library + - Add `isLeftAligned` and `getLeftPaddingBits` common codegen helpers +- Updated dependencies [[`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07)]: + - @latticexyz/schema-type@2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/common/package.json b/packages/common/package.json index 37b1d7404b..86df629bb5 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/common", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Common low level logic shared between packages", "repository": { "type": "git", diff --git a/packages/config/CHANGELOG.md b/packages/config/CHANGELOG.md index 600de540f4..d16e698b78 100644 --- a/packages/config/CHANGELOG.md +++ b/packages/config/CHANGELOG.md @@ -1,5 +1,13 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- Updated dependencies [[`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/config/package.json b/packages/config/package.json index 97167c71ef..25c16ecf4d 100644 --- a/packages/config/package.json +++ b/packages/config/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/config", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Config for Store and World", "repository": { "type": "git", diff --git a/packages/create-mud/CHANGELOG.md b/packages/create-mud/CHANGELOG.md index 6da28de26b..5928630bcd 100644 --- a/packages/create-mud/CHANGELOG.md +++ b/packages/create-mud/CHANGELOG.md @@ -1,5 +1,196 @@ # Change Log +## 2.0.0-next.1 + +### Major Changes + +- [#1214](https://github.com/latticexyz/mud/pull/1214) [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9) Thanks [@holic](https://github.com/holic)! - Templates and examples now use MUD's new sync packages, all built on top of [viem](https://viem.sh/). This greatly speeds up and stabilizes our networking code and improves types throughout. + + These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys. + + If you're using `store-cache` and `useRow`/`useRows`, you should wait to upgrade until we have a suitable replacement for those libraries. We're working on a [sql.js](https://github.com/sql-js/sql.js/)-powered sync module that will replace `store-cache`. + + **Migrate existing RECS apps to new sync packages** + + As you migrate, you may find some features replaced, removed, or not included by default. Please [open an issue](https://github.com/latticexyz/mud/issues/new) and let us know if we missed anything. + + 1. Add `@latticexyz/store-sync` package to your app's `client` package and make sure `viem` is pinned to version `1.3.1` (otherwise you may get type errors) + + 2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain. + + ```diff + - import { foundry } from "viem/chains"; + - import { MUDChain, latticeTestnet } from "@latticexyz/common/chains"; + + import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains"; + + - export const supportedChains: MUDChain[] = [foundry, latticeTestnet]; + + export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet]; + ``` + + 3. In `getNetworkConfig.ts`, remove the return type (to let TS infer it for now), remove now-unused config values, and add the viem `chain` object. + + ```diff + - export async function getNetworkConfig(): Promise { + + export async function getNetworkConfig() { + ``` + + ```diff + const initialBlockNumber = params.has("initialBlockNumber") + ? Number(params.get("initialBlockNumber")) + - : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC + + : world?.blockNumber ?? 0n; + ``` + + ```diff + + return { + + privateKey: getBurnerWallet().value, + + chain, + + worldAddress, + + initialBlockNumber, + + faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl, + + }; + ``` + + 4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`. + + ```diff + - import { setupMUDV2Network } from "@latticexyz/std-client"; + - import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network"; + + import { createFaucetService } from "@latticexyz/network"; + + import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem"; + + import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs"; + + import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common"; + ``` + + ```diff + - const result = await setupMUDV2Network({ + - ... + - }); + + + const clientOptions = { + + chain: networkConfig.chain, + + transport: transportObserver(fallback([webSocket(), http()])), + + pollingInterval: 1000, + + } as const satisfies ClientConfig; + + + const publicClient = createPublicClient(clientOptions); + + + const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex); + + const burnerWalletClient = createWalletClient({ + + ...clientOptions, + + account: burnerAccount, + + }); + + + const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({ + + world, + + config: storeConfig, + + address: networkConfig.worldAddress as Hex, + + publicClient, + + components: contractComponents, + + startBlock: BigInt(networkConfig.initialBlockNumber), + + indexerUrl: networkConfig.indexerUrl ?? undefined, + + }); + + + const worldContract = createContract({ + + address: networkConfig.worldAddress as Hex, + + abi: IWorld__factory.abi, + + publicClient, + + walletClient: burnerWalletClient, + + }); + ``` + + ```diff + // Request drip from faucet + - const signer = result.network.signer.get(); + - if (networkConfig.faucetServiceUrl && signer) { + - const address = await signer.getAddress(); + + if (networkConfig.faucetServiceUrl) { + + const address = burnerAccount.address; + ``` + + ```diff + const requestDrip = async () => { + - const balance = await signer.getBalance(); + + const balance = await publicClient.getBalance({ address }); + console.info(`[Dev Faucet]: Player balance -> ${balance}`); + - const lowBalance = balance?.lte(utils.parseEther("1")); + + const lowBalance = balance < parseEther("1"); + ``` + + You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor. + + The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes. + + ```diff + + return { + + world, + + components, + + playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }), + + publicClient, + + walletClient: burnerWalletClient, + + latestBlock$, + + blockStorageOperations$, + + waitForTransaction, + + worldContract, + + }; + ``` + + 5. Update `createSystemCalls` with the new return type of `setupNetwork`. + + ```diff + export function createSystemCalls( + - { worldSend, txReduced$, singletonEntity }: SetupNetworkResult, + + { worldContract, waitForTransaction }: SetupNetworkResult, + { Counter }: ClientComponents + ) { + const increment = async () => { + - const tx = await worldSend("increment", []); + - await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash); + + const tx = await worldContract.write.increment(); + + await waitForTransaction(tx); + return getComponentValue(Counter, singletonEntity); + }; + ``` + + 6. (optional) If you still need a clock, you can create it with: + + ```ts + import { map, filter } from "rxjs"; + import { createClock } from "@latticexyz/network"; + + const clock = createClock({ + period: 1000, + initialTime: 0, + syncInterval: 5000, + }); + + world.registerDisposer(() => clock.dispose()); + + latestBlock$ + .pipe( + map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms + filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block + filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + ) + .subscribe(clock.update); // Update the local clock + ``` + + If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`: + + ```ts + import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs"; + + const syncProgress = useComponentValue(SyncProgress, singletonEntity, { + message: "Connecting", + percentage: 0, + step: SyncStep.INITIALIZE, + }); + + if (syncProgress.step === SyncStep.LIVE) { + // we're live! + } + ``` + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/create-mud/package.json b/packages/create-mud/package.json index 59bb091628..df39dea0d5 100644 --- a/packages/create-mud/package.json +++ b/packages/create-mud/package.json @@ -1,6 +1,6 @@ { "name": "create-mud", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Create a new MUD project", "license": "MIT", "author": "Lattice ", diff --git a/packages/dev-tools/CHANGELOG.md b/packages/dev-tools/CHANGELOG.md index 6e8ab1fb50..ec704cca98 100644 --- a/packages/dev-tools/CHANGELOG.md +++ b/packages/dev-tools/CHANGELOG.md @@ -1,5 +1,19 @@ # @latticexyz/dev-tools +## 2.0.0-next.1 + +### Patch Changes + +- [#1258](https://github.com/latticexyz/mud/pull/1258) [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7) Thanks [@holic](https://github.com/holic)! - Add `tableIdToHex` and `hexToTableId` pure functions and move/deprecate `TableId`. + +- Updated dependencies [[`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`e259ef79`](https://github.com/latticexyz/mud/commit/e259ef79f4d9026353176d0f74628cae50c2f69b), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/std-client@2.0.0-next.1 + - @latticexyz/network@2.0.0-next.1 + - @latticexyz/world@2.0.0-next.1 + - @latticexyz/react@2.0.0-next.1 + - @latticexyz/utils@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/dev-tools/package.json b/packages/dev-tools/package.json index 1e8bc30740..9a7f1d5268 100644 --- a/packages/dev-tools/package.json +++ b/packages/dev-tools/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/dev-tools", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "MUD developer tools", "repository": { "type": "git", @@ -49,10 +49,10 @@ "vitest": "0.31.4" }, "peerDependencies": { - "@latticexyz/network": "2.0.0-next.0", - "@latticexyz/std-client": "2.0.0-next.0", - "@latticexyz/utils": "2.0.0-next.0", - "@latticexyz/world": "2.0.0-next.0" + "@latticexyz/network": "2.0.0-next.1", + "@latticexyz/std-client": "2.0.0-next.1", + "@latticexyz/utils": "2.0.0-next.1", + "@latticexyz/world": "2.0.0-next.1" }, "publishConfig": { "access": "public" diff --git a/packages/ecs-browser/CHANGELOG.md b/packages/ecs-browser/CHANGELOG.md index 4ba8554b59..a6c7300901 100644 --- a/packages/ecs-browser/CHANGELOG.md +++ b/packages/ecs-browser/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- Updated dependencies [[`e259ef79`](https://github.com/latticexyz/mud/commit/e259ef79f4d9026353176d0f74628cae50c2f69b), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd)]: + - @latticexyz/std-client@2.0.0-next.1 + - @latticexyz/recs@2.0.0-next.1 + - @latticexyz/utils@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/ecs-browser/package.json b/packages/ecs-browser/package.json index 5b0d506419..1cb7b53a42 100644 --- a/packages/ecs-browser/package.json +++ b/packages/ecs-browser/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/ecs-browser", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Component Browser for RECS", "repository": { "type": "git", diff --git a/packages/gas-report/CHANGELOG.md b/packages/gas-report/CHANGELOG.md index 3142a43f4a..552b0de501 100644 --- a/packages/gas-report/CHANGELOG.md +++ b/packages/gas-report/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +## 2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/gas-report/package.json b/packages/gas-report/package.json index 91298ffa0c..afe9c8d17d 100644 --- a/packages/gas-report/package.json +++ b/packages/gas-report/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/gas-report", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Gas reporter for specific lines within forge tests", "repository": { "type": "git", diff --git a/packages/network/CHANGELOG.md b/packages/network/CHANGELOG.md index 27254774ef..76967eec03 100644 --- a/packages/network/CHANGELOG.md +++ b/packages/network/CHANGELOG.md @@ -1,5 +1,21 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- [#1258](https://github.com/latticexyz/mud/pull/1258) [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7) Thanks [@holic](https://github.com/holic)! - Add `tableIdToHex` and `hexToTableId` pure functions and move/deprecate `TableId`. + +- Updated dependencies [[`3236f799`](https://github.com/latticexyz/mud/commit/3236f799e501be227da6e42e7b41a4928750115c), [`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021), [`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/services@2.0.0-next.1 + - @latticexyz/store@2.0.0-next.1 + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + - @latticexyz/recs@2.0.0-next.1 + - @latticexyz/world@2.0.0-next.1 + - @latticexyz/solecs@2.0.0-next.1 + - @latticexyz/utils@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/network/package.json b/packages/network/package.json index 2d47dc50f7..0c773301a2 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/network", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "repository": { "type": "git", "url": "https://github.com/latticexyz/mud.git", diff --git a/packages/noise/CHANGELOG.md b/packages/noise/CHANGELOG.md index 909fd2841d..885f03e4c1 100644 --- a/packages/noise/CHANGELOG.md +++ b/packages/noise/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +## 2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/noise/package.json b/packages/noise/package.json index 7a03c172b7..3f06771e55 100644 --- a/packages/noise/package.json +++ b/packages/noise/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/noise", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "license": "MIT", "type": "module", "exports": { diff --git a/packages/phaserx/CHANGELOG.md b/packages/phaserx/CHANGELOG.md index fc7e820464..3008ff8e78 100644 --- a/packages/phaserx/CHANGELOG.md +++ b/packages/phaserx/CHANGELOG.md @@ -1,5 +1,12 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- Updated dependencies []: + - @latticexyz/utils@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/phaserx/package.json b/packages/phaserx/package.json index 2c46aecc02..4af5e4914b 100644 --- a/packages/phaserx/package.json +++ b/packages/phaserx/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/phaserx", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "repository": { "type": "git", "url": "https://github.com/latticexyz/mud.git", diff --git a/packages/protocol-parser/CHANGELOG.md b/packages/protocol-parser/CHANGELOG.md index 86b3d6f569..7d37840360 100644 --- a/packages/protocol-parser/CHANGELOG.md +++ b/packages/protocol-parser/CHANGELOG.md @@ -1,5 +1,13 @@ # @latticexyz/protocol-parser +## 2.0.0-next.1 + +### Patch Changes + +- Updated dependencies [[`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/protocol-parser/package.json b/packages/protocol-parser/package.json index e5272606d9..c340f7660c 100644 --- a/packages/protocol-parser/package.json +++ b/packages/protocol-parser/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/protocol-parser", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Parser utilities for the MUD protocol", "repository": { "type": "git", diff --git a/packages/react/CHANGELOG.md b/packages/react/CHANGELOG.md index 893e61296b..9c11baf31f 100644 --- a/packages/react/CHANGELOG.md +++ b/packages/react/CHANGELOG.md @@ -1,5 +1,14 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- Updated dependencies [[`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021), [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/store@2.0.0-next.1 + - @latticexyz/recs@2.0.0-next.1 + - @latticexyz/store-cache@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/react/package.json b/packages/react/package.json index 72d54a04dd..f3ba944dbc 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/react", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "React tools for MUD client.", "repository": { "type": "git", diff --git a/packages/recs/CHANGELOG.md b/packages/recs/CHANGELOG.md index d8391e781d..2e8466186c 100644 --- a/packages/recs/CHANGELOG.md +++ b/packages/recs/CHANGELOG.md @@ -1,5 +1,210 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- [#1214](https://github.com/latticexyz/mud/pull/1214) [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9) Thanks [@holic](https://github.com/holic)! - Templates and examples now use MUD's new sync packages, all built on top of [viem](https://viem.sh/). This greatly speeds up and stabilizes our networking code and improves types throughout. + + These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys. + + If you're using `store-cache` and `useRow`/`useRows`, you should wait to upgrade until we have a suitable replacement for those libraries. We're working on a [sql.js](https://github.com/sql-js/sql.js/)-powered sync module that will replace `store-cache`. + + **Migrate existing RECS apps to new sync packages** + + As you migrate, you may find some features replaced, removed, or not included by default. Please [open an issue](https://github.com/latticexyz/mud/issues/new) and let us know if we missed anything. + + 1. Add `@latticexyz/store-sync` package to your app's `client` package and make sure `viem` is pinned to version `1.3.1` (otherwise you may get type errors) + + 2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain. + + ```diff + - import { foundry } from "viem/chains"; + - import { MUDChain, latticeTestnet } from "@latticexyz/common/chains"; + + import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains"; + + - export const supportedChains: MUDChain[] = [foundry, latticeTestnet]; + + export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet]; + ``` + + 3. In `getNetworkConfig.ts`, remove the return type (to let TS infer it for now), remove now-unused config values, and add the viem `chain` object. + + ```diff + - export async function getNetworkConfig(): Promise { + + export async function getNetworkConfig() { + ``` + + ```diff + const initialBlockNumber = params.has("initialBlockNumber") + ? Number(params.get("initialBlockNumber")) + - : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC + + : world?.blockNumber ?? 0n; + ``` + + ```diff + + return { + + privateKey: getBurnerWallet().value, + + chain, + + worldAddress, + + initialBlockNumber, + + faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl, + + }; + ``` + + 4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`. + + ```diff + - import { setupMUDV2Network } from "@latticexyz/std-client"; + - import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network"; + + import { createFaucetService } from "@latticexyz/network"; + + import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem"; + + import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs"; + + import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common"; + ``` + + ```diff + - const result = await setupMUDV2Network({ + - ... + - }); + + + const clientOptions = { + + chain: networkConfig.chain, + + transport: transportObserver(fallback([webSocket(), http()])), + + pollingInterval: 1000, + + } as const satisfies ClientConfig; + + + const publicClient = createPublicClient(clientOptions); + + + const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex); + + const burnerWalletClient = createWalletClient({ + + ...clientOptions, + + account: burnerAccount, + + }); + + + const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({ + + world, + + config: storeConfig, + + address: networkConfig.worldAddress as Hex, + + publicClient, + + components: contractComponents, + + startBlock: BigInt(networkConfig.initialBlockNumber), + + indexerUrl: networkConfig.indexerUrl ?? undefined, + + }); + + + const worldContract = createContract({ + + address: networkConfig.worldAddress as Hex, + + abi: IWorld__factory.abi, + + publicClient, + + walletClient: burnerWalletClient, + + }); + ``` + + ```diff + // Request drip from faucet + - const signer = result.network.signer.get(); + - if (networkConfig.faucetServiceUrl && signer) { + - const address = await signer.getAddress(); + + if (networkConfig.faucetServiceUrl) { + + const address = burnerAccount.address; + ``` + + ```diff + const requestDrip = async () => { + - const balance = await signer.getBalance(); + + const balance = await publicClient.getBalance({ address }); + console.info(`[Dev Faucet]: Player balance -> ${balance}`); + - const lowBalance = balance?.lte(utils.parseEther("1")); + + const lowBalance = balance < parseEther("1"); + ``` + + You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor. + + The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes. + + ```diff + + return { + + world, + + components, + + playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }), + + publicClient, + + walletClient: burnerWalletClient, + + latestBlock$, + + blockStorageOperations$, + + waitForTransaction, + + worldContract, + + }; + ``` + + 5. Update `createSystemCalls` with the new return type of `setupNetwork`. + + ```diff + export function createSystemCalls( + - { worldSend, txReduced$, singletonEntity }: SetupNetworkResult, + + { worldContract, waitForTransaction }: SetupNetworkResult, + { Counter }: ClientComponents + ) { + const increment = async () => { + - const tx = await worldSend("increment", []); + - await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash); + + const tx = await worldContract.write.increment(); + + await waitForTransaction(tx); + return getComponentValue(Counter, singletonEntity); + }; + ``` + + 6. (optional) If you still need a clock, you can create it with: + + ```ts + import { map, filter } from "rxjs"; + import { createClock } from "@latticexyz/network"; + + const clock = createClock({ + period: 1000, + initialTime: 0, + syncInterval: 5000, + }); + + world.registerDisposer(() => clock.dispose()); + + latestBlock$ + .pipe( + map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms + filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block + filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + ) + .subscribe(clock.update); // Update the local clock + ``` + + If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`: + + ```ts + import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs"; + + const syncProgress = useComponentValue(SyncProgress, singletonEntity, { + message: "Connecting", + percentage: 0, + step: SyncStep.INITIALIZE, + }); + + if (syncProgress.step === SyncStep.LIVE) { + // we're live! + } + ``` + +- [#1195](https://github.com/latticexyz/mud/pull/1195) [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd) Thanks [@holic](https://github.com/holic)! - Update RECS components with v2 key/value schemas. This helps with encoding/decoding composite keys and strong types for keys/values. + + This may break if you were previously dependent on `component.id`, `component.metadata.componentId`, or `component.metadata.tableId`: + + - `component.id` is now the on-chain `bytes32` hex representation of the table ID + - `component.metadata.componentName` is the table name (e.g. `Position`) + - `component.metadata.tableName` is the namespaced table name (e.g. `myworld:Position`) + - `component.metadata.keySchema` is an object with key names and their corresponding ABI types + - `component.metadata.valueSchema` is an object with field names and their corresponding ABI types + +- Updated dependencies [[`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07)]: + - @latticexyz/schema-type@2.0.0-next.1 + - @latticexyz/utils@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/recs/package.json b/packages/recs/package.json index 2a83e49696..f1016cfdce 100644 --- a/packages/recs/package.json +++ b/packages/recs/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/recs", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "repository": { "type": "git", "url": "https://github.com/latticexyz/mud.git", diff --git a/packages/schema-type/CHANGELOG.md b/packages/schema-type/CHANGELOG.md index 87bd04d59c..07f3bdee33 100644 --- a/packages/schema-type/CHANGELOG.md +++ b/packages/schema-type/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 2.0.0-next.1 + +### Minor Changes + +- [#1196](https://github.com/latticexyz/mud/pull/1196) [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07) Thanks [@holic](https://github.com/holic)! - add type narrowing `isStaticAbiType` + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/schema-type/package.json b/packages/schema-type/package.json index d22d473607..8359220b20 100644 --- a/packages/schema-type/package.json +++ b/packages/schema-type/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/schema-type", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "SchemaType enum for various languages", "repository": { "type": "git", diff --git a/packages/services/CHANGELOG.md b/packages/services/CHANGELOG.md index af1b1d6420..5e1cb9198b 100644 --- a/packages/services/CHANGELOG.md +++ b/packages/services/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- [#1116](https://github.com/latticexyz/mud/pull/1116) [`3236f799`](https://github.com/latticexyz/mud/commit/3236f799e501be227da6e42e7b41a4928750115c) Thanks [@authcall](https://github.com/authcall)! - protocol-parser in Go + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/services/package.json b/packages/services/package.json index f6f1589f34..68172e8f6f 100644 --- a/packages/services/package.json +++ b/packages/services/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/services", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "MUD services for enhanced interactions with on-chain ECS state", "repository": { "type": "git", diff --git a/packages/solecs/CHANGELOG.md b/packages/solecs/CHANGELOG.md index 37b870fea7..302792aeb7 100644 --- a/packages/solecs/CHANGELOG.md +++ b/packages/solecs/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +## 2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/solecs/package.json b/packages/solecs/package.json index 42a459096c..32b0ffd8e4 100644 --- a/packages/solecs/package.json +++ b/packages/solecs/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/solecs", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Solidity Entity Component System", "repository": { "type": "git", diff --git a/packages/solhint-config-mud/CHANGELOG.md b/packages/solhint-config-mud/CHANGELOG.md index da3ed97883..c804e256a5 100644 --- a/packages/solhint-config-mud/CHANGELOG.md +++ b/packages/solhint-config-mud/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +## 2.0.0-next.1 + ## 2.0.0-next.0 All notable changes to this project will be documented in this file. diff --git a/packages/solhint-config-mud/package.json b/packages/solhint-config-mud/package.json index 950cb06b82..a2ee399c42 100644 --- a/packages/solhint-config-mud/package.json +++ b/packages/solhint-config-mud/package.json @@ -1,6 +1,6 @@ { "name": "solhint-config-mud", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "repository": { "type": "git", "url": "https://github.com/latticexyz/mud.git", diff --git a/packages/solhint-plugin-mud/CHANGELOG.md b/packages/solhint-plugin-mud/CHANGELOG.md index da3ed97883..c804e256a5 100644 --- a/packages/solhint-plugin-mud/CHANGELOG.md +++ b/packages/solhint-plugin-mud/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +## 2.0.0-next.1 + ## 2.0.0-next.0 All notable changes to this project will be documented in this file. diff --git a/packages/solhint-plugin-mud/package.json b/packages/solhint-plugin-mud/package.json index aad68cd4e7..909da43ef5 100644 --- a/packages/solhint-plugin-mud/package.json +++ b/packages/solhint-plugin-mud/package.json @@ -1,6 +1,6 @@ { "name": "solhint-plugin-mud", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "repository": { "type": "git", "url": "https://github.com/latticexyz/mud.git", diff --git a/packages/std-client/CHANGELOG.md b/packages/std-client/CHANGELOG.md index 4c940d9b63..c2981b6645 100644 --- a/packages/std-client/CHANGELOG.md +++ b/packages/std-client/CHANGELOG.md @@ -1,5 +1,35 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- [#1206](https://github.com/latticexyz/mud/pull/1206) [`e259ef79`](https://github.com/latticexyz/mud/commit/e259ef79f4d9026353176d0f74628cae50c2f69b) Thanks [@holic](https://github.com/holic)! - Generated `contractComponents` now properly import `World` as type + +- [#1258](https://github.com/latticexyz/mud/pull/1258) [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7) Thanks [@holic](https://github.com/holic)! - Add `tableIdToHex` and `hexToTableId` pure functions and move/deprecate `TableId`. + +- [#1195](https://github.com/latticexyz/mud/pull/1195) [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd) Thanks [@holic](https://github.com/holic)! - Update RECS components with v2 key/value schemas. This helps with encoding/decoding composite keys and strong types for keys/values. + + This may break if you were previously dependent on `component.id`, `component.metadata.componentId`, or `component.metadata.tableId`: + + - `component.id` is now the on-chain `bytes32` hex representation of the table ID + - `component.metadata.componentName` is the table name (e.g. `Position`) + - `component.metadata.tableName` is the namespaced table name (e.g. `myworld:Position`) + - `component.metadata.keySchema` is an object with key names and their corresponding ABI types + - `component.metadata.valueSchema` is an object with field names and their corresponding ABI types + +- Updated dependencies [[`168a4cb4`](https://github.com/latticexyz/mud/commit/168a4cb43ce4f7bfbdb7b1b9d4c305b912a0d3f2), [`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021), [`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206), [`e259ef79`](https://github.com/latticexyz/mud/commit/e259ef79f4d9026353176d0f74628cae50c2f69b), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/cli@2.0.0-next.1 + - @latticexyz/store@2.0.0-next.1 + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/recs@2.0.0-next.1 + - @latticexyz/network@2.0.0-next.1 + - @latticexyz/world@2.0.0-next.1 + - @latticexyz/store-cache@2.0.0-next.1 + - @latticexyz/config@2.0.0-next.1 + - @latticexyz/solecs@2.0.0-next.1 + - @latticexyz/utils@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/std-client/package.json b/packages/std-client/package.json index 38ede79c5a..888c75f3bb 100644 --- a/packages/std-client/package.json +++ b/packages/std-client/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/std-client", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Standard library for MUD client.", "repository": { "type": "git", diff --git a/packages/std-contracts/CHANGELOG.md b/packages/std-contracts/CHANGELOG.md index 00b22b7f08..61e2c56abe 100644 --- a/packages/std-contracts/CHANGELOG.md +++ b/packages/std-contracts/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +## 2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/std-contracts/package.json b/packages/std-contracts/package.json index 81727f613c..b70ccc72e7 100644 --- a/packages/std-contracts/package.json +++ b/packages/std-contracts/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/std-contracts", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "MUD Contracts Standard Library", "repository": { "type": "git", diff --git a/packages/store-cache/CHANGELOG.md b/packages/store-cache/CHANGELOG.md index dedfd98bb8..171c025126 100644 --- a/packages/store-cache/CHANGELOG.md +++ b/packages/store-cache/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- Updated dependencies [[`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021), [`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/store@2.0.0-next.1 + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + - @latticexyz/config@2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/store-cache/package.json b/packages/store-cache/package.json index 2031277211..013f9247f4 100644 --- a/packages/store-cache/package.json +++ b/packages/store-cache/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/store-cache", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Database to replicate Store contract state on a TypeScript client", "repository": { "type": "git", diff --git a/packages/store-indexer/CHANGELOG.md b/packages/store-indexer/CHANGELOG.md new file mode 100644 index 0000000000..67cda5a3f1 --- /dev/null +++ b/packages/store-indexer/CHANGELOG.md @@ -0,0 +1,232 @@ +# @latticexyz/store-indexer + +## 2.0.0-next.1 + +### Major Changes + +- [#1198](https://github.com/latticexyz/mud/pull/1198) [`e86fbc12`](https://github.com/latticexyz/mud/commit/e86fbc1260f698c6a7b6a92c901fefd186c329ff) Thanks [@holic](https://github.com/holic)! - Adds store indexer service package with utils to query the indexer service. + + You can run the indexer locally by checking out the MUD monorepo, installing/building everything, and running `pnpm start:local` from `packages/store-indexer`. + + To query the indexer in the client, you can create a tRPC client with a URL pointing to the indexer service and call the available tRPC methods: + + ```ts + import { createIndexerClient } from "@latticexyz/store-sync/trpc-indexer"; + + const indexer = createIndexerClient({ url: indexerUrl }); + const result = await indexer.findAll.query({ + chainId: publicClient.chain.id, + address, + }); + ``` + + If you're using `syncToRecs`, you can just pass in the `indexerUrl` option as a shortcut to the above: + + ```ts + import { syncToRecs } from "@latticexyz/store-sync/recs"; + + syncToRecs({ + ... + indexerUrl: "https://your.indexer.service", + }); + ``` + +### Minor Changes + +- [#1234](https://github.com/latticexyz/mud/pull/1234) [`131c63e5`](https://github.com/latticexyz/mud/commit/131c63e539a8e9947835dcc323c8b37562aed9ca) Thanks [@holic](https://github.com/holic)! - - Accept a plain viem `PublicClient` (instead of requiring a `Chain` to be set) in `store-sync` and `store-indexer` functions. These functions now fetch chain ID using `publicClient.getChainId()` when no `publicClient.chain.id` is present. + - Allow configuring `store-indexer` with a set of RPC URLs (`RPC_HTTP_URL` and `RPC_WS_URL`) instead of `CHAIN_ID`. + +### Patch Changes + +- [#1214](https://github.com/latticexyz/mud/pull/1214) [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9) Thanks [@holic](https://github.com/holic)! - Templates and examples now use MUD's new sync packages, all built on top of [viem](https://viem.sh/). This greatly speeds up and stabilizes our networking code and improves types throughout. + + These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys. + + If you're using `store-cache` and `useRow`/`useRows`, you should wait to upgrade until we have a suitable replacement for those libraries. We're working on a [sql.js](https://github.com/sql-js/sql.js/)-powered sync module that will replace `store-cache`. + + **Migrate existing RECS apps to new sync packages** + + As you migrate, you may find some features replaced, removed, or not included by default. Please [open an issue](https://github.com/latticexyz/mud/issues/new) and let us know if we missed anything. + + 1. Add `@latticexyz/store-sync` package to your app's `client` package and make sure `viem` is pinned to version `1.3.1` (otherwise you may get type errors) + + 2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain. + + ```diff + - import { foundry } from "viem/chains"; + - import { MUDChain, latticeTestnet } from "@latticexyz/common/chains"; + + import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains"; + + - export const supportedChains: MUDChain[] = [foundry, latticeTestnet]; + + export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet]; + ``` + + 3. In `getNetworkConfig.ts`, remove the return type (to let TS infer it for now), remove now-unused config values, and add the viem `chain` object. + + ```diff + - export async function getNetworkConfig(): Promise { + + export async function getNetworkConfig() { + ``` + + ```diff + const initialBlockNumber = params.has("initialBlockNumber") + ? Number(params.get("initialBlockNumber")) + - : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC + + : world?.blockNumber ?? 0n; + ``` + + ```diff + + return { + + privateKey: getBurnerWallet().value, + + chain, + + worldAddress, + + initialBlockNumber, + + faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl, + + }; + ``` + + 4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`. + + ```diff + - import { setupMUDV2Network } from "@latticexyz/std-client"; + - import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network"; + + import { createFaucetService } from "@latticexyz/network"; + + import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem"; + + import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs"; + + import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common"; + ``` + + ```diff + - const result = await setupMUDV2Network({ + - ... + - }); + + + const clientOptions = { + + chain: networkConfig.chain, + + transport: transportObserver(fallback([webSocket(), http()])), + + pollingInterval: 1000, + + } as const satisfies ClientConfig; + + + const publicClient = createPublicClient(clientOptions); + + + const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex); + + const burnerWalletClient = createWalletClient({ + + ...clientOptions, + + account: burnerAccount, + + }); + + + const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({ + + world, + + config: storeConfig, + + address: networkConfig.worldAddress as Hex, + + publicClient, + + components: contractComponents, + + startBlock: BigInt(networkConfig.initialBlockNumber), + + indexerUrl: networkConfig.indexerUrl ?? undefined, + + }); + + + const worldContract = createContract({ + + address: networkConfig.worldAddress as Hex, + + abi: IWorld__factory.abi, + + publicClient, + + walletClient: burnerWalletClient, + + }); + ``` + + ```diff + // Request drip from faucet + - const signer = result.network.signer.get(); + - if (networkConfig.faucetServiceUrl && signer) { + - const address = await signer.getAddress(); + + if (networkConfig.faucetServiceUrl) { + + const address = burnerAccount.address; + ``` + + ```diff + const requestDrip = async () => { + - const balance = await signer.getBalance(); + + const balance = await publicClient.getBalance({ address }); + console.info(`[Dev Faucet]: Player balance -> ${balance}`); + - const lowBalance = balance?.lte(utils.parseEther("1")); + + const lowBalance = balance < parseEther("1"); + ``` + + You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor. + + The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes. + + ```diff + + return { + + world, + + components, + + playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }), + + publicClient, + + walletClient: burnerWalletClient, + + latestBlock$, + + blockStorageOperations$, + + waitForTransaction, + + worldContract, + + }; + ``` + + 5. Update `createSystemCalls` with the new return type of `setupNetwork`. + + ```diff + export function createSystemCalls( + - { worldSend, txReduced$, singletonEntity }: SetupNetworkResult, + + { worldContract, waitForTransaction }: SetupNetworkResult, + { Counter }: ClientComponents + ) { + const increment = async () => { + - const tx = await worldSend("increment", []); + - await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash); + + const tx = await worldContract.write.increment(); + + await waitForTransaction(tx); + return getComponentValue(Counter, singletonEntity); + }; + ``` + + 6. (optional) If you still need a clock, you can create it with: + + ```ts + import { map, filter } from "rxjs"; + import { createClock } from "@latticexyz/network"; + + const clock = createClock({ + period: 1000, + initialTime: 0, + syncInterval: 5000, + }); + + world.registerDisposer(() => clock.dispose()); + + latestBlock$ + .pipe( + map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms + filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block + filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct + ) + .subscribe(clock.update); // Update the local clock + ``` + + If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`: + + ```ts + import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs"; + + const syncProgress = useComponentValue(SyncProgress, singletonEntity, { + message: "Connecting", + percentage: 0, + step: SyncStep.INITIALIZE, + }); + + if (syncProgress.step === SyncStep.LIVE) { + // we're live! + } + ``` + +- Updated dependencies [[`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021), [`e86fbc12`](https://github.com/latticexyz/mud/commit/e86fbc1260f698c6a7b6a92c901fefd186c329ff), [`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`57a52608`](https://github.com/latticexyz/mud/commit/57a5260830401c9ad93196a895a50b0fc4a86183), [`9e5baf4f`](https://github.com/latticexyz/mud/commit/9e5baf4fff0c60615b8f2b4645fb11cb78cb0bd8), [`131c63e5`](https://github.com/latticexyz/mud/commit/131c63e539a8e9947835dcc323c8b37562aed9ca), [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206), [`582388ba`](https://github.com/latticexyz/mud/commit/582388ba5f95c3efde56779058220dbd7aedee0b), [`582388ba`](https://github.com/latticexyz/mud/commit/582388ba5f95c3efde56779058220dbd7aedee0b), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/store@2.0.0-next.1 + - @latticexyz/store-sync@2.0.0-next.1 + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/block-logs-stream@2.0.0-next.1 diff --git a/packages/store-indexer/package.json b/packages/store-indexer/package.json index a1dd58cbe7..e23a10802b 100644 --- a/packages/store-indexer/package.json +++ b/packages/store-indexer/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/store-indexer", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Minimal Typescript indexer for Store", "repository": { "type": "git", diff --git a/packages/store-sync/CHANGELOG.md b/packages/store-sync/CHANGELOG.md index 3111308f11..5a0b5b2e7e 100644 --- a/packages/store-sync/CHANGELOG.md +++ b/packages/store-sync/CHANGELOG.md @@ -1,5 +1,99 @@ # @latticexyz/store-sync +## 2.0.0-next.1 + +### Major Changes + +- [#1198](https://github.com/latticexyz/mud/pull/1198) [`e86fbc12`](https://github.com/latticexyz/mud/commit/e86fbc1260f698c6a7b6a92c901fefd186c329ff) Thanks [@holic](https://github.com/holic)! - Adds store indexer service package with utils to query the indexer service. + + You can run the indexer locally by checking out the MUD monorepo, installing/building everything, and running `pnpm start:local` from `packages/store-indexer`. + + To query the indexer in the client, you can create a tRPC client with a URL pointing to the indexer service and call the available tRPC methods: + + ```ts + import { createIndexerClient } from "@latticexyz/store-sync/trpc-indexer"; + + const indexer = createIndexerClient({ url: indexerUrl }); + const result = await indexer.findAll.query({ + chainId: publicClient.chain.id, + address, + }); + ``` + + If you're using `syncToRecs`, you can just pass in the `indexerUrl` option as a shortcut to the above: + + ```ts + import { syncToRecs } from "@latticexyz/store-sync/recs"; + + syncToRecs({ + ... + indexerUrl: "https://your.indexer.service", + }); + ``` + +### Minor Changes + +- [#1234](https://github.com/latticexyz/mud/pull/1234) [`131c63e5`](https://github.com/latticexyz/mud/commit/131c63e539a8e9947835dcc323c8b37562aed9ca) Thanks [@holic](https://github.com/holic)! - - Accept a plain viem `PublicClient` (instead of requiring a `Chain` to be set) in `store-sync` and `store-indexer` functions. These functions now fetch chain ID using `publicClient.getChainId()` when no `publicClient.chain.id` is present. + + - Allow configuring `store-indexer` with a set of RPC URLs (`RPC_HTTP_URL` and `RPC_WS_URL`) instead of `CHAIN_ID`. + +- [#1235](https://github.com/latticexyz/mud/pull/1235) [`582388ba`](https://github.com/latticexyz/mud/commit/582388ba5f95c3efde56779058220dbd7aedee0b) Thanks [@holic](https://github.com/holic)! - Export `singletonEntity` as const rather than within the `syncToRecs` result. + + ```diff + - const { singletonEntity, ... } = syncToRecs({ ... }); + + import { singletonEntity, syncToRecs } from "@latticexyz/store-sync/recs"; + + const { ... } = syncToRecs({ ... }); + ``` + +### Patch Changes + +- [#1228](https://github.com/latticexyz/mud/pull/1228) [`57a52608`](https://github.com/latticexyz/mud/commit/57a5260830401c9ad93196a895a50b0fc4a86183) Thanks [@holic](https://github.com/holic)! - Adds `latestBlockNumber` and `lastBlockNumberProcessed` to internal `SyncProgress` component + +- [#1197](https://github.com/latticexyz/mud/pull/1197) [`9e5baf4f`](https://github.com/latticexyz/mud/commit/9e5baf4fff0c60615b8f2b4645fb11cb78cb0bd8) Thanks [@holic](https://github.com/holic)! - Add RECS sync strategy and corresponding utils + + ```ts + import { createPublicClient, http } from 'viem'; + import { syncToRecs } from '@latticexyz/store-sync'; + import storeConfig from 'contracts/mud.config'; + import { defineContractComponents } from './defineContractComponents'; + + const publicClient = createPublicClient({ + chain, + transport: http(), + pollingInterval: 1000, + }); + + const { components, singletonEntity, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({ + world, + config: storeConfig, + address: '0x...', + publicClient, + components: defineContractComponents(...), + }); + ``` + +- [#1235](https://github.com/latticexyz/mud/pull/1235) [`582388ba`](https://github.com/latticexyz/mud/commit/582388ba5f95c3efde56779058220dbd7aedee0b) Thanks [@holic](https://github.com/holic)! - Add `startBlock` option to `syncToRecs`. + + ```ts + import { syncToRecs } from "@latticexyz/store-sync/recs"; + import worlds from "contracts/worlds.json"; + + syncToRecs({ + startBlock: worlds['31337'].blockNumber, + ... + }); + ``` + +- [#1258](https://github.com/latticexyz/mud/pull/1258) [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7) Thanks [@holic](https://github.com/holic)! - Add `tableIdToHex` and `hexToTableId` pure functions and move/deprecate `TableId`. + +- Updated dependencies [[`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021), [`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`afdba793`](https://github.com/latticexyz/mud/commit/afdba793fd84abf17eef5ef59dd56fabe353c8bd), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/store@2.0.0-next.1 + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + - @latticexyz/recs@2.0.0-next.1 + - @latticexyz/block-logs-stream@2.0.0-next.1 + - @latticexyz/protocol-parser@2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/store-sync/package.json b/packages/store-sync/package.json index 71418ece36..91db043557 100644 --- a/packages/store-sync/package.json +++ b/packages/store-sync/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/store-sync", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Utilities to sync MUD Store events with a client or cache", "repository": { "type": "git", diff --git a/packages/store/CHANGELOG.md b/packages/store/CHANGELOG.md index c38ca4f06f..0550c1295f 100644 --- a/packages/store/CHANGELOG.md +++ b/packages/store/CHANGELOG.md @@ -1,5 +1,22 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- [#1194](https://github.com/latticexyz/mud/pull/1194) [`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021) Thanks [@dk1a](https://github.com/dk1a)! - Optimize storage library + +- [#1237](https://github.com/latticexyz/mud/pull/1237) [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206) Thanks [@alvrs](https://github.com/alvrs)! - Align Store events parameter naming between IStoreWrite and StoreCore + +- [#1210](https://github.com/latticexyz/mud/pull/1210) [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3) Thanks [@dk1a](https://github.com/dk1a)! - - Refactor tightcoder to use typescript functions instead of ejs + - Optimize `TightCoder` library + - Add `isLeftAligned` and `getLeftPaddingBits` common codegen helpers +- Updated dependencies [[`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + - @latticexyz/config@2.0.0-next.1 + - @latticexyz/gas-report@2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/store/package.json b/packages/store/package.json index 5110b51940..fa398731b4 100644 --- a/packages/store/package.json +++ b/packages/store/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/store", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "Store", "repository": { "type": "git", diff --git a/packages/utils/CHANGELOG.md b/packages/utils/CHANGELOG.md index e0407bdf06..a1dc460375 100644 --- a/packages/utils/CHANGELOG.md +++ b/packages/utils/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +## 2.0.0-next.1 + ## 2.0.0-next.0 ### Patch Changes diff --git a/packages/utils/package.json b/packages/utils/package.json index 71a160da3c..9d941049d1 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/utils", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "repository": { "type": "git", "url": "https://github.com/latticexyz/mud.git", diff --git a/packages/world/CHANGELOG.md b/packages/world/CHANGELOG.md index 40ccdaaa50..ed4b886c2c 100644 --- a/packages/world/CHANGELOG.md +++ b/packages/world/CHANGELOG.md @@ -1,5 +1,19 @@ # Change Log +## 2.0.0-next.1 + +### Patch Changes + +- [#1210](https://github.com/latticexyz/mud/pull/1210) [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3) Thanks [@dk1a](https://github.com/dk1a)! - - Refactor tightcoder to use typescript functions instead of ejs + - Optimize `TightCoder` library + - Add `isLeftAligned` and `getLeftPaddingBits` common codegen helpers +- Updated dependencies [[`c963b46c`](https://github.com/latticexyz/mud/commit/c963b46c7eaceebc652930936643365b8c48a021), [`3fb9ce28`](https://github.com/latticexyz/mud/commit/3fb9ce2839271a0dcfe97f86394195f7a6f70f50), [`35c9f33d`](https://github.com/latticexyz/mud/commit/35c9f33dfb84b0bb94e0f7a8b0c9830761795bdb), [`5c965a91`](https://github.com/latticexyz/mud/commit/5c965a919355bf98d7ea69463890fe605bcde206), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`60cfd089`](https://github.com/latticexyz/mud/commit/60cfd089fc7a17b98864b631d265f36718df35a9), [`6071163f`](https://github.com/latticexyz/mud/commit/6071163f70599384c5034dd772ef6fc7cdae9983), [`6c673325`](https://github.com/latticexyz/mud/commit/6c6733256f91cddb0e913217cbd8e02e6bc484c7), [`cd5abcc3`](https://github.com/latticexyz/mud/commit/cd5abcc3b4744fab9a45c322bc76ff013355ffcb), [`cc2c8da0`](https://github.com/latticexyz/mud/commit/cc2c8da000c32c02a82a1a0fd17075d11eac56c3)]: + - @latticexyz/store@2.0.0-next.1 + - @latticexyz/common@2.0.0-next.1 + - @latticexyz/schema-type@2.0.0-next.1 + - @latticexyz/config@2.0.0-next.1 + - @latticexyz/gas-report@2.0.0-next.1 + ## 2.0.0-next.0 ### Minor Changes diff --git a/packages/world/package.json b/packages/world/package.json index ed0ad417ba..165935038f 100644 --- a/packages/world/package.json +++ b/packages/world/package.json @@ -1,6 +1,6 @@ { "name": "@latticexyz/world", - "version": "2.0.0-next.0", + "version": "2.0.0-next.1", "description": "World framework", "repository": { "type": "git",