Releases: latticexyz/mud
@latticexyz/[email protected]
Minor Changes
-
#1413
8025c350
Thanks @holic! - Added a new@latticexyz/abi-ts
package to generate TS type declaration files (.d.ts
) for each ABI JSON file.This allows you to import your JSON ABI and use it directly with libraries like viem and abitype.
pnpm add @latticexyz/abi-ts pnpm abi-ts
By default,
abi-ts
looks for files with the glob**/*.abi.json
, but you can customize this glob with the--input
argument, e.g.pnpm abi-ts --input 'abi/IWorld.sol/IWorld.abi.json'
[email protected]
[email protected]
[email protected]
@latticexyz/[email protected]
Major Changes
-
#1370
9d0f492a
Thanks @alvrs! - - The previousCall.withSender
util is replaced withWorldContextProvider
, since the usecase of appending themsg.sender
to the calldata is tightly coupled withWorldContextConsumer
(which extracts the appended context from the calldata).The previous
Call.withSender
utility reverted if the call failed and only returned the returndata on success. This is replaced withcallWithContextOrRevert
/delegatecallWithContextOrRevert
-import { Call } from "@latticexyz/world/src/Call.sol"; +import { WorldContextProvider } from "@latticexyz/world/src/WorldContext.sol"; -Call.withSender({ - delegate: false, - value: 0, - ... -}); +WorldContextProvider.callWithContextOrRevert({ + value: 0, + ... +}); -Call.withSender({ - delegate: true, - value: 0, - ... -}); +WorldContextProvider.delegatecallWithContextOrRevert({ + ... +});
In addition there are utils that return a
bool success
flag instead of reverting on errors. This mirrors the behavior of Solidity's low levelcall
/delegatecall
functions and is useful in situations where additional logic should be executed in case of a reverting external call.library WorldContextProvider { function callWithContext( address target, // Address to call bytes memory funcSelectorAndArgs, // Abi encoded function selector and arguments to pass to pass to the contract address msgSender, // Address to append to the calldata as context for msgSender uint256 value // Value to pass with the call ) internal returns (bool success, bytes memory data); function delegatecallWithContext( address target, // Address to call bytes memory funcSelectorAndArgs, // Abi encoded function selector and arguments to pass to pass to the contract address msgSender // Address to append to the calldata as context for msgSender ) internal returns (bool success, bytes memory data); }
-
WorldContext
is renamed toWorldContextConsumer
to clarify the relationship betweenWorldContextProvider
(appending context to the calldata) andWorldContextConsumer
(extracting context from the calldata)-import { WorldContext } from "@latticexyz/world/src/WorldContext.sol"; -import { WorldContextConsumer } from "@latticexyz/world/src/WorldContext.sol";
-
The
World
contract previously had a_call
method to handle calling systems via their resource selector, performing accesss control checks and call hooks registered for the system.library SystemCall { /** * Calls a system via its resource selector and perform access control checks. * Does not revert if the call fails, but returns a `success` flag along with the returndata. */ function call( address caller, bytes32 resourceSelector, bytes memory funcSelectorAndArgs, uint256 value ) internal returns (bool success, bytes memory data); /** * Calls a system via its resource selector, perform access control checks and trigger hooks registered for the system. * Does not revert if the call fails, but returns a `success` flag along with the returndata. */ function callWithHooks( address caller, bytes32 resourceSelector, bytes memory funcSelectorAndArgs, uint256 value ) internal returns (bool success, bytes memory data); /** * Calls a system via its resource selector, perform access control checks and trigger hooks registered for the system. * Reverts if the call fails. */ function callWithHooksOrRevert( address caller, bytes32 resourceSelector, bytes memory funcSelectorAndArgs, uint256 value ) internal returns (bytes memory data); }
-
System hooks now are called with the system's resource selector instead of its address. The system's address can still easily obtained within the hook via
Systems.get(resourceSelector)
if necessary.interface ISystemHook { function onBeforeCallSystem( address msgSender, - address systemAddress, + bytes32 resourceSelector, bytes memory funcSelectorAndArgs ) external; function onAfterCallSystem( address msgSender, - address systemAddress, + bytes32 resourceSelector, bytes memory funcSelectorAndArgs ) external; }
-
Minor Changes
-
#1378
ce97426c
Thanks @alvrs! - It is now possible to upgrade systems by callingregisterSystem
again with an existing system id (resource selector).// Register a system world.registerSystem(systemId, systemAddress, publicAccess); // Upgrade the system by calling `registerSystem` with the // same system id but a new system address or publicAccess flag world.registerSystem(systemId, newSystemAddress, newPublicAccess);
-
#1364
1ca35e9a
Thanks @alvrs! - TheWorld
has a newcallFrom
entry point which allows systems to be called on behalf of other addresses if those addresses have registered a delegation.
If there is a delegation, the call is forwarded to the system withdelegator
asmsgSender
.interface IBaseWorld { function callFrom( address delegator, bytes32 resourceSelector, bytes memory funcSelectorAndArgs ) external payable virtual returns (bytes memory); }
A delegation can be registered via the
World
'sregisterDelegation
function.
Ifdelegatee
isaddress(0)
, the delegation is considered to be a "fallback" delegation and is used incallFrom
if there is no delegation is found for the specific caller.
Otherwise the delegation is registered for the specificdelegatee
.interface IBaseWorld { function registerDelegation( address delegatee, bytes32 delegationControl, bytes memory initFuncSelectorAndArgs ) external; }
The
delegationControl
refers to the resource selector of aDelegationControl
system that must have been registered beforehand.
As part of registering the delegation, theDelegationControl
system is called with the providedinitFuncSelectorAndArgs
.
This can be used to initialize data in the givenDelegationControl
system.The
DelegationControl
system must implement theIDelegationControl
interface:interface IDelegationControl { function verify(address delegator, bytes32 systemId, bytes calldata funcSelectorAndArgs) external returns (bool); }
When
callFrom
is called, theWorld
checks if a delegation is registered for the given caller, and if so calls the delegation control'sverify
function with the same same arguments ascallFrom
.
If the call toverify
is successful and returnstrue
, the delegation is valid and the call is forwarded to the system withdelegator
asmsgSender
.Note: if
UNLIMITED_DELEGATION
(from@latticexyz/world/src/constants.sol
) is passed asdelegationControl
, the external call to the delegation control contract is skipped and the delegation is considered valid.For examples of
DelegationControl
systems, check out theCallboundDelegationControl
orTimeboundDelegationControl
systems in thestd-delegations
module.
SeeStandardDelegations.t.sol
for usage examples. -
#1274
c583f3cd
Thanks @johngrantuk! - It is now possible to transfer ownership of namespaces!// Register a new namespace world.registerNamespace("namespace"); // It's owned by the caller of the function (address(this)) // Transfer ownership of the namespace to address(42) world.transferOwnership("namespace", address(42)); // It's now owned by address(42)
Patch Changes
- Updated dependencies []:
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
@latticexyz/[email protected]
@latticexyz/[email protected]
@latticexyz/[email protected]
Patch Changes
- Updated dependencies []:
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
@latticexyz/[email protected]
Patch Changes
- Updated dependencies [
ce97426c
,1ca35e9a
,9d0f492a
,c583f3cd
]:- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
@latticexyz/[email protected]
Patch Changes
- Updated dependencies []:
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]
- @latticexyz/[email protected]