For my program, I need to implement the Token2022 transfer hook. Inside the transfer hook, I need to read and write a PDA account driven from the address of the owner of the destination ATA.
EDIT: In the transfer hook I need to update 2 PDAs (user state). One is for the sender, and one is for the receiver. Everything is fine with the sender since we have it as a parameter in the transfer instruction. But we don't have the receiver's wallet address.
Here is how I initialize the PDA account
pub user: AccountInfo<'info>,
#[account(
init,
payer = _payer,
space = UserCampaignState::space(),
seeds = [
USER_CAMPAIGN_STATE_SEED.as_ref(),
user.key().as_ref(),
],
bump
)]
pub user_state: Account<'info, UserCampaignState>,
According to documentation, in ExtraAccountMetaList
we have the owner of the source ATA (index 3), but no receiver, unfortunately.
index 0-3 are the accounts required for token transfer (source, mint, destination, owner)
So, my question is how to initialize ExtraAccountMetaList
with the receiver's address and/or PDA. OR is there a workaround inside transfer_hook to get a PDA by the receiver's address and, most importantly, write in it?
Thank you in advance! I hope this will help others who struggle with receiver in transfer hook as well :)