Updated helpers

This commit is contained in:
Zer0dot 2021-02-05 21:51:12 -05:00
parent 338e58951a
commit 2601dbb2df
3 changed files with 89 additions and 130 deletions

View File

@ -18,7 +18,6 @@ import { Artifact as BuidlerArtifact } from '@nomiclabs/buidler/types';
import { verifyContract } from './etherscan-verification'; import { verifyContract } from './etherscan-verification';
import { getIErc20Detailed } from './contracts-getters'; import { getIErc20Detailed } from './contracts-getters';
import { usingTenderly } from './tenderly-utils'; import { usingTenderly } from './tenderly-utils';
import { addGas, totalGas } from './gas-tracker';
export type MockTokenMap = { [symbol: string]: MintableERC20 }; export type MockTokenMap = { [symbol: string]: MintableERC20 };
@ -90,9 +89,6 @@ export const withSaveAndVerify = async <ContractType extends Contract>(
args: (string | string[])[], args: (string | string[])[],
verify?: boolean verify?: boolean
): Promise<ContractType> => { ): Promise<ContractType> => {
addGas(instance.deployTransaction.gasLimit);
console.log("Current totalGas value:", totalGas);
console.log("Logged gas limit:", instance.deployTransaction.gasLimit);
await waitForTx(instance.deployTransaction); await waitForTx(instance.deployTransaction);
await registerContractInJsonDb(id, instance); await registerContractInJsonDb(id, instance);
if (usingTenderly()) { if (usingTenderly()) {
@ -167,8 +163,8 @@ export const getParamPerPool = <T>({ proto, uniswap }: iParamsPerPool<T>, pool:
switch (pool) { switch (pool) {
case AavePools.proto: case AavePools.proto:
return proto; return proto;
case AavePools.uniswap: case AavePools.uniswap:
return uniswap; return uniswap;
default: default:
return proto; return proto;
} }

View File

@ -26,8 +26,6 @@ import {
} from './contracts-deployments'; } from './contracts-deployments';
import { ZERO_ADDRESS } from './constants'; import { ZERO_ADDRESS } from './constants';
import { isZeroAddress } from 'ethereumjs-util'; import { isZeroAddress } from 'ethereumjs-util';
import { addGas } from './gas-tracker';
import { getTreasuryAddress } from './configuration';
export const chooseATokenDeployment = (id: eContractid) => { export const chooseATokenDeployment = (id: eContractid) => {
switch (id) { switch (id) {
@ -56,7 +54,6 @@ export const initReservesByHelper = async (
const poolAddress = await addressProvider.getLendingPool(); const poolAddress = await addressProvider.getLendingPool();
// Set aTokenAndRatesDeployer as temporal admin // Set aTokenAndRatesDeployer as temporal admin
addGas(await addressProvider.estimateGas.setPoolAdmin(atokenAndRatesDeployer.address));
await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address)); await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address));
// CHUNK CONFIGURATION // CHUNK CONFIGURATION
@ -79,7 +76,6 @@ export const initReservesByHelper = async (
let reserveInitDecimals: string[] = []; let reserveInitDecimals: string[] = [];
let reserveSymbols: string[] = []; let reserveSymbols: string[] = [];
// TEST START
let initInputParams: { let initInputParams: {
aTokenImpl: string, aTokenImpl: string,
stableDebtTokenImpl: string, stableDebtTokenImpl: string,
@ -97,7 +93,6 @@ export const initReservesByHelper = async (
stableDebtTokenName: string, stableDebtTokenName: string,
stableDebtTokenSymbol: string, stableDebtTokenSymbol: string,
}[] = []; }[] = [];
// TEST END
console.log( console.log(
`- Token deployments in ${reservesChunks.length * 2} txs instead of ${ `- Token deployments in ${reservesChunks.length * 2} txs instead of ${
@ -118,7 +113,7 @@ export const initReservesByHelper = async (
BigNumberish BigNumberish
][] = []; ][] = [];
const reservesDecimals: string[] = []; const reservesDecimals: string[] = [];
// TEST START
const inputParams: { const inputParams: {
asset: string, asset: string,
rates: [ rates: [
@ -130,7 +125,7 @@ export const initReservesByHelper = async (
BigNumberish BigNumberish
] ]
}[] = []; }[] = [];
// TEST END
for (let [assetSymbol, { reserveDecimals }] of reservesChunk) { for (let [assetSymbol, { reserveDecimals }] of reservesChunk) {
const assetAddressIndex = Object.keys(tokenAddresses).findIndex( const assetAddressIndex = Object.keys(tokenAddresses).findIndex(
(value) => value === assetSymbol (value) => value === assetSymbol
@ -166,7 +161,6 @@ export const initReservesByHelper = async (
]); ]);
reservesDecimals.push(reserveDecimals); reservesDecimals.push(reserveDecimals);
// TEST START
inputParams.push({ inputParams.push({
asset: tokenAddress, asset: tokenAddress,
rates: [ rates: [
@ -178,10 +172,8 @@ export const initReservesByHelper = async (
stableRateSlope2 stableRateSlope2
] ]
}); });
// TEST END
} }
// tx1 and tx2 gas is accounted for later.
// Deploy stable and variable deployers and save implementations // Deploy stable and variable deployers and save implementations
const tx1 = await waitForTx( const tx1 = await waitForTx(
await stableAndVariableDeployer.initDeployment(tokens, symbols) await stableAndVariableDeployer.initDeployment(tokens, symbols)
@ -219,29 +211,6 @@ export const initReservesByHelper = async (
reserveSymbols = [...reserveSymbols, ...symbols]; reserveSymbols = [...reserveSymbols, ...symbols];
} }
// TEST START
for (let i = 0; i < deployedATokens.length; i ++) {
initInputParams.push({
aTokenImpl: deployedATokens[i],
stableDebtTokenImpl: deployedStableTokens[i],
variableDebtTokenImpl: deployedVariableTokens[i],
underlyingAssetDecimals: reserveInitDecimals[i],
interestRateStrategyAddress: deployedRates[i],
underlyingAsset: reserveTokens[i],
treasury: treasuryAddress,
incentivesController: ZERO_ADDRESS,
underlyingAssetName: reserveSymbols[i],
aTokenName: `Aave interest bearing ${reserveSymbols[i]}`,
aTokenSymbol: `a${reserveSymbols[i]}`,
variableDebtTokenName: `Aave variable debt bearing ${reserveSymbols[i]}`,
variableDebtTokenSymbol: `variableDebt${reserveSymbols[i]}`,
stableDebtTokenName: `Aave stable debt bearing ${reserveSymbols[i]}`,
stableDebtTokenSymbol: `stableDebt${reserveSymbols[i]}`
});
}
// TEST END
// Deploy delegated aware reserves tokens // Deploy delegated aware reserves tokens
const delegatedAwareReserves = Object.entries(reservesParams).filter( const delegatedAwareReserves = Object.entries(reservesParams).filter(
([_, { aTokenImpl }]) => aTokenImpl === eContractid.DelegationAwareAToken ([_, { aTokenImpl }]) => aTokenImpl === eContractid.DelegationAwareAToken
@ -311,42 +280,46 @@ export const initReservesByHelper = async (
reserveSymbols.push(symbol); reserveSymbols.push(symbol);
} }
// Deploy init reserves per chunks for (let i = 0; i < deployedATokens.length; i ++) {
const chunkedStableTokens = chunk(deployedStableTokens, initChunks); initInputParams.push({
const chunkedVariableTokens = chunk(deployedVariableTokens, initChunks); aTokenImpl: deployedATokens[i],
const chunkedAtokens = chunk(deployedATokens, initChunks); stableDebtTokenImpl: deployedStableTokens[i],
const chunkedRates = chunk(deployedRates, initChunks); variableDebtTokenImpl: deployedVariableTokens[i],
const chunkedDecimals = chunk(reserveInitDecimals, initChunks); underlyingAssetDecimals: reserveInitDecimals[i],
const chunkedSymbols = chunk(reserveSymbols, initChunks); interestRateStrategyAddress: deployedRates[i],
underlyingAsset: reserveTokens[i],
treasury: treasuryAddress,
incentivesController: ZERO_ADDRESS,
underlyingAssetName: reserveSymbols[i],
aTokenName: `Aave interest bearing ${reserveSymbols[i]}`,
aTokenSymbol: `a${reserveSymbols[i]}`,
variableDebtTokenName: `Aave variable debt bearing ${reserveSymbols[i]}`,
variableDebtTokenSymbol: `variableDebt${reserveSymbols[i]}`,
stableDebtTokenName: `Aave stable debt bearing ${reserveSymbols[i]}`,
stableDebtTokenSymbol: `stableDebt${reserveSymbols[i]}`
});
}
// Deploy init reserves per chunks
const chunkedSymbols = chunk(reserveSymbols, initChunks);
const chunkedInitInputParams = chunk(initInputParams, initChunks);
// TEST START
const configurator = await getLendingPoolConfiguratorProxy(); const configurator = await getLendingPoolConfiguratorProxy();
await waitForTx(await addressProvider.setPoolAdmin(admin)); await waitForTx(await addressProvider.setPoolAdmin(admin));
const chunkedInitInputParams = chunk(initInputParams, initChunks); console.log(`- Reserves initialization in ${chunkedInitInputParams.length} txs`);
// TEST END for (let chunkIndex = 0; chunkIndex < chunkedInitInputParams.length; chunkIndex++) {
console.log(`- Reserves initialization in ${chunkedStableTokens.length} txs`);
for (let chunkIndex = 0; chunkIndex < chunkedDecimals.length; chunkIndex++) {
const tx3 = await waitForTx( const tx3 = await waitForTx(
// await atokenAndRatesDeployer.initReserve(
// chunkedStableTokens[chunkIndex],
// chunkedVariableTokens[chunkIndex],
// chunkedAtokens[chunkIndex],
// chunkedRates[chunkIndex],
// chunkedDecimals[chunkIndex]
// )
await configurator.batchInitReserve(chunkedInitInputParams[chunkIndex]) await configurator.batchInitReserve(chunkedInitInputParams[chunkIndex])
); );
console.log(` - Reserve ready for: ${chunkedSymbols[chunkIndex].join(', ')}`); console.log(` - Reserve ready for: ${chunkedSymbols[chunkIndex].join(', ')}`);
console.log(' * gasUsed', tx3.gasUsed.toString()); console.log(' * gasUsed', tx3.gasUsed.toString());
gasUsage = gasUsage.add(tx3.gasUsed); gasUsage = gasUsage.add(tx3.gasUsed);
} }
addGas(gasUsage);
// Set deployer back as admin // Set deployer back as admin
addGas(await addressProvider.estimateGas.setPoolAdmin(admin));
await waitForTx(await addressProvider.setPoolAdmin(admin)); await waitForTx(await addressProvider.setPoolAdmin(admin));
return gasUsage; return gasUsage;
}; };
@ -393,7 +366,7 @@ export const configureReservesByHelper = async (
const liquidationBonuses: string[] = []; const liquidationBonuses: string[] = [];
const reserveFactors: string[] = []; const reserveFactors: string[] = [];
const stableRatesEnabled: boolean[] = []; const stableRatesEnabled: boolean[] = [];
// TEST START
const inputParams : { const inputParams : {
asset: string; asset: string;
baseLTV: BigNumberish; baseLTV: BigNumberish;
@ -402,7 +375,6 @@ export const configureReservesByHelper = async (
reserveFactor: BigNumberish; reserveFactor: BigNumberish;
stableBorrowingEnabled: boolean; stableBorrowingEnabled: boolean;
}[] = []; }[] = [];
// TEST END
for (const [ for (const [
assetSymbol, assetSymbol,
@ -432,7 +404,6 @@ export const configureReservesByHelper = async (
} }
// Push data // Push data
// TEST START
inputParams.push({ inputParams.push({
asset: tokenAddress, asset: tokenAddress,
baseLTV: baseLTVAsCollateral, baseLTV: baseLTVAsCollateral,
@ -441,7 +412,6 @@ export const configureReservesByHelper = async (
reserveFactor: reserveFactor, reserveFactor: reserveFactor,
stableBorrowingEnabled: stableBorrowRateEnabled stableBorrowingEnabled: stableBorrowRateEnabled
}); });
// TEST END
tokens.push(tokenAddress); tokens.push(tokenAddress);
symbols.push(assetSymbol); symbols.push(assetSymbol);
@ -453,42 +423,15 @@ export const configureReservesByHelper = async (
} }
if (tokens.length) { if (tokens.length) {
// Set aTokenAndRatesDeployer as temporal admin // Set aTokenAndRatesDeployer as temporal admin
addGas(await addressProvider.estimateGas.setPoolAdmin(atokenAndRatesDeployer.address));
await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address)); await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address));
// Deploy init per chunks // Deploy init per chunks
const enableChunks = 20; const enableChunks = 20;
const chunkedTokens = chunk(tokens, enableChunks);
const chunkedSymbols = chunk(symbols, enableChunks); const chunkedSymbols = chunk(symbols, enableChunks);
const chunkedBase = chunk(baseLTVA, enableChunks);
const chunkedliquidationThresholds = chunk(liquidationThresholds, enableChunks);
const chunkedliquidationBonuses = chunk(liquidationBonuses, enableChunks);
const chunkedReserveFactors = chunk(reserveFactors, enableChunks);
const chunkedStableRatesEnabled = chunk(stableRatesEnabled, enableChunks);
// TEST START
const chunkedInputParams = chunk(inputParams, enableChunks); const chunkedInputParams = chunk(inputParams, enableChunks);
// TEST END
console.log(`- Configure reserves in ${chunkedTokens.length} txs`);
for (let chunkIndex = 0; chunkIndex < chunkedTokens.length; chunkIndex++) {
// addGas(await atokenAndRatesDeployer.estimateGas.configureReserves(
// chunkedTokens[chunkIndex],
// chunkedBase[chunkIndex],
// chunkedliquidationThresholds[chunkIndex],
// chunkedliquidationBonuses[chunkIndex],
// chunkedReserveFactors[chunkIndex],
// chunkedStableRatesEnabled[chunkIndex],
// { gasLimit: 12000000 }
// ));
addGas(await atokenAndRatesDeployer.estimateGas.configureReserves(
chunkedInputParams[chunkIndex],
{ gasLimit: 12000000 }
));
console.log(`- Configure reserves in ${chunkedInputParams.length} txs`);
for (let chunkIndex = 0; chunkIndex < chunkedInputParams.length; chunkIndex++) {
await waitForTx( await waitForTx(
await atokenAndRatesDeployer.configureReserves( await atokenAndRatesDeployer.configureReserves(
chunkedInputParams[chunkIndex], chunkedInputParams[chunkIndex],
@ -498,7 +441,6 @@ export const configureReservesByHelper = async (
console.log(` - Init for: ${chunkedSymbols[chunkIndex].join(', ')}`); console.log(` - Init for: ${chunkedSymbols[chunkIndex].join(', ')}`);
} }
// Set deployer back as admin // Set deployer back as admin
addGas(await addressProvider.estimateGas.setPoolAdmin(admin));
await waitForTx(await addressProvider.setPoolAdmin(admin)); await waitForTx(await addressProvider.setPoolAdmin(admin));
} }
}; };
@ -544,8 +486,28 @@ export const initTokenReservesByHelper = async (
let deployedVariableTokens: string[] = []; let deployedVariableTokens: string[] = [];
let deployedATokens: string[] = []; let deployedATokens: string[] = [];
let deployedRates: string[] = []; let deployedRates: string[] = [];
let reserveTokens: string[] = [];
let reserveInitDecimals: string[] = []; let reserveInitDecimals: string[] = [];
let reserveSymbols: string[] = []; let reserveSymbols: string[] = [];
let initInputParams: {
aTokenImpl: string,
stableDebtTokenImpl: string,
variableDebtTokenImpl: string,
underlyingAssetDecimals: BigNumberish,
interestRateStrategyAddress: string,
underlyingAsset: string,
treasury: string,
incentivesController: string,
underlyingAssetName: string,
aTokenName: string,
aTokenSymbol: string,
variableDebtTokenName: string,
variableDebtTokenSymbol: string,
stableDebtTokenName: string,
stableDebtTokenSymbol: string,
}[] = [];
const network = const network =
process.env.MAINNET_FORK === 'true' process.env.MAINNET_FORK === 'true'
? eEthereumNetwork.main ? eEthereumNetwork.main
@ -650,34 +612,47 @@ export const initTokenReservesByHelper = async (
deployedStableTokens.push(stableTokenImpl); deployedStableTokens.push(stableTokenImpl);
deployedVariableTokens.push(variableTokenImpl); deployedVariableTokens.push(variableTokenImpl);
deployedATokens.push(aTokenImplementation); deployedATokens.push(aTokenImplementation);
reserveTokens.push();
deployedRates.push(strategyImpl); deployedRates.push(strategyImpl);
reserveInitDecimals.push(decimals.toString()); reserveInitDecimals.push(decimals.toString());
reserveSymbols.push(symbol); reserveSymbols.push(symbol);
} }
// Deploy init reserves per chunks for (let i = 0; i < deployedATokens.length; i ++) {
const chunkedStableTokens = chunk(deployedStableTokens, initChunks); initInputParams.push({
const chunkedVariableTokens = chunk(deployedVariableTokens, initChunks); aTokenImpl: deployedATokens[i],
const chunkedAtokens = chunk(deployedATokens, initChunks); stableDebtTokenImpl: deployedStableTokens[i],
const chunkedRates = chunk(deployedRates, initChunks); variableDebtTokenImpl: deployedVariableTokens[i],
const chunkedDecimals = chunk(reserveInitDecimals, initChunks); underlyingAssetDecimals: reserveInitDecimals[i],
const chunkedSymbols = chunk(reserveSymbols, initChunks); interestRateStrategyAddress: deployedRates[i],
underlyingAsset: tokenAddresses[reserveSymbols[i]],
treasury: treasuryAddress,
incentivesController: ZERO_ADDRESS,
underlyingAssetName: reserveSymbols[i],
aTokenName: `Aave interest bearing ${reserveSymbols[i]}`,
aTokenSymbol: `a${reserveSymbols[i]}`,
variableDebtTokenName: `Aave variable debt bearing ${reserveSymbols[i]}`,
variableDebtTokenSymbol: `variableDebt${reserveSymbols[i]}`,
stableDebtTokenName: `Aave stable debt bearing ${reserveSymbols[i]}`,
stableDebtTokenSymbol: `stableDebt${reserveSymbols[i]}`
});
}
console.log(`- Reserves initialization in ${chunkedStableTokens.length} txs`); // Deploy init reserves per chunks
for (let chunkIndex = 0; chunkIndex < chunkedDecimals.length; chunkIndex++) { const chunkedSymbols = chunk(reserveSymbols, initChunks);
const chunkedInitInputParams = chunk(initInputParams, initChunks);
const configurator = await getLendingPoolConfiguratorProxy();
await waitForTx(await addressProvider.setPoolAdmin(admin));
console.log(`- Reserves initialization in ${chunkedInitInputParams.length} txs`);
for (let chunkIndex = 0; chunkIndex < chunkedInitInputParams.length; chunkIndex++) {
const tx3 = await waitForTx( const tx3 = await waitForTx(
await atokenAndRatesDeployer.initReserve( await configurator.batchInitReserve(chunkedInitInputParams[chunkIndex])
chunkedStableTokens[chunkIndex],
chunkedVariableTokens[chunkIndex],
chunkedAtokens[chunkIndex],
chunkedRates[chunkIndex],
chunkedDecimals[chunkIndex]
)
); );
console.log(` - Reserve ready for: ${chunkedSymbols[chunkIndex].join(', ')}`); console.log(` - Reserve ready for: ${chunkedSymbols[chunkIndex].join(', ')}`);
console.log(' * gasUsed', tx3.gasUsed.toString()); console.log(' * gasUsed', tx3.gasUsed.toString());
gasUsage = gasUsage.add(tx3.gasUsed);
} }
// Set deployer back as admin // Set deployer back as admin

View File

@ -7,13 +7,12 @@ import {
SymbolMap, SymbolMap,
} 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-deployments'; import { deployMockAggregator } from './contracts-deployments';
import {chunk, waitForTx} from './misc-utils'; import { chunk, waitForTx } from './misc-utils';
import {getStableAndVariableTokensHelper} from './contracts-getters'; import { getStableAndVariableTokensHelper } from './contracts-getters';
import { addGas } from './gas-tracker';
export const setInitialMarketRatesInRatesOracleByHelper = async ( export const setInitialMarketRatesInRatesOracleByHelper = async (
marketRates: iMultiPoolsAssets<IMarketRates>, marketRates: iMultiPoolsAssets<IMarketRates>,
@ -46,20 +45,12 @@ export const setInitialMarketRatesInRatesOracleByHelper = async (
const chunkedSymbols = chunk(symbols, ratesChunks); const chunkedSymbols = chunk(symbols, ratesChunks);
// Set helper as owner // Set helper as owner
addGas(await lendingRateOracleInstance.estimateGas.transferOwnership(stableAndVariableTokenHelper.address));
await waitForTx( await waitForTx(
await lendingRateOracleInstance.transferOwnership(stableAndVariableTokenHelper.address) await lendingRateOracleInstance.transferOwnership(stableAndVariableTokenHelper.address)
); );
console.log(`- Oracle borrow initalization in ${chunkedTokens.length} txs`); console.log(`- Oracle borrow initalization in ${chunkedTokens.length} txs`);
for (let chunkIndex = 0; chunkIndex < chunkedTokens.length; chunkIndex++) { for (let chunkIndex = 0; chunkIndex < chunkedTokens.length; chunkIndex++) {
addGas(await stableAndVariableTokenHelper.estimateGas.setOracleBorrowRates(
chunkedTokens[chunkIndex],
chunkedRates[chunkIndex],
lendingRateOracleInstance.address
));
const tx3 = await waitForTx( const tx3 = await waitForTx(
await stableAndVariableTokenHelper.setOracleBorrowRates( await stableAndVariableTokenHelper.setOracleBorrowRates(
chunkedTokens[chunkIndex], chunkedTokens[chunkIndex],
@ -70,7 +61,6 @@ export const setInitialMarketRatesInRatesOracleByHelper = async (
console.log(` - Setted Oracle Borrow Rates for: ${chunkedSymbols[chunkIndex].join(', ')}`); console.log(` - Setted Oracle Borrow Rates for: ${chunkedSymbols[chunkIndex].join(', ')}`);
} }
// Set back ownership // Set back ownership
addGas(await stableAndVariableTokenHelper.estimateGas.setOracleOwnership(lendingRateOracleInstance.address, admin));
await waitForTx( await waitForTx(
await stableAndVariableTokenHelper.setOracleOwnership(lendingRateOracleInstance.address, admin) await stableAndVariableTokenHelper.setOracleOwnership(lendingRateOracleInstance.address, admin)
); );
@ -88,7 +78,6 @@ export const setInitialAssetPricesInOracle = async (
const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[ const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[
assetAddressIndex assetAddressIndex
]; ];
addGas(await priceOracleInstance.estimateGas.setAssetPrice(assetAddress, price));
await waitForTx(await priceOracleInstance.setAssetPrice(assetAddress, price)); await waitForTx(await priceOracleInstance.setAssetPrice(assetAddress, price));
} }
}; };
@ -105,7 +94,6 @@ export const setAssetPricesInOracle = async (
const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[ const [, assetAddress] = (Object.entries(assetsAddresses) as [string, string][])[
assetAddressIndex assetAddressIndex
]; ];
addGas(await priceOracleInstance.estimateGas.setAssetPrice(assetAddress, price));
await waitForTx(await priceOracleInstance.setAssetPrice(assetAddress, price)); await waitForTx(await priceOracleInstance.setAssetPrice(assetAddress, price));
} }
}; };