mud

MUD is a framework for building ambitious onchain applications

MIT License

Downloads
318.4K
Stars
643
Committers
80

Bot releases are visible (Hide)

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Major Changes

  • #1410 9af542d3 Thanks @holic! - Renames mud-gas-report binary to gas-report, since it's no longer MUD specific.
mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - [email protected]

Published by github-actions[bot] about 1 year ago

Minor Changes

  • #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,
    
mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

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'
    

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

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'
    
mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Major Changes

  • #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;
      }
      

Minor Changes

  • #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)
    

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

mud - [email protected]

Published by github-actions[bot] about 1 year ago

mud - [email protected]

Published by github-actions[bot] about 1 year ago

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago

Patch Changes

  • #1377 33f50f8a Thanks @alvrs! - Fixed an issue where the TypeScript types for createFaucetService were not exported correctly from the @latticexyz/services package

  • #1219 80a26419 Thanks @ludns! - The build phase of services now works on machines with older protobuf compilers

mud - @latticexyz/[email protected]

Published by github-actions[bot] about 1 year ago