From 5d6332d6eac7150bff2188fb49ec793df3780edb Mon Sep 17 00:00:00 2001 From: dangerousfood Date: Tue, 2 Feb 2021 16:06:01 -0600 Subject: [PATCH 1/3] add xSushi --- helpers/types.ts | 3 +++ markets/aave/commons.ts | 1 + markets/aave/index.ts | 4 ++++ markets/aave/reservesConfigs.ts | 17 +++++++++++++++++ 4 files changed, 25 insertions(+) diff --git a/helpers/types.ts b/helpers/types.ts index 7b2e6662..cf9bb815 100644 --- a/helpers/types.ts +++ b/helpers/types.ts @@ -203,6 +203,7 @@ export interface iAssetBase { USD: T; REN: T; ENJ: T; + xSUSHI: T; } export type iAssetsWithoutETH = Omit, 'ETH'>; @@ -231,6 +232,7 @@ export type iAavePoolAssets = Pick< | 'UNI' | 'REN' | 'ENJ' + | 'xSUSHI' >; export type iMultiPoolsAssets = iAssetCommon | iAavePoolAssets; @@ -261,6 +263,7 @@ export enum TokenContractId { YFI = 'YFI', UNI = 'UNI', ENJ = 'ENJ', + xSUSHI = 'xSUSHI' } export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams { diff --git a/markets/aave/commons.ts b/markets/aave/commons.ts index f2fdb6f3..6833e67f 100644 --- a/markets/aave/commons.ts +++ b/markets/aave/commons.ts @@ -23,6 +23,7 @@ const MOCK_CHAINLINK_AGGREGATORS_PRICES = { WBTC: oneEther.multipliedBy('47.332685').toFixed(), YFI: oneEther.multipliedBy('22.407436').toFixed(), ZRX: oneEther.multipliedBy('0.001151').toFixed(), + xSUSHI: oneEther.multipliedBy('0.00913428586').toFixed(), USD: '5848466240000000', }; // ---------------- diff --git a/markets/aave/index.ts b/markets/aave/index.ts index eefcdd3b..d60db80f 100644 --- a/markets/aave/index.ts +++ b/markets/aave/index.ts @@ -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', }, [EthereumNetwork.tenderlyMain]: { AAVE: '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9', @@ -145,6 +148,7 @@ export const AaveConfig: IAaveConfiguration = { WETH: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', YFI: '0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e', ZRX: '0xE41d2489571d322189246DaFA5ebDe1F4699F498', + xSUSHI: '0x8798249c2E607446EfB7Ad49eC89dD1865Ff4272', }, }, }; diff --git a/markets/aave/reservesConfigs.ts b/markets/aave/reservesConfigs.ts index 68ec93d6..30f094ac 100644 --- a/markets/aave/reservesConfigs.ts +++ b/markets/aave/reservesConfigs.ts @@ -340,4 +340,21 @@ export const strategyZRX: IReserveParams = { reserveDecimals: '18', aTokenImpl: eContractid.AToken, reserveFactor: '2000' +}; + +export const strategyXSUSHI: IReserveParams = { + 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', + baseLTVAsCollateral: '2500', + liquidationThreshold: '4500', + liquidationBonus: '11500', + borrowingEnabled: true, + stableBorrowRateEnabled: false, + reserveDecimals: '18', + aTokenImpl: eContractid.AToken, + reserveFactor: '3500', }; \ No newline at end of file From 7f44a0c2422cf08290a7a35b5652b5ef43d4d22f Mon Sep 17 00:00:00 2001 From: The3D Date: Fri, 5 Mar 2021 10:36:55 +0100 Subject: [PATCH 2/3] Removed unused param in struct --- .../IReserveInterestRateStrategy.sol | 16 +++++ .../DefaultReserveInterestRateStrategy.sol | 68 +++++++++++++++---- test-suites/test-aave/rate-strategy.spec.ts | 8 +-- 3 files changed, 75 insertions(+), 17 deletions(-) diff --git a/contracts/interfaces/IReserveInterestRateStrategy.sol b/contracts/interfaces/IReserveInterestRateStrategy.sol index 70eb99ee..cee593cb 100644 --- a/contracts/interfaces/IReserveInterestRateStrategy.sol +++ b/contracts/interfaces/IReserveInterestRateStrategy.sol @@ -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, diff --git a/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol b/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol index 2863a3cb..af4db241 100644 --- a/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol +++ b/contracts/protocol/lendingpool/DefaultReserveInterestRateStrategy.sol @@ -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); diff --git a/test-suites/test-aave/rate-strategy.spec.ts b/test-suites/test-aave/rate-strategy.spec.ts index 83021e97..6961f8b5 100644 --- a/test-suites/test-aave/rate-strategy.spec.ts +++ b/test-suites/test-aave/rate-strategy.spec.ts @@ -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', From 671a6878bfc61d6b5b33a063ea3276d1405213c7 Mon Sep 17 00:00:00 2001 From: David Racero Date: Wed, 10 Mar 2021 18:17:52 +0100 Subject: [PATCH 3/3] Update LP oracles with latest oracle interface --- hardhat.config.ts | 2 +- markets/amm/commons.ts | 64 +++++++++++++++++++++--------------------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/hardhat.config.ts b/hardhat.config.ts index 0c6fa1e1..234be8f2 100644 --- a/hardhat.config.ts +++ b/hardhat.config.ts @@ -58,7 +58,7 @@ const getCommonNetworkConfig = (networkName: eNetwork, networkId: number) => ({ const mainnetFork = MAINNET_FORK ? { - blockNumber: 11739065, + blockNumber: 12012081, url: NETWORKS_RPC_URL['main'], } : undefined; diff --git a/markets/amm/commons.ts b/markets/amm/commons.ts index b892064d..3a676eda 100644 --- a/markets/amm/commons.ts +++ b/markets/amm/commons.ts @@ -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', }, },