feat: Added impersonateAddress function

This commit is contained in:
David Racero 2021-05-17 13:11:38 +02:00
parent 93334a94ab
commit 991a7d424f

View File

@ -9,6 +9,7 @@ import { BuidlerRuntimeEnvironment } from '@nomiclabs/buidler/types';
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';
export const toWad = (value: string | number) => new BigNumber(value).times(WAD).toFixed();
@ -115,3 +116,16 @@ export const notFalsyOrZeroAddress = (address: tEthereumAddress | null | undefin
}
return isAddress(address) && !isZeroAddress(address);
};
export const impersonateAddress = async (address: tEthereumAddress): Promise<SignerWithAddress> => {
await (DRE as HardhatRuntimeEnvironment).network.provider.request({
method: 'hardhat_impersonateAccount',
params: [address],
});
const signer = await DRE.ethers.provider.getSigner(address);
return {
signer,
address,
};
};