-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad570b6
commit 0a9e9b2
Showing
5 changed files
with
231 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
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 BASE_URL = 'https://api.agora.space/ethernaut/retropgf' | ||
|
||
class Agora { | ||
constructor(apiKey) { | ||
this.apiKey = apiKey | ||
|
||
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 | ||
} | ||
|
||
async getSpec() { | ||
return this.createRequest('/api/v1/spec', {}) | ||
} | ||
|
||
async createRequest(endpoint, params = {}) { | ||
let populatedEndpoint = endpoint | ||
for (const key in params) { | ||
populatedEndpoint = populatedEndpoint.replace(`:${key}`, params[key]) | ||
} | ||
|
||
const config = { | ||
method: 'POST', | ||
url: `${BASE_URL}${populatedEndpoint}`, | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
}, | ||
responseType: 'json', | ||
} | ||
|
||
const response = await axios(config) | ||
|
||
// Http error | ||
if (response.status !== 200) { | ||
throw new EthernautCliError( | ||
'ethernaut-retropgf', | ||
`Http status error: ${response.status}`, | ||
) | ||
} | ||
|
||
// Api error | ||
if (response.data.status !== '1') { | ||
debug.log(response.data, 'interact') | ||
throw new EthernautCliError( | ||
'ethernaut-retropgf', | ||
`Agora api error: ${response.data.result}`, | ||
) | ||
} | ||
|
||
return response.data.result | ||
} | ||
} | ||
|
||
module.exports = Agora |
82 changes: 82 additions & 0 deletions
82
packages/ethernaut-retropgf/src/internal/agora/Governance.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
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 |
21 changes: 21 additions & 0 deletions
21
packages/ethernaut-retropgf/src/internal/agora/Identity.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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, | ||
}) | ||
} | ||
} | ||
|
||
module.exports = Retro |
This file contains 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