Skip to content

Commit

Permalink
feat: removal of the rate oracle, initial implementation, tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
The-3D committed Sep 28, 2021
1 parent 1379838 commit 1f5b953
Show file tree
Hide file tree
Showing 25 changed files with 164 additions and 484 deletions.
44 changes: 0 additions & 44 deletions contracts/deployments/RateOracleSetupHelper.sol

This file was deleted.

5 changes: 0 additions & 5 deletions contracts/interfaces/IPoolAddressesProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ interface IPoolAddressesProvider {
event PoolUpdated(address indexed newAddress);
event PoolConfiguratorUpdated(address indexed newAddress);
event PriceOracleUpdated(address indexed newAddress);
event RateOracleUpdated(address indexed newAddress);
event ACLManagerUpdated(address indexed newAddress);
event ACLAdminUpdated(address indexed newAddress);
event ProxyCreated(bytes32 id, address indexed newAddress);
Expand Down Expand Up @@ -85,10 +84,6 @@ interface IPoolAddressesProvider {

function setPriceOracle(address priceOracle) external;

function getRateOracle() external view returns (address);

function setRateOracle(address rateOracle) external;

/**
* @notice Returns the address of the ACL manager proxy
* @return The ACLManager proxy address
Expand Down
24 changes: 0 additions & 24 deletions contracts/interfaces/IRateOracle.sol

This file was deleted.

21 changes: 21 additions & 0 deletions contracts/misc/AaveProtocolDataProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,25 @@ contract AaveProtocolDataProvider {
reserve.variableDebtTokenAddress
);
}

/**
* @notice Returns the address of the IR strategy
* @param asset The address of the underlying asset of the reserve
* @return irStrategyAddress The address of the IR strategy
*/
function getIRStrategyAddress(address asset)
external
view
returns (
address irStrategyAddress
)
{
DataTypes.ReserveData memory reserve = IPool(ADDRESSES_PROVIDER.getPool()).getReserveData(
asset
);

return (
reserve.interestRateStrategyAddress
);
}
}
26 changes: 0 additions & 26 deletions contracts/mocks/oracle/RateOracle.sol

This file was deleted.

10 changes: 0 additions & 10 deletions contracts/protocol/configuration/PoolAddressesProvider.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ contract PoolAddressesProvider is Ownable, IPoolAddressesProvider {
bytes32 private constant POOL = 'POOL';
bytes32 private constant POOL_CONFIGURATOR = 'POOL_CONFIGURATOR';
bytes32 private constant PRICE_ORACLE = 'PRICE_ORACLE';
bytes32 private constant RATE_ORACLE = 'RATE_ORACLE';
bytes32 private constant ACL_MANAGER = 'ACL_MANAGER';
bytes32 private constant ACL_ADMIN = 'ACL_ADMIN';

Expand Down Expand Up @@ -89,15 +88,6 @@ contract PoolAddressesProvider is Ownable, IPoolAddressesProvider {
emit PriceOracleUpdated(priceOracle);
}

function getRateOracle() external view override returns (address) {
return getAddress(RATE_ORACLE);
}

function setRateOracle(address rateOracle) external override onlyOwner {
_addresses[RATE_ORACLE] = rateOracle;
emit RateOracleUpdated(rateOracle);
}

/// @inheritdoc IPoolAddressesProvider
function getACLManager() external view override returns (address) {
return getAddress(ACL_MANAGER);
Expand Down
3 changes: 3 additions & 0 deletions contracts/protocol/libraries/logic/BorrowLogic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {PercentageMath} from '../math/PercentageMath.sol';
import {DataTypes} from '../types/DataTypes.sol';
import {ValidationLogic} from './ValidationLogic.sol';
import {ReserveLogic} from './ReserveLogic.sol';
import 'hardhat/console.sol';

/**
* @title BorrowLogic library
Expand Down Expand Up @@ -164,6 +165,8 @@ library BorrowLogic {
? stableDebt
: variableDebt;

console.log('Payback amount: ', paybackAmount);

if (params.amount < paybackAmount) {
paybackAmount = params.amount;
}
Expand Down
4 changes: 2 additions & 2 deletions contracts/protocol/libraries/types/DataTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ library DataTypes {
ReserveConfigurationMap configuration;
//the liquidity index. Expressed in ray
uint128 liquidityIndex;
//variable borrow index. Expressed in ray
uint128 variableBorrowIndex;
//the current supply rate. Expressed in ray
uint128 currentLiquidityRate;
//variable borrow index. Expressed in ray
uint128 variableBorrowIndex;
//the current variable borrow rate. Expressed in ray
uint128 currentVariableBorrowRate;
//the current stable borrow rate. Expressed in ray
Expand Down
19 changes: 15 additions & 4 deletions contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {WadRayMath} from '../libraries/math/WadRayMath.sol';
import {PercentageMath} from '../libraries/math/PercentageMath.sol';
import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRateStrategy.sol';
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
import {IRateOracle} from '../../interfaces/IRateOracle.sol';
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
import {DataTypes} from '../libraries/types/DataTypes.sol';
import "hardhat/console.sol";

/**
* @title DefaultReserveInterestRateStrategy contract
Expand Down Expand Up @@ -54,14 +54,20 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
// Slope of the stable interest curve when utilization rate > OPTIMAL_UTILIZATION_RATE. Expressed in ray
uint256 internal immutable _stableRateSlope2;

uint256 internal immutable _baseStableRateOffset;

uint256 internal immutable _stableRateExcessOffset;

constructor(
IPoolAddressesProvider provider,
uint256 optimalUtilizationRate,
uint256 baseVariableBorrowRate,
uint256 variableRateSlope1,
uint256 variableRateSlope2,
uint256 stableRateSlope1,
uint256 stableRateSlope2
uint256 stableRateSlope2,
uint256 baseStableRateOffset,
uint256 stableRateExcessOffset
) {
OPTIMAL_UTILIZATION_RATE = optimalUtilizationRate;
EXCESS_UTILIZATION_RATE = WadRayMath.RAY - optimalUtilizationRate;
Expand All @@ -71,6 +77,8 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
_variableRateSlope2 = variableRateSlope2;
_stableRateSlope1 = stableRateSlope1;
_stableRateSlope2 = stableRateSlope2;
_baseStableRateOffset = baseStableRateOffset;
_stableRateExcessOffset = stableRateExcessOffset;
}

function getVariableRateSlope1() external view returns (uint256) {
Expand All @@ -89,6 +97,10 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
return _stableRateSlope2;
}

function getBaseStableBorrowRate() public view returns(uint256) {
return _variableRateSlope1 + _baseStableRateOffset;
}

/// @inheritdoc IReserveInterestRateStrategy
function getBaseVariableBorrowRate() external view override returns (uint256) {
return _baseVariableBorrowRate;
Expand Down Expand Up @@ -140,8 +152,7 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
? 0
: vars.totalDebt.rayDiv(vars.availableLiquidity + params.unbacked + vars.totalDebt);

vars.currentStableBorrowRate = IRateOracle(addressesProvider.getRateOracle())
.getMarketBorrowRate(params.reserve);
vars.currentStableBorrowRate = getBaseStableBorrowRate();

if (vars.borrowUtilizationRate > OPTIMAL_UTILIZATION_RATE) {
uint256 excessUtilizationRateRatio = (vars.borrowUtilizationRate - OPTIMAL_UTILIZATION_RATE)
Expand Down
13 changes: 1 addition & 12 deletions helpers/contracts-deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
PoolAddressesProviderRegistryFactory,
PoolConfiguratorFactory,
PoolFactory,
RateOracleFactory,
MintableDelegationERC20Factory,
MintableERC20Factory,
MockAggregatorFactory,
Expand Down Expand Up @@ -45,7 +44,6 @@ import {
linkBytecode,
insertContractAddressInDb,
} from './contracts-helpers';
import { RateOracleSetupHelperFactory } from '../types/RateOracleSetupHelperFactory';
import { MintableDelegationERC20 } from '../types/MintableDelegationERC20';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { PoolLibraryAddresses } from '../types/PoolFactory';
Expand Down Expand Up @@ -197,9 +195,6 @@ export const deployPool = async () => {
export const deployPriceOracle = async () =>
withSave(await new PriceOracleFactory(await getFirstSigner()).deploy(), eContractid.PriceOracle);

export const deployRateOracle = async () =>
withSave(await new RateOracleFactory(await getFirstSigner()).deploy(), eContractid.RateOracle);

export const deployMockAggregator = async (price: tStringTokenSmallUnits) =>
withSave(
await new MockAggregatorFactory(await getFirstSigner()).deploy(price),
Expand Down Expand Up @@ -241,7 +236,7 @@ export const deployMintableDelegationERC20 = async (
);

export const deployDefaultReserveInterestRateStrategy = async (
args: [tEthereumAddress, string, string, string, string, string, string]
args: [tEthereumAddress, string, string, string, string, string, string, string, string]
) =>
withSave(
await new DefaultReserveInterestRateStrategyFactory(await getFirstSigner()).deploy(...args),
Expand Down Expand Up @@ -353,12 +348,6 @@ export const deployAllMockTokens = async () => {
return tokens;
};

export const deployRateOracleSetupHelper = async () =>
withSave(
await new RateOracleSetupHelperFactory(await getFirstSigner()).deploy(),
eContractid.RateOracleSetupHelper
);

export const deployReservesSetupHelper = async () =>
withSave(
await new ReservesSetupHelperFactory(await getFirstSigner()).deploy(),
Expand Down
28 changes: 11 additions & 17 deletions helpers/contracts-getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ import {
PoolAddressesProviderRegistryFactory,
PoolConfiguratorFactory,
PoolFactory,
RateOracleFactory,
MintableERC20Factory,
MockFlashLoanReceiverFactory,
MockStableDebtTokenFactory,
MockVariableDebtTokenFactory,
PriceOracleFactory,
RateOracleSetupHelperFactory,
StableDebtTokenFactory,
VariableDebtTokenFactory,
WETH9MockedFactory,
Expand All @@ -26,6 +24,8 @@ import {
BridgeLogicFactory,
ACLManagerFactory,
EModeLogicFactory,
DefaultReserveInterestRateStrategy,
DefaultReserveInterestRateStrategyFactory,
} from '../types';
import { IERC20DetailedFactory } from '../types/IERC20DetailedFactory';
import { getEthersSigners, MockTokenMap } from './contracts-helpers';
Expand Down Expand Up @@ -130,6 +130,15 @@ export const getVariableDebtToken = async (address?: tEthereumAddress) =>
await getFirstSigner()
);

export const getIRStrategy = async (address?: tEthereumAddress) =>
await DefaultReserveInterestRateStrategyFactory.connect(
address ||
(
await getDb().get(`${eContractid.DefaultReserveInterestRateStrategy}.${DRE.network.name}`).value()
).address,
await getFirstSigner()
);

export const getMintableERC20 = async (address: tEthereumAddress) =>
await MintableERC20Factory.connect(
address ||
Expand Down Expand Up @@ -172,12 +181,6 @@ export const getMockFlashLoanReceiver = async (address?: tEthereumAddress) =>
await getFirstSigner()
);

export const getRateOracle = async (address?: tEthereumAddress) =>
await RateOracleFactory.connect(
address || (await getDb().get(`${eContractid.RateOracle}.${DRE.network.name}`).value()).address,
await getFirstSigner()
);

export const getAllMockedTokens = async () => {
const db = getDb();
const tokens: MockTokenMap = await Object.keys(TokenContractId).reduce<Promise<MockTokenMap>>(
Expand Down Expand Up @@ -230,15 +233,6 @@ export const getPoolAddressesProviderRegistry = async (address?: tEthereumAddres
await getFirstSigner()
);

export const getRateOracleSetupHelper = async (address?: tEthereumAddress) =>
await RateOracleSetupHelperFactory.connect(
address ||
(
await getDb().get(`${eContractid.RateOracleSetupHelper}.${DRE.network.name}`).value()
).address,
await getFirstSigner()
);

export const getReservesSetupHelper = async (address?: tEthereumAddress) =>
await ReservesSetupHelperFactory.connect(
address ||
Expand Down
Loading

0 comments on commit 1f5b953

Please sign in to comment.