// SPDX-License-Identifier: MIT pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ import { EphemeralInventorySystem } from "../../systems/inventory/EphemeralInventorySystem.sol"; import { CreateInventoryItemParams, InventoryItemParams } from "../../systems/inventory/types.sol"; import { revertWithBytes } from "@latticexyz/world/src/revertWithBytes.sol"; import { IWorldCall } from "@latticexyz/world/src/IWorldKernel.sol"; import { SystemCall } from "@latticexyz/world/src/SystemCall.sol"; import { Systems } from "@latticexyz/world/src/codegen/tables/Systems.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; type EphemeralInventorySystemType is bytes32; // equivalent to WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: "evefrontier", name: "EphemeralInvento" })) EphemeralInventorySystemType constant ephemeralInventorySystem = EphemeralInventorySystemType.wrap( 0x737965766566726f6e74696572000000457068656d6572616c496e76656e746f ); struct CallWrapper { ResourceId systemId; address from; } struct RootCallWrapper { ResourceId systemId; address from; } /** * @title EphemeralInventorySystemLib * @author MUD (https://mud.dev) by Lattice (https://lattice.xyz) * @dev This library is automatically generated from the corresponding system contract. Do not edit manually. */ library EphemeralInventorySystemLib { error EphemeralInventorySystemLib_CallingFromRootSystem(); error EphemeralInventory_InsufficientCapacity(string message, uint256 maxCapacity, uint256 usedCapacity); error EphemeralInventory_InvalidTenantId(uint256 smartObjectId, bytes32 tenantId); error EphemeralInventory_InvalidItemObjectId(uint256 smartObjectId); error EphemeralInventory_InvalidItemDepositQuantity(uint256 smartObjectId, uint256 quantity); error EphemeralInventory_NonExistentEntityRecord(string message, uint256 smartObjectId); error EphemeralInventory_InvalidSmartObjectId(uint256 smartObjectId); error EphemeralInventory_InvalidEphemeralOwner(uint256 smartObjectId, address ephemeralOwner); function getEphemeralSmartObjectId( EphemeralInventorySystemType self, uint256 smartObjectId, address ephemeralOwner ) internal view returns (uint256) { return CallWrapper(self.toResourceId(), address(0)).getEphemeralSmartObjectId(smartObjectId, ephemeralOwner); } function createAndDepositEphemeral( EphemeralInventorySystemType self, uint256 smartObjectId, address ephemeralOwner, CreateInventoryItemParams[] memory items ) internal { return CallWrapper(self.toResourceId(), address(0)).createAndDepositEphemeral(smartObjectId, ephemeralOwner, items); } function depositEphemeral( EphemeralInventorySystemType self, uint256 smartObjectId, address ephemeralOwner, InventoryItemParams[] memory items ) internal { return CallWrapper(self.toResourceId(), address(0)).depositEphemeral(smartObjectId, ephemeralOwner, items); } function withdrawEphemeral( EphemeralInventorySystemType self, uint256 smartObjectId, address ephemeralOwner, InventoryItemParams[] memory items ) internal { return CallWrapper(self.toResourceId(), address(0)).withdrawEphemeral(smartObjectId, ephemeralOwner, items); } function getEphemeralSmartObjectId( CallWrapper memory self, uint256 smartObjectId, address ephemeralOwner ) internal view returns (uint256) { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert EphemeralInventorySystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall( _getEphemeralSmartObjectId_uint256_address.getEphemeralSmartObjectId, (smartObjectId, ephemeralOwner) ); bytes memory worldCall = self.from == address(0) ? abi.encodeCall(IWorldCall.call, (self.systemId, systemCall)) : abi.encodeCall(IWorldCall.callFrom, (self.from, self.systemId, systemCall)); (bool success, bytes memory returnData) = address(_world()).staticcall(worldCall); if (!success) revertWithBytes(returnData); bytes memory result = abi.decode(returnData, (bytes)); return abi.decode(result, (uint256)); } function createAndDepositEphemeral( CallWrapper memory self, uint256 smartObjectId, address ephemeralOwner, CreateInventoryItemParams[] memory items ) internal { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert EphemeralInventorySystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall( _createAndDepositEphemeral_uint256_address_CreateInventoryItemParamsArray.createAndDepositEphemeral, (smartObjectId, ephemeralOwner, items) ); self.from == address(0) ? _world().call(self.systemId, systemCall) : _world().callFrom(self.from, self.systemId, systemCall); } function depositEphemeral( CallWrapper memory self, uint256 smartObjectId, address ephemeralOwner, InventoryItemParams[] memory items ) internal { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert EphemeralInventorySystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall( _depositEphemeral_uint256_address_InventoryItemParamsArray.depositEphemeral, (smartObjectId, ephemeralOwner, items) ); self.from == address(0) ? _world().call(self.systemId, systemCall) : _world().callFrom(self.from, self.systemId, systemCall); } function withdrawEphemeral( CallWrapper memory self, uint256 smartObjectId, address ephemeralOwner, InventoryItemParams[] memory items ) internal { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert EphemeralInventorySystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall( _withdrawEphemeral_uint256_address_InventoryItemParamsArray.withdrawEphemeral, (smartObjectId, ephemeralOwner, items) ); self.from == address(0) ? _world().call(self.systemId, systemCall) : _world().callFrom(self.from, self.systemId, systemCall); } function getEphemeralSmartObjectId( RootCallWrapper memory self, uint256 smartObjectId, address ephemeralOwner ) internal view returns (uint256) { bytes memory systemCall = abi.encodeCall( _getEphemeralSmartObjectId_uint256_address.getEphemeralSmartObjectId, (smartObjectId, ephemeralOwner) ); bytes memory result = SystemCall.staticcallOrRevert(self.from, self.systemId, systemCall); return abi.decode(result, (uint256)); } function createAndDepositEphemeral( RootCallWrapper memory self, uint256 smartObjectId, address ephemeralOwner, CreateInventoryItemParams[] memory items ) internal { bytes memory systemCall = abi.encodeCall( _createAndDepositEphemeral_uint256_address_CreateInventoryItemParamsArray.createAndDepositEphemeral, (smartObjectId, ephemeralOwner, items) ); SystemCall.callWithHooksOrRevert(self.from, self.systemId, systemCall, msg.value); } function depositEphemeral( RootCallWrapper memory self, uint256 smartObjectId, address ephemeralOwner, InventoryItemParams[] memory items ) internal { bytes memory systemCall = abi.encodeCall( _depositEphemeral_uint256_address_InventoryItemParamsArray.depositEphemeral, (smartObjectId, ephemeralOwner, items) ); SystemCall.callWithHooksOrRevert(self.from, self.systemId, systemCall, msg.value); } function withdrawEphemeral( RootCallWrapper memory self, uint256 smartObjectId, address ephemeralOwner, InventoryItemParams[] memory items ) internal { bytes memory systemCall = abi.encodeCall( _withdrawEphemeral_uint256_address_InventoryItemParamsArray.withdrawEphemeral, (smartObjectId, ephemeralOwner, items) ); SystemCall.callWithHooksOrRevert(self.from, self.systemId, systemCall, msg.value); } function callFrom(EphemeralInventorySystemType self, address from) internal pure returns (CallWrapper memory) { return CallWrapper(self.toResourceId(), from); } function callAsRoot(EphemeralInventorySystemType self) internal view returns (RootCallWrapper memory) { return RootCallWrapper(self.toResourceId(), msg.sender); } function callAsRootFrom( EphemeralInventorySystemType self, address from ) internal pure returns (RootCallWrapper memory) { return RootCallWrapper(self.toResourceId(), from); } function toResourceId(EphemeralInventorySystemType self) internal pure returns (ResourceId) { return ResourceId.wrap(EphemeralInventorySystemType.unwrap(self)); } function fromResourceId(ResourceId resourceId) internal pure returns (EphemeralInventorySystemType) { return EphemeralInventorySystemType.wrap(resourceId.unwrap()); } function getAddress(EphemeralInventorySystemType self) internal view returns (address) { return Systems.getSystem(self.toResourceId()); } function _world() private view returns (IWorldCall) { return IWorldCall(StoreSwitch.getStoreAddress()); } } /** * System Function Interfaces * * We generate an interface for each system function, which is then used for encoding system calls. * This is necessary to handle function overloading correctly (which abi.encodeCall cannot). * * Each interface is uniquely named based on the function name and parameters to prevent collisions. */ interface _getEphemeralSmartObjectId_uint256_address { function getEphemeralSmartObjectId(uint256 smartObjectId, address ephemeralOwner) external; } interface _createAndDepositEphemeral_uint256_address_CreateInventoryItemParamsArray { function createAndDepositEphemeral( uint256 smartObjectId, address ephemeralOwner, CreateInventoryItemParams[] memory items ) external; } interface _depositEphemeral_uint256_address_InventoryItemParamsArray { function depositEphemeral(uint256 smartObjectId, address ephemeralOwner, InventoryItemParams[] memory items) external; } interface _withdrawEphemeral_uint256_address_InventoryItemParamsArray { function withdrawEphemeral( uint256 smartObjectId, address ephemeralOwner, InventoryItemParams[] memory items ) external; } using EphemeralInventorySystemLib for EphemeralInventorySystemType global; using EphemeralInventorySystemLib for CallWrapper global; using EphemeralInventorySystemLib for RootCallWrapper global;