1
1
#![ allow( missing_docs) ]
2
2
use crate :: math:: Decimal ;
3
- use solana_program:: { msg , pubkey:: Pubkey } ;
3
+ use solana_program:: pubkey:: Pubkey ;
4
4
use std:: fmt;
5
5
6
- #[ derive( Debug ) ]
7
- enum LogEventType {
8
- PythOraclePriceUpdateType ,
9
- SwitchboardV1OraclePriceUpdateType ,
6
+ extern crate serde;
7
+ extern crate serde_json;
8
+
9
+ #[ derive( Debug , Serialize ) ]
10
+ pub enum LogEventType {
11
+ ObligationStateUpdate ,
12
+ ProgramVersion ,
13
+ PythError ,
14
+ PythOraclePriceUpdate ,
15
+ ReserveStateUpdate ,
16
+ SwitchboardError ,
17
+ SwitchboardV1OraclePriceUpdate ,
10
18
}
11
19
12
20
impl fmt:: Display for LogEventType {
@@ -15,49 +23,83 @@ impl fmt::Display for LogEventType {
15
23
}
16
24
}
17
25
18
- pub fn emit_log_event ( e : & dyn LogEvent ) {
19
- msg ! ( "Solend Log Event" ) ;
20
- msg ! ( & e. to_string( ) ) ;
21
- }
22
-
23
- pub trait LogEvent {
24
- fn to_string ( & self ) -> String ;
26
+ #[ macro_export]
27
+ macro_rules! emit_log_event {
28
+ ( $e: expr) => {
29
+ msg!( "solend-event-log:" ) ;
30
+ msg!( & serde_json:: to_string( $e) . unwrap( ) ) ;
31
+ } ;
25
32
}
26
33
34
+ #[ derive( Serialize ) ]
27
35
pub struct PythOraclePriceUpdate {
36
+ pub event_type : LogEventType ,
28
37
pub oracle_pubkey : Pubkey ,
29
38
pub price : Decimal ,
30
- pub conf : u64 ,
39
+ pub confidence : u64 ,
31
40
pub published_slot : u64 ,
32
41
}
33
42
34
- impl LogEvent for PythOraclePriceUpdate {
35
- fn to_string ( & self ) -> String {
36
- return format ! (
37
- "{},{},{},{},{}" ,
38
- LogEventType :: PythOraclePriceUpdateType . to_string( ) ,
39
- self . oracle_pubkey. to_string( ) ,
40
- self . price. to_string( ) ,
41
- self . conf. to_string( ) ,
42
- self . published_slot,
43
- ) ;
44
- }
43
+ #[ derive( Serialize ) ]
44
+ pub struct PythError {
45
+ pub event_type : LogEventType ,
46
+ pub oracle_pubkey : Pubkey ,
47
+ pub error_message : String ,
45
48
}
46
49
50
+ #[ derive( Serialize ) ]
47
51
pub struct SwitchboardV1OraclePriceUpdate {
52
+ pub event_type : LogEventType ,
48
53
pub oracle_pubkey : Pubkey ,
49
54
pub price : Decimal ,
50
55
pub published_slot : u64 ,
51
56
}
52
57
53
- impl LogEvent for SwitchboardV1OraclePriceUpdate {
54
- fn to_string ( & self ) -> String {
55
- return format ! (
56
- "{},{},{},{}" ,
57
- LogEventType :: SwitchboardV1OraclePriceUpdateType . to_string( ) ,
58
- self . oracle_pubkey. to_string( ) ,
59
- self . price. to_string( ) ,
60
- self . published_slot,
61
- ) ;
62
- }
58
+ #[ derive( Serialize ) ]
59
+ pub struct SwitchboardError {
60
+ pub event_type : LogEventType ,
61
+ pub oracle_pubkey : Pubkey ,
62
+ pub error_message : String ,
63
+ }
64
+
65
+ #[ derive( Serialize ) ]
66
+ pub struct ProgramVersion {
67
+ pub event_type : LogEventType ,
68
+ pub version : u8 ,
69
+ }
70
+
71
+ #[ derive( Serialize ) ]
72
+ pub struct ReserveStateUpdate {
73
+ pub event_type : LogEventType ,
74
+ pub reserve_id : Pubkey ,
75
+ pub available_amount : u64 ,
76
+ pub borrowed_amount_wads : Decimal ,
77
+ pub cumulative_borrow_rate_wads : Decimal ,
78
+ pub collateral_mint_total_supply : u64 ,
79
+ pub collateral_exchange_rate : String ,
80
+ }
81
+
82
+ #[ derive( Serialize ) ]
83
+ pub struct ObligationStateUpdate {
84
+ pub event_type : LogEventType ,
85
+ pub obligation_id : Pubkey ,
86
+ pub allowed_borrow_value : Decimal ,
87
+ pub unhealthy_borrow_value : Decimal ,
88
+ pub deposits : Vec < DepositLog > ,
89
+ pub borrows : Vec < BorrowLog > ,
90
+ }
91
+
92
+ #[ derive( Serialize ) ]
93
+ pub struct DepositLog {
94
+ pub reserve_id : Pubkey ,
95
+ pub deposited_amount : u64 ,
96
+ pub market_value : Decimal ,
97
+ }
98
+
99
+ #[ derive( Serialize ) ]
100
+ pub struct BorrowLog {
101
+ pub reserve_id : Pubkey ,
102
+ pub cumulative_borrow_rate_wads : Decimal ,
103
+ pub borrowed_amount_wads : Decimal ,
104
+ pub market_value : Decimal ,
63
105
}
0 commit comments