-
Notifications
You must be signed in to change notification settings - Fork 4
/
ops.js
93 lines (87 loc) · 3.91 KB
/
ops.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import SNIP20Contract from '@hackbg/snip20'
import MGMTContract from './schema'
import RPTContract from './schema'
import { taskmaster } from '@hackbg/fadroma'
import { resolve, dirname, fileURLToPath } from '@hackbg/fadroma/js/sys.js'
import { pull } from '@hackbg/fadroma/js/net.js'
export default async function deploy ({
task = taskmaster(),
builder = new SecretNetwork.Builder(),
initMsgs
}) {
return await task('build, upload, and initialize contracts', async () => {
const binaries = await build({ task, builder })
const receipts = await upload({ task, builder, binaries })
const contracts = await initialize({ task, builder, initMsgs })
})
}
export async function build ({
task = taskmaster(),
workspace = resolve(dirname(fileURLToPath(import.meta.url))),
outputDir = resolve(workspace, 'artifacts'),
builder = new SecretNetwork.Builder(),
} = {}) {
await pull('enigmampc/secret-contract-optimizer:latest')
const binaries = {}
await task.parallel('build project',
task('build token', async () => {
binaries.TOKEN = await builder.build({outputDir, workspace, crate: 'snip20-reference-impl'})
}),
task('build mgmt', async () => {
binaries.MGMT = await builder.build({outputDir, workspace, crate: 'sienna-mgmt'})
}),
task('build rpt', async () => {
binaries.RPT = await builder.build({outputDir, workspace, crate: 'sienna-rpt'})
})
)
return binaries
}
export async function upload ({
task = taskmaster(),
builder = new SecretNetwork.Builder(),
binaries
} = {}) {
const receipts = {}
await task('upload token', async () => {
receipts.TOKEN = await builder.uploadCached(binaries.TOKEN)
console.log(`⚖️ compressed size ${receipts.TOKEN.compressedSize} bytes`)
})
await task('upload mgmt', async () => {
receipts.MGMT = await builder.uploadCached(binaries.MGMT)
console.log(`⚖️ compressed size ${receipts.MGMT.compressedSize} bytes`)
})
await task('upload rpt', async () => {
receipts.RPT = await builder.uploadCached(binaries.RPT)
console.log(`⚖️ compressed size ${receipts.RPT.compressedSize} bytes`)
})
return receipts
}
export async function initialize ({
task = taskmaster(),
agent,
receipts,
inits
}) {
const contracts = {}
const initTXs = {}
await task('initialize token', async report => {
const {codeId} = receipts.TOKEN
contracts.TOKEN = new SNIP20Contract({ agent, codeId })
report(await contracts.TOKEN.init(inits.TOKEN))
})
await task('initialize mgmt', async report => {
const {codeId} = receipts.MGMT
inits.MGMT.initMsg.token = [contracts.TOKEN.address, contracts.TOKEN.codeHash]
contracts.MGMT = new MGMTContract({ agent, codeId })
report(await contracts.MGMT.init(inits.MGMT))
})
await task('initialize rpt', async report => {
const {codeId} = receipts.RPT
inits.RPT.initMsg.token = [contracts.TOKEN.address, contracts.TOKEN.codeHash]
inits.RPT.initMsg.mgmt = [contracts.MGMT.address, contracts.MGMT.codeHash]
contracts.RPT = new RPTContract({ agent, codeId })
report(await contracts.RPT.init(inits.RPT))
})
return contracts
}
export async function launch () {}