From 9d1c13cf960f48af7dfce0a5b61fcafddda4db42 Mon Sep 17 00:00:00 2001 From: The3D Date: Mon, 21 Sep 2020 17:41:38 +0200 Subject: [PATCH] added events to mintToTreasury() --- contracts/tokenization/AToken.sol | 19 +++++-- contracts/tokenization/VariableDebtToken.sol | 15 +++++- contracts/tokenization/interfaces/IAToken.sol | 45 ++-------------- .../interfaces/IScaledBalanceToken.sol | 49 +++++++++++++++++ .../interfaces/IVariableDebtToken.sol | 53 +++++-------------- 5 files changed, 93 insertions(+), 88 deletions(-) create mode 100644 contracts/tokenization/interfaces/IScaledBalanceToken.sol diff --git a/contracts/tokenization/AToken.sol b/contracts/tokenization/AToken.sol index 45f623a3..fe270785 100644 --- a/contracts/tokenization/AToken.sol +++ b/contracts/tokenization/AToken.sol @@ -22,7 +22,6 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken { using WadRayMath for uint256; using SafeERC20 for IERC20; - bytes public constant EIP712_REVISION = bytes('1'); bytes32 internal constant EIP712_DOMAIN = keccak256( 'EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)' @@ -39,9 +38,9 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken { /// @dev owner => next valid nonce to submit with permit() mapping(address => uint256) public _nonces; - + bytes32 public DOMAIN_SEPARATOR; - + modifier onlyLendingPool { require(msg.sender == address(POOL), Errors.CALLER_MUST_BE_LENDING_POOL); _; @@ -140,7 +139,11 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken { } function mintToTreasury(uint256 amount, uint256 index) external override onlyLendingPool { - _mint(RESERVE_TREASURY_ADDRESS, amount.div(index)); + _mint(RESERVE_TREASURY_ADDRESS, amount.div(index)); + + //transfer event to track balances + emit Transfer(address(0), RESERVE_TREASURY_ADDRESS, amount); + emit Mint(RESERVE_TREASURY_ADDRESS, amount, index); } /** @@ -216,6 +219,14 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken { return currentSupplyScaled.rayMul(POOL.getReserveNormalizedIncome(UNDERLYING_ASSET_ADDRESS)); } + /** + * @dev Returns the scaled total supply of the variable debt token. Represents sum(borrows/index) + * @return the scaled total supply + **/ + function scaledTotalSupply() public virtual override view returns (uint256) { + return super.totalSupply(); + } + /** * @dev Used to validate transfers before actually executing them. * @param user address of the user to check diff --git a/contracts/tokenization/VariableDebtToken.sol b/contracts/tokenization/VariableDebtToken.sol index a94f16aa..600ef08d 100644 --- a/contracts/tokenization/VariableDebtToken.sol +++ b/contracts/tokenization/VariableDebtToken.sol @@ -62,7 +62,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken { _mint(user, amount.rayDiv(index)); emit Transfer(address(0), user, amount); - emit MintDebt(user, amount, index); + emit Mint(user, amount, index); } /** @@ -78,7 +78,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken { _burn(user, amount.rayDiv(index)); emit Transfer(user, address(0), amount); - emit BurnDebt(user, amount, index); + emit Burn(user, amount, index); } /** @@ -104,4 +104,15 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken { function scaledTotalSupply() public virtual override view returns (uint256) { return super.totalSupply(); } + + /** + * @dev returns the principal balance of the user and principal total supply. + * @param user the address of the user + * @return the principal balance of the user + * @return the principal total supply + **/ + function getScaledUserBalanceAndSupply(address user) external override view returns (uint256, uint256){ + return (super.balanceOf(user), super.totalSupply()); + } + } diff --git a/contracts/tokenization/interfaces/IAToken.sol b/contracts/tokenization/interfaces/IAToken.sol index a9fbc49b..b5e182bc 100644 --- a/contracts/tokenization/interfaces/IAToken.sol +++ b/contracts/tokenization/interfaces/IAToken.sol @@ -2,8 +2,9 @@ pragma solidity ^0.6.8; import {IERC20} from '../../interfaces/IERC20.sol'; +import {IScaledBalanceToken} from './IScaledBalanceToken.sol'; -interface IAToken is IERC20 { +interface IAToken is IERC20, IScaledBalanceToken { /** * @dev emitted after aTokens are burned * @param from the address performing the redeem @@ -16,15 +17,6 @@ interface IAToken is IERC20 { uint256 value, uint256 index ); - - /** - * @dev emitted after the mint action - * @param from the address performing the mint - * @param value the amount to be minted - * @param index the last index of the reserve - **/ - event Mint(address indexed from, uint256 value, uint256 index); - /** * @dev emitted during the transfer action * @param from the address from which the tokens are being transferred @@ -38,7 +30,6 @@ interface IAToken is IERC20 { uint256 value, uint256 index ); - /** * @dev burns the aTokens and sends the equivalent amount of underlying to the target. * only lending pools can call this function @@ -52,15 +43,6 @@ interface IAToken is IERC20 { uint256 index ) external; - /** - * @dev mints aTokens to user - * only lending pools can call this function - * @param user the address receiving the minted tokens - * @param amount the amount of tokens to mint - * @param index the liquidity index - */ - function mint(address user, uint256 amount, uint256 index) external; - /** * @dev mints aTokens to the reserve treasury * @param amount the amount to mint @@ -81,28 +63,7 @@ interface IAToken is IERC20 { uint256 value ) external; - /** - * @dev returns the principal balance of the user. The principal balance is the last - * updated stored balance, which does not consider the perpetually accruing interest. - * @param user the address of the user - * @return the principal balance of the user - **/ - function scaledBalanceOf(address user) external view returns (uint256); - - /** - * @dev returns the principal balance of the user and principal total supply. - * @param user the address of the user - * @return the principal balance of the user - * @return the principal total supply - **/ - function getScaledUserBalanceAndSupply(address user) external view returns (uint256, uint256); - - /** - * @dev Used to validate transfers before actually executing them. - * @param user address of the user to check - * @param amount the amount to check - * @return true if the user can transfer amount, false otherwise - **/ + function isTransferAllowed(address user, uint256 amount) external view returns (bool); /** diff --git a/contracts/tokenization/interfaces/IScaledBalanceToken.sol b/contracts/tokenization/interfaces/IScaledBalanceToken.sol new file mode 100644 index 00000000..9bcd2427 --- /dev/null +++ b/contracts/tokenization/interfaces/IScaledBalanceToken.sol @@ -0,0 +1,49 @@ + +// SPDX-License-Identifier: agpl-3.0 +pragma solidity ^0.6.8; + +interface IScaledBalanceToken { + + /** + * @dev emitted after the mint action + * @param from the address performing the mint + * @param value the amount to be minted + * @param index the last index of the reserve + **/ + event Mint(address indexed from, uint256 value, uint256 index); + + /** + * @dev mints aTokens to user + * only lending pools can call this function + * @param user the address receiving the minted tokens + * @param amount the amount of tokens to mint + * @param index the liquidity index + */ + function mint( + address user, + uint256 amount, + uint256 index + ) external; + + /** + * @dev returns the principal balance of the user. The principal balance is the last + * updated stored balance, which does not consider the perpetually accruing interest. + * @param user the address of the user + * @return the principal balance of the user + **/ + function scaledBalanceOf(address user) external view returns (uint256); + + /** + * @dev returns the principal balance of the user and principal total supply. + * @param user the address of the user + * @return the principal balance of the user + * @return the principal total supply + **/ + function getScaledUserBalanceAndSupply(address user) external view returns (uint256, uint256); + + /** + * @dev Returns the scaled total supply of the variable debt token. Represents sum(borrows/index) + * @return the scaled total supply + **/ + function scaledTotalSupply() external view returns (uint256); +} diff --git a/contracts/tokenization/interfaces/IVariableDebtToken.sol b/contracts/tokenization/interfaces/IVariableDebtToken.sol index 0b680f51..2e6bae93 100644 --- a/contracts/tokenization/interfaces/IVariableDebtToken.sol +++ b/contracts/tokenization/interfaces/IVariableDebtToken.sol @@ -1,63 +1,36 @@ // SPDX-License-Identifier: agpl-3.0 pragma solidity ^0.6.8; +import {IScaledBalanceToken} from './IScaledBalanceToken.sol'; + /** * @title interface IVariableDebtToken * @author Aave * @notice defines the basic interface for a variable debt token. - * @dev does not inherit from IERC20 to save in contract size **/ -interface IVariableDebtToken { - /** - * @dev emitted when new variable debt is minted - * @param user the user receiving the debt - * @param amount the amount of debt being minted - * @param index the index of the user - **/ - event MintDebt( - address user, - uint256 amount, - uint256 index - ); - +interface IVariableDebtToken is IScaledBalanceToken { + /** * @dev emitted when variable debt is burnt * @param user the user which debt has been burned * @param amount the amount of debt being burned * @param index the index of the user **/ - event BurnDebt( - address user, + event Burn( + address indexed user, uint256 amount, uint256 index ); - /** - * @dev mints new variable debt - * @param user the user receiving the debt - * @param amount the amount of debt being minted - * @param index the variable debt index of the reserve - **/ - function mint(address user, uint256 amount, uint256 index) external; - - /** + /** * @dev burns user variable debt * @param user the user which debt is burnt - * @param amount the amount of debt being burned * @param index the variable debt index of the reserve **/ - function burn(address user, uint256 amount, uint256 index) external; - - /** - * @dev returns the scaled balance of the variable debt token - * @param user the user - **/ - function scaledBalanceOf(address user) external view returns(uint256); - - /** - * @dev Returns the scaled total supply of the variable debt token. Represents sum(borrows/index) - * @return the scaled total supply - **/ - function scaledTotalSupply() external view returns(uint256); - + function burn( + address user, + uint256 amount, + uint256 index + ) external; + }