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

token-js: createAssociatedTokenAccountIdempotentInstruction shouldn't require client to pass in associatedToken #7178

Closed
metaproph3t opened this issue Aug 21, 2024 · 3 comments · Fixed by #7183
Labels
good first issue Good for newcomers

Comments

@metaproph3t
Copy link

The handy createAssociatedTokenAccountIdempotentInstruction allows you create instructions that idempotently create associated token accounts. One thing that annoys me about it is that it requires me to pass in the associated token account, like so:

...
.preInstructions([
        createAssociatedTokenAccountIdempotentInstruction(
          this.provider.publicKey,
          token.getAssociatedTokenAddressSync(
            tokenMint,
            pdaOwner,
            true
          ),
          pdaOwner,
          tokenMint
)]
...

I don't see the purpose of this given that associated token accounts can always be derived by the getAssociatedTokenAddressSync. Maybe this function was written before getAssociatedTokenAddressSync existed? In any case, it would be nice if this parameter was made optional or removed entirely.

@joncinque
Copy link
Contributor

The instruction creators like this are meant to be totally customizable, just like createAssociatedTokenAccountInstruction -- if you want to add a helper, PRs are always welcome!

@joncinque joncinque added the good first issue Good for newcomers label Aug 21, 2024
@joncinque joncinque changed the title createAssociatedTokenAccountIdempotentInstruction shouldn't require client to pass in associatedToken token-js: createAssociatedTokenAccountIdempotentInstruction shouldn't require client to pass in associatedToken Aug 21, 2024
@metaproph3t
Copy link
Author

What does customizable mean here? An associated token account pubkey is the result of applying getAssociatedTokenAddressSync to mint and owner, so what's the point of having both mint/owner and associatedToken? I'm trying to understand what use-case this unlocks

@joncinque
Copy link
Contributor

"customizable" just means you can set every possible account in the instruction, even if it's incorrect. If you're particularly performance-sensitive, then this creator allows you to incur the cost of deriving the associated token account address just once rather than being forced to do it multiple times.

But either way, we can definitely add a helper!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
2 participants