From 991a7d424f3025ba08b1ec912408995c380b75cf Mon Sep 17 00:00:00 2001 From: David Racero Date: Mon, 17 May 2021 13:11:38 +0200 Subject: [PATCH] feat: Added impersonateAddress function --- helpers/misc-utils.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/helpers/misc-utils.ts b/helpers/misc-utils.ts index 54d5fa44..55cde7f2 100644 --- a/helpers/misc-utils.ts +++ b/helpers/misc-utils.ts @@ -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 => { + await (DRE as HardhatRuntimeEnvironment).network.provider.request({ + method: 'hardhat_impersonateAccount', + params: [address], + }); + const signer = await DRE.ethers.provider.getSigner(address); + + return { + signer, + address, + }; +};