-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateQi
executable file
·88 lines (78 loc) · 2.21 KB
/
createQi
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
#!/usr/bin/env node
const { request, gql } = require('graphql-request')
const snapshot = require('@snapshot-labs/snapshot.js')
const client = new snapshot.Client712('https://hub.snapshot.org')
const ethers = require('ethers')
const { Command } = require('commander')
const delay = require('delay')
const program = new Command()
program.description('Create tetuQi gauge proposal')
program.requiredOption('-p, --proposalId <string>')
program.option('-d, --dry')
program.parse()
const GRAPHQL_ENDPOINT = 'https://hub.snapshot.org/graphql'
async function getProposal (proposalId) {
const proposalResp = await request(GRAPHQL_ENDPOINT, gql`
query {
proposals (
where: {
id: "${proposalId}"
}
) {
id
title
body
choices
start
end
snapshot
state
scores
scores_by_strategy
scores_total
scores_updated
author
space {
id
name
}
}
}
`)
if (proposalResp.proposals.length === 0) throw new Error('proposal not found')
return proposalResp.proposals[0]
}
async function main () {
const { title, choices, start, end, snapshot } = await getProposal(program.opts().proposalId)
if (!process.env.DEPLOYER_MNEMONIC) throw new Error('must set DEPLOYER_MNEMONIC')
const signer = ethers.Wallet.fromMnemonic(process.env.DEPLOYER_MNEMONIC, process.env.DEPLOYER_MNEMONIC_PATH || "m/44'/60'/0'/0/0")
try {
const proposal = {
space: 'tetuqi.eth',
type: 'weighted',
title: `Reflect: ${title}`,
body: 'We will use this proposal result in the QiDAO Gauge vote.',
choices,
start,
end: end - 86400, // -1 day
snapshot: parseInt(snapshot, 10),
plugins: '{}',
app: 'snapshot',
discussion: '',
from: signer.address
}
if (program.opts().dry) {
console.log('Dry run, proposal below...')
console.log(proposal)
} else {
console.log(proposal)
console.log('About to create proposal in 5 seconds...')
await delay(5000)
const resp = await client.proposal(signer, signer.address, proposal)
console.log(resp)
}
} catch (err) {
console.log(err)
}
}
main()