Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into holic/gas-report-isolate
Browse files Browse the repository at this point in the history
  • Loading branch information
holic committed Mar 5, 2024
2 parents 8f06920 + c58da9a commit 53ac3fc
Show file tree
Hide file tree
Showing 528 changed files with 2,637 additions and 5,420 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-otters-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/world-modules": patch
---

ERC20 and ERC721 implementations now always register the token namespace, instead of checking if it has already been registered. This prevents issues with registering the namespace beforehand, namely that only the owner of a system can create a puppet for it.
5 changes: 5 additions & 0 deletions .changeset/famous-feet-suffer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store": patch
---

Refactored `StoreCore` to import `IStoreEvents` instead of defining the events twice.
21 changes: 21 additions & 0 deletions .changeset/few-berries-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"create-mud": patch
"@latticexyz/cli": major
"@latticexyz/common": major
"@latticexyz/store": patch
"@latticexyz/world": patch
"@latticexyz/world-modules": patch
---

Moved table ID and field layout constants in code-generated table libraries from the file level into the library, for clearer access and cleaner imports.

```diff
-import { SomeTable, SomeTableTableId } from "./codegen/tables/SomeTable.sol";
+import { SomeTable } from "./codegen/tables/SomeTable.sol";

-console.log(SomeTableTableId);
+console.log(SomeTable._tableId);

-console.log(SomeTable.getFieldLayout());
+console.log(SomeTable._fieldLayout);
```
5 changes: 5 additions & 0 deletions .changeset/heavy-shirts-dance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store": patch
---

Added interfaces for all errors that are used by `StoreCore`, which includes `FieldLayout`, `PackedCounter`, `Schema`, and `Slice`. This interfaces are inherited by `IStore`, ensuring that all possible errors are included in the `IStore` ABI for proper decoding in the frontend.
5 changes: 5 additions & 0 deletions .changeset/loud-rockets-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/common": patch
---

Upgraded prettier version to 3.2.5 and prettier-plugin-solidity version to 1.3.1.
25 changes: 25 additions & 0 deletions .changeset/moody-shirts-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
"@latticexyz/common": minor
"create-mud": minor
---

Added viem custom client actions that work the same as MUD's now-deprecated `getContract`, `writeContract`, and `sendTransaction` wrappers. Templates have been updated to reflect the new patterns.

You can migrate your own code like this:

```diff
-import { createWalletClient } from "viem";
-import { getContract, writeContract, sendTransaction } from "@latticexyz/common";
+import { createWalletClient, getContract } from "viem";
+import { transactionQueue, writeObserver } from "@latticexyz/common/actions";

-const walletClient = createWalletClient(...);
+const walletClient = createWalletClient(...)
+ .extend(transactionQueue())
+ .extend(writeObserver({ onWrite });

const worldContract = getContract({
client: { publicClient, walletClient },
- onWrite,
});
```
4 changes: 2 additions & 2 deletions .changeset/nasty-waves-divide.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest"

const latestBlockNumber$ = latestBlock$.pipe(
filter(isNonPendingBlock),
map((block) => block.number)
map((block) => block.number),
);

latestBlockNumber$
Expand All @@ -38,7 +38,7 @@ latestBlockNumber$
"event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)",
]),
}),
mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs)))
mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))),
)
.subscribe((block) => {
console.log("got events for block", block);
Expand Down
5 changes: 5 additions & 0 deletions .changeset/spicy-waves-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@latticexyz/store": patch
---

Moved the `HelloStore` to `IStoreEvents` so all Store events are defined in the same interface.
2 changes: 1 addition & 1 deletion .changeset/tame-lemons-play.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ As you migrate, you may find some features replaced, removed, or not included by
.pipe(
map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms
filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block
filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct
filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct
)
.subscribe(clock.update); // Update the local clock
```
Expand Down
16 changes: 16 additions & 0 deletions .changeset/tough-pumpkins-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
"create-mud": patch
"@latticexyz/store": minor
"@latticexyz/world": minor
"@latticexyz/world-modules": minor
---

Moved key schema and value schema methods to constants in code-generated table libraries for less bytecode and less gas in register/install methods.

```diff
-console.log(SomeTable.getKeySchema());
+console.log(SomeTable._keySchema);

-console.log(SomeTable.getValueSchema());
+console.log(SomeTable._valueSchema);
```
3 changes: 2 additions & 1 deletion .github/workflows/test-published-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ on:
jobs:
test-create-mud-project:
name: Test create-mud project
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest-16-cores, windows-latest]
template: [vanilla, react, react-ecs, phaser, threejs]

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
with:
Expand Down
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3395,7 +3395,7 @@ As you migrate, you may find some features replaced, removed, or not included by
.pipe(
map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms
filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block
filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct
filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct
)
.subscribe(clock.update); // Update the local clock
```
Expand Down Expand Up @@ -3633,7 +3633,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest"

const latestBlockNumber$ = latestBlock$.pipe(
filter(isNonPendingBlock),
map((block) => block.number)
map((block) => block.number),
);

latestBlockNumber$
Expand All @@ -3649,7 +3649,7 @@ latestBlockNumber$
"event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)",
]),
}),
mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs)))
mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))),
)
.subscribe((block) => {
console.log("got events for block", block);
Expand Down
2 changes: 1 addition & 1 deletion docs/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function HomePage() {
"min-h-screen flex flex-col animate-in animate-duration-500 fade-in",
"gap-12 p-8",
"sm:justify-between",
"md:gap-16 md:p-16"
"md:gap-16 md:p-16",
)}
>
<div className="flex items-center justify-between">
Expand Down
10 changes: 9 additions & 1 deletion docs/components/MUDTable.module.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
.table {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace;
font-family:
ui-monospace,
SFMono-Regular,
Menlo,
Monaco,
Consolas,
Liberation Mono,
Courier New,
monospace;
background-color: hsl(var(--nextra-primary-hue) 100% 66%/0.1);
margin-top: 1em;
text-align: center;
Expand Down
6 changes: 3 additions & 3 deletions docs/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3395,7 +3395,7 @@ As you migrate, you may find some features replaced, removed, or not included by
.pipe(
map((block) => Number(block.timestamp) * 1000), // Map to timestamp in ms
filter((blockTimestamp) => blockTimestamp !== clock.lastUpdateTime), // Ignore if the clock was already refreshed with this block
filter((blockTimestamp) => blockTimestamp !== clock.currentTime) // Ignore if the current local timestamp is correct
filter((blockTimestamp) => blockTimestamp !== clock.currentTime), // Ignore if the current local timestamp is correct
)
.subscribe(clock.update); // Update the local clock
```
Expand Down Expand Up @@ -3633,7 +3633,7 @@ const latestBlock$ = await createBlockStream({ publicClient, blockTag: "latest"

const latestBlockNumber$ = latestBlock$.pipe(
filter(isNonPendingBlock),
map((block) => block.number)
map((block) => block.number),
);

latestBlockNumber$
Expand All @@ -3649,7 +3649,7 @@ latestBlockNumber$
"event StoreEphemeralRecord(bytes32 table, bytes32[] key, bytes data)",
]),
}),
mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs)))
mergeMap(({ logs }) => from(groupLogsByBlockNumber(logs))),
)
.subscribe((block) => {
console.log("got events for block", block);
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 @@ -255,7 +255,7 @@ export type SystemCalls = ReturnType<typeof createSystemCalls>;

export function createSystemCalls(
{ playerEntity, worldContract, waitForTransaction }: SetupNetworkResult,
{ Player, Position }: ClientComponents
{ Player, Position }: ClientComponents,
) {
const moveBy = async (deltaX: number, deltaY: number) => {
if (!playerEntity) {
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/guides/emojimon/4-map-and-terrain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export type SystemCalls = ReturnType<typeof createSystemCalls>;

export function createSystemCalls(
{ playerEntity, worldContract, waitForTransaction }: SetupNetworkResult,
{ MapConfig, Obstruction, Player, Position }: ClientComponents
{ MapConfig, Obstruction, Player, Position }: ClientComponents,
) {
const isObstructed = (x: number, y: number) => {
return runQuery([Has(Obstruction), HasValue(Position, { x, y })]).size > 0;
Expand Down
4 changes: 2 additions & 2 deletions docs/pages/guides/emojimon/5-a-wild-emojimon-appears.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ export type SystemCalls = ReturnType<typeof createSystemCalls>;

export function createSystemCalls(
{ playerEntity, worldContract, waitForTransaction }: SetupNetworkResult,
{ Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents
{ Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents,
) {
const wrapPosition = (x: number, y: number) => {
const mapConfig = getComponentValue(MapConfig, singletonEntity);
Expand Down Expand Up @@ -890,7 +890,7 @@ export type SystemCalls = ReturnType<typeof createSystemCalls>;

export function createSystemCalls(
{ playerEntity, worldContract, waitForTransaction }: SetupNetworkResult,
{ Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents
{ Encounter, MapConfig, MonsterCatchAttempt, Obstruction, Player, Position }: ClientComponents,
) {
const wrapPosition = (x: number, y: number) => {
const mapConfig = getComponentValue(MapConfig, singletonEntity);
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/guides/hello-world/add-table.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ This exclamation point tells the compiler that it's OK, there will be a real val
<CollapseCode>

```html filename="index.html" copy showLineNumbers {12-17}
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
74 changes: 2 additions & 72 deletions docs/pages/store/reference/misc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -470,50 +470,6 @@ function encode(uint256[] memory _staticFieldLengths, uint256 numDynamicFields)
| -------- | ------------- | ------------------------------------------------------------ |
| `<none>` | `FieldLayout` | A FieldLayout structure containing the encoded field layout. |

### Errors

#### FieldLayoutLib_TooManyFields

```solidity
error FieldLayoutLib_TooManyFields(uint256 numFields, uint256 maxFields);
```

#### FieldLayoutLib_TooManyDynamicFields

```solidity
error FieldLayoutLib_TooManyDynamicFields(uint256 numFields, uint256 maxFields);
```

#### FieldLayoutLib_Empty

```solidity
error FieldLayoutLib_Empty();
```

#### FieldLayoutLib_InvalidStaticDataLength

```solidity
error FieldLayoutLib_InvalidStaticDataLength(uint256 staticDataLength, uint256 computedStaticDataLength);
```

#### FieldLayoutLib_StaticLengthIsZero

```solidity
error FieldLayoutLib_StaticLengthIsZero(uint256 index);
```

#### FieldLayoutLib_StaticLengthIsNotZero

```solidity
error FieldLayoutLib_StaticLengthIsNotZero(uint256 index);
```

#### FieldLayoutLib_StaticLengthDoesNotFitInAWord

```solidity
error FieldLayoutLib_StaticLengthDoesNotFitInAWord(uint256 index);
```

## FieldLayout

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/FieldLayout.sol)
Expand Down Expand Up @@ -991,24 +947,6 @@ function encode(SchemaType[] memory schemas) internal pure returns (Schema);
| -------- | -------- | ------------------- |
| `<none>` | `Schema` | The encoded Schema. |

### Errors

#### SchemaLib_InvalidLength

_Error raised when the provided schema has an invalid length._

```solidity
error SchemaLib_InvalidLength(uint256 length);
```

#### SchemaLib_StaticTypeAfterDynamicType

_Error raised when a static type is placed after a dynamic type in a schema._

```solidity
error SchemaLib_StaticTypeAfterDynamicType();
```

## Schema

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Schema.sol)
Expand Down Expand Up @@ -1192,14 +1130,6 @@ function getSubslice(bytes memory data, uint256 start, uint256 end) internal pur
| -------- | ------- | ------------------------------------- |
| `<none>` | `Slice` | A new Slice representing the subslice |

### Errors

#### Slice_OutOfBounds

```solidity
error Slice_OutOfBounds(bytes data, uint256 start, uint256 end);
```

## Slice

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Slice.sol)
Expand Down Expand Up @@ -1618,9 +1548,9 @@ bytes2 constant RESOURCE_OFFCHAIN_TABLE = "ot";

#### STORE_VERSION

Contains a constant representing the version of the store.
Contains a constant representing the version of the Store.

_Identifier for the current store version._
_Identifier for the current Store version._

```solidity
bytes32 constant STORE_VERSION = "1.0.0-unaudited";
Expand Down
Loading

0 comments on commit 53ac3fc

Please sign in to comment.