Skip to content

Commit

Permalink
Merge branch 'feat/shapeshift_member_uri'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Implementations/API/package-lock.json
#	Implementations/API/yarn.lock
  • Loading branch information
crazyyuan committed Aug 23, 2023
2 parents 4369a97 + 3fdcc7c commit 191647e
Show file tree
Hide file tree
Showing 6 changed files with 3,243 additions and 3,128 deletions.
64 changes: 64 additions & 0 deletions Implementations/API/backend/functions/boardroom/getMembers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { APIGatewayProxyHandlerV2 } from "aws-lambda";
import { BoardroomAddressKeyConfig, shapeshiftApiConfig } from "../config";
import fetch, { RequestInit } from "node-fetch";
import { utils } from "ethers";

function apiRequest(path: string, method: "GET" | "POST", data?: any) {
const payload: RequestInit = {
headers: {
"Content-Type": "application/json",
},
method,
redirect: "follow",
};
if (method === "POST") payload.body = JSON.stringify(data);
return fetch(path, payload).then((res) => res.json());
}

export const handler: APIGatewayProxyHandlerV2 = async (event) => {
const network = event?.pathParameters?.network;
if (!network) return { statusCode: 400, message: "Missing network" };

const path = shapeshiftApiConfig[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 template = {
"@context": {
"@vocab": "http://daostar.org/",
},
type: "DAO",
name: eventId,
};

const address = utils.getAddress(eventId);

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

const res = (await apiRequest(queryPath, "GET")) as any;

if (!res.data) return { statusCode: 404, message: "DAO not found" };
const voters = res.data;

const membersFormatted = voters.map((a: any) => {
return {
id: a.address,
type: "EthereumAddress",
};
});

const transformed = { members: membersFormatted, ...template };

return transformed
? {
statusCode: 200,
body: JSON.stringify(transformed),
}
: {
statusCode: 404,
body: JSON.stringify({ error: true }),
};
};
47 changes: 29 additions & 18 deletions Implementations/API/backend/functions/config.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@
export const daohausGraphConfig: { [key: string]: any } = {
'1': 'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus',
'100': 'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-xdai',
'4': 'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-rinkeby',
'10': 'https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-optimism',
}
"1": "https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus",
"100":
"https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-xdai",
"4": "https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-rinkeby",
"10": "https://api.thegraph.com/subgraphs/name/odyssy-automaton/daohaus-optimism",
};

export const daostackGraphConfig: { [key: string]: any } = {
'1': 'https://api.thegraph.com/subgraphs/name/daostack/v41_11',
'100': 'https://api.thegraph.com/subgraphs/name/daostack/v41_11_xdai',
}
"1": "https://api.thegraph.com/subgraphs/name/daostack/v41_11",
"100": "https://api.thegraph.com/subgraphs/name/daostack/v41_11_xdai",
};

export const aaveGraphConfig: { [key: string]: any } = {
'1': 'https://api.thegraph.com/subgraphs/name/aave/governance-v2',
}
"1": "https://api.thegraph.com/subgraphs/name/aave/governance-v2",
};

export const gnosisGraphConfig: { [key: string]: any } = {
'1': 'https://api.thegraph.com/subgraphs/name/gjeanmart/gnosis-safe-mainnet'
}
"1": "https://api.thegraph.com/subgraphs/name/gjeanmart/gnosis-safe-mainnet",
};

export const gnosisApiConfig: { [key: string]: any } = {
'1': 'https://safe-transaction-mainnet.safe.global/api/v1'
}
"1": "https://safe-transaction-mainnet.safe.global/api/v1",
};

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

export const nonusApiConfig: { [key: string]: any } = {
'1': 'https://api.thegraph.com/subgraphs/name/nounsdao/nouns-subgraph'
}
"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 BoardroomAddressKeyConfig: { [key: string]: any } = {
"0x90A48D5CF7343B08dA12E067680B4C6dbfE551Be":
"c909030d97aaa3f635a09eb4a3df58fc",
};

export const delegationsSubgraphs: { [key: string]: string } = {
"1": "https://subgrapher.snapshot.org/gateway.thegraph.com/api/0f15b42bdeff7a063a4e1757d7e2f99e/deployments/id/QmXZiV6S13ha6QXq4dmaM3TB4CHcDxBMvGexSNu9Kc28EH",
Expand All @@ -40,3 +50,4 @@ export const delegationsSubgraphs: { [key: string]: string } = {
"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"
}

26 changes: 26 additions & 0 deletions Implementations/API/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Implementations/API/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"@serverless-stack/resources": "^1.18.4",
"@types/aws-lambda": "^8.10.97",
"typescript": "^4.7.2",
"vitest": "^0.12.9"
"vitest": "^0.12.9",
"prettier": "^2.3.2"
},
"workspaces": [
"backend"
Expand Down
13 changes: 8 additions & 5 deletions Implementations/API/stacks/MyStack.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Api, StackContext } from '@serverless-stack/resources'
import { Api, StackContext } from "@serverless-stack/resources";

export function MyStack({ stack }: StackContext) {
// Create the HTTP API
Expand All @@ -22,6 +22,8 @@ export function MyStack({ stack }: StackContext) {
'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',
Expand All @@ -30,8 +32,9 @@ export function MyStack({ stack }: StackContext) {
},
})

// Show the API endpoint in the output
stack.addOutputs({
ApiEndpoint: api.url,
})

// Show the API endpoint in the output
stack.addOutputs({
ApiEndpoint: api.url,
});
}
Loading

0 comments on commit 191647e

Please sign in to comment.