Migrating from MultisigCreate v1 to v2

Squads has recently made a new update to their program which introduced rent collection of account data for transactions that have been initiated through the Squads program.

Here's how to use the new Multisig Create V2 instruction.

Typescript

    const creator = fundedKeypairExample();

    const createKey = Keypair.generate();
    
    const [multisigPda] = multisig.getMultisigPda({
      createKey: createKey.publicKey,
    });
    
  
    const programConfigPda = getProgramConfigPda({})[0];

    const programConfig =
      await multisig.accounts.ProgramConfig.fromAccountAddress(
        connection,
        programConfigPda
      );

    const configTreasury = programConfig.treasury;

    const tx = multisig.transactions.multisigCreateV2({
      blockhash: (await connection.getLatestBlockhash()).blockhash,
      treasury: configTreasury,
      createKey: createKey.publicKey,
      creator: creator.publicKey,
      multisigPda,
      configAuthority: null,
      timeLock: 0,
      threshold: 1,
      rentCollector: null,
      members: [
        {
          key: members.almighty.publicKey,
          permissions: Permissions.all(),
        },
        {
          key: members.almighty.publicKey,
          permissions: Permissions.all(),
        },
      ],
      programId,
    });

    
    tx.sign([creator, createKey]);

Rust


        let rpc_client = RpcClient::new(rpc_url);

        let progress = ProgressBar::new_spinner().with_message("Sending transaction...");
        progress.enable_steady_tick(Duration::from_millis(100));

        let blockhash = rpc_client
            .get_latest_blockhash()
            .await
            .expect("Failed to get blockhash");

        let random_keypair = Keypair::new();

        let multisig_key = get_multisig_pda(&random_keypair.pubkey(), Some(&program_id));

        let program_config_pda = get_program_config_pda(Some(&program_id));

        let program_config = rpc_client
            .get_account(&program_config_pda.0)
            .await
            .expect("Failed to fetch program config account");

        let mut program_config_data = program_config.data.as_slice();

        let treasury = ProgramConfig::try_deserialize(&mut program_config_data)
            .unwrap()
            .treasury;

        let message = Message::try_compile(
            &transaction_creator,
            &[Instruction {
                accounts: MultisigCreateV2Accounts {
                    create_key: random_keypair.pubkey(),
                    creator: transaction_creator,
                    multisig: multisig_key.0,
                    system_program: system_program::id(),
                    program_config: program_config_pda.0,
                    treasury,
                }
                .to_account_metas(Some(false)),
                data: MultisigCreateV2Data {
                    args: MultisigCreateArgsV2 {
                        config_authority,
                        members,
                        threshold,
                        time_lock: 0,
                        memo: None,
                        rent_collector,
                    },
                }
                .data(),
                program_id,
            }],
            &[],
            blockhash,
        )
        .unwrap();

        let transaction = VersionedTransaction::try_new(
            VersionedMessage::V0(message),
            &[
                &*transaction_creator_keypair,
                &random_keypair as &dyn Signer,
            ],
        )
        .expect("Failed to create transaction");

        let signature = send_and_confirm_transaction(&transaction, &rpc_client).await?;

Last updated