Skip to content

Commit

Permalink
improve desposit script
Browse files Browse the repository at this point in the history
  • Loading branch information
josojo committed Feb 9, 2024
1 parent eabaf55 commit edcf648
Showing 1 changed file with 9 additions and 39 deletions.
48 changes: 9 additions & 39 deletions src/scripts/depositForkonomicTokenIntoBridge.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const path = require('path');
const { ethers } = require('hardhat');
require('dotenv').config({ path: path.resolve(__dirname, '../.env') });
const common = require('../common/common');

async function main() {
/*
Expand Down Expand Up @@ -35,45 +36,8 @@ async function main() {
const forkonomicTokenAddress = maticTokenAddress;

// Load provider
let currentProvider = ethers.provider;
if (deployParameters.multiplierGas || deployParameters.maxFeePerGas) {
if (process.env.HARDHAT_NETWORK !== 'hardhat') {
currentProvider = new ethers.providers.JsonRpcProvider(`https://${process.env.HARDHAT_NETWORK}.infura.io/v3/${process.env.INFURA_PROJECT_ID}`);
if (deployParameters.maxPriorityFeePerGas && deployParameters.maxFeePerGas) {
console.log(`Hardcoded gas used: MaxPriority${deployParameters.maxPriorityFeePerGas} gwei, MaxFee${deployParameters.maxFeePerGas} gwei`);
const FEE_DATA = {
maxFeePerGas: ethers.utils.parseUnits(deployParameters.maxFeePerGas, 'gwei'),
maxPriorityFeePerGas: ethers.utils.parseUnits(deployParameters.maxPriorityFeePerGas, 'gwei'),
};
currentProvider.getFeeData = async () => FEE_DATA;
} else {
console.log('Multiplier gas used: ', deployParameters.multiplierGas);
async function overrideFeeData() {
const feedata = await ethers.provider.getFeeData();
return {
maxFeePerGas: feedata.maxFeePerGas.mul(deployParameters.multiplierGas).div(1000),
maxPriorityFeePerGas: feedata.maxPriorityFeePerGas.mul(deployParameters.multiplierGas).div(1000),
};
}
currentProvider.getFeeData = overrideFeeData;
}
}
}

// Load deployer
let deployer;
if (deployParameters.deployerPvtKey) {
deployer = new ethers.Wallet(deployParameters.deployerPvtKey, currentProvider);
console.log('Using pvtKey deployer with address: ', deployer.address);
} else if (process.env.PK) {
deployer = new ethers.Wallet(process.env.PK, currentProvider);
console.log('Using PK deployer with address: ', deployer.address);
} else if (process.env.MNEMONIC) {
deployer = ethers.Wallet.fromMnemonic(process.env.MNEMONIC, 'm/44\'/60\'/0\'/0/0').connect(currentProvider);
console.log('Using MNEMONIC deployer with address: ', deployer.address);
} else {
[deployer] = (await ethers.getSigners());
}
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');
Expand All @@ -88,7 +52,13 @@ async function main() {
'contracts/ForkonomicToken.sol:ForkonomicToken',
forkonomicTokenAddress,
);
console.log('ForkonomicToken address: ', forkonomicToken.address);
console.log('ForkonomicToken owner: ', deployer.address);
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 tx1 = await forkonomicToken.connect(deployer).approve(polygonZkEVMBridgeAddress, depositAmount, { gasLimit: 500000 });
console.log('Approved bridge to spend forkonomic tokens');
console.log('by the following tx: ', tx1.hash);
Expand Down

0 comments on commit edcf648

Please sign in to comment.