-
Notifications
You must be signed in to change notification settings - Fork 19
/
ERC20MintableBurnable.sol
100 lines (89 loc) · 3.97 KB
/
ERC20MintableBurnable.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.9;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
/// @title A contract for an mintable and burnable ERC20 that is handled by the bridge Cosmos SDK module account
/// @author Kava Labs, LLC
/// @custom:security-contact [email protected]
contract ERC20MintableBurnable is ERC20, Ownable {
/// @notice The decimals places of the token.
uint8 private immutable _decimals;
/// @notice Represents an ERC20 token lock emitted during a lock call
/// @param sender The Kava address of the sender that locked the funds
/// @param toAddr The Ethereum address to send the funds to
/// @param amount The amount that was locked
event Withdraw(
address indexed sender,
address indexed toAddr,
uint256 amount
);
/// @notice Represents a conversion from ERC20 to sdk.Coin
/// @param sender The Kava address of the sender that converted coins
/// @param toKavaAddr The Kava address where to send the converted coins to
/// @param amount The amount that was converted
event ConvertToCoin(
address indexed sender,
address indexed toKavaAddr,
uint256 amount
);
/// @notice Registers the ERC20 token with mint and burn permissions for the
/// contract owner, by default the account that deploys this contract.
/// @param name The name of the ERC20 token.
/// @param symbol The symbol of the ERC20 token.
/// @param decimals_ The number of decimals of the ERC20 token.
constructor(
string memory name,
string memory symbol,
uint8 decimals_
) ERC20(name, symbol) {
_decimals = decimals_;
}
/// @notice Creates more supply for a given account and amount by contract owner.
/// @param to The account to send the minted supply to.
/// @param amount The amount of the token to mint.
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
function decimals() public view override returns (uint8) {
return _decimals;
}
/// @notice Withdraws `amount` of tokens to Ethereum from the caller.
/// @dev Destroys `amount` tokens from the caller and emits a withdraw
/// event for the relayer to unlock funds on Ethereum.
/// @param toAddr The account on Ethereum to withdraw the funds to.
/// @param amount The amount of the token to withdraw.
function withdraw(address toAddr, uint256 amount) public virtual {
_burn(msg.sender, amount);
emit Withdraw(msg.sender, toAddr, amount);
}
/// @notice Withdraws `amount` of tokens to Ethereum from `account`.
/// @dev Destroys `amount` tokens from the caller, deducts from the caller's
/// allowance, and emits a withdraw event for the relayer to unlock
/// funds on Ethereum.
///
/// See {ERC20-_burn} and {ERC20-allowance}.
///
/// Requirements:
/// - the caller must have allowance for ``accounts``'s tokens of at
/// least `amount`.
/// @param toAddr The account on Ethereum to withdraw the funds to.
/// @param amount The amount of the token to withdraw.
function withdrawFrom(
address account,
address toAddr,
uint256 amount
) public virtual {
_spendAllowance(account, msg.sender, amount);
_burn(account, amount);
emit Withdraw(msg.sender, toAddr, amount);
}
/// @notice Converts an amount of tokens to Cosmos sdk.Coin
/// @dev Transfers amount of tokens to the owner address (module account)
/// and emits a ConvertToCoin event.
/// @param toKavaAddr The Kava address where to send the converted coins to.
/// @param amount The amount of the token to convert.
function convertToCoin(address toKavaAddr, uint256 amount) public virtual {
_transfer(msg.sender, owner(), amount);
emit ConvertToCoin(msg.sender, toKavaAddr, amount);
}
}