Skip to content

Commit b4ed523

Browse files
authored
Merge pull request #68 from aave/polygon-verifier
Polygon integration
2 parents e45dff5 + 3870182 commit b4ed523

33 files changed

+588
-557
lines changed

contracts/deployments/ATokensAndRatesHelper.sol

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ contract ATokensAndRatesHelper is Ownable {
3232
uint256 liquidationBonus;
3333
uint256 reserveFactor;
3434
bool stableBorrowingEnabled;
35+
bool borrowingEnabled;
3536
}
3637

3738
constructor(
@@ -73,10 +74,12 @@ contract ATokensAndRatesHelper is Ownable {
7374
inputParams[i].liquidationBonus
7475
);
7576

76-
configurator.enableBorrowingOnReserve(
77-
inputParams[i].asset,
78-
inputParams[i].stableBorrowingEnabled
79-
);
77+
if (inputParams[i].borrowingEnabled) {
78+
configurator.enableBorrowingOnReserve(
79+
inputParams[i].asset,
80+
inputParams[i].stableBorrowingEnabled
81+
);
82+
}
8083
configurator.setReserveFactor(inputParams[i].asset, inputParams[i].reserveFactor);
8184
}
8285
}

helper-hardhat-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ export const NETWORKS_DEFAULT_GAS: iParamsPerNetwork<number> = {
4242
[eEthereumNetwork.buidlerevm]: 65 * GWEI,
4343
[eEthereumNetwork.tenderlyMain]: 0.01 * GWEI,
4444
[ePolygonNetwork.mumbai]: 1 * GWEI,
45-
[ePolygonNetwork.matic]: 2 * GWEI,
45+
[ePolygonNetwork.matic]: 1 * GWEI,
4646
[eXDaiNetwork.xdai]: 1 * GWEI,
4747
};

helpers/configuration.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const loadPoolConfig = (configName: ConfigNames): PoolConfiguration => {
3030
case ConfigNames.Matic:
3131
return MaticConfig;
3232
case ConfigNames.Amm:
33-
return AmmConfig;
33+
return AmmConfig;
3434
case ConfigNames.Commons:
3535
return CommonsConfig;
3636
default:
@@ -113,6 +113,19 @@ export const getWethAddress = async (config: ICommonConfiguration) => {
113113
return weth.address;
114114
};
115115

116+
export const getWrappedNativeTokenAddress = async (config: ICommonConfiguration) => {
117+
const currentNetwork = process.env.MAINNET_FORK === 'true' ? 'main' : DRE.network.name;
118+
const wethAddress = getParamPerNetwork(config.WrappedNativeToken, <eNetwork>currentNetwork);
119+
if (wethAddress) {
120+
return wethAddress;
121+
}
122+
if (currentNetwork.includes('main')) {
123+
throw new Error('WETH not set at mainnet configuration.');
124+
}
125+
const weth = await deployWETHMocked();
126+
return weth.address;
127+
};
128+
116129
export const getLendingRateOracles = (poolConfig: ICommonConfiguration) => {
117130
const {
118131
ProtocolGlobalParams: { UsdAddress },

helpers/contracts-deployments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ import {
5656
linkBytecode,
5757
insertContractAddressInDb,
5858
deployContract,
59+
verifyContract,
5960
} from './contracts-helpers';
6061
import { StableAndVariableTokensHelperFactory } from '../types/StableAndVariableTokensHelperFactory';
6162
import { MintableDelegationERC20 } from '../types/MintableDelegationERC20';
6263
import { readArtifact as buidlerReadArtifact } from '@nomiclabs/buidler/plugins';
6364
import { HardhatRuntimeEnvironment } from 'hardhat/types';
6465
import { LendingPoolLibraryAddresses } from '../types/LendingPoolFactory';
6566
import { UiPoolDataProvider } from '../types';
66-
import { verifyContract } from './etherscan-verification';
6767

6868
export const deployUiPoolDataProvider = async (
6969
[incentivesController, aaveOracle]: [tEthereumAddress, tEthereumAddress],
@@ -73,7 +73,7 @@ export const deployUiPoolDataProvider = async (
7373
const args: string[] = [incentivesController, aaveOracle];
7474
const instance = await deployContract<UiPoolDataProvider>(id, args);
7575
if (verify) {
76-
await verifyContract(instance.address, args);
76+
await verifyContract(id, instance, args);
7777
}
7878
return instance;
7979
};

helpers/contracts-getters.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ import {
3333
} from '../types';
3434
import { IERC20DetailedFactory } from '../types/IERC20DetailedFactory';
3535
import { MockTokenMap } from './contracts-helpers';
36-
import { DRE, getDb } from './misc-utils';
36+
import { DRE, getDb, notFalsyOrZeroAddress } from './misc-utils';
3737
import { eContractid, PoolConfiguration, tEthereumAddress, TokenContractId } from './types';
3838

3939
export const getFirstSigner = async () => (await DRE.ethers.getSigners())[0];
4040

41-
export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress) =>
42-
await LendingPoolAddressesProviderFactory.connect(
41+
export const getLendingPoolAddressesProvider = async (address?: tEthereumAddress) => {
42+
return await LendingPoolAddressesProviderFactory.connect(
4343
address ||
4444
(await getDb().get(`${eContractid.LendingPoolAddressesProvider}.${DRE.network.name}`).value())
4545
.address,
4646
await getFirstSigner()
4747
);
48-
48+
};
4949
export const getLendingPoolConfiguratorProxy = async (address?: tEthereumAddress) => {
5050
return await LendingPoolConfiguratorFactory.connect(
5151
address ||
@@ -172,7 +172,7 @@ export const getPairsTokenAggregator = (
172172
},
173173
aggregatorsAddresses: { [tokenSymbol: string]: tEthereumAddress }
174174
): [string[], string[]] => {
175-
const { ETH, USD, WETH, ...assetsAddressesWithoutEth } = allAssetsAddresses;
175+
const { ETH, WETH, ...assetsAddressesWithoutEth } = allAssetsAddresses;
176176

177177
const pairs = Object.entries(assetsAddressesWithoutEth).map(([tokenSymbol, tokenAddress]) => {
178178
//if (true/*tokenSymbol !== 'WETH' && tokenSymbol !== 'ETH' && tokenSymbol !== 'LpWETH'*/) {
@@ -195,12 +195,13 @@ export const getPairsTokenAggregator = (
195195

196196
export const getLendingPoolAddressesProviderRegistry = async (address?: tEthereumAddress) =>
197197
await LendingPoolAddressesProviderRegistryFactory.connect(
198-
address ||
199-
(
200-
await getDb()
201-
.get(`${eContractid.LendingPoolAddressesProviderRegistry}.${DRE.network.name}`)
202-
.value()
203-
).address,
198+
notFalsyOrZeroAddress(address)
199+
? address
200+
: (
201+
await getDb()
202+
.get(`${eContractid.LendingPoolAddressesProviderRegistry}.${DRE.network.name}`)
203+
.value()
204+
).address,
204205
await getFirstSigner()
205206
);
206207

helpers/contracts-helpers.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import {
2222
import { MintableERC20 } from '../types/MintableERC20';
2323
import { Artifact } from 'hardhat/types';
2424
import { Artifact as BuidlerArtifact } from '@nomiclabs/buidler/types';
25-
import { verifyContract } from './etherscan-verification';
25+
import { verifyEtherscanContract } from './etherscan-verification';
2626
import { getIErc20Detailed } from './contracts-getters';
27-
import { usingTenderly } from './tenderly-utils';
27+
import { usingTenderly, verifyAtTenderly } from './tenderly-utils';
28+
import { usingPolygon, verifyAtPolygon } from './polygon-utils';
2829

2930
export type MockTokenMap = { [symbol: string]: MintableERC20 };
3031

@@ -98,18 +99,8 @@ export const withSaveAndVerify = async <ContractType extends Contract>(
9899
): Promise<ContractType> => {
99100
await waitForTx(instance.deployTransaction);
100101
await registerContractInJsonDb(id, instance);
101-
if (usingTenderly()) {
102-
console.log();
103-
console.log('Doing Tenderly contract verification of', id);
104-
await (DRE as any).tenderlyRPC.verify({
105-
name: id,
106-
address: instance.address,
107-
});
108-
console.log(`Verified ${id} at Tenderly!`);
109-
console.log();
110-
}
111102
if (verify) {
112-
await verifyContract(instance.address, args);
103+
await verifyContract(id, instance, args);
113104
}
114105
return instance;
115106
};
@@ -328,3 +319,19 @@ export const buildFlashLiquidationAdapterParams = (
328319
[collateralAsset, debtAsset, user, debtToCover, useEthPath]
329320
);
330321
};
322+
323+
export const verifyContract = async (
324+
id: string,
325+
instance: Contract,
326+
args: (string | string[])[]
327+
) => {
328+
if (usingPolygon()) {
329+
await verifyAtPolygon(id, instance, args);
330+
} else {
331+
if (usingTenderly()) {
332+
await verifyAtTenderly(id, instance);
333+
}
334+
await verifyEtherscanContract(instance.address, args);
335+
}
336+
return instance;
337+
};

helpers/etherscan-verification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function delay(ms: number) {
2020
return new Promise((resolve) => setTimeout(resolve, ms));
2121
}
2222

23-
export const verifyContract = async (
23+
export const verifyEtherscanContract = async (
2424
address: string,
2525
constructorArguments: (string | string[])[],
2626
libraries?: string

0 commit comments

Comments
 (0)