Added gas tracking

This commit is contained in:
Zer0dot 2021-01-11 21:15:47 -05:00
parent a4540633ea
commit 688b62fed2
11 changed files with 71 additions and 9 deletions

8
gas-tracker.ts Normal file
View File

@ -0,0 +1,8 @@
// Should be a ts file that has a global var var gas = 0;
import { BigNumber } from 'ethers';
export var totalGas:BigNumber = BigNumber.from(0);
export function addGas(amount: BigNumber) {
totalGas = totalGas.add(amount);
}

View File

@ -11,7 +11,6 @@ import {
PoolConfiguration,
eEthereumNetwork,
} from './types';
import { MintableERC20 } from '../types/MintableERC20';
import { MockContract } from 'ethereum-waffle';
import { getReservesConfigByPool } from './configuration';
@ -58,6 +57,7 @@ import { MintableDelegationERC20 } from '../types/MintableDelegationERC20';
import { readArtifact as buidlerReadArtifact } from '@nomiclabs/buidler/plugins';
import { HardhatRuntimeEnvironment } from 'hardhat/types';
import { LendingPoolLibraryAddresses } from '../types/LendingPoolFactory';
import { addGas } from '../gas-tracker';
const readArtifact = async (id: string) => {
if (DRE.network.name === eEthereumNetwork.buidlerevm) {
@ -71,7 +71,8 @@ export const deployLendingPoolAddressesProvider = async (marketId: string, verif
eContractid.LendingPoolAddressesProvider,
[marketId],
verify
);
)
export const deployLendingPoolAddressesProviderRegistry = async (verify?: boolean) =>
withSaveAndVerify(

View File

@ -16,7 +16,9 @@ import { MintableERC20 } from '../types/MintableERC20';
import { Artifact } from 'hardhat/types';
import { Artifact as BuidlerArtifact } from '@nomiclabs/buidler/types';
import { verifyContract } from './etherscan-verification';
import { getIErc20Detailed } from './contracts-getters';
import { getIErc20Detailed, getFirstSigner } from './contracts-getters';
import { addGas, totalGas } from '../gas-tracker';
export type MockTokenMap = { [symbol: string]: MintableERC20 };
@ -88,6 +90,13 @@ export const withSaveAndVerify = async <ContractType extends Contract>(
args: (string | string[])[],
verify?: boolean
): Promise<ContractType> => {
// const signer = await getFirstSigner();
// const factory = ethers.ContractFactory.fromSolidity(instance);
// const gasCost = await signer.estimateGas(await factory.getDeployTransaction());
// console.log("TEST:", gasCost.toString());
addGas(instance.deployTransaction.gasLimit);
console.log("Current totalGas value:", totalGas);
console.log("LOGGED GAS LIMIT:", instance.deployTransaction.gasLimit);
await waitForTx(instance.deployTransaction);
await registerContractInJsonDb(id, instance);
if (DRE.network.name.includes('tenderly')) {

View File

@ -25,6 +25,7 @@ import {
} from './contracts-deployments';
import { ZERO_ADDRESS } from './constants';
import { isZeroAddress } from 'ethereumjs-util';
import { addGas } from '../gas-tracker';
const chooseATokenDeployment = (id: eContractid) => {
switch (id) {
@ -53,6 +54,7 @@ export const initReservesByHelper = async (
const poolAddress = await addressProvider.getLendingPool();
// Set aTokenAndRatesDeployer as temporal admin
addGas(await addressProvider.estimateGas.setPoolAdmin(atokenAndRatesDeployer.address));
await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address));
// CHUNK CONFIGURATION
@ -130,6 +132,7 @@ export const initReservesByHelper = async (
reservesDecimals.push(reserveDecimals);
}
// tx1 and tx2 gas is accounted for later.
// Deploy stable and variable deployers and save implementations
const tx1 = await waitForTx(
await stableAndVariableDeployer.initDeployment(tokens, symbols, incentivesController)
@ -158,7 +161,7 @@ export const initReservesByHelper = async (
console.log(' * gasUsed: debtTokens batch', tx1.gasUsed.toString());
console.log(' * gasUsed: aTokens and Strategy batch', tx2.gasUsed.toString());
gasUsage = gasUsage.add(tx1.gasUsed).add(tx2.gasUsed);
addGas(gasUsage);
const stableTokens: string[] = tx1.events?.map((e) => e.args?.stableToken) || [];
const variableTokens: string[] = tx1.events?.map((e) => e.args?.variableToken) || [];
const aTokens: string[] = tx2.events?.map((e) => e.args?.aToken) || [];
@ -352,6 +355,7 @@ export const configureReservesByHelper = async (
}
if (tokens.length) {
// Set aTokenAndRatesDeployer as temporal admin
addGas(await addressProvider.estimateGas.setPoolAdmin(atokenAndRatesDeployer.address));
await waitForTx(await addressProvider.setPoolAdmin(atokenAndRatesDeployer.address));
// Deploy init per chunks
@ -366,6 +370,15 @@ export const configureReservesByHelper = async (
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 }
));
await waitForTx(
await atokenAndRatesDeployer.configureReserves(
chunkedTokens[chunkIndex],
@ -380,6 +393,7 @@ export const configureReservesByHelper = async (
console.log(` - Init for: ${chunkedSymbols[chunkIndex].join(', ')}`);
}
// Set deployer back as admin
addGas(await addressProvider.estimateGas.setPoolAdmin(admin));
await waitForTx(await addressProvider.setPoolAdmin(admin));
}
};

View File

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

View File

@ -126,7 +126,7 @@ export const CommonsConfig: ICommonConfiguration = {
[eEthereumNetwork.buidlerevm]: '',
[eEthereumNetwork.kovan]: '',//'0xdCde9Bb6a49e37fA433990832AB541AE2d4FEB4a',
[eEthereumNetwork.ropsten]: '0x05dcca805a6562c1bdd0423768754acb6993241b',
[eEthereumNetwork.main]: '0x8A32f49FFbA88aba6EFF96F45D8BD1D4b3f35c7D',
[eEthereumNetwork.main]: '', //'0x8A32f49FFbA88aba6EFF96F45D8BD1D4b3f35c7D',
[eEthereumNetwork.tenderlyMain]: '0x8A32f49FFbA88aba6EFF96F45D8BD1D4b3f35c7D',
},
TokenDistributor: {
@ -144,7 +144,7 @@ export const CommonsConfig: ICommonConfiguration = {
[eEthereumNetwork.buidlerevm]: '',
[EthereumNetwork.kovan]: '',//'0xB8bE51E6563BB312Cbb2aa26e352516c25c26ac1',
[EthereumNetwork.ropsten]: ZERO_ADDRESS,
[EthereumNetwork.main]: '0xA50ba011c48153De246E5192C8f9258A2ba79Ca9',
[EthereumNetwork.main]: '', //'0xA50ba011c48153De246E5192C8f9258A2ba79Ca9',
[EthereumNetwork.tenderlyMain]: '0xA50ba011c48153De246E5192C8f9258A2ba79Ca9',
},
FallbackOracle: {

View File

@ -18,8 +18,10 @@ import {
} from '../../helpers/contracts-getters';
import { formatEther, isAddress, parseEther } from 'ethers/lib/utils';
import { isZeroAddress } from 'ethereumjs-util';
import { Signer } from 'ethers';
import { Signer, BigNumber } from 'ethers';
import { parse } from 'path';
import { addGas } from '../../gas-tracker';
//import BigNumber from 'bignumber.js';
task(
'full:deploy-address-provider',
@ -92,6 +94,10 @@ task(
// );
// 4. Set pool admins
addGas(await addressesProvider.estimateGas.setPoolAdmin(await getGenesisPoolAdmin(poolConfig)));
addGas(await addressesProvider.estimateGas.setEmergencyAdmin(await getEmergencyAdmin(poolConfig)));
await waitForTx(await addressesProvider.setPoolAdmin(await getGenesisPoolAdmin(poolConfig)));
await waitForTx(await addressesProvider.setEmergencyAdmin(await getEmergencyAdmin(poolConfig)));

View File

@ -17,6 +17,7 @@ import {
getLendingRateOracle,
getPairsTokenAggregator,
} from '../../helpers/contracts-getters';
import { addGas } from '../../gas-tracker';
task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
@ -66,8 +67,10 @@ task('full:deploy-oracles', 'Deploy oracles for dev enviroment')
admin
);
}
console.log("ORACLES: %s and %s", aaveOracle.address, lendingRateOracle.address);
// Register the proxy price provider on the addressesProvider
addGas(await addressesProvider.estimateGas.setPriceOracle(aaveOracle.address));
addGas(await addressesProvider.estimateGas.setLendingRateOracle(lendingRateOracle.address));
await waitForTx(await addressesProvider.setPriceOracle(aaveOracle.address));
await waitForTx(await addressesProvider.setLendingRateOracle(lendingRateOracle.address));
} catch (error) {

View File

@ -19,6 +19,7 @@ import {
getLendingPoolAddressesProvider,
} from '../../helpers/contracts-getters';
import { ZERO_ADDRESS } from '../../helpers/constants';
import { addGas } from '../../gas-tracker';
task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
.addFlag('verify', 'Verify contracts at Etherscan')
@ -47,6 +48,8 @@ task('full:initialize-lending-pool', 'Initialize lending pool configuration.')
await configureReservesByHelper(ReservesConfig, reserveAssets, testHelpers, admin);
const collateralManager = await deployLendingPoolCollateralManager(verify);
addGas(await addressesProvider.estimateGas.setLendingPoolCollateralManager(collateralManager.address));
await waitForTx(
await addressesProvider.setLendingPoolCollateralManager(collateralManager.address)
);

View File

@ -4,6 +4,7 @@ import {checkVerification} from '../../helpers/etherscan-verification';
import {ConfigNames} from '../../helpers/configuration';
import {EthereumNetworkNames} from '../../helpers/types';
import {printContracts} from '../../helpers/misc-utils';
import {totalGas} from '../../gas-tracker';
task('aave:mainnet', 'Deploy development enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
@ -56,4 +57,5 @@ task('aave:mainnet', 'Deploy development enviroment')
}
console.log('\nFinished migrations');
printContracts();
console.log("Total gas used:", totalGas);
});

View File

@ -4,6 +4,7 @@ import {checkVerification} from '../../helpers/etherscan-verification';
import {ConfigNames} from '../../helpers/configuration';
import {EthereumNetworkNames} from '../../helpers/types';
import {printContracts} from '../../helpers/misc-utils';
import {totalGas} from '../../gas-tracker';
task('uniswap:mainnet', 'Deploy development enviroment')
.addFlag('verify', 'Verify contracts at Etherscan')
@ -23,12 +24,14 @@ task('uniswap:mainnet', 'Deploy development enviroment')
const provider = new DRE.ethers.providers.Web3Provider(DRE.tenderlyRPC as any);
DRE.ethers.provider = provider;
}
// addGas(1);
// console.log(totalGas);
console.log('Migration started\n');
console.log('1. Deploy address provider');
await DRE.run('full:deploy-address-provider', {pool: POOL_NAME});
console.log('2. Deploy lending pool');
await DRE.run('full:deploy-lending-pool');
@ -56,4 +59,5 @@ task('uniswap:mainnet', 'Deploy development enviroment')
}
console.log('\nFinished migrations');
printContracts();
console.log("Total gas used:", totalGas);
});