Get All Proposals For DAO
Fetch all proposals for a DAO.
If we want to fetch all proposals for a DAO, we have to follow these steps
Get Realm id for the DAO you are interested in. You can either have it beforehand or search based on DAO name.
Once we have the realm address, we will fetch all the associated governance accounts.
We will use the _in operator to pass all governance accounts in one call and fetch all the associated proposals.
// Node doesn't implement fetch so we have to import it
import fetch from "node-fetch";
const SHYFT_API_KEY = 'YOUR-KEY'
async function fetchGraphQL(query, variables = {}, name = "MyQuery") {
const result = await fetch(
`https://programs.shyft.to/v0/graphql/?api_key=${SHYFT_API_KEY}`,
{
method: "POST",
body: JSON.stringify({
query: query,
variables: variables,
operationName: name
})
}
);
return await result.json();
}
async function fetchProposals(governanceAccounts) {
const query = `
query MyQuery($_in: [String!] = "") {
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1(
where: {governance: {_in: $_in}}
) {
closedAt
descriptionLink
draftAt
executingAt
executionFlags
governance
governingTokenMint
instructionsCount
instructionsExecutedCount
instructionsNextIndex
lamports
maxVoteWeight
name
noVotesCount
signatoriesCount
signatoriesSignedOffCount
signingOffAt
state
tokenOwnerRecord
voteThreshold
votingAt
votingAtSlot
votingCompletedAt
yesVotesCount
}
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2(
where: {governance: {_in: $_in}}
) {
abstainVoteWeight
closedAt
denyVoteWeight
descriptionLink
draftAt
executingAt
executionFlags
governance
governingTokenMint
lamports
maxVoteWeight
maxVotingTime
name
options
reserved1
signatoriesCount
signatoriesSignedOffCount
signingOffAt
startVotingAt
state
tokenOwnerRecord
vetoVoteWeight
voteThreshold
voteType
votingAt
votingAtSlot
votingCompletedAt
}
}
`;
const variables = {
_in: governanceAccounts
}
const { errors, data } = await fetchGraphQL(query, variables);
if (errors) {
// handle those errors like a pro
console.error(errors);
}
return data;
}
async function fetchGovernanceAccounts(realm) {
//We are only interested in pubkeys of the governance accounts
const query = `
query MyQuery {
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_GovernanceV1(
where: {realm: {_eq: ${JSON.stringify(realm)}}}
) {
pubkey
}
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_GovernanceV2(
where: {realm: {_eq:${JSON.stringify(realm)}}}
) {
pubkey
}
}
`;
const { errors, data } = await fetchGraphQL(query);
if (errors) {
// handle those errors like a pro
console.error(errors);
}
//Fetch all governance accounts
const governanceAccounts = []
data?.GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_GovernanceV1?.forEach(account => {
governanceAccounts.push(account.pubkey);
})
data?.GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_GovernanceV2?.forEach(account => {
governanceAccounts.push(account.pubkey);
})
return governanceAccounts;
}
//Fetch governance accounts for Grape DAO realm
const govAccounts = await fetchGovernanceAccounts("By2sVGZXwfQq6rAiAM3rNPJ9iQfb5e2QhnF4YjJ4Bip")
//Fetch all proposals for the goverance accounts
const proposals = await fetchProposals(govAccounts);
console.log(proposals);
{
"data": {
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1": [],
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2": [
{
"abstainVoteWeight": null,
"closedAt": null,
"denyVoteWeight": 0,
"descriptionLink": "",
"draftAt": 1659166149,
"executingAt": null,
"executionFlags": 0,
"governance": "e6Tw228L7G6sHZmSsGq5jkTXPwm8KNuNBvsQrJvN61t",
"governingTokenMint": "8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA",
"lamports": 3480000,
"maxVoteWeight": 102499801530352,
"maxVotingTime": null,
"name": "Send Element4ls / Dean the Machine to 3PKhz…6cSNt",
"options": [
{
"label": "Approve",
"voteWeight": "3934219891938",
"voteResult": 2,
"instructionsExecutedCount": 0,
"instructionsCount": 1,
"instructionsNextIndex": 1
}
],
"reserved1": 0,
"signatoriesCount": 1,
"signatoriesSignedOffCount": 1,
"signingOffAt": 1659166152,
"startVotingAt": null,
"state": 7,
"tokenOwnerRecord": "G7xHgK76oZXufXNRJ1efDubbuhNbU2kjbLiFK7BeMDRR",
"vetoVoteWeight": 0,
"voteThreshold": {
"type": 0,
"value": 5
},
"voteType": {
"type": 0
},
"votingAt": 1659166152,
"votingAtSlot": 143769256,
"votingCompletedAt": 1659427027
}
//More responses in the array
]
}
}
Last updated