Skip to content

Commit

Permalink
chore: update deployment script
Browse files Browse the repository at this point in the history
  • Loading branch information
MexicanAce committed Dec 4, 2024
1 parent f10f345 commit d9614f6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 14 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WALLET_PRIVATE_KEY=
46 changes: 32 additions & 14 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ const ethersStaticSalt = new Uint8Array([
62, 140, 111, 128, 47, 32, 21,
177, 177, 174, 166,
]);
const SESSIONS_NAME = "SessionKeyValidator";
const ACCOUNT_IMPL_NAME = "SsoAccount";
const AA_FACTORY_NAME = "AAFactory";
const PAYMASTER_NAME = "ExampleAuthServerPaymaster";

async function deploy(name: string, deployer: Wallet, proxy: boolean, args?: any[]): Promise<string> {
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { deployFactory, create2 } = require("../test/utils");
console.log("Deploying", name, "contract...");
let implContract;
if (name == "AAFactory") {
if (name == AA_FACTORY_NAME) {
implContract = await deployFactory(deployer, args![0]);
} else {
implContract = await create2(name, deployer, ethersStaticSalt, args);
Expand Down Expand Up @@ -48,26 +52,25 @@ task("deploy", "Deploys ZKsync SSO contracts")
const provider = getProvider();

let privateKey: string;
if (cmd.privatekey) {
privateKey = cmd.privatekey;
} else if (hre.network.name == "inMemoryNode" || hre.network.name == "dockerizedNode") {
if (hre.network.name == "inMemoryNode" || hre.network.name == "dockerizedNode") {
console.log("Using local rich wallet");
privateKey = LOCAL_RICH_WALLETS[0].privateKey;
cmd.fund = "1";
} else {
throw new Error("Private key must be provided to deploy on non-local network");
if (!process.env.WALLET_PRIVATE_KEY) throw "⛔️ Wallet private key wasn't found in .env file!";
privateKey = process.env.WALLET_PRIVATE_KEY;
}

const deployer = new Wallet(privateKey, provider);
console.log("Deployer address:", deployer.address);

if (!cmd.only) {
await deploy("WebAuthValidator", deployer, !cmd.noProxy);
const sessions = await deploy("SessionKeyValidator", deployer, !cmd.noProxy);
const implementation = await deploy("SsoAccount", deployer, false);
const sessions = await deploy(SESSIONS_NAME, deployer, !cmd.noProxy);
const implementation = await deploy(ACCOUNT_IMPL_NAME, deployer, false);
// TODO: enable proxy for factory -- currently it's not working
const factory = await deploy("AAFactory", deployer, false, [implementation]);
const paymaster = await deploy("ExampleAuthServerPaymaster", deployer, false, [factory, sessions]);
const factory = await deploy(AA_FACTORY_NAME, deployer, false, [implementation]);
const paymaster = await deploy(PAYMASTER_NAME, deployer, false, [factory, sessions]);

if (cmd.fund != 0) {
console.log("Funding paymaster with", cmd.fund, "ETH...");
Expand All @@ -83,18 +86,33 @@ task("deploy", "Deploys ZKsync SSO contracts")
}
} else {
let args: any[] = [];
if (cmd.only == "AAFactory") {
if (cmd.only == AA_FACTORY_NAME) {
if (!cmd.implementation) {
throw new Error("Implementation address must be provided to deploy factory");
throw "⛔️ Implementation (--implementation <value>) address must be provided to deploy factory";
}
args = [cmd.implementation];
}
if (cmd.only == "ExampleAuthServerPaymaster") {
if (cmd.only == PAYMASTER_NAME) {
if (!cmd.factory || !cmd.sessions) {
throw new Error("Factory and SessionModule addresses must be provided to deploy paymaster");
throw "⛔️ Factory (--factory <value>) and SessionModule (--sessions <value>) addresses must be provided to deploy paymaster";
}
args = [cmd.factory, cmd.sessions];
}
await deploy(cmd.only, deployer, false, args);
const deployedContract = await deploy(cmd.only, deployer, false, args);

if (cmd.only == PAYMASTER_NAME) {
if (cmd.fund == 0) {
console.log("⚠️ Paymaster is unfunded ⚠️\n");
} else {
console.log("Funding paymaster with", cmd.fund, "ETH...");
await (
await deployer.sendTransaction({
to: deployedContract,
value: ethers.parseEther(cmd.fund),
})
).wait();
console.log("Paymaster funded\n");
}
}
}
});

0 comments on commit d9614f6

Please sign in to comment.