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

Incorrect code generation for creating a Regular Token Account #8

Closed
julianzamt opened this issue Aug 29, 2023 · 2 comments
Closed
Assignees
Labels
Bug This is an item that causes unwanted behavior Enhancement This improve the product or Código's source code

Comments

@julianzamt
Copy link

julianzamt commented Aug 29, 2023

Describe the bug
Not all Token accounts must be ATAs. Some users may prefer the old pattern, where N token accounts from a Mint can be owned by the same wallet.
However, using csl_spl_token.initialize_account3 in combination with csl_spl_token.Account generates code as if the account to be initialized is a PDA, but it cannot be, as it must be created beforehand. This is wrong and must be fixed.

Also, a phantasmagoric account is generated, unnecessarilly polluting the accounts array.

To Reproduce

methods:
  - name: create_mint_and_account
    uses:
      - csl_spl_token.initialize_mint2
      - csl_spl_token.initialize_account3
    inputs:
      - name: mint
        type: csl_spl_token.Mint
        solana:
          attributes: [ init ]
      - name: regular_token_account
        type: csl_spl_token.Account
        solana:
          attributes: [ init ]

processor:
Wrong "PDA" code

Unnecessary extra seeds args:

pub fn process_create_nft_without_optional_fields(
program_id: &Pubkey,
accounts: &[AccountInfo],
regular_token_account_seed_wallet: Pubkey,
regular_token_account_seed_token_program: Pubkey,
regular_token_account_seed_mint: Pubkey,
	)
// Derive PDAs
let (regular_token_account_pubkey, regular_token_account_bump) = Pubkey::find_program_address(
	&[regular_token_account_seed_wallet.as_ref(), regular_token_account_seed_token_program.as_ref(), 
regular_token_account_seed_mint.as_ref()],
&Pubkey::from_str("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL").unwrap(),
);

And also, PDA creation, which is wrong, but further, it is created as if it is owned by the local program

let space = spl_token::state::Account::LEN;
let rent = Rent::get()?;
let rent_minimum_balance = rent.minimum_balance(space);

invoke_signed(
	&create_account(
	&fee_payer_info.key,
	&regular_token_account_info.key,
	rent_minimum_balance,
	space as u64,
	program_id,
),
&[fee_payer_info.clone(), regular_token_account_info.clone()],
&[&[regular_token_account_seed_wallet.as_ref(), regular_token_account_seed_token_program.as_ref(), regular_token_account_seed_mint.as_ref(), &[regular_token_account_bump]]],
)?;

"Phantasmagoric" unrequired extra account:

let account_info_iter = &mut accounts.iter();
let fee_payer_info = next_account_info(account_info_iter)?;
let mint_info = next_account_info(account_info_iter)?;
let regular_token_account_info = next_account_info(account_info_iter)?;
let system_program_info = next_account_info(account_info_iter)?;
***let account_info = next_account_info(account_info_iter)?;*** ----------------> ???????
let csl_spl_token_v_0_0_0_info = next_account_info(account_info_iter)?;

Expected behavior
To generate code for regular account creation.

Código CLI version:

  • Version v0.8
@julianzamt julianzamt added the Triage This item needs to be prioritize label Aug 29, 2023
@JazielGuerrero JazielGuerrero added Bug This is an item that causes unwanted behavior Enhancement This improve the product or Código's source code high and removed Triage This item needs to be prioritize labels Aug 30, 2023
@JazielGuerrero
Copy link
Collaborator

The account named account is not a ghost account. Because your ix is using initialize_account3, this ix has an input named account and is coming from there:

  - name: initialize_account3
    solana:
      default-payer: false
    summary: Like InitializeAccount2, but does not require the Rent sysvar to be provided
    inputs:
      - name: account
        type: sol:account_info
        description: The account to initialize.
        solana:
          attributes: [ mut ]
      - name: mint
        type: Mint
        description: The mint this account will be associated with.
      - name: owner
        type: sol:pubkey
        description: The new account's owner/multisignature.

@JazielGuerrero
Copy link
Collaborator

I created the following issue: #26 to keep track of the other part of this ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is an item that causes unwanted behavior Enhancement This improve the product or Código's source code
Projects
None yet
Development

No branches or pull requests

2 participants