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": {
|
"DefaultReserveInterestRateStrategy": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0x830bceA96E56DBC1F8578f75fBaC0AF16B32A07d",
|
"address": "0xE91bBe8ee03560E3dda2786f95335F5399813Ca0",
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
},
|
},
|
||||||
"localhost": {
|
"localhost": {
|
||||||
|
@ -146,7 +146,7 @@
|
||||||
},
|
},
|
||||||
"TokenDistributor": {
|
"TokenDistributor": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
|
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
|
||||||
},
|
},
|
||||||
"localhost": {
|
"localhost": {
|
||||||
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
|
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
|
||||||
|
@ -154,7 +154,7 @@
|
||||||
},
|
},
|
||||||
"InitializableAdminUpgradeabilityProxy": {
|
"InitializableAdminUpgradeabilityProxy": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4",
|
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60",
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
},
|
},
|
||||||
"localhost": {
|
"localhost": {
|
||||||
|
@ -164,7 +164,7 @@
|
||||||
},
|
},
|
||||||
"MockFlashLoanReceiver": {
|
"MockFlashLoanReceiver": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
|
"address": "0xEBAB67ee3ef604D5c250A53b4b8fcbBC6ec3007C"
|
||||||
},
|
},
|
||||||
"localhost": {
|
"localhost": {
|
||||||
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
|
"address": "0x3bDA11B584dDff7F66E0cFe1da1562c92B45db60"
|
||||||
|
@ -172,7 +172,7 @@
|
||||||
},
|
},
|
||||||
"WalletBalanceProvider": {
|
"WalletBalanceProvider": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0x392E5355a0e88Bd394F717227c752670fb3a8020",
|
"address": "0xBE36BE5680244Ae1A6F983E4A6f6E1c142cdAbe3",
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
},
|
},
|
||||||
"localhost": {
|
"localhost": {
|
||||||
|
@ -412,7 +412,7 @@
|
||||||
},
|
},
|
||||||
"AaveProtocolTestHelpers": {
|
"AaveProtocolTestHelpers": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460"
|
"address": "0xD67ba212bA61226DF3d20B2bD92deD3A6770f32d"
|
||||||
},
|
},
|
||||||
"localhost": {
|
"localhost": {
|
||||||
"address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460"
|
"address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460"
|
||||||
|
@ -420,7 +420,7 @@
|
||||||
},
|
},
|
||||||
"StableDebtToken": {
|
"StableDebtToken": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0xA0AB1cB92A4AF81f84dCd258155B5c25D247b54E",
|
"address": "0x3870a14c5057f596e385ea21537792fE4fF4C1BE",
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
},
|
},
|
||||||
"localhost": {
|
"localhost": {
|
||||||
|
@ -430,7 +430,7 @@
|
||||||
},
|
},
|
||||||
"VariableDebtToken": {
|
"VariableDebtToken": {
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0x5f7134cd38C826a7649f9Cc47dda24d834DD2967",
|
"address": "0x4977FC58783ceBCC310311C800B786EcAf45F98f",
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
},
|
},
|
||||||
"localhost": {
|
"localhost": {
|
||||||
|
@ -444,7 +444,7 @@
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
},
|
},
|
||||||
"buidlerevm": {
|
"buidlerevm": {
|
||||||
"address": "0xE91bBe8ee03560E3dda2786f95335F5399813Ca0",
|
"address": "0x32eF223A01fB55Fd862E6E30d5F4A3b2d44f9586",
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -488,4 +488,4 @@
|
||||||
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,24 +218,51 @@ export const deployPriceOracle = async (verify?: boolean) => {
|
||||||
return instance;
|
return instance;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deployMockAggregator = async (price: tStringTokenSmallUnits) =>
|
export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify?: boolean) => {
|
||||||
await deployContract<MockAggregator>(eContractid.MockAggregator, [price]);
|
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 ([
|
export const deployChainlinkProxyPriceProvider = async (
|
||||||
assetsAddresses,
|
[assetsAddresses, sourcesAddresses, fallbackOracleAddress]: [
|
||||||
sourcesAddresses,
|
tEthereumAddress[],
|
||||||
fallbackOracleAddress,
|
tEthereumAddress[],
|
||||||
]: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress]) =>
|
tEthereumAddress
|
||||||
await deployContract<MockAggregator>(eContractid.ChainlinkProxyPriceProvider, [
|
],
|
||||||
assetsAddresses,
|
verify?: boolean
|
||||||
sourcesAddresses,
|
) => {
|
||||||
fallbackOracleAddress,
|
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 () =>
|
export const getChainlingProxyPriceProvider = async (address?: tEthereumAddress) =>
|
||||||
await deployContract<LendingRateOracle>(eContractid.LendingRateOracle, []);
|
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(
|
const liquidationManagerArtifact = await readArtifact(
|
||||||
BRE.config.paths.artifacts,
|
BRE.config.paths.artifacts,
|
||||||
eContractid.LendingPoolLiquidationManager
|
eContractid.LendingPoolLiquidationManager
|
||||||
|
@ -247,29 +274,70 @@ export const deployLendingPoolLiquidationManager = async () => {
|
||||||
return (await liquidationManager.deployed()) as LendingPoolLiquidationManager;
|
return (await liquidationManager.deployed()) as LendingPoolLiquidationManager;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const deployTokenDistributor = async () =>
|
export const deployTokenDistributor = async (verify?: boolean) => {
|
||||||
await deployContract<TokenDistributor>(eContractid.TokenDistributor, []);
|
const instance = await deployContract<TokenDistributor>(eContractid.TokenDistributor, []);
|
||||||
|
if (verify) {
|
||||||
|
await verifyContract(eContractid.TokenDistributor, instance.address, []);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
export const deployInitializableAdminUpgradeabilityProxy = async () =>
|
export const deployInitializableAdminUpgradeabilityProxy = async (verify?: boolean) => {
|
||||||
await deployContract<InitializableAdminUpgradeabilityProxy>(
|
const instance = await deployContract<InitializableAdminUpgradeabilityProxy>(
|
||||||
eContractid.InitializableAdminUpgradeabilityProxy,
|
eContractid.InitializableAdminUpgradeabilityProxy,
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
if (verify) {
|
||||||
|
await verifyContract(eContractid.InitializableAdminUpgradeabilityProxy, instance.address, []);
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
|
||||||
export const deployMockFlashLoanReceiver = async (addressesProvider: tEthereumAddress) =>
|
export const deployMockFlashLoanReceiver = async (
|
||||||
await deployContract<MockFlashLoanReceiver>(eContractid.MockFlashLoanReceiver, [
|
addressesProvider: tEthereumAddress,
|
||||||
addressesProvider,
|
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) =>
|
export const deployWalletBalancerProvider = async (
|
||||||
await deployContract<WalletBalanceProvider>(eContractid.WalletBalanceProvider, [
|
addressesProvider: tEthereumAddress,
|
||||||
addressesProvider,
|
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) =>
|
export const deployAaveProtocolTestHelpers = async (
|
||||||
await deployContract<AaveProtocolTestHelpers>(eContractid.AaveProtocolTestHelpers, [
|
addressesProvider: tEthereumAddress,
|
||||||
addressesProvider,
|
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]) =>
|
export const deployMintableErc20 = async ([name, symbol, decimals]: [string, string, number]) =>
|
||||||
await deployContract<MintableErc20>(eContractid.MintableERC20, [name, symbol, decimals]);
|
await deployContract<MintableErc20>(eContractid.MintableERC20, [name, symbol, decimals]);
|
||||||
|
|
|
@ -22,7 +22,7 @@ function delay(ms: number) {
|
||||||
export const verifyContract = async (
|
export const verifyContract = async (
|
||||||
contractName: string,
|
contractName: string,
|
||||||
address: string,
|
address: string,
|
||||||
constructorArguments: string[],
|
constructorArguments: (string | string[])[],
|
||||||
libraries?: string
|
libraries?: string
|
||||||
) => {
|
) => {
|
||||||
const currentNetwork = BRE.network.name;
|
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 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,
|
IMarketRates,
|
||||||
iAssetBase,
|
iAssetBase,
|
||||||
iAssetAggregatorBase,
|
iAssetAggregatorBase,
|
||||||
|
eContractid,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
import {LendingRateOracle} from '../types/LendingRateOracle';
|
import {LendingRateOracle} from '../types/LendingRateOracle';
|
||||||
import {PriceOracle} from '../types/PriceOracle';
|
import {PriceOracle} from '../types/PriceOracle';
|
||||||
import {MockAggregator} from '../types/MockAggregator';
|
import {MockAggregator} from '../types/MockAggregator';
|
||||||
import {deployMockAggregator} from './contracts-helpers';
|
import {deployMockAggregator, getContract} from './contracts-helpers';
|
||||||
import {waitForTx} from './misc-utils';
|
import {waitForTx} from './misc-utils';
|
||||||
|
import {verifyContract} from './etherscan-verification';
|
||||||
|
|
||||||
export const setInitialMarketRatesInRatesOracle = async (
|
export const setInitialMarketRatesInRatesOracle = async (
|
||||||
marketRates: iMultiPoolsAssets<IMarketRates>,
|
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} = {};
|
const aggregators: {[tokenSymbol: string]: MockAggregator} = {};
|
||||||
for (const tokenContractName of Object.keys(initialPrices)) {
|
for (const tokenContractName of Object.keys(initialPrices)) {
|
||||||
if (tokenContractName !== 'ETH') {
|
if (tokenContractName !== 'ETH') {
|
||||||
|
@ -55,7 +60,7 @@ export const deployAllMockAggregators = async (initialPrices: iAssetAggregatorBa
|
||||||
(value) => value === tokenContractName
|
(value) => value === tokenContractName
|
||||||
);
|
);
|
||||||
const [, price] = (Object.entries(initialPrices) as [string, string][])[priceIndex];
|
const [, price] = (Object.entries(initialPrices) as [string, string][])[priceIndex];
|
||||||
aggregators[tokenContractName] = await deployMockAggregator(price);
|
aggregators[tokenContractName] = await deployMockAggregator(price, verify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return aggregators;
|
return aggregators;
|
||||||
|
|
|
@ -21,6 +21,7 @@ import {
|
||||||
} from '../../helpers/oracles-helpers';
|
} from '../../helpers/oracles-helpers';
|
||||||
import {tEthereumAddress} from '../../helpers/types';
|
import {tEthereumAddress} from '../../helpers/types';
|
||||||
import {waitForTx} from '../../helpers/misc-utils';
|
import {waitForTx} from '../../helpers/misc-utils';
|
||||||
|
import {getAllAggregatorsAddresses, getAllTokenAddresses} from '../../helpers/mock-helpers';
|
||||||
|
|
||||||
task('deploy-oracles', 'Deploy oracles for dev enviroment')
|
task('deploy-oracles', 'Deploy oracles for dev enviroment')
|
||||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||||
|
@ -64,39 +65,23 @@ task('deploy-oracles', 'Deploy oracles for dev enviroment')
|
||||||
fallbackOracle
|
fallbackOracle
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: Missing verify
|
const mockAggregators = await deployAllMockAggregators(
|
||||||
const mockAggregators = await deployAllMockAggregators(MOCK_CHAINLINK_AGGREGATORS_PRICES);
|
MOCK_CHAINLINK_AGGREGATORS_PRICES,
|
||||||
|
verify
|
||||||
|
);
|
||||||
|
|
||||||
const allTokenAddresses = Object.entries(mockTokens).reduce(
|
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
||||||
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, tokenContract]) => ({
|
const allAggregatorsAddresses = getAllAggregatorsAddresses(mockAggregators);
|
||||||
...accum,
|
|
||||||
[tokenSymbol]: tokenContract.address,
|
|
||||||
}),
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
const allAggregatorsAddresses = Object.entries(mockAggregators).reduce(
|
|
||||||
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, aggregator]) => ({
|
|
||||||
...accum,
|
|
||||||
[tokenSymbol]: aggregator.address,
|
|
||||||
}),
|
|
||||||
{}
|
|
||||||
);
|
|
||||||
|
|
||||||
const [tokens, aggregators] = getPairsTokenAggregator(
|
const [tokens, aggregators] = getPairsTokenAggregator(
|
||||||
allTokenAddresses,
|
allTokenAddresses,
|
||||||
allAggregatorsAddresses
|
allAggregatorsAddresses
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: Missing verify and getter
|
await deployChainlinkProxyPriceProvider([tokens, aggregators, fallbackOracle.address], verify);
|
||||||
const chainlinkProxyPriceProvider = await deployChainlinkProxyPriceProvider([
|
|
||||||
tokens,
|
|
||||||
aggregators,
|
|
||||||
fallbackOracle.address,
|
|
||||||
]);
|
|
||||||
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
await waitForTx(await addressesProvider.setPriceOracle(fallbackOracle.address));
|
||||||
|
|
||||||
// TODO: Missing verify
|
const lendingRateOracle = await deployLendingRateOracle(verify);
|
||||||
const lendingRateOracle = await deployLendingRateOracle();
|
|
||||||
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
|
||||||
|
|
||||||
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
||||||
|
|
|
@ -1,39 +1,50 @@
|
||||||
import {task} from '@nomiclabs/buidler/config';
|
import {task} from '@nomiclabs/buidler/config';
|
||||||
import {
|
import {
|
||||||
getLendingPoolAddressesProvider,
|
getLendingPoolAddressesProvider,
|
||||||
getMockedTokens,
|
getMockedTokens,
|
||||||
initReserves,
|
initReserves,
|
||||||
|
deployLendingPoolLiquidationManager,
|
||||||
|
deployTokenDistributor,
|
||||||
|
deployInitializableAdminUpgradeabilityProxy,
|
||||||
|
insertContractAddressInDb,
|
||||||
|
deployMockFlashLoanReceiver,
|
||||||
|
deployWalletBalancerProvider,
|
||||||
|
deployAaveProtocolTestHelpers,
|
||||||
|
getLendingPool,
|
||||||
|
getLendingPoolConfiguratorProxy,
|
||||||
} from '../../helpers/contracts-helpers';
|
} from '../../helpers/contracts-helpers';
|
||||||
import {getReservesConfigByPool} from '../../helpers/constants';
|
import {
|
||||||
|
getReservesConfigByPool,
|
||||||
|
getFeeDistributionParamsCommon,
|
||||||
|
ZERO_ADDRESS,
|
||||||
|
} from '../../helpers/constants';
|
||||||
|
|
||||||
import {tEthereumAddress, AavePools} from '../../helpers/types';
|
import {tEthereumAddress, AavePools, eContractid} from '../../helpers/types';
|
||||||
import {waitForTx} from '../../helpers/misc-utils';
|
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')
|
task('initialize-lending-pool', 'Initialize lending pool configuration.')
|
||||||
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
.addOptionalParam('verify', 'Verify contracts at Etherscan')
|
||||||
.setAction(async ({verify}, localBRE) => {
|
.setAction(async ({verify}, localBRE) => {
|
||||||
await localBRE.run('set-bre');
|
await localBRE.run('set-bre');
|
||||||
|
|
||||||
const mockTokens = await getMockedTokens();
|
const mockTokens = await getMockedTokens();
|
||||||
|
const lendingPoolProxy = await getLendingPool();
|
||||||
const allTokenAddresses = Object.entries(mockTokens).reduce(
|
const lendingPoolConfiguratorProxy = await getLendingPoolConfiguratorProxy();
|
||||||
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, tokenContract]) => ({
|
const [lendingPoolManager, secondaryWallet] = await Promise.all(
|
||||||
...accum,
|
(await localBRE.ethers.getSigners()).map(async (x) => x.getAddress())
|
||||||
[tokenSymbol]: tokenContract.address,
|
|
||||||
}),
|
|
||||||
{}
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const allTokenAddresses = getAllTokenAddresses(mockTokens);
|
||||||
|
|
||||||
|
const {USD, ...tokensAddressesWithoutUsd} = allTokenAddresses;
|
||||||
|
|
||||||
const addressesProvider = await getLendingPoolAddressesProvider();
|
const addressesProvider = await getLendingPoolAddressesProvider();
|
||||||
|
|
||||||
const {
|
const protoPoolReservesAddresses = <{[symbol: string]: tEthereumAddress}>(
|
||||||
UNI_DAI_ETH,
|
filterMapBy(allTokenAddresses, (key: string) => !key.includes('UNI'))
|
||||||
UNI_USDC_ETH,
|
);
|
||||||
UNI_SETH_ETH,
|
|
||||||
UNI_LINK_ETH,
|
|
||||||
UNI_MKR_ETH,
|
|
||||||
UNI_LEND_ETH,
|
|
||||||
...protoPoolReservesAddresses
|
|
||||||
} = <{[symbol: string]: tEthereumAddress}>allTokenAddresses;
|
|
||||||
|
|
||||||
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
const reservesParams = getReservesConfigByPool(AavePools.proto);
|
||||||
|
|
||||||
|
@ -59,15 +70,15 @@ await localBRE.run('set-bre');
|
||||||
lendingPoolConfiguratorProxy
|
lendingPoolConfiguratorProxy
|
||||||
);
|
);
|
||||||
|
|
||||||
const liquidationManager = await deployLendingPoolLiquidationManager();
|
const liquidationManager = await deployLendingPoolLiquidationManager(verify);
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await addressesProvider.setLendingPoolLiquidationManager(liquidationManager.address)
|
await addressesProvider.setLendingPoolLiquidationManager(liquidationManager.address)
|
||||||
);
|
);
|
||||||
|
|
||||||
const {receivers, percentages} = getFeeDistributionParamsCommon(lendingPoolManager);
|
const {receivers, percentages} = getFeeDistributionParamsCommon(lendingPoolManager);
|
||||||
|
|
||||||
const tokenDistributorImpl = await deployTokenDistributor();
|
const tokenDistributorImpl = await deployTokenDistributor(verify);
|
||||||
const tokenDistributorProxy = await deployInitializableAdminUpgradeabilityProxy();
|
const tokenDistributorProxy = await deployInitializableAdminUpgradeabilityProxy(verify);
|
||||||
const implementationParams = tokenDistributorImpl.interface.encodeFunctionData('initialize', [
|
const implementationParams = tokenDistributorImpl.interface.encodeFunctionData('initialize', [
|
||||||
ZERO_ADDRESS,
|
ZERO_ADDRESS,
|
||||||
tokensAddressesWithoutUsd.LEND,
|
tokensAddressesWithoutUsd.LEND,
|
||||||
|
@ -79,7 +90,7 @@ await localBRE.run('set-bre');
|
||||||
await waitForTx(
|
await waitForTx(
|
||||||
await tokenDistributorProxy['initialize(address,address,bytes)'](
|
await tokenDistributorProxy['initialize(address,address,bytes)'](
|
||||||
tokenDistributorImpl.address,
|
tokenDistributorImpl.address,
|
||||||
await secondaryWallet.getAddress(),
|
secondaryWallet,
|
||||||
implementationParams
|
implementationParams
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -87,16 +98,18 @@ await localBRE.run('set-bre');
|
||||||
|
|
||||||
await insertContractAddressInDb(eContractid.TokenDistributor, tokenDistributorProxy.address);
|
await insertContractAddressInDb(eContractid.TokenDistributor, tokenDistributorProxy.address);
|
||||||
|
|
||||||
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(addressesProvider.address);
|
const mockFlashLoanReceiver = await deployMockFlashLoanReceiver(
|
||||||
|
addressesProvider.address,
|
||||||
|
verify
|
||||||
|
);
|
||||||
await insertContractAddressInDb(
|
await insertContractAddressInDb(
|
||||||
eContractid.MockFlashLoanReceiver,
|
eContractid.MockFlashLoanReceiver,
|
||||||
mockFlashLoanReceiver.address
|
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);
|
await insertContractAddressInDb(eContractid.AaveProtocolTestHelpers, testHelpers.address);
|
||||||
|
});
|
||||||
});
|
|
|
@ -25,10 +25,8 @@ task('dev-migration', 'Deploy development enviroment')
|
||||||
console.log('4. Deploy oracles');
|
console.log('4. Deploy oracles');
|
||||||
await localBRE.run('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');
|
console.log('\nFinished migration');
|
||||||
});
|
});
|
||||||
|
|
|
@ -27,6 +27,7 @@ import {
|
||||||
deployVariableDebtToken,
|
deployVariableDebtToken,
|
||||||
deployGenericAToken,
|
deployGenericAToken,
|
||||||
getPairsTokenAggregator,
|
getPairsTokenAggregator,
|
||||||
|
initReserves,
|
||||||
} from '../helpers/contracts-helpers';
|
} from '../helpers/contracts-helpers';
|
||||||
import {LendingPoolAddressesProvider} from '../types/LendingPoolAddressesProvider';
|
import {LendingPoolAddressesProvider} from '../types/LendingPoolAddressesProvider';
|
||||||
import {Signer} from 'ethers';
|
import {Signer} from 'ethers';
|
||||||
|
@ -59,6 +60,7 @@ import {
|
||||||
deployAllMockAggregators,
|
deployAllMockAggregators,
|
||||||
} from '../helpers/oracles-helpers';
|
} from '../helpers/oracles-helpers';
|
||||||
import {waitForTx} from '../helpers/misc-utils';
|
import {waitForTx} from '../helpers/misc-utils';
|
||||||
|
import {enableReservesToBorrow, enableReservesAsCollateral} from '../helpers/init-helpers';
|
||||||
|
|
||||||
const deployAllMockTokens = async (deployer: Signer) => {
|
const deployAllMockTokens = async (deployer: Signer) => {
|
||||||
const tokens: {[symbol: string]: MockContract | MintableErc20} = {};
|
const tokens: {[symbol: string]: MockContract | MintableErc20} = {};
|
||||||
|
@ -90,83 +92,6 @@ const deployAllMockTokens = async (deployer: Signer) => {
|
||||||
return tokens;
|
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) => {
|
const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
|
||||||
console.time('setup');
|
console.time('setup');
|
||||||
const lendingPoolManager = await deployer.getAddress();
|
const lendingPoolManager = await deployer.getAddress();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user