Get Proposals For Governing Mint
Fetch all proposals for a governing mint.
Each DOA is governed by certain tokens. In order to vote on proposals for a DAO, you need to have those tokens. To get this data we need to query
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV2
and filter the data based on the governingTokenMint.
You can run this code in replit to see it in action.
// 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(mint) {
const query = `
query MyQuery {
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1(
where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}}
) {
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: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}}
) {
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 { errors, data } = await fetchGraphQL(query);
if (errors) {
// handle those errors like a pro
console.error(errors);
}
// do something great with this precious data
console.log(data);
}
//Fetch all proposals for Grape governing token
fetchProposals("8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA");
Fetch Active Proposals
Each proposals goes though different states which you can read more about here. We are interested in active proposals, which means we need all proposals where state equals to 2. We will modify the above example to account for it.
// 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 fetchActiveProposals(mint) {
const query = `
query MyQuery {
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1(
where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}, state: {_eq: 2}}
) {
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: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}, state: {_eq: 2}}
) {
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 { errors, data } = await fetchGraphQL(query);
if (errors) {
// handle those errors like a pro
console.error(errors);
}
// do something great with this precious data
console.log(data);
}
//Fetch active proposals for Grape governing token
fetchActiveProposals("8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA");
Get all proposals sorted by voting time
Each proposal has a votingAt timestamp, which tells you when voting started for that proposal. While fetching proposals, we can order them by votingAt to see new proposals first.
// 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 fetchActiveProposals(mint) {
const query = `
query MyQuery {
GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw_ProposalV1(
where: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}
order_by: {votingAt: desc}
) {
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: {governingTokenMint: {_eq: ${JSON.stringify(mint)}}
order_by: {votingAt: desc}
) {
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 { errors, data } = await fetchGraphQL(query);
if (errors) {
// handle those errors like a pro
console.error(errors);
}
// do something great with this precious data
console.log(data);
}
//Fetch active proposals for Grape governing token
fetchActiveProposals("8upjSpvjcdpuzhfR1zriwg5NXkwDruejqNE9WNbPRtyA");
Last updated