Skip to content

Commit

Permalink
Merge branch 'main' into aa-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
alvrs authored Mar 27, 2024
2 parents 824ba9b + e86bd14 commit 31272a1
Show file tree
Hide file tree
Showing 33 changed files with 1,135 additions and 204 deletions.
9 changes: 9 additions & 0 deletions .changeset/cold-apes-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@latticexyz/cli": patch
"@latticexyz/world-modules": patch
"@latticexyz/world": patch
---

Added a new preview module, `Unstable_DelegationWithSignatureModule`, which allows registering delegations with a signature.

Note: this module is marked as `Unstable`, because it will be removed and included in the default `World` deployment once it is audited.
8 changes: 4 additions & 4 deletions docs/pages/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ To run any of the TypeScript templates:

1. Select the template:

- [Vanilla](./vanilla)
- [React-ECS](./react-ecs)
- [Vanilla](./templates/typescript/vanilla)
- [React-ECS](./templates/typescript/react-ecs)
- React
- [Phaser](./phaser)
- [Three.js](./three)
- Phaser
- [Three.js](./templates/typescript/threejs)

1. Start the development server, which updates automatically when you modify files.

Expand Down
6 changes: 6 additions & 0 deletions docs/pages/store/store-hooks.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { CollapseCode } from "../../components/CollapseCode";
import { Callout } from "nextra/components";

# Store hooks

<Callout type="info" emoji="">
This page is about hooks before and after information is modified. You can also use [`System`
hooks](../world/system-hooks) that execute before or after a `System` call.
</Callout>

Store hooks allow you to react to state changes onchain.

There are many ways to [interact with tables](./reference/store-core), but they all boil down to four types of state changes:
Expand Down
40 changes: 19 additions & 21 deletions docs/pages/store/table-libraries.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,25 @@ The [CLI config](/cli/config) section goes into more detail on the available con

To illustrate table library functionality on this page, we'll use two example tables with the following configurations:

```ts
const Position = {
keySchema: {
entity: "address",
},
valueSchema: {
// Two static length fields
x: "uint32",
y: "uint32",
},
};

const Inventory = {
keySchema: {
entity: "address",
},
valueSchema: {
// One dynamic length field
slots: "uint8[]",
},
};
```ts filename="Position"
schema: {
entity: "address",

// Two static length fields
x: "uint32",
y: "uint32",
},
key: ["entity"],
```

```ts filename="Inventory"
schema: {
entity: "address",

// One dynamic length field
slots: "uint8[]",
},
key: ["entity"],
```

## Usage
Expand Down
14 changes: 6 additions & 8 deletions docs/pages/store/tables.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { Callout } from "nextra/components";
# Tables

Each piece of data in `Store` is stored as a _record_ in a _table_.
You can think of tables in two ways, either [as a relational database](./how-mud-models-data) or as a key-value store.
You can think of tables in two ways, either [as a relational database](./data-model) or as a key-value store.

- Each table is identified by a unique `ResourceId tableId`.
- Each record in a table is identified by a unique `bytes32[] keyTuple`.
You can think of the key tuple as a composite key in a relational database, or as a nested mapping in a key-value store.
- Each table has a `ValueSchema` that defines the types of data stored in the table.
- Each table has a value schema (all the `schema` fields that aren't part of the `key`) that defines the types of data stored in the table.
You can think of the value schema as the column types in a table in a relational database, or the type of structs stored in a key-value store.

Tables are registered in the `Store` contract at runtime.
Expand Down Expand Up @@ -46,6 +46,8 @@ The table ID encodes the table's type and name in a 32-byte `ResourceId` value a
import { ResourceId, ResourceIdLib } from "@latticexyz/store/src/ResourceId.sol";
import { RESOURCE_TABLE, RESOURCE_OFFCHAIN_TABLE } from "@latticexyz/store/src/storeResourceTypes.sol";
...
// Using the `RESOURCE_TABLE` type makes it an onchain table
ResourceId tableId = ResourceIdLib.encode({
typeId: RESOURCE_TABLE,
Expand Down Expand Up @@ -103,7 +105,6 @@ Key and (value) field names are simple string arrays, and must have the same len
string[] memory keyNames = new string[](1);
keyNames[0] = "owner";
string[] memory fieldNames = new string[](1);
fieldNames[0] = "balance";
```
Expand All @@ -118,17 +119,14 @@ import { FieldLayout, FieldLayoutLib } from "@latticexyz/store/src/FieldLayout.s
uint256[] memory staticFields = new uint256[](1);
staticFields[0] = 32; // The byte length of the first field
FieldLayout fieldLayout = FieldLayoutLib.encode({
staticFields: staticFields,
numDynamicFields: 0
});
FieldLayout fieldLayout = FieldLayoutLib.encode(staticFields, 0);
```

### Manually register a table

Registering a table is a prerequisite for writing to the table, and allows [offchain indexers](../services/indexer) to [replicate the onchain state](/guides/replicating-onchain-state).

```solidity
```solidity copy
import { IStore } from "@latticexyz/store/src/IStore.sol";
IStore store = IStore(STORE_ADDRESS);
Expand Down
1 change: 1 addition & 0 deletions docs/pages/templates/typescript/_meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export default {
vanilla: "Vanilla",
"react-ecs": "React-ECS",
threejs: "Three.js",
vue: "Vue",
};
8 changes: 8 additions & 0 deletions docs/pages/templates/typescript/vue.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Disclaimer from "../disclaimer.mdx";

# Vue

[Vue](https://vuejs.org/) is a framework for building web user interfaces.
[You can see the MUD integration here](https://github.com/LidamaoHub/MUD-Template-VUE/tree/master).

<Disclaimer />
12 changes: 12 additions & 0 deletions docs/pages/world/account-delegation.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Callout } from "nextra/components";

# Account delegation

_Account delegation_ allows a _delegator_ address to permit a _delegatee_ address to call a `System` on its behalf.
Expand All @@ -17,6 +19,16 @@ This feature enables multiple use cases.
This is conceptually similar to how ERC20's [`approve`/`transferFrom`](https://eips.ethereum.org/EIPS/eip-20#transferfrom) enables atomic swaps by allowing contracts to withdraw from a user's balance and then deposit a different asset in a single transaction.
For example, an agent could exchange two in-game assets atomically if the two sides of the trade give it the necessary permission.

<details>

<summary>Delegation and Account Abstraction</summary>

While there are some overlaps in use cases between [ERC-4337](https://www.erc4337.io/) and MUD's account delegation, they are different things.
In ERC-4337, a smart contract wallet becomes your main onchain identity.
With MUD delegation, you keep your existing account, but (temporarily) approve other accounts to act on its behalf.

</details>

## User delegation

The most common type of delegation is when a delegator address allows a specific delegatee address to act on its behalf.
Expand Down
8 changes: 4 additions & 4 deletions docs/pages/world/namespaces-access-control.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ import { console } from "forge-std/console.sol";
import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol";
import { IWorld } from "../src/codegen/world/IWorld.sol";
import { CounterTableId } from "../src/codegen/index.sol";
import { Counter } from "../src/codegen/index.sol";
contract Permissions is Script {
function run() external {
address worldAddress = 0x6E9474e9c83676B9A71133FF96Db43E7AA0a4342;
address worldAddress = 0x4F4DDaFBc93Cf8d11a253f21dDbcF836139efdeC;
// Load the private key from the `PRIVATE_KEY` environment variable (in .env)
uint256 namespaceOwnerPrivateKey = vm.envUint("PRIVATE_KEY");
// Start broadcasting transactions from the account owning the namespace
vm.startBroadcast(namespaceOwnerPrivateKey);
IWorld(worldAddress).grantAccess(CounterTableId, address(0));
IWorld(worldAddress).revokeAccess(CounterTableId, address(1));
IWorld(worldAddress).grantAccess(Counter._tableId, address(0));
IWorld(worldAddress).revokeAccess(Counter._tableId, address(1));
vm.stopBroadcast();
}
Expand Down
8 changes: 8 additions & 0 deletions docs/pages/world/system-hooks.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Callout } from "nextra/components";

# System hooks

<Callout type="info" emoji="">
This page is about hooks that are called before or after a `System` call. You can also use [store
hooks](../store/store-hooks) that are called whenever information in a table is modified, regardless of the source of
the change.
</Callout>

The [namespace owner](/world/namespaces-access-control#ownership) can [register](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol#L68-L99) hooks that are called before and/or after calls to a specific `System`.

## System hook contracts
Expand Down
Loading

0 comments on commit 31272a1

Please sign in to comment.