diff --git a/helpers/misc-utils.ts b/helpers/misc-utils.ts index 387d4399..80470028 100644 --- a/helpers/misc-utils.ts +++ b/helpers/misc-utils.ts @@ -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 => { - 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 { diff --git a/tasks/helpers/impersonate-transfer.ts b/tasks/helpers/impersonate-transfer.ts new file mode 100644 index 00000000..264c60f0 --- /dev/null +++ b/tasks/helpers/impersonate-transfer.ts @@ -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); + } + });