Skip to content

Commit

Permalink
feat: Added simulation of Defender relayer via hardhat impersonation.…
Browse files Browse the repository at this point in the history
… Added expected script to submit Incentives proposal
  • Loading branch information
kartojal committed Apr 22, 2021
1 parent a0a5fac commit adce219
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 161 deletions.
5 changes: 3 additions & 2 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const getCommonNetworkConfig = (networkName: eNetwork, networkId: number) => ({

const mainnetFork = MAINNET_FORK
? {
blockNumber: 12276538,
blockNumber: 12290275,
url: NETWORKS_RPC_URL['main'],
}
: undefined;
Expand Down Expand Up @@ -120,7 +120,8 @@ const buidlerConfig: HardhatUserConfig = {
hardfork: 'istanbul',
blockGasLimit: DEFAULT_BLOCK_GAS_LIMIT,
gas: DEFAULT_BLOCK_GAS_LIMIT,
gasPrice: 8000000000,
gasPrice:
NETWORKS_DEFAULT_GAS[MAINNET_FORK ? eEthereumNetwork.main : eEthereumNetwork.hardhat],
chainId: BUIDLEREVM_CHAINID,
throwOnTransactionFailures: true,
throwOnCallFailures: true,
Expand Down
2 changes: 1 addition & 1 deletion helper-hardhat-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const NETWORKS_RPC_URL: iParamsPerNetwork<string> = {
export const NETWORKS_DEFAULT_GAS: iParamsPerNetwork<number> = {
[eEthereumNetwork.kovan]: 1 * GWEI,
[eEthereumNetwork.ropsten]: 1 * GWEI,
[eEthereumNetwork.main]: 100 * GWEI,
[eEthereumNetwork.main]: 180 * GWEI,
[eEthereumNetwork.coverage]: 1 * GWEI,
[eEthereumNetwork.hardhat]: 1 * GWEI,
[eEthereumNetwork.buidlerevm]: 1 * GWEI,
Expand Down
20 changes: 17 additions & 3 deletions helpers/defender-utils.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import { formatEther } from '@ethersproject/units';
import { DefenderRelaySigner, DefenderRelayProvider } from 'defender-relay-client/lib/ethers';
import { Signer } from 'ethers';
import { DRE, impersonateAccountsHardhat } from './misc-utils';

export const getDefenderRelaySigner = async () => {
const { DEFENDER_API_KEY, DEFENDER_SECRET_KEY } = process.env;
let signer: Signer;

if (!DEFENDER_API_KEY || !DEFENDER_SECRET_KEY) {
throw new Error('Defender secrets required');
}

const credentials = { apiKey: DEFENDER_API_KEY, apiSecret: DEFENDER_SECRET_KEY };
const signer = new DefenderRelaySigner(credentials, new DefenderRelayProvider(credentials), {

signer = new DefenderRelaySigner(credentials, new DefenderRelayProvider(credentials), {
speed: 'fast',
});
const address = await signer.getAddress();

return { signer, address };
const defenderAddress = await signer.getAddress();

// Reemplace signer if MAINNET_FORK is active
if (process.env.MAINNET_FORK === 'true') {
console.log(' - Impersonating Defender Relay');
await impersonateAccountsHardhat([defenderAddress]);
signer = await DRE.ethers.getSigner(defenderAddress);
}
console.log(' - Balance: ', formatEther(await signer.getBalance()));

return { signer, address: defenderAddress };
};
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"compile": "SKIP_LOAD=true hardhat compile",
"console:fork": "MAINNET_FORK=true hardhat console",
"prepublishOnly": "npm run compile",
"deploy:incentives-controller-impl:main": "npm run hardhat:main -- deploy-incentives-impl"
"deploy:incentives-controller-impl:main": "npm run hardhat:main -- deploy-incentives-impl",
"submit-proposal:mainner": "npx hardhat --network main incentives-submit-proposal:mainnet --defender --proposal-execution-payload 0x5778DAee2a634acd303dC9dC91e58D57C8FFfcC8 --a-tokens 0x7b2a3CF972C3193F26CdeC6217D27379b6417bD0,0xE994d6d8595741a6245bC3197fD66C10a3E75C5f,0x1C050bCa8BAbe53Ef769d0d2e411f556e1a27E7B,0x3F06560cfB7af6E6B5102c358f679DE5150b3b4C,0xC2fcab14Ec1F2dFA82a23C639c4770345085a50F,0x541dCd3F00Bcd1A683cc73E1b2A8693b602201f4 --variable-debt-tokens 0x3F87b818f94F3cC21e47FD3Bf015E8D8183A3E08,0x4aBF3e82D5f45A8D8E8C48B544bcA562e20EE2ff,0x1f57Cc62113C3a6346882DcF3Ed49120411ac2d2,0x99E81EDbcab512d393638C087fD29c3DC6c9B00E,0x52fdFB1157878f540DCB961561ce5F3b0bbe6f80,0xDddE1FA049209Bc24B69D5fa316a56EfeC918D79"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -65,6 +66,7 @@
"hardhat-gas-reporter": "^1.0.0",
"husky": "^4.2.5",
"is-ipfs": "^5.0.0",
"kebab-case": "^1.0.1",
"lowdb": "1.0.0",
"prettier": "^2.0.5",
"prettier-plugin-solidity": "^1.0.0-alpha.53",
Expand Down
6 changes: 4 additions & 2 deletions tasks/deployment/deploy-reserve-implementations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ task(
incentivesController,
defender,
});
console.log(`- Deployed ${reserveConfigs[x].symbol} AToken impl`);
console.log(`- Deployed ${reserveConfigs[x].symbol} AToken impl at: ${aTokens[x]}`);
variableDebtTokens[x] = await localBRE.run('deploy-var-debt-token', {
pool,
asset: reserveConfigs[x].tokenAddress,
incentivesController,
defender,
});
console.log(`- Deployed ${reserveConfigs[x].symbol} Variable Debt Token impl`);
console.log(
`- Deployed ${reserveConfigs[x].symbol} Variable Debt Token impl at: ${variableDebtTokens[x]}`
);
}

return {
Expand Down
223 changes: 119 additions & 104 deletions tasks/migrations/incentives-deploy-mainnet.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { task } from 'hardhat/config';
import { DRE } from '../../helpers/misc-utils';
import { DRE, impersonateAccountsHardhat } from '../../helpers/misc-utils';
import { tEthereumAddress } from '../../helpers/types';
import { getReserveConfigs } from '../../test-fork/helpers';
import { ProposalIncentivesExecutor__factory, IERC20Detailed__factory } from '../../types';
import { ILendingPool } from '../../types/ILendingPool';
import { getDefenderRelaySigner } from '../../helpers/defender-utils';
import { Signer } from 'ethers';
import kebabCase from 'kebab-case';

const {
RESERVES = 'DAI,GUSD,USDC,USDT,WBTC,WETH',
Expand All @@ -24,108 +26,121 @@ const INCENTIVES_PROXY = '0xd784927Ff2f95ba542BfC824c8a8a98F3495f6b5';
task(
'incentives-deploy:mainnet',
'Deploy the payload contract, atokens and variable debt token implementations. Print the params for submitting proposal'
).setAction(async (_, localBRE) => {
let aTokensImpl: tEthereumAddress[];
let variableDebtTokensImpl: tEthereumAddress[];
let proposalExecutionPayload: tEthereumAddress;
let symbols: {
[key: string]: {
aToken: { symbol: string; name: string };
variableDebtToken: { symbol: string; name: string };
)
.addFlag('defender')
.setAction(async ({ defender }, localBRE) => {
let aTokensImpl: tEthereumAddress[];
let variableDebtTokensImpl: tEthereumAddress[];
let proposalExecutionPayload: tEthereumAddress;
let symbols: {
[key: string]: {
aToken: { symbol: string; name: string };
variableDebtToken: { symbol: string; name: string };
};
} = {};

await localBRE.run('set-DRE');

let deployer: Signer;
[deployer] = await DRE.ethers.getSigners();

if (defender) {
const { signer } = await getDefenderRelaySigner();
deployer = signer;
}

const ethers = DRE.ethers;

const incentivesProxy = INCENTIVES_PROXY;

if (
!RESERVES ||
!POOL_CONFIGURATOR ||
!POOL_DATA_PROVIDER ||
!ECO_RESERVE ||
!AAVE_TOKEN ||
!AAVE_GOVERNANCE_V2 ||
!AAVE_SHORT_EXECUTOR ||
!TREASURY
) {
throw new Error('You have not set correctly the .env file, make sure to read the README.md');
}

console.log('- Deploying aTokens and Variable Debt Tokens implementations');

// Deploy aTokens and debt tokens
const { aTokens, variableDebtTokens } = await DRE.run('deploy-reserve-implementations', {
provider: POOL_PROVIDER,
assets: RESERVES,
incentivesController: incentivesProxy,
treasury: TREASURY,
defender: true,
});

aTokensImpl = [...aTokens];
variableDebtTokensImpl = [...variableDebtTokens];

// Deploy Proposal Executor Payload
const {
address: proposalExecutionPayloadAddress,
} = await new ProposalIncentivesExecutor__factory(deployer).deploy();
proposalExecutionPayload = proposalExecutionPayloadAddress;

console.log('Deployed ProposalIncentivesExecutor at:', proposalExecutionPayloadAddress);

// Initialize contracts and tokens
const pool = (await ethers.getContractAt(
'ILendingPool',
AAVE_LENDING_POOL,
deployer
)) as ILendingPool;

// Save aToken and debt token names
const reserveConfigs = await getReserveConfigs(POOL_PROVIDER, RESERVES, deployer);

for (let x = 0; x < reserveConfigs.length; x++) {
const { tokenAddress, symbol } = reserveConfigs[x];
const { aTokenAddress, variableDebtTokenAddress } = await pool.getReserveData(tokenAddress);
const aToken = IERC20Detailed__factory.connect(aTokenAddress, deployer);
const varDebtToken = IERC20Detailed__factory.connect(variableDebtTokenAddress, deployer);

symbols[symbol] = {
aToken: {
name: await aToken.name(),
symbol: await aToken.symbol(),
},
variableDebtToken: {
name: await varDebtToken.name(),
symbol: await varDebtToken.symbol(),
},
};
}

console.log('- Finished deployment script');

console.log('=== INFO ===');
console.log('Proposal payload:', proposalExecutionPayloadAddress);
console.log('Incentives Controller proxy:', incentivesProxy);
console.log(
'Needed params to submit the proposal at the following task: ',
'$ npx hardhat --network main incentives-submit-proposal:mainnet'
);
const proposalParams = {
proposalExecutionPayload,
aTokens: aTokensImpl.join(','),
variableDebtTokens: variableDebtTokensImpl.join(','),
};
} = {};

await localBRE.run('set-DRE');

const { signer: proposerRelay, address: proposerAddress } = await getDefenderRelaySigner();

const ethers = DRE.ethers;

const incentivesProxy = INCENTIVES_PROXY;

if (
!RESERVES ||
!POOL_CONFIGURATOR ||
!POOL_DATA_PROVIDER ||
!ECO_RESERVE ||
!AAVE_TOKEN ||
!AAVE_GOVERNANCE_V2 ||
!AAVE_SHORT_EXECUTOR ||
!TREASURY
) {
throw new Error('You have not set correctly the .env file, make sure to read the README.md');
}

console.log('- Deploying aTokens and Variable Debt Tokens implementations');

// Deploy aTokens and debt tokens
const { aTokens, variableDebtTokens } = await DRE.run('deploy-reserve-implementations', {
provider: POOL_PROVIDER,
assets: RESERVES,
incentivesController: incentivesProxy,
treasury: TREASURY,
defender: true,
console.log(
`--defender `,
Object.keys(proposalParams)
.map((str) => `--${kebabCase(str)} ${proposalParams[str]}`)
.join(' ')
);

await DRE.run('verify-proposal-etherscan', {
assets: RESERVES,
aTokens: aTokensImpl.join(','),
variableDebtTokens: variableDebtTokensImpl.join(','),
proposalPayloadAddress: proposalExecutionPayloadAddress,
});
});

aTokensImpl = [...aTokens];
variableDebtTokensImpl = [...variableDebtTokens];

// Deploy Proposal Executor Payload
const {
address: proposalExecutionPayloadAddress,
} = await new ProposalIncentivesExecutor__factory(proposerRelay).deploy();
proposalExecutionPayload = proposalExecutionPayloadAddress;

console.log(-'Deployed ProposalIncentivesExecutor at:', proposalExecutionPayloadAddress);

// Initialize contracts and tokens
const pool = (await ethers.getContractAt(
'ILendingPool',
AAVE_LENDING_POOL,
proposerRelay
)) as ILendingPool;

// Save aToken and debt token names
const reserveConfigs = await getReserveConfigs(POOL_PROVIDER, RESERVES, proposerRelay);

for (let x = 0; x < reserveConfigs.length; x++) {
const { tokenAddress, symbol } = reserveConfigs[x];
const { aTokenAddress, variableDebtTokenAddress } = await pool.getReserveData(tokenAddress);
const aToken = IERC20Detailed__factory.connect(aTokenAddress, proposerRelay);
const varDebtToken = IERC20Detailed__factory.connect(variableDebtTokenAddress, proposerRelay);

symbols[symbol] = {
aToken: {
name: await aToken.name(),
symbol: await aToken.symbol(),
},
variableDebtToken: {
name: await varDebtToken.name(),
symbol: await varDebtToken.symbol(),
},
};
}

console.log('- Finished deployment script');

console.log('=== INFO ===');
console.log('Proposal payload:', proposalExecutionPayloadAddress);
console.log('Incentives Controller proxy:', incentivesProxy);
console.log(
'Needed params to submit the proposal at the following task: ',
'$ npx hardhat --network main incentives-submit-proposal:mainnet'
);
const proposalParams = {
proposalExecutionPayload,
aTokens: aTokensImpl.join(','),
variableDebtTokens: variableDebtTokensImpl.join(','),
};
console.log(JSON.stringify(proposalParams, null, 2));

await DRE.run('verify-proposal-etherscan', {
assets: RESERVES,
aTokens: aTokensImpl.join(','),
variableDebtTokens: variableDebtTokensImpl.join(','),
proposalPayloadAddress: proposalExecutionPayloadAddress,
});
});
Loading

0 comments on commit adce219

Please sign in to comment.