Skip to content

Commit

Permalink
Connecting to Agora API
Browse files Browse the repository at this point in the history
  • Loading branch information
eternauta1337 committed Apr 25, 2024
1 parent a761e0c commit 7524af8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/ethernaut-cli/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require('ethernaut-wallet-ui')
require('ethernaut-challenges')
require('ethernaut-ui')
require('ethernaut-oso')
require('ethernaut-retropgf')
require('ethernaut-ai-ui')

async function main() {
Expand Down
26 changes: 11 additions & 15 deletions packages/ethernaut-retropgf/src/internal/agora/Agora.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@ const Identity = require('./Identity')
const Governance = require('./Governance')
const Retro = require('./Retro')

const BASE_URL = 'https://api.agora.space/ethernaut/retropgf'
const BASE_URL = 'https://vote.optimism.io/api/v1'

// See API spec at https://vote.optimism.io/api_v1
// API categories split into Identity, Governance, and Retro objects

class Agora {
constructor(apiKey) {
this.apiKey = apiKey
constructor() {
this.bearerToken = process.env.AGORA_BEARER_TOKEN

this._identity = new Identity(this)
this._governance = new Governance(this)
Expand All @@ -32,17 +35,17 @@ class Agora {
return this.createRequest('/api/v1/spec', {})
}

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

const config = {
method: 'POST',
method,
url: `${BASE_URL}${populatedEndpoint}`,
headers: {
Authorization: `Bearer ${this.apiKey}`,
Authorization: `Bearer ${this.bearerToken}`,
},
responseType: 'json',
}
Expand All @@ -57,16 +60,9 @@ class Agora {
)
}

// Api error
if (response.data.status !== '1') {
debug.log(response.data, 'interact')
throw new EthernautCliError(
'ethernaut-retropgf',
`Agora api error: ${response.data.result}`,
)
}
debug.log(response.data, 'retropgf')

return response.data.result
return response.data
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/ethernaut-retropgf/src/internal/agora/Retro.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ class Retro {
roundId,
})
}

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

return data.projects
}
}

module.exports = Retro
6 changes: 6 additions & 0 deletions packages/ethernaut-retropgf/src/tasks/lists.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const output = require('ethernaut-common/src/ui/output')
const Agora = require('../internal/agora/Agora')

require('../scopes/retro')
.task('lists', 'Prints out all the lists of the current round')
.setAction(async () => {
try {
const agora = new Agora()

const info = await agora.retro.getProjects()
console.log('@@@@', info)

// TODO
return output.resultBox('RetroPGF')
} catch (err) {
Expand Down

0 comments on commit 7524af8

Please sign in to comment.