From df901ff493ff22421c4abfbcbef8f441fea16d31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crist=C3=B3v=C3=A3o=20Honorato?= Date: Tue, 30 Jul 2024 17:32:09 +0200 Subject: [PATCH] Migrate current deploy scripts to zodiac-core --- .../contracts/src/deploy/createEIP1193.ts | 22 ++++++++++++++ .../src/deploy/deploy_circulating_supply.ts | 29 +++++++++++-------- .../deploy_erc20_exit_module_mastercopy.ts | 29 ++++++++++++------- .../deploy_erc721_exit_module_mastercopy.ts | 26 ++++++++++------- 4 files changed, 73 insertions(+), 33 deletions(-) create mode 100644 packages/contracts/src/deploy/createEIP1193.ts diff --git a/packages/contracts/src/deploy/createEIP1193.ts b/packages/contracts/src/deploy/createEIP1193.ts new file mode 100644 index 0000000..6be63e9 --- /dev/null +++ b/packages/contracts/src/deploy/createEIP1193.ts @@ -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 }); + }, + }; +} diff --git a/packages/contracts/src/deploy/deploy_circulating_supply.ts b/packages/contracts/src/deploy/deploy_circulating_supply.ts index 3e43e93..d199e3b 100644 --- a/packages/contracts/src/deploy/deploy_circulating_supply.ts +++ b/packages/contracts/src/deploy/deploy_circulating_supply.ts @@ -1,9 +1,11 @@ -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"; @@ -11,25 +13,28 @@ 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); } diff --git a/packages/contracts/src/deploy/deploy_erc20_exit_module_mastercopy.ts b/packages/contracts/src/deploy/deploy_erc20_exit_module_mastercopy.ts index 7e8b44b..322a905 100644 --- a/packages/contracts/src/deploy/deploy_erc20_exit_module_mastercopy.ts +++ b/packages/contracts/src/deploy/deploy_erc20_exit_module_mastercopy.ts @@ -1,9 +1,11 @@ -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"; @@ -11,7 +13,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 ExitERC20 = await hre.ethers.getContractFactory("ExitERC20"); @@ -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); } diff --git a/packages/contracts/src/deploy/deploy_erc721_exit_module_mastercopy.ts b/packages/contracts/src/deploy/deploy_erc721_exit_module_mastercopy.ts index 6212423..62bcdd4 100644 --- a/packages/contracts/src/deploy/deploy_erc721_exit_module_mastercopy.ts +++ b/packages/contracts/src/deploy/deploy_erc721_exit_module_mastercopy.ts @@ -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"; @@ -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"); @@ -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); }