Skip to content

Commit e7d312e

Browse files
authored
feat: Remove direct "hardhat" imports, update types in deploy/ scripts (#284)
* improve: Load existing HRE rather than re-instantiate The HRE should only be constructed once, and for the deploy scripts we should try to load that existing object Unfortunately we can't use mark the `hre` type as a `HardhatRuntimeEnvironment` because the `hardhat-deploy` module adds some properties to it that we want to access like `deployments` and `companionNetworks` that we want to use. * Fix type * Update utils.ts
1 parent 625db8f commit e7d312e

25 files changed

+76
-89
lines changed

deploy/001_deploy_hubpool.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { L1_ADDRESS_MAP } from "./consts";
22

3-
import "hardhat-deploy";
4-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
3+
import { DeployFunction } from "hardhat-deploy/types";
4+
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

6-
const func = async function (hre: HardhatRuntimeEnvironment) {
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
77
const { deployments, getNamedAccounts, getChainId } = hre;
88
const { deploy } = deployments;
99

deploy/002_deploy_optimism_adapter.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { L1_ADDRESS_MAP } from "./consts";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
24

3-
import "hardhat-deploy";
4-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
5-
6-
const func = async function (hre: HardhatRuntimeEnvironment) {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
76
const { deployments, getNamedAccounts, getChainId } = hre;
87
const { deploy } = deployments;
98

deploy/003_deploy_optimism_spokepool.ts

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

5-
const func = async function () {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
66
const hubPool = await hre.companionNetworks.l1.deployments.get("HubPool");
77
const chainId = await hre.getChainId();
88
console.log(`Using L1 (chainId ${chainId}) hub pool @ ${hubPool.address}`);

deploy/004_deploy_arbitrum_adapter.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { L1_ADDRESS_MAP } from "./consts";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
24

3-
import "hardhat-deploy";
4-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
5-
6-
const func = async function (hre: HardhatRuntimeEnvironment) {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
76
const { deployments, getNamedAccounts, getChainId } = hre;
87
const { deploy } = deployments;
98

deploy/005_deploy_arbitrum_spokepool.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import "hardhat-deploy";
2-
import hre from "hardhat";
1+
import { DeployFunction } from "hardhat-deploy/types";
32
import { L2_ADDRESS_MAP } from "./consts";
43
import { deployNewProxy } from "../utils";
4+
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

6-
const func = async function () {
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
77
const hubPool = await hre.companionNetworks.l1.deployments.get("HubPool");
88
const chainId = await hre.getChainId();
99
console.log(`Using L1 (chainId ${chainId}) hub pool @ ${hubPool.address}`);

deploy/006_deploy_ethereum_adapter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
1+
import { DeployFunction } from "hardhat-deploy/types";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
33

4-
const func = async function (hre: HardhatRuntimeEnvironment) {
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
55
const { deployments, getNamedAccounts } = hre;
66
const { deploy } = deployments;
77

deploy/007_deploy_ethereum_spokepool.ts

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

6-
export async function printProxyVerificationInstructions() {}
7-
8-
const func = async function () {
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
97
const hubPool = await hre.companionNetworks.l1.deployments.get("HubPool");
108
const chainId = await hre.getChainId();
119
console.log(`Using L1 (chainId ${chainId}) hub pool @ ${hubPool.address}`);

deploy/008_deploy_polygon_token_bridger_mainnet.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
3-
1+
import { DeployFunction } from "hardhat-deploy/types";
42
import { L1_ADDRESS_MAP, POLYGON_CHAIN_IDS } from "./consts";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
54

6-
const func = async function (hre: HardhatRuntimeEnvironment) {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
76
const { deployments, getNamedAccounts, getChainId } = hre;
87
const { deploy } = deployments;
98

deploy/009_deploy_polygon_adapter.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
3-
1+
import { DeployFunction } from "hardhat-deploy/types";
42
import { L1_ADDRESS_MAP } from "./consts";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
54

6-
const func = async function (hre: HardhatRuntimeEnvironment) {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
76
const { deployments, getNamedAccounts, getChainId } = hre;
87
const { deploy } = deployments;
98

deploy/010_deploy_polygon_token_bridger_polygon.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
3-
1+
import { DeployFunction } from "hardhat-deploy/types";
42
import { L1_ADDRESS_MAP } from "./consts";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
54

6-
const func = async function (hre: HardhatRuntimeEnvironment) {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
76
const { deployments, getNamedAccounts, getChainId } = hre;
87
const { deploy } = deployments;
98

deploy/011_deploy_polygon_spokepool.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import "hardhat-deploy";
2-
import hre from "hardhat";
1+
import { DeployFunction } from "hardhat-deploy/types";
32
import { L2_ADDRESS_MAP } from "./consts";
43
import { deployNewProxy } from "../utils";
4+
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

6-
const func = async function () {
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
77
const hubPool = await hre.companionNetworks.l1.deployments.get("HubPool");
88
const chainId = await hre.getChainId();
99
console.log(`Using L1 (chainId ${chainId}) hub pool @ ${hubPool.address}`);

deploy/012_deploy_boba_adapter.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
import { HardhatRuntimeEnvironment } from "hardhat/types";
12
import { L1_ADDRESS_MAP } from "./consts";
3+
import { DeployFunction } from "hardhat-deploy/types";
24

3-
import "hardhat-deploy";
4-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
5-
6-
const func = async function (hre: HardhatRuntimeEnvironment) {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
76
const { deployments, getNamedAccounts, getChainId } = hre;
87
const { deploy } = deployments;
98

deploy/013_deploy_boba_spokepool.ts

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

5-
const func = async function () {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
66
const hubPool = await hre.companionNetworks.l1.deployments.get("HubPool");
77
const chainId = await hre.getChainId();
88
console.log(`Using L1 (chainId ${chainId}) hub pool @ ${hubPool.address}`);

deploy/014_deploy_config_store.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
1+
import { DeployFunction } from "hardhat-deploy/types";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
33

4-
const func = async function (hre: HardhatRuntimeEnvironment) {
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
55
const { deployments, getNamedAccounts } = hre;
66
const { deploy } = deployments;
77

deploy/015_deploy_zksync_adapter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
1+
import { DeployFunction } from "hardhat-deploy/types";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
33

4-
const func = async function (hre: HardhatRuntimeEnvironment) {
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
55
const { deployments, getNamedAccounts } = hre;
66

77
const { deploy } = deployments;

deploy/016_deploy_zksync_spokepool.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import "hardhat-deploy";
2-
import hre from "hardhat";
1+
import { DeployFunction } from "hardhat-deploy/types";
32
import { L2_ADDRESS_MAP } from "./consts";
43
import { deployNewProxy } from "../utils";
4+
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

6-
const func = async function () {
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
77
const hubPool = await hre.companionNetworks.l1.deployments.get("HubPool");
88
const chainId = await hre.getChainId();
99
console.log(`Using L1 (chainId ${chainId}) hub pool @ ${hubPool.address}`);

deploy/017_deploy_ethereum_merkle_distributor.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
1+
import { DeployFunction } from "hardhat-deploy/types";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
33

4-
const func = async function (hre: HardhatRuntimeEnvironment) {
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
55
const { deployments, getNamedAccounts } = hre;
66
const { deploy } = deployments;
77

deploy/018_deploy_arbitrum_rescueadapter.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { L1_ADDRESS_MAP } from "./consts";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
24

3-
import "hardhat-deploy";
4-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
5-
6-
const func = async function (hre: HardhatRuntimeEnvironment) {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
76
const { deployments, getNamedAccounts, getChainId } = hre;
87
const { deploy } = deployments;
98

deploy/019_deploy_bond_token.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
1+
import { DeployFunction } from "hardhat-deploy/types";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
33

4-
const func = async function (hre: HardhatRuntimeEnvironment) {
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
55
const { deployments, getNamedAccounts } = hre;
66
const { deployer } = await getNamedAccounts();
77

deploy/020_deploy_arbitrum_sendtoken_adapter.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { L1_ADDRESS_MAP } from "./consts";
2+
import { DeployFunction } from "hardhat-deploy/types";
3+
import { HardhatRuntimeEnvironment } from "hardhat/types";
24

3-
import "hardhat-deploy";
4-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
5-
6-
const func = async function (hre: HardhatRuntimeEnvironment) {
5+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
76
const { deployments, getNamedAccounts, getChainId } = hre;
87
const { deploy } = deployments;
98

deploy/021_deploy_erc1155.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import "hardhat-deploy";
2-
import { HardhatRuntimeEnvironment } from "hardhat/types/runtime";
1+
import { DeployFunction } from "hardhat-deploy/types";
2+
import { HardhatRuntimeEnvironment } from "hardhat/types";
33

4-
const func = async function (hre: HardhatRuntimeEnvironment) {
4+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
55
const { deployments, getNamedAccounts } = hre;
66
const { deploy } = deployments;
77

deploy/022_upgrade_spokepool.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import "hardhat-deploy";
2-
import hre from "hardhat";
1+
import { DeployFunction } from "hardhat-deploy/types";
32
import { getContractFactory } from "../utils";
43
import * as deployments from "../deployments/deployments.json";
4+
import { HardhatRuntimeEnvironment } from "hardhat/types";
55

6-
const func = async function () {
6+
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
77
const { upgrades, run, getChainId, getNamedAccounts } = hre;
88
const { deployer } = await getNamedAccounts();
99

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@across-protocol/contracts-v2",
3-
"version": "2.2.0",
3+
"version": "2.2.1",
44
"author": "UMA Team",
55
"license": "AGPL-3.0-only",
66
"repository": {

test/fixtures/MerkleLib.Fixture.ts

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { Contract, getContractFactory } from "../../utils/utils";
2-
import hre from "hardhat";
1+
import { Contract, getContractFactory, hre } from "../../utils/utils";
32

4-
export const merkleLibFixture: () => Promise<{ merkleLibTest: Contract }> = hre.deployments.createFixture(
5-
async ({ deployments }) => {
6-
const [signer] = await hre.ethers.getSigners();
7-
const merkleLibTest = await (await getContractFactory("MerkleLibTest", { signer })).deploy();
8-
return { merkleLibTest };
9-
}
10-
);
3+
export const merkleLibFixture: () => Promise<{ merkleLibTest: Contract }> = hre.deployments.createFixture(async () => {
4+
const [signer] = await hre.ethers.getSigners();
5+
const merkleLibTest = await (await getContractFactory("MerkleLibTest", { signer })).deploy();
6+
return { merkleLibTest };
7+
});

utils/utils.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import * as chai from "chai";
55
import { getBytecode, getAbi } from "@uma/contracts-node";
66
import * as optimismContracts from "@eth-optimism/contracts";
77
import { smock, FakeContract } from "@defi-wonderland/smock";
8-
chai.use(smock.matchers);
8+
import { FactoryOptions } from "hardhat/types";
99
import hre from "hardhat";
1010
import { ethers } from "hardhat";
1111
import { BigNumber, Signer, Contract, ContractFactory } from "ethers";
12-
import { FactoryOptions } from "hardhat/types";
13-
1412
export { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
1513

14+
chai.use(smock.matchers);
15+
1616
function isFactoryOptions(signerOrFactoryOptions: Signer | FactoryOptions): signerOrFactoryOptions is FactoryOptions {
1717
return "signer" in signerOrFactoryOptions || "libraries" in signerOrFactoryOptions;
1818
}

0 commit comments

Comments
 (0)