From ce07d43fdb5198d2d8992275cb13f58bc44f4b38 Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Wed, 8 Jan 2025 15:01:43 +0000 Subject: [PATCH] fix world ts issues --- packages/world/ts/actions/callFrom.ts | 38 +++++++++++++- packages/world/ts/encodeSystemCall.ts | 6 +-- packages/world/ts/encodeSystemCallFrom.ts | 4 +- packages/world/ts/encodeSystemCalls.ts | 4 +- packages/world/ts/encodeSystemCallsFrom.ts | 4 +- packages/world/ts/worldCallAbi.ts | 60 ++++++++++++++++++++++ 6 files changed, 104 insertions(+), 12 deletions(-) create mode 100644 packages/world/ts/worldCallAbi.ts diff --git a/packages/world/ts/actions/callFrom.ts b/packages/world/ts/actions/callFrom.ts index b095f69ccf..e3217e51e3 100644 --- a/packages/world/ts/actions/callFrom.ts +++ b/packages/world/ts/actions/callFrom.ts @@ -21,7 +21,6 @@ import { encodeKey, } from "@latticexyz/protocol-parser/internal"; import worldConfig from "../../mud.config"; -import IStoreReadAbi from "../../out/IStoreRead.sol/IStoreRead.abi.json"; type CallFromParameters = { worldAddress: Hex; @@ -134,7 +133,42 @@ async function retrieveSystemFunctionFromContract( const [staticData, encodedLengths, dynamicData] = await _readContract({ address: worldAddress, - abi: IStoreReadAbi, + abi: [ + { + type: "function", + name: "getRecord", + inputs: [ + { + name: "tableId", + type: "bytes32", + internalType: "ResourceId", + }, + { + name: "keyTuple", + type: "bytes32[]", + internalType: "bytes32[]", + }, + ], + outputs: [ + { + name: "staticData", + type: "bytes", + internalType: "bytes", + }, + { + name: "encodedLengths", + type: "bytes32", + internalType: "EncodedLengths", + }, + { + name: "dynamicData", + type: "bytes", + internalType: "bytes", + }, + ], + stateMutability: "view", + }, + ], functionName: "getRecord", args: [table.tableId, encodeKey(keySchema, { worldFunctionSelector })], }); diff --git a/packages/world/ts/encodeSystemCall.ts b/packages/world/ts/encodeSystemCall.ts index a6a36e735b..8de1bb4ea1 100644 --- a/packages/world/ts/encodeSystemCall.ts +++ b/packages/world/ts/encodeSystemCall.ts @@ -1,6 +1,6 @@ import { Abi, EncodeFunctionDataParameters, Hex, encodeFunctionData, type ContractFunctionName } from "viem"; import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"; -import IWorldCallAbi from "../out/IWorldKernel.sol/IWorldCall.abi.json"; +import { worldCallAbi } from "./worldCallAbi"; export type SystemCall> = EncodeFunctionDataParameters< abi, @@ -15,9 +15,7 @@ export function encodeSystemCall): AbiParametersToPrimitiveTypes< - ExtractAbiFunction["inputs"] -> { +}: SystemCall): AbiParametersToPrimitiveTypes["inputs"]> { return [ systemId, encodeFunctionData({ diff --git a/packages/world/ts/encodeSystemCallFrom.ts b/packages/world/ts/encodeSystemCallFrom.ts index 691675684e..39393dee21 100644 --- a/packages/world/ts/encodeSystemCallFrom.ts +++ b/packages/world/ts/encodeSystemCallFrom.ts @@ -1,7 +1,7 @@ import { Abi, EncodeFunctionDataParameters, encodeFunctionData, Address, type ContractFunctionName } from "viem"; import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"; -import IWorldCallAbi from "../out/IWorldKernel.sol/IWorldCall.abi.json"; import { SystemCall } from "./encodeSystemCall"; +import { worldCallAbi } from "./worldCallAbi"; export type SystemCallFrom> = SystemCall< abi, @@ -18,7 +18,7 @@ export function encodeSystemCallFrom): AbiParametersToPrimitiveTypes< - ExtractAbiFunction["inputs"] + ExtractAbiFunction["inputs"] > { return [ from, diff --git a/packages/world/ts/encodeSystemCalls.ts b/packages/world/ts/encodeSystemCalls.ts index f93301da43..cf8bb74a5f 100644 --- a/packages/world/ts/encodeSystemCalls.ts +++ b/packages/world/ts/encodeSystemCalls.ts @@ -1,12 +1,12 @@ import { Abi, type ContractFunctionName } from "viem"; -import IWorldCallAbi from "../out/IWorldKernel.sol/IWorldCall.abi.json"; import { SystemCall, encodeSystemCall } from "./encodeSystemCall"; import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"; +import { worldCallAbi } from "./worldCallAbi"; /** Encode system calls to be passed as arguments into `World.batchCall` */ export function encodeSystemCalls>( abi: abi, systemCalls: readonly Omit, "abi">[], -): AbiParametersToPrimitiveTypes["inputs"]>[] { +): AbiParametersToPrimitiveTypes["inputs"]>[] { return systemCalls.map((systemCall) => encodeSystemCall({ ...systemCall, abi } as SystemCall)); } diff --git a/packages/world/ts/encodeSystemCallsFrom.ts b/packages/world/ts/encodeSystemCallsFrom.ts index 0e0b40d0da..cc8e265d1f 100644 --- a/packages/world/ts/encodeSystemCallsFrom.ts +++ b/packages/world/ts/encodeSystemCallsFrom.ts @@ -1,14 +1,14 @@ import { Abi, Address, type ContractFunctionName } from "viem"; -import IWorldCallAbi from "../out/IWorldKernel.sol/IWorldCall.abi.json"; import { SystemCallFrom, encodeSystemCallFrom } from "./encodeSystemCallFrom"; import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype"; +import { worldCallAbi } from "./worldCallAbi"; /** Encode system calls to be passed as arguments into `World.batchCallFrom` */ export function encodeSystemCallsFrom>( abi: abi, from: Address, systemCalls: readonly Omit, "abi" | "from">[], -): AbiParametersToPrimitiveTypes["inputs"]>[] { +): AbiParametersToPrimitiveTypes["inputs"]>[] { return systemCalls.map((systemCall) => encodeSystemCallFrom({ ...systemCall, abi, from } as SystemCallFrom), ); diff --git a/packages/world/ts/worldCallAbi.ts b/packages/world/ts/worldCallAbi.ts new file mode 100644 index 0000000000..7fa386b2f4 --- /dev/null +++ b/packages/world/ts/worldCallAbi.ts @@ -0,0 +1,60 @@ +// TODO: replace this with abi-ts generated files once we move to +// generating full TS files rather than DTS + +export const worldCallAbi = [ + { + type: "function", + name: "call", + inputs: [ + { + name: "systemId", + type: "bytes32", + internalType: "ResourceId", + }, + { + name: "callData", + type: "bytes", + internalType: "bytes", + }, + ], + outputs: [ + { + name: "", + type: "bytes", + internalType: "bytes", + }, + ], + stateMutability: "payable", + }, + { + type: "function", + name: "callFrom", + inputs: [ + { + name: "delegator", + type: "address", + internalType: "address", + }, + { + name: "systemId", + type: "bytes32", + internalType: "ResourceId", + }, + { + name: "callData", + type: "bytes", + internalType: "bytes", + }, + ], + outputs: [ + { + name: "", + type: "bytes", + internalType: "bytes", + }, + ], + stateMutability: "payable", + }, +] as const; + +export type worldCallAbi = typeof worldCallAbi;