1
1
module pyth_lazer ::pyth_lazer ;
2
2
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 ;
6
8
use sui::bcs;
7
9
use sui::ecdsa_k1::secp256k1_ecrecover;
8
10
@@ -47,15 +49,15 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
47
49
let timestamp = cursor.peel_u64 ();
48
50
let channel_value = cursor.peel_u8 ();
49
51
let channel = if (channel_value == 0 ) {
50
- Channel:: Invalid
52
+ channel:: new_invalid ()
51
53
} else if (channel_value == 1 ) {
52
- Channel:: RealTime
54
+ channel:: new_real_time ()
53
55
} else if (channel_value == 2 ) {
54
- Channel:: FixedRate50ms
56
+ channel:: new_fixed_rate_50ms ()
55
57
} else if (channel_value == 3 ) {
56
- Channel:: FixedRate200ms
58
+ channel:: new_fixed_rate_200ms ()
57
59
} else {
58
- Channel:: Invalid // Default to Invalid for unknown values
60
+ channel:: new_invalid () // Default to Invalid for unknown values
59
61
};
60
62
61
63
let mut feeds = vector ::empty <Feed >();
@@ -65,17 +67,17 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
65
67
66
68
while (feed_i < feed_count) {
67
69
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
+ ) ;
79
81
80
82
let properties_count = cursor.peel_u8 ();
81
83
let mut properties_i = 0 ;
@@ -86,53 +88,53 @@ public fun parse_and_validate_update(update: vector<u8>): Update {
86
88
if (property_id == 0 ) {
87
89
let price = cursor.peel_u64 ();
88
90
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) )));
90
92
} else {
91
- feed.price = option::some (option::none ());
93
+ feed.set_price ( option::some (option::none () ));
92
94
}
93
95
} else if (property_id == 1 ) {
94
96
let best_bid_price = cursor.peel_u64 ();
95
97
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) )));
97
99
} else {
98
- feed.best_bid_price = option::some (option::none ());
100
+ feed.set_best_bid_price ( option::some (option::none () ));
99
101
}
100
102
} else if (property_id == 2 ) {
101
103
let best_ask_price = cursor.peel_u64 ();
102
104
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) )));
104
106
} else {
105
- feed.best_ask_price = option::some (option::none ());
107
+ feed.set_best_ask_price ( option::some (option::none () ));
106
108
}
107
109
} else if (property_id == 3 ) {
108
110
let publisher_count = cursor.peel_u16 ();
109
- feed.publisher_count = option::some (publisher_count);
111
+ feed.set_publisher_count ( option::some (publisher_count) );
110
112
} else if (property_id == 4 ) {
111
113
let exponent = cursor.peel_u16 ();
112
- feed.exponent = option::some (i16::from_u16 (exponent));
114
+ feed.set_exponent ( option::some (i16::from_u16 (exponent) ));
113
115
} else if (property_id == 5 ) {
114
116
let confidence = cursor.peel_u64 ();
115
117
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) )));
117
119
} else {
118
- feed.confidence = option::some (option::none ());
120
+ feed.set_confidence ( option::some (option::none () ));
119
121
}
120
122
} else if (property_id == 6 ) {
121
123
let exists = cursor.peel_u8 ();
122
124
if (exists == 1 ) {
123
125
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) )));
125
127
} else {
126
- feed.funding_rate = option::some (option::none ());
128
+ feed.set_funding_rate ( option::some (option::none () ));
127
129
}
128
130
} else if (property_id == 7 ) {
129
131
let exists = cursor.peel_u8 ();
130
132
131
133
if (exists == 1 ) {
132
134
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) ));
134
136
} else {
135
- feed.funding_timestamp = option::some (option::none ());
137
+ feed.set_funding_timestamp ( option::some (option::none () ));
136
138
}
137
139
} else {
138
140
// 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 {
151
153
let remaining_bytes = cursor.into_remainder_bytes ();
152
154
assert !(remaining_bytes.length () == 0 , 0 );
153
155
154
- Update {
155
- timestamp: timestamp,
156
- channel: channel,
157
- feeds: feeds,
158
- }
156
+ update::new (timestamp, channel, feeds)
159
157
}
0 commit comments