Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion contracts/base/ERC20Base.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import "../openzeppelin-presets/token/ERC20/extensions/ERC20Permit.sol";
import "../extension/ContractMetadata.sol";
import "../extension/Multicall.sol";
import "../extension/Ownable.sol";
import "../extension/interface/IMintableERC20.sol";
import "../extension/interface/IBurnableERC20.sol";

/**
* The `ERC20Base` smart contract implements the ERC20 standard.
Expand All @@ -24,7 +26,7 @@ import "../extension/Ownable.sol";
* presenting a message signed by the account.
*/

contract ERC20Base is ContractMetadata, Multicall, Ownable, ERC20Permit {
contract ERC20Base is ContractMetadata, Multicall, Ownable, ERC20Permit, IMintableERC20, IBurnableERC20 {
/*//////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -62,6 +64,22 @@ contract ERC20Base is ContractMetadata, Multicall, Ownable, ERC20Permit {
_burn(msg.sender, _amount);
}

/**
* @notice Lets an owner burn a given amount of an account's tokens.
* @dev `_account` should own the `_amount` of tokens.
*
* @param _account The account to burn tokens from.
* @param _amount The number of tokens to burn.
*/
function burnFrom(address _account, uint256 _amount) external virtual override {
require(_canBurn(), "Not authorized to burn.");
require(balanceOf(_account) >= _amount, "not enough balance");
uint256 decreasedAllowance = allowance(_account, msg.sender) - _amount;
_approve(_account, msg.sender, 0);
_approve(_account, msg.sender, decreasedAllowance);
_burn(_account, _amount);
}

/*//////////////////////////////////////////////////////////////
Internal (overrideable) functions
//////////////////////////////////////////////////////////////*/
Expand All @@ -76,6 +94,11 @@ contract ERC20Base is ContractMetadata, Multicall, Ownable, ERC20Permit {
return msg.sender == owner();
}

/// @dev Returns whether tokens can be burned in the given execution context.
function _canBurn() internal view virtual returns (bool) {
return msg.sender == owner();
}

/// @dev Returns whether owner can be set in the given execution context.
function _canSetOwner() internal view virtual override returns (bool) {
return msg.sender == owner();
Expand Down
24 changes: 23 additions & 1 deletion contracts/base/ERC20Drop.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "../extension/Multicall.sol";
import "../extension/Ownable.sol";
import "../extension/PrimarySale.sol";
import "../extension/DropSinglePhase.sol";
import "../extension/interface/IBurnableERC20.sol";

import "../lib/CurrencyTransferLib.sol";

Expand All @@ -33,7 +34,7 @@ import "../lib/CurrencyTransferLib.sol";
*
*/

contract ERC20Drop is ContractMetadata, Multicall, Ownable, ERC20Permit, PrimarySale, DropSinglePhase {
contract ERC20Drop is ContractMetadata, Multicall, Ownable, ERC20Permit, PrimarySale, DropSinglePhase, IBurnableERC20 {
/*//////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -62,6 +63,22 @@ contract ERC20Drop is ContractMetadata, Multicall, Ownable, ERC20Permit, Primary
_burn(msg.sender, _amount);
}

/**
* @notice Lets an owner burn a given amount of an account's tokens.
* @dev `_account` should own the `_amount` of tokens.
*
* @param _account The account to burn tokens from.
* @param _amount The number of tokens to burn.
*/
function burnFrom(address _account, uint256 _amount) external virtual override {
require(_canBurn(), "Not authorized to burn.");
require(balanceOf(_account) >= _amount, "not enough balance");
uint256 decreasedAllowance = allowance(_account, msg.sender) - _amount;
_approve(_account, msg.sender, 0);
_approve(_account, msg.sender, decreasedAllowance);
_burn(_account, _amount);
}

/*//////////////////////////////////////////////////////////////
Internal (overrideable) functions
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -114,6 +131,11 @@ contract ERC20Drop is ContractMetadata, Multicall, Ownable, ERC20Permit, Primary
return msg.sender == owner();
}

/// @dev Returns whether tokens can be burned in the given execution context.
function _canBurn() internal view virtual returns (bool) {
return msg.sender == owner();
}

/// @dev Returns whether owner can be set in the given execution context.
function _canSetOwner() internal view virtual override returns (bool) {
return msg.sender == owner();
Expand Down
25 changes: 24 additions & 1 deletion contracts/base/ERC20Vote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pragma solidity ^0.8.0;
import "../openzeppelin-presets/token/ERC20/extensions/ERC20Votes.sol";

import "./ERC20Base.sol";
import "../extension/interface/IMintableERC20.sol";
import "../extension/interface/IBurnableERC20.sol";

/**
* The `ERC20Vote` smart contract implements the ERC20 standard and ERC20Votes.
Expand All @@ -24,7 +26,7 @@ import "./ERC20Base.sol";
* presenting a message signed by the account.
*/

contract ERC20Vote is ContractMetadata, Multicall, Ownable, ERC20Votes {
contract ERC20Vote is ContractMetadata, Multicall, Ownable, ERC20Votes, IMintableERC20, IBurnableERC20 {
/*//////////////////////////////////////////////////////////////
Constructor
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -62,6 +64,22 @@ contract ERC20Vote is ContractMetadata, Multicall, Ownable, ERC20Votes {
_burn(msg.sender, _amount);
}

/**
* @notice Lets an owner burn a given amount of an account's tokens.
* @dev `_account` should own the `_amount` of tokens.
*
* @param _account The account to burn tokens from.
* @param _amount The number of tokens to burn.
*/
function burnFrom(address _account, uint256 _amount) external virtual override {
require(_canBurn(), "Not authorized to burn.");
require(balanceOf(_account) >= _amount, "not enough balance");
uint256 decreasedAllowance = allowance(_account, msg.sender) - _amount;
_approve(_account, msg.sender, 0);
_approve(_account, msg.sender, decreasedAllowance);
_burn(_account, _amount);
}

/*//////////////////////////////////////////////////////////////
Internal (overrideable) functions
//////////////////////////////////////////////////////////////*/
Expand All @@ -76,6 +94,11 @@ contract ERC20Vote is ContractMetadata, Multicall, Ownable, ERC20Votes {
return msg.sender == owner();
}

/// @dev Returns whether tokens can be burned in the given execution context.
function _canBurn() internal view virtual returns (bool) {
return msg.sender == owner();
}

/// @dev Returns whether owner can be set in the given execution context.
function _canSetOwner() internal view virtual override returns (bool) {
return msg.sender == owner();
Expand Down