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 10 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` `StoreWrite` contract, and renamed `StoreData` to `Store`.
alvrs marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 6 additions & 5 deletions docs/pages/store/reference/store-core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -1015,23 +1015,24 @@ function _loadEncodedDynamicDataLength(
| -------- | --------------- | ----------------------------------------------------------------------------------------- |
| `<none>` | `PackedCounter` | 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)
[StoreWrite](/src/StoreWrite.sol/abstract.StoreWrite.md), [StoreRead](/store/reference/store-core#storeread)

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._
but not write methods.
Note that `Store` does not implement `IStore`, because we want `IWorldKernel` to inherit `IStore` but it does not implement all the Store methods._

### Functions

#### constructor

Constructs the StoreData contract and initializes the StoreCore.
Constructs the Store contract and initializes the StoreCore.

_Emits a HelloStore event upon creation._

Expand Down
45 changes: 17 additions & 28 deletions docs/pages/store/reference/store.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,26 @@
[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), [IPackedCounterErrors](/src/IPackedCounterErrors.sol/interface.IPackedCounterErrors.md), [ISchemaErrors](/src/ISchemaErrors.sol/interface.ISchemaErrors.md), [ISliceErrors](/src/ISliceErrors.sol/interface.ISliceErrors.md)
[IStoreRead](/store/reference/store#istoreread), [IStoreWrite](/store/reference/store#istorewrite), [IStoreRegistration](/store/reference/store#istoreregistration), [IStoreErrors](/store/reference/store#istoreerrors), [IFieldLayoutErrors](/src/IFieldLayoutErrors.sol/interface.IFieldLayoutErrors.md), [IPackedCounterErrors](/src/IPackedCounterErrors.sol/interface.IPackedCounterErrors.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.

### 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. |

## IStoreEvents

[Git Source](https://github.com/latticexyz/mud/blob/main/packages/store/src/IStoreEvents.sol)
Expand Down Expand Up @@ -313,33 +329,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
13 changes: 13 additions & 0 deletions docs/pages/world/reference/world-external.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ that are dynamically registered in the World during deployment.

_._

## Store

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

**Inherits:**
[StoreWrite](/src/StoreWrite.sol/abstract.StoreWrite.md), [StoreRead](/store/reference/store-core#storeread)

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.
Note that `Store` does not implement `IStore`, because we want `IWorldKernel` to inherit `IStore` but it does not implement all the Store methods._

### Functions

#### storeVersion
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/world/reference/world.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[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)
Store, [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._
Expand Down
14 changes: 11 additions & 3 deletions packages/store/src/IStore.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// 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 { IStoreData } from "./IStoreData.sol";
import { IStoreRegistration } from "./IStoreRegistration.sol";
import { IFieldLayoutErrors } from "./IFieldLayoutErrors.sol";
import { IPackedCounterErrors } from "./IPackedCounterErrors.sol";
Expand All @@ -15,11 +16,18 @@ import { ISliceErrors } from "./ISliceErrors.sol";
* @notice IStore implements the error interfaces for each library that it uses.
*/
interface IStore is
IStoreData,
IStoreRead,
IStoreWrite,
IStoreRegistration,
IStoreErrors,
IFieldLayoutErrors,
IPackedCounterErrors,
ISchemaErrors,
ISliceErrors
{}
{
/**
* @notice Returns the version of the Store contract.
* @return version The version of the Store contract.
*/
function storeVersion() external view returns (bytes32 version);
holic marked this conversation as resolved.
Show resolved Hide resolved
}
19 changes: 0 additions & 19 deletions packages/store/src/IStoreData.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@
pragma solidity >=0.8.24;

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

/**
* @title Store Data Contract
* @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.
* Note that `Store` does not implement `IStore`, because we want `IWorldKernel` to inherit `IStore` but it does not implement all the Store methods.
yonadaa marked this conversation as resolved.
Show resolved Hide resolved
*/
abstract contract StoreData is IStoreData, StoreRead {
abstract contract Store is StoreWrite, StoreRead {
/**
* @notice Constructs the StoreData contract and initializes the StoreCore.
* @notice Constructs the Store contract and initializes the StoreCore.
* @dev Emits a HelloStore event upon creation.
*/
constructor() {
Expand Down
10 changes: 10 additions & 0 deletions packages/store/src/StoreWrite.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.24;

import { IStoreWrite } from "./IStoreWrite.sol";

/**
* @title StoreWrite
* @author MUD (https://mud.dev) by Lattice (https://lattice.xyz)
*/
abstract contract StoreWrite is IStoreWrite {}
Loading
Loading