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

Improvement of script #228

Merged
merged 4 commits into from
Feb 12, 2024
Merged
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
53 changes: 53 additions & 0 deletions src/scripts/activateForcedTransactions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable import/no-dynamic-require, global-require */
/* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved, no-restricted-syntax */
const path = require('path');
const { ethers } = require('hardhat');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const common = require('../common/common');

async function main() {
/*
* Check deploy parameters
* Check that every necessary parameter is fullfilled
*/
const args = process.argv.slice(2);
const deploymentName = args[0];
const deployParameters = require(`../../deployments/${deploymentName}/deploy_parameters.json`);
const deploymentOutput = require(`../../deployments/${deploymentName}/deploy_output.json`);

const mandatoryDeploymentOutput = [
'polygonZkEVMAddress',
'deployerAddress',
];
for (const parameterName of mandatoryDeploymentOutput) {
if (deploymentOutput[parameterName] === undefined || deploymentOutput[parameterName] === '') {
throw new Error(`Missing parameter: ${parameterName}`);
}
}
const {
polygonZkEVMAddress,
deployerAddress,
} = deploymentOutput;

const currentProvider = await common.loadProvider(deployParameters, process.env);
const deployer = await common.loadDeployer(currentProvider, deployParameters);

if (deployerAddress === undefined || deployerAddress.toLowerCase() !== deployer.address.toLowerCase()) {
throw new Error('Wrong deployer address');
}

const zkevm = (await ethers.getContractAt(
'contracts/ForkableZkEVM.sol:ForkableZkEVM',
polygonZkEVMAddress,
)).connect(deployer);

const tx0 = await zkevm.connect(deployer).activateForceBatches({ gasLimit: 500000 });
await tx0.wait();
console.log('Activate forced batches');
console.log('by the following tx: ', tx0.hash);
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
7 changes: 4 additions & 3 deletions src/scripts/depositForkonomicTokenIntoBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ async function main() {
);

const depositAmount = ethers.utils.parseEther('10');
const tx0 = await forkonomicToken.connect(deployer).mint(polygonZkEVMBridgeAddress, ethers.utils.parseEther('100000'), { gasLimit: 500000 });
console.log('Mint forkonomic tokens');
console.log('by the following tx: ', tx0.hash);
const balance = await forkonomicToken.connect(deployer).balanceOf(deployer.address);
if (balance.lt(depositAmount)) {
throw new Error('Not enough tokens');
}

const tx1 = await forkonomicToken.connect(deployer).approve(polygonZkEVMBridgeAddress, depositAmount, { gasLimit: 500000 });
console.log('Approved bridge to spend forkonomic tokens');
Expand Down
61 changes: 61 additions & 0 deletions src/scripts/mintForkonomicTokens.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/* eslint-disable import/no-dynamic-require, global-require */
/* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved, no-restricted-syntax */
const path = require('path');
const { ethers } = require('hardhat');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const common = require('../common/common');

async function main() {
/*
* Check deploy parameters
* Check that every necessary parameter is fullfilled
*/
const args = process.argv.slice(2);
const deploymentName = args[0];
const deployParameters = require(`../../deployments/${deploymentName}/deploy_parameters.json`);
const deploymentOutput = require(`../../deployments/${deploymentName}/deploy_output.json`);

const mandatoryDeploymentOutput = [
'maticTokenAddress',
'trustedSequencer',
'deployerAddress',
];
for (const parameterName of mandatoryDeploymentOutput) {
if (deploymentOutput[parameterName] === undefined || deploymentOutput[parameterName] === '') {
throw new Error(`Missing parameter: ${parameterName}`);
}
}
const {
maticTokenAddress,
trustedSequencer,
deployerAddress,
} = deploymentOutput;

const forkonomicTokenAddress = maticTokenAddress;
const currentProvider = await common.loadProvider(deployParameters, process.env);
const deployer = await common.loadDeployer(currentProvider, deployParameters);

if (deployerAddress === undefined || deployerAddress.toLowerCase() !== deployer.address.toLowerCase()) {
throw new Error('Wrong deployer address');
}

const forkonomicToken = (await ethers.getContractAt(
'contracts/ForkonomicToken.sol:ForkonomicToken',
forkonomicTokenAddress,
)).connect(deployer);

const tx0 = await forkonomicToken.connect(deployer).mint(deployer.address, ethers.utils.parseEther('100000'), { gasLimit: 500000 });
await tx0.wait();
console.log('Mint forkonomic tokens for deployer');
console.log('by the following tx: ', tx0.hash);

const tx1 = await forkonomicToken.connect(deployer).mint(trustedSequencer, ethers.utils.parseEther('100000'), { gasLimit: 500000 });
await tx1.wait();
console.log('Mint forkonomic tokens for trusted sequencer');
console.log('by the following tx: ', tx1.hash);
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
57 changes: 57 additions & 0 deletions src/scripts/prepareSequencer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* eslint-disable no-await-in-loop, no-use-before-define, no-lonely-if, import/no-dynamic-require, global-require */
/* eslint-disable no-console, no-inner-declarations, no-undef, import/no-unresolved, no-restricted-syntax */
const path = require('path');
const { ethers } = require('hardhat');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const common = require('../common/common');

async function main() {
/*
* Check deploy parameters
* Check that every necessary parameter is fullfilled
*/
const args = process.argv.slice(2);
const deploymentName = args[0];
const deployParameters = require(`../../deployments/${deploymentName}/deploy_parameters.json`);
const deploymentOutput = require(`../../deployments/${deploymentName}/deploy_output.json`);

const mandatoryDeploymentOutput = [
'polygonZkEVMAddress',
'maticTokenAddress',
'trustedSequencer',
];
for (const parameterName of mandatoryDeploymentOutput) {
if (deploymentOutput[parameterName] === undefined || deploymentOutput[parameterName] === '') {
throw new Error(`Missing parameter: ${parameterName}`);
}
}
const {
polygonZkEVMAddress,
maticTokenAddress,
trustedSequencer,
} = deploymentOutput;

const forkonomicTokenAddress = maticTokenAddress;
const currentProvider = await common.loadProvider(deployParameters, process.env);
const deployer = await common.loadDeployer(currentProvider, deployParameters);

if (trustedSequencer === undefined || trustedSequencer.toLowerCase() !== deployer.address.toLowerCase()) {
throw new Error('Wrong deployer address');
}
console.log('polygonZkEVMAddress: ', polygonZkEVMAddress);

const forkonomicToken = (await ethers.getContractAt(
'contracts/ForkonomicToken.sol:ForkonomicToken',
forkonomicTokenAddress,
)).connect(deployer);

const tx1 = await forkonomicToken.approve(polygonZkEVMAddress, ethers.constants.MaxUint256, { gasLimit: 500000 });
await tx1.wait();
console.log('Approved zkevm by the sequencer to spend forkonomic tokens');
console.log('by the following tx: ', tx1.hash);
}

main().catch((e) => {
console.error(e);
process.exit(1);
});
Loading