-
Notifications
You must be signed in to change notification settings - Fork 32
/
forgeScriptRun.js
executable file
·73 lines (68 loc) · 2 KB
/
forgeScriptRun.js
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
#!/usr/bin/env node
const fs = require('fs')
const {
readChainSpecificOptions,
readChainVerificationOptions,
logWallet,
isVerifierEnabled,
} = require('./utils/chain.js')
const {
createDeploymentDirs,
getNewDeployments,
getNewDeploymentReceipts,
saveNewDeployment,
} = require('./utils/deployments.js')
const { loadEnv } = require('./utils/env.js')
const { forgeScript } = require('./utils/forge.js')
const { logInfo } = require('./utils/logger.js')
const {
parseCommandLineArgs,
isBroadcasted,
addVerifyIfNotPresent,
addOptions,
} = require('./utils/options.js')
const { assertCondition } = require('./utils/utils.js')
const { readWalletOptions } = require('./utils/wallet.js')
loadEnv()
const { positionalArgs, options } = parseCommandLineArgs({
requiredArgsCount: 3,
usage:
'Usage: "npx fsr <path-to-script> <chain-name> <wallet-name> [<options>]"',
})
const [scriptFN, chainName, walletName] = positionalArgs
assertCondition(
fs.existsSync(scriptFN),
`Script file ${scriptFN} does not exist`
)
// Check if this script is being broadcasted
const isBroadcast = isBroadcasted(options)
createDeploymentDirs(chainName)
logWallet(chainName, walletName)
let forgeOptions = addOptions(
`-f ${chainName}`,
readWalletOptions(walletName, isBroadcast)
)
forgeOptions = addOptions(forgeOptions, readChainSpecificOptions(chainName))
forgeOptions = addOptions(forgeOptions, options)
if (isBroadcast && isVerifierEnabled(chainName)) {
forgeOptions = addOptions(
forgeOptions,
readChainVerificationOptions(chainName)
)
forgeOptions = addVerifyIfNotPresent(forgeOptions)
}
const currentTimestamp = Date.now()
forgeScript(scriptFN, forgeOptions)
const newDeployments = getNewDeployments(chainName, currentTimestamp)
if (newDeployments.length === 0) {
logInfo('No new deployments found')
process.exit(0)
}
const newReceipts = getNewDeploymentReceipts(
chainName,
scriptFN,
currentTimestamp
)
newDeployments.forEach((contractAlias) =>
saveNewDeployment(chainName, contractAlias, newReceipts)
)