solana: привязать singleton pda в shine_payments

This commit is contained in:
AidarKC 2026-06-09 23:10:20 +04:00
parent fb0c5ad3f8
commit 5981d3f871

View File

@ -596,7 +596,7 @@ fn process_init(program_id: &Pubkey, accounts: &[AccountInfo]) -> ProgramResult
}
fn process_update_coef_limit(
_program_id: &Pubkey,
program_id: &Pubkey,
accounts: &[AccountInfo],
args: UpdateCoefLimitArgs,
) -> ProgramResult {
@ -606,6 +606,8 @@ fn process_update_coef_limit(
let coef_limit_pda = next_account_info(account_iter)?;
require!(account_iter.next().is_none(), PaymentsError::InvalidInstruction);
validate_singleton_state_pda(program_id, config_pda, settings::CONFIG_SEED)?;
validate_singleton_state_pda(program_id, coef_limit_pda, settings::COEF_LIMIT_SEED)?;
let config = read_state::<ConfigState>(config_pda)?;
require_keys_eq!(config.dao_wallet, *signer.key, PaymentsError::UnauthorizedDao);
require!(args.coef_ppm > 0, PaymentsError::InvalidCoefficient);
@ -635,6 +637,7 @@ fn process_grant_manager_limits(
require!(account_iter.next().is_none(), PaymentsError::InvalidInstruction);
require_system_program(system_program_ai)?;
validate_singleton_state_pda(program_id, config_pda, settings::CONFIG_SEED)?;
let config = read_state::<ConfigState>(config_pda)?;
require_keys_eq!(config.dao_wallet, *signer.key, PaymentsError::UnauthorizedDao);
require!(
@ -738,6 +741,7 @@ fn process_manager_add_ticket(
let (expected_manager_pda, _) = find_manager_allowance_pda(program_id, signer.key);
require_keys_eq!(expected_manager_pda, *manager_allowance_pda.key, PaymentsError::InvalidPdaAddress);
validate_singleton_state_pda(program_id, queues_pda, settings::QUEUES_SEED)?;
let mut allowance = read_state::<ManagerAllowanceState>(manager_allowance_pda)?;
require_keys_eq!(allowance.manager_wallet, *signer.key, PaymentsError::InvalidManagerWallet);
@ -793,6 +797,10 @@ fn process_step_payout(program_id: &Pubkey, accounts: &[AccountInfo]) -> Program
let sol_usd_price_update = next_account_info(account_iter)?;
require!(account_iter.next().is_none(), PaymentsError::InvalidInstruction);
validate_singleton_state_pda(program_id, config_pda, settings::CONFIG_SEED)?;
validate_singleton_state_pda(program_id, coef_limit_pda, settings::COEF_LIMIT_SEED)?;
validate_singleton_state_pda(program_id, queues_pda, settings::QUEUES_SEED)?;
validate_singleton_state_pda(program_id, inflow_vault_pda, settings::INFLOW_VAULT_SEED)?;
let config = read_state::<ConfigState>(config_pda)?;
let coef_limit = read_state::<CoefLimitState>(coef_limit_pda)?;
let mut queues = read_state::<QueuesState>(queues_pda)?;
@ -856,6 +864,7 @@ fn process_change_ticket_recipient(
let ticket_pda = next_account_info(account_iter)?;
require!(account_iter.next().is_none(), PaymentsError::InvalidInstruction);
validate_singleton_state_pda(program_id, queues_pda, settings::QUEUES_SEED)?;
let queues = read_state::<QueuesState>(queues_pda)?;
let mut ticket = read_state::<TicketState>(ticket_pda)?;
require!(!ticket.is_paid, PaymentsError::TicketAlreadyPaid);
@ -944,6 +953,17 @@ fn ensure_expected_pdas(
Ok(())
}
fn validate_singleton_state_pda(
program_id: &Pubkey,
pda: &AccountInfo,
seed: &[u8],
) -> ProgramResult {
let (expected_pda, _) = find_single_pda(program_id, seed);
require_keys_eq!(expected_pda, *pda.key, PaymentsError::InvalidPdaAddress);
require_keys_eq!(*pda.owner, id(), PaymentsError::InvalidPdaAddress);
Ok(())
}
fn find_single_pda(program_id: &Pubkey, seed: &[u8]) -> (Pubkey, u8) {
Pubkey::find_program_address(&[seed], program_id)
}
@ -979,6 +999,9 @@ fn buy_ticket_by_purchase_usd(
transfer_lamports: u64,
recipient_wallet: Pubkey,
) -> ProgramResult {
validate_singleton_state_pda(program_id, ctx.config_pda, settings::CONFIG_SEED)?;
validate_singleton_state_pda(program_id, ctx.coef_limit_pda, settings::COEF_LIMIT_SEED)?;
validate_singleton_state_pda(program_id, ctx.queues_pda, settings::QUEUES_SEED)?;
let config = read_state::<ConfigState>(ctx.config_pda)?;
let coef_limit = read_state::<CoefLimitState>(ctx.coef_limit_pda)?;
let mut queues = read_state::<QueuesState>(ctx.queues_pda)?;