Updated migration scripts to add the reserve factor configuration

This commit is contained in:
The3D 2020-11-28 12:54:54 +01:00
parent 872eb3ff94
commit 7892587f1b
6 changed files with 49 additions and 104 deletions

View File

@ -31,20 +31,20 @@ contract ATokensAndRatesHelper is Ownable {
}
function initDeployment(
address[] calldata tokens,
address[] calldata assets,
string[] calldata symbols,
uint256[6][] calldata rates,
address treasuryAddress,
address incentivesController
) external onlyOwner {
require(tokens.length == symbols.length, 't Arrays not same length');
require(assets.length == symbols.length, 't Arrays not same length');
require(rates.length == symbols.length, 'r Arrays not same length');
for (uint256 i = 0; i < tokens.length; i++) {
for (uint256 i = 0; i < assets.length; i++) {
emit deployedContracts(
address(
new AToken(
LendingPool(pool),
tokens[i],
assets[i],
treasuryAddress,
StringLib.concat('Aave interest bearing ', symbols[i]),
StringLib.concat('a', symbols[i]),
@ -89,37 +89,38 @@ contract ATokensAndRatesHelper is Ownable {
}
}
function enableReservesAsCollateral(
address[] calldata tokens,
function configureReserves(
address[] calldata assets,
uint256[] calldata baseLTVs,
uint256[] calldata liquidationThresholds,
uint256[] calldata liquidationBonuses
uint256[] calldata liquidationBonuses,
uint256[] calldata reserveFactors,
bool[] calldata stableBorrowingEnabled
) external onlyOwner {
require(baseLTVs.length == tokens.length);
require(liquidationThresholds.length == tokens.length);
require(liquidationBonuses.length == tokens.length);
require(baseLTVs.length == assets.length);
require(liquidationThresholds.length == assets.length);
require(liquidationBonuses.length == assets.length);
require(stableBorrowingEnabled.length == assets.length);
require(reserveFactors.length == assets.length);
for (uint256 i = 0; i < tokens.length; i++) {
LendingPoolConfigurator(poolConfigurator).configureReserveAsCollateral(
tokens[i],
LendingPoolConfigurator configurator = LendingPoolConfigurator(poolConfigurator);
for (uint256 i = 0; i < assets.length; i++) {
configurator.configureReserveAsCollateral(
assets[i],
baseLTVs[i],
liquidationThresholds[i],
liquidationBonuses[i]
);
}
}
function enableBorrowingOnReserves(address[] calldata tokens, bool[] calldata stableBorrowingEnabled)
external
onlyOwner
{
require(stableBorrowingEnabled.length == tokens.length);
for (uint256 i = 0; i < tokens.length; i++) {
LendingPoolConfigurator(poolConfigurator).enableBorrowingOnReserve(
tokens[i],
configurator.enableBorrowingOnReserve(
assets[i],
stableBorrowingEnabled[i]
);
configurator.enableBorrowingOnReserve(
assets[i],
stableBorrowingEnabled[i]
);
configurator.setReserveFactor(assets[i], reserveFactors[i]);
}
}
}

View File

@ -286,74 +286,7 @@ export const getPairsTokenAggregator = (
return [mappedPairs, mappedAggregators];
};
export const enableReservesToBorrowByHelper = async (
reservesParams: iMultiPoolsAssets<IReserveParams>,
tokenAddresses: { [symbol: string]: tEthereumAddress },
helpers: AaveProtocolDataProvider,
admin: tEthereumAddress
) => {
const addressProvider = await getLendingPoolAddressesProvider();
const atokenAndRatesDeployer = await getATokensAndRatesHelper();
const tokens: string[] = [];
const symbols: string[] = [];
const stableEnabled: boolean[] = [];
// Prepare data
for (const [assetSymbol, { borrowingEnabled, stableBorrowRateEnabled }] of Object.entries(
reservesParams
) as [string, IReserveParams][]) {
if (!borrowingEnabled) continue;
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
(value) => value === assetSymbol
);
const [, tokenAddress] = (Object.entries(tokenAddresses) as [string, string][])[
assetAddressIndex
];
const { borrowingEnabled: borrowingAlreadyEnabled } = await helpers.getReserveConfigurationData(
tokenAddress
);
if (borrowingAlreadyEnabled) {
console.log(`Reserve ${assetSymbol} is already enabled for borrowing, skipping`);
continue;
}
tokens.push(tokenAddress);
stableEnabled.push(stableBorrowRateEnabled);
symbols.push(assetSymbol);
}
if (tokens.length) {
// Set aTokenAndRatesDeployer as temporal admin
await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address));
// Deploy init per chunks
const stableChunks = 20;
const chunkedTokens = chunk(tokens, stableChunks);
const chunkedSymbols = chunk(symbols, stableChunks);
const chunkedStableEnabled = chunk(stableEnabled, stableChunks);
console.log(`- Borrow stable initialization in ${chunkedTokens.length} txs`);
for (let chunkIndex = 0; chunkIndex < chunkedTokens.length; chunkIndex++) {
try {
await waitForTx(
await atokenAndRatesDeployer.enableBorrowingOnReserves(
chunkedTokens[chunkIndex],
chunkedStableEnabled[chunkIndex],
{ gasLimit: 12000000 }
)
);
} catch (error) {
console.error(error);
throw error;
}
console.log(` - Init for: ${chunkedSymbols[chunkIndex].join(', ')}`);
}
// Set deployer back as admin
await waitForTx(await addressProvider.setPoolAdmin(admin));
}
};
export const enableReservesAsCollateralByHelper = async (
export const configureReservesByHelper = async (
reservesParams: iMultiPoolsAssets<IReserveParams>,
tokenAddresses: { [symbol: string]: tEthereumAddress },
helpers: AaveProtocolDataProvider,
@ -366,10 +299,12 @@ export const enableReservesAsCollateralByHelper = async (
const baseLTVA: string[] = [];
const liquidationThresholds: string[] = [];
const liquidationBonuses: string[] = [];
const reserveFactors: string[] = [];
const stableRatesEnabled: boolean[] = [];
for (const [
assetSymbol,
{ baseLTVAsCollateral, liquidationBonus, liquidationThreshold },
{ baseLTVAsCollateral, liquidationBonus, liquidationThreshold, reserveFactor, stableBorrowRateEnabled },
] of Object.entries(reservesParams) as [string, IReserveParams][]) {
if (baseLTVAsCollateral === '-1') continue;
@ -393,6 +328,8 @@ export const enableReservesAsCollateralByHelper = async (
baseLTVA.push(baseLTVAsCollateral);
liquidationThresholds.push(liquidationThreshold);
liquidationBonuses.push(liquidationBonus);
reserveFactors.push(reserveFactor);
stableRatesEnabled.push(stableBorrowRateEnabled);
}
if (tokens.length) {
// Set aTokenAndRatesDeployer as temporal admin
@ -405,15 +342,19 @@ export const enableReservesAsCollateralByHelper = async (
const chunkedBase = chunk(baseLTVA, enableChunks);
const chunkedliquidationThresholds = chunk(liquidationThresholds, enableChunks);
const chunkedliquidationBonuses = chunk(liquidationBonuses, enableChunks);
const chunkedReserveFactors = chunk(reserveFactors, enableChunks);
const chunkedStableRatesEnabled = chunk(stableRatesEnabled, enableChunks);
console.log(`- Enable reserve as collateral in ${chunkedTokens.length} txs`);
console.log(`- Configure reserves in ${chunkedTokens.length} txs`);
for (let chunkIndex = 0; chunkIndex < chunkedTokens.length; chunkIndex++) {
await waitForTx(
await atokenAndRatesDeployer.enableReservesAsCollateral(
await atokenAndRatesDeployer.configureReserves(
chunkedTokens[chunkIndex],
chunkedBase[chunkIndex],
chunkedliquidationThresholds[chunkIndex],
chunkedliquidationBonuses[chunkIndex],
chunkedReserveFactors[chunkIndex],
chunkedStableRatesEnabled[chunkIndex],
{ gasLimit: 12000000 }
)
);

View File

@ -262,6 +262,7 @@ export enum TokenContractId {
export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {
aTokenImpl: eContractid;
reserveFactor: string;
}
export interface IReserveBorrowParams {

View File

@ -16,6 +16,7 @@ export const strategyBase: IReserveParams = {
stableBorrowRateEnabled: true,
reserveDecimals: '18',
aTokenImpl: eContractid.AToken,
reserveFactor: '1000'
};
export const stablecoinStrategyBase: IReserveParams = {
@ -32,6 +33,7 @@ export const stablecoinStrategyBase: IReserveParams = {
stableBorrowRateEnabled: true,
reserveDecimals: '18',
aTokenImpl: eContractid.AToken,
reserveFactor: '1000'
};
export const stablecoinStrategyCentralized: IReserveParams = {
@ -48,6 +50,7 @@ export const stablecoinStrategyCentralized: IReserveParams = {
stableBorrowRateEnabled: true,
reserveDecimals: '6',
aTokenImpl: eContractid.AToken,
reserveFactor: '1000'
};
export const strategyGovernanceTokens: IReserveParams = {
@ -136,6 +139,7 @@ export const stablecoinStrategySUSD: IReserveParams = {
stableBorrowRateEnabled: false,
reserveDecimals: '18',
aTokenImpl: eContractid.AToken,
reserveFactor: '1000'
};
export const strategySNX: IReserveParams = {
@ -196,6 +200,7 @@ export const strategyWBTC: IReserveParams = {
stableBorrowRateEnabled: true,
reserveDecimals: '8',
aTokenImpl: eContractid.AToken,
reserveFactor: '1000'
};
export const strategyWETH: IReserveParams = {
@ -212,6 +217,7 @@ export const strategyWETH: IReserveParams = {
stableBorrowRateEnabled: true,
reserveDecimals: '18',
aTokenImpl: eContractid.AToken,
reserveFactor: '1000'
};
export const strategyYFI: IReserveParams = {

View File

@ -11,8 +11,7 @@ import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types';
import { waitForTx } from '../../helpers/misc-utils';
import {
initReservesByHelper,
enableReservesToBorrowByHelper,
enableReservesAsCollateralByHelper,
configureReservesByHelper,
} from '../../helpers/init-helpers';
import { exit } from 'process';
import {
@ -45,8 +44,7 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
const treasuryAddress = await getTreasuryAddress(poolConfig);
await initReservesByHelper(ReservesConfig, reserveAssets, admin, treasuryAddress, ZERO_ADDRESS, verify);
await enableReservesToBorrowByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
await enableReservesAsCollateralByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
const collateralManager = await deployLendingPoolCollateralManager(verify);
await waitForTx(

View File

@ -37,8 +37,7 @@ import {
import { DRE, waitForTx } from '../helpers/misc-utils';
import {
initReservesByHelper,
enableReservesToBorrowByHelper,
enableReservesAsCollateralByHelper,
configureReservesByHelper,
} from '../helpers/init-helpers';
import AaveConfig from '../markets/aave';
import { ZERO_ADDRESS } from '../helpers/constants';
@ -215,8 +214,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const treasuryAddress = await getTreasuryAddress(config);
await initReservesByHelper(reservesParams, allReservesAddresses, admin, treasuryAddress, ZERO_ADDRESS, false);
await enableReservesToBorrowByHelper(reservesParams, allReservesAddresses, testHelpers, admin);
await enableReservesAsCollateralByHelper(
await configureReservesByHelper(
reservesParams,
allReservesAddresses,
testHelpers,