solana-labs / solana-program-library

A collection of Solana programs maintained by Solana Labs
https://solanalabs.com
Apache License 2.0
3.56k stars 2.07k forks source link

What Account to use for SPL Token Transfer After Recipient's Derived Token Address Ownership Transferred #2514

Closed ozyman42 closed 2 years ago

ozyman42 commented 3 years ago

Problem

I'm noticing that with many NFT marketplaces, they transfer ownership of the NFT by having owners transfer control of the SPL token account, rather than creating a token account for the recipient based on the derived address. For example, this token account is being transferred between owners https://explorer.solana.com/address/BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB (see transaction history how the authority keeps changing hands).

When I call Token.getAssociatedTokenAddress with mint 3MwVdf1kEDRUU4qTfoHk1u363qJGxrCYHT5RBAEBQGLs and owner BAJkBrrMZusHYingeqmvKND7LZBYRLYRMjDtFJ7wbjkT I get the derived address BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB. But now since BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB has a new owner than the original owner, we can run into a situation where I want to send the SPL token to original owner BAJkBrrMZusHYingeqmvKND7LZBYRLYRMjDtFJ7wbjkT, but I can't use BW766zFWF5PRr5LssdJv2zoCkUAwvELwaLswho4ZMPmB as the destination in the Token.createTransferInstruction instruction, since it has the wrong owner, and I can't generate a new keypair to use for creation of a new recipient associated token account because then I get the error Associated address does not match seed derivation.

Proposed Solution

I guess I need to transfer ownership of the token account I'm sending from, but this solution seems to just perpetuate a problem where account ownership is being transferred rather than creating the derived account for a recipient. Account transfer works for NFTs where the supply is 1, but I don't see this account transfer working in cases where I want to transfer some fungible SPL tokens but not all.

fabiooshiro commented 2 years ago

I have a similar problem!

t-nelson commented 2 years ago

we don't use github for support. try https://solana.com/discord