Skip to content

Commit 1aee40c

Browse files
committed
finished adding id back to return type, distinguishing between get return type and the overall price feed return that will be given from the query function
1 parent 9fe481a commit 1aee40c

File tree

4 files changed

+98
-47
lines changed

4 files changed

+98
-47
lines changed

target_chains/stylus/contracts/pyth-receiver/src/integration_tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ mod test {
118118
.sender(alice)
119119
.get_price_unsafe(good_update1_feed_id());
120120
assert!(price_result.is_ok());
121-
assert_eq!(price_result.unwrap(), good_update1_results());
121+
assert_eq!(price_result.unwrap(), good_update1_results_get_price());
122122
}
123123

124124
#[motsu::test]
@@ -172,7 +172,7 @@ mod test {
172172
.sender(alice)
173173
.get_price_unsafe(good_update1_feed_id());
174174
assert!(price_result.is_ok());
175-
assert_eq!(price_result.unwrap(), good_update2_results());
175+
assert_eq!(price_result.unwrap(), good_update2_results_get_price());
176176
}
177177

178178
#[motsu::test]
@@ -241,7 +241,7 @@ mod test {
241241
.sender(alice)
242242
.get_price_no_older_than(good_update1_feed_id(), u64::MAX);
243243
assert!(price_result.is_ok());
244-
assert_eq!(price_result.unwrap(), good_update2_results());
244+
assert_eq!(price_result.unwrap(), good_update2_results_get_price());
245245
}
246246

247247
#[motsu::test]
@@ -304,11 +304,11 @@ mod test {
304304

305305
let first_price_result = pyth_contract.sender(alice).get_price_unsafe(first_id);
306306
assert!(first_price_result.is_ok());
307-
assert_eq!(first_price_result.unwrap(), multiple_updates_results()[0]);
307+
assert_eq!(first_price_result.unwrap(), multiple_updates_results_get_price()[0]);
308308

309309
let second_price_result = pyth_contract.sender(alice).get_price_unsafe(second_id);
310310
assert!(second_price_result.is_ok());
311-
assert_eq!(second_price_result.unwrap(), multiple_updates_results()[1]);
311+
assert_eq!(second_price_result.unwrap(), multiple_updates_results_get_price()[1]);
312312
}
313313

314314
#[motsu::test]
@@ -340,14 +340,14 @@ mod test {
340340
assert!(first_price_result.is_ok());
341341
assert_eq!(
342342
first_price_result.unwrap(),
343-
multiple_updates_diff_vaa_results()[0]
343+
multiple_updates_diff_vaa_results_get_price()[0]
344344
);
345345

346346
let second_price_result = pyth_contract.sender(alice).get_price_unsafe(second_id);
347347
assert!(second_price_result.is_ok());
348348
assert_eq!(
349349
second_price_result.unwrap(),
350-
multiple_updates_diff_vaa_results()[1]
350+
multiple_updates_diff_vaa_results_get_price()[1]
351351
);
352352
}
353353

target_chains/stylus/contracts/pyth-receiver/src/lib.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use pythnet_sdk::{
3939
},
4040
},
4141
};
42-
use structs::{DataSource, DataSourceStorage, PriceFeedReturn, PriceFeedStorage};
42+
use structs::{DataSource, DataSourceStorage, PriceFeedReturn, PriceInfoStorage, PriceReturn};
4343
use wormhole_vaas::{Readable, Vaa, Writeable};
4444

4545
sol_interface! {
@@ -111,7 +111,7 @@ impl PythReceiver {
111111
}
112112
}
113113

114-
pub fn get_price_unsafe(&self, id: [u8; 32]) -> Result<PriceFeedReturn, PythReceiverError> {
114+
pub fn get_price_unsafe(&self, id: [u8; 32]) -> Result<PriceReturn, PythReceiverError> {
115115
let id_fb = FixedBytes::<32>::from(id);
116116

117117
let price_info = self.latest_price_info.get(id_fb);
@@ -121,29 +121,26 @@ impl PythReceiver {
121121
}
122122

123123
Ok((
124-
id,
125-
price_info.publish_time.get(),
126-
price_info.expo.get(),
127124
price_info.price.get(),
128125
price_info.conf.get(),
129-
price_info.ema_price.get(),
130-
price_info.ema_conf.get(),
126+
price_info.expo.get(),
127+
price_info.publish_time.get(),
131128
))
132129
}
133130

134131
pub fn get_price_no_older_than(
135132
&self,
136133
id: [u8; 32],
137134
age: u64,
138-
) -> Result<PriceFeedReturn, PythReceiverError> {
135+
) -> Result<PriceReturn, PythReceiverError> {
139136
let price_info = self.get_price_unsafe(id)?;
140137
if !self.is_no_older_than(price_info.1, age) {
141138
return Err(PythReceiverError::NewPriceUnavailable);
142139
}
143140
Ok(price_info)
144141
}
145142

146-
pub fn get_ema_price_unsafe(&self, id: [u8; 32]) -> Result<PriceFeedReturn, PythReceiverError> {
143+
pub fn get_ema_price_unsafe(&self, id: [u8; 32]) -> Result<PriceReturn, PythReceiverError> {
147144
let id_fb = FixedBytes::<32>::from(id);
148145
let price_info = self.latest_price_info.get(id_fb);
149146

@@ -152,21 +149,18 @@ impl PythReceiver {
152149
}
153150

154151
Ok((
155-
id,
156-
price_info.publish_time.get(),
157-
price_info.expo.get(),
158-
price_info.ema_price.get(),
159-
price_info.ema_conf.get(),
160152
price_info.ema_price.get(),
161153
price_info.ema_conf.get(),
154+
price_info.expo.get(),
155+
price_info.publish_time.get(),
162156
))
163157
}
164158

165159
pub fn get_ema_price_no_older_than(
166160
&self,
167161
id: [u8; 32],
168162
age: u64,
169-
) -> Result<PriceFeedReturn, PythReceiverError> {
163+
) -> Result<PriceReturn, PythReceiverError> {
170164
let price_info = self.get_ema_price_unsafe(id)?;
171165
if !self.is_no_older_than(price_info.1, age) {
172166
return Err(PythReceiverError::NewPriceUnavailable);

target_chains/stylus/contracts/pyth-receiver/src/structs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ pub struct PriceFeedStorage {
6060

6161
pub type PriceFeedReturn = ([u8; 32], U64, I32, I64, U64, I64, U64);
6262

63-
pub type PriceReturn = ([u8; 32], U64, I32, I64, U64, I64, U64);
63+
// (price, conf, expo, publish_time)
64+
pub type PriceReturn = (I64, U64, I32, U64);
6465

6566
#[cfg(test)]
6667
mod tests {

target_chains/stylus/contracts/pyth-receiver/src/test_data.rs

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,57 @@ pub fn multiple_updates_diff_vaa() -> Vec<Vec<u8>> {
7474
}
7575

7676
#[cfg(test)]
77-
pub fn multiple_updates_diff_vaa_results() -> [([u8; 32], U64, I32, I64, U64, I64, U64); 2] {
77+
pub fn good_update1_results_full() -> ([u8; 32], U64, I32, I64, U64, I64, U64) {
78+
(
79+
good_update1_feed_id(),
80+
U64::from(1752170378u64),
81+
I32::from_le_bytes((-8i32).to_le_bytes()),
82+
I64::from_le_bytes(6512459i64.to_le_bytes()),
83+
U64::from(20759u64),
84+
I64::from_le_bytes(6423048i64.to_le_bytes()),
85+
U64::from(14961u64),
86+
)
87+
}
88+
89+
#[cfg(test)]
90+
pub fn good_update2_results_full() -> ([u8; 32], U64, I32, I64, U64, I64, U64) {
91+
(
92+
good_update1_feed_id(),
93+
U64::from(1752171074u64),
94+
I32::from_le_bytes((-8i32).to_le_bytes()),
95+
I64::from_le_bytes(6468786i64.to_le_bytes()),
96+
U64::from(12875u64),
97+
I64::from_le_bytes(6434624i64.to_le_bytes()),
98+
U64::from(14559u64),
99+
)
100+
}
101+
102+
#[cfg(test)]
103+
pub fn multiple_updates_results_full() -> [([u8; 32], U64, I32, I64, U64, I64, U64); 2] {
104+
[
105+
(
106+
multiple_updates_first_feed_id(),
107+
U64::from(1751573123u64),
108+
I32::from_le_bytes((-8i32).to_le_bytes()),
109+
I64::from_le_bytes(10990356724259i64.to_le_bytes()),
110+
U64::from(3891724259u64),
111+
I64::from_le_bytes(10974970400000i64.to_le_bytes()),
112+
U64::from(3918344000u64),
113+
),
114+
(
115+
multiple_updates_second_feed_id(),
116+
U64::from(1751573123u64),
117+
I32::from_le_bytes((-8i32).to_le_bytes()),
118+
I64::from_le_bytes(258906787480i64.to_le_bytes()),
119+
U64::from(158498649u64),
120+
I64::from_le_bytes(258597182000i64.to_le_bytes()),
121+
U64::from(131285914u64),
122+
),
123+
]
124+
}
125+
126+
#[cfg(test)]
127+
pub fn multiple_updates_diff_vaa_results_full() -> [([u8; 32], U64, I32, I64, U64, I64, U64); 2] {
78128
[
79129
(
80130
multiple_updates_diff_first_feed_id(),
@@ -98,51 +148,57 @@ pub fn multiple_updates_diff_vaa_results() -> [([u8; 32], U64, I32, I64, U64, I6
98148
}
99149

100150
#[cfg(test)]
101-
pub fn good_update1_results() -> ([u8; 32], U64, I32, I64, U64, I64, U64) {
151+
pub fn good_update1_results_get_price() -> (I64, U64, I32, U64) {
102152
(
103-
good_update1_feed_id(),
104-
U64::from(1752170378u64),
105-
I32::from_le_bytes((-8i32).to_le_bytes()),
106153
I64::from_le_bytes(6512459i64.to_le_bytes()),
107154
U64::from(20759u64),
108-
I64::from_le_bytes(6423048i64.to_le_bytes()),
109-
U64::from(14961u64),
155+
I32::from_le_bytes((-8i32).to_le_bytes()),
156+
U64::from(1752170378u64),
110157
)
111158
}
112159

113160
#[cfg(test)]
114-
pub fn good_update2_results() -> ([u8; 32], U64, I32, I64, U64, I64, U64) {
161+
pub fn good_update2_results_get_price() -> (I64, U64, I32, U64) {
115162
(
116-
good_update1_feed_id(),
117-
U64::from(1752171074u64),
118-
I32::from_le_bytes((-8i32).to_le_bytes()),
119163
I64::from_le_bytes(6468786i64.to_le_bytes()),
120164
U64::from(12875u64),
121-
I64::from_le_bytes(6434624i64.to_le_bytes()),
122-
U64::from(14559u64),
165+
I32::from_le_bytes((-8i32).to_le_bytes()),
166+
U64::from(1752171074u64),
123167
)
124168
}
125169

126170
#[cfg(test)]
127-
pub fn multiple_updates_results() -> [([u8; 32], U64, I32, I64, U64, I64, U64); 2] {
171+
pub fn multiple_updates_results_get_price() -> [(I64, U64, I32, U64); 2] {
128172
[
129173
(
130-
multiple_updates_first_feed_id(),
131-
U64::from(1751573123u64),
132-
I32::from_le_bytes((-8i32).to_le_bytes()),
133174
I64::from_le_bytes(10990356724259i64.to_le_bytes()),
134175
U64::from(3891724259u64),
135-
I64::from_le_bytes(10974970400000i64.to_le_bytes()),
136-
U64::from(3918344000u64),
176+
I32::from_le_bytes((-8i32).to_le_bytes()),
177+
U64::from(1751573123u64),
137178
),
138179
(
139-
multiple_updates_second_feed_id(),
140-
U64::from(1751573123u64),
141-
I32::from_le_bytes((-8i32).to_le_bytes()),
142180
I64::from_le_bytes(258906787480i64.to_le_bytes()),
143181
U64::from(158498649u64),
144-
I64::from_le_bytes(258597182000i64.to_le_bytes()),
145-
U64::from(131285914u64),
182+
I32::from_le_bytes((-8i32).to_le_bytes()),
183+
U64::from(1751573123u64),
184+
),
185+
]
186+
}
187+
188+
#[cfg(test)]
189+
pub fn multiple_updates_diff_vaa_results_get_price() -> [(I64, U64, I32, U64); 2] {
190+
[
191+
(
192+
I64::from_le_bytes(35134945i64.to_le_bytes()),
193+
U64::from(36279u64),
194+
I32::from_le_bytes((-8i32).to_le_bytes()),
195+
U64::from(1752094858u64),
196+
),
197+
(
198+
I64::from_le_bytes(10985663592646i64.to_le_bytes()),
199+
U64::from(4569386330u64),
200+
I32::from_le_bytes((-8i32).to_le_bytes()),
201+
U64::from(1751573860u64),
146202
),
147203
]
148204
}

0 commit comments

Comments
 (0)