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
64
65
use agnostic_orderbook::state::OrderSummary;
use anchor_lang::{event, prelude::*};

use super::state::TermLoanFlags;

#[event]
pub struct MarginUserInitialized {
    pub market: Pubkey,
    pub borrower_account: Pubkey,
    pub margin_account: Pubkey,
    pub underlying_settlement: Pubkey,
    pub ticket_settlement: Pubkey,
}

#[event]
pub struct OrderPlaced {
    pub market: Pubkey,
    /// The authority placing this order, almost always the margin account
    pub authority: Pubkey,
    pub margin_user: Option<Pubkey>,
    pub order_type: OrderType,
    pub order_summary: OrderSummary,
    pub limit_price: u64,
    pub auto_stake: bool,
    pub post_only: bool,
    pub post_allowed: bool,
}

#[derive(AnchorDeserialize, AnchorSerialize)]
pub enum OrderType {
    MarginBorrow,
    MarginLend,
    MarginSellTickets,
    Lend,
    SellTickets,
}

#[event]
pub struct TermLoanCreated {
    pub term_loan: Pubkey,
    pub authority: Pubkey,
    pub order_id: Option<u128>,
    pub sequence_number: u64,
    pub market: Pubkey,
    pub maturation_timestamp: i64,
    pub quote_filled: u64,
    pub base_filled: u64,
    pub flags: TermLoanFlags,
}

#[event]
pub struct TermLoanRepay {
    pub orderbook_user: Pubkey,
    pub term_loan: Pubkey,
    pub repayment_amount: u64,
    pub final_balance: u64,
}

#[event]
pub struct TermLoanFulfilled {
    pub term_loan: Pubkey,
    pub orderbook_user: Pubkey,
    pub borrower: Pubkey,
    pub timestamp: i64,
}