-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardhat.config.ts
99 lines (91 loc) · 2.39 KB
/
hardhat.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import "@nomiclabs/hardhat-ethers";
import dotenv from "dotenv";
import { task, types } from "hardhat/config";
import type { HttpNetworkUserConfig } from "hardhat/types";
import yargs from "yargs";
import { makeTrade } from "./src/make_trade";
const argv = yargs
.option("network", {
type: "string",
default: "rinkeby",
})
.help(false)
.version(false)
.parseSync();
// Load environment variables.
dotenv.config();
const { INFURA_KEY, MNEMONIC, PK, NODE_URL } = process.env;
const DEFAULT_MNEMONIC =
"candy maple cake sugar pudding cream honey rich smooth crumble sweet treat";
const sharedNetworkConfig: HttpNetworkUserConfig = {};
if (PK) {
sharedNetworkConfig.accounts = [PK];
} else {
sharedNetworkConfig.accounts = {
mnemonic: MNEMONIC || DEFAULT_MNEMONIC,
};
}
if (
["rinkeby", "mainnet"].includes(argv.network) &&
NODE_URL === undefined &&
INFURA_KEY === undefined
) {
throw new Error(
`Could not find Infura key in env, unable to connect to network ${argv.network}`
);
}
task("trade", "Makes a random trade on GPv2 given the users balances")
.addOptionalParam(
"tokenListUrl",
"The token-list to use to identify tradable tokens"
)
.addOptionalParam(
"acceptableSlippageBps",
"The normal slippage threshold for a standard trade in bps",
100,
types.int
)
.addOptionalParam(
"apiUrl",
"The base API URL to use for requests (defaults to staging on the current network)"
)
.addOptionalParam(
"maxSlippageBps",
"If no trades are possible with acceptable slippage, it tries to trade back to a good state unless the trade exceeds this slippage threshold in bps",
1000,
types.int
)
.setAction(
async (
{ tokenListUrl, apiUrl, maxSlippageBps, acceptableSlippageBps },
hardhatRuntime
) => {
await makeTrade(
apiUrl,
tokenListUrl,
acceptableSlippageBps,
maxSlippageBps,
hardhatRuntime
);
}
);
export default {
solidity: "0.7.3",
networks: {
mainnet: {
...sharedNetworkConfig,
chainId: 1,
url: NODE_URL || `https://mainnet.infura.io/v3/${INFURA_KEY}`,
},
rinkeby: {
...sharedNetworkConfig,
chainId: 4,
url: NODE_URL || `https://rinkeby.infura.io/v3/${INFURA_KEY}`,
},
xdai: {
...sharedNetworkConfig,
chainId: 100,
url: NODE_URL || "https://rpc.gnosischain.com",
},
},
};