From d97adb077d5ddb38fe059212bed4ecca4ec99745 Mon Sep 17 00:00:00 2001 From: Uladzislau Hubar Date: Sat, 25 Nov 2023 18:34:09 +0100 Subject: [PATCH] Added task for test tokens minting --- hardhat.config.ts | 1 + scripts/mint_test_tokens.ts | 2 +- tasks/mint_test_tokens.ts | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 tasks/mint_test_tokens.ts diff --git a/hardhat.config.ts b/hardhat.config.ts index 8b111af2..fbbefcb7 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -16,6 +16,7 @@ import { HardhatRuntimeEnvironment } from 'hardhat/types'; import './tasks/address_converter'; import './tasks/deploy_test_token'; import './tasks/low_level_call_data_encoder'; +import './tasks/mint_test_tokens'; import './tasks/selector_encoder'; import './tasks/send_otp'; import './utils/type-extensions'; diff --git a/scripts/mint_test_tokens.ts b/scripts/mint_test_tokens.ts index 834b5648..87f3ba8c 100644 --- a/scripts/mint_test_tokens.ts +++ b/scripts/mint_test_tokens.ts @@ -4,7 +4,7 @@ async function main() { const accounts = await hre.ethers.getSigners(); const { minter } = await hre.getNamedAccounts(); - const tokenContract = await hre.ethers.getContract('ERC20Token'); + const tokenContract = await hre.ethers.getContract('Token'); const amountToMint = hre.ethers.utils.parseEther(`${5_000_000}`); for (const acc of accounts) { diff --git a/tasks/mint_test_tokens.ts b/tasks/mint_test_tokens.ts new file mode 100644 index 00000000..ff14bef7 --- /dev/null +++ b/tasks/mint_test_tokens.ts @@ -0,0 +1,39 @@ +import { task } from 'hardhat/config'; +import { HardhatRuntimeEnvironment } from 'hardhat/types'; + +type TestTokenDeploymentParameters = { + tokenAddress: string; + receiver: string; + amount: string; +}; + +task('mint_test_tokens', 'Mint Test Trace Tokens') + .addParam('tokenAddress', 'Token Address') + .addParam('receiver', 'Receiver Address') + .addParam('amount', 'Amount of tokens to mint') + .setAction(async (taskArgs: TestTokenDeploymentParameters, hre: HardhatRuntimeEnvironment) => { + const { tokenAddress, receiver, amount } = taskArgs; + const { minter } = await hre.getNamedAccounts(); + + const Token = await hre.ethers.getContractAt('Token', tokenAddress); + + const minterRole = await Token.MINTER_ROLE(); + if (!(await Token.hasRole(minterRole, minter))) { + console.log(`Setting minter role for ${minter}.`); + const setupMinterTx = await Token.setupRole(minter); + await setupMinterTx.wait(); + } + + const amountToMint = hre.ethers.utils.parseEther(amount); + + const mintTx = await Token.mint(receiver, amountToMint, { from: minter }); + await mintTx.wait(); + + const tokenSymbol = await Token.symbol(); + + console.log( + `${amountToMint.toString()} $${tokenSymbol} has been minted to ${tokenAddress} on the ${ + hre.network.name + } blockchain!`, + ); + });