Skip to content

Commit 9be32eb

Browse files
authored
chore(protocol-contracts): add decimals to mock ERC20 for registry tasks (#1642)
1 parent a5a98e3 commit 9be32eb

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

protocol-contracts/confidential-token-wrappers-registry/contracts/mocks/ERC20Mock.sol

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ pragma solidity ^0.8.20;
44
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
55

66
contract ERC20Mock is ERC20 {
7+
uint8 private immutable _decimals;
8+
79
error MintAmountExceedsMax(uint256 amount, uint256 maxAmount);
810

9-
uint256 public constant MAX_MINT_AMOUNT = 1_000_000 * 10 ** 18;
11+
uint256 public constant MAX_MINT_AMOUNT_TOKENS = 1_000_000;
1012

11-
constructor(string memory name_, string memory symbol_) ERC20(name_, symbol_) {}
13+
constructor(string memory name_, string memory symbol_, uint8 decimals_) ERC20(name_, symbol_) {
14+
_decimals = decimals_;
15+
}
1216

1317
function mint(address to, uint256 amount) external {
14-
if (amount > MAX_MINT_AMOUNT) {
15-
revert MintAmountExceedsMax(amount, MAX_MINT_AMOUNT);
18+
uint256 maxMintAmount = MAX_MINT_AMOUNT_TOKENS * 10 ** decimals();
19+
if (amount > maxMintAmount) {
20+
revert MintAmountExceedsMax(amount, maxMintAmount);
1621
}
1722
_mint(to, amount);
1823
}
24+
25+
function decimals() public view virtual override returns (uint8) {
26+
return _decimals;
27+
}
1928
}

protocol-contracts/confidential-token-wrappers-registry/tasks/mocks/deployMocks.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { task } from 'hardhat/config';
1+
import { task, types } from 'hardhat/config';
22
import { HardhatRuntimeEnvironment } from 'hardhat/types';
33

44
const ERC20_MOCK_CONTRACT_NAME = 'ERC20Mock';
55

66
// Deploy the ERC20Mock contract
7-
async function deployERC20Mock(hre: HardhatRuntimeEnvironment, name: string, symbol: string) {
7+
async function deployERC20Mock(hre: HardhatRuntimeEnvironment, name: string, symbol: string, decimals: number) {
88
const { getNamedAccounts, ethers, deployments, network } = hre;
99
const { save, getArtifact } = deployments;
1010

1111
const { deployer } = await getNamedAccounts();
1212
const deployerSigner = await ethers.getSigner(deployer);
1313

1414
const factory = await ethers.getContractFactory(ERC20_MOCK_CONTRACT_NAME, deployerSigner);
15-
const contract = await factory.deploy(name, symbol);
15+
const contract = await factory.deploy(name, symbol, decimals);
1616
await contract.waitForDeployment();
1717

1818
const contractAddress = await contract.getAddress();
@@ -40,14 +40,15 @@ async function deployERC20Mock(hre: HardhatRuntimeEnvironment, name: string, sym
4040

4141
// Deploy the ERC20Mock contract
4242
// Example usage:
43-
// npx hardhat task:deployERC20Mock --name "Mock Token" --symbol "MTK" --network testnet
43+
// npx hardhat task:deployERC20Mock --name "Mock Token" --symbol "MTK" --decimals 18 --network testnet
4444
task('task:deployERC20Mock')
4545
.addParam('name', 'The name of the ERC20 token')
4646
.addParam('symbol', 'The symbol of the ERC20 token')
47-
.setAction(async function ({ name, symbol }, hre) {
47+
.addParam('decimals', 'The decimals of the ERC20 token', 18, types.int)
48+
.setAction(async function ({ name, symbol, decimals }, hre) {
4849
console.log('Deploying ERC20Mock contract...\n');
4950

50-
await deployERC20Mock(hre, name, symbol);
51+
await deployERC20Mock(hre, name, symbol, parseInt(decimals));
5152

5253
console.log('✅ ERC20Mock contract deployed\n');
5354
});

0 commit comments

Comments
 (0)