mirror of
https://github.com/Instadapp/aave-protocol-v2.git
synced 2024-07-29 21:47:30 +00:00
tasks: added task to do erc20 transfers from impersonated addresses inside Tenderly forks
This commit is contained in:
parent
6fb9f24da9
commit
c041167b11
|
@ -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 {
|
||||
|
|
39
tasks/helpers/impersonate-transfer.ts
Normal file
39
tasks/helpers/impersonate-transfer.ts
Normal 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);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user