1

I have two programs.

// program one

#[derive(Accounts)]
pub struct MyContext<'info> {
   ...
   #[account(mut)]
   pub pda_in_prog_1: PDA_ONE<'info, T>,
   pub system_program: Program<'info, System>
}

// program two

#[derive(Accounts)]
pub struct MyContext<'info> {
   ...
   #[account(mut)]
   pub pda_in_prog_2: PDA_TWO<'info, T>,
   pub system_program: Program<'info, System>
}

Is there a way I can give program two authority over pda_in_prog_1. Some operations I want to carry out in program two might be closing or transferring funds from pda_in_prog_1.

2 Answers 2

2

i'm not sure you can transfer a PDA authority to another program. Although, instead of trying to update the PDA 1 in your program 2, you can build an instruction in program 1, that you call with a CPI. This way program 1 will have the necessary rights to update PDA 1

2

You certainly can! The associated-token-account program is a great and simple example showing this.

A person's associated-token-account is a PDA on the associated-token-account program:

    Pubkey::find_program_address(
        &[
            &wallet_address.to_bytes(),
            &token_program_id.to_bytes(),
            &token_mint_address.to_bytes(),
        ],
        associated_token_account_program_id,
    )

And it's calling create_account on the PDA, setting the owner to the token program at https://github.com/solana-labs/solana-program-library/blob/64d69190dcdfc25fa6041738f843727aa49783ab/associated-token-account/program/src/tools/account.rs#L57

Source at https://github.com/solana-labs/solana-program-library/blob/64d69190dcdfc25fa6041738f843727aa49783ab/associated-token-account/program/src/lib.rs#L65

So your program can call use invoke_signed with a create_account instruction, where the owner is any program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.