mirror of
https://github.com/d0zingcat/ore.git
synced 2026-05-14 07:26:51 +00:00
stake
This commit is contained in:
@@ -3,6 +3,8 @@ use solana_program::log::sol_log;
|
||||
use spl_token::amount_to_ui_amount;
|
||||
use steel::*;
|
||||
|
||||
use crate::AUTHORIZED_ACCOUNTS;
|
||||
|
||||
/// Withdraws ORE from the staking contract.
|
||||
pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramResult {
|
||||
// Parse data.
|
||||
@@ -11,7 +13,7 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
|
||||
// Load accounts.
|
||||
let clock = Clock::get()?;
|
||||
let [signer_info, mint_info, recipient_info, stake_info, treasury_info, treasury_tokens_info, system_program, token_program, associated_token_program] =
|
||||
let [signer_info, mint_info, recipient_info, stake_info, stake_tokens_info, treasury_info, system_program, token_program, associated_token_program] =
|
||||
accounts
|
||||
else {
|
||||
return Err(ProgramError::NotEnoughAccountKeys);
|
||||
@@ -24,14 +26,17 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
let stake = stake_info
|
||||
.as_account_mut::<Stake>(&ore_api::ID)?
|
||||
.assert_mut(|s| s.authority == *signer_info.key)?;
|
||||
stake_tokens_info.as_associated_token_account(stake_info.key, mint_info.key)?;
|
||||
let treasury = treasury_info.as_account_mut::<Treasury>(&ore_api::ID)?;
|
||||
treasury_tokens_info
|
||||
.is_writable()?
|
||||
.as_associated_token_account(&treasury_info.key, &mint_info.key)?;
|
||||
system_program.is_program(&system_program::ID)?;
|
||||
token_program.is_program(&spl_token::ID)?;
|
||||
associated_token_program.is_program(&spl_associated_token_account::ID)?;
|
||||
|
||||
assert!(
|
||||
AUTHORIZED_ACCOUNTS.contains(&signer_info.key),
|
||||
"Signer not whitelisted"
|
||||
);
|
||||
|
||||
// Open recipient token account.
|
||||
if recipient_info.data_is_empty() {
|
||||
create_associated_token_account(
|
||||
@@ -50,12 +55,12 @@ pub fn process_withdraw(accounts: &[AccountInfo<'_>], data: &[u8]) -> ProgramRes
|
||||
|
||||
// Transfer ORE to recipient.
|
||||
transfer_signed(
|
||||
treasury_info,
|
||||
treasury_tokens_info,
|
||||
stake_info,
|
||||
stake_tokens_info,
|
||||
recipient_info,
|
||||
token_program,
|
||||
amount,
|
||||
&[TREASURY],
|
||||
&[STAKE, &stake.authority.to_bytes()],
|
||||
)?;
|
||||
|
||||
// Log withdraw.
|
||||
|
||||
Reference in New Issue
Block a user