-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
helper script for testing the bridge
- Loading branch information
Showing
1 changed file
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
|