@latticexyz/schema-type 2.0.12-main-2f436a5c → 2.0.12-type-resolutions-effc7ab1

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.
Files changed (37) hide show
  1. package/cache/solidity-files-cache.json +1 -0
  2. package/package.json +3 -3
  3. package/src/solidity/SchemaType.sol +0 -230
  4. package/src/typescript/arrayAbiTypes.test.ts +0 -78
  5. package/src/typescript/arrayAbiTypes.ts +0 -47
  6. package/src/typescript/deprecated/SchemaType.ts +0 -202
  7. package/src/typescript/deprecated/mappings/AbiTypeToDefaultValue.ts +0 -208
  8. package/src/typescript/deprecated/mappings/AbiTypeToPrimitiveType.ts +0 -12
  9. package/src/typescript/deprecated/mappings/AbiTypeToSchemaType.ts +0 -6
  10. package/src/typescript/deprecated/mappings/SchemaTypeArrayToElement.ts +0 -109
  11. package/src/typescript/deprecated/mappings/SchemaTypeToAbiType.ts +0 -210
  12. package/src/typescript/deprecated/mappings/SchemaTypeToPrimitiveType.ts +0 -9
  13. package/src/typescript/deprecated/mappings/index.ts +0 -5
  14. package/src/typescript/deprecated/mappings/types.test-d.ts +0 -233
  15. package/src/typescript/deprecated/types/AbiTypes.ts +0 -5
  16. package/src/typescript/deprecated/types/ArraySchemaType.ts +0 -101
  17. package/src/typescript/deprecated/types/DynamicSchemaType.ts +0 -4
  18. package/src/typescript/deprecated/types/StaticAbiTypes.ts +0 -10
  19. package/src/typescript/deprecated/types/StaticArray.ts +0 -3
  20. package/src/typescript/deprecated/types/StaticSchemaType.ts +0 -4
  21. package/src/typescript/deprecated/types/index.ts +0 -8
  22. package/src/typescript/deprecated/utils/encodeSchema.ts +0 -48
  23. package/src/typescript/deprecated/utils/getAbiTypeDefaultValue.ts +0 -11
  24. package/src/typescript/deprecated/utils/getStaticByteLength.ts +0 -25
  25. package/src/typescript/deprecated/utils/index.ts +0 -3
  26. package/src/typescript/dynamicAbiTypes.test-d.ts +0 -66
  27. package/src/typescript/dynamicAbiTypes.ts +0 -128
  28. package/src/typescript/exports/deprecated.ts +0 -4
  29. package/src/typescript/exports/index.ts +0 -5
  30. package/src/typescript/exports/internal.ts +0 -6
  31. package/src/typescript/schemaAbiTypeToDefaultValue.ts +0 -8
  32. package/src/typescript/schemaAbiTypeToPrimitiveType.ts +0 -7
  33. package/src/typescript/schemaAbiTypes.test.ts +0 -17
  34. package/src/typescript/schemaAbiTypes.ts +0 -219
  35. package/src/typescript/staticAbiTypes.test-d.ts +0 -58
  36. package/src/typescript/staticAbiTypes.ts +0 -223
  37. package/src/typescript/utils.ts +0 -25
@@ -1,233 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
- import { describe } from "vitest";
3
- import { SchemaTypeToPrimitiveTypeLookup } from "./SchemaTypeToPrimitiveType";
4
- import { SchemaType } from "../SchemaType";
5
- import { AbiTypeToDefaultValue } from "./AbiTypeToDefaultValue";
6
- import { AbiTypeToPrimitiveType } from "./AbiTypeToPrimitiveType";
7
-
8
- describe("mapping between schema type, abi type and primitive types", () => {
9
- const expectSchemaTypeToPrimitiveType = (_: TestSchemaTypeToPrimitiveLookup) => void 0;
10
-
11
- // Expect argument of type `SchemaTypeToPrimitiveLookup` to be equivalent to `TestSchemaTypeToPrimitiveTypeLookup`
12
- const input = {} as SchemaTypeToPrimitiveTypeLookup;
13
- expectSchemaTypeToPrimitiveType(input);
14
- });
15
-
16
- describe("default values", () => {
17
- const expectAbiTypeToPrimitiveValues = (_: {
18
- [key in keyof typeof AbiTypeToDefaultValue]: AbiTypeToPrimitiveType<key>;
19
- }) => void 0;
20
-
21
- // Expect argument of type `AbiTypeToDefaultValue` to be equivalent to the expected primitive values
22
- expectAbiTypeToPrimitiveValues(AbiTypeToDefaultValue);
23
- });
24
-
25
- // Manual mapping from schema type to primitive type for testing purposes
26
- export type TestSchemaTypeToPrimitiveLookup = {
27
- [SchemaType.UINT8]: number;
28
- [SchemaType.UINT16]: number;
29
- [SchemaType.UINT24]: number;
30
- [SchemaType.UINT32]: number;
31
- [SchemaType.UINT40]: number;
32
- [SchemaType.UINT48]: number;
33
- [SchemaType.UINT56]: bigint;
34
- [SchemaType.UINT64]: bigint;
35
- [SchemaType.UINT72]: bigint;
36
- [SchemaType.UINT80]: bigint;
37
- [SchemaType.UINT88]: bigint;
38
- [SchemaType.UINT96]: bigint;
39
- [SchemaType.UINT104]: bigint;
40
- [SchemaType.UINT112]: bigint;
41
- [SchemaType.UINT120]: bigint;
42
- [SchemaType.UINT128]: bigint;
43
- [SchemaType.UINT136]: bigint;
44
- [SchemaType.UINT144]: bigint;
45
- [SchemaType.UINT152]: bigint;
46
- [SchemaType.UINT160]: bigint;
47
- [SchemaType.UINT168]: bigint;
48
- [SchemaType.UINT176]: bigint;
49
- [SchemaType.UINT184]: bigint;
50
- [SchemaType.UINT192]: bigint;
51
- [SchemaType.UINT200]: bigint;
52
- [SchemaType.UINT208]: bigint;
53
- [SchemaType.UINT216]: bigint;
54
- [SchemaType.UINT224]: bigint;
55
- [SchemaType.UINT232]: bigint;
56
- [SchemaType.UINT240]: bigint;
57
- [SchemaType.UINT248]: bigint;
58
- [SchemaType.UINT256]: bigint;
59
-
60
- [SchemaType.INT8]: number;
61
- [SchemaType.INT16]: number;
62
- [SchemaType.INT24]: number;
63
- [SchemaType.INT32]: number;
64
- [SchemaType.INT40]: number;
65
- [SchemaType.INT48]: number;
66
- [SchemaType.INT56]: bigint;
67
- [SchemaType.INT64]: bigint;
68
- [SchemaType.INT72]: bigint;
69
- [SchemaType.INT80]: bigint;
70
- [SchemaType.INT88]: bigint;
71
- [SchemaType.INT96]: bigint;
72
- [SchemaType.INT104]: bigint;
73
- [SchemaType.INT112]: bigint;
74
- [SchemaType.INT120]: bigint;
75
- [SchemaType.INT128]: bigint;
76
- [SchemaType.INT136]: bigint;
77
- [SchemaType.INT144]: bigint;
78
- [SchemaType.INT152]: bigint;
79
- [SchemaType.INT160]: bigint;
80
- [SchemaType.INT168]: bigint;
81
- [SchemaType.INT176]: bigint;
82
- [SchemaType.INT184]: bigint;
83
- [SchemaType.INT192]: bigint;
84
- [SchemaType.INT200]: bigint;
85
- [SchemaType.INT208]: bigint;
86
- [SchemaType.INT216]: bigint;
87
- [SchemaType.INT224]: bigint;
88
- [SchemaType.INT232]: bigint;
89
- [SchemaType.INT240]: bigint;
90
- [SchemaType.INT248]: bigint;
91
- [SchemaType.INT256]: bigint;
92
-
93
- [SchemaType.BYTES1]: string;
94
- [SchemaType.BYTES2]: string;
95
- [SchemaType.BYTES3]: string;
96
- [SchemaType.BYTES4]: string;
97
- [SchemaType.BYTES5]: string;
98
- [SchemaType.BYTES6]: string;
99
- [SchemaType.BYTES7]: string;
100
- [SchemaType.BYTES8]: string;
101
- [SchemaType.BYTES9]: string;
102
- [SchemaType.BYTES10]: string;
103
- [SchemaType.BYTES11]: string;
104
- [SchemaType.BYTES12]: string;
105
- [SchemaType.BYTES13]: string;
106
- [SchemaType.BYTES14]: string;
107
- [SchemaType.BYTES15]: string;
108
- [SchemaType.BYTES16]: string;
109
- [SchemaType.BYTES17]: string;
110
- [SchemaType.BYTES18]: string;
111
- [SchemaType.BYTES19]: string;
112
- [SchemaType.BYTES20]: string;
113
- [SchemaType.BYTES21]: string;
114
- [SchemaType.BYTES22]: string;
115
- [SchemaType.BYTES23]: string;
116
- [SchemaType.BYTES24]: string;
117
- [SchemaType.BYTES25]: string;
118
- [SchemaType.BYTES26]: string;
119
- [SchemaType.BYTES27]: string;
120
- [SchemaType.BYTES28]: string;
121
- [SchemaType.BYTES29]: string;
122
- [SchemaType.BYTES30]: string;
123
- [SchemaType.BYTES31]: string;
124
- [SchemaType.BYTES32]: string;
125
-
126
- [SchemaType.BOOL]: boolean;
127
- [SchemaType.ADDRESS]: string;
128
-
129
- [SchemaType.UINT8_ARRAY]: number[];
130
- [SchemaType.UINT16_ARRAY]: number[];
131
- [SchemaType.UINT24_ARRAY]: number[];
132
- [SchemaType.UINT32_ARRAY]: number[];
133
- [SchemaType.UINT40_ARRAY]: number[];
134
- [SchemaType.UINT48_ARRAY]: number[];
135
- [SchemaType.UINT56_ARRAY]: bigint[];
136
- [SchemaType.UINT64_ARRAY]: bigint[];
137
- [SchemaType.UINT72_ARRAY]: bigint[];
138
- [SchemaType.UINT80_ARRAY]: bigint[];
139
- [SchemaType.UINT88_ARRAY]: bigint[];
140
- [SchemaType.UINT96_ARRAY]: bigint[];
141
- [SchemaType.UINT104_ARRAY]: bigint[];
142
- [SchemaType.UINT112_ARRAY]: bigint[];
143
- [SchemaType.UINT120_ARRAY]: bigint[];
144
- [SchemaType.UINT128_ARRAY]: bigint[];
145
- [SchemaType.UINT136_ARRAY]: bigint[];
146
- [SchemaType.UINT144_ARRAY]: bigint[];
147
- [SchemaType.UINT152_ARRAY]: bigint[];
148
- [SchemaType.UINT160_ARRAY]: bigint[];
149
- [SchemaType.UINT168_ARRAY]: bigint[];
150
- [SchemaType.UINT176_ARRAY]: bigint[];
151
- [SchemaType.UINT184_ARRAY]: bigint[];
152
- [SchemaType.UINT192_ARRAY]: bigint[];
153
- [SchemaType.UINT200_ARRAY]: bigint[];
154
- [SchemaType.UINT208_ARRAY]: bigint[];
155
- [SchemaType.UINT216_ARRAY]: bigint[];
156
- [SchemaType.UINT224_ARRAY]: bigint[];
157
- [SchemaType.UINT232_ARRAY]: bigint[];
158
- [SchemaType.UINT240_ARRAY]: bigint[];
159
- [SchemaType.UINT248_ARRAY]: bigint[];
160
- [SchemaType.UINT256_ARRAY]: bigint[];
161
-
162
- [SchemaType.INT8_ARRAY]: number[];
163
- [SchemaType.INT16_ARRAY]: number[];
164
- [SchemaType.INT24_ARRAY]: number[];
165
- [SchemaType.INT32_ARRAY]: number[];
166
- [SchemaType.INT40_ARRAY]: number[];
167
- [SchemaType.INT48_ARRAY]: number[];
168
- [SchemaType.INT56_ARRAY]: bigint[];
169
- [SchemaType.INT64_ARRAY]: bigint[];
170
- [SchemaType.INT72_ARRAY]: bigint[];
171
- [SchemaType.INT80_ARRAY]: bigint[];
172
- [SchemaType.INT88_ARRAY]: bigint[];
173
- [SchemaType.INT96_ARRAY]: bigint[];
174
- [SchemaType.INT104_ARRAY]: bigint[];
175
- [SchemaType.INT112_ARRAY]: bigint[];
176
- [SchemaType.INT120_ARRAY]: bigint[];
177
- [SchemaType.INT128_ARRAY]: bigint[];
178
- [SchemaType.INT136_ARRAY]: bigint[];
179
- [SchemaType.INT144_ARRAY]: bigint[];
180
- [SchemaType.INT152_ARRAY]: bigint[];
181
- [SchemaType.INT160_ARRAY]: bigint[];
182
- [SchemaType.INT168_ARRAY]: bigint[];
183
- [SchemaType.INT176_ARRAY]: bigint[];
184
- [SchemaType.INT184_ARRAY]: bigint[];
185
- [SchemaType.INT192_ARRAY]: bigint[];
186
- [SchemaType.INT200_ARRAY]: bigint[];
187
- [SchemaType.INT208_ARRAY]: bigint[];
188
- [SchemaType.INT216_ARRAY]: bigint[];
189
- [SchemaType.INT224_ARRAY]: bigint[];
190
- [SchemaType.INT232_ARRAY]: bigint[];
191
- [SchemaType.INT240_ARRAY]: bigint[];
192
- [SchemaType.INT248_ARRAY]: bigint[];
193
- [SchemaType.INT256_ARRAY]: bigint[];
194
-
195
- [SchemaType.BYTES1_ARRAY]: string[];
196
- [SchemaType.BYTES2_ARRAY]: string[];
197
- [SchemaType.BYTES3_ARRAY]: string[];
198
- [SchemaType.BYTES4_ARRAY]: string[];
199
- [SchemaType.BYTES5_ARRAY]: string[];
200
- [SchemaType.BYTES6_ARRAY]: string[];
201
- [SchemaType.BYTES7_ARRAY]: string[];
202
- [SchemaType.BYTES8_ARRAY]: string[];
203
- [SchemaType.BYTES9_ARRAY]: string[];
204
- [SchemaType.BYTES10_ARRAY]: string[];
205
- [SchemaType.BYTES11_ARRAY]: string[];
206
- [SchemaType.BYTES12_ARRAY]: string[];
207
- [SchemaType.BYTES13_ARRAY]: string[];
208
- [SchemaType.BYTES14_ARRAY]: string[];
209
- [SchemaType.BYTES15_ARRAY]: string[];
210
- [SchemaType.BYTES16_ARRAY]: string[];
211
- [SchemaType.BYTES17_ARRAY]: string[];
212
- [SchemaType.BYTES18_ARRAY]: string[];
213
- [SchemaType.BYTES19_ARRAY]: string[];
214
- [SchemaType.BYTES20_ARRAY]: string[];
215
- [SchemaType.BYTES21_ARRAY]: string[];
216
- [SchemaType.BYTES22_ARRAY]: string[];
217
- [SchemaType.BYTES23_ARRAY]: string[];
218
- [SchemaType.BYTES24_ARRAY]: string[];
219
- [SchemaType.BYTES25_ARRAY]: string[];
220
- [SchemaType.BYTES26_ARRAY]: string[];
221
- [SchemaType.BYTES27_ARRAY]: string[];
222
- [SchemaType.BYTES28_ARRAY]: string[];
223
- [SchemaType.BYTES29_ARRAY]: string[];
224
- [SchemaType.BYTES30_ARRAY]: string[];
225
- [SchemaType.BYTES31_ARRAY]: string[];
226
- [SchemaType.BYTES32_ARRAY]: string[];
227
-
228
- [SchemaType.BOOL_ARRAY]: boolean[];
229
- [SchemaType.ADDRESS_ARRAY]: string[];
230
-
231
- [SchemaType.BYTES]: string;
232
- [SchemaType.STRING]: string;
233
- };
@@ -1,5 +0,0 @@
1
- import { SchemaType } from "../SchemaType";
2
- import { SchemaTypeToAbiType } from "../mappings/SchemaTypeToAbiType";
3
-
4
- export type AbiType = (typeof SchemaTypeToAbiType)[SchemaType];
5
- export const AbiTypes = Object.values(SchemaTypeToAbiType);
@@ -1,101 +0,0 @@
1
- import { SchemaType } from "../SchemaType";
2
-
3
- export type ArraySchemaType =
4
- | SchemaType.UINT8_ARRAY
5
- | SchemaType.UINT16_ARRAY
6
- | SchemaType.UINT24_ARRAY
7
- | SchemaType.UINT32_ARRAY
8
- | SchemaType.UINT40_ARRAY
9
- | SchemaType.UINT48_ARRAY
10
- | SchemaType.UINT56_ARRAY
11
- | SchemaType.UINT64_ARRAY
12
- | SchemaType.UINT72_ARRAY
13
- | SchemaType.UINT80_ARRAY
14
- | SchemaType.UINT88_ARRAY
15
- | SchemaType.UINT96_ARRAY
16
- | SchemaType.UINT104_ARRAY
17
- | SchemaType.UINT112_ARRAY
18
- | SchemaType.UINT120_ARRAY
19
- | SchemaType.UINT128_ARRAY
20
- | SchemaType.UINT136_ARRAY
21
- | SchemaType.UINT144_ARRAY
22
- | SchemaType.UINT152_ARRAY
23
- | SchemaType.UINT160_ARRAY
24
- | SchemaType.UINT168_ARRAY
25
- | SchemaType.UINT176_ARRAY
26
- | SchemaType.UINT184_ARRAY
27
- | SchemaType.UINT192_ARRAY
28
- | SchemaType.UINT200_ARRAY
29
- | SchemaType.UINT208_ARRAY
30
- | SchemaType.UINT216_ARRAY
31
- | SchemaType.UINT224_ARRAY
32
- | SchemaType.UINT232_ARRAY
33
- | SchemaType.UINT240_ARRAY
34
- | SchemaType.UINT248_ARRAY
35
- | SchemaType.UINT256_ARRAY
36
- | SchemaType.INT8_ARRAY
37
- | SchemaType.INT16_ARRAY
38
- | SchemaType.INT24_ARRAY
39
- | SchemaType.INT32_ARRAY
40
- | SchemaType.INT40_ARRAY
41
- | SchemaType.INT48_ARRAY
42
- | SchemaType.INT56_ARRAY
43
- | SchemaType.INT64_ARRAY
44
- | SchemaType.INT72_ARRAY
45
- | SchemaType.INT80_ARRAY
46
- | SchemaType.INT88_ARRAY
47
- | SchemaType.INT96_ARRAY
48
- | SchemaType.INT104_ARRAY
49
- | SchemaType.INT112_ARRAY
50
- | SchemaType.INT120_ARRAY
51
- | SchemaType.INT128_ARRAY
52
- | SchemaType.INT136_ARRAY
53
- | SchemaType.INT144_ARRAY
54
- | SchemaType.INT152_ARRAY
55
- | SchemaType.INT160_ARRAY
56
- | SchemaType.INT168_ARRAY
57
- | SchemaType.INT176_ARRAY
58
- | SchemaType.INT184_ARRAY
59
- | SchemaType.INT192_ARRAY
60
- | SchemaType.INT200_ARRAY
61
- | SchemaType.INT208_ARRAY
62
- | SchemaType.INT216_ARRAY
63
- | SchemaType.INT224_ARRAY
64
- | SchemaType.INT232_ARRAY
65
- | SchemaType.INT240_ARRAY
66
- | SchemaType.INT248_ARRAY
67
- | SchemaType.INT256_ARRAY
68
- | SchemaType.BYTES1_ARRAY
69
- | SchemaType.BYTES2_ARRAY
70
- | SchemaType.BYTES3_ARRAY
71
- | SchemaType.BYTES4_ARRAY
72
- | SchemaType.BYTES5_ARRAY
73
- | SchemaType.BYTES6_ARRAY
74
- | SchemaType.BYTES7_ARRAY
75
- | SchemaType.BYTES8_ARRAY
76
- | SchemaType.BYTES9_ARRAY
77
- | SchemaType.BYTES10_ARRAY
78
- | SchemaType.BYTES11_ARRAY
79
- | SchemaType.BYTES12_ARRAY
80
- | SchemaType.BYTES13_ARRAY
81
- | SchemaType.BYTES14_ARRAY
82
- | SchemaType.BYTES15_ARRAY
83
- | SchemaType.BYTES16_ARRAY
84
- | SchemaType.BYTES17_ARRAY
85
- | SchemaType.BYTES18_ARRAY
86
- | SchemaType.BYTES19_ARRAY
87
- | SchemaType.BYTES20_ARRAY
88
- | SchemaType.BYTES21_ARRAY
89
- | SchemaType.BYTES22_ARRAY
90
- | SchemaType.BYTES23_ARRAY
91
- | SchemaType.BYTES24_ARRAY
92
- | SchemaType.BYTES25_ARRAY
93
- | SchemaType.BYTES26_ARRAY
94
- | SchemaType.BYTES27_ARRAY
95
- | SchemaType.BYTES28_ARRAY
96
- | SchemaType.BYTES29_ARRAY
97
- | SchemaType.BYTES30_ARRAY
98
- | SchemaType.BYTES31_ARRAY
99
- | SchemaType.BYTES32_ARRAY
100
- | SchemaType.BOOL_ARRAY
101
- | SchemaType.ADDRESS_ARRAY;
@@ -1,4 +0,0 @@
1
- import { SchemaType } from "../SchemaType";
2
- import { ArraySchemaType } from "./ArraySchemaType";
3
-
4
- export type DynamicSchemaType = ArraySchemaType | SchemaType.BYTES | SchemaType.STRING;
@@ -1,10 +0,0 @@
1
- import { AbiTypes } from "./AbiTypes";
2
- import { AbiTypeToSchemaType } from "../mappings/AbiTypeToSchemaType";
3
- import { getStaticByteLength } from "../utils/getStaticByteLength";
4
- import { SchemaTypeToAbiType } from "../mappings/SchemaTypeToAbiType";
5
- import { StaticSchemaType } from "./StaticSchemaType";
6
-
7
- export type StaticAbiType = (typeof SchemaTypeToAbiType)[StaticSchemaType];
8
- export const StaticAbiTypes = AbiTypes.filter(
9
- (abiType) => getStaticByteLength(AbiTypeToSchemaType[abiType]) > 0,
10
- ) as StaticAbiType[];
@@ -1,3 +0,0 @@
1
- import { StaticAbiType } from "./StaticAbiTypes";
2
-
3
- export type StaticArray = `${StaticAbiType}[${number}]`;
@@ -1,4 +0,0 @@
1
- import { SchemaType } from "../SchemaType";
2
- import { DynamicSchemaType } from "./DynamicSchemaType";
3
-
4
- export type StaticSchemaType = Exclude<SchemaType, DynamicSchemaType>;
@@ -1,8 +0,0 @@
1
- export type { AbiType } from "./AbiTypes";
2
- export { AbiTypes } from "./AbiTypes";
3
- export type { ArraySchemaType } from "./ArraySchemaType";
4
- export type { DynamicSchemaType } from "./DynamicSchemaType";
5
- export type { StaticAbiType } from "./StaticAbiTypes";
6
- export { StaticAbiTypes } from "./StaticAbiTypes";
7
- export type { StaticArray } from "./StaticArray";
8
- export type { StaticSchemaType } from "./StaticSchemaType";
@@ -1,48 +0,0 @@
1
- import { getStaticByteLength } from "./getStaticByteLength";
2
- import { SchemaType } from "../SchemaType";
3
-
4
- /**
5
- * Encode a table schema into a bytes32 hex string
6
- * Port of `Schema.sol` from `@latticexyz/store`
7
- * @param schema The schema to encode SchemaType[]
8
- * @returns The encoded schema as a 32 byte hex string
9
- * @deprecated use `schemaToHex` from `protocol-parser` instead
10
- */
11
-
12
- export function encodeSchema(schema: SchemaType[]): Uint8Array {
13
- if (schema.length > 28) throw new Error("Schema can only have up to 28 fields");
14
- const encodedSchema = new Uint8Array(32);
15
- let length = 0;
16
- let staticFields = 0;
17
-
18
- // Compute the length of the schema and the number of static fields
19
- // and store the schema types in the encoded schema
20
- let hasDynamicFields = false;
21
- for (let i = 0; i < schema.length; i++) {
22
- const staticByteLength = getStaticByteLength(schema[i]);
23
-
24
- // Increase the static field count if the field is static
25
- if (staticByteLength > 0) {
26
- // Revert if we have seen a dynamic field before, but now we see a static field
27
- if (hasDynamicFields) throw new Error("Static fields must come before dynamic fields in the schema");
28
- staticFields++;
29
- } else {
30
- // Flag that we have seen a dynamic field
31
- hasDynamicFields = true;
32
- }
33
-
34
- length += staticByteLength;
35
- encodedSchema[i + 4] = schema[i];
36
- }
37
-
38
- // Require max 14 dynamic fields
39
- const dynamicFields = schema.length - staticFields;
40
- if (dynamicFields > 14) throw new Error("Schema can only have up to 14 dynamic fields");
41
-
42
- // Store total static length, and number of static and dynamic fields
43
- new DataView(encodedSchema.buffer).setUint16(0, length); // 2 length bytes
44
- encodedSchema[2] = staticFields; // number of static fields
45
- encodedSchema[3] = dynamicFields; // number of dynamic fields
46
-
47
- return encodedSchema;
48
- }
@@ -1,11 +0,0 @@
1
- import { AbiTypeToPrimitiveType } from "../mappings";
2
- import { AbiTypeToDefaultValue } from "../mappings/AbiTypeToDefaultValue";
3
-
4
- /**
5
- * Return a value corresponding to the Solidity default value for a given abi type
6
- */
7
- export function getAbiTypeDefaultValue<T extends string>(abiType: T) {
8
- // Remove fixed array lengths (eg map uint256[10] to uint256[])
9
- const normalizedType = abiType.replace(/(\w+)\[\d+\]/g, "$1[]");
10
- return AbiTypeToDefaultValue[normalizedType as keyof typeof AbiTypeToDefaultValue] as AbiTypeToPrimitiveType<T>;
11
- }
@@ -1,25 +0,0 @@
1
- import { SchemaType } from "../SchemaType";
2
-
3
- export function getStaticByteLength(schemaType: SchemaType) {
4
- const val = schemaType.valueOf();
5
- if (val < 32) {
6
- // uint8-256
7
- return val + 1;
8
- } else if (val < 64) {
9
- // int8-256, offset by 32
10
- return val + 1 - 32;
11
- } else if (val < 96) {
12
- // bytes1-32, offset by 64
13
- return val + 1 - 64;
14
- }
15
-
16
- // Other static types
17
- if (schemaType == SchemaType.BOOL) {
18
- return 1;
19
- } else if (schemaType == SchemaType.ADDRESS) {
20
- return 20;
21
- }
22
-
23
- // Return 0 for all dynamic types
24
- return 0;
25
- }
@@ -1,3 +0,0 @@
1
- export { encodeSchema } from "./encodeSchema";
2
- export { getStaticByteLength } from "./getStaticByteLength";
3
- export { getAbiTypeDefaultValue } from "./getAbiTypeDefaultValue";
@@ -1,66 +0,0 @@
1
- import { describe, expectTypeOf, it } from "vitest";
2
- import { Hex } from "viem";
3
- import { DynamicAbiTypeToPrimitiveType } from "./dynamicAbiTypes";
4
-
5
- describe("DynamicAbiTypeToPrimitiveType", () => {
6
- it("maps uint8 array to number array", () => {
7
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint8[]">>().toMatchTypeOf<readonly number[]>();
8
- });
9
- it("maps uint32 array to number array", () => {
10
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint32[]">>().toMatchTypeOf<readonly number[]>();
11
- });
12
- it("maps uint48 array to number array", () => {
13
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint48[]">>().toMatchTypeOf<readonly number[]>();
14
- });
15
- it("maps uint56 array to bigint array", () => {
16
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint56[]">>().toMatchTypeOf<readonly bigint[]>();
17
- });
18
- it("maps uint256 array to bigint array", () => {
19
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint256[]">>().toMatchTypeOf<readonly bigint[]>();
20
- });
21
-
22
- it("maps int8 array to number array", () => {
23
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int8[]">>().toMatchTypeOf<readonly number[]>();
24
- });
25
- it("maps int32 array to number array", () => {
26
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int32[]">>().toMatchTypeOf<readonly number[]>();
27
- });
28
- it("maps int48 array to number array", () => {
29
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int48[]">>().toMatchTypeOf<readonly number[]>();
30
- });
31
- it("maps int56 array to bigint array", () => {
32
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int56[]">>().toMatchTypeOf<readonly bigint[]>();
33
- });
34
- it("maps int256 array to bigint array", () => {
35
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int256[]">>().toMatchTypeOf<readonly bigint[]>();
36
- });
37
-
38
- it("maps bytes1 array to hex array", () => {
39
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes1[]">>().toMatchTypeOf<readonly Hex[]>();
40
- });
41
- it("maps bytes2 array to hex array", () => {
42
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes2[]">>().toMatchTypeOf<readonly Hex[]>();
43
- });
44
- it("maps bytes8 array to hex array", () => {
45
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes8[]">>().toMatchTypeOf<readonly Hex[]>();
46
- });
47
- it("maps bytes32 array to hex array", () => {
48
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes32[]">>().toMatchTypeOf<readonly Hex[]>();
49
- });
50
-
51
- it("maps bool array to boolean array", () => {
52
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bool[]">>().toMatchTypeOf<readonly boolean[]>();
53
- });
54
-
55
- it("maps address array to hex array", () => {
56
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"address[]">>().toMatchTypeOf<readonly Hex[]>();
57
- });
58
-
59
- it("maps bytes to hex", () => {
60
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes">>().toMatchTypeOf<Hex>();
61
- });
62
-
63
- it("maps string to string", () => {
64
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"string">>().toMatchTypeOf<string>();
65
- });
66
- });
@@ -1,128 +0,0 @@
1
- import { Hex } from "viem";
2
- import { DynamicAbiType, dynamicAbiTypes } from "./schemaAbiTypes";
3
- import { LiteralToBroad } from "./utils";
4
-
5
- // Variable-length ABI types, where their lengths are encoded by EncodedLengths within the record
6
-
7
- export type DynamicPrimitiveType =
8
- | readonly number[]
9
- | readonly bigint[]
10
- | readonly Hex[]
11
- | readonly boolean[]
12
- | Hex
13
- | string;
14
-
15
- export const dynamicAbiTypeToDefaultValue = {
16
- "uint8[]": [] as readonly number[],
17
- "uint16[]": [] as readonly number[],
18
- "uint24[]": [] as readonly number[],
19
- "uint32[]": [] as readonly number[],
20
- "uint40[]": [] as readonly number[],
21
- "uint48[]": [] as readonly number[],
22
- "uint56[]": [] as readonly bigint[],
23
- "uint64[]": [] as readonly bigint[],
24
- "uint72[]": [] as readonly bigint[],
25
- "uint80[]": [] as readonly bigint[],
26
- "uint88[]": [] as readonly bigint[],
27
- "uint96[]": [] as readonly bigint[],
28
- "uint104[]": [] as readonly bigint[],
29
- "uint112[]": [] as readonly bigint[],
30
- "uint120[]": [] as readonly bigint[],
31
- "uint128[]": [] as readonly bigint[],
32
- "uint136[]": [] as readonly bigint[],
33
- "uint144[]": [] as readonly bigint[],
34
- "uint152[]": [] as readonly bigint[],
35
- "uint160[]": [] as readonly bigint[],
36
- "uint168[]": [] as readonly bigint[],
37
- "uint176[]": [] as readonly bigint[],
38
- "uint184[]": [] as readonly bigint[],
39
- "uint192[]": [] as readonly bigint[],
40
- "uint200[]": [] as readonly bigint[],
41
- "uint208[]": [] as readonly bigint[],
42
- "uint216[]": [] as readonly bigint[],
43
- "uint224[]": [] as readonly bigint[],
44
- "uint232[]": [] as readonly bigint[],
45
- "uint240[]": [] as readonly bigint[],
46
- "uint248[]": [] as readonly bigint[],
47
- "uint256[]": [] as readonly bigint[],
48
-
49
- "int8[]": [] as readonly number[],
50
- "int16[]": [] as readonly number[],
51
- "int24[]": [] as readonly number[],
52
- "int32[]": [] as readonly number[],
53
- "int40[]": [] as readonly number[],
54
- "int48[]": [] as readonly number[],
55
- "int56[]": [] as readonly bigint[],
56
- "int64[]": [] as readonly bigint[],
57
- "int72[]": [] as readonly bigint[],
58
- "int80[]": [] as readonly bigint[],
59
- "int88[]": [] as readonly bigint[],
60
- "int96[]": [] as readonly bigint[],
61
- "int104[]": [] as readonly bigint[],
62
- "int112[]": [] as readonly bigint[],
63
- "int120[]": [] as readonly bigint[],
64
- "int128[]": [] as readonly bigint[],
65
- "int136[]": [] as readonly bigint[],
66
- "int144[]": [] as readonly bigint[],
67
- "int152[]": [] as readonly bigint[],
68
- "int160[]": [] as readonly bigint[],
69
- "int168[]": [] as readonly bigint[],
70
- "int176[]": [] as readonly bigint[],
71
- "int184[]": [] as readonly bigint[],
72
- "int192[]": [] as readonly bigint[],
73
- "int200[]": [] as readonly bigint[],
74
- "int208[]": [] as readonly bigint[],
75
- "int216[]": [] as readonly bigint[],
76
- "int224[]": [] as readonly bigint[],
77
- "int232[]": [] as readonly bigint[],
78
- "int240[]": [] as readonly bigint[],
79
- "int248[]": [] as readonly bigint[],
80
- "int256[]": [] as readonly bigint[],
81
-
82
- "bytes1[]": [] as readonly Hex[],
83
- "bytes2[]": [] as readonly Hex[],
84
- "bytes3[]": [] as readonly Hex[],
85
- "bytes4[]": [] as readonly Hex[],
86
- "bytes5[]": [] as readonly Hex[],
87
- "bytes6[]": [] as readonly Hex[],
88
- "bytes7[]": [] as readonly Hex[],
89
- "bytes8[]": [] as readonly Hex[],
90
- "bytes9[]": [] as readonly Hex[],
91
- "bytes10[]": [] as readonly Hex[],
92
- "bytes11[]": [] as readonly Hex[],
93
- "bytes12[]": [] as readonly Hex[],
94
- "bytes13[]": [] as readonly Hex[],
95
- "bytes14[]": [] as readonly Hex[],
96
- "bytes15[]": [] as readonly Hex[],
97
- "bytes16[]": [] as readonly Hex[],
98
- "bytes17[]": [] as readonly Hex[],
99
- "bytes18[]": [] as readonly Hex[],
100
- "bytes19[]": [] as readonly Hex[],
101
- "bytes20[]": [] as readonly Hex[],
102
- "bytes21[]": [] as readonly Hex[],
103
- "bytes22[]": [] as readonly Hex[],
104
- "bytes23[]": [] as readonly Hex[],
105
- "bytes24[]": [] as readonly Hex[],
106
- "bytes25[]": [] as readonly Hex[],
107
- "bytes26[]": [] as readonly Hex[],
108
- "bytes27[]": [] as readonly Hex[],
109
- "bytes28[]": [] as readonly Hex[],
110
- "bytes29[]": [] as readonly Hex[],
111
- "bytes30[]": [] as readonly Hex[],
112
- "bytes31[]": [] as readonly Hex[],
113
- "bytes32[]": [] as readonly Hex[],
114
-
115
- "bool[]": [] as readonly boolean[],
116
- "address[]": [] as readonly Hex[],
117
-
118
- bytes: "0x",
119
- string: "",
120
- } as const satisfies Record<DynamicAbiType, DynamicPrimitiveType>;
121
-
122
- export type DynamicAbiTypeToPrimitiveType<TDynamicAbiType extends DynamicAbiType = DynamicAbiType> = LiteralToBroad<
123
- (typeof dynamicAbiTypeToDefaultValue)[TDynamicAbiType]
124
- >;
125
-
126
- export function isDynamicAbiType(abiType: unknown): abiType is DynamicAbiType {
127
- return dynamicAbiTypes.includes(abiType as DynamicAbiType);
128
- }
@@ -1,4 +0,0 @@
1
- export * from "../deprecated/types";
2
- export * from "../deprecated/mappings";
3
- export * from "../deprecated/utils";
4
- export * from "../deprecated/SchemaType";
@@ -1,5 +0,0 @@
1
- /**
2
- * External exports.
3
- *
4
- * Be sure we're ready to commit to these being supported and changes made backward compatible!
5
- */