From b700df8b4f4636a8ef8e2c586fa8469dfc23acd6 Mon Sep 17 00:00:00 2001 From: GreatSoshiant <61604245+GreatSoshiant@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:07:36 -0700 Subject: [PATCH 1/6] files added to the repo --- .../crowd_fund/.cargo/config.toml | 16 + .../applications/crowd_fund/Cargo.lock | 1611 +++++++++++++++++ .../applications/crowd_fund/Cargo.toml | 25 + .../applications/crowd_fund/README.md | 46 + .../crowd_fund/rust-toolchain.toml | 2 + .../applications/crowd_fund/src/lib.rs | 193 ++ .../applications/crowd_fund/src/main.rs | 6 + src/app/applications/crowd_fund/page.mdx | 273 +++ 8 files changed, 2172 insertions(+) create mode 100644 example_code/applications/crowd_fund/.cargo/config.toml create mode 100644 example_code/applications/crowd_fund/Cargo.lock create mode 100644 example_code/applications/crowd_fund/Cargo.toml create mode 100644 example_code/applications/crowd_fund/README.md create mode 100644 example_code/applications/crowd_fund/rust-toolchain.toml create mode 100644 example_code/applications/crowd_fund/src/lib.rs create mode 100644 example_code/applications/crowd_fund/src/main.rs create mode 100644 src/app/applications/crowd_fund/page.mdx diff --git a/example_code/applications/crowd_fund/.cargo/config.toml b/example_code/applications/crowd_fund/.cargo/config.toml new file mode 100644 index 0000000..8c46df4 --- /dev/null +++ b/example_code/applications/crowd_fund/.cargo/config.toml @@ -0,0 +1,16 @@ +[target.wasm32-unknown-unknown] +rustflags = [ + "-C", "link-arg=-zstack-size=32768", +] + +[target.aarch64-apple-darwin] +rustflags = [ +"-C", "link-arg=-undefined", +"-C", "link-arg=dynamic_lookup", +] + +[target.x86_64-apple-darwin] +rustflags = [ +"-C", "link-arg=-undefined", +"-C", "link-arg=dynamic_lookup", +] diff --git a/example_code/applications/crowd_fund/Cargo.lock b/example_code/applications/crowd_fund/Cargo.lock new file mode 100644 index 0000000..6d303e8 --- /dev/null +++ b/example_code/applications/crowd_fund/Cargo.lock @@ -0,0 +1,1611 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +dependencies = [ + "memchr", +] + +[[package]] +name = "alloy-primitives" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f783611babedbbe90db3478c120fb5f5daacceffc210b39adc0af4fe0da70bad" +dependencies = [ + "alloy-rlp", + "bytes", + "cfg-if 1.0.0", + "const-hex", + "derive_more", + "hex-literal", + "itoa", + "k256", + "keccak-asm", + "proptest", + "rand", + "ruint", + "serde", + "tiny-keccak", +] + +[[package]] +name = "alloy-rlp" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d58d9f5da7b40e9bfff0b7e7816700be4019db97d4b6359fe7f94a9e22e42ac" +dependencies = [ + "arrayvec", + "bytes", +] + +[[package]] +name = "alloy-sol-macro" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bad41a7c19498e3f6079f7744656328699f8ea3e783bdd10d85788cd439f572" +dependencies = [ + "alloy-sol-macro-expander", + "alloy-sol-macro-input", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.50", +] + +[[package]] +name = "alloy-sol-macro-expander" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd9899da7d011b4fe4c406a524ed3e3f963797dbc93b45479d60341d3a27b252" +dependencies = [ + "alloy-sol-macro-input", + "const-hex", + "heck", + "indexmap", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.50", + "syn-solidity", + "tiny-keccak", +] + +[[package]] +name = "alloy-sol-macro-input" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32d595768fdc61331a132b6f65db41afae41b9b97d36c21eb1b955c422a7e60" +dependencies = [ + "const-hex", + "dunce", + "heck", + "proc-macro2", + "quote", + "syn 2.0.50", + "syn-solidity", +] + +[[package]] +name = "alloy-sol-types" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a49042c6d3b66a9fe6b2b5a8bf0d39fc2ae1ee0310a2a26ffedd79fb097878dd" +dependencies = [ + "alloy-primitives", + "alloy-sol-macro", + "const-hex", + "serde", +] + +[[package]] +name = "ark-ff" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b3235cc41ee7a12aaaf2c575a2ad7b46713a8a50bda2fc3b003a04845c05dd6" +dependencies = [ + "ark-ff-asm 0.3.0", + "ark-ff-macros 0.3.0", + "ark-serialize 0.3.0", + "ark-std 0.3.0", + "derivative", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.3.3", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm 0.4.2", + "ark-ff-macros 0.4.2", + "ark-serialize 0.4.2", + "ark-std 0.4.0", + "derivative", + "digest 0.10.7", + "itertools", + "num-bigint", + "num-traits", + "paste", + "rustc_version 0.4.0", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db02d390bf6643fb404d3d22d31aee1c4bc4459600aef9113833d17e786c6e44" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fd794a08ccb318058009eefdf15bcaaaaf6f8161eb3345f907222bac38b20" +dependencies = [ + "num-bigint", + "num-traits", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-serialize" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6c2b318ee6e10f8c2853e73a83adc0ccb88995aa978d8a3408d492ab2ee671" +dependencies = [ + "ark-std 0.3.0", + "digest 0.9.0", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-std 0.4.0", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-std" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df2c09229cbc5a028b1d70e00fdb2acee28b1055dfb5ca73eea49c5a25c4e7c" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand", +] + +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + +[[package]] +name = "auto_impl" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c87f3f15e7794432337fc718554eaa4dc8f04c9677a950ffe366f20a162ae42" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", +] + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + +[[package]] +name = "bitflags" +version = "2.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byte-slice-cast" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3ac9f8b63eca6fd385229b3675f6cc0dc5c8a5c8a54a59d4f52ffd670d87b0c" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" + +[[package]] +name = "cc" +version = "1.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9e8aabfac534be767c909e0690571677d49f41bd8465ae876fe043d52ba5292" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-hex" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d59688ad0945eaf6b84cb44fedbe93484c81b48970e98f09db8a22832d7961" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "hex", + "proptest", + "serde", +] + +[[package]] +name = "const-oid" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "cpufeatures" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" +dependencies = [ + "generic-array", + "rand_core", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "der" +version = "0.7.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" +dependencies = [ + "const-oid", + "zeroize", +] + +[[package]] +name = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case 0.4.0", + "proc-macro2", + "quote", + "rustc_version 0.4.0", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "const-oid", + "crypto-common", + "subtle", +] + +[[package]] +name = "dunce" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ce8c6da7551ec6c462cbaf3bfbc75131ebbfa1c944aeaa9dab51ca1c5f0c3b" + +[[package]] +name = "ecdsa" +version = "0.16.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature", + "spki", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "elliptic-curve" +version = "0.13.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core", + "sec1", + "subtle", + "zeroize", +] + +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + +[[package]] +name = "fastrlp" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139834ddba373bbdd213dffe02c8d110508dcf1726c2be27e8d1f7d7e1856418" +dependencies = [ + "arrayvec", + "auto_impl", + "bytes", +] + +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core", + "subtle", +] + +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "byteorder", + "rand", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", + "zeroize", +] + +[[package]] +name = "getrandom" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hex-literal" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "impl-codec" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba6a270039626615617f3f36d15fc827041df3b78c439da2cadfa47455a77f2f" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11d7a9f6330b71fea57921c9b61c47ee6e84f72d394754eff6163ae67e7395eb" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "indexmap" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" + +[[package]] +name = "k256" +version = "0.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +dependencies = [ + "cfg-if 1.0.0", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2", +] + +[[package]] +name = "keccak" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc2af9a1119c51f12a14607e783cb977bde58bc069ff0c3da1095e635d70654" +dependencies = [ + "cpufeatures", +] + +[[package]] +name = "keccak-asm" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "422fbc7ff2f2f5bdffeb07718e5a5324dca72b0c9293d50df4026652385e3314" +dependencies = [ + "digest 0.10.7", + "sha3-asm", +] + +[[package]] +name = "keccak-const" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d8d8ce877200136358e0bbff3a77965875db3af755a11e1fa6b1b3e2df13ea" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.153" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "linux-raw-sys" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" + +[[package]] +name = "memchr" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" + +[[package]] +name = "memory_units" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" + +[[package]] +name = "mini-alloc" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9993556d3850cdbd0da06a3dc81297edcfa050048952d84d75e8b944e8f5af" +dependencies = [ + "cfg-if 1.0.0", + "wee_alloc", +] + +[[package]] +name = "mini-alloc" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14eacc4bfcf10da9b6d5185ef51b2dc75434afac34b4d8aabe40f6b141ee071c" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "num-bigint" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" +dependencies = [ + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "parity-scale-codec" +version = "3.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "306800abfa29c7f16596b5970a588435e3d5b3149683d00c12b699cc19f895ee" +dependencies = [ + "arrayvec", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "3.6.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d830939c76d294956402033aee57a6da7b438f2294eb94864c37b0569053a42c" +dependencies = [ + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "paste" +version = "1.0.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" + +[[package]] +name = "pest" +version = "2.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd53dff83f26735fdc1ca837098ccf133605d794cdae66acfc2bfac3ec809d95" +dependencies = [ + "memchr", + "thiserror", + "ucd-trie", +] + +[[package]] +name = "pkcs8" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash", + "impl-codec", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "proptest" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" +dependencies = [ + "bit-set", + "bit-vec", + "bitflags", + "lazy_static", + "num-traits", + "rand", + "rand_chacha", + "rand_xorshift", + "regex-syntax", + "rusty-fork", + "tempfile", + "unarray", +] + +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rand_xorshift" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" +dependencies = [ + "rand_core", +] + +[[package]] +name = "regex" +version = "1.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5bb987efffd3c6d0d8f5f89510bb458559eab11e4f869acb20bf845e016259cd" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", +] + +[[package]] +name = "rlp" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb919243f34364b6bd2fc10ef797edbfa75f33c252e7998527479c6d6b47e1ec" +dependencies = [ + "bytes", + "rustc-hex", +] + +[[package]] +name = "ruint" +version = "1.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c3cc4c2511671f327125da14133d0c5c5d137f006a1017a16f557bc85b16286" +dependencies = [ + "alloy-rlp", + "ark-ff 0.3.0", + "ark-ff 0.4.2", + "bytes", + "fastrlp", + "num-bigint", + "num-traits", + "parity-scale-codec", + "primitive-types", + "proptest", + "rand", + "rlp", + "ruint-macro", + "serde", + "valuable", + "zeroize", +] + +[[package]] +name = "ruint-macro" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.22", +] + +[[package]] +name = "rustix" +version = "0.38.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +dependencies = [ + "bitflags", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + +[[package]] +name = "sec1" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" +dependencies = [ + "semver-parser", +] + +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + +[[package]] +name = "semver-parser" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" +dependencies = [ + "pest", +] + +[[package]] +name = "serde" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", +] + +[[package]] +name = "sha2" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.7", +] + +[[package]] +name = "sha3" +version = "0.10.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" +dependencies = [ + "digest 0.10.7", + "keccak", +] + +[[package]] +name = "sha3-asm" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57d79b758b7cb2085612b11a235055e485605a5103faccdd633f35bd7aee69dd" +dependencies = [ + "cc", + "cfg-if 1.0.0", +] + +[[package]] +name = "signature" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" +dependencies = [ + "digest 0.10.7", + "rand_core", +] + +[[package]] +name = "spki" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "stylus-crowd-fund" +version = "0.1.0" +dependencies = [ + "alloy-primitives", + "alloy-sol-types", + "hex", + "mini-alloc 0.4.2", + "stylus-sdk", +] + +[[package]] +name = "stylus-proc" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fd02e91dffe7b73df84a861c992494d6b72054bc9a17fe73e147e34e9a64ef3" +dependencies = [ + "alloy-primitives", + "alloy-sol-types", + "cfg-if 1.0.0", + "convert_case 0.6.0", + "lazy_static", + "proc-macro2", + "quote", + "regex", + "sha3", + "syn 1.0.109", + "syn-solidity", +] + +[[package]] +name = "stylus-sdk" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26042693706e29fb7e3cf3d71c99534ac97fca98b6f81ba77ab658022ab2e210" +dependencies = [ + "alloy-primitives", + "alloy-sol-types", + "cfg-if 1.0.0", + "derivative", + "hex", + "keccak-const", + "lazy_static", + "mini-alloc 0.6.0", + "regex", + "stylus-proc", +] + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn-solidity" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d71e19bca02c807c9faa67b5a47673ff231b6e7449b251695188522f1dc44b2" +dependencies = [ + "paste", + "proc-macro2", + "quote", + "syn 2.0.50", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tempfile" +version = "3.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a365e8cd18e44762ef95d87f284f4b5cd04107fec2ff3052bd6a3e6069669e67" +dependencies = [ + "cfg-if 1.0.0", + "fastrand", + "rustix", + "windows-sys", +] + +[[package]] +name = "thiserror" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", +] + +[[package]] +name = "tiny-keccak" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" +dependencies = [ + "crunchy", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap", + "toml_datetime", + "winnow", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "ucd-trie" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed646292ffc8188ef8ea4d1e0e0150fb15a5c2e12ad9b8fc191ae7a8a7f3c4b9" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unarray" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "wee_alloc" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb3b5a6b2bb17cb6ad44a2e68a43e8d2722c997da10e928665c72ec6c0a0b8e" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "memory_units", + "winapi", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d380ba1dc7187569a8a9e91ed34b8ccfc33123bbacb8c0aed2d1ad7f3ef2dc5f" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68e5dcfb9413f53afd9c8f86e56a7b4d86d9a2fa26090ea2dc9e40fba56c6ec6" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dab469ebbc45798319e69eebf92308e541ce46760b49b18c6b3fe5e8965b30f" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a4e9b6a7cac734a8b4138a4e1044eac3404d8326b6c0f939276560687a033fb" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28b0ec9c422ca95ff34a78755cfa6ad4a51371da2a5ace67500cf7ca5f232c58" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "704131571ba93e89d7cd43482277d6632589b18ecf4468f591fbae0a8b101614" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42079295511643151e98d61c38c0acc444e52dd42ab456f7ccfd5152e8ecf21c" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0770833d60a970638e989b3fa9fd2bb1aaadcf88963d1659fd7d9990196ed2d6" + +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] + +[[package]] +name = "zeroize" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", +] diff --git a/example_code/applications/crowd_fund/Cargo.toml b/example_code/applications/crowd_fund/Cargo.toml new file mode 100644 index 0000000..9dd12e2 --- /dev/null +++ b/example_code/applications/crowd_fund/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "stylus-crowd-fund" +version = "0.1.0" +edition = "2021" + +[dependencies] +alloy-primitives = "=0.7.6" +alloy-sol-types = "=0.7.6" +mini-alloc = "0.4.2" +stylus-sdk = "0.6.0" +hex = "0.4.3" + +[features] +export-abi = ["stylus-sdk/export-abi"] +debug = ["stylus-sdk/debug"] + +[lib] +crate-type = ["lib", "cdylib"] + +[profile.release] +codegen-units = 1 +strip = true +lto = true +panic = "abort" +opt-level = "s" \ No newline at end of file diff --git a/example_code/applications/crowd_fund/README.md b/example_code/applications/crowd_fund/README.md new file mode 100644 index 0000000..811e80c --- /dev/null +++ b/example_code/applications/crowd_fund/README.md @@ -0,0 +1,46 @@ +# Stylus Crowd Fund Example + +An example project for writing Arbitrum Stylus programs in Rust using the [stylus-sdk](https://github.com/OffchainLabs/stylus-sdk-rs). It includes a Rust implementation of a crowd fund Ethereum smart contract. Below is the interface for the CrowdFund contract: + +```js +// SPDX-License-Identifier: MIT-OR-APACHE-2.0 +pragma solidity ^0.8.23; + +interface ICrowdFund { + function launch(uint256 goal, uint256 start_at, uint256 end_at) external; + + function cancel(uint256 id) external; + + function pledge(uint256 id, uint256 amount) external; + + function unpledge(uint256 id, uint256 amount) external; + + function claim(uint256 id) external; + + function refund(uint256 id) external; +} +``` + +### ABI Export + +You can export the Solidity ABI for your program by using the `cargo stylus` tool as follows: + +```bash +cargo stylus export-abi +``` + +## Deploying + +You can use the `cargo stylus` command to also deploy your program to the Stylus testnet. We can use the tool to first check +our program compiles to valid WASM for Stylus and will succeed a deployment onchain without transacting. By default, this will use the Stylus testnet public RPC endpoint. See here for [Stylus testnet information](https://docs.arbitrum.io/stylus/reference/testnet-information). + +```bash +cargo stylus check +``` + +Next, we deploy: + +```bash +cargo stylus deploy \ + --private-key-path= +``` diff --git a/example_code/applications/crowd_fund/rust-toolchain.toml b/example_code/applications/crowd_fund/rust-toolchain.toml new file mode 100644 index 0000000..dc2d42d --- /dev/null +++ b/example_code/applications/crowd_fund/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.80.0" \ No newline at end of file diff --git a/example_code/applications/crowd_fund/src/lib.rs b/example_code/applications/crowd_fund/src/lib.rs new file mode 100644 index 0000000..6bb6484 --- /dev/null +++ b/example_code/applications/crowd_fund/src/lib.rs @@ -0,0 +1,193 @@ +#![cfg_attr(not(feature = "export-abi"), no_main)] +extern crate alloc; +use alloy_sol_types::sol; + +use stylus_sdk::{alloy_primitives::{Address, U256}, block, call::Call, contract, evm, msg, prelude::*}; + + +sol_interface! { + interface IERC20 { + function transfer(address, uint256) external returns (bool); + function transferFrom(address, address, uint256) external returns (bool); + } +} + +sol!{ + event Launch( + uint256 id, + address indexed creator, + uint256 goal, + uint256 start_at, + uint256 end_at + ); + event Cancel(uint256 id); + event Pledge(uint256 indexed id, address indexed caller, uint256 amount); + event Unpledge(uint256 indexed id, address indexed caller, uint256 amount); + event Claim(uint256 id); + event Refund(uint256 id, address indexed caller, uint256 amount); +} + + +sol_storage! { + #[entrypoint] + pub struct CrowdFund{ + // Total count of campaigns created. + // It is also used to generate id for new campaigns. + uint256 count; + // The address of the NFT contract. + address token_address; + // Mapping from id to Campaign + CampaignStruct[] campaigns; // The transactions array + // Mapping from campaign id => pledger => amount pledged + mapping(uint256 => mapping(address => uint256)) pledged_amount; + } + pub struct CampaignStruct { + // Creator of campaign + address creator; + // Amount of tokens to raise + uint256 goal; + // Total amount pledged + uint256 pledged; + // Timestamp of start of campaign + uint256 start_at; + // Timestamp of end of campaign + uint256 end_at; + // True if goal was reached and creator has claimed the tokens. + bool claimed; + } + +} + +/// Declare that `CrowdFund` is a contract with the following external methods. +#[public] +impl CrowdFund { + pub const ONE_DAY: u64 = 86400; // 1 day = 24 hours * 60 minutes * 60 seconds = 86400 seconds. + + + pub fn launch(&mut self, goal: U256, start_at: U256, end_at: U256) { + assert!(start_at U256::from(block::timestamp() + 7 * Self::ONE_DAY)); + + let number = self.count.get(); + self.count.set(number+ U256::from(1)); + + let mut new_campaign = self.campaigns.grow(); + new_campaign.creator.set(msg::sender()); + new_campaign.goal.set(goal); + new_campaign.pledged.set(U256::from(0)); + new_campaign.start_at.set(start_at); + new_campaign.end_at.set(end_at); + new_campaign.claimed.set(false); + let number = U256::from(self.campaigns.len()); + evm::log(Launch { + id: number - U256::from(1), + creator: msg::sender(), + goal: goal, + start_at: start_at, + end_at:end_at + }); + } + pub fn cancel(&mut self, id: U256) { + if let Some(mut entry) = self.campaigns.get_mut(id) { + if entry.creator.get() == msg::sender() + && U256::from(block::timestamp()) > entry.start_at.get() { + entry.creator.set(Address::ZERO); + entry.goal.set(U256::from(0)); + entry.pledged.set(U256::from(0)); + entry.start_at.set(U256::from(0)); + entry.end_at.set(U256::from(0)); + entry.claimed.set(false); + evm::log(Cancel{id:id}); + } + } + } + pub fn pledge(&mut self, id: U256, amount: U256) { + if let Some(mut entry) = self.campaigns.get_mut(id) { + if U256::from(block::timestamp()) >= entry.start_at.get() + && U256::from(block::timestamp()) <= entry.end_at.get() { + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged + amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount + amount); + + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + } + } + + } + pub fn unpledge(&mut self, id: U256, amount: U256) { + if let Some(mut entry) = self.campaigns.get_mut(id) { + if U256::from(block::timestamp()) <= entry.end_at.get(){ + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged - amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount - amount); + // Token transfer + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + // Emit the log + evm::log(Unpledge {id: id, caller: msg::sender(), amount: amount}); + } + } + } + pub fn claim(&mut self, id: U256) { + // First mutable borrow to access campaigns and the entry + if let Some(mut entry) = self.campaigns.get_mut(id) { + let creator = entry.creator.get(); + let end_at = entry.end_at.get(); + let pledged = entry.pledged.get(); + let goal = entry.goal.get(); + let claimed = entry.claimed.get(); + + // Check conditions on the entry + if creator == msg::sender() + && U256::from(block::timestamp()) > end_at + && pledged >= goal + && !claimed + { + // Mark the entry as claimed + entry.claimed.set(true); + + // Now, perform the token transfer + let token_address = *self.token_address; + let token = IERC20::new(token_address); + + let config = Call::new_in(self); + token.transfer(config, creator, pledged).unwrap(); + evm::log(Claim{id:id}); + } + } + } + + pub fn refund(&mut self, id: U256) { + // First mutable borrow to access campaigns and the entry + if let Some(entry) = self.campaigns.get_mut(id) { + let end_at = entry.end_at.get(); + let goal = entry.goal.get(); + let pledged = entry.pledged.get(); + + if U256::from(block::timestamp()) > end_at + && pledged < goal { + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_balance = pledged_amount_sender.get(); + pledged_amount_sender.set(U256::from(0)); + let token_address = *self.token_address; + let token = IERC20::new(token_address); + + let config = Call::new_in(self); + token.transfer(config, msg::sender(), old_balance).unwrap(); + evm::log(Refund{id: id, caller: msg::sender(), amount: old_balance}); + + } + } + } +} \ No newline at end of file diff --git a/example_code/applications/crowd_fund/src/main.rs b/example_code/applications/crowd_fund/src/main.rs new file mode 100644 index 0000000..d83a330 --- /dev/null +++ b/example_code/applications/crowd_fund/src/main.rs @@ -0,0 +1,6 @@ +#![cfg_attr(not(feature = "export-abi"), no_main)] + +#[cfg(feature = "export-abi")] +fn main() { + stylus_crowd_fund::print_abi("MIT-OR-APACHE-2.0", "pragma solidity ^0.8.23;"); +} diff --git a/src/app/applications/crowd_fund/page.mdx b/src/app/applications/crowd_fund/page.mdx new file mode 100644 index 0000000..a553004 --- /dev/null +++ b/src/app/applications/crowd_fund/page.mdx @@ -0,0 +1,273 @@ +export const metadata = { + title: 'Crowd Fund • Stylus by Example', + description: 'An example implementation of the Crowd Fund in Rust using Arbitrum Stylus.', +}; + +{/* Begin Content */} + +# Crowd Fund + +An Arbitrum Stylus version implementation of [Solidity Crowd Fund](https://solidity-by-example.org/app/crowd-fund/). + +This is the logic of the contract: + +**For Campaign Creators:** + +- **Campaign Creation:** Initiate a crowdfunding campaign by specifying a funding goal and a deadline. +- **Fund Claiming:** If your campaign reaches or exceeds the funding goal by the deadline, you can claim the pledged tokens. + +**For Contributors:** + +- **Pledging Tokens:** Support campaigns by pledging your ERC20 tokens, which are transferred to the campaign's smart contract. +- **Withdrawal of Pledge:** If a campaign does not meet its funding goal, you can withdraw your pledged tokens after the campaign ends. + +Here is the interface for Crowd Fund. + +```solidity +// SPDX-License-Identifier: MIT-OR-APACHE-2.0 +pragma solidity ^0.8.23; + +interface ICrowdFund { + function launch(uint256 goal, uint256 start_at, uint256 end_at) external; + + function cancel(uint256 id) external; + + function pledge(uint256 id, uint256 amount) external; + + function unpledge(uint256 id, uint256 amount) external; + + function claim(uint256 id) external; + + function refund(uint256 id) external; +} +``` + +Example implementation of a Crowd Fund contract written in Rust. + +### src/lib.rs + +```rust +#![cfg_attr(not(feature = "export-abi"), no_main)] +extern crate alloc; +use alloy_sol_types::sol; + +use stylus_sdk::{alloy_primitives::{Address, U256}, block, call::Call, contract, evm, msg, prelude::*}; + + +sol_interface! { + interface IERC20 { + function transfer(address, uint256) external returns (bool); + function transferFrom(address, address, uint256) external returns (bool); + } +} + +sol!{ + event Launch( + uint256 id, + address indexed creator, + uint256 goal, + uint256 start_at, + uint256 end_at + ); + event Cancel(uint256 id); + event Pledge(uint256 indexed id, address indexed caller, uint256 amount); + event Unpledge(uint256 indexed id, address indexed caller, uint256 amount); + event Claim(uint256 id); + event Refund(uint256 id, address indexed caller, uint256 amount); +} + + +sol_storage! { + #[entrypoint] + pub struct CrowdFund{ + // Total count of campaigns created. + // It is also used to generate id for new campaigns. + uint256 count; + // The address of the NFT contract. + address token_address; + // Mapping from id to Campaign + CampaignStruct[] campaigns; // The transactions array + // Mapping from campaign id => pledger => amount pledged + mapping(uint256 => mapping(address => uint256)) pledged_amount; + } + pub struct CampaignStruct { + // Creator of campaign + address creator; + // Amount of tokens to raise + uint256 goal; + // Total amount pledged + uint256 pledged; + // Timestamp of start of campaign + uint256 start_at; + // Timestamp of end of campaign + uint256 end_at; + // True if goal was reached and creator has claimed the tokens. + bool claimed; + } + +} + +/// Declare that `CrowdFund` is a contract with the following external methods. +#[public] +impl CrowdFund { + pub const ONE_DAY: u64 = 86400; // 1 day = 24 hours * 60 minutes * 60 seconds = 86400 seconds. + + + pub fn launch(&mut self, goal: U256, start_at: U256, end_at: U256) { + assert!(start_at U256::from(block::timestamp() + 7 * Self::ONE_DAY)); + + let number = self.count.get(); + self.count.set(number+ U256::from(1)); + + let mut new_campaign = self.campaigns.grow(); + new_campaign.creator.set(msg::sender()); + new_campaign.goal.set(goal); + new_campaign.pledged.set(U256::from(0)); + new_campaign.start_at.set(start_at); + new_campaign.end_at.set(end_at); + new_campaign.claimed.set(false); + let number = U256::from(self.campaigns.len()); + evm::log(Launch { + id: number - U256::from(1), + creator: msg::sender(), + goal: goal, + start_at: start_at, + end_at:end_at + }); + } + pub fn cancel(&mut self, id: U256) { + if let Some(mut entry) = self.campaigns.get_mut(id) { + if entry.creator.get() == msg::sender() + && U256::from(block::timestamp()) > entry.start_at.get() { + entry.creator.set(Address::ZERO); + entry.goal.set(U256::from(0)); + entry.pledged.set(U256::from(0)); + entry.start_at.set(U256::from(0)); + entry.end_at.set(U256::from(0)); + entry.claimed.set(false); + evm::log(Cancel{id:id}); + } + } + } + pub fn pledge(&mut self, id: U256, amount: U256) { + if let Some(mut entry) = self.campaigns.get_mut(id) { + if U256::from(block::timestamp()) >= entry.start_at.get() + && U256::from(block::timestamp()) <= entry.end_at.get() { + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged + amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount + amount); + + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + } + } + + } + pub fn unpledge(&mut self, id: U256, amount: U256) { + if let Some(mut entry) = self.campaigns.get_mut(id) { + if U256::from(block::timestamp()) <= entry.end_at.get(){ + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged - amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount - amount); + // Token transfer + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + // Emit the log + evm::log(Unpledge {id: id, caller: msg::sender(), amount: amount}); + } + } + } + pub fn claim(&mut self, id: U256) { + // First mutable borrow to access campaigns and the entry + if let Some(mut entry) = self.campaigns.get_mut(id) { + let creator = entry.creator.get(); + let end_at = entry.end_at.get(); + let pledged = entry.pledged.get(); + let goal = entry.goal.get(); + let claimed = entry.claimed.get(); + + // Check conditions on the entry + if creator == msg::sender() + && U256::from(block::timestamp()) > end_at + && pledged >= goal + && !claimed + { + // Mark the entry as claimed + entry.claimed.set(true); + + // Now, perform the token transfer + let token_address = *self.token_address; + let token = IERC20::new(token_address); + + let config = Call::new_in(self); + token.transfer(config, creator, pledged).unwrap(); + evm::log(Claim{id:id}); + } + } + } + + pub fn refund(&mut self, id: U256) { + // First mutable borrow to access campaigns and the entry + if let Some(entry) = self.campaigns.get_mut(id) { + let end_at = entry.end_at.get(); + let goal = entry.goal.get(); + let pledged = entry.pledged.get(); + + if U256::from(block::timestamp()) > end_at + && pledged < goal { + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_balance = pledged_amount_sender.get(); + pledged_amount_sender.set(U256::from(0)); + let token_address = *self.token_address; + let token = IERC20::new(token_address); + + let config = Call::new_in(self); + token.transfer(config, msg::sender(), old_balance).unwrap(); + evm::log(Refund{id: id, caller: msg::sender(), amount: old_balance}); + + } + } + } +} +``` + +### Cargo.toml + +```toml +[package] +name = "stylus-crowd-fund" +version = "0.1.0" +edition = "2021" + +[dependencies] +alloy-primitives = "=0.7.6" +alloy-sol-types = "=0.7.6" +mini-alloc = "0.4.2" +stylus-sdk = "0.6.0" +hex = "0.4.3" + +[features] +export-abi = ["stylus-sdk/export-abi"] +debug = ["stylus-sdk/debug"] + +[lib] +crate-type = ["lib", "cdylib"] + +[profile.release] +codegen-units = 1 +strip = true +lto = true +panic = "abort" +opt-level = "s" +``` From 3e02de6f381f9000fc9abba9c1d072c790e06d9b Mon Sep 17 00:00:00 2001 From: GreatSoshiant <61604245+GreatSoshiant@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:23:05 -0700 Subject: [PATCH 2/6] Update routes.ts --- src/data/routes.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/data/routes.ts b/src/data/routes.ts index 5f3da20..66a41f6 100644 --- a/src/data/routes.ts +++ b/src/data/routes.ts @@ -157,4 +157,9 @@ export const applications = [ title: 'Vending Machine', description: 'An example implementation of the Vending Machine in Rust using Arbitrum Stylus.', }, + { + route: '/applications/crowd_fund', + title: 'Crowd Fund', + description: 'An example implementation of the Crowd Fund contract in Rust using Arbitrum Stylus.', + }, ]; From 038b900c652d7706628435615bf37156df9b8402 Mon Sep 17 00:00:00 2001 From: GreatSoshiant <61604245+GreatSoshiant@users.noreply.github.com> Date: Sun, 15 Sep 2024 17:26:37 -0700 Subject: [PATCH 3/6] format fixed --- .../applications/crowd_fund/src/lib.rs | 122 ++++++++++-------- src/app/applications/crowd_fund/page.mdx | 120 +++++++++-------- 2 files changed, 131 insertions(+), 111 deletions(-) diff --git a/example_code/applications/crowd_fund/src/lib.rs b/example_code/applications/crowd_fund/src/lib.rs index 6bb6484..900d7a1 100644 --- a/example_code/applications/crowd_fund/src/lib.rs +++ b/example_code/applications/crowd_fund/src/lib.rs @@ -2,8 +2,13 @@ extern crate alloc; use alloy_sol_types::sol; -use stylus_sdk::{alloy_primitives::{Address, U256}, block, call::Call, contract, evm, msg, prelude::*}; - +use stylus_sdk::{ + alloy_primitives::{Address, U256}, + block, + call::Call, + contract, evm, msg, + prelude::*, +}; sol_interface! { interface IERC20 { @@ -12,7 +17,7 @@ sol_interface! { } } -sol!{ +sol! { event Launch( uint256 id, address indexed creator, @@ -27,7 +32,6 @@ sol!{ event Refund(uint256 id, address indexed caller, uint256 amount); } - sol_storage! { #[entrypoint] pub struct CrowdFund{ @@ -35,7 +39,7 @@ sol_storage! { // It is also used to generate id for new campaigns. uint256 count; // The address of the NFT contract. - address token_address; + address token_address; // Mapping from id to Campaign CampaignStruct[] campaigns; // The transactions array // Mapping from campaign id => pledger => amount pledged @@ -63,14 +67,13 @@ sol_storage! { impl CrowdFund { pub const ONE_DAY: u64 = 86400; // 1 day = 24 hours * 60 minutes * 60 seconds = 86400 seconds. - pub fn launch(&mut self, goal: U256, start_at: U256, end_at: U256) { - assert!(start_at U256::from(block::timestamp() + 7 * Self::ONE_DAY)); let number = self.count.get(); - self.count.set(number+ U256::from(1)); + self.count.set(number + U256::from(1)); let mut new_campaign = self.campaigns.grow(); new_campaign.creator.set(msg::sender()); @@ -85,56 +88,61 @@ impl CrowdFund { creator: msg::sender(), goal: goal, start_at: start_at, - end_at:end_at + end_at: end_at, }); } pub fn cancel(&mut self, id: U256) { if let Some(mut entry) = self.campaigns.get_mut(id) { if entry.creator.get() == msg::sender() - && U256::from(block::timestamp()) > entry.start_at.get() { - entry.creator.set(Address::ZERO); - entry.goal.set(U256::from(0)); - entry.pledged.set(U256::from(0)); - entry.start_at.set(U256::from(0)); - entry.end_at.set(U256::from(0)); - entry.claimed.set(false); - evm::log(Cancel{id:id}); + && U256::from(block::timestamp()) > entry.start_at.get() + { + entry.creator.set(Address::ZERO); + entry.goal.set(U256::from(0)); + entry.pledged.set(U256::from(0)); + entry.start_at.set(U256::from(0)); + entry.end_at.set(U256::from(0)); + entry.claimed.set(false); + evm::log(Cancel { id: id }); } } } - pub fn pledge(&mut self, id: U256, amount: U256) { + pub fn pledge(&mut self, id: U256, amount: U256) { if let Some(mut entry) = self.campaigns.get_mut(id) { if U256::from(block::timestamp()) >= entry.start_at.get() - && U256::from(block::timestamp()) <= entry.end_at.get() { - let pledged = U256::from(entry.pledged.get()); - entry.pledged.set(pledged + amount); - let mut pledged_amount_info = self.pledged_amount.setter(id); - let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); - let old_amount = pledged_amount_sender.get(); - pledged_amount_sender.set(old_amount + amount); - - let token = IERC20::new(*self.token_address); - let config = Call::new_in(self); - token.transfer(config, contract::address(), amount).unwrap(); - } - } + && U256::from(block::timestamp()) <= entry.end_at.get() + { + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged + amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount + amount); + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + } + } } pub fn unpledge(&mut self, id: U256, amount: U256) { if let Some(mut entry) = self.campaigns.get_mut(id) { - if U256::from(block::timestamp()) <= entry.end_at.get(){ - let pledged = U256::from(entry.pledged.get()); - entry.pledged.set(pledged - amount); - let mut pledged_amount_info = self.pledged_amount.setter(id); - let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); - let old_amount = pledged_amount_sender.get(); - pledged_amount_sender.set(old_amount - amount); - // Token transfer - let token = IERC20::new(*self.token_address); - let config = Call::new_in(self); - token.transfer(config, contract::address(), amount).unwrap(); - // Emit the log - evm::log(Unpledge {id: id, caller: msg::sender(), amount: amount}); + if U256::from(block::timestamp()) <= entry.end_at.get() { + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged - amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount - amount); + // Token transfer + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + // Emit the log + evm::log(Unpledge { + id: id, + caller: msg::sender(), + amount: amount, + }); } } } @@ -146,7 +154,7 @@ impl CrowdFund { let pledged = entry.pledged.get(); let goal = entry.goal.get(); let claimed = entry.claimed.get(); - + // Check conditions on the entry if creator == msg::sender() && U256::from(block::timestamp()) > end_at @@ -155,14 +163,14 @@ impl CrowdFund { { // Mark the entry as claimed entry.claimed.set(true); - + // Now, perform the token transfer let token_address = *self.token_address; let token = IERC20::new(token_address); - + let config = Call::new_in(self); token.transfer(config, creator, pledged).unwrap(); - evm::log(Claim{id:id}); + evm::log(Claim { id: id }); } } } @@ -174,20 +182,22 @@ impl CrowdFund { let goal = entry.goal.get(); let pledged = entry.pledged.get(); - if U256::from(block::timestamp()) > end_at - && pledged < goal { + if U256::from(block::timestamp()) > end_at && pledged < goal { let mut pledged_amount_info = self.pledged_amount.setter(id); let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); let old_balance = pledged_amount_sender.get(); pledged_amount_sender.set(U256::from(0)); let token_address = *self.token_address; let token = IERC20::new(token_address); - + let config = Call::new_in(self); token.transfer(config, msg::sender(), old_balance).unwrap(); - evm::log(Refund{id: id, caller: msg::sender(), amount: old_balance}); - + evm::log(Refund { + id: id, + caller: msg::sender(), + amount: old_balance, + }); } } - } -} \ No newline at end of file + } +} diff --git a/src/app/applications/crowd_fund/page.mdx b/src/app/applications/crowd_fund/page.mdx index a553004..857a675 100644 --- a/src/app/applications/crowd_fund/page.mdx +++ b/src/app/applications/crowd_fund/page.mdx @@ -51,8 +51,13 @@ Example implementation of a Crowd Fund contract written in Rust. extern crate alloc; use alloy_sol_types::sol; -use stylus_sdk::{alloy_primitives::{Address, U256}, block, call::Call, contract, evm, msg, prelude::*}; - +use stylus_sdk::{ + alloy_primitives::{Address, U256}, + block, + call::Call, + contract, evm, msg, + prelude::*, +}; sol_interface! { interface IERC20 { @@ -61,7 +66,7 @@ sol_interface! { } } -sol!{ +sol! { event Launch( uint256 id, address indexed creator, @@ -76,7 +81,6 @@ sol!{ event Refund(uint256 id, address indexed caller, uint256 amount); } - sol_storage! { #[entrypoint] pub struct CrowdFund{ @@ -84,7 +88,7 @@ sol_storage! { // It is also used to generate id for new campaigns. uint256 count; // The address of the NFT contract. - address token_address; + address token_address; // Mapping from id to Campaign CampaignStruct[] campaigns; // The transactions array // Mapping from campaign id => pledger => amount pledged @@ -112,14 +116,13 @@ sol_storage! { impl CrowdFund { pub const ONE_DAY: u64 = 86400; // 1 day = 24 hours * 60 minutes * 60 seconds = 86400 seconds. - pub fn launch(&mut self, goal: U256, start_at: U256, end_at: U256) { - assert!(start_at U256::from(block::timestamp() + 7 * Self::ONE_DAY)); let number = self.count.get(); - self.count.set(number+ U256::from(1)); + self.count.set(number + U256::from(1)); let mut new_campaign = self.campaigns.grow(); new_campaign.creator.set(msg::sender()); @@ -134,56 +137,61 @@ impl CrowdFund { creator: msg::sender(), goal: goal, start_at: start_at, - end_at:end_at + end_at: end_at, }); } pub fn cancel(&mut self, id: U256) { if let Some(mut entry) = self.campaigns.get_mut(id) { if entry.creator.get() == msg::sender() - && U256::from(block::timestamp()) > entry.start_at.get() { - entry.creator.set(Address::ZERO); - entry.goal.set(U256::from(0)); - entry.pledged.set(U256::from(0)); - entry.start_at.set(U256::from(0)); - entry.end_at.set(U256::from(0)); - entry.claimed.set(false); - evm::log(Cancel{id:id}); + && U256::from(block::timestamp()) > entry.start_at.get() + { + entry.creator.set(Address::ZERO); + entry.goal.set(U256::from(0)); + entry.pledged.set(U256::from(0)); + entry.start_at.set(U256::from(0)); + entry.end_at.set(U256::from(0)); + entry.claimed.set(false); + evm::log(Cancel { id: id }); } } } - pub fn pledge(&mut self, id: U256, amount: U256) { + pub fn pledge(&mut self, id: U256, amount: U256) { if let Some(mut entry) = self.campaigns.get_mut(id) { if U256::from(block::timestamp()) >= entry.start_at.get() - && U256::from(block::timestamp()) <= entry.end_at.get() { - let pledged = U256::from(entry.pledged.get()); - entry.pledged.set(pledged + amount); - let mut pledged_amount_info = self.pledged_amount.setter(id); - let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); - let old_amount = pledged_amount_sender.get(); - pledged_amount_sender.set(old_amount + amount); - - let token = IERC20::new(*self.token_address); - let config = Call::new_in(self); - token.transfer(config, contract::address(), amount).unwrap(); - } - } + && U256::from(block::timestamp()) <= entry.end_at.get() + { + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged + amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount + amount); + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + } + } } pub fn unpledge(&mut self, id: U256, amount: U256) { if let Some(mut entry) = self.campaigns.get_mut(id) { - if U256::from(block::timestamp()) <= entry.end_at.get(){ - let pledged = U256::from(entry.pledged.get()); - entry.pledged.set(pledged - amount); - let mut pledged_amount_info = self.pledged_amount.setter(id); - let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); - let old_amount = pledged_amount_sender.get(); - pledged_amount_sender.set(old_amount - amount); - // Token transfer - let token = IERC20::new(*self.token_address); - let config = Call::new_in(self); - token.transfer(config, contract::address(), amount).unwrap(); - // Emit the log - evm::log(Unpledge {id: id, caller: msg::sender(), amount: amount}); + if U256::from(block::timestamp()) <= entry.end_at.get() { + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged - amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount - amount); + // Token transfer + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + // Emit the log + evm::log(Unpledge { + id: id, + caller: msg::sender(), + amount: amount, + }); } } } @@ -195,7 +203,7 @@ impl CrowdFund { let pledged = entry.pledged.get(); let goal = entry.goal.get(); let claimed = entry.claimed.get(); - + // Check conditions on the entry if creator == msg::sender() && U256::from(block::timestamp()) > end_at @@ -204,14 +212,14 @@ impl CrowdFund { { // Mark the entry as claimed entry.claimed.set(true); - + // Now, perform the token transfer let token_address = *self.token_address; let token = IERC20::new(token_address); - + let config = Call::new_in(self); token.transfer(config, creator, pledged).unwrap(); - evm::log(Claim{id:id}); + evm::log(Claim { id: id }); } } } @@ -223,22 +231,24 @@ impl CrowdFund { let goal = entry.goal.get(); let pledged = entry.pledged.get(); - if U256::from(block::timestamp()) > end_at - && pledged < goal { + if U256::from(block::timestamp()) > end_at && pledged < goal { let mut pledged_amount_info = self.pledged_amount.setter(id); let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); let old_balance = pledged_amount_sender.get(); pledged_amount_sender.set(U256::from(0)); let token_address = *self.token_address; let token = IERC20::new(token_address); - + let config = Call::new_in(self); token.transfer(config, msg::sender(), old_balance).unwrap(); - evm::log(Refund{id: id, caller: msg::sender(), amount: old_balance}); - + evm::log(Refund { + id: id, + caller: msg::sender(), + amount: old_balance, + }); } } - } + } } ``` From bb0b3912eaf930f4cff1acdf278648b675743453 Mon Sep 17 00:00:00 2001 From: GreatSoshiant <61604245+GreatSoshiant@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:06:04 -0700 Subject: [PATCH 4/6] changed asserts to errors --- .../applications/crowd_fund/src/lib.rs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/example_code/applications/crowd_fund/src/lib.rs b/example_code/applications/crowd_fund/src/lib.rs index 900d7a1..41a1046 100644 --- a/example_code/applications/crowd_fund/src/lib.rs +++ b/example_code/applications/crowd_fund/src/lib.rs @@ -18,6 +18,10 @@ sol_interface! { } sol! { + error NotStarted(); + error StartGreaterThanEnd(); + error EndGreaterThanMaxDuration(); + event Launch( uint256 id, address indexed creator, @@ -32,6 +36,13 @@ sol! { event Refund(uint256 id, address indexed caller, uint256 amount); } +#[derive(SolidityError)] +pub enum CrowdFundErrors { + NotStarted(NotStarted), + StartGreaterThanEnd(StartGreaterThanEnd), + EndGreaterThanMaxDuration(EndGreaterThanMaxDuration), +} + sol_storage! { #[entrypoint] pub struct CrowdFund{ @@ -67,10 +78,16 @@ sol_storage! { impl CrowdFund { pub const ONE_DAY: u64 = 86400; // 1 day = 24 hours * 60 minutes * 60 seconds = 86400 seconds. - pub fn launch(&mut self, goal: U256, start_at: U256, end_at: U256) { - assert!(start_at < U256::from(block::timestamp())); - assert!(end_at < start_at); - assert!(end_at > U256::from(block::timestamp() + 7 * Self::ONE_DAY)); + pub fn launch(&mut self, goal: U256, start_at: U256, end_at: U256) -> Result<(), CrowdFundErrors> { + if start_at < U256::from(block::timestamp()) { + return Err(CrowdFundErrors::NotStarted(NotStarted {})); + } + if end_at < start_at{ + return Err(CrowdFundErrors::StartGreaterThanEnd(StartGreaterThanEnd {})); + } + if end_at > U256::from(block::timestamp() + 7 * Self::ONE_DAY) { + return Err(CrowdFundErrors::EndGreaterThanMaxDuration(EndGreaterThanMaxDuration {})); + } let number = self.count.get(); self.count.set(number + U256::from(1)); @@ -90,6 +107,7 @@ impl CrowdFund { start_at: start_at, end_at: end_at, }); + Ok(()) } pub fn cancel(&mut self, id: U256) { if let Some(mut entry) = self.campaigns.get_mut(id) { From 5facd11e12398e0c4fe9bc4d49e2eabe0e457288 Mon Sep 17 00:00:00 2001 From: GreatSoshiant <61604245+GreatSoshiant@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:16:54 -0700 Subject: [PATCH 5/6] new errors added --- example_code/applications/crowd_fund/src/lib.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/example_code/applications/crowd_fund/src/lib.rs b/example_code/applications/crowd_fund/src/lib.rs index 41a1046..583d8e1 100644 --- a/example_code/applications/crowd_fund/src/lib.rs +++ b/example_code/applications/crowd_fund/src/lib.rs @@ -19,8 +19,14 @@ sol_interface! { sol! { error NotStarted(); + error NotEnded(); + error AlreadyEnded(); error StartGreaterThanEnd(); error EndGreaterThanMaxDuration(); + error SenderIsNotCreator(); + error AlreadyClaimed(); + error GoalNotReached(); + error GoalReached(); event Launch( uint256 id, @@ -39,8 +45,14 @@ sol! { #[derive(SolidityError)] pub enum CrowdFundErrors { NotStarted(NotStarted), + NotEnded(NotEnded), + AlreadyEnded(AlreadyEnded), StartGreaterThanEnd(StartGreaterThanEnd), EndGreaterThanMaxDuration(EndGreaterThanMaxDuration), + SenderIsNotCreator(SenderIsNotCreator), + GoalNotReached(GoalNotReached), + GoalReached(GoalReached), + } sol_storage! { @@ -88,7 +100,6 @@ impl CrowdFund { if end_at > U256::from(block::timestamp() + 7 * Self::ONE_DAY) { return Err(CrowdFundErrors::EndGreaterThanMaxDuration(EndGreaterThanMaxDuration {})); } - let number = self.count.get(); self.count.set(number + U256::from(1)); From c97a9b87efc10b4178dd6f62c1f9f04b4a4fc450 Mon Sep 17 00:00:00 2001 From: GreatSoshiant <61604245+GreatSoshiant@users.noreply.github.com> Date: Thu, 26 Sep 2024 10:48:50 -0700 Subject: [PATCH 6/6] added all errors --- .../applications/crowd_fund/src/lib.rs | 178 ++++++++++-------- 1 file changed, 101 insertions(+), 77 deletions(-) diff --git a/example_code/applications/crowd_fund/src/lib.rs b/example_code/applications/crowd_fund/src/lib.rs index 583d8e1..8eef823 100644 --- a/example_code/applications/crowd_fund/src/lib.rs +++ b/example_code/applications/crowd_fund/src/lib.rs @@ -18,6 +18,7 @@ sol_interface! { } sol! { + error StartTimePassed(); error NotStarted(); error NotEnded(); error AlreadyEnded(); @@ -27,7 +28,7 @@ sol! { error AlreadyClaimed(); error GoalNotReached(); error GoalReached(); - + event Launch( uint256 id, address indexed creator, @@ -44,6 +45,7 @@ sol! { #[derive(SolidityError)] pub enum CrowdFundErrors { + StartTimePassed(StartTimePassed), NotStarted(NotStarted), NotEnded(NotEnded), AlreadyEnded(AlreadyEnded), @@ -52,6 +54,7 @@ pub enum CrowdFundErrors { SenderIsNotCreator(SenderIsNotCreator), GoalNotReached(GoalNotReached), GoalReached(GoalReached), + AlreadyClaimed(AlreadyClaimed) } @@ -92,7 +95,7 @@ impl CrowdFund { pub fn launch(&mut self, goal: U256, start_at: U256, end_at: U256) -> Result<(), CrowdFundErrors> { if start_at < U256::from(block::timestamp()) { - return Err(CrowdFundErrors::NotStarted(NotStarted {})); + return Err(CrowdFundErrors::StartTimePassed(StartTimePassed {})); } if end_at < start_at{ return Err(CrowdFundErrors::StartGreaterThanEnd(StartGreaterThanEnd {})); @@ -120,62 +123,70 @@ impl CrowdFund { }); Ok(()) } - pub fn cancel(&mut self, id: U256) { + pub fn cancel(&mut self, id: U256) -> Result<(), CrowdFundErrors> { if let Some(mut entry) = self.campaigns.get_mut(id) { - if entry.creator.get() == msg::sender() - && U256::from(block::timestamp()) > entry.start_at.get() - { - entry.creator.set(Address::ZERO); - entry.goal.set(U256::from(0)); - entry.pledged.set(U256::from(0)); - entry.start_at.set(U256::from(0)); - entry.end_at.set(U256::from(0)); - entry.claimed.set(false); - evm::log(Cancel { id: id }); + if entry.creator.get() != msg::sender() { + return Err(CrowdFundErrors::SenderIsNotCreator(SenderIsNotCreator {})); + } + if U256::from(block::timestamp()) < entry.start_at.get() { + return Err(CrowdFundErrors::NotStarted(NotStarted {})); } + entry.creator.set(Address::ZERO); + entry.goal.set(U256::from(0)); + entry.pledged.set(U256::from(0)); + entry.start_at.set(U256::from(0)); + entry.end_at.set(U256::from(0)); + entry.claimed.set(false); + evm::log(Cancel { id: id }); } + Ok(()) } - pub fn pledge(&mut self, id: U256, amount: U256) { + pub fn pledge(&mut self, id: U256, amount: U256) -> Result<(), CrowdFundErrors> { if let Some(mut entry) = self.campaigns.get_mut(id) { - if U256::from(block::timestamp()) >= entry.start_at.get() - && U256::from(block::timestamp()) <= entry.end_at.get() - { - let pledged = U256::from(entry.pledged.get()); - entry.pledged.set(pledged + amount); - let mut pledged_amount_info = self.pledged_amount.setter(id); - let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); - let old_amount = pledged_amount_sender.get(); - pledged_amount_sender.set(old_amount + amount); - - let token = IERC20::new(*self.token_address); - let config = Call::new_in(self); - token.transfer(config, contract::address(), amount).unwrap(); + if U256::from(block::timestamp()) < entry.start_at.get() { + return Err(CrowdFundErrors::NotStarted(NotStarted {})); + } + if U256::from(block::timestamp()) > entry.end_at.get() { + return Err(CrowdFundErrors::AlreadyEnded(AlreadyEnded {})); } + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged + amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount + amount); + + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); } + Ok(()) } - pub fn unpledge(&mut self, id: U256, amount: U256) { + pub fn unpledge(&mut self, id: U256, amount: U256) -> Result<(), CrowdFundErrors> { if let Some(mut entry) = self.campaigns.get_mut(id) { - if U256::from(block::timestamp()) <= entry.end_at.get() { - let pledged = U256::from(entry.pledged.get()); - entry.pledged.set(pledged - amount); - let mut pledged_amount_info = self.pledged_amount.setter(id); - let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); - let old_amount = pledged_amount_sender.get(); - pledged_amount_sender.set(old_amount - amount); - // Token transfer - let token = IERC20::new(*self.token_address); - let config = Call::new_in(self); - token.transfer(config, contract::address(), amount).unwrap(); - // Emit the log - evm::log(Unpledge { - id: id, - caller: msg::sender(), - amount: amount, - }); + if U256::from(block::timestamp()) > entry.end_at.get() { + return Err(CrowdFundErrors::AlreadyEnded(AlreadyEnded {})); } + let pledged = U256::from(entry.pledged.get()); + entry.pledged.set(pledged - amount); + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_amount = pledged_amount_sender.get(); + pledged_amount_sender.set(old_amount - amount); + // Token transfer + let token = IERC20::new(*self.token_address); + let config = Call::new_in(self); + token.transfer(config, contract::address(), amount).unwrap(); + // Emit the log + evm::log(Unpledge { + id: id, + caller: msg::sender(), + amount: amount, + }); } + Ok(()) } - pub fn claim(&mut self, id: U256) { + pub fn claim(&mut self, id: U256) -> Result<(), CrowdFundErrors> { // First mutable borrow to access campaigns and the entry if let Some(mut entry) = self.campaigns.get_mut(id) { let creator = entry.creator.get(); @@ -185,48 +196,61 @@ impl CrowdFund { let claimed = entry.claimed.get(); // Check conditions on the entry - if creator == msg::sender() - && U256::from(block::timestamp()) > end_at - && pledged >= goal - && !claimed - { - // Mark the entry as claimed - entry.claimed.set(true); - - // Now, perform the token transfer - let token_address = *self.token_address; - let token = IERC20::new(token_address); - - let config = Call::new_in(self); - token.transfer(config, creator, pledged).unwrap(); - evm::log(Claim { id: id }); + if creator != msg::sender() { + return Err(CrowdFundErrors::SenderIsNotCreator(SenderIsNotCreator {})); + } + if U256::from(block::timestamp()) < end_at { + return Err(CrowdFundErrors::NotEnded(NotEnded {})); } + if pledged < goal { + return Err(CrowdFundErrors::GoalNotReached(GoalNotReached {})); + + } + if claimed { + return Err(CrowdFundErrors::AlreadyClaimed(AlreadyClaimed {})); + } + // Mark the entry as claimed + entry.claimed.set(true); + + // Now, perform the token transfer + let token_address = *self.token_address; + let token = IERC20::new(token_address); + + let config = Call::new_in(self); + token.transfer(config, creator, pledged).unwrap(); + evm::log(Claim { id: id }); } + Ok(()) } - pub fn refund(&mut self, id: U256) { + pub fn refund(&mut self, id: U256) -> Result<(), CrowdFundErrors> { // First mutable borrow to access campaigns and the entry if let Some(entry) = self.campaigns.get_mut(id) { let end_at = entry.end_at.get(); let goal = entry.goal.get(); let pledged = entry.pledged.get(); - if U256::from(block::timestamp()) > end_at && pledged < goal { - let mut pledged_amount_info = self.pledged_amount.setter(id); - let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); - let old_balance = pledged_amount_sender.get(); - pledged_amount_sender.set(U256::from(0)); - let token_address = *self.token_address; - let token = IERC20::new(token_address); - - let config = Call::new_in(self); - token.transfer(config, msg::sender(), old_balance).unwrap(); - evm::log(Refund { - id: id, - caller: msg::sender(), - amount: old_balance, - }); + if U256::from(block::timestamp()) <= end_at { + return Err(CrowdFundErrors::NotEnded(NotEnded {})); + } + if pledged >= goal { + return Err(CrowdFundErrors::GoalReached(GoalReached {})); } + let mut pledged_amount_info = self.pledged_amount.setter(id); + let mut pledged_amount_sender = pledged_amount_info.setter(msg::sender()); + let old_balance = pledged_amount_sender.get(); + pledged_amount_sender.set(U256::from(0)); + let token_address = *self.token_address; + let token = IERC20::new(token_address); + + let config = Call::new_in(self); + token.transfer(config, msg::sender(), old_balance).unwrap(); + evm::log(Refund { + id: id, + caller: msg::sender(), + amount: old_balance, + }); } + Ok(()) } }