Skip to content

Commit b83d01c

Browse files
refactor(UBA): sideload HRE environment variable (#289)
* refactor(UBA): sideload HRE environment variable This change essentially side-loads the HRE variables to prevent the need to directly interface with the Hardhat Runtime Environment. Signed-off-by: james-a-morris <[email protected]> * fix: resolve additional import issues Signed-off-by: james-a-morris <[email protected]> --------- Signed-off-by: james-a-morris <[email protected]>
1 parent 7a56413 commit b83d01c

31 files changed

+176
-80
lines changed

deploy/003_deploy_optimism_spokepool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { deployNewProxy } from "../utils";
1+
import { deployNewProxy } from "../utils/utils.hre";
22
import { DeployFunction } from "hardhat-deploy/types";
33
import { HardhatRuntimeEnvironment } from "hardhat/types";
44

deploy/005_deploy_arbitrum_spokepool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DeployFunction } from "hardhat-deploy/types";
22
import { L2_ADDRESS_MAP } from "./consts";
3-
import { deployNewProxy } from "../utils";
3+
import { deployNewProxy } from "../utils/utils.hre";
44
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

66
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

deploy/007_deploy_ethereum_spokepool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DeployFunction } from "hardhat-deploy/types";
2-
import { deployNewProxy } from "../utils";
2+
import { deployNewProxy } from "../utils/utils.hre";
33
import { L1_ADDRESS_MAP } from "./consts";
44
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

deploy/011_deploy_polygon_spokepool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DeployFunction } from "hardhat-deploy/types";
22
import { L2_ADDRESS_MAP } from "./consts";
3-
import { deployNewProxy } from "../utils";
3+
import { deployNewProxy } from "../utils/utils.hre";
44
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

66
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

deploy/013_deploy_boba_spokepool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DeployFunction } from "hardhat-deploy/types";
2-
import { deployNewProxy } from "../utils";
2+
import { deployNewProxy } from "../utils/utils.hre";
33
import { HardhatRuntimeEnvironment } from "hardhat/types";
44

55
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

deploy/016_deploy_zksync_spokepool.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { DeployFunction } from "hardhat-deploy/types";
22
import { L2_ADDRESS_MAP } from "./consts";
3-
import { deployNewProxy } from "../utils";
3+
import { deployNewProxy } from "../utils/utils.hre";
44
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

66
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {

scripts/mintERC1155.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import { getContractFactory, ethers, hre } from "../utils/utils";
1+
import { getContractFactory, ethers } from "../utils/utils";
22
import { readFileSync } from "fs";
33
import path from "path";
44
import { getNodeUrl } from "@uma/common";
5+
import { hre } from "../utils/utils.hre";
56

67
const RECIPIENTS_CHUNK_SIZE = 100; // TODO: Still need to figure out which size is optimal
78

scripts/setERC1155Metadata.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getContractFactory, ethers, hre } from "../utils/utils";
1+
import { getContractFactory, ethers } from "../utils/utils";
2+
import { hre } from "../utils/utils.hre";
23
import { readFileSync } from "fs";
34
import path from "path";
45
import { CID } from "multiformats/cid";

test/HubPool.Admin.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1-
import { getContractFactory, SignerWithAddress, seedWallet, expect } from "../utils/utils";
2-
import { Contract, ethers, randomAddress, utf8ToHex } from "../utils/utils";
3-
import { originChainId, destinationChainId, bondAmount, zeroAddress, mockTreeRoot } from "./constants";
4-
import { mockSlowRelayRoot, finalFeeUsdc, finalFee, totalBond } from "./constants";
1+
import {
2+
getContractFactory,
3+
SignerWithAddress,
4+
seedWallet,
5+
expect,
6+
Contract,
7+
ethers,
8+
randomAddress,
9+
utf8ToHex,
10+
} from "../utils/utils";
11+
import {
12+
originChainId,
13+
destinationChainId,
14+
bondAmount,
15+
zeroAddress,
16+
mockTreeRoot,
17+
mockSlowRelayRoot,
18+
finalFeeUsdc,
19+
finalFee,
20+
totalBond,
21+
} from "./constants";
522
import { hubPoolFixture } from "./fixtures/HubPool.Fixture";
623

724
let hubPool: Contract, weth: Contract, usdc: Contract;

test/MerkleLib.Proofs.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
import { PoolRebalanceLeaf, RelayerRefundLeaf } from "./MerkleLib.utils";
22
import { merkleLibFixture } from "./fixtures/MerkleLib.Fixture";
33
import { MerkleTree, EMPTY_MERKLE_ROOT } from "../utils/MerkleTree";
4-
import { expect, randomBigNumber, randomAddress, getParamType, defaultAbiCoder } from "../utils/utils";
5-
import { keccak256, Contract, BigNumber } from "../utils/utils";
4+
import {
5+
expect,
6+
randomBigNumber,
7+
randomAddress,
8+
getParamType,
9+
defaultAbiCoder,
10+
keccak256,
11+
Contract,
12+
BigNumber,
13+
} from "../utils/utils";
614

715
let merkleLibTest: Contract;
816

test/MerkleLib.utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getParamType, expect, BigNumber, Contract, defaultAbiCoder, keccak256, toBNWei } from "../utils/utils";
22
import { repaymentChainId, amountToReturn } from "./constants";
33
import { MerkleTree } from "../utils/MerkleTree";
4-
import { RelayData, SlowFill } from "./fixtures/SpokePool.Fixture";
4+
import { SlowFill } from "./fixtures/SpokePool.Fixture";
55
export interface PoolRebalanceLeaf {
66
chainId: BigNumber;
77
groupIndex: BigNumber;

test/SpokePool.Admin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { expect, ethers, Contract, SignerWithAddress, getContractFactory, hre } from "../utils/utils";
1+
import { expect, ethers, Contract, SignerWithAddress, getContractFactory } from "../utils/utils";
2+
import { hre } from "../utils/utils.hre";
23
import { spokePoolFixture } from "./fixtures/SpokePool.Fixture";
34
import { destinationChainId, mockRelayerRefundRoot, mockSlowRelayRoot } from "./constants";
45

test/SpokePool.Upgrades.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { expect, ethers, Contract, SignerWithAddress, hre, randomAddress } from "../utils/utils";
1+
import { expect, ethers, Contract, SignerWithAddress, randomAddress } from "../utils/utils";
2+
import { hre } from "../utils/utils.hre";
23
import { spokePoolFixture } from "./fixtures/SpokePool.Fixture";
34

45
let spokePool: Contract;

test/chain-adapters/Arbitrum_Adapter.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ import {
99
toWei,
1010
defaultAbiCoder,
1111
toBN,
12+
getContractFactory,
13+
seedWallet,
14+
randomAddress,
1215
} from "../../utils/utils";
13-
import { getContractFactory, seedWallet, randomAddress } from "../../utils/utils";
1416
import { hubPoolFixture, enableTokensForLP } from "../fixtures/HubPool.Fixture";
1517
import { constructSingleChainTree } from "../MerkleLib.utils";
1618

test/chain-adapters/Ethereum_Adapter.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import * as consts from "../constants";
2-
import { ethers, expect, Contract, SignerWithAddress, randomAddress, hre } from "../../utils/utils";
3-
import { getContractFactory, seedWallet } from "../../utils/utils";
2+
import {
3+
ethers,
4+
expect,
5+
Contract,
6+
SignerWithAddress,
7+
randomAddress,
8+
getContractFactory,
9+
seedWallet,
10+
} from "../../utils/utils";
11+
import { hre } from "../../utils/utils.hre";
412
import { hubPoolFixture, enableTokensForLP } from "../fixtures/HubPool.Fixture";
513
import { constructSingleChainTree } from "../MerkleLib.utils";
614

test/chain-adapters/Optimism_Adapter.ts

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
import { sampleL2Gas, amountToLp, mockTreeRoot, refundProposalLiveness, bondAmount } from "./../constants";
2-
import { ethers, expect, Contract, FakeContract, SignerWithAddress, createFake, hre } from "../../utils/utils";
3-
import { getContractFactory, seedWallet, randomAddress } from "../../utils/utils";
2+
import {
3+
ethers,
4+
expect,
5+
Contract,
6+
FakeContract,
7+
SignerWithAddress,
8+
createFake,
9+
getContractFactory,
10+
seedWallet,
11+
randomAddress,
12+
} from "../../utils/utils";
413
import { hubPoolFixture, enableTokensForLP } from "../fixtures/HubPool.Fixture";
514
import { constructSingleChainTree } from "../MerkleLib.utils";
615

test/chain-adapters/Polygon_Adapter.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import { amountToLp, mockTreeRoot, refundProposalLiveness, bondAmount, mockSlowRelayRoot } from "./../constants";
2-
import { ethers, expect, Contract, FakeContract, SignerWithAddress } from "../../utils/utils";
3-
import { createFake, getContractFactory, seedWallet, randomAddress, hre } from "../../utils/utils";
2+
import {
3+
ethers,
4+
expect,
5+
Contract,
6+
FakeContract,
7+
SignerWithAddress,
8+
createFake,
9+
getContractFactory,
10+
seedWallet,
11+
randomAddress,
12+
} from "../../utils/utils";
13+
import { hre } from "../../utils/utils.hre";
414
import { hubPoolFixture, enableTokensForLP } from "../fixtures/HubPool.Fixture";
515
import { constructSingleChainTree } from "../MerkleLib.utils";
616
import { TokenRolesEnum } from "@uma/common";

test/chain-specific-spokepools/Arbitrum_SpokePool.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { mockTreeRoot, amountToReturn, amountHeldByPool, zeroAddress } from "../constants";
2-
import { ethers, expect, Contract, FakeContract, SignerWithAddress, createFake, toWei } from "../../utils/utils";
3-
import { getContractFactory, seedContract, avmL1ToL2Alias, hre } from "../../utils/utils";
2+
import {
3+
ethers,
4+
expect,
5+
Contract,
6+
FakeContract,
7+
SignerWithAddress,
8+
createFake,
9+
toWei,
10+
getContractFactory,
11+
seedContract,
12+
avmL1ToL2Alias,
13+
} from "../../utils/utils";
14+
import { hre } from "../../utils/utils.hre";
415
import { hubPoolFixture } from "../fixtures/HubPool.Fixture";
516
import { constructSingleRelayerRefundTree } from "../MerkleLib.utils";
617

test/chain-specific-spokepools/Ethereum_SpokePool.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { mockTreeRoot, amountToReturn, amountHeldByPool } from "../constants";
2-
import { ethers, expect, Contract, SignerWithAddress, hre } from "../../utils/utils";
3-
import { getContractFactory, seedContract } from "../../utils/utils";
2+
import { ethers, expect, Contract, SignerWithAddress, getContractFactory, seedContract } from "../../utils/utils";
3+
import { hre } from "../../utils/utils.hre";
44
import { hubPoolFixture } from "../fixtures/HubPool.Fixture";
55
import { constructSingleRelayerRefundTree } from "../MerkleLib.utils";
66

test/chain-specific-spokepools/Optimism_SpokePool.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
import { mockTreeRoot, amountToReturn, amountHeldByPool } from "../constants";
2-
import { ethers, expect, Contract, FakeContract, SignerWithAddress, createFake, toWei } from "../../utils/utils";
3-
import { getContractFactory, seedContract, hre } from "../../utils/utils";
2+
import {
3+
ethers,
4+
expect,
5+
Contract,
6+
FakeContract,
7+
SignerWithAddress,
8+
createFake,
9+
toWei,
10+
getContractFactory,
11+
seedContract,
12+
} from "../../utils/utils";
13+
import { hre } from "../../utils/utils.hre";
14+
415
import { hubPoolFixture } from "../fixtures/HubPool.Fixture";
516
import { constructSingleRelayerRefundTree } from "../MerkleLib.utils";
617

test/chain-specific-spokepools/Polygon_SpokePool.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import { mockTreeRoot, amountToReturn, amountHeldByPool, zeroAddress, TokenRolesEnum } from "../constants";
2-
import { ethers, expect, Contract, SignerWithAddress, getContractFactory, createFake } from "../../utils/utils";
3-
import { seedContract, toWei, randomBigNumber, seedWallet, FakeContract, hre } from "../../utils/utils";
2+
import {
3+
ethers,
4+
expect,
5+
Contract,
6+
SignerWithAddress,
7+
getContractFactory,
8+
createFake,
9+
seedContract,
10+
toWei,
11+
randomBigNumber,
12+
seedWallet,
13+
FakeContract,
14+
} from "../../utils/utils";
15+
import { hre } from "../../utils/utils.hre";
416
import { hubPoolFixture } from "../fixtures/HubPool.Fixture";
517
import { constructSingleRelayerRefundTree } from "../MerkleLib.utils";
618
import { randomBytes } from "crypto";

test/chain-specific-spokepools/Succinct_SpokePool.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ethers, expect, Contract, SignerWithAddress, getContractFactory, hre } from "../../utils/utils";
1+
import { ethers, expect, Contract, SignerWithAddress, getContractFactory } from "../../utils/utils";
2+
import { hre } from "../../utils/utils.hre";
23
import { hubPoolFixture } from "../fixtures/HubPool.Fixture";
34

45
let succinctSpokePool: Contract, timer: Contract, weth: Contract;

test/fixtures/BondToken.Fixture.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Contract, getContractFactory, hre } from "../../utils/utils";
1+
import { Contract, getContractFactory } from "../../utils/utils";
2+
import { hre } from "../../utils/utils.hre";
23
import { hubPoolFixture } from "./HubPool.Fixture";
34

45
export const bondTokenFixture = hre.deployments.createFixture(async ({ ethers }, hubPool?: Contract) => {

test/fixtures/HubPool.Fixture.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getContractFactory, randomAddress, hre, Contract, Signer } from "../../utils/utils";
1+
import { getContractFactory, randomAddress, Contract, Signer } from "../../utils/utils";
2+
import { hre } from "../../utils/utils.hre";
23
import { originChainId, bondAmount, refundProposalLiveness, finalFee } from "../constants";
34
import { repaymentChainId, finalFeeUsdc, TokenRolesEnum } from "../constants";
45
import { umaEcosystemFixture } from "./UmaEcosystem.Fixture";

test/fixtures/MerkleLib.Fixture.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Contract, getContractFactory, hre } from "../../utils/utils";
1+
import { Contract, getContractFactory } from "../../utils/utils";
2+
import { hre } from "../../utils/utils.hre";
23

34
export const merkleLibFixture: () => Promise<{ merkleLibTest: Contract }> = hre.deployments.createFixture(async () => {
45
const [signer] = await hre.ethers.getSigners();

test/fixtures/SpokePool.Fixture.ts

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import {
2-
getContractFactory,
3-
SignerWithAddress,
4-
Contract,
5-
hre,
6-
ethers,
7-
BigNumber,
8-
defaultAbiCoder,
9-
} from "../../utils/utils";
1+
import { getContractFactory, SignerWithAddress, Contract, ethers, BigNumber, defaultAbiCoder } from "../../utils/utils";
2+
import { hre } from "../../utils/utils.hre";
3+
104
import * as consts from "../constants";
115

126
export const spokePoolFixture = hre.deployments.createFixture(async ({ ethers }) => {

test/fixtures/UmaEcosystem.Fixture.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { getContractFactory, utf8ToHex, hre, Contract } from "../../utils/utils";
1+
import { getContractFactory, utf8ToHex, Contract } from "../../utils/utils";
2+
import { hre } from "../../utils/utils.hre";
23
import { refundProposalLiveness, zeroRawValue, identifier } from "../constants";
34
import { interfaceName } from "@uma/common";
45

test/gas-analytics/HubPool.RootExecution.ts

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
import { toBNWei, toBN, SignerWithAddress, seedWallet, Contract, ethers, hre, expect } from "../../utils/utils";
2-
import { getContractFactory, BigNumber, randomAddress, createRandomBytes32 } from "../../utils/utils";
1+
import {
2+
toBNWei,
3+
toBN,
4+
SignerWithAddress,
5+
seedWallet,
6+
Contract,
7+
ethers,
8+
expect,
9+
getContractFactory,
10+
BigNumber,
11+
randomAddress,
12+
createRandomBytes32,
13+
} from "../../utils/utils";
314
import { deployErc20 } from "./utils";
415
import * as consts from "../constants";
516
import { hubPoolFixture, enableTokensForLP } from "../fixtures/HubPool.Fixture";
617
import { buildPoolRebalanceLeafTree, buildPoolRebalanceLeaves, PoolRebalanceLeaf } from "../MerkleLib.utils";
718
import { MerkleTree } from "../../utils/MerkleTree";
19+
import { hre } from "../../utils/utils.hre";
820

921
require("dotenv").config();
1022

test/merkle-distributor/MerkleDistributor.ts

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
/* eslint-disable no-unused-expressions */
22

3-
import {
4-
ethers,
5-
getContractFactory,
6-
SignerWithAddress,
7-
Contract,
8-
toWei,
9-
toBN,
10-
expect,
11-
keccak256,
12-
defaultAbiCoder,
13-
} from "../../utils/utils";
3+
import { ethers, getContractFactory, SignerWithAddress, Contract, toWei, toBN, expect } from "../../utils/utils";
144
import { deployErc20 } from "../gas-analytics/utils";
155
import { MAX_UINT_VAL, MerkleTree } from "@uma/common";
166

utils/utils.hre.ts

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { getContractFactory } from "./utils";
2+
import hre from "hardhat";
3+
4+
export async function deployNewProxy(name: string, args: (number | string)[]): Promise<void> {
5+
const { run, upgrades } = hre;
6+
7+
const proxy = await upgrades.deployProxy(await getContractFactory(name, {}), args, { kind: "uups" });
8+
const instance = await proxy.deployed();
9+
console.log(`New ${name} proxy deployed @ ${instance.address}`);
10+
const implementationAddress = await upgrades.erc1967.getImplementationAddress(instance.address);
11+
console.log(`${name} implementation deployed @ ${implementationAddress}`);
12+
13+
// hardhat-upgrades overrides the `verify` task that ships with `hardhat` so that if the address passed
14+
// is a proxy, hardhat will first verify the implementation and then the proxy and also link the proxy
15+
// to the implementation's ABI on etherscan.
16+
// https://docs.openzeppelin.com/upgrades-plugins/1.x/api-hardhat-upgrades#verify
17+
await run("verify:verify", {
18+
address: instance.address,
19+
});
20+
}
21+
22+
export { hre };

0 commit comments

Comments
 (0)