-
Notifications
You must be signed in to change notification settings - Fork 1
/
hardhat.config.ts
157 lines (144 loc) · 6.26 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import * as dotenv from "dotenv";
import { HardhatUserConfig, task, subtask } from "hardhat/config";
import { TASK_CLEAN, TASK_COMPILE_SOLIDITY_COMPILE_JOBS, TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS } from "hardhat/builtin-tasks/task-names";
import "@nomiclabs/hardhat-etherscan";
import "@nomiclabs/hardhat-waffle";
import "hardhat-gas-reporter";
import "solidity-coverage";
import "hardhat-abi-exporter";
import 'hardhat-contract-sizer'
import { promise as glob } from 'glob-promise'
import shell, { ShellString } from 'shelljs'
dotenv.config();
subtask(TASK_COMPILE_SOLIDITY_GET_SOURCE_PATHS)
.setAction(async (_: any, __: any, runSuper: any) => {
const paths = (await runSuper()).filter((path: string) => {
return !(path.includes('spells/'))
});
return paths;
});
async function makeTypes(subfolder: string) {
const temp = '.temp'
shell.mkdir('-p', temp)
const files = await glob(`artifacts/contracts/${subfolder}/**/+([a-zA-Z0-9_]).json`)
files.forEach(file => {
shell.cp(file, `${temp}/`)
})
shell.exec(`npx typechain --target ethers-v5 --out-dir typechain/${subfolder} ${temp}/*`)
shell.rm('-rf', temp)
}
subtask(TASK_COMPILE_SOLIDITY_COMPILE_JOBS).setAction(
async (taskArgs, { run }, runSuper) => {
const compileSolOutput = await runSuper(taskArgs)
if(compileSolOutput.artifactsEmittedPerJob.length > 0) {
await makeTypes('core')
await makeTypes('interfaces/codex')
await makeTypes('interfaces/core')
await makeTypes('library')
}
return compileSolOutput
},
)
task(TASK_CLEAN,
async ({ global }: { global: boolean }, { config }, runSuper) => {
if (global) {
return
}
shell.rm('-rf', './typechain')
await runSuper()
},
)
// This is a sample Hardhat task. To learn how to create your own go to
// https://hardhat.org/guides/create-task.html
task("accounts", "Prints the list of accounts", async (taskArgs, hre) => {
const accounts = await hre.ethers.getSigners();
for (const account of accounts) {
console.log(account.address);
}
});
function makeInterface(subfolder: string, abiPath: string, interfaceName: string) {
shell.mkdir('-p', `contracts/interfaces/${subfolder}`)
const flatJson = JSON.stringify(JSON.parse(shell.cat(`.abis/contracts/${subfolder}/${abiPath}`)))
new ShellString(flatJson).exec(`npx abi-to-sol ${interfaceName}`).to(`contracts/interfaces/${subfolder}/${interfaceName}.sol`)
}
task('rarity-interfaces', 'Generates interfaces for Rarity contracts').setAction(async () => {
makeInterface('core', 'attributes.sol/rarity_attributes.json', 'IRarityAttributes')
makeInterface('core', 'base.sol/codex.json', 'IRarityBase')
makeInterface('core', 'feats.sol/rarity_feats.json', 'IRarityFeats')
makeInterface('core', 'gold.sol/rarity_gold.json', 'IRarityGold')
makeInterface('core', 'namesv2.sol/rarity_names.json', 'IRarityNames2')
makeInterface('core', 'rarity_crafting_skills.sol/rarity_crafting_skills.json', 'IRarityCraftingSkills')
makeInterface('core', 'rarity_crafting_common.sol/rarity_crafting.json', 'IRarityCommonCrafting')
makeInterface('core', 'rarity_crafting_masterwork_projects.sol/rarity_masterwork_projects.json', 'IRarityMasterworkProjects')
makeInterface('core', 'rarity_crafting_masterwork_items.sol/rarity_masterwork_items.json', 'IRarityMasterworkItems')
makeInterface('core', 'rarity_crafting-materials-1.sol/rarity_crafting_materials.json', 'IRarityCraftingMaterials')
makeInterface('core', 'rarity_crafting-materials-2.sol/rarity_crafting_materials_2.json', 'IRarityCraftingMaterials2')
makeInterface('core', 'rarity_equipment_2.sol/rarity_equipment_2.json', 'IRarityEquipment2')
makeInterface('core', 'rarity_adventure_2.sol/rarity_adventure_2.json', 'IRarityAdventure2')
makeInterface('core', 'rarity.sol/rarity.json', 'IRarity')
makeInterface('core', 'skills.sol/rarity_skills.json', 'IRaritySkills')
makeInterface('core', 'wRGLD.sol/wrapped_rarity_gold.json', 'IRarityWGold')
makeInterface('codex', 'codex-base-random-2.sol/codex.json', 'IRarityCodexBaseRandom2')
makeInterface('codex', 'codex-base-random.sol/codex.json', 'IRarityCodexBaseRandom')
makeInterface('codex', 'codex-class-skills.sol/codex.json', 'IRarityCodexClassSkills')
makeInterface('codex', 'codex-conditions.sol/codex.json', 'IRarityCodexConditions')
makeInterface('codex', 'codex-feats-1.sol/codex.json', 'IRarityCodexFeats1')
makeInterface('codex', 'codex-feats-2.sol/codex.json', 'IRarityCodexFeats2')
makeInterface('codex', 'codex-gambits.sol/gambits.json', 'IRarityCodexGambits')
makeInterface('codex', 'codex-items-armor-2.sol/codex.json', 'IRarityCodexCommonArmor')
makeInterface('codex', 'codex-items-armor-masterwork.sol/codex.json', 'IRarityCodexMasterworkArmor')
makeInterface('codex', 'codex-items-goods.sol/codex.json', 'IRarityCodexCommonGoods')
makeInterface('codex', 'codex-items-tools.sol/codex.json', 'IRarityCodexCommonTools')
makeInterface('codex', 'codex-items-tools-masterwork.sol/codex.json', 'IRarityCodexMasterworkTools')
makeInterface('codex', 'codex-items-weapons-2.sol/codex.json', 'IRarityCodexCommonWeapons')
makeInterface('codex', 'codex-items-weapons-masterwork.sol/codex.json', 'IRarityCodexMasterworkWeapons')
makeInterface('codex', 'codex-skills.sol/codex.json', 'IRarityCodexSkills')
makeInterface('codex', 'codex-crafting-skills.sol/codex.json', 'IRarityCodexCraftingSkills')
})
// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more
const config: HardhatUserConfig = {
solidity: {
version: "0.8.7",
settings: {
outputSelection: {
"*": {
"*": ["storageLayout"]
}
},
optimizer: {
enabled: true,
runs: 200,
},
}
},
paths: {
sources: "./contracts"
},
networks: {
hardhat: {
loggingEnabled: false,
allowUnlimitedContractSize: true,
forking: {
url: process.env.FTMRPC || "https://rpc.ankr.com/fantom"
}
},
mainnet: {
url: "https://rpc.ankr.com/fantom",
accounts: [process.env.PRIVATE_KEY || ""]
}
},
gasReporter: {
enabled: process.env.REPORT_GAS === "true",
currency: "USD",
},
etherscan: {
apiKey: process.env.FTMSCAN_API_KEY,
},
abiExporter: {
path: '.abis',
runOnCompile: true,
clear: true
}
};
export default config;