Skip to content

Commit 2d2aa08

Browse files
authored
fix(world): switch to TS for ABIs in utils (#3429)
1 parent a7625b9 commit 2d2aa08

7 files changed

Lines changed: 109 additions & 12 deletions

File tree

.changeset/little-tables-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@latticexyz/world": patch
3+
---
4+
5+
Moved TS utils over to using hardcoded ABIs instead of ones imported from `.abi.json` files to fix some internal type resolution issues.

packages/world/ts/actions/callFrom.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
encodeKey,
2222
} from "@latticexyz/protocol-parser/internal";
2323
import worldConfig from "../../mud.config";
24-
import IStoreReadAbi from "../../out/IStoreRead.sol/IStoreRead.abi.json";
2524

2625
type CallFromParameters = {
2726
worldAddress: Hex;
@@ -134,7 +133,42 @@ async function retrieveSystemFunctionFromContract(
134133

135134
const [staticData, encodedLengths, dynamicData] = await _readContract({
136135
address: worldAddress,
137-
abi: IStoreReadAbi,
136+
abi: [
137+
{
138+
type: "function",
139+
name: "getRecord",
140+
inputs: [
141+
{
142+
name: "tableId",
143+
type: "bytes32",
144+
internalType: "ResourceId",
145+
},
146+
{
147+
name: "keyTuple",
148+
type: "bytes32[]",
149+
internalType: "bytes32[]",
150+
},
151+
],
152+
outputs: [
153+
{
154+
name: "staticData",
155+
type: "bytes",
156+
internalType: "bytes",
157+
},
158+
{
159+
name: "encodedLengths",
160+
type: "bytes32",
161+
internalType: "EncodedLengths",
162+
},
163+
{
164+
name: "dynamicData",
165+
type: "bytes",
166+
internalType: "bytes",
167+
},
168+
],
169+
stateMutability: "view",
170+
},
171+
],
138172
functionName: "getRecord",
139173
args: [table.tableId, encodeKey(keySchema, { worldFunctionSelector })],
140174
});

packages/world/ts/encodeSystemCall.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Abi, EncodeFunctionDataParameters, Hex, encodeFunctionData, type ContractFunctionName } from "viem";
22
import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
3-
import IWorldCallAbi from "../out/IWorldKernel.sol/IWorldCall.abi.json";
3+
import { worldCallAbi } from "./worldCallAbi";
44

55
export type SystemCall<abi extends Abi, functionName extends ContractFunctionName<abi>> = EncodeFunctionDataParameters<
66
abi,
@@ -15,9 +15,7 @@ export function encodeSystemCall<abi extends Abi, functionName extends ContractF
1515
systemId,
1616
functionName,
1717
args,
18-
}: SystemCall<abi, functionName>): AbiParametersToPrimitiveTypes<
19-
ExtractAbiFunction<typeof IWorldCallAbi, "call">["inputs"]
20-
> {
18+
}: SystemCall<abi, functionName>): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "call">["inputs"]> {
2119
return [
2220
systemId,
2321
encodeFunctionData<abi, functionName>({

packages/world/ts/encodeSystemCallFrom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Abi, EncodeFunctionDataParameters, encodeFunctionData, Address, type ContractFunctionName } from "viem";
22
import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
3-
import IWorldCallAbi from "../out/IWorldKernel.sol/IWorldCall.abi.json";
43
import { SystemCall } from "./encodeSystemCall";
4+
import { worldCallAbi } from "./worldCallAbi";
55

66
export type SystemCallFrom<abi extends Abi, functionName extends ContractFunctionName<abi>> = SystemCall<
77
abi,
@@ -18,7 +18,7 @@ export function encodeSystemCallFrom<abi extends Abi, functionName extends Contr
1818
functionName,
1919
args,
2020
}: SystemCallFrom<abi, functionName>): AbiParametersToPrimitiveTypes<
21-
ExtractAbiFunction<typeof IWorldCallAbi, "callFrom">["inputs"]
21+
ExtractAbiFunction<worldCallAbi, "callFrom">["inputs"]
2222
> {
2323
return [
2424
from,
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Abi, type ContractFunctionName } from "viem";
2-
import IWorldCallAbi from "../out/IWorldKernel.sol/IWorldCall.abi.json";
32
import { SystemCall, encodeSystemCall } from "./encodeSystemCall";
43
import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
4+
import { worldCallAbi } from "./worldCallAbi";
55

66
/** Encode system calls to be passed as arguments into `World.batchCall` */
77
export function encodeSystemCalls<abi extends Abi, functionName extends ContractFunctionName<abi>>(
88
abi: abi,
99
systemCalls: readonly Omit<SystemCall<abi, functionName>, "abi">[],
10-
): AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof IWorldCallAbi, "call">["inputs"]>[] {
10+
): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "call">["inputs"]>[] {
1111
return systemCalls.map((systemCall) => encodeSystemCall({ ...systemCall, abi } as SystemCall<abi, functionName>));
1212
}

packages/world/ts/encodeSystemCallsFrom.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Abi, Address, type ContractFunctionName } from "viem";
2-
import IWorldCallAbi from "../out/IWorldKernel.sol/IWorldCall.abi.json";
32
import { SystemCallFrom, encodeSystemCallFrom } from "./encodeSystemCallFrom";
43
import type { AbiParametersToPrimitiveTypes, ExtractAbiFunction } from "abitype";
4+
import { worldCallAbi } from "./worldCallAbi";
55

66
/** Encode system calls to be passed as arguments into `World.batchCallFrom` */
77
export function encodeSystemCallsFrom<abi extends Abi, functionName extends ContractFunctionName<abi>>(
88
abi: abi,
99
from: Address,
1010
systemCalls: readonly Omit<SystemCallFrom<abi, functionName>, "abi" | "from">[],
11-
): AbiParametersToPrimitiveTypes<ExtractAbiFunction<typeof IWorldCallAbi, "callFrom">["inputs"]>[] {
11+
): AbiParametersToPrimitiveTypes<ExtractAbiFunction<worldCallAbi, "callFrom">["inputs"]>[] {
1212
return systemCalls.map((systemCall) =>
1313
encodeSystemCallFrom({ ...systemCall, abi, from } as SystemCallFrom<abi, functionName>),
1414
);

packages/world/ts/worldCallAbi.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// TODO: replace this with abi-ts generated files once we move to
2+
// generating full TS files rather than DTS
3+
4+
export const worldCallAbi = [
5+
{
6+
type: "function",
7+
name: "call",
8+
inputs: [
9+
{
10+
name: "systemId",
11+
type: "bytes32",
12+
internalType: "ResourceId",
13+
},
14+
{
15+
name: "callData",
16+
type: "bytes",
17+
internalType: "bytes",
18+
},
19+
],
20+
outputs: [
21+
{
22+
name: "",
23+
type: "bytes",
24+
internalType: "bytes",
25+
},
26+
],
27+
stateMutability: "payable",
28+
},
29+
{
30+
type: "function",
31+
name: "callFrom",
32+
inputs: [
33+
{
34+
name: "delegator",
35+
type: "address",
36+
internalType: "address",
37+
},
38+
{
39+
name: "systemId",
40+
type: "bytes32",
41+
internalType: "ResourceId",
42+
},
43+
{
44+
name: "callData",
45+
type: "bytes",
46+
internalType: "bytes",
47+
},
48+
],
49+
outputs: [
50+
{
51+
name: "",
52+
type: "bytes",
53+
internalType: "bytes",
54+
},
55+
],
56+
stateMutability: "payable",
57+
},
58+
] as const;
59+
60+
export type worldCallAbi = typeof worldCallAbi;

0 commit comments

Comments
 (0)