mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
added task for deploying new asset
This commit is contained in:
parent
eea6d38f24
commit
a3403631be
|
@ -27,7 +27,7 @@ const MAINNET_FORK = process.env.MAINNET_FORK === 'true';
|
|||
|
||||
// Prevent to load scripts before compilation and typechain
|
||||
if (!SKIP_LOAD) {
|
||||
['misc', 'migrations', 'dev', 'full', 'verifications'].forEach((folder) => {
|
||||
['misc', 'migrations', 'dev', 'full', 'verifications', 'helpers'].forEach((folder) => {
|
||||
const tasksPath = path.join(__dirname, 'tasks', folder);
|
||||
fs.readdirSync(tasksPath)
|
||||
.filter((pth) => pth.includes('.ts'))
|
||||
|
|
|
@ -26,7 +26,7 @@ import {
|
|||
import { ZERO_ADDRESS } from './constants';
|
||||
import { isZeroAddress } from 'ethereumjs-util';
|
||||
|
||||
const chooseATokenDeployment = (id: eContractid) => {
|
||||
export const chooseATokenDeployment = (id: eContractid) => {
|
||||
switch (id) {
|
||||
case eContractid.AToken:
|
||||
return deployGenericAToken;
|
||||
|
|
91
tasks/helpers/deploy-new-asset.ts
Normal file
91
tasks/helpers/deploy-new-asset.ts
Normal file
|
@ -0,0 +1,91 @@
|
|||
import { task } from 'hardhat/config';
|
||||
import { EthereumNetwork } from '../../helpers/types';
|
||||
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';
|
||||
import { ZERO_ADDRESS } from './../../helpers/constants';
|
||||
|
||||
const isSymbolValid = (symbol: string, network: EthereumNetwork) =>
|
||||
Object.keys(reserveConfigs).includes('strategy' + symbol) &&
|
||||
marketConfigs.AaveConfig.ReserveAssets[network][symbol] &&
|
||||
marketConfigs.AaveConfig.ReservesConfig[symbol] === reserveConfigs['strategy' + symbol];
|
||||
|
||||
task('external:deploy-new-asset', 'Deploy A token, Debt Token, Risk Parameters')
|
||||
.addParam('symbol', `Asset symbol, needs `)
|
||||
.addFlag('verify', 'Verify contracts at Etherscan')
|
||||
.setAction(async ({ verify, symbol }, localBRE) => {
|
||||
if (!isSymbolValid(symbol, localBRE.network.name as EthereumNetwork)) {
|
||||
throw new Error(
|
||||
`
|
||||
WRONG RESERVE ASSET SETUP:
|
||||
The symbol ${symbol} has no reserve Config and/or reserve Asset setup.
|
||||
update /markets/aave/index.ts and add the asset address for ${localBRE.network.name} network
|
||||
update /markets/aave/reservesConfigs.ts and add parameters for ${symbol}
|
||||
`
|
||||
);
|
||||
}
|
||||
const strategyParams = reserveConfigs['strategy' + symbol];
|
||||
const reserveAssetAddress =
|
||||
marketConfigs.AaveConfig.ReserveAssets[localBRE.network.name][symbol];
|
||||
const deployCustomAToken = chooseATokenDeployment(strategyParams.aTokenImpl);
|
||||
const addressProvider = await getLendingPoolAddressesProvider();
|
||||
const poolAddress = await addressProvider.getLendingPool();
|
||||
const treasuryAddress = await getTreasuryAddress(marketConfigs.AaveConfig);
|
||||
const aToken = await deployCustomAToken(
|
||||
[
|
||||
poolAddress,
|
||||
reserveAssetAddress,
|
||||
treasuryAddress,
|
||||
`Aave interest bearing ${symbol}`,
|
||||
`a${symbol}`,
|
||||
ZERO_ADDRESS,
|
||||
],
|
||||
verify
|
||||
);
|
||||
const stableDebt = await deployStableDebtToken(
|
||||
[
|
||||
poolAddress,
|
||||
reserveAssetAddress,
|
||||
`Aave stable debt bearing ${symbol}`,
|
||||
`stableDebt${symbol}`,
|
||||
ZERO_ADDRESS,
|
||||
],
|
||||
verify
|
||||
);
|
||||
const variableDebt = await deployVariableDebtToken(
|
||||
[
|
||||
poolAddress,
|
||||
reserveAssetAddress,
|
||||
`Aave variable debt bearing ${symbol}`,
|
||||
`variableDebt${symbol}`,
|
||||
ZERO_ADDRESS,
|
||||
],
|
||||
verify
|
||||
);
|
||||
const rates = await deployDefaultReserveInterestRateStrategy(
|
||||
[
|
||||
reserveAssetAddress,
|
||||
strategyParams.optimalUtilizationRate,
|
||||
strategyParams.baseVariableBorrowRate,
|
||||
strategyParams.variableRateSlope1,
|
||||
strategyParams.variableRateSlope2,
|
||||
strategyParams.stableRateSlope1,
|
||||
strategyParams.stableRateSlope2,
|
||||
],
|
||||
verify
|
||||
);
|
||||
console.log(`
|
||||
New interest bearing asset deployed on ${localBRE.network}:
|
||||
Interest bearing a${symbol} address: ${aToken.address}
|
||||
Variable Debt variableDebt${symbol} address: ${variableDebt.address}
|
||||
Stable Debt stableDebt${symbol} address: ${stableDebt.address}
|
||||
Strategy Implementation for ${symbol} address: ${rates}
|
||||
`);
|
||||
});
|
Loading…
Reference in New Issue
Block a user