@latticexyz/common 2.0.0-alpha.1.21 → 2.0.0-alpha.1.210

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/chains.js +2 -0
  2. package/dist/chains.js.map +1 -0
  3. package/dist/chunk-UPQEB2HW.js +2 -0
  4. package/dist/chunk-UPQEB2HW.js.map +1 -0
  5. package/dist/codegen.js +56 -0
  6. package/dist/codegen.js.map +1 -0
  7. package/dist/errors.js +2 -0
  8. package/dist/errors.js.map +1 -0
  9. package/dist/foundry.js +3 -0
  10. package/dist/foundry.js.map +1 -0
  11. package/dist/type-utils.js +1 -0
  12. package/dist/type-utils.js.map +1 -0
  13. package/dist/utils.js +2 -0
  14. package/dist/utils.js.map +1 -0
  15. package/package.json +31 -16
  16. package/src/chains/index.ts +2 -0
  17. package/src/chains/latticeTestnet.ts +30 -0
  18. package/src/chains/types.ts +6 -0
  19. package/src/codegen/index.ts +4 -0
  20. package/src/codegen/modules.d.ts +1 -0
  21. package/src/codegen/render-solidity/common.ts +176 -0
  22. package/src/codegen/render-solidity/index.ts +4 -0
  23. package/src/codegen/render-solidity/renderEnums.ts +17 -0
  24. package/src/codegen/render-solidity/renderTypeHelpers.ts +99 -0
  25. package/src/codegen/render-solidity/types.ts +66 -0
  26. package/src/codegen/render-typescript/index.ts +1 -0
  27. package/src/codegen/render-typescript/schemaTypesToRecsTypeStrings.ts +202 -0
  28. package/src/codegen/utils/contractToInterface.ts +214 -0
  29. package/src/codegen/utils/format.ts +39 -0
  30. package/src/codegen/utils/formatAndWrite.ts +21 -0
  31. package/src/codegen/utils/index.ts +4 -0
  32. package/src/codegen/utils/posixPath.ts +8 -0
  33. package/src/errors/MUDError.ts +3 -0
  34. package/src/errors/index.ts +1 -0
  35. package/src/foundry/index.ts +124 -0
  36. package/src/type-utils/abi.ts +5 -0
  37. package/src/type-utils/common.ts +19 -0
  38. package/src/type-utils/index.ts +2 -0
  39. package/src/utils/curry.ts +9 -0
  40. package/src/utils/index.ts +1 -0
  41. package/dist/_commonjsHelpers-77f246c3.js +0 -5
  42. package/dist/_commonjsHelpers-77f246c3.js.map +0 -1
  43. package/dist/codegen/index.js +0 -33534
  44. package/dist/codegen/index.js.map +0 -1
  45. package/dist/foundry/index.js +0 -1169
  46. package/dist/foundry/index.js.map +0 -1
package/dist/chains.js ADDED
@@ -0,0 +1,2 @@
1
+ var t={name:"Lattice Testnet",id:4242,network:"lattice-testnet",nativeCurrency:{decimals:18,name:"Ether",symbol:"ETH"},rpcUrls:{default:{http:["https://follower.testnet-chain.linfra.xyz"],webSocket:["wss://follower.testnet-chain.linfra.xyz"]},public:{http:["https://follower.testnet-chain.linfra.xyz"],webSocket:["wss://follower.testnet-chain.linfra.xyz"]}},blockExplorers:{otterscan:{name:"Otterscan",url:"https://explorer.testnet-chain.linfra.xyz"},default:{name:"Otterscan",url:"https://explorer.testnet-chain.linfra.xyz"}},modeUrl:"https://mode.testnet-mud-services.linfra.xyz",faucetUrl:"https://faucet.testnet-mud-services.linfra.xyz"};export{t as latticeTestnet};
2
+ //# sourceMappingURL=chains.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/chains/latticeTestnet.ts"],"sourcesContent":["import type { MUDChain } from \"./types\";\n\nexport const latticeTestnet = {\n name: \"Lattice Testnet\",\n id: 4242,\n network: \"lattice-testnet\",\n nativeCurrency: { decimals: 18, name: \"Ether\", symbol: \"ETH\" },\n rpcUrls: {\n default: {\n http: [\"https://follower.testnet-chain.linfra.xyz\"],\n webSocket: [\"wss://follower.testnet-chain.linfra.xyz\"],\n },\n public: {\n http: [\"https://follower.testnet-chain.linfra.xyz\"],\n webSocket: [\"wss://follower.testnet-chain.linfra.xyz\"],\n },\n },\n blockExplorers: {\n otterscan: {\n name: \"Otterscan\",\n url: \"https://explorer.testnet-chain.linfra.xyz\",\n },\n default: {\n name: \"Otterscan\",\n url: \"https://explorer.testnet-chain.linfra.xyz\",\n },\n },\n modeUrl: \"https://mode.testnet-mud-services.linfra.xyz\",\n faucetUrl: \"https://faucet.testnet-mud-services.linfra.xyz\",\n} as const satisfies MUDChain;\n"],"mappings":"AAEO,IAAMA,EAAiB,CAC5B,KAAM,kBACN,GAAI,KACJ,QAAS,kBACT,eAAgB,CAAE,SAAU,GAAI,KAAM,QAAS,OAAQ,KAAM,EAC7D,QAAS,CACP,QAAS,CACP,KAAM,CAAC,2CAA2C,EAClD,UAAW,CAAC,yCAAyC,CACvD,EACA,OAAQ,CACN,KAAM,CAAC,2CAA2C,EAClD,UAAW,CAAC,yCAAyC,CACvD,CACF,EACA,eAAgB,CACd,UAAW,CACT,KAAM,YACN,IAAK,2CACP,EACA,QAAS,CACP,KAAM,YACN,IAAK,2CACP,CACF,EACA,QAAS,+CACT,UAAW,gDACb","names":["latticeTestnet"]}
@@ -0,0 +1,2 @@
1
+ var r=class extends Error{name="MUDError"};export{r as a};
2
+ //# sourceMappingURL=chunk-UPQEB2HW.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors/MUDError.ts"],"sourcesContent":["export class MUDError extends Error {\n name = \"MUDError\";\n}\n"],"mappings":"AAAO,IAAMA,EAAN,cAAuB,KAAM,CAClC,KAAO,UACT","names":["MUDError"]}
@@ -0,0 +1,56 @@
1
+ import{a}from"./chunk-UPQEB2HW.js";import L from"path";import{parse as W,visit as N}from"@solidity-parser/parser";function X(t,r){let n=W(t),s=!1,i=[],R=[],p=[];if(N(n,{ContractDefinition({name:T}){T===r&&(s=!0)},FunctionDefinition({name:T,visibility:y,parameters:o,stateMutability:I,returnParameters:g,isConstructor:v,isFallback:M,isReceiveEther:P},u){if(u!==void 0&&u.type==="ContractDefinition"&&u.name===r)try{if(v||M||P)return;if(y==="default")throw new a("Visibility is not specified");if(y==="external"||y==="public"){R.push({name:T===null?"":T,parameters:o.map(m),stateMutability:I||"",returnParameters:g===null?[]:g.map(m)});for(let{typeName:c}of o.concat(g??[])){let C=B(c);i=i.concat(Y(n,C))}}}catch(c){throw c instanceof a&&(c.message=`Function "${T}" in contract "${r}": ${c.message}`),c}},CustomErrorDefinition({name:T,parameters:y}){p.push({name:T===null?"":T,parameters:y.map(m)});for(let o of y){let I=B(o.typeName);i=i.concat(Y(n,I))}}}),!s)throw new a(`Contract not found: ${r}`);return{functions:R,errors:p,symbolImports:i}}function m({name:t,typeName:r,storageLocation:n}){let s="",{name:i,stateMutability:R}=S(r);return s+=i,R!==null&&(s+=` ${R}`),n!==null&&(s+=` ${n}`),t!==null&&(s+=` ${t}`),s}function S(t){if(t===null)return{name:"",stateMutability:null};if(t.type==="ElementaryTypeName")return{name:t.name,stateMutability:t.stateMutability};if(t.type==="UserDefinedTypeName")return{name:t.namePath,stateMutability:null};if(t.type==="ArrayTypeName"){let r="";t.length?.type==="NumberLiteral"?r=t.length.number:t.length?.type==="Identifier"&&(r=t.length.name);let{name:n,stateMutability:s}=S(t.baseTypeName);return{name:`${n}[${r}]`,stateMutability:s}}else throw new a(`Invalid typeName.type ${t.type}`)}function B(t){if(t?.type==="UserDefinedTypeName")return[t.namePath.split(".")[0]];if(t?.type==="ArrayTypeName"){let r=B(t.baseTypeName);if(t.length?.type==="Identifier"){let n=t.length.name;r.push(n.split(".")[0])}return r}else return[]}function Y(t,r){let n=[];for(let s of r){let i;if(N(t,{ImportDirective({path:R,symbolAliases:p}){if(p)for(let T of p){let y=T[1]||T[0];if(s===y){i={symbol:T[0],path:R};return}}}}),i)n.push(i);else throw new a(`Symbol "${s}" has no explicit import`)}return n}import k from"chalk";import l from"prettier";import F from"prettier-plugin-solidity";async function _(t,r){let n;r&&(n=await l.resolveConfig(r));try{return l.format(t,{plugins:[F],parser:"solidity-parse",printWidth:120,semi:!0,tabWidth:2,useTabs:!1,bracketSpacing:!0,...n})}catch(s){let i;return s instanceof Error?i=s.message:i=s,console.log(k.yellow(`Error during output formatting: ${i}`)),t}}async function d(t){return l.format(t,{parser:"typescript"})}import{mkdirSync as b,writeFileSync as E}from"fs";import{dirname as U}from"path";async function ne(t,r,n){let s=await _(t);b(U(r),{recursive:!0}),E(r,s),console.log(`${n}: ${r}`)}async function se(t,r,n){let s=await d(t);b(U(r),{recursive:!0}),E(r,s),console.log(`${n}: ${r}`)}function h(t){return t.replace(/\\/g,"/")}var $=`// SPDX-License-Identifier: MIT
2
+ pragma solidity >=0.8.0;
3
+
4
+ /* Autogenerated file. Do not edit manually. */`;function f(t,r){return D("",t,r)}function A(t){let r=t.filter(n=>n!==void 0&&n!=="");return D(",",r,n=>n)}function Ie({staticResourceData:t,keyTuple:r}){let n=t?"":"_tableId",s=t?"":"bytes32 _tableId",i=A(r.map(({name:T})=>T)),R=A(r.map(({name:T,typeWithLocation:y})=>`${y} ${T}`)),p=`
5
+ bytes32[] memory _keyTuple = new bytes32[](${r.length});
6
+ ${f(r,(T,y)=>`_keyTuple[${y}] = ${H(T.name,T)};`)}
7
+ `;return{_tableId:n,_typedTableId:s,_keyArgs:i,_typedKeyArgs:R,_keyTupleDefinition:p}}function x(t,r){return"./"+L.relative("./"+r,"./"+t)}function ge(t){return w(t.map(r=>"path"in r?r:{symbol:r.symbol,path:x(r.fromPath,r.usedInPath)}))}function ue(t){return w(t.map(({symbol:r,fromPath:n,usedInPath:s})=>({symbol:r,path:x(n,s)})))}function w(t){let r=new Map;for(let{symbol:s,path:i}of t)r.has(i)||r.set(i,new Set),r.get(i)?.add(s);let n=[];for(let[s,i]of r){let R=[...i].join(", ");n.push(`import { ${R} } from "${h(s)}";`)}return n.join(`
8
+ `)}function me(t,r){let n="";return n+=r(void 0,"StoreSwitch","",void 0),t&&(n+=`
9
+ `+r("IStore _store","_store"," (using the specified store)","_store")),n}function Be(t){let r=`bytes32(abi.encodePacked(bytes16("${t.namespace}"), bytes16("${t.name}")))`,n=`
10
+ bytes32 constant _tableId = ${r};
11
+ bytes32 constant ${t.tableIdName} = _tableId;
12
+ `;return{hardcodedTableId:r,tableIdDefinition:n}}function H(t,{typeUnwrap:r,internalTypeId:n}){let s=`${r}(${t})`;if(n.match(/^uint\d{1,3}$/))return`bytes32(uint256(${s}))`;if(n.match(/^int\d{1,3}$/))return`bytes32(uint256(int256(${s})))`;if(n.match(/^bytes\d{1,2}$/))return`bytes32(${s})`;if(n==="address")return`bytes32(uint256(uint160(${s})))`;if(n==="bool")return`_boolToBytes32(${s})`;throw new Error(`Unknown value type id ${n}`)}function D(t,r,n){return r.map((s,i)=>n(s,i)+(i===r.length-1?"":t)).join(`
13
+ `)}function Ye(t){let r=$;return r+=f(t,({name:n,memberNames:s})=>`
14
+ enum ${n} {
15
+ ${A(s)}
16
+ }
17
+ `),r}function Se(t){let{fields:r,keyTuple:n}=t,s="";for(let i of K([...r,...n]))s+=i;return r.some(({internalTypeId:i})=>i.match("bool"))&&(s+=`
18
+ function _toBool(uint8 value) pure returns (bool result) {
19
+ assembly {
20
+ result := value
21
+ }
22
+ }
23
+ `),n.some(({internalTypeId:i})=>i.match("bool"))&&(s+=`
24
+ function _boolToBytes32(bool value) pure returns (bytes32 result) {
25
+ assembly {
26
+ result := value
27
+ }
28
+ }
29
+ `),s}function K(t){let r=new Map,n=new Map;for(let{typeWrappingData:s,typeWrap:i,typeUnwrap:R,internalTypeId:p}of t){if(!s)continue;let{kind:T}=s;if(T==="staticArray"){let{elementType:y,staticLength:o}=s;r.set(i,j(i,y,o,p)),n.set(R,V(R,y,o,p))}}return[...r.values(),...n.values()]}function j(t,r,n,s){return`
30
+ function ${t}(
31
+ ${s} memory _value
32
+ ) pure returns (
33
+ ${r}[${n}] memory _result
34
+ ) {
35
+ // in memory static arrays are just dynamic arrays without the length byte
36
+ assembly {
37
+ _result := add(_value, 0x20)
38
+ }
39
+ }
40
+ `}function V(t,r,n,s){let i=n*32;return`
41
+ function ${t}(
42
+ ${r}[${n}] memory _value
43
+ ) view returns (
44
+ ${s} memory _result
45
+ ) {
46
+ _result = new ${s}(${n});
47
+ uint256 fromPointer;
48
+ uint256 toPointer;
49
+ assembly {
50
+ fromPointer := _value
51
+ toPointer := add(_result, 0x20)
52
+ }
53
+ Memory.copy(fromPointer, toPointer, ${i});
54
+ }
55
+ `}import{SchemaType as e}from"@latticexyz/schema-type";var xe={[e.UINT8]:"RecsType.Number",[e.UINT16]:"RecsType.Number",[e.UINT24]:"RecsType.Number",[e.UINT32]:"RecsType.Number",[e.UINT40]:"RecsType.Number",[e.UINT48]:"RecsType.Number",[e.UINT56]:"RecsType.BigInt",[e.UINT64]:"RecsType.BigInt",[e.UINT72]:"RecsType.BigInt",[e.UINT80]:"RecsType.BigInt",[e.UINT88]:"RecsType.BigInt",[e.UINT96]:"RecsType.BigInt",[e.UINT104]:"RecsType.BigInt",[e.UINT112]:"RecsType.BigInt",[e.UINT120]:"RecsType.BigInt",[e.UINT128]:"RecsType.BigInt",[e.UINT136]:"RecsType.BigInt",[e.UINT144]:"RecsType.BigInt",[e.UINT152]:"RecsType.BigInt",[e.UINT160]:"RecsType.BigInt",[e.UINT168]:"RecsType.BigInt",[e.UINT176]:"RecsType.BigInt",[e.UINT184]:"RecsType.BigInt",[e.UINT192]:"RecsType.BigInt",[e.UINT200]:"RecsType.BigInt",[e.UINT208]:"RecsType.BigInt",[e.UINT216]:"RecsType.BigInt",[e.UINT224]:"RecsType.BigInt",[e.UINT232]:"RecsType.BigInt",[e.UINT240]:"RecsType.BigInt",[e.UINT248]:"RecsType.BigInt",[e.UINT256]:"RecsType.BigInt",[e.INT8]:"RecsType.Number",[e.INT16]:"RecsType.Number",[e.INT24]:"RecsType.Number",[e.INT32]:"RecsType.Number",[e.INT40]:"RecsType.Number",[e.INT48]:"RecsType.Number",[e.INT56]:"RecsType.BigInt",[e.INT64]:"RecsType.BigInt",[e.INT72]:"RecsType.BigInt",[e.INT80]:"RecsType.BigInt",[e.INT88]:"RecsType.BigInt",[e.INT96]:"RecsType.BigInt",[e.INT104]:"RecsType.BigInt",[e.INT112]:"RecsType.BigInt",[e.INT120]:"RecsType.BigInt",[e.INT128]:"RecsType.BigInt",[e.INT136]:"RecsType.BigInt",[e.INT144]:"RecsType.BigInt",[e.INT152]:"RecsType.BigInt",[e.INT160]:"RecsType.BigInt",[e.INT168]:"RecsType.BigInt",[e.INT176]:"RecsType.BigInt",[e.INT184]:"RecsType.BigInt",[e.INT192]:"RecsType.BigInt",[e.INT200]:"RecsType.BigInt",[e.INT208]:"RecsType.BigInt",[e.INT216]:"RecsType.BigInt",[e.INT224]:"RecsType.BigInt",[e.INT232]:"RecsType.BigInt",[e.INT240]:"RecsType.BigInt",[e.INT248]:"RecsType.BigInt",[e.INT256]:"RecsType.BigInt",[e.BYTES1]:"RecsType.String",[e.BYTES2]:"RecsType.String",[e.BYTES3]:"RecsType.String",[e.BYTES4]:"RecsType.String",[e.BYTES5]:"RecsType.String",[e.BYTES6]:"RecsType.String",[e.BYTES7]:"RecsType.String",[e.BYTES8]:"RecsType.String",[e.BYTES9]:"RecsType.String",[e.BYTES10]:"RecsType.String",[e.BYTES11]:"RecsType.String",[e.BYTES12]:"RecsType.String",[e.BYTES13]:"RecsType.String",[e.BYTES14]:"RecsType.String",[e.BYTES15]:"RecsType.String",[e.BYTES16]:"RecsType.String",[e.BYTES17]:"RecsType.String",[e.BYTES18]:"RecsType.String",[e.BYTES19]:"RecsType.String",[e.BYTES20]:"RecsType.String",[e.BYTES21]:"RecsType.String",[e.BYTES22]:"RecsType.String",[e.BYTES23]:"RecsType.String",[e.BYTES24]:"RecsType.String",[e.BYTES25]:"RecsType.String",[e.BYTES26]:"RecsType.String",[e.BYTES27]:"RecsType.String",[e.BYTES28]:"RecsType.String",[e.BYTES29]:"RecsType.String",[e.BYTES30]:"RecsType.String",[e.BYTES31]:"RecsType.String",[e.BYTES32]:"RecsType.String",[e.BOOL]:"RecsType.Boolean",[e.ADDRESS]:"RecsType.String",[e.UINT8_ARRAY]:"RecsType.NumberArray",[e.UINT16_ARRAY]:"RecsType.NumberArray",[e.UINT24_ARRAY]:"RecsType.NumberArray",[e.UINT32_ARRAY]:"RecsType.NumberArray",[e.UINT40_ARRAY]:"RecsType.NumberArray",[e.UINT48_ARRAY]:"RecsType.NumberArray",[e.UINT56_ARRAY]:"RecsType.BigIntArray",[e.UINT64_ARRAY]:"RecsType.BigIntArray",[e.UINT72_ARRAY]:"RecsType.BigIntArray",[e.UINT80_ARRAY]:"RecsType.BigIntArray",[e.UINT88_ARRAY]:"RecsType.BigIntArray",[e.UINT96_ARRAY]:"RecsType.BigIntArray",[e.UINT104_ARRAY]:"RecsType.BigIntArray",[e.UINT112_ARRAY]:"RecsType.BigIntArray",[e.UINT120_ARRAY]:"RecsType.BigIntArray",[e.UINT128_ARRAY]:"RecsType.BigIntArray",[e.UINT136_ARRAY]:"RecsType.BigIntArray",[e.UINT144_ARRAY]:"RecsType.BigIntArray",[e.UINT152_ARRAY]:"RecsType.BigIntArray",[e.UINT160_ARRAY]:"RecsType.BigIntArray",[e.UINT168_ARRAY]:"RecsType.BigIntArray",[e.UINT176_ARRAY]:"RecsType.BigIntArray",[e.UINT184_ARRAY]:"RecsType.BigIntArray",[e.UINT192_ARRAY]:"RecsType.BigIntArray",[e.UINT200_ARRAY]:"RecsType.BigIntArray",[e.UINT208_ARRAY]:"RecsType.BigIntArray",[e.UINT216_ARRAY]:"RecsType.BigIntArray",[e.UINT224_ARRAY]:"RecsType.BigIntArray",[e.UINT232_ARRAY]:"RecsType.BigIntArray",[e.UINT240_ARRAY]:"RecsType.BigIntArray",[e.UINT248_ARRAY]:"RecsType.BigIntArray",[e.UINT256_ARRAY]:"RecsType.BigIntArray",[e.INT8_ARRAY]:"RecsType.NumberArray",[e.INT16_ARRAY]:"RecsType.NumberArray",[e.INT24_ARRAY]:"RecsType.NumberArray",[e.INT32_ARRAY]:"RecsType.NumberArray",[e.INT40_ARRAY]:"RecsType.NumberArray",[e.INT48_ARRAY]:"RecsType.NumberArray",[e.INT56_ARRAY]:"RecsType.BigIntArray",[e.INT64_ARRAY]:"RecsType.BigIntArray",[e.INT72_ARRAY]:"RecsType.BigIntArray",[e.INT80_ARRAY]:"RecsType.BigIntArray",[e.INT88_ARRAY]:"RecsType.BigIntArray",[e.INT96_ARRAY]:"RecsType.BigIntArray",[e.INT104_ARRAY]:"RecsType.BigIntArray",[e.INT112_ARRAY]:"RecsType.BigIntArray",[e.INT120_ARRAY]:"RecsType.BigIntArray",[e.INT128_ARRAY]:"RecsType.BigIntArray",[e.INT136_ARRAY]:"RecsType.BigIntArray",[e.INT144_ARRAY]:"RecsType.BigIntArray",[e.INT152_ARRAY]:"RecsType.BigIntArray",[e.INT160_ARRAY]:"RecsType.BigIntArray",[e.INT168_ARRAY]:"RecsType.BigIntArray",[e.INT176_ARRAY]:"RecsType.BigIntArray",[e.INT184_ARRAY]:"RecsType.BigIntArray",[e.INT192_ARRAY]:"RecsType.BigIntArray",[e.INT200_ARRAY]:"RecsType.BigIntArray",[e.INT208_ARRAY]:"RecsType.BigIntArray",[e.INT216_ARRAY]:"RecsType.BigIntArray",[e.INT224_ARRAY]:"RecsType.BigIntArray",[e.INT232_ARRAY]:"RecsType.BigIntArray",[e.INT240_ARRAY]:"RecsType.BigIntArray",[e.INT248_ARRAY]:"RecsType.BigIntArray",[e.INT256_ARRAY]:"RecsType.BigIntArray",[e.BYTES1_ARRAY]:"RecsType.BigIntArray",[e.BYTES2_ARRAY]:"RecsType.BigIntArray",[e.BYTES3_ARRAY]:"RecsType.BigIntArray",[e.BYTES4_ARRAY]:"RecsType.BigIntArray",[e.BYTES5_ARRAY]:"RecsType.BigIntArray",[e.BYTES6_ARRAY]:"RecsType.BigIntArray",[e.BYTES7_ARRAY]:"RecsType.BigIntArray",[e.BYTES8_ARRAY]:"RecsType.BigIntArray",[e.BYTES9_ARRAY]:"RecsType.BigIntArray",[e.BYTES10_ARRAY]:"RecsType.BigIntArray",[e.BYTES11_ARRAY]:"RecsType.BigIntArray",[e.BYTES12_ARRAY]:"RecsType.BigIntArray",[e.BYTES13_ARRAY]:"RecsType.BigIntArray",[e.BYTES14_ARRAY]:"RecsType.BigIntArray",[e.BYTES15_ARRAY]:"RecsType.BigIntArray",[e.BYTES16_ARRAY]:"RecsType.BigIntArray",[e.BYTES17_ARRAY]:"RecsType.BigIntArray",[e.BYTES18_ARRAY]:"RecsType.BigIntArray",[e.BYTES19_ARRAY]:"RecsType.BigIntArray",[e.BYTES20_ARRAY]:"RecsType.BigIntArray",[e.BYTES21_ARRAY]:"RecsType.BigIntArray",[e.BYTES22_ARRAY]:"RecsType.BigIntArray",[e.BYTES23_ARRAY]:"RecsType.BigIntArray",[e.BYTES24_ARRAY]:"RecsType.BigIntArray",[e.BYTES25_ARRAY]:"RecsType.BigIntArray",[e.BYTES26_ARRAY]:"RecsType.BigIntArray",[e.BYTES27_ARRAY]:"RecsType.BigIntArray",[e.BYTES28_ARRAY]:"RecsType.BigIntArray",[e.BYTES29_ARRAY]:"RecsType.BigIntArray",[e.BYTES30_ARRAY]:"RecsType.BigIntArray",[e.BYTES31_ARRAY]:"RecsType.BigIntArray",[e.BYTES32_ARRAY]:"RecsType.BigIntArray",[e.BOOL_ARRAY]:"RecsType.T",[e.ADDRESS_ARRAY]:"RecsType.StringArray",[e.BYTES]:"RecsType.String",[e.STRING]:"RecsType.String"};export{X as contractToInterface,ne as formatAndWriteSolidity,se as formatAndWriteTypescript,_ as formatSolidity,d as formatTypescript,h as posixPath,w as renderAbsoluteImports,A as renderArguments,Ie as renderCommonData,Ye as renderEnums,ge as renderImports,f as renderList,ue as renderRelativeImports,Be as renderTableId,Se as renderTypeHelpers,H as renderValueTypeToBytes32,me as renderWithStore,$ as renderedSolidityHeader,xe as schemaTypesToRecsTypeStrings,x as solidityRelativeImportPath};
56
+ //# sourceMappingURL=codegen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/codegen/render-solidity/common.ts","../src/codegen/utils/contractToInterface.ts","../src/codegen/utils/format.ts","../src/codegen/utils/formatAndWrite.ts","../src/codegen/utils/posixPath.ts","../src/codegen/render-solidity/renderEnums.ts","../src/codegen/render-solidity/renderTypeHelpers.ts","../src/codegen/render-typescript/schemaTypesToRecsTypeStrings.ts"],"sourcesContent":["import path from \"path\";\nimport {\n AbsoluteImportDatum,\n RelativeImportDatum,\n ImportDatum,\n StaticResourceData,\n RenderKeyTuple,\n RenderType,\n} from \"./types\";\nimport { posixPath } from \"../utils\";\n\nexport const renderedSolidityHeader = `// SPDX-License-Identifier: MIT\npragma solidity >=0.8.0;\n\n/* Autogenerated file. Do not edit manually. */`;\n\n/**\n * Renders a list of lines\n */\nexport function renderList<T>(list: T[], renderItem: (item: T, index: number) => string) {\n return internalRenderList(\"\", list, renderItem);\n}\n\n/**\n * Renders a comma-separated list of arguments for solidity functions, ignoring empty and undefined ones\n */\nexport function renderArguments(args: (string | undefined)[]) {\n const filteredArgs = args.filter((arg) => arg !== undefined && arg !== \"\") as string[];\n return internalRenderList(\",\", filteredArgs, (arg) => arg);\n}\n\nexport function renderCommonData({\n staticResourceData,\n keyTuple,\n}: {\n staticResourceData?: StaticResourceData;\n keyTuple: RenderKeyTuple[];\n}) {\n // static resource means static tableId as well, and no tableId arguments\n const _tableId = staticResourceData ? \"\" : \"_tableId\";\n const _typedTableId = staticResourceData ? \"\" : \"bytes32 _tableId\";\n\n const _keyArgs = renderArguments(keyTuple.map(({ name }) => name));\n const _typedKeyArgs = renderArguments(keyTuple.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`));\n\n const _keyTupleDefinition = `\n bytes32[] memory _keyTuple = new bytes32[](${keyTuple.length});\n ${renderList(keyTuple, (key, index) => `_keyTuple[${index}] = ${renderValueTypeToBytes32(key.name, key)};`)}\n `;\n\n return {\n _tableId,\n _typedTableId,\n _keyArgs,\n _typedKeyArgs,\n _keyTupleDefinition,\n };\n}\n\n/** For 2 paths which are relative to a common root, create a relative import path from one to another */\nexport function solidityRelativeImportPath(fromPath: string, usedInPath: string) {\n // 1st \"./\" must be added because path strips it,\n // but solidity expects it unless there's \"../\" (\"./../\" is fine).\n // 2nd and 3rd \"./\" forcefully avoid absolute paths (everything is relative to `src`).\n return \"./\" + path.relative(\"./\" + usedInPath, \"./\" + fromPath);\n}\n\n/**\n * Aggregates, deduplicates and renders imports for symbols per path.\n * Identical symbols from different paths are NOT handled, they should be checked before rendering.\n */\nexport function renderImports(imports: ImportDatum[]) {\n return renderAbsoluteImports(\n imports.map((importDatum) => {\n if (\"path\" in importDatum) {\n return importDatum;\n } else {\n return {\n symbol: importDatum.symbol,\n path: solidityRelativeImportPath(importDatum.fromPath, importDatum.usedInPath),\n };\n }\n })\n );\n}\n\n/**\n * Aggregates, deduplicates and renders imports for symbols per path.\n * Identical symbols from different paths are NOT handled, they should be checked before rendering.\n */\nexport function renderRelativeImports(imports: RelativeImportDatum[]) {\n return renderAbsoluteImports(\n imports.map(({ symbol, fromPath, usedInPath }) => ({\n symbol,\n path: solidityRelativeImportPath(fromPath, usedInPath),\n }))\n );\n}\n\n/**\n * Aggregates, deduplicates and renders imports for symbols per path.\n * Identical symbols from different paths are NOT handled, they should be checked before rendering.\n */\nexport function renderAbsoluteImports(imports: AbsoluteImportDatum[]) {\n // Aggregate symbols by import path, also deduplicating them\n const aggregatedImports = new Map<string, Set<string>>();\n for (const { symbol, path } of imports) {\n if (!aggregatedImports.has(path)) {\n aggregatedImports.set(path, new Set());\n }\n aggregatedImports.get(path)?.add(symbol);\n }\n // Render imports\n const renderedImports = [];\n for (const [path, symbols] of aggregatedImports) {\n const renderedSymbols = [...symbols].join(\", \");\n renderedImports.push(`import { ${renderedSymbols} } from \"${posixPath(path)}\";`);\n }\n return renderedImports.join(\"\\n\");\n}\n\nexport function renderWithStore(\n storeArgument: boolean,\n callback: (\n _typedStore: string | undefined,\n _store: string,\n _commentSuffix: string,\n _untypedStore: string | undefined\n ) => string\n) {\n let result = \"\";\n result += callback(undefined, \"StoreSwitch\", \"\", undefined);\n\n if (storeArgument) {\n result += \"\\n\" + callback(\"IStore _store\", \"_store\", \" (using the specified store)\", \"_store\");\n }\n\n return result;\n}\n\nexport function renderTableId(staticResourceData: StaticResourceData) {\n const hardcodedTableId = `bytes32(abi.encodePacked(bytes16(\"${staticResourceData.namespace}\"), bytes16(\"${staticResourceData.name}\")))`;\n\n const tableIdDefinition = `\n bytes32 constant _tableId = ${hardcodedTableId};\n bytes32 constant ${staticResourceData.tableIdName} = _tableId;\n `;\n return {\n hardcodedTableId,\n tableIdDefinition,\n };\n}\n\nexport function renderValueTypeToBytes32(name: string, { typeUnwrap, internalTypeId }: RenderType) {\n const innerText = `${typeUnwrap}(${name})`;\n\n if (internalTypeId.match(/^uint\\d{1,3}$/)) {\n return `bytes32(uint256(${innerText}))`;\n } else if (internalTypeId.match(/^int\\d{1,3}$/)) {\n return `bytes32(uint256(int256(${innerText})))`;\n } else if (internalTypeId.match(/^bytes\\d{1,2}$/)) {\n return `bytes32(${innerText})`;\n } else if (internalTypeId === \"address\") {\n return `bytes32(uint256(uint160(${innerText})))`;\n } else if (internalTypeId === \"bool\") {\n return `_boolToBytes32(${innerText})`;\n } else {\n throw new Error(`Unknown value type id ${internalTypeId}`);\n }\n}\n\nfunction internalRenderList<T>(lineTerminator: string, list: T[], renderItem: (item: T, index: number) => string) {\n return list\n .map((item, index) => renderItem(item, index) + (index === list.length - 1 ? \"\" : lineTerminator))\n .join(\"\\n\");\n}\n","import { parse, visit } from \"@solidity-parser/parser\";\nimport type { SourceUnit, TypeName, VariableDeclaration } from \"@solidity-parser/parser/dist/src/ast-types\";\nimport { MUDError } from \"../../errors\";\n\nexport interface ContractInterfaceFunction {\n name: string;\n parameters: string[];\n stateMutability: string;\n returnParameters: string[];\n}\n\nexport interface ContractInterfaceError {\n name: string;\n parameters: string[];\n}\n\ninterface SymbolImport {\n symbol: string;\n path: string;\n}\n\n/**\n * Parse the contract data to get the functions necessary to generate an interface,\n * and symbols to import from the original contract.\n * @param data contents of a file with the solidity contract\n * @param contractName name of the contract\n * @returns interface data\n */\nexport function contractToInterface(data: string, contractName: string) {\n const ast = parse(data);\n\n let withContract = false;\n let symbolImports: SymbolImport[] = [];\n const functions: ContractInterfaceFunction[] = [];\n const errors: ContractInterfaceError[] = [];\n\n visit(ast, {\n ContractDefinition({ name }) {\n if (name === contractName) {\n withContract = true;\n }\n },\n FunctionDefinition(\n { name, visibility, parameters, stateMutability, returnParameters, isConstructor, isFallback, isReceiveEther },\n parent\n ) {\n if (parent !== undefined && parent.type === \"ContractDefinition\" && parent.name === contractName) {\n try {\n // skip constructor and fallbacks\n if (isConstructor || isFallback || isReceiveEther) return;\n // forbid default visibility (this check might be unnecessary, modern solidity already disallows this)\n if (visibility === \"default\") throw new MUDError(`Visibility is not specified`);\n\n if (visibility === \"external\" || visibility === \"public\") {\n functions.push({\n name: name === null ? \"\" : name,\n parameters: parameters.map(parseParameter),\n stateMutability: stateMutability || \"\",\n returnParameters: returnParameters === null ? [] : returnParameters.map(parseParameter),\n });\n\n for (const { typeName } of parameters.concat(returnParameters ?? [])) {\n const symbols = typeNameToSymbols(typeName);\n symbolImports = symbolImports.concat(symbolsToImports(ast, symbols));\n }\n }\n } catch (error: unknown) {\n if (error instanceof MUDError) {\n error.message = `Function \"${name}\" in contract \"${contractName}\": ${error.message}`;\n }\n throw error;\n }\n }\n },\n CustomErrorDefinition({ name, parameters }) {\n errors.push({\n name: name === null ? \"\" : name,\n parameters: parameters.map(parseParameter),\n });\n\n for (const parameter of parameters) {\n const symbols = typeNameToSymbols(parameter.typeName);\n symbolImports = symbolImports.concat(symbolsToImports(ast, symbols));\n }\n },\n });\n\n if (!withContract) {\n throw new MUDError(`Contract not found: ${contractName}`);\n }\n\n return {\n functions,\n errors,\n symbolImports,\n };\n}\n\nfunction parseParameter({ name, typeName, storageLocation }: VariableDeclaration): string {\n let typedNameWithLocation = \"\";\n\n const { name: flattenedTypeName, stateMutability } = flattenTypeName(typeName);\n // type name (e.g. uint256)\n typedNameWithLocation += flattenedTypeName;\n // optional mutability (e.g. address payable)\n if (stateMutability !== null) {\n typedNameWithLocation += ` ${stateMutability}`;\n }\n // location, when relevant (e.g. string memory)\n if (storageLocation !== null) {\n typedNameWithLocation += ` ${storageLocation}`;\n }\n // optional variable name\n if (name !== null) {\n typedNameWithLocation += ` ${name}`;\n }\n\n return typedNameWithLocation;\n}\n\nfunction flattenTypeName(typeName: TypeName | null): { name: string; stateMutability: string | null } {\n if (typeName === null) {\n return {\n name: \"\",\n stateMutability: null,\n };\n }\n if (typeName.type === \"ElementaryTypeName\") {\n return {\n name: typeName.name,\n stateMutability: typeName.stateMutability,\n };\n } else if (typeName.type === \"UserDefinedTypeName\") {\n return {\n name: typeName.namePath,\n stateMutability: null,\n };\n } else if (typeName.type === \"ArrayTypeName\") {\n let length = \"\";\n if (typeName.length?.type === \"NumberLiteral\") {\n length = typeName.length.number;\n } else if (typeName.length?.type === \"Identifier\") {\n length = typeName.length.name;\n }\n\n const { name, stateMutability } = flattenTypeName(typeName.baseTypeName);\n return {\n name: `${name}[${length}]`,\n stateMutability,\n };\n } else {\n // TODO function types are unsupported but could be useful\n throw new MUDError(`Invalid typeName.type ${typeName.type}`);\n }\n}\n\n// Get symbols that need to be imported for given typeName\nfunction typeNameToSymbols(typeName: TypeName | null): string[] {\n if (typeName?.type === \"UserDefinedTypeName\") {\n // split is needed to get a library, if types are internal to it\n const symbol = typeName.namePath.split(\".\")[0];\n return [symbol];\n } else if (typeName?.type === \"ArrayTypeName\") {\n const symbols = typeNameToSymbols(typeName.baseTypeName);\n // array types can also use symbols (constants) for length\n if (typeName.length?.type === \"Identifier\") {\n const innerTypeName = typeName.length.name;\n symbols.push(innerTypeName.split(\".\")[0]);\n }\n return symbols;\n } else {\n return [];\n }\n}\n\n// Get imports for given symbols.\n// To avoid circular dependencies of interfaces on their implementations,\n// symbols used for args/returns must always be imported from an auxiliary file.\n// To avoid parsing the entire project to build dependencies,\n// symbols must be imported with an explicit `import { symbol } from ...`\nfunction symbolsToImports(ast: SourceUnit, symbols: string[]) {\n const imports: SymbolImport[] = [];\n\n for (const symbol of symbols) {\n let symbolImport: SymbolImport | undefined;\n\n visit(ast, {\n ImportDirective({ path, symbolAliases }) {\n if (symbolAliases) {\n for (const symbolAndAlias of symbolAliases) {\n // either check the alias, or the original symbol if there's no alias\n const symbolAlias = symbolAndAlias[1] || symbolAndAlias[0];\n if (symbol === symbolAlias) {\n symbolImport = {\n // always use the original symbol for interface imports\n symbol: symbolAndAlias[0],\n path,\n };\n return;\n }\n }\n }\n },\n });\n\n if (symbolImport) {\n imports.push(symbolImport);\n } else {\n throw new MUDError(`Symbol \"${symbol}\" has no explicit import`);\n }\n }\n\n return imports;\n}\n","import chalk from \"chalk\";\nimport prettier from \"prettier\";\nimport prettierPluginSolidity from \"prettier-plugin-solidity\";\n\nexport async function formatSolidity(content: string, prettierConfigPath?: string) {\n let config;\n if (prettierConfigPath) {\n config = await prettier.resolveConfig(prettierConfigPath);\n }\n try {\n return prettier.format(content, {\n plugins: [prettierPluginSolidity],\n parser: \"solidity-parse\",\n\n printWidth: 120,\n semi: true,\n tabWidth: 2,\n useTabs: false,\n bracketSpacing: true,\n\n ...config,\n });\n } catch (error) {\n let message;\n if (error instanceof Error) {\n message = error.message;\n } else {\n message = error;\n }\n console.log(chalk.yellow(`Error during output formatting: ${message}`));\n return content;\n }\n}\n\nexport async function formatTypescript(content: string) {\n return prettier.format(content, {\n parser: \"typescript\",\n });\n}\n","import { mkdirSync, writeFileSync } from \"fs\";\nimport { dirname } from \"path\";\nimport { formatSolidity, formatTypescript } from \"./format\";\n\nexport async function formatAndWriteSolidity(output: string, fullOutputPath: string, logPrefix: string) {\n const formattedOutput = await formatSolidity(output);\n\n mkdirSync(dirname(fullOutputPath), { recursive: true });\n\n writeFileSync(fullOutputPath, formattedOutput);\n console.log(`${logPrefix}: ${fullOutputPath}`);\n}\n\nexport async function formatAndWriteTypescript(output: string, fullOutputPath: string, logPrefix: string) {\n const formattedOutput = await formatTypescript(output);\n\n mkdirSync(dirname(fullOutputPath), { recursive: true });\n\n writeFileSync(fullOutputPath, formattedOutput);\n console.log(`${logPrefix}: ${fullOutputPath}`);\n}\n","/**\n * Explicitly normalize a given path to a posix path (using `/` as separator).\n * This should be used for generating Solidity files that will be consumed by solc,\n * because solc expects `/` as path separator, but path.join produces `\\` if the user is on windows.\n */\nexport function posixPath(path: string) {\n return path.replace(/\\\\/g, \"/\");\n}\n","import { renderArguments, renderList, renderedSolidityHeader } from \"./common\";\nimport { RenderEnum } from \"./types\";\n\nexport function renderEnums(enums: RenderEnum[]) {\n let result = renderedSolidityHeader;\n\n result += renderList(\n enums,\n ({ name, memberNames }) => `\n enum ${name} {\n ${renderArguments(memberNames)}\n }\n `\n );\n\n return result;\n}\n","import { RenderField, RenderKeyTuple, RenderType } from \"./types\";\n\nexport function renderTypeHelpers(options: { fields: RenderField[]; keyTuple: RenderKeyTuple[] }) {\n const { fields, keyTuple } = options;\n\n let result = \"\";\n\n for (const wrappingHelper of getWrappingHelpers([...fields, ...keyTuple])) {\n result += wrappingHelper;\n }\n\n // bool is special - it's the only primitive value type that can't be typecasted to/from\n if (fields.some(({ internalTypeId }) => internalTypeId.match(\"bool\"))) {\n result += `\n function _toBool(uint8 value) pure returns (bool result) {\n assembly {\n result := value\n }\n }\n `;\n }\n if (keyTuple.some(({ internalTypeId }) => internalTypeId.match(\"bool\"))) {\n result += `\n function _boolToBytes32(bool value) pure returns (bytes32 result) {\n assembly {\n result := value\n }\n }\n `;\n }\n\n return result;\n}\n\nfunction getWrappingHelpers(array: RenderType[]) {\n const wrappers = new Map();\n const unwrappers = new Map();\n for (const { typeWrappingData, typeWrap, typeUnwrap, internalTypeId } of array) {\n if (!typeWrappingData) continue;\n const { kind } = typeWrappingData;\n\n if (kind === \"staticArray\") {\n const { elementType, staticLength } = typeWrappingData;\n wrappers.set(typeWrap, renderWrapperStaticArray(typeWrap, elementType, staticLength, internalTypeId));\n unwrappers.set(typeUnwrap, renderUnwrapperStaticArray(typeUnwrap, elementType, staticLength, internalTypeId));\n }\n }\n\n return [...wrappers.values(), ...unwrappers.values()];\n}\n\nfunction renderWrapperStaticArray(\n functionName: string,\n elementType: string,\n staticLength: number,\n internalTypeId: string\n) {\n // WARNING: ensure this still works if changing major solidity versions!\n // (the memory layout for static arrays may change)\n return `\n function ${functionName}(\n ${internalTypeId} memory _value\n ) pure returns (\n ${elementType}[${staticLength}] memory _result\n ) {\n // in memory static arrays are just dynamic arrays without the length byte\n assembly {\n _result := add(_value, 0x20)\n }\n }\n `;\n}\n\nfunction renderUnwrapperStaticArray(\n functionName: string,\n elementType: string,\n staticLength: number,\n internalTypeId: string\n) {\n // byte length for memory copying (more efficient than a loop)\n const byteLength = staticLength * 32;\n // TODO to optimize memory usage consider generalizing TightEncoder to a render-time utility\n return `\n function ${functionName}(\n ${elementType}[${staticLength}] memory _value\n ) view returns (\n ${internalTypeId} memory _result\n ) {\n _result = new ${internalTypeId}(${staticLength});\n uint256 fromPointer;\n uint256 toPointer;\n assembly {\n fromPointer := _value\n toPointer := add(_result, 0x20)\n }\n Memory.copy(fromPointer, toPointer, ${byteLength});\n }\n `;\n}\n","import { SchemaType } from \"@latticexyz/schema-type\";\n\nexport const schemaTypesToRecsTypeStrings: Record<SchemaType, string> = {\n [SchemaType.UINT8]: \"RecsType.Number\",\n [SchemaType.UINT16]: \"RecsType.Number\",\n [SchemaType.UINT24]: \"RecsType.Number\",\n [SchemaType.UINT32]: \"RecsType.Number\",\n [SchemaType.UINT40]: \"RecsType.Number\",\n [SchemaType.UINT48]: \"RecsType.Number\",\n [SchemaType.UINT56]: \"RecsType.BigInt\",\n [SchemaType.UINT64]: \"RecsType.BigInt\",\n [SchemaType.UINT72]: \"RecsType.BigInt\",\n [SchemaType.UINT80]: \"RecsType.BigInt\",\n [SchemaType.UINT88]: \"RecsType.BigInt\",\n [SchemaType.UINT96]: \"RecsType.BigInt\",\n [SchemaType.UINT104]: \"RecsType.BigInt\",\n [SchemaType.UINT112]: \"RecsType.BigInt\",\n [SchemaType.UINT120]: \"RecsType.BigInt\",\n [SchemaType.UINT128]: \"RecsType.BigInt\",\n [SchemaType.UINT136]: \"RecsType.BigInt\",\n [SchemaType.UINT144]: \"RecsType.BigInt\",\n [SchemaType.UINT152]: \"RecsType.BigInt\",\n [SchemaType.UINT160]: \"RecsType.BigInt\",\n [SchemaType.UINT168]: \"RecsType.BigInt\",\n [SchemaType.UINT176]: \"RecsType.BigInt\",\n [SchemaType.UINT184]: \"RecsType.BigInt\",\n [SchemaType.UINT192]: \"RecsType.BigInt\",\n [SchemaType.UINT200]: \"RecsType.BigInt\",\n [SchemaType.UINT208]: \"RecsType.BigInt\",\n [SchemaType.UINT216]: \"RecsType.BigInt\",\n [SchemaType.UINT224]: \"RecsType.BigInt\",\n [SchemaType.UINT232]: \"RecsType.BigInt\",\n [SchemaType.UINT240]: \"RecsType.BigInt\",\n [SchemaType.UINT248]: \"RecsType.BigInt\",\n [SchemaType.UINT256]: \"RecsType.BigInt\",\n [SchemaType.INT8]: \"RecsType.Number\",\n [SchemaType.INT16]: \"RecsType.Number\",\n [SchemaType.INT24]: \"RecsType.Number\",\n [SchemaType.INT32]: \"RecsType.Number\",\n [SchemaType.INT40]: \"RecsType.Number\",\n [SchemaType.INT48]: \"RecsType.Number\",\n [SchemaType.INT56]: \"RecsType.BigInt\",\n [SchemaType.INT64]: \"RecsType.BigInt\",\n [SchemaType.INT72]: \"RecsType.BigInt\",\n [SchemaType.INT80]: \"RecsType.BigInt\",\n [SchemaType.INT88]: \"RecsType.BigInt\",\n [SchemaType.INT96]: \"RecsType.BigInt\",\n [SchemaType.INT104]: \"RecsType.BigInt\",\n [SchemaType.INT112]: \"RecsType.BigInt\",\n [SchemaType.INT120]: \"RecsType.BigInt\",\n [SchemaType.INT128]: \"RecsType.BigInt\",\n [SchemaType.INT136]: \"RecsType.BigInt\",\n [SchemaType.INT144]: \"RecsType.BigInt\",\n [SchemaType.INT152]: \"RecsType.BigInt\",\n [SchemaType.INT160]: \"RecsType.BigInt\",\n [SchemaType.INT168]: \"RecsType.BigInt\",\n [SchemaType.INT176]: \"RecsType.BigInt\",\n [SchemaType.INT184]: \"RecsType.BigInt\",\n [SchemaType.INT192]: \"RecsType.BigInt\",\n [SchemaType.INT200]: \"RecsType.BigInt\",\n [SchemaType.INT208]: \"RecsType.BigInt\",\n [SchemaType.INT216]: \"RecsType.BigInt\",\n [SchemaType.INT224]: \"RecsType.BigInt\",\n [SchemaType.INT232]: \"RecsType.BigInt\",\n [SchemaType.INT240]: \"RecsType.BigInt\",\n [SchemaType.INT248]: \"RecsType.BigInt\",\n [SchemaType.INT256]: \"RecsType.BigInt\",\n [SchemaType.BYTES1]: \"RecsType.String\",\n [SchemaType.BYTES2]: \"RecsType.String\",\n [SchemaType.BYTES3]: \"RecsType.String\",\n [SchemaType.BYTES4]: \"RecsType.String\",\n [SchemaType.BYTES5]: \"RecsType.String\",\n [SchemaType.BYTES6]: \"RecsType.String\",\n [SchemaType.BYTES7]: \"RecsType.String\",\n [SchemaType.BYTES8]: \"RecsType.String\",\n [SchemaType.BYTES9]: \"RecsType.String\",\n [SchemaType.BYTES10]: \"RecsType.String\",\n [SchemaType.BYTES11]: \"RecsType.String\",\n [SchemaType.BYTES12]: \"RecsType.String\",\n [SchemaType.BYTES13]: \"RecsType.String\",\n [SchemaType.BYTES14]: \"RecsType.String\",\n [SchemaType.BYTES15]: \"RecsType.String\",\n [SchemaType.BYTES16]: \"RecsType.String\",\n [SchemaType.BYTES17]: \"RecsType.String\",\n [SchemaType.BYTES18]: \"RecsType.String\",\n [SchemaType.BYTES19]: \"RecsType.String\",\n [SchemaType.BYTES20]: \"RecsType.String\",\n [SchemaType.BYTES21]: \"RecsType.String\",\n [SchemaType.BYTES22]: \"RecsType.String\",\n [SchemaType.BYTES23]: \"RecsType.String\",\n [SchemaType.BYTES24]: \"RecsType.String\",\n [SchemaType.BYTES25]: \"RecsType.String\",\n [SchemaType.BYTES26]: \"RecsType.String\",\n [SchemaType.BYTES27]: \"RecsType.String\",\n [SchemaType.BYTES28]: \"RecsType.String\",\n [SchemaType.BYTES29]: \"RecsType.String\",\n [SchemaType.BYTES30]: \"RecsType.String\",\n [SchemaType.BYTES31]: \"RecsType.String\",\n [SchemaType.BYTES32]: \"RecsType.String\",\n [SchemaType.BOOL]: \"RecsType.Boolean\",\n [SchemaType.ADDRESS]: \"RecsType.String\",\n [SchemaType.UINT8_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT16_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT24_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT32_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT40_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT48_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.UINT56_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT64_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT72_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT80_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT88_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT96_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT104_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT112_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT120_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT128_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT136_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT144_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT152_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT160_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT168_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT176_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT184_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT192_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT200_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT208_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT216_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT224_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT232_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT240_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT248_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.UINT256_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT8_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT16_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT24_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT32_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT40_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT48_ARRAY]: \"RecsType.NumberArray\",\n [SchemaType.INT56_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT64_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT72_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT80_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT88_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT96_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT104_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT112_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT120_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT128_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT136_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT144_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT152_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT160_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT168_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT176_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT184_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT192_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT200_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT208_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT216_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT224_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT232_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT240_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT248_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.INT256_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES1_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES2_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES3_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES4_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES5_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES6_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES7_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES8_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES9_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES10_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES11_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES12_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES13_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES14_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES15_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES16_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES17_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES18_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES19_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES20_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES21_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES22_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES23_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES24_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES25_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES26_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES27_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES28_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES29_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES30_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES31_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BYTES32_ARRAY]: \"RecsType.BigIntArray\",\n [SchemaType.BOOL_ARRAY]: \"RecsType.T\", // no boolean array\n [SchemaType.ADDRESS_ARRAY]: \"RecsType.StringArray\",\n [SchemaType.BYTES]: \"RecsType.String\",\n [SchemaType.STRING]: \"RecsType.String\",\n};\n"],"mappings":"mCAAA,OAAOA,MAAU,OCAjB,OAAS,SAAAC,EAAO,SAAAC,MAAa,0BA4BtB,SAASC,EAAoBC,EAAcC,EAAsB,CACtE,IAAMC,EAAMC,EAAMH,CAAI,EAElBI,EAAe,GACfC,EAAgC,CAAC,EAC/BC,EAAyC,CAAC,EAC1CC,EAAmC,CAAC,EAqD1C,GAnDAC,EAAMN,EAAK,CACT,mBAAmB,CAAE,KAAAO,CAAK,EAAG,CACvBA,IAASR,IACXG,EAAe,GAEnB,EACA,mBACE,CAAE,KAAAK,EAAM,WAAAC,EAAY,WAAAC,EAAY,gBAAAC,EAAiB,iBAAAC,EAAkB,cAAAC,EAAe,WAAAC,EAAY,eAAAC,CAAe,EAC7GC,EACA,CACA,GAAIA,IAAW,QAAaA,EAAO,OAAS,sBAAwBA,EAAO,OAAShB,EA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Y,EAAG,uBAC3B,CAACA,EAAW,YAAY,EAAG,uBAC3B,CAACA,EAAW,YAAY,EAAG,uBAC3B,CAACA,EAAW,YAAY,EAAG,uBAC3B,CAACA,EAAW,YAAY,EAAG,uBAC3B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,UAAU,EAAG,aACzB,CAACA,EAAW,aAAa,EAAG,uBAC5B,CAACA,EAAW,KAAK,EAAG,kBACpB,CAACA,EAAW,MAAM,EAAG,iBACvB","names":["path","parse","visit","contractToInterface","data","contractName","ast","parse","withContract","symbolImports","functions","errors","visit","name","visibility","parameters","stateMutability","returnParameters","isConstructor","isFallback","isReceiveEther","parent","MUDError","parseParameter","typeName","symbols","typeNameToSymbols","symbolsToImports","error","parameter","storageLocation","typedNameWithLocation","flattenedTypeName","flattenTypeName","length","innerTypeName","imports","symbol","symbolImport","path","symbolAliases","symbolAndAlias","symbolAlias","chalk","prettier","prettierPluginSolidity","formatSolidity","content","prettierConfigPath","config","error","message","formatTypescript","mkdirSync","writeFileSync","dirname","formatAndWriteSolidity","output","fullOutputPath","logPrefix","formattedOutput","formatSolidity","mkdirSync","dirname","writeFileSync","formatAndWriteTypescript","formatTypescript","posixPath","path","renderedSolidityHeader","renderList","list","renderItem","internalRenderList","renderArguments","args","filteredArgs","arg","renderCommonData","staticResourceData","keyTuple","_tableId","_typedTableId","_keyArgs","name","_typedKeyArgs","typeWithLocation","_keyTupleDefinition","key","index","renderValueTypeToBytes32","solidityRelativeImportPath","fromPath","usedInPath","path","renderImports","imports","renderAbsoluteImports","importDatum","renderRelativeImports","symbol","aggregatedImports","renderedImports","symbols","renderedSymbols","posixPath","renderWithStore","storeArgument","callback","result","renderTableId","hardcodedTableId","tableIdDefinition","typeUnwrap","internalTypeId","innerText","lineTerminator","item","renderEnums","enums","result","renderedSolidityHeader","renderList","name","memberNames","renderArguments","renderTypeHelpers","options","fields","keyTuple","result","wrappingHelper","getWrappingHelpers","internalTypeId","array","wrappers","unwrappers","typeWrappingData","typeWrap","typeUnwrap","kind","elementType","staticLength","renderWrapperStaticArray","renderUnwrapperStaticArray","functionName","byteLength","SchemaType","schemaTypesToRecsTypeStrings"]}
package/dist/errors.js ADDED
@@ -0,0 +1,2 @@
1
+ import{a}from"./chunk-UPQEB2HW.js";export{a as MUDError};
2
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,3 @@
1
+ import{execa as o}from"execa";import a from"chalk";async function n(t){let{stdout:r}=await o("forge",["config","--json"],{stdio:["inherit","pipe","pipe"],env:{FOUNDRY_PROFILE:t}});return JSON.parse(r)}async function l(t){return(await n(t)).src}async function y(t){return(await n(t)).script}async function x(t){return(await n(t)).test}async function O(t){return(await n(t)).out}async function w(t){return(await n(t)).eth_rpc_url||"http://127.0.0.1:8545"}async function d(t,r){let i={env:{FOUNDRY_PROFILE:r?.profile},stdout:"inherit",stderr:"pipe"};await(r?.silent?o("forge",t,i):s("forge",t,i))}async function m(t,r){return s("cast",t,{env:{FOUNDRY_PROFILE:r?.profile}})}async function F(t){return s("anvil",t)}async function s(t,r,i){let c=`${t} ${r.join(" ")}`;try{console.log(a.gray(`running "${c}"`));let{stdout:e}=await o(t,r,{stdout:"pipe",stderr:"pipe",...i});return e}catch(e){let g=e?.stderr||e?.message||"";throw g+=a.red(`
2
+ Error running "${c}"`),new Error(g)}}export{F as anvil,m as cast,d as forge,n as getForgeConfig,O as getOutDirectory,w as getRpcUrl,y as getScriptDirectory,l as getSrcDirectory,x as getTestDirectory};
3
+ //# sourceMappingURL=foundry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/foundry/index.ts"],"sourcesContent":["import { execa, Options } from \"execa\";\nimport chalk from \"chalk\";\n\nexport interface ForgeConfig {\n // project\n src: string;\n test: string;\n script: string;\n out: string;\n libs: string[];\n eth_rpc_url: string | null;\n\n // all unspecified keys (this interface is far from comprehensive)\n [key: string]: unknown;\n}\n\n/**\n * Get forge config as a parsed json object.\n */\nexport async function getForgeConfig(profile?: string) {\n const { stdout } = await execa(\"forge\", [\"config\", \"--json\"], {\n stdio: [\"inherit\", \"pipe\", \"pipe\"],\n env: { FOUNDRY_PROFILE: profile },\n });\n\n return JSON.parse(stdout) as ForgeConfig;\n}\n\n/**\n * Get the value of \"src\" from forge config.\n * The path to the contract sources relative to the root of the project.\n */\nexport async function getSrcDirectory(profile?: string) {\n return (await getForgeConfig(profile)).src;\n}\n\n/**\n * Get the value of \"script\" from forge config.\n * The path to the contract sources relative to the root of the project.\n */\nexport async function getScriptDirectory(profile?: string) {\n return (await getForgeConfig(profile)).script;\n}\n\n/**\n * Get the value of \"test\" from forge config.\n * The path to the test contract sources relative to the root of the project.\n */\nexport async function getTestDirectory(profile?: string) {\n return (await getForgeConfig(profile)).test;\n}\n\n/**\n * Get the value of \"out\" from forge config.\n * The path to put contract artifacts in, relative to the root of the project.\n */\nexport async function getOutDirectory(profile?: string) {\n return (await getForgeConfig(profile)).out;\n}\n\n/**\n * Get the value of \"eth_rpc_url\" from forge config, default to \"http://127.0.0.1:8545\"\n * @param profile The foundry profile to use\n * @returns The rpc url\n */\nexport async function getRpcUrl(profile?: string) {\n return (await getForgeConfig(profile)).eth_rpc_url || \"http://127.0.0.1:8545\";\n}\n\n/**\n * Execute a forge command\n * @param args The arguments to pass to forge\n * @param options { profile?: The foundry profile to use; silent?: If true, nothing will be logged to the console }\n */\nexport async function forge(args: string[], options?: { profile?: string; silent?: boolean }): Promise<void> {\n const execOptions: Options<string> = {\n env: { FOUNDRY_PROFILE: options?.profile },\n stdout: \"inherit\",\n stderr: \"pipe\",\n };\n\n await (options?.silent ? execa(\"forge\", args, execOptions) : execLog(\"forge\", args, execOptions));\n}\n\n/**\n * Execute a cast command\n * @param args The arguments to pass to cast\n * @returns Stdout of the command\n */\nexport async function cast(args: string[], options?: { profile?: string }): Promise<string> {\n return execLog(\"cast\", args, {\n env: { FOUNDRY_PROFILE: options?.profile },\n });\n}\n\n/**\n * Start an anvil chain\n * @param args The arguments to pass to anvil\n * @returns Stdout of the command\n */\nexport async function anvil(args: string[]): Promise<string> {\n return execLog(\"anvil\", args);\n}\n\n/**\n * Executes the given command, returns the stdout, and logs the command to the console.\n * Throws an error if the command fails.\n * @param command The command to execute\n * @param args The arguments to pass to the command\n * @returns The stdout of the command\n */\nasync function execLog(command: string, args: string[], options?: Options<string>): Promise<string> {\n const commandString = `${command} ${args.join(\" \")}`;\n try {\n console.log(chalk.gray(`running \"${commandString}\"`));\n const { stdout } = await execa(command, args, { stdout: \"pipe\", stderr: \"pipe\", ...options });\n return stdout;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (error: any) {\n let errorMessage = error?.stderr || error?.message || \"\";\n errorMessage += chalk.red(`\\nError running \"${commandString}\"`);\n throw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ACF,QAAQ,IAAIV,EAAM,KAAK,YAAYiB,IAAgB,CAAC,EACpD,GAAM,CAAE,OAAAd,CAAO,EAAI,MAAMJ,EAAMiB,EAASN,EAAM,CAAE,OAAQ,OAAQ,OAAQ,OAAQ,GAAGC,CAAQ,CAAC,EAC5F,OAAOR,CAET,OAASe,EAAP,CACA,IAAIC,EAAeD,GAAO,QAAUA,GAAO,SAAW,GACtD,MAAAC,GAAgBnB,EAAM,IAAI;AAAA,iBAAoBiB,IAAgB,EACxD,IAAI,MAAME,CAAY,CAC9B,CACF","names":["execa","chalk","getForgeConfig","profile","stdout","getSrcDirectory","getScriptDirectory","getTestDirectory","getOutDirectory","getRpcUrl","forge","args","options","execOptions","execLog","cast","anvil","command","commandString","error","errorMessage"]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=type-utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/utils.js ADDED
@@ -0,0 +1,2 @@
1
+ function n(a,...r){return(...e)=>a(...r,...e)}export{n as curry};
2
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/curry.ts"],"sourcesContent":["export function curry<F extends (...params: [...P, ...any[]]) => any, P extends any[]>(func: F, ...partialParams: P) {\n return ((...args: any[]) => func(...partialParams, ...args)) as CurryParams<F, P>;\n}\n\ntype CurryParams<F extends (...params: [...PartialParams, ...any[]]) => any, PartialParams extends any[]> = F extends (\n ...params: [...PartialParams, ...infer RemainingParams]\n) => infer Result\n ? (...params: RemainingParams) => Result\n : never;\n"],"mappings":"AAAO,SAASA,EAAuEC,KAAYC,EAAkB,CACnH,MAAQ,IAAIC,IAAgBF,EAAK,GAAGC,EAAe,GAAGC,CAAI,CAC5D","names":["curry","func","partialParams","args"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@latticexyz/common",
3
- "version": "2.0.0-alpha.1.21+4ad66187",
3
+ "version": "2.0.0-alpha.1.210+69c126a9",
4
4
  "description": "Common low level logic shared between packages",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,8 +10,12 @@
10
10
  "license": "MIT",
11
11
  "type": "module",
12
12
  "exports": {
13
- "./codegen": "./dist/codegen/index.js",
14
- "./foundry": "./dist/foundry/index.js"
13
+ "./codegen": "./dist/codegen.js",
14
+ "./foundry": "./dist/foundry.js",
15
+ "./type-utils": "./dist/type-utils.js",
16
+ "./utils": "./dist/utils.js",
17
+ "./errors": "./dist/errors.js",
18
+ "./chains": "./dist/chains.js"
15
19
  },
16
20
  "typesVersions": {
17
21
  "*": {
@@ -20,31 +24,42 @@
20
24
  ],
21
25
  "foundry": [
22
26
  "./src/foundry/index.ts"
27
+ ],
28
+ "type-utils": [
29
+ "./src/type-utils/index.ts"
30
+ ],
31
+ "utils": [
32
+ "./src/utils/index.ts"
33
+ ],
34
+ "errors": [
35
+ "./src/errors/index.ts"
36
+ ],
37
+ "chains": [
38
+ "./src/chains/index.ts"
23
39
  ]
24
40
  }
25
41
  },
26
- "files": [
27
- "dist"
28
- ],
29
42
  "scripts": {
30
- "build": "vite build",
31
- "release": "npm publish --access=public",
43
+ "build": "pnpm run build:js",
44
+ "build:js": "tsup",
45
+ "clean": "pnpm run clean:js",
46
+ "clean:js": "rimraf dist",
47
+ "dev": "tsup --watch",
32
48
  "test": "vitest typecheck --run --passWithNoTests"
33
49
  },
34
50
  "dependencies": {
35
- "@latticexyz/config": "2.0.0-alpha.1.21+4ad66187",
36
- "@latticexyz/schema-type": "2.0.0-alpha.1.21+4ad66187",
37
- "@latticexyz/solidity-parser": "^0.16.0",
51
+ "@latticexyz/schema-type": "2.0.0-alpha.1.210+69c126a9",
52
+ "@solidity-parser/parser": "^0.16.0",
38
53
  "chalk": "^5.2.0",
39
54
  "execa": "^7.0.0",
40
55
  "prettier": "^2.8.4",
41
56
  "prettier-plugin-solidity": "^1.1.2"
42
57
  },
43
58
  "devDependencies": {
44
- "@types/rollup-plugin-peer-deps-external": "^2.2.1",
45
- "rollup-plugin-peer-deps-external": "^2.2.4",
46
- "vite": "^4.3.0",
47
- "vitest": "^0.30.1"
59
+ "@types/node": "^18.15.11",
60
+ "@wagmi/chains": "^0.2.22",
61
+ "tsup": "^6.7.0",
62
+ "vitest": "0.30.1"
48
63
  },
49
- "gitHead": "4ad661878bcf916a9ab7fd4d72d051b372af74c5"
64
+ "gitHead": "69c126a9e3d95a451b88d36c50e30279cc628a9d"
50
65
  }
@@ -0,0 +1,2 @@
1
+ export type { MUDChain } from "./types";
2
+ export { latticeTestnet } from "./latticeTestnet";
@@ -0,0 +1,30 @@
1
+ import type { MUDChain } from "./types";
2
+
3
+ export const latticeTestnet = {
4
+ name: "Lattice Testnet",
5
+ id: 4242,
6
+ network: "lattice-testnet",
7
+ nativeCurrency: { decimals: 18, name: "Ether", symbol: "ETH" },
8
+ rpcUrls: {
9
+ default: {
10
+ http: ["https://follower.testnet-chain.linfra.xyz"],
11
+ webSocket: ["wss://follower.testnet-chain.linfra.xyz"],
12
+ },
13
+ public: {
14
+ http: ["https://follower.testnet-chain.linfra.xyz"],
15
+ webSocket: ["wss://follower.testnet-chain.linfra.xyz"],
16
+ },
17
+ },
18
+ blockExplorers: {
19
+ otterscan: {
20
+ name: "Otterscan",
21
+ url: "https://explorer.testnet-chain.linfra.xyz",
22
+ },
23
+ default: {
24
+ name: "Otterscan",
25
+ url: "https://explorer.testnet-chain.linfra.xyz",
26
+ },
27
+ },
28
+ modeUrl: "https://mode.testnet-mud-services.linfra.xyz",
29
+ faucetUrl: "https://faucet.testnet-mud-services.linfra.xyz",
30
+ } as const satisfies MUDChain;
@@ -0,0 +1,6 @@
1
+ import type { Chain } from "@wagmi/chains";
2
+
3
+ export type MUDChain = Chain & {
4
+ modeUrl?: string;
5
+ faucetUrl?: string;
6
+ };
@@ -0,0 +1,4 @@
1
+ import "./modules.d";
2
+ export * from "./render-solidity";
3
+ export * from "./render-typescript";
4
+ export * from "./utils";
@@ -0,0 +1 @@
1
+ declare module "prettier-plugin-solidity";
@@ -0,0 +1,176 @@
1
+ import path from "path";
2
+ import {
3
+ AbsoluteImportDatum,
4
+ RelativeImportDatum,
5
+ ImportDatum,
6
+ StaticResourceData,
7
+ RenderKeyTuple,
8
+ RenderType,
9
+ } from "./types";
10
+ import { posixPath } from "../utils";
11
+
12
+ export const renderedSolidityHeader = `// SPDX-License-Identifier: MIT
13
+ pragma solidity >=0.8.0;
14
+
15
+ /* Autogenerated file. Do not edit manually. */`;
16
+
17
+ /**
18
+ * Renders a list of lines
19
+ */
20
+ export function renderList<T>(list: T[], renderItem: (item: T, index: number) => string) {
21
+ return internalRenderList("", list, renderItem);
22
+ }
23
+
24
+ /**
25
+ * Renders a comma-separated list of arguments for solidity functions, ignoring empty and undefined ones
26
+ */
27
+ export function renderArguments(args: (string | undefined)[]) {
28
+ const filteredArgs = args.filter((arg) => arg !== undefined && arg !== "") as string[];
29
+ return internalRenderList(",", filteredArgs, (arg) => arg);
30
+ }
31
+
32
+ export function renderCommonData({
33
+ staticResourceData,
34
+ keyTuple,
35
+ }: {
36
+ staticResourceData?: StaticResourceData;
37
+ keyTuple: RenderKeyTuple[];
38
+ }) {
39
+ // static resource means static tableId as well, and no tableId arguments
40
+ const _tableId = staticResourceData ? "" : "_tableId";
41
+ const _typedTableId = staticResourceData ? "" : "bytes32 _tableId";
42
+
43
+ const _keyArgs = renderArguments(keyTuple.map(({ name }) => name));
44
+ const _typedKeyArgs = renderArguments(keyTuple.map(({ name, typeWithLocation }) => `${typeWithLocation} ${name}`));
45
+
46
+ const _keyTupleDefinition = `
47
+ bytes32[] memory _keyTuple = new bytes32[](${keyTuple.length});
48
+ ${renderList(keyTuple, (key, index) => `_keyTuple[${index}] = ${renderValueTypeToBytes32(key.name, key)};`)}
49
+ `;
50
+
51
+ return {
52
+ _tableId,
53
+ _typedTableId,
54
+ _keyArgs,
55
+ _typedKeyArgs,
56
+ _keyTupleDefinition,
57
+ };
58
+ }
59
+
60
+ /** For 2 paths which are relative to a common root, create a relative import path from one to another */
61
+ export function solidityRelativeImportPath(fromPath: string, usedInPath: string) {
62
+ // 1st "./" must be added because path strips it,
63
+ // but solidity expects it unless there's "../" ("./../" is fine).
64
+ // 2nd and 3rd "./" forcefully avoid absolute paths (everything is relative to `src`).
65
+ return "./" + path.relative("./" + usedInPath, "./" + fromPath);
66
+ }
67
+
68
+ /**
69
+ * Aggregates, deduplicates and renders imports for symbols per path.
70
+ * Identical symbols from different paths are NOT handled, they should be checked before rendering.
71
+ */
72
+ export function renderImports(imports: ImportDatum[]) {
73
+ return renderAbsoluteImports(
74
+ imports.map((importDatum) => {
75
+ if ("path" in importDatum) {
76
+ return importDatum;
77
+ } else {
78
+ return {
79
+ symbol: importDatum.symbol,
80
+ path: solidityRelativeImportPath(importDatum.fromPath, importDatum.usedInPath),
81
+ };
82
+ }
83
+ })
84
+ );
85
+ }
86
+
87
+ /**
88
+ * Aggregates, deduplicates and renders imports for symbols per path.
89
+ * Identical symbols from different paths are NOT handled, they should be checked before rendering.
90
+ */
91
+ export function renderRelativeImports(imports: RelativeImportDatum[]) {
92
+ return renderAbsoluteImports(
93
+ imports.map(({ symbol, fromPath, usedInPath }) => ({
94
+ symbol,
95
+ path: solidityRelativeImportPath(fromPath, usedInPath),
96
+ }))
97
+ );
98
+ }
99
+
100
+ /**
101
+ * Aggregates, deduplicates and renders imports for symbols per path.
102
+ * Identical symbols from different paths are NOT handled, they should be checked before rendering.
103
+ */
104
+ export function renderAbsoluteImports(imports: AbsoluteImportDatum[]) {
105
+ // Aggregate symbols by import path, also deduplicating them
106
+ const aggregatedImports = new Map<string, Set<string>>();
107
+ for (const { symbol, path } of imports) {
108
+ if (!aggregatedImports.has(path)) {
109
+ aggregatedImports.set(path, new Set());
110
+ }
111
+ aggregatedImports.get(path)?.add(symbol);
112
+ }
113
+ // Render imports
114
+ const renderedImports = [];
115
+ for (const [path, symbols] of aggregatedImports) {
116
+ const renderedSymbols = [...symbols].join(", ");
117
+ renderedImports.push(`import { ${renderedSymbols} } from "${posixPath(path)}";`);
118
+ }
119
+ return renderedImports.join("\n");
120
+ }
121
+
122
+ export function renderWithStore(
123
+ storeArgument: boolean,
124
+ callback: (
125
+ _typedStore: string | undefined,
126
+ _store: string,
127
+ _commentSuffix: string,
128
+ _untypedStore: string | undefined
129
+ ) => string
130
+ ) {
131
+ let result = "";
132
+ result += callback(undefined, "StoreSwitch", "", undefined);
133
+
134
+ if (storeArgument) {
135
+ result += "\n" + callback("IStore _store", "_store", " (using the specified store)", "_store");
136
+ }
137
+
138
+ return result;
139
+ }
140
+
141
+ export function renderTableId(staticResourceData: StaticResourceData) {
142
+ const hardcodedTableId = `bytes32(abi.encodePacked(bytes16("${staticResourceData.namespace}"), bytes16("${staticResourceData.name}")))`;
143
+
144
+ const tableIdDefinition = `
145
+ bytes32 constant _tableId = ${hardcodedTableId};
146
+ bytes32 constant ${staticResourceData.tableIdName} = _tableId;
147
+ `;
148
+ return {
149
+ hardcodedTableId,
150
+ tableIdDefinition,
151
+ };
152
+ }
153
+
154
+ export function renderValueTypeToBytes32(name: string, { typeUnwrap, internalTypeId }: RenderType) {
155
+ const innerText = `${typeUnwrap}(${name})`;
156
+
157
+ if (internalTypeId.match(/^uint\d{1,3}$/)) {
158
+ return `bytes32(uint256(${innerText}))`;
159
+ } else if (internalTypeId.match(/^int\d{1,3}$/)) {
160
+ return `bytes32(uint256(int256(${innerText})))`;
161
+ } else if (internalTypeId.match(/^bytes\d{1,2}$/)) {
162
+ return `bytes32(${innerText})`;
163
+ } else if (internalTypeId === "address") {
164
+ return `bytes32(uint256(uint160(${innerText})))`;
165
+ } else if (internalTypeId === "bool") {
166
+ return `_boolToBytes32(${innerText})`;
167
+ } else {
168
+ throw new Error(`Unknown value type id ${internalTypeId}`);
169
+ }
170
+ }
171
+
172
+ function internalRenderList<T>(lineTerminator: string, list: T[], renderItem: (item: T, index: number) => string) {
173
+ return list
174
+ .map((item, index) => renderItem(item, index) + (index === list.length - 1 ? "" : lineTerminator))
175
+ .join("\n");
176
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./common";
2
+ export * from "./renderEnums";
3
+ export * from "./renderTypeHelpers";
4
+ export * from "./types";
@@ -0,0 +1,17 @@
1
+ import { renderArguments, renderList, renderedSolidityHeader } from "./common";
2
+ import { RenderEnum } from "./types";
3
+
4
+ export function renderEnums(enums: RenderEnum[]) {
5
+ let result = renderedSolidityHeader;
6
+
7
+ result += renderList(
8
+ enums,
9
+ ({ name, memberNames }) => `
10
+ enum ${name} {
11
+ ${renderArguments(memberNames)}
12
+ }
13
+ `
14
+ );
15
+
16
+ return result;
17
+ }