MUD is a framework for building ambitious onchain applications
MIT License
Bot releases are visible (Hide)
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
8025c350
]:
Published by github-actions[bot] about 1 year ago
#1403 55377ffe
Thanks @holic! - We now use @latticexyz/abi-ts
to generate TS type declaration files (.d.ts
) for each ABI JSON file. This replaces our usage TypeChain everywhere.
If you have a MUD project created from an older template, you can replace TypeChain with abi-ts
by first updating your contracts' package.json
:
-"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:typechain",
+"build": "pnpm run build:mud && pnpm run build:abi && pnpm run build:abi-ts",
-"build:abi": "forge clean && forge build",
+"build:abi": "rimraf abi && forge build --extra-output-files abi --out abi --skip test script MudTest.sol",
+"build:abi-ts": "mud abi-ts --input 'abi/IWorld.sol/IWorld.abi.json' && prettier --write '**/*.abi.json.d.ts'",
"build:mud": "mud tablegen && mud worldgen",
-"build:typechain": "rimraf types && typechain --target=ethers-v5 out/IWorld.sol/IWorld.json",
And update your client's setupNetwork.ts
with:
-import { IWorld__factory } from "contracts/types/ethers-contracts/factories/IWorld__factory";
+import IWorldAbi from "contracts/abi/IWorld.sol/IWorld.abi.json";
const worldContract = createContract({
address: networkConfig.worldAddress as Hex,
- abi: IWorld__factory.abi,
+ abi: IWorldAbi,
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
#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'
8025c350
, 9af542d3
, 8025c350
]:
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
#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'
Published by github-actions[bot] about 1 year ago
#1370 9d0f492a
Thanks @alvrs! - - The previous Call.withSender
util is replaced with WorldContextProvider
, since the usecase of appending the msg.sender
to the calldata is tightly coupled with WorldContextConsumer
(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 with callWithContextOrRevert
/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 level call
/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 to WorldContextConsumer
to clarify the relationship between WorldContextProvider
(appending context to the calldata) and WorldContextConsumer
(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;
}
#1378 ce97426c
Thanks @alvrs! - It is now possible to upgrade systems by calling registerSystem
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! - The World
has a new callFrom
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 with delegator
as msgSender
.
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
's registerDelegation
function.
If delegatee
is address(0)
, the delegation is considered to be a "fallback" delegation and is used in callFrom
if there is no delegation is found for the specific caller.
Otherwise the delegation is registered for the specific delegatee
.
interface IBaseWorld {
function registerDelegation(
address delegatee,
bytes32 delegationControl,
bytes memory initFuncSelectorAndArgs
) external;
}
The delegationControl
refers to the resource selector of a DelegationControl
system that must have been registered beforehand.
As part of registering the delegation, the DelegationControl
system is called with the provided initFuncSelectorAndArgs
.
This can be used to initialize data in the given DelegationControl
system.
The DelegationControl
system must implement the IDelegationControl
interface:
interface IDelegationControl {
function verify(address delegator, bytes32 systemId, bytes calldata funcSelectorAndArgs) external returns (bool);
}
When callFrom
is called, the World
checks if a delegation is registered for the given caller, and if so calls the delegation control's verify
function with the same same arguments as callFrom
.
If the call to verify
is successful and returns true
, the delegation is valid and the call is forwarded to the system with delegator
as msgSender
.
Note: if UNLIMITED_DELEGATION
(from @latticexyz/world/src/constants.sol
) is passed as delegationControl
, the external call to the delegation control contract is skipped and the delegation is considered valid.
For examples of DelegationControl
systems, check out the CallboundDelegationControl
or TimeboundDelegationControl
systems in the std-delegations
module.
See StandardDelegations.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)
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
ce97426c
, 1ca35e9a
, 9d0f492a
, c583f3cd
]:
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago
Published by github-actions[bot] about 1 year ago