-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'dbfc5a6d38cd2b70a3c7e2206619b445e6f63b45' into feat/link
# Conflicts: # daostar-website/src/components/Homepage/MemberLogos/MemberLogos.js
- Loading branch information
Showing
1,358 changed files
with
88,727 additions
and
8,922 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
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
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
77 changes: 77 additions & 0 deletions
77
Implementations/API/backend/functions/boardroom/getMembers.ts
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,77 @@ | ||
import { APIGatewayProxyHandlerV2 } from "aws-lambda"; | ||
import { BoardroomKey, boardroomApiConfig } 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 = boardroomApiConfig[network]; | ||
if (!path) return { statusCode: 400, message: "Missing config for network" }; | ||
|
||
const name = event?.pathParameters?.id; | ||
if (!name) return { statusCode: 400, message: "Missing name" }; | ||
|
||
const cursor: string | undefined = event?.queryStringParameters?.cursor; | ||
|
||
const template = { | ||
"@context": { | ||
"@vocab": "http://daostar.org/", | ||
}, | ||
type: "DAO", | ||
name: name, | ||
}; | ||
|
||
let queryPath = | ||
path + | ||
"/" + | ||
name + | ||
"/voters" + | ||
"?limit=50&key=" + | ||
process.env.BOARDROOM_KEY; | ||
if (cursor) { | ||
queryPath += "&cursor=" + decodeURIComponent(cursor); | ||
} | ||
|
||
const res = (await apiRequest(queryPath, "GET")) as any; | ||
|
||
if (!res.data) return { statusCode: 404, message: "DAO not found" }; | ||
const voters = res.data; | ||
const nextCursor = res.nextCursor; | ||
|
||
const membersFormatted = voters.map((a: any) => { | ||
return { | ||
id: a.address, | ||
type: "EthereumAddress", | ||
}; | ||
}); | ||
|
||
const transformed = { | ||
members: membersFormatted, | ||
...template, | ||
nextCursor: encodeURIComponent(nextCursor), | ||
}; | ||
|
||
return transformed | ||
? { | ||
statusCode: 200, | ||
body: JSON.stringify(transformed), | ||
} | ||
: { | ||
statusCode: 404, | ||
body: JSON.stringify({ error: true }), | ||
}; | ||
}; |
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 |
---|---|---|
@@ -1,31 +1,55 @@ | ||
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", | ||
"10": "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 boardroomApiConfig: { [key: string]: any } = { | ||
"1": "https://api.boardroom.info/v1/protocols", | ||
"10": "https://api.boardroom.info/v1/protocols", | ||
}; | ||
|
||
export const BoardroomKey = "8f123cfd353883b4f1a16db3110a69d7"; | ||
|
||
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", | ||
}; |
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
91 changes: 91 additions & 0 deletions
91
Implementations/API/backend/functions/snapshot/getDelegations.ts
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,91 @@ | ||
import { APIGatewayProxyHandlerV2 } from 'aws-lambda' | ||
import { delegationsSubgraphs } from 'functions/config' | ||
import snapshot from '@snapshot-labs/snapshot.js'; | ||
import { getAddress } from '@ethersproject/address'; | ||
|
||
|
||
const { | ||
subgraphRequest, | ||
} = snapshot.utils; | ||
|
||
async function getDelegationsOutAndIn( | ||
network: string, | ||
space: string | ||
): Promise<string[]> { | ||
if (!delegationsSubgraphs[network]) return []; | ||
|
||
const max = 1000; | ||
let result: any = []; | ||
let page = 0; | ||
|
||
const members: string[] = [] | ||
|
||
const query = { | ||
delegations: { | ||
__args: { | ||
first: max, | ||
skip: 0, | ||
where: { | ||
space_in: [space], | ||
} | ||
}, | ||
delegator: true, | ||
delegate: true, | ||
space: true | ||
} | ||
}; | ||
while (true) { | ||
query.delegations.__args.skip = page * max; | ||
const pageResult = await subgraphRequest(delegationsSubgraphs[network], query); | ||
const pageDelegations = pageResult.delegations || []; | ||
result = result.concat(pageDelegations); | ||
page++; | ||
if (pageDelegations.length < max) break; | ||
} | ||
|
||
result.forEach((delegation: any) => { | ||
const delegator = getAddress(delegation.delegator); | ||
const delegate = getAddress(delegation.delegate); | ||
if (delegation.space === space) { | ||
members.push(delegator) | ||
members.push(delegate) | ||
|
||
} | ||
}); | ||
|
||
return members | ||
} | ||
|
||
export const handler: APIGatewayProxyHandlerV2 = async (event) => { | ||
|
||
const space = event?.pathParameters?.id | ||
if (!space) return { statusCode: 400, message: 'Missing id' } | ||
|
||
const template = { | ||
'@context': { | ||
'@vocab': 'http://daostar.org/', | ||
}, | ||
type: 'DAO', | ||
name: space, | ||
} | ||
|
||
const members = await getDelegationsOutAndIn('1', space) | ||
|
||
console.log({ members }) | ||
|
||
const membersFormatted = members.map((m: string) => { | ||
return { id: m, type: 'EthereumAddress' } | ||
}) | ||
|
||
const transformed = { members: membersFormatted, ...template } | ||
|
||
return transformed | ||
? { | ||
statusCode: 200, | ||
body: JSON.stringify(transformed), | ||
} | ||
: { | ||
statusCode: 404, | ||
body: JSON.stringify({ error: true }), | ||
} | ||
} |
Oops, something went wrong.