sablier_network_program/state/
fee.rs

1use anchor_lang::prelude::*;
2
3use crate::constants::SEED_FEE;
4
5/// Escrows the lamport balance owed to a particular worker.
6#[account]
7#[derive(Debug, InitSpace)]
8pub struct Fee {
9    /// The number of lamports that are distributable for this epoch period.
10    pub distributable_balance: u64,
11    /// The worker who received the fees.
12    pub worker: Pubkey,
13    pub bump: u8,
14}
15
16impl Fee {
17    /// Derive the pubkey of a fee account.
18    pub fn pubkey(worker: Pubkey) -> Pubkey {
19        Pubkey::find_program_address(&[SEED_FEE, worker.as_ref()], &crate::ID).0
20    }
21}
22
23/// Trait for reading and writing to a fee account.
24pub trait FeeAccount {
25    /// Get the pubkey of the fee account.
26    fn pubkey(&self) -> Pubkey;
27
28    /// Initialize the account to hold fee object.
29    fn init(&mut self, worker: Pubkey, bump: u8) -> Result<()>;
30}
31
32impl FeeAccount for Account<'_, Fee> {
33    fn pubkey(&self) -> Pubkey {
34        Fee::pubkey(self.worker)
35    }
36
37    fn init(&mut self, worker: Pubkey, bump: u8) -> Result<()> {
38        self.distributable_balance = 0;
39        self.worker = worker;
40        self.bump = bump;
41        Ok(())
42    }
43}