@latticexyz/recs 2.0.0-main-35c9f33d → 2.0.0-main-788de8de
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +208 -3
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## 2.0.0-main-
|
3
|
+
## 2.0.0-main-788de8de
|
4
4
|
|
5
5
|
### Patch Changes
|
6
6
|
|
@@ -204,8 +204,213 @@
|
|
204
204
|
- `component.metadata.valueSchema` is an object with field names and their corresponding ABI types
|
205
205
|
|
206
206
|
- Updated dependencies [[`48909d15`](https://github.com/latticexyz/mud/commit/48909d151b3dfceab128c120bc6bb77de53c456b), [`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07), [`f03531d9`](https://github.com/latticexyz/mud/commit/f03531d97c999954a626ef63bc5bbae51a7b90f3), [`4e4a3415`](https://github.com/latticexyz/mud/commit/4e4a34150aeae988c8e61e25d55c227afb6c2d4b), [`53522998`](https://github.com/latticexyz/mud/commit/535229984565539e6168042150b45fe0f9b48b0f)]:
|
207
|
-
- @latticexyz/schema-type@2.0.0-main-
|
208
|
-
- @latticexyz/utils@2.0.0-main-
|
207
|
+
- @latticexyz/schema-type@2.0.0-main-788de8de
|
208
|
+
- @latticexyz/utils@2.0.0-main-788de8de
|
209
|
+
|
210
|
+
## 2.0.0-next.1
|
211
|
+
|
212
|
+
### Patch Changes
|
213
|
+
|
214
|
+
- [#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.
|
215
|
+
|
216
|
+
These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys.
|
217
|
+
|
218
|
+
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`.
|
219
|
+
|
220
|
+
**Migrate existing RECS apps to new sync packages**
|
221
|
+
|
222
|
+
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.
|
223
|
+
|
224
|
+
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)
|
225
|
+
|
226
|
+
2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain.
|
227
|
+
|
228
|
+
```diff
|
229
|
+
- import { foundry } from "viem/chains";
|
230
|
+
- import { MUDChain, latticeTestnet } from "@latticexyz/common/chains";
|
231
|
+
+ import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains";
|
232
|
+
|
233
|
+
- export const supportedChains: MUDChain[] = [foundry, latticeTestnet];
|
234
|
+
+ export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet];
|
235
|
+
```
|
236
|
+
|
237
|
+
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.
|
238
|
+
|
239
|
+
```diff
|
240
|
+
- export async function getNetworkConfig(): Promise<NetworkConfig> {
|
241
|
+
+ export async function getNetworkConfig() {
|
242
|
+
```
|
243
|
+
|
244
|
+
```diff
|
245
|
+
const initialBlockNumber = params.has("initialBlockNumber")
|
246
|
+
? Number(params.get("initialBlockNumber"))
|
247
|
+
- : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC
|
248
|
+
+ : world?.blockNumber ?? 0n;
|
249
|
+
```
|
250
|
+
|
251
|
+
```diff
|
252
|
+
+ return {
|
253
|
+
+ privateKey: getBurnerWallet().value,
|
254
|
+
+ chain,
|
255
|
+
+ worldAddress,
|
256
|
+
+ initialBlockNumber,
|
257
|
+
+ faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
|
258
|
+
+ };
|
259
|
+
```
|
260
|
+
|
261
|
+
4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`.
|
262
|
+
|
263
|
+
```diff
|
264
|
+
- import { setupMUDV2Network } from "@latticexyz/std-client";
|
265
|
+
- import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network";
|
266
|
+
+ import { createFaucetService } from "@latticexyz/network";
|
267
|
+
+ import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem";
|
268
|
+
+ import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
|
269
|
+
+ import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common";
|
270
|
+
```
|
271
|
+
|
272
|
+
```diff
|
273
|
+
- const result = await setupMUDV2Network({
|
274
|
+
- ...
|
275
|
+
- });
|
276
|
+
|
277
|
+
+ const clientOptions = {
|
278
|
+
+ chain: networkConfig.chain,
|
279
|
+
+ transport: transportObserver(fallback([webSocket(), http()])),
|
280
|
+
+ pollingInterval: 1000,
|
281
|
+
+ } as const satisfies ClientConfig;
|
282
|
+
|
283
|
+
+ const publicClient = createPublicClient(clientOptions);
|
284
|
+
|
285
|
+
+ const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex);
|
286
|
+
+ const burnerWalletClient = createWalletClient({
|
287
|
+
+ ...clientOptions,
|
288
|
+
+ account: burnerAccount,
|
289
|
+
+ });
|
290
|
+
|
291
|
+
+ const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({
|
292
|
+
+ world,
|
293
|
+
+ config: storeConfig,
|
294
|
+
+ address: networkConfig.worldAddress as Hex,
|
295
|
+
+ publicClient,
|
296
|
+
+ components: contractComponents,
|
297
|
+
+ startBlock: BigInt(networkConfig.initialBlockNumber),
|
298
|
+
+ indexerUrl: networkConfig.indexerUrl ?? undefined,
|
299
|
+
+ });
|
300
|
+
|
301
|
+
+ const worldContract = createContract({
|
302
|
+
+ address: networkConfig.worldAddress as Hex,
|
303
|
+
+ abi: IWorld__factory.abi,
|
304
|
+
+ publicClient,
|
305
|
+
+ walletClient: burnerWalletClient,
|
306
|
+
+ });
|
307
|
+
```
|
308
|
+
|
309
|
+
```diff
|
310
|
+
// Request drip from faucet
|
311
|
+
- const signer = result.network.signer.get();
|
312
|
+
- if (networkConfig.faucetServiceUrl && signer) {
|
313
|
+
- const address = await signer.getAddress();
|
314
|
+
+ if (networkConfig.faucetServiceUrl) {
|
315
|
+
+ const address = burnerAccount.address;
|
316
|
+
```
|
317
|
+
|
318
|
+
```diff
|
319
|
+
const requestDrip = async () => {
|
320
|
+
- const balance = await signer.getBalance();
|
321
|
+
+ const balance = await publicClient.getBalance({ address });
|
322
|
+
console.info(`[Dev Faucet]: Player balance -> ${balance}`);
|
323
|
+
- const lowBalance = balance?.lte(utils.parseEther("1"));
|
324
|
+
+ const lowBalance = balance < parseEther("1");
|
325
|
+
```
|
326
|
+
|
327
|
+
You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor.
|
328
|
+
|
329
|
+
The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes.
|
330
|
+
|
331
|
+
```diff
|
332
|
+
+ return {
|
333
|
+
+ world,
|
334
|
+
+ components,
|
335
|
+
+ playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }),
|
336
|
+
+ publicClient,
|
337
|
+
+ walletClient: burnerWalletClient,
|
338
|
+
+ latestBlock$,
|
339
|
+
+ blockStorageOperations$,
|
340
|
+
+ waitForTransaction,
|
341
|
+
+ worldContract,
|
342
|
+
+ };
|
343
|
+
```
|
344
|
+
|
345
|
+
5. Update `createSystemCalls` with the new return type of `setupNetwork`.
|
346
|
+
|
347
|
+
```diff
|
348
|
+
export function createSystemCalls(
|
349
|
+
- { worldSend, txReduced$, singletonEntity }: SetupNetworkResult,
|
350
|
+
+ { worldContract, waitForTransaction }: SetupNetworkResult,
|
351
|
+
{ Counter }: ClientComponents
|
352
|
+
) {
|
353
|
+
const increment = async () => {
|
354
|
+
- const tx = await worldSend("increment", []);
|
355
|
+
- await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash);
|
356
|
+
+ const tx = await worldContract.write.increment();
|
357
|
+
+ await waitForTransaction(tx);
|
358
|
+
return getComponentValue(Counter, singletonEntity);
|
359
|
+
};
|
360
|
+
```
|
361
|
+
|
362
|
+
6. (optional) If you still need a clock, you can create it with:
|
363
|
+
|
364
|
+
```ts
|
365
|
+
import { map, filter } from "rxjs";
|
366
|
+
import { createClock } from "@latticexyz/network";
|
367
|
+
|
368
|
+
const clock = createClock({
|
369
|
+
period: 1000,
|
370
|
+
initialTime: 0,
|
371
|
+
syncInterval: 5000,
|
372
|
+
});
|
373
|
+
|
374
|
+
world.registerDisposer(() => clock.dispose());
|
375
|
+
|
376
|
+
latestBlock$
|
377
|
+
.pipe(
|
378
|
+
map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms
|
379
|
+
filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block
|
380
|
+
filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct
|
381
|
+
)
|
382
|
+
.subscribe(clock.update); // Update the local clock
|
383
|
+
```
|
384
|
+
|
385
|
+
If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`:
|
386
|
+
|
387
|
+
```ts
|
388
|
+
import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs";
|
389
|
+
|
390
|
+
const syncProgress = useComponentValue(SyncProgress, singletonEntity, {
|
391
|
+
message: "Connecting",
|
392
|
+
percentage: 0,
|
393
|
+
step: SyncStep.INITIALIZE,
|
394
|
+
});
|
395
|
+
|
396
|
+
if (syncProgress.step === SyncStep.LIVE) {
|
397
|
+
// we're live!
|
398
|
+
}
|
399
|
+
```
|
400
|
+
|
401
|
+
- [#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.
|
402
|
+
|
403
|
+
This may break if you were previously dependent on `component.id`, `component.metadata.componentId`, or `component.metadata.tableId`:
|
404
|
+
|
405
|
+
- `component.id` is now the on-chain `bytes32` hex representation of the table ID
|
406
|
+
- `component.metadata.componentName` is the table name (e.g. `Position`)
|
407
|
+
- `component.metadata.tableName` is the namespaced table name (e.g. `myworld:Position`)
|
408
|
+
- `component.metadata.keySchema` is an object with key names and their corresponding ABI types
|
409
|
+
- `component.metadata.valueSchema` is an object with field names and their corresponding ABI types
|
410
|
+
|
411
|
+
- Updated dependencies [[`b02f9d0e`](https://github.com/latticexyz/mud/commit/b02f9d0e43089e5f9b46d817ea2032ce0a1b0b07)]:
|
412
|
+
- @latticexyz/schema-type@2.0.0-next.1
|
413
|
+
- @latticexyz/utils@2.0.0-next.1
|
209
414
|
|
210
415
|
## 2.0.0-next.0
|
211
416
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@latticexyz/recs",
|
3
|
-
"version": "2.0.0-main-
|
3
|
+
"version": "2.0.0-main-788de8de",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "https://github.com/latticexyz/mud.git",
|
@@ -15,8 +15,8 @@
|
|
15
15
|
"dependencies": {
|
16
16
|
"mobx": "^6.7.0",
|
17
17
|
"rxjs": "7.5.5",
|
18
|
-
"@latticexyz/schema-type": "2.0.0-main-
|
19
|
-
"@latticexyz/utils": "2.0.0-main-
|
18
|
+
"@latticexyz/schema-type": "2.0.0-main-788de8de",
|
19
|
+
"@latticexyz/utils": "2.0.0-main-788de8de"
|
20
20
|
},
|
21
21
|
"devDependencies": {
|
22
22
|
"@types/jest": "^27.4.1",
|