From 66cd7ec0dc71cb8d06f9bf0259ee67d946981781 Mon Sep 17 00:00:00 2001 From: Dhvani Patel Date: Mon, 13 May 2024 11:11:33 +0100 Subject: [PATCH] use hook util --- packages/hardhat/contracts/Game.sol | 5 +- .../nextjs/contracts/deployedContracts.ts | 918 ++---------------- 2 files changed, 72 insertions(+), 851 deletions(-) diff --git a/packages/hardhat/contracts/Game.sol b/packages/hardhat/contracts/Game.sol index 5b3db858..897a5aaa 100644 --- a/packages/hardhat/contracts/Game.sol +++ b/packages/hardhat/contracts/Game.sol @@ -19,6 +19,7 @@ import { ObjectTypeMetadata } from "@biomesaw/world/src/codegen/tables/ObjectTyp import { AirObjectID } from "@biomesaw/world/src/ObjectTypeIds.sol"; import { getObjectType, getEntityAtCoord, getPosition, getEntityFromPlayer, getObjectTypeAtCoord } from "../utils/EntityUtils.sol"; import { voxelCoordsAreEqual } from "@biomesaw/utils/src/VoxelCoordUtils.sol"; +import { decodeCallData } from "../utils/HookUtils.sol"; import { NamedBuild } from "../utils/GameUtils.sol"; @@ -93,8 +94,8 @@ contract Game is ICustomUnregisterDelegation, IOptionalSystemHook { bytes memory callData ) external override onlyBiomeWorld { if (ResourceId.unwrap(systemId) == ResourceId.unwrap(BuildSystemId)) { - Slice callDataArgs = SliceLib.getSubslice(callData, 4); - (, VoxelCoord memory coord) = abi.decode(callDataArgs.toBytes(), (uint8, VoxelCoord)); + (, bytes memory callDataArgs) = decodeCallData(callData); + (, VoxelCoord memory coord) = abi.decode(callDataArgs, (uint8, VoxelCoord)); coordHashToBuilder[getCoordHash(coord)] = msgSender; } } diff --git a/packages/nextjs/contracts/deployedContracts.ts b/packages/nextjs/contracts/deployedContracts.ts index 4ac356b3..196f6dd1 100644 --- a/packages/nextjs/contracts/deployedContracts.ts +++ b/packages/nextjs/contracts/deployedContracts.ts @@ -5,9 +5,9 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract"; const deployedContracts = { - 690: { + 31337: { Game: { - address: "0x4FB8395E1B22E44b498A02fd2eb5a5C49f1DadF1", + address: "0xaC47e91215fb80462139756f43438402998E4A3a", abi: [ { inputs: [ @@ -197,6 +197,73 @@ const deployedContracts = { stateMutability: "view", type: "function", }, + { + inputs: [], + name: "getBuilds", + outputs: [ + { + components: [ + { + internalType: "string", + name: "name", + type: "string", + }, + { + components: [ + { + internalType: "uint8[]", + name: "objectTypeIds", + type: "uint8[]", + }, + { + components: [ + { + internalType: "int16", + name: "x", + type: "int16", + }, + { + internalType: "int16", + name: "y", + type: "int16", + }, + { + internalType: "int16", + name: "z", + type: "int16", + }, + ], + internalType: "struct VoxelCoord[]", + name: "relativePositions", + type: "tuple[]", + }, + ], + internalType: "struct Build", + name: "build", + type: "tuple", + }, + ], + internalType: "struct NamedBuild[]", + name: "", + type: "tuple[]", + }, + ], + stateMutability: "view", + type: "function", + }, + { + inputs: [], + name: "getDisplayName", + outputs: [ + { + internalType: "string", + name: "", + type: "string", + }, + ], + stateMutability: "view", + type: "function", + }, { inputs: [ { @@ -394,853 +461,6 @@ const deployedContracts = { }, }, }, - 17069: { - Game: { - address: "0xB1f332427AdE17d97686395cB109B216A2B51F03", - abi: [ - { - inputs: [ - { - internalType: "address", - name: "_biomeWorldAddress", - type: "address", - }, - { - internalType: "address", - name: "_delegatorAddress", - type: "address", - }, - ], - stateMutability: "nonpayable", - type: "constructor", - }, - { - inputs: [], - name: "basicGetter", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "biomeWorldAddress", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "delegator", - type: "address", - }, - ], - name: "canUnregister", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "delegatorAddress", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getRegisteredPlayers", - outputs: [ - { - internalType: "address[]", - name: "", - type: "address[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "msgSender", - type: "address", - }, - { - internalType: "ResourceId", - name: "systemId", - type: "bytes32", - }, - { - internalType: "bytes", - name: "callData", - type: "bytes", - }, - ], - name: "onAfterCallSystem", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "msgSender", - type: "address", - }, - { - internalType: "ResourceId", - name: "systemId", - type: "bytes32", - }, - { - internalType: "bytes", - name: "callData", - type: "bytes", - }, - ], - name: "onBeforeCallSystem", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "msgSender", - type: "address", - }, - { - internalType: "ResourceId", - name: "systemId", - type: "bytes32", - }, - { - internalType: "uint8", - name: "enabledHooksBitmap", - type: "uint8", - }, - { - internalType: "bytes32", - name: "callDataHash", - type: "bytes32", - }, - ], - name: "onRegisterHook", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "msgSender", - type: "address", - }, - { - internalType: "ResourceId", - name: "systemId", - type: "bytes32", - }, - { - internalType: "uint8", - name: "enabledHooksBitmap", - type: "uint8", - }, - { - internalType: "bytes32", - name: "callDataHash", - type: "bytes32", - }, - ], - name: "onUnregisterHook", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "bytes4", - name: "interfaceId", - type: "bytes4", - }, - ], - name: "supportsInterface", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - ], - inheritedFunctions: { - canUnregister: "@latticexyz/world/src/ICustomUnregisterDelegation.sol", - supportsInterface: "@latticexyz/world/src/IOptionalSystemHook.sol", - onAfterCallSystem: "@latticexyz/world/src/IOptionalSystemHook.sol", - onBeforeCallSystem: "@latticexyz/world/src/IOptionalSystemHook.sol", - onRegisterHook: "@latticexyz/world/src/IOptionalSystemHook.sol", - onUnregisterHook: "@latticexyz/world/src/IOptionalSystemHook.sol", - }, - }, - }, - 31337: { - Game: { - address: "0x12Bcb546bC60fF39F1Adfc7cE4605d5Bd6a6A876", - abi: [ - { - inputs: [ - { - internalType: "address", - name: "_biomeWorldAddress", - type: "address", - }, - { - components: [ - { - internalType: "int16", - name: "x", - type: "int16", - }, - { - internalType: "int16", - name: "y", - type: "int16", - }, - { - internalType: "int16", - name: "z", - type: "int16", - }, - ], - internalType: "struct VoxelCoord", - name: "lowerSouthwestCorner", - type: "tuple", - }, - { - components: [ - { - internalType: "int16", - name: "x", - type: "int16", - }, - { - internalType: "int16", - name: "y", - type: "int16", - }, - { - internalType: "int16", - name: "z", - type: "int16", - }, - ], - internalType: "struct VoxelCoord", - name: "size", - type: "tuple", - }, - { - internalType: "address", - name: "_gameStarter", - type: "address", - }, - ], - stateMutability: "nonpayable", - type: "constructor", - }, - { - inputs: [ - { - internalType: "bytes", - name: "data", - type: "bytes", - }, - { - internalType: "uint256", - name: "start", - type: "uint256", - }, - { - internalType: "uint256", - name: "end", - type: "uint256", - }, - ], - name: "Slice_OutOfBounds", - type: "error", - }, - { - inputs: [], - name: "biomeWorldAddress", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "claimRewardPool", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "gameEndBlock", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "gameStarter", - outputs: [ - { - internalType: "address", - name: "", - type: "address", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getAlivePlayers", - outputs: [ - { - internalType: "address[]", - name: "", - type: "address[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getAreas", - outputs: [ - { - components: [ - { - internalType: "string", - name: "name", - type: "string", - }, - { - components: [ - { - components: [ - { - internalType: "int16", - name: "x", - type: "int16", - }, - { - internalType: "int16", - name: "y", - type: "int16", - }, - { - internalType: "int16", - name: "z", - type: "int16", - }, - ], - internalType: "struct VoxelCoord", - name: "lowerSouthwestCorner", - type: "tuple", - }, - { - components: [ - { - internalType: "int16", - name: "x", - type: "int16", - }, - { - internalType: "int16", - name: "y", - type: "int16", - }, - { - internalType: "int16", - name: "z", - type: "int16", - }, - ], - internalType: "struct VoxelCoord", - name: "size", - type: "tuple", - }, - ], - internalType: "struct Area", - name: "area", - type: "tuple", - }, - ], - internalType: "struct NamedArea[]", - name: "", - type: "tuple[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getAvatars", - outputs: [ - { - internalType: "bytes32[]", - name: "", - type: "bytes32[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getCountdownEndBlock", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getDeadPlayers", - outputs: [ - { - internalType: "address[]", - name: "", - type: "address[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getDisplayName", - outputs: [ - { - internalType: "string", - name: "", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getDisqualifiedPlayers", - outputs: [ - { - internalType: "address[]", - name: "", - type: "address[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getKillsLeaderboard", - outputs: [ - { - components: [ - { - internalType: "address", - name: "player", - type: "address", - }, - { - internalType: "bool", - name: "isAlive", - type: "bool", - }, - { - internalType: "uint256", - name: "kills", - type: "uint256", - }, - ], - internalType: "struct LeaderboardEntry[]", - name: "", - type: "tuple[]", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getMatchArea", - outputs: [ - { - components: [ - { - components: [ - { - internalType: "int16", - name: "x", - type: "int16", - }, - { - internalType: "int16", - name: "y", - type: "int16", - }, - { - internalType: "int16", - name: "z", - type: "int16", - }, - ], - internalType: "struct VoxelCoord", - name: "lowerSouthwestCorner", - type: "tuple", - }, - { - components: [ - { - internalType: "int16", - name: "x", - type: "int16", - }, - { - internalType: "int16", - name: "y", - type: "int16", - }, - { - internalType: "int16", - name: "z", - type: "int16", - }, - ], - internalType: "struct VoxelCoord", - name: "size", - type: "tuple", - }, - ], - internalType: "struct Area", - name: "", - type: "tuple", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getRewardPool", - outputs: [ - { - internalType: "uint256", - name: "", - type: "uint256", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getStatus", - outputs: [ - { - internalType: "string", - name: "", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "getUnregisterMessage", - outputs: [ - { - internalType: "string", - name: "", - type: "string", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [], - name: "isGameStarted", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "msgSender", - type: "address", - }, - { - internalType: "ResourceId", - name: "systemId", - type: "bytes32", - }, - { - internalType: "bytes", - name: "callData", - type: "bytes", - }, - ], - name: "onAfterCallSystem", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "msgSender", - type: "address", - }, - { - internalType: "ResourceId", - name: "systemId", - type: "bytes32", - }, - { - internalType: "bytes", - name: "callData", - type: "bytes", - }, - ], - name: "onBeforeCallSystem", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "msgSender", - type: "address", - }, - { - internalType: "ResourceId", - name: "systemId", - type: "bytes32", - }, - { - internalType: "uint8", - name: "enabledHooksBitmap", - type: "uint8", - }, - { - internalType: "bytes32", - name: "callDataHash", - type: "bytes32", - }, - ], - name: "onRegisterHook", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "address", - name: "msgSender", - type: "address", - }, - { - internalType: "ResourceId", - name: "systemId", - type: "bytes32", - }, - { - internalType: "uint8", - name: "enabledHooksBitmap", - type: "uint8", - }, - { - internalType: "bytes32", - name: "callDataHash", - type: "bytes32", - }, - ], - name: "onUnregisterHook", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [], - name: "registerPlayer", - outputs: [], - stateMutability: "payable", - type: "function", - }, - { - inputs: [ - { - components: [ - { - internalType: "int16", - name: "x", - type: "int16", - }, - { - internalType: "int16", - name: "y", - type: "int16", - }, - { - internalType: "int16", - name: "z", - type: "int16", - }, - ], - internalType: "struct VoxelCoord", - name: "lowerSouthwestCorner", - type: "tuple", - }, - { - components: [ - { - internalType: "int16", - name: "x", - type: "int16", - }, - { - internalType: "int16", - name: "y", - type: "int16", - }, - { - internalType: "int16", - name: "z", - type: "int16", - }, - ], - internalType: "struct VoxelCoord", - name: "size", - type: "tuple", - }, - ], - name: "setMatchArea", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "uint256", - name: "numBlocksToEnd", - type: "uint256", - }, - ], - name: "startGame", - outputs: [], - stateMutability: "nonpayable", - type: "function", - }, - { - inputs: [ - { - internalType: "bytes4", - name: "interfaceId", - type: "bytes4", - }, - ], - name: "supportsInterface", - outputs: [ - { - internalType: "bool", - name: "", - type: "bool", - }, - ], - stateMutability: "view", - type: "function", - }, - ], - inheritedFunctions: { - onAfterCallSystem: "@latticexyz/world/src/IOptionalSystemHook.sol", - onBeforeCallSystem: "@latticexyz/world/src/IOptionalSystemHook.sol", - onRegisterHook: "@latticexyz/world/src/IOptionalSystemHook.sol", - onUnregisterHook: "@latticexyz/world/src/IOptionalSystemHook.sol", - supportsInterface: "@latticexyz/world/src/IOptionalSystemHook.sol", - }, - }, - }, } as const; export default deployedContracts satisfies GenericContractsDeclaration;