SHA256
102 lines
4.2 KiB
JavaScript
102 lines
4.2 KiB
JavaScript
#!/usr/bin/env node
|
|
"use strict";
|
|
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
const { Connection, PublicKey, Transaction, sendAndConfirmTransaction } = require("@solana/web3.js");
|
|
const { TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, createBurnCheckedInstruction } = require("@solana/spl-token");
|
|
const {
|
|
PROGRAM_VERSION_V3,
|
|
Vote,
|
|
YesNoVote,
|
|
VoteType,
|
|
withCreateProposal,
|
|
withInsertTransaction,
|
|
withSignOffProposal,
|
|
withCastVote,
|
|
getTokenOwnerRecordAddress,
|
|
} = require("@solana/spl-governance");
|
|
const { clusterUrl, ensureDir, loadKeypair, nowStamp, parseEnvConfig, resolveConfigPath, toInstructionData } = require("./js_common");
|
|
|
|
async function main() {
|
|
const currentOwnerWallet = process.argv[3];
|
|
const nftMintStr = process.argv[4];
|
|
if (!currentOwnerWallet || !nftMintStr) throw new Error("Usage: node 08_propose_vote_burn_nft.js <config.env> <current_owner_wallet> <nft_mint>");
|
|
|
|
const cfg = parseEnvConfig(resolveConfigPath(process.argv[2], "nft-flow.config.env"));
|
|
const conn = new Connection(clusterUrl(cfg.CLUSTER), "confirmed");
|
|
const main = loadKeypair(path.resolve(__dirname, "..", cfg.MAIN_KEYPAIR));
|
|
const realm = new PublicKey(cfg.REALM);
|
|
const governance = new PublicKey(cfg.GOVERNANCE);
|
|
const governingMint = new PublicKey(cfg.GOVERNING_MINT);
|
|
const govPid = new PublicKey(cfg.SPL_GOVERNANCE_PROGRAM_ID);
|
|
const nftMint = new PublicKey(nftMintStr);
|
|
const currentOwner = new PublicKey(currentOwnerWallet);
|
|
const mainTor = await getTokenOwnerRecordAddress(govPid, realm, governingMint, main.publicKey);
|
|
const sourceAta = getAssociatedTokenAddressSync(nftMint, currentOwner, false, TOKEN_2022_PROGRAM_ID);
|
|
|
|
const ixCreate = [];
|
|
const proposal = await withCreateProposal(
|
|
ixCreate,
|
|
govPid,
|
|
PROGRAM_VERSION_V3,
|
|
realm,
|
|
governance,
|
|
mainTor,
|
|
`Burn NFT ${nftMint.toBase58().slice(0, 8)}`,
|
|
cfg.NFT_METADATA_URI || "https://arweave.net/",
|
|
governingMint,
|
|
main.publicKey,
|
|
undefined,
|
|
VoteType.SINGLE_CHOICE,
|
|
["Approve"],
|
|
true,
|
|
main.publicKey
|
|
);
|
|
const txCreate = await sendAndConfirmTransaction(conn, new Transaction().add(...ixCreate), [main], { commitment: "confirmed" });
|
|
|
|
const burnIx = [toInstructionData(createBurnCheckedInstruction(sourceAta, nftMint, governance, 1n, 0, [], TOKEN_2022_PROGRAM_ID))];
|
|
const ixInsert = [];
|
|
const proposalTx = await withInsertTransaction(ixInsert, govPid, PROGRAM_VERSION_V3, governance, proposal, mainTor, main.publicKey, 0, 0, 0, burnIx, main.publicKey);
|
|
const txInsert = await sendAndConfirmTransaction(conn, new Transaction().add(...ixInsert), [main], { commitment: "confirmed" });
|
|
|
|
const ixSign = [];
|
|
withSignOffProposal(ixSign, govPid, PROGRAM_VERSION_V3, realm, governance, proposal, main.publicKey, undefined, mainTor);
|
|
const txSign = await sendAndConfirmTransaction(conn, new Transaction().add(...ixSign), [main], { commitment: "confirmed" });
|
|
|
|
const vote = Vote.fromYesNoVote(YesNoVote.Yes);
|
|
const ixVote1 = [];
|
|
await withCastVote(ixVote1, govPid, PROGRAM_VERSION_V3, realm, governance, proposal, mainTor, mainTor, main.publicKey, governingMint, vote, main.publicKey);
|
|
const txVote1 = await sendAndConfirmTransaction(conn, new Transaction().add(...ixVote1), [main], { commitment: "confirmed" });
|
|
|
|
const runs = path.resolve(__dirname, "..", cfg.RUNS_DIR || "./local/runs");
|
|
ensureDir(runs);
|
|
const report = {
|
|
type: "burn_nft",
|
|
realm: realm.toBase58(),
|
|
governance: governance.toBase58(),
|
|
proposal: proposal.toBase58(),
|
|
proposalTransaction: proposalTx.toBase58(),
|
|
nftMint: nftMint.toBase58(),
|
|
currentOwnerWallet: currentOwner.toBase58(),
|
|
sourceAta: sourceAta.toBase58(),
|
|
txCreate,
|
|
txInsert,
|
|
txSign,
|
|
txVote1,
|
|
};
|
|
const reportPath = path.join(runs, `${nowStamp()}_proposal_burn_${currentOwner.toBase58().slice(0, 8)}.json`);
|
|
fs.writeFileSync(reportPath, JSON.stringify(report, null, 2));
|
|
|
|
console.log("Burn proposal создан и проголосован.");
|
|
console.log("proposal:", report.proposal);
|
|
console.log("proposalTransaction:", report.proposalTransaction);
|
|
console.log("sourceAta:", report.sourceAta);
|
|
console.log("report:", reportPath);
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e?.message || e);
|
|
process.exit(1);
|
|
});
|