mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Merge branch 'master' of github.com:aave/protocol-v2 into polygon-verifier
This commit is contained in:
commit
264385a839
|
@ -11,6 +11,22 @@ interface IReserveInterestRateStrategy {
|
|||
|
||||
function getMaxVariableBorrowRate() external view returns (uint256);
|
||||
|
||||
function calculateInterestRates(
|
||||
address reserve,
|
||||
uint256 availableLiquidity,
|
||||
uint256 totalStableDebt,
|
||||
uint256 totalVariableDebt,
|
||||
uint256 averageStableBorrowRate,
|
||||
uint256 reserveFactor
|
||||
)
|
||||
external
|
||||
view
|
||||
returns (
|
||||
uint256,
|
||||
uint256,
|
||||
uint256
|
||||
);
|
||||
|
||||
function calculateInterestRates(
|
||||
address reserve,
|
||||
address aToken,
|
||||
|
|
|
@ -98,15 +98,6 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
return _baseVariableBorrowRate.add(_variableRateSlope1).add(_variableRateSlope2);
|
||||
}
|
||||
|
||||
struct CalcInterestRatesLocalVars {
|
||||
uint256 totalDebt;
|
||||
uint256 currentVariableBorrowRate;
|
||||
uint256 currentStableBorrowRate;
|
||||
uint256 currentLiquidityRate;
|
||||
uint256 utilizationRate;
|
||||
uint256 availableLiquidity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Calculates the interest rates depending on the reserve's state and configurations
|
||||
* @param reserve The address of the reserve
|
||||
|
@ -136,6 +127,58 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
uint256,
|
||||
uint256
|
||||
)
|
||||
{
|
||||
uint256 availableLiquidity = IERC20(reserve).balanceOf(aToken);
|
||||
//avoid stack too deep
|
||||
availableLiquidity = availableLiquidity.add(liquidityAdded).sub(liquidityTaken);
|
||||
|
||||
return
|
||||
calculateInterestRates(
|
||||
reserve,
|
||||
availableLiquidity,
|
||||
totalStableDebt,
|
||||
totalVariableDebt,
|
||||
averageStableBorrowRate,
|
||||
reserveFactor
|
||||
);
|
||||
}
|
||||
|
||||
struct CalcInterestRatesLocalVars {
|
||||
uint256 totalDebt;
|
||||
uint256 currentVariableBorrowRate;
|
||||
uint256 currentStableBorrowRate;
|
||||
uint256 currentLiquidityRate;
|
||||
uint256 utilizationRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Calculates the interest rates depending on the reserve's state and configurations.
|
||||
* NOTE This function is kept for compatibility with the previous DefaultInterestRateStrategy interface.
|
||||
* New protocol implementation uses the new calculateInterestRates() interface
|
||||
* @param reserve The address of the reserve
|
||||
* @param availableLiquidity The liquidity available in the corresponding aToken
|
||||
* @param totalStableDebt The total borrowed from the reserve a stable rate
|
||||
* @param totalVariableDebt The total borrowed from the reserve at a variable rate
|
||||
* @param averageStableBorrowRate The weighted average of all the stable rate loans
|
||||
* @param reserveFactor The reserve portion of the interest that goes to the treasury of the market
|
||||
* @return The liquidity rate, the stable borrow rate and the variable borrow rate
|
||||
**/
|
||||
function calculateInterestRates(
|
||||
address reserve,
|
||||
uint256 availableLiquidity,
|
||||
uint256 totalStableDebt,
|
||||
uint256 totalVariableDebt,
|
||||
uint256 averageStableBorrowRate,
|
||||
uint256 reserveFactor
|
||||
)
|
||||
public
|
||||
view
|
||||
override
|
||||
returns (
|
||||
uint256,
|
||||
uint256,
|
||||
uint256
|
||||
)
|
||||
{
|
||||
CalcInterestRatesLocalVars memory vars;
|
||||
|
||||
|
@ -143,11 +186,10 @@ contract DefaultReserveInterestRateStrategy is IReserveInterestRateStrategy {
|
|||
vars.currentVariableBorrowRate = 0;
|
||||
vars.currentStableBorrowRate = 0;
|
||||
vars.currentLiquidityRate = 0;
|
||||
vars.availableLiquidity = IERC20(reserve).balanceOf(aToken);
|
||||
vars.availableLiquidity = vars.availableLiquidity.add(liquidityAdded).sub(liquidityTaken);
|
||||
|
||||
vars.utilizationRate =
|
||||
vars.totalDebt == 0 ? 0 : vars.totalDebt.rayDiv(vars.availableLiquidity.add(vars.totalDebt));
|
||||
vars.utilizationRate = vars.totalDebt == 0
|
||||
? 0
|
||||
: vars.totalDebt.rayDiv(availableLiquidity.add(vars.totalDebt));
|
||||
|
||||
vars.currentStableBorrowRate = ILendingRateOracle(addressesProvider.getLendingRateOracle())
|
||||
.getMarketBorrowRate(reserve);
|
||||
|
|
|
@ -58,7 +58,7 @@ const getCommonNetworkConfig = (networkName: eNetwork, networkId: number) => ({
|
|||
|
||||
const mainnetFork = MAINNET_FORK
|
||||
? {
|
||||
blockNumber: 11739065,
|
||||
blockNumber: 12012081,
|
||||
url: NETWORKS_RPC_URL['main'],
|
||||
}
|
||||
: undefined;
|
||||
|
|
|
@ -68,5 +68,6 @@ export const MOCK_CHAINLINK_AGGREGATORS_PRICES = {
|
|||
BptBALWETH: oneEther.multipliedBy('22.407436').toFixed(),
|
||||
WMATIC: oneEther.multipliedBy('0.003620948469').toFixed(),
|
||||
STAKE: oneEther.multipliedBy('0.003620948469').toFixed(),
|
||||
xSUSHI: oneEther.multipliedBy('0.00913428586').toFixed(),
|
||||
USD: '5848466240000000',
|
||||
};
|
||||
|
|
|
@ -72,6 +72,9 @@ export const setInitialAssetPricesInOracle = async (
|
|||
priceOracleInstance: PriceOracle
|
||||
) => {
|
||||
for (const [assetSymbol, price] of Object.entries(prices) as [string, string][]) {
|
||||
|
||||
console.log("Trying for ", assetsAddresses, assetSymbol);
|
||||
|
||||
const assetAddressIndex = Object.keys(assetsAddresses).findIndex(
|
||||
(value) => value === assetSymbol
|
||||
);
|
||||
|
|
|
@ -238,6 +238,7 @@ export interface iAssetBase<T> {
|
|||
BptBALWETH: T;
|
||||
WMATIC: T;
|
||||
STAKE: T;
|
||||
xSUSHI: T;
|
||||
}
|
||||
|
||||
export type iAssetsWithoutETH<T> = Omit<iAssetBase<T>, 'ETH'>;
|
||||
|
@ -266,6 +267,7 @@ export type iAavePoolAssets<T> = Pick<
|
|||
| 'UNI'
|
||||
| 'REN'
|
||||
| 'ENJ'
|
||||
| 'xSUSHI'
|
||||
>;
|
||||
|
||||
export type iLpPoolAssets<T> = Pick<
|
||||
|
@ -349,6 +351,7 @@ export enum TokenContractId {
|
|||
BptBALWETH = 'BptBALWETH',
|
||||
WMATIC = 'WMATIC',
|
||||
STAKE = 'STAKE',
|
||||
xSUSHI = 'xSUSHI'
|
||||
}
|
||||
|
||||
export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {
|
||||
|
|
|
@ -22,6 +22,7 @@ import {
|
|||
strategyWBTC,
|
||||
strategyWETH,
|
||||
strategyYFI,
|
||||
strategyXSUSHI,
|
||||
} from './reservesConfigs';
|
||||
|
||||
// ----------------
|
||||
|
@ -53,6 +54,7 @@ export const AaveConfig: IAaveConfiguration = {
|
|||
WETH: strategyWETH,
|
||||
YFI: strategyYFI,
|
||||
ZRX: strategyZRX,
|
||||
xSUSHI: strategyXSUSHI,
|
||||
},
|
||||
ReserveAssets: {
|
||||
[eEthereumNetwork.buidlerevm]: {},
|
||||
|
@ -123,6 +125,7 @@ export const AaveConfig: IAaveConfiguration = {
|
|||
WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
||||
YFI: '0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
|
||||
ZRX: '0xE41d2489571d322189246DaFA5ebDe1F4699F498',
|
||||
xSUSHI: '0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272',
|
||||
},
|
||||
[eEthereumNetwork.tenderlyMain]: {
|
||||
AAVE: '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9',
|
||||
|
@ -145,6 +148,7 @@ export const AaveConfig: IAaveConfiguration = {
|
|||
WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
||||
YFI: '0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e',
|
||||
ZRX: '0xE41d2489571d322189246DaFA5ebDe1F4699F498',
|
||||
xSUSHI: '0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -89,3 +89,17 @@ export const rateStrategyVolatileThree: IInterestRateStrategyParams = {
|
|||
stableRateSlope1: new BigNumber(0.1).multipliedBy(oneRay).toFixed(),
|
||||
stableRateSlope2: new BigNumber(3).multipliedBy(oneRay).toFixed(),
|
||||
}
|
||||
|
||||
|
||||
export const rateStrategyVolatileFour: IInterestRateStrategyParams = {
|
||||
name: "rateStrategyVolatileFour",
|
||||
optimalUtilizationRate: new BigNumber(0.45).multipliedBy(oneRay).toFixed(),
|
||||
baseVariableBorrowRate: '0',
|
||||
variableRateSlope1: new BigNumber(0.07).multipliedBy(oneRay).toFixed(),
|
||||
variableRateSlope2: new BigNumber(3).multipliedBy(oneRay).toFixed(),
|
||||
stableRateSlope1: '0',
|
||||
stableRateSlope2: '0',
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// import BigNumber from 'bignumber.js';
|
||||
// import { oneRay } from '../../helpers/constants';
|
||||
import { eContractid, IReserveParams } from '../../helpers/types';
|
||||
|
||||
import {
|
||||
rateStrategyStableOne,
|
||||
rateStrategyStableTwo,
|
||||
|
@ -10,6 +9,7 @@ import {
|
|||
rateStrategyVolatileOne,
|
||||
rateStrategyVolatileTwo,
|
||||
rateStrategyVolatileThree,
|
||||
rateStrategyVolatileFour,
|
||||
} from './rateStrategies';
|
||||
|
||||
export const strategyBUSD: IReserveParams = {
|
||||
|
@ -251,4 +251,16 @@ export const strategyZRX: IReserveParams = {
|
|||
reserveDecimals: '18',
|
||||
aTokenImpl: eContractid.AToken,
|
||||
reserveFactor: '2000'
|
||||
};
|
||||
|
||||
export const strategyXSUSHI: IReserveParams = {
|
||||
strategy: rateStrategyVolatileFour,
|
||||
baseLTVAsCollateral: '2500',
|
||||
liquidationThreshold: '4500',
|
||||
liquidationBonus: '11500',
|
||||
borrowingEnabled: true,
|
||||
stableBorrowRateEnabled: false,
|
||||
reserveDecimals: '18',
|
||||
aTokenImpl: eContractid.AToken,
|
||||
reserveFactor: '3500',
|
||||
};
|
|
@ -253,22 +253,22 @@ export const CommonsConfig: ICommonConfiguration = {
|
|||
WBTC: '0xdeb288F737066589598e9214E782fa5A8eD689e8',
|
||||
USDC: '0x986b5E1e1755e3C2440e960477f25201B0a8bbD4',
|
||||
DAI: '0x773616E4d11A78F511299002da57A0a94577F1f4',
|
||||
UniDAIWETH: '0xf4071801C4421Db7e63DaC15B9432e50C44a7F42',
|
||||
UniWBTCWETH: '0x55EF7F1226507cFd846DE009C2f097c2211b6Fb8',
|
||||
UniAAVEWETH: '0x5671387d56eAB334A2D65d6D0BB4D907898C7abA',
|
||||
UniBATWETH: '0xA61ca04DF33B72b235a8A28CfB535bb7A5271B70',
|
||||
UniDAIUSDC: '0xFd8dFc92B030e6BA957336e9f08C2a711e19069A',
|
||||
UniCRVWETH: '0xd4D344D076256Fdf806375983b2cab2Db52FD506',
|
||||
UniLINKWETH: '0x8C0e5df19B998F06e57A1Db1a38232F7590abe4b',
|
||||
UniMKRWETH: '0x92f2A28fE33E0b6Ea218057EEe004E3B2B6de45d',
|
||||
UniRENWETH: '0xFc0398b247107138dB494395600fB0d075b72C9A',
|
||||
UniSNXWETH: '0xF5CB13c859383B5fb070bd111Cae7a900c00BA07',
|
||||
UniUNIWETH: '0xE50e47E37DCF55dE1c5F2c32d346BB52064f7CE6',
|
||||
UniUSDCWETH: '0xBE6ac123799572c98eFdE48895465AB392534AFD',
|
||||
UniWBTCUSDC: '0xd6b8b08a0d13994A5f4a1949F4870DE57e9B40d9',
|
||||
UniYFIWETH: '0x94daB35789f05f54224F6851921160DE21318072',
|
||||
BptWBTCWETH: '0x4a2731c9f3B4355922c676f9b538278D79C299C5',
|
||||
BptBALWETH: '0xD9400999f38E1877a6dDDb0090A327F19257f9AE',
|
||||
UniDAIWETH: '0x66a6b87a18db78086acda75b7720dc47cdabcc05',
|
||||
UniWBTCWETH: '0x7004BB6F2013F13C54899309cCa029B49707E547',
|
||||
UniAAVEWETH: '0xB525547968610395B60085bDc8033FFeaEaa5F64',
|
||||
UniBATWETH: '0xB394D8a1CE721630Cbea8Ec110DCEf0D283EDE3a',
|
||||
UniDAIUSDC: '0x3B148Fa5E8297DB64262442052b227328730EA81',
|
||||
UniCRVWETH: '0x10F7078e2f29802D2AC78045F61A69aE0883535A',
|
||||
UniLINKWETH: '0x30adCEfA5d483284FD79E1eFd54ED3e0A8eaA632',
|
||||
UniMKRWETH: '0xEBF4A448ff3D835F8FA883941a3E9D5E74B40B5E',
|
||||
UniRENWETH: '0xe2f7C06906A9dB063C28EB5c71B6Ab454e5222dD',
|
||||
UniSNXWETH: '0x29bfee7E90572Abf1088a58a145a10D051b78E46',
|
||||
UniUNIWETH: '0xC2E93e8121237A885A00627975eB06C7BF9808d6',
|
||||
UniUSDCWETH: '0x71c4a2173CE3620982DC8A7D870297533360Da4E',
|
||||
UniWBTCUSDC: '0x11f4ba2227F21Dc2A9F0b0e6Ea740369d580a212',
|
||||
UniYFIWETH: '0x664223b8Bb0934aE0970e601F452f75AaCe9Aa2A',
|
||||
BptWBTCWETH: '0x4CA8D8fC2b4fCe8A2dcB71Da884bba042d48E067',
|
||||
BptBALWETH: '0x2e4e78936b100be6Ef85BCEf7FB25bC770B02B85',
|
||||
USD: '0x9326BFA02ADD2366b30bacB125260Af641031331',
|
||||
},
|
||||
[eEthereumNetwork.tenderlyMain]: {
|
||||
|
@ -276,22 +276,22 @@ export const CommonsConfig: ICommonConfiguration = {
|
|||
WBTC: '0xdeb288F737066589598e9214E782fa5A8eD689e8',
|
||||
USDC: '0x986b5E1e1755e3C2440e960477f25201B0a8bbD4',
|
||||
DAI: '0x773616E4d11A78F511299002da57A0a94577F1f4',
|
||||
UniDAIWETH: '0xf4071801C4421Db7e63DaC15B9432e50C44a7F42',
|
||||
UniWBTCWETH: '0x55EF7F1226507cFd846DE009C2f097c2211b6Fb8',
|
||||
UniAAVEWETH: '0x5671387d56eAB334A2D65d6D0BB4D907898C7abA',
|
||||
UniBATWETH: '0xA61ca04DF33B72b235a8A28CfB535bb7A5271B70',
|
||||
UniDAIUSDC: '0xFd8dFc92B030e6BA957336e9f08C2a711e19069A',
|
||||
UniCRVWETH: '0xd4D344D076256Fdf806375983b2cab2Db52FD506',
|
||||
UniLINKWETH: '0x8C0e5df19B998F06e57A1Db1a38232F7590abe4b',
|
||||
UniMKRWETH: '0x92f2A28fE33E0b6Ea218057EEe004E3B2B6de45d',
|
||||
UniRENWETH: '0xFc0398b247107138dB494395600fB0d075b72C9A',
|
||||
UniSNXWETH: '0xF5CB13c859383B5fb070bd111Cae7a900c00BA07',
|
||||
UniUNIWETH: '0xE50e47E37DCF55dE1c5F2c32d346BB52064f7CE6',
|
||||
UniUSDCWETH: '0xBE6ac123799572c98eFdE48895465AB392534AFD',
|
||||
UniWBTCUSDC: '0xd6b8b08a0d13994A5f4a1949F4870DE57e9B40d9',
|
||||
UniYFIWETH: '0x94daB35789f05f54224F6851921160DE21318072',
|
||||
BptWBTCWETH: '0x4a2731c9f3B4355922c676f9b538278D79C299C5',
|
||||
BptBALWETH: '0xD9400999f38E1877a6dDDb0090A327F19257f9AE',
|
||||
UniDAIWETH: '0x66a6b87a18db78086acda75b7720dc47cdabcc05',
|
||||
UniWBTCWETH: '0x7004BB6F2013F13C54899309cCa029B49707E547',
|
||||
UniAAVEWETH: '0xB525547968610395B60085bDc8033FFeaEaa5F64',
|
||||
UniBATWETH: '0xB394D8a1CE721630Cbea8Ec110DCEf0D283EDE3a',
|
||||
UniDAIUSDC: '0x3B148Fa5E8297DB64262442052b227328730EA81',
|
||||
UniCRVWETH: '0x10F7078e2f29802D2AC78045F61A69aE0883535A',
|
||||
UniLINKWETH: '0x30adCEfA5d483284FD79E1eFd54ED3e0A8eaA632',
|
||||
UniMKRWETH: '0xEBF4A448ff3D835F8FA883941a3E9D5E74B40B5E',
|
||||
UniRENWETH: '0xe2f7C06906A9dB063C28EB5c71B6Ab454e5222dD',
|
||||
UniSNXWETH: '0x29bfee7E90572Abf1088a58a145a10D051b78E46',
|
||||
UniUNIWETH: '0xC2E93e8121237A885A00627975eB06C7BF9808d6',
|
||||
UniUSDCWETH: '0x71c4a2173CE3620982DC8A7D870297533360Da4E',
|
||||
UniWBTCUSDC: '0x11f4ba2227F21Dc2A9F0b0e6Ea740369d580a212',
|
||||
UniYFIWETH: '0x664223b8Bb0934aE0970e601F452f75AaCe9Aa2A',
|
||||
BptWBTCWETH: '0x4CA8D8fC2b4fCe8A2dcB71Da884bba042d48E067',
|
||||
BptBALWETH: '0x2e4e78936b100be6Ef85BCEf7FB25bC770B02B85',
|
||||
USD: '0x9326BFA02ADD2366b30bacB125260Af641031331',
|
||||
},
|
||||
},
|
||||
|
|
|
@ -191,6 +191,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
|||
WMATIC: mockTokens.WMATIC.address,
|
||||
USD: USD_ADDRESS,
|
||||
STAKE: mockTokens.STAKE.address,
|
||||
xSUSHI: mockTokens.xSUSHI.address
|
||||
},
|
||||
fallbackOracle
|
||||
);
|
||||
|
|
|
@ -42,7 +42,7 @@ makeSuite('Interest rate strategy tests', (testEnv: TestEnv) => {
|
|||
0: currentLiquidityRate,
|
||||
1: currentStableBorrowRate,
|
||||
2: currentVariableBorrowRate,
|
||||
} = await strategyInstance.calculateInterestRates(
|
||||
} = await strategyInstance['calculateInterestRates(address,address,uint256,uint256,uint256,uint256,uint256,uint256)'](
|
||||
dai.address,
|
||||
aDai.address,
|
||||
0,
|
||||
|
@ -69,7 +69,7 @@ makeSuite('Interest rate strategy tests', (testEnv: TestEnv) => {
|
|||
0: currentLiquidityRate,
|
||||
1: currentStableBorrowRate,
|
||||
2: currentVariableBorrowRate,
|
||||
} = await strategyInstance.calculateInterestRates(
|
||||
} = await strategyInstance['calculateInterestRates(address,address,uint256,uint256,uint256,uint256,uint256,uint256)'](
|
||||
dai.address,
|
||||
aDai.address,
|
||||
'200000000000000000',
|
||||
|
@ -108,7 +108,7 @@ makeSuite('Interest rate strategy tests', (testEnv: TestEnv) => {
|
|||
0: currentLiquidityRate,
|
||||
1: currentStableBorrowRate,
|
||||
2: currentVariableBorrowRate,
|
||||
} = await strategyInstance.calculateInterestRates(
|
||||
} = await strategyInstance['calculateInterestRates(address,address,uint256,uint256,uint256,uint256,uint256,uint256)'](
|
||||
dai.address,
|
||||
aDai.address,
|
||||
'0',
|
||||
|
@ -150,7 +150,7 @@ makeSuite('Interest rate strategy tests', (testEnv: TestEnv) => {
|
|||
0: currentLiquidityRate,
|
||||
1: currentStableBorrowRate,
|
||||
2: currentVariableBorrowRate,
|
||||
} = await strategyInstance.calculateInterestRates(
|
||||
} = await strategyInstance['calculateInterestRates(address,address,uint256,uint256,uint256,uint256,uint256,uint256)'](
|
||||
dai.address,
|
||||
aDai.address,
|
||||
'0',
|
||||
|
|
Loading…
Reference in New Issue
Block a user