-
Notifications
You must be signed in to change notification settings - Fork 22
/
ERC20WithData.sol
70 lines (62 loc) · 2.36 KB
/
ERC20WithData.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.0;
import '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import '@openzeppelin/contracts/utils/introspection/ERC165.sol';
import '@openzeppelin/contracts/utils/Context.sol';
import '@openzeppelin/contracts/access/Ownable.sol';
import './IERC20WithData.sol';
/**
* Example ERC20 token with mint, burn, and attached data support.
*
* This contract demonstrates a very simple ERC20 fungible token. Notes on functionality:
* - the contract owner (ie deployer) is the only party allowed to mint
* - any party can approve another party to manage (ie transfer) a certain amount of their
* tokens (approving for MAX_INT gives an unlimited approval)
* - any party can burn their own tokens
* - decimals hard-coded to 18 (so 1 token is expressed as 1000000000000000000)
*
* The inclusion of a "data" argument on each external method allows FireFly to write
* extra data to the chain alongside each token transaction, in order to correlate it with
* other on- and off-chain events.
*
* This is a sample only and NOT a reference implementation.
*/
contract ERC20WithData is Context, Ownable, ERC165, ERC20, IERC20WithData {
constructor(string memory name, string memory symbol) ERC20(name, symbol) Ownable(msg.sender) {}
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC20WithData).interfaceId || super.supportsInterface(interfaceId);
}
function mintWithData(
address to,
uint256 amount,
bytes calldata data
) public virtual onlyOwner {
_mint(to, amount);
}
function transferWithData(
address from,
address to,
uint256 amount,
bytes calldata data
) public virtual {
if (from == _msgSender()) {
transfer(to, amount);
} else {
transferFrom(from, to, amount);
}
}
function burnWithData(address from, uint256 amount, bytes calldata data) public virtual {
require(from == _msgSender(), 'ERC20WithData: caller is not owner');
_burn(from, amount);
}
function approveWithData(
address spender,
uint256 amount,
bytes calldata data
) public virtual returns (bool) {
return approve(spender, amount);
}
}