|
| 1 | +import * as anchor from "@coral-xyz/anchor"; |
| 2 | +import * as multisig from "@sqds/multisig"; |
| 3 | +import { |
| 4 | + LaunchpadClient, |
| 5 | + METADAO_MULTISIG_VAULT, |
| 6 | +} from "@metadaoproject/futarchy/v0.7"; |
| 7 | +import { PublicKey, Transaction, TransactionMessage } from "@solana/web3.js"; |
| 8 | + |
| 9 | +// Set the launch address before running the script |
| 10 | +const launch = new PublicKey(""); |
| 11 | + |
| 12 | +// Set the number of seconds to extend the launch by |
| 13 | +const durationSeconds = 60 * 60 * 24; // 1 day |
| 14 | + |
| 15 | +const provider = anchor.AnchorProvider.env(); |
| 16 | + |
| 17 | +// Payer MUST be a signer with permissions to propose transactions on MetaDAO's multisig |
| 18 | +const payer = provider.wallet["payer"]; |
| 19 | + |
| 20 | +const launchpad: LaunchpadClient = LaunchpadClient.createClient({ provider }); |
| 21 | + |
| 22 | +// MetaDAO Squads multisig and vault addresses |
| 23 | +const metadaoSquadsMultisig = new PublicKey( |
| 24 | + "8N3Tvc6B1wEVKVC6iD4s6eyaCNqX2ovj2xze2q3Q9DWH", |
| 25 | +); |
| 26 | +const metadaoSquadsMultisigVault = METADAO_MULTISIG_VAULT; |
| 27 | + |
| 28 | +export const extendLaunch = async () => { |
| 29 | + const launchAccount = await launchpad.getLaunch(launch); |
| 30 | + |
| 31 | + console.log(`Extending launch: ${launch.toBase58()}`); |
| 32 | + console.log(`Current seconds_for_launch: ${launchAccount.secondsForLaunch}`); |
| 33 | + console.log(`Extension: ${durationSeconds} seconds`); |
| 34 | + console.log( |
| 35 | + `New seconds_for_launch: ${launchAccount.secondsForLaunch + durationSeconds}`, |
| 36 | + ); |
| 37 | + |
| 38 | + // Build the extend_launch instruction |
| 39 | + const extendLaunchIx = await launchpad |
| 40 | + .extendLaunchIx({ |
| 41 | + launch, |
| 42 | + durationSeconds, |
| 43 | + admin: metadaoSquadsMultisigVault, |
| 44 | + }) |
| 45 | + .instruction(); |
| 46 | + |
| 47 | + // Build the transaction message with the multisig vault as payer |
| 48 | + const transactionMessage = new TransactionMessage({ |
| 49 | + instructions: [extendLaunchIx], |
| 50 | + payerKey: metadaoSquadsMultisigVault, |
| 51 | + recentBlockhash: (await provider.connection.getLatestBlockhash()).blockhash, |
| 52 | + }); |
| 53 | + |
| 54 | + // Log the transaction message as base64 |
| 55 | + const compiledMessage = transactionMessage.compileToLegacyMessage(); |
| 56 | + const base64Message = Buffer.from(compiledMessage.serialize()).toString( |
| 57 | + "base64", |
| 58 | + ); |
| 59 | + console.log("\nTransaction message (base64):"); |
| 60 | + console.log(base64Message); |
| 61 | + |
| 62 | + // TODO: Uncomment this when ready to extend the launch |
| 63 | + return; |
| 64 | + |
| 65 | + // Fetch the current multisig state to get the next transaction index |
| 66 | + const metaDaoSquadsMultisigAccount = |
| 67 | + await multisig.accounts.Multisig.fromAccountAddress( |
| 68 | + provider.connection, |
| 69 | + metadaoSquadsMultisig, |
| 70 | + ); |
| 71 | + |
| 72 | + const transactionIndex = |
| 73 | + BigInt(metaDaoSquadsMultisigAccount.transactionIndex.toString()) + 1n; |
| 74 | + |
| 75 | + // Create vault transaction instruction |
| 76 | + const vaultTxCreateIx = multisig.instructions.vaultTransactionCreate({ |
| 77 | + multisigPda: metadaoSquadsMultisig, |
| 78 | + transactionIndex, |
| 79 | + creator: payer.publicKey, |
| 80 | + rentPayer: payer.publicKey, |
| 81 | + vaultIndex: 0, |
| 82 | + ephemeralSigners: 0, |
| 83 | + transactionMessage, |
| 84 | + }); |
| 85 | + |
| 86 | + // Create proposal instruction |
| 87 | + const proposalCreateIx = multisig.instructions.proposalCreate({ |
| 88 | + multisigPda: metadaoSquadsMultisig, |
| 89 | + transactionIndex, |
| 90 | + creator: payer.publicKey, |
| 91 | + rentPayer: payer.publicKey, |
| 92 | + isDraft: false, |
| 93 | + }); |
| 94 | + |
| 95 | + // Build, sign, and send the transaction |
| 96 | + const tx = new Transaction().add(vaultTxCreateIx, proposalCreateIx); |
| 97 | + tx.recentBlockhash = ( |
| 98 | + await provider.connection.getLatestBlockhash() |
| 99 | + ).blockhash; |
| 100 | + tx.feePayer = payer.publicKey; |
| 101 | + tx.sign(payer); |
| 102 | + |
| 103 | + const txHash = await provider.connection.sendRawTransaction(tx.serialize()); |
| 104 | + await provider.connection.confirmTransaction(txHash, "confirmed"); |
| 105 | + |
| 106 | + const [proposalPda] = multisig.getProposalPda({ |
| 107 | + multisigPda: metadaoSquadsMultisig, |
| 108 | + transactionIndex, |
| 109 | + }); |
| 110 | + |
| 111 | + console.log("\nVault transaction + proposal created successfully!"); |
| 112 | + console.log("Transaction signature:", txHash); |
| 113 | + console.log("Proposal index:", transactionIndex.toString()); |
| 114 | + console.log("Proposal PDA:", proposalPda.toBase58()); |
| 115 | + console.log("Go ahead and approve/execute the transaction through Squads."); |
| 116 | +}; |
| 117 | + |
| 118 | +extendLaunch().catch(console.error); |
0 commit comments