tasks: added task to do erc20 transfers from impersonated addresses inside Tenderly forks

This commit is contained in:
David Racero 2021-06-02 18:14:12 +02:00
parent 6fb9f24da9
commit c041167b11
2 changed files with 46 additions and 4 deletions

View File

@ -10,6 +10,7 @@ import { tEthereumAddress } from './types';
import { isAddress } from 'ethers/lib/utils';
import { isZeroAddress } from 'ethereumjs-util';
import { SignerWithAddress } from '../test-suites/test-aave/helpers/make-suite';
import { usingTenderly } from './tenderly-utils';
export const toWad = (value: string | number) => new BigNumber(value).times(WAD).toFixed();
@ -118,10 +119,12 @@ export const notFalsyOrZeroAddress = (address: tEthereumAddress | null | undefin
};
export const impersonateAddress = async (address: tEthereumAddress): Promise<SignerWithAddress> => {
await (DRE as HardhatRuntimeEnvironment).network.provider.request({
method: 'hardhat_impersonateAccount',
params: [address],
});
if (!usingTenderly()) {
await (DRE as HardhatRuntimeEnvironment).network.provider.request({
method: 'hardhat_impersonateAccount',
params: [address],
});
}
const signer = await DRE.ethers.provider.getSigner(address);
return {

View File

@ -0,0 +1,39 @@
import { formatUnits } from '@ethersproject/units';
import { task } from 'hardhat/config';
import { impersonateAddress, waitForTx } from '../../helpers/misc-utils';
import { usingTenderly } from '../../helpers/tenderly-utils';
import { IERC20DetailedFactory } from '../../types/IERC20DetailedFactory';
task('dev:impersonate-transfer', 'Send ERC20 from an impersonated address')
.addParam('from', 'Impersonate from user address')
.addParam('to', 'Where to send impersonated funds')
.addParam('token', 'ERC20 Token address')
.addOptionalParam('amount', 'Optional amount in wei unit to send, by default is all')
.setAction(async ({ from, to, token, amount }, localBRE) => {
await localBRE.run('set-DRE');
const fromSigner = await impersonateAddress(from);
const erc20 = IERC20DetailedFactory.connect(token, fromSigner.signer);
const amountToSend = amount ? amount : await erc20.balanceOf(from);
const symbol = await erc20.symbol();
const decimals = await erc20.decimals();
console.log('- Transfering...');
await waitForTx(await erc20.transfer(to, amountToSend));
console.log('- Sent ', formatUnits(await erc20.balanceOf(from), decimals), symbol, 'to', to);
console.log('\nBalances after transfer');
console.log('=======================');
console.log('from:');
console.log('- Address:', from);
console.log('- Balance:', formatUnits(await erc20.balanceOf(from), decimals), symbol);
console.log('to:');
console.log('- Address:', to);
console.log('- Balance:', formatUnits(await erc20.balanceOf(to), decimals), symbol);
if (usingTenderly()) {
const postDeployHead = localBRE.tenderlyRPC.getHead();
const postDeployFork = localBRE.tenderlyRPC.getFork();
console.log('Tenderly Info');
console.log('- Head', postDeployHead);
console.log('- Fork', postDeployFork);
}
});