-
Notifications
You must be signed in to change notification settings - Fork 11
/
hardhat.utils.ts
29 lines (24 loc) · 1.02 KB
/
hardhat.utils.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
// tslint:disable: no-implicit-dependencies
import { join } from 'path'
import { readJSON, writeJSON, ensureDir } from 'fs-extra'
export const cache = join(__dirname, 'cache')
export const artifacts = join(__dirname, 'artifacts')
export const tests = join(__dirname, 'src', 'tests')
export const sources = join(__dirname, 'src', 'contracts')
export const deployments = join(__dirname, 'deployments')
export async function loadArtifact(sources: string, artifacts: string, name: string): Promise<any> {
const projectRoot = __dirname
const pathToContracts = sources.replace(projectRoot, '')
return readJSON(join(artifacts, pathToContracts, `${name}.sol`, `${name}.json`))
}
export async function saveDeployment(name: string, address: string): Promise<string> {
await ensureDir(deployments)
const filePath = join(deployments, `${name}.json`)
await writeJSON(filePath, {
address
})
return filePath
}
export async function loadDeployment(name: string): Promise<any> {
return readJSON(join(deployments, `${name}.json`))
}