1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use crate::*;
pub fn handler(ctx: Context<RescueTokens>) -> Result<()> {
let seeds = gen_miner_signer_seeds!(ctx.accounts.miner);
let signer_seeds = &[&seeds[..]];
token::transfer(
CpiContext::new_with_signer(
ctx.accounts.token_program.to_account_info(),
token::Transfer {
from: ctx.accounts.miner_token_account.to_account_info(),
to: ctx.accounts.destination_token_account.to_account_info(),
authority: ctx.accounts.miner.to_account_info(),
},
signer_seeds,
),
ctx.accounts.miner_token_account.amount,
)?;
Ok(())
}
#[derive(Accounts)]
pub struct RescueTokens<'info> {
pub miner: Account<'info, Miner>,
pub authority: Signer<'info>,
#[account(mut)]
pub miner_token_account: Account<'info, TokenAccount>,
#[account(mut)]
pub destination_token_account: Account<'info, TokenAccount>,
pub token_program: Program<'info, token::Token>,
}
impl<'info> Validate<'info> for RescueTokens<'info> {
fn validate(&self) -> Result<()> {
assert_keys_eq!(self.miner.authority, self.authority);
assert_keys_neq!(self.miner.token_vault_key, self.miner_token_account);
assert_keys_neq!(self.miner.token_vault_key, self.destination_token_account);
assert_keys_eq!(self.miner_token_account.owner, self.miner);
assert_keys_eq!(
self.miner_token_account.mint,
self.destination_token_account.mint
);
Ok(())
}
}