Skip to content

Commit 72723b9

Browse files
committed
log price update
1 parent 35a282b commit 72723b9

File tree

4 files changed

+87
-2
lines changed

4 files changed

+87
-2
lines changed

token-lending/program/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
pub mod entrypoint;
66
pub mod error;
77
pub mod instruction;
8+
pub mod logs;
89
pub mod math;
910
pub mod processor;
1011
pub mod pyth;

token-lending/program/src/logs.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#![allow(missing_docs)]
2+
use solana_program::{
3+
msg,
4+
pubkey::Pubkey,
5+
};
6+
use std::{fmt};
7+
use crate::{
8+
pyth,
9+
math::{Decimal},
10+
};
11+
12+
13+
#[derive(Debug)]
14+
enum LogEventType {
15+
PythOraclePriceUpdateType,
16+
SwitchboardV1OraclePriceUpdateType,
17+
}
18+
19+
impl fmt::Display for LogEventType{
20+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21+
write!(f, "{:?}", self)
22+
}
23+
}
24+
25+
pub fn emit_log_event(e: &dyn LogEvent) {
26+
msg!("Solend Log Event");
27+
msg!(&e.to_string());
28+
}
29+
30+
31+
pub trait LogEvent {
32+
fn to_string(&self) -> String;
33+
}
34+
35+
pub struct PythOraclePriceUpdate {
36+
oracle_pubkey: Pubkey,
37+
price: i64,
38+
conf: u64,
39+
status: pyth::PriceStatus,
40+
published_slot: u64,
41+
}
42+
43+
impl LogEvent for PythOraclePriceUpdate {
44+
fn to_string(&self) -> String {
45+
return format!(
46+
"{},{},{},{},{},{}",
47+
LogEventType::PythOraclePriceUpdateType.to_string(),
48+
self.oracle_pubkey.to_string(),
49+
self.price.to_string(),
50+
self.conf.to_string(),
51+
self.status.to_string(),
52+
self.published_slot,
53+
);
54+
}
55+
}
56+
57+
pub struct SwitchboardV1OraclePriceUpdate {
58+
oracle_pubkey: Pubkey,
59+
price: Decimal,
60+
published_slot: u64,
61+
}
62+
63+
impl LogEvent for SwitchboardV1OraclePriceUpdate {
64+
fn to_string(&self) -> String {
65+
return format!(
66+
"{},{},{},{}",
67+
LogEventType::SwitchboardV1OraclePriceUpdateType.to_string(),
68+
self.oracle_pubkey.to_string(),
69+
self.price.to_string(),
70+
self.published_slot,
71+
);
72+
}
73+
}

token-lending/program/src/processor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::{
44
self as spl_token_lending,
55
error::LendingError,
66
instruction::LendingInstruction,
7+
logs::{emit_log_event},
78
math::{Decimal, Rate, TryAdd, TryDiv, TryMul, TrySub, WAD},
89
pyth,
910
state::{

token-lending/program/src/pyth.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ use bytemuck::{
44
cast_slice, cast_slice_mut, from_bytes, from_bytes_mut, try_cast_slice, try_cast_slice_mut,
55
Pod, PodCastError, Zeroable,
66
};
7-
use std::mem::size_of;
7+
use std::{
8+
mem::size_of,
9+
fmt,
10+
};
811

912
pub const MAGIC: u32 = 0xa1b2c3d4;
1013
pub const VERSION_2: u32 = 2;
@@ -29,7 +32,7 @@ pub enum AccountType {
2932
Price,
3033
}
3134

32-
#[derive(PartialEq, Copy, Clone)]
35+
#[derive(PartialEq, Copy, Clone, Debug)]
3336
#[repr(C)]
3437
pub enum PriceStatus {
3538
Unknown,
@@ -38,6 +41,13 @@ pub enum PriceStatus {
3841
Auction,
3942
}
4043

44+
impl fmt::Display for PriceStatus{
45+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
46+
write!(f, "{:?}", self)
47+
}
48+
}
49+
50+
4151
#[derive(PartialEq, Copy, Clone)]
4252
#[repr(C)]
4353
pub enum CorpAction {

0 commit comments

Comments
 (0)