2020-12-21 16:13:51 +00:00
|
|
|
import { task } from 'hardhat/config';
|
2021-02-23 14:42:47 +00:00
|
|
|
import { eEthereumNetwork } from '../../helpers/types';
|
2020-12-21 16:13:51 +00:00
|
|
|
import { getTreasuryAddress } from '../../helpers/configuration';
|
|
|
|
import * as marketConfigs from '../../markets/aave';
|
|
|
|
import * as reserveConfigs from '../../markets/aave/reservesConfigs';
|
|
|
|
import { chooseATokenDeployment } from '../../helpers/init-helpers';
|
|
|
|
import { getLendingPoolAddressesProvider } from './../../helpers/contracts-getters';
|
|
|
|
import {
|
|
|
|
deployDefaultReserveInterestRateStrategy,
|
|
|
|
deployStableDebtToken,
|
|
|
|
deployVariableDebtToken,
|
|
|
|
} from './../../helpers/contracts-deployments';
|
2020-12-22 09:15:50 +00:00
|
|
|
import { setDRE } from '../../helpers/misc-utils';
|
2020-12-21 16:13:51 +00:00
|
|
|
import { ZERO_ADDRESS } from './../../helpers/constants';
|
|
|
|
|
2020-12-22 09:15:50 +00:00
|
|
|
const LENDING_POOL_ADDRESS_PROVIDER = {
|
|
|
|
main: '0xb53c1a33016b2dc2ff3653530bff1848a515c8c5',
|
|
|
|
kovan: '0x652B2937Efd0B5beA1c8d54293FC1289672AFC6b',
|
|
|
|
};
|
|
|
|
|
2021-02-23 14:42:47 +00:00
|
|
|
const isSymbolValid = (symbol: string, network: eEthereumNetwork) =>
|
2020-12-21 16:13:51 +00:00
|
|
|
Object.keys(reserveConfigs).includes('strategy' + symbol) &&
|
|
|
|
marketConfigs.AaveConfig.ReserveAssets[network][symbol] &&
|
|
|
|
marketConfigs.AaveConfig.ReservesConfig[symbol] === reserveConfigs['strategy' + symbol];
|
|
|
|
|
2020-12-22 09:15:50 +00:00
|
|
|
task('external:deploy-new-asset', 'Deploy A token, Debt Tokens, Risk Parameters')
|
|
|
|
.addParam('symbol', `Asset symbol, needs to have configuration ready`)
|
2020-12-21 16:13:51 +00:00
|
|
|
.addFlag('verify', 'Verify contracts at Etherscan')
|
|
|
|
.setAction(async ({ verify, symbol }, localBRE) => {
|
2020-12-22 09:15:50 +00:00
|
|
|
const network = localBRE.network.name;
|
2021-02-23 14:42:47 +00:00
|
|
|
if (!isSymbolValid(symbol, network as eEthereumNetwork)) {
|
2020-12-21 16:13:51 +00:00
|
|
|
throw new Error(
|
|
|
|
`
|
|
|
|
WRONG RESERVE ASSET SETUP:
|
|
|
|
The symbol ${symbol} has no reserve Config and/or reserve Asset setup.
|
2020-12-22 09:15:50 +00:00
|
|
|
update /markets/aave/index.ts and add the asset address for ${network} network
|
2020-12-21 16:13:51 +00:00
|
|
|
update /markets/aave/reservesConfigs.ts and add parameters for ${symbol}
|
|
|
|
`
|
|
|
|
);
|
|
|
|
}
|
2020-12-22 09:15:50 +00:00
|
|
|
setDRE(localBRE);
|
2020-12-21 16:13:51 +00:00
|
|
|
const strategyParams = reserveConfigs['strategy' + symbol];
|
|
|
|
const reserveAssetAddress =
|
|
|
|
marketConfigs.AaveConfig.ReserveAssets[localBRE.network.name][symbol];
|
|
|
|
const deployCustomAToken = chooseATokenDeployment(strategyParams.aTokenImpl);
|
2020-12-22 09:15:50 +00:00
|
|
|
const addressProvider = await getLendingPoolAddressesProvider(
|
|
|
|
LENDING_POOL_ADDRESS_PROVIDER[network]
|
|
|
|
);
|
2020-12-21 16:13:51 +00:00
|
|
|
const poolAddress = await addressProvider.getLendingPool();
|
|
|
|
const treasuryAddress = await getTreasuryAddress(marketConfigs.AaveConfig);
|
|
|
|
const aToken = await deployCustomAToken(
|
|
|
|
[
|
|
|
|
poolAddress,
|
|
|
|
reserveAssetAddress,
|
|
|
|
treasuryAddress,
|
2021-02-08 21:18:49 +00:00
|
|
|
ZERO_ADDRESS, // Incentives Controller
|
2020-12-21 16:13:51 +00:00
|
|
|
`Aave interest bearing ${symbol}`,
|
|
|
|
`a${symbol}`,
|
|
|
|
],
|
|
|
|
verify
|
|
|
|
);
|
|
|
|
const stableDebt = await deployStableDebtToken(
|
|
|
|
[
|
|
|
|
poolAddress,
|
|
|
|
reserveAssetAddress,
|
2021-02-08 21:18:49 +00:00
|
|
|
ZERO_ADDRESS, // Incentives Controller
|
2020-12-21 16:13:51 +00:00
|
|
|
`Aave stable debt bearing ${symbol}`,
|
|
|
|
`stableDebt${symbol}`,
|
|
|
|
],
|
|
|
|
verify
|
|
|
|
);
|
|
|
|
const variableDebt = await deployVariableDebtToken(
|
|
|
|
[
|
|
|
|
poolAddress,
|
|
|
|
reserveAssetAddress,
|
2021-02-08 21:18:49 +00:00
|
|
|
ZERO_ADDRESS, // Incentives Controller
|
2020-12-21 16:13:51 +00:00
|
|
|
`Aave variable debt bearing ${symbol}`,
|
|
|
|
`variableDebt${symbol}`,
|
|
|
|
],
|
|
|
|
verify
|
|
|
|
);
|
|
|
|
const rates = await deployDefaultReserveInterestRateStrategy(
|
|
|
|
[
|
2020-12-22 10:37:08 +00:00
|
|
|
addressProvider.address,
|
2020-12-21 16:13:51 +00:00
|
|
|
strategyParams.optimalUtilizationRate,
|
|
|
|
strategyParams.baseVariableBorrowRate,
|
|
|
|
strategyParams.variableRateSlope1,
|
|
|
|
strategyParams.variableRateSlope2,
|
|
|
|
strategyParams.stableRateSlope1,
|
|
|
|
strategyParams.stableRateSlope2,
|
|
|
|
],
|
|
|
|
verify
|
|
|
|
);
|
|
|
|
console.log(`
|
2020-12-22 09:15:50 +00:00
|
|
|
New interest bearing asset deployed on ${network}:
|
2020-12-21 16:13:51 +00:00
|
|
|
Interest bearing a${symbol} address: ${aToken.address}
|
|
|
|
Variable Debt variableDebt${symbol} address: ${variableDebt.address}
|
|
|
|
Stable Debt stableDebt${symbol} address: ${stableDebt.address}
|
2020-12-22 09:15:50 +00:00
|
|
|
Strategy Implementation for ${symbol} address: ${rates.address}
|
2020-12-21 16:13:51 +00:00
|
|
|
`);
|
|
|
|
});
|