-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(store,world): replace isStore with storeAddress (#1061)
* refactor(store): replace isStore with storeAddress * refactor(world): replace isStore with storeAddress * rename WorldContext to WorldConsumer * gas-report * ignore storeAddress in deploy * add storeAddress to MudV2Test * fix StoreSwitch * rebuild and simplify examples * rebuild e2e * refactor MudV2Test to avoid circular dependencies * update templates * move comment about systems from StoreConsumer to WorldConsumer * use storeAddress in KeysWithValueHook for consistency * some gas optimizations * more optimizations * refactor StoreSwitch to use storage for storeAddress, exclude MudTest from abi * rebuild * cleanup * rebuild * Update packages/store/src/StoreSwitch.sol Co-authored-by: alvarius <[email protected]> * Update packages/store/src/StoreCore.sol Co-authored-by: alvarius <[email protected]> * Create selfish-cycles-retire.md * prettier * Update .changeset/selfish-cycles-retire.md Co-authored-by: alvarius <[email protected]> * Update .changeset/selfish-cycles-retire.md Co-authored-by: alvarius <[email protected]> --------- Co-authored-by: alvarius <[email protected]>
- Loading branch information
Showing
57 changed files
with
489 additions
and
447 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
"@latticexyz/std-contracts": minor | ||
"@latticexyz/store": minor | ||
"@latticexyz/world": minor | ||
--- | ||
|
||
Rename `MudV2Test` to `MudTest` and move from `@latticexyz/std-contracts` to `@latticexyz/store`. | ||
|
||
```solidity | ||
// old import | ||
import { MudV2Test } from "@latticexyz/std-contracts/src/test/MudV2Test.t.sol"; | ||
// new import | ||
import { MudTest } from "@latticexyz/store/src/MudTest.sol"; | ||
``` | ||
|
||
Refactor `StoreSwitch` to use a storage slot instead of `function isStore()` to determine which contract is Store: | ||
|
||
- Previously `StoreSwitch` called `isStore()` on `msg.sender` to determine if `msg.sender` is a `Store` contract. If the call succeeded, the `Store` methods were called on `msg.sender`, otherwise the data was written to the own storage. | ||
- With this change `StoreSwitch` instead checks for an `address` in a known storage slot. If the address equals the own address, data is written to the own storage. If it is an external address, `Store` methods are called on this address. If it is unset (`address(0)`), store methods are called on `msg.sender`. | ||
- In practice this has the same effect as before: By default the `World` contracts sets its own address in `StoreSwitch`, while `System` contracts keep the Store address undefined, so `Systems` write to their caller (`World`) if they are executed via `call` or directly to the `World` storage if they are executed via `delegatecall`. | ||
- Besides gas savings, this change has two additional benefits: | ||
1. it is now possible for `Systems` to explicitly set a `Store` address to make them exclusive to that `Store` and | ||
2. table libraries can now be used in tests without having to provide an explicit `Store` argument, because the `MudTest` base contract redirects reads and writes to the internal `World` contract. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.