Skip to content

Commit 71586e2

Browse files
authored
Rename ema to rational and mark ema as deprecated (#10)
1 parent 46f6365 commit 71586e2

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

pyth-sdk-solana/src/state.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,10 @@ pub struct PriceComp {
248248
pub latest: PriceInfo,
249249
}
250250

251-
/// An exponentially-weighted moving average.
251+
#[deprecated = "Type is renamed to Rational, please use the new name."]
252+
pub type Ema = Rational;
253+
254+
/// An number represented as both `value` and also in rational as `numer/denom`.
252255
#[derive(
253256
Copy,
254257
Clone,
@@ -262,12 +265,9 @@ pub struct PriceComp {
262265
serde::Deserialize,
263266
)]
264267
#[repr(C)]
265-
pub struct Ema {
266-
/// The current value of the EMA
268+
pub struct Rational {
267269
pub val: i64,
268-
/// numerator state for next update
269270
pub numer: i64,
270-
/// denominator state for next update
271271
pub denom: i64,
272272
}
273273

@@ -295,10 +295,10 @@ pub struct PriceAccount {
295295
pub last_slot: u64,
296296
/// valid slot-time of agg. price
297297
pub valid_slot: u64,
298-
/// time-weighted average price
299-
pub twap: Ema,
300-
/// time-weighted average confidence interval
301-
pub twac: Ema,
298+
/// exponentially moving average price
299+
pub twap: Rational,
300+
/// exponentially moving average confidence interval
301+
pub twac: Rational,
302302
/// space for future derived values
303303
pub drv1: i64,
304304
/// space for future derived values

pyth-sdk-solana/tests/stale_price.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ use pyth_sdk_solana::state::{
55
AccKey,
66
AccountType,
77
CorpAction,
8-
Ema,
98
PriceAccount,
109
PriceComp,
1110
PriceInfo,
1211
PriceStatus,
1312
PriceType,
13+
Rational,
1414
MAGIC,
1515
VERSION_2,
1616
};
@@ -23,7 +23,7 @@ use common::test_instr_exec_ok;
2323
fn price_account_all_zero() -> PriceAccount {
2424
let acc_key = AccKey { val: [0; 32] };
2525

26-
let ema = Ema {
26+
let rational = Rational {
2727
val: 0,
2828
numer: 0,
2929
denom: 0,
@@ -54,8 +54,8 @@ fn price_account_all_zero() -> PriceAccount {
5454
num_qt: 0,
5555
last_slot: 0,
5656
valid_slot: 0,
57-
twap: ema,
58-
twac: ema,
57+
twap: rational,
58+
twac: rational,
5959
drv1: 0,
6060
drv2: 0,
6161
prod: acc_key,

0 commit comments

Comments
 (0)