SHA256
Подготовка перед деплоем в mainnet
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
const path = require("path");
|
||||
const BN = require("bn.js");
|
||||
const { Connection, Transaction, sendAndConfirmTransaction } = require("@solana/web3.js");
|
||||
const { getAssociatedTokenAddressSync, createAssociatedTokenAccountIdempotentInstruction, createMintToInstruction, TOKEN_PROGRAM_ID } = require("@solana/spl-token");
|
||||
const { withDepositGoverningTokens, PROGRAM_VERSION_V3, getTokenOwnerRecordAddress } = require("@solana/spl-governance");
|
||||
const { PublicKey, clusterUrl, loadKeypair, parseEnvConfig, resolveConfigPath } = require("./js_common");
|
||||
|
||||
async function main() {
|
||||
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 voter2 = loadKeypair(path.resolve(__dirname, "..", cfg.VOTER2_KEYPAIR));
|
||||
const realm = new PublicKey(cfg.REALM);
|
||||
const mint = new PublicKey(cfg.GOVERNING_MINT);
|
||||
const govPid = new PublicKey(cfg.SPL_GOVERNANCE_PROGRAM_ID);
|
||||
|
||||
const ata = getAssociatedTokenAddressSync(mint, voter2.publicKey, false, TOKEN_PROGRAM_ID);
|
||||
const mintTx = new Transaction().add(
|
||||
createAssociatedTokenAccountIdempotentInstruction(main.publicKey, ata, voter2.publicKey, mint, TOKEN_PROGRAM_ID),
|
||||
createMintToInstruction(mint, ata, main.publicKey, 1n, [], TOKEN_PROGRAM_ID)
|
||||
);
|
||||
const sigMint = await sendAndConfirmTransaction(conn, mintTx, [main], { commitment: "confirmed" });
|
||||
|
||||
const tor = await getTokenOwnerRecordAddress(govPid, realm, mint, voter2.publicKey);
|
||||
const ai = await conn.getAccountInfo(tor, "confirmed");
|
||||
let sigDeposit = "already_exists";
|
||||
if (!ai) {
|
||||
const ix = [];
|
||||
await withDepositGoverningTokens(ix, govPid, PROGRAM_VERSION_V3, realm, ata, mint, voter2.publicKey, main.publicKey, voter2.publicKey, new BN(1), true);
|
||||
sigDeposit = await sendAndConfirmTransaction(conn, new Transaction().add(...ix), [main, voter2], { commitment: "confirmed" });
|
||||
}
|
||||
|
||||
console.log("Второй голосующий подготовлен.");
|
||||
console.log("mintTx:", sigMint);
|
||||
console.log("depositTx:", sigDeposit);
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e?.message || e);
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in New Issue
Block a user