@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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present Lattice Labs Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ var b=["uint8","uint16","uint24","uint32","uint40","uint48","uint56","uint64","uint72","uint80","uint88","uint96","uint104","uint112","uint120","uint128","uint136","uint144","uint152","uint160","uint168","uint176","uint184","uint192","uint200","uint208","uint216","uint224","uint232","uint240","uint248","uint256","int8","int16","int24","int32","int40","int48","int56","int64","int72","int80","int88","int96","int104","int112","int120","int128","int136","int144","int152","int160","int168","int176","int184","int192","int200","int208","int216","int224","int232","int240","int248","int256","bytes1","bytes2","bytes3","bytes4","bytes5","bytes6","bytes7","bytes8","bytes9","bytes10","bytes11","bytes12","bytes13","bytes14","bytes15","bytes16","bytes17","bytes18","bytes19","bytes20","bytes21","bytes22","bytes23","bytes24","bytes25","bytes26","bytes27","bytes28","bytes29","bytes30","bytes31","bytes32","bool","address","uint8[]","uint16[]","uint24[]","uint32[]","uint40[]","uint48[]","uint56[]","uint64[]","uint72[]","uint80[]","uint88[]","uint96[]","uint104[]","uint112[]","uint120[]","uint128[]","uint136[]","uint144[]","uint152[]","uint160[]","uint168[]","uint176[]","uint184[]","uint192[]","uint200[]","uint208[]","uint216[]","uint224[]","uint232[]","uint240[]","uint248[]","uint256[]","int8[]","int16[]","int24[]","int32[]","int40[]","int48[]","int56[]","int64[]","int72[]","int80[]","int88[]","int96[]","int104[]","int112[]","int120[]","int128[]","int136[]","int144[]","int152[]","int160[]","int168[]","int176[]","int184[]","int192[]","int200[]","int208[]","int216[]","int224[]","int232[]","int240[]","int248[]","int256[]","bytes1[]","bytes2[]","bytes3[]","bytes4[]","bytes5[]","bytes6[]","bytes7[]","bytes8[]","bytes9[]","bytes10[]","bytes11[]","bytes12[]","bytes13[]","bytes14[]","bytes15[]","bytes16[]","bytes17[]","bytes18[]","bytes19[]","bytes20[]","bytes21[]","bytes22[]","bytes23[]","bytes24[]","bytes25[]","bytes26[]","bytes27[]","bytes28[]","bytes29[]","bytes30[]","bytes31[]","bytes32[]","bool[]","address[]","bytes","string"],E=b.slice(0,98),I=b.slice(98);var x={uint8:0,uint16:0,uint24:0,uint32:0,uint40:0,uint48:0,uint56:0n,uint64:0n,uint72:0n,uint80:0n,uint88:0n,uint96:0n,uint104:0n,uint112:0n,uint120:0n,uint128:0n,uint136:0n,uint144:0n,uint152:0n,uint160:0n,uint168:0n,uint176:0n,uint184:0n,uint192:0n,uint200:0n,uint208:0n,uint216:0n,uint224:0n,uint232:0n,uint240:0n,uint248:0n,uint256:0n,int8:0,int16:0,int24:0,int32:0,int40:0,int48:0,int56:0n,int64:0n,int72:0n,int80:0n,int88:0n,int96:0n,int104:0n,int112:0n,int120:0n,int128:0n,int136:0n,int144:0n,int152:0n,int160:0n,int168:0n,int176:0n,int184:0n,int192:0n,int200:0n,int208:0n,int216:0n,int224:0n,int232:0n,int240:0n,int248:0n,int256:0n,bytes1:"0x00",bytes2:"0x0000",bytes3:"0x000000",bytes4:"0x00000000",bytes5:"0x0000000000",bytes6:"0x000000000000",bytes7:"0x00000000000000",bytes8:"0x0000000000000000",bytes9:"0x000000000000000000",bytes10:"0x00000000000000000000",bytes11:"0x0000000000000000000000",bytes12:"0x000000000000000000000000",bytes13:"0x00000000000000000000000000",bytes14:"0x0000000000000000000000000000",bytes15:"0x000000000000000000000000000000",bytes16:"0x00000000000000000000000000000000",bytes17:"0x0000000000000000000000000000000000",bytes18:"0x000000000000000000000000000000000000",bytes19:"0x00000000000000000000000000000000000000",bytes20:"0x0000000000000000000000000000000000000000",bytes21:"0x000000000000000000000000000000000000000000",bytes22:"0x00000000000000000000000000000000000000000000",bytes23:"0x0000000000000000000000000000000000000000000000",bytes24:"0x000000000000000000000000000000000000000000000000",bytes25:"0x00000000000000000000000000000000000000000000000000",bytes26:"0x0000000000000000000000000000000000000000000000000000",bytes27:"0x000000000000000000000000000000000000000000000000000000",bytes28:"0x00000000000000000000000000000000000000000000000000000000",bytes29:"0x0000000000000000000000000000000000000000000000000000000000",bytes30:"0x000000000000000000000000000000000000000000000000000000000000",bytes31:"0x00000000000000000000000000000000000000000000000000000000000000",bytes32:"0x0000000000000000000000000000000000000000000000000000000000000000",bool:!1,address:"0x0000000000000000000000000000000000000000"},c={uint8:1,uint16:2,uint24:3,uint32:4,uint40:5,uint48:6,uint56:7,uint64:9,uint72:9,uint80:10,uint88:11,uint96:12,uint104:13,uint112:14,uint120:15,uint128:16,uint136:17,uint144:18,uint152:19,uint160:20,uint168:21,uint176:22,uint184:23,uint192:24,uint200:25,uint208:26,uint216:27,uint224:28,uint232:29,uint240:30,uint248:31,uint256:32,int8:1,int16:2,int24:3,int32:4,int40:5,int48:6,int56:7,int64:9,int72:9,int80:10,int88:11,int96:12,int104:13,int112:14,int120:15,int128:16,int136:17,int144:18,int152:19,int160:20,int168:21,int176:22,int184:23,int192:24,int200:25,int208:26,int216:27,int224:28,int232:29,int240:30,int248:31,int256:32,bytes1:1,bytes2:2,bytes3:3,bytes4:4,bytes5:5,bytes6:6,bytes7:7,bytes8:8,bytes9:9,bytes10:10,bytes11:11,bytes12:12,bytes13:13,bytes14:14,bytes15:15,bytes16:16,bytes17:17,bytes18:18,bytes19:19,bytes20:20,bytes21:21,bytes22:22,bytes23:23,bytes24:24,bytes25:25,bytes26:26,bytes27:27,bytes28:28,bytes29:29,bytes30:30,bytes31:31,bytes32:32,bool:1,address:20};function D(t,e=[]){let i=t.reduce((n,y)=>n+c[y],0),s=t.length,a=e.length,r=t.map(n=>b.indexOf(n)),p=e.map(n=>b.indexOf(n));return`0x${[i.toString(16).padStart(4,"0"),s.toString(16).padStart(2,"0"),a.toString(16).padStart(2,"0"),...r.map(n=>n.toString(16).padStart(2,"0")),...p.map(n=>n.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}function J(t,e=[]){return{staticDataLength:t.reduce((s,a)=>s+c[a],0),staticFields:t,dynamicFields:e,isEmpty:!1,schemaData:D(t,e)}}var P={"uint8[]":[],"uint16[]":[],"uint24[]":[],"uint32[]":[],"uint40[]":[],"uint48[]":[],"uint56[]":[],"uint64[]":[],"uint72[]":[],"uint80[]":[],"uint88[]":[],"uint96[]":[],"uint104[]":[],"uint112[]":[],"uint120[]":[],"uint128[]":[],"uint136[]":[],"uint144[]":[],"uint152[]":[],"uint160[]":[],"uint168[]":[],"uint176[]":[],"uint184[]":[],"uint192[]":[],"uint200[]":[],"uint208[]":[],"uint216[]":[],"uint224[]":[],"uint232[]":[],"uint240[]":[],"uint248[]":[],"uint256[]":[],"int8[]":[],"int16[]":[],"int24[]":[],"int32[]":[],"int40[]":[],"int48[]":[],"int56[]":[],"int64[]":[],"int72[]":[],"int80[]":[],"int88[]":[],"int96[]":[],"int104[]":[],"int112[]":[],"int120[]":[],"int128[]":[],"int136[]":[],"int144[]":[],"int152[]":[],"int160[]":[],"int168[]":[],"int176[]":[],"int184[]":[],"int192[]":[],"int200[]":[],"int208[]":[],"int216[]":[],"int224[]":[],"int232[]":[],"int240[]":[],"int248[]":[],"int256[]":[],"bytes1[]":[],"bytes2[]":[],"bytes3[]":[],"bytes4[]":[],"bytes5[]":[],"bytes6[]":[],"bytes7[]":[],"bytes8[]":[],"bytes9[]":[],"bytes10[]":[],"bytes11[]":[],"bytes12[]":[],"bytes13[]":[],"bytes14[]":[],"bytes15[]":[],"bytes16[]":[],"bytes17[]":[],"bytes18[]":[],"bytes19[]":[],"bytes20[]":[],"bytes21[]":[],"bytes22[]":[],"bytes23[]":[],"bytes24[]":[],"bytes25[]":[],"bytes26[]":[],"bytes27[]":[],"bytes28[]":[],"bytes29[]":[],"bytes30[]":[],"bytes31[]":[],"bytes32[]":[],"bool[]":[],"address[]":[],bytes:"0x",string:""};function $(t){return t.replace(/\[\]$/g,"")}var n0={...x,...P};import{hexToString as U,sliceHex as C}from"viem";function f(t,e){throw new Error(e??`Unexpected value: ${t}`)}import{getAddress as F,hexToBigInt as V,hexToBool as k}from"viem";import{MUDError as o}from"@latticexyz/common/errors";var u=class extends o{name="InvalidHexValueError";constructor(e){super(`Hex value "${e}" is an odd length (${e.length-2}). It must be an even length.`)}},g=class extends o{name="InvalidHexLengthForSchemaError";constructor(e){super(`Hex value "${e}" has length of ${e.length-2}, but expected length of 64 for a schema.`)}},h=class extends o{name="InvalidHexLengthForPackedCounterError";constructor(e){super(`Hex value "${e}" has length of ${e.length-2}, but expected length of 64 for a packed counter.`)}},l=class extends o{name="InvalidHexLengthForStaticFieldError";constructor(e,i){super(`Hex value "${i}" has length of ${i.length-2}, but expected length of ${c[e]*2} for ${e} type.`)}},A=class extends o{name="InvalidHexLengthForArrayFieldError";constructor(e,i){super(`Hex value "${i}" has length of ${i.length-2}, but expected a multiple of ${c[e]*2} for ${e}[] type.`)}},d=class extends o{name="SchemaStaticLengthMismatchError";constructor(e,i,s){super(`Schema "${e}" static data length (${i}) did not match the summed length of all static fields (${s}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`)}},S=class extends o{name="PackedCounterLengthMismatchError";constructor(e,i,s){super(`PackedCounter "${e}" total bytes length (${i}) did not match the summed length of all field byte lengths (${s}).`)}};function H(t,e){if(e.length>3&&e.length%2!==0)throw new u(e);if((e.length-2)/2!==c[t])throw new l(t,e);switch(t){case"uint8":case"uint16":case"uint24":case"uint32":case"uint40":case"uint48":case"uint56":case"uint64":case"uint72":case"uint80":case"uint88":case"uint96":case"uint104":case"uint112":case"uint120":case"uint128":case"uint136":case"uint144":case"uint152":case"uint160":case"uint168":case"uint176":case"uint184":case"uint192":case"uint200":case"uint208":case"uint216":case"uint224":case"uint232":case"uint240":case"uint248":case"uint256":case"int8":case"int16":case"int24":case"int32":case"int40":case"int48":case"int56":case"int64":case"int72":case"int80":case"int88":case"int96":case"int104":case"int112":case"int120":case"int128":case"int136":case"int144":case"int152":case"int160":case"int168":case"int176":case"int184":case"int192":case"int200":case"int208":case"int216":case"int224":case"int232":case"int240":case"int248":case"int256":{let s=V(e,{signed:t.startsWith("int")}),a=typeof x[t];if(a==="number")return Number(s);if(a==="bigint")return s;throw new Error(`Unexpected default value type (${a}) for ABI type (${t})`)}case"bytes1":case"bytes2":case"bytes3":case"bytes4":case"bytes5":case"bytes6":case"bytes7":case"bytes8":case"bytes9":case"bytes10":case"bytes11":case"bytes12":case"bytes13":case"bytes14":case"bytes15":case"bytes16":case"bytes17":case"bytes18":case"bytes19":case"bytes20":case"bytes21":case"bytes22":case"bytes23":case"bytes24":case"bytes25":case"bytes26":case"bytes27":case"bytes28":case"bytes29":case"bytes30":case"bytes31":case"bytes32":return e;case"bool":return k(e);case"address":return F(e)}return f(t,`Unsupported static ABI type: ${t}`)}function L(t,e){if(t==="bytes")return e;if(t==="string")return U(e);if(e.length>3&&e.length%2!==0)throw new u(e);let i=(e.length-2)/2;switch(t){case"uint8[]":case"uint16[]":case"uint24[]":case"uint32[]":case"uint40[]":case"uint48[]":case"uint56[]":case"uint64[]":case"uint72[]":case"uint80[]":case"uint88[]":case"uint96[]":case"uint104[]":case"uint112[]":case"uint120[]":case"uint128[]":case"uint136[]":case"uint144[]":case"uint152[]":case"uint160[]":case"uint168[]":case"uint176[]":case"uint184[]":case"uint192[]":case"uint200[]":case"uint208[]":case"uint216[]":case"uint224[]":case"uint232[]":case"uint240[]":case"uint248[]":case"uint256[]":case"int8[]":case"int16[]":case"int24[]":case"int32[]":case"int40[]":case"int48[]":case"int56[]":case"int64[]":case"int72[]":case"int80[]":case"int88[]":case"int96[]":case"int104[]":case"int112[]":case"int120[]":case"int128[]":case"int136[]":case"int144[]":case"int152[]":case"int160[]":case"int168[]":case"int176[]":case"int184[]":case"int192[]":case"int200[]":case"int208[]":case"int216[]":case"int224[]":case"int232[]":case"int240[]":case"int248[]":case"int256[]":case"bytes1[]":case"bytes2[]":case"bytes3[]":case"bytes4[]":case"bytes5[]":case"bytes6[]":case"bytes7[]":case"bytes8[]":case"bytes9[]":case"bytes10[]":case"bytes11[]":case"bytes12[]":case"bytes13[]":case"bytes14[]":case"bytes15[]":case"bytes16[]":case"bytes17[]":case"bytes18[]":case"bytes19[]":case"bytes20[]":case"bytes21[]":case"bytes22[]":case"bytes23[]":case"bytes24[]":case"bytes25[]":case"bytes26[]":case"bytes27[]":case"bytes28[]":case"bytes29[]":case"bytes30[]":case"bytes31[]":case"bytes32[]":case"bool[]":case"address[]":{let s=$(t),a=c[s];if(i%a!==0)throw new A(s,e);return new Array(i/a).fill(void 0).map((p,n)=>{let y=C(e,n*a,(n+1)*a);return H(s,y)})}}return f(t,`Unsupported dynamic ABI type: ${t}`)}import{decodeAbiParameters as R}from"viem";function B0(t,e){return e.map((i,s)=>R([{type:t.staticFields[s]}],i)[0])}import{sliceHex as w}from"viem";function C0(t){if(t.length!==66)throw new h(t);let e=H("uint56",w(t,0,7)),i=L("uint40[]",w(t,7)),s=BigInt(i.reduce((a,r)=>a+r,0));if(s!==e)throw new S(t,e,s);return{totalByteLength:e,fieldByteLengths:i}}import{hexToNumber as m,sliceHex as T}from"viem";function v(t){if(t.length!==66)throw new g(t);let e=m(T(t,0,2)),i=m(T(t,2,3)),s=m(T(t,3,4)),a=[],r=[];for(let n=4;n<4+i;n++){let y=m(T(t,n,n+1));a.push(b[y])}for(let n=4+i;n<4+i+s;n++){let y=m(T(t,n,n+1));r.push(b[y])}let p=a.reduce((n,y)=>n+c[y],0);if(p!==e)throw new d(t,e,p);return{staticDataLength:e,staticFields:a,dynamicFields:r,isEmpty:t==="0x",schemaData:t}}import{sliceHex as B}from"viem";function J0(t){let e=v(B(t,0,32));return{keySchema:v(B(t,32,64)),valueSchema:e,isEmpty:t==="0x",schemaData:t}}export{u as InvalidHexLengthError,A as InvalidHexLengthForArrayFieldError,h as InvalidHexLengthForPackedCounterError,g as InvalidHexLengthForSchemaError,l as InvalidHexLengthForStaticFieldError,S as PackedCounterLengthMismatchError,d as SchemaStaticLengthMismatchError,n0 as abiTypeToDefaultValue,J as abiTypesToSchema,D as abiTypesToSchemaData,$ as arrayAbiTypeToStaticAbiType,L as decodeDynamicField,B0 as decodeKeyTuple,H as decodeStaticField,P as dynamicAbiTypeToDefaultValue,I as dynamicAbiTypes,C0 as hexToPackedCounter,v as hexToSchema,J0 as hexToTableSchema,b as schemaAbiTypes,c as staticAbiTypeToByteLength,x as staticAbiTypeToDefaultValue,E as staticAbiTypes};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schemaAbiTypes.ts","../src/staticAbiTypes.ts","../src/abiTypesToSchemaData.ts","../src/abiTypesToSchema.ts","../src/dynamicAbiTypes.ts","../src/abiTypeToDefaultValue.ts","../src/decodeDynamicField.ts","../src/assertExhaustive.ts","../src/decodeStaticField.ts","../src/errors.ts","../src/decodeKeyTuple.ts","../src/hexToPackedCounter.ts","../src/hexToSchema.ts","../src/hexToTableSchema.ts"],"sourcesContent":["import { AbiType } from \"abitype\";\nimport { TupleSplit } from \"./utils\";\n\n// Keep this array in sync with SchemaType.sol enum\n\nexport const schemaAbiTypes = [\n \"uint8\",\n \"uint16\",\n \"uint24\",\n \"uint32\",\n \"uint40\",\n \"uint48\",\n \"uint56\",\n \"uint64\",\n \"uint72\",\n \"uint80\",\n \"uint88\",\n \"uint96\",\n \"uint104\",\n \"uint112\",\n \"uint120\",\n \"uint128\",\n \"uint136\",\n \"uint144\",\n \"uint152\",\n \"uint160\",\n \"uint168\",\n \"uint176\",\n \"uint184\",\n \"uint192\",\n \"uint200\",\n \"uint208\",\n \"uint216\",\n \"uint224\",\n \"uint232\",\n \"uint240\",\n \"uint248\",\n \"uint256\",\n \"int8\",\n \"int16\",\n \"int24\",\n \"int32\",\n \"int40\",\n \"int48\",\n \"int56\",\n \"int64\",\n \"int72\",\n \"int80\",\n \"int88\",\n \"int96\",\n \"int104\",\n \"int112\",\n \"int120\",\n \"int128\",\n \"int136\",\n \"int144\",\n \"int152\",\n \"int160\",\n \"int168\",\n \"int176\",\n \"int184\",\n \"int192\",\n \"int200\",\n \"int208\",\n \"int216\",\n \"int224\",\n \"int232\",\n \"int240\",\n \"int248\",\n \"int256\",\n \"bytes1\",\n \"bytes2\",\n \"bytes3\",\n \"bytes4\",\n \"bytes5\",\n \"bytes6\",\n \"bytes7\",\n \"bytes8\",\n \"bytes9\",\n \"bytes10\",\n \"bytes11\",\n \"bytes12\",\n \"bytes13\",\n \"bytes14\",\n \"bytes15\",\n \"bytes16\",\n \"bytes17\",\n \"bytes18\",\n \"bytes19\",\n \"bytes20\",\n \"bytes21\",\n \"bytes22\",\n \"bytes23\",\n \"bytes24\",\n \"bytes25\",\n \"bytes26\",\n \"bytes27\",\n \"bytes28\",\n \"bytes29\",\n \"bytes30\",\n \"bytes31\",\n \"bytes32\",\n \"bool\",\n \"address\",\n \"uint8[]\",\n \"uint16[]\",\n \"uint24[]\",\n \"uint32[]\",\n \"uint40[]\",\n \"uint48[]\",\n \"uint56[]\",\n \"uint64[]\",\n \"uint72[]\",\n \"uint80[]\",\n \"uint88[]\",\n \"uint96[]\",\n \"uint104[]\",\n \"uint112[]\",\n \"uint120[]\",\n \"uint128[]\",\n \"uint136[]\",\n \"uint144[]\",\n \"uint152[]\",\n \"uint160[]\",\n \"uint168[]\",\n \"uint176[]\",\n \"uint184[]\",\n \"uint192[]\",\n \"uint200[]\",\n \"uint208[]\",\n \"uint216[]\",\n \"uint224[]\",\n \"uint232[]\",\n \"uint240[]\",\n \"uint248[]\",\n \"uint256[]\",\n \"int8[]\",\n \"int16[]\",\n \"int24[]\",\n \"int32[]\",\n \"int40[]\",\n \"int48[]\",\n \"int56[]\",\n \"int64[]\",\n \"int72[]\",\n \"int80[]\",\n \"int88[]\",\n \"int96[]\",\n \"int104[]\",\n \"int112[]\",\n \"int120[]\",\n \"int128[]\",\n \"int136[]\",\n \"int144[]\",\n \"int152[]\",\n \"int160[]\",\n \"int168[]\",\n \"int176[]\",\n \"int184[]\",\n \"int192[]\",\n \"int200[]\",\n \"int208[]\",\n \"int216[]\",\n \"int224[]\",\n \"int232[]\",\n \"int240[]\",\n \"int248[]\",\n \"int256[]\",\n \"bytes1[]\",\n \"bytes2[]\",\n \"bytes3[]\",\n \"bytes4[]\",\n \"bytes5[]\",\n \"bytes6[]\",\n \"bytes7[]\",\n \"bytes8[]\",\n \"bytes9[]\",\n \"bytes10[]\",\n \"bytes11[]\",\n \"bytes12[]\",\n \"bytes13[]\",\n \"bytes14[]\",\n \"bytes15[]\",\n \"bytes16[]\",\n \"bytes17[]\",\n \"bytes18[]\",\n \"bytes19[]\",\n \"bytes20[]\",\n \"bytes21[]\",\n \"bytes22[]\",\n \"bytes23[]\",\n \"bytes24[]\",\n \"bytes25[]\",\n \"bytes26[]\",\n \"bytes27[]\",\n \"bytes28[]\",\n \"bytes29[]\",\n \"bytes30[]\",\n \"bytes31[]\",\n \"bytes32[]\",\n \"bool[]\",\n \"address[]\",\n \"bytes\",\n \"string\",\n] as const satisfies readonly AbiType[];\n\nexport type SchemaAbiType = (typeof schemaAbiTypes)[number];\n\n// These are defined here to keep the index position (98) consolidated, since we use it both in runtime code and type definition\nexport const staticAbiTypes = schemaAbiTypes.slice(0, 98) as any as TupleSplit<typeof schemaAbiTypes, 98>[0];\nexport const dynamicAbiTypes = schemaAbiTypes.slice(98) as any as TupleSplit<typeof schemaAbiTypes, 98>[1];\n","import { Hex } from \"viem\";\nimport { staticAbiTypes } from \"./schemaAbiTypes\";\n\n// Fixed-length ABI types\n\nexport { staticAbiTypes };\n\nexport type StaticAbiType = (typeof staticAbiTypes)[number];\n\nexport type StaticPrimitiveType = number | bigint | boolean | Hex;\n\nexport const staticAbiTypeToDefaultValue = {\n uint8: 0,\n uint16: 0,\n uint24: 0,\n uint32: 0,\n uint40: 0,\n uint48: 0,\n uint56: 0n,\n uint64: 0n,\n uint72: 0n,\n uint80: 0n,\n uint88: 0n,\n uint96: 0n,\n uint104: 0n,\n uint112: 0n,\n uint120: 0n,\n uint128: 0n,\n uint136: 0n,\n uint144: 0n,\n uint152: 0n,\n uint160: 0n,\n uint168: 0n,\n uint176: 0n,\n uint184: 0n,\n uint192: 0n,\n uint200: 0n,\n uint208: 0n,\n uint216: 0n,\n uint224: 0n,\n uint232: 0n,\n uint240: 0n,\n uint248: 0n,\n uint256: 0n,\n\n int8: 0,\n int16: 0,\n int24: 0,\n int32: 0,\n int40: 0,\n int48: 0,\n int56: 0n,\n int64: 0n,\n int72: 0n,\n int80: 0n,\n int88: 0n,\n int96: 0n,\n int104: 0n,\n int112: 0n,\n int120: 0n,\n int128: 0n,\n int136: 0n,\n int144: 0n,\n int152: 0n,\n int160: 0n,\n int168: 0n,\n int176: 0n,\n int184: 0n,\n int192: 0n,\n int200: 0n,\n int208: 0n,\n int216: 0n,\n int224: 0n,\n int232: 0n,\n int240: 0n,\n int248: 0n,\n int256: 0n,\n\n bytes1: \"0x00\",\n bytes2: \"0x0000\",\n bytes3: \"0x000000\",\n bytes4: \"0x00000000\",\n bytes5: \"0x0000000000\",\n bytes6: \"0x000000000000\",\n bytes7: \"0x00000000000000\",\n bytes8: \"0x0000000000000000\",\n bytes9: \"0x000000000000000000\",\n bytes10: \"0x00000000000000000000\",\n bytes11: \"0x0000000000000000000000\",\n bytes12: \"0x000000000000000000000000\",\n bytes13: \"0x00000000000000000000000000\",\n bytes14: \"0x0000000000000000000000000000\",\n bytes15: \"0x000000000000000000000000000000\",\n bytes16: \"0x00000000000000000000000000000000\",\n bytes17: \"0x0000000000000000000000000000000000\",\n bytes18: \"0x000000000000000000000000000000000000\",\n bytes19: \"0x00000000000000000000000000000000000000\",\n bytes20: \"0x0000000000000000000000000000000000000000\",\n bytes21: \"0x000000000000000000000000000000000000000000\",\n bytes22: \"0x00000000000000000000000000000000000000000000\",\n bytes23: \"0x0000000000000000000000000000000000000000000000\",\n bytes24: \"0x000000000000000000000000000000000000000000000000\",\n bytes25: \"0x00000000000000000000000000000000000000000000000000\",\n bytes26: \"0x0000000000000000000000000000000000000000000000000000\",\n bytes27: \"0x000000000000000000000000000000000000000000000000000000\",\n bytes28: \"0x00000000000000000000000000000000000000000000000000000000\",\n bytes29: \"0x0000000000000000000000000000000000000000000000000000000000\",\n bytes30: \"0x000000000000000000000000000000000000000000000000000000000000\",\n bytes31: \"0x00000000000000000000000000000000000000000000000000000000000000\",\n bytes32: \"0x0000000000000000000000000000000000000000000000000000000000000000\",\n\n bool: false,\n address: \"0x0000000000000000000000000000000000000000\",\n} as const satisfies Record<StaticAbiType, StaticPrimitiveType>;\n\nexport type StaticAbiTypeToPrimitiveType<TStaticAbiType extends StaticAbiType = StaticAbiType> =\n (typeof staticAbiTypeToDefaultValue)[TStaticAbiType];\n\nexport const staticAbiTypeToByteLength = {\n uint8: 1,\n uint16: 2,\n uint24: 3,\n uint32: 4,\n uint40: 5,\n uint48: 6,\n uint56: 7,\n uint64: 9,\n uint72: 9,\n uint80: 10,\n uint88: 11,\n uint96: 12,\n uint104: 13,\n uint112: 14,\n uint120: 15,\n uint128: 16,\n uint136: 17,\n uint144: 18,\n uint152: 19,\n uint160: 20,\n uint168: 21,\n uint176: 22,\n uint184: 23,\n uint192: 24,\n uint200: 25,\n uint208: 26,\n uint216: 27,\n uint224: 28,\n uint232: 29,\n uint240: 30,\n uint248: 31,\n uint256: 32,\n\n int8: 1,\n int16: 2,\n int24: 3,\n int32: 4,\n int40: 5,\n int48: 6,\n int56: 7,\n int64: 9,\n int72: 9,\n int80: 10,\n int88: 11,\n int96: 12,\n int104: 13,\n int112: 14,\n int120: 15,\n int128: 16,\n int136: 17,\n int144: 18,\n int152: 19,\n int160: 20,\n int168: 21,\n int176: 22,\n int184: 23,\n int192: 24,\n int200: 25,\n int208: 26,\n int216: 27,\n int224: 28,\n int232: 29,\n int240: 30,\n int248: 31,\n int256: 32,\n\n bytes1: 1,\n bytes2: 2,\n bytes3: 3,\n bytes4: 4,\n bytes5: 5,\n bytes6: 6,\n bytes7: 7,\n bytes8: 8,\n bytes9: 9,\n bytes10: 10,\n bytes11: 11,\n bytes12: 12,\n bytes13: 13,\n bytes14: 14,\n bytes15: 15,\n bytes16: 16,\n bytes17: 17,\n bytes18: 18,\n bytes19: 19,\n bytes20: 20,\n bytes21: 21,\n bytes22: 22,\n bytes23: 23,\n bytes24: 24,\n bytes25: 25,\n bytes26: 26,\n bytes27: 27,\n bytes28: 28,\n bytes29: 29,\n bytes30: 30,\n bytes31: 31,\n bytes32: 32,\n\n bool: 1,\n address: 20,\n} as const satisfies Record<StaticAbiType, number>;\n","import { Hex } from \"viem\";\nimport { DynamicAbiType } from \"./dynamicAbiTypes\";\nimport { schemaAbiTypes } from \"./schemaAbiTypes\";\nimport { StaticAbiType, staticAbiTypeToByteLength } from \"./staticAbiTypes\";\n\nexport function abiTypesToSchemaData(staticFields: StaticAbiType[], dynamicFields: DynamicAbiType[] = []): Hex {\n const staticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);\n const numStaticFields = staticFields.length;\n const numDynamicFields = dynamicFields.length;\n const staticSchemaTypes = staticFields.map((abiType) => schemaAbiTypes.indexOf(abiType));\n const dynamicSchemaTypes = dynamicFields.map((abiType) => schemaAbiTypes.indexOf(abiType));\n return `0x${[\n staticDataLength.toString(16).padStart(4, \"0\"),\n numStaticFields.toString(16).padStart(2, \"0\"),\n numDynamicFields.toString(16).padStart(2, \"0\"),\n ...staticSchemaTypes.map((schemaType) => schemaType.toString(16).padStart(2, \"0\")),\n ...dynamicSchemaTypes.map((schemaType) => schemaType.toString(16).padStart(2, \"0\")),\n ]\n .join(\"\")\n .padEnd(64, \"0\")}`;\n}\n","import { Schema } from \"./common\";\nimport { DynamicAbiType } from \"./dynamicAbiTypes\";\nimport { StaticAbiType, staticAbiTypeToByteLength } from \"./staticAbiTypes\";\nimport { abiTypesToSchemaData } from \"./abiTypesToSchemaData\";\n\nexport function abiTypesToSchema(staticFields: StaticAbiType[], dynamicFields: DynamicAbiType[] = []): Schema {\n const staticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);\n return {\n staticDataLength,\n staticFields,\n dynamicFields,\n isEmpty: false,\n schemaData: abiTypesToSchemaData(staticFields, dynamicFields),\n };\n}\n","import { StaticAbiType } from \"./staticAbiTypes\";\nimport { Hex } from \"viem\";\nimport { dynamicAbiTypes } from \"./schemaAbiTypes\";\n\n// Variable-length ABI types, where their lengths are defined by a PackedCounter\n\nexport { dynamicAbiTypes };\n\nexport type DynamicAbiType = (typeof dynamicAbiTypes)[number];\n\nexport type DynamicPrimitiveType = number[] | bigint[] | Hex[] | boolean[] | Hex | string;\n\nexport const dynamicAbiTypeToDefaultValue = {\n \"uint8[]\": [] as number[],\n \"uint16[]\": [] as number[],\n \"uint24[]\": [] as number[],\n \"uint32[]\": [] as number[],\n \"uint40[]\": [] as number[],\n \"uint48[]\": [] as number[],\n \"uint56[]\": [] as bigint[],\n \"uint64[]\": [] as bigint[],\n \"uint72[]\": [] as bigint[],\n \"uint80[]\": [] as bigint[],\n \"uint88[]\": [] as bigint[],\n \"uint96[]\": [] as bigint[],\n \"uint104[]\": [] as bigint[],\n \"uint112[]\": [] as bigint[],\n \"uint120[]\": [] as bigint[],\n \"uint128[]\": [] as bigint[],\n \"uint136[]\": [] as bigint[],\n \"uint144[]\": [] as bigint[],\n \"uint152[]\": [] as bigint[],\n \"uint160[]\": [] as bigint[],\n \"uint168[]\": [] as bigint[],\n \"uint176[]\": [] as bigint[],\n \"uint184[]\": [] as bigint[],\n \"uint192[]\": [] as bigint[],\n \"uint200[]\": [] as bigint[],\n \"uint208[]\": [] as bigint[],\n \"uint216[]\": [] as bigint[],\n \"uint224[]\": [] as bigint[],\n \"uint232[]\": [] as bigint[],\n \"uint240[]\": [] as bigint[],\n \"uint248[]\": [] as bigint[],\n \"uint256[]\": [] as bigint[],\n\n \"int8[]\": [] as number[],\n \"int16[]\": [] as number[],\n \"int24[]\": [] as number[],\n \"int32[]\": [] as number[],\n \"int40[]\": [] as number[],\n \"int48[]\": [] as number[],\n \"int56[]\": [] as bigint[],\n \"int64[]\": [] as bigint[],\n \"int72[]\": [] as bigint[],\n \"int80[]\": [] as bigint[],\n \"int88[]\": [] as bigint[],\n \"int96[]\": [] as bigint[],\n \"int104[]\": [] as bigint[],\n \"int112[]\": [] as bigint[],\n \"int120[]\": [] as bigint[],\n \"int128[]\": [] as bigint[],\n \"int136[]\": [] as bigint[],\n \"int144[]\": [] as bigint[],\n \"int152[]\": [] as bigint[],\n \"int160[]\": [] as bigint[],\n \"int168[]\": [] as bigint[],\n \"int176[]\": [] as bigint[],\n \"int184[]\": [] as bigint[],\n \"int192[]\": [] as bigint[],\n \"int200[]\": [] as bigint[],\n \"int208[]\": [] as bigint[],\n \"int216[]\": [] as bigint[],\n \"int224[]\": [] as bigint[],\n \"int232[]\": [] as bigint[],\n \"int240[]\": [] as bigint[],\n \"int248[]\": [] as bigint[],\n \"int256[]\": [] as bigint[],\n\n \"bytes1[]\": [] as Hex[],\n \"bytes2[]\": [] as Hex[],\n \"bytes3[]\": [] as Hex[],\n \"bytes4[]\": [] as Hex[],\n \"bytes5[]\": [] as Hex[],\n \"bytes6[]\": [] as Hex[],\n \"bytes7[]\": [] as Hex[],\n \"bytes8[]\": [] as Hex[],\n \"bytes9[]\": [] as Hex[],\n \"bytes10[]\": [] as Hex[],\n \"bytes11[]\": [] as Hex[],\n \"bytes12[]\": [] as Hex[],\n \"bytes13[]\": [] as Hex[],\n \"bytes14[]\": [] as Hex[],\n \"bytes15[]\": [] as Hex[],\n \"bytes16[]\": [] as Hex[],\n \"bytes17[]\": [] as Hex[],\n \"bytes18[]\": [] as Hex[],\n \"bytes19[]\": [] as Hex[],\n \"bytes20[]\": [] as Hex[],\n \"bytes21[]\": [] as Hex[],\n \"bytes22[]\": [] as Hex[],\n \"bytes23[]\": [] as Hex[],\n \"bytes24[]\": [] as Hex[],\n \"bytes25[]\": [] as Hex[],\n \"bytes26[]\": [] as Hex[],\n \"bytes27[]\": [] as Hex[],\n \"bytes28[]\": [] as Hex[],\n \"bytes29[]\": [] as Hex[],\n \"bytes30[]\": [] as Hex[],\n \"bytes31[]\": [] as Hex[],\n \"bytes32[]\": [] as Hex[],\n\n \"bool[]\": [] as boolean[],\n \"address[]\": [] as Hex[],\n\n bytes: \"0x\",\n string: \"\",\n} as const satisfies Record<DynamicAbiType, DynamicPrimitiveType>;\n\nexport type DynamicAbiTypeToPrimitiveType<TDynamicAbiType extends DynamicAbiType = DynamicAbiType> =\n (typeof dynamicAbiTypeToDefaultValue)[TDynamicAbiType];\n\nexport type ArrayAbiTypeToStaticAbiType<T extends string> = T extends `${infer StaticAbiType}[]`\n ? StaticAbiType\n : never;\n\nexport function arrayAbiTypeToStaticAbiType<T extends `${StaticAbiType}[]`>(\n abiType: T\n): ArrayAbiTypeToStaticAbiType<T> {\n return abiType.replace(/\\[\\]$/g, \"\") as ArrayAbiTypeToStaticAbiType<T>;\n}\n","import { SchemaAbiType } from \"./schemaAbiTypes\";\nimport { DynamicAbiTypeToPrimitiveType, dynamicAbiTypeToDefaultValue } from \"./dynamicAbiTypes\";\nimport { StaticAbiTypeToPrimitiveType, staticAbiTypeToDefaultValue } from \"./staticAbiTypes\";\n\nexport const abiTypeToDefaultValue = {\n ...staticAbiTypeToDefaultValue,\n ...dynamicAbiTypeToDefaultValue,\n} as const satisfies Record<SchemaAbiType, StaticAbiTypeToPrimitiveType | DynamicAbiTypeToPrimitiveType>;\n","import { Hex, hexToString, sliceHex } from \"viem\";\nimport { DynamicAbiType, DynamicAbiTypeToPrimitiveType, arrayAbiTypeToStaticAbiType } from \"./dynamicAbiTypes\";\nimport { assertExhaustive } from \"./assertExhaustive\";\nimport { staticAbiTypeToByteLength } from \"./staticAbiTypes\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { InvalidHexLengthError, InvalidHexLengthForArrayFieldError } from \"./errors\";\n\n// TODO: require size/length for dynamic fields, because hex might be longer (sometimes we just move the length pointer of arrays without updating the value)\n// this means the error should probably change from \"invalid length\" to \"too short\", which viem has that we could reuse?\n\nexport function decodeDynamicField<\n TAbiType extends DynamicAbiType,\n TPrimitiveType extends DynamicAbiTypeToPrimitiveType<TAbiType>\n>(abiType: TAbiType, data: Hex): TPrimitiveType {\n if (abiType === \"bytes\") {\n return data as TPrimitiveType;\n }\n if (abiType === \"string\") {\n return hexToString(data) as TPrimitiveType;\n }\n\n if (data.length > 3 && data.length % 2 !== 0) {\n throw new InvalidHexLengthError(data);\n }\n\n const dataSize = (data.length - 2) / 2;\n\n switch (abiType) {\n case \"uint8[]\":\n case \"uint16[]\":\n case \"uint24[]\":\n case \"uint32[]\":\n case \"uint40[]\":\n case \"uint48[]\":\n case \"uint56[]\":\n case \"uint64[]\":\n case \"uint72[]\":\n case \"uint80[]\":\n case \"uint88[]\":\n case \"uint96[]\":\n case \"uint104[]\":\n case \"uint112[]\":\n case \"uint120[]\":\n case \"uint128[]\":\n case \"uint136[]\":\n case \"uint144[]\":\n case \"uint152[]\":\n case \"uint160[]\":\n case \"uint168[]\":\n case \"uint176[]\":\n case \"uint184[]\":\n case \"uint192[]\":\n case \"uint200[]\":\n case \"uint208[]\":\n case \"uint216[]\":\n case \"uint224[]\":\n case \"uint232[]\":\n case \"uint240[]\":\n case \"uint248[]\":\n case \"uint256[]\":\n case \"int8[]\":\n case \"int16[]\":\n case \"int24[]\":\n case \"int32[]\":\n case \"int40[]\":\n case \"int48[]\":\n case \"int56[]\":\n case \"int64[]\":\n case \"int72[]\":\n case \"int80[]\":\n case \"int88[]\":\n case \"int96[]\":\n case \"int104[]\":\n case \"int112[]\":\n case \"int120[]\":\n case \"int128[]\":\n case \"int136[]\":\n case \"int144[]\":\n case \"int152[]\":\n case \"int160[]\":\n case \"int168[]\":\n case \"int176[]\":\n case \"int184[]\":\n case \"int192[]\":\n case \"int200[]\":\n case \"int208[]\":\n case \"int216[]\":\n case \"int224[]\":\n case \"int232[]\":\n case \"int240[]\":\n case \"int248[]\":\n case \"int256[]\":\n case \"bytes1[]\":\n case \"bytes2[]\":\n case \"bytes3[]\":\n case \"bytes4[]\":\n case \"bytes5[]\":\n case \"bytes6[]\":\n case \"bytes7[]\":\n case \"bytes8[]\":\n case \"bytes9[]\":\n case \"bytes10[]\":\n case \"bytes11[]\":\n case \"bytes12[]\":\n case \"bytes13[]\":\n case \"bytes14[]\":\n case \"bytes15[]\":\n case \"bytes16[]\":\n case \"bytes17[]\":\n case \"bytes18[]\":\n case \"bytes19[]\":\n case \"bytes20[]\":\n case \"bytes21[]\":\n case \"bytes22[]\":\n case \"bytes23[]\":\n case \"bytes24[]\":\n case \"bytes25[]\":\n case \"bytes26[]\":\n case \"bytes27[]\":\n case \"bytes28[]\":\n case \"bytes29[]\":\n case \"bytes30[]\":\n case \"bytes31[]\":\n case \"bytes32[]\":\n case \"bool[]\":\n case \"address[]\": {\n const staticAbiType = arrayAbiTypeToStaticAbiType(abiType);\n const itemByteLength = staticAbiTypeToByteLength[staticAbiType];\n if (dataSize % itemByteLength !== 0) {\n throw new InvalidHexLengthForArrayFieldError(staticAbiType, data);\n }\n const items = new Array(dataSize / itemByteLength).fill(undefined).map((_, i) => {\n const itemData = sliceHex(data, i * itemByteLength, (i + 1) * itemByteLength);\n return decodeStaticField(staticAbiType, itemData);\n });\n return items as TPrimitiveType;\n }\n }\n\n return assertExhaustive(abiType, `Unsupported dynamic ABI type: ${abiType}`);\n}\n","export function assertExhaustive(value: never, message?: string): never {\n throw new Error(message ?? `Unexpected value: ${value}`);\n}\n","import { Hex, getAddress, hexToBigInt, hexToBool } from \"viem\";\nimport {\n StaticAbiType,\n StaticAbiTypeToPrimitiveType,\n staticAbiTypeToByteLength,\n staticAbiTypeToDefaultValue,\n} from \"./staticAbiTypes\";\nimport { assertExhaustive } from \"./assertExhaustive\";\nimport { InvalidHexLengthError, InvalidHexLengthForStaticFieldError } from \"./errors\";\n\nexport function decodeStaticField<\n TAbiType extends StaticAbiType,\n TPrimitiveType extends StaticAbiTypeToPrimitiveType<TAbiType>\n>(abiType: TAbiType, data: Hex): TPrimitiveType {\n if (data.length > 3 && data.length % 2 !== 0) {\n throw new InvalidHexLengthError(data);\n }\n\n const dataSize = (data.length - 2) / 2;\n if (dataSize !== staticAbiTypeToByteLength[abiType]) {\n throw new InvalidHexLengthForStaticFieldError(abiType, data);\n }\n\n switch (abiType) {\n case \"uint8\":\n case \"uint16\":\n case \"uint24\":\n case \"uint32\":\n case \"uint40\":\n case \"uint48\":\n case \"uint56\":\n case \"uint64\":\n case \"uint72\":\n case \"uint80\":\n case \"uint88\":\n case \"uint96\":\n case \"uint104\":\n case \"uint112\":\n case \"uint120\":\n case \"uint128\":\n case \"uint136\":\n case \"uint144\":\n case \"uint152\":\n case \"uint160\":\n case \"uint168\":\n case \"uint176\":\n case \"uint184\":\n case \"uint192\":\n case \"uint200\":\n case \"uint208\":\n case \"uint216\":\n case \"uint224\":\n case \"uint232\":\n case \"uint240\":\n case \"uint248\":\n case \"uint256\":\n case \"int8\":\n case \"int16\":\n case \"int24\":\n case \"int32\":\n case \"int40\":\n case \"int48\":\n case \"int56\":\n case \"int64\":\n case \"int72\":\n case \"int80\":\n case \"int88\":\n case \"int96\":\n case \"int104\":\n case \"int112\":\n case \"int120\":\n case \"int128\":\n case \"int136\":\n case \"int144\":\n case \"int152\":\n case \"int160\":\n case \"int168\":\n case \"int176\":\n case \"int184\":\n case \"int192\":\n case \"int200\":\n case \"int208\":\n case \"int216\":\n case \"int224\":\n case \"int232\":\n case \"int240\":\n case \"int248\":\n case \"int256\": {\n const value = hexToBigInt(data, { signed: abiType.startsWith(\"int\") });\n const defaultValueType = typeof staticAbiTypeToDefaultValue[abiType];\n if (defaultValueType === \"number\") {\n return Number(value) as TPrimitiveType;\n }\n if (defaultValueType === \"bigint\") {\n return value as TPrimitiveType;\n }\n throw new Error(`Unexpected default value type (${defaultValueType}) for ABI type (${abiType})`);\n }\n\n case \"bytes1\":\n case \"bytes2\":\n case \"bytes3\":\n case \"bytes4\":\n case \"bytes5\":\n case \"bytes6\":\n case \"bytes7\":\n case \"bytes8\":\n case \"bytes9\":\n case \"bytes10\":\n case \"bytes11\":\n case \"bytes12\":\n case \"bytes13\":\n case \"bytes14\":\n case \"bytes15\":\n case \"bytes16\":\n case \"bytes17\":\n case \"bytes18\":\n case \"bytes19\":\n case \"bytes20\":\n case \"bytes21\":\n case \"bytes22\":\n case \"bytes23\":\n case \"bytes24\":\n case \"bytes25\":\n case \"bytes26\":\n case \"bytes27\":\n case \"bytes28\":\n case \"bytes29\":\n case \"bytes30\":\n case \"bytes31\":\n case \"bytes32\": {\n return data as TPrimitiveType;\n }\n\n case \"bool\": {\n return hexToBool(data) as TPrimitiveType;\n }\n\n case \"address\": {\n return getAddress(data) as TPrimitiveType;\n }\n }\n\n return assertExhaustive(abiType, `Unsupported static ABI type: ${abiType}`);\n}\n","import { MUDError } from \"@latticexyz/common/errors\";\nimport { Hex } from \"viem\";\nimport { StaticAbiType, staticAbiTypeToByteLength } from \"./staticAbiTypes\";\n\nexport class InvalidHexLengthError extends MUDError {\n override name = \"InvalidHexValueError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" is an odd length (${value.length - 2}). It must be an even length.`);\n }\n}\n\nexport class InvalidHexLengthForSchemaError extends MUDError {\n override name = \"InvalidHexLengthForSchemaError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" has length of ${value.length - 2}, but expected length of 64 for a schema.`);\n }\n}\n\nexport class InvalidHexLengthForPackedCounterError extends MUDError {\n override name = \"InvalidHexLengthForPackedCounterError\";\n constructor(value: Hex) {\n super(`Hex value \"${value}\" has length of ${value.length - 2}, but expected length of 64 for a packed counter.`);\n }\n}\n\nexport class InvalidHexLengthForStaticFieldError extends MUDError {\n override name = \"InvalidHexLengthForStaticFieldError\";\n constructor(abiType: StaticAbiType, value: Hex) {\n super(\n `Hex value \"${value}\" has length of ${value.length - 2}, but expected length of ${\n staticAbiTypeToByteLength[abiType] * 2\n } for ${abiType} type.`\n );\n }\n}\n\nexport class InvalidHexLengthForArrayFieldError extends MUDError {\n override name = \"InvalidHexLengthForArrayFieldError\";\n constructor(abiType: StaticAbiType, value: Hex) {\n super(\n `Hex value \"${value}\" has length of ${value.length - 2}, but expected a multiple of ${\n staticAbiTypeToByteLength[abiType] * 2\n } for ${abiType}[] type.`\n );\n }\n}\n\nexport class SchemaStaticLengthMismatchError extends MUDError {\n override name = \"SchemaStaticLengthMismatchError\";\n constructor(schemaData: Hex, definedLength: number, summedLength: number) {\n super(\n `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?`\n );\n }\n}\n\nexport class PackedCounterLengthMismatchError extends MUDError {\n override name = \"PackedCounterLengthMismatchError\";\n constructor(packedCounterData: Hex, definedLength: bigint, summedLength: bigint) {\n super(\n `PackedCounter \"${packedCounterData}\" total bytes length (${definedLength}) did not match the summed length of all field byte lengths (${summedLength}).`\n );\n }\n}\n","import { Schema } from \"./common\";\nimport { Hex, decodeAbiParameters } from \"viem\";\nimport { StaticPrimitiveType } from \"./staticAbiTypes\";\n\n// key tuples are encoded in the same way as abi.encode, so we can decode them with viem\n\nexport function decodeKeyTuple(keySchema: Schema, keyTuple: Hex[]): StaticPrimitiveType[] {\n return keyTuple.map(\n (key, index) => decodeAbiParameters([{ type: keySchema.staticFields[index] }], key)[0] as StaticPrimitiveType\n );\n}\n","import { Hex, sliceHex } from \"viem\";\nimport { decodeStaticField } from \"./decodeStaticField\";\nimport { decodeDynamicField } from \"./decodeDynamicField\";\nimport { InvalidHexLengthForPackedCounterError, PackedCounterLengthMismatchError } from \"./errors\";\n\n// Keep this logic in sync with PackedCounter.sol\n\n// - First 7 bytes (uint56) are used for the total byte length of the dynamic data\n// - 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\n\n// 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)\n\nexport function hexToPackedCounter(data: Hex): {\n totalByteLength: bigint;\n fieldByteLengths: number[];\n} {\n if (data.length !== 66) {\n throw new InvalidHexLengthForPackedCounterError(data);\n }\n const totalByteLength = decodeStaticField(\"uint56\", sliceHex(data, 0, 7));\n\n // TODO: use schema to make sure we only parse as many as we need (rather than zeroes at the end)?\n const fieldByteLengths = decodeDynamicField(\"uint40[]\", sliceHex(data, 7));\n\n const summedLength = BigInt(fieldByteLengths.reduce((a, b) => a + b, 0));\n if (summedLength !== totalByteLength) {\n throw new PackedCounterLengthMismatchError(data, totalByteLength, summedLength);\n }\n\n return { totalByteLength, fieldByteLengths };\n}\n","import { Hex, hexToNumber, sliceHex } from \"viem\";\nimport { Schema } from \"./common\";\nimport { StaticAbiType, staticAbiTypeToByteLength } from \"./staticAbiTypes\";\nimport { DynamicAbiType } from \"./dynamicAbiTypes\";\nimport { schemaAbiTypes } from \"./schemaAbiTypes\";\nimport { InvalidHexLengthForSchemaError, SchemaStaticLengthMismatchError } from \"./errors\";\n\nexport function hexToSchema(data: Hex): Schema {\n if (data.length !== 66) {\n throw new InvalidHexLengthForSchemaError(data);\n }\n\n const staticDataLength = hexToNumber(sliceHex(data, 0, 2));\n const numStaticFields = hexToNumber(sliceHex(data, 2, 3));\n const numDynamicFields = hexToNumber(sliceHex(data, 3, 4));\n const staticFields: StaticAbiType[] = [];\n const dynamicFields: DynamicAbiType[] = [];\n\n for (let i = 4; i < 4 + numStaticFields; i++) {\n const schemaTypeIndex = hexToNumber(sliceHex(data, i, i + 1));\n staticFields.push(schemaAbiTypes[schemaTypeIndex] as StaticAbiType);\n }\n for (let i = 4 + numStaticFields; i < 4 + numStaticFields + numDynamicFields; i++) {\n const schemaTypeIndex = hexToNumber(sliceHex(data, i, i + 1));\n dynamicFields.push(schemaAbiTypes[schemaTypeIndex] as DynamicAbiType);\n }\n\n // validate static data length\n const actualStaticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);\n if (actualStaticDataLength !== staticDataLength) {\n throw new SchemaStaticLengthMismatchError(data, staticDataLength, actualStaticDataLength);\n }\n\n return {\n staticDataLength,\n staticFields,\n dynamicFields,\n isEmpty: data === \"0x\",\n schemaData: data,\n };\n}\n","import { Hex, sliceHex } from \"viem\";\nimport { TableSchema } from \"./common\";\nimport { hexToSchema } from \"./hexToSchema\";\n\nexport function hexToTableSchema(data: Hex): TableSchema {\n const valueSchema = hexToSchema(sliceHex(data, 0, 32));\n const keySchema = hexToSchema(sliceHex(data, 32, 64));\n return {\n keySchema,\n valueSchema,\n isEmpty: data === \"0x\",\n schemaData: data,\n };\n}\n"],"mappings":"AAKO,IAAMA,EAAiB,CAC5B,QACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,OACA,QACA,QACA,QACA,QACA,QACA,QACA,QACA,QACA,QACA,QACA,QACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,SACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,OACA,UACA,UACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,SACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,UACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,YACA,SACA,YACA,QACA,QACF,EAKaC,EAAiBD,EAAe,MAAM,EAAG,EAAE,EAC3CE,EAAkBF,EAAe,MAAM,EAAE,ECvM/C,IAAMG,EAA8B,CACzC,MAAO,EACP,OAAQ,EACR,OAAQ,EACR,OAAQ,EACR,OAAQ,EACR,OAAQ,EACR,OAAQ,GACR,OAAQ,GACR,OAAQ,GACR,OAAQ,GACR,OAAQ,GACR,OAAQ,GACR,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,QAAS,GACT,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AbiTypes","staticAbiTypes","dynamicAbiTypes","staticAbiTypeToDefaultValue","staticAbiTypeToByteLength","abiTypesToSchemaData","staticFields","dynamicFields","staticDataLength","acc","fieldType","staticAbiTypeToByteLength","numStaticFields","numDynamicFields","staticSchemaTypes","abiType","schemaAbiTypes","dynamicSchemaTypes","schemaType","abiTypesToSchema","staticFields","dynamicFields","acc","fieldType","staticAbiTypeToByteLength","abiTypesToSchemaData","dynamicAbiTypeToDefaultValue","arrayAbiTypeToStaticAbiType","abiType","abiTypeToDefaultValue","staticAbiTypeToDefaultValue","dynamicAbiTypeToDefaultValue","hexToString","sliceHex","assertExhaustive","value","message","getAddress","hexToBigInt","hexToBool","MUDError","InvalidHexLengthError","MUDError","value","InvalidHexLengthForSchemaError","InvalidHexLengthForPackedCounterError","InvalidHexLengthForStaticFieldError","abiType","staticAbiTypeToByteLength","InvalidHexLengthForArrayFieldError","SchemaStaticLengthMismatchError","schemaData","definedLength","summedLength","PackedCounterLengthMismatchError","packedCounterData","decodeStaticField","abiType","data","InvalidHexLengthError","staticAbiTypeToByteLength","InvalidHexLengthForStaticFieldError","value","hexToBigInt","defaultValueType","staticAbiTypeToDefaultValue","hexToBool","getAddress","assertExhaustive","decodeDynamicField","abiType","data","hexToString","InvalidHexLengthError","dataSize","staticAbiType","arrayAbiTypeToStaticAbiType","itemByteLength","staticAbiTypeToByteLength","InvalidHexLengthForArrayFieldError","_","i","itemData","sliceHex","decodeStaticField","assertExhaustive","decodeAbiParameters","decodeKeyTuple","keySchema","keyTuple","key","index","sliceHex","hexToPackedCounter","data","InvalidHexLengthForPackedCounterError","totalByteLength","decodeStaticField","sliceHex","fieldByteLengths","decodeDynamicField","summedLength","b","PackedCounterLengthMismatchError","hexToNumber","sliceHex","hexToSchema","data","InvalidHexLengthForSchemaError","staticDataLength","hexToNumber","sliceHex","numStaticFields","numDynamicFields","staticFields","dynamicFields","i","schemaTypeIndex","schemaAbiTypes","actualStaticDataLength","acc","fieldType","staticAbiTypeToByteLength","SchemaStaticLengthMismatchError","sliceHex","hexToTableSchema","data","valueSchema","hexToSchema","sliceHex"]}
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@latticexyz/protocol-parser",
3
+ "version": "2.0.0-alpha.1.222+7c2d6351",
4
+ "description": "Parser utilities for the MUD protocol",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/latticexyz/mud.git",
8
+ "directory": "packages/protocol-parser"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": "./dist/index.js"
14
+ },
15
+ "types": "src/index.ts",
16
+ "scripts": {
17
+ "build": "pnpm run build:js",
18
+ "build:js": "tsup",
19
+ "clean": "pnpm run clean:js",
20
+ "clean:js": "rimraf dist",
21
+ "dev": "tsup --watch",
22
+ "lint": "eslint .",
23
+ "test": "vitest typecheck --run && vitest --run"
24
+ },
25
+ "dependencies": {
26
+ "@latticexyz/common": "2.0.0-alpha.1.222+7c2d6351",
27
+ "@latticexyz/config": "2.0.0-alpha.1.222+7c2d6351",
28
+ "@latticexyz/schema-type": "2.0.0-alpha.1.222+7c2d6351",
29
+ "@latticexyz/store": "2.0.0-alpha.1.222+7c2d6351",
30
+ "abitype": "0.8.7",
31
+ "viem": "1.0.6"
32
+ },
33
+ "devDependencies": {
34
+ "tsup": "^6.7.0",
35
+ "vitest": "0.31.4"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public"
39
+ },
40
+ "gitHead": "7c2d6351294741009c6631441b5395cddef4aabc"
41
+ }
@@ -0,0 +1,8 @@
1
+ import { SchemaAbiType } from "./schemaAbiTypes";
2
+ import { DynamicAbiTypeToPrimitiveType, dynamicAbiTypeToDefaultValue } from "./dynamicAbiTypes";
3
+ import { StaticAbiTypeToPrimitiveType, staticAbiTypeToDefaultValue } from "./staticAbiTypes";
4
+
5
+ export const abiTypeToDefaultValue = {
6
+ ...staticAbiTypeToDefaultValue,
7
+ ...dynamicAbiTypeToDefaultValue,
8
+ } as const satisfies Record<SchemaAbiType, StaticAbiTypeToPrimitiveType | DynamicAbiTypeToPrimitiveType>;
@@ -0,0 +1,28 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { abiTypesToSchema } from "./abiTypesToSchema";
3
+
4
+ describe("abiTypesToSchema", () => {
5
+ it("encodes schema from ABI types", () => {
6
+ expect(abiTypesToSchema(["bool"])).toStrictEqual({
7
+ staticDataLength: 1,
8
+ staticFields: ["bool"],
9
+ dynamicFields: [],
10
+ isEmpty: false,
11
+ schemaData: "0x0001010060000000000000000000000000000000000000000000000000000000",
12
+ });
13
+ expect(abiTypesToSchema(["bool"], ["bool[]"])).toStrictEqual({
14
+ staticDataLength: 1,
15
+ staticFields: ["bool"],
16
+ dynamicFields: ["bool[]"],
17
+ isEmpty: false,
18
+ schemaData: "0x0001010160c20000000000000000000000000000000000000000000000000000",
19
+ });
20
+ expect(abiTypesToSchema(["bytes32", "int32"], ["uint256[]", "address[]", "bytes", "string"])).toStrictEqual({
21
+ staticDataLength: 36,
22
+ staticFields: ["bytes32", "int32"],
23
+ dynamicFields: ["uint256[]", "address[]", "bytes", "string"],
24
+ isEmpty: false,
25
+ schemaData: "0x002402045f2381c3c4c500000000000000000000000000000000000000000000",
26
+ });
27
+ });
28
+ });
@@ -0,0 +1,15 @@
1
+ import { Schema } from "./common";
2
+ import { DynamicAbiType } from "./dynamicAbiTypes";
3
+ import { StaticAbiType, staticAbiTypeToByteLength } from "./staticAbiTypes";
4
+ import { abiTypesToSchemaData } from "./abiTypesToSchemaData";
5
+
6
+ export function abiTypesToSchema(staticFields: StaticAbiType[], dynamicFields: DynamicAbiType[] = []): Schema {
7
+ const staticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);
8
+ return {
9
+ staticDataLength,
10
+ staticFields,
11
+ dynamicFields,
12
+ isEmpty: false,
13
+ schemaData: abiTypesToSchemaData(staticFields, dynamicFields),
14
+ };
15
+ }
@@ -0,0 +1,14 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { abiTypesToSchemaData } from "./abiTypesToSchemaData";
3
+
4
+ describe("abiTypesToSchemaData", () => {
5
+ it("encodes schema data from ABI types", () => {
6
+ expect(abiTypesToSchemaData(["bool"])).toBe("0x0001010060000000000000000000000000000000000000000000000000000000");
7
+ expect(abiTypesToSchemaData(["bool"], ["bool[]"])).toBe(
8
+ "0x0001010160c20000000000000000000000000000000000000000000000000000"
9
+ );
10
+ expect(abiTypesToSchemaData(["bytes32", "int32"], ["uint256[]", "address[]", "bytes", "string"])).toBe(
11
+ "0x002402045f2381c3c4c500000000000000000000000000000000000000000000"
12
+ );
13
+ });
14
+ });
@@ -0,0 +1,21 @@
1
+ import { Hex } from "viem";
2
+ import { DynamicAbiType } from "./dynamicAbiTypes";
3
+ import { schemaAbiTypes } from "./schemaAbiTypes";
4
+ import { StaticAbiType, staticAbiTypeToByteLength } from "./staticAbiTypes";
5
+
6
+ export function abiTypesToSchemaData(staticFields: StaticAbiType[], dynamicFields: DynamicAbiType[] = []): Hex {
7
+ const staticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);
8
+ const numStaticFields = staticFields.length;
9
+ const numDynamicFields = dynamicFields.length;
10
+ const staticSchemaTypes = staticFields.map((abiType) => schemaAbiTypes.indexOf(abiType));
11
+ const dynamicSchemaTypes = dynamicFields.map((abiType) => schemaAbiTypes.indexOf(abiType));
12
+ return `0x${[
13
+ staticDataLength.toString(16).padStart(4, "0"),
14
+ numStaticFields.toString(16).padStart(2, "0"),
15
+ numDynamicFields.toString(16).padStart(2, "0"),
16
+ ...staticSchemaTypes.map((schemaType) => schemaType.toString(16).padStart(2, "0")),
17
+ ...dynamicSchemaTypes.map((schemaType) => schemaType.toString(16).padStart(2, "0")),
18
+ ]
19
+ .join("")
20
+ .padEnd(64, "0")}`;
21
+ }
@@ -0,0 +1,3 @@
1
+ export function assertExhaustive(value: never, message?: string): never {
2
+ throw new Error(message ?? `Unexpected value: ${value}`);
3
+ }
package/src/common.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { Hex } from "viem";
2
+ import { DynamicAbiType } from "./dynamicAbiTypes";
3
+ import { StaticAbiType } from "./staticAbiTypes";
4
+
5
+ export type Schema = Readonly<{
6
+ staticDataLength: number;
7
+ staticFields: StaticAbiType[];
8
+ dynamicFields: DynamicAbiType[];
9
+ isEmpty: boolean;
10
+ schemaData: Hex;
11
+ }>;
12
+
13
+ export type TableSchema = { keySchema: Schema; valueSchema: Schema; isEmpty: boolean; schemaData: Hex };
@@ -0,0 +1,48 @@
1
+ import { assertType, describe, it } from "vitest";
2
+ import { decodeDynamicField } from "./decodeDynamicField";
3
+ import { Hex } from "viem";
4
+
5
+ describe("decodeDynamicField", () => {
6
+ it("returns a boolean array for bool[] ABI type", () => {
7
+ assertType<boolean[]>(decodeDynamicField("bool[]", "0x"));
8
+ });
9
+
10
+ it("returns a number array or bigint array for uint[] ABI types", () => {
11
+ assertType<number[]>(decodeDynamicField("uint8[]", "0x"));
12
+ assertType<number[]>(decodeDynamicField("uint16[]", "0x"));
13
+ assertType<number[]>(decodeDynamicField("uint32[]", "0x"));
14
+ assertType<number[]>(decodeDynamicField("uint48[]", "0x"));
15
+ assertType<bigint[]>(decodeDynamicField("uint56[]", "0x"));
16
+ assertType<bigint[]>(decodeDynamicField("uint128[]", "0x"));
17
+ assertType<bigint[]>(decodeDynamicField("uint256[]", "0x"));
18
+ });
19
+
20
+ it("returns a number array or bigint array for int[] ABI types", () => {
21
+ assertType<number[]>(decodeDynamicField("int8[]", "0x"));
22
+ assertType<number[]>(decodeDynamicField("int16[]", "0x"));
23
+ assertType<number[]>(decodeDynamicField("int32[]", "0x"));
24
+ assertType<number[]>(decodeDynamicField("int48[]", "0x"));
25
+ assertType<bigint[]>(decodeDynamicField("int56[]", "0x"));
26
+ assertType<bigint[]>(decodeDynamicField("int128[]", "0x"));
27
+ assertType<bigint[]>(decodeDynamicField("int256[]", "0x"));
28
+ });
29
+
30
+ it("returns a hex array for bytes[] ABI types", () => {
31
+ assertType<Hex[]>(decodeDynamicField("bytes1[]", "0x"));
32
+ assertType<Hex[]>(decodeDynamicField("bytes2[]", "0x"));
33
+ assertType<Hex[]>(decodeDynamicField("bytes8[]", "0x"));
34
+ assertType<Hex[]>(decodeDynamicField("bytes32[]", "0x"));
35
+ });
36
+
37
+ it("returns a hex array for address ABI type", () => {
38
+ assertType<Hex[]>(decodeDynamicField("address[]", "0x"));
39
+ });
40
+
41
+ it("returns a hex for bytes ABI type", () => {
42
+ assertType<Hex>(decodeDynamicField("bytes", "0x"));
43
+ });
44
+
45
+ it("returns a string for string ABI type", () => {
46
+ assertType<string>(decodeDynamicField("string", "0x"));
47
+ });
48
+ });
@@ -0,0 +1,175 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { decodeDynamicField } from "./decodeDynamicField";
3
+
4
+ describe("decodeDynamicField", () => {
5
+ it("can decode bool[]", () => {
6
+ expect(decodeDynamicField("bool[]", "0x00")).toStrictEqual([false]);
7
+ expect(decodeDynamicField("bool[]", "0x01")).toStrictEqual([true]);
8
+ expect(decodeDynamicField("bool[]", "0x0000")).toStrictEqual([false, false]);
9
+ expect(decodeDynamicField("bool[]", "0x0001")).toStrictEqual([false, true]);
10
+ expect(decodeDynamicField("bool[]", "0x0100")).toStrictEqual([true, false]);
11
+ expect(decodeDynamicField("bool[]", "0x0101")).toStrictEqual([true, true]);
12
+ });
13
+
14
+ it("can decode uint8[]", () => {
15
+ expect(decodeDynamicField("uint8[]", "0x00")).toStrictEqual([0]);
16
+ expect(decodeDynamicField("uint8[]", "0x01")).toStrictEqual([1]);
17
+ expect(decodeDynamicField("uint8[]", "0xff")).toStrictEqual([255]);
18
+ expect(decodeDynamicField("uint8[]", "0x0000")).toStrictEqual([0, 0]);
19
+ expect(decodeDynamicField("uint8[]", "0x0101")).toStrictEqual([1, 1]);
20
+ expect(decodeDynamicField("uint8[]", "0xffff")).toStrictEqual([255, 255]);
21
+ });
22
+
23
+ it("can decode uint256[]", () => {
24
+ expect(
25
+ decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000000")
26
+ ).toStrictEqual([0n]);
27
+ expect(
28
+ decodeDynamicField("uint256[]", "0x0000000000000000000000000000000000000000000000000000000000000001")
29
+ ).toStrictEqual([1n]);
30
+ expect(
31
+ decodeDynamicField("uint256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
32
+ ).toStrictEqual([115792089237316195423570985008687907853269984665640564039457584007913129639935n]);
33
+ expect(
34
+ decodeDynamicField("uint256[]", "0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe")
35
+ ).toStrictEqual([115792089237316195423570985008687907853269984665640564039457584007913129639934n]);
36
+ expect(
37
+ decodeDynamicField(
38
+ "uint256[]",
39
+ "0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001"
40
+ )
41
+ ).toStrictEqual([1n, 1n]);
42
+ expect(
43
+ decodeDynamicField(
44
+ "uint256[]",
45
+ "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
46
+ )
47
+ ).toStrictEqual([
48
+ 115792089237316195423570985008687907853269984665640564039457584007913129639935n,
49
+ 115792089237316195423570985008687907853269984665640564039457584007913129639935n,
50
+ ]);
51
+ });
52
+
53
+ it("can decode int8[]", () => {
54
+ expect(decodeDynamicField("int8[]", "0x00")).toStrictEqual([0]);
55
+ expect(decodeDynamicField("int8[]", "0x01")).toStrictEqual([1]);
56
+ expect(decodeDynamicField("int8[]", "0x7f")).toStrictEqual([127]);
57
+ expect(decodeDynamicField("int8[]", "0x80")).toStrictEqual([-128]);
58
+ expect(decodeDynamicField("int8[]", "0x81")).toStrictEqual([-127]);
59
+ expect(decodeDynamicField("int8[]", "0xff")).toStrictEqual([-1]);
60
+
61
+ expect(decodeDynamicField("int8[]", "0x0000")).toStrictEqual([0, 0]);
62
+ expect(decodeDynamicField("int8[]", "0x0100")).toStrictEqual([1, 0]);
63
+ expect(decodeDynamicField("int8[]", "0x007f")).toStrictEqual([0, 127]);
64
+ expect(decodeDynamicField("int8[]", "0x8080")).toStrictEqual([-128, -128]);
65
+ expect(decodeDynamicField("int8[]", "0x8181")).toStrictEqual([-127, -127]);
66
+ expect(decodeDynamicField("int8[]", "0x00ff")).toStrictEqual([0, -1]);
67
+ });
68
+
69
+ it("can decode int256[]", () => {
70
+ expect(
71
+ decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000000")
72
+ ).toStrictEqual([0n]);
73
+ expect(
74
+ decodeDynamicField("int256[]", "0x0000000000000000000000000000000000000000000000000000000000000001")
75
+ ).toStrictEqual([1n]);
76
+ expect(
77
+ decodeDynamicField("int256[]", "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
78
+ ).toStrictEqual([57896044618658097711785492504343953926634992332820282019728792003956564819967n]);
79
+ expect(
80
+ decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000000")
81
+ ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819968n]);
82
+ expect(
83
+ decodeDynamicField("int256[]", "0x8000000000000000000000000000000000000000000000000000000000000001")
84
+ ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819967n]);
85
+ expect(
86
+ decodeDynamicField("int256[]", "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
87
+ ).toStrictEqual([-1n]);
88
+
89
+ expect(
90
+ decodeDynamicField(
91
+ "int256[]",
92
+ "0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"
93
+ )
94
+ ).toStrictEqual([57896044618658097711785492504343953926634992332820282019728792003956564819967n, -1n]);
95
+ expect(
96
+ decodeDynamicField(
97
+ "int256[]",
98
+ "0x80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
99
+ )
100
+ ).toStrictEqual([-57896044618658097711785492504343953926634992332820282019728792003956564819968n, 0n]);
101
+ expect(
102
+ decodeDynamicField(
103
+ "int256[]",
104
+ "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8000000000000000000000000000000000000000000000000000000000000001"
105
+ )
106
+ ).toStrictEqual([-1n, -57896044618658097711785492504343953926634992332820282019728792003956564819967n]);
107
+ });
108
+
109
+ it("can decode bytes arrays", () => {
110
+ expect(decodeDynamicField("bytes1[]", "0x01")).toStrictEqual(["0x01"]);
111
+ expect(decodeDynamicField("bytes1[]", "0x0001")).toStrictEqual(["0x00", "0x01"]);
112
+ expect(decodeDynamicField("bytes2[]", "0x0001")).toStrictEqual(["0x0001"]);
113
+ expect(decodeDynamicField("bytes8[]", "0xff00ff00ff00ff00")).toStrictEqual(["0xff00ff00ff00ff00"]);
114
+ expect(decodeDynamicField("bytes1[]", "0xff00ff00ff00ff00")).toStrictEqual([
115
+ "0xff",
116
+ "0x00",
117
+ "0xff",
118
+ "0x00",
119
+ "0xff",
120
+ "0x00",
121
+ "0xff",
122
+ "0x00",
123
+ ]);
124
+ expect(decodeDynamicField("bytes2[]", "0xff00ff00ff00ff00")).toStrictEqual([
125
+ "0xff00",
126
+ "0xff00",
127
+ "0xff00",
128
+ "0xff00",
129
+ ]);
130
+ expect(decodeDynamicField("bytes4[]", "0xff00ff00ff00ff00")).toStrictEqual(["0xff00ff00", "0xff00ff00"]);
131
+ expect(
132
+ decodeDynamicField("bytes32[]", "0x0000000000000000000000000000000000000000000000000000000000000001")
133
+ ).toStrictEqual(["0x0000000000000000000000000000000000000000000000000000000000000001"]);
134
+ expect(
135
+ decodeDynamicField(
136
+ "bytes32[]",
137
+ "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"
138
+ )
139
+ ).toStrictEqual([
140
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
141
+ "0x0000000000000000000000000000000000000000000000000000000000000001",
142
+ ]);
143
+ });
144
+
145
+ it("can decode address[]", () => {
146
+ expect(decodeDynamicField("address[]", "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266")).toStrictEqual([
147
+ "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
148
+ ]);
149
+ expect(decodeDynamicField("address[]", "0xffffffffffffffffffffffffffffffffffffffff")).toStrictEqual([
150
+ "0xFFfFfFffFFfffFFfFFfFFFFFffFFFffffFfFFFfF",
151
+ ]);
152
+
153
+ expect(() => decodeDynamicField("address[]", "0x00")).toThrow(
154
+ 'Hex value "0x00" has length of 2, but expected a multiple of 40 for address[] type.'
155
+ );
156
+ expect(() => decodeDynamicField("address[]", "0xffffffffffffffffffffffffffffffffffffffffff")).toThrow(
157
+ 'Hex value "0xffffffffffffffffffffffffffffffffffffffffff" has length of 42, but expected a multiple of 40 for address[] type.'
158
+ );
159
+ });
160
+
161
+ it("can decode bytes", () => {
162
+ expect(decodeDynamicField("bytes", "0x")).toBe("0x");
163
+ expect(decodeDynamicField("bytes", "0x01")).toBe("0x01");
164
+ expect(decodeDynamicField("bytes", "0x0001")).toBe("0x0001");
165
+ expect(decodeDynamicField("bytes", "0xff00ff00ff00ff00")).toBe("0xff00ff00ff00ff00");
166
+ expect(decodeDynamicField("bytes", "0x0000000000000000000000000000000000000000000000000000000000000001")).toBe(
167
+ "0x0000000000000000000000000000000000000000000000000000000000000001"
168
+ );
169
+ });
170
+
171
+ it("can decode string", () => {
172
+ expect(decodeDynamicField("string", "0x")).toBe("");
173
+ expect(decodeDynamicField("string", "0x68656c6c6f")).toBe("hello");
174
+ });
175
+ });