Skip to content

Commit

Permalink
Added task for test tokens minting
Browse files Browse the repository at this point in the history
  • Loading branch information
u-hubar committed Nov 25, 2023
1 parent 8118344 commit d97adb0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion scripts/mint_test_tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
39 changes: 39 additions & 0 deletions tasks/mint_test_tokens.ts
Original file line number Diff line number Diff line change
@@ -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<string>('tokenAddress', 'Token Address')
.addParam<string>('receiver', 'Receiver Address')
.addParam<string>('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!`,
);
});

0 comments on commit d97adb0

Please sign in to comment.