Skip to content

Commit

Permalink
feat: allow configuring confirmations for contract deployments (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
milapsheth authored Oct 12, 2023
1 parent 1d3dd9a commit af8eeca
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 9 additions & 4 deletions scripts/create2Deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const create2DeployContract = async (
key,
args = [],
txOptions = null,
confirmations = null,
) => {
if (txOptions && !Number.isNaN(Number(txOptions))) {
txOptions = {
Expand All @@ -55,8 +56,10 @@ const create2DeployContract = async (
const salt = getSaltFromKey(key);
const factory = new ContractFactory(contractJson.abi, contractJson.bytecode);
const bytecode = factory.getDeployTransaction(...args).data;
const tx = await deployer.connect(wallet).deploy(bytecode, salt, txOptions);
await tx.wait();

const tx = await deployer.deploy(bytecode, salt, txOptions);
await tx.wait(confirmations);

const address = await deployer.deployedAddress(
bytecode,
wallet.address,
Expand All @@ -73,6 +76,7 @@ const create2DeployAndInitContract = async (
args = [],
initArgs = [],
txOptions = null,
confirmations = null,
) => {
if (txOptions && !Number.isNaN(Number(txOptions))) {
txOptions = {
Expand All @@ -91,10 +95,11 @@ const create2DeployAndInitContract = async (
);
const contract = new Contract(address, contractJson.abi, wallet);
const initData = (await contract.populateTransaction.init(...initArgs)).data;

const tx = await deployer
.connect(wallet)
.deployAndInit(bytecode, salt, initData, txOptions);
await tx.wait();
await tx.wait(confirmations);

return contract;
};

Expand Down
14 changes: 10 additions & 4 deletions scripts/create3Deployer.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const create3DeployContract = async (
key,
args = [],
txOptions = null,
confirmations = null,
) => {
if (txOptions && !Number.isNaN(Number(txOptions))) {
txOptions = {
Expand All @@ -51,9 +52,12 @@ const create3DeployContract = async (
const salt = getSaltFromKey(key);
const factory = new ContractFactory(contractJson.abi, contractJson.bytecode);
const bytecode = factory.getDeployTransaction(...args).data;
const tx = await deployer.connect(wallet).deploy(bytecode, salt, txOptions);
await tx.wait();

const tx = await deployer.deploy(bytecode, salt, txOptions);
await tx.wait(confirmations);

const address = await deployer.deployedAddress('0x', wallet.address, salt);

return new Contract(address, contractJson.abi, wallet);
};

Expand All @@ -65,6 +69,7 @@ const create3DeployAndInitContract = async (
args = [],
initArgs = [],
txOptions = null,
confirmations = null,
) => {
if (txOptions && !Number.isNaN(Number(txOptions))) {
txOptions = {
Expand All @@ -79,10 +84,11 @@ const create3DeployAndInitContract = async (
const address = await deployer.deployedAddress('0x', wallet.address, salt);
const contract = new Contract(address, contractJson.abi, wallet);
const initData = (await contract.populateTransaction.init(...initArgs)).data;

const tx = await deployer
.connect(wallet)
.deployAndInit(bytecode, salt, initData, txOptions);
await tx.wait();
await tx.wait(confirmations);

return contract;
};

Expand Down

0 comments on commit af8eeca

Please sign in to comment.