Skip to content

Commit

Permalink
Add deploy script and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kolezhniuk committed Dec 23, 2024
1 parent fd5d37e commit 62f7390
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 0 deletions.
53 changes: 53 additions & 0 deletions helpers/DeployHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
waitNotToInterfereWithHardhatIgnition,
} from "./helperUtils";
import { MCPaymentProxyModule } from "../ignition/modules/mcPayment";
import { SponsorPaymentProxyModule } from "../ignition/modules/sponsorPayment";

const SMT_MAX_DEPTH = 64;

Expand Down Expand Up @@ -1232,6 +1233,58 @@ export class DeployHelper {
};
}

async deploySponsorPayment(
ownerPercentage: number,
sponsorWithDrawalDelay: number,
deployStrategy: "basic" | "create2" = "basic",
): Promise<{
sponsorPayment: Contract;
}> {
const owner = this.signers[0];
const SponsorPaymentFactory = await ethers.getContractFactory("SponsorPayment");
const Create2AddressAnchorFactory = await ethers.getContractFactory("Create2AddressAnchor");

let sponsorPayment;
if (deployStrategy === "create2") {
this.log("deploying with CREATE2 strategy...");

// Deploying SponsorPayment contract to predictable address but with dummy implementation
sponsorPayment = (
await ignition.deploy(SponsorPaymentProxyModule, {
strategy: deployStrategy,
})
).proxy;
await sponsorPayment.waitForDeployment();

// Upgrading SponsorPayment contract to the first real implementation
// and force network files import, so creation, as they do not exist at the moment
const sponsorPaymentAddress = await sponsorPayment.getAddress();
await upgrades.forceImport(sponsorPaymentAddress, Create2AddressAnchorFactory);
sponsorPayment = await upgrades.upgradeProxy(sponsorPaymentAddress, SponsorPaymentFactory, {
redeployImplementation: "always",
call: {
fn: "initialize",
args: [await owner.getAddress(), ownerPercentage, sponsorWithDrawalDelay],
},
});
} else {
this.log("deploying with BASIC strategy...");

sponsorPayment = await upgrades.deployProxy(SponsorPaymentFactory, [
await owner.getAddress(),
ownerPercentage,
sponsorWithDrawalDelay,
]);
}

await sponsorPayment.waitForDeployment();
console.log("\nSponsorPaymentAddress deployed to:", await sponsorPayment.getAddress());

return {
sponsorPayment,
};
}

async upgradeIdentityTreeStore(
identityTreeStoreAddress: string,
stateAddress: string,
Expand Down
10 changes: 10 additions & 0 deletions helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@ export const contractsInfo = Object.freeze({
libraries: {},
},
},
SPONSOR_PAYMENT: {
name: "SponsorPayment",
version: "1.0.0",
unifiedAddress: "",
create2Calldata: ethers.hexlify(ethers.toUtf8Bytes("iden3.create2.SponsorPayment")),
verificationOpts: {
constructorArgsImplementation: [],
libraries: {},
},
},
CROSS_CHAIN_PROOF_VALIDATOR: {
name: "CrossChainProofValidator",
unifiedAddress: "",
Expand Down
22 changes: 22 additions & 0 deletions ignition/modules/sponsorPayment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { buildModule } from "@nomicfoundation/hardhat-ignition/modules";
import { contractsInfo } from "../../helpers/constants";

export const SponsorPaymentProxyModule = buildModule("SponsorPaymentProxyModule", (m) => {
const proxyAdminOwner = m.getAccount(0);

// This contract is supposed to be deployed to the same address across many networks,
// so the first implementation address is a dummy contract that does nothing but accepts any calldata.
// Therefore, it is a mechanism to deploy TransparentUpgradeableProxy contract
// with constant constructor arguments, so predictable init bytecode and predictable CREATE2 address.
// Subsequent upgrades are supposed to switch this proxy to the real implementation.

const proxy = m.contract("TransparentUpgradeableProxy", [
contractsInfo.CREATE2_ADDRESS_ANCHOR.unifiedAddress,
proxyAdminOwner,
contractsInfo.SPONSOR_PAYMENT.create2Calldata,
]);
const proxyAdminAddress = m.readEventArgument(proxy, "AdminChanged", "newAdmin");
const proxyAdmin = m.contractAt("ProxyAdmin", proxyAdminAddress);

return { proxyAdmin, proxy };
});
29 changes: 29 additions & 0 deletions scripts/deploy/deploySponsorPayment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { DeployHelper } from "../../helpers/DeployHelper";
import { getConfig, verifyContract } from "../../helpers/helperUtils";
import { contractsInfo } from "../../helpers/constants";

async function main() {
const config = getConfig();
const deployStrategy: "basic" | "create2" =
config.deployStrategy == "create2" ? "create2" : "basic";

const deployHelper = await DeployHelper.initialize(null, true);

const { sponsorPayment } = await deployHelper.deploySponsorPayment(
10,
60 * 60 * 24, // 1 day unix time
deployStrategy,
);

await verifyContract(
await sponsorPayment.getAddress(),
contractsInfo.SPONSOR_PAYMENT.verificationOpts,
);
}

main()
.then(() => process.exit(0))
.catch((error) => {
console.error(error);
process.exit(1);
});

0 comments on commit 62f7390

Please sign in to comment.