Skip to content

Commit

Permalink
feat: add deployment for title escrow factory (Open-Attestation#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
superical committed Apr 11, 2022
1 parent fb86103 commit 3677214
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 14 deletions.
48 changes: 41 additions & 7 deletions tasks/deploy-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,67 @@ import { verifyContract } from "./helpers/verify-contract";
import { TASK_DEPLOY_TOKEN } from "./task-names";

task(TASK_DEPLOY_TOKEN)
.setDescription("Deploys the TradeTrustERC721 token")
.setDescription("Deploys the TradeTrustERC721 token and, optionally, Title Escrow factory if not provided.")
.addParam("name", "Name of the token")
.addParam("symbol", "Symbol of token")
.addFlag("verify", "Verify on Etherscan")
.setAction(async ({ name, symbol, verify }, hre) => {
.addOptionalParam("factory", "Address of Title Escrow factory contract (Optional)")
.setAction(async ({ name, symbol, verify, factory }, hre) => {
const { ethers } = hre;
try {
const [deployer] = await hre.ethers.getSigners();
const [deployer] = await ethers.getSigners();
const deployerAddress = await deployer.getAddress();
let factoryAddress = factory;
let deployedNewFactory = false;

console.log(`[Deployer] ${deployerAddress}`);

if (!factoryAddress) {
console.log("[Status] No factory address provided, will deploy Title Escrow factory");
const titleEscrowFacFactory = await ethers.getContractFactory("TitleEscrowFactory");
const titleEscrowFactoryContract = await titleEscrowFacFactory.connect(deployer).deploy();
const factoryDeployTx = titleEscrowFactoryContract.deployTransaction;
console.log(`[Transaction - TitleEscrowFactory] Pending ${factoryDeployTx.hash}`);
await titleEscrowFactoryContract.deployed();
deployedNewFactory = true;
factoryAddress = titleEscrowFactoryContract.address;
console.log(`[Address - TitleEscrowFactory] Deployed to ${factoryAddress}`);
} else {
console.log(`[Status] Using ${factoryAddress} as Title Escrow factory`);
}

const contractName = "TradeTrustERC721";
const token: TradeTrustERC721 = await deployToken({
constructorParams: { name, symbol },
constructorParams: { name, symbol, factoryAddress },
hre,
contractName,
deployer,
});

if (verify) {
console.log("[Status] Waiting to verify (may take a while)...");
await token.deployTransaction.wait(5);
console.log("[Status] Start verification");

if (deployedNewFactory) {
await verifyContract({
address: factoryAddress,
constructorArgsParams: [],
contract: "contracts/TitleEscrowFactory.sol:TitleEscrowFactory",
hre,
});
}
await verifyContract({
address: token.address,
constructorArgsParams: [name, symbol],
constructorArgsParams: [name, symbol, factoryAddress],
contract: "contracts/TradeTrustERC721.sol:TradeTrustERC721",
hre,
});
}

console.log(`[Status] Completed deploying token`);
console.log("[Status] Completed deploying token");
} catch (err) {
console.log(`[Status] Failed to deploy token`);
console.log("[Status] An error occurred while deploying token");
console.error(err);
}
});
10 changes: 4 additions & 6 deletions tasks/helpers/deploy-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { TradeTrustERC721 } from "@tradetrust/contracts";
type DeployTokenConstructorParameters = {
name: string;
symbol: string;
factoryAddress: string;
};

export const deployToken = async <TToken extends TradeTrustERC721>({
Expand All @@ -20,19 +21,16 @@ export const deployToken = async <TToken extends TradeTrustERC721>({
}): Promise<TToken> => {
const { ethers } = hre;

const deployerAddress = await deployer.getAddress();
console.log(`[Deployer] ${deployerAddress}`);

const tokenFactory = await ethers.getContractFactory(contractName);
const token = (await tokenFactory
.connect(deployer)
.deploy(constructorParams.name, constructorParams.symbol)) as TToken;
.deploy(constructorParams.name, constructorParams.symbol, constructorParams.factoryAddress)) as TToken;

const tx = token.deployTransaction;
console.log(`[Transaction] Pending ${tx.hash}...`);
console.log(`[Transaction - ${contractName}] Pending ${tx.hash}`);

await token.deployed();
console.log(`[Address] Deployed to ${token.address}`);
console.log(`[Address - ${contractName}] Deployed to ${token.address}`);

return token;
};
4 changes: 3 additions & 1 deletion tasks/helpers/verify-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ type Parameters = {
hre: HardhatRuntimeEnvironment;
address: string;
constructorArgsParams: any[];
contract?: string;
};

export const verifyContract = async ({ hre, address, constructorArgsParams }: Parameters) => {
export const verifyContract = async ({ hre, address, constructorArgsParams, contract }: Parameters) => {
if (["localhost", "hardhat"].includes(hre.network.name)) {
console.log(`[Status] Skipped verifying contract ${address} on local`);
return;
Expand All @@ -15,6 +16,7 @@ export const verifyContract = async ({ hre, address, constructorArgsParams }: Pa
await hre.run("verify", {
address,
constructorArgsParams,
contract,
});
console.log(`[Status] Verified contract at ${address}`);
};

0 comments on commit 3677214

Please sign in to comment.