Skip to content

Commit

Permalink
Nice
Browse files Browse the repository at this point in the history
  • Loading branch information
guibescos committed Jan 30, 2024
1 parent 7596a4a commit 873ead9
Show file tree
Hide file tree
Showing 3 changed files with 467 additions and 4 deletions.
8 changes: 4 additions & 4 deletions target_chains/solana/programs/pyth-solana-receiver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ pub mod pyth_solana_receiver {
Ok(())
}

pub fn authorize_governance_authority_transfer(
ctx: Context<AuthorizeGovernanceAuthorityTransfer>,
pub fn accept_governance_authority_transfer(
ctx: Context<AcceptGovernanceAuthorityTransfer>,
) -> Result<()> {
let config = &mut ctx.accounts.config;
config.governance_authority = config.target_governance_authority.ok_or(error!(
Expand Down Expand Up @@ -244,13 +244,13 @@ pub struct Governance<'info> {
}

#[derive(Accounts)]
pub struct AuthorizeGovernanceAuthorityTransfer<'info> {
pub struct AcceptGovernanceAuthorityTransfer<'info> {
#[account(constraint =
payer.key() == config.target_governance_authority.ok_or(error!(ReceiverError::NonexistentGovernanceAuthorityTransferRequest))? @
ReceiverError::TargetGovernanceAuthorityMismatch
)]
pub payer: Signer<'info>,
#[account(seeds = [CONFIG_SEED.as_ref()], bump)]
#[account(mut, seeds = [CONFIG_SEED.as_ref()], bump)]
pub config: Account<'info, Config>,
}

Expand Down
57 changes: 57 additions & 0 deletions target_chains/solana/programs/pyth-solana-receiver/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ impl accounts::Governance {
}
}

impl accounts::AcceptGovernanceAuthorityTransfer {
pub fn populate(payer: Pubkey) -> Self {
let config = get_config_address();
accounts::AcceptGovernanceAuthorityTransfer { payer, config }
}
}

impl instruction::Initialize {
pub fn populate(payer: &Pubkey, initial_config: Config) -> Instruction {
Instruction {
Expand Down Expand Up @@ -173,6 +180,56 @@ impl instruction::SetFee {
}


impl instruction::SetWormholeAddress {
pub fn populate(payer: Pubkey, wormhole: Pubkey) -> Instruction {
let governance_accounts = accounts::Governance::populate(payer).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::SetWormholeAddress { wormhole }.data(),
}
}
}


impl instruction::SetMinimumSignatures {
pub fn populate(payer: Pubkey, minimum_signatures: u8) -> Instruction {
let governance_accounts = accounts::Governance::populate(payer).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::SetMinimumSignatures { minimum_signatures }.data(),
}
}
}

impl instruction::RequestGovernanceAuthorityTransfer {
pub fn populate(payer: Pubkey, target_governance_authority: Pubkey) -> Instruction {
let governance_accounts = accounts::Governance::populate(payer).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::RequestGovernanceAuthorityTransfer {
target_governance_authority,
}
.data(),
}
}
}

impl instruction::AcceptGovernanceAuthorityTransfer {
pub fn populate(payer: Pubkey) -> Instruction {
let governance_accounts =
accounts::AcceptGovernanceAuthorityTransfer::populate(payer).to_account_metas(None);
Instruction {
program_id: ID,
accounts: governance_accounts,
data: instruction::AcceptGovernanceAuthorityTransfer {}.data(),
}
}
}


pub fn get_treasury_address() -> Pubkey {
Pubkey::find_program_address(&[TREASURY_SEED.as_ref()], &ID).0
}
Expand Down
Loading

0 comments on commit 873ead9

Please sign in to comment.