Skip to content

Commit

Permalink
Fix build pipeline, workspace, release flow, etc.. (#1118)
Browse files Browse the repository at this point in the history
* fix(build): add html-webpack-plugin

* fix(defender): workspace package name

* chore(pnpm): migrate to pnpm

* chore(bump): sdk version bump

* chore(pnpm): fix build errors

* chore(build): remove faulty export

* fix(build): default export to contracts

* chore(npm): reinstate factory export

* chore(release): contracts 0.8.3

* chore(release): contracts 0.8.5

* chore(release): contract 0.8.6

* chore(release): sdk 0.8.6 - fixed packages

* chore(bump): version bump

* fix(build): transpile SDK in NextJS app

* fix(build): update github workflow to use pnpm

* fix(build): install pnpm in github actions

---------

Co-authored-by: bitbeckers <[email protected]>
  • Loading branch information
Jipperism and bitbeckers authored Oct 12, 2023
1 parent 22c2c0e commit a311a1a
Show file tree
Hide file tree
Showing 42 changed files with 29,372 additions and 42,415 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,34 @@ jobs:
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8.9.0
- name: Set up Node.js 18
uses: actions/setup-node@v3
with:
node-version: "18.15.0"
cache: "yarn"
cache: "pnpm"
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
- name: Install
run: |
yarn install --immutable
pnpm install --frozen-lockfile
# Always run this step so that all linting errors can be seen at once.
if: always()
- name: Build
run: |
yarn build
pnpm run build
# Always run this step so that all linting errors can be seen at once.
if: always()
- name: Lint
run: |
yarn lint
pnpm run lint
# Always run this step so that all linting errors can be seen at once.
if: always()
- name: Test
run: |
yarn test
pnpm test
# Always run this step so that all linting errors can be seen at once.
if: always()
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hoist-pattern=!@hypercerts-org/contracts
link-workspace-packages=false
8 changes: 5 additions & 3 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-toolbox";
import "@nomiclabs/hardhat-ethers";
import "@openzeppelin/hardhat-defender";
import "@openzeppelin/hardhat-upgrades";
import "@openzeppelin/hardhat-defender";

import "@primitivefi/hardhat-dodoc";
import { config as dotenvConfig } from "dotenv";
import fs from "fs";
Expand Down Expand Up @@ -70,7 +71,7 @@ function getChainConfig(chain: keyof typeof chainIds) {
};
}

const config: HardhatUserConfig = {
const config = {
abiExporter: {
path: "./src/abi",
runOnCompile: true,
Expand All @@ -82,6 +83,7 @@ const config: HardhatUserConfig = {
defender: {
apiKey: ozApiKey!,
apiSecret: ozSecretKey!,
useDefenderDeploy: true,
},
dodoc: {
runOnCompile: true,
Expand Down Expand Up @@ -124,7 +126,7 @@ const config: HardhatUserConfig = {
tests: "./test",
},
preprocess: {
eachLine: (hre) => ({
eachLine: () => ({
transform: (line: string) => {
if (line.match(/^\s*import /i)) {
getRemappings().forEach(([find, replace]) => {
Expand Down
43 changes: 19 additions & 24 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hypercerts-org/contracts",
"description": "EVM compatible protocol for managing impact claims",
"version": "0.7.1",
"version": "0.8.6",
"author": {
"name": "Hypercerts Foundation",
"url": "https://github.com/hypercerts-org/hypercerts"
Expand All @@ -21,13 +21,6 @@
"import": "./dist/esm/index.js",
"types": "./dist/index.d.ts"
},
"packageManager": "[email protected]",
"workspaces": {
"nohoist": [
"prettier-plugin-solidity",
"solhint"
]
},
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
Expand All @@ -41,14 +34,14 @@
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.3",
"@openzeppelin/hardhat-defender": "^1.8.2",
"@openzeppelin/hardhat-upgrades": "^1.22.1",
"@openzeppelin/hardhat-upgrades": "^1.28",
"@primitivefi/hardhat-dodoc": "^0.2.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@trivago/prettier-plugin-sort-imports": "^3.3.0",
"@typechain/ethers-v5": "^10.2.0",
"@typechain/hardhat": "^6.1.5",
"@typechain/ethers-v5": "^11.1.1",
"@typechain/hardhat": "^9.0.0",
"@types/chai": "^4.3.4",
"@types/mocha": "9.1.0",
"@types/node": "^18.11.11",
Expand All @@ -62,25 +55,26 @@
"eslint": "^8.23.1",
"eslint-config-prettier": "^8.5.0",
"ethers": "^5.7.2",
"hardhat": "^2.13.0",
"hardhat": "2.13.1",
"hardhat-abi-exporter": "^2.10.1",
"hardhat-gas-reporter": "^1.0.9",
"hardhat-preprocessor": "^0.1.5",
"husky": "^8.0.1",
"lint-staged": "^13.0.3",
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.1.3",
"rimraf": "^3.0.2",
"rollup": "^3.17.2",
"rimraf": "^5.0.5",
"rollup": "^4.0.2",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-dts": "^5.2.0",
"rollup-plugin-esbuild": "^5.0.0",
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-esbuild": "^6.1.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"shx": "^0.3.4",
"solhint": "^3.3.7",
"solidity-coverage": "^0.8.2",
"ts-node": "^10.9.1",
"typechain": "^8.1.1",
"typescript": "^4.9.3"
"typechain": "^8.3.1",
"typescript": "^4.9.4"
},
"keywords": [
"blockchain",
Expand All @@ -93,23 +87,24 @@
"template"
],
"scripts": {
"build": "yarn clean && hardhat compile && rollup -c",
"build": "pnpm clean && hardhat compile && pnpm tsc -p tsconfig.build.json && rollup -c",
"build:forge": "forge build",
"build:hardhat": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile && yarn build:ts:esm && yarn build:ts:cjs && yarn build:declarations",
"build:ts:esm": "npx tsc --build tsconfig.esm.json",
"build:ts:cjs": "npx tsc --build tsconfig.cjs.json",
"build:hardhat": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile && pnpm build:declarations",
"build:declarations": "shx cp ./src/types/*.d.ts ./dist/index.d.ts",
"clean": "rimraf cache out dist typechain abi",
"docs": "hardhat dodoc",
"lint": "yarn lint:sol && yarn prettier:check",
"lint": "pnpm lint:sol && pnpm prettier:check",
"lint:sol": "solhint -w 5 \"./{src,test}/**/*.sol\"",
"prettier": "prettier --config \"./.prettierrc.yml\" --write \"**/*.{json,md,sol,yml}\"",
"prettier:check": "prettier --config \"./.prettierrc.yml\" --check \"**/*.{json,md,sol,yml}\"",
"slither": "slither ./src",
"test": "yarn test:hardhat && yarn test:forge",
"test": "pnpm test:hardhat && pnpm test:forge",
"test:forge": "forge test",
"test:hardhat": "hardhat test",
"test:gas": "forge test --match-path test/foundry/PerformanceTesting.t.sol --gas-report",
"hardhat": "hardhat"
},
"dependencies": {
"@hypercerts-org/contracts": "link:"
}
}
18 changes: 14 additions & 4 deletions contracts/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,35 @@ import nodePolyfills from "rollup-plugin-node-polyfills";

export default [
{
input: `src/index.ts`,
plugins: [autoExternal(), nodePolyfills(), json(), commonjs(), nodeResolve(), esbuild()],
input: `build/index.js`,
plugins: [
autoExternal(),
nodePolyfills(),
json(),
commonjs(),
nodeResolve(),
esbuild({ tsconfig: "tsconfig.build.json" }),
],
output: [
{
format: "esm",
dir: "dist/esm",
sourcemap: true,
exports: "named",
},
{
format: "cjs",
dir: "dist/cjs",
sourcemap: true,
exports: "named",
},
],
},
{
input: `src/index.ts`,
input: `build/index.d.ts`,
plugins: [json(), dts()],
output: {
file: `dist/index.d.ts`,
format: "es",
},
},
];
9 changes: 5 additions & 4 deletions contracts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import HypercertMinterAbi from "./abi/HypercertMinter.json";
import { HypercertMinter__factory } from "./types/factories/src/HypercertMinter__factory";
// import { HypercertMinter__factory } from "./types/factories/src/HypercertMinter__factory";
import type { AllowlistMinter } from "./types/src/AllowlistMinter";
import type { HypercertMinter } from "./types/src/HypercertMinter";
import type { IAllowlist } from "./types/src/interfaces/IAllowlist";
Expand All @@ -13,15 +13,16 @@ import type { Errors } from "./types/src/libs/Errors";
3) add the path to the ts.config.build.json under the { include: [...] } configuration.
4) bump package.json version to publish a new package to npm.
*/

// Factory
// export { HypercertMinter__factory };

// Interfaces
export { IAllowlist, IHypercertToken };
export { HypercertMinterAbi };

// Contracts
export { HypercertMinter, AllowlistMinter };

// Factories
export { HypercertMinter__factory as HypercertMinterFactory };

// Libs
export { Errors };
14 changes: 8 additions & 6 deletions contracts/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { writeFile } from "node:fs/promises";

task("deploy", "Deploy contracts and verify")
.addOptionalParam("output", "write the details of the deployment to this file if this is set")
.setAction(async ({ output }, { ethers, upgrades }) => {
.setAction(async ({ output }, { ethers, upgrades, network, run }) => {
const HypercertMinter = await ethers.getContractFactory("HypercertMinter");
const hypercertMinter = await upgrades.deployProxy(HypercertMinter, {
kind: "uups",
Expand All @@ -27,21 +27,23 @@ task("deploy", "Deploy contracts and verify")
);
}

if (hre.network.name !== "hardhat" && hre.network.name !== "localhost") {
if (network.name !== "hardhat" && network.name !== "localhost") {
try {
const code = await hypercertMinter.instance?.provider.getCode(hypercertMinter.address);
if (code === "0x") {
console.log(`${hypercertMinter.name} contract deployment has not completed. waiting to verify...`);
await hypercertMinter.instance?.deployed();
}
await hre.run("verify:verify", {
await run("verify:verify", {
address: hypercertMinter.address,
});
} catch ({ message }) {
if ((message as string).includes("Reason: Already Verified")) {
} catch (error) {
const errorMessage = (error as Error).message;

if (errorMessage.includes("Reason: Already Verified")) {
console.log("Reason: Already Verified");
}
console.error(message);
console.error(errorMessage);
}
}
});
17 changes: 9 additions & 8 deletions contracts/tasks/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { task } from "hardhat/config";
*/
task("upgrade", "Upgrade implementation contract and verify")
.addParam("proxy", "Provider proxy address")
.setAction(async ({ proxy }, { ethers, upgrades }) => {
.setAction(async ({ proxy }, { ethers, upgrades, run }) => {
const HypercertMinter = await ethers.getContractFactory("HypercertMinter");

// Validate (redundant?)
Expand All @@ -26,14 +26,16 @@ task("upgrade", "Upgrade implementation contract and verify")
console.log(`${hypercertMinterUpgrade.name} contract upgrade has not completed. waiting to verify...`);
await hypercertMinterUpgrade.instance?.deployed();
}
await hre.run("verify:verify", {
await run("verify:verify", {
address: hypercertMinterUpgrade.address,
});
} catch ({ message }) {
if ((message as string).includes("Reason: Already Verified")) {
} catch (error) {
const errorMessage = (error as Error).message;

if (errorMessage.includes("Reason: Already Verified")) {
console.log("Reason: Already Verified");
}
console.error(message);
console.error(errorMessage);
}
});

Expand All @@ -43,12 +45,11 @@ task("upgrade", "Upgrade implementation contract and verify")
task("propose-upgrade", "Propose an upgrade to OpenZeppelin Defender")
.addParam("proxy", "Proxy contract address")
.addParam("multisig", "Owner multisig address")
.setAction(async ({ proxy, multisig }, { ethers, upgrades }) => {
.setAction(async ({ proxy, multisig }, { ethers, defender }) => {
const HypercertMinter = await ethers.getContractFactory("HypercertMinter");
console.log("Proposing upgrade..");
const proposal = await defender.proposeUpgrade(proxy, HypercertMinter, {
multisig
multisig,
});
console.log("Upgrade proposal created at: ", proposal.url);
});

2 changes: 1 addition & 1 deletion contracts/test/HypercertMinter.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from "chai";
import { ethers, upgrades } from "hardhat";

import { HypercertMinter } from "../typechain";
import { HypercertMinter } from "../src/types";

describe("Hypercert Minter", function () {
it("is upgradeable", async () => {
Expand Down
35 changes: 22 additions & 13 deletions contracts/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"allowSyntheticDefaultImports": true,
"assumeChangesOnlyAffectDirectDependencies": true,
"declaration": true,
"declarationMap": true,
"emitDecoratorMetadata": true,
"esModuleInterop": true,
"experimentalDecorators": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"composite": true,
"lib": ["esnext"],
"moduleResolution": "nodenext",
"noImplicitThis": true,
"lib": ["es6"],
"module": "ESNext",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitOverride": false,
"removeComments": true,
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
"strictNullChecks": true
"target": "ESNext",
"outDir": "build"
},
"files": ["src/index.ts"],
"include": ["src/**/*.ts", "src/abi/*.json"],
"exclude": ["node_modules"]
"include": ["./src"],
"files": [
"src/abi/HypercertMinter.json",
"src/types/src/AllowlistMinter.ts",
"src/types/src/HypercertMinter.ts",
"src/types/src/interfaces/IAllowlist.ts",
"src/types/src/interfaces/IHypercertToken.ts",
"src/types/src/libs/Errors.ts"
]
}
Loading

0 comments on commit a311a1a

Please sign in to comment.