SKIP TO CONTENT

Demo build — mock protocol data. No chain, no ABIs yet.

  • SYNCING: ……

MockERC20.sol

Minimal ERC20 for tests.

60 lines1.9 KBSolidity
Source of test/mocks/MockERC20.sol, 60 lines of Solidity
1// SPDX-License-Identifier: MIT
2pragma solidity ^0.8.24;
3 
4/// @dev Minimal mintable ERC20 with configurable decimals. Stands in for USDG and for
5/// every tokenized equity (NVDA, AAPL, TSLA, ...) in the test suite.
6contract MockERC20 {
7 string public name;
8 string public symbol;
9 uint8 public immutable decimals;
10 
11 uint256 public totalSupply;
12 mapping(address => uint256) public balanceOf;
13 mapping(address => mapping(address => uint256)) public allowance;
14 
15 event Transfer(address indexed from, address indexed to, uint256 value);
16 event Approval(address indexed owner, address indexed spender, uint256 value);
17 
18 constructor(string memory n, string memory s, uint8 d) {
19 name = n;
20 symbol = s;
21 decimals = d;
22 }
23 
24 function mint(address to, uint256 amount) external {
25 totalSupply += amount;
26 balanceOf[to] += amount;
27 emit Transfer(address(0), to, amount);
28 }
29 
30 function burn(address from, uint256 amount) external {
31 balanceOf[from] -= amount;
32 totalSupply -= amount;
33 emit Transfer(from, address(0), amount);
34 }
35 
36 function approve(address spender, uint256 amount) external returns (bool) {
37 allowance[msg.sender][spender] = amount;
38 emit Approval(msg.sender, spender, amount);
39 return true;
40 }
41 
42 function transfer(address to, uint256 amount) public virtual returns (bool) {
43 _transfer(msg.sender, to, amount);
44 return true;
45 }
46 
47 function transferFrom(address from, address to, uint256 amount) external returns (bool) {
48 uint256 allowed = allowance[from][msg.sender];
49 if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
50 _transfer(from, to, amount);
51 return true;
52 }
53 
54 function _transfer(address from, address to, uint256 amount) internal {
55 balanceOf[from] -= amount;
56 balanceOf[to] += amount;
57 emit Transfer(from, to, amount);
58 }
59}
60 

Click any line number to deep-link to it — the target line highlights on load.