Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(store): add StoreWrite and Store abstract contracts #2411

Merged
merged 27 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3ed90fa
refactor(store): add StoreWrite
yonadaa Mar 11, 2024
ed64f14
refactor: StoreData is Store
yonadaa Mar 11, 2024
638378e
chore: docs
yonadaa Mar 12, 2024
80df20f
chore: changeset
yonadaa Mar 12, 2024
ca39905
chore: remove StoreData
yonadaa Mar 12, 2024
fe0680b
Merge remote-tracking branch 'origin/main' into yonadaaa/abstract-store
yonadaa Mar 12, 2024
6349fc4
fix: protocol versions
yonadaa Mar 12, 2024
a3b7a27
chore: comment
yonadaa Mar 12, 2024
f92a94b
Merge remote-tracking branch 'origin/main' into yonadaaa/abstract-store
yonadaa Mar 13, 2024
c19e69e
chore: docs
yonadaa Mar 13, 2024
1568d8d
Merge remote-tracking branch 'origin/main' into yonadaaa/abstract-store
yonadaa Mar 18, 2024
c3a7170
refactor: store is istore
yonadaa Mar 18, 2024
421b02b
refactor: move storedata
yonadaa Mar 18, 2024
334bcf5
chore: comment
yonadaa Mar 18, 2024
9cf83c9
chore: docs
yonadaa Mar 18, 2024
24eb902
Merge branch 'main' into yonadaaa/abstract-store
alvrs Mar 21, 2024
a2cd5c8
add StoreKernel
alvrs Mar 21, 2024
354f344
Merge branch 'main' into yonadaaa/abstract-store
alvrs Mar 21, 2024
a1b1a65
update docs
alvrs Mar 21, 2024
8e9f374
Update .changeset/silly-mirrors-marry.md
alvrs Mar 21, 2024
97c6a2a
Update packages/world/src/World.sol
alvrs Mar 21, 2024
d220a1d
update docs
alvrs Mar 21, 2024
19f40b5
update comment
alvrs Mar 21, 2024
36b54a3
Update packages/store/src/IStoreKernel.sol
alvrs Mar 21, 2024
47e3c54
Update packages/store/src/IStoreKernel.sol
alvrs Mar 21, 2024
794f428
Update packages/store/src/IStore.sol
alvrs Mar 21, 2024
a56a7d2
update docs
alvrs Mar 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/silly-mirrors-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@latticexyz/store": minor
"@latticexyz/world": patch
---

Added an `abstract` `StoreKernel` contract, which includes all Store interfaces except for registration, and implements write methods, `protocolVersion` and initializes `StoreCore`. `Store` extends `StoreKernel` with the `IStoreRegistration` interface. `StoreData` is removed as a separate interface/contract. `World` now extends `StoreKernel` (since the registration methods are added via the `InitModule`).
32 changes: 3 additions & 29 deletions docs/pages/store/reference/store-core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1015,44 +1015,18 @@ function _loadEncodedDynamicDataLength(
| -------- | ---------------- | ----------------------------------------------------------------------------------------- |
| `<none>` | `EncodedLengths` | The loaded encoded dynamic data length from storage for the given table ID and key tuple. |

## StoreData
## Store

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/StoreData.sol)
[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/Store.sol)

**Inherits:**
[IStoreData](/store/reference/store#istoredata), [StoreRead](/store/reference/store-core#storeread)
[IStore](/src/IStore.sol/interface.IStore.md), [StoreKernel](/src/StoreKernel.sol/abstract.StoreKernel.md)

This contract integrates the core storage functionalities and provides an interface for data storage.

_This abstract contract initializes `StoreCore`, implements `storeVersion`, and read methods,
but not write methods._

### Functions

#### constructor

Constructs the StoreData contract and initializes the StoreCore.

_Emits a HelloStore event upon creation._

```solidity
constructor();
```

#### storeVersion

Retrieves the protocol version of the Store.

```solidity
function storeVersion() public pure returns (bytes32);
```

**Returns**

| Name | Type | Description |
| -------- | --------- | ---------------------------------- |
| `<none>` | `bytes32` | The protocol version of the Store. |

## StoreRead

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/StoreRead.sol)
Expand Down
31 changes: 1 addition & 30 deletions docs/pages/store/reference/store.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/IStore.sol)

**Inherits:**
[IStoreData](/store/reference/store#istoredata), [IStoreRegistration](/store/reference/store#istoreregistration), [IStoreErrors](/store/reference/store#istoreerrors), [IFieldLayoutErrors](/src/IFieldLayoutErrors.sol/interface.IFieldLayoutErrors.md), [IEncodedLengthsErrors](/src/IEncodedLengthsErrors.sol/interface.IEncodedLengthsErrors.md), [ISchemaErrors](/src/ISchemaErrors.sol/interface.ISchemaErrors.md), [ISliceErrors](/src/ISliceErrors.sol/interface.ISliceErrors.md)

IStore implements the error interfaces for each library that it uses.
[IStoreKernel](/src/IStoreKernel.sol/interface.IStoreKernel.md), [IStoreRegistration](/store/reference/store#istoreregistration)

## IStoreEvents

Expand Down Expand Up @@ -313,33 +311,6 @@ error Store_InvalidSplice(uint40 startWithinField, uint40 deleteCount, uint40 fi
| `deleteCount` | `uint40` | The number of bytes to delete in the splice operation. |
| `fieldLength` | `uint40` | The field length for the splice operation. |

## IStoreData

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/IStoreData.sol)

**Inherits:**
[IStoreRead](/store/reference/store#istoreread), [IStoreWrite](/store/reference/store#istorewrite)

The IStoreData interface includes methods for reading and writing table values.

_These methods are frequently invoked during runtime, so it is essential to prioritize optimizing their gas cost._

### Functions

#### storeVersion

Returns the version of the Store contract.

```solidity
function storeVersion() external view returns (bytes32 version);
```

**Returns**

| Name | Type | Description |
| --------- | --------- | ---------------------------------- |
| `version` | `bytes32` | The version of the Store contract. |

## IStoreRead

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/IStoreRead.sol)
Expand Down
18 changes: 7 additions & 11 deletions docs/pages/world/reference/world-external.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ that are dynamically registered in the World during deployment.

_._

### Functions

#### storeVersion
## Store

Retrieves the protocol version of the Store.
[Git Source](https://github.com/latticexyz/mud/blob/main/packages/world/src/Store.sol)

```solidity
function storeVersion() public pure returns (bytes32);
```
**Inherits:**
[IStore](/src/IStore.sol/interface.IStore.md), [StoreKernel](/src/StoreKernel.sol/abstract.StoreKernel.md)

**Returns**
This contract integrates the core storage functionalities and provides an interface for data storage.

| Name | Type | Description |
| -------- | --------- | ---------------------------------- |
| `<none>` | `bytes32` | The protocol version of the Store. |
_This abstract contract initializes `StoreCore`, implements `storeVersion`, and read methods,
but not write methods._

#### registerTable

Expand Down
4 changes: 3 additions & 1 deletion docs/pages/world/reference/world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
[Git Source](https://github.com/latticexyz/mud/blob/main/packages/world/src/World.sol)

**Inherits:**
[StoreData](/store/reference/store-core#storedata), [IWorldKernel](/world/reference/world-external#iworldkernel)
StoreKernel, [IWorldKernel](/world/reference/world-external#iworldkernel)

_This contract is the core "World" contract containing various methods for
data manipulation, system calls, and dynamic function selector handling._

_World doesn't inherit `Store` because the `IStoreRegistration` methods are added via the `InitModule`._

### State Variables

#### creator
Expand Down
18 changes: 2 additions & 16 deletions packages/store/src/IStore.sol
Original file line number Diff line number Diff line change
@@ -1,25 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { IStoreErrors } from "./IStoreErrors.sol";
import { IStoreData } from "./IStoreData.sol";
import { IStoreKernel } from "./IStoreKernel.sol";
import { IStoreRegistration } from "./IStoreRegistration.sol";
import { IFieldLayoutErrors } from "./IFieldLayoutErrors.sol";
import { IEncodedLengthsErrors } from "./IEncodedLengthsErrors.sol";
import { ISchemaErrors } from "./ISchemaErrors.sol";
import { ISliceErrors } from "./ISliceErrors.sol";

/**
* @title IStore
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
* @notice IStore implements the error interfaces for each library that it uses.
*/
interface IStore is
IStoreData,
IStoreRegistration,
IStoreErrors,
IFieldLayoutErrors,
IEncodedLengthsErrors,
ISchemaErrors,
ISliceErrors
{}
interface IStore is IStoreKernel, IStoreRegistration {}
19 changes: 0 additions & 19 deletions packages/store/src/IStoreData.sol

This file was deleted.

31 changes: 31 additions & 0 deletions packages/store/src/IStoreKernel.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { IStoreRead } from "./IStoreRead.sol";
import { IStoreWrite } from "./IStoreWrite.sol";
import { IStoreErrors } from "./IStoreErrors.sol";
import { IFieldLayoutErrors } from "./IFieldLayoutErrors.sol";
import { IEncodedLengthsErrors } from "./IEncodedLengthsErrors.sol";
import { ISchemaErrors } from "./ISchemaErrors.sol";
import { ISliceErrors } from "./ISliceErrors.sol";

/**
* @title IStoreKernel
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
* @notice IStoreKernel includes the error interfaces for each library that it uses.
*/
interface IStoreKernel is
IStoreRead,
IStoreWrite,
IStoreErrors,
IFieldLayoutErrors,
IEncodedLengthsErrors,
ISchemaErrors,
ISliceErrors
{
/**
* @notice Returns the protocol version of the Store contract.
* @return version The protocol version of the Store contract.
*/
function storeVersion() external view returns (bytes32 version);
}
18 changes: 18 additions & 0 deletions packages/store/src/Store.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { STORE_VERSION } from "./version.sol";
import { IStore } from "./IStore.sol";
import { StoreKernel } from "./StoreKernel.sol";
import { StoreRead } from "./StoreRead.sol";
import { StoreCore } from "./StoreCore.sol";
import { IStoreEvents } from "./IStoreEvents.sol";

/**
* @title Store Contract
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
* @notice This contract integrates the core storage functionalities and provides an interface for data storage.
* @dev This abstract contract initializes `StoreCore`, implements `storeVersion`, and read methods,
* but not write methods.
*/
abstract contract Store is IStore, StoreKernel {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
pragma solidity >=0.8.24;

import { STORE_VERSION } from "./version.sol";
import { IStoreData } from "./IStoreData.sol";
import { IStore } from "./IStore.sol";
import { StoreRead } from "./StoreRead.sol";
import { StoreCore } from "./StoreCore.sol";
import { IStoreEvents } from "./IStoreEvents.sol";
import { IStoreKernel } from "./IStoreKernel.sol";

/**
* @title Store Data Contract
* @title StoreKernel Contract
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
* @notice This contract integrates the core storage functionalities and provides an interface for data storage.
* @dev This abstract contract initializes `StoreCore`, implements `storeVersion`, and read methods,
* but not write methods.
* @notice This contract integrates the storage functionalities except registration and provides an interface for data storage.
* @dev This abstract contract initializes `StoreCore`, implements `storeVersion`, and read methods.
*/
abstract contract StoreData is IStoreData, StoreRead {
abstract contract StoreKernel is IStoreKernel, StoreRead {
/**
* @notice Constructs the StoreData contract and initializes the StoreCore.
* @notice Constructs the StoreKernel contract and initializes the StoreCore.
* @dev Emits a HelloStore event upon creation.
*/
constructor() {
Expand Down
Loading
Loading