diff --git a/contracts/StaticATokenRateProvider.sol b/contracts/StaticATokenRateProvider.sol index 438527d..189c8e3 100644 --- a/contracts/StaticATokenRateProvider.sol +++ b/contracts/StaticATokenRateProvider.sol @@ -22,18 +22,26 @@ import "./interfaces/IStaticAToken.sol"; * @notice Returns the value of a wrapped (static) aToken in terms of the underlying (dynamic) aToken */ contract StaticATokenRateProvider is IRateProvider { - IStaticAToken public immutable waToken; + ILendingPool public immutable lendingPool; + address public immutable asset; constructor(IStaticAToken _waToken) { - waToken = _waToken; + lendingPool = _waToken.LENDING_POOL(); + asset = _waToken.ASSET(); } /** * @return The value of the wrapped aToken in terms of the underlying aToken */ function getRate() external view override returns (uint256) { + // This pulls the implementation of used in the StaticAToken contract + // except avoiding storing relevant variables in storage for gas reasons. + // solhint-disable-next-line max-line-length + // see: https://github.com/aave/protocol-v2/blob/ac58fea62bb8afee23f66197e8bce6d79ecda292/contracts/protocol/tokenization/StaticATokenLM.sol#L255-L257 + uint256 rate = lendingPool.getReserveNormalizedIncome(asset); + // getRate returns a 18 decimal fixed point number, but `rate` has 27 decimals (i.e. a 'ray' value) // so we need to convert it. - return waToken.rate() / 10**9; + return rate / 10**9; } } diff --git a/contracts/interfaces/ILendingPool.sol b/contracts/interfaces/ILendingPool.sol new file mode 100644 index 0000000..6e032e2 --- /dev/null +++ b/contracts/interfaces/ILendingPool.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-3.0-or-later +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +pragma solidity ^0.8.0; + +interface ILendingPool { + /** + * @dev returns a 27 decimal fixed point 'ray' value so a rate of 1 is represented as 1e27 + */ + function getReserveNormalizedIncome(address asset) external view returns (uint256); +} diff --git a/contracts/interfaces/IStaticAToken.sol b/contracts/interfaces/IStaticAToken.sol index 1337e43..b76935b 100644 --- a/contracts/interfaces/IStaticAToken.sol +++ b/contracts/interfaces/IStaticAToken.sol @@ -14,7 +14,19 @@ pragma solidity ^0.8.0; +import "./ILendingPool.sol"; + interface IStaticAToken { + /** + * @dev returns the address of the staticAToken's underlying asset + */ + function ASSET() external view returns (address); + + /** + * @dev returns the address of the staticAToken's lending pool + */ + function LENDING_POOL() external view returns (ILendingPool); + /** * @dev returns a 27 decimal fixed point 'ray' value so a rate of 1 is represented as 1e27 */