Skip to content

Commit

Permalink
feat: added optimal stable to variable debt ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
The-3D committed Sep 28, 2021
1 parent 1f5b953 commit e0a9756
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
10 changes: 7 additions & 3 deletions contracts/protocol/pool/DefaultReserveInterestRateStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {IReserveInterestRateStrategy} from '../../interfaces/IReserveInterestRat
import {IPoolAddressesProvider} from '../../interfaces/IPoolAddressesProvider.sol';
import {IERC20} from '../../dependencies/openzeppelin/contracts/IERC20.sol';
import {DataTypes} from '../libraries/types/DataTypes.sol';
import "hardhat/console.sol";
import 'hardhat/console.sol';

/**
* @title DefaultReserveInterestRateStrategy contract
Expand All @@ -29,6 +29,8 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
**/
uint256 public immutable OPTIMAL_UTILIZATION_RATE;

uint256 public immutable OPTIMAL_STABLE_TO_VARIABLE_DEBT_RATIO;

/**
* @dev This constant represents the excess utilization rate above the optimal. It's always equal to
* 1-optimal utilization rate. Added as a constant here for gas optimizations.
Expand Down Expand Up @@ -67,10 +69,12 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
uint256 stableRateSlope1,
uint256 stableRateSlope2,
uint256 baseStableRateOffset,
uint256 stableRateExcessOffset
uint256 stableRateExcessOffset,
uint256 optimalStableToVariableDebtRatio
) {
OPTIMAL_UTILIZATION_RATE = optimalUtilizationRate;
EXCESS_UTILIZATION_RATE = WadRayMath.RAY - optimalUtilizationRate;
OPTIMAL_STABLE_TO_VARIABLE_DEBT_RATIO = optimalStableToVariableDebtRatio;
addressesProvider = provider;
_baseVariableBorrowRate = baseVariableBorrowRate;
_variableRateSlope1 = variableRateSlope1;
Expand All @@ -97,7 +101,7 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
return _stableRateSlope2;
}

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

Expand Down
3 changes: 1 addition & 2 deletions helpers/contracts-deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ export const deployEModeLogic = async () => {
return withSave(eModeLogic, eContractid.EModeLogic);
};


export const deployAaveLibraries = async (): Promise<PoolLibraryAddresses> => {
const supplyLogic = await deploySupplyLogic();
const borrowLogic = await deployBorrowLogic();
Expand Down Expand Up @@ -236,7 +235,7 @@ export const deployMintableDelegationERC20 = async (
);

export const deployDefaultReserveInterestRateStrategy = async (
args: [tEthereumAddress, string, string, string, string, string, string, string, string]
args: [tEthereumAddress, string, string, string, string, string, string, string, string, string]
) =>
withSave(
await new DefaultReserveInterestRateStrategyFactory(await getFirstSigner()).deploy(...args),
Expand Down
7 changes: 5 additions & 2 deletions helpers/init-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const initReservesByHelper = async (
string,
string,
string,
string,
string
];
let rateStrategies: Record<string, typeof strategyRates> = {};
Expand Down Expand Up @@ -130,7 +131,8 @@ export const initReservesByHelper = async (
stableRateSlope1,
stableRateSlope2,
baseStableRateOffset,
stableRateExcessOffset
stableRateExcessOffset,
optimalStableToVariableDebtRatio,
} = strategy;
if (!strategyAddresses[strategy.name]) {
// Strategy does not exist, create a new one
Expand All @@ -143,7 +145,8 @@ export const initReservesByHelper = async (
stableRateSlope1,
stableRateSlope2,
baseStableRateOffset,
stableRateExcessOffset
stableRateExcessOffset,
optimalStableToVariableDebtRatio,
];
strategyAddresses[strategy.name] = (
await deployDefaultReserveInterestRateStrategy(rateStrategies[strategy.name])
Expand Down
2 changes: 1 addition & 1 deletion helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ export enum ProtocolErrors {
RC_INVALID_UNBACKED_MINT_CAP = '103',
VL_UNBACKED_MINT_CAP_EXCEEDED = '104',


// old

INVALID_FROM_BALANCE_AFTER_TRANSFER = 'Invalid from balance after transfer',
Expand Down Expand Up @@ -326,6 +325,7 @@ export interface IInterestRateStrategyParams {
stableRateSlope2: string;
baseStableRateOffset: string;
stableRateExcessOffset: string;
optimalStableToVariableDebtRatio: string;
}

export interface IReserveBorrowParams {
Expand Down
27 changes: 18 additions & 9 deletions market-config/rateStrategies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export const rateStrategyStableOne: IInterestRateStrategyParams = {
stableRateSlope1: '0',
stableRateSlope2: '0',
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

// DAI TUSD
Expand All @@ -24,7 +25,8 @@ export const rateStrategyStableTwo: IInterestRateStrategyParams = {
stableRateSlope1: utils.parseUnits('0.02', 27).toString(),
stableRateSlope2: utils.parseUnits('0.75', 27).toString(),
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

// USDC USDT
Expand All @@ -37,7 +39,8 @@ export const rateStrategyStableThree: IInterestRateStrategyParams = {
stableRateSlope1: utils.parseUnits('0.02', 27).toString(),
stableRateSlope2: utils.parseUnits('0.6', 27).toString(),
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

// WETH
Expand All @@ -50,7 +53,8 @@ export const rateStrategyWETH: IInterestRateStrategyParams = {
stableRateSlope1: utils.parseUnits('0.1', 27).toString(),
stableRateSlope2: utils.parseUnits('1', 27).toString(),
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

// AAVE
Expand All @@ -63,7 +67,8 @@ export const rateStrategyAAVE: IInterestRateStrategyParams = {
stableRateSlope1: '0',
stableRateSlope2: '0',
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

// BAT ENJ LINK MANA MKR REN YFI ZRX
Expand All @@ -76,7 +81,8 @@ export const rateStrategyVolatileOne: IInterestRateStrategyParams = {
stableRateSlope1: utils.parseUnits('0.1', 27).toString(),
stableRateSlope2: utils.parseUnits('0.3', 27).toString(),
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

// KNC WBTC
Expand All @@ -89,7 +95,8 @@ export const rateStrategyVolatileTwo: IInterestRateStrategyParams = {
stableRateSlope1: utils.parseUnits('0.1', 27).toString(),
stableRateSlope2: utils.parseUnits('0.3', 27).toString(),
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

// SNX
Expand All @@ -102,7 +109,8 @@ export const rateStrategyVolatileThree: IInterestRateStrategyParams = {
stableRateSlope1: utils.parseUnits('0.1', 27).toString(),
stableRateSlope2: utils.parseUnits('3', 27).toString(),
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

export const rateStrategyVolatileFour: IInterestRateStrategyParams = {
Expand All @@ -114,5 +122,6 @@ export const rateStrategyVolatileFour: IInterestRateStrategyParams = {
stableRateSlope1: '0',
stableRateSlope2: '0',
baseStableRateOffset: utils.parseUnits('0.02', 27).toString(),
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString()
stableRateExcessOffset: utils.parseUnits('0.05', 27).toString(),
optimalStableToVariableDebtRatio: utils.parseUnits('0.2', 27).toString(),
};

0 comments on commit e0a9756

Please sign in to comment.