Skip to content

Commit

Permalink
1053 sdk sdk and contract should build for cjs and esm (#1064)
Browse files Browse the repository at this point in the history
* v0.1.0

* feat(publish): cjs and esm in contracts 0.1.0

* v0.4.0

* feat(package): SDK cjs and esm release 0.4.0

* v0.2.0

* v0.5.0

* feat(npm): rollup, publish sdk 0.5 contr 0.2

* v0.3.0

* v0.4.0

* feat(release): contracts 0.4.0 CJS and ESM

* v0.6.0

* chore(update): update hc packages in fe

* fix(graph): graph ci-cd for dev and pr

* fix(foundry): remove hardcoded version from gha

* chore(update): matchstick lib

* fix(gha): move changes to correct files

* fix(test): contract tests after foundry update

* fix(lint): bypass lint warns
  • Loading branch information
bitbeckers authored Oct 3, 2023
1 parent ae3e65e commit 39284c0
Show file tree
Hide file tree
Showing 36 changed files with 12,527 additions and 2,528 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ jobs:
cache: "yarn"
- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-87bc53fc6c874bd4c92d97ed180b949e3a36d78c
- name: Install
run: |
yarn install --immutable
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-defender.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
# A push occurs to one of the matched branches.
push:
branches:
- main
- main
paths:
- defender/**
# Allows you to run this workflow manually from the Actions tab
Expand All @@ -20,7 +20,7 @@ jobs:
deploy-defender:
# NOTE: This name appears in GitHub's Checks API.
name: deploy-defender
environment: deploy
environment: deploy
runs-on: ubuntu-latest
steps:
- name: Checkout code
Expand All @@ -37,4 +37,4 @@ jobs:
- name: Build the autotasks
run: yarn build:defender
- name: Deploy to OpenZeppelin Defender
run: yarn deploy:defender
run: yarn deploy:defender
11 changes: 8 additions & 3 deletions .github/workflows/deploy-graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ on:
# A push occurs to one of the matched branches.
push:
branches:
- main
- main
- develop
paths:
- graph/**
# Allows you to run this workflow manually from the Actions tab
Expand All @@ -34,5 +35,9 @@ jobs:
run: yarn install --immutable
- name: Build the subgraph
run: yarn build:graph
- name: Deploy the subgraph
run: yarn deploy:graph
- name: Deploy the subgraph to goerli testnet
if: github.ref == 'refs/heads/develop'
run: yarn deploy:graph:goerli
- name: Deploy the subgraph to Optimism mainnet
if: github.ref == 'refs/heads/main'
run: yarn deploy:graph:optimism
3 changes: 1 addition & 2 deletions contracts/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
*
!dist/**
!package.json
!README.md
lib/
1 change: 1 addition & 0 deletions contracts/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
**/deployments
**/.openzeppelin
**/docs
**/src/abi/

# files
*.env
Expand Down
6 changes: 4 additions & 2 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ function getChainConfig(chain: keyof typeof chainIds) {

const config: HardhatUserConfig = {
abiExporter: {
path: "./abi",
path: "./src/abi",
runOnCompile: true,
clear: true,
flat: true,
format: "minimal",
except: ["@openzeppelin"],
},
defender: {
apiKey: ozApiKey!,
Expand Down Expand Up @@ -145,7 +147,7 @@ const config: HardhatUserConfig = {
},
},
typechain: {
outDir: "./typechain",
outDir: "./src/types",
target: "ethers-v5",
},
};
Expand Down
31 changes: 23 additions & 8 deletions contracts/package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"name": "@hypercerts-org/contracts",
"description": "EVM compatible protocol for managing impact claims",
"version": "0.0.13",
"version": "0.4.0",
"author": {
"name": "Hypercerts Foundation",
"url": "https://github.com/hypercerts-org/hypercerts"
},
"homepage": "https://hypercerts.org",
"bugs": "https://github.com/hypercerts-org/hypercerts/issues/new",
"repository": {
"directory": "contracts",
"url": "https://github.com/hypercerts-org/hypercerts",
"type": "git"
},
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/index.d.ts"
},
"packageManager": "[email protected]",
"workspaces": {
"nohoist": [
Expand All @@ -36,6 +43,9 @@
"@openzeppelin/hardhat-defender": "^1.8.2",
"@openzeppelin/hardhat-upgrades": "^1.22.1",
"@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",
Expand All @@ -61,6 +71,10 @@
"prettier": "^2.7.1",
"prettier-plugin-solidity": "^1.1.3",
"rimraf": "^3.0.2",
"rollup": "^3.17.2",
"rollup-plugin-auto-external": "^2.0.0",
"rollup-plugin-dts": "^5.2.0",
"rollup-plugin-esbuild": "^5.0.0",
"shx": "^0.3.4",
"solhint": "^3.3.7",
"solidity-coverage": "^0.8.2",
Expand All @@ -79,15 +93,16 @@
"template"
],
"scripts": {
"build": "yarn clean && yarn build:hardhat",
"build": "yarn clean && hardhat compile && rollup -c",
"build:forge": "forge build",
"build:hardhat": "cross-env TS_NODE_TRANSPILE_ONLY=true hardhat compile && yarn build:ts && yarn build:declarations",
"build:ts": "npx tsc --build tsconfig.build.json",
"build:declarations": "shx cp ./typechain/*.d.ts ./dist/src/types",
"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: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:sol": "solhint \"./{src,test}/**/*.sol\"",
"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",
Expand Down
32 changes: 32 additions & 0 deletions contracts/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import commonjs from "@rollup/plugin-commonjs";
import json from "@rollup/plugin-json";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import autoExternal from "rollup-plugin-auto-external";
import dts from "rollup-plugin-dts";
import esbuild from "rollup-plugin-esbuild";
import nodePolyfills from "rollup-plugin-node-polyfills";

export default [
{
input: `src/index.ts`,
plugins: [autoExternal(), nodePolyfills(), json(), commonjs(), nodeResolve(), esbuild()],
output: [
{
format: "esm",
dir: "dist/esm",
},
{
format: "cjs",
dir: "dist/cjs",
},
],
},
{
input: `src/index.ts`,
plugins: [json(), dts()],
output: {
file: `dist/index.d.ts`,
format: "es",
},
},
];
28 changes: 15 additions & 13 deletions contracts/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import HypercertMinterAbi from "./abi/HypercertMinter.json";
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";
import type { IHypercertToken } from "./types/src/interfaces/IHypercertToken";
import type { Errors } from "./types/src/libs/Errors";

/*
in order to adjust the build folder:
1) import any files here you want in the final build package.
2) copy the file path of the import.
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.
*/
// ABIs
import ERC1155UpgradeableABI from "../abi/ERC1155Upgradeable.json" assert { type: "json" };
import HypercertMinterABI from "../abi/HypercertMinter.json" assert { type: "json" };
import IHypercertTokenABI from "../abi/IHypercertToken.json" assert { type: "json" };
import SemiFungible1155ABI from "../abi/SemiFungible1155.json" assert { type: "json" };

// ABIs
export { HypercertMinterABI, IHypercertTokenABI, SemiFungible1155ABI, ERC1155UpgradeableABI };

// Interfaces
export type { IHypercertToken } from "../typechain/src/interfaces/IHypercertToken";
export { IAllowlist, IHypercertToken };
export { HypercertMinterAbi };

// Contracts
export { HypercertMinter } from "../typechain/src/HypercertMinter";
export { AllowlistMinter } from "../typechain/src/AllowlistMinter";
export { HypercertMinter, AllowlistMinter };

// Factories
export { HypercertMinter__factory as HyperCertMinterFactory } from "../typechain/factories/src/HypercertMinter__factory";
export { HypercertMinter__factory as HypercertMinterFactory };

// Libs
export { Errors };
6 changes: 3 additions & 3 deletions contracts/test/foundry/AllowlistMinter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract MerkleHelper is AllowlistMinter, Merkle {
}
}

function generateData(uint256 size, uint256 value) public view returns (bytes32[] memory data) {
function generateData(uint256 size, uint256 value) public pure returns (bytes32[] memory data) {
data = new bytes32[](size);
for (uint256 i = 0; i < size; i++) {
address user = address(uint160(i + 1));
Expand Down Expand Up @@ -147,7 +147,7 @@ contract AllowlistTest is PRBTest, StdCheats, StdUtils {

merkle.createAllowlist(claimID, root, size * units);

changePrank(address(1));
startHoax(address(1));
bytes32[] memory proof = merkle.getProof(data, 0);
merkle.processClaim(proof, claimID, units);

Expand Down Expand Up @@ -190,7 +190,7 @@ contract AllowlistTest is PRBTest, StdCheats, StdUtils {

merkle.createAllowlist(claimID, root, size * value);

changePrank(address(3));
startHoax(address(3));

merkle.isAllowedToClaim(proof, claimID, data[2]);

Expand Down
6 changes: 3 additions & 3 deletions contracts/test/foundry/HypercertMinter.transfers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ contract HypercertMinterTransferTest is PRBTest, StdCheats, StdUtils {
vm.prank(alice);
hypercertMinter.mintClaim(alice, _units, _uri, IHypercertToken.TransferRestrictions.AllowAll);

changePrank(bob);
startHoax(bob);
vm.expectRevert("ERC1155: caller is not token owner or approved");
hypercertMinter.safeTransferFrom(alice, bob, tokenID, 1, "");

Expand All @@ -108,7 +108,7 @@ contract HypercertMinterTransferTest is PRBTest, StdCheats, StdUtils {
vm.prank(alice);
hypercertMinter.mintClaim(alice, _units, _uri, IHypercertToken.TransferRestrictions.DisallowAll);

changePrank(bob);
startHoax(bob);
vm.expectRevert("ERC1155: caller is not token owner or approved");
hypercertMinter.safeTransferFrom(alice, bob, tokenID, 1, "");

Expand All @@ -125,7 +125,7 @@ contract HypercertMinterTransferTest is PRBTest, StdCheats, StdUtils {
vm.prank(alice);
hypercertMinter.mintClaim(alice, _units, _uri, IHypercertToken.TransferRestrictions.FromCreatorOnly);

changePrank(bob);
startHoax(bob);
vm.expectRevert("ERC1155: caller is not token owner or approved");
hypercertMinter.safeTransferFrom(alice, bob, tokenID, 1, "");

Expand Down
10 changes: 1 addition & 9 deletions contracts/test/foundry/SemiFungible1155.transfers.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,25 @@ contract SemiFungible1155TransferTest is PRBTest, StdCheats, StdUtils {
_uri = "ipfs://bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi";
alice = address(1);
bob = address(2);
hoax(alice, 100 ether);
startHoax(alice, 100 ether);
}

// UNHAPPY PATHS
function testFailTransferTypeIDToken() public {
vm.startPrank(alice);
semiFungible.mintValue(alice, 10000, _uri);

//NotApprovedOrOWner, since no owner
semiFungible.safeTransferFrom(alice, bob, 1 << 128, 1, "");
}

function testFailTransferNonExistingFractionToken() public {
vm.startPrank(alice);
semiFungible.mintValue(alice, 10000, _uri);

//NotApprovedOrOWner, since no owner
semiFungible.safeTransferFrom(alice, bob, 1 << (128 + 2), 1, "");
}

function testTransferNonExistingTokenWithValue() public {
vm.startPrank(alice);

uint256 baseID = 1 << 128;
uint128 tokenID = 1;

Expand All @@ -51,8 +47,6 @@ contract SemiFungible1155TransferTest is PRBTest, StdCheats, StdUtils {
}

function testTransferNonExistingFungibleTokenTokenNoValue() public {
vm.startPrank(alice);

uint256 baseID = 1 << 128;
uint128 tokenID = 1;

Expand All @@ -66,8 +60,6 @@ contract SemiFungible1155TransferTest is PRBTest, StdCheats, StdUtils {
uint256 baseID = 1 << 128;
uint128 tokenID = 1;

startHoax(alice, 100 ether);

semiFungible.mintValue(alice, 10000, _uri);

assertEq(semiFungible.balanceOf(alice, baseID), 0);
Expand Down
24 changes: 6 additions & 18 deletions contracts/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,23 @@
{
"compilerOptions": {
"assumeChangesOnlyAffectDirectDependencies": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"alwaysStrict": true,
"assumeChangesOnlyAffectDirectDependencies": true,
"declaration": true,
"esModuleInterop": true,
"resolveJsonModule": true,
"forceConsistentCasingInFileNames": true,
"incremental": true,
"composite": true,
"lib": ["esnext"],
"module": "ESNext",
"moduleResolution": "nodenext",
"noImplicitThis": true,
"outDir": "dist",
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"strict": true,
"strictNullChecks": true,
"target": "es6"
"strictNullChecks": true
},
"files": ["src/index.ts"],
"include": [
"typechain/common.ts",
"abi/HypercertMinter.json",
"abi/IHypercertToken.json",
"abi/SemiFungible1155.json",
"abi/ERC1155Upgradeable.json",
"typechain/src/interfaces/IHypercertToken.ts",
"typechain/src/HypercertMinter.ts",
"typechain/src/AllowlistMinter.ts",
"typechain/factories/src/HypercertMinter__factory.ts"
],
"include": ["src/**/*.ts", "src/abi/*.json"],
"exclude": ["node_modules"]
}
8 changes: 8 additions & 0 deletions contracts/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"outDir": "dist/cjs",
"module": "commonjs",
"target": "es2015"
}
}
Loading

0 comments on commit 39284c0

Please sign in to comment.