@latticexyz/protocol-parser 2.0.0-alpha.1.239 → 2.0.0-alpha.1.243

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/dist/index.js CHANGED
@@ -1,2 +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};
1
+ import{staticAbiTypeToByteLength as w}from"@latticexyz/schema-type";import{schemaAbiTypes as S,staticAbiTypeToByteLength as P}from"@latticexyz/schema-type";function A(t,e=[]){let s=t.reduce((i,a)=>i+P[a],0),c=t.length,n=e.length,r=t.map(i=>S.indexOf(i)),y=e.map(i=>S.indexOf(i));return`0x${[s.toString(16).padStart(4,"0"),c.toString(16).padStart(2,"0"),n.toString(16).padStart(2,"0"),...r.map(i=>i.toString(16).padStart(2,"0")),...y.map(i=>i.toString(16).padStart(2,"0"))].join("").padEnd(64,"0")}`}function X(t,e=[]){return{staticDataLength:t.reduce((c,n)=>c+w[n],0),staticFields:t,dynamicFields:e,isEmpty:!1,schemaData:A(t,e)}}import{hexToString as U,sliceHex as z}from"viem";import{assertExhaustive as M}from"@latticexyz/common/utils";import{arrayAbiTypeToStaticAbiType as V,staticAbiTypeToByteLength as N}from"@latticexyz/schema-type";import{getAddress as B,hexToBigInt as E,hexToBool as I}from"viem";import{assertExhaustive as F}from"@latticexyz/common/utils";import{staticAbiTypeToByteLength as k,staticAbiTypeToDefaultValue as C}from"@latticexyz/schema-type";import{MUDError as o}from"@latticexyz/common/errors";import{staticAbiTypeToByteLength as v}from"@latticexyz/schema-type";var m=class extends o{name="InvalidHexValueError";constructor(e){super(`Hex value "${e}" is an odd length (${e.length-2}). It must be an even length.`)}},b=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.`)}},T=class extends o{name="InvalidHexLengthForStaticFieldError";constructor(e,s){super(`Hex value "${s}" has length of ${s.length-2}, but expected length of ${v[e]*2} for ${e} type.`)}},x=class extends o{name="InvalidHexLengthForArrayFieldError";constructor(e,s){super(`Hex value "${s}" has length of ${s.length-2}, but expected a multiple of ${v[e]*2} for ${e}[] type.`)}},f=class extends o{name="SchemaStaticLengthMismatchError";constructor(e,s,c){super(`Schema "${e}" static data length (${s}) did not match the summed length of all static fields (${c}). Is \`staticAbiTypeToByteLength\` up to date with Solidity schema types?`)}},l=class extends o{name="PackedCounterLengthMismatchError";constructor(e,s,c){super(`PackedCounter "${e}" total bytes length (${s}) did not match the summed length of all field byte lengths (${c}).`)}};function d(t,e){if(e.length>3&&e.length%2!==0)throw new m(e);if((e.length-2)/2!==k[t])throw new T(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 c=E(e,{signed:t.startsWith("int")}),n=typeof C[t];if(n==="number")return Number(c);if(n==="bigint")return c;throw new Error(`Unexpected default value type (${n}) 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 I(e);case"address":return B(e)}return F(t,`Unsupported static ABI type: ${t}`)}function H(t,e){if(t==="bytes")return e;if(t==="string")return U(e);if(e.length>3&&e.length%2!==0)throw new m(e);let s=(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 c=V(t),n=N[c];if(s%n!==0)throw new x(c,e);return new Array(s/n).fill(void 0).map((y,i)=>{let a=z(e,i*n,(i+1)*n);return d(c,a)})}}return M(t,`Unsupported dynamic ABI type: ${t}`)}import{decodeAbiParameters as O}from"viem";function Ae(t,e){return e.map((s,c)=>O([{type:t.staticFields[c]}],s)[0])}import{sliceHex as D}from"viem";function we(t){if(t.length!==66)throw new h(t);let e=d("uint56",D(t,0,7)),s=H("uint40[]",D(t,7)),c=BigInt(s.reduce((n,r)=>n+r,0));if(c!==e)throw new l(t,e,c);return{totalByteLength:e,fieldByteLengths:s}}import{hexToNumber as p,sliceHex as u}from"viem";import{staticAbiTypeToByteLength as j,schemaAbiTypes as L}from"@latticexyz/schema-type";function g(t){if(t.length!==66)throw new b(t);let e=p(u(t,0,2)),s=p(u(t,2,3)),c=p(u(t,3,4)),n=[],r=[];for(let i=4;i<4+s;i++){let a=p(u(t,i,i+1));n.push(L[a])}for(let i=4+s;i<4+s+c;i++){let a=p(u(t,i,i+1));r.push(L[a])}let y=n.reduce((i,a)=>i+j[a],0);if(y!==e)throw new f(t,e,y);return{staticDataLength:e,staticFields:n,dynamicFields:r,isEmpty:t==="0x",schemaData:t}}import{sliceHex as $}from"viem";function Oe(t){let e=g($(t,0,32));return{keySchema:g($(t,32,64)),valueSchema:e,isEmpty:t==="0x",schemaData:t}}export{m as InvalidHexLengthError,x as InvalidHexLengthForArrayFieldError,h as InvalidHexLengthForPackedCounterError,b as InvalidHexLengthForSchemaError,T as InvalidHexLengthForStaticFieldError,l as PackedCounterLengthMismatchError,f as SchemaStaticLengthMismatchError,X as abiTypesToSchema,A as abiTypesToSchemaData,H as decodeDynamicField,Ae as decodeKeyTuple,d as decodeStaticField,we as hexToPackedCounter,g as hexToSchema,Oe as hexToTableSchema};
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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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EAAYC,EAASH,EAAM,GAAI,EAAE,CAAC,EAGlD,YAAAC,EACA,QAASD,IAAS,KAClB,WAAYA,CACd,CACF","names":["schemaAbiTypes","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"]}
1
+ {"version":3,"sources":["../src/abiTypesToSchema.ts","../src/abiTypesToSchemaData.ts","../src/decodeDynamicField.ts","../src/decodeStaticField.ts","../src/errors.ts","../src/decodeKeyTuple.ts","../src/hexToPackedCounter.ts","../src/hexToSchema.ts","../src/hexToTableSchema.ts"],"sourcesContent":["import { StaticAbiType, DynamicAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\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 { Hex } from \"viem\";\nimport { schemaAbiTypes, StaticAbiType, DynamicAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\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 { Hex, hexToString, sliceHex } from \"viem\";\nimport { assertExhaustive } from \"@latticexyz/common/utils\";\nimport {\n DynamicAbiType,\n DynamicAbiTypeToPrimitiveType,\n arrayAbiTypeToStaticAbiType,\n staticAbiTypeToByteLength,\n} from \"@latticexyz/schema-type\";\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","import { Hex, getAddress, hexToBigInt, hexToBool } from \"viem\";\nimport { assertExhaustive } from \"@latticexyz/common/utils\";\nimport {\n StaticAbiType,\n StaticAbiTypeToPrimitiveType,\n staticAbiTypeToByteLength,\n staticAbiTypeToDefaultValue,\n} from \"@latticexyz/schema-type\";\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 { Hex } from \"viem\";\nimport { MUDError } from \"@latticexyz/common/errors\";\nimport { StaticAbiType, staticAbiTypeToByteLength } from \"@latticexyz/schema-type\";\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 { Hex, decodeAbiParameters } from \"viem\";\nimport { StaticPrimitiveType } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\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 { StaticAbiType, DynamicAbiType, staticAbiTypeToByteLength, schemaAbiTypes } from \"@latticexyz/schema-type\";\nimport { Schema } from \"./common\";\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":"AAAA,OAAwC,6BAAAA,MAAiC,0BCCzE,OAAS,kBAAAC,EAA+C,6BAAAC,MAAiC,0BAElF,SAASC,EAAqBC,EAA+BC,EAAkC,CAAC,EAAQ,CAC7G,IAAMC,EAAmBF,EAAa,OAAO,CAACG,EAAKC,IAAcD,EAAML,EAA0BM,CAAS,EAAG,CAAC,EACxGC,EAAkBL,EAAa,OAC/BM,EAAmBL,EAAc,OACjCM,EAAoBP,EAAa,IAAKQ,GAAYX,EAAe,QAAQW,CAAO,CAAC,EACjFC,EAAqBR,EAAc,IAAKO,GAAYX,EAAe,QAAQW,CAAO,CAAC,EACzF,MAAO,KAAK,CACVN,EAAiB,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,EAC7CG,EAAgB,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,EAC5CC,EAAiB,SAAS,EAAE,EAAE,S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AI,EAAG,EAAI,EAAIH,EAAiB,IAAK,CAC5C,IAAMI,EAAkBN,EAAYC,EAASJ,EAAM,EAAG,EAAI,CAAC,CAAC,EAC5DO,EAAa,KAAKG,EAAeD,CAAe,CAAkB,EAEpE,QAAS,EAAI,EAAIJ,EAAiB,EAAI,EAAIA,EAAkBC,EAAkB,IAAK,CACjF,IAAMG,EAAkBN,EAAYC,EAASJ,EAAM,EAAG,EAAI,CAAC,CAAC,EAC5DQ,EAAc,KAAKE,EAAeD,CAAe,CAAmB,EAItE,IAAME,EAAyBJ,EAAa,OAAO,CAACK,EAAKC,IAAcD,EAAME,EAA0BD,CAAS,EAAG,CAAC,EACpH,GAAIF,IAA2BT,EAC7B,MAAM,IAAIa,EAAgCf,EAAME,EAAkBS,CAAsB,EAG1F,MAAO,CACL,iBAAAT,EACA,aAAAK,EACA,cAAAC,EACA,QAASR,IAAS,KAClB,WAAYA,CACd,CACF,CCtCA,OAAc,YAAAgB,MAAgB,OAIvB,SAASC,GAAiBC,EAAwB,CACvD,IAAMC,EAAcC,EAAYC,EAASH,EAAM,EAAG,EAAE,CAAC,EAErD,MAAO,CACL,UAFgBE,EAAYC,EAASH,EAAM,GAAI,EAAE,CAAC,EAGlD,YAAAC,EACA,QAASD,IAAS,KAClB,WAAYA,CACd,CACF","names":["staticAbiTypeToByteLength","schemaAbiTypes","staticAbiTypeToByteLength","abiTypesToSchemaData","staticFields","dynamicFields","staticDataLength","acc","fieldType","numStaticFields","numDynamicFields","staticSchemaTypes","abiType","dynamicSchemaTypes","schemaType","abiTypesToSchema","staticFields","dynamicFields","acc","fieldType","staticAbiTypeToByteLength","abiTypesToSchemaData","hexToString","sliceHex","assertExhaustive","arrayAbiTypeToStaticAbiType","staticAbiTypeToByteLength","getAddress","hexToBigInt","hexToBool","assertExhaustive","staticAbiTypeToByteLength","staticAbiTypeToDefaultValue","MUDError","staticAbiTypeToByteLength","InvalidHexLengthError","value","InvalidHexLengthForSchemaError","InvalidHexLengthForPackedCounterError","InvalidHexLengthForStaticFieldError","abiType","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","_","itemData","sliceHex","decodeStaticField","assertExhaustive","decodeAbiParameters","decodeKeyTuple","keySchema","keyTuple","key","index","sliceHex","hexToPackedCounter","data","InvalidHexLengthForPackedCounterError","totalByteLength","decodeStaticField","sliceHex","fieldByteLengths","decodeDynamicField","summedLength","a","b","PackedCounterLengthMismatchError","hexToNumber","sliceHex","staticAbiTypeToByteLength","schemaAbiTypes","hexToSchema","data","InvalidHexLengthForSchemaError","staticDataLength","hexToNumber","sliceHex","numStaticFields","numDynamicFields","staticFields","dynamicFields","schemaTypeIndex","schemaAbiTypes","actualStaticDataLength","acc","fieldType","staticAbiTypeToByteLength","SchemaStaticLengthMismatchError","sliceHex","hexToTableSchema","data","valueSchema","hexToSchema","sliceHex"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/protocol-parser",
3
- "version": "2.0.0-alpha.1.239+5afabfac",
3
+ "version": "2.0.0-alpha.1.243+fc3bd590",
4
4
  "description": "Parser utilities for the MUD protocol",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,10 +23,10 @@
23
23
  "test": "vitest typecheck --run && vitest --run"
24
24
  },
25
25
  "dependencies": {
26
- "@latticexyz/common": "2.0.0-alpha.1.239+5afabfac",
27
- "@latticexyz/config": "2.0.0-alpha.1.239+5afabfac",
28
- "@latticexyz/schema-type": "2.0.0-alpha.1.239+5afabfac",
29
- "@latticexyz/store": "2.0.0-alpha.1.239+5afabfac",
26
+ "@latticexyz/common": "2.0.0-alpha.1.243+fc3bd590",
27
+ "@latticexyz/config": "2.0.0-alpha.1.243+fc3bd590",
28
+ "@latticexyz/schema-type": "2.0.0-alpha.1.243+fc3bd590",
29
+ "@latticexyz/store": "2.0.0-alpha.1.243+fc3bd590",
30
30
  "abitype": "0.8.7",
31
31
  "viem": "1.0.6"
32
32
  },
@@ -37,5 +37,5 @@
37
37
  "publishConfig": {
38
38
  "access": "public"
39
39
  },
40
- "gitHead": "5afabfaca2755b3fe1869f6d8a614ac14836a4c2"
40
+ "gitHead": "fc3bd590c5b3b9f10fe391c0a68e1e99d1dd34cc"
41
41
  }
@@ -1,6 +1,5 @@
1
+ import { StaticAbiType, DynamicAbiType, staticAbiTypeToByteLength } from "@latticexyz/schema-type";
1
2
  import { Schema } from "./common";
2
- import { DynamicAbiType } from "./dynamicAbiTypes";
3
- import { StaticAbiType, staticAbiTypeToByteLength } from "./staticAbiTypes";
4
3
  import { abiTypesToSchemaData } from "./abiTypesToSchemaData";
5
4
 
6
5
  export function abiTypesToSchema(staticFields: StaticAbiType[], dynamicFields: DynamicAbiType[] = []): Schema {
@@ -1,7 +1,5 @@
1
1
  import { Hex } from "viem";
2
- import { DynamicAbiType } from "./dynamicAbiTypes";
3
- import { schemaAbiTypes } from "./schemaAbiTypes";
4
- import { StaticAbiType, staticAbiTypeToByteLength } from "./staticAbiTypes";
2
+ import { schemaAbiTypes, StaticAbiType, DynamicAbiType, staticAbiTypeToByteLength } from "@latticexyz/schema-type";
5
3
 
6
4
  export function abiTypesToSchemaData(staticFields: StaticAbiType[], dynamicFields: DynamicAbiType[] = []): Hex {
7
5
  const staticDataLength = staticFields.reduce((acc, fieldType) => acc + staticAbiTypeToByteLength[fieldType], 0);
package/src/common.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Hex } from "viem";
2
- import { DynamicAbiType } from "./dynamicAbiTypes";
3
- import { StaticAbiType } from "./staticAbiTypes";
2
+ import { DynamicAbiType, StaticAbiType } from "@latticexyz/schema-type";
4
3
 
5
4
  export type Schema = Readonly<{
6
5
  staticDataLength: number;
@@ -1,6 +1,6 @@
1
1
  import { assertType, describe, it } from "vitest";
2
- import { decodeDynamicField } from "./decodeDynamicField";
3
2
  import { Hex } from "viem";
3
+ import { decodeDynamicField } from "./decodeDynamicField";
4
4
 
5
5
  describe("decodeDynamicField", () => {
6
6
  it("returns a boolean array for bool[] ABI type", () => {
@@ -1,7 +1,11 @@
1
1
  import { Hex, hexToString, sliceHex } from "viem";
2
- import { DynamicAbiType, DynamicAbiTypeToPrimitiveType, arrayAbiTypeToStaticAbiType } from "./dynamicAbiTypes";
3
- import { assertExhaustive } from "./assertExhaustive";
4
- import { staticAbiTypeToByteLength } from "./staticAbiTypes";
2
+ import { assertExhaustive } from "@latticexyz/common/utils";
3
+ import {
4
+ DynamicAbiType,
5
+ DynamicAbiTypeToPrimitiveType,
6
+ arrayAbiTypeToStaticAbiType,
7
+ staticAbiTypeToByteLength,
8
+ } from "@latticexyz/schema-type";
5
9
  import { decodeStaticField } from "./decodeStaticField";
6
10
  import { InvalidHexLengthError, InvalidHexLengthForArrayFieldError } from "./errors";
7
11
 
@@ -1,6 +1,6 @@
1
- import { Schema } from "./common";
2
1
  import { Hex, decodeAbiParameters } from "viem";
3
- import { StaticPrimitiveType } from "./staticAbiTypes";
2
+ import { StaticPrimitiveType } from "@latticexyz/schema-type";
3
+ import { Schema } from "./common";
4
4
 
5
5
  // key tuples are encoded in the same way as abi.encode, so we can decode them with viem
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { assertType, describe, it } from "vitest";
2
- import { decodeStaticField } from "./decodeStaticField";
3
2
  import { Hex } from "viem";
3
+ import { decodeStaticField } from "./decodeStaticField";
4
4
 
5
5
  describe("decodeStaticField", () => {
6
6
  it("returns a boolean for bool ABI type", () => {
@@ -1,11 +1,11 @@
1
1
  import { Hex, getAddress, hexToBigInt, hexToBool } from "viem";
2
+ import { assertExhaustive } from "@latticexyz/common/utils";
2
3
  import {
3
4
  StaticAbiType,
4
5
  StaticAbiTypeToPrimitiveType,
5
6
  staticAbiTypeToByteLength,
6
7
  staticAbiTypeToDefaultValue,
7
- } from "./staticAbiTypes";
8
- import { assertExhaustive } from "./assertExhaustive";
8
+ } from "@latticexyz/schema-type";
9
9
  import { InvalidHexLengthError, InvalidHexLengthForStaticFieldError } from "./errors";
10
10
 
11
11
  export function decodeStaticField<
package/src/errors.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { MUDError } from "@latticexyz/common/errors";
2
1
  import { Hex } from "viem";
3
- import { StaticAbiType, staticAbiTypeToByteLength } from "./staticAbiTypes";
2
+ import { MUDError } from "@latticexyz/common/errors";
3
+ import { StaticAbiType, staticAbiTypeToByteLength } from "@latticexyz/schema-type";
4
4
 
5
5
  export class InvalidHexLengthError extends MUDError {
6
6
  override name = "InvalidHexValueError";
@@ -1,8 +1,6 @@
1
1
  import { Hex, hexToNumber, sliceHex } from "viem";
2
+ import { StaticAbiType, DynamicAbiType, staticAbiTypeToByteLength, schemaAbiTypes } from "@latticexyz/schema-type";
2
3
  import { Schema } from "./common";
3
- import { StaticAbiType, staticAbiTypeToByteLength } from "./staticAbiTypes";
4
- import { DynamicAbiType } from "./dynamicAbiTypes";
5
- import { schemaAbiTypes } from "./schemaAbiTypes";
6
4
  import { InvalidHexLengthForSchemaError, SchemaStaticLengthMismatchError } from "./errors";
7
5
 
8
6
  export function hexToSchema(data: Hex): Schema {
package/src/index.ts CHANGED
@@ -1,14 +1,10 @@
1
1
  export * from "./abiTypesToSchema";
2
2
  export * from "./abiTypesToSchemaData";
3
- export * from "./abiTypeToDefaultValue";
4
3
  export * from "./common";
5
4
  export * from "./decodeDynamicField";
6
5
  export * from "./decodeKeyTuple";
7
6
  export * from "./decodeStaticField";
8
- export * from "./dynamicAbiTypes";
9
7
  export * from "./errors";
10
8
  export * from "./hexToPackedCounter";
11
9
  export * from "./hexToSchema";
12
10
  export * from "./hexToTableSchema";
13
- export * from "./schemaAbiTypes";
14
- export * from "./staticAbiTypes";
@@ -1,8 +0,0 @@
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>;
@@ -1,3 +0,0 @@
1
- export function assertExhaustive(value: never, message?: string): never {
2
- throw new Error(message ?? `Unexpected value: ${value}`);
3
- }
@@ -1,66 +0,0 @@
1
- import { describe, expectTypeOf, it } from "vitest";
2
- import { DynamicAbiTypeToPrimitiveType } from "./dynamicAbiTypes";
3
- import { Hex } from "viem";
4
-
5
- describe("DynamicAbiTypeToPrimitiveType", () => {
6
- it("maps uint8 array to number array", () => {
7
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint8[]">>().toMatchTypeOf<number[]>();
8
- });
9
- it("maps uint32 array to number array", () => {
10
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint32[]">>().toMatchTypeOf<number[]>();
11
- });
12
- it("maps uint48 array to number array", () => {
13
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint48[]">>().toMatchTypeOf<number[]>();
14
- });
15
- it("maps uint56 array to bigint array", () => {
16
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint56[]">>().toMatchTypeOf<bigint[]>();
17
- });
18
- it("maps uint256 array to bigint array", () => {
19
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"uint256[]">>().toMatchTypeOf<bigint[]>();
20
- });
21
-
22
- it("maps int8 array to number array", () => {
23
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int8[]">>().toMatchTypeOf<number[]>();
24
- });
25
- it("maps int32 array to number array", () => {
26
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int32[]">>().toMatchTypeOf<number[]>();
27
- });
28
- it("maps int48 array to number array", () => {
29
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int48[]">>().toMatchTypeOf<number[]>();
30
- });
31
- it("maps int56 array to bigint array", () => {
32
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int56[]">>().toMatchTypeOf<bigint[]>();
33
- });
34
- it("maps int256 array to bigint array", () => {
35
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"int256[]">>().toMatchTypeOf<bigint[]>();
36
- });
37
-
38
- it("maps bytes1 array to hex array", () => {
39
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes1[]">>().toMatchTypeOf<Hex[]>();
40
- });
41
- it("maps bytes2 array to hex array", () => {
42
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes2[]">>().toMatchTypeOf<Hex[]>();
43
- });
44
- it("maps bytes8 array to hex array", () => {
45
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes8[]">>().toMatchTypeOf<Hex[]>();
46
- });
47
- it("maps bytes32 array to hex array", () => {
48
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bytes32[]">>().toMatchTypeOf<Hex[]>();
49
- });
50
-
51
- it("maps bool array to boolean array", () => {
52
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"bool[]">>().toMatchTypeOf<boolean[]>();
53
- });
54
-
55
- it("maps address array to hex array", () => {
56
- expectTypeOf<DynamicAbiTypeToPrimitiveType<"address[]">>().toMatchTypeOf<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,131 +0,0 @@
1
- import { StaticAbiType } from "./staticAbiTypes";
2
- import { Hex } from "viem";
3
- import { dynamicAbiTypes } from "./schemaAbiTypes";
4
-
5
- // Variable-length ABI types, where their lengths are defined by a PackedCounter
6
-
7
- export { dynamicAbiTypes };
8
-
9
- export type DynamicAbiType = (typeof dynamicAbiTypes)[number];
10
-
11
- export type DynamicPrimitiveType = number[] | bigint[] | Hex[] | boolean[] | Hex | string;
12
-
13
- export const dynamicAbiTypeToDefaultValue = {
14
- "uint8[]": [] as number[],
15
- "uint16[]": [] as number[],
16
- "uint24[]": [] as number[],
17
- "uint32[]": [] as number[],
18
- "uint40[]": [] as number[],
19
- "uint48[]": [] as number[],
20
- "uint56[]": [] as bigint[],
21
- "uint64[]": [] as bigint[],
22
- "uint72[]": [] as bigint[],
23
- "uint80[]": [] as bigint[],
24
- "uint88[]": [] as bigint[],
25
- "uint96[]": [] as bigint[],
26
- "uint104[]": [] as bigint[],
27
- "uint112[]": [] as bigint[],
28
- "uint120[]": [] as bigint[],
29
- "uint128[]": [] as bigint[],
30
- "uint136[]": [] as bigint[],
31
- "uint144[]": [] as bigint[],
32
- "uint152[]": [] as bigint[],
33
- "uint160[]": [] as bigint[],
34
- "uint168[]": [] as bigint[],
35
- "uint176[]": [] as bigint[],
36
- "uint184[]": [] as bigint[],
37
- "uint192[]": [] as bigint[],
38
- "uint200[]": [] as bigint[],
39
- "uint208[]": [] as bigint[],
40
- "uint216[]": [] as bigint[],
41
- "uint224[]": [] as bigint[],
42
- "uint232[]": [] as bigint[],
43
- "uint240[]": [] as bigint[],
44
- "uint248[]": [] as bigint[],
45
- "uint256[]": [] as bigint[],
46
-
47
- "int8[]": [] as number[],
48
- "int16[]": [] as number[],
49
- "int24[]": [] as number[],
50
- "int32[]": [] as number[],
51
- "int40[]": [] as number[],
52
- "int48[]": [] as number[],
53
- "int56[]": [] as bigint[],
54
- "int64[]": [] as bigint[],
55
- "int72[]": [] as bigint[],
56
- "int80[]": [] as bigint[],
57
- "int88[]": [] as bigint[],
58
- "int96[]": [] as bigint[],
59
- "int104[]": [] as bigint[],
60
- "int112[]": [] as bigint[],
61
- "int120[]": [] as bigint[],
62
- "int128[]": [] as bigint[],
63
- "int136[]": [] as bigint[],
64
- "int144[]": [] as bigint[],
65
- "int152[]": [] as bigint[],
66
- "int160[]": [] as bigint[],
67
- "int168[]": [] as bigint[],
68
- "int176[]": [] as bigint[],
69
- "int184[]": [] as bigint[],
70
- "int192[]": [] as bigint[],
71
- "int200[]": [] as bigint[],
72
- "int208[]": [] as bigint[],
73
- "int216[]": [] as bigint[],
74
- "int224[]": [] as bigint[],
75
- "int232[]": [] as bigint[],
76
- "int240[]": [] as bigint[],
77
- "int248[]": [] as bigint[],
78
- "int256[]": [] as bigint[],
79
-
80
- "bytes1[]": [] as Hex[],
81
- "bytes2[]": [] as Hex[],
82
- "bytes3[]": [] as Hex[],
83
- "bytes4[]": [] as Hex[],
84
- "bytes5[]": [] as Hex[],
85
- "bytes6[]": [] as Hex[],
86
- "bytes7[]": [] as Hex[],
87
- "bytes8[]": [] as Hex[],
88
- "bytes9[]": [] as Hex[],
89
- "bytes10[]": [] as Hex[],
90
- "bytes11[]": [] as Hex[],
91
- "bytes12[]": [] as Hex[],
92
- "bytes13[]": [] as Hex[],
93
- "bytes14[]": [] as Hex[],
94
- "bytes15[]": [] as Hex[],
95
- "bytes16[]": [] as Hex[],
96
- "bytes17[]": [] as Hex[],
97
- "bytes18[]": [] as Hex[],
98
- "bytes19[]": [] as Hex[],
99
- "bytes20[]": [] as Hex[],
100
- "bytes21[]": [] as Hex[],
101
- "bytes22[]": [] as Hex[],
102
- "bytes23[]": [] as Hex[],
103
- "bytes24[]": [] as Hex[],
104
- "bytes25[]": [] as Hex[],
105
- "bytes26[]": [] as Hex[],
106
- "bytes27[]": [] as Hex[],
107
- "bytes28[]": [] as Hex[],
108
- "bytes29[]": [] as Hex[],
109
- "bytes30[]": [] as Hex[],
110
- "bytes31[]": [] as Hex[],
111
- "bytes32[]": [] as Hex[],
112
-
113
- "bool[]": [] as boolean[],
114
- "address[]": [] as Hex[],
115
-
116
- bytes: "0x",
117
- string: "",
118
- } as const satisfies Record<DynamicAbiType, DynamicPrimitiveType>;
119
-
120
- export type DynamicAbiTypeToPrimitiveType<TDynamicAbiType extends DynamicAbiType = DynamicAbiType> =
121
- (typeof dynamicAbiTypeToDefaultValue)[TDynamicAbiType];
122
-
123
- export type ArrayAbiTypeToStaticAbiType<T extends string> = T extends `${infer StaticAbiType}[]`
124
- ? StaticAbiType
125
- : never;
126
-
127
- export function arrayAbiTypeToStaticAbiType<T extends `${StaticAbiType}[]`>(
128
- abiType: T
129
- ): ArrayAbiTypeToStaticAbiType<T> {
130
- return abiType.replace(/\[\]$/g, "") as ArrayAbiTypeToStaticAbiType<T>;
131
- }
@@ -1,211 +0,0 @@
1
- import { AbiType } from "abitype";
2
- import { TupleSplit } from "./utils";
3
-
4
- // Keep this array in sync with SchemaType.sol enum
5
-
6
- export const schemaAbiTypes = [
7
- "uint8",
8
- "uint16",
9
- "uint24",
10
- "uint32",
11
- "uint40",
12
- "uint48",
13
- "uint56",
14
- "uint64",
15
- "uint72",
16
- "uint80",
17
- "uint88",
18
- "uint96",
19
- "uint104",
20
- "uint112",
21
- "uint120",
22
- "uint128",
23
- "uint136",
24
- "uint144",
25
- "uint152",
26
- "uint160",
27
- "uint168",
28
- "uint176",
29
- "uint184",
30
- "uint192",
31
- "uint200",
32
- "uint208",
33
- "uint216",
34
- "uint224",
35
- "uint232",
36
- "uint240",
37
- "uint248",
38
- "uint256",
39
- "int8",
40
- "int16",
41
- "int24",
42
- "int32",
43
- "int40",
44
- "int48",
45
- "int56",
46
- "int64",
47
- "int72",
48
- "int80",
49
- "int88",
50
- "int96",
51
- "int104",
52
- "int112",
53
- "int120",
54
- "int128",
55
- "int136",
56
- "int144",
57
- "int152",
58
- "int160",
59
- "int168",
60
- "int176",
61
- "int184",
62
- "int192",
63
- "int200",
64
- "int208",
65
- "int216",
66
- "int224",
67
- "int232",
68
- "int240",
69
- "int248",
70
- "int256",
71
- "bytes1",
72
- "bytes2",
73
- "bytes3",
74
- "bytes4",
75
- "bytes5",
76
- "bytes6",
77
- "bytes7",
78
- "bytes8",
79
- "bytes9",
80
- "bytes10",
81
- "bytes11",
82
- "bytes12",
83
- "bytes13",
84
- "bytes14",
85
- "bytes15",
86
- "bytes16",
87
- "bytes17",
88
- "bytes18",
89
- "bytes19",
90
- "bytes20",
91
- "bytes21",
92
- "bytes22",
93
- "bytes23",
94
- "bytes24",
95
- "bytes25",
96
- "bytes26",
97
- "bytes27",
98
- "bytes28",
99
- "bytes29",
100
- "bytes30",
101
- "bytes31",
102
- "bytes32",
103
- "bool",
104
- "address",
105
- "uint8[]",
106
- "uint16[]",
107
- "uint24[]",
108
- "uint32[]",
109
- "uint40[]",
110
- "uint48[]",
111
- "uint56[]",
112
- "uint64[]",
113
- "uint72[]",
114
- "uint80[]",
115
- "uint88[]",
116
- "uint96[]",
117
- "uint104[]",
118
- "uint112[]",
119
- "uint120[]",
120
- "uint128[]",
121
- "uint136[]",
122
- "uint144[]",
123
- "uint152[]",
124
- "uint160[]",
125
- "uint168[]",
126
- "uint176[]",
127
- "uint184[]",
128
- "uint192[]",
129
- "uint200[]",
130
- "uint208[]",
131
- "uint216[]",
132
- "uint224[]",
133
- "uint232[]",
134
- "uint240[]",
135
- "uint248[]",
136
- "uint256[]",
137
- "int8[]",
138
- "int16[]",
139
- "int24[]",
140
- "int32[]",
141
- "int40[]",
142
- "int48[]",
143
- "int56[]",
144
- "int64[]",
145
- "int72[]",
146
- "int80[]",
147
- "int88[]",
148
- "int96[]",
149
- "int104[]",
150
- "int112[]",
151
- "int120[]",
152
- "int128[]",
153
- "int136[]",
154
- "int144[]",
155
- "int152[]",
156
- "int160[]",
157
- "int168[]",
158
- "int176[]",
159
- "int184[]",
160
- "int192[]",
161
- "int200[]",
162
- "int208[]",
163
- "int216[]",
164
- "int224[]",
165
- "int232[]",
166
- "int240[]",
167
- "int248[]",
168
- "int256[]",
169
- "bytes1[]",
170
- "bytes2[]",
171
- "bytes3[]",
172
- "bytes4[]",
173
- "bytes5[]",
174
- "bytes6[]",
175
- "bytes7[]",
176
- "bytes8[]",
177
- "bytes9[]",
178
- "bytes10[]",
179
- "bytes11[]",
180
- "bytes12[]",
181
- "bytes13[]",
182
- "bytes14[]",
183
- "bytes15[]",
184
- "bytes16[]",
185
- "bytes17[]",
186
- "bytes18[]",
187
- "bytes19[]",
188
- "bytes20[]",
189
- "bytes21[]",
190
- "bytes22[]",
191
- "bytes23[]",
192
- "bytes24[]",
193
- "bytes25[]",
194
- "bytes26[]",
195
- "bytes27[]",
196
- "bytes28[]",
197
- "bytes29[]",
198
- "bytes30[]",
199
- "bytes31[]",
200
- "bytes32[]",
201
- "bool[]",
202
- "address[]",
203
- "bytes",
204
- "string",
205
- ] as const satisfies readonly AbiType[];
206
-
207
- export type SchemaAbiType = (typeof schemaAbiTypes)[number];
208
-
209
- // These are defined here to keep the index position (98) consolidated, since we use it both in runtime code and type definition
210
- export const staticAbiTypes = schemaAbiTypes.slice(0, 98) as any as TupleSplit<typeof schemaAbiTypes, 98>[0];
211
- export const dynamicAbiTypes = schemaAbiTypes.slice(98) as any as TupleSplit<typeof schemaAbiTypes, 98>[1];
@@ -1,58 +0,0 @@
1
- import { describe, expectTypeOf, it } from "vitest";
2
- import { StaticAbiTypeToPrimitiveType } from "./staticAbiTypes";
3
- import { Hex } from "viem";
4
-
5
- describe("StaticAbiTypeToPrimitiveType", () => {
6
- it("maps uint8 to number", () => {
7
- expectTypeOf<StaticAbiTypeToPrimitiveType<"uint8">>().toBeNumber();
8
- });
9
- it("maps uint32 to number", () => {
10
- expectTypeOf<StaticAbiTypeToPrimitiveType<"uint32">>().toBeNumber();
11
- });
12
- it("maps uint48 to number", () => {
13
- expectTypeOf<StaticAbiTypeToPrimitiveType<"uint48">>().toBeNumber();
14
- });
15
- it("maps uint56 to number", () => {
16
- expectTypeOf<StaticAbiTypeToPrimitiveType<"uint56">>().toMatchTypeOf<bigint>();
17
- });
18
- it("maps uint256 to number", () => {
19
- expectTypeOf<StaticAbiTypeToPrimitiveType<"uint256">>().toMatchTypeOf<bigint>();
20
- });
21
-
22
- it("maps int8 to number", () => {
23
- expectTypeOf<StaticAbiTypeToPrimitiveType<"int8">>().toBeNumber();
24
- });
25
- it("maps int32 to number", () => {
26
- expectTypeOf<StaticAbiTypeToPrimitiveType<"int32">>().toBeNumber();
27
- });
28
- it("maps int48 to number", () => {
29
- expectTypeOf<StaticAbiTypeToPrimitiveType<"int48">>().toBeNumber();
30
- });
31
- it("maps int56 to number", () => {
32
- expectTypeOf<StaticAbiTypeToPrimitiveType<"int56">>().toMatchTypeOf<bigint>();
33
- });
34
- it("maps int256 to number", () => {
35
- expectTypeOf<StaticAbiTypeToPrimitiveType<"int256">>().toMatchTypeOf<bigint>();
36
- });
37
-
38
- it("maps bytes1 to hex", () => {
39
- expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes1">>().toMatchTypeOf<Hex>();
40
- });
41
- it("maps bytes2 to hex", () => {
42
- expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes2">>().toMatchTypeOf<Hex>();
43
- });
44
- it("maps bytes8 to hex", () => {
45
- expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes8">>().toMatchTypeOf<Hex>();
46
- });
47
- it("maps bytes32 to hex", () => {
48
- expectTypeOf<StaticAbiTypeToPrimitiveType<"bytes32">>().toMatchTypeOf<Hex>();
49
- });
50
-
51
- it("maps bool to boolean", () => {
52
- expectTypeOf<StaticAbiTypeToPrimitiveType<"bool">>().toBeBoolean();
53
- });
54
-
55
- it("maps address to hex", () => {
56
- expectTypeOf<StaticAbiTypeToPrimitiveType<"address">>().toMatchTypeOf<Hex>();
57
- });
58
- });
@@ -1,221 +0,0 @@
1
- import { Hex } from "viem";
2
- import { staticAbiTypes } from "./schemaAbiTypes";
3
-
4
- // Fixed-length ABI types
5
-
6
- export { staticAbiTypes };
7
-
8
- export type StaticAbiType = (typeof staticAbiTypes)[number];
9
-
10
- export type StaticPrimitiveType = number | bigint | boolean | Hex;
11
-
12
- export const staticAbiTypeToDefaultValue = {
13
- uint8: 0,
14
- uint16: 0,
15
- uint24: 0,
16
- uint32: 0,
17
- uint40: 0,
18
- uint48: 0,
19
- uint56: 0n,
20
- uint64: 0n,
21
- uint72: 0n,
22
- uint80: 0n,
23
- uint88: 0n,
24
- uint96: 0n,
25
- uint104: 0n,
26
- uint112: 0n,
27
- uint120: 0n,
28
- uint128: 0n,
29
- uint136: 0n,
30
- uint144: 0n,
31
- uint152: 0n,
32
- uint160: 0n,
33
- uint168: 0n,
34
- uint176: 0n,
35
- uint184: 0n,
36
- uint192: 0n,
37
- uint200: 0n,
38
- uint208: 0n,
39
- uint216: 0n,
40
- uint224: 0n,
41
- uint232: 0n,
42
- uint240: 0n,
43
- uint248: 0n,
44
- uint256: 0n,
45
-
46
- int8: 0,
47
- int16: 0,
48
- int24: 0,
49
- int32: 0,
50
- int40: 0,
51
- int48: 0,
52
- int56: 0n,
53
- int64: 0n,
54
- int72: 0n,
55
- int80: 0n,
56
- int88: 0n,
57
- int96: 0n,
58
- int104: 0n,
59
- int112: 0n,
60
- int120: 0n,
61
- int128: 0n,
62
- int136: 0n,
63
- int144: 0n,
64
- int152: 0n,
65
- int160: 0n,
66
- int168: 0n,
67
- int176: 0n,
68
- int184: 0n,
69
- int192: 0n,
70
- int200: 0n,
71
- int208: 0n,
72
- int216: 0n,
73
- int224: 0n,
74
- int232: 0n,
75
- int240: 0n,
76
- int248: 0n,
77
- int256: 0n,
78
-
79
- bytes1: "0x00",
80
- bytes2: "0x0000",
81
- bytes3: "0x000000",
82
- bytes4: "0x00000000",
83
- bytes5: "0x0000000000",
84
- bytes6: "0x000000000000",
85
- bytes7: "0x00000000000000",
86
- bytes8: "0x0000000000000000",
87
- bytes9: "0x000000000000000000",
88
- bytes10: "0x00000000000000000000",
89
- bytes11: "0x0000000000000000000000",
90
- bytes12: "0x000000000000000000000000",
91
- bytes13: "0x00000000000000000000000000",
92
- bytes14: "0x0000000000000000000000000000",
93
- bytes15: "0x000000000000000000000000000000",
94
- bytes16: "0x00000000000000000000000000000000",
95
- bytes17: "0x0000000000000000000000000000000000",
96
- bytes18: "0x000000000000000000000000000000000000",
97
- bytes19: "0x00000000000000000000000000000000000000",
98
- bytes20: "0x0000000000000000000000000000000000000000",
99
- bytes21: "0x000000000000000000000000000000000000000000",
100
- bytes22: "0x00000000000000000000000000000000000000000000",
101
- bytes23: "0x0000000000000000000000000000000000000000000000",
102
- bytes24: "0x000000000000000000000000000000000000000000000000",
103
- bytes25: "0x00000000000000000000000000000000000000000000000000",
104
- bytes26: "0x0000000000000000000000000000000000000000000000000000",
105
- bytes27: "0x000000000000000000000000000000000000000000000000000000",
106
- bytes28: "0x00000000000000000000000000000000000000000000000000000000",
107
- bytes29: "0x0000000000000000000000000000000000000000000000000000000000",
108
- bytes30: "0x000000000000000000000000000000000000000000000000000000000000",
109
- bytes31: "0x00000000000000000000000000000000000000000000000000000000000000",
110
- bytes32: "0x0000000000000000000000000000000000000000000000000000000000000000",
111
-
112
- bool: false,
113
- address: "0x0000000000000000000000000000000000000000",
114
- } as const satisfies Record<StaticAbiType, StaticPrimitiveType>;
115
-
116
- export type StaticAbiTypeToPrimitiveType<TStaticAbiType extends StaticAbiType = StaticAbiType> =
117
- (typeof staticAbiTypeToDefaultValue)[TStaticAbiType];
118
-
119
- export const staticAbiTypeToByteLength = {
120
- uint8: 1,
121
- uint16: 2,
122
- uint24: 3,
123
- uint32: 4,
124
- uint40: 5,
125
- uint48: 6,
126
- uint56: 7,
127
- uint64: 9,
128
- uint72: 9,
129
- uint80: 10,
130
- uint88: 11,
131
- uint96: 12,
132
- uint104: 13,
133
- uint112: 14,
134
- uint120: 15,
135
- uint128: 16,
136
- uint136: 17,
137
- uint144: 18,
138
- uint152: 19,
139
- uint160: 20,
140
- uint168: 21,
141
- uint176: 22,
142
- uint184: 23,
143
- uint192: 24,
144
- uint200: 25,
145
- uint208: 26,
146
- uint216: 27,
147
- uint224: 28,
148
- uint232: 29,
149
- uint240: 30,
150
- uint248: 31,
151
- uint256: 32,
152
-
153
- int8: 1,
154
- int16: 2,
155
- int24: 3,
156
- int32: 4,
157
- int40: 5,
158
- int48: 6,
159
- int56: 7,
160
- int64: 9,
161
- int72: 9,
162
- int80: 10,
163
- int88: 11,
164
- int96: 12,
165
- int104: 13,
166
- int112: 14,
167
- int120: 15,
168
- int128: 16,
169
- int136: 17,
170
- int144: 18,
171
- int152: 19,
172
- int160: 20,
173
- int168: 21,
174
- int176: 22,
175
- int184: 23,
176
- int192: 24,
177
- int200: 25,
178
- int208: 26,
179
- int216: 27,
180
- int224: 28,
181
- int232: 29,
182
- int240: 30,
183
- int248: 31,
184
- int256: 32,
185
-
186
- bytes1: 1,
187
- bytes2: 2,
188
- bytes3: 3,
189
- bytes4: 4,
190
- bytes5: 5,
191
- bytes6: 6,
192
- bytes7: 7,
193
- bytes8: 8,
194
- bytes9: 9,
195
- bytes10: 10,
196
- bytes11: 11,
197
- bytes12: 12,
198
- bytes13: 13,
199
- bytes14: 14,
200
- bytes15: 15,
201
- bytes16: 16,
202
- bytes17: 17,
203
- bytes18: 18,
204
- bytes19: 19,
205
- bytes20: 20,
206
- bytes21: 21,
207
- bytes22: 22,
208
- bytes23: 23,
209
- bytes24: 24,
210
- bytes25: 25,
211
- bytes26: 26,
212
- bytes27: 27,
213
- bytes28: 28,
214
- bytes29: 29,
215
- bytes30: 30,
216
- bytes31: 31,
217
- bytes32: 32,
218
-
219
- bool: 1,
220
- address: 20,
221
- } as const satisfies Record<StaticAbiType, number>;
package/src/utils.ts DELETED
@@ -1,5 +0,0 @@
1
- export type TupleSplit<T, N extends number, O extends readonly any[] = readonly []> = O["length"] extends N
2
- ? [O, T]
3
- : T extends readonly [infer F, ...infer R]
4
- ? TupleSplit<readonly [...R], N, readonly [...O, F]>
5
- : [O, T];