diff --git a/.github/.git_commit_template.txt b/.github/.git_commit_template.txt new file mode 100644 index 00000000..b939b207 --- /dev/null +++ b/.github/.git_commit_template.txt @@ -0,0 +1,29 @@ +Applying this commit will #Add your title here + +# ## Help ## +# +# Subject line imperative uppercase verbs: +# +# Add = Create a capability e.g. feature, test, dependency. +# Drop = Delete a capability e.g. feature, test, dependency. +# Fix = Fix an issue e.g. bug, typo, accident, misstatement. +# Bump = Increase the version of something e.g. a dependency. +# Make = Change the build process, or tools, or infrastructure. +# Start = Begin doing something; e.g. enable a toggle, feature flag, etc. +# Stop = End doing something; e.g. disable a toggle, feature flag, etc. +# Optimize = A change that MUST be just about performance, e.g. speed up code. +# Document = A change that MUST be only in the documentation, e.g. help files. +# Refactor = A change that MUST be just refactoring. +# Reformat = A change that MUST be just format, e.g. indent line, trim space, etc. +# Rephrase = A change that MUST be just textual, e.g. edit a comment, doc, etc. +# +# For the subject line: +# * Use 50 characters maximum. +# * Do not use a sentence-ending period. +# +# For the body text: +# * Use as many lines as you like. +# * Use 72 characters maximum per line for typical word wrap text. +# +# +# ## Write your list of changes after this line ## \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..6c2da5c4 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,25 @@ + + +## Description of Changes + + + +[Link to Jira Ticket](https://halodao.atlassian.net/browse/HDF-) + +## How To Test + +### Developer Checklist: + +- [x] I have followed the guidelines in our Contributing document +- [x] This PR has a corresponding JIRA ticket +- [x] My branch conforms with our naming convention i.e. `feature/HDF-XXX-description` +- [x] I have written new tests for your core changes, as applicable +- [x] I have successfully ran tests locally +- [x] I have formatted my code using format document in VSCode + +### Reviewers Checklist: + +- [ ] Code is readable and understandable; any unclear parts have explanations +- [ ] UI/UX changes match the corresponding figma/other design resources, if applicable +- [ ] I have successfully ran tests locally + diff --git a/contracts/incentives/RnbwDistributionManager.sol b/contracts/incentives/RnbwDistributionManager.sol index 9c674fdf..f50bd13a 100644 --- a/contracts/incentives/RnbwDistributionManager.sol +++ b/contracts/incentives/RnbwDistributionManager.sol @@ -2,7 +2,7 @@ pragma solidity 0.6.12; pragma experimental ABIEncoderV2; -import {SafeMath} from './lib/SafeMath.sol'; +import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol'; import {DistributionTypes} from './lib/DistributionTypes.sol'; import {IRnbwDistributionManager} from './interfaces/IRnbwDistributionManager.sol'; diff --git a/contracts/incentives/RnbwIncentivesController.sol b/contracts/incentives/RnbwIncentivesController.sol index 98d5c8bb..b4b94765 100644 --- a/contracts/incentives/RnbwIncentivesController.sol +++ b/contracts/incentives/RnbwIncentivesController.sol @@ -3,9 +3,9 @@ pragma solidity 0.6.12; pragma experimental ABIEncoderV2; import {DistributionTypes} from './lib/DistributionTypes.sol'; -import {SafeMath} from './lib/SafeMath.sol'; -import {IERC20} from './interfaces/IERC20.sol'; +import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; +import {SafeMath} from '@openzeppelin/contracts/math/SafeMath.sol'; import {IAToken} from './interfaces/IAToken.sol'; import {IRnbwIncentivesController} from './interfaces/IRnbwIncentivesController.sol'; import {IStakedAave} from './interfaces/IStakedAave.sol'; @@ -70,11 +70,7 @@ contract RnbwIncentivesController is uint256 totalSupply ) external override { uint256 accruedRewards = _updateUserAssetInternal(user, msg.sender, userBalance, totalSupply); - /* console.log("user: ", user); - console.log("msg.sender: ", msg.sender); - console.log("userBalance: ", userBalance); - console.log("totalSupply: ", totalSupply); - console.log("accruedRewards: ", accruedRewards); */ + if (accruedRewards != 0) { _usersUnclaimedRewards[user] = _usersUnclaimedRewards[user].add(accruedRewards); emit RewardsAccrued(user, accruedRewards); diff --git a/contracts/incentives/lib/Context.sol b/contracts/incentives/lib/Context.sol deleted file mode 100644 index 8445c2e6..00000000 --- a/contracts/incentives/lib/Context.sol +++ /dev/null @@ -1,25 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity 0.6.12; - -/** - * @dev From https://github.com/OpenZeppelin/openzeppelin-contracts - * Provides information about the current execution context, including the - * sender of the transaction and its data. While these are generally available - * via msg.sender and msg.data, they should not be accessed in such a direct - * manner, since when dealing with GSN meta-transactions the account sending and - * paying for execution may not be the actual sender (as far as an application - * is concerned). - * - * This contract is only required for intermediate, library-like contracts. - */ -abstract contract Context { - function _msgSender() internal view virtual returns (address payable) { - return msg.sender; - } - - function _msgData() internal view virtual returns (bytes memory) { - this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 - return msg.data; - } -} diff --git a/contracts/incentives/lib/ERC20.sol b/contracts/incentives/lib/ERC20.sol deleted file mode 100644 index f9c1babf..00000000 --- a/contracts/incentives/lib/ERC20.sol +++ /dev/null @@ -1,224 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.6.12; - -import {Context} from './Context.sol'; -import {IERC20} from '../interfaces/IERC20.sol'; -import {IERC20Detailed} from '../interfaces/IERC20Detailed.sol'; -import {SafeMath} from './SafeMath.sol'; - -/** - * @title ERC20 - * @notice Basic ERC20 implementation - * @author Aave - **/ -contract ERC20 is Context, IERC20, IERC20Detailed { - using SafeMath for uint256; - - mapping(address => uint256) private _balances; - mapping(address => mapping(address => uint256)) private _allowances; - uint256 private _totalSupply; - string private _name; - string private _symbol; - uint8 private _decimals; - - constructor( - string memory name, - string memory symbol, - uint8 decimals - ) public { - _name = name; - _symbol = symbol; - _decimals = decimals; - } - - /** - * @return the name of the token - **/ - function name() public view override returns (string memory) { - return _name; - } - - /** - * @return the symbol of the token - **/ - function symbol() public view override returns (string memory) { - return _symbol; - } - - /** - * @return the decimals of the token - **/ - function decimals() public view override returns (uint8) { - return _decimals; - } - - /** - * @return the total supply of the token - **/ - function totalSupply() public view override returns (uint256) { - return _totalSupply; - } - - /** - * @return the balance of the token - **/ - function balanceOf(address account) public view override returns (uint256) { - return _balances[account]; - } - - /** - * @dev executes a transfer of tokens from msg.sender to recipient - * @param recipient the recipient of the tokens - * @param amount the amount of tokens being transferred - * @return true if the transfer succeeds, false otherwise - **/ - function transfer(address recipient, uint256 amount) public virtual override returns (bool) { - _transfer(_msgSender(), recipient, amount); - return true; - } - - /** - * @dev returns the allowance of spender on the tokens owned by owner - * @param owner the owner of the tokens - * @param spender the user allowed to spend the owner's tokens - * @return the amount of owner's tokens spender is allowed to spend - **/ - function allowance(address owner, address spender) - public - view - virtual - override - returns (uint256) - { - return _allowances[owner][spender]; - } - - /** - * @dev allows spender to spend the tokens owned by msg.sender - * @param spender the user allowed to spend msg.sender tokens - * @return true - **/ - function approve(address spender, uint256 amount) public virtual override returns (bool) { - _approve(_msgSender(), spender, amount); - return true; - } - - /** - * @dev executes a transfer of token from sender to recipient, if msg.sender is allowed to do so - * @param sender the owner of the tokens - * @param recipient the recipient of the tokens - * @param amount the amount of tokens being transferred - * @return true if the transfer succeeds, false otherwise - **/ - function transferFrom( - address sender, - address recipient, - uint256 amount - ) public virtual override returns (bool) { - _transfer(sender, recipient, amount); - _approve( - sender, - _msgSender(), - _allowances[sender][_msgSender()].sub(amount, 'ERC20: transfer amount exceeds allowance') - ); - return true; - } - - /** - * @dev increases the allowance of spender to spend msg.sender tokens - * @param spender the user allowed to spend on behalf of msg.sender - * @param addedValue the amount being added to the allowance - * @return true - **/ - function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { - _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue)); - return true; - } - - /** - * @dev decreases the allowance of spender to spend msg.sender tokens - * @param spender the user allowed to spend on behalf of msg.sender - * @param subtractedValue the amount being subtracted to the allowance - * @return true - **/ - function decreaseAllowance(address spender, uint256 subtractedValue) - public - virtual - returns (bool) - { - _approve( - _msgSender(), - spender, - _allowances[_msgSender()][spender].sub( - subtractedValue, - 'ERC20: decreased allowance below zero' - ) - ); - return true; - } - - function _transfer( - address sender, - address recipient, - uint256 amount - ) internal virtual { - require(sender != address(0), 'ERC20: transfer from the zero address'); - require(recipient != address(0), 'ERC20: transfer to the zero address'); - - _beforeTokenTransfer(sender, recipient, amount); - - _balances[sender] = _balances[sender].sub(amount, 'ERC20: transfer amount exceeds balance'); - _balances[recipient] = _balances[recipient].add(amount); - emit Transfer(sender, recipient, amount); - } - - function _mint(address account, uint256 amount) internal virtual { - require(account != address(0), 'ERC20: mint to the zero address'); - - _beforeTokenTransfer(address(0), account, amount); - - _totalSupply = _totalSupply.add(amount); - _balances[account] = _balances[account].add(amount); - emit Transfer(address(0), account, amount); - } - - function _burn(address account, uint256 amount) internal virtual { - require(account != address(0), 'ERC20: burn from the zero address'); - - _beforeTokenTransfer(account, address(0), amount); - - _balances[account] = _balances[account].sub(amount, 'ERC20: burn amount exceeds balance'); - _totalSupply = _totalSupply.sub(amount); - emit Transfer(account, address(0), amount); - } - - function _approve( - address owner, - address spender, - uint256 amount - ) internal virtual { - require(owner != address(0), 'ERC20: approve from the zero address'); - require(spender != address(0), 'ERC20: approve to the zero address'); - - _allowances[owner][spender] = amount; - emit Approval(owner, spender, amount); - } - - function _setName(string memory newName) internal { - _name = newName; - } - - function _setSymbol(string memory newSymbol) internal { - _symbol = newSymbol; - } - - function _setDecimals(uint8 newDecimals) internal { - _decimals = newDecimals; - } - - function _beforeTokenTransfer( - address from, - address to, - uint256 amount - ) internal virtual {} -} diff --git a/contracts/incentives/lib/MintableErc20.sol b/contracts/incentives/lib/MintableErc20.sol deleted file mode 100644 index 370b0b39..00000000 --- a/contracts/incentives/lib/MintableErc20.sol +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.6.12; - -import './ERC20.sol'; - -/** - * @title ERC20Mintable - * @dev ERC20 minting logic - */ -contract MintableErc20 is ERC20 { - constructor( - string memory name, - string memory symbol, - uint8 decimals - ) public ERC20(name, symbol, decimals) {} - - /** - * @dev Function to mint tokens - * @param value The amount of tokens to mint. - * @return A boolean that indicates if the operation was successful. - */ - function mint(uint256 value) public returns (bool) { - _mint(msg.sender, value); - return true; - } -} diff --git a/contracts/incentives/lib/SafeMath.sol b/contracts/incentives/lib/SafeMath.sol deleted file mode 100644 index e7ccdc46..00000000 --- a/contracts/incentives/lib/SafeMath.sol +++ /dev/null @@ -1,164 +0,0 @@ -// SPDX-License-Identifier: agpl-3.0 -pragma solidity 0.6.12; - -/** - * @dev From https://github.com/OpenZeppelin/openzeppelin-contracts - * Wrappers over Solidity's arithmetic operations with added overflow - * checks. - * - * Arithmetic operations in Solidity wrap on overflow. This can easily result - * in bugs, because programmers usually assume that an overflow raises an - * error, which is the standard behavior in high level programming languages. - * `SafeMath` restores this intuition by reverting the transaction when an - * operation overflows. - * - * Using this library instead of the unchecked operations eliminates an entire - * class of bugs, so it's recommended to use it always. - */ -library SafeMath { - /** - * @dev Returns the addition of two unsigned integers, reverting on - * overflow. - * - * Counterpart to Solidity's `+` operator. - * - * Requirements: - * - Addition cannot overflow. - */ - function add(uint256 a, uint256 b) internal pure returns (uint256) { - uint256 c = a + b; - require(c >= a, 'SafeMath: addition overflow'); - - return c; - } - - /** - * @dev Returns the subtraction of two unsigned integers, reverting on - * overflow (when the result is negative). - * - * Counterpart to Solidity's `-` operator. - * - * Requirements: - * - Subtraction cannot overflow. - */ - function sub(uint256 a, uint256 b) internal pure returns (uint256) { - return sub(a, b, 'SafeMath: subtraction overflow'); - } - - /** - * @dev Returns the subtraction of two unsigned integers, reverting with custom message on - * overflow (when the result is negative). - * - * Counterpart to Solidity's `-` operator. - * - * Requirements: - * - Subtraction cannot overflow. - */ - function sub( - uint256 a, - uint256 b, - string memory errorMessage - ) internal pure returns (uint256) { - require(b <= a, errorMessage); - uint256 c = a - b; - - return c; - } - - /** - * @dev Returns the multiplication of two unsigned integers, reverting on - * overflow. - * - * Counterpart to Solidity's `*` operator. - * - * Requirements: - * - Multiplication cannot overflow. - */ - function mul(uint256 a, uint256 b) internal pure returns (uint256) { - // Gas optimization: this is cheaper than requiring 'a' not being zero, but the - // benefit is lost if 'b' is also tested. - // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 - if (a == 0) { - return 0; - } - - uint256 c = a * b; - require(c / a == b, 'SafeMath: multiplication overflow'); - - return c; - } - - /** - * @dev Returns the integer division of two unsigned integers. Reverts on - * division by zero. The result is rounded towards zero. - * - * Counterpart to Solidity's `/` operator. Note: this function uses a - * `revert` opcode (which leaves remaining gas untouched) while Solidity - * uses an invalid opcode to revert (consuming all remaining gas). - * - * Requirements: - * - The divisor cannot be zero. - */ - function div(uint256 a, uint256 b) internal pure returns (uint256) { - return div(a, b, 'SafeMath: division by zero'); - } - - /** - * @dev Returns the integer division of two unsigned integers. Reverts with custom message on - * division by zero. The result is rounded towards zero. - * - * Counterpart to Solidity's `/` operator. Note: this function uses a - * `revert` opcode (which leaves remaining gas untouched) while Solidity - * uses an invalid opcode to revert (consuming all remaining gas). - * - * Requirements: - * - The divisor cannot be zero. - */ - function div( - uint256 a, - uint256 b, - string memory errorMessage - ) internal pure returns (uint256) { - // Solidity only automatically asserts when dividing by 0 - require(b > 0, errorMessage); - uint256 c = a / b; - // assert(a == b * c + a % b); // There is no case in which this doesn't hold - - return c; - } - - /** - * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), - * Reverts when dividing by zero. - * - * Counterpart to Solidity's `%` operator. This function uses a `revert` - * opcode (which leaves remaining gas untouched) while Solidity uses an - * invalid opcode to revert (consuming all remaining gas). - * - * Requirements: - * - The divisor cannot be zero. - */ - function mod(uint256 a, uint256 b) internal pure returns (uint256) { - return mod(a, b, 'SafeMath: modulo by zero'); - } - - /** - * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), - * Reverts with custom message when dividing by zero. - * - * Counterpart to Solidity's `%` operator. This function uses a `revert` - * opcode (which leaves remaining gas untouched) while Solidity uses an - * invalid opcode to revert (consuming all remaining gas). - * - * Requirements: - * - The divisor cannot be zero. - */ - function mod( - uint256 a, - uint256 b, - string memory errorMessage - ) internal pure returns (uint256) { - require(b != 0, errorMessage); - return a % b; - } -}