1

** The code is functional. The issue was with the test framework. See solution **.

I'm trying to create a group mint with token-2022.

I've followed the steps in:

https://github.com/solana-labs/solana-program-library/blob/master/token/program-2022-test/tests/token_group_initialize.rs

Being an interface, i've used the spl-token-2022 program id with all of the instructions. Have not provided my own implementations.

The instructions in order (full code at the end of the question):

  1. create mint account (with enough lamports to cover group pointer)
  2. initialise the group pointer extension on the mint created in (1)
  3. initialise the mint
  4. initialize_group

Instructions 1-3 execute correctly. However at step (4) I'm hit with "Invalid Instruction".

[2024-01-07T19:33:59.051326000Z DEBUG solana_runtime::message_processor::stable_log] Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [2]
[2024-01-07T19:33:59.051718000Z DEBUG solana_runtime::message_processor::stable_log] Program log: Error: Invalid instruction

Full code:


pub fn create_group_mint_combined(
    payer: &Signer,
    group_mint: &Signer,
    authority: &AccountInfo,
    authority_seeds: &[&[u8]],
    max_group_size: u32,
) -> Result {
    let rent = Rent::get()?;
    let mint_space =
        ExtensionType::try_calculate_account_len::(&[ExtensionType::GroupPointer])?;
    let mint_rent_lamports = rent.minimum_balance(mint_space);
    invoke(
        &system_instruction::create_account(
            &payer.key(),
            &group_mint.key(),
            mint_rent_lamports,
            mint_space.try_into().unwrap(),
            &spl_token_2022::ID,
        ),
        &[payer.to_account_info(), group_mint.to_account_info()],
    )?;
    let initialize_extension = spl_token_2022::extension::group_pointer::instruction::initialize(
        &spl_token_2022::ID,
        &group_mint.key(),
        Some(authority.key()),
        Some(group_mint.key()),
    )
    .unwrap();
    invoke_signed(
        &initialize_extension,
        &[
            group_mint.to_account_info(),
            authority.to_account_info(),
            group_mint.to_account_info(),
        ],
        &[authority_seeds],
    )?;


    let initialize_ix = initialize_mint2(
        &spl_token_2022::ID,
        &group_mint.key(),
        &authority.key(),
        Some(&authority.key()),
        0,
    )
    .unwrap();
    msg!("Invoke initialise mint2");
    invoke_signed(
        &initialize_ix,
        &[group_mint.to_account_info()],
        &[authority_seeds],
    )?;

    msg!("Initialize group");
    
    invoke_signed(
        &initialize_group(
            &spl_token_2022::ID,
            &group_mint.key(),
            &group_mint.key(),
            &authority.key(),
            // Pubkey::new_unique().into(),
            Some(authority.key()),
            max_group_size,
        ),
        &[
            group_mint.to_account_info(),
            authority.to_account_info(),
        ],
        &[authority_seeds],
    )?;
    msg!("Invoked");
    Ok(())
}

1 Answer 1

1

Turns out I was missing a little snippet from my test configuration.

The Invalid Instruction error was due to an spl-token-2022 library version mismatch in the framework. The following works to fix it:

program.prefer_bpf(false);
program.add_program(
  "spl_token_2022",
  spl_token_2022::id(),
  processor!(Processor::process),
);
1
  • I'm running into this same problem, i'm not sure where you added this snippet. I'm using the function ` token_group_initialize()?;` from anchor_spl::token_2022_extensions::token_group_initialize Commented Jun 13 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.