mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
Added initialize task
This commit is contained in:
parent
54d9e3a7ee
commit
82ee09caef
|
@ -110,7 +110,7 @@
|
|||
},
|
||||
"DefaultReserveInterestRateStrategy": {
|
||||
"buidlerevm": {
|
||||
"address": "0x830bceA96E56DBC1F8578f75fBaC0AF16B32A07d",
|
||||
"address": "0xE91bBe8ee03560E3dda2786f95335F5399813Ca0",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
},
|
||||
"localhost": {
|
||||
|
@ -146,7 +146,7 @@
|
|||
},
|
||||
"TokenDistributor": {
|
||||
"buidlerevm": {
|
||||
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
|
||||
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
|
||||
},
|
||||
"localhost": {
|
||||
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
|
||||
|
@ -154,7 +154,7 @@
|
|||
},
|
||||
"InitializableAdminUpgradeabilityProxy": {
|
||||
"buidlerevm": {
|
||||
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4",
|
||||
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
},
|
||||
"localhost": {
|
||||
|
@ -164,7 +164,7 @@
|
|||
},
|
||||
"MockFlashLoanReceiver": {
|
||||
"buidlerevm": {
|
||||
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
|
||||
"address": "0xEBAB67ee3ef604D5c250A53b4b8fcbBC6ec3007C"
|
||||
},
|
||||
"localhost": {
|
||||
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
|
||||
|
@ -172,7 +172,7 @@
|
|||
},
|
||||
"WalletBalanceProvider": {
|
||||
"buidlerevm": {
|
||||
"address": "0x392E5355a0e88Bd394F717227c752670fb3a8020",
|
||||
"address": "0xBE36BE5680244Ae1A6F983E4A6f6E1c142cdAbe3",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
},
|
||||
"localhost": {
|
||||
|
@ -412,7 +412,7 @@
|
|||
},
|
||||
"AaveProtocolTestHelpers": {
|
||||
"buidlerevm": {
|
||||
"address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460"
|
||||
"address": "0xD67ba212bA61226DF3d20B2bD92deD3A6770f32d"
|
||||
},
|
||||
"localhost": {
|
||||
"address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460"
|
||||
|
@ -420,7 +420,7 @@
|
|||
},
|
||||
"StableDebtToken": {
|
||||
"buidlerevm": {
|
||||
"address": "0xA0AB1cB92A4AF81f84dCd258155B5c25D247b54E",
|
||||
"address": "0x3870a14c5057f596e385ea21537792fE4fF4C1BE",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
},
|
||||
"localhost": {
|
||||
|
@ -430,7 +430,7 @@
|
|||
},
|
||||
"VariableDebtToken": {
|
||||
"buidlerevm": {
|
||||
"address": "0x5f7134cd38C826a7649f9Cc47dda24d834DD2967",
|
||||
"address": "0x4977FC58783ceBCC310311C800B786EcAf45F98f",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
},
|
||||
"localhost": {
|
||||
|
@ -444,7 +444,7 @@
|
|||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
},
|
||||
"buidlerevm": {
|
||||
"address": "0xE91bBe8ee03560E3dda2786f95335F5399813Ca0",
|
||||
"address": "0x32eF223A01fB55Fd862E6E30d5F4A3b2d44f9586",
|
||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
},
|
||||
|
@ -488,4 +488,4 @@
|
|||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -218,24 +218,51 @@ export const deployPriceOracle = async (verify?: boolean) => {
|
|||
return instance;
|
||||
};
|
||||
|
||||
export const deployMockAggregator = async (price: tStringTokenSmallUnits) =>
|
||||
await deployContract<MockAggregator>(eContractid.MockAggregator, [price]);
|
||||
export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify?: boolean) => {
|
||||
const args = [price];
|
||||
const instance = await deployContract<MockAggregator>(eContractid.MockAggregator, args);
|
||||
if (verify) {
|
||||
await verifyContract(eContractid.MockAggregator, instance.address, args);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const deployChainlinkProxyPriceProvider = async ([
|
||||
assetsAddresses,
|
||||
sourcesAddresses,
|
||||
fallbackOracleAddress,
|
||||
]: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress]) =>
|
||||
await deployContract<MockAggregator>(eContractid.ChainlinkProxyPriceProvider, [
|
||||
assetsAddresses,
|
||||
sourcesAddresses,
|
||||
fallbackOracleAddress,
|
||||
]);
|
||||
export const deployChainlinkProxyPriceProvider = async (
|
||||
[assetsAddresses, sourcesAddresses, fallbackOracleAddress]: [
|
||||
tEthereumAddress[],
|
||||
tEthereumAddress[],
|
||||
tEthereumAddress
|
||||
],
|
||||
verify?: boolean
|
||||
) => {
|
||||
const args = [assetsAddresses, sourcesAddresses, fallbackOracleAddress];
|
||||
const instance = await deployContract<MockAggregator>(
|
||||
eContractid.ChainlinkProxyPriceProvider,
|
||||
args
|
||||
);
|
||||
if (verify) {
|
||||
await verifyContract(eContractid.MockAggregator, instance.address, args);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const deployLendingRateOracle = async () =>
|
||||
await deployContract<LendingRateOracle>(eContractid.LendingRateOracle, []);
|
||||
export const getChainlingProxyPriceProvider = async (address?: tEthereumAddress) =>
|
||||
await getContract<MockAggregator>(
|
||||
eContractid.ChainlinkProxyPriceProvider,
|
||||
address ||
|
||||
(await getDb().get(`${eContractid.ChainlinkProxyPriceProvider}.${BRE.network.name}`).value())
|
||||
.address
|
||||
);
|
||||
|
||||
export const deployLendingPoolLiquidationManager = async () => {
|
||||
export const deployLendingRateOracle = async (verify?: boolean) => {
|
||||
const instance = await deployContract<LendingRateOracle>(eContractid.LendingRateOracle, []);
|
||||
if (verify) {
|
||||
await verifyContract(eContractid.LendingRateOracle, instance.address, []);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const deployLendingPoolLiquidationManager = async (verify?: boolean) => {
|
||||
const liquidationManagerArtifact = await readArtifact(
|
||||
BRE.config.paths.artifacts,
|
||||
eContractid.LendingPoolLiquidationManager
|
||||
|
@ -247,29 +274,70 @@ export const deployLendingPoolLiquidationManager = async () => {
|
|||
return (await liquidationManager.deployed()) as LendingPoolLiquidationManager;
|
||||
};
|
||||
|
||||
export const deployTokenDistributor = async () =>
|
||||
await deployContract<TokenDistributor>(eContractid.TokenDistributor, []);
|
||||
export const deployTokenDistributor = async (verify?: boolean) => {
|
||||
const instance = await deployContract<TokenDistributor>(eContractid.TokenDistributor, []);
|
||||
if (verify) {
|
||||
await verifyContract(eContractid.TokenDistributor, instance.address, []);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const deployInitializableAdminUpgradeabilityProxy = async () =>
|
||||
await deployContract<InitializableAdminUpgradeabilityProxy>(
|
||||
export const deployInitializableAdminUpgradeabilityProxy = async (verify?: boolean) => {
|
||||
const instance = await deployContract<InitializableAdminUpgradeabilityProxy>(
|
||||
eContractid.InitializableAdminUpgradeabilityProxy,
|
||||
[]
|
||||
);
|
||||
if (verify) {
|
||||
await verifyContract(eContractid.InitializableAdminUpgradeabilityProxy, instance.address, []);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const deployMockFlashLoanReceiver = async (addressesProvider: tEthereumAddress) =>
|
||||
await deployContract<MockFlashLoanReceiver>(eContractid.MockFlashLoanReceiver, [
|
||||
addressesProvider,
|
||||
]);
|
||||
export const deployMockFlashLoanReceiver = async (
|
||||
addressesProvider: tEthereumAddress,
|
||||
verify?: boolean
|
||||
) => {
|
||||
const args = [addressesProvider];
|
||||
const instance = await deployContract<MockFlashLoanReceiver>(
|
||||
eContractid.MockFlashLoanReceiver,
|
||||
args
|
||||
);
|
||||
if (verify) {
|
||||
await verifyContract(eContractid.MockFlashLoanReceiver, instance.address, args);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const deployWalletBalancerProvider = async (addressesProvider: tEthereumAddress) =>
|
||||
await deployContract<WalletBalanceProvider>(eContractid.WalletBalanceProvider, [
|
||||
addressesProvider,
|
||||
]);
|
||||
export const deployWalletBalancerProvider = async (
|
||||
addressesProvider: tEthereumAddress,
|
||||
verify?: boolean
|
||||
) => {
|
||||
const args = [addressesProvider];
|
||||
const instance = await deployContract<WalletBalanceProvider>(
|
||||
eContractid.WalletBalanceProvider,
|
||||
args
|
||||
);
|
||||
if (verify) {
|
||||
await verifyContract(eContractid.WalletBalanceProvider, instance.address, args);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const deployAaveProtocolTestHelpers = async (addressesProvider: tEthereumAddress) =>
|
||||
await deployContract<AaveProtocolTestHelpers>(eContractid.AaveProtocolTestHelpers, [
|
||||
addressesProvider,
|
||||
]);
|
||||
export const deployAaveProtocolTestHelpers = async (
|
||||
addressesProvider: tEthereumAddress,
|
||||
verify?: boolean
|
||||
) => {
|
||||
const args = [addressesProvider];
|
||||
const instance = await deployContract<AaveProtocolTestHelpers>(
|
||||
eContractid.AaveProtocolTestHelpers,
|
||||
args
|
||||
);
|
||||
|
||||
if (verify) {
|
||||
await verifyContract(eContractid.AaveProtocolTestHelpers, instance.address, args);
|
||||
}
|
||||
return instance;
|
||||
};
|
||||
|
||||
export const deployMintableErc20 = async ([name, symbol, decimals]: [string, string, number]) =>
|
||||
await deployContract<MintableErc20>(eContractid.MintableERC20, [name, symbol, decimals]);
|
||||
|
|
|
@ -22,7 +22,7 @@ function delay(ms: number) {
|
|||
export const verifyContract = async (
|
||||
contractName: string,
|
||||
address: string,
|
||||
constructorArguments: string[],
|
||||
constructorArguments: (string | string[])[],
|
||||
libraries?: string
|
||||
) => {
|
||||
const currentNetwork = BRE.network.name;
|
||||
|
|
80
helpers/init-helpers.ts
Normal file
80
helpers/init-helpers.ts
Normal file
|
@ -0,0 +1,80 @@
|
|||
import {iMultiPoolsAssets, IReserveParams, tEthereumAddress} from './types';
|
||||
import {LendingPool} from '../types/LendingPool';
|
||||
import {LendingPoolConfigurator} from '../types/LendingPoolConfigurator';
|
||||
|
||||
export const enableReservesToBorrow = async (
|
||||
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
||||
tokenAddresses: {[symbol: string]: tEthereumAddress},
|
||||
lendingPool: LendingPool,
|
||||
lendingPoolConfigurator: LendingPoolConfigurator
|
||||
) => {
|
||||
for (const [assetSymbol, {borrowingEnabled, stableBorrowRateEnabled}] of Object.entries(
|
||||
reservesParams
|
||||
) as [string, IReserveParams][]) {
|
||||
if (!borrowingEnabled) continue;
|
||||
try {
|
||||
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
||||
(value) => value === assetSymbol
|
||||
);
|
||||
const [, tokenAddress] = (Object.entries(tokenAddresses) as [string, string][])[
|
||||
assetAddressIndex
|
||||
];
|
||||
const {
|
||||
borrowingEnabled: borrowingAlreadyEnabled,
|
||||
} = await lendingPool.getReserveConfigurationData(tokenAddress);
|
||||
|
||||
if (borrowingAlreadyEnabled) {
|
||||
console.log(`Reserve ${assetSymbol} is already enabled for borrowing, skipping`);
|
||||
continue;
|
||||
}
|
||||
|
||||
await lendingPoolConfigurator.enableBorrowingOnReserve(tokenAddress, stableBorrowRateEnabled);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
`Enabling reserve for borrowings for ${assetSymbol} failed with error ${e}. Skipped.`
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const enableReservesAsCollateral = async (
|
||||
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
||||
tokenAddresses: {[symbol: string]: tEthereumAddress},
|
||||
lendingPool: LendingPool,
|
||||
lendingPoolConfigurator: LendingPoolConfigurator
|
||||
) => {
|
||||
for (const [
|
||||
assetSymbol,
|
||||
{baseLTVAsCollateral, liquidationBonus, liquidationThreshold},
|
||||
] of Object.entries(reservesParams) as [string, IReserveParams][]) {
|
||||
if (baseLTVAsCollateral === '-1') continue;
|
||||
|
||||
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
||||
(value) => value === assetSymbol
|
||||
);
|
||||
const [, tokenAddress] = (Object.entries(tokenAddresses) as [string, string][])[
|
||||
assetAddressIndex
|
||||
];
|
||||
const {
|
||||
usageAsCollateralEnabled: alreadyEnabled,
|
||||
} = await lendingPool.getReserveConfigurationData(tokenAddress);
|
||||
|
||||
if (alreadyEnabled) {
|
||||
console.log(`Reserve ${assetSymbol} is already enabled as collateral, skipping`);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await lendingPoolConfigurator.enableReserveAsCollateral(
|
||||
tokenAddress,
|
||||
baseLTVAsCollateral,
|
||||
liquidationThreshold,
|
||||
liquidationBonus
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
`Enabling reserve as collateral for ${assetSymbol} failed with error ${e}. Skipped.`
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
|
@ -42,3 +42,11 @@ export const increaseTime = async (secondsToIncrease: number) => {
|
|||
};
|
||||
|
||||
export const waitForTx = async (tx: ContractTransaction) => await tx.wait();
|
||||
|
||||
export const filterMapBy = (raw: {[key: string]: any}, fn: (key: string) => boolean) =>
|
||||
Object.keys(raw)
|
||||
.filter(fn)
|
||||
.reduce<{[key: string]: any}>((obj, key) => {
|
||||
obj[key] = raw[key];
|
||||
return obj;
|
||||
}, {});
|
||||
|
|
21
helpers/mock-helpers.ts
Normal file
21
helpers/mock-helpers.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import {MockTokenMap, tEthereumAddress} from './types';
|
||||
import {MockAggregator} from '../types/MockAggregator';
|
||||
|
||||
export const getAllTokenAddresses = (mockTokens: MockTokenMap) =>
|
||||
Object.entries(mockTokens).reduce(
|
||||
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, tokenContract]) => ({
|
||||
...accum,
|
||||
[tokenSymbol]: tokenContract.address,
|
||||
}),
|
||||
{}
|
||||
);
|
||||
export const getAllAggregatorsAddresses = (mockAggregators: {
|
||||
[tokenSymbol: string]: MockAggregator;
|
||||
}) =>
|
||||
Object.entries(mockAggregators).reduce(
|
||||
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, aggregator]) => ({
|
||||
...accum,
|
||||
[tokenSymbol]: aggregator.address,
|
||||
}),
|
||||
{}
|
||||
);
|
|
@ -4,13 +4,15 @@ import {
|
|||
IMarketRates,
|
||||
iAssetBase,
|
||||
iAssetAggregatorBase,
|
||||
eContractid,
|
||||
} from './types';
|
||||
|
||||
import {LendingRateOracle} from '../types/LendingRateOracle';
|
||||
import {PriceOracle} from '../types/PriceOracle';
|
||||
import {MockAggregator} from '../types/MockAggregator';
|
||||
import {deployMockAggregator} from './contracts-helpers';
|
||||
import {deployMockAggregator, getContract} from './contracts-helpers';
|
||||
import {waitForTx} from './misc-utils';
|
||||
import {verifyContract} from './etherscan-verification';
|
||||
|
||||
export const setInitialMarketRatesInRatesOracle = async (
|
||||
marketRates: iMultiPoolsAssets<IMarketRates>,
|
||||
|
@ -47,7 +49,10 @@ export const setInitialAssetPricesInOracle = async (
|
|||
}
|
||||
};
|
||||
|
||||
export const deployAllMockAggregators = async (initialPrices: iAssetAggregatorBase<string>) => {
|
||||
export const deployAllMockAggregators = async (
|
||||
initialPrices: iAssetAggregatorBase<string>,
|
||||
verify?: boolean
|
||||
) => {
|
||||
const aggregators: {[tokenSymbol: string]: MockAggregator} = {};
|
||||
for (const tokenContractName of Object.keys(initialPrices)) {
|
||||
if (tokenContractName !== 'ETH') {
|
||||
|
@ -55,7 +60,7 @@ export const deployAllMockAggregators = async (initialPrices: iAssetAggregatorBa
|
|||
(value) => value === tokenContractName
|
||||
);
|
||||
const [, price] = (Object.entries(initialPrices) as [string, string][])[priceIndex];
|
||||
aggregators[tokenContractName] = await deployMockAggregator(price);
|
||||
aggregators[tokenContractName] = await deployMockAggregator(price, verify);
|
||||
}
|
||||
}
|
||||
return aggregators;
|
||||
|
|
|
@ -21,6 +21,7 @@ import {
|
|||
} from '../../helpers/oracles-helpers';
|
||||
import {tEthereumAddress} from '../../helpers/types';
|
||||
import {waitForTx} from '../../helpers/misc-utils';
|
||||
import {getAllAggregatorsAddresses, getAllTokenAddresses} from '../../helpers/mock-helpers';
|
||||
|
||||
task('deploy-oracles', 'Deploy oracles for dev enviroment')
|
||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||
|
@ -64,39 +65,23 @@ task('deploy-oracles', 'Deploy oracles for dev enviroment')
|
|||
fallbackOracle
|
||||
);
|
||||
|
||||
// TODO: Missing verify
|
||||
const mockAggregators = await deployAllMockAggregators(MOCK_CHAINLINK_AGGREGATORS_PRICES);
|
||||
const mockAggregators = await deployAllMockAggregators(
|
||||
MOCK_CHAINLINK_AGGREGATORS_PRICES,
|
||||
verify
|
||||
);
|
||||
|
||||
const allTokenAddresses = Object.entries(mockTokens).reduce(
|
||||
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, tokenContract]) => ({
|
||||
...accum,
|
||||
[tokenSymbol]: tokenContract.address,
|
||||
}),
|
||||
{}
|
||||
);
|
||||
const allAggregatorsAddresses = Object.entries(mockAggregators).reduce(
|
||||
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, aggregator]) => ({
|
||||
...accum,
|
||||
[tokenSymbol]: aggregator.address,
|
||||
}),
|
||||
{}
|
||||
);
|
||||
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
||||
const allAggregatorsAddresses = getAllAggregatorsAddresses(mockAggregators);
|
||||
|
||||
const [tokens, aggregators] = getPairsTokenAggregator(
|
||||
allTokenAddresses,
|
||||
allAggregatorsAddresses
|
||||
);
|
||||
|
||||
// TODO: Missing verify and getter
|
||||
const chainlinkProxyPriceProvider = await deployChainlinkProxyPriceProvider([
|
||||
tokens,
|
||||
aggregators,
|
||||
fallbackOracle.address,
|
||||
]);
|
||||
await deployChainlinkProxyPriceProvider([tokens, aggregators, fallbackOracle.address], verify);
|
||||
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
||||
|
||||
// TODO: Missing verify
|
||||
const lendingRateOracle = await deployLendingRateOracle();
|
||||
const lendingRateOracle = await deployLendingRateOracle(verify);
|
||||
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
||||
|
||||
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
||||
|
|
|
@ -1,39 +1,50 @@
|
|||
import {task} from '@nomiclabs/buidler/config';
|
||||
import {
|
||||
getLendingPoolAddressesProvider,
|
||||
getMockedTokens,
|
||||
initReserves,
|
||||
getLendingPoolAddressesProvider,
|
||||
getMockedTokens,
|
||||
initReserves,
|
||||
deployLendingPoolLiquidationManager,
|
||||
deployTokenDistributor,
|
||||
deployInitializableAdminUpgradeabilityProxy,
|
||||
insertContractAddressInDb,
|
||||
deployMockFlashLoanReceiver,
|
||||
deployWalletBalancerProvider,
|
||||
deployAaveProtocolTestHelpers,
|
||||
getLendingPool,
|
||||
getLendingPoolConfiguratorProxy,
|
||||
} from '../../helpers/contracts-helpers';
|
||||
import {getReservesConfigByPool} from '../../helpers/constants';
|
||||
import {
|
||||
getReservesConfigByPool,
|
||||
getFeeDistributionParamsCommon,
|
||||
ZERO_ADDRESS,
|
||||
} from '../../helpers/constants';
|
||||
|
||||
import {tEthereumAddress, AavePools} from '../../helpers/types';
|
||||
import {waitForTx} from '../../helpers/misc-utils';
|
||||
import {tEthereumAddress, AavePools, eContractid} from '../../helpers/types';
|
||||
import {waitForTx, filterMapBy} from '../../helpers/misc-utils';
|
||||
import {enableReservesToBorrow, enableReservesAsCollateral} from '../../helpers/init-helpers';
|
||||
import {getAllTokenAddresses, getAllAggregatorsAddresses} from '../../helpers/mock-helpers';
|
||||
|
||||
task('initialize-lending-pool', 'Deploy oracles for dev enviroment')
|
||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||
.setAction(async ({verify}, localBRE) => {
|
||||
await localBRE.run('set-bre');
|
||||
task('initialize-lending-pool', 'Initialize lending pool configuration.')
|
||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||
.setAction(async ({verify}, localBRE) => {
|
||||
await localBRE.run('set-bre');
|
||||
|
||||
const mockTokens = await getMockedTokens();
|
||||
|
||||
const allTokenAddresses = Object.entries(mockTokens).reduce(
|
||||
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, tokenContract]) => ({
|
||||
...accum,
|
||||
[tokenSymbol]: tokenContract.address,
|
||||
}),
|
||||
{}
|
||||
const lendingPoolProxy = await getLendingPool();
|
||||
const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy();
|
||||
const [lendingPoolManager, secondaryWallet] = await Promise.all(
|
||||
(await localBRE.ethers.getSigners()).map(async (x) => x.getAddress())
|
||||
);
|
||||
|
||||
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
||||
|
||||
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
||||
|
||||
const addressesProvider = await getLendingPoolAddressesProvider();
|
||||
|
||||
const {
|
||||
UNI_DAI_ETH,
|
||||
UNI_USDC_ETH,
|
||||
UNI_SETH_ETH,
|
||||
UNI_LINK_ETH,
|
||||
UNI_MKR_ETH,
|
||||
UNI_LEND_ETH,
|
||||
...protoPoolReservesAddresses
|
||||
} = <{[symbol: string]: tEthereumAddress}>allTokenAddresses;
|
||||
const protoPoolReservesAddresses = <{[symbol: string]: tEthereumAddress}>(
|
||||
filterMapBy(allTokenAddresses, (key: string) => !key.includes('UNI'))
|
||||
);
|
||||
|
||||
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
||||
|
||||
|
@ -59,15 +70,15 @@ await localBRE.run('set-bre');
|
|||
lendingPoolConfiguratorProxy
|
||||
);
|
||||
|
||||
const liquidationManager = await deployLendingPoolLiquidationManager();
|
||||
const liquidationManager = await deployLendingPoolLiquidationManager(verify);
|
||||
await waitForTx(
|
||||
await addressesProvider.setLendingPoolLiquidationManager(liquidationManager.address)
|
||||
);
|
||||
|
||||
const {receivers, percentages} = getFeeDistributionParamsCommon(lendingPoolManager);
|
||||
|
||||
const tokenDistributorImpl = await deployTokenDistributor();
|
||||
const tokenDistributorProxy = await deployInitializableAdminUpgradeabilityProxy();
|
||||
const tokenDistributorImpl = await deployTokenDistributor(verify);
|
||||
const tokenDistributorProxy = await deployInitializableAdminUpgradeabilityProxy(verify);
|
||||
const implementationParams = tokenDistributorImpl.interface.encodeFunctionData('initialize', [
|
||||
ZERO_ADDRESS,
|
||||
tokensAddressesWithoutUsd.LEND,
|
||||
|
@ -79,7 +90,7 @@ await localBRE.run('set-bre');
|
|||
await waitForTx(
|
||||
await tokenDistributorProxy['initialize(address,address,bytes)'](
|
||||
tokenDistributorImpl.address,
|
||||
await secondaryWallet.getAddress(),
|
||||
secondaryWallet,
|
||||
implementationParams
|
||||
)
|
||||
);
|
||||
|
@ -87,16 +98,18 @@ await localBRE.run('set-bre');
|
|||
|
||||
await insertContractAddressInDb(eContractid.TokenDistributor, tokenDistributorProxy.address);
|
||||
|
||||
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(addressesProvider.address);
|
||||
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
|
||||
addressesProvider.address,
|
||||
verify
|
||||
);
|
||||
await insertContractAddressInDb(
|
||||
eContractid.MockFlashLoanReceiver,
|
||||
mockFlashLoanReceiver.address
|
||||
);
|
||||
|
||||
await deployWalletBalancerProvider(addressesProvider.address);
|
||||
await deployWalletBalancerProvider(addressesProvider.address, verify);
|
||||
|
||||
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address);
|
||||
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address, verify);
|
||||
|
||||
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
|
||||
|
||||
});
|
||||
});
|
|
@ -25,10 +25,8 @@ task('dev-migration', 'Deploy development enviroment')
|
|||
console.log('4. Deploy oracles');
|
||||
await localBRE.run('deploy-oracles');
|
||||
|
||||
// 5. Initialize lending pool configuration
|
||||
//
|
||||
// console.log('5. Initialize lending pool')
|
||||
// await localBRE.run('initialize-lending-pool');
|
||||
console.log('5. Initialize lending pool');
|
||||
await localBRE.run('initialize-lending-pool');
|
||||
|
||||
console.log('\nFinished migration');
|
||||
});
|
||||
|
|
|
@ -27,6 +27,7 @@ import {
|
|||
deployVariableDebtToken,
|
||||
deployGenericAToken,
|
||||
getPairsTokenAggregator,
|
||||
initReserves,
|
||||
} from '../helpers/contracts-helpers';
|
||||
import {LendingPoolAddressesProvider} from '../types/LendingPoolAddressesProvider';
|
||||
import {Signer} from 'ethers';
|
||||
|
@ -59,6 +60,7 @@ import {
|
|||
deployAllMockAggregators,
|
||||
} from '../helpers/oracles-helpers';
|
||||
import {waitForTx} from '../helpers/misc-utils';
|
||||
import {enableReservesToBorrow, enableReservesAsCollateral} from '../helpers/init-helpers';
|
||||
|
||||
const deployAllMockTokens = async (deployer: Signer) => {
|
||||
const tokens: {[symbol: string]: MockContract | MintableErc20} = {};
|
||||
|
@ -90,83 +92,6 @@ const deployAllMockTokens = async (deployer: Signer) => {
|
|||
return tokens;
|
||||
};
|
||||
|
||||
const enableReservesToBorrow = async (
|
||||
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
||||
tokenAddresses: {[symbol: string]: tEthereumAddress},
|
||||
lendingPool: LendingPool,
|
||||
lendingPoolConfigurator: LendingPoolConfigurator
|
||||
) => {
|
||||
for (const [assetSymbol, {borrowingEnabled, stableBorrowRateEnabled}] of Object.entries(
|
||||
reservesParams
|
||||
) as [string, IReserveParams][]) {
|
||||
if (!borrowingEnabled) continue;
|
||||
try {
|
||||
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
||||
(value) => value === assetSymbol
|
||||
);
|
||||
const [, tokenAddress] = (Object.entries(tokenAddresses) as [string, string][])[
|
||||
assetAddressIndex
|
||||
];
|
||||
const {
|
||||
borrowingEnabled: borrowingAlreadyEnabled,
|
||||
} = await lendingPool.getReserveConfigurationData(tokenAddress);
|
||||
|
||||
if (borrowingAlreadyEnabled) {
|
||||
console.log(`Reserve ${assetSymbol} is already enabled for borrowing, skipping`);
|
||||
continue;
|
||||
}
|
||||
|
||||
await lendingPoolConfigurator.enableBorrowingOnReserve(tokenAddress, stableBorrowRateEnabled);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
`Enabling reserve for borrowings for ${assetSymbol} failed with error ${e}. Skipped.`
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const enableReservesAsCollateral = async (
|
||||
reservesParams: iMultiPoolsAssets<IReserveParams>,
|
||||
tokenAddresses: {[symbol: string]: tEthereumAddress},
|
||||
lendingPool: LendingPool,
|
||||
lendingPoolConfigurator: LendingPoolConfigurator
|
||||
) => {
|
||||
for (const [
|
||||
assetSymbol,
|
||||
{baseLTVAsCollateral, liquidationBonus, liquidationThreshold},
|
||||
] of Object.entries(reservesParams) as [string, IReserveParams][]) {
|
||||
if (baseLTVAsCollateral === '-1') continue;
|
||||
|
||||
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
|
||||
(value) => value === assetSymbol
|
||||
);
|
||||
const [, tokenAddress] = (Object.entries(tokenAddresses) as [string, string][])[
|
||||
assetAddressIndex
|
||||
];
|
||||
const {
|
||||
usageAsCollateralEnabled: alreadyEnabled,
|
||||
} = await lendingPool.getReserveConfigurationData(tokenAddress);
|
||||
|
||||
if (alreadyEnabled) {
|
||||
console.log(`Reserve ${assetSymbol} is already enabled as collateral, skipping`);
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await lendingPoolConfigurator.enableReserveAsCollateral(
|
||||
tokenAddress,
|
||||
baseLTVAsCollateral,
|
||||
liquidationThreshold,
|
||||
liquidationBonus
|
||||
);
|
||||
} catch (e) {
|
||||
console.log(
|
||||
`Enabling reserve as collateral for ${assetSymbol} failed with error ${e}. Skipped.`
|
||||
);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||
console.time('setup');
|
||||
const lendingPoolManager = await deployer.getAddress();
|
||||
|
|
Loading…
Reference in New Issue
Block a user