Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Multi contract deploy #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
"ts-node": "10.9.1",
"typescript": "^5.0.2"
}
}
}
17 changes: 17 additions & 0 deletions src/db/mongo-adapter/mongo-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,23 @@ export class MongoDBAdapter {
});
}

async getContracts (contractName : string, version ?: string) {
if (!version) {
({ dbVersion: version } = await this.versioner.getCheckLatestVersion());
}

const cursor = await this.contracts.find({
name: contractName,
version,
});

const foundContracts = await cursor.toArray();

if (foundContracts.length > 0) {
return foundContracts;
} else return null;
}

async writeContract (contractName : string, data : Omit<IContractDbData, "version">, version ?: string) {
if (!version) {
({ dbVersion: version } = await this.versioner.getCheckLatestVersion());
Expand Down
1 change: 1 addition & 0 deletions src/db/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface IContractDbData {
address : string;
abi : string;
bytecode : string;
args : string;
implementation : string | null;
version : string;
}
Expand Down
28 changes: 21 additions & 7 deletions src/missions/base-deploy-mission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,28 @@ export class BaseDeployMission <
}

async getFromDB () {
return this.campaign.dbAdapter.getContract(this.dbName);
return this.campaign.dbAdapter.getContract(this.contractName);
}

async saveToDB (contract : IContractV6) {
this.logger.debug(`Writing ${this.dbName} to DB...`);
this.logger.debug(`Writing ${this.contractName} to DB...`);

this.implAddress = this.proxyData.isProxy
? await this.campaign.deployer.getProxyImplAddress(await contract.getAddress())
: null;

const contractDbDoc = await this.buildDbObject(contract, this.implAddress);

return this.campaign.dbAdapter.writeContract(this.dbName, contractDbDoc);
return this.campaign.dbAdapter.writeContract(this.contractName, contractDbDoc);
}

async needsDeploy () {
const dbContract = await this.getFromDB();

if (!dbContract) {
this.logger.info(`${this.dbName} not found in DB, proceeding to deploy...`);
this.logger.info(`${this.contractName} not found in DB, proceeding to deploy...`);
} else {
this.logger.info(`${this.dbName} 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,
dbContract.address,
Expand Down Expand Up @@ -91,11 +90,26 @@ export class BaseDeployMission <
implAddress : string | null
) : Promise<Omit<IContractDbData, "version">> {
const { abi, bytecode } = this.getArtifact();

const bnToString = (key : string, value : TDeployArgs) => {
if (typeof value === "bigint") {
// eslint-disable-next-line @typescript-eslint/ban-types
return `${(value as BigInt).toString()}n`;
}

if (Array.isArray(value) && value.length === 0) {
return undefined;
}

return value;
};

return {
name: this.dbName,
name: this.contractName,
address: await hhContract.getAddress(),
abi: JSON.stringify(abi),
bytecode,
args: JSON.stringify(await this.deployArgs(), bnToString),
implementation: implAddress,
};
}
Expand Down