@latticexyz/recs 2.0.0-next.8 → 2.0.0-skystrife-playtest-3e6ab07b
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 +249 -0
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,254 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 2.0.0-skystrife-playtest-3e6ab07b
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- [#1351](https://github.com/latticexyz/mud/pull/1351) [`c14f8bf1`](https://github.com/latticexyz/mud/commit/c14f8bf1ec8c199902c12899853ac144aa69bb9c) Thanks [@holic](https://github.com/holic)! - - Moved `createActionSystem` from `std-client` to `recs` package and updated it to better support v2 sync stack.
|
8
|
+
|
9
|
+
If you want to use `createActionSystem` alongside `syncToRecs`, you'll need to pass in arguments like so:
|
10
|
+
|
11
|
+
```ts
|
12
|
+
import { syncToRecs } from "@latticexyz/store-sync/recs";
|
13
|
+
import { createActionSystem } from "@latticexyz/recs/deprecated";
|
14
|
+
import { from, mergeMap } from "rxjs";
|
15
|
+
|
16
|
+
const { blockLogsStorage$, waitForTransaction } = syncToRecs({
|
17
|
+
world,
|
18
|
+
...
|
19
|
+
});
|
20
|
+
|
21
|
+
const txReduced$ = blockLogsStorage$.pipe(
|
22
|
+
mergeMap(({ operations }) => from(operations.map((op) => op.log?.transactionHash).filter(isDefined)))
|
23
|
+
);
|
24
|
+
|
25
|
+
const actionSystem = createActionSystem(world, txReduced$, waitForTransaction);
|
26
|
+
```
|
27
|
+
|
28
|
+
- Fixed a bug in `waitForComponentValueIn` that caused the promise to not resolve if the component value was already set when the function was called.
|
29
|
+
|
30
|
+
- Fixed a bug in `createActionSystem` that caused optimistic updates to be incorrectly propagated to requirement checks. To fix the bug, you must now pass in the full component object to the action's `updates` instead of just the component name.
|
31
|
+
|
32
|
+
```diff
|
33
|
+
actions.add({
|
34
|
+
updates: () => [
|
35
|
+
{
|
36
|
+
- component: "Resource",
|
37
|
+
+ component: Resource,
|
38
|
+
...
|
39
|
+
}
|
40
|
+
],
|
41
|
+
...
|
42
|
+
});
|
43
|
+
```
|
44
|
+
|
45
|
+
### Patch Changes
|
46
|
+
|
47
|
+
- [#1340](https://github.com/latticexyz/mud/pull/1340) [`ce7125a1`](https://github.com/latticexyz/mud/commit/ce7125a1b97efd3db47c5ea1593d5a37ba143f64) Thanks [@holic](https://github.com/holic)! - Removes `solecs` package. These were v1 contracts, now entirely replaced by our v2 tooling. See the [MUD docs](https://mud.dev/) for building with v2 or create a new project from our v2 templates with `pnpm create mud@next your-app-name`.
|
48
|
+
|
49
|
+
- [#1167](https://github.com/latticexyz/mud/pull/1167) [`1e2ad78e`](https://github.com/latticexyz/mud/commit/1e2ad78e277b551dd1b8efb0e4438fb10441644c) Thanks [@holic](https://github.com/holic)! - improve RECS error messages for v2 components
|
50
|
+
|
51
|
+
- [#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.
|
52
|
+
|
53
|
+
These new sync packages come with support for our `recs` package, including `encodeEntity` and `decodeEntity` utilities for composite keys.
|
54
|
+
|
55
|
+
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`.
|
56
|
+
|
57
|
+
**Migrate existing RECS apps to new sync packages**
|
58
|
+
|
59
|
+
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.
|
60
|
+
|
61
|
+
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)
|
62
|
+
|
63
|
+
2. In your `supportedChains.ts`, replace `foundry` chain with our new `mudFoundry` chain.
|
64
|
+
|
65
|
+
```diff
|
66
|
+
- import { foundry } from "viem/chains";
|
67
|
+
- import { MUDChain, latticeTestnet } from "@latticexyz/common/chains";
|
68
|
+
+ import { MUDChain, latticeTestnet, mudFoundry } from "@latticexyz/common/chains";
|
69
|
+
|
70
|
+
- export const supportedChains: MUDChain[] = [foundry, latticeTestnet];
|
71
|
+
+ export const supportedChains: MUDChain[] = [mudFoundry, latticeTestnet];
|
72
|
+
```
|
73
|
+
|
74
|
+
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.
|
75
|
+
|
76
|
+
```diff
|
77
|
+
- export async function getNetworkConfig(): Promise<NetworkConfig> {
|
78
|
+
+ export async function getNetworkConfig() {
|
79
|
+
```
|
80
|
+
|
81
|
+
```diff
|
82
|
+
const initialBlockNumber = params.has("initialBlockNumber")
|
83
|
+
? Number(params.get("initialBlockNumber"))
|
84
|
+
- : world?.blockNumber ?? -1; // -1 will attempt to find the block number from RPC
|
85
|
+
+ : world?.blockNumber ?? 0n;
|
86
|
+
```
|
87
|
+
|
88
|
+
```diff
|
89
|
+
+ return {
|
90
|
+
+ privateKey: getBurnerWallet().value,
|
91
|
+
+ chain,
|
92
|
+
+ worldAddress,
|
93
|
+
+ initialBlockNumber,
|
94
|
+
+ faucetServiceUrl: params.get("faucet") ?? chain.faucetUrl,
|
95
|
+
+ };
|
96
|
+
```
|
97
|
+
|
98
|
+
4. In `setupNetwork.ts`, replace `setupMUDV2Network` with `syncToRecs`.
|
99
|
+
|
100
|
+
```diff
|
101
|
+
- import { setupMUDV2Network } from "@latticexyz/std-client";
|
102
|
+
- import { createFastTxExecutor, createFaucetService, getSnapSyncRecords } from "@latticexyz/network";
|
103
|
+
+ import { createFaucetService } from "@latticexyz/network";
|
104
|
+
+ import { createPublicClient, fallback, webSocket, http, createWalletClient, getContract, Hex, parseEther, ClientConfig } from "viem";
|
105
|
+
+ import { encodeEntity, syncToRecs } from "@latticexyz/store-sync/recs";
|
106
|
+
+ import { createBurnerAccount, createContract, transportObserver } from "@latticexyz/common";
|
107
|
+
```
|
108
|
+
|
109
|
+
```diff
|
110
|
+
- const result = await setupMUDV2Network({
|
111
|
+
- ...
|
112
|
+
- });
|
113
|
+
|
114
|
+
+ const clientOptions = {
|
115
|
+
+ chain: networkConfig.chain,
|
116
|
+
+ transport: transportObserver(fallback([webSocket(), http()])),
|
117
|
+
+ pollingInterval: 1000,
|
118
|
+
+ } as const satisfies ClientConfig;
|
119
|
+
|
120
|
+
+ const publicClient = createPublicClient(clientOptions);
|
121
|
+
|
122
|
+
+ const burnerAccount = createBurnerAccount(networkConfig.privateKey as Hex);
|
123
|
+
+ const burnerWalletClient = createWalletClient({
|
124
|
+
+ ...clientOptions,
|
125
|
+
+ account: burnerAccount,
|
126
|
+
+ });
|
127
|
+
|
128
|
+
+ const { components, latestBlock$, blockStorageOperations$, waitForTransaction } = await syncToRecs({
|
129
|
+
+ world,
|
130
|
+
+ config: storeConfig,
|
131
|
+
+ address: networkConfig.worldAddress as Hex,
|
132
|
+
+ publicClient,
|
133
|
+
+ components: contractComponents,
|
134
|
+
+ startBlock: BigInt(networkConfig.initialBlockNumber),
|
135
|
+
+ indexerUrl: networkConfig.indexerUrl ?? undefined,
|
136
|
+
+ });
|
137
|
+
|
138
|
+
+ const worldContract = createContract({
|
139
|
+
+ address: networkConfig.worldAddress as Hex,
|
140
|
+
+ abi: IWorld__factory.abi,
|
141
|
+
+ publicClient,
|
142
|
+
+ walletClient: burnerWalletClient,
|
143
|
+
+ });
|
144
|
+
```
|
145
|
+
|
146
|
+
```diff
|
147
|
+
// Request drip from faucet
|
148
|
+
- const signer = result.network.signer.get();
|
149
|
+
- if (networkConfig.faucetServiceUrl && signer) {
|
150
|
+
- const address = await signer.getAddress();
|
151
|
+
+ if (networkConfig.faucetServiceUrl) {
|
152
|
+
+ const address = burnerAccount.address;
|
153
|
+
```
|
154
|
+
|
155
|
+
```diff
|
156
|
+
const requestDrip = async () => {
|
157
|
+
- const balance = await signer.getBalance();
|
158
|
+
+ const balance = await publicClient.getBalance({ address });
|
159
|
+
console.info(`[Dev Faucet]: Player balance -> ${balance}`);
|
160
|
+
- const lowBalance = balance?.lte(utils.parseEther("1"));
|
161
|
+
+ const lowBalance = balance < parseEther("1");
|
162
|
+
```
|
163
|
+
|
164
|
+
You can remove the previous ethers `worldContract`, snap sync code, and fast transaction executor.
|
165
|
+
|
166
|
+
The return of `setupNetwork` is a bit different than before, so you may have to do corresponding app changes.
|
167
|
+
|
168
|
+
```diff
|
169
|
+
+ return {
|
170
|
+
+ world,
|
171
|
+
+ components,
|
172
|
+
+ playerEntity: encodeEntity({ address: "address" }, { address: burnerWalletClient.account.address }),
|
173
|
+
+ publicClient,
|
174
|
+
+ walletClient: burnerWalletClient,
|
175
|
+
+ latestBlock$,
|
176
|
+
+ blockStorageOperations$,
|
177
|
+
+ waitForTransaction,
|
178
|
+
+ worldContract,
|
179
|
+
+ };
|
180
|
+
```
|
181
|
+
|
182
|
+
5. Update `createSystemCalls` with the new return type of `setupNetwork`.
|
183
|
+
|
184
|
+
```diff
|
185
|
+
export function createSystemCalls(
|
186
|
+
- { worldSend, txReduced$, singletonEntity }: SetupNetworkResult,
|
187
|
+
+ { worldContract, waitForTransaction }: SetupNetworkResult,
|
188
|
+
{ Counter }: ClientComponents
|
189
|
+
) {
|
190
|
+
const increment = async () => {
|
191
|
+
- const tx = await worldSend("increment", []);
|
192
|
+
- await awaitStreamValue(txReduced$, (txHash) => txHash === tx.hash);
|
193
|
+
+ const tx = await worldContract.write.increment();
|
194
|
+
+ await waitForTransaction(tx);
|
195
|
+
return getComponentValue(Counter, singletonEntity);
|
196
|
+
};
|
197
|
+
```
|
198
|
+
|
199
|
+
6. (optional) If you still need a clock, you can create it with:
|
200
|
+
|
201
|
+
```ts
|
202
|
+
import { map, filter } from "rxjs";
|
203
|
+
import { createClock } from "@latticexyz/network";
|
204
|
+
|
205
|
+
const clock = createClock({
|
206
|
+
period: 1000,
|
207
|
+
initialTime: 0,
|
208
|
+
syncInterval: 5000,
|
209
|
+
});
|
210
|
+
|
211
|
+
world.registerDisposer(() => clock.dispose());
|
212
|
+
|
213
|
+
latestBlock$
|
214
|
+
.pipe(
|
215
|
+
map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms
|
216
|
+
filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block
|
217
|
+
filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct
|
218
|
+
)
|
219
|
+
.subscribe(clock.update); // Update the local clock
|
220
|
+
```
|
221
|
+
|
222
|
+
If you're using the previous `LoadingState` component, you'll want to migrate to the new `SyncProgress`:
|
223
|
+
|
224
|
+
```ts
|
225
|
+
import { SyncStep, singletonEntity } from "@latticexyz/store-sync/recs";
|
226
|
+
|
227
|
+
const syncProgress = useComponentValue(SyncProgress, singletonEntity, {
|
228
|
+
message: "Connecting",
|
229
|
+
percentage: 0,
|
230
|
+
step: SyncStep.INITIALIZE,
|
231
|
+
});
|
232
|
+
|
233
|
+
if (syncProgress.step === SyncStep.LIVE) {
|
234
|
+
// we're live!
|
235
|
+
}
|
236
|
+
```
|
237
|
+
|
238
|
+
- [#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.
|
239
|
+
|
240
|
+
This may break if you were previously dependent on `component.id`, `component.metadata.componentId`, or `component.metadata.tableId`:
|
241
|
+
|
242
|
+
- `component.id` is now the on-chain `bytes32` hex representation of the table ID
|
243
|
+
- `component.metadata.componentName` is the table name (e.g. `Position`)
|
244
|
+
- `component.metadata.tableName` is the namespaced table name (e.g. `myworld:Position`)
|
245
|
+
- `component.metadata.keySchema` is an object with key names and their corresponding ABI types
|
246
|
+
- `component.metadata.valueSchema` is an object with field names and their corresponding ABI types
|
247
|
+
|
248
|
+
- 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), [`b8a6158d`](https://github.com/latticexyz/mud/commit/b8a6158d63738ebfc1e7eb221909436d050c7e39), [`4e4a3415`](https://github.com/latticexyz/mud/commit/4e4a34150aeae988c8e61e25d55c227afb6c2d4b), [`53522998`](https://github.com/latticexyz/mud/commit/535229984565539e6168042150b45fe0f9b48b0f)]:
|
249
|
+
- @latticexyz/schema-type@2.0.0-skystrife-playtest-3e6ab07b
|
250
|
+
- @latticexyz/utils@2.0.0-skystrife-playtest-3e6ab07b
|
251
|
+
|
3
252
|
## 2.0.0-next.8
|
4
253
|
|
5
254
|
### Patch Changes
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@latticexyz/recs",
|
3
|
-
"version": "2.0.0-
|
3
|
+
"version": "2.0.0-skystrife-playtest-3e6ab07b",
|
4
4
|
"repository": {
|
5
5
|
"type": "git",
|
6
6
|
"url": "https://github.com/latticexyz/mud.git",
|
@@ -25,8 +25,8 @@
|
|
25
25
|
"dependencies": {
|
26
26
|
"mobx": "^6.7.0",
|
27
27
|
"rxjs": "7.5.5",
|
28
|
-
"@latticexyz/schema-type": "2.0.0-
|
29
|
-
"@latticexyz/utils": "2.0.0-
|
28
|
+
"@latticexyz/schema-type": "2.0.0-skystrife-playtest-3e6ab07b",
|
29
|
+
"@latticexyz/utils": "2.0.0-skystrife-playtest-3e6ab07b"
|
30
30
|
},
|
31
31
|
"devDependencies": {
|
32
32
|
"@types/jest": "^27.4.1",
|