-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathERC777Token.sol
59 lines (42 loc) · 1.75 KB
/
ERC777Token.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC777/ERC777.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
contract ERC777Token is ERC777, Ownable {
uint256 constant public maxSupply = 1000000000000000000000000000; // 1 thousand millions of tokens
uint256 constant public preAssigned = 300000000000000000000000000; // 300 hundred millions of tokens
event TokensWrapped(
address indexed sender,
uint amount
);
event TokensUnwrapped(
address indexed sender,
uint amount
);
IERC20 public tokenAddress;
constructor (IERC20 _tokenAddress) ERC777("ERC777Token", "777", new address[](0)) {
tokenAddress = _tokenAddress;
_mint(msg.sender, preAssigned, "", "");
}
function wrapToken(uint amount) external {
IERC20 token = tokenAddress;
require(address(token) != address(0), "Token address not set");
address sender = msg.sender;
token.transferFrom(sender, address(this), amount);
_mint(sender, amount, "", "");
emit TokensWrapped(sender, amount);
}
function unwrapToken(uint amount) external {
require(address(tokenAddress) != address(0), "Token address not set");
address sender = msg.sender;
burn(amount, "");
(bool success, ) = address(tokenAddress).call(abi.encodeWithSignature("transfer(address,uint256)", sender, amount));
require(success);
emit TokensUnwrapped(sender, amount);
}
function setToken(IERC20 newToken) external onlyOwner {
require(address(newToken) != address(0), "Address cannot be 0");
tokenAddress = IERC20(newToken);
}
}