mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Updated migration scripts to add the reserve factor configuration
This commit is contained in:
parent
872eb3ff94
commit
7892587f1b
|
@ -31,20 +31,20 @@ contract ATokensAndRatesHelper is Ownable {
|
||||||
}
|
}
|
||||||
|
|
||||||
function initDeployment(
|
function initDeployment(
|
||||||
address[] calldata tokens,
|
address[] calldata assets,
|
||||||
string[] calldata symbols,
|
string[] calldata symbols,
|
||||||
uint256[6][] calldata rates,
|
uint256[6][] calldata rates,
|
||||||
address treasuryAddress,
|
address treasuryAddress,
|
||||||
address incentivesController
|
address incentivesController
|
||||||
) external onlyOwner {
|
) 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');
|
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(
|
emit deployedContracts(
|
||||||
address(
|
address(
|
||||||
new AToken(
|
new AToken(
|
||||||
LendingPool(pool),
|
LendingPool(pool),
|
||||||
tokens[i],
|
assets[i],
|
||||||
treasuryAddress,
|
treasuryAddress,
|
||||||
StringLib.concat('Aave interest bearing ', symbols[i]),
|
StringLib.concat('Aave interest bearing ', symbols[i]),
|
||||||
StringLib.concat('a', symbols[i]),
|
StringLib.concat('a', symbols[i]),
|
||||||
|
@ -89,37 +89,38 @@ contract ATokensAndRatesHelper is Ownable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function enableReservesAsCollateral(
|
function configureReserves(
|
||||||
address[] calldata tokens,
|
address[] calldata assets,
|
||||||
uint256[] calldata baseLTVs,
|
uint256[] calldata baseLTVs,
|
||||||
uint256[] calldata liquidationThresholds,
|
uint256[] calldata liquidationThresholds,
|
||||||
uint256[] calldata liquidationBonuses
|
uint256[] calldata liquidationBonuses,
|
||||||
|
uint256[] calldata reserveFactors,
|
||||||
|
bool[] calldata stableBorrowingEnabled
|
||||||
) external onlyOwner {
|
) external onlyOwner {
|
||||||
require(baseLTVs.length == tokens.length);
|
require(baseLTVs.length == assets.length);
|
||||||
require(liquidationThresholds.length == tokens.length);
|
require(liquidationThresholds.length == assets.length);
|
||||||
require(liquidationBonuses.length == tokens.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 configurator = LendingPoolConfigurator(poolConfigurator);
|
||||||
LendingPoolConfigurator(poolConfigurator).configureReserveAsCollateral(
|
for (uint256 i = 0; i < assets.length; i++) {
|
||||||
tokens[i],
|
configurator.configureReserveAsCollateral(
|
||||||
|
assets[i],
|
||||||
baseLTVs[i],
|
baseLTVs[i],
|
||||||
liquidationThresholds[i],
|
liquidationThresholds[i],
|
||||||
liquidationBonuses[i]
|
liquidationBonuses[i]
|
||||||
);
|
);
|
||||||
}
|
configurator.enableBorrowingOnReserve(
|
||||||
}
|
assets[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],
|
|
||||||
stableBorrowingEnabled[i]
|
stableBorrowingEnabled[i]
|
||||||
);
|
);
|
||||||
|
|
||||||
|
configurator.enableBorrowingOnReserve(
|
||||||
|
assets[i],
|
||||||
|
stableBorrowingEnabled[i]
|
||||||
|
);
|
||||||
|
configurator.setReserveFactor(assets[i], reserveFactors[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -286,74 +286,7 @@ export const getPairsTokenAggregator = (
|
||||||
return [mappedPairs, mappedAggregators];
|
return [mappedPairs, mappedAggregators];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const enableReservesToBorrowByHelper = async (
|
export const configureReservesByHelper = 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 (
|
|
||||||
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
||||||
tokenAddresses: { [symbol: string]: tEthereumAddress },
|
tokenAddresses: { [symbol: string]: tEthereumAddress },
|
||||||
helpers: AaveProtocolDataProvider,
|
helpers: AaveProtocolDataProvider,
|
||||||
|
@ -366,10 +299,12 @@ export const enableReservesAsCollateralByHelper = async (
|
||||||
const baseLTVA: string[] = [];
|
const baseLTVA: string[] = [];
|
||||||
const liquidationThresholds: string[] = [];
|
const liquidationThresholds: string[] = [];
|
||||||
const liquidationBonuses: string[] = [];
|
const liquidationBonuses: string[] = [];
|
||||||
|
const reserveFactors: string[] = [];
|
||||||
|
const stableRatesEnabled: boolean[] = [];
|
||||||
|
|
||||||
for (const [
|
for (const [
|
||||||
assetSymbol,
|
assetSymbol,
|
||||||
{ baseLTVAsCollateral, liquidationBonus, liquidationThreshold },
|
{ baseLTVAsCollateral, liquidationBonus, liquidationThreshold, reserveFactor, stableBorrowRateEnabled },
|
||||||
] of Object.entries(reservesParams) as [string, IReserveParams][]) {
|
] of Object.entries(reservesParams) as [string, IReserveParams][]) {
|
||||||
if (baseLTVAsCollateral === '-1') continue;
|
if (baseLTVAsCollateral === '-1') continue;
|
||||||
|
|
||||||
|
@ -393,6 +328,8 @@ export const enableReservesAsCollateralByHelper = async (
|
||||||
baseLTVA.push(baseLTVAsCollateral);
|
baseLTVA.push(baseLTVAsCollateral);
|
||||||
liquidationThresholds.push(liquidationThreshold);
|
liquidationThresholds.push(liquidationThreshold);
|
||||||
liquidationBonuses.push(liquidationBonus);
|
liquidationBonuses.push(liquidationBonus);
|
||||||
|
reserveFactors.push(reserveFactor);
|
||||||
|
stableRatesEnabled.push(stableBorrowRateEnabled);
|
||||||
}
|
}
|
||||||
if (tokens.length) {
|
if (tokens.length) {
|
||||||
// Set aTokenAndRatesDeployer as temporal admin
|
// Set aTokenAndRatesDeployer as temporal admin
|
||||||
|
@ -405,15 +342,19 @@ export const enableReservesAsCollateralByHelper = async (
|
||||||
const chunkedBase = chunk(baseLTVA, enableChunks);
|
const chunkedBase = chunk(baseLTVA, enableChunks);
|
||||||
const chunkedliquidationThresholds = chunk(liquidationThresholds, enableChunks);
|
const chunkedliquidationThresholds = chunk(liquidationThresholds, enableChunks);
|
||||||
const chunkedliquidationBonuses = chunk(liquidationBonuses, 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++) {
|
for (let chunkIndex = 0; chunkIndex < chunkedTokens.length; chunkIndex++) {
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await atokenAndRatesDeployer.enableReservesAsCollateral(
|
await atokenAndRatesDeployer.configureReserves(
|
||||||
chunkedTokens[chunkIndex],
|
chunkedTokens[chunkIndex],
|
||||||
chunkedBase[chunkIndex],
|
chunkedBase[chunkIndex],
|
||||||
chunkedliquidationThresholds[chunkIndex],
|
chunkedliquidationThresholds[chunkIndex],
|
||||||
chunkedliquidationBonuses[chunkIndex],
|
chunkedliquidationBonuses[chunkIndex],
|
||||||
|
chunkedReserveFactors[chunkIndex],
|
||||||
|
chunkedStableRatesEnabled[chunkIndex],
|
||||||
{ gasLimit: 12000000 }
|
{ gasLimit: 12000000 }
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -262,6 +262,7 @@ export enum TokenContractId {
|
||||||
|
|
||||||
export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {
|
export interface IReserveParams extends IReserveBorrowParams, IReserveCollateralParams {
|
||||||
aTokenImpl: eContractid;
|
aTokenImpl: eContractid;
|
||||||
|
reserveFactor: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IReserveBorrowParams {
|
export interface IReserveBorrowParams {
|
||||||
|
|
|
@ -16,6 +16,7 @@ export const strategyBase: IReserveParams = {
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '18',
|
reserveDecimals: '18',
|
||||||
aTokenImpl: eContractid.AToken,
|
aTokenImpl: eContractid.AToken,
|
||||||
|
reserveFactor: '1000'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const stablecoinStrategyBase: IReserveParams = {
|
export const stablecoinStrategyBase: IReserveParams = {
|
||||||
|
@ -32,6 +33,7 @@ export const stablecoinStrategyBase: IReserveParams = {
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '18',
|
reserveDecimals: '18',
|
||||||
aTokenImpl: eContractid.AToken,
|
aTokenImpl: eContractid.AToken,
|
||||||
|
reserveFactor: '1000'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const stablecoinStrategyCentralized: IReserveParams = {
|
export const stablecoinStrategyCentralized: IReserveParams = {
|
||||||
|
@ -48,6 +50,7 @@ export const stablecoinStrategyCentralized: IReserveParams = {
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '6',
|
reserveDecimals: '6',
|
||||||
aTokenImpl: eContractid.AToken,
|
aTokenImpl: eContractid.AToken,
|
||||||
|
reserveFactor: '1000'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const strategyGovernanceTokens: IReserveParams = {
|
export const strategyGovernanceTokens: IReserveParams = {
|
||||||
|
@ -136,6 +139,7 @@ export const stablecoinStrategySUSD: IReserveParams = {
|
||||||
stableBorrowRateEnabled: false,
|
stableBorrowRateEnabled: false,
|
||||||
reserveDecimals: '18',
|
reserveDecimals: '18',
|
||||||
aTokenImpl: eContractid.AToken,
|
aTokenImpl: eContractid.AToken,
|
||||||
|
reserveFactor: '1000'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const strategySNX: IReserveParams = {
|
export const strategySNX: IReserveParams = {
|
||||||
|
@ -196,6 +200,7 @@ export const strategyWBTC: IReserveParams = {
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '8',
|
reserveDecimals: '8',
|
||||||
aTokenImpl: eContractid.AToken,
|
aTokenImpl: eContractid.AToken,
|
||||||
|
reserveFactor: '1000'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const strategyWETH: IReserveParams = {
|
export const strategyWETH: IReserveParams = {
|
||||||
|
@ -212,6 +217,7 @@ export const strategyWETH: IReserveParams = {
|
||||||
stableBorrowRateEnabled: true,
|
stableBorrowRateEnabled: true,
|
||||||
reserveDecimals: '18',
|
reserveDecimals: '18',
|
||||||
aTokenImpl: eContractid.AToken,
|
aTokenImpl: eContractid.AToken,
|
||||||
|
reserveFactor: '1000'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const strategyYFI: IReserveParams = {
|
export const strategyYFI: IReserveParams = {
|
||||||
|
|
|
@ -11,8 +11,7 @@ import { eEthereumNetwork, ICommonConfiguration } from '../../helpers/types';
|
||||||
import { waitForTx } from '../../helpers/misc-utils';
|
import { waitForTx } from '../../helpers/misc-utils';
|
||||||
import {
|
import {
|
||||||
initReservesByHelper,
|
initReservesByHelper,
|
||||||
enableReservesToBorrowByHelper,
|
configureReservesByHelper,
|
||||||
enableReservesAsCollateralByHelper,
|
|
||||||
} from '../../helpers/init-helpers';
|
} from '../../helpers/init-helpers';
|
||||||
import { exit } from 'process';
|
import { exit } from 'process';
|
||||||
import {
|
import {
|
||||||
|
@ -45,8 +44,7 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
|
||||||
const treasuryAddress = await getTreasuryAddress(poolConfig);
|
const treasuryAddress = await getTreasuryAddress(poolConfig);
|
||||||
|
|
||||||
await initReservesByHelper(ReservesConfig, reserveAssets, admin, treasuryAddress, ZERO_ADDRESS, verify);
|
await initReservesByHelper(ReservesConfig, reserveAssets, admin, treasuryAddress, ZERO_ADDRESS, verify);
|
||||||
await enableReservesToBorrowByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
|
await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
|
||||||
await enableReservesAsCollateralByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
|
|
||||||
|
|
||||||
const collateralManager = await deployLendingPoolCollateralManager(verify);
|
const collateralManager = await deployLendingPoolCollateralManager(verify);
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
|
|
|
@ -37,8 +37,7 @@ import {
|
||||||
import { DRE, waitForTx } from '../helpers/misc-utils';
|
import { DRE, waitForTx } from '../helpers/misc-utils';
|
||||||
import {
|
import {
|
||||||
initReservesByHelper,
|
initReservesByHelper,
|
||||||
enableReservesToBorrowByHelper,
|
configureReservesByHelper,
|
||||||
enableReservesAsCollateralByHelper,
|
|
||||||
} from '../helpers/init-helpers';
|
} from '../helpers/init-helpers';
|
||||||
import AaveConfig from '../markets/aave';
|
import AaveConfig from '../markets/aave';
|
||||||
import { ZERO_ADDRESS } from '../helpers/constants';
|
import { ZERO_ADDRESS } from '../helpers/constants';
|
||||||
|
@ -215,8 +214,7 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
const treasuryAddress = await getTreasuryAddress(config);
|
const treasuryAddress = await getTreasuryAddress(config);
|
||||||
|
|
||||||
await initReservesByHelper(reservesParams, allReservesAddresses, admin, treasuryAddress, ZERO_ADDRESS, false);
|
await initReservesByHelper(reservesParams, allReservesAddresses, admin, treasuryAddress, ZERO_ADDRESS, false);
|
||||||
await enableReservesToBorrowByHelper(reservesParams, allReservesAddresses, testHelpers, admin);
|
await configureReservesByHelper(
|
||||||
await enableReservesAsCollateralByHelper(
|
|
||||||
reservesParams,
|
reservesParams,
|
||||||
allReservesAddresses,
|
allReservesAddresses,
|
||||||
testHelpers,
|
testHelpers,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user