From 13f4d34867873cb91e9969a88b02091c5d95075f Mon Sep 17 00:00:00 2001 From: andyk Date: Fri, 21 Aug 2020 17:03:01 +0300 Subject: [PATCH] refactoring flashloan folder to fit current guideline, move events to interfaces --- .../LendingPoolAddressesProvider.sol | 11 -- .../LendingPoolAddressesProviderRegistry.sol | 4 - .../flashloan/base/FlashLoanReceiverBase.sol | 20 +- .../interfaces/IFlashLoanReceiver.sol | 10 +- contracts/interfaces/ILendingPool.sol | 136 +++++++++++++ .../ILendingPoolAddressesProvider.sol | 11 ++ .../ILendingPoolAddressesProviderRegistry.sol | 4 + contracts/lendingpool/LendingPool.sol | 183 ++---------------- contracts/tokenization/AToken.sol | 78 -------- contracts/tokenization/StableDebtToken.sol | 34 ---- contracts/tokenization/VariableDebtToken.sol | 36 ---- contracts/tokenization/interfaces/IAToken.sol | 78 ++++++++ .../interfaces/IStableDebtToken.sol | 34 ++++ .../interfaces/IVariableDebtToken.sol | 36 ++++ 14 files changed, 334 insertions(+), 341 deletions(-) diff --git a/contracts/configuration/LendingPoolAddressesProvider.sol b/contracts/configuration/LendingPoolAddressesProvider.sol index 916842d9..a93069a1 100644 --- a/contracts/configuration/LendingPoolAddressesProvider.sol +++ b/contracts/configuration/LendingPoolAddressesProvider.sol @@ -16,17 +16,6 @@ import '../interfaces/ILendingPoolAddressesProvider.sol'; contract LendingPoolAddressesProvider is Ownable, ILendingPoolAddressesProvider { mapping(bytes32 => address) private _addresses; - //events - event LendingPoolUpdated(address indexed newAddress); - event LendingPoolManagerUpdated(address indexed newAddress); - event LendingPoolConfiguratorUpdated(address indexed newAddress); - event LendingPoolLiquidationManagerUpdated(address indexed newAddress); - event EthereumAddressUpdated(address indexed newAddress); - event PriceOracleUpdated(address indexed newAddress); - event LendingRateOracleUpdated(address indexed newAddress); - - event ProxyCreated(bytes32 id, address indexed newAddress); - bytes32 private constant LENDING_POOL = 'LENDING_POOL'; bytes32 private constant LENDING_POOL_CORE = 'LENDING_POOL_CORE'; bytes32 private constant LENDING_POOL_CONFIGURATOR = 'LENDING_POOL_CONFIGURATOR'; diff --git a/contracts/configuration/LendingPoolAddressesProviderRegistry.sol b/contracts/configuration/LendingPoolAddressesProviderRegistry.sol index 4066e14e..5a766ece 100644 --- a/contracts/configuration/LendingPoolAddressesProviderRegistry.sol +++ b/contracts/configuration/LendingPoolAddressesProviderRegistry.sol @@ -11,10 +11,6 @@ import '../interfaces/ILendingPoolAddressesProviderRegistry.sol'; **/ contract LendingPoolAddressesProviderRegistry is Ownable, ILendingPoolAddressesProviderRegistry { - //events - event AddressesProviderRegistered(address indexed newAddress); - event AddressesProviderUnregistered(address indexed newAddress); - mapping(address => uint256) addressesProviders; address[] addressesProvidersList; diff --git a/contracts/flashloan/base/FlashLoanReceiverBase.sol b/contracts/flashloan/base/FlashLoanReceiverBase.sol index d25a3325..9bccc014 100644 --- a/contracts/flashloan/base/FlashLoanReceiverBase.sol +++ b/contracts/flashloan/base/FlashLoanReceiverBase.sol @@ -14,25 +14,25 @@ abstract contract FlashLoanReceiverBase is IFlashLoanReceiver { ILendingPoolAddressesProvider public addressesProvider; - constructor(ILendingPoolAddressesProvider _provider) public { - addressesProvider = _provider; + constructor(ILendingPoolAddressesProvider provider) public { + addressesProvider = provider; } receive() external payable {} function transferFundsBackInternal( - address _reserve, - address _destination, - uint256 _amount + address reserve, + address destination, + uint256 amount ) internal { - transferInternal(_destination, _reserve, _amount); + transferInternal(destination, reserve, amount); } function transferInternal( - address _destination, - address _reserve, - uint256 _amount + address destination, + address reserve, + uint256 amount ) internal { - IERC20(_reserve).safeTransfer(_destination, _amount); + IERC20(reserve).safeTransfer(destination, amount); } } diff --git a/contracts/flashloan/interfaces/IFlashLoanReceiver.sol b/contracts/flashloan/interfaces/IFlashLoanReceiver.sol index 4392c348..95fe6f3d 100644 --- a/contracts/flashloan/interfaces/IFlashLoanReceiver.sol +++ b/contracts/flashloan/interfaces/IFlashLoanReceiver.sol @@ -9,10 +9,10 @@ pragma solidity ^0.6.8; **/ interface IFlashLoanReceiver { function executeOperation( - address _reserve, - address _destination, - uint256 _amount, - uint256 _fee, - bytes calldata _params + address reserve, + address destination, + uint256 amount, + uint256 fee, + bytes calldata params ) external; } diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol index 831c4fdc..1bca3979 100644 --- a/contracts/interfaces/ILendingPool.sol +++ b/contracts/interfaces/ILendingPool.sol @@ -6,6 +6,142 @@ import {ReserveConfiguration} from '../libraries/configuration/ReserveConfigurat pragma experimental ABIEncoderV2; interface ILendingPool { + /** + * @dev emitted on deposit + * @param reserve the address of the reserve + * @param user the address of the user + * @param amount the amount to be deposited + * @param referral the referral number of the action + **/ + event Deposit( + address indexed reserve, + address indexed user, + uint256 amount, + uint16 indexed referral + ); + + /** + * @dev emitted during a withdraw action. + * @param reserve the address of the reserve + * @param user the address of the user + * @param amount the amount to be withdrawn + **/ + event Withdraw(address indexed reserve, address indexed user, uint256 amount); + + /** + * @dev emitted on borrow + * @param reserve the address of the reserve + * @param user the address of the user + * @param amount the amount to be deposited + * @param borrowRateMode the rate mode, can be either 1-stable or 2-variable + * @param borrowRate the rate at which the user has borrowed + * @param referral the referral number of the action + **/ + event Borrow( + address indexed reserve, + address indexed user, + uint256 amount, + uint256 borrowRateMode, + uint256 borrowRate, + uint16 indexed referral + ); + /** + * @dev emitted on repay + * @param reserve the address of the reserve + * @param user the address of the user for which the repay has been executed + * @param repayer the address of the user that has performed the repay action + * @param amount the amount repaid + **/ + event Repay( + address indexed reserve, + address indexed user, + address indexed repayer, + uint256 amount + ); + /** + * @dev emitted when a user performs a rate swap + * @param reserve the address of the reserve + * @param user the address of the user executing the swap + **/ + event Swap(address indexed reserve, address indexed user, uint256 timestamp); + + /** + * @dev emitted when a user enables a reserve as collateral + * @param reserve the address of the reserve + * @param user the address of the user + **/ + event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user); + + /** + * @dev emitted when a user disables a reserve as collateral + * @param reserve the address of the reserve + * @param user the address of the user + **/ + event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user); + + /** + * @dev emitted when the stable rate of a user gets rebalanced + * @param reserve the address of the reserve + * @param user the address of the user for which the rebalance has been executed + **/ + event RebalanceStableBorrowRate(address indexed reserve, address indexed user); + /** + * @dev emitted when a flashloan is executed + * @param target the address of the flashLoanReceiver + * @param reserve the address of the reserve + * @param amount the amount requested + * @param totalFee the total fee on the amount + **/ + event FlashLoan( + address indexed target, + address indexed reserve, + uint256 amount, + uint256 totalFee + ); + /** + * @dev these events are not emitted directly by the LendingPool + * but they are declared here as the LendingPoolLiquidationManager + * is executed using a delegateCall(). + * This allows to have the events in the generated ABI for LendingPool. + **/ + + /** + * @dev emitted when a borrow fee is liquidated + * @param collateral the address of the collateral being liquidated + * @param reserve the address of the reserve + * @param user the address of the user being liquidated + * @param feeLiquidated the total fee liquidated + * @param liquidatedCollateralForFee the amount of collateral received by the protocol in exchange for the fee + **/ + event OriginationFeeLiquidated( + address indexed collateral, + address indexed reserve, + address indexed user, + uint256 feeLiquidated, + uint256 liquidatedCollateralForFee + ); + /** + * @dev emitted when a borrower is liquidated + * @param collateral the address of the collateral being liquidated + * @param reserve the address of the reserve + * @param user the address of the user being liquidated + * @param purchaseAmount the total amount liquidated + * @param liquidatedCollateralAmount the amount of collateral being liquidated + * @param accruedBorrowInterest the amount of interest accrued by the borrower since the last action + * @param liquidator the address of the liquidator + * @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise + **/ + event LiquidationCall( + address indexed collateral, + address indexed reserve, + address indexed user, + uint256 purchaseAmount, + uint256 liquidatedCollateralAmount, + uint256 accruedBorrowInterest, + address liquidator, + bool receiveAToken + ); + /** * @dev deposits The underlying asset into the reserve. A corresponding amount of the overlying asset (aTokens) * is minted. diff --git a/contracts/interfaces/ILendingPoolAddressesProvider.sol b/contracts/interfaces/ILendingPoolAddressesProvider.sol index 9978c60e..78e336f9 100644 --- a/contracts/interfaces/ILendingPoolAddressesProvider.sol +++ b/contracts/interfaces/ILendingPoolAddressesProvider.sol @@ -7,6 +7,17 @@ pragma solidity ^0.6.8; */ interface ILendingPoolAddressesProvider { + //events + event LendingPoolUpdated(address indexed newAddress); + event LendingPoolManagerUpdated(address indexed newAddress); + event LendingPoolConfiguratorUpdated(address indexed newAddress); + event LendingPoolLiquidationManagerUpdated(address indexed newAddress); + event EthereumAddressUpdated(address indexed newAddress); + event PriceOracleUpdated(address indexed newAddress); + event LendingRateOracleUpdated(address indexed newAddress); + + event ProxyCreated(bytes32 id, address indexed newAddress); + function getLendingPool() external view returns (address); function setLendingPoolImpl(address pool) external; diff --git a/contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol b/contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol index 859fdf79..fc8a9531 100644 --- a/contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol +++ b/contracts/interfaces/ILendingPoolAddressesProviderRegistry.sol @@ -7,6 +7,10 @@ pragma solidity ^0.6.8; **/ interface ILendingPoolAddressesProviderRegistry { + //events + event AddressesProviderRegistered(address indexed newAddress); + event AddressesProviderUnregistered(address indexed newAddress); + function getAddressesProvidersList() external view returns (address[] memory); function isAddressesProviderRegistered(address _provider) external view returns (uint256); diff --git a/contracts/lendingpool/LendingPool.sol b/contracts/lendingpool/LendingPool.sol index 6d9ec9d5..ee429e6f 100644 --- a/contracts/lendingpool/LendingPool.sol +++ b/contracts/lendingpool/LendingPool.sol @@ -51,141 +51,6 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { address[] internal reservesList; - /** - * @dev emitted on deposit - * @param reserve the address of the reserve - * @param user the address of the user - * @param amount the amount to be deposited - * @param referral the referral number of the action - **/ - event Deposit( - address indexed reserve, - address indexed user, - uint256 amount, - uint16 indexed referral - ); - - /** - * @dev emitted during a withdraw action. - * @param reserve the address of the reserve - * @param user the address of the user - * @param amount the amount to be withdrawn - **/ - event Withdraw(address indexed reserve, address indexed user, uint256 amount); - - /** - * @dev emitted on borrow - * @param reserve the address of the reserve - * @param user the address of the user - * @param amount the amount to be deposited - * @param borrowRateMode the rate mode, can be either 1-stable or 2-variable - * @param borrowRate the rate at which the user has borrowed - * @param referral the referral number of the action - **/ - event Borrow( - address indexed reserve, - address indexed user, - uint256 amount, - uint256 borrowRateMode, - uint256 borrowRate, - uint16 indexed referral - ); - /** - * @dev emitted on repay - * @param reserve the address of the reserve - * @param user the address of the user for which the repay has been executed - * @param repayer the address of the user that has performed the repay action - * @param amount the amount repaid - **/ - event Repay( - address indexed reserve, - address indexed user, - address indexed repayer, - uint256 amount - ); - /** - * @dev emitted when a user performs a rate swap - * @param reserve the address of the reserve - * @param user the address of the user executing the swap - **/ - event Swap(address indexed reserve, address indexed user, uint256 timestamp); - - /** - * @dev emitted when a user enables a reserve as collateral - * @param reserve the address of the reserve - * @param user the address of the user - **/ - event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user); - - /** - * @dev emitted when a user disables a reserve as collateral - * @param reserve the address of the reserve - * @param user the address of the user - **/ - event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user); - - /** - * @dev emitted when the stable rate of a user gets rebalanced - * @param reserve the address of the reserve - * @param user the address of the user for which the rebalance has been executed - **/ - event RebalanceStableBorrowRate(address indexed reserve, address indexed user); - /** - * @dev emitted when a flashloan is executed - * @param target the address of the flashLoanReceiver - * @param reserve the address of the reserve - * @param amount the amount requested - * @param totalFee the total fee on the amount - **/ - event FlashLoan( - address indexed target, - address indexed reserve, - uint256 amount, - uint256 totalFee - ); - /** - * @dev these events are not emitted directly by the LendingPool - * but they are declared here as the LendingPoolLiquidationManager - * is executed using a delegateCall(). - * This allows to have the events in the generated ABI for LendingPool. - **/ - - /** - * @dev emitted when a borrow fee is liquidated - * @param collateral the address of the collateral being liquidated - * @param reserve the address of the reserve - * @param user the address of the user being liquidated - * @param feeLiquidated the total fee liquidated - * @param liquidatedCollateralForFee the amount of collateral received by the protocol in exchange for the fee - **/ - event OriginationFeeLiquidated( - address indexed collateral, - address indexed reserve, - address indexed user, - uint256 feeLiquidated, - uint256 liquidatedCollateralForFee - ); - /** - * @dev emitted when a borrower is liquidated - * @param collateral the address of the collateral being liquidated - * @param reserve the address of the reserve - * @param user the address of the user being liquidated - * @param purchaseAmount the total amount liquidated - * @param liquidatedCollateralAmount the amount of collateral being liquidated - * @param accruedBorrowInterest the amount of interest accrued by the borrower since the last action - * @param liquidator the address of the liquidator - * @param receiveAToken true if the liquidator wants to receive aTokens, false otherwise - **/ - event LiquidationCall( - address indexed collateral, - address indexed reserve, - address indexed user, - uint256 purchaseAmount, - uint256 liquidatedCollateralAmount, - uint256 accruedBorrowInterest, - address liquidator, - bool receiveAToken - ); /** * @dev only lending pools configurator can use functions affected by this modifier **/ @@ -415,12 +280,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { IERC20(asset).safeTransferFrom(msg.sender, reserve.aTokenAddress, paybackAmount); - emit Repay( - asset, - _onBehalfOf, - msg.sender, - paybackAmount - ); + emit Repay(asset, _onBehalfOf, msg.sender, paybackAmount); } /** @@ -511,10 +371,7 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { reserve.updateInterestRates(asset, 0, 0); - emit RebalanceStableBorrowRate( - asset, - _user - ); + emit RebalanceStableBorrowRate(asset, _user); return; } @@ -875,18 +732,18 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { } /** - * @dev returns the normalized income per unit of asset - * @param asset the address of the reserve - * @return the reserve normalized income + * @dev returns the normalized income per unit of asset + * @param asset the address of the reserve + * @return the reserve normalized income */ function getReserveNormalizedIncome(address asset) external override view returns (uint256) { return _reserves[asset].getNormalizedIncome(); } /** - * @dev returns the normalized variable debt per unit of asset - * @param asset the address of the reserve - * @return the reserve normalized debt + * @dev returns the normalized variable debt per unit of asset + * @param asset the address of the reserve + * @return the reserve normalized debt */ function getReserveNormalizedVariableDebt(address asset) external @@ -898,11 +755,11 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { } /** - * @dev validate if a balance decrease for an asset is allowed - * @param asset the address of the reserve - * @param user the user related to the balance decrease - * @param amount the amount being transferred/redeemed - * @return true if the balance decrease can be allowed, false otherwise + * @dev validate if a balance decrease for an asset is allowed + * @param asset the address of the reserve + * @param user the user related to the balance decrease + * @param amount the amount being transferred/redeemed + * @return true if the balance decrease can be allowed, false otherwise */ function balanceDecreaseAllowed( address asset, @@ -922,16 +779,16 @@ contract LendingPool is ReentrancyGuard, VersionedInitializable, ILendingPool { } /** - * @dev returns the list of the initialized reserves - **/ - function getReservesList() external view returns(address[] memory){ - return reservesList; + * @dev returns the list of the initialized reserves + **/ + function getReservesList() external view returns (address[] memory) { + return reservesList; } /** - * @dev returns the addresses provider - **/ - function getAddressesProvider() external view returns(ILendingPoolAddressesProvider){ + * @dev returns the addresses provider + **/ + function getAddressesProvider() external view returns (ILendingPoolAddressesProvider) { return addressesProvider; } } diff --git a/contracts/tokenization/AToken.sol b/contracts/tokenization/AToken.sol index ef948d42..76b57d64 100644 --- a/contracts/tokenization/AToken.sol +++ b/contracts/tokenization/AToken.sol @@ -22,84 +22,6 @@ contract AToken is VersionedInitializable, ERC20, IAToken { uint256 public constant UINT_MAX_VALUE = uint256(-1); - /** - * @dev emitted after aTokens are burned - * @param from the address performing the redeem - * @param value the amount to be redeemed - * @param fromBalanceIncrease the cumulated balance since the last update of the user - * @param fromIndex the last index of the user - **/ - event Burn( - address indexed from, - address indexed target, - uint256 value, - uint256 fromBalanceIncrease, - uint256 fromIndex - ); - - /** - * @dev emitted after the mint action - * @param from the address performing the mint - * @param value the amount to be minted - * @param fromBalanceIncrease the cumulated balance since the last update of the user - * @param fromIndex the last index of the user - **/ - event Mint(address indexed from, uint256 value, uint256 fromBalanceIncrease, uint256 fromIndex); - - /** - * @dev emitted during the transfer action - * @param from the address from which the tokens are being transferred - * @param to the adress of the destination - * @param value the amount to be minted - * @param fromBalanceIncrease the cumulated balance since the last update of the user - * @param toBalanceIncrease the cumulated balance since the last update of the destination - * @param fromIndex the last index of the user - * @param toIndex the last index of the liquidator - **/ - event BalanceTransfer( - address indexed from, - address indexed to, - uint256 value, - uint256 fromBalanceIncrease, - uint256 toBalanceIncrease, - uint256 fromIndex, - uint256 toIndex - ); - - /** - * @dev emitted when the accumulation of the interest - * by an user is redirected to another user - * @param from the address from which the interest is being redirected - * @param to the adress of the destination - * @param fromBalanceIncrease the cumulated balance since the last update of the user - * @param fromIndex the last index of the user - **/ - event InterestStreamRedirected( - address indexed from, - address indexed to, - uint256 redirectedBalance, - uint256 fromBalanceIncrease, - uint256 fromIndex - ); - - /** - * @dev emitted when the redirected balance of an user is being updated - * @param targetAddress the address of which the balance is being updated - * @param targetBalanceIncrease the cumulated balance since the last update of the target - * @param targetIndex the last index of the user - * @param redirectedBalanceAdded the redirected balance being added - * @param redirectedBalanceRemoved the redirected balance being removed - **/ - event RedirectedBalanceUpdated( - address indexed targetAddress, - uint256 targetBalanceIncrease, - uint256 targetIndex, - uint256 redirectedBalanceAdded, - uint256 redirectedBalanceRemoved - ); - - event InterestRedirectionAllowanceChanged(address indexed from, address indexed to); - address public immutable UNDERLYING_ASSET_ADDRESS; mapping(address => uint256) private _userIndexes; diff --git a/contracts/tokenization/StableDebtToken.sol b/contracts/tokenization/StableDebtToken.sol index b8021b33..318c7e04 100644 --- a/contracts/tokenization/StableDebtToken.sol +++ b/contracts/tokenization/StableDebtToken.sol @@ -33,40 +33,6 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase { mapping(address => UserData) private _usersData; - /** - * @dev emitted when new stable debt is minted - * @param user the address of the user - * @param amount the amount minted - * @param previousBalance the previous balance of the user - * @param currentBalance the current balance of the user - * @param balanceIncrease the debt increase since the last update - * @param newRate the rate of the debt after the minting - **/ - event MintDebt( - address user, - uint256 amount, - uint256 previousBalance, - uint256 currentBalance, - uint256 balanceIncrease, - uint256 newRate - ); - - /** - * @dev emitted when new stable debt is burned - * @param user the address of the user - * @param amount the amount minted - * @param previousBalance the previous balance of the user - * @param currentBalance the current balance of the user - * @param balanceIncrease the debt increase since the last update - **/ - event BurnDebt( - address user, - uint256 amount, - uint256 previousBalance, - uint256 currentBalance, - uint256 balanceIncrease - ); - constructor( address pool, address underlyingAsset, diff --git a/contracts/tokenization/VariableDebtToken.sol b/contracts/tokenization/VariableDebtToken.sol index 87d92889..9a4ffd2c 100644 --- a/contracts/tokenization/VariableDebtToken.sol +++ b/contracts/tokenization/VariableDebtToken.sol @@ -22,42 +22,6 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken { mapping(address => uint256) private _userIndexes; - /** - * @dev emitted when new variable debt is minted - * @param user the user receiving the debt - * @param amount the amount of debt being minted - * @param previousBalance the previous balance of the user - * @param currentBalance the current balance of the user - * @param balanceIncrease the debt accumulated since the last action - * @param index the index of the user - **/ - event MintDebt( - address user, - uint256 amount, - uint256 previousBalance, - uint256 currentBalance, - uint256 balanceIncrease, - uint256 index - ); - - /** - * @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 previousBalance the previous balance of the user - * @param currentBalance the current balance of the user - * @param balanceIncrease the debt accumulated since the last action - * @param index the index of the user - **/ - event BurnDebt( - address user, - uint256 amount, - uint256 previousBalance, - uint256 currentBalance, - uint256 balanceIncrease, - uint256 index - ); - constructor( address pool, address underlyingAsset, diff --git a/contracts/tokenization/interfaces/IAToken.sol b/contracts/tokenization/interfaces/IAToken.sol index f4196f80..51eefa18 100644 --- a/contracts/tokenization/interfaces/IAToken.sol +++ b/contracts/tokenization/interfaces/IAToken.sol @@ -4,6 +4,84 @@ pragma solidity ^0.6.8; import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol'; interface IAToken is IERC20 { + /** + * @dev emitted after aTokens are burned + * @param from the address performing the redeem + * @param value the amount to be redeemed + * @param fromBalanceIncrease the cumulated balance since the last update of the user + * @param fromIndex the last index of the user + **/ + event Burn( + address indexed from, + address indexed target, + uint256 value, + uint256 fromBalanceIncrease, + uint256 fromIndex + ); + + /** + * @dev emitted after the mint action + * @param from the address performing the mint + * @param value the amount to be minted + * @param fromBalanceIncrease the cumulated balance since the last update of the user + * @param fromIndex the last index of the user + **/ + event Mint(address indexed from, uint256 value, uint256 fromBalanceIncrease, uint256 fromIndex); + + /** + * @dev emitted during the transfer action + * @param from the address from which the tokens are being transferred + * @param to the adress of the destination + * @param value the amount to be minted + * @param fromBalanceIncrease the cumulated balance since the last update of the user + * @param toBalanceIncrease the cumulated balance since the last update of the destination + * @param fromIndex the last index of the user + * @param toIndex the last index of the liquidator + **/ + event BalanceTransfer( + address indexed from, + address indexed to, + uint256 value, + uint256 fromBalanceIncrease, + uint256 toBalanceIncrease, + uint256 fromIndex, + uint256 toIndex + ); + + /** + * @dev emitted when the accumulation of the interest + * by an user is redirected to another user + * @param from the address from which the interest is being redirected + * @param to the adress of the destination + * @param fromBalanceIncrease the cumulated balance since the last update of the user + * @param fromIndex the last index of the user + **/ + event InterestStreamRedirected( + address indexed from, + address indexed to, + uint256 redirectedBalance, + uint256 fromBalanceIncrease, + uint256 fromIndex + ); + + /** + * @dev emitted when the redirected balance of an user is being updated + * @param targetAddress the address of which the balance is being updated + * @param targetBalanceIncrease the cumulated balance since the last update of the target + * @param targetIndex the last index of the user + * @param redirectedBalanceAdded the redirected balance being added + * @param redirectedBalanceRemoved the redirected balance being removed + **/ + event RedirectedBalanceUpdated( + address indexed targetAddress, + uint256 targetBalanceIncrease, + uint256 targetIndex, + uint256 redirectedBalanceAdded, + uint256 redirectedBalanceRemoved + ); + + event InterestRedirectionAllowanceChanged(address indexed from, address indexed to); + /** * @dev redirects the interest generated to a target address. * when the interest is redirected, the user balance is added to diff --git a/contracts/tokenization/interfaces/IStableDebtToken.sol b/contracts/tokenization/interfaces/IStableDebtToken.sol index 57e8fb74..0aaccd26 100644 --- a/contracts/tokenization/interfaces/IStableDebtToken.sol +++ b/contracts/tokenization/interfaces/IStableDebtToken.sol @@ -13,6 +13,40 @@ pragma solidity ^0.6.8; **/ interface IStableDebtToken { + /** + * @dev emitted when new stable debt is minted + * @param user the address of the user + * @param amount the amount minted + * @param previousBalance the previous balance of the user + * @param currentBalance the current balance of the user + * @param balanceIncrease the debt increase since the last update + * @param newRate the rate of the debt after the minting + **/ + event MintDebt( + address user, + uint256 amount, + uint256 previousBalance, + uint256 currentBalance, + uint256 balanceIncrease, + uint256 newRate + ); + + /** + * @dev emitted when new stable debt is burned + * @param user the address of the user + * @param amount the amount minted + * @param previousBalance the previous balance of the user + * @param currentBalance the current balance of the user + * @param balanceIncrease the debt increase since the last update + **/ + event BurnDebt( + address user, + uint256 amount, + uint256 previousBalance, + uint256 currentBalance, + uint256 balanceIncrease + ); + /** * @dev mints debt token to the target user. The resulting rate is the weighted average * between the rate of the new debt and the rate of the previous debt diff --git a/contracts/tokenization/interfaces/IVariableDebtToken.sol b/contracts/tokenization/interfaces/IVariableDebtToken.sol index f434aa8c..fdd86a0d 100644 --- a/contracts/tokenization/interfaces/IVariableDebtToken.sol +++ b/contracts/tokenization/interfaces/IVariableDebtToken.sol @@ -8,6 +8,42 @@ pragma solidity ^0.6.8; * @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 previousBalance the previous balance of the user + * @param currentBalance the current balance of the user + * @param balanceIncrease the debt accumulated since the last action + * @param index the index of the user + **/ + event MintDebt( + address user, + uint256 amount, + uint256 previousBalance, + uint256 currentBalance, + uint256 balanceIncrease, + uint256 index + ); + + /** + * @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 previousBalance the previous balance of the user + * @param currentBalance the current balance of the user + * @param balanceIncrease the debt accumulated since the last action + * @param index the index of the user + **/ + event BurnDebt( + address user, + uint256 amount, + uint256 previousBalance, + uint256 currentBalance, + uint256 balanceIncrease, + uint256 index + ); + /** * @dev mints new variable debt * @param user the user receiving the debt