@latticexyz/gas-report
Advanced tools
Changelog
Version 2.0.0-next.8
feat(world,store): add ERC165 checks for all registration methods (#1458) (@latticexyz/store, @latticexyz/world)
The World
now performs ERC165
interface checks to ensure that the StoreHook
, SystemHook
, System
, DelegationControl
and Module
contracts to actually implement their respective interfaces before registering them in the World.
The required supportsInterface
methods are implemented on the respective base contracts.
When creating one of these contracts, the recommended approach is to extend the base contract rather than the interface.
- import { IStoreHook } from "@latticexyz/store/src/IStore.sol";
+ import { StoreHook } from "@latticexyz/store/src/StoreHook.sol";
- contract MyStoreHook is IStoreHook {}
+ contract MyStoreHook is StoreHook {}
- import { ISystemHook } from "@latticexyz/world/src/interfaces/ISystemHook.sol";
+ import { SystemHook } from "@latticexyz/world/src/SystemHook.sol";
- contract MySystemHook is ISystemHook {}
+ contract MySystemHook is SystemHook {}
- import { IDelegationControl } from "@latticexyz/world/src/interfaces/IDelegationControl.sol";
+ import { DelegationControl } from "@latticexyz/world/src/DelegationControl.sol";
- contract MyDelegationControl is IDelegationControl {}
+ contract MyDelegationControl is DelegationControl {}
- import { IModule } from "@latticexyz/world/src/interfaces/IModule.sol";
+ import { Module } from "@latticexyz/world/src/Module.sol";
- contract MyModule is IModule {}
+ contract MyModule is Module {}
feat(world): change requireOwnerOrSelf to requireOwner (#1457) (@latticexyz/world)
The access control library no longer allows calls by the World
contract to itself to bypass the ownership check.
This is a breaking change for root modules that relied on this mechanism to register root tables, systems or function selectors.
To upgrade, root modules must use delegatecall
instead of a regular call
to install root tables, systems or function selectors.
- world.registerSystem(rootSystemId, rootSystemAddress);
+ address(world).delegatecall(abi.encodeCall(world.registerSystem, (rootSystemId, rootSystemAddress)));
An installRoot
method was added to the IModule
interface.
This method is now called when installing a root module via world.installRootModule
.
When installing non-root modules via world.installModule
, the module's install
function continues to be called.
feat(world): add Balance table and BalanceTransferSystem (#1425) (@latticexyz/world)
The World now maintains a balance per namespace. When a system is called with value, the value stored in the World contract and credited to the system's namespace.
Previously, the World contract did not store value, but passed it on to the system contracts. However, as systems are expected to be stateless (reading/writing state only via the calling World) and can be registered in multiple Worlds, this could have led to exploits.
Any address with access to a namespace can use the balance of that namespace. This allows all systems registered in the same namespace to work with the same balance.
There are two new World methods to transfer balance between namespaces (transferBalanceToNamespace
) or to an address (transferBalanceToAddress
).
interface IBaseWorld {
function transferBalanceToNamespace(bytes16 fromNamespace, bytes16 toNamespace, uint256 amount) external;
function transferBalanceToAddress(bytes16 fromNamespace, address toAddress, uint256 amount) external;
}
feat(store,world): add ability to unregister hooks (#1422) (@latticexyz/store, @latticexyz/world)
It is now possible to unregister Store hooks and System hooks.
interface IStore {
function unregisterStoreHook(bytes32 table, IStoreHook hookAddress) external;
// ...
}
interface IWorld {
function unregisterSystemHook(bytes32 resourceSelector, ISystemHook hookAddress) external;
// ...
}
feat(protocol-parser): add keySchema/valueSchema helpers (#1443) (@latticexyz/store)
Moved KeySchema
, ValueSchema
, SchemaToPrimitives
and TableRecord
types into @latticexyz/protocol-parser
feat(protocol-parser): add keySchema/valueSchema helpers (#1443) (@latticexyz/protocol-parser)
Adds decodeKey
, decodeValue
, encodeKey
, and encodeValue
helpers to decode/encode from key/value schemas. Deprecates previous methods that use a schema object with static/dynamic field arrays, originally attempting to model our on-chain behavior but ended up not very ergonomic when working with table configs.