2021-08-13 09:53:42 +00:00
|
|
|
// Original: https://github.com/Uniswap/uniswap-v3-core/blob/main/contracts/test/TestERC20.sol
|
|
|
|
// Copyright 2021 Uniswap Labs
|
|
|
|
// LICENSE: https://github.com/Uniswap/uniswap-v3-core/blob/main/LICENSE
|
|
|
|
|
2021-07-30 14:20:56 +00:00
|
|
|
pragma solidity =0.7.6;
|
|
|
|
|
|
|
|
import '@uniswap/v3-core/contracts/interfaces/IERC20Minimal.sol';
|
|
|
|
|
|
|
|
contract TestERC20 is IERC20Minimal {
|
|
|
|
mapping(address => uint256) public override balanceOf;
|
|
|
|
mapping(address => mapping(address => uint256)) public override allowance;
|
|
|
|
|
|
|
|
constructor(uint256 amountToMint) {
|
|
|
|
mint(msg.sender, amountToMint);
|
|
|
|
}
|
|
|
|
|
|
|
|
function mint(address to, uint256 amount) public {
|
|
|
|
uint256 balanceNext = balanceOf[to] + amount;
|
|
|
|
require(balanceNext >= amount, 'overflow balance');
|
|
|
|
balanceOf[to] = balanceNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
function transfer(address recipient, uint256 amount) external override returns (bool) {
|
|
|
|
uint256 balanceBefore = balanceOf[msg.sender];
|
|
|
|
require(balanceBefore >= amount, 'insufficient balance');
|
|
|
|
balanceOf[msg.sender] = balanceBefore - amount;
|
|
|
|
|
|
|
|
uint256 balanceRecipient = balanceOf[recipient];
|
|
|
|
require(balanceRecipient + amount >= balanceRecipient, 'recipient balance overflow');
|
|
|
|
balanceOf[recipient] = balanceRecipient + amount;
|
|
|
|
|
|
|
|
emit Transfer(msg.sender, recipient, amount);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function approve(address spender, uint256 amount) external override returns (bool) {
|
|
|
|
allowance[msg.sender][spender] = amount;
|
|
|
|
emit Approval(msg.sender, spender, amount);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function transferFrom(
|
|
|
|
address sender,
|
|
|
|
address recipient,
|
|
|
|
uint256 amount
|
|
|
|
) external override returns (bool) {
|
|
|
|
uint256 allowanceBefore = allowance[sender][msg.sender];
|
|
|
|
|
|
|
|
require(allowanceBefore >= amount, 'allowance insufficient');
|
|
|
|
|
|
|
|
allowance[sender][msg.sender] = allowanceBefore - amount;
|
|
|
|
|
|
|
|
uint256 balanceRecipient = balanceOf[recipient];
|
|
|
|
require(balanceRecipient + amount >= balanceRecipient, 'overflow balance recipient');
|
|
|
|
balanceOf[recipient] = balanceRecipient + amount;
|
|
|
|
uint256 balanceSender = balanceOf[sender];
|
|
|
|
require(balanceSender >= amount, 'underflow balance sender');
|
|
|
|
balanceOf[sender] = balanceSender - amount;
|
|
|
|
|
|
|
|
emit Transfer(sender, recipient, amount);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|