solana-py icon indicating copy to clipboard operation
solana-py copied to clipboard

create_associated_token_account for Token Program 2022

Open FarmerRJ opened this issue 1 year ago • 1 comments

create_associated_token_account does not allow for using the Token 2022 program. Can you add a program_id parameter to it so we can specify if it is a 2022 token.

FarmerRJ avatar Jun 21 '24 15:06 FarmerRJ

Modify the following two methods to allow for token_program_id as an argument:

  • https://github.com/michaelhly/solana-py/blob/7f2f3cb8e4028cddc5d550e39f66e031942a9884/src/spl/token/instructions.py#L1227
  • https://github.com/michaelhly/solana-py/blob/7f2f3cb8e4028cddc5d550e39f66e031942a9884/src/spl/token/instructions.py#L1214

michaelhly avatar Jun 22 '24 15:06 michaelhly

@michaelhly , happy to pick this one up as well. Seems like a quick fix.

zeke08 avatar Oct 14 '24 12:10 zeke08

I can see that there's already a constant TOKEN_2022_PROGRAM_ID.

https://github.com/michaelhly/solana-py/blob/7f2f3cb8e4028cddc5d550e39f66e031942a9884/src/spl/token/constants.py#L20

For this fix, do we type the new argument token_program_id as an enum between ASSOCIATED_TOKEN_PROGRAM_ID & TOKEN_2022_PROGRAM_ID or simply let be of type Pubkey (and default it to ASSOCIATED_TOKEN_PROGRAM_ID)?

zeke08 avatar Oct 14 '24 12:10 zeke08

No. We want the following account metadata to be either TOKEN_PROGRAM_ID or TOKEN_2022_PROGRAM_ID: https://github.com/michaelhly/solana-py/blob/7f2f3cb8e4028cddc5d550e39f66e031942a9884/src/spl/token/instructions.py#L1241

Also here: https://github.com/michaelhly/solana-py/blob/7f2f3cb8e4028cddc5d550e39f66e031942a9884/src/spl/token/instructions.py#L1221

michaelhly avatar Oct 14 '24 20:10 michaelhly