Skip to content

Commit

Permalink
added GAS_MULTIPLIER constant, small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed Jan 26, 2024
1 parent 4c50e2d commit 4dfd153
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 238 deletions.
1 change: 0 additions & 1 deletion l1-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"token-info": "ts-node scripts/token-info.ts",
"deploy-testkit": "ts-node scripts/deploy-testkit.ts",
"verify": "hardhat run --network env scripts/verify.ts",
"deploy-testnet-erc20": "ts-node scripts/deploy-testnet-token.ts",
"read-variable": "ts-node scripts/read-variable.ts",
"erc20-deploy-on-chain": "ts-node scripts/erc20-deploy-on-chain.ts",
"erc20-finish-deployment-on-chain": "ts-node scripts/erc20-finish-deployment-on-chain.ts",
Expand Down
55 changes: 4 additions & 51 deletions l1-contracts/scripts/deploy-erc20.ts
Original file line number Diff line number Diff line change
@@ -1,59 +1,17 @@
import * as hardhat from "hardhat";
import "@nomiclabs/hardhat-ethers";
import { Command } from "commander";
import { Wallet } from "ethers";
import { parseEther } from "ethers/lib/utils";
import { web3Provider } from "./utils";
import * as fs from "fs";
import * as path from "path";

const DEFAULT_ERC20 = "TestnetERC20Token";
import { deployTokens,TokenDescription } from "../src.ts/deploy-token";

const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, "etc/test_config/constant");
const ethTestConfig = JSON.parse(fs.readFileSync(`${testConfigPath}/eth.json`, { encoding: "utf-8" }));

const provider = web3Provider();

type Token = {
address: string | null;
name: string;
symbol: string;
decimals: number;
};

type TokenDescription = Token & {
implementation?: string;
};

async function deployToken(token: TokenDescription, wallet: Wallet): Promise<Token> {
token.implementation = token.implementation || DEFAULT_ERC20;
const tokenFactory = await hardhat.ethers.getContractFactory(token.implementation, wallet);
const args = token.implementation !== "WETH9" ? [token.name, token.symbol, token.decimals] : [];
const erc20 = await tokenFactory.deploy(...args, { gasLimit: 5000000 });
await erc20.deployTransaction.wait();

if (token.implementation !== "WETH9") {
await erc20.mint(wallet.address, parseEther("3000000000"));
}
for (let i = 0; i < 10; ++i) {
const testWallet = Wallet.fromMnemonic(ethTestConfig.test_mnemonic as string, "m/44'/60'/0'/0/" + i).connect(
provider
);
if (token.implementation !== "WETH9") {
await erc20.mint(testWallet.address, parseEther("3000000000"));
}
}

token.address = erc20.address;

// Remove the unneeded field
if (token.implementation) {
delete token.implementation;
}

return token;
}

async function main() {
const program = new Command();

Expand All @@ -80,7 +38,7 @@ async function main() {
? new Wallet(cmd.privateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

console.log(JSON.stringify(await deployToken(token, wallet), null, 2));
console.log(JSON.stringify(await deployTokens([token], wallet, ethTestConfig.mnemonic, true, false), null, 2));
});

program
Expand All @@ -89,17 +47,12 @@ async function main() {
.description("Adds a multiple tokens given in JSON format")
.action(async (tokens_json: string, cmd) => {
const tokens: Array<TokenDescription> = JSON.parse(tokens_json);
const result = [];

const wallet = cmd.privateKey
? new Wallet(cmd.privateKey, provider)
: Wallet.fromMnemonic(ethTestConfig.mnemonic, "m/44'/60'/0'/0/1").connect(provider);

for (const token of tokens) {
result.push(await deployToken(token, wallet));
}

console.log(JSON.stringify(result, null, 2));

console.log(JSON.stringify((await deployTokens(tokens, wallet, ethTestConfig.mnemonic, true, false)), null, 2));
});

await program.parseAsync(process.argv);
Expand Down
76 changes: 0 additions & 76 deletions l1-contracts/scripts/deploy-testnet-token.ts

This file was deleted.

4 changes: 2 additions & 2 deletions l1-contracts/scripts/deploy-weth-bridges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Deployer } from "../src.ts/deploy";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import * as fs from "fs";
import * as path from "path";
import { web3Provider } from "./utils";
import { GAS_MULTIPLIER, web3Provider} from "./utils";

const provider = web3Provider();
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, "etc/test_config/constant");
Expand All @@ -29,7 +29,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Deployer } from "../src.ts/deploy";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import * as fs from "fs";
import * as path from "path";
import { web3Provider, deployedAddressesFromEnv } from "./utils";
import { web3Provider, deployedAddressesFromEnv, GAS_MULTIPLIER } from "./utils";

const provider = web3Provider();
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, "etc/test_config/constant");
Expand Down Expand Up @@ -36,7 +36,7 @@ async function main() {
const ownerAddress = cmd.ownerAddress ? cmd.ownerAddress : deployWallet.address;
console.log(`Using owner address: ${ownerAddress}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

let nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/erc20-deploy-on-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "commander";
import { Wallet } from "ethers";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { Deployer } from "../src.ts/deploy";
import { web3Provider } from "./utils";
import { GAS_MULTIPLIER, web3Provider } from "./utils";

import * as fs from "fs";
import * as path from "path";
Expand Down Expand Up @@ -33,7 +33,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/erc20-finish-deployment-on-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Wallet } from "ethers";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import * as zksync from "zksync-ethers";
import { Deployer } from "../src.ts/deploy";
import { web3Provider } from "./utils";
import { GAS_MULTIPLIER, web3Provider } from "./utils";

import * as fs from "fs";
import * as path from "path";
Expand Down Expand Up @@ -49,7 +49,7 @@ async function main() {
"m/44'/60'/0'/0/0"
).connect(l2Provider);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/initialize-erc20-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Wallet } from "ethers";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { Deployer } from "../src.ts/deploy";
import { initializeErc20Bridge } from "../src.ts/erc20-initialize";
import { deployedAddressesFromEnv, web3Provider } from "./utils";
import { GAS_MULTIPLIER, deployedAddressesFromEnv, web3Provider } from "./utils";

import * as fs from "fs";
import * as path from "path";
Expand Down Expand Up @@ -33,7 +33,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/initialize-governance-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "commander";
import { ethers, Wallet } from "ethers";
import { Deployer } from "../src.ts/deploy";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { web3Provider } from "./utils";
import { GAS_MULTIPLIER, web3Provider } from "./utils";

import * as fs from "fs";
import * as path from "path";
Expand All @@ -29,7 +29,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const ownerAddress = cmd.ownerAddress ? cmd.ownerAddress : deployWallet.address;
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/initialize-governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "commander";
import { Wallet } from "ethers";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { Deployer } from "../src.ts/deploy";
import { deployedAddressesFromEnv, web3Provider } from "./utils";
import { GAS_MULTIPLIER, deployedAddressesFromEnv, web3Provider } from "./utils";

import * as fs from "fs";
import * as path from "path";
Expand All @@ -29,7 +29,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const ownerAddress = cmd.ownerAddress ? cmd.ownerAddress : deployWallet.address;
Expand Down
6 changes: 3 additions & 3 deletions l1-contracts/scripts/initialize-l2-weth-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "commander";
import { ethers, Wallet } from "ethers";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { Deployer } from "../src.ts/deploy";
import { getNumberFromEnv, getTokens, SYSTEM_CONFIG, web3Provider } from "./utils";
import { GAS_MULTIPLIER, getNumberFromEnv, getTokens, SYSTEM_CONFIG, web3Provider } from "./utils";

import * as fs from "fs";
import * as path from "path";
Expand Down Expand Up @@ -106,7 +106,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const deployer = new Deployer({
Expand Down Expand Up @@ -148,7 +148,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/initialize-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Command } from "commander";
import { Wallet } from "ethers";
import { Deployer } from "../src.ts/deploy";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { web3Provider } from "./utils";
import { GAS_MULTIPLIER, web3Provider } from "./utils";

import * as fs from "fs";
import * as path from "path";
Expand All @@ -28,7 +28,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/initialize-weth-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Wallet } from "ethers";
import { formatUnits, parseUnits } from "ethers/lib/utils";
import { Deployer } from "../src.ts/deploy";
import { initializeWethBridge } from "../src.ts/weth-initialize";
import { deployedAddressesFromEnv, web3Provider } from "./utils";
import { GAS_MULTIPLIER, deployedAddressesFromEnv, web3Provider } from "./utils";

import * as fs from "fs";
import * as path from "path";
Expand Down Expand Up @@ -32,7 +32,7 @@ async function main() {
).connect(provider);
console.log(`Using deployer wallet: ${deployWallet.address}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/migrate-governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as fs from "fs";
import * as hre from "hardhat";
import { Deployer } from "../src.ts/deploy";
import { applyL1ToL2Alias } from "../src.ts/utils";
import { getAddressFromEnv, getNumberFromEnv, web3Provider } from "./utils";
import { GAS_MULTIPLIER, getAddressFromEnv, getNumberFromEnv, web3Provider } from "./utils";

import { getL1TxInfo } from "../../l2-contracts/src/utils";

Expand Down Expand Up @@ -50,7 +50,7 @@ async function main() {
.option("--gas-price <gas-price>")
.option("--refund-recipient <refund-recipient>")
.action(async (cmd) => {
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const refundRecipient = cmd.refundRecipient;
Expand Down
4 changes: 2 additions & 2 deletions l1-contracts/scripts/register-hyperchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { formatUnits, parseUnits } from "ethers/lib/utils";
import * as fs from "fs";
import * as path from "path";
import { Deployer } from "../src.ts/deploy";
import { ADDRESS_ONE, getTokens, web3Provider } from "./utils";
import {GAS_MULTIPLIER, ADDRESS_ONE, getTokens, web3Provider } from "./utils";

const provider = web3Provider();
const testConfigPath = path.join(process.env.ZKSYNC_HOME as string, "etc/test_config/constant");
Expand Down Expand Up @@ -38,7 +38,7 @@ async function main() {
const ownerAddress = cmd.governorAddress || deployWallet.address;
console.log(`Using governor address: ${ownerAddress}`);

const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : await provider.getGasPrice();
const gasPrice = cmd.gasPrice ? parseUnits(cmd.gasPrice, "gwei") : (await provider.getGasPrice()).mul(GAS_MULTIPLIER);
console.log(`Using gas price: ${formatUnits(gasPrice, "gwei")} gwei`);

const nonce = cmd.nonce ? parseInt(cmd.nonce) : await deployWallet.getTransactionCount();
Expand Down
Loading

0 comments on commit 4dfd153

Please sign in to comment.