11module pyth_lazer ::pyth_lazer ;
22
3- use pyth_lazer::i16::{Self , I16 };
4- use pyth_lazer::i64::{Self , I64 };
5- use pyth_lazer::update::Update ;
3+ use pyth_lazer::i16::Self ;
4+ use pyth_lazer::i64::Self ;
5+ use pyth_lazer::update::{Self , Update };
6+ use pyth_lazer::feed::{Self , Feed };
7+ use pyth_lazer::channel::Self ;
68use sui::bcs;
79use sui::ecdsa_k1::secp256k1_ecrecover;
810
@@ -47,15 +49,15 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
4749 let timestamp = cursor.peel_u64 ();
4850 let channel_value = cursor.peel_u8 ();
4951 let channel = if (channel_value == 0 ) {
50- Channel:: Invalid
52+ channel:: new_invalid ()
5153 } else if (channel_value == 1 ) {
52- Channel:: RealTime
54+ channel:: new_real_time ()
5355 } else if (channel_value == 2 ) {
54- Channel:: FixedRate50ms
56+ channel:: new_fixed_rate_50ms ()
5557 } else if (channel_value == 3 ) {
56- Channel:: FixedRate200ms
58+ channel:: new_fixed_rate_200ms ()
5759 } else {
58- Channel:: Invalid // Default to Invalid for unknown values
60+ channel:: new_invalid () // Default to Invalid for unknown values
5961 };
6062
6163 let mut feeds = vector ::empty <Feed >();
@@ -65,17 +67,17 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
6567
6668 while (feed_i < feed_count) {
6769 let feed_id = cursor.peel_u32 ();
68- let mut feed = Feed {
69- feed_id: feed_id ,
70- price: option::none (),
71- best_bid_price: option::none (),
72- best_ask_price: option::none (),
73- publisher_count: option::none (),
74- exponent: option::none (),
75- confidence: option::none (),
76- funding_rate: option::none (),
77- funding_timestamp: option::none (),
78- } ;
70+ let mut feed = feed:: new (
71+ feed_id,
72+ option::none (),
73+ option::none (),
74+ option::none (),
75+ option::none (),
76+ option::none (),
77+ option::none (),
78+ option::none (),
79+ option::none ()
80+ ) ;
7981
8082 let properties_count = cursor.peel_u8 ();
8183 let mut properties_i = 0 ;
@@ -86,53 +88,53 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
8688 if (property_id == 0 ) {
8789 let price = cursor.peel_u64 ();
8890 if (price != 0 ) {
89- feed.price = option::some (option::some (i64::from_u64 (price)));
91+ feed.set_price ( option::some (option::some (i64::from_u64 (price) )));
9092 } else {
91- feed.price = option::some (option::none ());
93+ feed.set_price ( option::some (option::none () ));
9294 }
9395 } else if (property_id == 1 ) {
9496 let best_bid_price = cursor.peel_u64 ();
9597 if (best_bid_price != 0 ) {
96- feed.best_bid_price = option::some (option::some (i64::from_u64 (best_bid_price)));
98+ feed.set_best_bid_price ( option::some (option::some (i64::from_u64 (best_bid_price) )));
9799 } else {
98- feed.best_bid_price = option::some (option::none ());
100+ feed.set_best_bid_price ( option::some (option::none () ));
99101 }
100102 } else if (property_id == 2 ) {
101103 let best_ask_price = cursor.peel_u64 ();
102104 if (best_ask_price != 0 ) {
103- feed.best_ask_price = option::some (option::some (i64::from_u64 (best_ask_price)));
105+ feed.set_best_ask_price ( option::some (option::some (i64::from_u64 (best_ask_price) )));
104106 } else {
105- feed.best_ask_price = option::some (option::none ());
107+ feed.set_best_ask_price ( option::some (option::none () ));
106108 }
107109 } else if (property_id == 3 ) {
108110 let publisher_count = cursor.peel_u16 ();
109- feed.publisher_count = option::some (publisher_count);
111+ feed.set_publisher_count ( option::some (publisher_count) );
110112 } else if (property_id == 4 ) {
111113 let exponent = cursor.peel_u16 ();
112- feed.exponent = option::some (i16::from_u16 (exponent));
114+ feed.set_exponent ( option::some (i16::from_u16 (exponent) ));
113115 } else if (property_id == 5 ) {
114116 let confidence = cursor.peel_u64 ();
115117 if (confidence != 0 ) {
116- feed.confidence = option::some (option::some (i64::from_u64 (confidence)));
118+ feed.set_confidence ( option::some (option::some (i64::from_u64 (confidence) )));
117119 } else {
118- feed.confidence = option::some (option::none ());
120+ feed.set_confidence ( option::some (option::none () ));
119121 }
120122 } else if (property_id == 6 ) {
121123 let exists = cursor.peel_u8 ();
122124 if (exists == 1 ) {
123125 let funding_rate = cursor.peel_u64 ();
124- feed.funding_rate = option::some (option::some (i64::from_u64 (funding_rate)));
126+ feed.set_funding_rate ( option::some (option::some (i64::from_u64 (funding_rate) )));
125127 } else {
126- feed.funding_rate = option::some (option::none ());
128+ feed.set_funding_rate ( option::some (option::none () ));
127129 }
128130 } else if (property_id == 7 ) {
129131 let exists = cursor.peel_u8 ();
130132
131133 if (exists == 1 ) {
132134 let funding_timestamp = cursor.peel_u64 ();
133- feed.funding_timestamp = option::some (option::some (funding_timestamp));
135+ feed.set_funding_timestamp ( option::some (option::some (funding_timestamp) ));
134136 } else {
135- feed.funding_timestamp = option::some (option::none ());
137+ feed.set_funding_timestamp ( option::some (option::none () ));
136138 }
137139 } else {
138140 // When we have an unknown property, we do not know its length, and therefore
@@ -151,9 +153,5 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
151153 let remaining_bytes = cursor.into_remainder_bytes ();
152154 assert !(remaining_bytes.length () == 0 , 0 );
153155
154- Update {
155- timestamp: timestamp,
156- channel: channel,
157- feeds: feeds,
158- }
156+ update::new (timestamp, channel, feeds)
159157}
0 commit comments