@latticexyz/protocol-parser 2.0.0-alpha.1.222
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +41 -0
- package/src/abiTypeToDefaultValue.ts +8 -0
- package/src/abiTypesToSchema.test.ts +28 -0
- package/src/abiTypesToSchema.ts +15 -0
- package/src/abiTypesToSchemaData.test.ts +14 -0
- package/src/abiTypesToSchemaData.ts +21 -0
- package/src/assertExhaustive.ts +3 -0
- package/src/common.ts +13 -0
- package/src/decodeDynamicField.test-d.ts +48 -0
- package/src/decodeDynamicField.test.ts +175 -0
- package/src/decodeDynamicField.ts +141 -0
- package/src/decodeKeyTuple.test.ts +34 -0
- package/src/decodeKeyTuple.ts +11 -0
- package/src/decodeStaticField.test-d.ts +40 -0
- package/src/decodeStaticField.test.ts +94 -0
- package/src/decodeStaticField.ts +145 -0
- package/src/dynamicAbiTypes.test-d.ts +66 -0
- package/src/dynamicAbiTypes.ts +131 -0
- package/src/errors.ts +64 -0
- package/src/hexToPackedCounter.test.ts +34 -0
- package/src/hexToPackedCounter.ts +31 -0
- package/src/hexToSchema.test.ts +40 -0
- package/src/hexToSchema.ts +41 -0
- package/src/hexToTableSchema.ts +14 -0
- package/src/index.ts +14 -0
- package/src/schemaAbiTypes.ts +211 -0
- package/src/staticAbiTypes.test-d.ts +58 -0
- package/src/staticAbiTypes.ts +221 -0
- package/src/utils.ts +5 -0
package/src/errors.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { MUDError } from "@latticexyz/common/errors";
|
|
2
|
+
import { Hex } from "viem";
|
|
3
|
+
import { StaticAbiType, staticAbiTypeToByteLength } from "./staticAbiTypes";
|
|
4
|
+
|
|
5
|
+
export class InvalidHexLengthError extends MUDError {
|
|
6
|
+
override name = "InvalidHexValueError";
|
|
7
|
+
constructor(value: Hex) {
|
|
8
|
+
super(`Hex value "${value}" is an odd length (${value.length - 2}). It must be an even length.`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class InvalidHexLengthForSchemaError extends MUDError {
|
|
13
|
+
override name = "InvalidHexLengthForSchemaError";
|
|
14
|
+
constructor(value: Hex) {
|
|
15
|
+
super(`Hex value "${value}" has length of ${value.length - 2}, but expected length of 64 for a schema.`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export class InvalidHexLengthForPackedCounterError extends MUDError {
|
|
20
|
+
override name = "InvalidHexLengthForPackedCounterError";
|
|
21
|
+
constructor(value: Hex) {
|
|
22
|
+
super(`Hex value "${value}" has length of ${value.length - 2}, but expected length of 64 for a packed counter.`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export class InvalidHexLengthForStaticFieldError extends MUDError {
|
|
27
|
+
override name = "InvalidHexLengthForStaticFieldError";
|
|
28
|
+
constructor(abiType: StaticAbiType, value: Hex) {
|
|
29
|
+
super(
|
|
30
|
+
`Hex value "${value}" has length of ${value.length - 2}, but expected length of ${
|
|
31
|
+
staticAbiTypeToByteLength[abiType] * 2
|
|
32
|
+
} for ${abiType} type.`
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class InvalidHexLengthForArrayFieldError extends MUDError {
|
|
38
|
+
override name = "InvalidHexLengthForArrayFieldError";
|
|
39
|
+
constructor(abiType: StaticAbiType, value: Hex) {
|
|
40
|
+
super(
|
|
41
|
+
`Hex value "${value}" has length of ${value.length - 2}, but expected a multiple of ${
|
|
42
|
+
staticAbiTypeToByteLength[abiType] * 2
|
|
43
|
+
} for ${abiType}[] type.`
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class SchemaStaticLengthMismatchError extends MUDError {
|
|
49
|
+
override name = "SchemaStaticLengthMismatchError";
|
|
50
|
+
constructor(schemaData: Hex, definedLength: number, summedLength: number) {
|
|
51
|
+
super(
|
|
52
|
+
`Schema "${schemaData}" static data length (${definedLength}) did not match the summed length of all static fields (${summedLength}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export class PackedCounterLengthMismatchError extends MUDError {
|
|
58
|
+
override name = "PackedCounterLengthMismatchError";
|
|
59
|
+
constructor(packedCounterData: Hex, definedLength: bigint, summedLength: bigint) {
|
|
60
|
+
super(
|
|
61
|
+
`PackedCounter "${packedCounterData}" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).`
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { hexToPackedCounter } from "./hexToPackedCounter";
|
|
3
|
+
|
|
4
|
+
describe("hexToPackedCounter", () => {
|
|
5
|
+
it("decodes hex data to packed counter", () => {
|
|
6
|
+
expect(hexToPackedCounter("0x0000000000008000000000200000000020000000004000000000000000000000"))
|
|
7
|
+
.toMatchInlineSnapshot(`
|
|
8
|
+
{
|
|
9
|
+
"fieldByteLengths": [
|
|
10
|
+
32,
|
|
11
|
+
32,
|
|
12
|
+
64,
|
|
13
|
+
0,
|
|
14
|
+
0,
|
|
15
|
+
],
|
|
16
|
+
"totalByteLength": 128n,
|
|
17
|
+
}
|
|
18
|
+
`);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("throws if schema hex data is not bytes32", () => {
|
|
22
|
+
expect(() => hexToPackedCounter("0x01234")).toThrowErrorMatchingInlineSnapshot(
|
|
23
|
+
'"Hex value \\"0x01234\\" has length of 5, but expected length of 64 for a packed counter."'
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("throws if packed counter total byte length doesn't match summed byte length of fields", () => {
|
|
28
|
+
expect(() =>
|
|
29
|
+
hexToPackedCounter("0x0000000000004000000000200000000020000000004000000000000000000000")
|
|
30
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
31
|
+
'"PackedCounter \\"0x0000000000004000000000200000000020000000004000000000000000000000\\" total bytes length (64) did not match the summed length of all field byte lengths (128)."'
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Hex, sliceHex } from "viem";
|
|
2
|
+
import { decodeStaticField } from "./decodeStaticField";
|
|
3
|
+
import { decodeDynamicField } from "./decodeDynamicField";
|
|
4
|
+
import { InvalidHexLengthForPackedCounterError, PackedCounterLengthMismatchError } from "./errors";
|
|
5
|
+
|
|
6
|
+
// Keep this logic in sync with PackedCounter.sol
|
|
7
|
+
|
|
8
|
+
// - First 7 bytes (uint56) are used for the total byte length of the dynamic data
|
|
9
|
+
// - The next 5 byte (uint40) sections are used for the byte length of each field, in the same order as the schema's dynamic fields
|
|
10
|
+
|
|
11
|
+
// We use byte lengths rather than item counts so that, on chain, we can slice without having to get the schema first (and thus the field lengths of each dynamic type)
|
|
12
|
+
|
|
13
|
+
export function hexToPackedCounter(data: Hex): {
|
|
14
|
+
totalByteLength: bigint;
|
|
15
|
+
fieldByteLengths: number[];
|
|
16
|
+
} {
|
|
17
|
+
if (data.length !== 66) {
|
|
18
|
+
throw new InvalidHexLengthForPackedCounterError(data);
|
|
19
|
+
}
|
|
20
|
+
const totalByteLength = decodeStaticField("uint56", sliceHex(data, 0, 7));
|
|
21
|
+
|
|
22
|
+
// TODO: use schema to make sure we only parse as many as we need (rather than zeroes at the end)?
|
|
23
|
+
const fieldByteLengths = decodeDynamicField("uint40[]", sliceHex(data, 7));
|
|
24
|
+
|
|
25
|
+
const summedLength = BigInt(fieldByteLengths.reduce((a, b) => a + b, 0));
|
|
26
|
+
if (summedLength !== totalByteLength) {
|
|
27
|
+
throw new PackedCounterLengthMismatchError(data, totalByteLength, summedLength);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { totalByteLength, fieldByteLengths };
|
|
31
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { hexToSchema } from "./hexToSchema";
|
|
3
|
+
|
|
4
|
+
describe("hexToSchema", () => {
|
|
5
|
+
it("decodes schema hex data to schema", () => {
|
|
6
|
+
expect(hexToSchema("0x0001010060000000000000000000000000000000000000000000000000000000")).toStrictEqual({
|
|
7
|
+
staticDataLength: 1,
|
|
8
|
+
staticFields: ["bool"],
|
|
9
|
+
dynamicFields: [],
|
|
10
|
+
isEmpty: false,
|
|
11
|
+
schemaData: "0x0001010060000000000000000000000000000000000000000000000000000000",
|
|
12
|
+
});
|
|
13
|
+
expect(hexToSchema("0x0001010160c20000000000000000000000000000000000000000000000000000")).toStrictEqual({
|
|
14
|
+
staticDataLength: 1,
|
|
15
|
+
staticFields: ["bool"],
|
|
16
|
+
dynamicFields: ["bool[]"],
|
|
17
|
+
isEmpty: false,
|
|
18
|
+
schemaData: "0x0001010160c20000000000000000000000000000000000000000000000000000",
|
|
19
|
+
});
|
|
20
|
+
expect(hexToSchema("0x002402045f2381c3c4c500000000000000000000000000000000000000000000")).toStrictEqual({
|
|
21
|
+
staticDataLength: 36,
|
|
22
|
+
staticFields: ["bytes32", "int32"],
|
|
23
|
+
dynamicFields: ["uint256[]", "address[]", "bytes", "string"],
|
|
24
|
+
isEmpty: false,
|
|
25
|
+
schemaData: "0x002402045f2381c3c4c500000000000000000000000000000000000000000000",
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("throws if schema hex data is not bytes32", () => {
|
|
30
|
+
expect(() => hexToSchema("0x002502045f2381c3c4c5")).toThrow(
|
|
31
|
+
'Hex value "0x002502045f2381c3c4c5" has length of 20, but expected length of 64 for a schema.'
|
|
32
|
+
);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("throws if schema static field lengths do not match", () => {
|
|
36
|
+
expect(() => hexToSchema("0x002502045f2381c3c4c500000000000000000000000000000000000000000000")).toThrow(
|
|
37
|
+
'Schema "0x002502045f2381c3c4c500000000000000000000000000000000000000000000" static data length (37) did not match the summed length of all static fields (36). Is `staticAbiTypeToByteLength` up to date with Solidity schema types?'
|
|
38
|
+
);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Hex, hexToNumber, sliceHex } from "viem";
|
|
2
|
+
import { Schema } from "./common";
|
|
3
|
+
import { StaticAbiType, staticAbiTypeToByteLength } from "./staticAbiTypes";
|
|
4
|
+
import { DynamicAbiType } from "./dynamicAbiTypes";
|
|
5
|
+
import { schemaAbiTypes } from "./schemaAbiTypes";
|
|
6
|
+
import { InvalidHexLengthForSchemaError, SchemaStaticLengthMismatchError } from "./errors";
|
|
7
|
+
|
|
8
|
+
export function hexToSchema(data: Hex): Schema {
|
|
9
|
+
if (data.length !== 66) {
|
|
10
|
+
throw new InvalidHexLengthForSchemaError(data);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const staticDataLength = hexToNumber(sliceHex(data, 0, 2));
|
|
14
|
+
const numStaticFields = hexToNumber(sliceHex(data, 2, 3));
|
|
15
|
+
const numDynamicFields = hexToNumber(sliceHex(data, 3, 4));
|
|
16
|
+
const staticFields: StaticAbiType[] = [];
|
|
17
|
+
const dynamicFields: DynamicAbiType[] = [];
|
|
18
|
+
|
|
19
|
+
for (let i = 4; i < 4 + numStaticFields; i++) {
|
|
20
|
+
const schemaTypeIndex = hexToNumber(sliceHex(data, i, i + 1));
|
|
21
|
+
staticFields.push(schemaAbiTypes[schemaTypeIndex] as StaticAbiType);
|
|
22
|
+
}
|
|
23
|
+
for (let i = 4 + numStaticFields; i < 4 + numStaticFields + numDynamicFields; i++) {
|
|
24
|
+
const schemaTypeIndex = hexToNumber(sliceHex(data, i, i + 1));
|
|
25
|
+
dynamicFields.push(schemaAbiTypes[schemaTypeIndex] as DynamicAbiType);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// validate static data length
|
|
29
|
+
const actualStaticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);
|
|
30
|
+
if (actualStaticDataLength !== staticDataLength) {
|
|
31
|
+
throw new SchemaStaticLengthMismatchError(data, staticDataLength, actualStaticDataLength);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
staticDataLength,
|
|
36
|
+
staticFields,
|
|
37
|
+
dynamicFields,
|
|
38
|
+
isEmpty: data === "0x",
|
|
39
|
+
schemaData: data,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Hex, sliceHex } from "viem";
|
|
2
|
+
import { TableSchema } from "./common";
|
|
3
|
+
import { hexToSchema } from "./hexToSchema";
|
|
4
|
+
|
|
5
|
+
export function hexToTableSchema(data: Hex): TableSchema {
|
|
6
|
+
const valueSchema = hexToSchema(sliceHex(data, 0, 32));
|
|
7
|
+
const keySchema = hexToSchema(sliceHex(data, 32, 64));
|
|
8
|
+
return {
|
|
9
|
+
keySchema,
|
|
10
|
+
valueSchema,
|
|
11
|
+
isEmpty: data === "0x",
|
|
12
|
+
schemaData: data,
|
|
13
|
+
};
|
|
14
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from "./abiTypesToSchema";
|
|
2
|
+
export * from "./abiTypesToSchemaData";
|
|
3
|
+
export * from "./abiTypeToDefaultValue";
|
|
4
|
+
export * from "./common";
|
|
5
|
+
export * from "./decodeDynamicField";
|
|
6
|
+
export * from "./decodeKeyTuple";
|
|
7
|
+
export * from "./decodeStaticField";
|
|
8
|
+
export * from "./dynamicAbiTypes";
|
|
9
|
+
export * from "./errors";
|
|
10
|
+
export * from "./hexToPackedCounter";
|
|
11
|
+
export * from "./hexToSchema";
|
|
12
|
+
export * from "./hexToTableSchema";
|
|
13
|
+
export * from "./schemaAbiTypes";
|
|
14
|
+
export * from "./staticAbiTypes";
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { AbiType } from "abitype";
|
|
2
|
+
import { TupleSplit } from "./utils";
|
|
3
|
+
|
|
4
|
+
// Keep this array in sync with SchemaType.sol enum
|
|
5
|
+
|
|
6
|
+
export const schemaAbiTypes = [
|
|
7
|
+
"uint8",
|
|
8
|
+
"uint16",
|
|
9
|
+
"uint24",
|
|
10
|
+
"uint32",
|
|
11
|
+
"uint40",
|
|
12
|
+
"uint48",
|
|
13
|
+
"uint56",
|
|
14
|
+
"uint64",
|
|
15
|
+
"uint72",
|
|
16
|
+
"uint80",
|
|
17
|
+
"uint88",
|
|
18
|
+
"uint96",
|
|
19
|
+
"uint104",
|
|
20
|
+
"uint112",
|
|
21
|
+
"uint120",
|
|
22
|
+
"uint128",
|
|
23
|
+
"uint136",
|
|
24
|
+
"uint144",
|
|
25
|
+
"uint152",
|
|
26
|
+
"uint160",
|
|
27
|
+
"uint168",
|
|
28
|
+
"uint176",
|
|
29
|
+
"uint184",
|
|
30
|
+
"uint192",
|
|
31
|
+
"uint200",
|
|
32
|
+
"uint208",
|
|
33
|
+
"uint216",
|
|
34
|
+
"uint224",
|
|
35
|
+
"uint232",
|
|
36
|
+
"uint240",
|
|
37
|
+
"uint248",
|
|
38
|
+
"uint256",
|
|
39
|
+
"int8",
|
|
40
|
+
"int16",
|
|
41
|
+
"int24",
|
|
42
|
+
"int32",
|
|
43
|
+
"int40",
|
|
44
|
+
"int48",
|
|
45
|
+
"int56",
|
|
46
|
+
"int64",
|
|
47
|
+
"int72",
|
|
48
|
+
"int80",
|
|
49
|
+
"int88",
|
|
50
|
+
"int96",
|
|
51
|
+
"int104",
|
|
52
|
+
"int112",
|
|
53
|
+
"int120",
|
|
54
|
+
"int128",
|
|
55
|
+
"int136",
|
|
56
|
+
"int144",
|
|
57
|
+
"int152",
|
|
58
|
+
"int160",
|
|
59
|
+
"int168",
|
|
60
|
+
"int176",
|
|
61
|
+
"int184",
|
|
62
|
+
"int192",
|
|
63
|
+
"int200",
|
|
64
|
+
"int208",
|
|
65
|
+
"int216",
|
|
66
|
+
"int224",
|
|
67
|
+
"int232",
|
|
68
|
+
"int240",
|
|
69
|
+
"int248",
|
|
70
|
+
"int256",
|
|
71
|
+
"bytes1",
|
|
72
|
+
"bytes2",
|
|
73
|
+
"bytes3",
|
|
74
|
+
"bytes4",
|
|
75
|
+
"bytes5",
|
|
76
|
+
"bytes6",
|
|
77
|
+
"bytes7",
|
|
78
|
+
"bytes8",
|
|
79
|
+
"bytes9",
|
|
80
|
+
"bytes10",
|
|
81
|
+
"bytes11",
|
|
82
|
+
"bytes12",
|
|
83
|
+
"bytes13",
|
|
84
|
+
"bytes14",
|
|
85
|
+
"bytes15",
|
|
86
|
+
"bytes16",
|
|
87
|
+
"bytes17",
|
|
88
|
+
"bytes18",
|
|
89
|
+
"bytes19",
|
|
90
|
+
"bytes20",
|
|
91
|
+
"bytes21",
|
|
92
|
+
"bytes22",
|
|
93
|
+
"bytes23",
|
|
94
|
+
"bytes24",
|
|
95
|
+
"bytes25",
|
|
96
|
+
"bytes26",
|
|
97
|
+
"bytes27",
|
|
98
|
+
"bytes28",
|
|
99
|
+
"bytes29",
|
|
100
|
+
"bytes30",
|
|
101
|
+
"bytes31",
|
|
102
|
+
"bytes32",
|
|
103
|
+
"bool",
|
|
104
|
+
"address",
|
|
105
|
+
"uint8[]",
|
|
106
|
+
"uint16[]",
|
|
107
|
+
"uint24[]",
|
|
108
|
+
"uint32[]",
|
|
109
|
+
"uint40[]",
|
|
110
|
+
"uint48[]",
|
|
111
|
+
"uint56[]",
|
|
112
|
+
"uint64[]",
|
|
113
|
+
"uint72[]",
|
|
114
|
+
"uint80[]",
|
|
115
|
+
"uint88[]",
|
|
116
|
+
"uint96[]",
|
|
117
|
+
"uint104[]",
|
|
118
|
+
"uint112[]",
|
|
119
|
+
"uint120[]",
|
|
120
|
+
"uint128[]",
|
|
121
|
+
"uint136[]",
|
|
122
|
+
"uint144[]",
|
|
123
|
+
"uint152[]",
|
|
124
|
+
"uint160[]",
|
|
125
|
+
"uint168[]",
|
|
126
|
+
"uint176[]",
|
|
127
|
+
"uint184[]",
|
|
128
|
+
"uint192[]",
|
|
129
|
+
"uint200[]",
|
|
130
|
+
"uint208[]",
|
|
131
|
+
"uint216[]",
|
|
132
|
+
"uint224[]",
|
|
133
|
+
"uint232[]",
|
|
134
|
+
"uint240[]",
|
|
135
|
+
"uint248[]",
|
|
136
|
+
"uint256[]",
|
|
137
|
+
"int8[]",
|
|
138
|
+
"int16[]",
|
|
139
|
+
"int24[]",
|
|
140
|
+
"int32[]",
|
|
141
|
+
"int40[]",
|
|
142
|
+
"int48[]",
|
|
143
|
+
"int56[]",
|
|
144
|
+
"int64[]",
|
|
145
|
+
"int72[]",
|
|
146
|
+
"int80[]",
|
|
147
|
+
"int88[]",
|
|
148
|
+
"int96[]",
|
|
149
|
+
"int104[]",
|
|
150
|
+
"int112[]",
|
|
151
|
+
"int120[]",
|
|
152
|
+
"int128[]",
|
|
153
|
+
"int136[]",
|
|
154
|
+
"int144[]",
|
|
155
|
+
"int152[]",
|
|
156
|
+
"int160[]",
|
|
157
|
+
"int168[]",
|
|
158
|
+
"int176[]",
|
|
159
|
+
"int184[]",
|
|
160
|
+
"int192[]",
|
|
161
|
+
"int200[]",
|
|
162
|
+
"int208[]",
|
|
163
|
+
"int216[]",
|
|
164
|
+
"int224[]",
|
|
165
|
+
"int232[]",
|
|
166
|
+
"int240[]",
|
|
167
|
+
"int248[]",
|
|
168
|
+
"int256[]",
|
|
169
|
+
"bytes1[]",
|
|
170
|
+
"bytes2[]",
|
|
171
|
+
"bytes3[]",
|
|
172
|
+
"bytes4[]",
|
|
173
|
+
"bytes5[]",
|
|
174
|
+
"bytes6[]",
|
|
175
|
+
"bytes7[]",
|
|
176
|
+
"bytes8[]",
|
|
177
|
+
"bytes9[]",
|
|
178
|
+
"bytes10[]",
|
|
179
|
+
"bytes11[]",
|
|
180
|
+
"bytes12[]",
|
|
181
|
+
"bytes13[]",
|
|
182
|
+
"bytes14[]",
|
|
183
|
+
"bytes15[]",
|
|
184
|
+
"bytes16[]",
|
|
185
|
+
"bytes17[]",
|
|
186
|
+
"bytes18[]",
|
|
187
|
+
"bytes19[]",
|
|
188
|
+
"bytes20[]",
|
|
189
|
+
"bytes21[]",
|
|
190
|
+
"bytes22[]",
|
|
191
|
+
"bytes23[]",
|
|
192
|
+
"bytes24[]",
|
|
193
|
+
"bytes25[]",
|
|
194
|
+
"bytes26[]",
|
|
195
|
+
"bytes27[]",
|
|
196
|
+
"bytes28[]",
|
|
197
|
+
"bytes29[]",
|
|
198
|
+
"bytes30[]",
|
|
199
|
+
"bytes31[]",
|
|
200
|
+
"bytes32[]",
|
|
201
|
+
"bool[]",
|
|
202
|
+
"address[]",
|
|
203
|
+
"bytes",
|
|
204
|
+
"string",
|
|
205
|
+
] as const satisfies readonly AbiType[];
|
|
206
|
+
|
|
207
|
+
export type SchemaAbiType = (typeof schemaAbiTypes)[number];
|
|
208
|
+
|
|
209
|
+
// These are defined here to keep the index position (98) consolidated, since we use it both in runtime code and type definition
|
|
210
|
+
export const staticAbiTypes = schemaAbiTypes.slice(0, 98) as any as TupleSplit<typeof schemaAbiTypes, 98>[0];
|
|
211
|
+
export const dynamicAbiTypes = schemaAbiTypes.slice(98) as any as TupleSplit<typeof schemaAbiTypes, 98>[1];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { describe, expectTypeOf, it } from "vitest";
|
|
2
|
+
import { StaticAbiTypeToPrimitiveType } from "./staticAbiTypes";
|
|
3
|
+
import { Hex } from "viem";
|
|
4
|
+
|
|
5
|
+
describe("StaticAbiTypeToPrimitiveType", () => {
|
|
6
|
+
it("maps uint8 to number", () => {
|
|
7
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint8">>().toBeNumber();
|
|
8
|
+
});
|
|
9
|
+
it("maps uint32 to number", () => {
|
|
10
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint32">>().toBeNumber();
|
|
11
|
+
});
|
|
12
|
+
it("maps uint48 to number", () => {
|
|
13
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint48">>().toBeNumber();
|
|
14
|
+
});
|
|
15
|
+
it("maps uint56 to number", () => {
|
|
16
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint56">>().toMatchTypeOf<bigint>();
|
|
17
|
+
});
|
|
18
|
+
it("maps uint256 to number", () => {
|
|
19
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"uint256">>().toMatchTypeOf<bigint>();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("maps int8 to number", () => {
|
|
23
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int8">>().toBeNumber();
|
|
24
|
+
});
|
|
25
|
+
it("maps int32 to number", () => {
|
|
26
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int32">>().toBeNumber();
|
|
27
|
+
});
|
|
28
|
+
it("maps int48 to number", () => {
|
|
29
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int48">>().toBeNumber();
|
|
30
|
+
});
|
|
31
|
+
it("maps int56 to number", () => {
|
|
32
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int56">>().toMatchTypeOf<bigint>();
|
|
33
|
+
});
|
|
34
|
+
it("maps int256 to number", () => {
|
|
35
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"int256">>().toMatchTypeOf<bigint>();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("maps bytes1 to hex", () => {
|
|
39
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes1">>().toMatchTypeOf<Hex>();
|
|
40
|
+
});
|
|
41
|
+
it("maps bytes2 to hex", () => {
|
|
42
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes2">>().toMatchTypeOf<Hex>();
|
|
43
|
+
});
|
|
44
|
+
it("maps bytes8 to hex", () => {
|
|
45
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes8">>().toMatchTypeOf<Hex>();
|
|
46
|
+
});
|
|
47
|
+
it("maps bytes32 to hex", () => {
|
|
48
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes32">>().toMatchTypeOf<Hex>();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("maps bool to boolean", () => {
|
|
52
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"bool">>().toBeBoolean();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("maps address to hex", () => {
|
|
56
|
+
expectTypeOf<StaticAbiTypeToPrimitiveType<"address">>().toMatchTypeOf<Hex>();
|
|
57
|
+
});
|
|
58
|
+
});
|