Skip to content

Commit

Permalink
Add HC contracts to OpenZeppelin Defender (#1134)
Browse files Browse the repository at this point in the history
* Fix/package build (#1124)

* chore(npm): sdk to workspace to stop link:
* chore(npm): contracts in workspace, no link:
* chore(bump): 0.8.7
* chore(bump): contracts 0.8.7 into sdk 0.8.8
* fix(ci): linting errors from updated ws
* fix(doc): optimism chainId to 10 from 100
* chore(build): remove type module from package.json
* chore(contracts): package sol files
* chore(pack): add sol files to contracts package
* chore(bump): contract 0.8.9
* chore(pack): exports setup
* chore(pack): contracts dir in package
* chore(pack): cleanup build scripts
* chore(bump): contracts 0.8.10
* chore(pack): add all contracts for inheritence
* chore(bump): contracts 0.8.11
* chore(bump): sdk 0.8.10 with updated contracts package
* chore(bump): updated packages in frontend
* chore(gha): run action on pr and push to develop

* feat(defender): use hc packages in oz defender
  • Loading branch information
bitbeckers authored Oct 23, 2023
1 parent 117b3fc commit 6ef61f4
Show file tree
Hide file tree
Showing 28 changed files with 1,028 additions and 414 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ on:
push:
branches:
- main
- develop
# Or when a pull request event occurs for a pull request against one of the
# matched branches.
pull_request:
branches:
- main
- develop
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand Down
1 change: 1 addition & 0 deletions contracts/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
**/build
**/cache
**/coverage
**/contracts
**/.coverage_artifacts
**/.coverage_cache
**/.coverage_contracts
Expand Down
24 changes: 17 additions & 7 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.8.7",
"version": "0.8.11",
"author": {
"name": "Hypercerts Foundation",
"url": "https://github.com/hypercerts-org/hypercerts"
Expand All @@ -17,10 +17,18 @@
"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"
".": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist",
"README.md",
"package.json",
"contracts"
],
"devDependencies": {
"@commitlint/cli": "^17.1.2",
"@commitlint/config-conventional": "^17.1.0",
Expand Down Expand Up @@ -49,6 +57,7 @@
"@typescript-eslint/parser": "^5.38.0",
"chai": "^4.3.7",
"commitizen": "^4.2.5",
"copyfiles": "^2.4.1",
"cross-env": "^7.0.3",
"cz-conventional-changelog": "^3.3.0",
"dotenv": "^16.0.2",
Expand Down Expand Up @@ -88,14 +97,15 @@
"template"
],
"scripts": {
"build": "pnpm clean && hardhat compile && pnpm tsc -p tsconfig.build.json && rollup -c",
"build": "hardhat compile && pnpm tsc -p tsconfig.build.json && rollup -c && pnpm copy:contracts",
"build:forge": "forge build",
"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",
"copy:contracts": "copyfiles -u 1 ./src/**/*.sol ./src/*.sol ./contracts",
"docs": "hardhat dodoc",
"lint": "pnpm lint:sol && pnpm prettier:check",
"lint:sol": "solhint -w 5 \"./{src,test}/**/*.sol\"",
"prebuild": "pnpm clean",
"prepublish": "pnpm build",
"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
1 change: 0 additions & 1 deletion contracts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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.
Expand Down
15 changes: 9 additions & 6 deletions defender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"author": "Hypercerts Foundation",
"license": "Apache-2.0",
"main": "index.js",
"type": "module",
"scripts": {
"build": "webpack",
"build": "rimraf build && webpack",
"deploy:test": "pnpm build && pnpm setup:test",
"deploy:prod": "pnpm build && pnpm setup:prod",
"setup:test": "NODE_OPTIONS='--no-warnings --loader ts-node/esm' npx ts-node src/setup.ts TEST",
"setup:prod": "NODE_OPTIONS='--no-warnings --loader ts-node/esm' npx ts-node src/setup.ts PROD"
"setup:test": "npx tsx src/setup.ts TEST",
"setup:prod": "npx tsx src/setup.ts src/setup.ts PROD"
},
"dependencies": {
"@hypercerts-org/contracts": "0.8.11",
"@openzeppelin/defender-autotask-client": "^1.48.0",
"@openzeppelin/defender-autotask-utils": "^1.48.0",
"@openzeppelin/defender-base-client": "^1.48.0",
Expand All @@ -23,12 +23,15 @@
"axios": "^1.2.6",
"dotenv": "^16.0.3",
"ethers": "5.7.2",
"node-fetch": "^3.3.0",
"ts-node": "^10.9.1"
"node-fetch": "^3.3.0"
},
"devDependencies": {
"@types/node": "^18.11.18",
"rimraf": "^5.0.5",
"terser-webpack-plugin": "^5.3.9",
"ts-loader": "^9.4.2",
"ts-node": "^10.9.1",
"tsx": "^3.14.0",
"typescript": "^4.9.4",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
Expand Down
10 changes: 5 additions & 5 deletions defender/src/auto-tasks/batch-mint-claims-from-allowlists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {
AutotaskEvent,
BlockTriggerEvent,
} from "@openzeppelin/defender-autotask-utils";
import { abi } from "../HypercertMinterABI";
import { HypercertMinterAbi } from "@hypercerts-org/contracts";
import { MissingDataError, NotImplementedError } from "../errors";
import {
getNetworkConfigFromName,
SUPABASE_ALLOWLIST_TABLE_NAME,
} from "../networks";
import { createClient } from "@supabase/supabase-js";
import { ethers } from "ethers";
import { BigNumber, ethers } from "ethers";
import fetch from "node-fetch";

export async function handler(event: AutotaskEvent) {
Expand Down Expand Up @@ -69,7 +69,7 @@ export async function handler(event: AutotaskEvent) {
console.log("Contract address", contractAddress);
console.log("From address", fromAddress);

const contractInterface = new ethers.utils.Interface(abi);
const contractInterface = new ethers.utils.Interface(HypercertMinterAbi);

// Parse events
// Parse events
Expand Down Expand Up @@ -97,8 +97,8 @@ export async function handler(event: AutotaskEvent) {
}

// Get claimIDs
const claimIds = batchTransferEvents[0].args["claimIDs"] as string[];
console.log("ClaimIDs: ", batchTransferEvents[0].args["claimIDs"].toString());
const claimIds = batchTransferEvents[0].args[0] as BigNumber[];
console.log("ClaimIDs: ", claimIds.toString());

const formattedClaimIds = claimIds.map(
(claimId) => `${contractAddress}-${claimId.toString().toLowerCase()}`,
Expand Down
4 changes: 2 additions & 2 deletions defender/src/auto-tasks/mint-claim-from-allowlist.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { abi } from "../HypercertMinterABI";
import { HypercertMinterAbi } from "@hypercerts-org/contracts";
import { MissingDataError, NotImplementedError } from "../errors";
import {
getNetworkConfigFromName,
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function handler(event: AutotaskEvent) {
console.log("Contract address", contractAddress);
console.log("From address", fromAddress);

const contractInterface = new ethers.utils.Interface(abi);
const contractInterface = new ethers.utils.Interface(HypercertMinterAbi);

// Parse events
const batchTransferEvents = txnLogs
Expand Down
15 changes: 9 additions & 6 deletions defender/src/auto-tasks/on-allowlist-created.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { abi } from "../HypercertMinterABI";
import { MissingDataError, NotImplementedError } from "../errors";
import {
AutotaskEvent,
Expand All @@ -10,9 +9,10 @@ import {
} from "../networks";
import { StandardMerkleTree } from "@openzeppelin/merkle-tree";
import { createClient } from "@supabase/supabase-js";
import axios from "axios";
import { ethers } from "ethers";
import fetch from "node-fetch";
import axios from "axios";
import { HypercertMinterAbi } from "@hypercerts-org/contracts";

const getIpfsGatewayUri = (cidOrIpfsUri: string) => {
const NFT_STORAGE_IPFS_GATEWAY = "https://nftstorage.link/ipfs/{cid}";
Expand Down Expand Up @@ -72,14 +72,17 @@ export async function handler(event: AutotaskEvent) {
throw new Error("No provider available");
}

const contractInterface = new ethers.utils.Interface(abi);
const contract = new ethers.Contract(contractAddress, abi, provider);
const contract = new ethers.Contract(
contractAddress,
HypercertMinterAbi,
provider,
);

//Ignore unknown events
const allowlistCreatedEvents = txnLogs
.map((l) => {
try {
return contractInterface.parseLog(l);
return contract.interface.parseLog(l);
} catch (e) {
console.log("Failed to parse log", l);
return null;
Expand All @@ -98,7 +101,7 @@ export async function handler(event: AutotaskEvent) {
);
}

const tokenId = allowlistCreatedEvents[0].args["tokenID"].toString();
const tokenId = allowlistCreatedEvents[0].args[0].toString();
console.log("TokenId: ", tokenId);

const metadataUri = await contract.functions.uri(tokenId);
Expand Down
2 changes: 1 addition & 1 deletion defender/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { NETWORKS, SupportedNetworks } from "./networks.js";
import { NETWORKS, SupportedNetworks } from "./networks";
import * as dotenv from "dotenv";

dotenv.config();
Expand Down
2 changes: 1 addition & 1 deletion defender/src/create-autotask.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from "./config.js";
import config from "./config";
import { AutotaskClient } from "@openzeppelin/defender-autotask-client";
import { SentinelTrigger } from "@openzeppelin/defender-autotask-client/lib/models/autotask.js";

Expand Down
2 changes: 1 addition & 1 deletion defender/src/create-sentinel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { abi } from "./HypercertMinterABI.js";
import config from "./config.js";
import { NetworkConfig } from "./networks.js";
import { NetworkConfig } from "./networks";
import { SentinelClient } from "@openzeppelin/defender-sentinel-client";
import {
EventCondition,
Expand Down
2 changes: 1 addition & 1 deletion defender/src/reset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import config from "./config.js";
import config from "./config";
import { AutotaskClient } from "@openzeppelin/defender-autotask-client";
import { SentinelClient } from "@openzeppelin/defender-sentinel-client";

Expand Down
8 changes: 4 additions & 4 deletions defender/src/rollout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createTask } from "./create-autotask.js";
import { createSentinel } from "./create-sentinel.js";
import { ApiError } from "./errors.js";
import { NetworkConfig, encodeName } from "./networks.js";
import { createTask } from "./create-autotask";
import { createSentinel } from "./create-sentinel";
import { ApiError } from "./errors";
import { NetworkConfig, encodeName } from "./networks";

export const rollOut = async (networks: NetworkConfig[]) => {
return await Promise.all(
Expand Down
12 changes: 6 additions & 6 deletions defender/src/setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import config from "./config.js";
import { ApiError, ConfigError } from "./errors.js";
import { NETWORKS } from "./networks.js";
import { reset } from "./reset.js";
import { rollOut } from "./rollout.js";
import { updateAutotask, updateSentinel } from "./update.js";
import config from "./config";
import { ApiError, ConfigError } from "./errors";
import { NETWORKS } from "./networks";
import { reset } from "./reset";
import { rollOut } from "./rollout";
import { updateAutotask, updateSentinel } from "./update";
import { AutotaskClient } from "@openzeppelin/defender-autotask-client";
import { SentinelClient } from "@openzeppelin/defender-sentinel-client";

Expand Down
6 changes: 3 additions & 3 deletions defender/src/update.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { abi } from "./HypercertMinterABI.js";
import config from "./config.js";
import { NetworkConfig, decodeName } from "./networks.js";
import { abi } from "./HypercertMinterABI";
import config from "./config";
import { NetworkConfig, decodeName } from "./networks";
import { AutotaskClient } from "@openzeppelin/defender-autotask-client";
import { SentinelClient } from "@openzeppelin/defender-sentinel-client";

Expand Down
1 change: 1 addition & 0 deletions defender/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"noImplicitAny": true,
"removeComments": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": false,
"strict": false,
"target": "es6"
Expand Down
17 changes: 12 additions & 5 deletions defender/webpack.config.cjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
const path = require("path");
const webpack = require("webpack");
const TerserPlugin = require("terser-webpack-plugin");

module.exports = {
entry: {
'batch-mint-claims-from-allowlists': "./src/auto-tasks/batch-mint-claims-from-allowlists.ts",
'on-allowlist-created': "./src/auto-tasks/on-allowlist-created.ts",
'mint-claim-from-allowlist': "./src/auto-tasks/mint-claim-from-allowlist.ts"
"batch-mint-claims-from-allowlists":
"./src/auto-tasks/batch-mint-claims-from-allowlists.ts",
"on-allowlist-created": "./src/auto-tasks/on-allowlist-created.ts",
"mint-claim-from-allowlist":
"./src/auto-tasks/mint-claim-from-allowlist.ts",
},
target: "node",
mode: "development",
devtool: 'cheap-module-source-map',
devtool: "cheap-module-source-map",
module: {
rules: [{ test: /\.tsx?$/, use: "ts-loader", exclude: /node_modules/ }],
},
Expand All @@ -32,10 +35,14 @@ module.exports = {
// List here all dependencies that are not run in the Autotask environment
new webpack.IgnorePlugin({ resourceRegExp: /dotenv/ }),
],
optimization: {
minimize: true,
minimizer: [new TerserPlugin()],
},
output: {
filename: "[name]/index.js",
path: path.resolve(__dirname, "build", "relay"),
sourceMapFilename: '[file].map',
sourceMapFilename: "[file].map",
library: { type: "commonjs2" },
},
};
1 change: 0 additions & 1 deletion frontend/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const nextConfig = {
config.resolve.fallback = { fs: false, net: false, tls: false };
return config;
},
transpilePackages: ["@hypercerts-org/sdk"],
};

export default withSentryConfig(
Expand Down
4 changes: 2 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
"@graphprotocol/client-cli": "^2.2.16",
"@hypercerts-org/contracts": "0.7.1",
"@hypercerts-org/contracts": "0.8.11",
"@hypercerts-org/observabletreemap": "workspace: *",
"@hypercerts-org/sdk": "0.8.4",
"@hypercerts-org/sdk": "0.8.10",
"@mui/icons-material": "^5.11.9",
"@mui/material": "^5.11.2",
"@mui/x-date-pickers": "^5.0.12",
Expand Down
Loading

0 comments on commit 6ef61f4

Please sign in to comment.