Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Token-2022 program supports on associated_token constraint #2434

Closed
grhbit opened this issue Mar 14, 2023 · 2 comments
Closed

Missing Token-2022 program supports on associated_token constraint #2434

grhbit opened this issue Mar 14, 2023 · 2 comments
Labels
bug Something isn't working lang

Comments

@grhbit
Copy link

grhbit commented Mar 14, 2023

Hello, I'm glad to hear that Anchor supports Token-2022 Program now!
Anchor v0.27.0 supports Token-2022 Program and many cases work well.

But I found two error cases for associated_token constraint.

Case 1

Use associated_token with init_if_need

#[derive(Accounts)]
pub struct Case1<'info> {
    #[account(mut)]
    pub authority: Signer<'info>,
    #[account(
        init_if_needed,
        payer = authority,
        associated_token::mint = mint,
        associated_token::authority = authority,
    )]
    pub token_account: InterfaceAccount<'info, TokenAccount>,
    #[account(
        mint::decimals = 9,
        mint::authority = authority,
    )]
    pub mint: InterfaceAccount<'info, Mint>,
    pub token_program: Interface<'info, TokenInterface>,
    pub associated_token_program: Program<'info, AssociatedToken>,
    pub system_program: Program<'info, System>,
}

Error Messages:
Error: AnchorError caused by account: token_account. Error Code: ConstraintAssociated. Error Number: 2009. Error Message: An associated constraint was violated.

let __associated_token_address = ::anchor_spl::associated_token::get_associated_token_address(&wallet_address, &#spl_token_mint_address.key());

Case 2

Use associated_token constraint

#[derive(Accounts)]
pub struct Case2<'info> {
    pub authority: SystemAccount<'info>,
    #[account(
        associated_token::mint = mint,
        associated_token::authority = authority,
    )]
    pub token_account: InterfaceAccount<'info, TokenAccount>,
    pub mint: InterfaceAccount<'info, Mint>,
}

Error: AnchorError caused by account: token_account. Error Code: AccountNotAssociatedTokenAccount. Error Number: 3014. Error Message: The given account is not the associated token account.

if pa.key() != ::anchor_spl::associated_token::get_associated_token_address(&#owner.key(), &#mint.key()) {

Both cases did not use token_program to make ATA.

@valentinmadrid
Copy link

@grhbit Please let me know if this works for you.

@acheroncrypto acheroncrypto added bug Something isn't working lang labels Oct 22, 2023
@acheroncrypto
Copy link
Collaborator

Fixed in #2603

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lang
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants