Skip to content

Commit

Permalink
Merge pull request #146 from metagov/feat/boardroom
Browse files Browse the repository at this point in the history
feat: improve boardroom framework api.
  • Loading branch information
crazyyuan authored Sep 5, 2023
2 parents 9031b4f + bd6abed commit 446de1d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 51 deletions.
15 changes: 7 additions & 8 deletions Implementations/API/backend/functions/boardroom/getMembers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { APIGatewayProxyHandlerV2 } from "aws-lambda";
import { BoardroomAddressKeyConfig, shapeshiftApiConfig } from "../config";
import { BoardroomKey, boardroomApiConfig } from "../config";
import fetch, { RequestInit } from "node-fetch";
import { utils } from "ethers";

Expand All @@ -19,25 +19,24 @@ export const handler: APIGatewayProxyHandlerV2 = async (event) => {
const network = event?.pathParameters?.network;
if (!network) return { statusCode: 400, message: "Missing network" };

const path = shapeshiftApiConfig[network];
const path = boardroomApiConfig[network];
if (!path) return { statusCode: 400, message: "Missing config for network" };

const eventId = event?.pathParameters?.id;
if (!eventId) return { statusCode: 400, message: "Missing id" };
const name = event?.pathParameters?.id;
if (!name) return { statusCode: 400, message: "Missing name" };

const template = {
"@context": {
"@vocab": "http://daostar.org/",
},
type: "DAO",
name: eventId,
name: name,
};

const address = utils.getAddress(eventId);

const queryPath =
path + "/voters" + "?limit=50&key=" + BoardroomAddressKeyConfig[address];
path + "/" + name + "/voters" + "?limit=50&key=" + BoardroomKey;

console.log("queryPath:", queryPath);
const res = (await apiRequest(queryPath, "GET")) as any;

if (!res.data) return { statusCode: 404, message: "DAO not found" };
Expand Down
26 changes: 14 additions & 12 deletions Implementations/API/backend/functions/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,31 @@ export const gnosisApiConfig: { [key: string]: any } = {

export const snapshotApiConfig: { [key: string]: any } = {
"1": "https://hub.snapshot.org/graphql",
"10": "https://hub.snapshot.org/graphql",
};

export const nonusApiConfig: { [key: string]: any } = {
"1": "https://api.thegraph.com/subgraphs/name/nounsdao/nouns-subgraph",
};

export const shapeshiftApiConfig: { [key: string]: any } = {
"1": "https://api.boardroom.info/v1/protocols/shapeshift",
export const boardroomApiConfig: { [key: string]: any } = {
"1": "https://api.boardroom.info/v1/protocols",
"10": "https://api.boardroom.info/v1/protocols",
};

export const BoardroomAddressKeyConfig: { [key: string]: any } = {
"0x90A48D5CF7343B08dA12E067680B4C6dbfE551Be":
"c909030d97aaa3f635a09eb4a3df58fc",
};
export const BoardroomKey = "c909030d97aaa3f635a09eb4a3df58fc";

export const delegationsSubgraphs: { [key: string]: string } = {
"1": "https://subgrapher.snapshot.org/gateway.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/deployments/id/QmXZiV6S13ha6QXq4dmaM3TB4CHcDxBMvGexSNu9Kc28EH",
"5": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-goerli",
"10": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-optimism",
"56": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-binance-smart-chain",
"100": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
"137": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
"250": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
"42161": "https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum"
}

"100":
"https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-gnosis-chain",
"137":
"https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-polygon",
"250":
"https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-fantom",
"42161":
"https://subgrapher.snapshot.org/api.thegraph.com/subgraphs/name/snapshot-labs/snapshot-arbitrum",
};
75 changes: 44 additions & 31 deletions Implementations/API/stacks/MyStack.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,50 @@
import { Api, StackContext } from "@serverless-stack/resources";

export function MyStack({ stack }: StackContext) {
// Create the HTTP API
const api = new Api(stack, 'Api', {
routes: {
'GET /molochv2/members/{network}/{id}': 'functions/molochv2/getMembers.handler',
'GET /molochv2/proposals/{network}/{id}': 'functions/molochv2/getProposals.handler',
// 'GET /molochv2/activities/{network}/{id}': 'functions/molochv2/getActivityLogs.handler',
'GET /molochv3/members/{network}/{id}': 'functions/molochv3/getMembers.handler',
'GET /molochv3/proposals/{network}/{id}': 'functions/molochv3/getProposals.handler',
'GET /molochv3/activities/{network}/{id}': 'functions/molochv3/getActivityLogs.handler',
'GET /daostack/proposals/{network}/{id}': 'functions/daostack/getProposals.handler',
'GET /daostack/members/{network}/{id}': 'functions/daostack/getMembers.handler',
'GET /aave/proposals/{network}/{id}': 'functions/aave/getProposals.handler',
'GET /gnosis/members/{network}/{id}': 'functions/gnosis/getMembers.handler',
'GET /gnosis/proposals/{network}/{id}': 'functions/gnosis/getProposals.handler',
'GET /gnosis/activities/{network}/{id}': 'functions/gnosis/getActivityLogs.handler',
'GET /daodao/members/{network}/{id}': 'functions/daodao/getMembers.handler',
'GET /daodao/proposals/{network}/{id}': 'functions/daodao/getProposals.handler',
'GET /snapshot/members/{id}': 'functions/snapshot/getMembers.handler',
'GET /snapshot/delegations/{id}': 'functions/snapshot/getDelegations.handler',
'GET /snapshot/proposals/{id}': 'functions/snapshot/getProposals.handler',
'GET /nouns/members/{network}/{id}': 'functions/nouns/getMembers.handler',
"GET /boardroom/members/{network}/{id}":
"functions/boardroom/getMembers.handler",
},
customDomain: {
domainName: 'services.daostar.org',
hostedZone: 'services.daostar.org',
path: 'api/v1',
},
})

// Create the HTTP API
const api = new Api(stack, "Api", {
routes: {
"GET /molochv2/members/{network}/{id}":
"functions/molochv2/getMembers.handler",
"GET /molochv2/proposals/{network}/{id}":
"functions/molochv2/getProposals.handler",
// 'GET /molochv2/activities/{network}/{id}': 'functions/molochv2/getActivityLogs.handler',
"GET /molochv3/members/{network}/{id}":
"functions/molochv3/getMembers.handler",
"GET /molochv3/proposals/{network}/{id}":
"functions/molochv3/getProposals.handler",
"GET /molochv3/activities/{network}/{id}":
"functions/molochv3/getActivityLogs.handler",
"GET /daostack/proposals/{network}/{id}":
"functions/daostack/getProposals.handler",
"GET /daostack/members/{network}/{id}":
"functions/daostack/getMembers.handler",
"GET /aave/proposals/{network}/{id}":
"functions/aave/getProposals.handler",
"GET /gnosis/members/{network}/{id}":
"functions/gnosis/getMembers.handler",
"GET /gnosis/proposals/{network}/{id}":
"functions/gnosis/getProposals.handler",
"GET /gnosis/activities/{network}/{id}":
"functions/gnosis/getActivityLogs.handler",
"GET /daodao/members/{network}/{id}":
"functions/daodao/getMembers.handler",
"GET /daodao/proposals/{network}/{id}":
"functions/daodao/getProposals.handler",
"GET /snapshot/members/{id}": "functions/snapshot/getMembers.handler",
"GET /snapshot/delegations/{id}":
"functions/snapshot/getDelegations.handler",
"GET /snapshot/proposals/{id}": "functions/snapshot/getProposals.handler",
"GET /nouns/members/{network}/{id}": "functions/nouns/getMembers.handler",
"GET /boardroom/members/{network}/{id}":
"functions/boardroom/getMembers.handler",
},
customDomain: {
domainName: "services.daostar.org",
hostedZone: "services.daostar.org",
path: "api/v1",
},
});

// Show the API endpoint in the output
stack.addOutputs({
Expand Down

0 comments on commit 446de1d

Please sign in to comment.