Skip to content

Commit

Permalink
fix: Make _pool public of AToken and DebtToken
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelmtzinf committed Dec 3, 2021
1 parent 5f5dff4 commit 014da25
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 31 deletions.
24 changes: 8 additions & 16 deletions contracts/protocol/tokenization/AToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {

uint256 public constant ATOKEN_REVISION = 0x1;

IPool internal immutable _pool;
IPool public immutable POOL;
address internal _treasury;
address internal _underlyingAsset;

modifier onlyPool() {
require(_msgSender() == address(_pool), Errors.CT_CALLER_MUST_BE_POOL);
require(_msgSender() == address(POOL), Errors.CT_CALLER_MUST_BE_POOL);
_;
}

Expand All @@ -45,7 +45,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
constructor(IPool pool)
IncentivizedERC20(pool.getAddressesProvider(), 'ATOKEN_IMPL', 'ATOKEN_IMPL', 0)
{
_pool = pool;
POOL = pool;
}

/// @inheritdoc IInitializableAToken
Expand All @@ -70,7 +70,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {

emit Initialized(
underlyingAsset,
address(_pool),
address(POOL),
treasury,
address(incentivesController),
aTokenDecimals,
Expand Down Expand Up @@ -161,7 +161,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
override(IncentivizedERC20, IERC20)
returns (uint256)
{
return super.balanceOf(user).rayMul(_pool.getReserveNormalizedIncome(_underlyingAsset));
return super.balanceOf(user).rayMul(POOL.getReserveNormalizedIncome(_underlyingAsset));
}

/// @inheritdoc IScaledBalanceToken
Expand All @@ -187,7 +187,7 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
return 0;
}

return currentSupplyScaled.rayMul(_pool.getReserveNormalizedIncome(_underlyingAsset));
return currentSupplyScaled.rayMul(POOL.getReserveNormalizedIncome(_underlyingAsset));
}

/// @inheritdoc IScaledBalanceToken
Expand All @@ -213,14 +213,6 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
return _underlyingAsset;
}

/**
* @notice Returns the address of the pool where this aToken is used
* @return Address of the pool
**/
function POOL() external view returns (IPool) {
return _pool;
}

/// @inheritdoc IAToken
function transferUnderlyingTo(address target, uint256 amount) external override onlyPool {
IERC20(_underlyingAsset).safeTransfer(target, amount);
Expand Down Expand Up @@ -271,15 +263,15 @@ contract AToken is VersionedInitializable, IncentivizedERC20, IAToken {
) internal {
address underlyingAsset = _underlyingAsset;

uint256 index = _pool.getReserveNormalizedIncome(underlyingAsset);
uint256 index = POOL.getReserveNormalizedIncome(underlyingAsset);

uint256 fromBalanceBefore = super.balanceOf(from).rayMul(index);
uint256 toBalanceBefore = super.balanceOf(to).rayMul(index);

super._transfer(from, to, Helpers.castUint128(amount.rayDiv(index)));

if (validate) {
_pool.finalizeTransfer(underlyingAsset, from, to, amount, fromBalanceBefore, toBalanceBefore);
POOL.finalizeTransfer(underlyingAsset, from, to, amount, fromBalanceBefore, toBalanceBefore);
}

emit BalanceTransfer(from, to, amount, index);
Expand Down
2 changes: 1 addition & 1 deletion contracts/protocol/tokenization/StableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ contract StableDebtToken is IStableDebtToken, DebtTokenBase {

emit Initialized(
underlyingAsset,
address(_pool),
address(POOL),
address(incentivesController),
debtTokenDecimals,
debtTokenName,
Expand Down
6 changes: 3 additions & 3 deletions contracts/protocol/tokenization/VariableDebtToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {

emit Initialized(
underlyingAsset,
address(_pool),
address(POOL),
address(incentivesController),
debtTokenDecimals,
debtTokenName,
Expand All @@ -70,7 +70,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {
return 0;
}

return scaledBalance.rayMul(_pool.getReserveNormalizedVariableDebt(_underlyingAsset));
return scaledBalance.rayMul(POOL.getReserveNormalizedVariableDebt(_underlyingAsset));
}

/// @inheritdoc IVariableDebtToken
Expand Down Expand Up @@ -135,7 +135,7 @@ contract VariableDebtToken is DebtTokenBase, IVariableDebtToken {

/// @inheritdoc IERC20
function totalSupply() public view virtual override returns (uint256) {
return super.totalSupply().rayMul(_pool.getReserveNormalizedVariableDebt(_underlyingAsset));
return super.totalSupply().rayMul(POOL.getReserveNormalizedVariableDebt(_underlyingAsset));
}

/// @inheritdoc IScaledBalanceToken
Expand Down
14 changes: 3 additions & 11 deletions contracts/protocol/tokenization/base/DebtTokenBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ abstract contract DebtTokenBase is
keccak256(
'DelegationWithSig(address delegator,address delegatee,uint256 value,uint256 nonce,uint256 deadline)'
);
IPool internal immutable _pool;
IPool public immutable POOL;

/**
* @dev Only pool can call functions marked by this modifier
**/
modifier onlyPool() {
require(_msgSender() == address(_pool), Errors.CT_CALLER_MUST_BE_POOL);
require(_msgSender() == address(POOL), Errors.CT_CALLER_MUST_BE_POOL);
_;
}

constructor(IPool pool)
IncentivizedERC20(pool.getAddressesProvider(), 'DEBT_TOKEN_IMPL', 'DEBT_TOKEN_IMPL', 0)
{
_pool = pool;
POOL = pool;
}

/// @inheritdoc ICreditDelegationToken
Expand Down Expand Up @@ -105,14 +105,6 @@ abstract contract DebtTokenBase is
**/
function _getUnderlyingAssetAddress() internal view virtual returns (address);

/**
* @notice Returns the address of the pool where this debtToken is used
* @return The address of the Pool
**/
function POOL() external view returns (IPool) {
return _pool;
}

/**
* @dev Being non transferrable, the debt token does not implement any of the
* standard ERC20 functions for transfer and allowance.
Expand Down

0 comments on commit 014da25

Please sign in to comment.