Skip to content

Commit 35c23b4

Browse files
authored
feat(target_chains/starknet): add reexports and utils (#1652)
1 parent b2ab8f5 commit 35c23b4

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

target_chains/starknet/contracts/Scarb.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ starknet = ">=2.5.4"
88
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
99
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.21.0" }
1010

11+
[lib]
12+
1113
[[target.starknet-contract]]
1214
build-external-contracts = ["openzeppelin::presets::erc20::ERC20"]

target_chains/starknet/contracts/src/lib.cairo

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@ pub mod reader;
55
pub mod hash;
66
pub mod util;
77
pub mod merkle_tree;
8+
9+
pub use byte_array::{ByteArray, ByteArrayTrait};
10+
pub use pyth::{
11+
Event, PriceFeedUpdated, WormholeAddressSet, GovernanceDataSourceSet, ContractUpgraded,
12+
DataSourcesSet, FeeSet, GetPriceUnsafeError, GovernanceActionError, UpdatePriceFeedsError,
13+
GetPriceNoOlderThanError, UpdatePriceFeedsIfNecessaryError, ParsePriceFeedsError, IPyth,
14+
IPythDispatcher, IPythDispatcherTrait, DataSource, Price, PriceFeedPublishTime, PriceFeed,
15+
};
16+
pub use util::{exp10, UnwrapWithFelt252, ResultMapErrInto};

target_chains/starknet/contracts/src/util.cairo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
mod exp10_;
2+
3+
pub use exp10_::exp10;
4+
15
use core::integer::u128_byte_reverse;
26

37
pub const ONE_SHIFT_160: u256 = 0x10000000000000000000000000000000000000000;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
pub fn exp10(x: u8) -> u256 {
2+
match x {
3+
0 => 1,
4+
1 => 10,
5+
2 => 100,
6+
3 => 1000,
7+
4 => 10000,
8+
5 => 100000,
9+
6 => 1000000,
10+
7 => 10000000,
11+
8 => 100000000,
12+
9 => 1000000000,
13+
10 => 10000000000,
14+
11 => 100000000000,
15+
12 => 1000000000000,
16+
13 => 10000000000000,
17+
14 => 100000000000000,
18+
15 => 1000000000000000,
19+
16 => 10000000000000000,
20+
17 => 100000000000000000,
21+
18 => 1000000000000000000,
22+
19 => 10000000000000000000,
23+
20 => 100000000000000000000,
24+
21 => 1000000000000000000000,
25+
22 => 10000000000000000000000,
26+
23 => 100000000000000000000000,
27+
24 => 1000000000000000000000000,
28+
25 => 10000000000000000000000000,
29+
26 => 100000000000000000000000000,
30+
27 => 1000000000000000000000000000,
31+
28 => 10000000000000000000000000000,
32+
29 => 100000000000000000000000000000,
33+
30 => 1000000000000000000000000000000,
34+
31 => 10000000000000000000000000000000,
35+
32 => 100000000000000000000000000000000,
36+
33 => 1000000000000000000000000000000000,
37+
34 => 10000000000000000000000000000000000,
38+
35 => 100000000000000000000000000000000000,
39+
36 => 1000000000000000000000000000000000000,
40+
37 => 10000000000000000000000000000000000000,
41+
38 => 100000000000000000000000000000000000000,
42+
39 => 1000000000000000000000000000000000000000,
43+
40 => 10000000000000000000000000000000000000000,
44+
41 => 100000000000000000000000000000000000000000,
45+
42 => 1000000000000000000000000000000000000000000,
46+
43 => 10000000000000000000000000000000000000000000,
47+
44 => 100000000000000000000000000000000000000000000,
48+
45 => 1000000000000000000000000000000000000000000000,
49+
46 => 10000000000000000000000000000000000000000000000,
50+
47 => 100000000000000000000000000000000000000000000000,
51+
48 => 1000000000000000000000000000000000000000000000000,
52+
49 => 10000000000000000000000000000000000000000000000000,
53+
50 => 100000000000000000000000000000000000000000000000000,
54+
51 => 1000000000000000000000000000000000000000000000000000,
55+
52 => 10000000000000000000000000000000000000000000000000000,
56+
53 => 100000000000000000000000000000000000000000000000000000,
57+
54 => 1000000000000000000000000000000000000000000000000000000,
58+
55 => 10000000000000000000000000000000000000000000000000000000,
59+
56 => 100000000000000000000000000000000000000000000000000000000,
60+
57 => 1000000000000000000000000000000000000000000000000000000000,
61+
58 => 10000000000000000000000000000000000000000000000000000000000,
62+
59 => 100000000000000000000000000000000000000000000000000000000000,
63+
60 => 1000000000000000000000000000000000000000000000000000000000000,
64+
61 => 10000000000000000000000000000000000000000000000000000000000000,
65+
62 => 100000000000000000000000000000000000000000000000000000000000000,
66+
63 => 1000000000000000000000000000000000000000000000000000000000000000,
67+
64 => 10000000000000000000000000000000000000000000000000000000000000000,
68+
65 => 100000000000000000000000000000000000000000000000000000000000000000,
69+
66 => 1000000000000000000000000000000000000000000000000000000000000000000,
70+
67 => 10000000000000000000000000000000000000000000000000000000000000000000,
71+
68 => 100000000000000000000000000000000000000000000000000000000000000000000,
72+
69 => 1000000000000000000000000000000000000000000000000000000000000000000000,
73+
70 => 10000000000000000000000000000000000000000000000000000000000000000000000,
74+
71 => 100000000000000000000000000000000000000000000000000000000000000000000000,
75+
72 => 1000000000000000000000000000000000000000000000000000000000000000000000000,
76+
73 => 10000000000000000000000000000000000000000000000000000000000000000000000000,
77+
74 => 100000000000000000000000000000000000000000000000000000000000000000000000000,
78+
75 => 1000000000000000000000000000000000000000000000000000000000000000000000000000,
79+
76 => 10000000000000000000000000000000000000000000000000000000000000000000000000000,
80+
77 => 100000000000000000000000000000000000000000000000000000000000000000000000000000,
81+
_ => core::panic_with_felt252('exp10: arg too big'),
82+
}
83+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
use std::io::{stdin, Read};
2+
3+
use test_vaas::print_as_cli_input;
4+
5+
fn main() {
6+
let mut buf = String::new();
7+
stdin().read_to_string(&mut buf).unwrap();
8+
let binary = hex::decode(buf.trim()).unwrap();
9+
print_as_cli_input(&binary);
10+
}

0 commit comments

Comments
 (0)