Skip to content

Commit

Permalink
fix: upgrade to latest governor contract and close #9
Browse files Browse the repository at this point in the history
  • Loading branch information
eccentricexit committed Apr 13, 2020
1 parent ff1c2e2 commit b4b97a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
23 changes: 18 additions & 5 deletions bots/execute-approved.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
const ethers = require('ethers')

const { bigNumberify } = ethers.utils
const { LAST_EXECUTED_SESSION } = require('../utils/db-keys')

// Executes transactions approved in the last session, if any.
module.exports = async ({ governor, currentSessionNumber, db }) => {
module.exports = async ({ governor, currentSessionNumber, db, timestamp }) => {
const sessionToExecute = currentSessionNumber.toNumber() - 1
if (sessionToExecute <= 0) return // We are in the very first session. Nothing to execute yet.

Expand All @@ -14,9 +17,12 @@ module.exports = async ({ governor, currentSessionNumber, db }) => {

if (lastExecutedSession === sessionToExecute) return // Already executed transactions from this session.

const submissionIndexes = await governor.getSubmittedLists(sessionToExecute)
const [submissionIndexes, executionTimeout] = await Promise.all([
governor.getSubmittedLists(sessionToExecute),
governor.executionTimeout()
])

const approvedSubmission = (
const approvedSubmissions = (
await Promise.all(
submissionIndexes.map(async listID => ({
listID,
Expand All @@ -25,9 +31,16 @@ module.exports = async ({ governor, currentSessionNumber, db }) => {
)
).filter(a => a.approved)

if (approvedSubmission.length === 0) return
if (approvedSubmissions.length === 0) return // No approved transactions.

const { listID, approvalTime } = approvedSubmissions[0]

const listID = approvedSubmission[0].listID
if (
bigNumberify(timestamp)
.sub(approvalTime)
.lte(executionTimeout)
)
return // Time to execute transactions has passed.

console.info('Executing approved transactions for session', sessionToExecute)
console.info('Approved List ID', listID.toNumber())
Expand Down
5 changes: 3 additions & 2 deletions bots/pass-period.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ module.exports = async ({
chainId,
signerAddress
}) => {
const session = await governor.sessions(currentSessionNumber)

// Are we still in the submission period?
if (
bigNumberify(timestamp)
.sub(lastApprovalTime)
.lte(submissionTimeout)
.lte(submissionTimeout.add(session.durationOffset))
)
return

// Submission period is over. Was there a dispute in the last session?
const session = await governor.sessions(currentSessionNumber)
if (session.status !== NO_DISPUTE) return

console.info('In approval period, calling executeSubmissions...')
Expand Down

0 comments on commit b4b97a1

Please sign in to comment.