Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into yonadaaa/indexer-bool…
Browse files Browse the repository at this point in the history
…-byte-arrays
  • Loading branch information
yonadaa committed Feb 20, 2024
2 parents 2124833 + 4e445a1 commit 5607081
Show file tree
Hide file tree
Showing 29 changed files with 600 additions and 127 deletions.
5 changes: 5 additions & 0 deletions .changeset/fifty-guests-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": patch
---

Bumped the Postgres column size for `int32`, `uint32`, `int64`, and `uint64` types to avoid overflows
5 changes: 5 additions & 0 deletions .changeset/lemon-numbers-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": patch
---

Moved boolean array types to use array column types (instead of JSON columns) for the Postgres decoded indexer
5 changes: 5 additions & 0 deletions .changeset/long-dots-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": patch
---

Moved numerical array types to use array column types (instead of JSON columns) for the Postgres decoded indexer
5 changes: 5 additions & 0 deletions .changeset/nasty-rice-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store-sync": minor
---

`createStoreSync` now [waits for idle](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback) between each chunk of logs in a block to allow for downstream render cycles to trigger. This means that hydrating logs from an indexer will no longer block until hydration completes, but rather allow for `onProgress` callbacks to trigger.
96 changes: 14 additions & 82 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# MUD

<div align="center">
<img src="docs/public/logo512-black-w-background.png" width="200" style="margin: 0 0 30px 0;" alt="MUD logo" />
<p>MUD - Engine for Autonomous Worlds</p>

![MUD logo](./docs/public/mud-cover-photo.png)

<div style="margin: 0 0 30px 0;"></div>
<p>Battle-tested onchain framework for developers</p>
</div>

<p align="center">
Expand All @@ -19,102 +22,31 @@
</a>
</p>

MUD is a framework for complex Ethereum applications.

It adds some conventions for organizing data and logic and abstracts away low-level complexities so you can focus on the features of your app.

It standardizes the way data is stored on-chain.
With this standard data model, MUD can provide all network code to synchronize contract and client state. This includes synchronizing state directly from an RPC node or a general-purpose MUD indexer.

MUD is MIT-licensed, open source and free to use.

## Features

![MUD features](./docs/public/features.png)
MUD is a framework for ambitious Ethereum applications.
It compresses the complexity of building EVM apps with a tightly integrated software stack that handles data storage, upgrades, delegations, etc.

### Today

- State synchronization between contracts and clients without custom networking code
- General purpose indexers (without custom indexing code)
- Seamless contract upgrades (+ automatic contract upgrades during development)
- Shared contract state
- Optimistic updates
- Automatic type generation for contracts and systems
- Query language to interact with contract state
- Data explorer to inspect and modify contract and local state
- Bitpacking utilities

### Soon

- Local simulation of transactions (including optimistic state)
- Built-in support for account abstraction
- Contract package manager
You can see MUD's features, both those available and those still in development, on [the development status page](https://status.mud.dev/).

## Quickstart

```
pnpm create mud@next my-project
```

For more information on how to get started, have a look at the [MUD documentation](https://mud.dev/quick-start).

## Talks

<div>
<a href="https://www.youtube.com/watch?v=UvIWmzscWp8" target="_blank"><img src="https://img.youtube.com/vi/UvIWmzscWp8/hqdefault.jpg" alt="Getting started with MUD" width="30%" /></a>
<a href="https://www.youtube.com/watch?v=j-_Zf8o5Wlo" target="_blank"><img src="https://img.youtube.com/vi/j-_Zf8o5Wlo/hqdefault.jpg" alt="MUD - An Engine for Autonomous Worlds" width="30%" /></a>
<a href="https://www.youtube.com/watch?v=mv3jA4USZtg" target="_blank"><img src="https://img.youtube.com/vi/mv3jA4USZtg/hqdefault.jpg" alt="MUD in Practice - How we built OPCraft" width="30%" /></a>
</div>

## Packages

MUD consists of several libraries. They can be used independently, but are best used together.
Then follow the directions onscreen.

| Package | Version |
| ----------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **[@latticexyz/recs](/packages/recs)** <br />TypeScript Reactive Entity Component System library | [![npm version](https://img.shields.io/npm/v/@latticexyz/recs.svg)](https://www.npmjs.org/package/@latticexyz/recs) |
| **[@latticexyz/services](/packages/services)** <br />Go services for indexer, faucet, message relay | [![npm version](https://img.shields.io/npm/v/@latticexyz/services.svg)](https://www.npmjs.org/package/@latticexyz/services) |
| **[@latticexyz/cli](/packages/cli)** <br />Command line interface for types, testing, faucet, deployment and more | [![npm version](https://img.shields.io/npm/v/@latticexyz/cli.svg)](https://www.npmjs.org/package/@latticexyz/cli) |
| **[@latticexyz/noise](/packages/noise)** <br />Solidity and AssemblyScript implementations of Perlin noise | [![npm version](https://img.shields.io/npm/v/@latticexyz/noise.svg)](https://www.npmjs.org/package/@latticexyz/noise) |
For more information on how to get started, have a look at the [MUD documentation](https://mud.dev/templates/typescript/getting-started).

## Contribute

We'd love your support in improving MUD! This monorepo includes all of MUD's source code, and pull requests are always welcome. To discuss new features or changes [join our Discord](https://lattice.xyz/discord).

### Local development setup

!!!
The following steps are only necessary if you want to contribute to MUD. To use MUD in your project, install the [packages](#packages) from npm or [set up a new project with the MUD cli](#quickstart).
!!!

1. Install the foundry toolkit (required to build and test MUD solidity packages): [https://getfoundry.sh/](https://getfoundry.sh/)

2. Install pnpm

```
npm install pnpm --global
```

3. Clone the MUD monorepo

```
git clone https://github.com/latticexyz/mud
```

4. Install MUD dependencies and setup local environment

```
cd mud && pnpm install && pnpm build
```

### Pull requests

MUD follows the [conventional commit specification](https://www.conventionalcommits.org/en/v1.0.0/) for commit messages and PR titles. Please keep the scope of your PR small (rather open multiple small PRs than one huge PR) and follow the conventional commit spec.
We'd love your support in improving MUD, [see here for instructions](https://mud.dev/contribute).
This monorepo includes all of MUD's source code, and pull requests are always welcome.
To discuss new features or changes [join our Discord](https://lattice.xyz/discord).

## Community support

[Join our Discord](https://lattice.xyz/discord) to get support and connect with the community!

## License

MUD is open-source software [licensed as MIT](LICENSE).
MUD is open-source software [under the MIT license](LICENSE).
4 changes: 2 additions & 2 deletions docs/pages/guides/emojimon/1-preface-the-ecs-model.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
ECS is a software architectural pattern used commonly in video game development. It is a data-oriented approach to game development that creates a clean break between data and logic. It does this through the separation of Entities, Components, and Systems:

- **Entities** are the basic units of a game, and they can have any number of components.
In a typical MUD implementation each entity is assigned a unique 32 byte identifier that is used as a key to the component tables (see next item).
In a typical MUD implementation each entity is assigned a unique 32-byte identifier that is used as a key to the component tables (see next item).
- **Components** are small pieces of data that define an entity's behavior (such as position or health).
In a typical MUD implementation components are implemented as tables.
The table key is the entity identifier, and the value is the data that defines an aspect of the entity such as position.
Expand All @@ -31,7 +31,7 @@ In a vacuum these components don't _do_ anything, they are just data (in this ex

### ECS in MUD

There is one last concept to understand before we begin—how to actually implement the ECS model using MUD and its mental models.
There is one last concept to understand before we begin—how to implement the ECS model using MUD and its mental models.

In MUD there are tables instead of components (MUD is a general database protocol, not specific to onchain games).
However, for the sake of this tutorial, these can be mostly thought of interchangeably.
Expand Down
12 changes: 6 additions & 6 deletions docs/pages/guides/emojimon/2-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

- git ([download](https://git-scm.com/downloads))
- foundry (forge, anvil, cast) ([download](https://book.getfoundry.sh/getting-started/installation), make sure to `foundryup` at least once)
- node.js (v17+) ([download](https://nodejs.org/en/download/))
- node.js (v18) ([download](https://nodejs.org/en/download/))
- pnpm (`npm install pnpm --global` after installing node)

## Setup
Expand All @@ -15,26 +15,26 @@ Most projects in MUD are started by running `pnpm create mud <project name>`, bu
You can use the command below.

```bash copy
git clone https://github.com/latticexyz/emojimon.git -b mud-update-next-14
git clone https://github.com/latticexyz/emojimon.git -b mud-update-next-16
```

1. Install the dependencies and start up the MUD services (anvil node, contracts deployer, and client).

```bash copy
cd emojimon && pnpm install && pnpm run dev
cd emojimon && pnpm install && pnpm dev
```

1. At this point you can play the game to see the finished game.
Open the game in your browser.
By default the game is at [http://localhost:3000](http://localhost:3000), but it could be on a different port if that port's taken.
By default the game is at [http://localhost:3000](http://localhost:3000).

1. Click the map to spawn at a specific location and move using the arrow keys.
Note that on each block you can only move one space, and the block time on the anvil blockchain is one second.

1. Now that you've seen our end goal, reset the repository to [the starting snapshot](https://github.com/latticexyz/emojimon/tree/8520a8206929f6265609cc9166c985846fd0cd87).
1. Now that you've seen our end goal, reset the repository to [the starting snapshot](https://github.com/latticexyz/emojimon/tree/9dd3616244bc25518b06dfaa7beda51da07fb750).

```sh copy
git reset --hard 8520a8206929f6265609cc9166c985846fd0cd87
git reset --hard 9dd3616244bc25518b06dfaa7beda51da07fb750
```

After you do this, the game is just a green area where the map is going to be.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/guides/emojimon/3-players-and-movement.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export const GameBoard = () => {
You can run this command to update all the files to this point in the game's development.
```sh copy
git reset --hard 025bae043c6b1f787bba13bec298dbda10d92c37
git reset --hard 561f68112cb104ca106dcf3d79fcaa4ce72d9e66
```
Now that we have players, movement, and a basic map, let's start making improvements to the map itself.
6 changes: 3 additions & 3 deletions docs/pages/guides/emojimon/4-map-and-terrain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ export const GameBoard = () => {
You can run this command to update all the files to this point in the game's development.

```sh copy
git reset --hard d886c8375177bddc3a8353a3aba52f4fb71b550e
git reset --hard 6fc5590d7b660f911b757d1fb32456dee9a97d38
```

## Turn boulders into obstructions
Expand Down Expand Up @@ -526,7 +526,7 @@ Now if you try moving onto a tile with a boulder you’ll see that you can’t!
You can run this command to update all the files to this point in the game's development.

```sh copy
git reset --hard 54213103d54d9d7772b212b5aefbdf9a43656cb9
git reset --hard 952cf5032af33945872a99a95eaa59379a5df536
```

## Wraparound movement
Expand Down Expand Up @@ -596,5 +596,5 @@ contract MapSystem is System {
You can run this command to update all the files to this point in the game's development.

```sh copy
git reset --hard 1bffe935acc047b6d3a0acb24af5bea86a750e2c
git reset --hard 11a3036da8e40ffd25d5f0098485c014d8e6c1c4
```
6 changes: 3 additions & 3 deletions docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ With this screen setup there are two more steps to go—enabling the player to c
You can run this command to update all the files to this point in the game's development.

```sh copy
git reset --hard b8b063b330e77656485faf75bed1af5c344bdfbc
git reset --hard 384d8b1aa8e3887d76ddbedf9da4729f84bf523f
```

## Capture emojimon
Expand Down Expand Up @@ -814,7 +814,7 @@ When you click the button, the `EncounterScreen` creates a pending toast and kic
You can run this command to update all the files to this point in the game's development.

```sh copy
git reset --hard 00bffa27dc5d369fe536e35b84e0a5d5cc466645
git reset --hard 9bf5f8478847d90430a90a345a3868bb379a18aa
```

## Flee encounters
Expand Down Expand Up @@ -990,5 +990,5 @@ export function createSystemCalls(
You can run this command to update all the files to this point in the game's development.

```sh copy
git reset --hard 6511b5e9aa38f02f417ed41a63c75a9217bca1b8
git reset --hard fd388e7d57c9ef4afb17534e47385246973a8ce5
```
2 changes: 1 addition & 1 deletion docs/pages/guides/emojimon/6-advanced.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const GameBoard = () => {
You can run this command to update all the files to this point in the game's development.

```sh copy
git reset --hard f389208bb898ce81aa697be70a2de18107f93c53
git reset --hard d2159d51d0dfa9e53d45487fa74aacf28e4f04c3
```

All you have to do now is deploy to testnet!
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/world/account-delegation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The most common type of delegation is when a delegator address allows a specific

### Creating a user delegation

First, the delegator has to call [`registerDelegation`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol#L234-L263).
First, the delegator has to call [`registerDelegation`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol#L251-L284).
This function takes three parameters:

- `delegatee`, the address given the privileges.
Expand Down Expand Up @@ -51,14 +51,14 @@ This means that if you need in a `World` to implement multiple delegation algori

### Removing a user delegation

You can use [`unregisterDelegation`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol#L283-L291) to remove a delegation.
You can use [`unregisterDelegation`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol#L286-L294) to remove a delegation.

Because of `unregisterDelegation` delegations cannot be used for a delegator to commit to allow something to be done in the future.
If you need a _commitment_, create a table with a `System` that lets the address that commits write the commitment and have an action that other addresses can call only if the proper commitment is there - without giving the committed address an option to delete the entry.

## Namespace delegation

The owner of a namespace can use [`registerNamespaceDelegation`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/WorldRegistrationSystem.sol#L300-L332) to register a delegation that applies to all callers of systems in this namespace.
The owner of a namespace can use [`registerNamespaceDelegation`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/WorldRegistrationSystem.sol#L296-L335) to register a delegation that applies to all callers of systems in this namespace.
This functionality is useful, for example, to implement a trusted forwarder for the namespace.
This is not a security concern because the namespace owner already has full control over any table or `System` in the namespace.

Expand Down
10 changes: 9 additions & 1 deletion docs/pages/world/balance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ uint256 balance = Balances.get(<namespace>);
To transfer ETH out of the `World` you need to have the `access` permission level to the namespace itself.
Note that `System` contracts within the namespace do have that permission.

You use either [`transferBalanceToNamespace`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol#L23-L52), if you want to transfer between namespaces in the same `World`, or [`transferBalanceToAddress`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/BalanceTransferSystem.sol#L54-L77), to transfer to a different address.
You use either [`transferBalanceToNamespace`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/BalanceTransferSystem.sol#L25-L57), if you want to transfer between namespaces in the same `World`, or [`transferBalanceToAddress`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/BalanceTransferSystem.sol#L59-L86), to transfer to a different address.

<details>

Expand All @@ -230,3 +230,11 @@ These steps assume you already transferred 1 ether to the root namespace.
```

</details>

If you need to transfer ETH in a `System` that has access to a namespace (for example, because it is in that namespace), you can use a function similar to this:

```solidity
function _transfer(address to, uint amount) private {
IWorld(_world()).transferBalanceToAddress(WorldResourceIdLib.encodeNamespace("<namespace goes here>"), to, amount);
}
```
7 changes: 5 additions & 2 deletions docs/pages/world/batch-calls.mdx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Batch calls

Batch calls allow a single call to the `World` to perform multiple `System` calls.
Using [`batchCall`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/BatchCallSystem.sol#L15-L33) you can issue calls on your own behalf.
If you have the proper [delegations](/world/account-delegation), you can also use [`batchCallFrom`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/core/implementations/BatchCallSystem.sol#L35-L53) to issue `System` calls on behalf of other addresses.
Using [`batchCall`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/BatchCallSystem.sol#L15-L35) you can issue calls on your own behalf.
If you have the proper [delegations](/world/account-delegation), you can also use [`batchCallFrom`](https://github.com/latticexyz/mud/blob/main/packages/world/src/modules/init/implementations/BatchCallSystem.sol#L37-L57) to issue `System` calls on behalf of other addresses.

The calls take place sequentially, and after they all finish successfully you get back the return values from all of them.
If any of the calls revert, so does `batchCall` / `batchCallFrom`, so all the state changes created by the previous calls are discarded.

The advantage of using `batchCall` rather than [the standard multicall](https://github.com/mds1/multicall) is that `batchCall` is a native MUD function that lives in the `World` contract, so it does not change `msg.sender`.
As a result, when you use `batchCall` MUD can apply [access control](./namespaces-access-control), and `System`s can rely on the value of [`_msgSender()`](./systems#writing-systems).
Loading

0 comments on commit 5607081

Please sign in to comment.