-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateSquad.ts
53 lines (47 loc) · 2.09 KB
/
createSquad.ts
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
import * as multisig from "@sqds/multisig";
const { Permissions } = multisig.types;
import { Connection, Keypair } from "@solana/web3.js";
const fs = require('fs');
(async () => {
const connection = new Connection("https://api.devnet.solana.com");
// Random Public Key that will be used to derive a multisig PDA
// This will need to be a signer on the transaction
const createKey = Keypair.generate();
// Creator should be a Keypair or a Wallet Adapter wallet
const walletPath = "ww4AoktpBksE1M4zk6vWxujbqtaqhGY59VMuAxV4yxq.json";
const walletJSON = JSON.parse(fs.readFileSync(walletPath, "utf-8"));
const creator = Keypair.fromSecretKey(Uint8Array.from(walletJSON));
// Derive the multisig PDA
const [multisigPda] = multisig.getMultisigPda({
createKey: createKey.publicKey,
});
const [programConfigPda] = multisig.getProgramConfigPda({});
const programConfig = await multisig.accounts.ProgramConfig.fromAccountAddress(connection, programConfigPda);
const configTreasury = programConfig.treasury;
const signature = await multisig.rpc.multisigCreateV2({
connection: connection,
creator: creator,
// Must sign the transaction, unless the .rpc method is used.
createKey: createKey,
// The PDA of the multisig you are creating, derived by a random PublicKey
multisigPda,
// Here the config authority will be the system program
configAuthority: null,
// Create without any time-lock
timeLock: 0,
// List of the members to add to the multisig
members: [{
// Members Public Key
key: creator.publicKey,
// Granted Proposer, Voter, and Executor permissions
permissions: Permissions.all(),
}
],
// This means that there needs to be 2 votes for a transaction proposal to be approved
threshold: 1,
rentCollector: null,
treasury: configTreasury
});
console.log("New squad pubkey: ", multisigPda)
console.log("Multisig created: ", signature)
})();