Skip to content

Instantly share code, notes, and snippets.

@psushi
Last active August 1, 2022 05:27
Show Gist options
  • Select an option

  • Save psushi/31b039139bfdcfa2e87a84c915fd2670 to your computer and use it in GitHub Desktop.

Select an option

Save psushi/31b039139bfdcfa2e87a84c915fd2670 to your computer and use it in GitHub Desktop.
Creating a proposal without Realms UI
import { getKeypair } from "./../../utils/general";
import { NextApiRequest, NextApiResponse } from "next";
import {
withCreateProposal,
getGovernanceProgramVersion,
TokenOwnerRecord,
getGovernanceAccounts,
pubkeyFilter,
getTokenOwnerRecord,
getTokenOwnerRecordForRealm,
VoteType,
CreateProposalArgs,
withInsertTransaction,
getGovernance,
withAddSignatory,
} from "@solana/spl-governance";
import {
PublicKey,
Transaction,
TransactionInstruction,
sendAndConfirmTransaction,
} from "@solana/web3.js";
import { getDevnetConnection } from "../../utils/general";
const TEST_PROGRAM_ID = new PublicKey(
"GovER5Lthms3bLBqWub97yVrMmEogzX7xNjdXpPPCVZw"
);
// Pubkey of an existing multisig realm
const MULTISIG_REALM = new PublicKey(
"8qfaVFsZJvo15hBHP66NsXYrnY1qSucayXyvSSCQeUdR"
);
// council mint pubkey
const COUNCIL_MINT = new PublicKey(
"FfhSaA7fX2UdMegBN4xd5CBX7nXn1QXNLsytXFfqfKJR"
);
const COUNCIL_MINT_GOVERNANCE = new PublicKey(
"EVJqJx3XYpKeugoW1cD4ae2AFEnvvveZHjSrDgxC5qbG"
);
const connection = getDevnetConnection();
const createProposal = async (req: NextApiRequest, res: NextApiResponse) => {
try {
// my local wallet
const LHT = getKeypair();
const programVersion = await getGovernanceProgramVersion(
connection,
TEST_PROGRAM_ID
);
console.log("programVersion", programVersion);
const tokenOwnerRecord = await getGovernanceAccounts(
connection,
TEST_PROGRAM_ID,
TokenOwnerRecord,
[pubkeyFilter(1, MULTISIG_REALM)!, pubkeyFilter(65, LHT.publicKey)!]
);
const governance = await getGovernance(connection, COUNCIL_MINT_GOVERNANCE);
console.log("tokenOwnerRecord", tokenOwnerRecord);
console.log("governance", governance);
// const tokenOwnerRecord = await getTokenOwnerRecordForRealm(
// connection,
// TEST_PROGRAM_ID,
// MULTI_REALMSIG,
// new PublicKey("FfhSaA7fX2UdMegBN4xd5CBX7nXn1QXNLsytXFfqfKJR"),
// LHT
// );
const proposalInstructions: TransactionInstruction[] = [];
const proposalAddress = await withCreateProposal(
proposalInstructions,
TEST_PROGRAM_ID,
programVersion,
MULTISIG_REALM,
COUNCIL_MINT_GOVERNANCE,
tokenOwnerRecord[0]!.pubkey,
"Test Proposal",
"This is a test proposal",
COUNCIL_MINT,
LHT.publicKey,
governance.account.proposalCount,
VoteType.SINGLE_CHOICE,
["Approve"],
true,
LHT.publicKey
);
// await withAddSignatory(
// proposalInstructions,
// TEST_PROGRAM_ID,
// programVersion,
// proposalAddress,
// tokenOwnerRecord[0]!.pubkey,
// LHT.publicKey,
// LHT.publicKey,
// LHT.publicKey
// );
const txn = new Transaction().add(...proposalInstructions);
console.log(txn);
const sig = await sendAndConfirmTransaction(connection, txn, [LHT, LHT]);
return res.json({
succes: true,
});
} catch (e) {
console.log(e);
return res.json({
succes: false,
});
}
};
export default createProposal;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment