Skip to content

Commit

Permalink
fix: Deploy Campaign polish and TODOs (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
Whytecrowe authored Dec 1, 2023
2 parents 06d7783 + 3d72878 commit 8b2976d
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 119 deletions.
9 changes: 4 additions & 5 deletions src/deploy/campaign/deploy-campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class DeployCampaign {
config : IDeployCampaignConfig;
version : string;

// TODO dep: figure out typing here so that methods of each contract type are resolved in Mission classes!
// TODO dep: improve typing here so that methods of each contract type are resolved in Mission classes!
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[name : string | symbol] : any;

Expand Down Expand Up @@ -75,13 +75,13 @@ export class DeployCampaign {
{}
);

this.logger.debug("Deploy Campaign initialized.");
this.logger.info("Deploy Campaign initialized.");

return campaignProxy;
}

async execute () {
this.logger.debug("Deploy Campaign execution started.");
this.logger.info("Deploy Campaign execution started.");

await Object.values(this.state.instances).reduce(
async (
Expand All @@ -102,12 +102,11 @@ export class DeployCampaign {
await this.monitor();
}

this.logger.debug("Deploy Campaign execution finished successfully.");
this.logger.info("Deploy Campaign execution finished successfully.");
}

updateStateContract (instanceName : string, contractName : string, contract : Contract) {
this.state.contracts[instanceName] = contract;
// TODO dep: make better logger and decide which levels to call where
this.logger.debug(`Data of deployed contract '${contractName}' is added to Campaign state at '${instanceName}'.`);
}

Expand Down
1 change: 0 additions & 1 deletion src/deploy/db/mongo-adapter/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ export const VERSION_TYPES = {
archived: "ARCHIVED",
};

// TODO dep: move these to default ENV config
export const DEFAULT_MONGO_URI = "mongodb://localhost:27018";
export const DEFAULT_MONGO_DB_NAME = "zns-campaign";
4 changes: 3 additions & 1 deletion src/deploy/db/mongo-adapter/get-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export const getMongoAdapter = async (logger ?: TLogger) : Promise<MongoDBAdapte
clientOpts: process.env.MONGO_DB_CLIENT_OPTS
? JSON.parse(process.env.MONGO_DB_CLIENT_OPTS)
: undefined,
version: process.env.MONGO_DB_VERSION,
version: process.env.MONGO_DB_VERSION
? process.env.MONGO_DB_VERSION
: undefined,
};

let createNew = false;
Expand Down
5 changes: 1 addition & 4 deletions src/deploy/db/mongo-adapter/mongo-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class MongoDBAdapter {
dbName,
clientOpts,
} : IMongoDBAdapterArgs) {
// TODO dep: add a way to get these from ENV
this.logger = logger;
this.client = new MongoClient(dbUri, clientOpts);
this.clientOpts = clientOpts;
Expand Down Expand Up @@ -96,7 +95,7 @@ export class MongoDBAdapter {
});
}

async writeContract (contractName : string, data : IContractDbData, version ?: string) {
async writeContract (contractName : string, data : Omit<IContractDbData, "version">, version ?: string) {
if (!version) {
({ dbVersion: version } = await this.getCheckLatestVersion());
}
Expand All @@ -115,7 +114,6 @@ export class MongoDBAdapter {
}

// Versioning methods
// TODO dep: add logging to all versioning stages and methods !!
async configureVersioning (version ?: string) {
// TODO dep: add archiving logic once determined on how to handle it
const tempV = await this.getTempVersion();
Expand Down Expand Up @@ -260,7 +258,6 @@ export class MongoDBAdapter {
}

async clearDBForVersion (version : string) {
// TODO dep: add more collections here when added
await this.contracts.deleteMany({
version,
});
Expand Down
17 changes: 12 additions & 5 deletions src/deploy/logger/create-logger.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
import winston from "winston";
import { TLogger } from "../campaign/types";
import { includes } from "hardhat/internal/hardhat-network/provider/filter";

let logger : TLogger | null = null;


// TODO dep: refine this function and configurability of this logger
export const createLogger = (logLevel ?: string, silent ?: boolean) => winston.createLogger({
level: logLevel,
format: winston.format.combine(
// TODO dep: adjust the format to what we need
winston.format.json(),
winston.format.timestamp(),
winston.format.prettyPrint(),
),
transports: [
// TODO dep: figure out where to transport this in production
new winston.transports.Console(),
],
// TODO dep: make sure we need this to be set!
// TODO dep: do we need this to be set ?
exitOnError: false,
silent,
});

// TODO dep: add more ENV vars here so we don't have to pass anything
export const getLogger = () : TLogger => {
if (logger) return logger;

Expand All @@ -31,5 +28,15 @@ export const getLogger = () : TLogger => {
process.env.SILENT_LOGGER === "true"
);

const logFileName = `deploy-${Date.now()}.log`;

if (process.env.ENV_LEVEL?.includes("prod") || process.env.ENV_LEVEL?.includes("test")) {
logger.add(
new winston.transports.File({ filename: logFileName }),
);

logger.debug(`The ENV_LEVEL is ${process.env.ENV_LEVEL}, logs will be saved in ${ logFileName } file`);
}

return logger;
};
17 changes: 5 additions & 12 deletions src/deploy/missions/base-deploy-mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import { ProxyKinds } from "../constants";
import { ContractByName } from "@tenderly/hardhat-tenderly/dist/tenderly/types";


// TODO dep:
// 1. add better logging for each step
// 2. add proper error handling
export class BaseDeployMission {
contractName! : string;
instanceName! : string;
Expand Down Expand Up @@ -57,11 +54,10 @@ export class BaseDeployMission {
async needsDeploy () {
const dbContract = await this.getFromDB();

// TODO dep: refine these
if (!dbContract) {
this.logger.debug(`${this.contractName} not found in DB, proceeding to deploy...`);
this.logger.info(`${this.contractName} not found in DB, proceeding to deploy...`);
} else {
this.logger.debug(`${this.contractName} found in DB at ${dbContract.address}, no deployment needed.`);
this.logger.info(`${this.contractName} found in DB at ${dbContract.address}, no deployment needed.`);

const contract = await this.campaign.deployer.getContractObject(
this.contractName,
Expand All @@ -84,17 +80,14 @@ export class BaseDeployMission {
return this.campaign.deployer.getContractArtifact(this.contractName);
}

buildDbObject (hhContract : Contract, implAddress : string | null) : IContractDbData {
buildDbObject (hhContract : Contract, implAddress : string | null) : Omit<IContractDbData, "version"> {
const { abi, bytecode } = this.getArtifact();
return {
name: this.contractName,
address: hhContract.address,
abi: JSON.stringify(abi),
bytecode,
implementation: implAddress,
// TODO dep: this might not be needed here since MongoAdapter will add it
// upon writing to DB
version: this.campaign.version,
};
}

Expand Down Expand Up @@ -142,7 +135,7 @@ export class BaseDeployMission {
}

async verify () {
this.logger.info(`Verifying ${this.contractName} on Etherscan...`);
this.logger.debug(`Verifying ${this.contractName} on Etherscan...`);
const { address } = await this.campaign[this.instanceName];

const ctorArgs = !this.proxyData.isProxy ? this.deployArgs() : undefined;
Expand All @@ -152,7 +145,7 @@ export class BaseDeployMission {
ctorArgs,
});

this.logger.info(`Etherscan verification for ${this.contractName} finished successfully.`);
this.logger.debug(`Etherscan verification for ${this.contractName} finished successfully.`);
}

async getMonitoringData () : Promise<Array<ContractByName>> {
Expand Down
3 changes: 1 addition & 2 deletions src/deploy/missions/contracts/access-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ export class ZNSAccessControllerDM extends BaseDeployMission {
proxyData = {
isProxy: false,
};
// TODO dep: make constants available for both this and tests.
// possibly use ones from the helpers

contractName = znsNames.accessController.contract;
instanceName = znsNames.accessController.instance;

Expand Down
22 changes: 0 additions & 22 deletions src/deploy/storage/base-storage-adapter.ts

This file was deleted.

52 changes: 0 additions & 52 deletions src/deploy/storage/file-storage.ts

This file was deleted.

9 changes: 0 additions & 9 deletions src/deploy/storage/utils.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/deploy/zns-campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const runZnsCampaign = async ({
dbVersion ?: string;
deployer ?: HardhatDeployer;
}) => {
// TODO dep: figure out the best place to put this at!
hre.upgrades.silenceWarnings();

const logger = getLogger();
Expand Down Expand Up @@ -53,7 +52,6 @@ export const runZnsCampaign = async ({

await campaign.execute();

// TODO dep: find the best place to call these !
await dbAdapter.finalizeDeployedVersion(dbVersion);

return campaign;
Expand Down
2 changes: 0 additions & 2 deletions test/DeployCampaignInt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -867,8 +867,6 @@ describe("Deploy Campaign Test", () => {
before (async () => {
[deployAdmin, admin, zeroVault] = await hre.ethers.getSigners();

// TODO dep ver: add proper checks for the new config values
// and make sure tenderly and etherscan ENV data is acquired correctly
config = {
deployAdmin,
governorAddresses: [deployAdmin.address],
Expand Down
4 changes: 2 additions & 2 deletions test/ZNSRootRegistrar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import { access } from "fs";
require("@nomicfoundation/hardhat-chai-matchers");


// TODO dep: this is the only test converted to use the new Campaign
// others need to be converted once the Campaign is ready in full
// This is the only test converted to use the new Campaign, other
// contract specific tests are using `deployZNS()` helper
describe("ZNSRootRegistrar", () => {
let deployer : SignerWithAddress;
let user : SignerWithAddress;
Expand Down

0 comments on commit 8b2976d

Please sign in to comment.