Skip to content

Reason for stack violation warnings inside anchor macro generation #63

Open
@sunguru98

Description

@sunguru98

The anchor token extensions macro inside the Accounts struct was triggering the token extensions stack violations warnings after fiddling with the expanded code using cargo expand

The following code creates the "too many large-sized variables" warning

for e in extensions {
      match e {
            ::anchor_spl::token_interface::spl_token_2022::extension::ExtensionType::GroupPointer => {
                let cpi_program = token_program.to_account_info();
                let accounts = ::anchor_spl::token_interface::GroupPointerInitialize {
                    token_program_id: token_program.to_account_info(),
                    mint: mint.to_account_info(),
                };
                let cpi_ctx = anchor_lang::context::CpiContext::new(
                    cpi_program,
                    accounts,
                );
                ::anchor_spl::token_interface::group_pointer_initialize(
                    cpi_ctx,
                    Option::<anchor_lang::prelude::Pubkey>::None,
                    Option::<anchor_lang::prelude::Pubkey>::None,
                )?;
            }
            ::anchor_spl::token_interface::spl_token_2022::extension::ExtensionType::GroupMemberPointer => {
                let cpi_program = token_program.to_account_info();
                let accounts = ::anchor_spl::token_interface::GroupMemberPointerInitialize {
                    token_program_id: token_program.to_account_info(),
                    mint: mint.to_account_info(),
                };
                let cpi_ctx = anchor_lang::context::CpiContext::new(
                    cpi_program,
                    accounts,
                );
                ::anchor_spl::token_interface::group_member_pointer_initialize(
                    cpi_ctx,
                    Option::<anchor_lang::prelude::Pubkey>::Some(manager.key()),
                    Option::<anchor_lang::prelude::Pubkey>::None,
                )?;
            }
            ::anchor_spl::token_interface::spl_token_2022::extension::ExtensionType::MetadataPointer => {
                let cpi_program = token_program.to_account_info();
                let accounts = ::anchor_spl::token_interface::MetadataPointerInitialize {
                    token_program_id: token_program.to_account_info(),
                    mint: mint.to_account_info(),
                };
                let cpi_ctx = anchor_lang::context::CpiContext::new(
                    cpi_program,
                    accounts,
                );
                ::anchor_spl::token_interface::metadata_pointer_initialize(
                    cpi_ctx,
                    Option::<
                        anchor_lang::prelude::Pubkey,
                    >::Some(authority.key()),
                    Option::<anchor_lang::prelude::Pubkey>::Some(mint.key()),
                )?;
            }
            ::anchor_spl::token_interface::spl_token_2022::extension::ExtensionType::MintCloseAuthority => {
                let cpi_program = token_program.to_account_info();
                let accounts = ::anchor_spl::token_interface::MintCloseAuthorityInitialize {
                    token_program_id: token_program.to_account_info(),
                    mint: mint.to_account_info(),
                };
                let cpi_ctx = anchor_lang::context::CpiContext::new(
                    cpi_program,
                    accounts,
                );
                ::anchor_spl::token_interface::mint_close_authority_initialize(
                    cpi_ctx,
                    Option::<
                        &anchor_lang::prelude::Pubkey,
                    >::Some(&manager.key()),
                )?;
            }
            ::anchor_spl::token_interface::spl_token_2022::extension::ExtensionType::TransferHook => {
                let cpi_program = token_program.to_account_info();
                let accounts = ::anchor_spl::token_interface::TransferHookInitialize {
                    token_program_id: token_program.to_account_info(),
                    mint: mint.to_account_info(),
                };
                let cpi_ctx = anchor_lang::context::CpiContext::new(
                    cpi_program,
                    accounts,
                );
                ::anchor_spl::token_interface::transfer_hook_initialize(
                    cpi_ctx,
                    Option::<
                        anchor_lang::prelude::Pubkey,
                    >::Some(authority.key()),
                    Option::<anchor_lang::prelude::Pubkey>::None,
                )?;
            }
            ::anchor_spl::token_interface::spl_token_2022::extension::ExtensionType::NonTransferable => {
                let cpi_program = token_program.to_account_info();
                let accounts = ::anchor_spl::token_interface::NonTransferableMintInitialize {
                    token_program_id: token_program.to_account_info(),
                    mint: mint.to_account_info(),
                };
                let cpi_ctx = anchor_lang::context::CpiContext::new(
                    cpi_program,
                    accounts,
                );
                ::anchor_spl::token_interface::non_transferable_mint_initialize(
                    cpi_ctx,
                )?;
            }
            ::anchor_spl::token_interface::spl_token_2022::extension::ExtensionType::PermanentDelegate => {
                let cpi_program = token_program.to_account_info();
                let accounts = ::anchor_spl::token_interface::PermanentDelegateInitialize {
                    token_program_id: token_program.to_account_info(),
                    mint: mint.to_account_info(),
                };
                let cpi_ctx = anchor_lang::context::CpiContext::new(
                    cpi_program,
                    accounts,
                );
                ::anchor_spl::token_interface::permanent_delegate_initialize(
                    cpi_ctx,
                    Option::<
                        &anchor_lang::prelude::Pubkey,
                    >::Some(
                            &args
                                .permanent_delegate
                                .unwrap_or_else(|| manager.key())
                                .key(),
                        )
                        .unwrap(),
                )?;
            }
            _ => {}
     }
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions