Skip to content

Commit

Permalink
feat(target_chains/starknet): add reexports and utils
Browse files Browse the repository at this point in the history
  • Loading branch information
Riateche committed Jun 5, 2024
1 parent a0c5d11 commit ecc3a2f
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 0 deletions.
2 changes: 2 additions & 0 deletions target_chains/starknet/contracts/Scarb.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ starknet = ">=2.5.4"
openzeppelin = { git = "https://github.com/OpenZeppelin/cairo-contracts.git", tag = "v0.10.0" }
snforge_std = { git = "https://github.com/foundry-rs/starknet-foundry", tag = "v0.21.0" }

[lib]

[[target.starknet-contract]]
build-external-contracts = ["openzeppelin::presets::erc20::ERC20"]
9 changes: 9 additions & 0 deletions target_chains/starknet/contracts/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ pub mod reader;
pub mod hash;
pub mod util;
pub mod merkle_tree;

pub use byte_array::{ByteArray, ByteArrayTrait};
pub use pyth::{
Event, PriceFeedUpdated, WormholeAddressSet, GovernanceDataSourceSet, ContractUpgraded,
DataSourcesSet, FeeSet, GetPriceUnsafeError, GovernanceActionError, UpdatePriceFeedsError,
GetPriceNoOlderThanError, UpdatePriceFeedsIfNecessaryError, ParsePriceFeedsError, IPyth,
IPythDispatcher, IPythDispatcherTrait, DataSource, Price, PriceFeedPublishTime, PriceFeed,
};
pub use util::{exp10, UnwrapWithFelt252, ResultMapErrInto};
4 changes: 4 additions & 0 deletions target_chains/starknet/contracts/src/util.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
mod exp10_;

pub use exp10_::exp10;

use core::integer::u128_byte_reverse;

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

use test_vaas::print_as_cli_input;

fn main() {
let mut buf = String::new();
stdin().read_to_string(&mut buf).unwrap();
let binary = hex::decode(buf.trim()).unwrap();
print_as_cli_input(&binary);
}

0 comments on commit ecc3a2f

Please sign in to comment.