mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
WIP full migrations
This commit is contained in:
parent
e720236170
commit
b3896fa4e3
|
@ -118,12 +118,18 @@ export const CommonsConfig: ICommonConfiguration = {
|
|||
// COMMON PROTOCOL ADDRESSES ACROSS POOLS
|
||||
// ----------------
|
||||
|
||||
ProviderRegistry: {
|
||||
[EthereumNetwork.kovan]: '0xcd9Dae41Cc8b7433c045D3D7C4C555315EF0DDDE',
|
||||
[EthereumNetwork.ropsten]: '0x84D3638AF869cA413702192E5AB9481C083A216a',
|
||||
[EthereumNetwork.main]: '0xd09F34960C37dA3a8602F0847CE5ac8f7B393d99',
|
||||
// If lendingPoolManagerAddress is set, will take priority over lendingPoolManagerAddressIndex
|
||||
LendingPoolManagerAddress: {
|
||||
[EthereumNetwork.kovan]: undefined,
|
||||
[EthereumNetwork.ropsten]: undefined,
|
||||
[EthereumNetwork.main]: undefined,
|
||||
},
|
||||
LendingPoolManagerAddressIndex: 0,
|
||||
ProviderRegistry: {
|
||||
[EthereumNetwork.kovan]: '',
|
||||
[EthereumNetwork.ropsten]: '',
|
||||
[EthereumNetwork.main]: '',
|
||||
},
|
||||
|
||||
LendingRateOracle: {
|
||||
[EthereumNetwork.kovan]: '0xdcde9bb6a49e37fa433990832ab541ae2d4feb4a',
|
||||
[EthereumNetwork.ropsten]: '0x05dcca805a6562c1bdd0423768754acb6993241b',
|
||||
|
|
19
helpers/contracts-getters.ts
Normal file
19
helpers/contracts-getters.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
import {BRE} from './misc-utils';
|
||||
import {ICommonConfiguration, eEthereumNetwork} from './types';
|
||||
import {getParamPerNetwork} from './contracts-helpers';
|
||||
|
||||
export const getGenesisLendingPoolManagerAddress = async (config: ICommonConfiguration) => {
|
||||
const currentNetwork = BRE.network.name;
|
||||
const targetAddress = getParamPerNetwork(
|
||||
config.LendingPoolManagerAddress,
|
||||
<eEthereumNetwork>currentNetwork
|
||||
);
|
||||
if (targetAddress) {
|
||||
return targetAddress;
|
||||
}
|
||||
const addressList = await Promise.all(
|
||||
(await BRE.ethers.getSigners()).map((signer) => signer.getAddress())
|
||||
);
|
||||
const addressIndex = config.LendingPoolManagerAddressIndex;
|
||||
return addressList[addressIndex];
|
||||
};
|
|
@ -783,3 +783,15 @@ export const initReserves = async (
|
|||
}
|
||||
}
|
||||
};
|
||||
|
||||
export const getLendingPoolAddressesProviderRegistry = async (address?: tEthereumAddress) => {
|
||||
return await getContract<LendingPoolAddressesProviderRegistry>(
|
||||
eContractid.LendingPoolAddressesProviderRegistry,
|
||||
address ||
|
||||
(
|
||||
await getDb()
|
||||
.get(`${eContractid.LendingPoolAddressesProviderRegistry}.${BRE.network.name}`)
|
||||
.value()
|
||||
).address
|
||||
);
|
||||
};
|
||||
|
|
|
@ -279,6 +279,8 @@ export interface ICommonConfiguration {
|
|||
ChainlinkProxyPriceProvider: iParamsPerNetwork<tEthereumAddress>;
|
||||
FallbackOracle: iParamsPerNetwork<tEthereumAddress>;
|
||||
ChainlinkAggregator: iParamsPerNetwork<ITokenAddress>;
|
||||
LendingPoolManagerAddress: iParamsPerNetwork<tEthereumAddress | undefined>;
|
||||
LendingPoolManagerAddressIndex: number;
|
||||
}
|
||||
|
||||
export interface IAaveConfiguration extends ICommonConfiguration {
|
||||
|
|
46
tasks/full/1_address_provider_registry.ts
Normal file
46
tasks/full/1_address_provider_registry.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import {task} from '@nomiclabs/buidler/config';
|
||||
import {
|
||||
deployLendingPoolAddressesProvider,
|
||||
deployLendingPoolAddressesProviderRegistry,
|
||||
getParamPerNetwork,
|
||||
getLendingPoolAddressesProvider,
|
||||
getLendingPoolAddressesProviderRegistry,
|
||||
} from '../../helpers/contracts-helpers';
|
||||
import {waitForTx} from '../../helpers/misc-utils';
|
||||
import {ConfigNames, loadPoolConfig} from '../../helpers/configuration';
|
||||
import {getGenesisLendingPoolManagerAddress} from '../../helpers/contracts-getters';
|
||||
import {eEthereumNetwork} from '../../helpers/types';
|
||||
|
||||
task(
|
||||
'full:deploy-address-provider',
|
||||
'Deploy address provider, registry and fee provider for dev enviroment'
|
||||
)
|
||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
|
||||
.setAction(async ({verify, pool}, localBRE) => {
|
||||
await localBRE.run('set-bre');
|
||||
const network = <eEthereumNetwork>localBRE.network.name;
|
||||
const poolConfig = loadPoolConfig(pool);
|
||||
const {ProviderId} = poolConfig;
|
||||
|
||||
const providerRegistryAddress = getParamPerNetwork(poolConfig.ProviderRegistry, network);
|
||||
// Deploy address provider and set genesis manager
|
||||
const addressesProvider = await deployLendingPoolAddressesProvider(verify);
|
||||
await waitForTx(
|
||||
await addressesProvider.setLendingPoolManager(
|
||||
await getGenesisLendingPoolManagerAddress(poolConfig)
|
||||
)
|
||||
);
|
||||
|
||||
// If no provider registry is set, deploy lending pool address provider registry and register the address provider
|
||||
const addressesProviderRegistry = !providerRegistryAddress
|
||||
? await deployLendingPoolAddressesProviderRegistry(verify)
|
||||
: await getLendingPoolAddressesProviderRegistry(providerRegistryAddress);
|
||||
|
||||
await waitForTx(
|
||||
await addressesProviderRegistry.registerAddressesProvider(
|
||||
addressesProvider.address,
|
||||
ProviderId
|
||||
)
|
||||
);
|
||||
});
|
44
tasks/full/3_lending_pool.todo
Normal file
44
tasks/full/3_lending_pool.todo
Normal file
|
@ -0,0 +1,44 @@
|
|||
import {task} from '@nomiclabs/buidler/config';
|
||||
import {
|
||||
deployLendingPool,
|
||||
getLendingPoolAddressesProvider,
|
||||
getLendingPool,
|
||||
insertContractAddressInDb,
|
||||
deployLendingPoolConfigurator,
|
||||
getLendingPoolConfiguratorProxy,
|
||||
} from '../../helpers/contracts-helpers';
|
||||
import {eContractid} from '../../helpers/types';
|
||||
import {waitForTx} from '../../helpers/misc-utils';
|
||||
|
||||
task('deploy-lending-pool', 'Deploy lending pool for dev enviroment')
|
||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||
.setAction(async ({verify}, localBRE) => {
|
||||
await localBRE.run('set-bre');
|
||||
|
||||
const addressesProvider = await getLendingPoolAddressesProvider();
|
||||
|
||||
const lendingPoolImpl = await deployLendingPool(verify);
|
||||
|
||||
// Set lending pool impl to Address Provider
|
||||
await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImpl.address));
|
||||
|
||||
const address = await addressesProvider.getLendingPool();
|
||||
const lendingPoolProxy = await getLendingPool(address);
|
||||
|
||||
await insertContractAddressInDb(eContractid.LendingPool, lendingPoolProxy.address);
|
||||
|
||||
const lendingPoolConfiguratorImpl = await deployLendingPoolConfigurator(verify);
|
||||
|
||||
// Set lending pool conf impl to Address Provider
|
||||
await waitForTx(
|
||||
await addressesProvider.setLendingPoolConfiguratorImpl(lendingPoolConfiguratorImpl.address)
|
||||
);
|
||||
|
||||
const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy(
|
||||
await addressesProvider.getLendingPoolConfigurator()
|
||||
);
|
||||
await insertContractAddressInDb(
|
||||
eContractid.LendingPoolConfigurator,
|
||||
lendingPoolConfiguratorProxy.address
|
||||
);
|
||||
});
|
74
tasks/full/4_oracles.todo
Normal file
74
tasks/full/4_oracles.todo
Normal file
|
@ -0,0 +1,74 @@
|
|||
import {task} from '@nomiclabs/buidler/config';
|
||||
import {
|
||||
getLendingPoolAddressesProvider,
|
||||
deployPriceOracle,
|
||||
getMockedTokens,
|
||||
getPairsTokenAggregator,
|
||||
deployChainlinkProxyPriceProvider,
|
||||
deployLendingRateOracle,
|
||||
getAllMockedTokens,
|
||||
} from '../../helpers/contracts-helpers';
|
||||
|
||||
import {
|
||||
setInitialAssetPricesInOracle,
|
||||
setInitialMarketRatesInRatesOracle,
|
||||
deployAllMockAggregators,
|
||||
} from '../../helpers/oracles-helpers';
|
||||
import {ICommonConfiguration, iAssetBase, TokenContractId} from '../../helpers/types';
|
||||
import {waitForTx} from '../../helpers/misc-utils';
|
||||
import {getAllAggregatorsAddresses, getAllTokenAddresses} from '../../helpers/mock-helpers';
|
||||
import {ConfigNames, loadPoolConfig} from '../../helpers/configuration';
|
||||
|
||||
task('deploy-oracles', 'Deploy oracles for dev enviroment')
|
||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||
.addParam('pool', `Pool name to retrieve configuration, supported: ${Object.values(ConfigNames)}`)
|
||||
.setAction(async ({verify, pool}, localBRE) => {
|
||||
await localBRE.run('set-bre');
|
||||
const poolConfig = loadPoolConfig(pool);
|
||||
const {
|
||||
Mocks: {ChainlinkAggregatorPrices, AllAssetsInitialPrices},
|
||||
ProtocolGlobalParams: {UsdAddress, MockUsdPriceInWei},
|
||||
LendingRateOracleRatesCommon,
|
||||
} = poolConfig as ICommonConfiguration;
|
||||
|
||||
const defaultTokenList = {
|
||||
...Object.fromEntries(Object.keys(TokenContractId).map((symbol) => [symbol, ''])),
|
||||
USD: UsdAddress,
|
||||
} as iAssetBase<string>;
|
||||
const mockTokens = await getAllMockedTokens();
|
||||
const mockTokensAddress = Object.keys(mockTokens).reduce<iAssetBase<string>>((prev, curr) => {
|
||||
prev[curr as keyof iAssetBase<string>] = mockTokens[curr].address;
|
||||
return prev;
|
||||
}, defaultTokenList);
|
||||
const addressesProvider = await getLendingPoolAddressesProvider();
|
||||
|
||||
const fallbackOracle = await deployPriceOracle(verify);
|
||||
await waitForTx(await fallbackOracle.setEthUsdPrice(MockUsdPriceInWei));
|
||||
await setInitialAssetPricesInOracle(AllAssetsInitialPrices, mockTokensAddress, fallbackOracle);
|
||||
|
||||
const mockAggregators = await deployAllMockAggregators(ChainlinkAggregatorPrices, verify);
|
||||
|
||||
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
||||
const allAggregatorsAddresses = getAllAggregatorsAddresses(mockAggregators);
|
||||
|
||||
const [tokens, aggregators] = getPairsTokenAggregator(
|
||||
allTokenAddresses,
|
||||
allAggregatorsAddresses
|
||||
);
|
||||
|
||||
await deployChainlinkProxyPriceProvider([tokens, aggregators, fallbackOracle.address], verify);
|
||||
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
||||
|
||||
const lendingRateOracle = await deployLendingRateOracle(verify);
|
||||
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
||||
|
||||
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
||||
const allReservesAddresses = {
|
||||
...tokensAddressesWithoutUsd,
|
||||
};
|
||||
await setInitialMarketRatesInRatesOracle(
|
||||
LendingRateOracleRatesCommon,
|
||||
allReservesAddresses,
|
||||
lendingRateOracle
|
||||
);
|
||||
});
|
80
tasks/full/5_initialize.todo
Normal file
80
tasks/full/5_initialize.todo
Normal file
|
@ -0,0 +1,80 @@
|
|||
import {task} from '@nomiclabs/buidler/config';
|
||||
import {
|
||||
getLendingPoolAddressesProvider,
|
||||
initReserves,
|
||||
deployLendingPoolLiquidationManager,
|
||||
insertContractAddressInDb,
|
||||
deployMockFlashLoanReceiver,
|
||||
deployWalletBalancerProvider,
|
||||
deployAaveProtocolTestHelpers,
|
||||
getLendingPool,
|
||||
getLendingPoolConfiguratorProxy,
|
||||
getAllMockedTokens,
|
||||
} from '../../helpers/contracts-helpers';
|
||||
import {getReservesConfigByPool} from '../../helpers/configuration';
|
||||
|
||||
import {tEthereumAddress, AavePools, eContractid} from '../../helpers/types';
|
||||
import {waitForTx, filterMapBy} from '../../helpers/misc-utils';
|
||||
import {enableReservesToBorrow, enableReservesAsCollateral} from '../../helpers/init-helpers';
|
||||
import {getAllTokenAddresses} from '../../helpers/mock-helpers';
|
||||
|
||||
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 getAllMockedTokens();
|
||||
const lendingPoolProxy = await getLendingPool();
|
||||
const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy();
|
||||
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
||||
|
||||
const addressesProvider = await getLendingPoolAddressesProvider();
|
||||
|
||||
const protoPoolReservesAddresses = <{[symbol: string]: tEthereumAddress}>(
|
||||
filterMapBy(allTokenAddresses, (key: string) => !key.includes('UNI'))
|
||||
);
|
||||
|
||||
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
||||
|
||||
console.log('Initialize configuration');
|
||||
await initReserves(
|
||||
reservesParams,
|
||||
protoPoolReservesAddresses,
|
||||
addressesProvider,
|
||||
lendingPoolProxy,
|
||||
lendingPoolConfiguratorProxy,
|
||||
AavePools.proto
|
||||
);
|
||||
await enableReservesToBorrow(
|
||||
reservesParams,
|
||||
protoPoolReservesAddresses,
|
||||
lendingPoolProxy,
|
||||
lendingPoolConfiguratorProxy
|
||||
);
|
||||
await enableReservesAsCollateral(
|
||||
reservesParams,
|
||||
protoPoolReservesAddresses,
|
||||
lendingPoolProxy,
|
||||
lendingPoolConfiguratorProxy
|
||||
);
|
||||
|
||||
const liquidationManager = await deployLendingPoolLiquidationManager(verify);
|
||||
await waitForTx(
|
||||
await addressesProvider.setLendingPoolLiquidationManager(liquidationManager.address)
|
||||
);
|
||||
|
||||
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
|
||||
addressesProvider.address,
|
||||
verify
|
||||
);
|
||||
await insertContractAddressInDb(
|
||||
eContractid.MockFlashLoanReceiver,
|
||||
mockFlashLoanReceiver.address
|
||||
);
|
||||
|
||||
await deployWalletBalancerProvider(addressesProvider.address, verify);
|
||||
|
||||
const testHelpers = await deployAaveProtocolTestHelpers(addressesProvider.address, verify);
|
||||
|
||||
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
|
||||
});
|
|
@ -1,5 +1,6 @@
|
|||
import {task} from '@nomiclabs/buidler/config';
|
||||
import {checkVerification} from '../../helpers/etherscan-verification';
|
||||
import {ConfigNames} from '../../helpers/configuration';
|
||||
|
||||
task('aave:full', 'Deploy development enviroment')
|
||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||
|
@ -9,5 +10,29 @@ task('aave:full', 'Deploy development enviroment')
|
|||
if (verify) {
|
||||
checkVerification();
|
||||
}
|
||||
await localBRE.run('set-bre');
|
||||
|
||||
// Prevent loss of gas verifying all the needed ENVs for Etherscan verification
|
||||
if (verify) {
|
||||
checkVerification();
|
||||
}
|
||||
|
||||
console.log('Migration started\n');
|
||||
|
||||
console.log('1. Deploy address provider');
|
||||
await localBRE.run('full:deploy-address-provider', {verify, pool: ConfigNames.Aave});
|
||||
|
||||
/*
|
||||
console.log('3. Deploy lending pool');
|
||||
await localBRE.run('deploy-lending-pool', {verify});
|
||||
|
||||
console.log('4. Deploy oracles');
|
||||
await localBRE.run('deploy-oracles', {verify, pool: ConfigNames.Aave});
|
||||
|
||||
console.log('5. Initialize lending pool');
|
||||
await localBRE.run('initialize-lending-pool', {verify});
|
||||
|
||||
// console.log('\nFinished migration');
|
||||
*/
|
||||
console.log('TODO: Pending to migrate');
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user