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
use {
crate::state::*,
anchor_lang::prelude::*,
};
#[derive(Accounts)]
#[instruction()]
pub struct RevenueCollect<'info> {
#[account(
mut,
seeds = [
SEED_REVENUE,
revenue.daemon.as_ref()
],
bump = revenue.bump,
)]
pub revenue: Account<'info, Revenue>,
#[account(mut)]
pub signer: Signer<'info>,
#[account(
mut,
seeds = [SEED_TREASURY],
bump = treasury.bump,
)]
pub treasury: Account<'info, Treasury>,
}
pub fn handler(ctx: Context<RevenueCollect>) -> ProgramResult {
let revenue = &mut ctx.accounts.revenue;
let treasury = &mut ctx.accounts.treasury;
**revenue.to_account_info().try_borrow_mut_lamports()? -= revenue.balance;
**treasury.to_account_info().try_borrow_mut_lamports()? += revenue.balance;
revenue.balance = 0;
Ok(())
}