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

lang, spl, cli: Add associated_token keyword #790

Merged
merged 4 commits into from
Sep 24, 2021
Merged

Conversation

armaniferrante
Copy link
Member

@armaniferrante armaniferrante commented Sep 23, 2021

Adds a new associated_token keyword to create associated token accounts from within a derive macro. For example,

#[derive(Accounts)]
pub struct TestInitAssociatedToken<'info> {
    #[account(
        init,
        payer = payer,
	associated_token::mint = mint,
        associated_token::authority = payer,
    )]
    pub token: Account<'info, TokenAccount>,
    pub mint: Account<'info, Mint>,
    pub payer: Signer<'info>,
    pub rent: Sysvar<'info, Rent>,
    pub system_program: Program<'info, System>,
    pub token_program: Program<'info, Token>,
    pub associated_token_program: Program<'info, AssociatedToken>,
}

@armaniferrante armaniferrante merged commit 2c827bc into master Sep 24, 2021
@armaniferrante armaniferrante deleted the armani/ata branch September 24, 2021 00:06
@acamill
Copy link
Contributor

acamill commented Oct 4, 2021

Hello, this is something made to prevent having to create them in the front end? Similar to the init of state accounts done program side?

Is so, the owner is always the program?

@armaniferrante
Copy link
Member Author

Hello, this is something made to prevent having to create them in the front end? Similar to the init of state accounts done program side?

Is so, the owner is always the program?

Correct.

@acamill
Copy link
Contributor

acamill commented Oct 9, 2021

Getting some errors that I'm not sure how to debug for

    #[account(
        init,
        payer = user,
    // seeds = [user.key.as_ref(), token_program.key.as_ref(), state.redeemable_mint_key.as_ref()],
    // bump = Pubkey::find_program_address(&[user.key.as_ref(), token_program.key.as_ref(), state.redeemable_mint_key.as_ref()], associated_token_program.key).1,
	associated_token::mint = redeemable_mint,
        associated_token::authority = user,
    )]
    pub user_redeemable: Account<'info, TokenAccount>,

user is signer/mut, accounts are Boxed, mint is mut and initialized, of type Mint 🤔

thread 'main' panicked at 'Code not parseable: Error("expected `=`")', lang/syn/src/idl/file.rs:337:58
stack backtrace:
   0:        0x104e59d13 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h8d168763f08a78b9
   1:        0x104b8f37c - core::fmt::write::h0fa46d4891ed63f1
   2:        0x104e57dea - std::io::Write::write_fmt::hacbf9e10e17149ce
   3:        0x104e58faf - std::panicking::default_hook::{{closure}}::hee7cf38dedfa76fc
   4:        0x104e581fd - std::panicking::default_hook::hd12252412832a45f
   5:        0x104e57c99 - std::panicking::rust_panic_with_hook::h521fd09e07057893
   6:        0x104e76efa - std::panicking::begin_panic_handler::{{closure}}::h3588a5a9cca9e8e5
   7:        0x104e76e68 - std::sys_common::backtrace::__rust_end_short_backtrace::h86522c151a195ff9
   8:        0x104e76e10 - _rust_begin_unwind
   9:        0x1050547af - core::panicking::panic_fmt::h8ab5bf5f27d0a26a
  10:        0x105054a95 - core::result::unwrap_failed::ha249df8fad19d4e8
  11:        0x104aef5f7 - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::hd2560d15db82a269
  12:        0x104b1e6d1 - anchor_syn::idl::file::parse_account_derives::h652a38fa632f8a91
  13:        0x104a1e6a0 - anchor_syn::idl::file::parse::he376b3ce809c9234
  14:        0x104aafc30 - anchor_cli::build_cwd::h83f0492aec3c3fd5
  15:        0x104aaf351 - anchor_cli::build_all::hc90a5361b64b45b7
  16:        0x104a1d6c4 - anchor_cli::build::h20143c4510e09e46
  17:        0x104a24e93 - anchor_cli::test::{{closure}}::h3f0d22222543c4a2
  18:        0x104a10e0f - anchor_cli::entry::h0bf337af26559e56
  19:        0x1049412ad - anchor::main::h2c4617e6bfc29ffa
  20:        0x10493f08a - std::sys_common::backtrace::__rust_begin_short_backtrace::h1cca6f7e642f44ce
  21:        0x104941787 - _main

@acamill
Copy link
Contributor

acamill commented Oct 9, 2021

Btw on your example above @armaniferrante payer is not marked as mut, that wouldn't work right?

@acamill
Copy link
Contributor

acamill commented Oct 9, 2021

Ok the issue was my local anchor-cli version that did not match. Thanks to @cqfd

@armaniferrante
Copy link
Member Author

Btw on your example above @armaniferrante payer is not marked as mut, that wouldn't work right?

Payer should be marked mut. It coincidentally work if it's not mutable if another account, e.g. the tx fee payer, is already marked mutable.

@acamill
Copy link
Contributor

acamill commented Oct 9, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants