Skip to content

Commit 299f956

Browse files
committed
Make type fixes
1 parent c8878cd commit 299f956

File tree

85 files changed

+2292
-4074
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2292
-4074
lines changed

.circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
command: yarn chain
5050
background: true
5151
- run:
52-
name: Buidler Test
52+
name: Hardhat Test
5353
command: yarn test
5454

5555
coverage:

.spec.template.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "module-alias/register";
22
import { BigNumber } from "ethers/utils";
3-
import { ethers } from "@nomiclabs/buidler";
3+
import { ethers } from "hardhat";
44

55
import { Address, Account } from "@utils/types";
66
import {} from "@utils/constants";

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
# Set Protocol V2 Contract Repository
99

1010
## Contracts
11-
[Set Protocol](https://setprotocol.com/) is a specification for tokenized asset management strategies on the ethereum blockchain written in the Solidity programming language. We use [Buidler](https://buidler.dev/) as a development environment for compiling, testing, and deploying our contracts.
11+
[Set Protocol](https://setprotocol.com/) is a specification for tokenized asset management strategies on the ethereum blockchain written in the Solidity programming language. We use [Hardhat](https://hardhat.org/) as a development environment for compiling, testing, and deploying our contracts.
1212

1313
## Development
1414

15-
To use console.log during Solidity development, do `import @nomiclabs/buidler/console.sol`
15+
To use console.log during Solidity development, follow the [guides](https://hardhat.org/guides/hardhat-console.html).
1616

1717
## Available Functionality
1818

19-
### Run Buidler EVM
19+
### Run Hardhat EVM
2020

2121
`yarn chain`
2222

contracts/protocol-viewers/SetTokenViewer.sol

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pragma experimental "ABIEncoderV2";
2020

2121

2222
import { ISetToken } from "../interfaces/ISetToken.sol";
23-
import "@nomiclabs/buidler/console.sol";
2423

2524

2625
/**

external/contracts/balancer/BRegistry.sol

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
pragma solidity 0.5.12;
22

3-
import "@nomiclabs/buidler/console.sol";
4-
53
import "@openzeppelin/contracts/math/Math.sol";
64
import "@openzeppelin/contracts/math/SafeMath.sol";
75
import "@openzeppelin/contracts/utils/EnumerableSet.sol";

buidler.config.ts renamed to hardhat.config.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
require("dotenv").config();
22

3-
import { BuidlerConfig, usePlugin, internalTask } from "@nomiclabs/buidler/config";
4-
import { TASK_COMPILE_RUN_COMPILER } from "@nomiclabs/buidler/builtin-tasks/task-names";
3+
import { HardhatUserConfig, internalTask } from "hardhat/config";
4+
import { TASK_COMPILE_SOLIDITY_COMPILE } from "hardhat/builtin-tasks/task-names";
55
import { execSync } from "child_process";
66
import { privateKeys } from "./utils/wallets";
77

8-
usePlugin("@nomiclabs/buidler-waffle");
9-
usePlugin("buidler-typechain");
10-
usePlugin("solidity-coverage");
11-
usePlugin("buidler-deploy");
8+
import "@nomiclabs/hardhat-waffle";
9+
import "hardhat-typechain";
10+
import "solidity-coverage";
11+
import "hardhat-deploy";
1212

13-
internalTask(TASK_COMPILE_RUN_COMPILER).setAction(setupNativeSolc);
13+
internalTask(TASK_COMPILE_SOLIDITY_COMPILE).setAction(setupNativeSolc);
1414

15-
const config: BuidlerConfig = {
16-
solc: {
15+
const config: HardhatUserConfig = {
16+
solidity: {
1717
version: "0.6.10",
18-
optimizer: { enabled: true, runs: 200 },
18+
settings: {
19+
optimizer: { enabled: true, runs: 200 },
20+
},
1921
},
2022
namedAccounts: {
2123
deployer: 0,
2224
},
2325
networks: {
24-
buidlerevm: {
26+
hardhat: {
2527
hardfork: "istanbul",
26-
accounts: getBuidlerPrivateKeys(),
27-
timeout: 100000,
28+
accounts: getHardhatPrivateKeys(),
2829
},
2930
localhost: {
3031
url: "http://127.0.0.1:8545",
@@ -53,14 +54,14 @@ const config: BuidlerConfig = {
5354
},
5455
typechain: {
5556
outDir: "typechain",
56-
target: "ethers-v4",
57+
target: "ethers-v5",
5758
},
5859
mocha: {
5960
timeout: 100000,
6061
}
6162
};
6263

63-
function getBuidlerPrivateKeys() {
64+
function getHardhatPrivateKeys() {
6465
return privateKeys.map(key => {
6566
const ONE_MILLION_ETH = "1000000000000000000000000";
6667
return {
@@ -81,7 +82,7 @@ async function setupNativeSolc({ input }, { config }, runSuper) {
8182

8283
console.log("Output", solcVersionOutput);
8384

84-
if (!solcVersionOutput.includes(config.solc.version)) {
85+
if (!solcVersionOutput.includes(config.solidity.version)) {
8586
console.log(`Using solcjs`);
8687
return runSuper();
8788
}

package.json

+20-17
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,28 @@
1515
"tsconfig.json"
1616
],
1717
"scripts": {
18-
"build": "yarn compile && yarn copy-external-abi && yarn typechain && yarn fix-typechain && yarn transpile-dist",
19-
"chain": "npx buidler node --no-deploy",
18+
"build": "yarn compile && yarn patch-hardhat-typechain && yarn typechain && yarn fix-typechain && yarn transpile-dist",
19+
"chain": "npx hardhat node --no-deploy",
2020
"clean": "rm -f coverage.json; rm -rf .coverage_cache; rm -rf .coverage_contracts; rm -rf cache; rm -rf coverage; rm -rf typechain; rm -rf artifacts",
21-
"compile": "npx buidler compile",
21+
"compile": "npx hardhat compile",
2222
"copy-external-abi": "cp -r external/abi/**/* artifacts",
23-
"coverage": "yarn clean && yarn build && npx buidler coverage --temp artifacts --network coverage",
24-
"etherscan:verify": "buidler --network kovan etherscan-verify --solc-input --license 'None'",
23+
"coverage": "yarn clean && yarn build && npx hardhat coverage --temp artifacts --network coverage",
24+
"etherscan:verify": "hardhat --network kovan etherscan-verify --solc-input --license 'None'",
2525
"fix-typechain": "node scripts/fix-typechain.js && yarn rename-extensions",
2626
"flatten": "npx waffle flatten",
2727
"lint": "yarn run lint-sol && yarn run lint-ts",
2828
"lint-sol": "solhint 'contracts/**/*.sol'",
2929
"lint-ts": "tslint -c tslint.json -p tsconfig.json --fix",
30+
"patch-hardhat-typechain": "node scripts/patch-hardhat-typechain.js",
3031
"precommit": "lint-staged",
3132
"prepare": "yarn build",
3233
"prepack": "if [[ \"$(basename \"$PWD\")\" == \"set-protocol-v2-contracts\" ]]; then echo \"CANNOT PUBLISH FROM THIS REPO\"; exit 1; fi;",
3334
"rename-extensions": "for f in typechain/*.d.ts; do mv -- \"$f\" \"${f%.d.ts}.ts\"; done",
34-
"test": "npx buidler test --network localhost",
35+
"test": "npx hardhat test --network localhost",
3536
"test:clean": "yarn clean && yarn build && yarn test",
3637
"transpile": "tsc",
3738
"transpile-dist": "tsc -p tsconfig.dist.json",
38-
"typechain": "npx buidler typechain"
39+
"typechain": "npx hardhat typechain"
3940
},
4041
"repository": {
4142
"type": "git",
@@ -45,8 +46,12 @@
4546
"license": "MIT",
4647
"homepage": "https://github.com/SetProtocol",
4748
"devDependencies": {
49+
"@ethersproject/bignumber": "^5.0.12",
50+
"@ethersproject/providers": "^5.0.17",
51+
"@nomiclabs/hardhat-ethers": "^2.0.1",
52+
"@nomiclabs/hardhat-waffle": "^2.0.1",
4853
"@openzeppelin/contracts": "^3.1.0",
49-
"@typechain/ethers-v4": "^1.0.0",
54+
"@typechain/ethers-v5": "^5.0.0",
5055
"@typechain/truffle-v4": "^2.0.2",
5156
"@typechain/truffle-v5": "^2.0.2",
5257
"@typechain/web3-v1": "^1.0.0",
@@ -55,34 +60,32 @@
5560
"@types/lodash": "^4.14.86",
5661
"@types/mocha": "^7.0.2",
5762
"@types/node": "^14.0.5",
58-
"buidler-deploy": "^0.5.14",
5963
"chai": "^4.2.0",
6064
"coveralls": "^3.0.1",
6165
"dotenv": "^8.2.0",
6266
"ethereum-waffle": "^2.5.1",
63-
"ethers": "^4.0.47",
67+
"ethers": "^5.0.24",
68+
"hardhat": "^2.0.6",
69+
"hardhat-deploy": "^0.7.0-beta.39",
70+
"hardhat-typechain": "^0.3.4",
6471
"husky": "^4.2.5",
6572
"lint-staged": "^10.2.11",
6673
"lodash": "^4.17.4",
6774
"solc": "^0.6.10",
6875
"solhint": "^3.1.0",
69-
"solidity-coverage": "^0.7.5",
70-
"ts-generator": "0.0.8",
76+
"solidity-coverage": "^0.7.13",
77+
"ts-generator": "^0.1.1",
7178
"ts-node": "^8.10.1",
7279
"tslint": "^5.8.0",
7380
"tslint-eslint-rules": "^5.3.1",
7481
"typescript": "^3.9.3",
7582
"web3": "^1.2.9"
7683
},
7784
"dependencies": {
78-
"@nomiclabs/buidler": "^1.3.4",
79-
"@nomiclabs/buidler-ethers": "^1.3.3",
80-
"@nomiclabs/buidler-waffle": "^1.3.3",
81-
"buidler-typechain": "0.1.1",
8285
"fs-extra": "^5.0.0",
8386
"module-alias": "^2.2.2",
8487
"replace-in-file": "^6.1.0",
85-
"typechain": "^2.0.0"
88+
"typechain": "^4.0.1"
8689
},
8790
"_moduleAliases": {
8891
"@utils": "utils",

scripts/fix-typechain.js

+132-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
const replace = require('replace-in-file');
22

3-
const options = {
3+
let changedFiles;
4+
5+
// Step 1: Replace all exports of classes to be declarations and to change to regular .ts files
6+
const options1 = {
47
//Glob(s)
58
files: [
69
'./typechain/*.d.ts',
@@ -12,9 +15,135 @@ const options = {
1215
};
1316

1417
try {
15-
let changedFiles = replace.sync(options);
16-
console.log('Modified files:', changedFiles.map(f => f.file.toString()).join(', '));
18+
changedFiles = replace.sync(options1);
19+
console.log('Step 1. Typechain fixing modified files:', changedFiles.map(f => f.file.toString()).join(', '));
1720
}
1821
catch (error) {
1922
console.error('Error occurred:', error);
2023
}
24+
25+
// Step 2: Replace all ethers.utils.Interface with just Interface
26+
const options2 = {
27+
//Glob(s)
28+
files: [
29+
'./typechain/*.ts',
30+
],
31+
32+
//Replacement to make (string or regex)
33+
from: /ethers\.utils\.Interface/g,
34+
to: 'Interface',
35+
};
36+
37+
try {
38+
changedFiles = replace.sync(options2);
39+
console.log('Step 2. Typechain fixing modified files:', changedFiles.map(f => f.file.toString()).join(', '));
40+
}
41+
catch (error) {
42+
console.error('Error occurred:', error);
43+
}
44+
45+
// Step 3: Fix import of Interface to come from @ethersproject/abi
46+
const options3 = {
47+
//Glob(s)
48+
files: [
49+
'./typechain/*.ts',
50+
],
51+
52+
//Replacement to make (string or regex)
53+
from: /import { FunctionFragment, EventFragment, Result } from \"@ethersproject\/abi\"/g,
54+
to: 'import { FunctionFragment, EventFragment, Result, Interface } from "@ethersproject/abi"',
55+
};
56+
57+
58+
try {
59+
changedFiles = replace.sync(options3);
60+
console.log('Step 3. Typechain fixing modified files:', changedFiles.map(f => f.file.toString()).join(', '));
61+
}
62+
catch (error) {
63+
console.error('Error occurred:', error);
64+
}
65+
66+
// Step 4: Fix import of Provider and TransactionRequest to come from @ethersproject/providers
67+
const options4 = {
68+
//Glob(s)
69+
files: [
70+
'./typechain/*.ts',
71+
],
72+
73+
//Replacement to make (string or regex)
74+
from: /import { Provider } from \"@utils\/test\/node_modules\/ethers\/providers\"/g,
75+
to: 'import { Provider, TransactionRequest } from "@ethersproject/providers"',
76+
};
77+
78+
79+
try {
80+
changedFiles = replace.sync(options4);
81+
console.log('Step 4. Typechain fixing modified files:', changedFiles.map(f => f.file.toString()).join(', '));
82+
}
83+
catch (error) {
84+
console.error('Error occurred:', error);
85+
}
86+
87+
// Step 5: Fix import of TransactionOverrides
88+
const options5a = {
89+
//Glob(s)
90+
files: [
91+
'./typechain/*.ts',
92+
],
93+
94+
//Replacement to make (string or regex)
95+
from: /import { TransactionOverrides } from \".\"/g,
96+
to: 'import { CallOverrides } from "@ethersproject/contracts"',
97+
};
98+
const options5b = {
99+
//Glob(s)
100+
files: [
101+
'./typechain/*.ts',
102+
],
103+
104+
//Replacement to make (string or regex)
105+
from: /TransactionOverrides/g,
106+
to: 'CallOverrides',
107+
};
108+
109+
110+
try {
111+
changedFiles = replace.sync(options5a);
112+
changedFiles = replace.sync(options5b);
113+
console.log('Step 5. Typechain fixing modified files:', changedFiles.map(f => f.file.toString()).join(', '));
114+
}
115+
catch (error) {
116+
console.error('Error occurred:', error);
117+
}
118+
119+
// Step 6: Fix import of UnsignedTransaction
120+
const options6a = {
121+
//Glob(s)
122+
files: [
123+
'./typechain/*.ts',
124+
],
125+
126+
//Replacement to make (string or regex)
127+
from: /import { UnsignedTransaction } from \"ethers\/utils\/transaction\"/g,
128+
to: '',
129+
};
130+
const options6b = {
131+
//Glob(s)
132+
files: [
133+
'./typechain/*.ts',
134+
],
135+
136+
//Replacement to make (string or regex)
137+
from: /UnsignedTransaction/g,
138+
to: 'TransactionRequest',
139+
};
140+
141+
142+
try {
143+
changedFiles = replace.sync(options6a);
144+
changedFiles = replace.sync(options6b);
145+
console.log('Step 6. Typechain fixing modified files:', changedFiles.map(f => f.file.toString()).join(', '));
146+
}
147+
catch (error) {
148+
console.error('Error occurred:', error);
149+
}

scripts/patch-hardhat-typechain.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const replace = require('replace-in-file');
2+
3+
let changedFiles;
4+
5+
// Step 1: Replace all exports of classes to be declarations and to change to regular .ts files
6+
const options1 = {
7+
//Glob(s)
8+
files: [
9+
'./node_modules/hardhat-typechain/dist/src/index.js',
10+
],
11+
12+
//Replacement to make (string or regex)
13+
from: /\$\{config.paths.artifacts\}\/\!\(build-info\)\//g,
14+
to: '{${config.paths.artifacts},external}/!(build-info)/',
15+
};
16+
17+
try {
18+
changedFiles = replace.sync(options1);
19+
console.log('Patching hardhat-typechain file.');
20+
}
21+
catch (error) {
22+
console.error('Error occurred:', error);
23+
}

0 commit comments

Comments
 (0)