diff --git a/Cargo.lock b/Cargo.lock index ca5b007..71fd032 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -337,6 +337,12 @@ version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + [[package]] name = "base64ct" version = "1.6.0" @@ -349,18 +355,6 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" -[[package]] -name = "bigdecimal" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6773ddc0eafc0e509fb60e48dff7f450f8e674a0686ae8605e8d9901bd5eefa" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits 0.2.19", - "serde", -] - [[package]] name = "bip39" version = "2.0.0" @@ -504,7 +498,7 @@ dependencies = [ [[package]] name = "cairo-felt" version = "0.9.1" -source = "git+https://github.com/bidzyyys/cairo-vm?branch=feature/scale-codec#eb835a9034e208a1756226d64e004cb55e417b96" +source = "git+https://github.com/bidzyyys/cairo-vm.git?branch=feature/scale-codec#eb835a9034e208a1756226d64e004cb55e417b96" dependencies = [ "lazy_static", "num-bigint", @@ -640,7 +634,7 @@ dependencies = [ "serde_json", "sha3", "smol_str", - "starknet-crypto 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-crypto 0.6.2", "thiserror", ] @@ -2457,20 +2451,21 @@ dependencies = [ "scale-info", "serde", "serde_json", - "serde_with", + "serde_with 2.3.3", "starkgate-manager-client", "starkgate-registry-client", - "starknet-accounts", - "starknet-core", + "starknet", + "starknet-accounts 0.11.0", + "starknet-core 0.11.1", "starknet-core-contract-client", - "starknet-crypto 0.6.2 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", + "starknet-crypto 0.7.2", "starknet-erc20-client", "starknet-eth-bridge-client", - "starknet-ff 0.3.7 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", - "starknet-providers", + "starknet-providers 0.11.0", "starknet-proxy-client", - "starknet-signers", + "starknet-signers 0.9.0", "starknet-token-bridge-client", + "starknet-types-core", "starknet_api", "subxt-lightclient", "thiserror", @@ -2519,6 +2514,28 @@ dependencies = [ "regex-automata", ] +[[package]] +name = "lambdaworks-crypto" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fb5d4f22241504f7c7b8d2c3a7d7835d7c07117f10bff2a7d96a9ef6ef217c3" +dependencies = [ + "lambdaworks-math", + "serde", + "sha2 0.10.8", + "sha3", +] + +[[package]] +name = "lambdaworks-math" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "358e172628e713b80a530a59654154bfc45783a6ed70ea284839800cebdf8f97" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -2863,9 +2880,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "oorandom" -version = "11.1.3" +version = "11.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" [[package]] name = "opaque-debug" @@ -3709,9 +3726,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.19" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc6e7ed6919cb46507fb01ff1654309219f62b4d603822501b0b80d42f6f21ef" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", "indexmap 1.9.3", @@ -3722,9 +3739,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.19" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "185f2b7aa7e02d418e453790dde16890256bbd2bcd04b7dc5348811052b53f49" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" dependencies = [ "proc-macro2", "quote", @@ -3844,9 +3861,9 @@ dependencies = [ [[package]] name = "serde_derive_internals" -version = "0.29.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330f01ce65a3a5fe59a60c82f3c9a024b573b8a6e875bd233fe5f934e71d54e3" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", @@ -3908,7 +3925,25 @@ dependencies = [ "indexmap 1.9.3", "serde", "serde_json", - "serde_with_macros", + "serde_with_macros 2.3.3", + "time", +] + +[[package]] +name = "serde_with" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9720086b3357bcb44fce40117d769a4d068c70ecfa190850a980a71755f66fcc" +dependencies = [ + "base64 0.22.1", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.2.6", + "serde", + "serde_derive", + "serde_json", + "serde_with_macros 3.10.0", "time", ] @@ -3924,6 +3959,18 @@ dependencies = [ "syn 2.0.63", ] +[[package]] +name = "serde_with_macros" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f1abbfe725f27678f4663bcacb75a83e829fd464c25d78dd038a3a29e307cec" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.63", +] + [[package]] name = "sha1" version = "0.10.6" @@ -4198,34 +4245,102 @@ dependencies = [ "utils", ] +[[package]] +name = "starknet" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e633a772f59214c296d5037c95c36b72792c9360323818da2b625c7b4ec4b49" +dependencies = [ + "starknet-accounts 0.10.0", + "starknet-contract", + "starknet-core 0.11.1", + "starknet-crypto 0.7.2", + "starknet-macros", + "starknet-providers 0.11.0", + "starknet-signers 0.9.0", +] + [[package]] name = "starknet-accounts" -version = "0.9.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e#2d59636911628260fa460179010bbd00e89de06e" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eee8a6b588a22c7e79f5d8d4e33413387db63a8beb98be8610138541794cc0a5" dependencies = [ "async-trait", "auto_impl", - "starknet-core", - "starknet-providers", - "starknet-signers", + "starknet-core 0.11.1", + "starknet-crypto 0.7.2", + "starknet-providers 0.11.0", + "starknet-signers 0.9.0", "thiserror", ] [[package]] -name = "starknet-core" +name = "starknet-accounts" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ee27ded58ade61da410fccafd57ed5429b0e79a9d62a4ae8b65818cb9d6f400" +dependencies = [ + "async-trait", + "auto_impl", + "starknet-core 0.12.0", + "starknet-crypto 0.7.2", + "starknet-providers 0.12.0", + "starknet-signers 0.10.0", + "thiserror", +] + +[[package]] +name = "starknet-contract" version = "0.10.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e#2d59636911628260fa460179010bbd00e89de06e" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5f91344f1e0b81873b6dc235c50ae4d084c6ea4dd4a1e3e27ad895803adb610" +dependencies = [ + "serde", + "serde_json", + "serde_with 2.3.3", + "starknet-accounts 0.10.0", + "starknet-core 0.11.1", + "starknet-providers 0.11.0", + "thiserror", +] + +[[package]] +name = "starknet-core" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d506e02a4083290d13b427dfe437fd95aa8b56315c455bb2f9cdeca76620d457" +dependencies = [ + "base64 0.21.7", + "crypto-bigint", + "flate2", + "hex", + "serde", + "serde_json", + "serde_json_pythonic", + "serde_with 2.3.3", + "sha3", + "starknet-crypto 0.7.2", + "starknet-types-core", +] + +[[package]] +name = "starknet-core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2538240cbe6663c673fe77465f294da707080f39678dd7066761554899e46100" dependencies = [ "base64 0.21.7", + "crypto-bigint", "flate2", "hex", "serde", "serde_json", "serde_json_pythonic", - "serde_with", + "serde_with 3.10.0", "sha3", - "starknet-crypto 0.6.2 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", - "starknet-ff 0.3.7 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", + "starknet-crypto 0.7.2", + "starknet-types-core", ] [[package]] @@ -4256,9 +4371,9 @@ dependencies = [ "num-traits 0.2.19", "rfc6979", "sha2 0.10.8", - "starknet-crypto-codegen 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-crypto-codegen", "starknet-curve 0.3.0", - "starknet-ff 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-ff", "zeroize", ] @@ -4276,16 +4391,17 @@ dependencies = [ "num-traits 0.2.19", "rfc6979", "sha2 0.10.8", - "starknet-crypto-codegen 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "starknet-curve 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "starknet-ff 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-crypto-codegen", + "starknet-curve 0.4.2", + "starknet-ff", "zeroize", ] [[package]] name = "starknet-crypto" -version = "0.6.2" -source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e#2d59636911628260fa460179010bbd00e89de06e" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60a5064173a8e8d2675e67744fd07f310de44573924b6b7af225a6bdd8102913" dependencies = [ "crypto-bigint", "hex", @@ -4295,9 +4411,8 @@ dependencies = [ "num-traits 0.2.19", "rfc6979", "sha2 0.10.8", - "starknet-crypto-codegen 0.3.3 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", - "starknet-curve 0.4.2 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", - "starknet-ff 0.3.7 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", + "starknet-curve 0.5.1", + "starknet-types-core", "zeroize", ] @@ -4307,18 +4422,8 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbc159a1934c7be9761c237333a57febe060ace2bc9e3b337a59a37af206d19f" dependencies = [ - "starknet-curve 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "starknet-ff 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 2.0.63", -] - -[[package]] -name = "starknet-crypto-codegen" -version = "0.3.3" -source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e#2d59636911628260fa460179010bbd00e89de06e" -dependencies = [ - "starknet-curve 0.4.2 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", - "starknet-ff 0.3.7 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", + "starknet-curve 0.4.2", + "starknet-ff", "syn 2.0.63", ] @@ -4328,7 +4433,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "252610baff59e4c4332ce3569f7469c5d3f9b415a2240d698fb238b2b4fc0942" dependencies = [ - "starknet-ff 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-ff", ] [[package]] @@ -4337,15 +4442,16 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d1c383518bb312751e4be80f53e8644034aa99a0afb29d7ac41b89a997db875b" dependencies = [ - "starknet-ff 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "starknet-ff", ] [[package]] name = "starknet-curve" -version = "0.4.2" -source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e#2d59636911628260fa460179010bbd00e89de06e" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcde6bd74269b8161948190ace6cf069ef20ac6e79cd2ba09b320efa7500b6de" dependencies = [ - "starknet-ff 0.3.7 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", + "starknet-types-core", ] [[package]] @@ -4390,33 +4496,53 @@ dependencies = [ ] [[package]] -name = "starknet-ff" -version = "0.3.7" -source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e#2d59636911628260fa460179010bbd00e89de06e" +name = "starknet-macros" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8986a940af916fc0a034f4e42c6ba76d94f1e97216d75447693dfd7aefaf3ef2" dependencies = [ - "ark-ff", - "bigdecimal", - "crypto-bigint", + "starknet-core 0.12.0", + "syn 2.0.63", +] + +[[package]] +name = "starknet-providers" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59c85e0a0f4563ae95dfeae14ea0f0c70610efc0ec2462505c64eff5765e7b97" +dependencies = [ + "async-trait", + "auto_impl", + "ethereum-types", + "flate2", "getrandom", - "hex", + "log", + "reqwest", "serde", + "serde_json", + "serde_with 2.3.3", + "starknet-core 0.11.1", + "thiserror", + "url", ] [[package]] name = "starknet-providers" -version = "0.10.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e#2d59636911628260fa460179010bbd00e89de06e" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60e8e69ba7a36dea2d28333be82b4011f8784333d3ae5618482b6587c1ffb66c" dependencies = [ "async-trait", "auto_impl", "ethereum-types", "flate2", + "getrandom", "log", "reqwest", "serde", "serde_json", - "serde_with", - "starknet-core", + "serde_with 3.10.0", + "starknet-core 0.12.0", "thiserror", "url", ] @@ -4438,16 +4564,35 @@ dependencies = [ [[package]] name = "starknet-signers" -version = "0.8.0" -source = "git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e#2d59636911628260fa460179010bbd00e89de06e" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17da2139119dbe3aacf1d5d4338798a5c489d17f424916ceb9d2efd83554f87" dependencies = [ "async-trait", "auto_impl", "crypto-bigint", "eth-keystore", + "getrandom", "rand", - "starknet-core", - "starknet-crypto 0.6.2 (git+https://github.com/xJonathanLEI/starknet-rs.git?rev=2d59636911628260fa460179010bbd00e89de06e)", + "starknet-core 0.11.1", + "starknet-crypto 0.7.2", + "thiserror", +] + +[[package]] +name = "starknet-signers" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70b9e01b61ae51d722e2b100d6ef913c5a2e70d1ea672733d385f7296d6055ef" +dependencies = [ + "async-trait", + "auto_impl", + "crypto-bigint", + "eth-keystore", + "getrandom", + "rand", + "starknet-core 0.12.0", + "starknet-crypto 0.7.2", "thiserror", ] @@ -4465,6 +4610,20 @@ dependencies = [ "utils", ] +[[package]] +name = "starknet-types-core" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b889ee5734db8b3c8a6551135c16764bf4ce1ab4955fffbb2ac5b6706542b64" +dependencies = [ + "lambdaworks-crypto", + "lambdaworks-math", + "num-bigint", + "num-integer", + "num-traits 0.2.19", + "serde", +] + [[package]] name = "starknet_api" version = "0.8.0" @@ -5004,9 +5163,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" +checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" [[package]] name = "unicode-xid" diff --git a/Cargo.toml b/Cargo.toml index 9110913..911ac25 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,12 +27,15 @@ starknet-token-bridge-client = { git = "https://github.com/keep-starknet-strange zaun-utils = { git = "https://github.com/keep-starknet-strange/zaun", package = "utils", branch = "main" } # Starknet Deps -starknet-accounts = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "2d59636911628260fa460179010bbd00e89de06e" } -starknet-core = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "2d59636911628260fa460179010bbd00e89de06e" } -starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "2d59636911628260fa460179010bbd00e89de06e" } -starknet-ff = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "2d59636911628260fa460179010bbd00e89de06e" } -starknet-providers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "2d59636911628260fa460179010bbd00e89de06e" } -starknet-signers = { git = "https://github.com/xJonathanLEI/starknet-rs.git", rev = "2d59636911628260fa460179010bbd00e89de06e" } +starknet = "0.11.0" +starknet-accounts = "0.11.0" +starknet-core = "0.11" +starknet-crypto = "0.7" +starknet-providers = "0.11" +starknet-signers = "0.9" +starknet-types-core = { version = "0.1.5", default-features = false, features = [ + "hash", +] } starknet_api = { git = "https://github.com/bidzyyys/starknet-api.git", branch = "feature/scale-codec" } # Third Party diff --git a/bin/madara b/bin/madara deleted file mode 100755 index 5a052ad..0000000 Binary files a/bin/madara and /dev/null differ diff --git a/src/contract_clients/config.rs b/src/contract_clients/config.rs index 2685404..c6b91fa 100644 --- a/src/contract_clients/config.rs +++ b/src/contract_clients/config.rs @@ -1,7 +1,6 @@ use ethereum_instance::EthereumClient; -use starknet_providers::jsonrpc::HttpTransport; -use starknet_providers::JsonRpcClient; -use url::Url; +use starknet::providers::jsonrpc::{HttpTransport, JsonRpcClient}; +use starknet::providers::Url; use crate::CliArgs; diff --git a/src/contract_clients/core_contract.rs b/src/contract_clients/core_contract.rs index 8468a36..c9a0ac9 100644 --- a/src/contract_clients/core_contract.rs +++ b/src/contract_clients/core_contract.rs @@ -5,8 +5,7 @@ use async_trait::async_trait; use ethers::abi::AbiEncode; use ethers::addressbook::Address; use ethers::prelude::{Bytes, I256, U256}; -use starknet_api::hash::{StarkFelt, StarkHash}; -use starknet_ff::FieldElement; +use starknet::core::types::Felt; use starknet_proxy_client::interfaces::proxy::{CoreContractInitData, CoreContractState}; use zaun_utils::LocalWalletSignerMiddleware; @@ -26,10 +25,10 @@ pub trait CoreContract { #[allow(clippy::too_many_arguments)] async fn add_implementation_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, implementation_address: Address, verifier_address: Address, finalized: bool, @@ -38,10 +37,10 @@ pub trait CoreContract { #[allow(clippy::too_many_arguments)] async fn upgrade_to_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, implementation_address: Address, verifier_address: Address, finalized: bool, @@ -53,14 +52,14 @@ pub trait CoreContract { async fn nominate_governor_core_contract_proxy(&self, l1_governor_address: Address); - async fn initialize(&self, program_hash: StarkFelt, config_hash: StarkFelt); + async fn initialize(&self, program_hash: Felt, config_hash: Felt); async fn initialize_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, verifer_address: Address, ); } @@ -70,10 +69,10 @@ pub trait CoreContractDeploy { } pub fn get_init_data_core_contract( - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: StarkFelt, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, verifier_address: Address, ) -> CoreContractInitData { CoreContractInitData { diff --git a/src/contract_clients/eth_bridge.rs b/src/contract_clients/eth_bridge.rs index f6df7ba..a8bf092 100644 --- a/src/contract_clients/eth_bridge.rs +++ b/src/contract_clients/eth_bridge.rs @@ -4,13 +4,13 @@ use async_trait::async_trait; use ethers::addressbook::Address; use ethers::providers::Middleware; use ethers::types::{Bytes, U256}; -use starknet_accounts::{Account, ConnectedAccount}; +use starknet::accounts::{Account, ConnectedAccount}; +use starknet::core::types::Felt; use starknet_eth_bridge_client::clients::eth_bridge::StarknetEthBridgeContractClient; use starknet_eth_bridge_client::interfaces::eth_bridge::StarknetEthBridgeTrait; use starknet_eth_bridge_client::{ deploy_starknet_eth_bridge_behind_safe_proxy, deploy_starknet_eth_bridge_behind_unsafe_proxy, }; -use starknet_ff::FieldElement; use starknet_providers::jsonrpc::HttpTransport; use starknet_providers::JsonRpcClient; use starknet_proxy_client::interfaces::proxy::ProxySupport3_0_2Trait; @@ -60,15 +60,15 @@ impl StarknetLegacyEthBridge { pub async fn deploy_l2_contracts( rpc_provider_l2: &JsonRpcClient, - legacy_eth_bridge_class_hash: FieldElement, - legacy_eth_bridge_proxy_address: FieldElement, + legacy_eth_bridge_class_hash: Felt, + legacy_eth_bridge_proxy_address: Felt, account: &RpcAccount<'_>, - ) -> FieldElement { + ) -> Felt { let deploy_tx = account .invoke_contract( account.address(), "deploy_contract", - vec![legacy_eth_bridge_class_hash, FieldElement::ZERO, FieldElement::ZERO, FieldElement::ZERO], + vec![legacy_eth_bridge_class_hash, Felt::ZERO, Felt::ZERO, Felt::ZERO], None, ) .send() @@ -88,7 +88,7 @@ impl StarknetLegacyEthBridge { let add_implementation_txn = invoke_contract( legacy_eth_bridge_proxy_address, "add_implementation", - vec![contract_address, FieldElement::ZERO, FieldElement::ONE, account.address(), FieldElement::ZERO], + vec![contract_address, Felt::ZERO, Felt::ONE, account.address(), Felt::ZERO], account, ) .await; @@ -104,7 +104,7 @@ impl StarknetLegacyEthBridge { let upgrade_to_txn = invoke_contract( legacy_eth_bridge_proxy_address, "upgrade_to", - vec![contract_address, FieldElement::ZERO, FieldElement::ONE, account.address(), FieldElement::ZERO], + vec![contract_address, Felt::ZERO, Felt::ONE, account.address(), Felt::ZERO], account, ) .await; @@ -198,7 +198,7 @@ impl StarknetLegacyEthBridge { &self, max_total_balance: &str, max_deposit: &str, - l2_bridge: FieldElement, + l2_bridge: Felt, l1_multisig_address: Address, is_dev: bool, ) { @@ -215,15 +215,15 @@ impl StarknetLegacyEthBridge { pub async fn setup_l2_bridge( &self, rpc_provider: &JsonRpcClient, - l2_bridge_address: FieldElement, - erc20_address: FieldElement, + l2_bridge_address: Felt, + erc20_address: Felt, l2_deployer_address: &str, account: &RpcAccount<'_>, ) { let tx = invoke_contract( l2_bridge_address, "initialize", - vec![FieldElement::from_dec_str("1").unwrap(), FieldElement::from_hex_be(l2_deployer_address).unwrap()], + vec![Felt::from_dec_str("1").unwrap(), Felt::from_hex(l2_deployer_address).unwrap()], account, ) .await; @@ -239,7 +239,7 @@ impl StarknetLegacyEthBridge { let tx = invoke_contract( l2_bridge_address, "set_l1_bridge", - vec![FieldElement::from_byte_slice_be(self.eth_bridge.address().as_bytes()).unwrap()], + vec![Felt::from_bytes_be_slice(self.eth_bridge.address().as_bytes())], account, ) .await; diff --git a/src/contract_clients/legacy_class.rs b/src/contract_clients/legacy_class.rs new file mode 100644 index 0000000..0cad6d9 --- /dev/null +++ b/src/contract_clients/legacy_class.rs @@ -0,0 +1,463 @@ +use starknet_types_core::felt::Felt; + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct EntryPointsByType { + pub constructor: Vec, + pub external: Vec, + pub l1_handler: Vec, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct SierraEntryPoint { + pub selector: Felt, + pub function_idx: u64, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct CompressedLegacyContractClass { + pub program: Vec, + pub entry_points_by_type: LegacyEntryPointsByType, + pub abi: Option>, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct LegacyEntryPointsByType { + #[serde(rename = "CONSTRUCTOR")] + pub constructor: Vec, + #[serde(rename = "EXTERNAL")] + pub external: Vec, + #[serde(rename = "L1_HANDLER")] + pub l1_handler: Vec, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct LegacyContractEntryPoint { + pub offset: u64, + pub selector: Felt, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub enum LegacyContractAbiEntry { + Function(LegacyFunctionAbiEntry), + Event(LegacyEventAbiEntry), + Struct(LegacyStructAbiEntry), +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct LegacyFunctionAbiEntry { + pub r#type: LegacyFunctionAbiType, + pub name: String, + pub inputs: Vec, + pub outputs: Vec, + #[serde(rename = "stateMutability")] + pub state_mutability: Option, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct LegacyEventAbiEntry { + pub r#type: LegacyEventAbiType, + pub name: String, + pub keys: Vec, + pub data: Vec, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct LegacyStructAbiEntry { + pub r#type: LegacyStructAbiType, + pub name: String, + pub size: u64, + pub members: Vec, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct LegacyStructMember { + pub name: String, + pub r#type: String, + pub offset: u64, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct LegacyTypedParameter { + pub name: String, + pub r#type: String, +} + +#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub enum LegacyFunctionAbiType { + #[serde(rename = "function")] + Function, + #[serde(rename = "l1_handler")] + L1Handler, + #[serde(rename = "constructor")] + Constructor, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub enum LegacyEventAbiType { + #[serde(rename = "event")] + Event, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub enum LegacyStructAbiType { + #[serde(rename = "struct")] + Struct, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub enum FunctionStateMutability { + #[serde(rename = "view")] + View, +} + +impl From for EntryPointsByType { + fn from(entry_points_by_type: starknet_core::types::EntryPointsByType) -> Self { + EntryPointsByType { + constructor: entry_points_by_type + .constructor + .into_iter() + .map(|sierra_entry_point| sierra_entry_point.into()) + .collect(), + external: entry_points_by_type + .external + .into_iter() + .map(|sierra_entry_point| sierra_entry_point.into()) + .collect(), + l1_handler: entry_points_by_type + .l1_handler + .into_iter() + .map(|sierra_entry_point| sierra_entry_point.into()) + .collect(), + } + } +} + +impl From for starknet_core::types::EntryPointsByType { + fn from(entry_points_by_type: EntryPointsByType) -> Self { + starknet_core::types::EntryPointsByType { + constructor: entry_points_by_type + .constructor + .into_iter() + .map(|sierra_entry_point| sierra_entry_point.into()) + .collect(), + external: entry_points_by_type + .external + .into_iter() + .map(|sierra_entry_point| sierra_entry_point.into()) + .collect(), + l1_handler: entry_points_by_type + .l1_handler + .into_iter() + .map(|sierra_entry_point| sierra_entry_point.into()) + .collect(), + } + } +} + +impl From for SierraEntryPoint { + fn from(sierra_entry_point: starknet_core::types::SierraEntryPoint) -> Self { + SierraEntryPoint { selector: sierra_entry_point.selector, function_idx: sierra_entry_point.function_idx } + } +} + +impl From for starknet_core::types::SierraEntryPoint { + fn from(sierra_entry_point: SierraEntryPoint) -> Self { + starknet_core::types::SierraEntryPoint { + selector: sierra_entry_point.selector, + function_idx: sierra_entry_point.function_idx, + } + } +} + +impl From for CompressedLegacyContractClass { + fn from(compressed_legacy_contract_class: starknet_core::types::CompressedLegacyContractClass) -> Self { + CompressedLegacyContractClass { + program: compressed_legacy_contract_class.program, + entry_points_by_type: compressed_legacy_contract_class.entry_points_by_type.into(), + abi: compressed_legacy_contract_class + .abi + .map(|abi| abi.into_iter().map(|legacy_contract_abi_entry| legacy_contract_abi_entry.into()).collect()), + } + } +} + +impl From for starknet_core::types::CompressedLegacyContractClass { + fn from(compressed_legacy_contract_class: CompressedLegacyContractClass) -> Self { + starknet_core::types::CompressedLegacyContractClass { + program: compressed_legacy_contract_class.program, + entry_points_by_type: compressed_legacy_contract_class.entry_points_by_type.into(), + abi: compressed_legacy_contract_class + .abi + .map(|abi| abi.into_iter().map(|legacy_contract_abi_entry| legacy_contract_abi_entry.into()).collect()), + } + } +} + +impl From for LegacyEntryPointsByType { + fn from(legacy_entry_points_by_type: starknet_core::types::LegacyEntryPointsByType) -> Self { + LegacyEntryPointsByType { + constructor: legacy_entry_points_by_type + .constructor + .into_iter() + .map(|legacy_contract_entry_point| legacy_contract_entry_point.into()) + .collect(), + external: legacy_entry_points_by_type + .external + .into_iter() + .map(|legacy_contract_entry_point| legacy_contract_entry_point.into()) + .collect(), + l1_handler: legacy_entry_points_by_type + .l1_handler + .into_iter() + .map(|legacy_contract_entry_point| legacy_contract_entry_point.into()) + .collect(), + } + } +} + +impl From for starknet_core::types::LegacyEntryPointsByType { + fn from(legacy_entry_points_by_type: LegacyEntryPointsByType) -> Self { + starknet_core::types::LegacyEntryPointsByType { + constructor: legacy_entry_points_by_type + .constructor + .into_iter() + .map(|legacy_contract_entry_point| legacy_contract_entry_point.into()) + .collect(), + external: legacy_entry_points_by_type + .external + .into_iter() + .map(|legacy_contract_entry_point| legacy_contract_entry_point.into()) + .collect(), + l1_handler: legacy_entry_points_by_type + .l1_handler + .into_iter() + .map(|legacy_contract_entry_point| legacy_contract_entry_point.into()) + .collect(), + } + } +} + +impl From for LegacyContractEntryPoint { + fn from(legacy_contract_entry_point: starknet_core::types::LegacyContractEntryPoint) -> Self { + LegacyContractEntryPoint { + offset: legacy_contract_entry_point.offset, + selector: legacy_contract_entry_point.selector, + } + } +} + +impl From for starknet_core::types::LegacyContractEntryPoint { + fn from(legacy_contract_entry_point: LegacyContractEntryPoint) -> Self { + starknet_core::types::LegacyContractEntryPoint { + offset: legacy_contract_entry_point.offset, + selector: legacy_contract_entry_point.selector, + } + } +} + +impl From for LegacyContractAbiEntry { + fn from(legacy_contract_abi_entry: starknet_core::types::LegacyContractAbiEntry) -> Self { + match legacy_contract_abi_entry { + starknet_core::types::LegacyContractAbiEntry::Function(legacy_function_abi_entry) => { + LegacyContractAbiEntry::Function(legacy_function_abi_entry.into()) + } + starknet_core::types::LegacyContractAbiEntry::Event(legacy_event_abi_entry) => { + LegacyContractAbiEntry::Event(legacy_event_abi_entry.into()) + } + starknet_core::types::LegacyContractAbiEntry::Struct(legacy_struct_abi_entry) => { + LegacyContractAbiEntry::Struct(legacy_struct_abi_entry.into()) + } + } + } +} + +impl From for starknet_core::types::LegacyContractAbiEntry { + fn from(legacy_contract_abi_entry: LegacyContractAbiEntry) -> Self { + match legacy_contract_abi_entry { + LegacyContractAbiEntry::Function(legacy_function_abi_entry) => { + starknet_core::types::LegacyContractAbiEntry::Function(legacy_function_abi_entry.into()) + } + LegacyContractAbiEntry::Event(legacy_event_abi_entry) => { + starknet_core::types::LegacyContractAbiEntry::Event(legacy_event_abi_entry.into()) + } + LegacyContractAbiEntry::Struct(legacy_struct_abi_entry) => { + starknet_core::types::LegacyContractAbiEntry::Struct(legacy_struct_abi_entry.into()) + } + } + } +} + +impl From for LegacyFunctionAbiEntry { + fn from(legacy_function_abi_entry: starknet_core::types::LegacyFunctionAbiEntry) -> Self { + LegacyFunctionAbiEntry { + r#type: legacy_function_abi_entry.r#type.into(), + name: legacy_function_abi_entry.name, + inputs: legacy_function_abi_entry.inputs.into_iter().map(|abi_entry| abi_entry.into()).collect(), + outputs: legacy_function_abi_entry.outputs.into_iter().map(|abi_entry| abi_entry.into()).collect(), + state_mutability: legacy_function_abi_entry + .state_mutability + .map(|state_mutability| state_mutability.into()), + } + } +} + +impl From for starknet_core::types::LegacyFunctionAbiEntry { + fn from(legacy_function_abi_entry: LegacyFunctionAbiEntry) -> Self { + starknet_core::types::LegacyFunctionAbiEntry { + r#type: legacy_function_abi_entry.r#type.into(), + name: legacy_function_abi_entry.name, + inputs: legacy_function_abi_entry.inputs.into_iter().map(|abi_entry| abi_entry.into()).collect(), + outputs: legacy_function_abi_entry.outputs.into_iter().map(|abi_entry| abi_entry.into()).collect(), + state_mutability: legacy_function_abi_entry + .state_mutability + .map(|state_mutability| state_mutability.into()), + } + } +} + +impl From for LegacyEventAbiEntry { + fn from(legacy_event_abi_entry: starknet_core::types::LegacyEventAbiEntry) -> Self { + LegacyEventAbiEntry { + r#type: legacy_event_abi_entry.r#type.into(), + name: legacy_event_abi_entry.name, + keys: legacy_event_abi_entry.keys.into_iter().map(|abi_entry| abi_entry.into()).collect(), + data: legacy_event_abi_entry.data.into_iter().map(|abi_entry| abi_entry.into()).collect(), + } + } +} + +impl From for starknet_core::types::LegacyEventAbiEntry { + fn from(legacy_event_abi_entry: LegacyEventAbiEntry) -> Self { + starknet_core::types::LegacyEventAbiEntry { + r#type: legacy_event_abi_entry.r#type.into(), + name: legacy_event_abi_entry.name, + keys: legacy_event_abi_entry.keys.into_iter().map(|abi_entry| abi_entry.into()).collect(), + data: legacy_event_abi_entry.data.into_iter().map(|abi_entry| abi_entry.into()).collect(), + } + } +} + +impl From for LegacyStructAbiEntry { + fn from(legacy_struct_abi_entry: starknet_core::types::LegacyStructAbiEntry) -> Self { + LegacyStructAbiEntry { + r#type: legacy_struct_abi_entry.r#type.into(), + name: legacy_struct_abi_entry.name, + size: legacy_struct_abi_entry.size, + members: legacy_struct_abi_entry.members.into_iter().map(|member| member.into()).collect(), + } + } +} + +impl From for starknet_core::types::LegacyStructAbiEntry { + fn from(legacy_struct_abi_entry: LegacyStructAbiEntry) -> Self { + starknet_core::types::LegacyStructAbiEntry { + r#type: legacy_struct_abi_entry.r#type.into(), + name: legacy_struct_abi_entry.name, + size: legacy_struct_abi_entry.size, + members: legacy_struct_abi_entry.members.into_iter().map(|member| member.into()).collect(), + } + } +} + +impl From for LegacyStructMember { + fn from(legacy_struct_member: starknet_core::types::LegacyStructMember) -> Self { + LegacyStructMember { + name: legacy_struct_member.name, + r#type: legacy_struct_member.r#type, + offset: legacy_struct_member.offset, + } + } +} + +impl From for starknet_core::types::LegacyStructMember { + fn from(legacy_struct_member: LegacyStructMember) -> Self { + starknet_core::types::LegacyStructMember { + name: legacy_struct_member.name, + r#type: legacy_struct_member.r#type, + offset: legacy_struct_member.offset, + } + } +} + +impl From for LegacyTypedParameter { + fn from(legacy_typed_parameter: starknet_core::types::LegacyTypedParameter) -> Self { + LegacyTypedParameter { r#type: legacy_typed_parameter.r#type, name: legacy_typed_parameter.name } + } +} + +impl From for starknet_core::types::LegacyTypedParameter { + fn from(legacy_typed_parameter: LegacyTypedParameter) -> Self { + starknet_core::types::LegacyTypedParameter { + r#type: legacy_typed_parameter.r#type, + name: legacy_typed_parameter.name, + } + } +} + +impl From for LegacyFunctionAbiType { + fn from(legacy_function_abi_type: starknet_core::types::LegacyFunctionAbiType) -> Self { + match legacy_function_abi_type { + starknet_core::types::LegacyFunctionAbiType::Function => LegacyFunctionAbiType::Function, + starknet_core::types::LegacyFunctionAbiType::L1Handler => LegacyFunctionAbiType::L1Handler, + starknet_core::types::LegacyFunctionAbiType::Constructor => LegacyFunctionAbiType::Constructor, + } + } +} + +impl From for starknet_core::types::LegacyFunctionAbiType { + fn from(legacy_function_abi_type: LegacyFunctionAbiType) -> Self { + match legacy_function_abi_type { + LegacyFunctionAbiType::Function => starknet_core::types::LegacyFunctionAbiType::Function, + LegacyFunctionAbiType::L1Handler => starknet_core::types::LegacyFunctionAbiType::L1Handler, + LegacyFunctionAbiType::Constructor => starknet_core::types::LegacyFunctionAbiType::Constructor, + } + } +} + +impl From for LegacyEventAbiType { + fn from(legacy_event_abi_type: starknet_core::types::LegacyEventAbiType) -> Self { + match legacy_event_abi_type { + starknet_core::types::LegacyEventAbiType::Event => LegacyEventAbiType::Event, + } + } +} + +impl From for starknet_core::types::LegacyEventAbiType { + fn from(legacy_event_abi_type: LegacyEventAbiType) -> Self { + match legacy_event_abi_type { + LegacyEventAbiType::Event => starknet_core::types::LegacyEventAbiType::Event, + } + } +} + +impl From for LegacyStructAbiType { + fn from(legacy_struct_abi_type: starknet_core::types::LegacyStructAbiType) -> Self { + match legacy_struct_abi_type { + starknet_core::types::LegacyStructAbiType::Struct => LegacyStructAbiType::Struct, + } + } +} + +impl From for starknet_core::types::LegacyStructAbiType { + fn from(legacy_struct_abi_type: LegacyStructAbiType) -> Self { + match legacy_struct_abi_type { + LegacyStructAbiType::Struct => starknet_core::types::LegacyStructAbiType::Struct, + } + } +} + +impl From for FunctionStateMutability { + fn from(function_state_mutability: starknet_core::types::FunctionStateMutability) -> Self { + match function_state_mutability { + starknet_core::types::FunctionStateMutability::View => FunctionStateMutability::View, + } + } +} + +impl From for starknet_core::types::FunctionStateMutability { + fn from(function_state_mutability: FunctionStateMutability) -> Self { + match function_state_mutability { + FunctionStateMutability::View => starknet_core::types::FunctionStateMutability::View, + } + } +} diff --git a/src/contract_clients/mod.rs b/src/contract_clients/mod.rs index 3eea932..5366904 100644 --- a/src/contract_clients/mod.rs +++ b/src/contract_clients/mod.rs @@ -1,6 +1,7 @@ pub mod config; pub mod core_contract; pub mod eth_bridge; +pub mod legacy_class; pub mod starknet_sovereign; pub mod starknet_validity; pub mod token_bridge; diff --git a/src/contract_clients/starknet_sovereign.rs b/src/contract_clients/starknet_sovereign.rs index 247f567..00e7363 100644 --- a/src/contract_clients/starknet_sovereign.rs +++ b/src/contract_clients/starknet_sovereign.rs @@ -2,11 +2,10 @@ use std::sync::Arc; use async_trait::async_trait; use ethers::types::Address; -use starknet_api::hash::{StarkFelt, StarkHash}; +use starknet::core::types::Felt; use starknet_core_contract_client::clients::StarknetSovereignContractClient; use starknet_core_contract_client::deploy_starknet_sovereign_behind_unsafe_proxy; use starknet_core_contract_client::interfaces::{OperatorTrait, StarknetGovernanceTrait}; -use starknet_ff::FieldElement; use starknet_proxy_client::interfaces::proxy::{CoreContractInitData, ProxyInitializeData, ProxySupport3_0_2Trait}; use zaun_utils::{LocalWalletSignerMiddleware, StarknetContractClient}; @@ -67,16 +66,14 @@ impl CoreContract for StarknetSovereignContract { #[allow(clippy::too_many_arguments)] async fn add_implementation_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, implementation_address: Address, verifier_address: Address, finalized: bool, ) { - let program_hash = StarkFelt(program_hash.to_bytes_be()); - let init_data = get_init_data_core_contract(block_number, state_root, program_hash, config_hash, verifier_address); let final_bytes = get_calldata_bytes(init_data.clone()); @@ -101,16 +98,14 @@ impl CoreContract for StarknetSovereignContract { #[allow(clippy::too_many_arguments)] async fn upgrade_to_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, implementation_address: Address, verifier_address: Address, finalized: bool, ) { - let program_hash = StarkFelt(program_hash.to_bytes_be()); - let init_data = get_init_data_core_contract(block_number, state_root, program_hash, config_hash, verifier_address); let final_bytes = get_calldata_bytes(init_data.clone()); @@ -158,7 +153,7 @@ impl CoreContract for StarknetSovereignContract { /// Initialize Starknet core contract with the specified program and config hashes. The rest of /// parameters will be left default. /// IMP : only need to be called when using unsafe proxy - async fn initialize(&self, program_hash: StarkFelt, config_hash: StarkFelt) { + async fn initialize(&self, program_hash: Felt, config_hash: Felt) { self.initialize_with(CoreContractInitData { program_hash: convert_felt_to_u256(program_hash), config_hash: convert_felt_to_u256(config_hash), @@ -171,14 +166,12 @@ impl CoreContract for StarknetSovereignContract { /// IMP : only need to be called when using unsafe proxy async fn initialize_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, verifer_address: Address, ) { - let program_hash = StarkFelt(program_hash.to_bytes_be()); - let init_data = get_init_data_core_contract(block_number, state_root, program_hash, config_hash, verifer_address); diff --git a/src/contract_clients/starknet_validity.rs b/src/contract_clients/starknet_validity.rs index 270baa1..ddf7f0b 100644 --- a/src/contract_clients/starknet_validity.rs +++ b/src/contract_clients/starknet_validity.rs @@ -2,11 +2,10 @@ use std::sync::Arc; use async_trait::async_trait; use ethers::types::Address; -use starknet_api::hash::{StarkFelt, StarkHash}; +use starknet::core::types::Felt; use starknet_core_contract_client::clients::StarknetValidityContractClient; use starknet_core_contract_client::deploy_starknet_validity_behind_safe_proxy; use starknet_core_contract_client::interfaces::{OperatorTrait, StarknetGovernanceTrait}; -use starknet_ff::FieldElement; use starknet_proxy_client::interfaces::proxy::{CoreContractInitData, ProxyInitializeData, ProxySupport3_0_2Trait}; use zaun_utils::{LocalWalletSignerMiddleware, StarknetContractClient}; @@ -67,16 +66,14 @@ impl CoreContract for StarknetValidityContract { #[allow(clippy::too_many_arguments)] async fn add_implementation_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, implementation_address: Address, verifier_address: Address, finalized: bool, ) { - let program_hash = StarkFelt(program_hash.to_bytes_be()); - let init_data = get_init_data_core_contract(block_number, state_root, program_hash, config_hash, verifier_address); let final_bytes = get_calldata_bytes(init_data.clone()); @@ -101,16 +98,14 @@ impl CoreContract for StarknetValidityContract { #[allow(clippy::too_many_arguments)] async fn upgrade_to_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, implementation_address: Address, verifier_address: Address, finalized: bool, ) { - let program_hash = StarkFelt(program_hash.to_bytes_be()); - let init_data = get_init_data_core_contract(block_number, state_root, program_hash, config_hash, verifier_address); let final_bytes = get_calldata_bytes(init_data.clone()); @@ -158,7 +153,7 @@ impl CoreContract for StarknetValidityContract { /// Initialize Starknet core contract with the specified program and config hashes. The rest of /// parameters will be left default. /// IMP : only need to be called when using unsafe proxy - async fn initialize(&self, program_hash: StarkFelt, config_hash: StarkFelt) { + async fn initialize(&self, program_hash: Felt, config_hash: Felt) { self.initialize_with(CoreContractInitData { program_hash: convert_felt_to_u256(program_hash), config_hash: convert_felt_to_u256(config_hash), @@ -171,14 +166,12 @@ impl CoreContract for StarknetValidityContract { /// IMP : only need to be called when using unsafe proxy async fn initialize_core_contract( &self, - block_number: StarkFelt, - state_root: StarkFelt, - program_hash: FieldElement, - config_hash: StarkHash, + block_number: Felt, + state_root: Felt, + program_hash: Felt, + config_hash: Felt, verifer_address: Address, ) { - let program_hash = StarkFelt(program_hash.to_bytes_be()); - let init_data = get_init_data_core_contract(block_number, state_root, program_hash, config_hash, verifer_address); diff --git a/src/contract_clients/token_bridge.rs b/src/contract_clients/token_bridge.rs index a2577fd..0a6f061 100644 --- a/src/contract_clients/token_bridge.rs +++ b/src/contract_clients/token_bridge.rs @@ -14,11 +14,11 @@ use starkgate_registry_client::clients::starkgate_registry::StarkgateRegistryCon use starkgate_registry_client::{ deploy_starkgate_registry_behind_safe_proxy, deploy_starkgate_registry_behind_unsafe_proxy, }; -use starknet_accounts::{Account, ConnectedAccount}; +use starknet::accounts::{Account, ConnectedAccount}; +use starknet_core::types::Felt; use starknet_erc20_client::clients::erc20::ERC20ContractClient; use starknet_erc20_client::deploy_dai_erc20_behind_unsafe_proxy; use starknet_erc20_client::interfaces::erc20::ERC20TokenTrait; -use starknet_ff::FieldElement; use starknet_providers::jsonrpc::HttpTransport; use starknet_providers::JsonRpcClient; use starknet_proxy_client::interfaces::proxy::ProxySupport5_0_0Trait; @@ -111,7 +111,7 @@ impl StarknetTokenBridge { rpc_provider_l2: &JsonRpcClient, priv_key: &str, l2_deployer_address: &str, - ) -> FieldElement { + ) -> Felt { let account = build_single_owner_account(rpc_provider_l2, priv_key, l2_deployer_address, false).await; let token_bridge_class_hash = declare_contract(DeclarationInput::DeclarationInputs( @@ -130,13 +130,7 @@ impl StarknetTokenBridge { .invoke_contract( account.address(), "deploy_contract", - vec![ - token_bridge_class_hash, - FieldElement::ZERO, - FieldElement::ZERO, - FieldElement::ONE, - FieldElement::ZERO, - ], + vec![token_bridge_class_hash, Felt::ZERO, Felt::ZERO, Felt::ONE, Felt::ZERO], None, ) .send() @@ -281,7 +275,7 @@ impl StarknetTokenBridge { } /// Deploys a test ERC20 token from L1 to L2 - pub async fn setup_l1_bridge(&self, fee: U256, l2_bridge: FieldElement) { + pub async fn setup_l1_bridge(&self, fee: U256, l2_bridge: Felt) { self.token_bridge.set_l2_token_bridge(field_element_to_u256(l2_bridge)).await.unwrap(); self.manager.enroll_token_bridge(self.address(), fee).await.unwrap(); } @@ -289,18 +283,14 @@ impl StarknetTokenBridge { pub async fn setup_l2_bridge( &self, rpc_provider_l2: &JsonRpcClient, - l2_bridge: FieldElement, + l2_bridge: Felt, l2_address: &str, account: &RpcAccount<'_>, - erc20_class_hash: FieldElement, + erc20_class_hash: Felt, ) { - let tx = invoke_contract( - l2_bridge, - "register_app_role_admin", - vec![FieldElement::from_hex_be(l2_address).unwrap()], - account, - ) - .await; + let tx = + invoke_contract(l2_bridge, "register_app_role_admin", vec![Felt::from_hex(l2_address).unwrap()], account) + .await; wait_for_transaction( rpc_provider_l2, @@ -311,13 +301,9 @@ impl StarknetTokenBridge { .unwrap(); log::debug!("🌗 setup_l2_bridge : register_app_role_admin //"); - let tx = invoke_contract( - l2_bridge, - "register_app_governor", - vec![FieldElement::from_hex_be(l2_address).unwrap()], - account, - ) - .await; + let tx = + invoke_contract(l2_bridge, "register_app_governor", vec![Felt::from_hex(l2_address).unwrap()], account) + .await; wait_for_transaction( rpc_provider_l2, @@ -328,13 +314,9 @@ impl StarknetTokenBridge { .unwrap(); log::debug!("🌗 setup_l2_bridge : register_app_governor //"); - let tx = invoke_contract( - l2_bridge, - "set_l2_token_governance", - vec![FieldElement::from_hex_be(l2_address).unwrap()], - account, - ) - .await; + let tx = + invoke_contract(l2_bridge, "set_l2_token_governance", vec![Felt::from_hex(l2_address).unwrap()], account) + .await; wait_for_transaction( rpc_provider_l2, @@ -367,7 +349,7 @@ impl StarknetTokenBridge { let tx = invoke_contract( l2_bridge, "set_l1_bridge", - vec![FieldElement::from_byte_slice_be(self.token_bridge.address().as_bytes()).unwrap()], + vec![Felt::from_bytes_be_slice(self.token_bridge.address().as_bytes())], account, ) .await; diff --git a/src/contract_clients/utils.rs b/src/contract_clients/utils.rs index 187959b..4311083 100644 --- a/src/contract_clients/utils.rs +++ b/src/contract_clients/utils.rs @@ -4,16 +4,20 @@ use ethers::types::U256; use hex::encode; use serde::{Deserialize, Serialize}; use serde_json::json; -use starknet_accounts::{Account, AccountFactory, ConnectedAccount, OpenZeppelinAccountFactory, SingleOwnerAccount}; -use starknet_api::hash::{pedersen_hash_array, StarkFelt, StarkHash}; -use starknet_core::types::contract::legacy::LegacyContractClass; -use starknet_core::types::{BlockId, BlockTag, CompressedLegacyContractClass, DeclareTransactionResult, FunctionCall}; -use starknet_core::utils::get_selector_from_name; -use starknet_ff::FieldElement; -use starknet_providers::jsonrpc::HttpTransport; -use starknet_providers::{JsonRpcClient, Provider}; -use starknet_signers::{LocalWallet, SigningKey}; - +use starknet::accounts::{ + Account, AccountFactory, ConnectedAccount, ExecutionEncoding, OpenZeppelinAccountFactory, SingleOwnerAccount, +}; +use starknet::core::types::contract::legacy::LegacyContractClass; +use starknet::core::types::{BlockId, BlockTag, DeclareTransactionResult, Felt, FunctionCall}; +use starknet::core::utils::get_selector_from_name; +use starknet::providers::jsonrpc::{HttpTransport, JsonRpcClient}; +use starknet::providers::Provider; +use starknet::signers::{LocalWallet, SigningKey}; +use starknet_core::types::contract::{CompiledClass, SierraClass}; +use starknet_core::types::BlockTag::Pending; +use starknet_types_core::hash::{Pedersen, StarkHash}; + +use crate::contract_clients::legacy_class::CompressedLegacyContractClass; use crate::contract_clients::utils::DeclarationInput::{DeclarationInputs, LegacyDeclarationInputs}; use crate::helpers::account_actions::{get_contract_address_from_deploy_tx, AccountActions}; use crate::utils::{invoke_contract, save_to_json, wait_for_transaction, JsonValueType}; @@ -26,23 +30,26 @@ pub async fn build_single_owner_account<'a>( account_address: &str, is_legacy: bool, ) -> RpcAccount<'a> { - let signer = LocalWallet::from(SigningKey::from_secret_scalar(FieldElement::from_hex_be(private_key).unwrap())); - let account_address = FieldElement::from_hex_be(account_address).expect("Invalid Contract Address"); - let execution_encoding = if is_legacy { - starknet_accounts::ExecutionEncoding::Legacy - } else { - starknet_accounts::ExecutionEncoding::New - }; + let signer = LocalWallet::from(SigningKey::from_secret_scalar(Felt::from_hex(private_key).unwrap())); + let account_address = Felt::from_hex(account_address).expect("Invalid Contract Address"); + let execution_encoding = if is_legacy { ExecutionEncoding::Legacy } else { ExecutionEncoding::New }; let chain_id = rpc.chain_id().await.unwrap(); - SingleOwnerAccount::new(rpc, signer, account_address, chain_id, execution_encoding) + + // Note: it's a fix for the starknet rs issue, by default, starknet.rs asks for nonce at the latest + // block which causes the issues hence setting the block id to pending so that we get nonce in + // right order + let mut singer_with_pending_id = + SingleOwnerAccount::new(rpc, signer, account_address, chain_id, execution_encoding); + singer_with_pending_id.set_block_id(BlockId::Tag(Pending)); + singer_with_pending_id } pub async fn read_erc20_balance( rpc: &JsonRpcClient, - contract_address: FieldElement, - account_address: FieldElement, -) -> Vec { + contract_address: Felt, + account_address: Felt, +) -> Vec { rpc.call( FunctionCall { contract_address, @@ -55,42 +62,40 @@ pub async fn read_erc20_balance( .unwrap() } -pub fn field_element_to_u256(input: FieldElement) -> U256 { +pub fn field_element_to_u256(input: Felt) -> U256 { U256::from_big_endian(&input.to_bytes_be()) } pub fn generate_config_hash( - config_hash_version: FieldElement, - chain_id: FieldElement, - fee_token_address: FieldElement, -) -> StarkHash { - pedersen_hash_array(&[ - StarkFelt(config_hash_version.to_bytes_be()), - StarkFelt(chain_id.to_bytes_be()), - StarkFelt(fee_token_address.to_bytes_be()), - ]) + config_hash_version: Felt, + chain_id: Felt, + fee_token_address: Felt, + native_fee_token_address: Felt, +) -> Felt { + Pedersen::hash_array(&[config_hash_version, chain_id, fee_token_address, native_fee_token_address]) } -pub fn get_bridge_init_configs(config: &CliArgs) -> (FieldElement, StarkHash) { - let program_hash = FieldElement::from_hex_be(config.sn_os_program_hash.as_str()).unwrap(); +pub fn get_bridge_init_configs(config: &CliArgs) -> (Felt, Felt) { + let program_hash = Felt::from_hex(config.sn_os_program_hash.as_str()).unwrap(); + let config_hash = generate_config_hash( - FieldElement::from_hex_be(&encode(config.config_hash_version.as_str())).expect("error in config_hash_version"), - FieldElement::from_hex_be(&encode(config.app_chain_id.as_str())).expect("error in app_chain_id"), - FieldElement::from_hex_be(config.fee_token_address.as_str()).expect("error in fee_token_address"), + Felt::from_hex(&encode(config.config_hash_version.as_str())).expect("error in config_hash_version"), + Felt::from_hex(&encode(config.app_chain_id.as_str())).expect("error in app_chain_id"), + Felt::from_hex(config.fee_token_address.as_str()).expect("error in fee_token_address"), + Felt::from_hex(config.native_fee_token_address.as_str()).expect("error in fee_token_address"), ); (program_hash, config_hash) } /// Broadcasted declare contract transaction v0. -#[derive(Debug, Eq, PartialEq, Serialize)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[derive(Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)] pub struct BroadcastedDeclareTransactionV0 { /// The address of the account contract sending the declaration transaction - pub sender_address: FieldElement, + pub sender_address: Felt, /// The maximal fee that can be charged for including the transaction - pub max_fee: FieldElement, + pub max_fee: Felt, /// Signature - pub signature: Vec, + pub signature: Vec, /// The class to be declared pub contract_class: Arc, /// If set to `true`, uses a query-only transaction version that's invalid for execution @@ -114,17 +119,26 @@ pub(crate) enum DeclarationInput<'a> { } #[allow(private_interfaces)] -pub async fn declare_contract(input: DeclarationInput<'_>) -> FieldElement { +pub async fn declare_contract(input: DeclarationInput<'_>) -> Felt { match input { DeclarationInputs(sierra_path, casm_path, account) => { - let (class_hash, sierra) = account.declare_contract_params_sierra(&sierra_path, &casm_path); + let contract_artifact: SierraClass = + serde_json::from_reader(std::fs::File::open(sierra_path).unwrap()).unwrap(); + + let contract_artifact_casm: CompiledClass = + serde_json::from_reader(std::fs::File::open(casm_path).unwrap()).unwrap(); + let class_hash = contract_artifact_casm.class_hash().unwrap(); + let sierra_class_hash = contract_artifact.class_hash().unwrap(); + + let flattened_class = contract_artifact.flatten().unwrap(); account - .declare(Arc::new(sierra.clone()), class_hash) + .declare_v3(Arc::new(flattened_class), class_hash) + .gas(0) .send() .await .expect("Error in declaring the contract using Cairo 1 declaration using the provided account"); - sierra.class_hash() + sierra_class_hash } LegacyDeclarationInputs(artifact_path, url) => { let contract_abi_artifact_temp: LegacyContractClass = serde_json::from_reader( @@ -132,27 +146,30 @@ pub async fn declare_contract(input: DeclarationInput<'_>) -> FieldElement { ) .unwrap(); - let contract_abi_artifact = - contract_abi_artifact_temp.clone().compress().expect("Error : Failed to compress the contract class"); + let contract_abi_artifact: CompressedLegacyContractClass = contract_abi_artifact_temp + .clone() + .compress() + .expect("Error : Failed to compress the contract class") + .into(); let params: BroadcastedDeclareTransactionV0 = BroadcastedDeclareTransactionV0 { - sender_address: FieldElement::from_hex_be("0x1").unwrap(), - max_fee: FieldElement::from(482250u128), + sender_address: Felt::from_hex("0x1").unwrap(), + max_fee: Felt::ZERO, signature: Vec::new(), contract_class: Arc::new(contract_abi_artifact), is_query: false, }; + // TODO: method can be updated based on the madara PR let json_body = &json!({ "jsonrpc": "2.0", - "method": "madara_addDeclareTransactionV0", + "method": "madara_addDeclareV0Transaction", "params": [params], "id": 4 }); let req_client = reqwest::Client::new(); let raw_txn_rpc = req_client.post(url).json(json_body).send().await; - match raw_txn_rpc { Ok(val) => { log::debug!( @@ -174,18 +191,17 @@ pub async fn declare_contract(input: DeclarationInput<'_>) -> FieldElement { pub(crate) async fn deploy_account_using_priv_key( priv_key: String, provider: &JsonRpcClient, - oz_account_class_hash: FieldElement, -) -> FieldElement { + oz_account_class_hash: Felt, +) -> Felt { let chain_id = provider.chain_id().await.unwrap(); - let signer = Arc::new(LocalWallet::from_signing_key(SigningKey::from_secret_scalar( - FieldElement::from_hex_be(&priv_key).unwrap(), - ))); + + let signer = LocalWallet::from(SigningKey::from_secret_scalar(Felt::from_hex(&priv_key).unwrap())); log::trace!("signer : {:?}", signer); let mut oz_account_factory = OpenZeppelinAccountFactory::new(oz_account_class_hash, chain_id, signer, provider).await.unwrap(); oz_account_factory.set_block_id(BlockId::Tag(BlockTag::Pending)); - let deploy_txn = oz_account_factory.deploy(FieldElement::ZERO); + let deploy_txn = oz_account_factory.deploy_v1(Felt::ZERO).max_fee(Felt::ZERO); let account_address = deploy_txn.address(); log::trace!("OZ Account Deployed : {:?}", account_address); save_to_json("account_address", &JsonValueType::StringType(account_address.to_string())).unwrap(); @@ -193,6 +209,7 @@ pub(crate) async fn deploy_account_using_priv_key( let sent_txn = deploy_txn.send().await.expect("Error in deploying the OZ account"); log::trace!("deploy account txn_hash : {:?}", sent_txn.transaction_hash); + wait_for_transaction(provider, sent_txn.transaction_hash, "deploy_account_using_priv_key").await.unwrap(); account_address @@ -200,22 +217,24 @@ pub(crate) async fn deploy_account_using_priv_key( pub(crate) async fn deploy_proxy_contract( account: &RpcAccount<'_>, - account_address: FieldElement, - class_hash: FieldElement, - salt: FieldElement, - deploy_from_zero: FieldElement, -) -> FieldElement { + account_address: Felt, + class_hash: Felt, + salt: Felt, + deploy_from_zero: Felt, +) -> Felt { let txn = account .invoke_contract( account_address, "deploy_contract", - vec![class_hash, salt, deploy_from_zero, FieldElement::ONE, FieldElement::ZERO], + vec![class_hash, salt, deploy_from_zero, Felt::ONE, Felt::ZERO], None, ) .send() .await .expect("Error deploying the contract proxy."); + log::debug!("txn in proxy contract is: {:?}", txn); + wait_for_transaction(account.provider(), txn.transaction_hash, "deploy_proxy_contract : deploy_contract") .await .unwrap(); @@ -228,7 +247,7 @@ pub(crate) async fn deploy_proxy_contract( deployed_address } -pub(crate) async fn init_governance_proxy(account: &'_ RpcAccount<'_>, contract_address: FieldElement, tag: &str) { +pub(crate) async fn init_governance_proxy(account: &'_ RpcAccount<'_>, contract_address: Felt, tag: &str) { let txn = invoke_contract(contract_address, "init_governance", vec![], account).await; wait_for_transaction(account.provider(), txn.transaction_hash, tag).await.unwrap(); } diff --git a/src/helpers/account_actions.rs b/src/helpers/account_actions.rs index f1e7107..74d7d53 100644 --- a/src/helpers/account_actions.rs +++ b/src/helpers/account_actions.rs @@ -2,72 +2,55 @@ use std::future::Future; use assert_matches::assert_matches; use async_trait::async_trait; -use starknet_accounts::{Account, Call, Execution, SingleOwnerAccount}; -use starknet_api::core::{calculate_contract_address, ClassHash, ContractAddress}; -use starknet_api::transaction::{Calldata, ContractAddressSalt}; -use starknet_core::types::contract::legacy::LegacyContractClass; +use starknet::accounts::{Account, Call, ExecutionV1, SingleOwnerAccount}; +use starknet::core::types::contract::legacy::LegacyContractClass; +use starknet::core::types::{Felt, FlattenedSierraClass, TransactionReceipt}; +use starknet::core::utils::get_selector_from_name; +use starknet::providers::jsonrpc::{HttpTransport, JsonRpcClient}; +use starknet::providers::Provider; +use starknet::signers::LocalWallet; use starknet_core::types::contract::{CompiledClass, SierraClass}; -use starknet_core::types::{ - FlattenedSierraClass, InvokeTransactionResult, MaybePendingTransactionReceipt, TransactionReceipt, -}; -use starknet_core::utils::get_selector_from_name; -use starknet_ff::FieldElement; -use starknet_providers::jsonrpc::HttpTransport; -use starknet_providers::{JsonRpcClient, Provider, ProviderError}; -use starknet_signers::LocalWallet; +use starknet_core::types::{InvokeTransactionResult, TransactionReceiptWithBlockInfo}; +use starknet_providers::ProviderError; use crate::contract_clients::utils::RpcAccount; -use crate::utils::constants::MAX_FEE_OVERRIDE; use crate::utils::wait_for_transaction; -pub struct U256 { - pub high: FieldElement, - pub low: FieldElement, -} - -pub type TransactionExecution<'a> = Execution<'a, RpcAccount<'a>>; +pub type TransactionExecution<'a> = ExecutionV1<'a, RpcAccount<'a>>; #[async_trait] pub trait AccountActions { fn invoke_contract( &self, - address: FieldElement, + address: Felt, method: &str, - calldata: Vec, + calldata: Vec, nonce: Option, ) -> TransactionExecution; - fn declare_contract_params_sierra( - &self, - path_to_sierra: &str, - path_to_casm: &str, - ) -> (FieldElement, FlattenedSierraClass); + fn declare_contract_params_sierra(&self, path_to_sierra: &str, path_to_casm: &str) -> (Felt, FlattenedSierraClass); fn declare_contract_params_legacy(&self, path_to_compiled_contract: &str) -> LegacyContractClass; } impl AccountActions for SingleOwnerAccount<&JsonRpcClient, LocalWallet> { fn invoke_contract( &self, - address: FieldElement, + address: Felt, method: &str, - calldata: Vec, + calldata: Vec, nonce: Option, ) -> TransactionExecution { let calls = vec![Call { to: address, selector: get_selector_from_name(method).unwrap(), calldata }]; - let max_fee = FieldElement::from_hex_be(MAX_FEE_OVERRIDE).unwrap(); - + // TODO: if we have the madara with fee flag set as 0, it shouldn't matter + let max_fee = Felt::ZERO; match nonce { - Some(nonce) => self.execute(calls).max_fee(max_fee).nonce(nonce.into()), - None => self.execute(calls).max_fee(max_fee), + Some(nonce) => self.execute_v1(calls).max_fee(max_fee).nonce(nonce.into()), + None => self.execute_v1(calls).max_fee(max_fee), } } - fn declare_contract_params_sierra( - &self, - path_to_sierra: &str, - path_to_casm: &str, - ) -> (FieldElement, FlattenedSierraClass) { + fn declare_contract_params_sierra(&self, path_to_sierra: &str, path_to_casm: &str) -> (Felt, FlattenedSierraClass) { let sierra: SierraClass = serde_json::from_reader( std::fs::File::open(env!("CARGO_MANIFEST_DIR").to_owned() + "/" + path_to_sierra).unwrap(), ) @@ -109,15 +92,15 @@ where panic!("Max poll count exceeded."); } -type TransactionReceiptResult = Result; +type TransactionReceiptResult = Result; pub async fn get_transaction_receipt( rpc: &JsonRpcClient, - transaction_hash: FieldElement, + transaction_hash: Felt, ) -> TransactionReceiptResult { // there is a delay between the transaction being available at the client - // and the sealing of the block, hence sleeping for 100ms - assert_poll(|| async { rpc.get_transaction_receipt(transaction_hash).await.is_ok() }, 100, 20).await; + // and the sealing of the block, hence sleeping for 500ms + assert_poll(|| async { rpc.get_transaction_receipt(transaction_hash).await.is_ok() }, 500, 20).await; rpc.get_transaction_receipt(transaction_hash).await } @@ -125,7 +108,7 @@ pub async fn get_transaction_receipt( pub async fn get_contract_address_from_deploy_tx( rpc: &JsonRpcClient, tx: &InvokeTransactionResult, -) -> Result { +) -> Result { let deploy_tx_hash = tx.transaction_hash; wait_for_transaction(rpc, deploy_tx_hash, "get_contract_address_from_deploy_tx").await.unwrap(); @@ -134,20 +117,9 @@ pub async fn get_contract_address_from_deploy_tx( let contract_address = assert_matches!( deploy_tx_receipt, - MaybePendingTransactionReceipt::Receipt(TransactionReceipt::Invoke(receipt)) => { + TransactionReceiptWithBlockInfo { receipt: TransactionReceipt::Invoke(receipt), .. } => { receipt.events.iter().find(|e| e.keys[0] == get_selector_from_name("ContractDeployed").unwrap()).unwrap().data[0] } ); Ok(contract_address) } - -pub async fn calculate_deployed_address( - salt: ContractAddressSalt, - class_hash: ClassHash, - calldata: &Calldata, - deployer_address: ContractAddress, -) -> FieldElement { - let address = calculate_contract_address(salt, class_hash, calldata, deployer_address).unwrap(); - let bytes = address.0.0.0; - FieldElement::from_bytes_be(&bytes).unwrap() -} diff --git a/src/main.rs b/src/main.rs index 7ad97ae..4c3417c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,11 +5,14 @@ mod setup_scripts; pub mod tests; pub mod utils; +use std::time::Duration; + use clap::{ArgAction, Parser}; use dotenv::dotenv; use inline_colorization::*; -use starknet_accounts::Account; -use starknet_ff::FieldElement; +use starknet::accounts::Account; +use starknet::core::types::Felt; +use tokio::time::sleep; use crate::contract_clients::config::Config; use crate::contract_clients::core_contract::CoreContract; @@ -46,11 +49,13 @@ pub struct CliArgs { sn_os_program_hash: String, #[clap(long, env, default_value = "StarknetOsConfig1")] config_hash_version: String, - #[clap(long, env, default_value = "MADARA")] + #[clap(long, env, default_value = "MADARA_DEVNET")] app_chain_id: String, #[clap(long, env, default_value = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7")] fee_token_address: String, - #[clap(long, env, default_value_t = 80)] + #[clap(long, env, default_value = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d")] + native_fee_token_address: String, + #[clap(long, env, default_value_t =20)] cross_chain_wait_time: u64, // Default test address value taken from anvil // IMP : Not to be used in prod environment @@ -83,16 +88,16 @@ pub async fn main() { pub struct DeployBridgeOutput { pub starknet_contract: Box, pub starknet_token_bridge: StarknetTokenBridge, - pub erc20_class_hash: FieldElement, - pub legacy_eth_bridge_class_hash: FieldElement, - pub account_address: FieldElement, - pub eth_proxy_address: FieldElement, - pub eth_bridge_proxy_address: FieldElement, - pub legacy_proxy_class_hash: FieldElement, - pub starkgate_proxy_class_hash: FieldElement, - pub erc20_legacy_class_hash: FieldElement, - pub erc20_l2_bridge_address: FieldElement, - pub l2_erc20_token_address: FieldElement, + pub erc20_class_hash: Felt, + pub legacy_eth_bridge_class_hash: Felt, + pub account_address: Felt, + pub eth_proxy_address: Felt, + pub eth_bridge_proxy_address: Felt, + pub legacy_proxy_class_hash: Felt, + pub starkgate_proxy_class_hash: Felt, + pub erc20_legacy_class_hash: Felt, + pub erc20_l2_bridge_address: Felt, + pub l2_erc20_token_address: Felt, pub eth_bridge: StarknetLegacyEthBridge, } @@ -108,6 +113,7 @@ pub async fn bootstrap(config: &CliArgs) -> DeployBridgeOutput { ) .unwrap(); log::info!("✅ Core setup init for L1 successful."); + sleep(Duration::from_secs(60)).await; log::info!("⏳ L2 State and Initialisation Started"); let account = account_init(&clients, config).await; log::info!("🔐 Account with given private key deployed on L2. [Account Address : {:?}]", account.address()); diff --git a/src/setup_scripts/argent.rs b/src/setup_scripts/argent.rs index 09f01c0..dd04600 100644 --- a/src/setup_scripts/argent.rs +++ b/src/setup_scripts/argent.rs @@ -1,6 +1,6 @@ use std::time::Duration; -use starknet_ff::FieldElement; +use starknet::core::types::Felt; use tokio::time::sleep; use crate::contract_clients::utils::{declare_contract, DeclarationInput, RpcAccount}; @@ -12,7 +12,7 @@ pub struct ArgentSetup<'a> { } pub struct ArgentSetupOutput { - pub argent_class_hash: FieldElement, + pub argent_class_hash: Felt, } impl<'a> ArgentSetup<'a> { diff --git a/src/setup_scripts/braavos.rs b/src/setup_scripts/braavos.rs index 750139a..bca89ac 100644 --- a/src/setup_scripts/braavos.rs +++ b/src/setup_scripts/braavos.rs @@ -1,7 +1,7 @@ use std::time::Duration; -use starknet_accounts::{Account, ConnectedAccount}; -use starknet_ff::FieldElement; +use starknet::accounts::{Account, ConnectedAccount}; +use starknet::core::types::Felt; use tokio::time::sleep; use crate::contract_clients::utils::{declare_contract, DeclarationInput, RpcAccount}; @@ -19,7 +19,7 @@ pub struct BraavosSetup<'a> { } pub struct BraavosSetupOutput { - pub braavos_class_hash: FieldElement, + pub braavos_class_hash: Felt, } impl<'a> BraavosSetup<'a> { @@ -70,7 +70,7 @@ impl<'a> BraavosSetup<'a> { .invoke_contract( self.account.address(), "deploy_contract", - vec![braavos_aggregator_class_hash, FieldElement::ZERO, FieldElement::ZERO, FieldElement::ZERO], + vec![braavos_aggregator_class_hash, Felt::ZERO, Felt::ZERO, Felt::ZERO], None, ) .send() diff --git a/src/setup_scripts/core_contract.rs b/src/setup_scripts/core_contract.rs index ad70a35..42b0962 100644 --- a/src/setup_scripts/core_contract.rs +++ b/src/setup_scripts/core_contract.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use ethers::abi::Address; -use starknet_api::hash::StarkFelt; use crate::contract_clients::config::Config; use crate::contract_clients::core_contract::{CoreContract, CoreContractDeploy}; @@ -31,11 +30,12 @@ impl<'a> CoreContractStarknetL1<'a> { false => Box::new(StarknetValidityContract::deploy(self.clients).await), }; log::info!("📦 Core address : {:?}", core_contract_client.address()); + save_to_json("l1_core_contract_address", &JsonValueType::EthAddress(core_contract_client.address())).unwrap(); let (program_hash, config_hash) = get_bridge_init_configs(self.arg_config); if self.arg_config.dev { - core_contract_client.initialize(StarkFelt(program_hash.to_bytes_be()), config_hash).await; + core_contract_client.initialize(program_hash, config_hash).await; } else { core_contract_client .add_implementation_core_contract( diff --git a/src/setup_scripts/erc20_bridge.rs b/src/setup_scripts/erc20_bridge.rs index 4f5fdd7..e0b511b 100644 --- a/src/setup_scripts/erc20_bridge.rs +++ b/src/setup_scripts/erc20_bridge.rs @@ -3,9 +3,9 @@ use std::time::Duration; use ethers::abi::Address; use ethers::prelude::{H160, U256}; +use starknet::core::types::Felt; use starknet_core::types::{BlockId, BlockTag, FunctionCall}; use starknet_core::utils::get_selector_from_name; -use starknet_ff::FieldElement; use starknet_providers::jsonrpc::HttpTransport; use starknet_providers::{JsonRpcClient, Provider}; use tokio::time::sleep; @@ -21,23 +21,23 @@ use crate::CliArgs; pub struct Erc20Bridge<'a> { account: RpcAccount<'a>, - account_address: FieldElement, + account_address: Felt, arg_config: &'a CliArgs, clients: &'a Config, core_contract: &'a dyn CoreContract, } pub struct Erc20BridgeSetupOutput { - pub erc20_cairo_one_class_hash: FieldElement, + pub erc20_cairo_one_class_hash: Felt, pub starknet_token_bridge: StarknetTokenBridge, - pub erc20_l2_bridge_address: FieldElement, - pub l2_erc20_token_address: FieldElement, + pub erc20_l2_bridge_address: Felt, + pub l2_erc20_token_address: Felt, } impl<'a> Erc20Bridge<'a> { pub fn new( account: RpcAccount<'a>, - account_address: FieldElement, + account_address: Felt, arg_config: &'a CliArgs, clients: &'a Config, core_contract: &'a dyn CoreContract, @@ -146,15 +146,15 @@ impl<'a> Erc20Bridge<'a> { async fn get_l2_token_address( rpc_provider_l2: &JsonRpcClient, - l2_bridge_address: &FieldElement, + l2_bridge_address: &Felt, l1_erc_20_address: &H160, -) -> FieldElement { +) -> Felt { rpc_provider_l2 .call( FunctionCall { contract_address: *l2_bridge_address, entry_point_selector: get_selector_from_name("get_l2_token").unwrap(), - calldata: vec![FieldElement::from_byte_slice_be(l1_erc_20_address.as_bytes()).unwrap()], + calldata: vec![Felt::from_bytes_be_slice(l1_erc_20_address.as_bytes())], }, BlockId::Tag(BlockTag::Pending), ) diff --git a/src/setup_scripts/eth_bridge.rs b/src/setup_scripts/eth_bridge.rs index 283cfb7..58e0fed 100644 --- a/src/setup_scripts/eth_bridge.rs +++ b/src/setup_scripts/eth_bridge.rs @@ -2,8 +2,8 @@ use std::str::FromStr; use std::time::Duration; use ethers::abi::Address; -use starknet_accounts::{Account, ConnectedAccount}; -use starknet_ff::FieldElement; +use starknet::accounts::{Account, ConnectedAccount}; +use starknet::core::types::Felt; use starknet_providers::jsonrpc::HttpTransport; use starknet_providers::JsonRpcClient; use tokio::time::sleep; @@ -22,26 +22,26 @@ use crate::CliArgs; pub struct EthBridge<'a> { account: RpcAccount<'a>, - account_address: FieldElement, + account_address: Felt, arg_config: &'a CliArgs, clients: &'a Config, core_contract: &'a dyn CoreContract, } pub struct EthBridgeSetupOutput { - pub legacy_proxy_class_hash: FieldElement, - pub starkgate_proxy_class_hash: FieldElement, - pub erc20_legacy_class_hash: FieldElement, - pub legacy_eth_bridge_class_hash: FieldElement, - pub eth_proxy_address: FieldElement, - pub eth_bridge_proxy_address: FieldElement, + pub legacy_proxy_class_hash: Felt, + pub starkgate_proxy_class_hash: Felt, + pub erc20_legacy_class_hash: Felt, + pub legacy_eth_bridge_class_hash: Felt, + pub eth_proxy_address: Felt, + pub eth_bridge_proxy_address: Felt, pub eth_bridge: StarknetLegacyEthBridge, } impl<'a> EthBridge<'a> { pub fn new( account: RpcAccount<'a>, - account_address: FieldElement, + account_address: Felt, arg_config: &'a CliArgs, clients: &'a Config, core_contract: &'a dyn CoreContract, @@ -98,8 +98,8 @@ impl<'a> EthBridge<'a> { self.account_address, legacy_proxy_class_hash, // salt taken from : https://sepolia.starkscan.co/tx/0x06a5a493cf33919e58aa4c75777bffdef97c0e39cac968896d7bee8cc67905a1 - FieldElement::from_str("0x322c2610264639f6b2cee681ac53fa65c37e187ea24292d1b21d859c55e1a78").unwrap(), - FieldElement::ONE, + Felt::from_str("0x322c2610264639f6b2cee681ac53fa65c37e187ea24292d1b21d859c55e1a78").unwrap(), + Felt::ONE, ) .await; log::info!("✴️ ETH ERC20 proxy deployed [ETH : {:?}]", eth_proxy_address); @@ -110,8 +110,8 @@ impl<'a> EthBridge<'a> { &self.account, self.account_address, legacy_proxy_class_hash, - FieldElement::from_str("0xabcdabcdabcd").unwrap(), - FieldElement::ZERO, + Felt::from_str("0xabcdabcdabcd").unwrap(), + Felt::ZERO, ) .await; log::info!("✴️ ETH Bridge proxy deployed [ETH Bridge : {:?}]", eth_bridge_proxy_address); @@ -121,6 +121,7 @@ impl<'a> EthBridge<'a> { init_governance_proxy(&self.account, eth_proxy_address, "eth_proxy_address : init_governance_proxy").await; sleep(Duration::from_secs(10)).await; + init_governance_proxy( &self.account, eth_bridge_proxy_address, @@ -211,16 +212,16 @@ impl<'a> EthBridge<'a> { pub async fn deploy_eth_token_on_l2( rpc_provider_l2: &JsonRpcClient, - eth_proxy_address: FieldElement, - eth_erc20_class_hash: FieldElement, + eth_proxy_address: Felt, + eth_erc20_class_hash: Felt, account: &RpcAccount<'_>, - eth_legacy_bridge_address: FieldElement, -) -> FieldElement { + eth_legacy_bridge_address: Felt, +) -> Felt { let deploy_tx = account .invoke_contract( account.address(), "deploy_contract", - vec![eth_erc20_class_hash, FieldElement::ZERO, FieldElement::ZERO, FieldElement::ZERO], + vec![eth_erc20_class_hash, Felt::ZERO, Felt::ZERO, Felt::ZERO], None, ) .send() @@ -236,13 +237,13 @@ pub async fn deploy_eth_token_on_l2( "add_implementation", vec![ contract_address, - FieldElement::ZERO, - FieldElement::from(4u64), - FieldElement::from_byte_slice_be("Ether".as_bytes()).unwrap(), - FieldElement::from_byte_slice_be("ETH".as_bytes()).unwrap(), - FieldElement::from_str("18").unwrap(), + Felt::ZERO, + Felt::from(4u64), + Felt::from_bytes_be_slice("Ether".as_bytes()), + Felt::from_bytes_be_slice("ETH".as_bytes()), + Felt::from_str("18").unwrap(), eth_legacy_bridge_address, - FieldElement::ZERO, + Felt::ZERO, ], account, ) @@ -261,13 +262,13 @@ pub async fn deploy_eth_token_on_l2( "upgrade_to", vec![ contract_address, - FieldElement::ZERO, - FieldElement::from(4u64), - FieldElement::from_byte_slice_be("Ether".as_bytes()).unwrap(), - FieldElement::from_byte_slice_be("ETH".as_bytes()).unwrap(), - FieldElement::from_str("18").unwrap(), + Felt::ZERO, + Felt::from(4u64), + Felt::from_bytes_be_slice("Ether".as_bytes()), + Felt::from_bytes_be_slice("ETH".as_bytes()), + Felt::from_str("18").unwrap(), eth_legacy_bridge_address, - FieldElement::ZERO, + Felt::ZERO, ], account, ) diff --git a/src/setup_scripts/udc.rs b/src/setup_scripts/udc.rs index fefa296..369a9be 100644 --- a/src/setup_scripts/udc.rs +++ b/src/setup_scripts/udc.rs @@ -1,7 +1,7 @@ use std::time::Duration; -use starknet_accounts::ConnectedAccount; -use starknet_ff::FieldElement; +use starknet::accounts::ConnectedAccount; +use starknet::core::types::Felt; use tokio::time::sleep; use crate::contract_clients::utils::{declare_contract, DeclarationInput, RpcAccount}; @@ -12,17 +12,17 @@ use crate::CliArgs; pub struct UdcSetup<'a> { account: RpcAccount<'a>, - account_address: FieldElement, + account_address: Felt, arg_config: &'a CliArgs, } pub struct UdcSetupOutput { - pub udc_class_hash: FieldElement, - pub udc_address: FieldElement, + pub udc_class_hash: Felt, + pub udc_address: Felt, } impl<'a> UdcSetup<'a> { - pub fn new(account: RpcAccount<'a>, account_address: FieldElement, arg_config: &'a CliArgs) -> Self { + pub fn new(account: RpcAccount<'a>, account_address: Felt, arg_config: &'a CliArgs) -> Self { Self { account, account_address, arg_config } } @@ -41,7 +41,7 @@ impl<'a> UdcSetup<'a> { .invoke_contract( self.account_address, "deploy_contract", - Vec::from([udc_class_hash, FieldElement::ZERO, FieldElement::ONE, FieldElement::ZERO]), + Vec::from([udc_class_hash, Felt::ZERO, Felt::ONE, Felt::ZERO]), None, ) .send() diff --git a/src/tests/constants.rs b/src/tests/constants.rs index 08fe16d..e1144af 100644 --- a/src/tests/constants.rs +++ b/src/tests/constants.rs @@ -6,9 +6,10 @@ pub const ETH_CHAIN_ID: &str = "31337"; pub const L1_DEPLOYER_ADDRESS: &str = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"; pub const L1_WAIT_TIME: &str = "15"; pub const FEE_TOKEN_ADDRESS: &str = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"; +pub const NATIVE_FEE_TOKEN_ADDRESS: &str = "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"; pub const SN_OS_PROGRAM_HASH: &str = "0x41fc2a467ef8649580631912517edcab7674173f1dbfa2e9b64fbcd82bc4d79"; -pub const SN_OS_CONFIG_HASH_VERSION: &str = "StarknetOsConfig1"; -pub const APP_CHAIN_ID: &str = "MADARA"; +pub const SN_OS_CONFIG_HASH_VERSION: &str = "StarknetOsConfig2"; +pub const APP_CHAIN_ID: &str = "MADARA_DEVNET"; pub const L2_DEPLOYER_ADDRESS: &str = "0x4fe5eea46caa0a1f344fafce82b39d66b552f00d3cd12e89073ef4b4ab37860"; pub const L1_MULTISIG_ADDRESS: &str = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8"; pub const L2_MULTISIG_ADDRESS: &str = "0x556455b8ac8bc00e0ad061d7df5458fa3c372304877663fa21d492a8d5e9435"; diff --git a/src/tests/erc20_bridge.rs b/src/tests/erc20_bridge.rs index 3a30a4e..d6e597b 100644 --- a/src/tests/erc20_bridge.rs +++ b/src/tests/erc20_bridge.rs @@ -2,23 +2,24 @@ use std::str::FromStr; use std::time::Duration; use ethers::prelude::U256; -use starknet_ff::FieldElement; +use ethers::types::Address; +use starknet::core::types::Felt; use tokio::time::sleep; use crate::contract_clients::config::Config; use crate::contract_clients::token_bridge::StarknetTokenBridge; -use crate::contract_clients::utils::read_erc20_balance; +use crate::contract_clients::utils::{build_single_owner_account, read_erc20_balance}; use crate::tests::constants::L2_DEPLOYER_ADDRESS; +use crate::utils::invoke_contract; use crate::CliArgs; - // TODO : Uncomment L2 --> L1 part after this part is added in the madara-orchestrator. pub async fn erc20_bridge_test_helper( clients: &Config, arg_config: &CliArgs, - l2_erc20_token_address: FieldElement, + l2_erc20_token_address: Felt, token_bridge: StarknetTokenBridge, - _l2_bridge_address: FieldElement, + l2_bridge_address: Felt, ) -> Result<(), anyhow::Error> { token_bridge.approve(token_bridge.bridge_address(), 100000000.into()).await; sleep(Duration::from_secs(arg_config.l1_wait_time.parse().unwrap())).await; @@ -26,12 +27,9 @@ pub async fn erc20_bridge_test_helper( log::debug!("Waiting for message to be consumed on l2 [⏳]"); sleep(Duration::from_secs(arg_config.cross_chain_wait_time)).await; - let balance_before = read_erc20_balance( - clients.provider_l2(), - l2_erc20_token_address, - FieldElement::from_str(L2_DEPLOYER_ADDRESS).unwrap(), - ) - .await; + let balance_before = + read_erc20_balance(clients.provider_l2(), l2_erc20_token_address, Felt::from_str(L2_DEPLOYER_ADDRESS).unwrap()) + .await; token_bridge .deposit( @@ -46,43 +44,43 @@ pub async fn erc20_bridge_test_helper( log::debug!("Waiting for message to be consumed on l2 [⏳]"); sleep(Duration::from_secs(arg_config.cross_chain_wait_time)).await; - let balance_after = read_erc20_balance( - clients.provider_l2(), - l2_erc20_token_address, - FieldElement::from_str(L2_DEPLOYER_ADDRESS).unwrap(), - ) - .await; + let balance_after = + read_erc20_balance(clients.provider_l2(), l2_erc20_token_address, Felt::from_str(L2_DEPLOYER_ADDRESS).unwrap()) + .await; + + assert_eq!(balance_before[0] + Felt::from(10), balance_after[0]); - assert_eq!(balance_before[0] + FieldElement::from_dec_str("10").unwrap(), balance_after[0]); + // let l1_recipient = Felt::from_hex(&arg_config.l1_deployer_address).unwrap(); + // let account = + // build_single_owner_account(clients.provider_l2(), &arg_config.rollup_priv_key, L2_DEPLOYER_ADDRESS, false) + // .await; - // let l1_recipient = FieldElement::from_hex_be(&arg_config.l1_deployer_address).unwrap(); - // // log::debug!("Initiated token withdraw on L2 [⏳]"); // invoke_contract( // l2_bridge_address, // "initiate_token_withdraw", // vec![ - // FieldElement::from_byte_slice_be(token_bridge.address().as_bytes()).unwrap(), + // Felt::from_bytes_be_slice(token_bridge.address().as_bytes()), // l1_recipient, - // FieldElement::from_dec_str("5").unwrap(), - // FieldElement::ZERO, + // Felt::from_dec_str("5").unwrap(), + // Felt::ZERO, // ], // &account, // ) // .await; - // + // sleep(Duration::from_secs(arg_config.l1_wait_time.parse().unwrap())).await; // log::debug!("Waiting for message to be consumed on l2 [⏳]"); // sleep(Duration::from_secs(arg_config.cross_chain_wait_time)).await; // sleep(Duration::from_secs(arg_config.l1_wait_time.parse().unwrap())).await; - // + // let l1_recipient: Address = Address::from_str(&arg_config.l1_deployer_address).unwrap(); // let balance_before = token_bridge.token_balance(l1_recipient).await; // token_bridge.withdraw(token_bridge.address(), 5.into(), l1_recipient).await; // let balance_after = token_bridge.token_balance(l1_recipient).await; - // + // assert_eq!(balance_before + U256::from_dec_str("5").unwrap(), balance_after); - // + // log::debug!("Token withdraw successful [✅]"); anyhow::Ok(()) diff --git a/src/tests/eth_bridge.rs b/src/tests/eth_bridge.rs index 8bf0c61..c0c57eb 100644 --- a/src/tests/eth_bridge.rs +++ b/src/tests/eth_bridge.rs @@ -2,76 +2,64 @@ use std::str::FromStr; use std::time::Duration; use ethers::prelude::U256; -use starknet_ff::FieldElement; +use ethers::types::Address; +// use ethers::types::Address; +use starknet::core::types::Felt; use tokio::time::sleep; use crate::contract_clients::config::Config; use crate::contract_clients::eth_bridge::StarknetLegacyEthBridge; -use crate::contract_clients::utils::read_erc20_balance; +use crate::contract_clients::utils::{build_single_owner_account, read_erc20_balance}; use crate::tests::constants::L2_DEPLOYER_ADDRESS; +use crate::utils::invoke_contract; use crate::CliArgs; - // TODO : Uncomment L2 --> L1 part after this part is added in the madara-orchestrator. pub async fn eth_bridge_test_helper( clients: &Config, arg_config: &CliArgs, - l2_eth_address: FieldElement, - _l2_bridge_address: FieldElement, + l2_eth_address: Felt, + l2_bridge_address: Felt, eth_bridge: StarknetLegacyEthBridge, ) -> Result<(), anyhow::Error> { - let balance_before = read_erc20_balance( - clients.provider_l2(), - l2_eth_address, - FieldElement::from_hex_be(L2_DEPLOYER_ADDRESS).unwrap(), - ) - .await; + let balance_before = + read_erc20_balance(clients.provider_l2(), l2_eth_address, Felt::from_hex(L2_DEPLOYER_ADDRESS).unwrap()).await; eth_bridge.deposit(10.into(), U256::from_str(L2_DEPLOYER_ADDRESS).unwrap(), 1000.into()).await; + log::debug!("ETH deposited on l1 [💰]"); sleep(Duration::from_secs(arg_config.cross_chain_wait_time)).await; sleep(Duration::from_secs((arg_config.l1_wait_time).parse()?)).await; log::debug!("L1 message executed on L2 [🔁]"); - let balance_after = read_erc20_balance( - clients.provider_l2(), - l2_eth_address, - FieldElement::from_hex_be(L2_DEPLOYER_ADDRESS).unwrap(), - ) - .await; + let balance_after = + read_erc20_balance(clients.provider_l2(), l2_eth_address, Felt::from_hex(L2_DEPLOYER_ADDRESS).unwrap()).await; - assert_eq!(balance_before[0] + FieldElement::from_dec_str("10").unwrap(), balance_after[0]); + assert_eq!(balance_before[0] + Felt::from_dec_str("10").unwrap(), balance_after[0]); + + // let l1_receipient = Felt::from_hex(&arg_config.l1_deployer_address).unwrap(); - // let l1_receipient = FieldElement::from_hex_be(&arg_config.l1_deployer_address).unwrap(); - // // sleep(Duration::from_secs((arg_config.l1_wait_time).parse()?)).await; - // + // let account = - // build_single_owner_account(clients.provider_l2(), &arg_config.rollup_priv_key, - // L2_DEPLOYER_ADDRESS, false) .await; - // - // invoke_contract( - // l2_bridge_address, - // "initiate_withdraw", - // vec![l1_receipient, FieldElement::from_dec_str("5").unwrap(), FieldElement::ZERO], - // &account, - // ) - // .await; + // build_single_owner_account(clients.provider_l2(), &arg_config.rollup_priv_key, L2_DEPLOYER_ADDRESS, false) + // .await; + + // invoke_contract(l2_bridge_address, "initiate_withdraw", vec![l1_receipient, Felt::from(5), Felt::ZERO], &account) + // .await; // log::debug!("ETH withdrawal initiated on l2 [💰]"); // log::debug!("Waiting for message to be consumed on l2 [⏳]"); // sleep(Duration::from_secs(arg_config.cross_chain_wait_time)).await; // sleep(Duration::from_secs((arg_config.l1_wait_time).parse()?)).await; - // - // let balance_before = - // eth_bridge.eth_balance(Address::from_str(&arg_config.l1_deployer_address).unwrap()).await; + + // let balance_before = eth_bridge.eth_balance(Address::from_str(&arg_config.l1_deployer_address).unwrap()).await; // log::debug!("Withdraw initiated on ETH Bridge [⏳]"); // eth_bridge.withdraw(5.into(), Address::from_str(&arg_config.l1_deployer_address).unwrap()).await; // log::debug!("Withdraw completed on ETH Bridge [✅]"); - // let balance_after = - // eth_bridge.eth_balance(Address::from_str(&arg_config.l1_deployer_address).unwrap()).await; - // + // let balance_after = eth_bridge.eth_balance(Address::from_str(&arg_config.l1_deployer_address).unwrap()).await; + // let decimals_eth = U256::from_dec_str("1000000000000000000").unwrap(); - // + // assert_eq!( // U256::checked_div(balance_before + U256::from_dec_str("5").unwrap(), decimals_eth).unwrap(), // U256::checked_div(balance_after, decimals_eth).unwrap() diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 15726a1..af68b5e 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -4,7 +4,7 @@ mod eth_bridge; use constants::{ APP_CHAIN_ID, ETH_CHAIN_ID, ETH_PRIV_KEY, ETH_RPC, FEE_TOKEN_ADDRESS, L1_DEPLOYER_ADDRESS, L1_WAIT_TIME, - ROLLUP_PRIV_KEY, ROLLUP_SEQ_URL, SN_OS_CONFIG_HASH_VERSION, SN_OS_PROGRAM_HASH, + NATIVE_FEE_TOKEN_ADDRESS, ROLLUP_PRIV_KEY, ROLLUP_SEQ_URL, SN_OS_CONFIG_HASH_VERSION, SN_OS_PROGRAM_HASH, }; use rstest::rstest; @@ -106,11 +106,12 @@ fn get_config() -> CliArgs { config_hash_version: String::from(SN_OS_CONFIG_HASH_VERSION), app_chain_id: String::from(APP_CHAIN_ID), fee_token_address: String::from(FEE_TOKEN_ADDRESS), - cross_chain_wait_time: 120, + native_fee_token_address: String::from(NATIVE_FEE_TOKEN_ADDRESS), + cross_chain_wait_time: 20, l1_multisig_address: String::from(L1_MULTISIG_ADDRESS), l2_multisig_address: String::from(L2_MULTISIG_ADDRESS), verifier_address: String::from(VERIFIER_ADDRESS), operator_address: String::from(OPERATOR_ADDRESS), - dev: true, + dev: false, } } diff --git a/src/utils/mod.rs b/src/utils/mod.rs index fad9ced..891e427 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,19 +1,15 @@ use std::path::Path; -use std::time::Duration; use std::{fs, io}; use ethers::addressbook::Address; use ethers::types::U256; use num_bigint::BigUint; use serde_json::{Map, Value}; -use starknet_accounts::ConnectedAccount; -use starknet_api::hash::StarkFelt; -use starknet_core::types::InvokeTransactionResult; -use starknet_core::types::MaybePendingTransactionReceipt::{PendingReceipt, Receipt}; -use starknet_ff::FieldElement; +use starknet::accounts::ConnectedAccount; +use starknet::core::types::{Felt, InvokeTransactionResult, TransactionReceipt}; +use starknet_core::types::TransactionReceiptWithBlockInfo; use starknet_providers::jsonrpc::HttpTransport; use starknet_providers::JsonRpcClient; -use tokio::time::sleep; use crate::contract_clients::utils::RpcAccount; use crate::helpers::account_actions::{get_transaction_receipt, AccountActions}; @@ -22,9 +18,9 @@ pub mod banner; pub mod constants; pub async fn invoke_contract<'a>( - contract: FieldElement, + contract: Felt, method: &str, - calldata: Vec, + calldata: Vec, account: &RpcAccount<'a>, ) -> InvokeTransactionResult { let txn_res = @@ -45,7 +41,7 @@ pub fn pad_bytes(address: Address) -> Vec { pub async fn wait_for_transaction( provider_l2: &JsonRpcClient, - transaction_hash: FieldElement, + transaction_hash: Felt, tag: &str, ) -> Result<(), anyhow::Error> { let transaction_receipt = get_transaction_receipt(provider_l2, transaction_hash).await; @@ -53,20 +49,24 @@ pub async fn wait_for_transaction( let transaction_status = transaction_receipt.ok().unwrap(); match transaction_status { - Receipt(transaction_receipt) => { - log::trace!("txn : {:?} : {:?}", tag, transaction_receipt); - Ok(()) + TransactionReceiptWithBlockInfo { receipt: TransactionReceipt::Invoke(receipt), .. } => { + log::trace!("txn : {:?} : {:?}", tag, receipt); } - PendingReceipt(..) => { - log::trace!("⏳ waiting for transaction : {:?}", transaction_hash); - sleep(Duration::from_secs(2)).await; - Box::pin(wait_for_transaction(provider_l2, transaction_hash, "")).await + TransactionReceiptWithBlockInfo { receipt: TransactionReceipt::DeployAccount(receipt), .. } => { + let contract_address = receipt.contract_address; + log::trace!("txn : {:?} : {:?}", tag, contract_address); } - } + _ => { + log::error!("Transaction status: {:?}", transaction_status); + panic!("Transaction failed"); + } + }; + + Ok(()) } -pub fn convert_felt_to_u256(felt: StarkFelt) -> U256 { - U256::from_big_endian(felt.bytes()) +pub fn convert_felt_to_u256(felt: Felt) -> U256 { + U256::from_big_endian(&felt.to_bytes_le()) } pub enum JsonValueType {