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.

Revisions

  1. psushi revised this gist Aug 1, 2022. No changes.
  2. psushi revised this gist Aug 1, 2022. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion createProposal.ts
    Original file line number Diff line number Diff line change
    @@ -27,22 +27,27 @@ 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
    @@ -103,7 +108,7 @@ const createProposal = async (req: NextApiRequest, res: NextApiResponse) => {

    const sig = await sendAndConfirmTransaction(connection, txn, [LHT, LHT]);

    // const sig = "";

    return res.json({
    succes: true,
    });
  3. psushi created this gist Aug 1, 2022.
    118 changes: 118 additions & 0 deletions createProposal.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,118 @@
    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"
    );

    const MULTISIG_REALM = new PublicKey(
    "8qfaVFsZJvo15hBHP66NsXYrnY1qSucayXyvSSCQeUdR"
    );

    const COUNCIL_MINT = new PublicKey(
    "FfhSaA7fX2UdMegBN4xd5CBX7nXn1QXNLsytXFfqfKJR"
    );

    const COUNCIL_MINT_GOVERNANCE = new PublicKey(
    "EVJqJx3XYpKeugoW1cD4ae2AFEnvvveZHjSrDgxC5qbG"
    );

    const connection = getDevnetConnection();
    const createProposal = async (req: NextApiRequest, res: NextApiResponse) => {
    try {
    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]);

    // const sig = "";
    return res.json({
    succes: true,
    });
    } catch (e) {
    console.log(e);
    return res.json({
    succes: false,
    });
    }
    };

    export default createProposal;