diff --git a/contracts/interfaces/ICreditDelegationToken.sol b/contracts/interfaces/ICreditDelegationToken.sol new file mode 100644 index 00000000..6f26d52e --- /dev/null +++ b/contracts/interfaces/ICreditDelegationToken.sol @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: agpl-3.0 +pragma solidity 0.6.12; + +interface ICreditDelegationToken { + event BorrowAllowanceDelegated( + address indexed fromUser, + address indexed toUser, + address asset, + uint256 amount + ); + + /** + * @dev delegates borrowing power to a user on the specific debt token + * @param delegatee the address receiving the delegated borrowing power + * @param amount the maximum amount being delegated. Delegation will still + * respect the liquidation constraints (even if delegated, a delegatee cannot + * force a delegator HF to go below 1) + **/ + function approveDelegation(address delegatee, uint256 amount) external; + + /** + * @dev returns the borrow allowance of the user + * @param fromUser The user to giving allowance + * @param toUser The user to give allowance to + * @return the current allowance of toUser + **/ + function borrowAllowance(address fromUser, address toUser) external view returns (uint256); +} diff --git a/contracts/protocol/tokenization/base/DebtTokenBase.sol b/contracts/protocol/tokenization/base/DebtTokenBase.sol index d592e6ff..07bdef22 100644 --- a/contracts/protocol/tokenization/base/DebtTokenBase.sol +++ b/contracts/protocol/tokenization/base/DebtTokenBase.sol @@ -2,6 +2,7 @@ pragma solidity 0.6.12; import {ILendingPool} from '../../../interfaces/ILendingPool.sol'; +import {ICreditDelegationToken} from '../../../interfaces/ICreditDelegationToken.sol'; import { VersionedInitializable } from '../../libraries/aave-upgradeability/VersionedInitializable.sol'; @@ -14,14 +15,11 @@ import {Errors} from '../../libraries/helpers/Errors.sol'; * @author Aave */ -abstract contract DebtTokenBase is IncentivizedERC20, VersionedInitializable { - event BorrowAllowanceDelegated( - address indexed fromUser, - address indexed toUser, - address asset, - uint256 amount - ); - +abstract contract DebtTokenBase is + IncentivizedERC20, + VersionedInitializable, + ICreditDelegationToken +{ address public immutable UNDERLYING_ASSET_ADDRESS; ILendingPool public immutable POOL; @@ -73,7 +71,7 @@ abstract contract DebtTokenBase is IncentivizedERC20, VersionedInitializable { * respect the liquidation constraints (even if delegated, a delegatee cannot * force a delegator HF to go below 1) **/ - function approveDelegation(address delegatee, uint256 amount) external { + function approveDelegation(address delegatee, uint256 amount) external override { _borrowAllowances[_msgSender()][delegatee] = amount; emit BorrowAllowanceDelegated(_msgSender(), delegatee, UNDERLYING_ASSET_ADDRESS, amount); } @@ -84,7 +82,12 @@ abstract contract DebtTokenBase is IncentivizedERC20, VersionedInitializable { * @param toUser The user to give allowance to * @return the current allowance of toUser **/ - function borrowAllowance(address fromUser, address toUser) external view returns (uint256) { + function borrowAllowance(address fromUser, address toUser) + external + view + override + returns (uint256) + { return _borrowAllowances[fromUser][toUser]; }