diff --git a/.cargo/config.toml b/.cargo/config.toml index 81cb1ef..afb374a 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,7 +1,7 @@ # paths = ["/path/to/override"] # path dependency overrides [alias] # command aliases -install_soroban = "install --git https://github.com/stellar/soroban-tools --rev 2b343d3e6afdb5eff54fb03622627cd55e785358 --root ./target soroban-cli --debug" +install_soroban = "install --git https://github.com/stellar/soroban-tools --rev af4b38e8fa7f6cb027089471d0ddfbc090cbf60e --root ./target soroban-cli --debug" b = "build --target wasm32-unknown-unknown --release" # c = "check" # t = "test" diff --git a/Cargo.lock b/Cargo.lock index 876b350..9094998 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,6 +64,12 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base32" version = "0.4.0" @@ -82,6 +88,12 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + [[package]] name = "block-buffer" version = "0.9.0" @@ -91,6 +103,15 @@ dependencies = [ "generic-array", ] +[[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 = "bumpalo" version = "3.12.1" @@ -150,6 +171,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "const-oid" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "795bc6e66a8e340f075fcf6227e417a2dc976b92b91f3cdc778bb858778b6747" + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -167,24 +194,56 @@ dependencies = [ [[package]] name = "crate-git-revision" -version = "0.0.4" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f998aef136a4e7833b0e4f0fc0939a59c40140b28e0ffbf524ad84fb2cc568c8" +checksum = "c521bf1f43d31ed2f73441775ed31935d77901cb3451e44b38a1c1612fcbaf98" dependencies = [ "serde", "serde_derive", "serde_json", ] +[[package]] +name = "crypto-bigint" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" +dependencies = [ + "generic-array", + "rand_core 0.6.4", + "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 = "ctor" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f34ba9a9bcb8645379e9de8cb3ecfcf4d1c85ba66d90deb3259206fa5aa193b" +dependencies = [ + "quote", + "syn 2.0.15", +] + [[package]] name = "curve25519-dalek" -version = "3.2.1" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", - "digest", - "rand_core", + "digest 0.9.0", + "rand_core 0.5.1", "subtle", "zeroize", ] @@ -268,6 +327,16 @@ dependencies = [ "syn 2.0.15", ] +[[package]] +name = "der" +version = "0.7.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c7ed52955ce76b1554f509074bb357d3fb8ac9b51288a65a3fd480d1dfba946" +dependencies = [ + "const-oid", + "zeroize", +] + [[package]] name = "derive_arbitrary" version = "1.3.0" @@ -288,6 +357,18 @@ 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 0.10.4", + "const-oid", + "crypto-common", + "subtle", +] + [[package]] name = "downcast-rs" version = "1.2.0" @@ -295,10 +376,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] -name = "dyn-fmt" -version = "0.3.0" +name = "ecdsa" +version = "0.16.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a0836c9bd73a9d3ca55b0effc5b1eedf96dd13ef994389bcac6d4d33c46188" +checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" +dependencies = [ + "der", + "digest 0.10.7", + "elliptic-curve", + "rfc6979", + "signature 2.1.0", + "spki", +] [[package]] name = "ed25519" @@ -306,7 +395,7 @@ version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" dependencies = [ - "signature", + "signature 1.6.4", ] [[package]] @@ -319,7 +408,7 @@ dependencies = [ "ed25519", "rand", "serde", - "sha2", + "sha2 0.9.9", "zeroize", ] @@ -329,12 +418,41 @@ version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +[[package]] +name = "elliptic-curve" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" +dependencies = [ + "base16ct", + "crypto-bigint", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + [[package]] name = "ethnum" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0198b9d0078e0f30dedc7acbb21c974e838fc8fae3ee170128658a98cb2c1c04" +[[package]] +name = "ff" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" +dependencies = [ + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "fnv" version = "1.0.7" @@ -349,6 +467,7 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] @@ -359,7 +478,20 @@ checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ "cfg-if", "libc", - "wasi", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", + "wasm-bindgen", ] [[package]] @@ -368,6 +500,17 @@ version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" +[[package]] +name = "group" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -383,6 +526,15 @@ dependencies = [ "serde", ] +[[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 = "iana-time-zone" version = "0.1.56" @@ -430,6 +582,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e04e2fd2b8188ea827b32ef11de88377086d690286ab35747ef7f9bf3ccb590" +[[package]] +name = "intx" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f38a50a899dc47a6d0ed5508e7f601a2e34c3a85303514b5d137f3c10a0c75" + [[package]] name = "itertools" version = "0.10.5" @@ -454,11 +612,34 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "k256" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "once_cell", + "sha2 0.10.7", + "signature 2.1.0", +] + +[[package]] +name = "keccak" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" +dependencies = [ + "cpufeatures", +] + [[package]] name = "libc" -version = "0.2.142" +version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" +checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" [[package]] name = "libm" @@ -490,12 +671,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memory_units" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" - [[package]] name = "miniz_oxide" version = "0.6.2" @@ -537,18 +712,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-rational" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" -dependencies = [ - "autocfg", - "num-bigint", - "num-integer", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.15" @@ -579,6 +742,22 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +[[package]] +name = "paste" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4b27ab7be369122c218afc2079489cdcb4b517c0a3fc386ff11e1fedfcc2b35" + +[[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" @@ -619,10 +798,10 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ - "getrandom", + "getrandom 0.1.16", "libc", "rand_chacha", - "rand_core", + "rand_core 0.5.1", "rand_hc", ] @@ -633,7 +812,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.5.1", ] [[package]] @@ -642,7 +821,16 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" dependencies = [ - "getrandom", + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom 0.2.10", ] [[package]] @@ -651,7 +839,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core", + "rand_core 0.5.1", +] + +[[package]] +name = "rfc6979" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" +dependencies = [ + "hmac", + "subtle", ] [[package]] @@ -660,6 +858,15 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + [[package]] name = "ryu" version = "1.0.13" @@ -672,6 +879,26 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" +[[package]] +name = "sec1" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0aec48e813d6b90b15f0b8948af3c63483992dee44c03e9930b3eebdabe046e" +dependencies = [ + "base16ct", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + [[package]] name = "serde" version = "1.0.162" @@ -737,19 +964,56 @@ version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ - "block-buffer", + "block-buffer 0.9.0", "cfg-if", "cpufeatures", - "digest", + "digest 0.9.0", "opaque-debug", ] +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if", + "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 = "signature" version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +[[package]] +name = "signature" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +dependencies = [ + "digest 0.10.7", + "rand_core 0.6.4", +] + +[[package]] +name = "smallvec" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb4feee49fdd9f707ef802e22365a35de4b7b299de4763d44bfea899442ff9" + [[package]] name = "soroban-crowdfund-contract" version = "0.0.0" @@ -760,13 +1024,16 @@ dependencies = [ [[package]] name = "soroban-env-common" -version = "0.0.16" +version = "0.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23eb21436bbc1680826a5b6b34a68ac25738ef064fcf6895b2621107d7711d30" +checksum = "52e28d297d1172c2a020660728ac24ca3af7118de85ad547d071f96221111dfb" dependencies = [ "arbitrary", "crate-git-revision", "ethnum", + "num-derive", + "num-integer", + "num-traits", "serde", "soroban-env-macros", "soroban-wasmi", @@ -776,9 +1043,9 @@ dependencies = [ [[package]] name = "soroban-env-guest" -version = "0.0.16" +version = "0.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5045712766e347b81acedaa8479a2d8faf37df399fc99c33ea68e3d061e1b301" +checksum = "8fbccdce4f74778cfe79e6ca8b6df2d094237d0bedf4aa167a73bfdaa7388fed" dependencies = [ "soroban-env-common", "static_assertions", @@ -786,32 +1053,36 @@ dependencies = [ [[package]] name = "soroban-env-host" -version = "0.0.16" +version = "0.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37f063c2a7e6609316eafd059ef4d52a10abdc72fdfbb608e5c0ee369f23f830" +checksum = "35eef83232686c48fc8c8bfc560ee2e065bdd18ac31da8cb570e93f3fd78fea0" dependencies = [ "backtrace", "curve25519-dalek", - "dyn-fmt", "ed25519-dalek", + "getrandom 0.2.10", "hex", + "k256", "log", "num-derive", "num-integer", "num-traits", - "sha2", + "rand", + "rand_chacha", + "sha2 0.9.9", + "sha3", "soroban-env-common", "soroban-native-sdk-macros", "soroban-wasmi", "static_assertions", - "tinyvec", + "stellar-strkey", ] [[package]] name = "soroban-env-macros" -version = "0.0.16" +version = "0.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "742a9f18064694890c8e1650d8c878e2b4b3d48d9d40732dc6caf7923d30c58f" +checksum = "97fcab4ca9be166587dd84939576634f2f7bccf213fe9f6aced9561ab4238be1" dependencies = [ "itertools", "proc-macro2", @@ -825,21 +1096,22 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "0.8.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78951e3924b3207227dbe9a303d2a7a2b96caa99a359d845dc8aaf9814c4addf" +checksum = "c379a73e5d14b0b9ba41157161c5362427a2ca75c936d1b737d41bca91ef252f" dependencies = [ "serde", "serde_json", + "soroban-env-common", "soroban-env-host", "thiserror", ] [[package]] name = "soroban-native-sdk-macros" -version = "0.0.16" +version = "0.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b52a3192c10a0d1b2b4bf33fe741cd2667065e412289e2dc455cd7bc747fec1a" +checksum = "6d891b456b0f6897ccbb8b67388ed7ce921fd47d19ff3ae8d8b1edca08339639" dependencies = [ "itertools", "proc-macro2", @@ -849,11 +1121,13 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "0.8.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cbc4bf0b3d99d061144105800ed337aa79040a375079ca2f39394c31e3d3857" +checksum = "f1cf449f8c53d905ac41d4c264442f26aa559d4a0ef451569a7739bd4d747595" dependencies = [ + "arbitrary", "bytes-lit", + "ctor", "ed25519-dalek", "rand", "soroban-env-guest", @@ -865,82 +1139,91 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "0.8.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a84443356be3560cd18c17e16f5595e21616e13f06d1e5404a657463b185c8b2" +checksum = "9b7ab0a02c265c41a44311e3e6271e0fccd518bda0c8383c7ff8aee478541d3b" dependencies = [ + "crate-git-revision", "darling", "itertools", "proc-macro2", "quote", - "sha2", + "rustc_version", + "sha2 0.9.9", "soroban-env-common", "soroban-spec", + "soroban-spec-rust", "stellar-xdr", "syn 2.0.15", ] [[package]] name = "soroban-spec" -version = "0.8.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95f7dadfc0e10726757d8c939d3b8436a610db1e985a4b414293fe92ac147899" +checksum = "adfd732ef1613e5ec919410fddd842d8cb804effb63c43acbf5ec6d77e6d0633" dependencies = [ "base64 0.13.1", - "darling", - "itertools", + "stellar-xdr", + "thiserror", + "wasmparser", +] + +[[package]] +name = "soroban-spec-rust" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fde0592863f1f34c1eff8bdbe35a6557adb6abadfc57804217fe035bec7421ef" +dependencies = [ "prettyplease", "proc-macro2", "quote", - "serde", - "serde_derive", - "serde_json", - "sha2", + "sha2 0.9.9", + "soroban-spec", "stellar-xdr", "syn 2.0.15", "thiserror", - "wasmparser", ] [[package]] name = "soroban-token-sdk" -version = "0.8.4" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49ae7d31ee22fc39b19d8b76bcf4e2b05b238839bcae871007c9d42d894ef512" +checksum = "38fabcf7f14b0a9b471d1663d3b29e32ca374a86dc8da6fe6536b5d3842def45" dependencies = [ "soroban-sdk", ] [[package]] name = "soroban-wasmi" -version = "0.16.0-soroban2" +version = "0.30.0-soroban" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc5dca8b60607a73948635d1b47f01986ca5b5a18c1a7ec22f6fda8a400dd360" +checksum = "c193640a103c4fc81163feca877bbea234dc20150015428ecc4e010f025f82bf" dependencies = [ - "soroban-wasmi_core", + "intx", + "smallvec", "spin", + "wasmi_arena", + "wasmi_core", "wasmparser-nostd", ] -[[package]] -name = "soroban-wasmi_core" -version = "0.16.0-soroban2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58caebfe0ad5e6d35c72f4894188d2ef9d6b01a6b67dadda2baf5700a322e453" -dependencies = [ - "downcast-rs", - "libm", - "memory_units", - "num-rational", - "num-traits", -] - [[package]] name = "spin" version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" +[[package]] +name = "spki" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +dependencies = [ + "base64ct", + "der", +] + [[package]] name = "static_assertions" version = "1.1.0" @@ -959,9 +1242,9 @@ dependencies = [ [[package]] name = "stellar-xdr" -version = "0.0.16" +version = "0.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b56b7f7c22e8458c49ee92918e2f733ff78f014fc1800cbb55b7e6a90a1201a5" +checksum = "ae197b4edde8835ab0ba018f1b5cdab0c47d0f28848f3f75d2951a1c9c7cdb48" dependencies = [ "arbitrary", "base64 0.13.1", @@ -1061,21 +1344,6 @@ dependencies = [ "time-core", ] -[[package]] -name = "tinyvec" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" -dependencies = [ - "tinyvec_macros", -] - -[[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - [[package]] name = "typenum" version = "1.16.0" @@ -1106,6 +1374,12 @@ version = "0.9.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + [[package]] name = "wasm-bindgen" version = "0.2.84" @@ -1160,6 +1434,24 @@ version = "0.2.84" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +[[package]] +name = "wasmi_arena" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "401c1f35e413fac1846d4843745589d9ec678977ab35a384db8ae7830525d468" + +[[package]] +name = "wasmi_core" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624e6333e861ef49095d2d678b76ebf30b06bf37effca845be7e5b87c90071b7" +dependencies = [ + "downcast-rs", + "libm", + "num-traits", + "paste", +] + [[package]] name = "wasmparser" version = "0.88.0" @@ -1171,9 +1463,9 @@ dependencies = [ [[package]] name = "wasmparser-nostd" -version = "0.90.0" +version = "0.100.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92a94fbf4c521b038f41382df2056cf47099d3b7a0faa5a6e46f7771fd7c84a6" +checksum = "9157cab83003221bfd385833ab587a039f5d6fa7304854042ba358a3b09e0724" dependencies = [ "indexmap-nostd", ] @@ -1277,9 +1569,9 @@ checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" [[package]] name = "zeroize" -version = "1.3.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" dependencies = [ "zeroize_derive", ] diff --git a/Cargo.toml b/Cargo.toml index 1c6be9a..3106b42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,5 @@ codegen-units = 1 lto = true [workspace.dependencies] -soroban-sdk = "0.8.4" -soroban-token-sdk = "0.8.4" +soroban-sdk = "0.9.2" +soroban-token-sdk = "0.9.2" diff --git a/Makefile b/Makefile index 3919581..9ed9215 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ build-optimized: fmt done build-docker: - docker build . --tag soroban-preview:9 + docker build . --tag soroban-preview:10 check: fmt cargo clippy --all-targets diff --git a/contracts/abundance/src/admin.rs b/contracts/abundance/src/admin.rs index 613bb50..a820bf0 100644 --- a/contracts/abundance/src/admin.rs +++ b/contracts/abundance/src/admin.rs @@ -1,17 +1,18 @@ -use crate::storage_types::DataKey; use soroban_sdk::{Address, Env}; +use crate::storage_types::DataKey; + pub fn has_administrator(e: &Env) -> bool { let key = DataKey::Admin; - e.storage().has(&key) + e.storage().instance().has(&key) } pub fn read_administrator(e: &Env) -> Address { let key = DataKey::Admin; - e.storage().get_unchecked(&key).unwrap() + e.storage().instance().get(&key).unwrap() } pub fn write_administrator(e: &Env, id: &Address) { let key = DataKey::Admin; - e.storage().set(&key, id); + e.storage().instance().set(&key, id); } diff --git a/contracts/abundance/src/allowance.rs b/contracts/abundance/src/allowance.rs index 2fad6e5..86d21cd 100644 --- a/contracts/abundance/src/allowance.rs +++ b/contracts/abundance/src/allowance.rs @@ -1,24 +1,64 @@ -use crate::storage_types::{AllowanceDataKey, DataKey}; +use crate::storage_types::{AllowanceDataKey, AllowanceValue, DataKey}; use soroban_sdk::{Address, Env}; -pub fn read_allowance(e: &Env, from: Address, spender: Address) -> i128 { +pub fn read_allowance(e: &Env, from: Address, spender: Address) -> AllowanceValue { let key = DataKey::Allowance(AllowanceDataKey { from, spender }); - if let Some(allowance) = e.storage().get(&key) { - allowance.unwrap() + if let Some(allowance) = e.storage().temporary().get::<_, AllowanceValue>(&key) { + if allowance.expiration_ledger < e.ledger().sequence() { + AllowanceValue { + amount: 0, + expiration_ledger: allowance.expiration_ledger, + } + } else { + allowance + } } else { - 0 + AllowanceValue { + amount: 0, + expiration_ledger: 0, + } } } -pub fn write_allowance(e: &Env, from: Address, spender: Address, amount: i128) { +pub fn write_allowance( + e: &Env, + from: Address, + spender: Address, + amount: i128, + expiration_ledger: u32, +) { + let allowance = AllowanceValue { + amount, + expiration_ledger, + }; + + if amount > 0 && expiration_ledger < e.ledger().sequence() { + panic!("expiration_ledger is less than ledger seq when amount > 0") + } + let key = DataKey::Allowance(AllowanceDataKey { from, spender }); - e.storage().set(&key, &amount); + e.storage().temporary().set(&key.clone(), &allowance); + + if amount > 0 { + e.storage().temporary().bump( + &key, + expiration_ledger + .checked_sub(e.ledger().sequence()) + .unwrap(), + ) + } } pub fn spend_allowance(e: &Env, from: Address, spender: Address, amount: i128) { let allowance = read_allowance(e, from.clone(), spender.clone()); - if allowance < amount { + if allowance.amount < amount { panic!("insufficient allowance"); } - write_allowance(e, from, spender, allowance - amount); + write_allowance( + e, + from, + spender, + allowance.amount - amount, + allowance.expiration_ledger, + ); } diff --git a/contracts/abundance/src/balance.rs b/contracts/abundance/src/balance.rs index fe9791c..06b17d6 100644 --- a/contracts/abundance/src/balance.rs +++ b/contracts/abundance/src/balance.rs @@ -1,10 +1,11 @@ -use crate::storage_types::DataKey; +use crate::storage_types::{DataKey, BALANCE_BUMP_AMOUNT}; use soroban_sdk::{Address, Env}; pub fn read_balance(e: &Env, addr: Address) -> i128 { let key = DataKey::Balance(addr); - if let Some(balance) = e.storage().get(&key) { - balance.unwrap() + if let Some(balance) = e.storage().persistent().get::(&key) { + e.storage().persistent().bump(&key, BALANCE_BUMP_AMOUNT); + balance } else { 0 } @@ -12,7 +13,8 @@ pub fn read_balance(e: &Env, addr: Address) -> i128 { fn write_balance(e: &Env, addr: Address, amount: i128) { let key = DataKey::Balance(addr); - e.storage().set(&key, &amount); + e.storage().persistent().set(&key, &amount); + e.storage().persistent().bump(&key, BALANCE_BUMP_AMOUNT); } pub fn receive_balance(e: &Env, addr: Address, amount: i128) { @@ -36,8 +38,8 @@ pub fn spend_balance(e: &Env, addr: Address, amount: i128) { pub fn is_authorized(e: &Env, addr: Address) -> bool { let key = DataKey::State(addr); - if let Some(state) = e.storage().get(&key) { - state.unwrap() + if let Some(state) = e.storage().persistent().get::(&key) { + state } else { true } @@ -45,5 +47,5 @@ pub fn is_authorized(e: &Env, addr: Address) -> bool { pub fn write_authorization(e: &Env, addr: Address, is_authorized: bool) { let key = DataKey::State(addr); - e.storage().set(&key, &is_authorized); + e.storage().persistent().set(&key, &is_authorized); } diff --git a/contracts/abundance/src/contract.rs b/contracts/abundance/src/contract.rs index 248662a..408ab57 100644 --- a/contracts/abundance/src/contract.rs +++ b/contracts/abundance/src/contract.rs @@ -6,17 +6,16 @@ use crate::balance::{is_authorized, write_authorization}; use crate::balance::{read_balance, receive_balance, spend_balance}; use crate::event; use crate::metadata::{read_decimal, read_name, read_symbol, write_metadata}; -use soroban_sdk::{contractimpl, Address, Bytes, Env}; +use crate::storage_types::INSTANCE_BUMP_AMOUNT; +use soroban_sdk::{contract, contractimpl, Address, Env, String}; use soroban_token_sdk::TokenMetadata; pub trait TokenTrait { - fn initialize(e: Env, admin: Address, decimal: u32, name: Bytes, symbol: Bytes); + fn initialize(e: Env, admin: Address, decimal: u32, name: String, symbol: String); fn allowance(e: Env, from: Address, spender: Address) -> i128; - fn increase_allowance(e: Env, from: Address, spender: Address, amount: i128); - - fn decrease_allowance(e: Env, from: Address, spender: Address, amount: i128); + fn approve(e: Env, from: Address, spender: Address, amount: i128, expiration_ledger: u32); fn balance(e: Env, id: Address) -> i128; @@ -42,9 +41,9 @@ pub trait TokenTrait { fn decimals(e: Env) -> u32; - fn name(e: Env) -> Bytes; + fn name(e: Env) -> String; - fn symbol(e: Env) -> Bytes; + fn symbol(e: Env) -> String; } fn check_nonnegative_amount(amount: i128) { @@ -53,11 +52,12 @@ fn check_nonnegative_amount(amount: i128) { } } +#[contract] pub struct Token; #[contractimpl] impl TokenTrait for Token { - fn initialize(e: Env, admin: Address, decimal: u32, name: Bytes, symbol: Bytes) { + fn initialize(e: Env, admin: Address, decimal: u32, name: String, symbol: String) { if has_administrator(&e) { panic!("already initialized") } @@ -77,46 +77,33 @@ impl TokenTrait for Token { } fn allowance(e: Env, from: Address, spender: Address) -> i128 { - read_allowance(&e, from, spender) + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + read_allowance(&e, from, spender).amount } - fn increase_allowance(e: Env, from: Address, spender: Address, amount: i128) { + fn approve(e: Env, from: Address, spender: Address, amount: i128, expiration_ledger: u32) { from.require_auth(); check_nonnegative_amount(amount); - let allowance = read_allowance(&e, from.clone(), spender.clone()); - let new_allowance = allowance - .checked_add(amount) - .expect("Updated allowance doesn't fit in an i128"); - - write_allowance(&e, from.clone(), spender.clone(), new_allowance); - event::increase_allowance(&e, from, spender, amount); - } - - fn decrease_allowance(e: Env, from: Address, spender: Address, amount: i128) { - from.require_auth(); - - check_nonnegative_amount(amount); + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); - let allowance = read_allowance(&e, from.clone(), spender.clone()); - if amount >= allowance { - write_allowance(&e, from.clone(), spender.clone(), 0); - } else { - write_allowance(&e, from.clone(), spender.clone(), allowance - amount); - } - event::decrease_allowance(&e, from, spender, amount); + write_allowance(&e, from.clone(), spender.clone(), amount, expiration_ledger); + event::approve(&e, from, spender, amount, expiration_ledger); } fn balance(e: Env, id: Address) -> i128 { + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); read_balance(&e, id) } fn spendable_balance(e: Env, id: Address) -> i128 { + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); read_balance(&e, id) } fn authorized(e: Env, id: Address) -> bool { + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); is_authorized(&e, id) } @@ -124,6 +111,9 @@ impl TokenTrait for Token { from.require_auth(); check_nonnegative_amount(amount); + + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + spend_balance(&e, from.clone(), amount); receive_balance(&e, to.clone(), amount); event::transfer(&e, from, to, amount); @@ -133,6 +123,9 @@ impl TokenTrait for Token { spender.require_auth(); check_nonnegative_amount(amount); + + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + spend_allowance(&e, from.clone(), spender, amount); spend_balance(&e, from.clone(), amount); receive_balance(&e, to.clone(), amount); @@ -143,6 +136,9 @@ impl TokenTrait for Token { from.require_auth(); check_nonnegative_amount(amount); + + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + spend_balance(&e, from.clone(), amount); event::burn(&e, from, amount); } @@ -151,6 +147,9 @@ impl TokenTrait for Token { spender.require_auth(); check_nonnegative_amount(amount); + + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + spend_allowance(&e, from.clone(), spender, amount); spend_balance(&e, from.clone(), amount); event::burn(&e, from, amount) @@ -160,6 +159,9 @@ impl TokenTrait for Token { check_nonnegative_amount(amount); let admin = read_administrator(&e); admin.require_auth(); + + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + spend_balance(&e, from.clone(), amount); event::clawback(&e, admin, from, amount); } @@ -167,6 +169,9 @@ impl TokenTrait for Token { fn set_authorized(e: Env, id: Address, authorize: bool) { let admin = read_administrator(&e); admin.require_auth(); + + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + write_authorization(&e, id.clone(), authorize); event::set_authorized(&e, admin, id, authorize); } @@ -181,6 +186,9 @@ impl TokenTrait for Token { fn mint(e: Env, to: Address, amount: i128) { check_nonnegative_amount(amount); to.require_auth(); + + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + receive_balance(&e, to.clone(), amount); event::mint(&e, to.clone(), to, amount); } @@ -188,6 +196,9 @@ impl TokenTrait for Token { fn set_admin(e: Env, new_admin: Address) { let admin = read_administrator(&e); admin.require_auth(); + + e.storage().instance().bump(INSTANCE_BUMP_AMOUNT); + write_administrator(&e, &new_admin); event::set_admin(&e, admin, new_admin); } @@ -196,11 +207,11 @@ impl TokenTrait for Token { read_decimal(&e) } - fn name(e: Env) -> Bytes { + fn name(e: Env) -> String { read_name(&e) } - fn symbol(e: Env) -> Bytes { + fn symbol(e: Env) -> String { read_symbol(&e) } } diff --git a/contracts/abundance/src/event.rs b/contracts/abundance/src/event.rs index 638850f..b897bb4 100644 --- a/contracts/abundance/src/event.rs +++ b/contracts/abundance/src/event.rs @@ -1,27 +1,22 @@ -use soroban_sdk::{Address, Env, Symbol}; +use soroban_sdk::{symbol_short, Address, Env, Symbol}; -pub(crate) fn increase_allowance(e: &Env, from: Address, to: Address, amount: i128) { - let topics = (Symbol::new(e, "increase_allowance"), from, to); - e.events().publish(topics, amount); -} - -pub(crate) fn decrease_allowance(e: &Env, from: Address, to: Address, amount: i128) { - let topics = (Symbol::new(e, "decrease_allowance"), from, to); - e.events().publish(topics, amount); +pub(crate) fn approve(e: &Env, from: Address, to: Address, amount: i128, expiration_ledger: u32) { + let topics = (Symbol::new(e, "approve"), from, to); + e.events().publish(topics, (amount, expiration_ledger)); } pub(crate) fn transfer(e: &Env, from: Address, to: Address, amount: i128) { - let topics = (Symbol::short("transfer"), from, to); + let topics = (symbol_short!("transfer"), from, to); e.events().publish(topics, amount); } pub(crate) fn mint(e: &Env, admin: Address, to: Address, amount: i128) { - let topics = (Symbol::short("mint"), admin, to); + let topics = (symbol_short!("mint"), admin, to); e.events().publish(topics, amount); } pub(crate) fn clawback(e: &Env, admin: Address, from: Address, amount: i128) { - let topics = (Symbol::short("clawback"), admin, from); + let topics = (symbol_short!("clawback"), admin, from); e.events().publish(topics, amount); } @@ -31,11 +26,11 @@ pub(crate) fn set_authorized(e: &Env, admin: Address, id: Address, authorize: bo } pub(crate) fn set_admin(e: &Env, admin: Address, new_admin: Address) { - let topics = (Symbol::short("set_admin"), admin); + let topics = (symbol_short!("set_admin"), admin); e.events().publish(topics, new_admin); } pub(crate) fn burn(e: &Env, from: Address, amount: i128) { - let topics = (Symbol::short("burn"), from); + let topics = (symbol_short!("burn"), from); e.events().publish(topics, amount); } diff --git a/contracts/abundance/src/metadata.rs b/contracts/abundance/src/metadata.rs index 558f189..f09ac1d 100644 --- a/contracts/abundance/src/metadata.rs +++ b/contracts/abundance/src/metadata.rs @@ -1,19 +1,19 @@ -use soroban_sdk::{Bytes, Env}; +use soroban_sdk::{Env, String}; use soroban_token_sdk::{TokenMetadata, TokenUtils}; pub fn read_decimal(e: &Env) -> u32 { let util = TokenUtils::new(e); - util.get_metadata_unchecked().unwrap().decimal + util.get_metadata().decimal } -pub fn read_name(e: &Env) -> Bytes { +pub fn read_name(e: &Env) -> String { let util = TokenUtils::new(e); - util.get_metadata_unchecked().unwrap().name + util.get_metadata().name } -pub fn read_symbol(e: &Env) -> Bytes { +pub fn read_symbol(e: &Env) -> String { let util = TokenUtils::new(e); - util.get_metadata_unchecked().unwrap().symbol + util.get_metadata().symbol } pub fn write_metadata(e: &Env, metadata: TokenMetadata) { diff --git a/contracts/abundance/src/storage_types.rs b/contracts/abundance/src/storage_types.rs index 1a0111a..707f44d 100644 --- a/contracts/abundance/src/storage_types.rs +++ b/contracts/abundance/src/storage_types.rs @@ -1,5 +1,8 @@ use soroban_sdk::{contracttype, Address}; +pub(crate) const INSTANCE_BUMP_AMOUNT: u32 = 34560; // 2 days +pub(crate) const BALANCE_BUMP_AMOUNT: u32 = 518400; // 30 days + #[derive(Clone)] #[contracttype] pub struct AllowanceDataKey { @@ -7,6 +10,12 @@ pub struct AllowanceDataKey { pub spender: Address, } +#[contracttype] +pub struct AllowanceValue { + pub amount: i128, + pub expiration_ledger: u32, +} + #[derive(Clone)] #[contracttype] pub enum DataKey { diff --git a/contracts/abundance/src/test.rs b/contracts/abundance/src/test.rs index 12eb0bc..0d0a0b0 100644 --- a/contracts/abundance/src/test.rs +++ b/contracts/abundance/src/test.rs @@ -2,7 +2,11 @@ extern crate std; use crate::{contract::Token, TokenClient}; -use soroban_sdk::{testutils::Address as _, Address, Env, IntoVal, Symbol}; +use soroban_sdk::{ + symbol_short, + testutils::{Address as _, AuthorizedFunction, AuthorizedInvocation}, + Address, Env, IntoVal, Symbol, +}; fn create_token<'a>(e: &Env, admin: &Address) -> TokenClient<'a> { let token = TokenClient::new(e, &e.register_contract(None, Token {})); @@ -25,23 +29,33 @@ fn test() { token.mint(&user1, &1000); assert_eq!( e.auths(), - [( + std::vec![( user1.clone(), - token.address.clone(), - Symbol::short("mint"), - (&user1, 1000_i128).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + symbol_short!("mint"), + (&user1, 1000_i128).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); assert_eq!(token.balance(&user1), 1000); - token.increase_allowance(&user2, &user3, &500); + token.approve(&user2, &user3, &500, &200); assert_eq!( e.auths(), - [( + std::vec![( user2.clone(), - token.address.clone(), - Symbol::new(&e, "increase_allowance"), - (&user2, &user3, 500_i128).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + symbol_short!("approve"), + (&user2, &user3, 500_i128, 200_u32).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); assert_eq!(token.allowance(&user2, &user3), 500); @@ -49,11 +63,16 @@ fn test() { token.transfer(&user1, &user2, &600); assert_eq!( e.auths(), - [( + std::vec![( user1.clone(), - token.address.clone(), - Symbol::short("transfer"), - (&user1, &user2, 600_i128).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + symbol_short!("transfer"), + (&user1, &user2, 600_i128).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); assert_eq!(token.balance(&user1), 400); @@ -62,11 +81,16 @@ fn test() { token.transfer_from(&user3, &user2, &user1, &400); assert_eq!( e.auths(), - [( + std::vec![( user3.clone(), - token.address.clone(), - Symbol::new(&e, "transfer_from"), - (&user3, &user2, &user1, 400_i128).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + Symbol::new(&e, "transfer_from"), + (&user3, &user2, &user1, 400_i128).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); assert_eq!(token.balance(&user1), 800); @@ -79,22 +103,32 @@ fn test() { token.set_admin(&admin2); assert_eq!( e.auths(), - [( + std::vec![( admin1.clone(), - token.address.clone(), - Symbol::short("set_admin"), - (&admin2,).into_val(&e), //THIS DOESN'T WORK + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + symbol_short!("set_admin"), + (&admin2,).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); token.set_authorized(&user2, &false); assert_eq!( e.auths(), - [( + std::vec![( admin2.clone(), - token.address.clone(), - Symbol::new(&e, "set_authorized"), - (&user2, false).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + Symbol::new(&e, "set_authorized"), + (&user2, false).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); assert_eq!(token.authorized(&user2), false); @@ -105,26 +139,36 @@ fn test() { token.clawback(&user3, &100); assert_eq!( e.auths(), - [( + std::vec![( admin2.clone(), - token.address.clone(), - Symbol::short("clawback"), - (&user3, 100_i128).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + symbol_short!("clawback"), + (&user3, 100_i128).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); assert_eq!(token.balance(&user3), 200); - // Increase by 400, with an existing 100 = 500 - token.increase_allowance(&user2, &user3, &400); + // Increase to 500 + token.approve(&user2, &user3, &500, &200); assert_eq!(token.allowance(&user2, &user3), 500); - token.decrease_allowance(&user2, &user3, &501); + token.approve(&user2, &user3, &0, &200); assert_eq!( e.auths(), - [( + std::vec![( user2.clone(), - token.address.clone(), - Symbol::new(&e, "decrease_allowance"), - (&user2, &user3, 501_i128).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + symbol_short!("approve"), + (&user2, &user3, 0_i128, 200_u32).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); assert_eq!(token.allowance(&user2, &user3), 0); @@ -143,19 +187,25 @@ fn test_burn() { token.mint(&user1, &1000); assert_eq!(token.balance(&user1), 1000); - token.increase_allowance(&user1, &user2, &500); + token.approve(&user1, &user2, &500, &200); assert_eq!(token.allowance(&user1, &user2), 500); token.burn_from(&user2, &user1, &500); assert_eq!( e.auths(), - [( + std::vec![( user2.clone(), - token.address.clone(), - Symbol::short("burn_from"), - (&user2, &user1, 500_i128).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + symbol_short!("burn_from"), + (&user2, &user1, 500_i128).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); + assert_eq!(token.allowance(&user1, &user2), 0); assert_eq!(token.balance(&user1), 500); assert_eq!(token.balance(&user2), 0); @@ -163,13 +213,19 @@ fn test_burn() { token.burn(&user1, &500); assert_eq!( e.auths(), - [( + std::vec![( user1.clone(), - token.address.clone(), - Symbol::short("burn"), - (&user1, 500_i128).into_val(&e), + AuthorizedInvocation { + function: AuthorizedFunction::Contract(( + token.address.clone(), + symbol_short!("burn"), + (&user1, 500_i128).into_val(&e), + )), + sub_invocations: std::vec![] + } )] ); + assert_eq!(token.balance(&user1), 0); assert_eq!(token.balance(&user2), 0); } @@ -242,7 +298,7 @@ fn transfer_from_insufficient_allowance() { token.mint(&user1, &1000); assert_eq!(token.balance(&user1), 1000); - token.increase_allowance(&user1, &user3, &100); + token.approve(&user1, &user3, &100, &200); assert_eq!(token.allowance(&user1, &user3), 100); token.transfer_from(&user3, &user1, &user2, &101); diff --git a/contracts/crowdfund/src/lib.rs b/contracts/crowdfund/src/lib.rs index 3585230..67cb96e 100644 --- a/contracts/crowdfund/src/lib.rs +++ b/contracts/crowdfund/src/lib.rs @@ -1,5 +1,7 @@ #![no_std] -use soroban_sdk::{contractimpl, contractmeta, contracttype, token, Address, Env, IntoVal, RawVal}; +use soroban_sdk::{ + contract, contractimpl, contractmeta, contracttype, token, Address, Env, IntoVal, Val, +}; mod events; mod test; @@ -25,8 +27,8 @@ pub enum State { Expired = 2, } -impl IntoVal for State { - fn into_val(&self, env: &Env) -> RawVal { +impl IntoVal for State { + fn into_val(&self, env: &Env) -> Val { (*self as u32).into_val(env) } } @@ -37,51 +39,51 @@ fn get_ledger_timestamp(e: &Env) -> u64 { fn get_recipient(e: &Env) -> Address { e.storage() - .get(&DataKey::Recipient) + .instance() + .get::<_, Address>(&DataKey::Recipient) .expect("not initialized") - .unwrap() } fn get_recipient_claimed(e: &Env) -> bool { e.storage() - .get(&DataKey::RecipientClaimed) + .instance() + .get::<_, bool>(&DataKey::RecipientClaimed) .expect("not initialized") - .unwrap() } fn get_deadline(e: &Env) -> u64 { e.storage() - .get(&DataKey::Deadline) + .instance() + .get::<_, u64>(&DataKey::Deadline) .expect("not initialized") - .unwrap() } fn get_started(e: &Env) -> u64 { e.storage() - .get(&DataKey::Started) + .instance() + .get::<_, u64>(&DataKey::Started) .expect("not initialized") - .unwrap() } fn get_target_amount(e: &Env) -> i128 { e.storage() - .get(&DataKey::Target) + .instance() + .get::<_, i128>(&DataKey::Target) .expect("not initialized") - .unwrap() } fn get_token(e: &Env) -> Address { e.storage() - .get(&DataKey::Token) + .instance() + .get::<_, Address>(&DataKey::Token) .expect("not initialized") - .unwrap() } fn get_user_deposited(e: &Env, user: &Address) -> i128 { e.storage() - .get(&DataKey::User(user.clone())) - .unwrap_or(Ok(0)) - .unwrap() + .instance() + .get::<_, i128>(&DataKey::User(user.clone())) + .unwrap_or(0) } fn get_balance(e: &Env, contract_id: &Address) -> i128 { @@ -114,11 +116,15 @@ fn get_state(e: &Env) -> State { } fn set_user_deposited(e: &Env, user: &Address, amount: &i128) { - e.storage().set(&DataKey::User(user.clone()), amount); + e.storage() + .instance() + .set(&DataKey::User(user.clone()), amount); } fn set_recipient_claimed(e: &Env) { - e.storage().set(&DataKey::RecipientClaimed, &true); + e.storage() + .instance() + .set(&DataKey::RecipientClaimed, &true); } // Transfer tokens from the contract to the recipient @@ -134,6 +140,7 @@ contractmeta!( val = "Crowdfunding contract that allows users to deposit tokens and withdraw them if the target is not met" ); +#[contract] struct Crowdfund; /* @@ -154,15 +161,21 @@ impl Crowdfund { target_amount: i128, token: Address, ) { - assert!(!e.storage().has(&DataKey::Recipient), "already initialized"); + assert!( + !e.storage().instance().has(&DataKey::Recipient), + "already initialized" + ); - e.storage().set(&DataKey::Recipient, &recipient); - e.storage().set(&DataKey::RecipientClaimed, &false); + e.storage().instance().set(&DataKey::Recipient, &recipient); + e.storage() + .instance() + .set(&DataKey::RecipientClaimed, &false); e.storage() + .instance() .set(&DataKey::Started, &get_ledger_timestamp(&e)); - e.storage().set(&DataKey::Deadline, &deadline); - e.storage().set(&DataKey::Target, &target_amount); - e.storage().set(&DataKey::Token, &token); + e.storage().instance().set(&DataKey::Deadline, &deadline); + e.storage().instance().set(&DataKey::Target, &target_amount); + e.storage().instance().set(&DataKey::Token, &token); } pub fn recipient(e: Env) -> Address { diff --git a/contracts/crowdfund/src/test.rs b/contracts/crowdfund/src/test.rs index e04a3fb..6a48e6c 100644 --- a/contracts/crowdfund/src/test.rs +++ b/contracts/crowdfund/src/test.rs @@ -3,8 +3,7 @@ use super::testutils::{register_test_contract as register_crowdfund, Crowdfund}; use soroban_sdk::{ testutils::{Address as AddressTestTrait, Events, Ledger}, - token::Client as Token, - vec, Address, Env, IntoVal, RawVal, Symbol, Vec, + token, vec, Address, Env, IntoVal, Symbol, Val, Vec, }; fn create_crowdfund_contract( @@ -33,11 +32,22 @@ struct Setup<'a> { recipient: Address, user1: Address, user2: Address, - token: Token<'a>, + token: token::Client<'a>, crowdfund: Crowdfund, crowdfund_id: Address, } +fn create_token_contract<'a>( + e: &Env, + admin: &Address, +) -> (token::Client<'a>, token::AdminClient<'a>) { + let contract_address = e.register_stellar_asset_contract(admin.clone()); + ( + token::Client::new(e, &contract_address), + token::AdminClient::new(e, &contract_address), + ) +} + /// Sets up a crowdfund with - /// 1. Deadline 10 seconds from now. /// 2. Target amount of 15. @@ -56,16 +66,15 @@ impl Setup<'_> { // Create the token contract let token_admin = Address::random(&e); - let contract_token = e.register_stellar_asset_contract(token_admin); - let token = Token::new(&e, &contract_token); + let (token, token_admin) = create_token_contract(&e, &token_admin); // Create the crowdfunding contract let (crowdfund_id, crowdfund) = - create_crowdfund_contract(&e, &recipient, deadline, &target_amount, &contract_token); + create_crowdfund_contract(&e, &recipient, deadline, &target_amount, &token.address); // Mint some tokens to work with - token.mock_all_auths().mint(&user1, &10); - token.mock_all_auths().mint(&user2, &8); + token_admin.mock_all_auths().mint(&user1, &10); + token_admin.mock_all_auths().mint(&user2, &8); crowdfund.client().mock_all_auths().deposit(&user1, &10); @@ -110,7 +119,7 @@ fn test_events() { .mock_all_auths() .deposit(&setup.user2, &3); - let mut crowd_fund_events: Vec<(Address, soroban_sdk::Vec, RawVal)> = vec![&setup.env]; + let mut crowd_fund_events: Vec<(Address, soroban_sdk::Vec, Val)> = vec![&setup.env]; // there are SAC events emitted also, filter those away, not asserting that aspect setup @@ -118,7 +127,6 @@ fn test_events() { .events() .all() .iter() - .map(core::result::Result::unwrap) .filter(|event| event.0 == setup.crowdfund_id) .for_each(|event| crowd_fund_events.push_back(event)); diff --git a/convert.ts b/convert.ts index 5ab7e28..922f93b 100644 --- a/convert.ts +++ b/convert.ts @@ -1,4 +1,4 @@ -import { Address, xdr } from 'soroban-client'; +import { Address, Contract, xdr } from 'soroban-client'; import { Buffer } from "buffer"; import { bufToBigint } from 'bigint-conversion'; @@ -33,9 +33,12 @@ export function scvalToBigInt(scval: xdr.ScVal | undefined): BigInt { }; } +export function strToScVal(base64Xdr: string): xdr.ScVal { + return xdr.ScVal.fromXDR(Buffer.from(base64Xdr, 'base64')); +} + export function scValStrToJs(base64Xdr: string): T { - let scval = xdr.ScVal.fromXDR(Buffer.from(base64Xdr, 'base64')); - return scValToJs(scval); + return scValToJs(strToScVal(base64Xdr)); } export function scValToJs(val: xdr.ScVal): T { @@ -106,8 +109,8 @@ export function scValToJs(val: xdr.ScVal): T { }); return res as unknown as T } - case xdr.ScValType.scvContractExecutable(): - return val.exec() as unknown as T; + case xdr.ScValType.scvContractInstance(): + return val.instance() as unknown as T; case xdr.ScValType.scvLedgerKeyNonce(): return val.nonceKey() as unknown as T; case xdr.ScValType.scvTimepoint(): diff --git a/docker/build.sh b/docker/build.sh index 409bea4..8f9f02d 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -2,6 +2,6 @@ # Build image and tag it with image name and version docker build . \ - --tag soroban-preview:9 \ + --tag soroban-preview:10 \ --force-rm \ --rm diff --git a/initialize.sh b/initialize.sh index 4ebfc02..58c6102 100755 --- a/initialize.sh +++ b/initialize.sh @@ -32,7 +32,7 @@ if [[ "$SOROBAN_RPC_HOST" == "" ]]; then fi fi -SOROBAN_RPC_URL="$SOROBAN_RPC_HOST/soroban/rpc" +SOROBAN_RPC_URL="$SOROBAN_RPC_HOST" case "$1" in standalone) @@ -99,9 +99,9 @@ soroban contract invoke \ --id "$ABUNDANCE_ID" \ -- \ initialize \ - --symbol '"41424E44"' \ + --symbol ABND \ --decimal 7 \ - --name '"4162756E64616E636520546F6B656E"' \ + --name abundance \ --admin "$ABUNDANCE_ADMIN_ADDRESS" echo "Initialize the crowdfund contract" diff --git a/package-lock.json b/package-lock.json index 240e40b..1cadd4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "next": "^13.4.4", "react": "^18.2.0", "react-dom": "^18.2.0", - "soroban-client": "0.8.1" + "soroban-client": "0.9.1" }, "devDependencies": { "@types/humanize-duration": "^3.27.1", @@ -45,10 +45,10 @@ "@stellar/freighter-api": "1.5.0", "bigint-conversion": "2.4.1", "buffer": "6.0.3", - "soroban-client": "0.8.1" + "soroban-client": "0.9.1" }, "devDependencies": { - "typescript": "5.0.4" + "typescript": "5.1.6" } }, ".soroban/abundance-token/node_modules/@stellar/freighter-api": { @@ -58,9 +58,9 @@ "optional": true }, ".soroban/abundance-token/node_modules/typescript": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", - "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", + "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", "dev": true, "optional": true, "bin": { @@ -68,7 +68,7 @@ "tsserver": "bin/tsserver" }, "engines": { - "node": ">=12.20" + "node": ">=14.17" } }, ".soroban/crowdfund-contract": { @@ -78,10 +78,10 @@ "@stellar/freighter-api": "1.5.0", "bigint-conversion": "2.4.1", "buffer": "6.0.3", - "soroban-client": "0.8.1" + "soroban-client": "0.9.1" }, "devDependencies": { - "typescript": "5.0.4" + "typescript": "5.1.6" } }, ".soroban/crowdfund-contract/node_modules/@stellar/freighter-api": { @@ -91,9 +91,9 @@ "optional": true }, ".soroban/crowdfund-contract/node_modules/typescript": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", - "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "version": "5.1.6", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", + "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", "dev": true, "optional": true, "bin": { @@ -101,7 +101,7 @@ "tsserver": "bin/tsserver" }, "engines": { - "node": ">=12.20" + "node": ">=14.17" } }, "node_modules/@babel/runtime": { @@ -3162,9 +3162,9 @@ "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" }, "node_modules/js-xdr": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/js-xdr/-/js-xdr-2.0.0.tgz", - "integrity": "sha512-4mctWHR47ejNcfpE8/Xl3l2wYqO1Qy09d1pveZRmarUz2BcuU/M8grzadxV6PoN/X0ywOb6cy6117qYUWkfeBA==" + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/js-xdr/-/js-xdr-3.0.0.tgz", + "integrity": "sha512-tSt6UKJ2L7t+yaQURGkHo9kop9qnVbChTlCu62zNiDbDZQoZb/YjUj2iFJ3lgelhfg9p5bhO2o/QX+g36TPsSQ==" }, "node_modules/js-yaml": { "version": "4.1.0", @@ -4400,9 +4400,9 @@ } }, "node_modules/soroban-client": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/soroban-client/-/soroban-client-0.8.1.tgz", - "integrity": "sha512-F+3K+hHlpXbSSdBMjvTlkim1tb2aMlg4OT+71r1ILk8T+bMFHXlZShettJg2VMQ402WGalBNN4Q9oSeoHsPVFQ==", + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/soroban-client/-/soroban-client-0.9.1.tgz", + "integrity": "sha512-wAxu8Z15vBirjizdGG5BnUtZDtf/+ul37q84xHqUUHS7t7sL8CBeTdM6bFYmlEVLjpfFtAhdB/yJBQU7Bo4kBQ==", "dependencies": { "axios": "^1.4.0", "bignumber.js": "^9.1.1", @@ -4412,7 +4412,7 @@ "eventsource": "^2.0.2", "lodash": "^4.17.21", "randombytes": "^2.1.0", - "stellar-base": "9.0.0-soroban.3", + "stellar-base": "10.0.0-soroban.3", "toml": "^3.0.0", "urijs": "^1.19.1" } @@ -4436,16 +4436,16 @@ } }, "node_modules/stellar-base": { - "version": "9.0.0-soroban.3", - "resolved": "https://registry.npmjs.org/stellar-base/-/stellar-base-9.0.0-soroban.3.tgz", - "integrity": "sha512-PaeIrspURhbDA0FSkH/mu/lQxxSYPplOdhIcW4VqmKW2kMm/ADXjyQr1y4tFIfv8EpIe5DCJ6sfIyadIoPd8HQ==", + "version": "10.0.0-soroban.3", + "resolved": "https://registry.npmjs.org/stellar-base/-/stellar-base-10.0.0-soroban.3.tgz", + "integrity": "sha512-XixwHHggxuWHQYY2CiVIzXLCGwaphS6pKF1GFyTC4QNIouR7IRWn/fzbXkYmzIbJTq6gM4mORO3kaLwl4bd7yA==", "dependencies": { "base32.js": "^0.1.0", "bignumber.js": "^9.1.1", + "buffer": "^6.0.3", "crc": "^4.3.2", "crypto-browserify": "^3.12.0", - "js-xdr": "^2.0.0", - "lodash": "^4.17.21", + "js-xdr": "^3.0.0", "sha.js": "^2.3.6", "tweetnacl": "^1.0.3" }, diff --git a/package.json b/package.json index ed7a139..4bc1731 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "next": "^13.4.4", "react": "^18.2.0", "react-dom": "^18.2.0", - "soroban-client": "0.8.1", + "soroban-client": "0.9.1", "crowdfund-contract": "file:.soroban/crowdfund-contract", "abundance-token": "file:.soroban/abundance-token" }, diff --git a/quickstart.sh b/quickstart.sh index ddad8de..e33ff3f 100755 --- a/quickstart.sh +++ b/quickstart.sh @@ -19,7 +19,7 @@ esac # this is set to the quickstart `soroban-dev` image annointed as the release # for a given Soroban Release, it is captured on Soroban Releases - https://soroban.stellar.org/docs/reference/releases -QUICKSTART_SOROBAN_DOCKER_SHA=stellar/quickstart:soroban-dev@sha256:57e8ab498bfa14c65595fbb01cb94b1cdee9637ef2e6634e59d54f6958c05bdb +QUICKSTART_SOROBAN_DOCKER_SHA=stellar/quickstart:soroban-dev@sha256:ed57f7a7683e3568ae401f5c6e93341a9f77d8ad41191bf752944d7898981e0c shift @@ -48,7 +48,7 @@ docker run -dti \ -p 8001:8000 \ --ipc=host \ --network soroban-network \ - soroban-preview:9 + soroban-preview:10 # Run the stellar quickstart image