Skip to content

Commit

Permalink
helper script for testing the bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
josojo committed Aug 16, 2023
1 parent 31946c9 commit 41a79ae
Showing 1 changed file with 113 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/scripts/depositForkonomicTokenIntoBridge.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* 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 deployParameters = require('../../deployment/deploy_parameters.json');
const deploymentOutput = require('../../deployment/deploy_output.json');

async function main() {
/*
* Check deploy parameters
* Check that every necessary parameter is fullfilled
*/
const mandatoryDeploymentParameters = [
'maticTokenAddress',
'createChildrenImplementationAddress',
];

for (const parameterName of mandatoryDeploymentParameters) {
if (deployParameters[parameterName] === undefined || deployParameters[parameterName] === '') {
throw new Error(`Missing parameter: ${parameterName}`);
}
}

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

const {
maticTokenAddress,
} = deployParameters;
const {
polygonZkEVMBridgeAddress,
} = deploymentOutput;

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.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());
}
console.log('using deployer: ', deployer.address);

const bridge = await hre.ethers.getContractAt(
'ForkableBridge',
polygonZkEVMBridgeAddress,
);

const forkonomicToken = await hre.ethers.getContractAt(
'ForkonomicToken',
forkonomicTokenAddress,
);

const depositAmount = ethers.utils.parseEther('10');
await forkonomicToken.approve(polygonZkEVMBridgeAddress, depositAmount);
console.log('Approved bridge to spend forkonomic tokens');

await bridge.bridgeAsset(
1,
deployer.address,
depositAmount,
forkonomicTokenAddress,
true,
'0x',
{ gasLimit: 5000000 },
);
console.log('Deposited forkonomic tokens into bridge');
}

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

0 comments on commit 41a79ae

Please sign in to comment.