Skip to content

Commit

Permalink
Migrate current deploy scripts to zodiac-core
Browse files Browse the repository at this point in the history
  • Loading branch information
cristovaoth committed Jul 30, 2024
1 parent 095ec26 commit df901ff
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 33 deletions.
22 changes: 22 additions & 0 deletions packages/contracts/src/deploy/createEIP1193.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Signer } from "ethers";
import { EIP1193Provider } from "zodiac-core";
import { EthereumProvider } from "hardhat/types";

export default function createAdapter({
provider,
signer,
}: {
provider: EthereumProvider;
signer: Signer;
}): EIP1193Provider {
return {
request: async ({ method, params }) => {
if (method == "eth_sendTransaction") {
const { hash } = await signer.sendTransaction((params as any[])[0]);
return hash;
}

return provider.request({ method, params });
},
};
}
29 changes: 17 additions & 12 deletions packages/contracts/src/deploy/deploy_circulating_supply.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
import { deployMastercopy, computeTargetAddress } from "@gnosis.pm/zodiac";
import { deployMastercopy } from "zodiac-core";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

import CONTRACT_ARTIFACT from "../../build/artifacts/contracts/CirculatingSupply/CirculatingSupplyERC20.sol/CirculatingSupplyERC20.json";

import createAdapter from "./createEIP1193";

const SaltZero =
"0x0000000000000000000000000000000000000000000000000000000000000000";
const FirstAddress = "0x0000000000000000000000000000000000000001";

const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts } = hre;
const { deployer: deployerAddress } = await getNamedAccounts();
const deployer = hre.ethers.provider.getSigner(deployerAddress);
const deployer = await hre.ethers.provider.getSigner(deployerAddress);

const CirculatingSupplyERC20 = await hre.ethers.getContractFactory(
"CirculatingSupplyERC20"
);

const args = [FirstAddress, FirstAddress, []];

const { address, isDeployed } = await computeTargetAddress(
deployer,
CirculatingSupplyERC20,
args,
SaltZero
);
const { noop, address } = await deployMastercopy({
bytecode: CirculatingSupplyERC20.bytecode,
constructorArgs: {
types: ["address", "address", "address[]"],
values: [FirstAddress, FirstAddress, []],
},
salt: SaltZero,
provider: createAdapter({
provider: hre.network.provider,
signer: deployer,
}),
});

if (isDeployed) {
if (noop) {
console.log("CirculatingSupplyERC20 already deployed to:", address);
} else {
await deployMastercopy(deployer, CirculatingSupplyERC20, args, SaltZero);
console.log("CirculatingSupplyERC20 was deployed to:", address);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { computeTargetAddress, deployMastercopy } from "@gnosis.pm/zodiac";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { deployMastercopy } from "zodiac-core";

import CONTRACT_ARTIFACT from "../../build/artifacts/contracts/ExitModule/ExitERC20Module.sol/ExitERC20.json";

import createAdapter from "./createEIP1193";

const SaltZero =
"0x0000000000000000000000000000000000000000000000000000000000000000";
const FirstAddress = "0x0000000000000000000000000000000000000001";

const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts } = hre;
const { deployer: deployerAddress } = await getNamedAccounts();
const deployer = hre.ethers.provider.getSigner(deployerAddress);
const deployer = await hre.ethers.provider.getSigner(deployerAddress);

const ExitERC20 = await hre.ethers.getContractFactory("ExitERC20");

Expand All @@ -22,17 +24,22 @@ const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
FirstAddress,
FirstAddress,
];
const { address, isDeployed } = await computeTargetAddress(
deployer,
ExitERC20,
args,
SaltZero
);

if (isDeployed) {
const { noop, address } = await deployMastercopy({
bytecode: ExitERC20.bytecode,
constructorArgs: {
types: ["address", "address", "address", "address", "address"],
values: args,
},
salt: SaltZero,
provider: createAdapter({
provider: hre.network.provider,
signer: deployer,
}),
});

if (noop) {
console.log("ExitERC20 already deployed to:", address);
} else {
await deployMastercopy(deployer, ExitERC20, args, SaltZero);
console.log("ExitERC20 was deployed to:", address);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { computeTargetAddress, deployMastercopy } from "@gnosis.pm/zodiac";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { deployMastercopy } from "zodiac-core";

import CONTRACT_ARTIFACT from "../../build/artifacts/contracts/ExitModule/ExitERC721Module.sol/ExitERC721.json";
import createAdapter from "./createEIP1193";

const SaltZero =
"0x0000000000000000000000000000000000000000000000000000000000000000";
Expand All @@ -11,7 +12,7 @@ const FirstAddress = "0x0000000000000000000000000000000000000001";
const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { getNamedAccounts } = hre;
const { deployer: deployerAddress } = await getNamedAccounts();
const deployer = hre.ethers.provider.getSigner(deployerAddress);
const deployer = await hre.ethers.provider.getSigner(deployerAddress);

const ExitERC721 = await hre.ethers.getContractFactory("ExitERC721");

Expand All @@ -23,17 +24,22 @@ const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
FirstAddress,
];

const { address, isDeployed } = await computeTargetAddress(
deployer,
ExitERC721,
args,
SaltZero
);
const { noop, address } = await deployMastercopy({
bytecode: ExitERC721.bytecode,
constructorArgs: {
types: ["address", "address", "address", "address", "address"],
values: args,
},
salt: SaltZero,
provider: createAdapter({
provider: hre.network.provider,
signer: deployer,
}),
});

if (isDeployed) {
if (noop) {
console.log("ExitERC721 already deployed to:", address);
} else {
await deployMastercopy(deployer, ExitERC721, args, SaltZero);
console.log("ExitERC721 was deployed to:", address);
}

Expand Down

0 comments on commit df901ff

Please sign in to comment.