Skip to content

Commit d9dfda4

Browse files
committed
add build for genarating types
1 parent 32146d0 commit d9dfda4

File tree

11 files changed

+3050
-1390
lines changed

11 files changed

+3050
-1390
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
diff --git a/dist/codegen/createBarrelFiles.js b/dist/codegen/createBarrelFiles.js
2+
index 4bf574d7f6701bc5a8fcb2c281b5c63f31923e79..7f9cbdbd0491d4fa6338a10b23d06c2665c9d968 100644
3+
--- a/dist/codegen/createBarrelFiles.js
4+
+++ b/dist/codegen/createBarrelFiles.js
5+
@@ -38,15 +38,13 @@ function createBarrelFiles(paths, { typeOnly, postfix = '', moduleSuffix = '' })
6+
const namespacesExports = nestedDirs
7+
.map((p) => {
8+
const namespaceIdentifier = (0, normalizeDirName_1.normalizeDirName)(p);
9+
+ const fromFilePath = moduleSuffix ? `'./${p}/index${moduleSuffix}'` : `'./${p}'`
10+
if (typeOnly)
11+
return [
12+
- `import type * as ${namespaceIdentifier} from './${p}';`,
13+
+ `import type * as ${namespaceIdentifier} from ${fromFilePath};`,
14+
`export type { ${namespaceIdentifier} };`,
15+
].join('\n');
16+
- if (moduleSuffix) {
17+
- return `export * as ${namespaceIdentifier} from './${p}/index${moduleSuffix}';`;
18+
- }
19+
- return `export * as ${namespaceIdentifier} from './${p}';`;
20+
+ return `export * as ${namespaceIdentifier} from ${fromFilePath};`;
21+
})
22+
.join('\n');
23+
const contracts = (fileReexports[path] || []).sort();

.yarnrc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ enableGlobalCache: false
55
enableScripts: false
66

77
nodeLinker: node-modules
8+
9+
nmHoistingLimits: workspaces

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@
1515
},
1616
"homepage": "https://github.com/BootNodeDev/intents-framework#readme",
1717
"description": "",
18-
"workspaces": [
19-
"typescript/solver",
20-
"solidity"
21-
],
18+
"workspaces": {
19+
"packages": [
20+
"typescript/solver",
21+
"solidity"
22+
],
23+
"nohoist": [
24+
"solidity/@hyperlane-xyz/core",
25+
"solidity/@openzeppelin/contracts",
26+
"solidity/@uniswap/permit2"
27+
]
28+
},
2229
"packageManager": "yarn@4.5.1"
2330
}

solidity/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# directories
22
cache
3+
cache_hardhat
4+
artifacts
5+
types
36
coverage
47
node_modules
58
out

solidity/exportBuildArtifact.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
3+
# set script location as working directory
4+
cd "$(dirname "$0")"
5+
6+
# Define the artifacts directory
7+
artifactsDir="./artifacts/build-info"
8+
# Define the output file
9+
outputFileJson="./dist/buildArtifact.json"
10+
outputFileJs="./dist/buildArtifact.js"
11+
outputFileTsd="./dist/buildArtifact.d.ts"
12+
13+
# log that we're in the script
14+
echo 'Finding and processing hardhat build artifact...'
15+
16+
# Find most recently modified JSON build artifact
17+
if [ "$(uname)" = "Darwin" ]; then
18+
# for local flow
19+
jsonFiles=$(find "$artifactsDir" -type f -name "*.json" -exec stat -f "%m %N" {} \; | sort -rn | head -n 1 | cut -d' ' -f2-)
20+
else
21+
# for CI flow
22+
jsonFiles=$(find "$artifactsDir" -type f -name "*.json" -exec stat -c "%Y %n" {} \; | sort -rn | head -n 1 | cut -d' ' -f2-)
23+
fi
24+
25+
if [ ! -f "$jsonFiles" ]; then
26+
echo 'Failed to find build artifact'
27+
exit 1
28+
fi
29+
30+
# Extract required keys and write to outputFile
31+
if jq -c '{input, solcLongVersion}' "$jsonFiles" > "$outputFileJson"; then
32+
echo "export const buildArtifact = " > "$outputFileJs"
33+
cat "$outputFileJson" >> "$outputFileJs"
34+
echo "export const buildArtifact: any" > "$outputFileTsd"
35+
echo 'Finished processing build artifact.'
36+
else
37+
echo 'Failed to process build artifact with jq'
38+
exit 1
39+
fi

solidity/foundry.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
solc = "0.8.25"
1515
src = "src"
1616
test = "test"
17-
allow_paths = ["../node_modules"]
17+
allow_paths = ["node_modules"]
18+
libs = ['node_modules', '../node_modules']
1819

1920
[profile.ci]
2021
fuzz = { runs = 10_000 }

solidity/hardhat.config.cts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import "@nomicfoundation/hardhat-foundry";
2+
import '@nomiclabs/hardhat-ethers';
3+
import '@typechain/hardhat';
4+
5+
/**
6+
* @type import('hardhat/config').HardhatUserConfig
7+
*/
8+
module.exports = {
9+
solidity: {
10+
version: '0.8.25',
11+
settings: {
12+
optimizer: {
13+
enabled: true,
14+
runs: 10_000,
15+
},
16+
},
17+
},
18+
typechain: {
19+
outDir: './types',
20+
target: 'ethers-v5',
21+
alwaysGenerateOverloads: true,
22+
node16Modules: true,
23+
},
24+
};

solidity/package.json

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,44 @@
1212
"dotenv-run-script": "^0.4.1"
1313
},
1414
"devDependencies": {
15+
"@nomicfoundation/hardhat-foundry": "^1.1.3",
16+
"@nomicfoundation/hardhat-toolbox": "^5.0.0",
17+
"@nomiclabs/hardhat-ethers": "^2.2.3",
18+
"@typechain/ethers-v5": "^11.1.2",
19+
"@typechain/ethers-v6": "^0.5.1",
20+
"@typechain/hardhat": "^9.1.0",
21+
"@types/node": "^22.10.7",
22+
"ethers": "^5.7.2",
1523
"forge-std": "github:foundry-rs/forge-std#v1.8.1",
24+
"hardhat": "^2.22.18",
1625
"prettier": "^3.0.0",
17-
"solhint": "^3.6.2"
26+
"solhint": "^3.6.2",
27+
"ts-generator": "^0.1.1",
28+
"ts-node": "^10.8.0",
29+
"tsx": "^4.19.1",
30+
"typechain": "patch:typechain@npm%3A8.3.2#~/.yarn/patches/typechain-npm-8.3.2-b02e27439e.patch",
31+
"typescript": "5.3.3"
1832
},
33+
"type": "module",
34+
"exports": {
35+
".": "./dist/index.js",
36+
"./mailbox": "./dist/contracts/Mailbox.js",
37+
"./buildArtifact.js": "./dist/buildArtifact.js",
38+
"./buildArtifact.json": "./dist/buildArtifact.json",
39+
"./contracts": "./contracts"
40+
},
41+
"types": "./dist/index.d.ts",
42+
"files": [
43+
"/dist",
44+
"/contracts"
45+
],
1946
"keywords": [],
2047
"private": true,
2148
"scripts": {
22-
"clean": "rm -rf cache out && forge clean",
23-
"build": "forge build",
49+
"clean": "yarn hardhat-esm clean && rm -rf ./dist ./cache ./types ./coverage ./out ./forge-cache ./fixtures && forge clean",
50+
"build": "yarn hardhat-esm compile && tsc && ./exportBuildArtifact.sh",
51+
"hardhat-esm": "NODE_OPTIONS='--experimental-loader ts-node/esm/transpile-only --no-warnings=ExperimentalWarning' hardhat --config hardhat.config.cts",
52+
"forge:build": "forge build",
2453
"lint": "yarn lint:sol && yarn prettier:check",
2554
"lint:sol": "forge fmt --check && solhint \"{script,src,test}/**/*.sol\"",
2655
"sol:fmt": "forge fmt",

solidity/remappings.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
@openzeppelin/=../node_modules/@openzeppelin/
2-
forge-std/=../node_modules/forge-std/src/
3-
@hyperlane-xyz/=../node_modules/@hyperlane-xyz/core/contracts/
4-
contracts/=../node_modules/@hyperlane-xyz/core/contracts/
5-
@uniswap/=../node_modules/@uniswap/
1+
@openzeppelin/=node_modules/@openzeppelin/
2+
forge-std/=node_modules/forge-std/src/
3+
@hyperlane-xyz/=node_modules/@hyperlane-xyz/core/contracts/
4+
contracts/=node_modules/@hyperlane-xyz/core/contracts/
5+
@uniswap/=node_modules/@uniswap/

solidity/tsconfig.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"declarationMap": true,
5+
"esModuleInterop": true,
6+
"forceConsistentCasingInFileNames": true,
7+
"incremental": false,
8+
"lib": [
9+
"ES2015", "ES2016", "ES2017", "ES2018",
10+
"ES2019", "ES2020","ES2021", "ES2022", "DOM"
11+
],
12+
"module": "nodenext",
13+
"moduleResolution": "nodenext",
14+
"noEmitOnError": true,
15+
"noFallthroughCasesInSwitch": true,
16+
"noImplicitAny": true,
17+
"noImplicitReturns": true,
18+
"noUnusedLocals": true,
19+
"preserveSymlinks": true,
20+
"preserveWatchOutput": true,
21+
"pretty": false,
22+
"resolveJsonModule": true,
23+
"skipLibCheck": true,
24+
"sourceMap": true,
25+
"strict": true,
26+
"target": "es2022",
27+
"outDir": "./dist",
28+
"rootDir": "./types"
29+
},
30+
"ts-node": {
31+
"experimentalSpecifierResolution": "node",
32+
"experimentalResolver": true,
33+
"files": true
34+
},
35+
"exclude": ["./test", "hardhat.config.cts", "./dist"]
36+
}

0 commit comments

Comments
 (0)