11pub mod base;
22pub mod compress;
33pub mod v1;
4+ pub mod v10;
5+ pub mod v11;
6+ pub mod v13;
47pub mod v2;
58pub mod v3;
69pub mod v4;
@@ -9,8 +12,6 @@ pub mod v6;
912pub mod v7;
1013pub mod v8;
1114pub mod v9;
12- pub mod v10;
13- pub mod v13;
1415
1516use base:: { ReportBase , ReportError } ;
1617
@@ -124,8 +125,12 @@ pub fn decode_full_report(payload: &[u8]) -> Result<(Vec<[u8; 32]>, Vec<u8>), Re
124125#[ cfg( test) ]
125126mod tests {
126127 use super :: * ;
127- use crate :: report:: { v1:: ReportDataV1 , v2:: ReportDataV2 , v3:: ReportDataV3 , v4:: ReportDataV4 , v5:: ReportDataV5 , v6:: ReportDataV6 , v7:: ReportDataV7 , v8:: ReportDataV8 , v9:: ReportDataV9 , v10:: ReportDataV10 , v13:: ReportDataV13 } ;
128- use num_bigint:: { BigInt } ;
128+ use crate :: report:: {
129+ v1:: ReportDataV1 , v10:: ReportDataV10 , v11:: ReportDataV11 , v13:: ReportDataV13 ,
130+ v2:: ReportDataV2 , v3:: ReportDataV3 , v4:: ReportDataV4 , v5:: ReportDataV5 , v6:: ReportDataV6 ,
131+ v7:: ReportDataV7 , v8:: ReportDataV8 , v9:: ReportDataV9 ,
132+ } ;
133+ use num_bigint:: BigInt ;
129134
130135 const V1_FEED_ID : ID = ID ( [
131136 0 , 1 , 107 , 74 , 167 , 229 , 124 , 167 , 182 , 138 , 225 , 191 , 69 , 101 , 63 , 86 , 182 , 86 , 253 , 58 ,
@@ -167,20 +172,29 @@ mod tests {
167172 00 , 10 , 107 , 74 , 167 , 229 , 124 , 167 , 182 , 138 , 225 , 191 , 69 , 101 , 63 , 86 , 182 , 86 , 253 , 58 ,
168173 163 , 53 , 239 , 127 , 174 , 105 , 107 , 102 , 63 , 27 , 132 , 114 ,
169174 ] ) ;
175+ const V11_FEED_ID : ID = ID ( [
176+ 00 , 11 , 251 , 109 , 19 , 88 , 151 , 228 , 170 , 245 , 101 , 123 , 255 , 211 , 176 , 180 , 143 , 142 , 42 ,
177+ 81 , 49 , 33 , 76 , 158 , 194 , 214 , 46 , 172 , 93 , 83 , 32 , 103 ,
178+ ] ) ;
170179 const V13_FEED_ID : ID = ID ( [
171180 00 , 13 , 19 , 169 , 185 , 197 , 227 , 122 , 9 , 159 , 55 , 78 , 146 , 195 , 121 , 20 , 175 , 92 , 38 , 143 ,
172181 58 , 138 , 151 , 33 , 241 , 114 , 81 , 53 , 191 , 180 , 203 , 184 ,
173182 ] ) ;
174183
175184 pub const MOCK_TIMESTAMP : u32 = 1718885772 ;
185+ pub const MOCK_LAST_SEEN_TIMESTAMP_NS : u64 = 1718885772000000000 ;
176186 pub const MOCK_FEE : usize = 10 ;
177187 pub const MOCK_PRICE : isize = 100 ;
178188 pub const MARKET_STATUS_OPEN : u32 = 2 ;
179- pub const MOCK_BEST_ASK : isize = 227 ;
180- pub const MOCK_BEST_BID : isize = 229 ;
189+ pub const MOCK_ASK : isize = 229 ;
190+ pub const MOCK_BEST_ASK : isize = 229 ;
191+ pub const MOCK_BID : isize = 227 ;
192+ pub const MOCK_BEST_BID : isize = 227 ;
181193 pub const MOCK_ASK_VOLUME : u64 = 1500 ;
182194 pub const MOCK_BID_VOLUME : u64 = 1200 ;
183195 pub const MOCK_LAST_TRADED_PRICE : isize = 228 ;
196+ pub const MOCK_MID : isize = 228 ;
197+ pub const MOCK_MARKET_STATUS : u32 = 2 ;
184198
185199 pub fn generate_mock_report_data_v1 ( ) -> ReportDataV1 {
186200 let report_data = ReportDataV1 {
@@ -357,6 +371,31 @@ mod tests {
357371 report_data
358372 }
359373
374+ pub fn generate_mock_report_data_v11 ( ) -> ReportDataV11 {
375+ let multiplier: BigInt = "1000000000000000000" . parse :: < BigInt > ( ) . unwrap ( ) ; // 1.0 with 18 decimals
376+
377+ let report_data = ReportDataV11 {
378+ feed_id : V11_FEED_ID ,
379+ valid_from_timestamp : MOCK_TIMESTAMP ,
380+ observations_timestamp : MOCK_TIMESTAMP ,
381+ native_fee : BigInt :: from ( MOCK_FEE ) ,
382+ link_fee : BigInt :: from ( MOCK_FEE ) ,
383+ expires_at : MOCK_TIMESTAMP + 100 ,
384+ mid : BigInt :: from ( MOCK_MID ) . checked_mul ( & multiplier) . unwrap ( ) ,
385+ last_seen_timestamp_ns : MOCK_LAST_SEEN_TIMESTAMP_NS ,
386+ bid : BigInt :: from ( MOCK_BID ) . checked_mul ( & multiplier) . unwrap ( ) ,
387+ bid_volume : MOCK_BID_VOLUME ,
388+ ask : BigInt :: from ( MOCK_ASK ) . checked_mul ( & multiplier) . unwrap ( ) ,
389+ ask_volume : MOCK_ASK_VOLUME ,
390+ last_traded_price : BigInt :: from ( MOCK_LAST_TRADED_PRICE )
391+ . checked_mul ( & multiplier)
392+ . unwrap ( ) ,
393+ market_status : MOCK_MARKET_STATUS ,
394+ } ;
395+
396+ report_data
397+ }
398+
360399 pub fn generate_mock_report_data_v13 ( ) -> ReportDataV13 {
361400 let multiplier: BigInt = "1000000000000000000" . parse :: < BigInt > ( ) . unwrap ( ) ; // 1.0 with 18 decimals
362401
@@ -367,11 +406,17 @@ mod tests {
367406 native_fee : BigInt :: from ( MOCK_FEE ) ,
368407 link_fee : BigInt :: from ( MOCK_FEE ) ,
369408 expires_at : MOCK_TIMESTAMP + 100 ,
370- best_ask : BigInt :: from ( MOCK_BEST_ASK ) . checked_mul ( & multiplier) . unwrap ( ) ,
371- best_bid : BigInt :: from ( MOCK_BEST_BID ) . checked_mul ( & multiplier) . unwrap ( ) ,
409+ best_ask : BigInt :: from ( MOCK_BEST_ASK )
410+ . checked_mul ( & multiplier)
411+ . unwrap ( ) ,
412+ best_bid : BigInt :: from ( MOCK_BEST_BID )
413+ . checked_mul ( & multiplier)
414+ . unwrap ( ) ,
372415 ask_volume : MOCK_ASK_VOLUME ,
373416 bid_volume : MOCK_BID_VOLUME ,
374- last_traded_price : BigInt :: from ( MOCK_LAST_TRADED_PRICE ) . checked_mul ( & multiplier) . unwrap ( ) ,
417+ last_traded_price : BigInt :: from ( MOCK_LAST_TRADED_PRICE )
418+ . checked_mul ( & multiplier)
419+ . unwrap ( ) ,
375420 } ;
376421
377422 report_data
@@ -727,6 +772,42 @@ mod tests {
727772 assert_eq ! ( decoded_report. feed_id, V10_FEED_ID ) ;
728773 }
729774
775+ #[ test]
776+ fn test_decode_report_v11 ( ) {
777+ let report_data = generate_mock_report_data_v11 ( ) ;
778+ let encoded_report_data = report_data. abi_encode ( ) . unwrap ( ) ;
779+
780+ let report = generate_mock_report ( & encoded_report_data) ;
781+
782+ let ( _report_context, report_blob) = decode_full_report ( & report) . unwrap ( ) ;
783+
784+ let expected_report_blob = vec ! [
785+ "000bfb6d135897e4aaf5657bffd3b0b48f8e2a5131214c9ec2d62eac5d532067" , // feed_id
786+ "0000000000000000000000000000000000000000000000000000000066741d8c" , // valid_from_timestamp
787+ "0000000000000000000000000000000000000000000000000000000066741d8c" , // observations_timestamp
788+ "000000000000000000000000000000000000000000000000000000000000000a" , // native_fee
789+ "000000000000000000000000000000000000000000000000000000000000000a" , // link_fee
790+ "0000000000000000000000000000000000000000000000000000000066741df0" , // expires_at
791+ "00000000000000000000000000000000000000000000000c5c22b80115100000" , // mid: 228 * 10^18
792+ "00000000000000000000000000000000000000000000000017dab580a9887800" , // last_seen_timestamp_ns
793+ "00000000000000000000000000000000000000000000000c4e42014d6dac0000" , // bid: 227 * 10^18
794+ "00000000000000000000000000000000000000000000000000000000000004b0" , // bid_volume: 1200
795+ "00000000000000000000000000000000000000000000000c6a036eb4bc740000" , // ask: 229 * 10^18
796+ "00000000000000000000000000000000000000000000000000000000000005dc" , // ask_volume: 1500
797+ "00000000000000000000000000000000000000000000000c5c22b80115100000" , // last_traded_price: 228 * 10^18
798+ "0000000000000000000000000000000000000000000000000000000000000002" , // market_status: 2 (open)
799+ ] ;
800+
801+ let expected = bytes ( & format ! ( "0x{}" , expected_report_blob. join( "" ) ) ) ;
802+ println ! ( "Actual : {}" , hex:: encode( & report_blob) ) ;
803+ println ! ( "Expected: {}" , hex:: encode( & expected) ) ;
804+ assert_eq ! ( report_blob, expected) ;
805+
806+ let decoded_report = ReportDataV10 :: decode ( & report_blob) . unwrap ( ) ;
807+
808+ assert_eq ! ( decoded_report. feed_id, V11_FEED_ID ) ;
809+ }
810+
730811 #[ test]
731812 fn test_decode_report_v13 ( ) {
732813 let report_data = generate_mock_report_data_v13 ( ) ;
@@ -743,8 +824,8 @@ mod tests {
743824 "000000000000000000000000000000000000000000000000000000000000000a" , // native_fee
744825 "000000000000000000000000000000000000000000000000000000000000000a" , // link_fee
745826 "0000000000000000000000000000000000000000000000000000000066741df0" , // expires_at
746- "00000000000000000000000000000000000000000000000c4e42014d6dac0000 " , // best_ask: 227 * 10^18
747- "00000000000000000000000000000000000000000000000c6a036eb4bc740000 " , // best_bid: 229 * 10^18
827+ "00000000000000000000000000000000000000000000000c6a036eb4bc740000 " , // best_ask: 229 * 10^18
828+ "00000000000000000000000000000000000000000000000c4e42014d6dac0000 " , // best_bid: 227 * 10^18
748829 "00000000000000000000000000000000000000000000000000000000000005dc" , // ask_volume: 1500
749830 "00000000000000000000000000000000000000000000000000000000000004b0" , // bid_volume: 1200
750831 "00000000000000000000000000000000000000000000000c5c22b80115100000" , // last_traded_price: 228 * 10^18
0 commit comments