Skip to main content
added 170 characters in body
Source Link
john
  • 7.8k
  • 2
  • 10
  • 26

You can also reference the examples here created by Jonas, which include 3 examples of Anchor transfer hook programs.

If the pda seeds are addresses of other accounts, you reference them by index.

If the pda seeds are addresses of other accounts, you reference them by index.

You can also reference the examples here created by Jonas, which include 3 examples of Anchor transfer hook programs.

If the pda seeds are addresses of other accounts, you reference them by index.

Source Link
john
  • 7.8k
  • 2
  • 10
  • 26

Yes, you can dynamically derive pdas in the list of extra_accounts_meta! Here is an example Anchor program you can reference.

If the pda seeds are addresses of other accounts, you reference them by index.

For example, these lines here:


// index 0-3 are the accounts required for token transfer (source, mint, destination, owner)
// index 4 is address of ExtraAccountMetaList account
let account_metas = vec![
    // index 5, wrapped SOL mint
    ExtraAccountMeta::new_with_pubkey(&ctx.accounts.wsol_mint.key(), false, false)?,
    // index 6, token program
    ExtraAccountMeta::new_with_pubkey(&ctx.accounts.token_program.key(), false, false)?,
    // index 7, associated token program
    ExtraAccountMeta::new_with_pubkey(
        &ctx.accounts.associated_token_program.key(),
        false,
        false,
    )?,
    // index 8, delegate PDA
    ExtraAccountMeta::new_with_seeds(
        &[Seed::Literal {
            bytes: "delegate".as_bytes().to_vec(),
        }],
        false, // is_signer
        false,  // is_writable
    )?,
    // index 9, delegate wrapped SOL token account
    ExtraAccountMeta::new_external_pda_with_seeds(
        7, // associated token program index
        &[
            Seed::AccountKey { index: 8 }, // owner index (delegate PDA)
            Seed::AccountKey { index: 6 }, // token program index
            Seed::AccountKey { index: 5 }, // wsol mint index
        ],
        false, // is_signer
        true,  // is_writable
    )?,
    // index 10, sender wrapped SOL token account
    ExtraAccountMeta::new_external_pda_with_seeds(
        7, // associated token program index
        &[
            Seed::AccountKey { index: 3 }, // owner index
            Seed::AccountKey { index: 6 }, // token program index
            Seed::AccountKey { index: 5 }, // wsol mint index
        ],
        false, // is_signer
        true,  // is_writable
    )?,
];