Skip to content

Commit

Permalink
Progress with Agora API
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Apr 26, 2024
1 parent 7524af8 commit 1c30f7d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 193 deletions.
34 changes: 8 additions & 26 deletions packages/ethernaut-retropgf/src/internal/agora/Agora.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const axios = require('axios')
const debug = require('ethernaut-common/src/ui/debug')
const EthernautCliError = require('ethernaut-common/src/error/error')
const Identity = require('./Identity')
const Governance = require('./Governance')
const Retro = require('./Retro')
const RetroFunding = require('./RetroFunding')

const BASE_URL = 'https://vote.optimism.io/api/v1'

Expand All @@ -14,36 +12,21 @@ class Agora {
constructor() {
this.bearerToken = process.env.AGORA_BEARER_TOKEN

this._identity = new Identity(this)
this._governance = new Governance(this)
this._retro = new Retro(this)
}

get identity() {
return this._identity
}

get governance() {
return this._governance
}

get retro() {
return this._retro
this.retro = new RetroFunding(this)
}

async getSpec() {
return this.createRequest('/api/v1/spec', {})
}

async createRequest(endpoint, params = {}, method = 'GET') {
let populatedEndpoint = endpoint
for (const key in params) {
populatedEndpoint = populatedEndpoint.replace(`:${key}`, params[key])
}
async createRequest(endpoint, method = 'GET') {
const url = `${BASE_URL}${endpoint}`

debug.log(`Requesting ${url}`, 'retropgf')

const config = {
method,
url: `${BASE_URL}${populatedEndpoint}`,
url,
headers: {
Authorization: `Bearer ${this.bearerToken}`,
},
Expand All @@ -52,15 +35,14 @@ class Agora {

const response = await axios(config)

// Http error
if (response.status !== 200) {
throw new EthernautCliError(
'ethernaut-retropgf',
`Http status error: ${response.status}`,
)
}

debug.log(response.data, 'retropgf')
debug.log(`Response ${JSON.stringify(response.data, null, 2)}`, 'retropgf')

return response.data
}
Expand Down
82 changes: 0 additions & 82 deletions packages/ethernaut-retropgf/src/internal/agora/Governance.js

This file was deleted.

21 changes: 0 additions & 21 deletions packages/ethernaut-retropgf/src/internal/agora/Identity.js

This file was deleted.

62 changes: 0 additions & 62 deletions packages/ethernaut-retropgf/src/internal/agora/Retro.js

This file was deleted.

43 changes: 43 additions & 0 deletions packages/ethernaut-retropgf/src/internal/agora/RetroFunding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
class RetroFunding {
constructor(agora) {
this.agora = agora
}

async projects({ limit = 10, offset = 0 }) {
return (
await this.agora.createRequest(
`/projects?limit=${limit}&?offset=${offset}`,
)
).projects
}

async round({ roundId }) {
return await this.agora.createRequest(`/retrofunding/rounds/${roundId}`)
}

async ballots({ roundId, limit = 10, offset = 0 }) {
return (
await this.agora.createRequest(
`/retrofunding/rounds/${roundId}/ballots?limit=${limit}&offset=${offset}`,
)
).ballots
}

async roundProjects({ roundId, limit = 10, offset = 0 }) {
return (
await this.agora.createRequest(
`/retrofunding/rounds/${roundId}/projects?limit=${limit}&offset=${offset}`,
)
).projects
}

async roundImpactMetrics({ roundId }) {
return (
await this.agora.createRequest(
`/retrofunding/rounds/${roundId}/impactMetrics`,
)
).impactMetrics
}
}

module.exports = RetroFunding
6 changes: 4 additions & 2 deletions packages/ethernaut-retropgf/src/tasks/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ require('../scopes/retro')
try {
const agora = new Agora()

const info = await agora.retro.getProjects()
console.log('@@@@', info)
const info = await agora.retro.roundImpactMetrics({
roundId: 1,
})
console.log('@@@@', JSON.stringify(info, null, 2))

// TODO
return output.resultBox('RetroPGF')
Expand Down

0 comments on commit 1c30f7d

Please sign in to comment.