Skip to content

Commit

Permalink
Merge branch 'main' into 230918-docker-indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
ludns authored Sep 21, 2023
2 parents 2c96ce4 + 92de599 commit a60fe06
Show file tree
Hide file tree
Showing 333 changed files with 5,327 additions and 4,095 deletions.
25 changes: 25 additions & 0 deletions .changeset/mean-seals-nail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"@latticexyz/world": patch
"@latticexyz/store": patch
---

The `ResourceType` table is removed.
It was previously used to store the resource type for each resource ID in a `World`. This is no longer necessary as the [resource type is now encoded in the resource ID](https://github.com/latticexyz/mud/pull/1544).

To still be able to determine whether a given resource ID exists, a `ResourceIds` table has been added.
The previous `ResourceType` table was part of `World` and missed tables that were registered directly via `StoreCore.registerTable` instead of via `World.registerTable` (e.g. when a table was registered as part of a root module).
This problem is solved by the new table `ResourceIds` being part of `Store`.

`StoreCore`'s `hasTable` function was removed in favor of using `ResourceIds.getExists(tableId)` directly.

```diff
- import { ResourceType } from "@latticexyz/world/src/tables/ResourceType.sol";
- import { StoreCore } from "@latticexyz/store/src/StoreCore.sol";
+ import { ResourceIds } from "@latticexyz/store/src/codegen/tables/ResourceIds.sol";

- bool tableExists = StoreCore.hasTable(tableId);
+ bool tableExists = ResourceIds.getExists(tableId);

- bool systemExists = ResourceType.get(systemId) != Resource.NONE;
+ bool systemExists = ResourceIds.getExists(systemId);
```
25 changes: 25 additions & 0 deletions .changeset/real-students-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"@latticexyz/world": major
---

All `World` methods acting on namespaces as resources have been updated to use `ResourceId namespaceId` as parameter instead of `bytes14 namespace`.
The reason for this change is to make it clearer when a namespace is used as resource, as opposed to being part of another resource's ID.

```diff
+ import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";

IBaseWorld {
- function registerNamespace(bytes14 namespace) external;
+ function registerNamespace(ResourceId namespaceId) external;

- function transferOwnership(bytes14 namespace, address newOwner) external;
+ function transferOwnership(ResourceId namespaceId, address newOwner) external;

- function transferBalanceToNamespace(bytes14 fromNamespace, bytes14 toNamespace, uint256 amount) external;
+ function transferBalanceToNamespace(ResourceId fromNamespaceId, ResourceId toNamespaceId, uint256 amount) external;

- function transferBalanceToAddress(bytes14 fromNamespace, address toAddress, uint256 amount) external;
+ function transferBalanceToAddress(ResourceId fromNamespaceId, address toAddress, uint256 amount) external;
}

```
12 changes: 12 additions & 0 deletions .changeset/serious-ads-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@latticexyz/cli": minor
"@latticexyz/common": minor
"@latticexyz/gas-report": major
"@latticexyz/noise": major
"@latticexyz/schema-type": major
"@latticexyz/store": major
"@latticexyz/world": major
"create-mud": minor
---

Bump Solidity version to 0.8.21
20 changes: 20 additions & 0 deletions .changeset/small-chicken-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
"@latticexyz/block-logs-stream": patch
"@latticexyz/cli": patch
"@latticexyz/common": major
"@latticexyz/dev-tools": patch
"@latticexyz/store-sync": patch
"@latticexyz/store": major
"create-mud": minor
---

What used to be known as `ephemeral` table is now called `offchain` table.
The previous `ephemeral` tables only supported an `emitEphemeral` method, which emitted a `StoreSetEphemeralRecord` event.

Now `offchain` tables support all regular table methods, except partial operations on dynamic fields (`push`, `pop`, `update`).
Unlike regular tables they don't store data on-chain but emit the same events as regular tables (`StoreSetRecord`, `StoreSpliceStaticData`, `StoreDeleteRecord`), so their data can be indexed by offchain indexers/clients.

```diff
- EphemeralTable.emitEphemeral(value);
+ OffchainTable.set(value);
```
70 changes: 70 additions & 0 deletions .changeset/stale-seahorses-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
"@latticexyz/cli": major
"@latticexyz/common": major
"@latticexyz/config": major
"@latticexyz/store": major
---

- `ResourceSelector` is replaced with `ResourceId`, `ResourceIdLib`, `ResourceIdInstance`, `WorldResourceIdLib` and `WorldResourceIdInstance`.

Previously a "resource selector" was a `bytes32` value with the first 16 bytes reserved for the resource's namespace, and the last 16 bytes reserved for the resource's name.
Now a "resource ID" is a `bytes32` value with the first 2 bytes reserved for the resource type, the next 14 bytes reserved for the resource's namespace, and the last 16 bytes reserved for the resource's name.

Previously `ResouceSelector` was a library and the resource selector type was a plain `bytes32`.
Now `ResourceId` is a user type, and the functionality is implemented in the `ResourceIdInstance` (for type) and `WorldResourceIdInstance` (for namespace and name) libraries.
We split the logic into two libraries, because `Store` now also uses `ResourceId` and needs to be aware of resource types, but not of namespaces/names.

```diff
- import { ResourceSelector } from "@latticexyz/world/src/ResourceSelector.sol";
+ import { ResourceId, ResourceIdInstance } from "@latticexyz/store/src/ResourceId.sol";
+ import { WorldResourceIdLib, WorldResourceIdInstance } from "@latticexyz/world/src/WorldResourceId.sol";
+ import { RESOURCE_SYSTEM } from "@latticexyz/world/src/worldResourceTypes.sol";

- bytes32 systemId = ResourceSelector.from("namespace", "name");
+ ResourceId systemId = WorldResourceIdLib.encode(RESOURCE_SYSTEM, "namespace", "name");

- using ResourceSelector for bytes32;
+ using WorldResourceIdInstance for ResourceId;
+ using ResourceIdInstance for ResourceId;

systemId.getName();
systemId.getNamespace();
+ systemId.getType();

```

- All `Store` and `World` methods now use the `ResourceId` type for `tableId`, `systemId`, `moduleId` and `namespaceId`.
All mentions of `resourceSelector` were renamed to `resourceId` or the more specific type (e.g. `tableId`, `systemId`)

```diff
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";

IStore {
function setRecord(
- bytes32 tableId,
+ ResourceId tableId,
bytes32[] calldata keyTuple,
bytes calldata staticData,
PackedCounter encodedLengths,
bytes calldata dynamicData,
FieldLayout fieldLayout
) external;

// Same for all other methods
}
```

```diff
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol";

IBaseWorld {
function callFrom(
address delegator,
- bytes32 resourceSelector,
+ ResourceId systemId,
bytes memory callData
) external payable returns (bytes memory);

// Same for all other methods
}
```
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist
**/.next
.next
templates/phaser/packages/art
CODEOWNERS
out
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"solidity.monoRepoSupport": true
"solidity.monoRepoSupport": true,
"solidity.compileUsingRemoteVersion": "v0.8.21+commit.d9974bed"
}
20 changes: 3 additions & 17 deletions docs/pages/store/advanced-features.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ uint256 value = CounterSingleton.get();

Additional documentation on Table library generation can be found in the [`tablegen`](/store/config#store-config--tablegen-tool) section.

### Ephemeral tables
### Offchain tables

Tables with the `ephemeral` property do not write to on-chain storage.
Tables with the `offchainOnly` property do not write to on-chain storage.
Instead, they simply emit events when records are set.
They are useful for sending data to connected clients without the gas costs associated with a storage write.

Expand All @@ -52,26 +52,12 @@ export default mudConfig({
amount: "uint32",
receiver: "bytes32",
},
ephemeral: true,
offchainOnly: true,
},
},
});
```

This will slightly change the generated code for the table. The `emitEphemeral` function is the main entrypoint:

```solidity
import { TradeExecuted, TradeExecutedData } from "./codegen/Tables.sol";
// Emitting an ephemeral record
TradeExecuted.emitEphemeral("0x1234", TradeExecutedData({
amount: 10,
receiver: "0x5678",
}));
```

`get`, `set`, and `delete` functions are not generated for ephemeral tables.

### Storage hooks

It is possible to register hooks on tables, allowing additional logic to be executed when records or fields are updated. Use cases include: creating indices on another table (like the `ownerOf` mapping of the ERC-721 spec as an example), emitting events on a different contract, or simply additional access-control and checks by reverting in the hook.
Expand Down
2 changes: 2 additions & 0 deletions docs/pages/tutorials/minimal/add-table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ A MUD table has two schemas:
- `valueSchema`, the value in the entry

Each schema is represented as a structure with field names as keys, and the appropriate [Solidity data types](https://docs.soliditylang.org/en/latest/types.html) as their values.
Note that the data types in the key schema are limited to those that are fixed length such at `bytes<n>`.
You cannot use strings, arrays, etc.

In this case, the counter value is represented as a 32 bit unsigned integer, because that is what `Counter` uses.
Block numbers and timestamps can be values up to `uint256`, so we'll use this type for these fields.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/world/internals.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Except `NamespaceOwner` is initialized in World's constructor, because it's need
Internal systems are in `core` module's [implementations](https://github.com/latticexyz/mud/tree/main/packages/world/src/modules/core/implementations) folder, because they're installed by `CoreModule`.

- `AccessManagementSystem` - grants/revokes access to/from resources
- `EphemeralRecordSystem` - has `emitEphemeralRecord` for ephemeral tables
- `BalanceTransferSystem` - handles balance transfers between namespaces and from namespaces to addresses
- `ModuleInstallationSystem` - installation of (non-root) modules in the World
- `StoreRegistrationSystem` - _its methods should not be used with the World framework_. Surfaces the APIs necessary to register Tables on-chain, but lacks namespaces used by World for better permission checks
- `WorldRegistrationSystem` - surfaces the APIs necessary to register Systems, Tables, and Namespaces on-chain
2 changes: 1 addition & 1 deletion e2e/packages/contracts/foundry.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[profile.default]
solc_version = "0.8.13"
solc = "0.8.21"
ffi = false
fuzz_runs = 256
optimizer = true
Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/contracts/src/CustomTypes.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
pragma solidity >=0.8.21;

struct Position {
int32 x;
Expand Down
2 changes: 1 addition & 1 deletion e2e/packages/contracts/src/codegen/index.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 34 additions & 30 deletions e2e/packages/contracts/src/codegen/tables/Multi.sol

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a60fe06

Please sign in to comment.