Skip to content

Commit 9eef20a

Browse files
committed
figuring out mini-alloc
1 parent e4ea5a0 commit 9eef20a

File tree

6 files changed

+92
-97
lines changed

6 files changed

+92
-97
lines changed

target_chains/stylus/Cargo.lock

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

target_chains/stylus/contracts/pyth-receiver/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@ alloy-sol-types = "=0.8.20"
1313
stylus-sdk = "0.9.0"
1414
byteorder = { version = "1.4.3" }
1515
hex = { version = "0.4", default-features = false }
16+
mini-alloc = { workspace = true, default-features = false }
1617
pythnet-sdk = { path = "../../../../pythnet/pythnet_sdk" }
17-
pyth-types = { path = "../pyth-types" }
1818
serde = { version = "1.0", features = ["derive"] }
1919
wormhole-vaas = "0.1.1"
20-
wormhole-contract = { path = "../../contracts/wormhole" }
2120

2221

2322
[dev-dependencies]
@@ -49,4 +48,4 @@ panic = "abort"
4948

5049
# If you need to reduce the binary size, it is advisable to try other
5150
# optimization levels, such as "s" and "z"
52-
opt-level = 3
51+
opt-level = "s"

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod test {
2727

2828
fn initialize_test_contract(vm: &TestVM) -> PythReceiver {
2929
let mut contract = PythReceiver::from(vm);
30-
let wormhole_address = address!("0x3F38404A2e3Cb949bcDfA19a5C3bDf3fE375fEb0");
30+
let wormhole_address = address!("0x395921b642ba511d421ae834fef56ac886735ca2");
3131
let single_update_fee = U256::from(100u64);
3232
let valid_time_period = U256::from(3600u64);
3333

@@ -130,7 +130,7 @@ mod test {
130130

131131
let test_price_id = TEST_PRICE_ID;
132132

133-
let update_data = create_valid_update_data();
133+
let update_data = test_data::good_update1();
134134
let _result = contract.update_price_feeds(update_data);
135135

136136

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

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ impl PythReceiver {
154154
Ok(())
155155
}
156156

157-
pub fn update_price_feeds_if_necessary(
158-
&mut self,
159-
_update_data: Vec<Vec<u8>>,
160-
_price_ids: Vec<[u8; 32]>,
161-
_publish_times: Vec<u64>,
162-
) {
163-
// dummy implementation
164-
}
157+
// pub fn update_price_feeds_if_necessary(
158+
// &mut self,
159+
// _update_data: Vec<Vec<u8>>,
160+
// _price_ids: Vec<[u8; 32]>,
161+
// _publish_times: Vec<u64>,
162+
// ) {
163+
// // dummy implementation
164+
// }
165165

166166
// fn update_price_feeds_internal(&mut self, update_data: Vec<u8>, price_ids: Vec<Address>, min_publish_time: u64, max_publish_time: u64, unique: bool) -> Result<(), PythReceiverError> {
167167
fn update_price_feeds_internal(&mut self, update_data: Vec<u8>) -> Result<(), PythReceiverError> {
@@ -240,60 +240,57 @@ impl PythReceiver {
240240
Ok(())
241241
}
242242

243-
pub fn get_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
244-
U256::from(0u8)
245-
}
246-
247-
pub fn get_twap_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
248-
U256::from(0u8)
249-
}
250-
251-
pub fn parse_price_feed_updates(
252-
&mut self,
253-
_update_data: Vec<Vec<u8>>,
254-
_price_ids: Vec<[u8; 32]>,
255-
_min_publish_time: u64,
256-
_max_publish_time: u64,
257-
) -> Vec<PriceInfoReturn> {
258-
Vec::new()
259-
}
260-
261-
pub fn parse_price_feed_updates_with_config(
262-
&mut self,
263-
_update_data: Vec<Vec<u8>>,
264-
_price_ids: Vec<[u8; 32]>,
265-
_min_allowed_publish_time: u64,
266-
_max_allowed_publish_time: u64,
267-
_check_uniqueness: bool,
268-
_check_update_data_is_minimal: bool,
269-
_store_updates_if_fresh: bool,
270-
) -> (Vec<PriceInfoReturn>, Vec<u64>) {
271-
(Vec::new(), Vec::new())
272-
}
273-
274-
pub fn parse_twap_price_feed_updates(
275-
&mut self,
276-
_update_data: Vec<Vec<u8>>,
277-
_price_ids: Vec<[u8; 32]>,
278-
) -> Vec<PriceInfoReturn> {
279-
Vec::new()
280-
}
281-
282-
pub fn parse_price_feed_updates_unique(
283-
&mut self,
284-
_update_data: Vec<Vec<u8>>,
285-
_price_ids: Vec<[u8; 32]>,
286-
_min_publish_time: u64,
287-
_max_publish_time: u64,
288-
) -> Vec<PriceInfoReturn> {
289-
Vec::new()
290-
}
243+
// pub fn get_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
244+
// U256::from(0u8)
245+
// }
246+
247+
// pub fn get_twap_update_fee(&self, _update_data: Vec<Vec<u8>>) -> U256 {
248+
// U256::from(0u8)
249+
// }
250+
251+
// pub fn parse_price_feed_updates(
252+
// &mut self,
253+
// _update_data: Vec<Vec<u8>>,
254+
// _price_ids: Vec<[u8; 32]>,
255+
// _min_publish_time: u64,
256+
// _max_publish_time: u64,
257+
// ) -> Vec<PriceInfoReturn> {
258+
// Vec::new()
259+
// }
260+
261+
// pub fn parse_price_feed_updates_with_config(
262+
// &mut self,
263+
// _update_data: Vec<Vec<u8>>,
264+
// _price_ids: Vec<[u8; 32]>,
265+
// _min_allowed_publish_time: u64,
266+
// _max_allowed_publish_time: u64,
267+
// _check_uniqueness: bool,
268+
// _check_update_data_is_minimal: bool,
269+
// _store_updates_if_fresh: bool,
270+
// ) -> (Vec<PriceInfoReturn>, Vec<u64>) {
271+
// (Vec::new(), Vec::new())
272+
// }
273+
274+
// pub fn parse_twap_price_feed_updates(
275+
// &mut self,
276+
// _update_data: Vec<Vec<u8>>,
277+
// _price_ids: Vec<[u8; 32]>,
278+
// ) -> Vec<PriceInfoReturn> {
279+
// Vec::new()
280+
// }
281+
282+
// pub fn parse_price_feed_updates_unique(
283+
// &mut self,
284+
// _update_data: Vec<Vec<u8>>,
285+
// _price_ids: Vec<[u8; 32]>,
286+
// _min_publish_time: u64,
287+
// _max_publish_time: u64,
288+
// ) -> Vec<PriceInfoReturn> {
289+
// Vec::new()
290+
// }
291291

292292
fn is_no_older_than(&self, publish_time: U64, max_age: u64) -> bool {
293-
let current_u64: u64 = self.vm().block_timestamp();
294-
let publish_time_u64: u64 = publish_time.to::<u64>();
295-
296-
current_u64.saturating_sub(publish_time_u64) <= max_age
293+
self.vm().block_timestamp().saturating_sub(publish_time.to::<u64>()) <= max_age
297294
}
298295
}
299296

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ pub struct DataSource {
4646
pub emitter_address: FixedBytes<32>,
4747
}
4848

49-
impl StorageKey for DataSourceStorage {
50-
fn to_slot(&self, root: B256) -> U256 {
51-
let chain_id: u16 = self.chain_id.get().to::<u16>();
52-
let emitter_address = self.emitter_address.get();
49+
// impl StorageKey for DataSourceStorage {
50+
// fn to_slot(&self, root: B256) -> U256 {
51+
// let chain_id: u16 = self.chain_id.get().to::<u16>();
52+
// let emitter_address = self.emitter_address.get();
5353

54-
let bytes = serialize_data_source_to_bytes(chain_id, emitter_address.as_slice().try_into().unwrap())
55-
.expect("Failed to serialize DataSource");
54+
// let bytes = serialize_data_source_to_bytes(chain_id, emitter_address.as_slice().try_into().unwrap())
55+
// .expect("Failed to serialize DataSource");
5656

57-
keccak256(bytes).to_slot(root)
58-
}
59-
}
57+
// keccak256(bytes).to_slot(root)
58+
// }
59+
// }
6060

6161
impl StorageKey for DataSource {
6262
fn to_slot(&self, root: B256) -> U256 {
@@ -97,27 +97,27 @@ pub struct PriceInfoStorage {
9797
pub ema_conf: StorageU64,
9898
}
9999

100-
pub struct PriceInfo {
101-
pub publish_time: U64,
102-
pub expo: I32,
103-
pub price: I64,
104-
pub conf: U64,
105-
pub ema_price: I64,
106-
pub ema_conf: U64,
107-
}
100+
// pub struct PriceInfo {
101+
// pub publish_time: U64,
102+
// pub expo: I32,
103+
// pub price: I64,
104+
// pub conf: U64,
105+
// pub ema_price: I64,
106+
// pub ema_conf: U64,
107+
// }
108108

109-
impl From<&PriceFeedMessage> for PriceInfo {
110-
fn from(price_feed_message: &PriceFeedMessage) -> Self {
111-
Self {
112-
publish_time: U64::from(price_feed_message.publish_time),
113-
expo: I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),
114-
price: I64::from_be_bytes(price_feed_message.price.to_be_bytes()),
115-
conf: U64::from(price_feed_message.conf),
116-
ema_price: I64::from_be_bytes(price_feed_message.ema_price.to_be_bytes()),
117-
ema_conf: U64::from(price_feed_message.ema_conf),
118-
}
119-
}
120-
}
109+
// impl From<&PriceFeedMessage> for PriceInfo {
110+
// fn from(price_feed_message: &PriceFeedMessage) -> Self {
111+
// Self {
112+
// publish_time: U64::from(price_feed_message.publish_time),
113+
// expo: I32::from_be_bytes(price_feed_message.exponent.to_be_bytes()),
114+
// price: I64::from_be_bytes(price_feed_message.price.to_be_bytes()),
115+
// conf: U64::from(price_feed_message.conf),
116+
// ema_price: I64::from_be_bytes(price_feed_message.ema_price.to_be_bytes()),
117+
// ema_conf: U64::from(price_feed_message.ema_conf),
118+
// }
119+
// }
120+
// }
121121

122122
// PriceInfo struct storing price information
123123
pub type PriceInfoReturn = (U64, I32, I64, U64, I64, U64);

target_chains/stylus/contracts/wormhole/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate alloc;
55
#[global_allocator]
66
static ALLOC: mini_alloc::MiniAlloc = mini_alloc::MiniAlloc::INIT;
77

8-
#[cfg(all(not(any(feature = "std", feature = "export-abi")), feature = "main"))]
8+
#[cfg(all(not(any(feature = "std", feature = "export-abi"))))]
99
#[panic_handler]
1010
fn panic(_info: &core::panic::PanicInfo) -> ! {
1111
loop {}

0 commit comments

Comments
 (0)