Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

AP-792: Add missing endowment contracts-related and VaultEmitter-related tasks #380

Merged
merged 12 commits into from
Sep 15, 2023
76 changes: 3 additions & 73 deletions contracts/multisigs/endowment-multisig/scripts/deploy.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,3 @@
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {HardhatRuntimeEnvironment} from "hardhat/types";
import {
EndowmentMultiSigEmitter__factory,
EndowmentMultiSigFactory__factory,
EndowmentMultiSig__factory,
} from "typechain-types";
import {Deployment, ProxyDeployment} from "types";
import {deploy, deployBehindProxy, logger, updateAddresses} from "utils";

export async function deployEndowmentMultiSig(
registrar: string,
proxyAdmin: string,
factoryOwner: string,
deployer: SignerWithAddress,
hre: HardhatRuntimeEnvironment
): Promise<{
emitter: ProxyDeployment<EndowmentMultiSigEmitter__factory>;
factory: Deployment<EndowmentMultiSigFactory__factory>;
implementation: Deployment<EndowmentMultiSig__factory>;
}> {
logger.out("Deploying EndowmentMultiSig contracts...");

// deploy implementation contract
const implementation = await deploy(new EndowmentMultiSig__factory(deployer));

// deploy factory
const factory = await deploy(new EndowmentMultiSigFactory__factory(deployer), [
implementation.contract.address,
proxyAdmin,
registrar,
]);

logger.out(`Transferring ownership to: ${factoryOwner}...`);
const tx = await factory.contract.transferOwnership(factoryOwner);
logger.out(`Tx hash: ${tx.hash}`);
await tx.wait();
const newOwner = await factory.contract.owner();
if (newOwner !== factoryOwner) {
throw new Error(`Error updating owner: expected '${factoryOwner}', actual: '${newOwner}'`);
}

// emitter data setup
const Emitter = new EndowmentMultiSigEmitter__factory(deployer);
const initData = Emitter.interface.encodeFunctionData("initEndowmentMultiSigEmitter", [
factory.contract.address,
]);
// deploy emitter
const emitter = await deployBehindProxy(Emitter, proxyAdmin, initData);

// update address file
await updateAddresses(
{
multiSig: {
endowment: {
emitter: {
implementation: emitter.implementation.contract.address,
proxy: emitter.proxy.contract.address,
},
factory: factory.contract.address,
implementation: implementation.contract.address,
},
},
},
hre
);

return {
emitter,
factory,
implementation,
};
}
export * from "./deployEndowmentMultiSig";
export * from "./deployEndowmentMultiSigEmitter";
export * from "./deployEndowmentMultiSigFactory";
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {HardhatRuntimeEnvironment} from "hardhat/types";
import {EndowmentMultiSig__factory} from "typechain-types";
import {Deployment} from "types";
import {deploy, logger, updateAddresses} from "utils";

export async function deployEndowmentMultiSig(
deployer: SignerWithAddress,
hre: HardhatRuntimeEnvironment
): Promise<Deployment<EndowmentMultiSig__factory>> {
logger.out("Deploying EndowmentMultiSig...");

// deploy implementation contract
const implementation = await deploy(new EndowmentMultiSig__factory(deployer));

// update address file
await updateAddresses(
{
multiSig: {
endowment: {
implementation: implementation.contract.address,
},
},
},
hre
);

return implementation;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {HardhatRuntimeEnvironment} from "hardhat/types";
import {EndowmentMultiSigEmitter__factory} from "typechain-types";
import {ProxyDeployment} from "types";
import {deployBehindProxy, logger, updateAddresses} from "utils";

export async function deployEndowmentMultiSigEmitter(
factory: string,
proxyAdmin: string,
deployer: SignerWithAddress,
hre: HardhatRuntimeEnvironment
): Promise<ProxyDeployment<EndowmentMultiSigEmitter__factory>> {
logger.out("Deploying EndowmentMultiSigEmitter...");

// deploy emitter
const Emitter = new EndowmentMultiSigEmitter__factory(deployer);
const initData = Emitter.interface.encodeFunctionData("initEndowmentMultiSigEmitter", [factory]);
const emitter = await deployBehindProxy(Emitter, proxyAdmin, initData);

// update address file
await updateAddresses(
{
multiSig: {
endowment: {
emitter: {
implementation: emitter.implementation.contract.address,
proxy: emitter.proxy.contract.address,
},
},
},
},
hre
);

return emitter;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {SignerWithAddress} from "@nomiclabs/hardhat-ethers/signers";
import {HardhatRuntimeEnvironment} from "hardhat/types";
import {EndowmentMultiSigFactory__factory} from "typechain-types";
import {Deployment} from "types";
import {deploy, logger, updateAddresses} from "utils";

export async function deployEndowmentMultiSigFactory(
implementation: string,
registrar: string,
proxyAdmin: string,
factoryOwner: string,
deployer: SignerWithAddress,
hre: HardhatRuntimeEnvironment
): Promise<Deployment<EndowmentMultiSigFactory__factory>> {
logger.out("Deploying EndowmentMultiSigFactory...");

// deploy factory
const factory = await deploy(new EndowmentMultiSigFactory__factory(deployer), [
implementation,
proxyAdmin,
registrar,
]);

logger.out(`Transferring ownership to: ${factoryOwner}...`);
const tx = await factory.contract.transferOwnership(factoryOwner);
logger.out(`Tx hash: ${tx.hash}`);
await tx.wait();
const newOwner = await factory.contract.owner();
if (newOwner !== factoryOwner) {
throw new Error(`Error updating owner: expected '${factoryOwner}', actual: '${newOwner}'`);
}

// update address file
await updateAddresses(
{
multiSig: {
endowment: {
factory: factory.contract.address,
},
},
},
hre
);

return factory;
}
28 changes: 20 additions & 8 deletions tasks/deploy/deployAngelProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import {deployIndexFund} from "contracts/core/index-fund/scripts/deploy";
import {deployRegistrar} from "contracts/core/registrar/scripts/deploy";
import {deployRouter} from "contracts/core/router/scripts/deploy";
import {deployVaultEmitter} from "contracts/core/vault/scripts/deployVaultEmitter";
import {deployEndowmentMultiSig} from "contracts/multisigs/endowment-multisig/scripts/deploy";
import {
deployEndowmentMultiSig,
deployEndowmentMultiSigEmitter,
deployEndowmentMultiSigFactory,
} from "contracts/multisigs/endowment-multisig/scripts/deploy";
import {
deployAPTeamMultiSig,
deployCharityApplications,
Expand Down Expand Up @@ -132,13 +136,21 @@ task("deploy:AngelProtocol", "Will deploy complete Angel Protocol")
hre
);

const endowmentMultiSig = await deployEndowmentMultiSig(
const endowmentMultiSig = await deployEndowmentMultiSig(deployer, hre);
const endowmentMultiSigFactory = await deployEndowmentMultiSigFactory(
endowmentMultiSig.contract.address,
registrar.proxy.contract.address,
proxyAdminMultisig.contract.address,
apTeamMultisig.proxy.contract.address,
deployer,
hre
);
const endowmentMultiSigEmitter = await deployEndowmentMultiSigEmitter(
endowmentMultiSigFactory.contract.address,
proxyAdminMultisig.contract.address,
deployer,
hre
);

const vaultEmitter = await deployVaultEmitter(
proxyAdminMultisig.contract.address,
Expand All @@ -152,8 +164,8 @@ task("deploy:AngelProtocol", "Will deploy complete Angel Protocol")
treasury: treasuryAddress,
uniswapRouter: thirdPartyAddresses.uniswap.swapRouter.address, //address
uniswapFactory: thirdPartyAddresses.uniswap.factory.address, //address
multisigFactory: endowmentMultiSig.factory.contract.address, //address
multisigEmitter: endowmentMultiSig.emitter.proxy.contract.address, //address
multisigFactory: endowmentMultiSigFactory.contract.address, //address
multisigEmitter: endowmentMultiSigEmitter.proxy.contract.address, //address
charityApplications: charityApplications.proxy.contract.address, //address
proxyAdmin: proxyAdminMultisig.contract.address, //address
usdcAddress: thirdPartyAddresses.usdcToken.address,
Expand Down Expand Up @@ -187,10 +199,10 @@ task("deploy:AngelProtocol", "Will deploy complete Angel Protocol")
charityApplications.proxy,
indexFund.implementation,
indexFund.proxy,
endowmentMultiSig.emitter.implementation,
endowmentMultiSig.emitter.proxy,
endowmentMultiSig.factory,
endowmentMultiSig.implementation,
endowmentMultiSigEmitter.implementation,
endowmentMultiSigEmitter.proxy,
endowmentMultiSigFactory,
endowmentMultiSig,
gasFwd.factory,
gasFwd.implementation,
vaultEmitter.implementation,
Expand Down
40 changes: 7 additions & 33 deletions tasks/deploy/deployEndowmentMultisig.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,31 @@
import {deployEndowmentMultiSig} from "contracts/multisigs/endowment-multisig/scripts/deploy";
import {task} from "hardhat/config";
import {confirmAction, isLocalNetwork, getAddresses, logger, verify, getSigners} from "utils";
import {confirmAction, getSigners, isLocalNetwork, logger, verify} from "utils";

type TaskArgs = {
apTeamSignerPkey?: string;
registrar?: string;
skipVerify: boolean;
yes: boolean;
};

task("deploy:EndowmentMultiSig", "Will deploy EndowmentMultiSig contract")
.addOptionalParam(
"registrar",
"Addresss of the registrar contract. Will do a local lookup from contract-address.json if none is provided."
)
.addOptionalParam(
"apTeamSignerPkey",
"If running on prod, provide a pkey for a valid APTeam Multisig Owner."
)
.addFlag("skipVerify", "Skip contract verification")
.addFlag("yes", "Automatic yes to prompt.")
.setAction(async (taskArgs: TaskArgs, hre) => {
try {
const addresses = await getAddresses(hre);
const {deployer} = await getSigners(hre);
logger.divider();
logger.out("Deploying EndowmentMultiSig...");

const registrarAddress = taskArgs.registrar || addresses.registrar.proxy;
const {deployer} = await getSigners(hre);

const isConfirmed = taskArgs.yes || (await confirmAction("Deploying EndowmentMultiSig..."));
const isConfirmed = taskArgs.yes || (await confirmAction());
if (!isConfirmed) {
return logger.out("Confirmation denied.", logger.Level.Warn);
}

const deployData = await deployEndowmentMultiSig(
registrarAddress,
addresses.multiSig.proxyAdmin,
addresses.multiSig.apTeam.proxy,
deployer,
hre
);

await hre.run("manage:registrar:updateConfig", {
multisigFactory: deployData.factory.contract.address,
multisigEmitter: deployData.emitter.proxy.contract.address,
apTeamSignerPkey: taskArgs.apTeamSignerPkey,
yes: true,
});
const deployData = await deployEndowmentMultiSig(deployer, hre);

if (!isLocalNetwork(hre) && !taskArgs.skipVerify) {
await verify(hre, deployData.emitter.implementation);
await verify(hre, deployData.emitter.proxy);
await verify(hre, deployData.factory);
await verify(hre, deployData.implementation);
await verify(hre, deployData);
}
} catch (error) {
logger.out(error, logger.Level.Error);
Expand Down
51 changes: 51 additions & 0 deletions tasks/deploy/deployEndowmentMultisigEmitter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import {deployEndowmentMultiSigEmitter} from "contracts/multisigs/endowment-multisig/scripts/deploy";
import {task} from "hardhat/config";
import {confirmAction, getAddresses, getSigners, isLocalNetwork, logger, verify} from "utils";

type TaskArgs = {
apTeamSignerPkey?: string;
skipVerify: boolean;
yes: boolean;
};

task("deploy:EndowmentMultiSigEmitter", "Will deploy EndowmentMultiSigEmitter contract")
.addOptionalParam(
"apTeamSignerPkey",
"If running on prod, provide a pkey for a valid APTeam Multisig Owner."
)
.addFlag("skipVerify", "Skip contract verification")
.addFlag("yes", "Automatic yes to prompt.")
.setAction(async (taskArgs: TaskArgs, hre) => {
try {
logger.divider();
logger.out("Deploying EndowmentMultiSigEmitter...");

const addresses = await getAddresses(hre);
const {deployer} = await getSigners(hre);

const isConfirmed = taskArgs.yes || (await confirmAction());
if (!isConfirmed) {
return logger.out("Confirmation denied.", logger.Level.Warn);
}

const deployData = await deployEndowmentMultiSigEmitter(
addresses.multiSig.endowment.factory,
addresses.multiSig.proxyAdmin,
deployer,
hre
);

await hre.run("manage:registrar:updateConfig", {
multisigEmitter: deployData.proxy.contract.address,
apTeamSignerPkey: taskArgs.apTeamSignerPkey,
yes: true,
});

if (!isLocalNetwork(hre) && !taskArgs.skipVerify) {
await verify(hre, deployData.implementation);
await verify(hre, deployData.proxy);
}
} catch (error) {
logger.out(error, logger.Level.Error);
}
});
Loading