Deployment function optimizations WIP

This commit is contained in:
David Racero 2020-10-15 19:19:02 +02:00
parent 88a2cb21f4
commit 03504849f1
14 changed files with 348 additions and 329 deletions

View File

@ -97,7 +97,7 @@
},
"PriceOracle": {
"buidlerevm": {
"address": "0x1750499D05Ed1674d822430FB960d5F6731fDf64",
"address": "0x0C6c3C47A1f650809B0D1048FDf9603e09473D7E",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -111,7 +111,7 @@
},
"MockAggregator": {
"buidlerevm": {
"address": "0xEC1C93A9f6a9e18E97784c76aC52053587FcDB89",
"address": "0xc11f8E173ee67ffA7BBdD185D2399994AAd23Ec6",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -125,7 +125,7 @@
},
"ChainlinkProxyPriceProvider": {
"buidlerevm": {
"address": "0x7B6C3e5486D9e6959441ab554A889099eed76290",
"address": "0xD662fb7FDC7526C79AA4417d2A4415416e057ec4",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -143,7 +143,7 @@
},
"LendingRateOracle": {
"buidlerevm": {
"address": "0xD83D2773a7873ae2b5f8Fb92097e20a8C64F691E",
"address": "0xEC1C93A9f6a9e18E97784c76aC52053587FcDB89",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -161,7 +161,7 @@
},
"DefaultReserveInterestRateStrategy": {
"buidlerevm": {
"address": "0xB660Fdd109a95718cB9d20E3A89EE6cE342aDcB6",
"address": "0x7d40dD74d3aE1a7e4A7dd08eaE899e85940563cd",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -220,7 +220,7 @@
},
"MockFlashLoanReceiver": {
"buidlerevm": {
"address": "0xBEF0d4b9c089a5883741fC14cbA352055f35DDA2"
"address": "0x63387deC8C4a0F17Cf0C27Ea3476F03F6a45d3AE"
},
"localhost": {
"address": "0x2B681757d757fbB80cc51c6094cEF5eE75bF55aA"
@ -231,7 +231,7 @@
},
"WalletBalanceProvider": {
"buidlerevm": {
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4",
"address": "0x2B681757d757fbB80cc51c6094cEF5eE75bF55aA",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -567,7 +567,7 @@
},
"AaveProtocolTestHelpers": {
"buidlerevm": {
"address": "0xe7536f450378748E1BD4645D3c77ec38e0F3ba28"
"address": "0x93472C0e03215F9c33DA240Eb16703C8244eAa8c"
},
"localhost": {
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4"
@ -578,7 +578,7 @@
},
"StableDebtToken": {
"buidlerevm": {
"address": "0x830bceA96E56DBC1F8578f75fBaC0AF16B32A07d",
"address": "0x5f687ea375c359E0CF6aa8A1004BE0c3BaBee7Fd",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -592,7 +592,7 @@
},
"VariableDebtToken": {
"buidlerevm": {
"address": "0xA0AB1cB92A4AF81f84dCd258155B5c25D247b54E",
"address": "0x626FdE749F9d499d3777320CAf29484B624ab84a",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -610,7 +610,7 @@
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"buidlerevm": {
"address": "0x5f7134cd38C826a7649f9Cc47dda24d834DD2967",
"address": "0xB660Fdd109a95718cB9d20E3A89EE6cE342aDcB6",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"coverage": {
@ -620,7 +620,7 @@
},
"MockAToken": {
"buidlerevm": {
"address": "0x392E5355a0e88Bd394F717227c752670fb3a8020",
"address": "0xBEF0d4b9c089a5883741fC14cbA352055f35DDA2",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -648,7 +648,7 @@
},
"MockStableDebtToken": {
"buidlerevm": {
"address": "0x3b050AFb4ac4ACE646b31fF3639C1CD43aC31460",
"address": "0xDf73fC454FA018051D4a1509e63D11530A59DE10",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -662,7 +662,7 @@
},
"MockVariableDebtToken": {
"buidlerevm": {
"address": "0xEBAB67ee3ef604D5c250A53b4b8fcbBC6ec3007C",
"address": "0x2cfcA5785261fbC88EFFDd46fCFc04c22525F9e4",
"deployer": "0xc783df8a850f42e7F7e57013759C285caa701eB6"
},
"localhost": {
@ -676,7 +676,7 @@
},
"MockSwapAdapter": {
"buidlerevm": {
"address": "0xDf73fC454FA018051D4a1509e63D11530A59DE10"
"address": "0x8280D40C9E9F04229D2435EAad6e0011309ce81B"
},
"coverage": {
"address": "0xBEF0d4b9c089a5883741fC14cbA352055f35DDA2"

View File

@ -2,6 +2,7 @@ import {
AaveProtocolTestHelpersFactory,
ATokenFactory,
DefaultReserveInterestRateStrategyFactory,
GenericLogicFactory,
LendingPoolAddressesProviderFactory,
LendingPoolAddressesProviderRegistryFactory,
LendingPoolConfiguratorFactory,
@ -11,20 +12,23 @@ import {
MockFlashLoanReceiverFactory,
MockSwapAdapterFactory,
PriceOracleFactory,
ReserveLogicFactory,
StableDebtTokenFactory,
VariableDebtTokenFactory,
} from '../types';
import {Ierc20DetailedFactory} from '../types/Ierc20DetailedFactory';
import {MockTokenMap} from './contracts-helpers';
import {getContract, MockTokenMap} from './contracts-helpers';
import {BRE, getDb} from './misc-utils';
import {eContractid, PoolConfiguration, tEthereumAddress, TokenContractId} from './types';
export const getFirstSigner = async () => (await BRE.ethers.getSigners())[0];
export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress) =>
await LendingPoolAddressesProviderFactory.connect(
address ||
(await getDb().get(`${eContractid.LendingPoolAddressesProvider}.${BRE.network.name}`).value())
.address,
BRE.ethers.provider
await getFirstSigner()
);
export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress) => {
@ -32,7 +36,7 @@ export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress
address ||
(await getDb().get(`${eContractid.LendingPoolConfigurator}.${BRE.network.name}`).value())
.address,
BRE.ethers.provider
await getFirstSigner()
);
};
@ -40,48 +44,48 @@ export const getLendingPool = async (address?: tEthereumAddress) =>
await LendingPoolFactory.connect(
address ||
(await getDb().get(`${eContractid.LendingPool}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getPriceOracle = async (address?: tEthereumAddress) =>
await PriceOracleFactory.connect(
address ||
(await getDb().get(`${eContractid.PriceOracle}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getAToken = async (address?: tEthereumAddress) =>
await ATokenFactory.connect(
address || (await getDb().get(`${eContractid.AToken}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getStableDebtToken = async (address?: tEthereumAddress) =>
await StableDebtTokenFactory.connect(
address ||
(await getDb().get(`${eContractid.StableDebtToken}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getVariableDebtToken = async (address?: tEthereumAddress) =>
await VariableDebtTokenFactory.connect(
address ||
(await getDb().get(`${eContractid.VariableDebtToken}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getMintableErc20 = async (address: tEthereumAddress) =>
await MintableErc20Factory.connect(
address ||
(await getDb().get(`${eContractid.MintableERC20}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getIErc20Detailed = async (address: tEthereumAddress) =>
await Ierc20DetailedFactory.connect(
address ||
(await getDb().get(`${eContractid.IERC20Detailed}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getAaveProtocolTestHelpers = async (address?: tEthereumAddress) =>
@ -89,7 +93,7 @@ export const getAaveProtocolTestHelpers = async (address?: tEthereumAddress) =>
address ||
(await getDb().get(`${eContractid.AaveProtocolTestHelpers}.${BRE.network.name}`).value())
.address,
BRE.ethers.provider
await getFirstSigner()
);
export const getInterestRateStrategy = async (address?: tEthereumAddress) =>
@ -100,7 +104,7 @@ export const getInterestRateStrategy = async (address?: tEthereumAddress) =>
.get(`${eContractid.DefaultReserveInterestRateStrategy}.${BRE.network.name}`)
.value()
).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getMockFlashLoanReceiver = async (address?: tEthereumAddress) =>
@ -108,21 +112,21 @@ export const getMockFlashLoanReceiver = async (address?: tEthereumAddress) =>
address ||
(await getDb().get(`${eContractid.MockFlashLoanReceiver}.${BRE.network.name}`).value())
.address,
BRE.ethers.provider
await getFirstSigner()
);
export const getMockSwapAdapter = async (address?: tEthereumAddress) =>
await MockSwapAdapterFactory.connect(
address ||
(await getDb().get(`${eContractid.MockSwapAdapter}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getLendingRateOracle = async (address?: tEthereumAddress) =>
await LendingRateOracleFactory.connect(
address ||
(await getDb().get(`${eContractid.LendingRateOracle}.${BRE.network.name}`).value()).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getMockedTokens = async (config: PoolConfiguration) => {
@ -189,5 +193,27 @@ export const getLendingPoolAddressesProviderRegistry = async (address?: tEthereu
.get(`${eContractid.LendingPoolAddressesProviderRegistry}.${BRE.network.name}`)
.value()
).address,
BRE.ethers.provider
await getFirstSigner()
);
export const getReserveLogicLibrary = async (address?: tEthereumAddress) =>
await ReserveLogicFactory.connect(
address ||
(
await getDb()
.get(`${eContractid.LendingPoolAddressesProviderRegistry}.${BRE.network.name}`)
.value()
).address,
await getFirstSigner()
);
export const getGenericLogic = async (address?: tEthereumAddress) =>
await GenericLogicFactory.connect(
address ||
(
await getDb()
.get(`${eContractid.LendingPoolAddressesProviderRegistry}.${BRE.network.name}`)
.value()
).address,
await getFirstSigner()
);

View File

@ -15,16 +15,10 @@ import {
PoolConfiguration,
} from './types';
import {LendingPoolAddressesProvider} from '../types/LendingPoolAddressesProvider';
import {MintableErc20 as MintableERC20} from '../types/MintableErc20';
import {LendingPoolAddressesProviderRegistry} from '../types/LendingPoolAddressesProviderRegistry';
import {LendingPoolConfigurator} from '../types/LendingPoolConfigurator';
import {readArtifact} from '@nomiclabs/buidler/plugins';
import {Artifact} from '@nomiclabs/buidler/types';
import {LendingPool} from '../types/LendingPool';
import {DefaultReserveInterestRateStrategy} from '../types/DefaultReserveInterestRateStrategy';
import {LendingPoolCollateralManager} from '../types/LendingPoolCollateralManager';
import {InitializableAdminUpgradeabilityProxy} from '../types/InitializableAdminUpgradeabilityProxy';
import {MockFlashLoanReceiver} from '../types/MockFlashLoanReceiver';
import {WalletBalanceProvider} from '../types/WalletBalanceProvider';
import {AToken} from '../types/AToken';
@ -35,7 +29,7 @@ import {VariableDebtToken} from '../types/VariableDebtToken';
import {MockContract} from 'ethereum-waffle';
import {getReservesConfigByPool} from './configuration';
import {verifyContract} from './etherscan-verification';
import {getFirstSigner, getGenericLogic} from './contracts-getters';
const {
ProtocolGlobalParams: {UsdAddress},
} = CommonsConfig;
@ -45,15 +39,25 @@ import {ZERO_ADDRESS} from './constants';
import {MockSwapAdapter} from '../types/MockSwapAdapter';
import {signTypedData_v4, TypedData} from 'eth-sig-util';
import {fromRpcSig, ECDSASignature} from 'ethereumjs-util';
import {getIErc20Detailed} from './contracts-getters';
import {
ChainlinkProxyPriceProviderFactory,
GenericLogicFactory,
InitializableAdminUpgradeabilityProxyFactory,
LendingPoolAddressesProviderFactory,
LendingPoolAddressesProviderRegistryFactory,
LendingPoolCollateralManagerFactory,
LendingPoolConfiguratorFactory,
LendingPoolFactory,
LendingPoolLibraryAddresses,
LendingRateOracleFactory,
MockAggregatorFactory,
MockFlashLoanReceiverFactory,
MockSwapAdapterFactory,
PriceOracleFactory,
ReserveLogicFactory,
WalletBalanceProviderFactory,
} from '../types';
import {getIErc20Detailed} from './contracts-getters';
export const registerContractInJsonDb = async (contractId: string, contractInstance: Contract) => {
const currentNetwork = BRE.network.name;
@ -109,71 +113,69 @@ export const deployContract = async <ContractType extends Contract>(
return contract;
};
export const withSaveAndVerify = async (
instance: Contract,
id: string,
args: (string | string[])[],
verify?: boolean
) => {
await registerContractInJsonDb(id, instance);
if (verify) {
await verifyContract(id, instance.address, args);
}
return instance;
};
export const getContract = async <ContractType extends Contract>(
contractName: string,
address: string
): Promise<ContractType> => (await BRE.ethers.getContractAt(contractName, address)) as ContractType;
export const deployLendingPoolAddressesProvider = async (verify?: boolean) => {
const instance = await deployContract<LendingPoolAddressesProvider>(
export const deployLendingPoolAddressesProvider = async (verify?: boolean) =>
withSaveAndVerify(
await new LendingPoolAddressesProviderFactory(await getFirstSigner()).deploy(),
eContractid.LendingPoolAddressesProvider,
[]
[],
verify
);
if (verify) {
await verifyContract(eContractid.LendingPoolAddressesProvider, instance.address, []);
}
return instance;
};
export const deployLendingPoolAddressesProviderRegistry = async (verify?: boolean) => {
const instance = await deployContract<LendingPoolAddressesProviderRegistry>(
export const deployLendingPoolAddressesProviderRegistry = async (verify?: boolean) =>
withSaveAndVerify(
await new LendingPoolAddressesProviderRegistryFactory(await getFirstSigner()).deploy(),
eContractid.LendingPoolAddressesProviderRegistry,
[]
[],
verify
);
if (verify) {
await verifyContract(eContractid.LendingPoolAddressesProviderRegistry, instance.address, []);
}
return instance;
};
export const deployLendingPoolConfigurator = async (verify?: boolean) => {
const instance = await deployContract<LendingPoolConfigurator>(
export const deployLendingPoolConfigurator = async (verify?: boolean) =>
withSaveAndVerify(
await new LendingPoolConfiguratorFactory(await getFirstSigner()).deploy(),
eContractid.LendingPoolConfigurator,
[]
);
if (verify) {
await verifyContract(eContractid.LendingPoolConfigurator, instance.address, []);
}
return instance;
};
const deployLibrary = async (libraryId: eContractid) => {
const factory = await BRE.ethers.getContractFactory(libraryId);
const library = await factory.deploy();
await library.deployed();
return library;
};
export const linkLibrariesToArtifact = async (artifact: Artifact) => {
const reserveLogic = await deployLibrary(eContractid.ReserveLogic);
const genericLogicArtifact = await readArtifact(
BRE.config.paths.artifacts,
eContractid.GenericLogic
[],
verify
);
const linkedGenericLogicByteCode = linkBytecode(genericLogicArtifact, {
[eContractid.ReserveLogic]: reserveLogic.address,
});
const genericLogicFactory = await BRE.ethers.getContractFactory(
genericLogicArtifact.abi,
linkedGenericLogicByteCode
export const deployReserveLogicLibrary = async (verify?: boolean) =>
withSaveAndVerify(
await new ReserveLogicFactory(await getFirstSigner()).deploy(),
eContractid.ReserveLogic,
[],
verify
);
const genericLogic = await (await genericLogicFactory.deploy()).deployed();
export const deployGenericLogic = async (verify?: boolean) =>
withSaveAndVerify(
await new GenericLogicFactory(await getFirstSigner()).deploy(),
eContractid.GenericLogic,
[],
verify
);
export const deployValidationLogic = async (
reserveLogic: Contract,
genericLogic: Contract,
verify?: boolean
) => {
const validationLogicArtifact = await readArtifact(
BRE.config.paths.artifacts,
eContractid.ValidationLogic
@ -191,141 +193,122 @@ export const linkLibrariesToArtifact = async (artifact: Artifact) => {
const validationLogic = await (await validationLogicFactory.deploy()).deployed();
const linkedBytecode = linkBytecode(artifact, {
[eContractid.ReserveLogic]: reserveLogic.address,
[eContractid.GenericLogic]: genericLogic.address,
[eContractid.ValidationLogic]: validationLogic.address,
});
const factory = await BRE.ethers.getContractFactory(artifact.abi, linkedBytecode);
return withSaveAndVerify(validationLogic, eContractid.ValidationLogic, [], verify);
};
return factory;
export const deployAaveLibraries = async (
verify?: boolean
): Promise<LendingPoolLibraryAddresses> => {
const reserveLogic = await deployReserveLogicLibrary(verify);
const genericLogic = await deployGenericLogic(verify);
const validationLogic = await deployValidationLogic(reserveLogic, genericLogic, verify);
// Hardcoded solidity placeholders, if any library changes path this will fail.
// Placeholder can be calculated via solidity keccak, but the LendingPoolLibraryAddresses Type seems to
// require a hardcoded string.
//
// how-to: PLACEHOLDER = solidityKeccak256(['string'], `${libPath}:${libName}`).slice(2, 36)
// '__$PLACEHOLDER$__'
// or grab placeholdes from LendingPoolLibraryAddresses at Typechain generation.
return {
['__$5201a97c05ba6aa659e2f36a933dd51801$__']: reserveLogic.address,
['__$d3b4366daeb9cadc7528af6145b50b2183$__']: genericLogic.address,
['__$4c26be947d349222af871a3168b3fe584b$__']: validationLogic.address,
};
};
export const deployLendingPool = async (verify?: boolean) => {
const lendingPoolArtifact = await readArtifact(
BRE.config.paths.artifacts,
eContractid.LendingPool
const libraries = await deployAaveLibraries(verify);
return withSaveAndVerify(
await new LendingPoolFactory(libraries, await getFirstSigner()).deploy(),
eContractid.LendingPool,
[],
verify
);
const factory = await linkLibrariesToArtifact(lendingPoolArtifact);
const lendingPool = await factory.deploy();
const instance = (await lendingPool.deployed()) as LendingPool;
if (verify) {
await verifyContract(eContractid.LendingPool, instance.address, []);
}
return instance;
};
export const deployPriceOracle = async (verify?: boolean) => {
const instance = await new PriceOracleFactory().deploy();
if (verify) {
await verifyContract(eContractid.PriceOracle, instance.address, []);
}
return instance;
};
export const deployPriceOracle = async (verify?: boolean) =>
withSaveAndVerify(
await new PriceOracleFactory(await getFirstSigner()).deploy(),
eContractid.PriceOracle,
[],
verify
);
export const deployLendingRateOracle = async (verify?: boolean) => {
const instance = await new LendingRateOracleFactory().deploy();
if (verify) {
await verifyContract(eContractid.LendingRateOracle, instance.address, []);
}
return instance;
};
export const deployLendingRateOracle = async (verify?: boolean) =>
withSaveAndVerify(
await new LendingRateOracleFactory(await getFirstSigner()).deploy(),
eContractid.LendingRateOracle,
[],
verify
);
export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify?: boolean) => {
const args: [tStringTokenSmallUnits] = [price];
const instance = await new MockAggregatorFactory().deploy(...args);
if (verify) {
await verifyContract(eContractid.MockAggregator, instance.address, args);
}
return instance;
};
export const deployMockAggregator = async (price: tStringTokenSmallUnits, verify?: boolean) =>
withSaveAndVerify(
await new MockAggregatorFactory(await getFirstSigner()).deploy(price),
eContractid.MockAggregator,
[price],
verify
);
export const deployChainlinkProxyPriceProvider = async (
[assetsAddresses, sourcesAddresses, fallbackOracleAddress]: [
tEthereumAddress[],
tEthereumAddress[],
tEthereumAddress
],
args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress],
verify?: boolean
) => {
const args: [tEthereumAddress[], tEthereumAddress[], tEthereumAddress] = [
assetsAddresses,
sourcesAddresses,
fallbackOracleAddress,
];
const instance = await new ChainlinkProxyPriceProviderFactory().deploy(...args);
if (verify) {
await verifyContract(eContractid.MockAggregator, instance.address, args);
}
return instance;
};
export const getChainlingProxyPriceProvider = async (address?: tEthereumAddress) =>
new ChainlinkProxyPriceProviderFactory().attach(
address ||
(await getDb().get(`${eContractid.ChainlinkProxyPriceProvider}.${BRE.network.name}`).value())
.address
) =>
withSaveAndVerify(
await new ChainlinkProxyPriceProviderFactory(await getFirstSigner()).deploy(...args),
eContractid.ChainlinkProxyPriceProvider,
args,
verify
);
export const deployLendingPoolCollateralManager = async (verify?: boolean) => {
const collateralManagerArtifact = await readArtifact(
BRE.config.paths.artifacts,
eContractid.LendingPoolCollateralManager
const genericLogic = await getGenericLogic();
const libraries = {
// See deployAaveLibraries() function
['__$d3b4366daeb9cadc7528af6145b50b2183$__']: genericLogic.address,
};
return withSaveAndVerify(
await new LendingPoolCollateralManagerFactory(libraries, await getFirstSigner()).deploy(),
eContractid.LendingPoolCollateralManager,
[],
verify
);
const factory = await linkLibrariesToArtifact(collateralManagerArtifact);
const args: string[] = [];
const collateralManager = await factory.deploy(args);
const instance = (await collateralManager.deployed()) as LendingPoolCollateralManager;
if (verify) {
await verifyContract(eContractid.LendingPoolCollateralManager, instance.address, args);
}
return instance;
};
export const deployInitializableAdminUpgradeabilityProxy = async (verify?: boolean) => {
const instance = await deployContract<InitializableAdminUpgradeabilityProxy>(
export const deployInitializableAdminUpgradeabilityProxy = async (verify?: boolean) =>
withSaveAndVerify(
await new InitializableAdminUpgradeabilityProxyFactory(await getFirstSigner()).deploy(),
eContractid.InitializableAdminUpgradeabilityProxy,
[]
[],
verify
);
if (verify) {
await verifyContract(eContractid.InitializableAdminUpgradeabilityProxy, instance.address, []);
}
return instance;
};
export const deployMockFlashLoanReceiver = async (
addressesProvider: tEthereumAddress,
verify?: boolean
) => {
const args = [addressesProvider];
const instance = await deployContract<MockFlashLoanReceiver>(
) =>
withSaveAndVerify(
await new MockFlashLoanReceiverFactory(await getFirstSigner()).deploy(addressesProvider),
eContractid.MockFlashLoanReceiver,
args
[addressesProvider],
verify
);
if (verify) {
await verifyContract(eContractid.MockFlashLoanReceiver, instance.address, args);
}
return instance;
};
export const deployWalletBalancerProvider = async (
addressesProvider: tEthereumAddress,
verify?: boolean
) => {
const args = [addressesProvider];
const instance = await deployContract<WalletBalanceProvider>(
) =>
withSaveAndVerify(
await new WalletBalanceProviderFactory(await getFirstSigner()).deploy(addressesProvider),
eContractid.WalletBalanceProvider,
args
[addressesProvider],
verify
);
if (verify) {
await verifyContract(eContractid.WalletBalanceProvider, instance.address, args);
}
return instance;
};
export const deployMockSwapAdapter = async (addressesProvider: tEthereumAddress) =>
await deployContract<MockSwapAdapter>(eContractid.MockSwapAdapter, [addressesProvider]);
await new MockSwapAdapterFactory(await getFirstSigner()).deploy(addressesProvider);
export const deployAaveProtocolTestHelpers = async (
addressesProvider: tEthereumAddress,
@ -565,121 +548,6 @@ export const deployMockTokens = async (config: PoolConfiguration, verify?: boole
return tokens;
};
export const initReserves = async (
reservesParams: iMultiPoolsAssets<IReserveParams>,
tokenAddresses: {[symbol: string]: tEthereumAddress},
lendingPoolAddressesProvider: LendingPoolAddressesProvider,
lendingPool: LendingPool,
helpers: AaveProtocolTestHelpers,
lendingPoolConfigurator: LendingPoolConfigurator,
aavePool: AavePools,
incentivesController: tEthereumAddress,
verify: boolean
) => {
if (aavePool !== AavePools.proto && aavePool !== AavePools.secondary) {
console.log(`Invalid Aave pool ${aavePool}`);
process.exit(1);
}
for (let [assetSymbol, {reserveDecimals}] of Object.entries(reservesParams) as [
string,
IReserveParams
][]) {
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
(value) => value === assetSymbol
);
const [, tokenAddress] = (Object.entries(tokenAddresses) as [string, string][])[
assetAddressIndex
];
const {isActive: reserveInitialized} = await helpers.getReserveConfigurationData(tokenAddress);
if (reserveInitialized) {
console.log(`Reserve ${assetSymbol} is already active, skipping configuration`);
continue;
}
try {
const reserveParamIndex = Object.keys(reservesParams).findIndex(
(value) => value === assetSymbol
);
const [
,
{
baseVariableBorrowRate,
variableRateSlope1,
variableRateSlope2,
stableRateSlope1,
stableRateSlope2,
},
] = (Object.entries(reservesParams) as [string, IReserveParams][])[reserveParamIndex];
const rateStrategyContract = await deployDefaultReserveInterestRateStrategy(
[
lendingPoolAddressesProvider.address,
baseVariableBorrowRate,
variableRateSlope1,
variableRateSlope2,
stableRateSlope1,
stableRateSlope2,
],
verify
);
const stableDebtToken = await deployStableDebtToken(
[
`Aave stable debt bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
`stableDebt${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
tokenAddress,
lendingPool.address,
incentivesController,
],
verify
);
const variableDebtToken = await deployVariableDebtToken(
[
`Aave variable debt bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
`variableDebt${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
tokenAddress,
lendingPool.address,
incentivesController,
],
verify
);
const aToken = await deployGenericAToken(
[
lendingPool.address,
tokenAddress,
`Aave interest bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
`a${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
incentivesController,
],
verify
);
if (process.env.POOL === AavePools.secondary) {
if (assetSymbol.search('UNI') === -1) {
assetSymbol = `Uni${assetSymbol}`;
} else {
assetSymbol = assetSymbol.replace(/_/g, '').replace('UNI', 'Uni');
}
}
await lendingPoolConfigurator.initReserve(
tokenAddress,
aToken.address,
stableDebtToken.address,
variableDebtToken.address,
reserveDecimals,
rateStrategyContract.address
);
} catch (e) {
console.log(`Reserve initialization for ${assetSymbol} failed with error ${e}. Skipped.`);
}
}
};
export const buildPermitParams = (
chainId: number,
token: tEthereumAddress,

View File

@ -1,7 +1,14 @@
import {iMultiPoolsAssets, IReserveParams, tEthereumAddress} from './types';
import {AavePools, iMultiPoolsAssets, IReserveParams, tEthereumAddress} from './types';
import {LendingPool} from '../types/LendingPool';
import {LendingPoolConfigurator} from '../types/LendingPoolConfigurator';
import {AaveProtocolTestHelpers} from '../types/AaveProtocolTestHelpers';
import {LendingPoolAddressesProvider} from '../types/LendingPoolAddressesProvider';
import {
deployDefaultReserveInterestRateStrategy,
deployStableDebtToken,
deployVariableDebtToken,
deployGenericAToken,
} from './contracts-helpers';
export const enableReservesToBorrow = async (
reservesParams: iMultiPoolsAssets<IReserveParams>,
@ -79,3 +86,123 @@ export const enableReservesAsCollateral = async (
}
}
};
export const initReserves = async (
reservesParams: iMultiPoolsAssets<IReserveParams>,
tokenAddresses: {[symbol: string]: tEthereumAddress},
lendingPoolAddressesProvider: LendingPoolAddressesProvider,
lendingPool: LendingPool,
helpers: AaveProtocolTestHelpers,
lendingPoolConfigurator: LendingPoolConfigurator,
aavePool: AavePools,
incentivesController: tEthereumAddress,
verify: boolean
) => {
if (aavePool !== AavePools.proto && aavePool !== AavePools.secondary) {
console.log(`Invalid Aave pool ${aavePool}`);
process.exit(1);
}
for (let [assetSymbol, {reserveDecimals}] of Object.entries(reservesParams) as [
string,
IReserveParams
][]) {
const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
(value) => value === assetSymbol
);
const [, tokenAddress] = (Object.entries(tokenAddresses) as [string, string][])[
assetAddressIndex
];
const {isActive: reserveInitialized} = await helpers.getReserveConfigurationData(tokenAddress);
if (reserveInitialized) {
console.log(`Reserve ${assetSymbol} is already active, skipping configuration`);
continue;
}
try {
const reserveParamIndex = Object.keys(reservesParams).findIndex(
(value) => value === assetSymbol
);
const [
,
{
baseVariableBorrowRate,
variableRateSlope1,
variableRateSlope2,
stableRateSlope1,
stableRateSlope2,
},
] = (Object.entries(reservesParams) as [string, IReserveParams][])[reserveParamIndex];
console.log('- Deploy def reserve');
const rateStrategyContract = await deployDefaultReserveInterestRateStrategy(
[
lendingPoolAddressesProvider.address,
baseVariableBorrowRate,
variableRateSlope1,
variableRateSlope2,
stableRateSlope1,
stableRateSlope2,
],
verify
);
console.log('- Deploy stable deb totken ', assetSymbol);
const stableDebtToken = await deployStableDebtToken(
[
`Aave stable debt bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
`stableDebt${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
tokenAddress,
lendingPool.address,
incentivesController,
],
verify
);
console.log('- Deploy var deb totken ', assetSymbol);
const variableDebtToken = await deployVariableDebtToken(
[
`Aave variable debt bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
`variableDebt${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
tokenAddress,
lendingPool.address,
incentivesController,
],
verify
);
console.log('- Deploy a token ', assetSymbol);
const aToken = await deployGenericAToken(
[
lendingPool.address,
tokenAddress,
`Aave interest bearing ${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
`a${assetSymbol === 'WETH' ? 'ETH' : assetSymbol}`,
incentivesController,
],
verify
);
if (process.env.POOL === AavePools.secondary) {
if (assetSymbol.search('UNI') === -1) {
assetSymbol = `Uni${assetSymbol}`;
} else {
assetSymbol = assetSymbol.replace(/_/g, '').replace('UNI', 'Uni');
}
}
console.log('- init reserve currency ', assetSymbol);
await lendingPoolConfigurator.initReserve(
tokenAddress,
aToken.address,
stableDebtToken.address,
variableDebtToken.address,
reserveDecimals,
rateStrategyContract.address
);
} catch (e) {
console.log(`Reserve initialization for ${assetSymbol} failed with error ${e}. Skipped.`);
}
}
};

View File

@ -5,6 +5,8 @@ import FileSync from 'lowdb/adapters/FileSync';
import {WAD} from './constants';
import {Wallet, ContractTransaction} from 'ethers';
import {BuidlerRuntimeEnvironment} from '@nomiclabs/buidler/types';
import path from 'path';
import fs from 'fs';
export const toWad = (value: string | number) => new BigNumber(value).times(WAD).toFixed();

View File

@ -47,7 +47,9 @@ export const setInitialAssetPricesInOracle = async (
const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[
assetAddressIndex
];
console.log('PRIOR');
await waitForTx(await priceOracleInstance.setAssetPrice(assetAddress, price));
console.log('AFTA');
}
};

View File

@ -93,7 +93,6 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
const lendingPoolImpl = await deployLendingPool();
console.log('Deployed lending pool, address:', lendingPoolImpl.address);
await waitForTx(await addressesProvider.setLendingPoolImpl(lendingPoolImpl.address));
console.log('Added pool to addresses provider');
@ -153,7 +152,10 @@ const buildTestEnv = async (deployer: Signer, secondaryWallet: Signer) => {
fallbackOracle
);
console.log('setted prices');
console.log('prior mocks');
const mockAggregators = await deployAllMockAggregators(MOCK_CHAINLINK_AGGREGATORS_PRICES);
console.log('aftahlocks');
const allTokenAddresses = Object.entries(mockTokens).reduce(
(accum: {[tokenSymbol: string]: tEthereumAddress}, [tokenSymbol, tokenContract]) => ({

View File

@ -1,6 +1,6 @@
import {makeSuite, TestEnv} from './helpers/make-suite';
import {MockSwapAdapter} from '../types/MockSwapAdapter';
import {getMockSwapAdapter} from '../helpers/contracts-helpers';
import {getMockSwapAdapter} from '../helpers/contracts-getters';
import {ProtocolErrors} from '../helpers/types';
import {ethers} from 'ethers';
import {APPROVAL_AMOUNT_LENDING_POOL} from '../helpers/constants';

View File

@ -2,16 +2,13 @@ import BigNumber from 'bignumber.js';
import {TestEnv, makeSuite} from './helpers/make-suite';
import {APPROVAL_AMOUNT_LENDING_POOL, oneRay} from '../helpers/constants';
import {
convertToCurrencyDecimals,
getMockFlashLoanReceiver,
getContract,
} from '../helpers/contracts-helpers';
import {convertToCurrencyDecimals, getContract} from '../helpers/contracts-helpers';
import {ethers} from 'ethers';
import {MockFlashLoanReceiver} from '../types/MockFlashLoanReceiver';
import {ProtocolErrors, eContractid} from '../helpers/types';
import {VariableDebtToken} from '../types/VariableDebtToken';
import {StableDebtToken} from '../types/StableDebtToken';
import {getMockFlashLoanReceiver} from '../helpers/contracts-getters';
const {expect} = require('chai');

View File

@ -17,11 +17,8 @@ import {
} from './utils/calculations';
import {getReserveAddressFromSymbol, getReserveData, getUserData} from './utils/helpers';
import {
convertToCurrencyDecimals,
getAToken,
getMintableErc20,
} from '../../helpers/contracts-helpers';
import {convertToCurrencyDecimals} from '../../helpers/contracts-helpers';
import {getAToken, getMintableErc20} from '../../helpers/contracts-getters';
import {MAX_UINT_AMOUNT, ONE_YEAR} from '../../helpers/constants';
import {SignerWithAddress, TestEnv} from './make-suite';
import {BRE, increaseTime, timeLatest, waitForTx} from '../../helpers/misc-utils';

View File

@ -1,7 +1,6 @@
import {evmRevert, evmSnapshot, BRE} from '../../helpers/misc-utils';
import {Signer} from 'ethers';
import {
getEthersSigners,
getLendingPool,
getLendingPoolAddressesProvider,
getAaveProtocolTestHelpers,
@ -11,7 +10,7 @@ import {
getPriceOracle,
getMockSwapAdapter,
getLendingPoolAddressesProviderRegistry,
} from '../../helpers/contracts-helpers';
} from '../../helpers/contracts-getters';
import {tEthereumAddress} from '../../helpers/types';
import {LendingPool} from '../../types/LendingPool';
import {AaveProtocolTestHelpers} from '../../types/AaveProtocolTestHelpers';
@ -27,6 +26,8 @@ import {PriceOracle} from '../../types/PriceOracle';
import {LendingPoolAddressesProvider} from '../../types/LendingPoolAddressesProvider';
import {MockSwapAdapter} from '../../types/MockSwapAdapter';
import {LendingPoolAddressesProviderRegistry} from '../../types/LendingPoolAddressesProviderRegistry';
import {getEthersSigners} from '../../helpers/contracts-helpers';
import {AaveProtocolTestHelpersFactory} from '../../types';
chai.use(bignumberChai());
chai.use(almostEqual());

View File

@ -7,7 +7,7 @@ import {
getAToken,
getStableDebtToken,
getVariableDebtToken,
} from '../../../helpers/contracts-helpers';
} from '../../../helpers/contracts-getters';
import {tEthereumAddress} from '../../../helpers/types';
import BigNumber from 'bignumber.js';
import {getDb, BRE} from '../../../helpers/misc-utils';
@ -27,7 +27,7 @@ export const getReserveData = async (
const stableDebtToken = await getStableDebtToken(tokenAddresses.stableDebtTokenAddress);
const variableDebtToken = await getVariableDebtToken(tokenAddresses.variableDebtTokenAddress);
const [principalStableDebt] = await stableDebtToken.getSupplyData();
const {0: principalStableDebt} = await stableDebtToken.getSupplyData();
const totalStableDebtLastUpdated = await stableDebtToken.getTotalSupplyLastUpdated();
const scaledVariableDebt = await variableDebtToken.scaledTotalSupply();

View File

@ -1,10 +1,11 @@
import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors, RateMode} from '../helpers/types';
import {APPROVAL_AMOUNT_LENDING_POOL, oneEther} from '../helpers/constants';
import {convertToCurrencyDecimals, getMockFlashLoanReceiver} from '../helpers/contracts-helpers';
import {convertToCurrencyDecimals} from '../helpers/contracts-helpers';
import {parseEther, parseUnits} from 'ethers/lib/utils';
import {BigNumber} from 'bignumber.js';
import {MockFlashLoanReceiver} from '../types/MockFlashLoanReceiver';
import {getMockFlashLoanReceiver} from '../helpers/contracts-getters';
const {expect} = require('chai');

View File

@ -1,16 +1,12 @@
import {expect} from 'chai';
import {makeSuite, TestEnv} from './helpers/make-suite';
import {ProtocolErrors, eContractid} from '../helpers/types';
import {
deployGenericAToken,
getAToken,
deployContract,
getContract,
} from '../helpers/contracts-helpers';
import {deployContract, getContract} from '../helpers/contracts-helpers';
import {MockAToken} from '../types/MockAToken';
import {MockStableDebtToken} from '../types/MockStableDebtToken';
import {MockVariableDebtToken} from '../types/MockVariableDebtToken';
import {ZERO_ADDRESS} from '../helpers/constants';
import {getAToken} from '../helpers/contracts-getters';
makeSuite('Upgradeability', (testEnv: TestEnv) => {
const {CALLER_NOT_AAVE_ADMIN} = ProtocolErrors;