coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.39k stars 1.26k forks source link

Rename `TokenMetadataInitialize` field `token_program_id` to `program_id` #3073

Open jacksondoherty opened 1 week ago

jacksondoherty commented 1 week ago

This better matches the spl_token_metadata_interface::instruction::initialize function.

The Token Metadata Interface (sRFC 17) is designed to work with external metadata programs, not just Token2022. These external programs might not be token programs, just metadata implementations.

In this example, I pass set an external metadata program as the token_program_id field which works but is confusing.

let accounts = TokenMetadataInitialize {
    token_program_id: ctx.accounts.metadata_program.to_account_info(), // <-- Here
    mint: ctx.accounts.mint.to_account_info(),
    metadata: ctx.accounts.metadata.to_account_info(),
    mint_authority: ctx.accounts.vending_machine_pda.to_account_info(),
    update_authority: ctx.accounts.vending_machine_pda.to_account_info(),
};
let vending_machine_pda_seeds: &[&[u8]; 2] = &[
    VENDING_MACHINE_PDA_SEED.as_bytes(),
    &[ctx.bumps.vending_machine_pda],
];
let signer_seeds = &[&vending_machine_pda_seeds[..]];
let cpi_ctx = CpiContext::new_with_signer(
    ctx.accounts.metadata_program.to_account_info(),
    accounts,
    signer_seeds,
);
token_metadata_initialize(
    cpi_ctx,
    token_metadata.name,
    token_metadata.symbol,
    token_metadata.uri,
)?;
jacksondoherty commented 1 week ago

If this moves ahead, we should do similarly for TokenGroupInitialize and TokenMemberInitialize

acheroncrypto commented 1 week ago

I'm usually against making breaking name changes, but we can make an exception for this case since all other fields looks to be the exact same as the spl_token_metadata_interface::instruction::initialize function's parameters, so it makes sense program_id is also the same. It also wouldn't be difficult to adapt this change since it's the only field that changes.

Happy to take a look if you'd like to make a PR for this.

jacksondoherty commented 1 week ago

PR here: #3076