Squads-Protocol / v4-examples

SDK examples for Squads V4
5 stars 2 forks source link

unable to create multisig using cpi in this example #4

Open pruales opened 2 months ago

pruales commented 2 months ago

I get this error:
AnchorError caused by account: multisig. Error Code: AccountNotInitialized. Error Number: 3012. Error Message: The program expected this account to be already initialized.

import * as anchor from "@coral-xyz/anchor";
import { Program } from "@coral-xyz/anchor";
import { TsumoriCredibleAccountPoc } from "../target/types/tsumori_credible_account_poc";
import { generateFundedKeypair } from "./util";

const SQUADS_PROGRAM_ID = new anchor.web3.PublicKey(
  "SQDS4ep65T869zMMBKyuUq6aD6EgTu8psMjkvj52pCf"
);
function toUtfBytes(str: string): Uint8Array {
  return new TextEncoder().encode(str);
}
const SEED_PREFIX = toUtfBytes("multisig");
const SEED_MULTISIG = toUtfBytes("multisig");
const SEED_PROGRAM_CONFIG = toUtfBytes("program_config");

const getProgramConfigPda = () => {
  return anchor.web3.PublicKey.findProgramAddressSync(
    [SEED_PREFIX, SEED_PROGRAM_CONFIG],
    SQUADS_PROGRAM_ID
  );
};

const getMultisigPDA = (createKey: anchor.web3.PublicKey) => {
  return anchor.web3.PublicKey.findProgramAddressSync(
    [SEED_PREFIX, SEED_MULTISIG, createKey.toBytes()],
    SQUADS_PROGRAM_ID
  );
};

describe("tsumori-credible-account-poc", () => {
  const createKey = anchor.web3.Keypair.generate();
  const [multisigPda] = getMultisigPDA(createKey.publicKey);
  const [programConfig] = getProgramConfigPda();

  anchor.setProvider(anchor.AnchorProvider.env());

  const program = anchor.workspace
    .TsumoriCredibleAccountPoc as Program<TsumoriCredibleAccountPoc>;

  it("create multisig", async () => {
    const creator = await generateFundedKeypair(
      anchor.getProvider().connection
    );

    const wallet = new anchor.Wallet(creator);
    const tx = await program.methods
      .createMultisig()
      .accounts({
        signer: creator.publicKey,
        createKey: createKey.publicKey,
        multisig: multisigPda,
        systemProgram: anchor.web3.SystemProgram.programId,
        programConfig,
        sqaudsProgramTreasury: anchor.web3.SystemProgram.programId,
        squadsMultisigProgram: SQUADS_PROGRAM_ID,
      })
      .signers([wallet.payer, createKey])
      .rpc();
    console.log("Your transaction signature", tx);
  });
});
joeymeere commented 2 months ago

Can you provide a minimal example in the context of this repo? It's a bit difficult to debug this with the edits that have been made + custom program added.

pruales commented 2 months ago

Can you provide a minimal example in the context of this repo? It's a bit difficult to debug this with the edits that have been made + custom program added.

hey yeah its just a copy of the create multisig example in this repo.