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