Skip to content

Commit

Permalink
Merge pull request #1266 from hypercerts-org/bugfix/defender-deployments
Browse files Browse the repository at this point in the history
(fix): update defender deploy scripts to use contracts package
  • Loading branch information
Jipperism authored Jan 16, 2024
2 parents 775c59a + 4ecf4a7 commit 1b0356b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy-defender.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/setup-node@v3
with:
cache: "pnpm"
node-version: "18.x"
node-version: "18.18.0"
- name: Install
run: pnpm install --frozen-lockfile
- name: Deploy Defender infra to testnets
Expand Down
2 changes: 1 addition & 1 deletion defender/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@graphql-mesh/cache-localforage": "^0.95.7",
"@hypercerts-org/contracts": "1.0.0",
"@hypercerts-org/contracts": "1.1.0",
"@openzeppelin/defender-autotask-client": "1.50.0",
"@openzeppelin/defender-autotask-utils": "1.50.0",
"@openzeppelin/defender-base-client": "1.49.0",
Expand Down
16 changes: 11 additions & 5 deletions defender/src/networks.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Network } from "@openzeppelin/defender-base-client";
import { deployments } from "@hypercerts-org/contracts";

export interface NetworkConfig {
// Used to identify the network for both Alchemy and OpenZeppelin Sentinel
networkKey: Network;
// Contract address on the network
contractAddress: string;
// Minter contract address on the network
hypercertMinterContractAddress: string;
// Exchange contract address on the network
hypercertExchangeContractAddress?: string;
// the selector to retrieve the key from event.secrets in OpenZeppelin
alchemyKeyEnvName?: string;
// Chain ID for the network
Expand All @@ -23,21 +26,24 @@ export const NETWORKS: SupportedNetworks = {
TEST: [
{
networkKey: "sepolia",
contractAddress: "0xa16DFb32Eb140a6f3F2AC68f41dAd8c7e83C4941",
hypercertMinterContractAddress:
deployments["11155111"].HypercertMinterUUPS,
hypercertExchangeContractAddress:
deployments["11155111"].HypercertExchange,
chainId: 11155111,
rpc: "https://rpc.sepolia.org",
},
],
PROD: [
{
networkKey: "optimism",
contractAddress: "0x822F17A9A5EeCFd66dBAFf7946a8071C265D1d07",
hypercertMinterContractAddress: deployments["10"].HypercertMinterUUPS,
alchemyKeyEnvName: "ALCHEMY_OPTIMISM_KEY",
chainId: 10,
},
{
networkKey: "celo",
contractAddress: "0x16ba53b74c234c870c61efc04cd418b8f2865959",
hypercertMinterContractAddress: deployments["42220"].HypercertMinterUUPS,
chainId: 42220,
rpc: "https://forno.celo.org",
},
Expand Down
70 changes: 30 additions & 40 deletions defender/src/rollout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@ import { ApiError } from "./errors";
import { NetworkConfig, encodeName } from "./networks";
import {
HypercertExchangeAbi,
deployments,
asDeployedChain,
HypercertMinterAbi,
} from "@hypercerts-org/contracts";

export const rollOut = async (networks: NetworkConfig[]) => {
return await Promise.all(
networks.map(async (network) => {
console.log(
"Contract address",
network.chainId.toString(),
asDeployedChain(network.chainId.toString()),
deployments[asDeployedChain(network.chainId.toString())],
deployments[asDeployedChain(network.chainId.toString())]
.HypercertExchange,
);
// On allowlist created
const autoTaskOnAllowlistCreated = await createTask(
encodeName(network, "minter", "on-allowlist-created"),
Expand All @@ -37,7 +27,7 @@ export const rollOut = async (networks: NetworkConfig[]) => {
await createSentinel({
name: encodeName(network, "minter", "AllowlistCreated"),
network: network,
contractAddress: network.contractAddress,
contractAddress: network.hypercertMinterContractAddress,
abi: HypercertMinterAbi,
eventConditions: [
{ eventSignature: "AllowlistCreated(uint256,bytes32)" },
Expand All @@ -62,7 +52,7 @@ export const rollOut = async (networks: NetworkConfig[]) => {
await createSentinel({
name: encodeName(network, "minter", "batchMintClaimsFromAllowlists"),
network: network,
contractAddress: network.contractAddress,
contractAddress: network.hypercertMinterContractAddress,
abi: HypercertMinterAbi,
autotaskID: autoTaskOnBatchMintClaimsFromAllowlists.autotaskId,
functionConditions: [
Expand Down Expand Up @@ -90,7 +80,7 @@ export const rollOut = async (networks: NetworkConfig[]) => {
await createSentinel({
name: encodeName(network, "minter", "mintClaimFromAllowlist"),
network: network,
contractAddress: network.contractAddress,
contractAddress: network.hypercertMinterContractAddress,
abi: HypercertMinterAbi,
autotaskID: autoTaskOnMintClaimFromAllowlist.autotaskId,
functionConditions: [
Expand All @@ -101,35 +91,35 @@ export const rollOut = async (networks: NetworkConfig[]) => {
],
});

// On execute taker bid
const autoTaskExecuteTakerBid = await createTask(
encodeName(network, "exchange", "execute-taker-bid"),
"execute-taker-bid",
);
if (!autoTaskExecuteTakerBid) {
throw new ApiError(
encodeName(
network,
"exchange",
"Could not create autoTask for execute-taker-bid",
),
if (network.hypercertExchangeContractAddress) {
// On execute taker bid
const autoTaskExecuteTakerBid = await createTask(
encodeName(network, "exchange", "execute-taker-bid"),
"execute-taker-bid",
);
if (!autoTaskExecuteTakerBid) {
throw new ApiError(
encodeName(
network,
"exchange",
"Could not create autoTask for execute-taker-bid",
),
);
}
await createSentinel({
name: encodeName(network, "exchange", "executeTakerBid"),
network: network,
autotaskID: autoTaskExecuteTakerBid.autotaskId,
contractAddress: network.hypercertExchangeContractAddress,
abi: HypercertExchangeAbi,
functionConditions: [
{
functionSignature:
"executeTakerBid((address,bytes),(uint8,uint256,uint256,uint256,uint256,uint8,address,address,address,uint256,uint256,uint256,uint256[],uint256[],bytes),bytes,(bytes32,(bytes32,uint8)[]))",
},
],
});
}
await createSentinel({
name: encodeName(network, "exchange", "executeTakerBid"),
network: network,
autotaskID: autoTaskExecuteTakerBid.autotaskId,
contractAddress:
deployments[asDeployedChain(network.chainId.toString())]
.HypercertExchange,
abi: HypercertExchangeAbi,
functionConditions: [
{
functionSignature:
"executeTakerBid((address,bytes),(uint8,uint256,uint256,uint256,uint256,uint8,address,address,address,uint256,uint256,uint256,uint256[],uint256[],bytes),bytes,(bytes32,(bytes32,uint8)[]))",
},
],
});
}),
);
};
12 changes: 3 additions & 9 deletions defender/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import config from "./config";
import { NetworkConfig, decodeName } from "./networks";
import { AutotaskClient } from "@openzeppelin/defender-autotask-client";
import { SentinelClient } from "@openzeppelin/defender-sentinel-client";
import {
asDeployedChain,
deployments,
HypercertExchangeAbi,
} from "@hypercerts-org/contracts";
import { HypercertExchangeAbi } from "@hypercerts-org/contracts";

export const updateAutotask = async (networks: NetworkConfig[]) => {
const autotaskClient = new AutotaskClient(config.credentials);
Expand Down Expand Up @@ -68,14 +64,12 @@ export const updateSentinel = async (networks: NetworkConfig[]) => {
);

if (contract === "minter") {
address = network?.contractAddress;
address = network?.hypercertMinterContractAddress;
abi = HypercertMinterAbi;
}

if (contract === "exchange") {
const deployment =
deployments[asDeployedChain(network.chainId.toString())];
address = deployment.HypercertExchange;
address = network?.hypercertExchangeContractAddress;
abi = HypercertExchangeAbi;
}

Expand Down
9 changes: 5 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1b0356b

Please sign in to comment.