1
1
#include "imports/stdlib.fc";
2
2
#include "common/errors.fc";
3
3
#include "common/storage.fc";
4
+ #include "common/utils.fc";
5
+ #include "./Wormhole.fc";
6
+
7
+ const int ACCUMULATOR_MAGIC = 0x504e4155; ;; "PNAU" (Pyth Network Accumulator Update)
8
+ const int MAJOR_VERSION = 1;
9
+ const int MINIMUM_ALLOWED_MINOR_VERSION = 0;
10
+
11
+ slice verify_header(slice data) {
12
+ int magic = data~load_uint(32);
13
+ throw_unless(ERROR_INVALID_MAGIC, magic == ACCUMULATOR_MAGIC);
14
+ int major_version = data~load_uint(8);
15
+ throw_unless(ERROR_INVALID_MAJOR_VERSION, major_version == MAJOR_VERSION);
16
+ int minor_version = data~load_uint(8);
17
+ throw_if(ERROR_INVALID_MINOR_VERSION, minor_version < MINIMUM_ALLOWED_MINOR_VERSION);
18
+ int trailing_header_size = data~load_uint(8);
19
+ ;; skip trailing headers and update type (uint8)
20
+ data~skip_bits(trailing_header_size);
21
+ data~skip_bits(8);
22
+ return data;
23
+ }
24
+
25
+ (int) get_update_fee(slice data) method_id {
26
+ load_data();
27
+ slice cs = verify_header(data);
28
+ int wormhole_proof_size_bytes = cs~load_uint(16);
29
+ (cell wormhole_proof, slice cs) = read_and_store_large_data(cs, wormhole_proof_size_bytes * 8);
30
+ int num_updates = cs~load_uint(8);
31
+ return single_update_fee * num_updates;
32
+ }
4
33
5
- ;; Opcodes
6
- const int OP_UPDATE_GUARDIAN_SET = 1;
7
- const int OP_EXECUTE_GOVERNANCE_ACTION = 2;
8
34
9
35
(int, int, int, int) parse_price(slice price_feed) {
10
36
int price = price_feed~load_int(256);
@@ -14,22 +40,25 @@ const int OP_EXECUTE_GOVERNANCE_ACTION = 2;
14
40
return (price, conf, expo, publish_time);
15
41
}
16
42
17
- (int, int, int, int) price_unsafe(int price_feed_id) method_id {
43
+ (int, int, int, int) get_price_unsafe(int price_feed_id) method_id {
44
+ load_data();
18
45
(slice result, int success) = latest_price_feeds.udict_get?(256, price_feed_id);
19
46
throw_unless(ERROR_PRICE_FEED_NOT_FOUND, success);
20
47
slice price_feed = result~load_ref().begin_parse();
21
48
slice price = price_feed~load_ref().begin_parse();
22
49
return parse_price(price);
23
50
}
24
51
25
- (int, int, int, int) price_no_older_than(int time_period, int price_feed_id) method_id {
26
- (int price, int conf, int expo, int publish_time) = price_unsafe(price_feed_id);
52
+ (int, int, int, int) get_price_no_older_than(int time_period, int price_feed_id) method_id {
53
+ load_data();
54
+ (int price, int conf, int expo, int publish_time) = get_price_unsafe(price_feed_id);
27
55
int current_time = now();
28
56
throw_if(ERROR_OUTDATED_PRICE, current_time - publish_time > time_period);
29
57
return (price, conf, expo, publish_time);
30
58
}
31
59
32
- (int, int, int, int) ema_price_unsafe(int price_feed_id) method_id {
60
+ (int, int, int, int) get_ema_price_unsafe(int price_feed_id) method_id {
61
+ load_data();
33
62
(slice result, int success) = latest_price_feeds.udict_get?(256, price_feed_id);
34
63
throw_unless(ERROR_PRICE_FEED_NOT_FOUND, success);
35
64
slice price_feed = result~load_ref().begin_parse();
@@ -38,8 +67,9 @@ const int OP_EXECUTE_GOVERNANCE_ACTION = 2;
38
67
return parse_price(ema_price);
39
68
}
40
69
41
- (int, int, int, int) ema_price_no_older_than(int time_period, int price_feed_id) method_id {
42
- (int price, int conf, int expo, int publish_time) = ema_price_unsafe(price_feed_id);
70
+ (int, int, int, int) get_ema_price_no_older_than(int time_period, int price_feed_id) method_id {
71
+ load_data();
72
+ (int price, int conf, int expo, int publish_time) = get_ema_price_unsafe(price_feed_id);
43
73
int current_time = now();
44
74
throw_if(ERROR_OUTDATED_PRICE, current_time - publish_time > time_period);
45
75
return (price, conf, expo, publish_time);
0 commit comments