From 1c30f7dfc9f346daff1efe371a60f773b8bc7701 Mon Sep 17 00:00:00 2001 From: Alejandro Date: Fri, 26 Apr 2024 09:05:16 -0300 Subject: [PATCH] Progress with Agora API --- .../src/internal/agora/Agora.js | 34 ++------ .../src/internal/agora/Governance.js | 82 ------------------- .../src/internal/agora/Identity.js | 21 ----- .../src/internal/agora/Retro.js | 62 -------------- .../src/internal/agora/RetroFunding.js | 43 ++++++++++ .../ethernaut-retropgf/src/tasks/lists.js | 6 +- 6 files changed, 55 insertions(+), 193 deletions(-) delete mode 100644 packages/ethernaut-retropgf/src/internal/agora/Governance.js delete mode 100644 packages/ethernaut-retropgf/src/internal/agora/Identity.js delete mode 100644 packages/ethernaut-retropgf/src/internal/agora/Retro.js create mode 100644 packages/ethernaut-retropgf/src/internal/agora/RetroFunding.js diff --git a/packages/ethernaut-retropgf/src/internal/agora/Agora.js b/packages/ethernaut-retropgf/src/internal/agora/Agora.js index c623800..bfa4803 100644 --- a/packages/ethernaut-retropgf/src/internal/agora/Agora.js +++ b/packages/ethernaut-retropgf/src/internal/agora/Agora.js @@ -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' @@ -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}`, }, @@ -52,7 +35,6 @@ class Agora { const response = await axios(config) - // Http error if (response.status !== 200) { throw new EthernautCliError( 'ethernaut-retropgf', @@ -60,7 +42,7 @@ class Agora { ) } - debug.log(response.data, 'retropgf') + debug.log(`Response ${JSON.stringify(response.data, null, 2)}`, 'retropgf') return response.data } diff --git a/packages/ethernaut-retropgf/src/internal/agora/Governance.js b/packages/ethernaut-retropgf/src/internal/agora/Governance.js deleted file mode 100644 index 2007c52..0000000 --- a/packages/ethernaut-retropgf/src/internal/agora/Governance.js +++ /dev/null @@ -1,82 +0,0 @@ -class Governance { - constructor(agora) { - this.agora = agora - } - - async getMetrics() { - return this.agora.createRequest('/api/v1/admin/metrics', {}) - } - - async getVotingTokenContractMetadata() { - return this.agora.createRequest('api/v1/contracts/votingToken', {}) - } - - async getAlligatorContractMetadata() { - return this.agora.createRequest('api/v1/contracts/alligator', {}) - } - - async getGovernorContractMetadata() { - return this.agora.createRequest('api/v1/contracts/governor', {}) - } - - async getContractMetadata() { - return this.agora.createRequest('/api/v1/contracts', {}) - } - - async getVote(transactionId) { - return this.agora.createRequest('/api/v1/votes/:transactionId', { - transactionId, - }) - } - - async getVotes() { - return this.agora.createRequest('/api/v1/votes', {}) - } - - async getProposalTypes() { - return this.agora.createRequest('/api/v1/proposals/types', {}) - } - - async getProposalVotes(proposalId) { - return this.agora.createRequest('/api/v1/proposals/:proposalID/votes', { - proposalId, - }) - } - - async getProposal(proposalId) { - return this.agora.createRequest('/api/v1/proposals/:proposalId', { - proposalId, - }) - } - - async getProposals() { - return this.agora.createRequest('/api/v1/proposals', {}) - } - - async getDelegateVotes(addressOrENSName) { - return this.agora.createRequest( - '/api/v1/delegates/:addressOrENSName/votes', - { - addressOrENSName, - }, - ) - } - - async getDelegatees(addressOrENSName) { - return this.agora.createRequest('/api/v1/delegatees/:addressOrENSName', { - addressOrENSName, - }) - } - - async getDelegate(addressOrENSName) { - return this.agora.createRequest('/api/v1/delegates/:addressOrENSName', { - addressOrENSName, - }) - } - - async getDelegates() { - return this.agora.createRequest('/api/v1/delegates', {}) - } -} - -module.exports = Governance diff --git a/packages/ethernaut-retropgf/src/internal/agora/Identity.js b/packages/ethernaut-retropgf/src/internal/agora/Identity.js deleted file mode 100644 index 79f3fb5..0000000 --- a/packages/ethernaut-retropgf/src/internal/agora/Identity.js +++ /dev/null @@ -1,21 +0,0 @@ -class Identity { - constructor(agora) { - this.agora = agora - } - - async isCitizen(addressOrENSName) { - return this.agora.createRequest('/api/v1/citizens/:addressOrENSName', { - addressOrENSName, - }) - } - - async getCitizens() { - return this.agora.createRequest('/api/v1/citizens', {}) - } - - async getProjects() { - return this.agora.createRequest('/api/v1/projects', {}) - } -} - -module.exports = Identity diff --git a/packages/ethernaut-retropgf/src/internal/agora/Retro.js b/packages/ethernaut-retropgf/src/internal/agora/Retro.js deleted file mode 100644 index a6166a5..0000000 --- a/packages/ethernaut-retropgf/src/internal/agora/Retro.js +++ /dev/null @@ -1,62 +0,0 @@ -class Retro { - constructor(agora) { - this.agora = agora - } - - async submitBallot(roundId, addressOrENSName) { - return this.agora.createRequest( - '/api/v1/retropgf/round/:roundID/ballot/:addressOrENSName/submit', - { - roundId, - addressOrENSName, - }, - ) - } - - async addProjectToBallot(projectId, roundId, addressOrENSName) { - return this.agora.createRequest( - '/api/v1/retropgf/round/:roundID/ballot/:addressOrENSName/addProject?projectID= ', - { - projectId, - roundId, - addressOrENSName, - }, - ) - } - - async removeProjectFromBallot(projectId, roundId, addressOrENSName) { - return this.agora.createRequest( - '/api/v1/retropgf/round/:roundID/ballot/:addressOrENSName/removeProject?projectID= ', - { - projectId, - roundId, - addressOrENSName, - }, - ) - } - - async getRoundApplicants(roundId) { - return this.agora.createRequest( - '/api/v1/retropgf/round/:roundID/projects', - { - roundId, - }, - ) - } - - async getRoundInfo(roundId) { - return this.agora.createRequest('/api/v1/retropgf/round/:roundID ', { - roundId, - }) - } - - async getProjects(limit = 10, offset = 0) { - const data = await this.agora.createRequest( - `/projects?limit=${limit}&?offset=${offset}`, - ) - - return data.projects - } -} - -module.exports = Retro diff --git a/packages/ethernaut-retropgf/src/internal/agora/RetroFunding.js b/packages/ethernaut-retropgf/src/internal/agora/RetroFunding.js new file mode 100644 index 0000000..8fe2c2a --- /dev/null +++ b/packages/ethernaut-retropgf/src/internal/agora/RetroFunding.js @@ -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 diff --git a/packages/ethernaut-retropgf/src/tasks/lists.js b/packages/ethernaut-retropgf/src/tasks/lists.js index 15cebb3..ed23b67 100644 --- a/packages/ethernaut-retropgf/src/tasks/lists.js +++ b/packages/ethernaut-retropgf/src/tasks/lists.js @@ -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')