// SPDX-License-Identifier: MIT pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ import { OwnershipSystem } from "../../systems/ownership/OwnershipSystem.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 OwnershipSystemType is bytes32; // equivalent to WorldResourceIdLib.encode({ typeId: RESOURCE_SYSTEM, namespace: "evefrontier", name: "OwnershipSystem" })) OwnershipSystemType constant ownershipSystem = OwnershipSystemType.wrap( 0x737965766566726f6e746965720000004f776e65727368697053797374656d00 ); struct CallWrapper { ResourceId systemId; address from; } struct RootCallWrapper { ResourceId systemId; address from; } /** * @title OwnershipSystemLib * @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 OwnershipSystemLib { error OwnershipSystemLib_CallingFromRootSystem(); error Ownership_InvalidSingleton(uint256 smartObjectId); error Ownership_InvalidAccount(address account); error Ownership_InvalidOwner(uint256 smartObjectId, address invalidOwner); error Ownership_NonexistentObject(uint256 smartObjectId); error Ownership_AlreadyOwned(uint256 smartObjectId, address currentOwner); error Ownership_SingletonInInventory(uint256 smartObjectId, uint256 inventoryObjectId); function owner(OwnershipSystemType self, uint256 smartObjectId) internal view returns (address) { return CallWrapper(self.toResourceId(), address(0)).owner(smartObjectId); } function assignOwner(OwnershipSystemType self, uint256 smartObjectId, address to) internal { return CallWrapper(self.toResourceId(), address(0)).assignOwner(smartObjectId, to); } function removeOwner(OwnershipSystemType self, uint256 smartObjectId, address from) internal { return CallWrapper(self.toResourceId(), address(0)).removeOwner(smartObjectId, from); } function getEphemeralOwner( OwnershipSystemType self, uint256 inventoryObjectId, uint256 itemObjectId ) internal view returns (address) { return CallWrapper(self.toResourceId(), address(0)).getEphemeralOwner(inventoryObjectId, itemObjectId); } function getInventoryOwner( OwnershipSystemType self, uint256 inventoryObjectId, uint256 itemObjectId ) internal view returns (address) { return CallWrapper(self.toResourceId(), address(0)).getInventoryOwner(inventoryObjectId, itemObjectId); } function owner(CallWrapper memory self, uint256 smartObjectId) internal view returns (address) { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert OwnershipSystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall(_owner_uint256.owner, (smartObjectId)); 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, (address)); } function assignOwner(CallWrapper memory self, uint256 smartObjectId, address to) internal { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert OwnershipSystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall(_assignOwner_uint256_address.assignOwner, (smartObjectId, to)); self.from == address(0) ? _world().call(self.systemId, systemCall) : _world().callFrom(self.from, self.systemId, systemCall); } function removeOwner(CallWrapper memory self, uint256 smartObjectId, address from) internal { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert OwnershipSystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall(_removeOwner_uint256_address.removeOwner, (smartObjectId, from)); self.from == address(0) ? _world().call(self.systemId, systemCall) : _world().callFrom(self.from, self.systemId, systemCall); } function getEphemeralOwner( CallWrapper memory self, uint256 inventoryObjectId, uint256 itemObjectId ) internal view returns (address) { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert OwnershipSystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall( _getEphemeralOwner_uint256_uint256.getEphemeralOwner, (inventoryObjectId, itemObjectId) ); 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, (address)); } function getInventoryOwner( CallWrapper memory self, uint256 inventoryObjectId, uint256 itemObjectId ) internal view returns (address) { // if the contract calling this function is a root system, it should use `callAsRoot` if (address(_world()) == address(this)) revert OwnershipSystemLib_CallingFromRootSystem(); bytes memory systemCall = abi.encodeCall( _getInventoryOwner_uint256_uint256.getInventoryOwner, (inventoryObjectId, itemObjectId) ); 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, (address)); } function owner(RootCallWrapper memory self, uint256 smartObjectId) internal view returns (address) { bytes memory systemCall = abi.encodeCall(_owner_uint256.owner, (smartObjectId)); bytes memory result = SystemCall.staticcallOrRevert(self.from, self.systemId, systemCall); return abi.decode(result, (address)); } function assignOwner(RootCallWrapper memory self, uint256 smartObjectId, address to) internal { bytes memory systemCall = abi.encodeCall(_assignOwner_uint256_address.assignOwner, (smartObjectId, to)); SystemCall.callWithHooksOrRevert(self.from, self.systemId, systemCall, msg.value); } function removeOwner(RootCallWrapper memory self, uint256 smartObjectId, address from) internal { bytes memory systemCall = abi.encodeCall(_removeOwner_uint256_address.removeOwner, (smartObjectId, from)); SystemCall.callWithHooksOrRevert(self.from, self.systemId, systemCall, msg.value); } function getEphemeralOwner( RootCallWrapper memory self, uint256 inventoryObjectId, uint256 itemObjectId ) internal view returns (address) { bytes memory systemCall = abi.encodeCall( _getEphemeralOwner_uint256_uint256.getEphemeralOwner, (inventoryObjectId, itemObjectId) ); bytes memory result = SystemCall.staticcallOrRevert(self.from, self.systemId, systemCall); return abi.decode(result, (address)); } function getInventoryOwner( RootCallWrapper memory self, uint256 inventoryObjectId, uint256 itemObjectId ) internal view returns (address) { bytes memory systemCall = abi.encodeCall( _getInventoryOwner_uint256_uint256.getInventoryOwner, (inventoryObjectId, itemObjectId) ); bytes memory result = SystemCall.staticcallOrRevert(self.from, self.systemId, systemCall); return abi.decode(result, (address)); } function callFrom(OwnershipSystemType self, address from) internal pure returns (CallWrapper memory) { return CallWrapper(self.toResourceId(), from); } function callAsRoot(OwnershipSystemType self) internal view returns (RootCallWrapper memory) { return RootCallWrapper(self.toResourceId(), msg.sender); } function callAsRootFrom(OwnershipSystemType self, address from) internal pure returns (RootCallWrapper memory) { return RootCallWrapper(self.toResourceId(), from); } function toResourceId(OwnershipSystemType self) internal pure returns (ResourceId) { return ResourceId.wrap(OwnershipSystemType.unwrap(self)); } function fromResourceId(ResourceId resourceId) internal pure returns (OwnershipSystemType) { return OwnershipSystemType.wrap(resourceId.unwrap()); } function getAddress(OwnershipSystemType 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 _owner_uint256 { function owner(uint256 smartObjectId) external; } interface _assignOwner_uint256_address { function assignOwner(uint256 smartObjectId, address to) external; } interface _removeOwner_uint256_address { function removeOwner(uint256 smartObjectId, address from) external; } interface _getEphemeralOwner_uint256_uint256 { function getEphemeralOwner(uint256 inventoryObjectId, uint256 itemObjectId) external; } interface _getInventoryOwner_uint256_uint256 { function getInventoryOwner(uint256 inventoryObjectId, uint256 itemObjectId) external; } using OwnershipSystemLib for OwnershipSystemType global; using OwnershipSystemLib for CallWrapper global; using OwnershipSystemLib for RootCallWrapper global;