-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into new-aave-linear-pool-deployment
* master: Remove wrong dependency (#2018) Improve deployment signers (#2017) Use hardhat network helpers (#2016)
- Loading branch information
Showing
44 changed files
with
148 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,27 @@ | ||
import { BigNumber } from 'ethers'; | ||
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address'; | ||
|
||
import { getForkedNetwork } from './test'; | ||
|
||
const WHALES: { [key: string]: string } = { | ||
mainnet: '0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503', | ||
}; | ||
import { impersonateAccount, setBalance as setAccountBalance } from '@nomicfoundation/hardhat-network-helpers'; | ||
import { fp } from '@balancer-labs/v2-helpers/src/numbers'; | ||
|
||
export async function getSigners(): Promise<SignerWithAddress[]> { | ||
const { ethers } = await import('hardhat'); | ||
return ethers.getSigners(); | ||
} | ||
|
||
export async function getSigner(indexOrAddress: number | string = 0): Promise<SignerWithAddress> { | ||
if (typeof indexOrAddress === 'string') { | ||
const { ethers } = await import('hardhat'); | ||
const signer = ethers.provider.getSigner(indexOrAddress); | ||
return SignerWithAddress.create(signer); | ||
} else { | ||
const signers = await getSigners(); | ||
return signers[indexOrAddress]; | ||
} | ||
export async function getSigner(index = 0): Promise<SignerWithAddress> { | ||
return (await getSigners())[index]; | ||
} | ||
|
||
export async function impersonate(address: string, balance?: BigNumber): Promise<SignerWithAddress> { | ||
if (balance) { | ||
await setBalance(address, balance); | ||
} | ||
|
||
return getSigner(address); | ||
} | ||
export async function impersonate(address: string, balance = fp(100)): Promise<SignerWithAddress> { | ||
await impersonateAccount(address); | ||
await setBalance(address, balance); | ||
|
||
export async function impersonateWhale(balance?: BigNumber): Promise<SignerWithAddress> { | ||
const hre = await import('hardhat'); | ||
const network = getForkedNetwork(hre); | ||
const address = WHALES[network]; | ||
if (!address) throw Error(`Could not find whale address for network ${network}`); | ||
return impersonate(address, balance); | ||
const { ethers } = await import('hardhat'); | ||
const signer = ethers.provider.getSigner(address); | ||
return SignerWithAddress.create(signer); | ||
} | ||
|
||
export async function setBalance(address: string, balance: BigNumber): Promise<void> { | ||
const hre = await import('hardhat'); | ||
await hre.network.provider.request({ method: 'hardhat_impersonateAccount', params: [address] }); | ||
|
||
const rawHexBalance = hre.ethers.utils.hexlify(balance); | ||
const hexBalance = rawHexBalance.replace('0x0', '0x'); | ||
await hre.network.provider.request({ method: 'hardhat_setBalance', params: [address, hexBalance] }); | ||
await setAccountBalance(address, balance); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.