Skip to content

Commit

Permalink
Merge branch 'master' into new-aave-linear-pool-deployment
Browse files Browse the repository at this point in the history
* master:
  Remove wrong dependency (#2018)
  Improve deployment signers (#2017)
  Use hardhat network helpers (#2016)
  • Loading branch information
TomAFrench committed Nov 16, 2022
2 parents 439eac4 + 751f00b commit c571f1a
Show file tree
Hide file tree
Showing 44 changed files with 148 additions and 198 deletions.
1 change: 1 addition & 0 deletions pkg/deployments/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"devDependencies": {
"@balancer-labs/balancer-js": "workspace:*",
"@balancer-labs/v2-helpers": "workspace:*",
"@nomicfoundation/hardhat-network-helpers": "^1.0.6",
"@nomiclabs/hardhat-ethers": "^2.2.1",
"@nomiclabs/hardhat-etherscan": "^3.1.2",
"@solidity-parser/parser": "^0.14.5",
Expand Down
44 changes: 11 additions & 33 deletions pkg/deployments/src/signers.ts
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ import { advanceToTimestamp, currentTimestamp, DAY, MINUTE, MONTH } from '@balan

import { actionId } from '@balancer-labs/v2-helpers/src/models/misc/actions';

import {
describeForkTest,
getSigner,
impersonate,
impersonateWhale,
getForkedNetwork,
Task,
TaskMode,
} from '../../../src';
import { describeForkTest, getSigner, impersonate, getForkedNetwork, Task, TaskMode } from '../../../src';

describeForkTest('NoProtocolFeeLiquidityBootstrappingPoolFactory', 'mainnet', 14850000, function () {
let owner: SignerWithAddress, whale: SignerWithAddress;
Expand All @@ -45,6 +37,8 @@ describeForkTest('NoProtocolFeeLiquidityBootstrappingPoolFactory', 'mainnet', 14
const initialBalanceUSDC = fp(1e6).div(1e12); // 6 digits
const initialBalances = [initialBalanceDAI, initialBalanceUSDC];

const LARGE_TOKEN_HOLDER = '0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503';

before('run task', async () => {
task = new Task('20211202-no-protocol-fee-lbp', TaskMode.TEST, getForkedNetwork(hre));
await task.run({ force: true });
Expand All @@ -53,7 +47,7 @@ describeForkTest('NoProtocolFeeLiquidityBootstrappingPoolFactory', 'mainnet', 14

before('load signers', async () => {
owner = await getSigner();
whale = await impersonateWhale(fp(100));
whale = await impersonate(LARGE_TOKEN_HOLDER);
});

before('load vault and tokens', async () => {
Expand Down Expand Up @@ -164,7 +158,7 @@ describeForkTest('NoProtocolFeeLiquidityBootstrappingPoolFactory', 'mainnet', 14
const authorizer = await vaultTask.instanceAt('Authorizer', await vault.getAuthorizer());

const DEFAULT_ADMIN_ROLE = await authorizer.DEFAULT_ADMIN_ROLE();
const admin = await impersonate(await authorizer.getRoleMember(DEFAULT_ADMIN_ROLE, 0), fp(100));
const admin = await impersonate(await authorizer.getRoleMember(DEFAULT_ADMIN_ROLE, 0));

await authorizer.connect(admin).grantRole(await actionId(factory, 'disable'), admin.address);
await factory.connect(admin).disable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { expect } from 'chai';
import { Contract } from 'ethers';

import { defaultAbiCoder } from '@ethersproject/abi';
import { fp } from '@balancer-labs/v2-helpers/src/numbers';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address';
import { actionId } from '@balancer-labs/v2-helpers/src/models/misc/actions';
import { WeightedPoolEncoder } from '@balancer-labs/balancer-js';
Expand Down Expand Up @@ -60,7 +59,7 @@ describeForkTest('DoubleEntrypointFixRelayer', 'mainnet', 14770592, function ()
});

before('grant permissions', async () => {
govMultisig = await impersonate(GOV_MULTISIG, fp(100));
govMultisig = await impersonate(GOV_MULTISIG);

const vaultTask = new Task('20210418-vault', TaskMode.READ_ONLY, getForkedNetwork(hre));
authorizer = await vaultTask.instanceAt('Authorizer', await vault.getAuthorizer());
Expand All @@ -71,10 +70,10 @@ describeForkTest('DoubleEntrypointFixRelayer', 'mainnet', 14770592, function ()
await authorizer.connect(govMultisig).grantRoles([exitPoolRole, withdrawCollectedFeesRole], relayer.address);

// User approval for relayer
btcBptHolder = await impersonate(BTC_STABLE_POOL_GAUGE, fp(100));
btcBptHolder = await impersonate(BTC_STABLE_POOL_GAUGE);
await vault.connect(btcBptHolder).setRelayerApproval(btcBptHolder.address, relayer.address, true);

snxBptHolder = await impersonate(SNX_WEIGHTED_POOL_GAUGE, fp(100));
snxBptHolder = await impersonate(SNX_WEIGHTED_POOL_GAUGE);
await vault.connect(snxBptHolder).setRelayerApproval(snxBptHolder.address, relayer.address, true);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import hre from 'hardhat';
import { BigNumber, Contract } from 'ethers';
import { expect } from 'chai';

import { fp } from '@balancer-labs/v2-helpers/src/numbers';
import * as expectEvent from '@balancer-labs/v2-helpers/src/test/expectEvent';

import { ZERO_ADDRESS } from '@balancer-labs/v2-helpers/src/constants';
Expand Down Expand Up @@ -47,7 +46,7 @@ describeForkTest('PreseededVotingEscrowDelegation', 'mainnet', 14850000, functio
getForkedNetwork(hre)
).deployedInstance('Authorizer');

const govMultisig = await impersonate(GOV_MULTISIG, fp(100));
const govMultisig = await impersonate(GOV_MULTISIG);
await authorizer
.connect(govMultisig)
.grantRole(await actionId(delegationProxy, 'setDelegation'), govMultisig.address);
Expand Down Expand Up @@ -111,7 +110,7 @@ describeForkTest('PreseededVotingEscrowDelegation', 'mainnet', 14850000, functio
const TRIBE_DAO = '0xc4EAc760C2C631eE0b064E39888b89158ff808B2';
const TRIBE_OPERATOR = '0x66977ce30049cd0e443216bf26377966c3a109e2';

const operator = await impersonate(TRIBE_OPERATOR, fp(100));
const operator = await impersonate(TRIBE_OPERATOR);

const receipt = await (
await delegation.connect(operator).create_boost(TRIBE_DAO, receiver.address, 1000, 0, await fromNow(MONTH), 0)
Expand Down
15 changes: 4 additions & 11 deletions pkg/deployments/tasks/20220609-stable-pool-v2/test/task.fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,7 @@ import { actionId } from '@balancer-labs/v2-helpers/src/models/misc/actions';
import { MAX_UINT256 } from '@balancer-labs/v2-helpers/src/constants';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-with-address';

import {
describeForkTest,
getSigner,
impersonate,
impersonateWhale,
getForkedNetwork,
Task,
TaskMode,
} from '../../../src';
import { describeForkTest, getSigner, impersonate, getForkedNetwork, Task, TaskMode } from '../../../src';

describeForkTest('StablePoolFactory', 'mainnet', 14850000, function () {
let owner: SignerWithAddress, whale: SignerWithAddress, govMultisig: SignerWithAddress;
Expand All @@ -39,6 +31,7 @@ describeForkTest('StablePoolFactory', 'mainnet', 14850000, function () {
const upscaledInitialBalances = [initialBalanceDAI, initialBalanceUSDC.mul(1e12)];

const GOV_MULTISIG = '0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f';
const LARGE_TOKEN_HOLDER = '0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503';

before('run task', async () => {
task = new Task('20220609-stable-pool-v2', TaskMode.TEST, getForkedNetwork(hre));
Expand All @@ -48,9 +41,9 @@ describeForkTest('StablePoolFactory', 'mainnet', 14850000, function () {

before('load signers', async () => {
owner = await getSigner();
whale = await impersonateWhale(fp(100));
whale = await impersonate(LARGE_TOKEN_HOLDER);

govMultisig = await impersonate(GOV_MULTISIG, fp(100));
govMultisig = await impersonate(GOV_MULTISIG);
});

before('setup contracts', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ describeForkTest('DistributionScheduler', 'mainnet', 14850000, function () {
});

before('setup accounts', async () => {
lmCommittee = await impersonate(LM_COMMITTEE_ADDRESS, fp(100));
distributor = await impersonate(DISTRIBUTOR_ADDRESS, fp(100));
lmCommittee = await impersonate(LM_COMMITTEE_ADDRESS);
distributor = await impersonate(DISTRIBUTOR_ADDRESS);
});

before('setup contracts', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ describeForkTest('FeeDistributor', 'mainnet', 15130000, function () {
});

before('setup accounts', async () => {
veBALHolder = await impersonate(VEBAL_HOLDER, fp(100));
veBALHolder2 = await impersonate(VEBAL_HOLDER_2, fp(100));
feeCollector = await impersonate(PROTOCOL_FEE_COLLECTOR, fp(100));
voterProxyAdmin = await impersonate(VOTER_PROXY_ADMIN, fp(100));
veBALHolder = await impersonate(VEBAL_HOLDER);
veBALHolder2 = await impersonate(VEBAL_HOLDER_2);
feeCollector = await impersonate(PROTOCOL_FEE_COLLECTOR);
voterProxyAdmin = await impersonate(VOTER_PROXY_ADMIN);
});

before('setup contracts', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describeForkTest('ProtocolFeePercentagesProvider', 'mainnet', 15130000, function

before('setup admin', async () => {
const DEFAULT_ADMIN_ROLE = await authorizer.DEFAULT_ADMIN_ROLE();
admin = await impersonate(await authorizer.getRoleMember(DEFAULT_ADMIN_ROLE, 0), fp(100));
admin = await impersonate(await authorizer.getRoleMember(DEFAULT_ADMIN_ROLE, 0));
});

context('without permissions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ describeForkTest('LiquidityGaugeFactoryV2', 'mainnet', 15397200, function () {

before('setup accounts', async () => {
admin = await getSigner(0);
veBALHolder = await impersonate(VEBAL_HOLDER, fp(100));
lpTokenHolder = await impersonate(LP_TOKEN_HOLDER, fp(100));
veBALHolder = await impersonate(VEBAL_HOLDER);
lpTokenHolder = await impersonate(LP_TOKEN_HOLDER);
});

before('setup contracts', async () => {
Expand Down Expand Up @@ -110,7 +110,7 @@ describeForkTest('LiquidityGaugeFactoryV2', 'mainnet', 15397200, function () {
it('grant permissions', async () => {
// We need to grant permission to the admin to add the LiquidityGaugeFactory to the GaugeAdder, and also to add
// gauges from said factory to the GaugeController.
const govMultisig = await impersonate(GOV_MULTISIG, fp(100));
const govMultisig = await impersonate(GOV_MULTISIG);

await Promise.all(
['addGaugeFactory', 'addEthereumGauge'].map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describeForkTest('ArbitrumRootGaugeFactoryV2', 'mainnet', 15397200, function ()
admin = await getSigner(0);
recipient = await getSigner(1);

veBALHolder = await impersonate(VEBAL_HOLDER, fp(100));
veBALHolder = await impersonate(VEBAL_HOLDER);
});

before('setup contracts', async () => {
Expand Down Expand Up @@ -95,7 +95,7 @@ describeForkTest('ArbitrumRootGaugeFactoryV2', 'mainnet', 15397200, function ()
it('grant permissions', async () => {
// We need to grant permission to the admin to add the Arbitrum factory to the GaugeAdder, and also to then add
// gauges from said factory to the GaugeController.
const govMultisig = await impersonate(GOV_MULTISIG, fp(100));
const govMultisig = await impersonate(GOV_MULTISIG);

await Promise.all(
['addGaugeFactory', 'addArbitrumGauge'].map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describeForkTest('OptimismRootGaugeFactoryV2', 'mainnet', 15397200, function ()
admin = await getSigner(0);
recipient = await getSigner(1);

veBALHolder = await impersonate(VEBAL_HOLDER, fp(100));
veBALHolder = await impersonate(VEBAL_HOLDER);
});

before('setup contracts', async () => {
Expand Down Expand Up @@ -85,7 +85,7 @@ describeForkTest('OptimismRootGaugeFactoryV2', 'mainnet', 15397200, function ()
it('grant permissions', async () => {
// We need to grant permission to the admin to add the Optimism factory to the GaugeAdder, and also to then add
// gauges from said factory to the GaugeController.
const govMultisig = await impersonate(GOV_MULTISIG, fp(100));
const govMultisig = await impersonate(GOV_MULTISIG);

await Promise.all(
['addGaugeFactory', 'addOptimismGauge'].map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ describeForkTest('PolygonRootGaugeFactoryV2', 'mainnet', 15397200, function () {
admin = await getSigner(0);
recipient = await getSigner(1);

veBALHolder = await impersonate(VEBAL_HOLDER, fp(100));
veBALHolder = await impersonate(VEBAL_HOLDER);
});

before('setup contracts', async () => {
Expand Down Expand Up @@ -95,7 +95,7 @@ describeForkTest('PolygonRootGaugeFactoryV2', 'mainnet', 15397200, function () {
it('grant permissions', async () => {
// We need to grant permission to the admin to add the Polygon factory to the GaugeAdder, and also to then add
// gauges from said factory to the GaugeController.
const govMultisig = await impersonate(GOV_MULTISIG, fp(100));
const govMultisig = await impersonate(GOV_MULTISIG);

await Promise.all(
['addGaugeFactory', 'addPolygonGauge'].map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import hre from 'hardhat';
import { expect } from 'chai';
import { BigNumber, Contract } from 'ethers';

import { BigNumberish, fp } from '@balancer-labs/v2-helpers/src/numbers';
import { BigNumberish } from '@balancer-labs/v2-helpers/src/numbers';

import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';
import { WeightedPoolEncoder } from '@balancer-labs/balancer-js';
Expand Down Expand Up @@ -53,7 +53,7 @@ describeForkTest('BatchRelayerLibrary', 'mainnet', 15485000, function () {

before('load signers', async () => {
// We impersonate an account that holds staked BPT for the ETH_STETH Pool.
sender = await impersonate(STAKED_ETH_STETH_HOLDER, fp(100));
sender = await impersonate(STAKED_ETH_STETH_HOLDER);
});

before('approve relayer at the authorizer', async () => {
Expand All @@ -65,7 +65,7 @@ describeForkTest('BatchRelayerLibrary', 'mainnet', 15485000, function () {

// We impersonate an account with the default admin role in order to be able to approve the relayer. This assumes
// such an account exists.
const admin = await impersonate(await authorizer.getRoleMember(await authorizer.DEFAULT_ADMIN_ROLE(), 0), fp(100));
const admin = await impersonate(await authorizer.getRoleMember(await authorizer.DEFAULT_ADMIN_ROLE(), 0));

// Grant relayer permission to call all relayer functions
await authorizer.connect(admin).grantRoles(relayerActionIds, relayer.address);
Expand Down
15 changes: 4 additions & 11 deletions pkg/deployments/tasks/20221021-managed-pool/test/task.fork.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,7 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/dist/src/signer-wit
import { ManagedPoolParams } from '@balancer-labs/v2-helpers/src/models/pools/weighted/types';
import { ProtocolFee } from '@balancer-labs/v2-helpers/src/models/vault/types';

import {
getSigner,
impersonate,
impersonateWhale,
getForkedNetwork,
Task,
TaskMode,
describeForkTest,
} from '../../../src';
import { getSigner, impersonate, getForkedNetwork, Task, TaskMode, describeForkTest } from '../../../src';

describeForkTest('ManagedPoolFactory', 'mainnet', 15634000, function () {
let owner: SignerWithAddress, whale: SignerWithAddress, govMultisig: SignerWithAddress;
Expand All @@ -44,6 +36,7 @@ describeForkTest('ManagedPoolFactory', 'mainnet', 15634000, function () {
const initialBalances = [initialBalanceUNI, initialBalanceAAVE, initialBalanceCOMP];

const GOV_MULTISIG = '0x10A19e7eE7d7F8a52822f6817de8ea18204F2e4f';
const LARGE_TOKEN_HOLDER = '0x47ac0fb4f2d84898e4d9e7b4dab3c24507a6d503';

const NAME = 'Balancer Pool Token';
const SYMBOL = 'BPT';
Expand All @@ -60,9 +53,9 @@ describeForkTest('ManagedPoolFactory', 'mainnet', 15634000, function () {

before('load signers', async () => {
owner = await getSigner();
whale = await impersonateWhale(fp(100));
whale = await impersonate(LARGE_TOKEN_HOLDER);

govMultisig = await impersonate(GOV_MULTISIG, fp(100));
govMultisig = await impersonate(GOV_MULTISIG);
});

before('setup contracts', async () => {
Expand Down
Loading

0 comments on commit c571f1a

Please sign in to comment.