Last active
October 22, 2020 22:54
-
-
Save Evalir/3d8ab957784a5d9250c547e51c76af3b to your computer and use it in GitHub Desktop.
GovernQueue contract interaction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import BN from 'bn.js' | |
| import { toHex } from 'web3-utils' | |
| // ... any other ethers imports | |
| // governQueueAddress should be the space queue address. | |
| const GQL_QUERY = ` | |
| governQueue(id: "governQueueAddress") { | |
| config { | |
| executionDelay | |
| scheduleDeposit { | |
| token { | |
| id | |
| } | |
| amount | |
| } | |
| challengeDeposit { | |
| token { | |
| id | |
| } | |
| amount | |
| } | |
| vetoDeposit { | |
| token { | |
| id | |
| } | |
| amount | |
| } | |
| resolver | |
| rules | |
| } | |
| } | |
| ` | |
| const FAILURE_MAP = "0x0000000000000000000000000000000000000000000000000000000000000000" | |
| const EMPTY_BYTES = '0x00' | |
| /** | |
| * scheduleAction schedules an action into a GovernQueue. | |
| * Instead of sending the action to a disputable delay from aragonOS, we directly call this | |
| * contract. | |
| * the actionsFromAragonPlugin is an array of objects with the form { to, value, data } | |
| */ | |
| async function scheduleAction(actionsFromAragonPlugin) { | |
| // init the queueContract with ethers, left out of the gist | |
| const queueContract = getQueueContract() | |
| // make subgraph query with the preferred client as well. | |
| const config = querySubgraph() | |
| // Building the nonce for the next tx | |
| const nonce = await queueContract.nonce() | |
| const bnNonce = new BN(nonce.toString()) | |
| const newNonce = bnNonce.add(new BN('1')) | |
| // We also need to get a timestamp bigger or equal to the current block.timestamp + config.executionDelay | |
| // Right now + execution delay + 60 seconds into the future | |
| const currentDate = Math.round(Date.now() / 1000) + Number(config.executionDelay) + 60 | |
| const tx = await queueContract['schedule']( | |
| { | |
| payload: { | |
| nonce: newNonce.toString(), | |
| executionTime: currentDate, | |
| submitter: account, | |
| executor, | |
| actions: actionsFromAragonPlugin, | |
| allowFailuresMap: FAILURE_MAP, | |
| // proof in snapshot's case, could be the proposal's IPFS CID | |
| proof: proof ? toHex(proof) : EMPTY_BYTES, | |
| }, | |
| config: { | |
| executionDelay: config.executionDelay, | |
| scheduleDeposit: { | |
| token: config.scheduleDeposit.token.id, | |
| amount: config.scheduleDeposit.amount, | |
| }, | |
| challengeDeposit: { | |
| token: config.challengeDeposit.token.id, | |
| amount: config.challengeDeposit.amount, | |
| }, | |
| vetoDeposit: { | |
| token: config.vetoDeposit.token.id, | |
| amount: config.vetoDeposit.amount, | |
| }, | |
| resolver: config.resolver, | |
| rules: config.rules, | |
| }, | |
| }, | |
| { | |
| // This can probably be optimized | |
| gasLimit: 500000, | |
| }, | |
| ) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment