Skip to content

Commit ac2718d

Browse files
committed
Log time and ema
1 parent 3a46596 commit ac2718d

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

program/rust/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn main() {
1212
parser.register_traits("pc_acc", borsh_derives.to_vec());
1313
parser.register_traits("pc_price_info", borsh_derives.to_vec());
1414
parser.register_traits("cmd_upd_price", borsh_derives.to_vec());
15+
parser.register_traits("pc_ema", borsh_derives.to_vec());
1516

1617
//generate and write bindings
1718
let bindings = Builder::default()

program/rust/src/log.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ use crate::c_oracle_header::*;
22
use crate::error::OracleError;
33
use borsh::BorshDeserialize;
44
use solana_program::account_info::AccountInfo;
5+
use solana_program::clock::Clock;
56
use solana_program::entrypoint::ProgramResult;
67
use solana_program::msg;
8+
use solana_program::sysvar::Sysvar;
79
use std::mem::size_of;
810

911
pub fn pre_log(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResult {
@@ -14,33 +16,38 @@ pub fn pre_log(accounts: &[AccountInfo], instruction_data: &[u8]) -> ProgramResu
1416
.cmd_
1517
.try_into()
1618
.map_err(|_| OracleError::Generic)?;
19+
20+
let clock = Clock::get()?;
21+
1722
match instruction_id {
1823
command_t_e_cmd_upd_price | command_t_e_cmd_agg_price => {
1924
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
2025
msg!(
21-
"UpdatePrice: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
26+
"UpdatePrice: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}, solana_time={:}",
2227
accounts.get(0)
2328
.ok_or(OracleError::Generic)?.key,
2429
accounts.get(1)
2530
.ok_or(OracleError::Generic)?.key,
2631
instruction.price_,
2732
instruction.conf_,
2833
instruction.status_,
29-
instruction.pub_slot_
34+
instruction.pub_slot_,
35+
clock.unix_timestamp
3036
);
3137
}
3238
command_t_e_cmd_upd_price_no_fail_on_error => {
3339
let instruction: cmd_upd_price = cmd_upd_price::try_from_slice(instruction_data)?;
3440
msg!(
35-
"UpdatePriceNoFailOnError: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
41+
"UpdatePriceNoFailOnError: publisher={:}, price_account={:}, price={:}, conf={:}, status={:}, slot={:}, solana_time={:}",
3642
accounts.get(0)
3743
.ok_or(OracleError::Generic)?.key,
3844
accounts.get(1)
3945
.ok_or(OracleError::Generic)?.key,
4046
instruction.price_,
4147
instruction.conf_,
4248
instruction.status_,
43-
instruction.pub_slot_
49+
instruction.pub_slot_,
50+
clock.unix_timestamp
4451
);
4552
}
4653
command_t_e_cmd_add_mapping => {
@@ -91,13 +98,26 @@ pub fn post_log(c_ret_val: u64, accounts: &[AccountInfo]) -> ProgramResult {
9198
.ok_or(OracleError::Generic)?
9299
.try_borrow_data()?[start..(start + size_of::<pc_price_info>())],
93100
)?;
101+
102+
let ema_info: pc_ema = pc_ema::try_from_slice(
103+
&accounts
104+
.get(1)
105+
.ok_or(OracleError::Generic)?
106+
.try_borrow_data()?[start..(start + size_of::<pc_ema>())],
107+
)?;
108+
109+
let clock = Clock::get()?;
110+
94111
msg!(
95-
"UpdateAggregate : price_account={:}, price={:}, conf={:}, status={:}, slot={:}",
96-
accounts.get(1).ok_or(OracleError::Generic)?.key,
112+
"UpdateAggregate : price_account={:}, price={:}, conf={:}, status={:}, slot={:}, solana_time={:}, ema={:}",
113+
accounts.get(1)
114+
.ok_or(OracleError::Generic)?.key,
97115
aggregate_price_info.price_,
98116
aggregate_price_info.conf_,
99117
aggregate_price_info.status_,
100-
aggregate_price_info.pub_slot_
118+
aggregate_price_info.pub_slot_,
119+
clock.unix_timestamp,
120+
ema_info.val_
101121
);
102122
}
103123
Ok(())

program/rust/src/price_t_offsets.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const size_t PRICE_T_AGGREGATE_OFFSET = offsetof(struct pc_price, agg_);
99
const size_t PRICE_T_AGGREGATE_CONF_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, conf_);
1010
const size_t PRICE_T_AGGREGATE_PRICE_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, price_);
1111
const size_t PRICE_T_AGGREGATE_STATUS_OFFSET = offsetof(struct pc_price, agg_) + offsetof(struct pc_price_info, status_);
12+
const size_t PRICE_T_EMA_OFFSET = offsetof(struct pc_price, twap_);
1213
const size_t PRICE_T_PREV_TIMESTAMP_OFFSET = offsetof(struct pc_price, prev_timestamp_);
1314
const size_t PRICE_T_PREV_CONF_OFFSET = offsetof(struct pc_price, prev_conf_);
1415
const size_t PRICE_T_PREV_AGGREGATE_OFFSET = offsetof(struct pc_price, prev_price_);

0 commit comments

Comments
 (0)