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 Program Type Handling in CreateAssociatedTokenAccount Method Causes Failures #1657

Closed
wernerkodezero opened this issue Jan 3, 2025 · 3 comments
Labels
bug Something isn't working library

Comments

@wernerkodezero
Copy link
Contributor

Describe the bug
If you look at the Create Associated Token Account method you will see that the Token Program Type is never passed to the Create Account method. This causes the Create Account method to fail with some addresses as it's not using the correct Token Program Type in all cases.

Future<ProgramAccount> createAssociatedTokenAccount({
    Ed25519HDPublicKey? owner,
    required Ed25519HDPublicKey mint,
    required Wallet funder,
    TokenProgramType tokenProgramType = TokenProgramType.tokenProgram,
    SignatureCallback? onSigned,
    Commitment commitment = Commitment.finalized,
  }) async {
    final effectiveOwner = owner ?? funder.publicKey;

    final derivedAddress = await findAssociatedTokenAddress(
      owner: effectiveOwner,
      mint: mint,
      tokenProgramType: tokenProgramType,
    );
    final instruction = AssociatedTokenAccountInstruction.createAccount(
      mint: mint,
      address: derivedAddress,
      owner: effectiveOwner,
      funder: funder.publicKey, <-- missing tokenProgramId here
    );

    await sendAndConfirmTransaction(
      message: Message.only(instruction),
      signers: [funder],
      onSigned: onSigned ?? ignoreOnSigned,
      commitment: commitment,
    );

    // TODO(IA): populate rentEpoch correctly
    return ProgramAccount(
      pubkey: derivedAddress.toBase58(),
      account: Account(
        owner: effectiveOwner.toBase58(),
        lamports: 0,
        executable: false,
        rentEpoch: BigInt.zero,
        data: null,
      ),
    );
  }
AccountMeta.readonly(
   pubKey: Ed25519HDPublicKey.fromBase58(
      tokenProgramId?.toBase58() ?? TokenProgram.id.toBase58(), <-- can be changed here too
   ), 
   isSigner: false,
),

Expected behavior
Should take the tokenProgramType into consideration

@wernerkodezero wernerkodezero added bug Something isn't working library labels Jan 3, 2025
@ookami-kb
Copy link
Collaborator

Hey @wernerkodezero feel free to create a PR – that would be the fastest way to resolve the issue.

@wernerkodezero
Copy link
Contributor Author

wernerkodezero commented Jan 5, 2025

Hey @ookami-kb I am trying to create a PR but I am running into a permission issue:

ERROR: Permission to espresso-cash/espresso-cash-public.git denied to wernerkodezero.
fatal: Could not read from remote repository.

SSH on my side is set up. I'm not sure if you need to give me permission to the repo.

@ookami-kb
Copy link
Collaborator

@wernerkodezero you cannot create PR directly to the repo, you need to fork it first: https://stackoverflow.com/questions/44415291/how-to-create-a-git-pull-request-on-a-public-github-repository

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

No branches or pull requests

2 participants