diff --git a/examples/cross-contract-calls/high-level/Cargo.toml b/examples/cross-contract-calls/high-level/Cargo.toml index 0f188089a..88cbc06d5 100644 --- a/examples/cross-contract-calls/high-level/Cargo.toml +++ b/examples/cross-contract-calls/high-level/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "cross-contract-high-level" version = "1.1.0" -authors = ["Near Inc "] +authors = ["Near Inc ", "@jriemann"] edition = "2021" [lib] diff --git a/examples/multi-token/.cargo/config.toml b/examples/multi-token/.cargo/config.toml new file mode 100644 index 000000000..4a9f7c79c --- /dev/null +++ b/examples/multi-token/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.wasm32-unknown-unknown] +rustflags = ["-C", "link-arg=-s"] + +[build] +target-dir = "../../target" diff --git a/examples/multi-token/Cargo.lock b/examples/multi-token/Cargo.lock new file mode 100644 index 000000000..ba0155836 --- /dev/null +++ b/examples/multi-token/Cargo.lock @@ -0,0 +1,3567 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + +[[package]] +name = "addr2line" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.7", + "once_cell", + "version_check", +] + +[[package]] +name = "aho-corasick" +version = "0.7.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" +dependencies = [ + "memchr", +] + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" + +[[package]] +name = "approval-receiver" +version = "0.1.0" +dependencies = [ + "near-contract-standards", + "near-sdk 4.1.0-pre.3", +] + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "async-channel" +version = "1.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14485364214912d3b19cc3435dde4df66065127f05fa0d75c712f36f12c2f28" +dependencies = [ + "concurrent-queue", + "event-listener", + "futures-core", +] + +[[package]] +name = "async-io" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83e21f3a490c72b3b0cf44962180e60045de2925d8dff97918f7ee43c8f637c7" +dependencies = [ + "autocfg", + "concurrent-queue", + "futures-lite", + "libc", + "log", + "once_cell", + "parking", + "polling", + "slab", + "socket2", + "waker-fn", + "winapi", +] + +[[package]] +name = "async-process" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02111fd8655a613c25069ea89fc8d9bb89331fa77486eb3bc059ee757cfa481c" +dependencies = [ + "async-io", + "autocfg", + "blocking", + "cfg-if 1.0.0", + "event-listener", + "futures-lite", + "libc", + "once_cell", + "signal-hook", + "winapi", +] + +[[package]] +name = "async-task" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524" + +[[package]] +name = "async-trait" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "atomic-waker" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cab84319d616cfb654d03394f38ab7e6f0919e181b1b57e1fd15e7fb4077d9a7" +dependencies = [ + "addr2line", + "cc", + "cfg-if 1.0.0", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "base64" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" + +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "binary-install" +version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5bc5f8c50dd6a80d0b303ddab79f42ddcb52fd43d68107ecf622c551fd4cd4" +dependencies = [ + "curl", + "dirs 1.0.5", + "failure", + "flate2", + "hex 0.3.2", + "is_executable", + "siphasher", + "tar", + "zip", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitvec" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7774144344a4faa177370406a7ff5f1da24303817368584c6206c8303eb07848" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" +dependencies = [ + "crypto-mac", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "blake2b_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +dependencies = [ + "arrayref", + "arrayvec 0.5.2", + "constant_time_eq", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +dependencies = [ + "generic-array", +] + +[[package]] +name = "blocking" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6ccb65d468978a086b69884437ded69a90faab3bbe6e67f242173ea728acccc" +dependencies = [ + "async-channel", + "async-task", + "atomic-waker", + "fastrand", + "futures-lite", + "once_cell", +] + +[[package]] +name = "borsh" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "15bf3650200d8bffa99015595e10f1fbd17de07abbc25bb067da79e769939bfa" +dependencies = [ + "borsh-derive", + "hashbrown 0.11.2", +] + +[[package]] +name = "borsh-derive" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6441c552f230375d18e3cc377677914d2ca2b0d36e52129fe15450a2dce46775" +dependencies = [ + "borsh-derive-internal", + "borsh-schema-derive-internal", + "proc-macro-crate 0.1.5", + "proc-macro2", + "syn", +] + +[[package]] +name = "borsh-derive-internal" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5449c28a7b352f2d1e592a8a28bf139bc71afb0764a14f3c02500935d8c44065" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "borsh-schema-derive-internal" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdbd5696d8bfa21d53d9fe39a714a18538bad11492a42d066dbbc395fb1951c0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + +[[package]] +name = "bumpalo" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" + +[[package]] +name = "byte-slice-cast" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87c5fdd0166095e1d463fc6cc01aa8ce547ad77a4e84d42eb6762b084e28067e" + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" + +[[package]] +name = "bytesize" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" + +[[package]] +name = "bzip2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6afcd980b5f3a45017c57e57a2fcccbb351cc43a356ce117ef760ef8052b89b0" +dependencies = [ + "bzip2-sys", + "libc", +] + +[[package]] +name = "bzip2-sys" +version = "0.1.11+1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "736a955f3fa7875102d57c82b8cac37ec45224a07fd32d58f9f7a186b6cd4cdc" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + +[[package]] +name = "c2-chacha" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27dae93fe7b1e0424dc57179ac396908c26b035a87234809f5c4dfd1b47dc80" +dependencies = [ + "cipher", + "ppv-lite86", +] + +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[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 = "chrono" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" +dependencies = [ + "iana-time-zone", + "js-sys", + "num-integer", + "num-traits", + "serde", + "time", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "cipher" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array", +] + +[[package]] +name = "codespan-reporting" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" +dependencies = [ + "termcolor", + "unicode-width", +] + +[[package]] +name = "concurrent-queue" +version = "1.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c" +dependencies = [ + "cache-padded", +] + +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "core-foundation" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" + +[[package]] +name = "cpufeatures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[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 = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curl" +version = "0.4.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "509bd11746c7ac09ebd19f0b17782eae80aadee26237658a6b4808afb5c11a22" +dependencies = [ + "curl-sys", + "libc", + "openssl-probe", + "openssl-sys", + "schannel", + "socket2", + "winapi", +] + +[[package]] +name = "curl-sys" +version = "0.4.56+curl-7.83.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6093e169dd4de29e468fa649fbae11cdcd5551c81fe5bf1b0677adad7ef3d26f" +dependencies = [ + "cc", + "libc", + "libz-sys", + "openssl-sys", + "pkg-config", + "vcpkg", + "winapi", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cxx" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19f39818dcfc97d45b03953c1292efc4e80954e1583c4aa770bac1383e2310a4" +dependencies = [ + "cc", + "cxxbridge-flags", + "cxxbridge-macro", + "link-cplusplus", +] + +[[package]] +name = "cxx-build" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e580d70777c116df50c390d1211993f62d40302881e54d4b79727acb83d0199" +dependencies = [ + "cc", + "codespan-reporting", + "once_cell", + "proc-macro2", + "quote", + "scratch", + "syn", +] + +[[package]] +name = "cxxbridge-flags" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56a46460b88d1cec95112c8c363f0e2c39afdb237f60583b0b36343bf627ea9c" + +[[package]] +name = "cxxbridge-macro" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "747b608fecf06b0d72d440f27acc99288207324b793be2c17991839f3d4995ea" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "defi" +version = "0.0.1" +dependencies = [ + "near-contract-standards", + "near-sdk 4.1.0-pre.3", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + +[[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.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" +dependencies = [ + "block-buffer 0.10.3", + "crypto-common", +] + +[[package]] +name = "dirs" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" +dependencies = [ + "libc", + "redox_users 0.3.5", + "winapi", +] + +[[package]] +name = "dirs" +version = "3.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30baa043103c9d0c2a57cf537cc2f35623889dc0d405e6c3cccfadbc81c71309" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b1d1d91c932ef41c0f2663aa8b0ca0342d444d842c06914aa0a7e352d0bada6" +dependencies = [ + "libc", + "redox_users 0.4.3", + "winapi", +] + +[[package]] +name = "dyn-clone" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2" + +[[package]] +name = "easy-ext" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53aff6fdc1b181225acdcb5b14c47106726fd8e486707315b1b138baed68ee31" + +[[package]] +name = "ed25519" +version = "1.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9c280362032ea4203659fc489832d0204ef09f247a0506f170dafcac08c369" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand 0.7.3", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "encoding_rs" +version = "0.8.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9852635589dc9f9ea1b6fe9f05b50ef208c85c834a562f0c6abb1c475736ec2b" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "failure" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d32e9bd16cc02eae7db7ef620b392808b89f6a5e16bb3497d159c6b92a0f4f86" +dependencies = [ + "backtrace", + "failure_derive", +] + +[[package]] +name = "failure_derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "fastrand" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" +dependencies = [ + "instant", +] + +[[package]] +name = "filetime" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94a7bbaa59354bc20dd75b67f23e2797b4490e9d6928203fb105c79e448c86c" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.2.16", + "windows-sys", +] + +[[package]] +name = "fixed-hash" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" +dependencies = [ + "byteorder", + "rand 0.8.5", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "flate2" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f82b0f4c27ad9f8bfd1f3208d882da2b09c301bc1c828fd3a00d0216d2fbbff6" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + +[[package]] +name = "form_urlencoded" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "funty" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" + +[[package]] +name = "futures-channel" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" + +[[package]] +name = "futures-io" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" + +[[package]] +name = "futures-lite" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7694489acd39452c77daa48516b894c153f192c3578d5a839b62c58099fcbf48" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + +[[package]] +name = "futures-sink" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" + +[[package]] +name = "futures-task" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" + +[[package]] +name = "futures-util" +version = "0.3.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "pin-utils", +] + +[[package]] +name = "generic-array" +version = "0.14.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.11.0+wasi-snapshot-preview1", +] + +[[package]] +name = "gimli" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22030e2c5a68ec659fde1e949a745124b48e6fa8b045b7ed5bd1fe4ccc5c4e5d" + +[[package]] +name = "h2" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" +dependencies = [ + "bytes", + "fnv", + "futures-core", + "futures-sink", + "futures-util", + "http", + "indexmap", + "slab", + "tokio", + "tokio-util", + "tracing", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "hex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "home" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2456aef2e6b6a9784192ae780c0f15bc57df0e918585282325e8c8ac27737654" +dependencies = [ + "winapi", +] + +[[package]] +name = "http" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +dependencies = [ + "bytes", + "fnv", + "itoa", +] + +[[package]] +name = "http-body" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +dependencies = [ + "bytes", + "http", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" + +[[package]] +name = "httpdate" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" + +[[package]] +name = "hyper" +version = "0.14.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c929dc5c39e335a03c405292728118860721b10190d98c2a0f0efd5baafbac" +dependencies = [ + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "httparse", + "httpdate", + "itoa", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", + "want", +] + +[[package]] +name = "hyper-tls" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +dependencies = [ + "bytes", + "hyper", + "native-tls", + "tokio", + "tokio-native-tls", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5a6ef98976b22b3b7f2f3a806f858cb862044cfa66805aa3ad84cb3d3b785ed" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "winapi", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fde6edd6cef363e9359ed3c98ba64590ba9eecba2293eb5a723ab32aee8926aa" +dependencies = [ + "cxx", + "cxx-build", +] + +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "idna" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + +[[package]] +name = "impl-codec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "161ebdfec3c8e3b52bf61c4f3550a1eea4f9579d10dc1b936f3171ebdcd6c443" +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", +] + +[[package]] +name = "indexmap" +version = "1.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "ipnet" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" + +[[package]] +name = "is_executable" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "302d553b8abc8187beb7d663e34c065ac4570b273bc9511a50e940e99409c577" +dependencies = [ + "winapi", +] + +[[package]] +name = "itoa" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" + +[[package]] +name = "js-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" +dependencies = [ + "wasm-bindgen", +] + +[[package]] +name = "keccak" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9b7d56ba4a8344d6be9729995e6b06f928af29998cdf79fe390cbf6b1fee838" + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +dependencies = [ + "spin", +] + +[[package]] +name = "libc" +version = "0.2.134" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" + +[[package]] +name = "libz-sys" +version = "1.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9702761c3935f8cc2f101793272e202c72b99da8f4224a19ddcf1279a6450bbf" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "link-cplusplus" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9272ab7b96c9046fbc5bc56c06c117cb639fe2d509df0c421cad82d2915cf369" +dependencies = [ + "cc", +] + +[[package]] +name = "lock_api" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +dependencies = [ + "autocfg", + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "matches" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" + +[[package]] +name = "memchr" +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 = "mime" +version = "0.3.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a60c7ce501c71e03a9c9c0d35b861413ae925bd979cc7a4e30d060069aaac8d" + +[[package]] +name = "miniz_oxide" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" +dependencies = [ + "adler", +] + +[[package]] +name = "mio" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57ee1c23c7c63b0c9250c339ffdc69255f110b298b901b9f6c82547b7b87caaf" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", +] + +[[package]] +name = "multi-token" +version = "1.1.0" +dependencies = [ + "near-contract-standards", + "near-sdk 4.1.0-pre.3", +] + +[[package]] +name = "multi-token-wrapper" +version = "0.1.0" +dependencies = [ + "anyhow", + "approval-receiver", + "defi", + "multi-token", + "near-contract-standards", + "near-primitives 0.5.0", + "near-sdk 4.0.0", + "near-units", + "serde_json", + "tokio", + "workspaces", +] + +[[package]] +name = "native-tls" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd7e2f3618557f980e0b17e8856252eee3c97fa12c54dff0ca290fb6266ca4a9" +dependencies = [ + "lazy_static", + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + +[[package]] +name = "near-account-id" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5fbe33ba04b086e082aabe4167f03d8e7f5af2db4fffb5e6061226e46e7f5ff" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "near-account-id" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de83d74a9241be8cc4eb3055216966b58bf8c463e8e285c0dc553925acdd19fa" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "near-account-id" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d258582a1878e6db67400b0504a5099db85718d22c2e07f747fe1706ae7150" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "near-account-id" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d924011380de759c3dc6fdbcda37a19a5c061f56dab69d28a34ecee765e23e4" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "near-chain-configs" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1faf676a95bd1718b06e5957e01a9415fedf7900f32d94d5bcf70abd678b10a2" +dependencies = [ + "anyhow", + "chrono", + "derive_more", + "near-crypto 0.15.0", + "near-primitives 0.15.0", + "num-rational", + "serde", + "serde_json", + "sha2 0.10.6", + "smart-default", + "tracing", +] + +[[package]] +name = "near-contract-standards" +version = "4.1.0-pre.3" +dependencies = [ + "near-sdk 4.1.0-pre.3", + "schemars", + "serde", + "serde_json", +] + +[[package]] +name = "near-crypto" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e44231c19aa95e0ff3b1a46209a8edb44f5e02fca8a60a19386ba38b2ee1942" +dependencies = [ + "arrayref", + "blake2", + "borsh", + "bs58", + "c2-chacha", + "curve25519-dalek", + "derive_more", + "ed25519-dalek", + "lazy_static", + "libc", + "near-account-id 0.5.0", + "parity-secp256k1", + "primitive-types", + "rand 0.7.3", + "rand_core 0.5.1", + "serde", + "serde_json", + "subtle", + "thiserror", +] + +[[package]] +name = "near-crypto" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8ecf0b8b31aa7f4e60f629f72213a2617ca4a5f45cd1ae9ed2cf7cecfebdbb7" +dependencies = [ + "arrayref", + "blake2", + "borsh", + "bs58", + "c2-chacha", + "curve25519-dalek", + "derive_more", + "ed25519-dalek", + "libc", + "near-account-id 0.13.0", + "once_cell", + "parity-secp256k1", + "primitive-types", + "rand 0.7.3", + "rand_core 0.5.1", + "serde", + "serde_json", + "subtle", + "thiserror", +] + +[[package]] +name = "near-crypto" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e75673d69fd7365508f3d32483669fe45b03bfb34e4d9363e90adae9dfb416c" +dependencies = [ + "arrayref", + "blake2", + "borsh", + "bs58", + "c2-chacha", + "curve25519-dalek", + "derive_more", + "ed25519-dalek", + "near-account-id 0.14.0", + "once_cell", + "parity-secp256k1", + "primitive-types", + "rand 0.7.3", + "rand_core 0.5.1", + "serde", + "serde_json", + "subtle", + "thiserror", +] + +[[package]] +name = "near-crypto" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7754612b47737d277fb818e9fdbb1406e90f9e57151c55c3584d714421976cb6" +dependencies = [ + "arrayref", + "blake2", + "borsh", + "bs58", + "c2-chacha", + "curve25519-dalek", + "derive_more", + "ed25519-dalek", + "near-account-id 0.15.0", + "once_cell", + "primitive-types", + "rand 0.7.3", + "secp256k1", + "serde", + "serde_json", + "subtle", + "thiserror", +] + +[[package]] +name = "near-jsonrpc-client" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384356f354bdf85d0ece627c6af6f38febb5406a4ffb32c5d75429b1a1472e29" +dependencies = [ + "borsh", + "lazy_static", + "log", + "near-chain-configs", + "near-crypto 0.15.0", + "near-jsonrpc-primitives", + "near-primitives 0.15.0", + "reqwest", + "serde", + "serde_json", + "thiserror", + "uuid", +] + +[[package]] +name = "near-jsonrpc-primitives" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ada226c74f05508c516f109a97b9f23335120d0bfda208f0d187b6bbfe6eef5a" +dependencies = [ + "near-chain-configs", + "near-crypto 0.15.0", + "near-primitives 0.15.0", + "near-rpc-error-macro 0.15.0", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "near-primitives" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78f106c7bbf2a12228daf4af2a976122b030745683ede24b5dc4514e8faaa36c" +dependencies = [ + "base64 0.13.0", + "borsh", + "bs58", + "byteorder", + "bytesize", + "chrono", + "derive_more", + "easy-ext", + "hex 0.4.3", + "near-crypto 0.5.0", + "near-primitives-core 0.5.0", + "near-rpc-error-macro 0.5.0", + "near-vm-errors 3.1.0", + "num-rational", + "primitive-types", + "rand 0.7.3", + "reed-solomon-erasure", + "regex", + "serde", + "serde_json", + "sha2 0.9.9", + "smart-default", + "validator", +] + +[[package]] +name = "near-primitives" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a2ba19282e79a4485a77736b679d276b09870bbf8042a18e0f0ae36347489c5" +dependencies = [ + "borsh", + "byteorder", + "bytesize", + "chrono", + "derive_more", + "easy-ext", + "hex 0.4.3", + "near-crypto 0.13.0", + "near-primitives-core 0.13.0", + "near-rpc-error-macro 0.13.0", + "near-vm-errors 0.13.0", + "num-rational", + "once_cell", + "primitive-types", + "rand 0.7.3", + "reed-solomon-erasure", + "serde", + "serde_json", + "smart-default", + "strum", + "thiserror", +] + +[[package]] +name = "near-primitives" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ad1a9a1640539c81f065425c31bffcfbf6b31ef1aeaade59ce905f5df6ac860" +dependencies = [ + "borsh", + "byteorder", + "bytesize", + "chrono", + "derive_more", + "easy-ext", + "hex 0.4.3", + "near-crypto 0.14.0", + "near-primitives-core 0.14.0", + "near-rpc-error-macro 0.14.0", + "near-vm-errors 0.14.0", + "num-rational", + "once_cell", + "primitive-types", + "rand 0.7.3", + "reed-solomon-erasure", + "serde", + "serde_json", + "smart-default", + "strum", + "thiserror", +] + +[[package]] +name = "near-primitives" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97670b302dce15f09bba50f24c67aa08130fd01528cc61d4415892401e88e974" +dependencies = [ + "borsh", + "byteorder", + "bytesize", + "cfg-if 1.0.0", + "chrono", + "derive_more", + "easy-ext", + "hex 0.4.3", + "near-crypto 0.15.0", + "near-primitives-core 0.15.0", + "near-rpc-error-macro 0.15.0", + "near-vm-errors 0.15.0", + "num-rational", + "once_cell", + "primitive-types", + "rand 0.7.3", + "reed-solomon-erasure", + "serde", + "serde_json", + "smart-default", + "strum", + "thiserror", +] + +[[package]] +name = "near-primitives-core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "108d06655885c1174823e41941fd44a82e13e850b12fa068a95194c96e247c68" +dependencies = [ + "base64 0.11.0", + "borsh", + "bs58", + "derive_more", + "hex 0.4.3", + "lazy_static", + "near-account-id 0.5.0", + "num-rational", + "serde", + "serde_json", + "sha2 0.9.9", +] + +[[package]] +name = "near-primitives-core" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb561feb392bb8c4f540256073446e6689af087bf6356e8dddcf75fc279f201f" +dependencies = [ + "base64 0.11.0", + "borsh", + "bs58", + "derive_more", + "near-account-id 0.13.0", + "num-rational", + "serde", + "sha2 0.10.6", + "strum", +] + +[[package]] +name = "near-primitives-core" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91d508f0fc340f6461e4e256417685720d3c4c00bb5a939b105160e49137caba" +dependencies = [ + "base64 0.11.0", + "borsh", + "bs58", + "derive_more", + "near-account-id 0.14.0", + "num-rational", + "serde", + "sha2 0.10.6", + "strum", +] + +[[package]] +name = "near-primitives-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7929e19d862221949734c4a0063a8f55e7069de3a2ebc2d4f4c13497a5e953cb" +dependencies = [ + "base64 0.13.0", + "borsh", + "bs58", + "derive_more", + "near-account-id 0.15.0", + "num-rational", + "serde", + "serde_repr", + "sha2 0.10.6", + "strum", +] + +[[package]] +name = "near-rpc-error-core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1db59973d0e8d8bd4be5ae508600add29f96737722d30e05cfc49e5044ded955" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn", +] + +[[package]] +name = "near-rpc-error-core" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77fdd7ea8d8f786878651c37691515d5053f827ae60894aa40c16882b78f77c9" +dependencies = [ + "quote", + "serde", + "syn", +] + +[[package]] +name = "near-rpc-error-core" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ee0b41c75ef859c193a8ff1dadfa0c8207bc0ac447cc22259721ad769a1408" +dependencies = [ + "quote", + "serde", + "syn", +] + +[[package]] +name = "near-rpc-error-core" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36addf90cc04bd547a627b3a292f59d7de4dd6fb5042115419ae901b93ce6c2d" +dependencies = [ + "quote", + "serde", + "syn", +] + +[[package]] +name = "near-rpc-error-macro" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46bde9eb491ab7ccccd48ee6d438dc07aa74318faa0ff007717c3d5b538d3951" +dependencies = [ + "near-rpc-error-core 0.5.0", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn", +] + +[[package]] +name = "near-rpc-error-macro" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e521842b6ae864dfe5391afbbe2df9e9d8427c26e9333b2e0b65cd42094f7607" +dependencies = [ + "near-rpc-error-core 0.13.0", + "serde", + "syn", +] + +[[package]] +name = "near-rpc-error-macro" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e837bd4bacd807073ec5ceb85708da7f721b46a4c2a978de86027fb0034ce31" +dependencies = [ + "near-rpc-error-core 0.14.0", + "serde", + "syn", +] + +[[package]] +name = "near-rpc-error-macro" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5beb352f3b91d8c491646c2fa4fdbbbf463c7b9c0226951c28f0197de44f99" +dependencies = [ + "near-rpc-error-core 0.15.0", + "serde", + "syn", +] + +[[package]] +name = "near-sandbox-utils" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201b7e0c5fcff633fb53e743b16c6aea4110e531764ccaa215ea1382db940b45" +dependencies = [ + "anyhow", + "async-process", + "binary-install", + "chrono", + "fs2", + "hex 0.3.2", + "home", +] + +[[package]] +name = "near-sdk" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bda34e06e28fb9a09ac54efbdc49f0c9308780fc932aaa81c49c493fde974045" +dependencies = [ + "base64 0.13.0", + "borsh", + "bs58", + "near-crypto 0.13.0", + "near-primitives 0.13.0", + "near-primitives-core 0.13.0", + "near-sdk-macros 4.0.0", + "near-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "near-vm-logic 0.13.0", + "serde", + "serde_json", + "wee_alloc", +] + +[[package]] +name = "near-sdk" +version = "4.1.0-pre.3" +dependencies = [ + "base64 0.13.0", + "borsh", + "bs58", + "near-crypto 0.14.0", + "near-primitives 0.14.0", + "near-primitives-core 0.14.0", + "near-sdk-macros 4.1.0-pre.3", + "near-sys 0.2.0", + "near-vm-logic 0.14.0", + "once_cell", + "serde", + "serde_json", + "wee_alloc", +] + +[[package]] +name = "near-sdk-macros" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72064fcc15a623a0d40a6c199ea5cbdc30a83cae4816889d46f218acf31bfba8" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "near-sdk-macros" +version = "4.1.0-pre.3" +dependencies = [ + "Inflector", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "near-sys" +version = "0.2.0" + +[[package]] +name = "near-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e307313276eaeced2ca95740b5639e1f3125b7c97f0a1151809d105f1aa8c6d3" + +[[package]] +name = "near-units" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97a2b77f295d398589eeee51ad0887905ef1734fb12b45cb6d77bd7e401988b9" +dependencies = [ + "near-units-core", + "near-units-macro", +] + +[[package]] +name = "near-units-core" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89aa2a7985de87a08ca35f28abd8d00f0f901e704257e6e029aadef981386bc6" +dependencies = [ + "num-format", + "regex", +] + +[[package]] +name = "near-units-macro" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89ab45d066220846f9bd5c21e9ab88c47c892edd36f962ada78bf8308523171a" +dependencies = [ + "near-units-core", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "near-vm-errors" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e02faf2bc1f6ef82b965cfe44389808fb5594f7aca4b596766117f4ce74df20" +dependencies = [ + "borsh", + "near-account-id 0.13.0", + "near-rpc-error-macro 0.13.0", + "serde", +] + +[[package]] +name = "near-vm-errors" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0da466a30f0446639cbd788c30865086fac3e8dcb07a79e51d2b0775ed4261e" +dependencies = [ + "borsh", + "near-account-id 0.14.0", + "near-rpc-error-macro 0.14.0", + "serde", +] + +[[package]] +name = "near-vm-errors" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5591c9c8afa83a040cb5c3f29bc52b2efae2c32d4bcaee1bba723738da1a5cf6" +dependencies = [ + "borsh", + "near-account-id 0.15.0", + "near-rpc-error-macro 0.15.0", + "serde", + "strum", +] + +[[package]] +name = "near-vm-errors" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffec816703a13b6ca5b3dbd0005e6eb5360087058203c93e859a019dbfd88300" +dependencies = [ + "borsh", + "hex 0.4.3", + "near-account-id 0.5.0", + "near-rpc-error-macro 0.5.0", + "serde", +] + +[[package]] +name = "near-vm-logic" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f024d90451cd3c24d7a0a5cabf3636b192a60eb8e3ff0456f6c18b91152c346d" +dependencies = [ + "base64 0.13.0", + "borsh", + "bs58", + "byteorder", + "near-account-id 0.13.0", + "near-crypto 0.13.0", + "near-primitives 0.13.0", + "near-primitives-core 0.13.0", + "near-vm-errors 0.13.0", + "ripemd", + "serde", + "sha2 0.10.6", + "sha3", +] + +[[package]] +name = "near-vm-logic" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81b534828419bacbf1f7b11ef7b00420f248c548c485d3f0cfda8bb6931152f2" +dependencies = [ + "base64 0.13.0", + "borsh", + "bs58", + "byteorder", + "near-account-id 0.14.0", + "near-crypto 0.14.0", + "near-primitives 0.14.0", + "near-primitives-core 0.14.0", + "near-vm-errors 0.14.0", + "ripemd", + "serde", + "sha2 0.10.6", + "sha3", + "zeropool-bn", +] + +[[package]] +name = "num-bigint" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-format" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc2a6559322ec7c5b7188ac5ca85865b187a46b03d30b00f0c0e3549eecadb1e" +dependencies = [ + "arrayvec 0.7.2", + "itoa", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_cpus" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" +dependencies = [ + "hermit-abi", + "libc", +] + +[[package]] +name = "object" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21158b2c33aa6d4561f1c0a6ea283ca92bc54802a93b263e910746d679a7eb53" +dependencies = [ + "memchr", +] + +[[package]] +name = "once_cell" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "openssl" +version = "0.10.42" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "openssl-probe" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" + +[[package]] +name = "openssl-sys" +version = "0.9.76" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" +dependencies = [ + "autocfg", + "cc", + "libc", + "pkg-config", + "vcpkg", +] + +[[package]] +name = "parity-scale-codec" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909" +dependencies = [ + "arrayvec 0.7.2", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27" +dependencies = [ + "proc-macro-crate 1.2.1", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "parity-secp256k1" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fca4f82fccae37e8bbdaeb949a4a218a1bbc485d11598f193d2a908042e5fc1" +dependencies = [ + "arrayvec 0.5.2", + "cc", + "cfg-if 0.1.10", + "rand 0.7.3", +] + +[[package]] +name = "parking" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09a279cbf25cb0757810394fbc1e359949b59e348145c643a939a525692e6929" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "windows-sys", +] + +[[package]] +name = "percent-encoding" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" + +[[package]] +name = "pin-project" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "pkg-config" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" + +[[package]] +name = "polling" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899b00b9c8ab553c743b3e11e87c5c7d423b2a2de229ba95b24a756344748011" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "libc", + "log", + "wepoll-ffi", + "winapi", +] + +[[package]] +name = "portpicker" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be97d76faf1bfab666e1375477b23fde79eccf0276e9b63b92a39d676a889ba9" +dependencies = [ + "rand 0.8.5", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "primitive-types" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" +dependencies = [ + "fixed-hash", + "impl-codec", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + +[[package]] +name = "proc-macro-crate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +dependencies = [ + "once_cell", + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro2" +version = "1.0.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[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 0.6.4", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "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.7", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +dependencies = [ + "rand_core 0.5.1", +] + +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom 0.1.16", + "redox_syscall 0.1.57", + "rust-argon2", +] + +[[package]] +name = "redox_users" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b033d837a7cf162d7993aded9304e30a83213c648b6e389db233191f891e5c2b" +dependencies = [ + "getrandom 0.2.7", + "redox_syscall 0.2.16", + "thiserror", +] + +[[package]] +name = "reed-solomon-erasure" +version = "4.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a415a013dd7c5d4221382329a5a3482566da675737494935cbbbcdec04662f9d" +dependencies = [ + "smallvec", +] + +[[package]] +name = "regex" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.6.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "reqwest" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" +dependencies = [ + "base64 0.13.0", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-tls", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "serde_urlencoded", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + +[[package]] +name = "ripemd" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd124222d17ad93a644ed9d011a40f4fb64aa54275c08cc216524a9ea82fb09f" +dependencies = [ + "digest 0.10.5", +] + +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64 0.13.0", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + +[[package]] +name = "rustc-demangle" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" + +[[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.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "rustversion" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97477e48b4cf8603ad5f7aaf897467cf42ab4218a38ef76fb14c2d6773a6d6a8" + +[[package]] +name = "ryu" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" + +[[package]] +name = "schannel" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2" +dependencies = [ + "lazy_static", + "windows-sys", +] + +[[package]] +name = "schemars" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a5fb6c61f29e723026dc8e923d94c694313212abbecbbe5f55a7748eec5b307" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f188d036977451159430f3b8dc82ec76364a42b7e289c2b18a9a18f4470058e9" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "scratch" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8132065adcfd6e02db789d9285a0deb2f3fcb04002865ab67d5fb103533898" + +[[package]] +name = "secp256k1" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7649a0b3ffb32636e60c7ce0d70511eda9c52c658cd0634e194d5a19943aeff" +dependencies = [ + "rand 0.8.5", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7058dc8eaf3f2810d7828680320acda0b25a288f6d288e19278e249bbf74226b" +dependencies = [ + "cc", +] + +[[package]] +name = "security-framework" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" +dependencies = [ + "bitflags", + "core-foundation", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + +[[package]] +name = "security-framework-sys" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0160a13a177a45bfb43ce71c01580998474f556ad854dcbca936dd2841a5c556" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "semver" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" + +[[package]] +name = "serde" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.145" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "serde_repr" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest 0.10.5", +] + +[[package]] +name = "sha3" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2904bea16a1ae962b483322a1c7b81d976029203aea1f461e51cd7705db7ba9" +dependencies = [ + "digest 0.10.5", + "keccak", +] + +[[package]] +name = "signal-hook" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +dependencies = [ + "libc", +] + +[[package]] +name = "signature" +version = "1.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" + +[[package]] +name = "siphasher" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b8de496cf83d4ed58b6be86c3a275b8602f6ffe98d3024a869e124147a9a3ac" + +[[package]] +name = "slab" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" +dependencies = [ + "autocfg", +] + +[[package]] +name = "smallvec" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" + +[[package]] +name = "smart-default" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "socket2" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "strum" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063e6045c0e62079840579a7e47a355ae92f60eb74daaf156fb1e84ba164e63f" +dependencies = [ + "strum_macros", +] + +[[package]] +name = "strum_macros" +version = "0.24.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "rustversion", + "syn", +] + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fcd952facd492f9be3ef0d0b7032a6e442ee9b361d4acc2b1d0c4aaa5f613a1" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "tar" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +dependencies = [ + "filetime", + "libc", + "xattr", +] + +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if 1.0.0", + "fastrand", + "libc", + "redox_syscall 0.2.16", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "thiserror" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "time" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +dependencies = [ + "libc", + "wasi 0.10.0+wasi-snapshot-preview1", + "winapi", +] + +[[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.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tokio" +version = "1.21.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" +dependencies = [ + "autocfg", + "bytes", + "libc", + "memchr", + "mio", + "num_cpus", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "winapi", +] + +[[package]] +name = "tokio-macros" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9724f9a975fb987ef7a3cd9be0350edcbe130698af5b8f7a631e23d42d052484" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-native-tls" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b" +dependencies = [ + "native-tls", + "tokio", +] + +[[package]] +name = "tokio-retry" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f57eb36ecbe0fc510036adff84824dd3c24bb781e21bfa67b69d556aa85214f" +dependencies = [ + "pin-project", + "rand 0.8.5", + "tokio", +] + +[[package]] +name = "tokio-util" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", + "tracing", +] + +[[package]] +name = "toml" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +dependencies = [ + "serde", +] + +[[package]] +name = "tower-service" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" + +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "uint" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a45526d29728d135c2900b0d30573fe3ee79fceb12ef534c7bb30e810a91b601" +dependencies = [ + "byteorder", + "crunchy", + "hex 0.4.3", + "static_assertions", +] + +[[package]] +name = "unicode-bidi" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" + +[[package]] +name = "unicode-ident" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" + +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "unicode-xid" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" + +[[package]] +name = "url" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +dependencies = [ + "form_urlencoded", + "idna 0.3.0", + "percent-encoding", + "serde", +] + +[[package]] +name = "uuid" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "feb41e78f93363bb2df8b0e86a2ca30eed7806ea16ea0c790d757cf93f79be83" +dependencies = [ + "getrandom 0.2.7", +] + +[[package]] +name = "validator" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "841d6937c33ec6039d8071bcf72933146b5bbe378d645d8fa59bdadabfc2a249" +dependencies = [ + "idna 0.2.3", + "lazy_static", + "regex", + "serde", + "serde_derive", + "serde_json", + "url", + "validator_types", +] + +[[package]] +name = "validator_types" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad9680608df133af2c1ddd5eaf1ddce91d60d61b6bc51494ef326458365a470a" + +[[package]] +name = "vcpkg" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "waker-fn" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d5b2c62b4012a3e1eca5a7e077d13b3bf498c4073e33ccd58626607748ceeca" + +[[package]] +name = "want" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +dependencies = [ + "log", + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" + +[[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.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" +dependencies = [ + "cfg-if 1.0.0", + "wasm-bindgen-macro", +] + +[[package]] +name = "wasm-bindgen-backend" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" +dependencies = [ + "bumpalo", + "log", + "once_cell", + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" +dependencies = [ + "cfg-if 1.0.0", + "js-sys", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "wasm-bindgen-backend", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" + +[[package]] +name = "web-sys" +version = "0.3.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[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 = "wepoll-ffi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +dependencies = [ + "cc", +] + +[[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-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[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.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "winreg" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +dependencies = [ + "winapi", +] + +[[package]] +name = "workspaces" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbc74416d48b2deb83004a0fff9d856e46a026c156da4acc4feca044a0a33755" +dependencies = [ + "async-process", + "async-trait", + "base64 0.13.0", + "borsh", + "bs58", + "chrono", + "dirs 3.0.2", + "hex 0.4.3", + "libc", + "near-account-id 0.15.0", + "near-crypto 0.15.0", + "near-jsonrpc-client", + "near-jsonrpc-primitives", + "near-primitives 0.15.0", + "near-sandbox-utils", + "portpicker", + "rand 0.8.5", + "reqwest", + "serde", + "serde_json", + "thiserror", + "tokio", + "tokio-retry", + "tracing", + "url", +] + +[[package]] +name = "wyz" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" + +[[package]] +name = "xattr" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" +dependencies = [ + "libc", +] + +[[package]] +name = "zeroize" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f8f187641dad4f680d25c4bfc4225b418165984179f26ca76ec4fb6441d3a17" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zeropool-bn" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71e61de68ede9ffdd69c01664f65a178c5188b73f78faa21f0936016a888ff7c" +dependencies = [ + "borsh", + "byteorder", + "crunchy", + "lazy_static", + "rand 0.8.5", + "rustc-hex", +] + +[[package]] +name = "zip" +version = "0.5.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93ab48844d61251bb3835145c521d88aa4031d7139e8485990f60ca911fa0815" +dependencies = [ + "byteorder", + "bzip2", + "crc32fast", + "flate2", + "thiserror", + "time", +] diff --git a/examples/multi-token/Cargo.toml b/examples/multi-token/Cargo.toml new file mode 100644 index 000000000..c27c7a27f --- /dev/null +++ b/examples/multi-token/Cargo.toml @@ -0,0 +1,37 @@ +[package] +name = "multi-token-wrapper" +version = "0.1.0" +authors = ["Near Inc ", "@jriemann", "doit.rant@gmail.com"] +edition = "2021" + +[dev-dependencies] +anyhow = "1.0" +near-primitives = "0.5.0" +near-contract-standards = { path = "../../near-contract-standards" } +near-sdk = "4.0.0-pre.6" +near-units = "0.2.0" +serde_json = "1.0" +tokio = { version = "1.14", features = ["full"] } +workspaces = "0.6.0" + +# remember to include a line for each contract +multi-token = { path = "./mt" } +defi = { path = "./test-contract-defi" } +approval-receiver = { path = "./test-approval-receiver" } + +[profile.release] +codegen-units = 1 +# Tell `rustc` to optimize for small code size. +opt-level = "z" +lto = true +debug = false +panic = "abort" +overflow-checks = true + +[workspace] +# remember to include a member for each contract +members = [ + "mt", + "test-contract-defi", + "test-approval-receiver", +] diff --git a/examples/multi-token/build.sh b/examples/multi-token/build.sh new file mode 100755 index 000000000..d339cb8b6 --- /dev/null +++ b/examples/multi-token/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash +TARGET="${CARGO_TARGET_DIR:-../../target}" +set -e +cd "$(dirname $0)" +cargo build --all --target wasm32-unknown-unknown --release +cp $TARGET/wasm32-unknown-unknown/release/defi.wasm ./res/ +cp $TARGET/wasm32-unknown-unknown/release/multi_token.wasm ./res/ +cp $TARGET/wasm32-unknown-unknown/release/approval_receiver.wasm ./res/ diff --git a/examples/multi-token/mt/Cargo.toml b/examples/multi-token/mt/Cargo.toml new file mode 100644 index 000000000..e25bcc918 --- /dev/null +++ b/examples/multi-token/mt/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "multi-token" +version = "1.1.0" +authors = ["Near Inc ", "@jriemann"] +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +near-sdk = { path = "../../../near-sdk" } +near-contract-standards = { path = "../../../near-contract-standards" } diff --git a/examples/multi-token/mt/src/lib.rs b/examples/multi-token/mt/src/lib.rs new file mode 100644 index 000000000..f4e7610d7 --- /dev/null +++ b/examples/multi-token/mt/src/lib.rs @@ -0,0 +1,476 @@ +use near_contract_standards::multi_token::metadata::MT_METADATA_SPEC; +use near_contract_standards::multi_token::token::{ClearedApproval, Token, TokenId}; +use near_contract_standards::multi_token::{ + core::MultiToken, + metadata::{MtContractMetadata, TokenMetadata}, +}; +use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::collections::LazyOption; +use near_sdk::json_types::U128; +use near_sdk::Promise; +use near_sdk::{ + env, near_bindgen, require, AccountId, BorshStorageKey, PanicOnDefault, PromiseOrValue, +}; + +#[near_bindgen] +#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] +pub struct ExampleMTContract { + tokens: MultiToken, + metadata: LazyOption, +} + +#[derive(BorshSerialize, BorshStorageKey)] +enum StorageKey { + MultiToken, + Metadata, + TokenMetadata, + Enumeration, + Approval, + TokenHolders, +} + +#[near_bindgen] +impl ExampleMTContract { + #[init] + pub fn new_default_meta(owner_id: AccountId) -> Self { + let metadata = MtContractMetadata { + spec: MT_METADATA_SPEC.to_string(), + name: "Example NEAR multi token".to_string(), + symbol: "EXAMPLE".to_string(), + icon: None, + base_uri: None, + reference: None, + reference_hash: None, + }; + + Self::new(owner_id, metadata) + } + + #[init] + pub fn new(owner_id: AccountId, metadata: MtContractMetadata) -> Self { + metadata.assert_valid(); + + Self { + tokens: MultiToken::new( + StorageKey::MultiToken, + owner_id, + Some(StorageKey::TokenMetadata), + Some(StorageKey::Enumeration), + Some(StorageKey::Approval), + Some(StorageKey::TokenHolders), + ), + metadata: LazyOption::new(StorageKey::Metadata, Some(&metadata)), + } + } + + #[payable] + pub fn mt_mint( + &mut self, + token_owner_id: AccountId, + token_metadata: TokenMetadata, + supply: U128, + ) -> Token { + // Only the owner of the MT contract can perform this operation + assert_eq!( + env::predecessor_account_id(), + self.tokens.owner_id, + "Unauthorized: {} != {}", + env::predecessor_account_id(), + self.tokens.owner_id + ); + self.tokens.internal_mint(token_owner_id, Some(supply.into()), Some(token_metadata), None) + } +} + +near_contract_standards::impl_multi_token_core!(ExampleMTContract, tokens); +near_contract_standards::impl_multi_token_approval!(ExampleMTContract, tokens); +near_contract_standards::impl_multi_token_enumeration!(ExampleMTContract, tokens); +near_contract_standards::impl_multi_token_storage!(ExampleMTContract, tokens); +near_contract_standards::impl_multi_token_holders!(ExampleMTContract, tokens); + +#[cfg(all(test, not(target_arch = "wasm32")))] +mod tests { + use super::*; + use near_sdk::test_utils::{accounts, VMContextBuilder}; + use near_sdk::testing_env; + + fn create_token_md(title: String, description: String) -> TokenMetadata { + TokenMetadata { + title: Some(title), + description: Some(description), + media: None, + media_hash: None, + issued_at: None, + expires_at: None, + starts_at: None, + updated_at: None, + extra: None, + reference: None, + reference_hash: None, + } + } + + #[test] + fn test_transfer() { + let mut context = VMContextBuilder::new(); + set_caller(&mut context, 0); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + let (token, _) = init_tokens(&mut contract); + + // check that the token is held by the owner + assert!(contract + .mt_token_holders(token.token_id.clone(), None, None) + .contains(&accounts(0))); + + // Initial balances are what we expect. + assert_eq!( + contract.mt_balance_of(accounts(0), token.token_id.clone()), + U128(1000), + "Wrong balance" + ); + assert_eq!( + contract.mt_balance_of(accounts(1), token.token_id.clone()), + U128(0), + "Wrong balance" + ); + + // Transfer some tokens + testing_env!(context.attached_deposit(1).build()); + // emulate storage_deposit + contract + .tokens + .accounts_storage + .insert(&accounts(1), &contract.tokens.storage_balance_bounds().min.into()); + + contract.mt_transfer(accounts(1), token.token_id.clone(), 4.into(), None, None); + + // Transfer should have succeeded. + assert_eq!( + contract.mt_balance_of(accounts(0), token.token_id.clone()).0, + 996, + "Wrong balance" + ); + assert_eq!( + contract.mt_balance_of(accounts(1), token.token_id.clone()).0, + 4, + "Wrong balance" + ); + + // Transfer some of the tokens back to original owner. + set_caller(&mut context, 1); + + contract.mt_transfer(accounts(0), token.token_id.clone(), 3.into(), None, None); + + assert_eq!( + contract.mt_balance_of(accounts(0), token.token_id.clone()).0, + 999, + "Wrong balance" + ); + assert_eq!( + contract.mt_balance_of(accounts(1), token.token_id.clone()).0, + 1, + "Wrong balance" + ); + + // check that account(1) now is holder of the token + let holders = contract.mt_token_holders(token.token_id.clone(), None, None); + assert!(holders.contains(&accounts(0))); + assert!(holders.contains(&accounts(1))); + + set_caller(&mut context, 1); + contract.mt_transfer(accounts(0), token.token_id.clone(), 1.into(), None, None); + + // check that account(1) is no longer holder of the token + assert!(contract + .mt_token_holders(token.token_id.clone(), None, None) + .contains(&accounts(0))); + assert!(!contract + .mt_token_holders(token.token_id.clone(), None, None) + .contains(&accounts(1))); + } + + #[test] + #[should_panic(expected = "Transferred amounts must be greater than 0")] + fn test_transfer_amount_must_be_positive() { + let mut context = VMContextBuilder::new(); + set_caller(&mut context, 0); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + let (token, _) = init_tokens(&mut contract); + testing_env!(context.attached_deposit(1).build()); + contract + .tokens + .accounts_storage + .insert(&accounts(1), &contract.tokens.storage_balance_bounds().min.into()); + contract.mt_transfer(accounts(1), token.token_id.clone(), U128(0), None, None) + } + + #[test] + #[should_panic(expected = "No approvals for token 1")] + fn test_transfer_no_approvals_for_account() { + let mut context = VMContextBuilder::new(); + set_caller(&mut context, 0); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + let (token, _) = init_tokens(&mut contract); + contract + .tokens + .accounts_storage + .insert(&accounts(1), &contract.tokens.storage_balance_bounds().min.into()); + + testing_env!(context.attached_deposit(1).build()); + contract.mt_transfer( + accounts(1), + token.token_id.clone(), + U128(1), + Some((accounts(0), 1)), + None, + ) + } + + #[test] + #[should_panic(expected = "The account doesn't have enough balance")] + fn test_sender_account_must_have_sufficient_balance() { + let mut context = VMContextBuilder::new(); + set_caller(&mut context, 0); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + let (token, _) = init_tokens(&mut contract); + testing_env!(context.attached_deposit(1).build()); + contract + .tokens + .accounts_storage + .insert(&accounts(1), &contract.tokens.storage_balance_bounds().min.into()); + // account(0) has only 2000 of token. + contract.mt_transfer(accounts(1), token.token_id.clone(), U128(3000), None, None) + } + + #[test] + #[should_panic(expected = "Requires attached deposit of exactly 1 yoctoNEAR")] + fn test_transfers_require_one_yocto() { + let mut context = VMContextBuilder::new(); + set_caller(&mut context, 0); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + let (token, _) = init_tokens(&mut contract); + contract + .tokens + .accounts_storage + .insert(&accounts(1), &contract.tokens.storage_balance_bounds().min.into()); + contract.mt_transfer(accounts(1), token.token_id.clone(), U128(1000), None, None) + } + + #[test] + #[should_panic(expected = "The account is not registered")] + fn test_receiver_must_be_registered() { + let mut context = VMContextBuilder::new(); + set_caller(&mut context, 0); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + let (token, _) = init_tokens(&mut contract); + testing_env!(context.attached_deposit(1).build()); + contract.mt_transfer(accounts(2), token.token_id.clone(), U128(100), None, None) + } + + #[test] + #[should_panic(expected = "Sender and receiver must differ")] + fn test_cannot_transfer_to_self() { + let mut context = VMContextBuilder::new(); + set_caller(&mut context, 0); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + let (token, _) = init_tokens(&mut contract); + testing_env!(context.attached_deposit(1).build()); + contract.mt_transfer(accounts(0), token.token_id.clone(), U128(100), None, None) + } + + #[test] + fn test_batch_transfer() { + let mut context = VMContextBuilder::new(); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + set_caller(&mut context, 0); + + let (quote_token, base_token) = init_tokens(&mut contract); + + testing_env!(context.attached_deposit(1).build()); + + contract + .tokens + .accounts_storage + .insert(&accounts(1), &(contract.tokens.storage_balance_bounds().min.0 * 2)); + // Perform the transfers + contract.mt_batch_transfer( + accounts(1), + vec![quote_token.token_id.clone(), base_token.token_id.clone()], + vec![U128(4), U128(600)], + None, + None, + ); + + assert_eq!( + contract.mt_balance_of(accounts(0), quote_token.token_id.clone()).0, + 996, + "Wrong balance" + ); + assert_eq!( + contract.mt_balance_of(accounts(1), quote_token.token_id.clone()).0, + 4, + "Wrong balance" + ); + + assert_eq!( + contract.mt_balance_of(accounts(0), base_token.token_id.clone()).0, + 1400, + "Wrong balance" + ); + assert_eq!( + contract.mt_balance_of(accounts(1), base_token.token_id.clone()).0, + 600, + "Wrong balance" + ); + } + + #[test] + #[should_panic(expected = "The account doesn't have enough balance")] + fn test_batch_transfer_all_balances_must_be_sufficient() { + let mut context = VMContextBuilder::new(); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + set_caller(&mut context, 0); + + let (quote_token, base_token) = init_tokens(&mut contract); + + testing_env!(context.attached_deposit(1).build()); + contract + .tokens + .accounts_storage + .insert(&accounts(1), &(contract.tokens.storage_balance_bounds().min.0 * 2)); + contract.mt_batch_transfer( + accounts(1), + vec![quote_token.token_id.clone(), base_token.token_id.clone()], + vec![U128(4), U128(6000)], + None, + None, + ); + } + + #[test] + fn test_simple_approvals() { + let mut context = VMContextBuilder::new(); + let mut contract = ExampleMTContract::new_default_meta(accounts(0)); + set_caller(&mut context, 0); + + let (quote_token, base_token) = init_tokens(&mut contract); + + let owner_id = accounts(0); + + // Initially, Account 1 is not approved. + testing_env!(context.attached_deposit(1).build()); + assert!(!contract.mt_is_approved( + owner_id.clone(), + vec![quote_token.token_id.clone()], + accounts(1), + vec![U128(20)], + None, + )); + + // Create approval for account 1 to transfer 20 of quote token from account 0. + testing_env!(context.attached_deposit(150000000000000000000).build()); + contract.mt_approve(vec![quote_token.token_id.clone()], vec![U128(20)], accounts(1), None); + + // Account 1 is approved for 20 tokens. + testing_env!(context.attached_deposit(1).build()); + assert!(contract.mt_is_approved( + owner_id.clone(), + vec![quote_token.token_id.clone()], + accounts(1), + vec![U128(20)], + None, + )); + + // Account 1 is NOT approved for more than 20 tokens. + testing_env!(context.attached_deposit(1).build()); + assert!(!contract.mt_is_approved( + owner_id.clone(), + vec![quote_token.token_id.clone()], + accounts(1), + vec![U128(21)], + None, + )); + + // Account 1 is NOT approved for the other token. + testing_env!(context.attached_deposit(1).build()); + assert!(!contract.mt_is_approved( + owner_id.clone(), + vec![base_token.token_id.clone()], + accounts(1), + vec![U128(20)], + None, + )); + + // Revoke the approval + contract.mt_revoke(vec![quote_token.token_id.clone()], accounts(1)); + assert!(!contract.mt_is_approved( + owner_id.clone(), + vec![quote_token.token_id.clone()], + accounts(1), + vec![U128(20)], + None, + )); + + // Create 2 approvals for 2 tokens in one call. + testing_env!(context.attached_deposit(2 * 150000000000000000000).build()); + contract.mt_approve( + vec![quote_token.token_id.clone(), base_token.token_id.clone()], + vec![U128(10), U128(500)], + accounts(1), + None, + ); + assert!(contract.mt_is_approved( + owner_id.clone(), + vec![quote_token.token_id.clone(), base_token.token_id.clone()], + accounts(1), + vec![U128(10), U128(500)], + None, + )); + + // Approve a different account + contract.mt_approve(vec![quote_token.token_id.clone()], vec![U128(30)], accounts(2), None); + + // Revoke all approvals for the quote token + testing_env!(context.attached_deposit(1).build()); + contract.mt_revoke_all(vec![quote_token.token_id.clone()]); + + // Neither account is still approved + assert!(!contract.mt_is_approved( + owner_id.clone(), + vec![quote_token.token_id.clone(), base_token.token_id.clone()], + accounts(1), + vec![U128(10), U128(500)], + None, + )); + assert!(!contract.mt_is_approved( + owner_id.clone(), + vec![quote_token.token_id.clone()], + accounts(2), + vec![U128(30)], + None, + )); + } + + fn init_tokens(contract: &mut ExampleMTContract) -> (Token, Token) { + let quote_token_md = create_token_md("PYC".into(), "Python token".into()); + let base_token_md = create_token_md("ABC".into(), "Alphabet token".into()); + + // emulate storage_deposit + contract + .tokens + .accounts_storage + .insert(&accounts(0), &(contract.tokens.storage_balance_bounds().min.0 * 2)); + + let quote_token = contract.mt_mint(accounts(0), quote_token_md.clone(), U128(1000)); + let base_token = contract.mt_mint(accounts(0), base_token_md.clone(), U128(2000)); + + (quote_token, base_token) + } + + fn set_caller(context: &mut VMContextBuilder, account_id: usize) { + testing_env!(context + .signer_account_id(accounts(account_id)) + .predecessor_account_id(accounts(account_id)) + .build()) + } +} diff --git a/examples/multi-token/res/.gitignore b/examples/multi-token/res/.gitignore new file mode 100644 index 000000000..fae4549b6 --- /dev/null +++ b/examples/multi-token/res/.gitignore @@ -0,0 +1,5 @@ +# Ignore all files +* + +# Except this to keep the directory +!.gitignore \ No newline at end of file diff --git a/examples/multi-token/test-approval-receiver/Cargo.toml b/examples/multi-token/test-approval-receiver/Cargo.toml new file mode 100644 index 000000000..5b1b8f3d9 --- /dev/null +++ b/examples/multi-token/test-approval-receiver/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "approval-receiver" +version = "0.1.0" +authors = ["Near Inc "] +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +near-sdk = { path = "../../../near-sdk" } +near-contract-standards = { path = "../../../near-contract-standards" } diff --git a/examples/multi-token/test-approval-receiver/src/lib.rs b/examples/multi-token/test-approval-receiver/src/lib.rs new file mode 100644 index 000000000..20c3d5126 --- /dev/null +++ b/examples/multi-token/test-approval-receiver/src/lib.rs @@ -0,0 +1,43 @@ +use near_contract_standards::multi_token::{approval::MultiTokenApprovalReceiver, token::TokenId}; +use near_sdk::{ + borsh::{self, BorshDeserialize, BorshSerialize}, + json_types::U128, + log, near_bindgen, AccountId, PanicOnDefault, PromiseOrValue, +}; + +pub const ON_MT_TOKEN_APPROVE_MSG: &str = "on_multi_token_approve"; + +#[near_bindgen] +#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] +pub struct Contract {} + +#[near_bindgen] +impl Contract { + #[init] + pub fn new() -> Self { + Self {} + } +} + +#[near_bindgen] +impl MultiTokenApprovalReceiver for Contract { + fn mt_on_approve( + &mut self, + tokens: Vec, + amounts: Vec, + owner_id: AccountId, + approval_ids: Vec, + msg: String, + ) -> PromiseOrValue { + log!( + "Tokens: {:?} Amounts: {:?} Owner: {}, approval_ids: {:?}", + tokens, + amounts, + owner_id, + approval_ids + ); + log!(&msg); + + PromiseOrValue::Value(ON_MT_TOKEN_APPROVE_MSG.to_string()) + } +} diff --git a/examples/multi-token/test-contract-defi/Cargo.toml b/examples/multi-token/test-contract-defi/Cargo.toml new file mode 100644 index 000000000..51edfe078 --- /dev/null +++ b/examples/multi-token/test-contract-defi/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "defi" +version = "0.0.1" +authors = ["Near Inc "] +edition = "2021" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +near-sdk = { path = "../../../near-sdk" } +near-contract-standards = { path = "../../../near-contract-standards" } diff --git a/examples/multi-token/test-contract-defi/src/lib.rs b/examples/multi-token/test-contract-defi/src/lib.rs new file mode 100644 index 000000000..5dab2884a --- /dev/null +++ b/examples/multi-token/test-contract-defi/src/lib.rs @@ -0,0 +1,97 @@ +/*! +Some hypothetical DeFi contract that will do smart things with the transferred tokens +*/ +use near_contract_standards::multi_token::core::MultiTokenReceiver; +use near_contract_standards::multi_token::token::TokenId; +use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::json_types::U128; +use near_sdk::{ + env, log, near_bindgen, require, AccountId, Balance, Gas, PanicOnDefault, PromiseOrValue, +}; + +const BASE_GAS: u64 = 5_000_000_000_000; +const PROMISE_CALL: u64 = 5_000_000_000_000; +const GAS_FOR_MT_ON_TRANSFER: Gas = Gas(BASE_GAS + PROMISE_CALL); + +#[near_bindgen] +#[derive(BorshDeserialize, BorshSerialize, PanicOnDefault)] +pub struct DeFi { + multi_token_account_id: AccountId, +} + +// Have to repeat the same trait for our own implementation. +trait ValueReturnTrait { + fn value_please( + &self, + num_tokens: usize, + amount_to_return: String, + ) -> PromiseOrValue>; +} + +#[near_bindgen] +impl DeFi { + #[init] + pub fn new(multi_token_account_id: AccountId) -> Self { + Self { multi_token_account_id } + } +} + +#[near_bindgen] +impl MultiTokenReceiver for DeFi { + /// If given `msg: "take-my-money", immediately returns U128::From(0) + /// Otherwise, makes a cross-contract call to own `value_please` function, passing `msg` + /// value_please will attempt to parse `msg` as an integer and return a vec of + /// token_ids.len() many copies of the U128 version of it. + fn mt_on_transfer( + &mut self, + sender_id: AccountId, + previous_owner_ids: Vec, + token_ids: Vec, + amounts: Vec, + msg: String, + ) -> PromiseOrValue> { + // Verifying that we were called by multi-token contract that we expect. + require!( + env::predecessor_account_id() == self.multi_token_account_id, + "Only supports the one multi-token contract" + ); + + log!( + "received {} types of tokens from @{} mt_on_transfer, msg = {}, previous_owner_ids = {:?}", + token_ids.len(), + sender_id.as_ref(), + msg, + previous_owner_ids + ); + + for (token_id, amount) in token_ids.iter().zip(amounts) { + log!("-> {} of token {}", token_id, amount.0); + } + + match msg.as_str() { + "take-my-money" => PromiseOrValue::Value(vec![U128::from(0); token_ids.len()]), + "fail" => env::panic_str("simulating failure"), + _ => { + let prepaid_gas = env::prepaid_gas(); + let account_id = env::current_account_id(); + Self::ext(account_id) + .with_static_gas(prepaid_gas - GAS_FOR_MT_ON_TRANSFER) + .value_please(token_ids.len(), msg) + .into() + } + } + } +} + +#[near_bindgen] +impl ValueReturnTrait for DeFi { + fn value_please( + &self, + num_tokens: usize, + amount_to_return: String, + ) -> PromiseOrValue> { + log!("in value_please, amount_to_return = {}", amount_to_return); + let amount: Balance = amount_to_return.parse().expect("Not an integer"); + PromiseOrValue::Value(vec![amount.into(); num_tokens]) + } +} diff --git a/examples/multi-token/tests/workspaces/main.rs b/examples/multi-token/tests/workspaces/main.rs new file mode 100644 index 000000000..5971a6fe2 --- /dev/null +++ b/examples/multi-token/tests/workspaces/main.rs @@ -0,0 +1,4 @@ +mod test_approval; +mod test_enumeration; +mod test_transfer; +mod utils; diff --git a/examples/multi-token/tests/workspaces/test_approval.rs b/examples/multi-token/tests/workspaces/test_approval.rs new file mode 100644 index 000000000..a1cad8c3c --- /dev/null +++ b/examples/multi-token/tests/workspaces/test_approval.rs @@ -0,0 +1,272 @@ +#[cfg(test)] +mod tests { + use approval_receiver::ON_MT_TOKEN_APPROVE_MSG; + use near_contract_standards::multi_token::token::Token; + use near_sdk::json_types::U128; + use near_sdk::ONE_YOCTO; + use workspaces::AccountId; + + use crate::utils::{ + get_storage_balance_bounds, helper_mint, init, init_approval_receiver_contract, + register_user_for_token, + }; + + #[tokio::test] + async fn simulate_mt_approval_with_receiver() -> anyhow::Result<()> { + let worker = workspaces::sandbox().await?; + let (mt, alice, _, _) = init(&worker).await?; + let approval_receiver = init_approval_receiver_contract(&worker).await?; + + let token: Token = helper_mint( + &mt, + alice.id().clone(), + 1000u128, + "title1".to_string(), + "desc1".to_string(), + ) + .await?; + + // Grant approval_receiver contract an approval to take 50 of alice's tokens. + let res = alice + .call(mt.id(), "mt_approve") + .args_json(( + [token.token_id.clone()], + [U128(50)], + approval_receiver.id(), + Option::::Some("some-msg".to_string()), + )) + .max_gas() + .deposit(450000000000000000000) + .transact() + .await? + .json::()?; + assert_eq!(res, ON_MT_TOKEN_APPROVE_MSG.to_string()); + + Ok(()) + } + + #[tokio::test] + async fn test_approval_after_failed_mt_transfer_call() -> anyhow::Result<()> { + let worker = workspaces::sandbox().await?; + let (mt, alice, _, defi) = init(&worker).await?; + + let token: Token = helper_mint( + &mt, + alice.id().clone(), + 1000u128, + "title1".to_string(), + "desc1".to_string(), + ) + .await?; + + register_user_for_token(&mt, defi.id(), get_storage_balance_bounds(&mt).await?.min.into()) + .await?; + + register_user_for_token(&mt, alice.id(), get_storage_balance_bounds(&mt).await?.min.into()) + .await?; + + let approve_amount = 50; + // approve defi to take 50 of alice's tokens. + let res = alice + .call(mt.id(), "mt_approve") + .args_json(( + [token.token_id.clone()], + [U128(approve_amount)], + defi.id(), + Option::::None, + )) + .max_gas() + .deposit(450000000000000000000) + .transact() + .await?; + assert!(res.is_success()); + + let is_approved: bool = mt + .call("mt_is_approved") + .args_json(( + alice.id(), + [token.token_id.clone()], + defi.id(), + [U128(approve_amount)], + Option::>::None, + )) + .view() + .await? + .json()?; + + assert!(is_approved); + + let _ = defi + .as_account() + .call(mt.id(), "mt_transfer_call") + .args_json(( + defi.id(), + token.token_id.clone(), + "50", + Option::<(AccountId, u64)>::Some((alice.id().clone(), 0)), + Option::::None, + "fail", + )) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await?; + + let is_approved: bool = mt + .call("mt_is_approved") + .args_json(( + alice.id(), + [token.token_id.clone()], + defi.id(), + [U128(approve_amount)], + Option::>::None, + )) + .view() + .await? + .json()?; + + assert!(is_approved); + + Ok(()) + } + + /** + In this test we simulate the following scenario: + 1. Alice grants approval to defi contract to take 500 of token_1. + 2. Bob grants approval to defi contract to take 1000 of token_2. + 3. Defi contract transfers 500 of token_1 and 900 of token_2 and fails. + 4. We check that Alice's and Bob's approvals is still valid for 500 and 1000 tokens. + */ + #[tokio::test] + async fn test_approval_after_failed_mt_batch_transfer_call() -> anyhow::Result<()> { + let worker = workspaces::sandbox().await?; + let (mt, alice, bob, defi) = init(&worker).await?; + + let token_1: Token = helper_mint( + &mt, + alice.id().clone(), + 500u128, + "token_1".to_string(), + "desc".to_string(), + ) + .await?; + let token_2: Token = + helper_mint(&mt, bob.id().clone(), 1000u128, "token_2".to_string(), "desc".to_string()) + .await?; + + register_user_for_token(&mt, defi.id(), get_storage_balance_bounds(&mt).await?.min.0 * 2) + .await?; + + register_user_for_token(&mt, alice.id(), get_storage_balance_bounds(&mt).await?.min.into()) + .await?; + + register_user_for_token(&mt, bob.id(), get_storage_balance_bounds(&mt).await?.min.into()) + .await?; + + // approve defi to take 500 of alice's tokens. + let alice_approve_amount = 500; + let res = alice + .call(mt.id(), "mt_approve") + .args_json(( + [token_1.token_id.clone()], + [U128(alice_approve_amount)], + defi.id(), + Option::::None, + )) + .max_gas() + .deposit(450000000000000000000) + .transact() + .await?; + assert!(res.is_success()); + + // approve defi to take 1000 of bob's tokens. + let bob_approve_amount = 1000; + let res = bob + .call(mt.id(), "mt_approve") + .args_json(( + [token_2.token_id.clone()], + [U128(bob_approve_amount)], + defi.id(), + Option::::None, + )) + .max_gas() + .deposit(450000000000000000000) + .transact() + .await?; + assert!(res.is_success()); + + let is_approved: bool = mt + .call("mt_is_approved") + .args_json(( + alice.id(), + [token_1.token_id.clone()], + defi.id(), + [U128(alice_approve_amount)], + Option::>::None, + )) + .view() + .await? + .json()?; + assert!(is_approved); + + let is_approved: bool = mt + .call("mt_is_approved") + .args_json(( + bob.id(), + [token_2.token_id.clone()], + defi.id(), + [U128(bob_approve_amount)], + Option::>::None, + )) + .view() + .await? + .json()?; + assert!(is_approved); + + let _ = defi + .as_account() + .call(mt.id(), "mt_batch_transfer_call") + .args_json(( + defi.id(), + [token_1.token_id.clone(), token_2.token_id.clone()], + ["500", "900"], // from bob we will take 900, when he has 1000 + Option::<(AccountId, u64)>::None, + Option::::None, + "fail", // DeFi contract will rollback the transfer + )) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await?; + + let is_approved: bool = mt + .call("mt_is_approved") + .args_json(( + alice.id(), + [token_1.token_id.clone()], + defi.id(), + [U128(alice_approve_amount)], + Option::>::None, + )) + .view() + .await? + .json()?; + assert!(is_approved); + + let is_approved: bool = mt + .call("mt_is_approved") + .args_json(( + bob.id(), + [token_2.token_id.clone()], + defi.id(), + [U128(bob_approve_amount)], + Option::>::None, + )) + .view() + .await? + .json()?; + assert!(is_approved); + + Ok(()) + } +} diff --git a/examples/multi-token/tests/workspaces/test_enumeration.rs b/examples/multi-token/tests/workspaces/test_enumeration.rs new file mode 100644 index 000000000..ec0136580 --- /dev/null +++ b/examples/multi-token/tests/workspaces/test_enumeration.rs @@ -0,0 +1,119 @@ +#[cfg(test)] +mod tests { + use crate::utils::{helper_mint, init}; + use near_contract_standards::multi_token::token::Token; + use near_sdk::json_types::U128; + + #[tokio::test] + async fn simulate_enum_all_tokens() -> anyhow::Result<()> { + let worker = workspaces::sandbox().await?; + let (mt, alice, _, _) = init(&worker).await?; + + // Mint 3 tokens + let token_1: Token = helper_mint( + &mt, + alice.id().clone(), + 1000u128, + "title1".to_string(), + "desc1".to_string(), + ) + .await?; + let token_2: Token = helper_mint( + &mt, + alice.id().clone(), + 20_000u128, + "title2".to_string(), + "desc2".to_string(), + ) + .await?; + let token_3: Token = + helper_mint(&mt, alice.id().clone(), 5u128, "title3".to_string(), "desc3".to_string()) + .await?; + + // Get all tokens + let res: Vec = mt + .call("mt_tokens") + .args_json((Option::::None, Option::::None)) + .view() + .await? + .json()?; + assert_eq!(res, vec![token_1.clone(), token_2.clone(), token_3.clone()]); + + // Get tokens from_index=1, limit=None + let res: Vec = mt + .call("mt_tokens") + .args_json((Some(U128(1)), Option::::None)) + .view() + .await? + .json()?; + assert_eq!(res, vec![token_2.clone(), token_3.clone()]); + + // Get tokens from_index=None, limit=2 + let res: Vec = mt + .call("mt_tokens") + .args_json((Option::::None, Some(2u64))) + .view() + .await? + .json()?; + assert_eq!(res, vec![token_1.clone(), token_2.clone()]); + + // Get tokens from_index=2, limit=1 + let res: Vec = + mt.call("mt_tokens").args_json((Some(U128(2)), Some(1u64))).view().await?.json()?; + assert_eq!(res, vec![token_3.clone()]); + + Ok(()) + } + + #[tokio::test] + async fn simulate_enum_tokens_for_owner() -> anyhow::Result<()> { + let worker = workspaces::sandbox().await?; + let (mt, alice, _, defi) = init(&worker).await?; + + // Mint 5 tokens, alternating ownership between alice and the defi contract account. + let token_1: Token = helper_mint( + &mt, + alice.id().clone(), + 1000u128, + "title1".to_string(), + "desc1".to_string(), + ) + .await?; + helper_mint(&mt, defi.id().clone(), 20_000u128, "title2".to_string(), "desc2".to_string()) + .await?; + let token_3: Token = + helper_mint(&mt, alice.id().clone(), 5u128, "title3".to_string(), "desc3".to_string()) + .await?; + let token_4: Token = helper_mint( + &mt, + defi.id().clone(), + 20_000u128, + "title4".to_string(), + "desc4".to_string(), + ) + .await?; + let token_5: Token = + helper_mint(&mt, alice.id().clone(), 5u128, "title5".to_string(), "desc5".to_string()) + .await?; + + // Get all tokens for a specific owner, alice. + let res: Vec = mt + .call("mt_tokens_for_owner") + .args_json((alice.id().clone(), Option::::None, Option::::None)) + .view() + .await? + .json()?; + assert_eq!(res, vec![token_1.clone(), token_3.clone(), token_5.clone()]); + + // Get limit=None tokens at from_index=1 for defi account. + let res: Vec = mt + .call("mt_tokens_for_owner") + .args_json((defi.id().clone(), Some(U128(1)), Option::::None)) + .view() + .await? + .json()?; + assert_eq!(res, vec![token_4.clone()]); + + Ok(()) + } +} diff --git a/examples/multi-token/tests/workspaces/test_transfer.rs b/examples/multi-token/tests/workspaces/test_transfer.rs new file mode 100644 index 000000000..89b430cb8 --- /dev/null +++ b/examples/multi-token/tests/workspaces/test_transfer.rs @@ -0,0 +1,256 @@ +#[cfg(test)] +mod tests { + use near_contract_standards::multi_token::token::Token; + use near_sdk::json_types::U128; + use near_sdk::ONE_YOCTO; + use near_units::parse_near; + use workspaces::AccountId; + + use crate::utils::{get_storage_balance_bounds, helper_mint, init, register_user_for_token}; + + #[tokio::test] + async fn simulate_mt_transfer_with_approval() -> anyhow::Result<()> { + let worker = workspaces::sandbox().await?; + let (mt, alice, bob, _) = init(&worker).await?; + + let charlie = mt + .as_account() + .create_subaccount("charlie") + .initial_balance(parse_near!("10 N")) + .transact() + .await? + .into_result()?; + + let token: Token = helper_mint( + &mt, + alice.id().clone(), + 1000u128, + "title1".to_string(), + "desc1".to_string(), + ) + .await?; + + // Grant bob an approval to take 50 of alice's tokens. + let _ = alice + .call(mt.id(), "mt_approve") + .args_json(([token.token_id.clone()], [U128(50)], bob.id(), Option::::None)) + .max_gas() + .deposit(490000000000000000000) + .transact() + .await?; + + register_user_for_token( + &mt, + charlie.id(), + get_storage_balance_bounds(&mt).await?.min.into(), + ) + .await?; + + // Bob tries to transfer 50 tokens to charlie + let res = bob + .call(mt.id(), "mt_transfer") + .args_json(( + charlie.id(), + token.token_id.clone(), + "50", + Option::<(AccountId, u64)>::Some((alice.id().clone(), 0)), + Option::::None, + )) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await?; + + assert!(res.is_success()); + + // Bob tries to transfer 50 tokens to charlie, but fails because of insufficient approval. + let res = bob + .call(mt.id(), "mt_transfer") + .args_json(( + charlie.id(), + token.token_id.clone(), + "50", + Option::<(AccountId, u64)>::Some((alice.id().clone(), 0)), + Option::::None, + )) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await?; + + assert!(res.is_failure()); + + Ok(()) + } + + #[tokio::test] + async fn simulate_mt_transfer_wrong_approval() -> anyhow::Result<()> { + let worker = workspaces::sandbox().await?; + let (mt, alice, bob, _) = init(&worker).await?; + + let charlie = mt + .as_account() + .create_subaccount("charlie") + .initial_balance(parse_near!("10 N")) + .transact() + .await? + .into_result()?; + + let token: Token = helper_mint( + &mt, + alice.id().clone(), + 1000u128, + "title1".to_string(), + "desc1".to_string(), + ) + .await?; + + // Grant bob an approval to take 50 of alice's tokens. + let _ = alice + .call(mt.id(), "mt_approve") + .args_json(([token.token_id.clone()], [U128(50)], bob.id(), Option::::None)) + .max_gas() + .deposit(490000000000000000000) + .transact() + .await?; + + // register charlie + let _ = charlie + .call(mt.id(), "register") + .args_json((token.token_id.clone(), charlie.id())) + .max_gas() + .transact() + .await?; + + // charlie tries to transfer 50 tokens to himself, but fails because of wrong approval. + let res = charlie + .call(mt.id(), "mt_transfer") + .args_json(( + charlie.id(), + token.token_id.clone(), + "50", + Option::<(AccountId, u64)>::Some((alice.id().clone(), 0)), + Option::::None, + )) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await?; + + println!("res = {:?}", res); + assert!(res.is_failure()); + + Ok(()) + } + + #[tokio::test] + async fn simulate_mt_transfer_and_call() -> anyhow::Result<()> { + // Setup MT contract, user, and DeFi contract. + let worker = workspaces::sandbox().await?; + let (mt, alice, _, defi) = init(&worker).await?; + + // Mint 2 tokens. + let token_1: Token = helper_mint( + &mt, + alice.id().clone(), + 1000u128, + "title1".to_string(), + "desc1".to_string(), + ) + .await?; + let token_2: Token = helper_mint( + &mt, + alice.id().clone(), + 20_000u128, + "title2".to_string(), + "desc2".to_string(), + ) + .await?; + + // Register defi account; alice (the token owner) was already registered during the mint. + register_user_for_token(&mt, defi.id(), get_storage_balance_bounds(&mt).await?.min.into()) + .await?; + + // Transfer some tokens using transfer_and_call to hit DeFi contract with XCC. + let res = alice + .call(mt.id(), "mt_transfer_call") + .args_json(( + defi.id(), + token_1.token_id.clone(), + "100", + Option::<(AccountId, u64)>::None, + Option::::None, + "30", // Number of tokens that the DeFi contract should refund. + )) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await?; + assert!(res.is_success()); + let amounts_kept: Vec = res.json()?; + assert_eq!(amounts_kept, vec![U128(70)]); + + let alice_balance: Vec = mt + .call("mt_batch_balance_of") + .args_json((alice.id(), vec![token_1.token_id.clone()])) + .view() + .await? + .json()?; + assert_eq!(alice_balance, vec![U128(930)]); + + let defi_balance: Vec = mt + .call("mt_batch_balance_of") + .args_json((defi.id(), vec![token_1.token_id.clone()])) + .view() + .await? + .json()?; + assert_eq!(defi_balance, vec![U128(70)]); + + // Next, do a batch transfer call, and use special msg 'take-my-money' so DeFi contract refunds nothing. + let res = alice + .call(mt.id(), "mt_batch_transfer_call") + .args_json(( + defi.id(), + [token_1.token_id.clone(), token_2.token_id.clone()], + ["100", "5000"], + Option::<(AccountId, u64)>::None, + Option::::None, + "take-my-money", // DeFi contract will keep all sent tokens. + )) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await?; + assert!(res.is_success()); + + // Attempt a transfer where DeFi contract will panic. Token transfer should be reverted in the callback. + let res = alice + .call(mt.id(), "mt_batch_transfer_call") + .args_json(( + defi.id(), + [token_1.token_id.clone(), token_2.token_id.clone()], + ["100", "5000"], + Option::<(AccountId, u64)>::None, + Option::::None, + "not-a-parsable-number", + )) + .max_gas() + .deposit(ONE_YOCTO) + .transact() + .await?; + assert!(res.is_success()); + let amounts_kept_by_receiver: Vec = res.json()?; + assert_eq!(amounts_kept_by_receiver, vec![U128(0), U128(0)]); + + // Balance hasn't changed. + let alice_balance: Vec = mt + .call("mt_batch_balance_of") + .args_json((alice.id(), vec![token_1.token_id.clone(), token_2.token_id.clone()])) + .view() + .await? + .json()?; + assert_eq!(alice_balance, vec![U128(830), U128(15_000)]); + + Ok(()) + } +} diff --git a/examples/multi-token/tests/workspaces/utils.rs b/examples/multi-token/tests/workspaces/utils.rs new file mode 100644 index 000000000..c4f6b8a47 --- /dev/null +++ b/examples/multi-token/tests/workspaces/utils.rs @@ -0,0 +1,113 @@ +use near_contract_standards::multi_token::metadata::TokenMetadata; +use near_contract_standards::multi_token::token::Token; +use near_contract_standards::storage_management::StorageBalanceBounds; +use near_sdk::Balance; +use near_units::parse_near; +use workspaces::{Account, AccountId, Contract, DevNetwork, Worker}; + +pub async fn get_storage_balance_bounds( + contract: &Contract, +) -> anyhow::Result { + Ok(contract.view("storage_balance_bounds", vec![]).await?.json::()?) +} + +pub async fn register_user_for_token( + contract: &Contract, + account_id: &AccountId, + deposit: u128, +) -> anyhow::Result<()> { + let res = contract + .call("storage_deposit") + .args_json((account_id, Some(false))) + .max_gas() + .deposit(deposit) + .transact() + .await?; + assert!(res.is_success()); + Ok(()) +} + +pub async fn helper_mint( + mt_contract: &Contract, + owner_id: AccountId, + amount: Balance, + title: String, + desc: String, +) -> anyhow::Result { + let token_md: TokenMetadata = TokenMetadata { + title: Some(title), + description: Some(desc), + media: None, + media_hash: None, + issued_at: None, + expires_at: None, + starts_at: None, + updated_at: None, + extra: None, + reference: None, + reference_hash: None, + }; + + let res = mt_contract + .call("mt_mint") + .args_json((owner_id, token_md, amount.to_string())) + .max_gas() + .deposit(parse_near!("7 mN")) + .transact() + .await?; + assert!(res.is_success()); + let token: Token = res.json()?; + + Ok(token) +} + +// Returns Multi-token contract, a non-owner user Alice, and a DeFi contract +// for receiving cross-contract calls. +pub async fn init( + worker: &Worker, +) -> anyhow::Result<(Contract, Account, Account, Contract)> { + let mt_contract = worker.dev_deploy(include_bytes!("../../res/multi_token.wasm")).await?; + + let res = mt_contract + .call("new_default_meta") + .args_json((mt_contract.id(),)) + .max_gas() + .transact() + .await?; + + assert!(res.is_success()); + + let defi_contract = worker.dev_deploy(include_bytes!("../../res/defi.wasm")).await?; + + let res = defi_contract.call("new").args_json((mt_contract.id(),)).max_gas().transact().await?; + assert!(res.is_success()); + + let alice = mt_contract + .as_account() + .create_subaccount("alice") + .initial_balance(parse_near!("10 N")) + .transact() + .await? + .into_result()?; + + let bob = mt_contract + .as_account() + .create_subaccount("bob") + .initial_balance(parse_near!("10 N")) + .transact() + .await? + .into_result()?; + + Ok((mt_contract, alice, bob, defi_contract)) +} + +pub async fn init_approval_receiver_contract( + worker: &Worker, +) -> anyhow::Result { + let approval_receiver_contract = + worker.dev_deploy(include_bytes!("../../res/approval_receiver.wasm")).await?; + let res = approval_receiver_contract.call("new").max_gas().transact().await?; + assert!(res.is_success()); + + Ok(approval_receiver_contract) +} diff --git a/near-contract-standards/src/event.rs b/near-contract-standards/src/event.rs index 3f055dc5a..c0d0fd482 100644 --- a/near-contract-standards/src/event.rs +++ b/near-contract-standards/src/event.rs @@ -1,4 +1,4 @@ -use near_sdk::env; +use near_sdk::{env, log}; use serde::Serialize; #[derive(Serialize, Debug)] @@ -8,6 +8,7 @@ use serde::Serialize; pub(crate) enum NearEvent<'a> { Nep171(crate::non_fungible_token::events::Nep171Event<'a>), Nep141(crate::fungible_token::events::Nep141Event<'a>), + Nep245(crate::multi_token::events::Nep245Event<'a>), } impl<'a> NearEvent<'a> { @@ -24,6 +25,6 @@ impl<'a> NearEvent<'a> { /// Logs the event to the host. This is required to ensure that the event is triggered /// and to consume the event. pub(crate) fn emit(self) { - near_sdk::env::log_str(&self.to_json_event_string()); + log!(&self.to_json_event_string()); } } diff --git a/near-contract-standards/src/lib.rs b/near-contract-standards/src/lib.rs index 7cfe66464..f8fb75a58 100644 --- a/near-contract-standards/src/lib.rs +++ b/near-contract-standards/src/lib.rs @@ -1,5 +1,7 @@ /// Fungible tokens as described in [by the spec](https://nomicon.io/Standards/FungibleToken/README.html). pub mod fungible_token; +/// Multi-fungible tokens as described [by the NEP-245 draft spec](https://github.com/near/NEPs/pull/245). +pub mod multi_token; /// Non-fungible tokens as described in [by the spec](https://nomicon.io/Standards/NonFungibleToken/README.html). pub mod non_fungible_token; /// Storage management deals with handling [state storage](https://docs.near.org/docs/concepts/storage-staking) on NEAR. This follows the [storage management standard](https://nomicon.io/Standards/StorageManagement.html). diff --git a/near-contract-standards/src/multi_token/approval/approval_impl.rs b/near-contract-standards/src/multi_token/approval/approval_impl.rs new file mode 100644 index 000000000..4193edb73 --- /dev/null +++ b/near-contract-standards/src/multi_token/approval/approval_impl.rs @@ -0,0 +1,172 @@ +use std::collections::HashMap; + +use near_sdk::{assert_one_yocto, env, json_types::U128, log, require, AccountId, Gas, Promise}; + +use crate::multi_token::approval::receiver::ext_approval_receiver; +use crate::multi_token::{ + core::MultiToken, + token::{Approval, TokenId}, + utils::{ + bytes_for_approved_account_id, expect_approval, expect_approval_for_token, refund_deposit, + Entity, + }, +}; + +use super::MultiTokenApproval; + +pub const GAS_FOR_RESOLVE_APPROVE: Gas = Gas(15_000_000_000_000); +pub const GAS_FOR_MT_APPROVE_CALL: Gas = Gas(50_000_000_000_000 + GAS_FOR_RESOLVE_APPROVE.0); + +impl MultiTokenApproval for MultiToken { + fn mt_approve( + &mut self, + token_ids: Vec, + amounts: Vec, + grantee_id: AccountId, + msg: Option, + ) -> Option { + let approver_id = env::predecessor_account_id(); + + // Unwrap to check if approval supported + let by_token = expect_approval(self.approvals_by_token_id.as_mut(), Entity::Contract); + + // Get some IDs and check if approval management supported both for contract & token + let next_id_by_token = + expect_approval(self.next_approval_id_by_id.as_mut(), Entity::Contract); + + let mut new_approval_ids: Vec = Vec::new(); + + let mut used_storage = 0; + + for (token_id, amount) in token_ids.iter().zip(&amounts) { + // Get the balance to check if user has enough tokens + let approver_balance = self + .balances_per_token + .get(token_id) + .and_then(|balances_per_account| balances_per_account.get(&approver_id)) + .unwrap_or(0); + require!(approver_balance >= amount.0, "Not enough balance to approve"); + + // Get the next approval id for the token + let new_approval_id: u64 = + expect_approval_for_token(next_id_by_token.get(token_id), token_id); + let new_approval = Approval { amount: amount.0, approval_id: new_approval_id }; + log!("New approval: {:?}", new_approval); + + // Get existing approvals for this token. If one exists for the grantee_id, overwrite it. + let mut by_owner = by_token.get(token_id).unwrap_or_default(); + let by_grantee = by_owner.get(&approver_id); + let mut grantee_to_approval = + if let Some(by_grantee) = by_grantee { by_grantee.clone() } else { HashMap::new() }; + + let old_approval_id = grantee_to_approval.insert(grantee_id.clone(), new_approval); + by_owner.insert(approver_id.clone(), grantee_to_approval); + by_token.insert(token_id, &by_owner); + next_id_by_token.insert(token_id, &(new_approval_id + 1)); + + new_approval_ids.push(new_approval_id); + + log!("Updated approvals by id: {:?}", old_approval_id); + used_storage += if old_approval_id.is_none() { + bytes_for_approved_account_id(&grantee_id) + } else { + 0 + }; + } + + refund_deposit(used_storage); + + // if given `msg`, schedule call to `mt_on_approve` and return it. Else, return None. + let receiver_gas: Gas = env::prepaid_gas() + .0 + .checked_sub(GAS_FOR_MT_APPROVE_CALL.into()) + .unwrap_or_else(|| env::panic_str("Prepaid gas overflow")) + .into(); + + msg.map(|msg| { + ext_approval_receiver::ext(grantee_id).with_static_gas(receiver_gas).mt_on_approve( + token_ids, + amounts, + approver_id, + new_approval_ids, + msg, + ) + }) + } + + fn mt_revoke(&mut self, token_ids: Vec, account_id: AccountId) { + assert_one_yocto(); + let owner_id = env::predecessor_account_id(); + + // Get all approvals for token, will panic if approval extension is not used for contract or token + let by_token = expect_approval(self.approvals_by_token_id.as_mut(), Entity::Contract); + + for token_id in token_ids.iter() { + // Remove approval for user & also clean maps to save space it it's empty + let mut by_owner = expect_approval_for_token(by_token.get(token_id), token_id); + let by_grantee = by_owner.get_mut(&owner_id); + + if let Some(grantee_to_approval) = by_grantee { + grantee_to_approval.remove(&account_id); + // The owner has no more approvals for this token. + if grantee_to_approval.is_empty() { + by_owner.remove(&owner_id); + } + } + + if by_owner.is_empty() { + by_token.remove(token_id); + } + } + } + + fn mt_revoke_all(&mut self, token_ids: Vec) { + assert_one_yocto(); + let owner_id = env::predecessor_account_id(); + + // Get all approvals for token, will panic if approval extension is not used for contract or token + let by_token = expect_approval(self.approvals_by_token_id.as_mut(), Entity::Contract); + + for token_id in token_ids.iter() { + let mut by_owner = expect_approval_for_token(by_token.get(token_id), token_id); + by_owner.remove(&owner_id); + by_token.insert(token_id, &by_owner); + } + } + + fn mt_is_approved( + &self, + owner_id: AccountId, + token_ids: Vec, + approved_account_id: AccountId, + amounts: Vec, + approval_ids: Option>, + ) -> bool { + let approval_ids = approval_ids.unwrap_or_default(); + require!( + approval_ids.is_empty() || approval_ids.len() == token_ids.len(), + "token_ids and approval_ids must have equal size" + ); + + let by_token = expect_approval(self.approvals_by_token_id.as_ref(), Entity::Contract); + + for (idx, (token_id, amount)) in token_ids.iter().zip(amounts).enumerate() { + let by_owner = by_token.get(token_id).unwrap_or_default(); + + let approval = match by_owner + .get(&owner_id) + .and_then(|grantee_to_approval| grantee_to_approval.get(&approved_account_id)) + { + Some(approval) if approval.amount.eq(&amount.into()) => approval, + _ => return false, + }; + + if let Some(given_approval) = approval_ids.get(idx) { + if !approval.approval_id.eq(given_approval) { + return false; + } + } + } + true + } +} diff --git a/near-contract-standards/src/multi_token/approval/mod.rs b/near-contract-standards/src/multi_token/approval/mod.rs new file mode 100644 index 000000000..a0c2f6c6c --- /dev/null +++ b/near-contract-standards/src/multi_token/approval/mod.rs @@ -0,0 +1,37 @@ +mod approval_impl; +mod receiver; + +pub use approval_impl::*; +pub use receiver::*; + +use crate::multi_token::token::TokenId; +use near_sdk::{json_types::U128, AccountId, Promise}; + +/// Trait used in approval management +/// Specs - https://github.com/shipsgold/NEPs/blob/master/specs/Standards/MultiToken/ApprovalManagement.md +pub trait MultiTokenApproval { + /// Add an approved account for a specific set of tokens + fn mt_approve( + &mut self, + token_ids: Vec, + amounts: Vec, + grantee_id: AccountId, + msg: Option, + ) -> Option; + + /// Revoke approvals granted to a specific user for a specific set of tokens. + fn mt_revoke(&mut self, token_ids: Vec, account_id: AccountId); + + /// Revoke all approvals for a token + fn mt_revoke_all(&mut self, token_ids: Vec); + + /// Check if account have access to transfer tokens + fn mt_is_approved( + &self, + owner_id: AccountId, + token_ids: Vec, + approved_account_id: AccountId, + amounts: Vec, + approval_ids: Option>, + ) -> bool; +} diff --git a/near-contract-standards/src/multi_token/approval/receiver.rs b/near-contract-standards/src/multi_token/approval/receiver.rs new file mode 100644 index 000000000..1af2c6aa3 --- /dev/null +++ b/near-contract-standards/src/multi_token/approval/receiver.rs @@ -0,0 +1,17 @@ +use near_sdk::{ext_contract, json_types::U128, AccountId}; + +use crate::multi_token::token::TokenId; + +/// Approval receiver is the trait for the method called (or attempted to be called) when an MT contract adds an approval for an account. +#[ext_contract(ext_approval_receiver)] +pub trait MultiTokenApprovalReceiver { + /// Respond to notification that contract has been granted approval for a token. + fn mt_on_approve( + &mut self, + tokens: Vec, + amounts: Vec, + owner_id: AccountId, + approval_ids: Vec, + msg: String, + ) -> near_sdk::PromiseOrValue; +} diff --git a/near-contract-standards/src/multi_token/core/core_impl.rs b/near-contract-standards/src/multi_token/core/core_impl.rs new file mode 100644 index 000000000..15f6282f6 --- /dev/null +++ b/near-contract-standards/src/multi_token/core/core_impl.rs @@ -0,0 +1,803 @@ +use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::collections::{LookupMap, UnorderedMap, UnorderedSet}; +use near_sdk::json_types::U128; +use near_sdk::{ + assert_one_yocto, env, log, require, AccountId, Balance, BorshStorageKey, CryptoHash, Gas, + IntoStorageKey, PromiseOrValue, PromiseResult, StorageUsage, +}; + +use crate::multi_token::core::receiver::ext_mt_receiver; +use crate::multi_token::core::resolver::{ext_mt_resolver, MultiTokenResolver}; +use crate::multi_token::core::MultiTokenCore; +use crate::multi_token::events::{MtMint, MtTransfer}; +use crate::multi_token::metadata::TokenMetadata; +use crate::multi_token::token::{Approval, ApprovalContainer, ClearedApproval, Token, TokenId}; +use crate::multi_token::utils::{ + expect_approval, expect_approval_for_token, refund_deposit_to_account, Entity, +}; + +pub const GAS_FOR_RESOLVE_TRANSFER: Gas = Gas(15_000_000_000_000); +pub const GAS_FOR_MT_TRANSFER_CALL: Gas = Gas(50_000_000_000_000 + GAS_FOR_RESOLVE_TRANSFER.0); + +const ERR_MORE_GAS_REQUIRED: &str = "More gas is required"; +const ERR_TOTAL_SUPPLY_OVERFLOW: &str = "Total supply overflow"; +const ERR_PREPAID_GAS_OVERFLOW: &str = "Prepaid gas overflow"; +const ERR_TOTAL_SUPPLY_NOT_FOUND_BY_TOKEN_ID: &str = "Total supply not found by token id"; + +/// Implementation of the multi-token standard +/// Allows to include NEP-245 compatible tokens to any contract. +/// There are next traits that any contract may implement: +/// - MultiTokenCore -- interface with transfer methods. MultiToken provides methods for it. +/// - MultiTokenApproval -- interface with approve methods. MultiToken provides methods for it. +/// - MultiTokenEnumeration -- interface for getting lists of tokens. MultiToken provides methods for it. +/// - MultiTokenMetadata -- return metadata for the token in NEP-245, up to contract to implement. +#[derive(BorshDeserialize, BorshSerialize)] +pub struct MultiToken { + /// Owner of contract + pub owner_id: AccountId, + + /// AccountID -> Near balance for storage. + pub accounts_storage: LookupMap, + + /// The storage size in bytes for one account. + pub account_storage_usage: StorageUsage, + + /// The storage size in bytes for one token. + pub storage_usage_per_token: StorageUsage, + + /// How much storage takes every token + pub extra_storage_in_bytes_per_emission: StorageUsage, + + /// Owner of each token + pub owner_by_id: UnorderedMap, + + /// Total supply for each token + pub total_supply: LookupMap, + + /// Metadata for each token + pub token_metadata_by_id: Option>, + + /// All tokens owned by user + pub tokens_per_owner: Option>>, + + /// Balance of user for given token + pub balances_per_token: UnorderedMap>, + /// Approvals granted for a given token. + /// Nested maps are structured as: token_id -> owner_id -> grantee_id -> (approval_id, amount) + pub approvals_by_token_id: Option, + + /// Next id of approval + pub next_approval_id_by_id: Option>, + + /// Next id for token + pub next_token_id: u64, + + /// Token holders with positive balance per token + pub holders_per_token: Option>>, +} + +#[derive(BorshStorageKey, BorshSerialize)] +pub enum StorageKey { + Accounts, + AccountTokens { account_id_hash: CryptoHash }, + PerOwner, + TokensPerOwner { account_hash: Vec }, + TokenPerOwnerInner { account_id_hash: CryptoHash }, + OwnerByIdInner { account_id_hash: CryptoHash }, + TokenMetadata, + Approvals, + ApprovalById, + ApprovalsInner { account_id_hash: CryptoHash }, + TotalSupply { supply: u128 }, + Balances, + BalancesInner { token_id: Vec }, + TokenHoldersInner { token_id: TokenId }, +} + +impl MultiToken { + pub fn new( + owner_by_id_prefix: Q, + owner_id: AccountId, + token_metadata_prefix: Option, + enumeration_prefix: Option, + approval_prefix: Option, + token_holders_prefix: Option, + ) -> Self + where + Q: IntoStorageKey, + R: IntoStorageKey, + S: IntoStorageKey, + T: IntoStorageKey, + U: IntoStorageKey, + { + let (approvals_by_token_id, next_approval_id_by_id) = if let Some(prefix) = approval_prefix + { + let prefix: Vec = prefix.into_storage_key(); + ( + Some(LookupMap::new(prefix.clone())), + Some(LookupMap::new([prefix, "n".into()].concat())), + ) + } else { + (None, None) + }; + + let mut this = Self { + owner_id, + extra_storage_in_bytes_per_emission: 0, + owner_by_id: UnorderedMap::new(owner_by_id_prefix), + total_supply: LookupMap::new(StorageKey::TotalSupply { supply: 0 }), + token_metadata_by_id: token_metadata_prefix.map(LookupMap::new), + tokens_per_owner: enumeration_prefix.map(LookupMap::new), + accounts_storage: LookupMap::new(StorageKey::Accounts), + balances_per_token: UnorderedMap::new(StorageKey::Balances), + approvals_by_token_id, + next_approval_id_by_id, + next_token_id: 0, + account_storage_usage: 0, + storage_usage_per_token: 0, + holders_per_token: token_holders_prefix.map(UnorderedMap::new), + }; + + this.measure_min_account_storage_cost(); + this.measure_min_token_storage_cost(); + + this + } + + fn measure_min_token_storage_cost(&mut self) { + let tmp_token_id = u64::MAX.to_string(); + let mut user_token_balance = LookupMap::new(StorageKey::BalancesInner { + token_id: env::sha256(tmp_token_id.as_bytes()), + }); + let tmp_account_id = AccountId::new_unchecked("a".repeat(64)); + + let initial_storage_usage = env::storage_usage(); + + user_token_balance.insert(&tmp_account_id, &u128::MAX); + + self.balances_per_token.insert(&tmp_token_id, &user_token_balance); + if let Some(holders) = &mut self.holders_per_token { + let mut holders_set = + UnorderedSet::new(StorageKey::TokenHoldersInner { token_id: tmp_token_id.clone() }); + holders_set.insert(&tmp_account_id); + holders.insert(&tmp_token_id, &holders_set); + } + self.storage_usage_per_token = env::storage_usage() - initial_storage_usage; + + self.balances_per_token.remove(&tmp_token_id); + } + + fn measure_min_account_storage_cost(&mut self) { + let tmp_account_id = AccountId::new_unchecked("a".repeat(64)); + let initial_storage_usage = env::storage_usage(); + + // storage in NEAR's per account + self.accounts_storage.insert(&tmp_account_id, &u128::MAX); + + self.account_storage_usage = env::storage_usage() - initial_storage_usage; + + self.accounts_storage.remove(&tmp_account_id); + } + + /// Used to get balance of specified account in specified token + pub fn internal_unwrap_balance_of( + &self, + token_id: &TokenId, + account_id: &AccountId, + ) -> Balance { + self.balances_per_token + .get(token_id) + .expect("This token does not exist") + .get(account_id) + .unwrap_or(0) + } + + /// Add to balance of user specified amount + pub fn internal_deposit( + &mut self, + token_id: &TokenId, + account_id: &AccountId, + amount: Balance, + ) { + let balance = self.internal_unwrap_balance_of(token_id, account_id); + if let Some(new) = balance.checked_add(amount) { + let mut balances = self.balances_per_token.get(token_id).expect("Token not found"); + balances.insert(account_id, &new); + self.total_supply.insert( + token_id, + &self + .total_supply + .get(token_id) + .expect(ERR_TOTAL_SUPPLY_NOT_FOUND_BY_TOKEN_ID) + .checked_add(amount) + .unwrap_or_else(|| env::panic_str(ERR_TOTAL_SUPPLY_OVERFLOW)), + ); + } else { + env::panic_str("Balance overflow"); + } + } + + /// Subtract specified amount from user account in given token + pub fn internal_withdraw( + &mut self, + token_id: &TokenId, + account_id: &AccountId, + amount: Balance, + ) { + let balance = self.internal_unwrap_balance_of(token_id, account_id); + if let Some(new) = balance.checked_sub(amount) { + let mut balances = self.balances_per_token.get(token_id).expect("Token not found"); + balances.insert(account_id, &new); + self.total_supply.insert( + token_id, + &self + .total_supply + .get(token_id) + .expect(ERR_TOTAL_SUPPLY_NOT_FOUND_BY_TOKEN_ID) + .checked_sub(amount) + .unwrap_or_else(|| env::panic_str(ERR_TOTAL_SUPPLY_OVERFLOW)), + ); + } else { + env::panic_str("The account doesn't have enough balance"); + } + } + + pub fn internal_batch_transfer( + &mut self, + sender_id: &AccountId, + receiver_id: &AccountId, + token_ids: &[TokenId], + amounts: &[Balance], + approvals: Option>>, + ) -> (Vec, Vec>) { + let approvals = approvals.unwrap_or_else(|| vec![None; token_ids.len()]); + (0..token_ids.len()) + .map(|i| { + self.internal_transfer( + sender_id, + receiver_id, + &token_ids[i], + amounts[i], + &approvals[i], + ) + }) + .unzip() + } + + pub fn internal_transfer( + &mut self, + original_sender_id: &AccountId, + receiver_id: &AccountId, + token_id: &TokenId, + amount: Balance, + approval: &Option<(AccountId, u64)>, + ) -> (AccountId, Option<(AccountId, Approval)>) { + // Safety checks + require!(amount > 0, "Transferred amounts must be greater than 0"); + + let (sender_id, old_approvals) = if let Some((owner_id, approval_id)) = approval { + ( + owner_id, + Some(self.check_and_apply_approval( + token_id, + owner_id, + original_sender_id, + approval_id, + amount, + )), + ) + } else { + // No approval. + (original_sender_id, None) + }; + + require!(sender_id != receiver_id, "Sender and receiver must differ"); + + self.internal_withdraw(token_id, sender_id, amount); + self.internal_deposit(token_id, receiver_id, amount); + self.assert_storage_usage(receiver_id); + self.internal_update_token_holders(token_id, receiver_id); + self.internal_update_token_holders(token_id, sender_id); + + MtTransfer { + old_owner_id: sender_id, + new_owner_id: receiver_id, + token_ids: &[token_id], + amounts: &[&amount.to_string()], + authorized_id: Some(original_sender_id).filter(|id| *id == sender_id), + memo: None, + } + .emit(); + + (sender_id.to_owned(), old_approvals) + } + + pub fn internal_mint( + &mut self, + owner_id: AccountId, + supply: Option, + metadata: Option, + refund_id: Option, + ) -> Token { + let token = self.internal_mint_with_refund(owner_id.clone(), supply, metadata, refund_id); + MtMint { + owner_id: &owner_id, + token_ids: &[&token.token_id], + amounts: &[&token.supply.to_string()], + memo: None, + } + .emit(); + + token + } + + /// Mint a new token without checking: + /// * Whether the caller id is equal to the `owner_id` + /// * `refund_id` will transfer the leftover balance after storage costs are calculated to the provided account. + /// Typically, the account will be the owner. If `None`, will not refund. This is useful for delaying refunding + /// until multiple tokens have been minted. + /// + /// Returns the newly minted token and does not emit the mint event. This allows minting multiple before emitting. + pub fn internal_mint_with_refund( + &mut self, + token_owner_id: AccountId, + supply: Option, + token_metadata: Option, + refund_id: Option, + ) -> Token { + // Remember current storage usage if refund_id is Some + let initial_storage_usage = refund_id.map(|account_id| (account_id, env::storage_usage())); + + // Panic if contract is using metadata extension and caller must provide it + if self.token_metadata_by_id.is_some() && token_metadata.is_none() { + env::panic_str("MUST provide metadata"); + } + // Increment next id of the token. Panic if it's overflowing u64::MAX + self.next_token_id = + self.next_token_id.checked_add(1).expect("u64 overflow, cannot mint any more tokens"); + + let token_id: TokenId = self.next_token_id.to_string(); + + // If contract uses approval management create new LookupMap for approvals + self.next_approval_id_by_id.as_mut().and_then(|internal| internal.insert(&token_id, &0)); + + // Alias + let owner_id: AccountId = token_owner_id; + + // Insert new owner + self.owner_by_id.insert(&token_id, &owner_id); + + // Insert new metadata + if let Some(metadata) = &token_metadata { + self.token_metadata_by_id.as_mut().and_then(|by_id| by_id.insert(&token_id, metadata)); + } + + // Insert new supply + let supply = supply.unwrap_or(0); + self.total_supply.insert(&token_id, &supply); + + // Insert new balance + let mut new_balances_per_account: LookupMap = + LookupMap::new(StorageKey::BalancesInner { + token_id: env::sha256(token_id.as_bytes()), + }); + new_balances_per_account.insert(&owner_id, &supply); + self.balances_per_token.insert(&token_id, &new_balances_per_account); + + self.internal_update_token_holders(&token_id, &owner_id); + + // Updates enumeration if extension is used + if let Some(per_owner) = &mut self.tokens_per_owner { + let mut token_ids = per_owner.get(&owner_id).unwrap_or_else(|| { + UnorderedSet::new(StorageKey::TokensPerOwner { + account_hash: env::sha256(owner_id.as_bytes()), + }) + }); + token_ids.insert(&token_id); + per_owner.insert(&owner_id, &token_ids); + } + + if let Some((id, usage)) = initial_storage_usage { + refund_deposit_to_account(env::storage_usage() - usage, id); + } + + Token { token_id, owner_id, supply, metadata: token_metadata } + } + + // validate that an approval exists with matching approval_id and sufficient balance. + pub fn check_and_apply_approval( + &mut self, + token_id: &TokenId, + owner_id: &AccountId, + grantee_id: &AccountId, + approval_id: &u64, + amount: Balance, + ) -> (AccountId, Approval) { + // If an approval was provided, ensure it meets requirements. + let approvals = expect_approval(self.approvals_by_token_id.as_mut(), Entity::Contract); + + let mut by_owner = expect_approval_for_token(approvals.get(token_id), token_id); + + let mut by_sender_id = by_owner + .get(owner_id) + .unwrap_or_else(|| panic!("No approvals for {}", owner_id)) + .clone(); + + let stored_approval: Approval = by_sender_id + .get(grantee_id) + .unwrap_or_else(|| panic!("No approval for {} from {}", grantee_id, owner_id)) + .clone(); + + require!(stored_approval.approval_id.eq(approval_id), "Invalid approval_id"); + + let new_approval_amount = stored_approval + .amount + .checked_sub(amount) + .expect("Not enough approval amount for transfer"); + + if new_approval_amount == 0 { + by_sender_id.remove(grantee_id); + } else { + by_sender_id.insert( + grantee_id.clone(), + Approval { approval_id: *approval_id, amount: new_approval_amount }, + ); + } + by_owner.insert(owner_id.clone(), by_sender_id.clone()); + + approvals.insert(token_id, &by_owner); + + // Given that we are consuming the approval or the part of it + // Return the now-deleted approvals, so that caller may restore them in case of revert. + (grantee_id.clone(), stored_approval) + } + + /// Used to update the set of current holders of a token. + pub fn internal_update_token_holders(&mut self, token_id: &TokenId, account_id: &AccountId) { + if let Some(token_holders_by_token) = self.holders_per_token.as_mut() { + let mut holders = token_holders_by_token.get(token_id).unwrap_or_else(|| { + UnorderedSet::new(StorageKey::TokenHoldersInner { token_id: token_id.clone() }) + }); + let balances = self.balances_per_token.get(token_id).expect("Token not found"); + + let account_balance = balances.get(account_id).expect("Account not found"); + + if account_balance == 0 { + holders.remove(account_id); + } else if !holders.contains(account_id) { + holders.insert(account_id); + } else { + return; + } + + token_holders_by_token.insert(token_id, &holders); + } + } +} + +impl MultiTokenCore for MultiToken { + fn mt_transfer( + &mut self, + receiver_id: AccountId, + token_id: TokenId, + amount: U128, + approval: Option<(AccountId, u64)>, + memo: Option, + ) { + self.mt_batch_transfer( + receiver_id, + vec![token_id], + vec![amount], + Some(vec![approval]), + memo, + ); + } + + fn mt_batch_transfer( + &mut self, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + _memo: Option, + ) { + assert_one_yocto(); + let sender_id = env::predecessor_account_id(); + require!(token_ids.len() == amounts.len()); + require!(!token_ids.is_empty()); + + let amounts: Vec = amounts.iter().map(|x| x.0).collect(); + + self.internal_batch_transfer(&sender_id, &receiver_id, &token_ids, &amounts, approvals); + } + + fn mt_transfer_call( + &mut self, + receiver_id: AccountId, + token_id: TokenId, + amount: U128, + approval: Option<(AccountId, u64)>, + _memo: Option, + msg: String, + ) -> PromiseOrValue { + assert_one_yocto(); + require!(env::prepaid_gas() > GAS_FOR_MT_TRANSFER_CALL, ERR_MORE_GAS_REQUIRED); + let sender_id = env::predecessor_account_id(); + + let amount_to_send: Balance = amount.0; + + let (old_owner, old_approvals) = + self.internal_transfer(&sender_id, &receiver_id, &token_id, amount_to_send, &approval); + + let receiver_gas = env::prepaid_gas() + .0 + .checked_sub(GAS_FOR_MT_TRANSFER_CALL.0) + .unwrap_or_else(|| env::panic_str(ERR_PREPAID_GAS_OVERFLOW)); + + ext_mt_receiver::ext(receiver_id.clone()) + .with_static_gas(receiver_gas.into()) + .mt_on_transfer( + sender_id.clone(), + vec![old_owner.clone()], + vec![token_id.clone()], + vec![amount], + msg, + ) + .then( + ext_mt_resolver::ext(env::current_account_id()) + .with_static_gas(GAS_FOR_RESOLVE_TRANSFER) + .mt_resolve_transfer( + vec![old_owner], + receiver_id, + vec![token_id], + vec![amount], + Some(vec![old_approvals]), + ), + ) + .into() + } + + fn mt_batch_transfer_call( + &mut self, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + _memo: Option, + msg: String, + ) -> PromiseOrValue> { + assert_one_yocto(); + require!(env::prepaid_gas() > GAS_FOR_MT_TRANSFER_CALL, ERR_MORE_GAS_REQUIRED); + let sender_id = env::predecessor_account_id(); + + let amounts_to_send: Vec = amounts.iter().map(|x| x.0).collect(); + + let (old_owners, old_approvals) = self.internal_batch_transfer( + &sender_id, + &receiver_id, + &token_ids, + &amounts_to_send, + approvals, + ); + + let receiver_gas = env::prepaid_gas() + .0 + .checked_sub(GAS_FOR_MT_TRANSFER_CALL.into()) + .unwrap_or_else(|| env::panic_str(ERR_PREPAID_GAS_OVERFLOW)); + + ext_mt_receiver::ext(receiver_id.clone()) + .with_static_gas(receiver_gas.into()) + .mt_on_transfer(sender_id, old_owners.clone(), token_ids.clone(), amounts.clone(), msg) + .then( + ext_mt_resolver::ext(env::current_account_id()) + .with_static_gas(GAS_FOR_RESOLVE_TRANSFER) + .mt_resolve_transfer( + old_owners, + receiver_id, + token_ids, + amounts, + Some(old_approvals), + ), + ) + .into() + } + + fn mt_token(&self, token_id: TokenId) -> Option { + self.internal_get_token_metadata(&token_id) + } + + fn mt_token_list(&self, token_ids: Vec) -> Vec> { + token_ids.iter().map(|token_id| self.internal_get_token_metadata(token_id)).collect() + } + + fn mt_balance_of(&self, account_id: AccountId, token_id: TokenId) -> U128 { + self.internal_balance_of(&account_id, &token_id) + } + + fn mt_batch_balance_of(&self, account_id: AccountId, token_ids: Vec) -> Vec { + token_ids.iter().map(|token_id| self.internal_balance_of(&account_id, token_id)).collect() + } + + fn mt_supply(&self, token_id: TokenId) -> Option { + self.internal_supply(&token_id) + } + + fn mt_batch_supply(&self, token_ids: Vec) -> Vec> { + token_ids.iter().map(|token_id| self.internal_supply(token_id)).collect() + } +} + +impl MultiToken { + fn internal_get_token_metadata(&self, token_id: &TokenId) -> Option { + let metadata = if let Some(metadata_by_id) = &self.token_metadata_by_id { + metadata_by_id.get(token_id) + } else { + None + }; + let supply = self.total_supply.get(token_id)?; + let owner_id = self.owner_by_id.get(token_id)?; + + Some(Token { token_id: token_id.clone(), owner_id, supply, metadata }) + } + + fn internal_balance_of(&self, account_id: &AccountId, token_id: &TokenId) -> U128 { + let token_balances_by_user = + self.balances_per_token.get(token_id).expect("Token not found."); + token_balances_by_user.get(account_id).unwrap_or(0).into() + } + + fn internal_supply(&self, token_id: &TokenId) -> Option { + self.total_supply.get(token_id).map(u128::into) + } + + pub fn internal_resolve_transfers( + &mut self, + previous_owner_ids: &[AccountId], + receiver: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + ) -> Vec { + // promise result contains what amounts were refunded by the receiver contract. + let (amounts_to_refund, revert_approvals): (Vec, bool) = match env::promise_result(0) + { + PromiseResult::NotReady => env::abort(), + PromiseResult::Successful(values) => { + if let Ok(unused) = near_sdk::serde_json::from_slice::>(&values) { + // we can't be refunded by more than what we sent over + ( + (0..amounts.len()) + .map(|i| U128(std::cmp::min(amounts[i].0, unused[i].0))) + .collect(), + false, + ) + } else { + // Can't parse. Refund the transfers, but don't restore the approvals for the non-compliant contract. + (amounts.clone(), false) + } + } + // If promise chain fails, undo all the transfers. + PromiseResult::Failed => (amounts.clone(), true), + }; + + let amounts_kept_by_receiver: Vec = (0..token_ids.len()) + .map(|i| { + self.internal_resolve_single_transfer( + &previous_owner_ids[i], + receiver.clone(), + token_ids[i].clone(), + amounts[i].into(), + amounts_to_refund[i].into(), + ) + }) + .collect(); + + if revert_approvals { + log!("Reverting approvals"); + + if let Some(by_token) = self.approvals_by_token_id.as_mut() { + if let Some(approvals) = approvals { + for (i, approval) in approvals.iter().enumerate() { + if let Some(cleared_approval) = approval { + let token_id = &token_ids[i]; + let previous_owner = &previous_owner_ids[i]; + let mut by_owner = by_token.get(token_id).expect("Token not found"); + let by_grantee = + by_owner.get_mut(previous_owner).expect("Previous owner not found"); + let (grantee_id, apprioval) = cleared_approval; + log!("Restored approval for token {:?} for owner {:?} and grantee {:?} with allowance {:?}", &token_id, &previous_owner, &grantee_id, &apprioval.amount); + by_grantee.insert(grantee_id.clone(), apprioval.clone()); + by_token.insert(token_id, &by_owner); + } + } + } + } + } + + amounts_kept_by_receiver + } + + pub fn internal_resolve_single_transfer( + &mut self, + sender_id: &AccountId, + receiver: AccountId, + token_id: TokenId, + amount: u128, + unused_amount: u128, + ) -> Balance { + if unused_amount > 0 { + // Whatever was unused gets returned to the original owner. + let mut balances = self.balances_per_token.get(&token_id).expect("Token not found"); + let receiver_balance = balances.get(&receiver).unwrap_or(0); + + if receiver_balance > 0 { + // If the receiver doesn't have enough funds to do the + // full refund, just refund all that we can. + let refund_amount = std::cmp::min(receiver_balance, unused_amount); + + if let Some(new_receiver_balance) = receiver_balance.checked_sub(refund_amount) { + balances.insert(&receiver, &new_receiver_balance); + } else { + env::panic_str("The receiver account doesn't have enough balance"); + } + + // Try to give the refund back to sender now + return if let Some(sender_balance) = balances.get(sender_id) { + if let Some(new_sender_balance) = sender_balance.checked_add(refund_amount) { + balances.insert(sender_id, &new_sender_balance); + log!("Refund {} from {} to {}", refund_amount, receiver, sender_id); + MtTransfer { + old_owner_id: sender_id, + new_owner_id: &receiver, + token_ids: &[&token_id], + amounts: &[&amount.to_string()], + authorized_id: None, + memo: None, + } + .emit(); + amount + .checked_sub(refund_amount) + .unwrap_or_else(|| env::panic_str(ERR_TOTAL_SUPPLY_OVERFLOW)) + } else { + env::panic_str("Sender balance overflow"); + } + } else { + self.total_supply + .get(&token_id) + .as_mut() + .expect(ERR_TOTAL_SUPPLY_NOT_FOUND_BY_TOKEN_ID) + .checked_sub(refund_amount) + .unwrap_or_else(|| env::panic_str(ERR_TOTAL_SUPPLY_OVERFLOW)); + + log!("The account of the sender was deleted"); + amount + .checked_sub(refund_amount) + .unwrap_or_else(|| env::panic_str(ERR_TOTAL_SUPPLY_OVERFLOW)) + }; + } + } + amount + } +} + +impl MultiTokenResolver for MultiToken { + fn mt_resolve_transfer( + &mut self, + previous_owner_ids: Vec, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + ) -> Vec { + self.internal_resolve_transfers( + &previous_owner_ids, + receiver_id, + token_ids, + amounts, + approvals, + ) + .iter() + .map(|&x| x.into()) + .collect() + } +} diff --git a/near-contract-standards/src/multi_token/core/mod.rs b/near-contract-standards/src/multi_token/core/mod.rs new file mode 100644 index 000000000..a969182ea --- /dev/null +++ b/near-contract-standards/src/multi_token/core/mod.rs @@ -0,0 +1,100 @@ +/*! Multi-Token Implementation (ERC-1155) + +*/ + +mod core_impl; +mod receiver; +mod resolver; + +pub use self::core_impl::*; +pub use self::receiver::MultiTokenReceiver; +pub use self::resolver::MultiTokenResolver; + +use crate::multi_token::token::TokenId; +use near_sdk::json_types::U128; +use near_sdk::{AccountId, PromiseOrValue}; + +use super::token::Token; + +/// Describes functionality according to this - https://eips.ethereum.org/EIPS/eip-1155 +/// And this - +pub trait MultiTokenCore { + /// Make a single transfer + /// + /// # Arguments + /// + /// * `receiver_id`: the valid NEAR account receiving the token + /// * `token_id`: ID of the token to transfer + /// * `amount`: the number of tokens to transfer + /// * `approval`: owner account and ID of approval for signer + /// * `memo`: Used as context + /// returns: () + /// + fn mt_transfer( + &mut self, + receiver_id: AccountId, + token_id: TokenId, + amount: U128, + approval: Option<(AccountId, u64)>, + memo: Option, + ); + + // Make a batch transfer + fn mt_batch_transfer( + &mut self, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + memo: Option, + ); + + /// Transfer MT and call a method on receiver contract. A successful + /// workflow will end in a success execution outcome to the callback on the MT + /// contract at the method `resolve_transfer`. + /// + /// # Arguments + /// + /// * `receiver_id`: NEAR account receiving MT + /// * `token_id`: Token to send + /// * `amount`: How much to send + /// * `approval`: owner account and ID of approval for signer + /// * `memo`: Used as context + /// * `msg`: Additional msg that will be passed to receiving contract + /// + /// returns: PromiseOrValue + /// + fn mt_transfer_call( + &mut self, + receiver_id: AccountId, + token_id: TokenId, + amount: U128, + approval: Option<(AccountId, u64)>, + memo: Option, + msg: String, + ) -> PromiseOrValue; + + // Batched version of mt_transfer_call + fn mt_batch_transfer_call( + &mut self, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + memo: Option, + msg: String, + ) -> PromiseOrValue>; + + // View Methods + fn mt_token(&self, token_id: TokenId) -> Option; + + fn mt_token_list(&self, token_ids: Vec) -> Vec>; + + fn mt_balance_of(&self, account_id: AccountId, token_id: TokenId) -> U128; + + fn mt_batch_balance_of(&self, account_id: AccountId, token_ids: Vec) -> Vec; + + fn mt_supply(&self, token_id: TokenId) -> Option; + + fn mt_batch_supply(&self, token_ids: Vec) -> Vec>; +} diff --git a/near-contract-standards/src/multi_token/core/receiver.rs b/near-contract-standards/src/multi_token/core/receiver.rs new file mode 100644 index 000000000..d50a6133b --- /dev/null +++ b/near-contract-standards/src/multi_token/core/receiver.rs @@ -0,0 +1,38 @@ +use crate::multi_token::token::TokenId; +use near_sdk::json_types::U128; +use near_sdk::{ext_contract, AccountId, PromiseOrValue}; + +/// Used when an MT is transferred using `transfer_call`. This trait should be implemented on receiving contract +#[ext_contract(ext_mt_receiver)] +pub trait MultiTokenReceiver { + /// Take some action after receiving a multi-token's + /// + /// ## Requirements: + /// * Contract MUST restrict calls to this function to a set of whitelisted MT + /// contracts + /// * Contract MUST panic if `token_ids` length does not equal `amounts` + /// length + /// * Contract MUST panic if `previous_owner_ids` length does not equal `token_ids` + /// length + /// + /// ## Arguments: + /// * `sender_id`: the sender of `transfer_call` + /// * `previous_owner_ids`: the accounts that owned the tokens prior to them being + /// transferred to this contract, which can differ from `sender_id` if using + /// Approval Management extension + /// * `token_ids`: the `token_ids` argument given to `transfer_call` + /// * `amounts`: the `amounts` argument given to `transfer_call` + /// * `msg`: information necessary for this contract to know how to process the + /// request. This may include method names and/or arguments. + /// + /// Returns the number of unused tokens in integer form. For instance, if `amounts` + /// is `[10]` but only 9 are needed, it will return `[1]`. + fn mt_on_transfer( + &mut self, + sender_id: AccountId, + previous_owner_ids: Vec, + token_ids: Vec, + amounts: Vec, + msg: String, + ) -> PromiseOrValue>; +} diff --git a/near-contract-standards/src/multi_token/core/resolver.rs b/near-contract-standards/src/multi_token/core/resolver.rs new file mode 100644 index 000000000..9d1be6aa8 --- /dev/null +++ b/near-contract-standards/src/multi_token/core/resolver.rs @@ -0,0 +1,48 @@ +use crate::multi_token::token::ClearedApproval; +use crate::multi_token::token::TokenId; +use near_sdk::ext_contract; +use near_sdk::json_types::U128; +use near_sdk::AccountId; + +/// `resolve_transfer` will be called after `on_transfer` +#[ext_contract(ext_mt_resolver)] +pub trait MultiTokenResolver { + /// Finalizes chain of cross-contract calls that started from `mt_transfer_call` + /// + /// Flow: + /// + /// 1. Sender calls `mt_transfer_call` on MT contract + /// 2. MT contract transfers tokens from sender to receiver + /// 3. MT contract calls `on_transfer` on receiver contract + /// 4+. [receiver may make cross-contract calls] + /// N. MT contract resolves chain with `mt_resolve_transfer` and may do anything + /// + /// Requirements: + /// * Contract MUST forbid calls to this function by any account except self + /// * If promise chain failed, contract MUST revert tokens transfer + /// * If promise chain resolves with `true`, contract MUST return tokens to + /// `previous_owner_ids` + /// + /// Arguments: + /// * `previous_owner_ids`: the owner prior to the call to `transfer_call` + /// * `receiver_id`: the `receiver_id` argument given to `transfer_call` + /// * `token_ids`: the vector of `token_id` argument given to `transfer_call` + /// * `approvals`: if using Approval Management, contract MUST provide + /// set of original approved accounts in this argument, and restore these + /// approved accounts in case of revert. + /// + /// Returns total amount spent by the `receiver_id`, corresponding to the `token_id`. + /// + /// Example: if sender calls `transfer_call({ "amounts": ["100"], token_ids: ["55"], receiver_id: "games" })`, + /// but `receiver_id` only uses 80, `on_transfer` will resolve with `["20"]`, and `resolve_transfer` + /// will return `[80]`. + + fn mt_resolve_transfer( + &mut self, + previous_owner_ids: Vec, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + ) -> Vec; +} diff --git a/near-contract-standards/src/multi_token/enumeration/enumeration_impl.rs b/near-contract-standards/src/multi_token/enumeration/enumeration_impl.rs new file mode 100644 index 000000000..f9773ee7b --- /dev/null +++ b/near-contract-standards/src/multi_token/enumeration/enumeration_impl.rs @@ -0,0 +1,66 @@ +use near_sdk::json_types::U128; +use near_sdk::{require, AccountId}; + +use crate::multi_token::{ + core::MultiToken, + token::{Token, TokenId}, +}; + +use super::MultiTokenEnumeration; + +impl MultiToken { + fn enum_get_token(&self, owner_id: AccountId, token_id: TokenId) -> Token { + let metadata = self.token_metadata_by_id.as_ref().and_then(|m| m.get(&token_id)); + let supply = self.total_supply.get(&token_id).expect("Total supply not found by token id"); + + Token { token_id, owner_id, metadata, supply } + } +} + +impl MultiTokenEnumeration for MultiToken { + fn mt_tokens(&self, from_index: Option, limit: Option) -> Vec { + let start_index: u128 = from_index.map(From::from).unwrap_or_default(); + require!( + self.owner_by_id.len() as u128 >= start_index, + "Out of bounds, please use a smaller from_index." + ); + let limit = limit.unwrap_or(u64::MAX); + require!(limit != 0, "Limit cannot be 0"); + + self.owner_by_id + .iter() + .skip(start_index as usize) + .take(limit as usize) + .map(|(token_id, owner_id)| self.enum_get_token(owner_id, token_id)) + .collect() + } + + fn mt_tokens_for_owner( + &self, + account_id: AccountId, + from_index: Option, + limit: Option, + ) -> Vec { + let tokens_per_owner = self.tokens_per_owner.as_ref().expect("Could not find field"); + let token_set = if let Some(set) = tokens_per_owner.get(&account_id) { + set + } else { + return vec![]; + }; + + let limit = limit.map(|v| v as usize).unwrap_or(usize::MAX); + require!(limit != 0, "Limit cannot be 0"); + let from_index: u128 = from_index.map(From::from).unwrap_or_default(); + require!( + token_set.len() as u128 > from_index, + "Out of bounds, please use a smaller from_index." + ); + + token_set + .iter() + .skip(from_index as usize) + .take(limit as usize) + .map(|token_id| self.enum_get_token(account_id.clone(), token_id)) + .collect() + } +} diff --git a/near-contract-standards/src/multi_token/enumeration/mod.rs b/near-contract-standards/src/multi_token/enumeration/mod.rs new file mode 100644 index 000000000..8247445fd --- /dev/null +++ b/near-contract-standards/src/multi_token/enumeration/mod.rs @@ -0,0 +1,53 @@ +use near_sdk::json_types::U128; +use near_sdk::AccountId; + +pub mod enumeration_impl; + +use super::{metadata::MtContractMetadata, token::Token}; + +/// Enumeration extension for NEP-245 +/// See specs here -> +pub trait MultiTokenEnumeration { + /// Get a list of all tokens (with pagination) + /// + /// # Arguments: + /// * `from_index` - Index to start from, defaults to 0 if not provided + /// * `limit` - The maximum number of tokens to return + /// + /// returns: List of [Token]s. + /// + fn mt_tokens(&self, from_index: Option, limit: Option) -> Vec; + + /// Get list of all tokens by a given account + /// + /// # Arguments: + /// * `account_id`: a valid NEAR account + /// * `from_index` - Index to start from, defaults to 0 if not provided + /// * `limit` - The maximum number of tokens to return + /// + /// returns: List of [Token]s owner by user + /// + fn mt_tokens_for_owner( + &self, + account_id: AccountId, + from_index: Option, + limit: Option, + ) -> Vec; +} + +/// The contract must implement the following view methods if using metadata extension +pub trait MultiTokenEnumerationMetadata { + /// Get list of all base metadata for the contract + /// + /// Arguments: + /// * `from_index`: a string representing an unsigned 128-bit integer, + /// representing the starting index of tokens to return + /// * `limit`: the maximum number of tokens to return + /// + /// Returns an array of `MTBaseTokenMetadata` objects, as described in the Metadata standard, and an empty array if there are no tokens + fn mt_tokens_base_metadata_all( + &self, + from_index: Option, + limit: Option, + ) -> Vec; +} diff --git a/near-contract-standards/src/multi_token/events.rs b/near-contract-standards/src/multi_token/events.rs new file mode 100644 index 000000000..eda3bb7c8 --- /dev/null +++ b/near-contract-standards/src/multi_token/events.rs @@ -0,0 +1,238 @@ +use crate::event::NearEvent; +use near_sdk::AccountId; +use serde::Serialize; + +/// Data to log for an Multi-token mint event. To log this event, call [`.emit()`](MtMint::emit). +#[must_use] +#[derive(Serialize, Debug, Clone)] +pub struct MtMint<'a> { + pub owner_id: &'a AccountId, + pub token_ids: &'a [&'a str], + pub amounts: &'a [&'a str], + #[serde(skip_serializing_if = "Option::is_none")] + pub memo: Option<&'a str>, +} + +impl MtMint<'_> { + /// Logs the event to the host. This is required to ensure that the event is triggered + /// and to consume the event. + pub fn emit(self) { + Self::emit_many(&[self]) + } + + /// Emits an mt mint event, through [`env::log_str`](near_sdk::env::log_str), + /// where each [`MtMint`] represents the data of each mint. + pub fn emit_many(data: &[MtMint<'_>]) { + new_245_v1(Nep245EventKind::MtMint(data)).emit() + } +} + +#[must_use] +#[derive(Serialize, Debug, Clone)] +pub struct MtTransfer<'a> { + pub old_owner_id: &'a AccountId, + pub new_owner_id: &'a AccountId, + pub token_ids: &'a [&'a str], + pub amounts: &'a [&'a str], + #[serde(skip_serializing_if = "Option::is_none")] + pub authorized_id: Option<&'a AccountId>, + #[serde(skip_serializing_if = "Option::is_none")] + pub memo: Option<&'a str>, +} + +impl MtTransfer<'_> { + /// Logs the event to the host. This is required to ensure that the event is triggered + /// and to consume the event. + pub fn emit(self) { + Self::emit_many(&[self]) + } + + /// Emits an mt transfer event, through [`env::log_str`](near_sdk::env::log_str), + /// where each [`MtTransfer`] represents the data of each transfer. + pub fn emit_many(data: &[MtTransfer<'_>]) { + new_245_v1(Nep245EventKind::MtTransfer(data)).emit() + } +} + +#[must_use] +#[derive(Serialize, Debug, Clone)] +pub struct MtBurn<'a> { + pub owner_id: &'a AccountId, + pub token_ids: &'a [&'a str], + pub amounts: &'a [&'a str], + #[serde(skip_serializing_if = "Option::is_none")] + pub authorized_id: Option<&'a AccountId>, + #[serde(skip_serializing_if = "Option::is_none")] + pub memo: Option<&'a str>, +} + +impl MtBurn<'_> { + /// Logs the event to the host. This is required to ensure that the event is triggered + /// and to consume the event. + pub fn emit(self) { + Self::emit_many(&[self]) + } + + /// Emits an mt burn event, through [`env::log_str`](near_sdk::env::log_str), + /// where each [`MtBurn`] represents the data of each burn. + pub fn emit_many(data: &[MtBurn<'_>]) { + new_245_v1(Nep245EventKind::MtBurn(data)).emit() + } +} + +#[derive(Serialize, Debug)] +pub(crate) struct Nep245Event<'a> { + version: &'static str, + #[serde(flatten)] + event_kind: Nep245EventKind<'a>, +} + +#[derive(Serialize, Debug)] +#[serde(tag = "event", content = "data")] +#[serde(rename_all = "snake_case")] +#[allow(clippy::enum_variant_names)] +enum Nep245EventKind<'a> { + MtMint(&'a [MtMint<'a>]), + MtTransfer(&'a [MtTransfer<'a>]), + MtBurn(&'a [MtBurn<'a>]), +} + +fn new_245<'a>(version: &'static str, event_kind: Nep245EventKind<'a>) -> NearEvent<'a> { + NearEvent::Nep245(Nep245Event { version, event_kind }) +} + +fn new_245_v1(event_kind: Nep245EventKind) -> NearEvent { + new_245("1.0.0", event_kind) +} + +#[cfg(test)] +mod tests { + use super::*; + use near_sdk::{test_utils, AccountId}; + + fn bob() -> AccountId { + AccountId::new_unchecked("bob".to_string()) + } + + fn alice() -> AccountId { + AccountId::new_unchecked("alice".to_string()) + } + + #[test] + fn mt_mint() { + let owner_id = &bob(); + let token_ids = &["0", "1"]; + let amounts = &["1000", "90000"]; + MtMint { owner_id, token_ids, amounts, memo: None }.emit(); + assert_eq!( + test_utils::get_logs()[0], + r#"EVENT_JSON:{"standard":"nep245","version":"1.0.0","event":"mt_mint","data":[{"owner_id":"bob","token_ids":["0","1"],"amounts":["1000","90000"]}]}"# + ); + } + + #[test] + fn mt_mints() { + MtMint::emit_many(&[ + MtMint { + owner_id: &alice(), + token_ids: &["0", "1"], + amounts: &["1000", "90000"], + memo: None, + }, + MtMint { owner_id: &bob(), token_ids: &["2"], amounts: &["1"], memo: Some("has memo") }, + ]); + assert_eq!( + test_utils::get_logs()[0], + r#"EVENT_JSON:{"standard":"nep245","version":"1.0.0","event":"mt_mint","data":[{"owner_id":"alice","token_ids":["0","1"],"amounts":["1000","90000"]},{"owner_id":"bob","token_ids":["2"],"amounts":["1"],"memo":"has memo"}]}"# + ); + } + + #[test] + fn mt_burn() { + let owner_id = &bob(); + let token_ids = &["0", "1"]; + let amounts = &["20", "40"]; + let authorized_id = &alice(); + MtBurn { owner_id, token_ids, amounts, authorized_id: Some(authorized_id), memo: None } + .emit(); + assert_eq!( + test_utils::get_logs()[0], + r#"EVENT_JSON:{"standard":"nep245","version":"1.0.0","event":"mt_burn","data":[{"owner_id":"bob","token_ids":["0","1"],"amounts":["20","40"],"authorized_id":"alice"}]}"# + ); + } + + #[test] + fn mt_burns() { + MtBurn::emit_many(&[ + MtBurn { + owner_id: &alice(), + token_ids: &["0", "1"], + amounts: &["1000", "90000"], + authorized_id: None, + memo: None, + }, + MtBurn { + owner_id: &bob(), + token_ids: &["2"], + amounts: &["1"], + authorized_id: Some(&alice()), + memo: Some("has memo"), + }, + ]); + assert_eq!( + test_utils::get_logs()[0], + r#"EVENT_JSON:{"standard":"nep245","version":"1.0.0","event":"mt_burn","data":[{"owner_id":"alice","token_ids":["0","1"],"amounts":["1000","90000"]},{"owner_id":"bob","token_ids":["2"],"amounts":["1"],"authorized_id":"alice","memo":"has memo"}]}"# + ); + } + + #[test] + fn mt_transfer() { + let old_owner_id = &bob(); + let new_owner_id = &alice(); + let token_ids = &["0", "1"]; + let amounts = &["48", "99"]; + MtTransfer { + old_owner_id, + new_owner_id, + token_ids, + amounts, + authorized_id: None, + memo: None, + } + .emit(); + assert_eq!( + test_utils::get_logs()[0], + r#"EVENT_JSON:{"standard":"nep245","version":"1.0.0","event":"mt_transfer","data":[{"old_owner_id":"bob","new_owner_id":"alice","token_ids":["0","1"],"amounts":["48","99"]}]}"# + ); + } + + #[test] + fn mt_transfers() { + MtTransfer::emit_many(&[ + MtTransfer { + old_owner_id: &alice(), + new_owner_id: &bob(), + token_ids: &["0", "1"], + amounts: &["48", "99"], + authorized_id: None, + memo: Some("has memo"), + }, + MtTransfer { + old_owner_id: &bob(), + new_owner_id: &alice(), + token_ids: &["1", "2"], + amounts: &["1", "99"], + authorized_id: Some(&bob()), + memo: None, + }, + ]); + assert_eq!( + test_utils::get_logs()[0], + concat!( + r#"EVENT_JSON:{"standard":"nep245","version":"1.0.0","event":"mt_transfer","data":["#, + r#"{"old_owner_id":"alice","new_owner_id":"bob","token_ids":["0","1"],"amounts":["48","99"],"memo":"has memo"},"#, + r#"{"old_owner_id":"bob","new_owner_id":"alice","token_ids":["1","2"],"amounts":["1","99"],"authorized_id":"bob"}]}"# + ) + ); + } +} diff --git a/near-contract-standards/src/multi_token/macros.rs b/near-contract-standards/src/multi_token/macros.rs new file mode 100644 index 000000000..f827422a8 --- /dev/null +++ b/near-contract-standards/src/multi_token/macros.rs @@ -0,0 +1,264 @@ +/// The core methods for a basic multi token. Extension standards may be +/// added in addition to this macro. +#[macro_export] +macro_rules! impl_multi_token_core { + ($contract: ident, $token: ident) => { + use $crate::multi_token::core::MultiTokenCore; + use $crate::multi_token::core::MultiTokenResolver; + + #[near_bindgen] + impl MultiTokenCore for $contract { + #[payable] + fn mt_transfer( + &mut self, + receiver_id: AccountId, + token_id: TokenId, + amount: U128, + approval: Option<(AccountId, u64)>, + memo: Option, + ) { + self.$token.mt_transfer(receiver_id, token_id, amount, approval, memo) + } + + #[payable] + fn mt_batch_transfer( + &mut self, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + memo: Option, + ) { + self.$token.mt_batch_transfer(receiver_id, token_ids, amounts, approvals, memo) + } + + #[payable] + fn mt_transfer_call( + &mut self, + receiver_id: AccountId, + token_id: TokenId, + amount: U128, + approval: Option<(AccountId, u64)>, + memo: Option, + msg: String, + ) -> PromiseOrValue { + self.$token.mt_transfer_call(receiver_id, token_id, amount, approval, memo, msg) + } + + #[payable] + fn mt_batch_transfer_call( + &mut self, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + memo: Option, + msg: String, + ) -> PromiseOrValue> { + self.$token.mt_batch_transfer_call( + receiver_id, + token_ids, + amounts, + approvals, + memo, + msg, + ) + } + + fn mt_token(&self, token_id: TokenId) -> Option { + self.$token.mt_token(token_id) + } + + fn mt_token_list(&self, token_ids: Vec) -> Vec> { + self.$token.mt_token_list(token_ids) + } + + fn mt_balance_of(&self, account_id: AccountId, token_id: TokenId) -> U128 { + self.$token.mt_balance_of(account_id, token_id) + } + + fn mt_batch_balance_of( + &self, + account_id: AccountId, + token_ids: Vec, + ) -> Vec { + self.$token.mt_batch_balance_of(account_id, token_ids) + } + + fn mt_supply(&self, token_id: TokenId) -> Option { + self.$token.mt_supply(token_id) + } + + fn mt_batch_supply(&self, token_ids: Vec) -> Vec> { + self.$token.mt_batch_supply(token_ids) + } + } + + #[near_bindgen] + impl MultiTokenResolver for $contract { + #[private] + fn mt_resolve_transfer( + &mut self, + previous_owner_ids: Vec, + receiver_id: AccountId, + token_ids: Vec, + amounts: Vec, + approvals: Option>>, + ) -> Vec { + self.$token.mt_resolve_transfer( + previous_owner_ids, + receiver_id, + token_ids, + amounts, + approvals, + ) + } + } + }; +} + +/// Multi token approval management allows for an escrow system where +/// multiple approvals per token exist. +#[macro_export] +macro_rules! impl_multi_token_approval { + ($contract: ident, $token: ident) => { + use $crate::multi_token::approval::MultiTokenApproval; + + #[near_bindgen] + impl MultiTokenApproval for $contract { + #[payable] + fn mt_approve( + &mut self, + token_ids: Vec, + amounts: Vec, + grantee_id: AccountId, + msg: Option, + ) -> Option { + self.$token.mt_approve(token_ids, amounts, grantee_id, msg) + } + + #[payable] + fn mt_revoke(&mut self, token_ids: Vec, account_id: AccountId) { + self.$token.mt_revoke(token_ids, account_id) + } + + #[payable] + fn mt_revoke_all(&mut self, token_ids: Vec) { + self.$token.mt_revoke_all(token_ids) + } + + fn mt_is_approved( + &self, + owner_id: AccountId, + token_ids: Vec, + approved_account_id: AccountId, + amounts: Vec, + approval_ids: Option>, + ) -> bool { + self.$token.mt_is_approved( + owner_id, + token_ids, + approved_account_id, + amounts, + approval_ids, + ) + } + } + }; +} + +/// Multi-token enumeration adds the extension standard offering several +/// view-only methods to get token supply, tokens per owner, etc. +#[macro_export] +macro_rules! impl_multi_token_enumeration { + ($contract: ident, $token: ident) => { + use $crate::multi_token::enumeration::MultiTokenEnumeration; + + #[near_bindgen] + impl MultiTokenEnumeration for $contract { + fn mt_tokens(&self, from_index: Option, limit: Option) -> Vec { + self.$token.mt_tokens(from_index, limit) + } + + fn mt_tokens_for_owner( + &self, + account_id: AccountId, + from_index: Option, + limit: Option, + ) -> Vec { + self.$token.mt_tokens_for_owner(account_id, from_index, limit) + } + } + }; +} + +/// Ensures that when multi token storage grows by collections adding entries, +/// the storage is be paid by the caller. This ensures that storage cannot grow to a point +/// that the FT contract runs out of Ⓝ. +/// Takes name of the Contract struct, the inner field for the token and optional method name to +/// call when the account was closed. +#[macro_export] +macro_rules! impl_multi_token_storage { + ($contract: ident, $token: ident $(, $on_account_closed_fn:ident)?) => { + use $crate::storage_management::{ + StorageManagement, StorageBalance, StorageBalanceBounds + }; + + #[near_bindgen] + impl StorageManagement for $contract { + #[payable] + fn storage_deposit( + &mut self, + account_id: Option, + registration_only: Option, + ) -> StorageBalance { + self.$token.storage_deposit(account_id, registration_only) + } + + #[payable] + fn storage_withdraw(&mut self, amount: Option) -> StorageBalance { + self.$token.storage_withdraw(amount) + } + + #[payable] + fn storage_unregister(&mut self, force: Option) -> bool { + #[allow(unused_variables)] + if let Some((account_id, balance)) = self.$token.internal_storage_unregister(force) { + $(self.$on_account_closed_fn(account_id, balance);)? + true + } else { + false + } + } + + fn storage_balance_bounds(&self) -> StorageBalanceBounds { + self.$token.storage_balance_bounds() + } + + fn storage_balance_of(&self, account_id: AccountId) -> Option { + self.$token.storage_balance_of(account_id) + } + } + }; +} + +/// Multi-token token holders adds the extension standard offering a +/// view-only methodd to get current token holders with positive balance by token_id +#[macro_export] +macro_rules! impl_multi_token_holders { + ($contract: ident, $token: ident) => { + use $crate::multi_token::token_holders::MultiTokenHolders; + + #[near_bindgen] + impl MultiTokenHolders for $contract { + fn mt_token_holders( + &self, + token_id: TokenId, + from_index: Option, + limit: Option, + ) -> Vec { + self.$token.mt_token_holders(token_id, from_index, limit) + } + } + }; +} diff --git a/near-contract-standards/src/multi_token/metadata.rs b/near-contract-standards/src/multi_token/metadata.rs new file mode 100644 index 000000000..e9060df3d --- /dev/null +++ b/near-contract-standards/src/multi_token/metadata.rs @@ -0,0 +1,80 @@ +use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::require; +use near_sdk::serde::{Deserialize, Serialize}; + +/// Version of standard +pub const MT_METADATA_SPEC: &str = "mt-0.0.1"; + +/// Metadata that will be permanently set at the contract init +#[derive(BorshDeserialize, BorshSerialize, Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] +#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] +#[serde(crate = "near_sdk::serde")] +pub struct MtContractMetadata { + pub spec: String, + pub name: String, + pub symbol: String, + pub icon: Option, + pub base_uri: Option, + pub reference: Option, + pub reference_hash: Option, +} + +/// Metadata for each token +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, BorshDeserialize, BorshSerialize)] +#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] +#[serde(crate = "near_sdk::serde")] +pub struct TokenMetadata { + pub title: Option, + /// Free-form description + pub description: Option, + /// URL to associated media, preferably to decentralized, content-addressed storage + pub media: Option, + /// Base64-encoded sha256 hash of content referenced by the `media` field. Required if `media` is included. + pub media_hash: Option, + /// When token was issued or minted, Unix epoch in milliseconds + pub issued_at: Option, + /// When token expires, Unix epoch in milliseconds + pub expires_at: Option, + /// When token starts being valid, Unix epoch in milliseconds + pub starts_at: Option, + /// When token was last updated, Unix epoch in milliseconds + pub updated_at: Option, + /// Anything extra the MT wants to store on-chain. Can be stringified JSON. + pub extra: Option, + /// URL to an off-chain JSON file with more info. + pub reference: Option, + /// Base64-encoded sha256 hash of JSON from reference field. Required if `reference` is included. + pub reference_hash: Option, +} + +/// Offers details on the contract-level metadata. +pub trait MultiTokenMetadataProvider { + fn mt_metadata(&self) -> MtContractMetadata; +} + +impl MtContractMetadata { + pub fn assert_valid(&self) { + require!(self.spec == MT_METADATA_SPEC, "Spec is not MT metadata"); + require!( + self.reference.is_some() == self.reference_hash.is_some(), + "Reference and reference hash must be present" + ); + if let Some(reference_hash) = &self.reference_hash { + require!(reference_hash.len() == 32, "Hash has to be 32 bytes"); + } + } +} + +impl TokenMetadata { + pub fn assert_valid(&self) { + require!(self.media.is_some() == self.media_hash.is_some()); + if let Some(media_hash) = &self.media_hash { + require!(media_hash.len() == 32, "Media hash has to be 32 bytes"); + } + + require!(self.reference.is_some() == self.reference_hash.is_some()); + if let Some(reference_hash) = &self.reference_hash { + require!(reference_hash.len() == 32, "Reference hash has to be 32 bytes"); + } + } +} diff --git a/near-contract-standards/src/multi_token/mod.rs b/near-contract-standards/src/multi_token/mod.rs new file mode 100644 index 000000000..121d13472 --- /dev/null +++ b/near-contract-standards/src/multi_token/mod.rs @@ -0,0 +1,21 @@ +pub mod core; + +pub mod token; + +pub mod approval; + +pub mod metadata; + +pub mod enumeration; + +pub mod utils; + +pub mod events; + +pub mod macros; + +pub mod storage_impl; + +pub mod token_holders; + +pub use macros::*; diff --git a/near-contract-standards/src/multi_token/storage_impl.rs b/near-contract-standards/src/multi_token/storage_impl.rs new file mode 100644 index 000000000..35637a623 --- /dev/null +++ b/near-contract-standards/src/multi_token/storage_impl.rs @@ -0,0 +1,149 @@ +use crate::multi_token::core::MultiToken; +use crate::storage_management::{StorageBalance, StorageBalanceBounds, StorageManagement}; +use near_sdk::json_types::U128; +use near_sdk::{assert_one_yocto, env, log, require, AccountId, Balance, Promise}; + +impl MultiToken { + /// Internal method that returns the Account ID and the balance in case the account was + /// unregistered. + pub fn internal_storage_unregister( + &mut self, + force: Option, + ) -> Option<(AccountId, Balance)> { + assert_one_yocto(); + let account_id = env::predecessor_account_id(); + let force = force.unwrap_or(false); + if let Some(balance) = self.accounts_storage.get(&account_id) { + let tokens_amount = self.get_tokens_amount(&account_id); + if tokens_amount == 0 || force { + self.accounts_storage.remove(&account_id); + Promise::new(account_id.clone()).transfer(balance); + Some((account_id, balance)) + } else { + env::panic_str( + "Can't unregister the account with the positive amount of tokens without force", + ) + } + } else { + log!("The account {} is not registered", &account_id); + None + } + } + + fn storage_cost(&self, account_id: &AccountId) -> Balance { + if let Some(tokens) = &self.tokens_per_owner { + if let Some(user_tokens) = tokens.get(account_id) { + return (user_tokens.len() * self.storage_usage_per_token + + self.account_storage_usage) as Balance + * env::storage_byte_cost(); + } + } + + (self.account_storage_usage + self.storage_usage_per_token) as Balance + * env::storage_byte_cost() + } + + fn get_tokens_amount(&self, account_id: &AccountId) -> u64 { + if let Some(tokens) = &self.tokens_per_owner { + if let Some(user_tokens) = tokens.get(account_id) { + return user_tokens.len(); + } + } + + 0 + } + + pub fn assert_storage_usage(&self, account_id: &AccountId) { + let storage_cost = self.storage_cost(account_id); + let storage_balance = self.accounts_storage.get(account_id); + if let Some(balance) = storage_balance { + if balance < storage_cost { + env::panic_str( + format!( + "The account doesn't have enough storage balance. Balance {}, required {}", + balance, storage_cost + ) + .as_str(), + ); + } + } else { + env::panic_str("The account is not registered"); + } + } + + fn internal_withdraw_near( + &mut self, + account_id: &AccountId, + amount: Option, + ) -> Balance { + let balance = self.accounts_storage.get(account_id).unwrap_or_else(|| { + env::panic_str(format!("The account {} is not registered", account_id).as_str()) + }); + let amount = amount.unwrap_or(balance); + require!(amount > 0, "Zero withdraw"); + + let new_storage_balance = balance + .checked_sub(amount) + .unwrap_or_else(|| env::panic_str("Not enough balance to withdraw")); + self.accounts_storage.insert(account_id, &new_storage_balance); + new_storage_balance + } +} + +impl StorageManagement for MultiToken { + #[allow(unused_variables)] + fn storage_deposit( + &mut self, + account_id: Option, + registration_only: Option, + ) -> StorageBalance { + let amount: Balance = env::attached_deposit(); + let account_id = account_id.unwrap_or_else(env::predecessor_account_id); + if self.accounts_storage.contains_key(&account_id) && registration_only.is_some() { + log!("The account is already registered, refunding the deposit"); + if amount > 0 { + Promise::new(env::predecessor_account_id()).transfer(amount); + } + } else { + let min_balance: u128 = self.storage_balance_bounds().min.into(); + if amount < min_balance { + env::panic_str("The attached deposit is less than the minimum storage balance"); + } + + let current_amount = self.accounts_storage.get(&account_id).unwrap_or(0); + self.accounts_storage.insert(&account_id, &(amount + current_amount)); + } + self.storage_balance_of(account_id.clone()).unwrap() + } + + fn storage_withdraw(&mut self, amount: Option) -> StorageBalance { + assert_one_yocto(); + let predecessor_account_id = env::predecessor_account_id(); + let to_withdraw = + self.internal_withdraw_near(&predecessor_account_id, amount.map(|a| a.into())); + Promise::new(predecessor_account_id.clone()).transfer(to_withdraw); + self.storage_balance_of(predecessor_account_id).unwrap() + } + + fn storage_unregister(&mut self, force: Option) -> bool { + self.internal_storage_unregister(force).is_some() + } + + fn storage_balance_bounds(&self) -> StorageBalanceBounds { + let required_storage_balance = Balance::from(self.account_storage_usage) + * env::storage_byte_cost() + + Balance::from(self.storage_usage_per_token) * env::storage_byte_cost(); + StorageBalanceBounds { + min: required_storage_balance.into(), + // The max amount of storage is unlimited, because we don't know the amount of tokens + max: None, + } + } + + fn storage_balance_of(&self, account_id: AccountId) -> Option { + self.accounts_storage.get(&account_id).map(|account_balance| StorageBalance { + total: account_balance.into(), + available: account_balance.saturating_sub(self.storage_cost(&account_id)).into(), + }) + } +} diff --git a/near-contract-standards/src/multi_token/token.rs b/near-contract-standards/src/multi_token/token.rs new file mode 100644 index 000000000..c10569b30 --- /dev/null +++ b/near-contract-standards/src/multi_token/token.rs @@ -0,0 +1,43 @@ +use crate::multi_token::metadata::TokenMetadata; +use near_sdk::borsh::{self, BorshDeserialize, BorshSerialize}; +use near_sdk::collections::LookupMap; +use near_sdk::serde::{Deserialize, Serialize}; +pub use near_sdk::{AccountId, Balance}; +use std::collections::HashMap; + +/// Type alias for convenience +pub type TokenId = String; + +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, BorshDeserialize, BorshSerialize)] +#[serde(crate = "near_sdk::serde")] +pub struct Approval { + pub amount: u128, + pub approval_id: u64, +} + +// How Approvals are stored in the contract +pub type ApprovalContainer = LookupMap>>; + +// Represents a record of an Approval that has been temporarily added or removed +// from the ApprovalContainer during cross-contract calls (XCC). +// This data is stored to facilitate possible rollback scenarios where the +// approval needs to be restored. +// +// The tuple contains the following elements: +// - `AccountId`: The Account ID of the owner who initially granted the approval. +// - `Approval`: A struct containing: +// - `amount`: The number of tokens that were initially approved for transfer. +// - `approval_id`: A unique identifier assigned to this specific approval. +pub type ClearedApproval = (AccountId, Approval); + +/// Info on individual token +#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] +#[cfg_attr(feature = "abi", derive(schemars::JsonSchema))] +#[serde(crate = "near_sdk::serde")] +pub struct Token { + pub token_id: String, + pub owner_id: AccountId, + /// Total amount generated + pub supply: u128, + pub metadata: Option, +} diff --git a/near-contract-standards/src/multi_token/token_holders/mod.rs b/near-contract-standards/src/multi_token/token_holders/mod.rs new file mode 100644 index 000000000..c9df4f314 --- /dev/null +++ b/near-contract-standards/src/multi_token/token_holders/mod.rs @@ -0,0 +1,24 @@ +use crate::multi_token::token::TokenId; +use near_sdk::{json_types::U128, AccountId}; + +mod token_holders_impl; + +pub use token_holders_impl::*; + +pub trait MultiTokenHolders { + /// Get a list of all token holders (with pagination) + /// + /// # Arguments: + /// * `token_id` - ID of the token + /// * `from_index`: a string representing an unsigned 128-bit integer, + /// representing the starting index of accounts to return + /// * `limit`: the maximum number of accounts to return + /// returns: List of [AccountId]s. + /// + fn mt_token_holders( + &self, + token_id: TokenId, + from_index: Option, + limit: Option, + ) -> Vec; +} diff --git a/near-contract-standards/src/multi_token/token_holders/token_holders_impl.rs b/near-contract-standards/src/multi_token/token_holders/token_holders_impl.rs new file mode 100644 index 000000000..45a1f2275 --- /dev/null +++ b/near-contract-standards/src/multi_token/token_holders/token_holders_impl.rs @@ -0,0 +1,29 @@ +use crate::multi_token::{core::MultiToken, token::TokenId}; +use near_sdk::{json_types::U128, require, AccountId}; + +use super::MultiTokenHolders; + +impl MultiTokenHolders for MultiToken { + fn mt_token_holders( + &self, + token_id: TokenId, + from_index: Option, + limit: Option, + ) -> Vec { + if let Some(holders_per_token) = &self.holders_per_token { + if let Some(holders) = holders_per_token.get(&token_id) { + let start_index: u128 = from_index.map(From::from).unwrap_or_default(); + require!( + holders.len() as u128 >= start_index, + "Out of bounds, please use a smaller from_index." + ); + let limit = limit.map(|v| v as usize).unwrap_or(usize::MAX); + require!(limit != 0, "Limit cannot be 0"); + + return holders.iter().skip(start_index as usize).take(limit as usize).collect(); + } + } + + vec![] + } +} diff --git a/near-contract-standards/src/multi_token/utils.rs b/near-contract-standards/src/multi_token/utils.rs new file mode 100644 index 000000000..aac00caf0 --- /dev/null +++ b/near-contract-standards/src/multi_token/utils.rs @@ -0,0 +1,56 @@ +use crate::multi_token::token::TokenId; +use near_sdk::{env, require, AccountId, Balance, Promise}; +use std::{fmt::Display, mem::size_of}; + +pub fn refund_deposit_to_account(storage_used: u64, account_id: AccountId) { + let required_cost = env::storage_byte_cost() * Balance::from(storage_used); + let attached_deposit = env::attached_deposit(); + + require!( + required_cost <= attached_deposit, + format!("Must attach {} yoctoNEAR to cover storage", required_cost) + ); + + let refund = attached_deposit - required_cost; + if refund > 1 { + Promise::new(account_id).transfer(refund); + } +} + +/// Assumes that the precedecessor will be refunded +pub fn refund_deposit(storage_used: u64) { + refund_deposit_to_account(storage_used, env::predecessor_account_id()) +} + +// TODO: need a way for end users to determine how much an approval will cost. +pub fn bytes_for_approved_account_id(account_id: &AccountId) -> u64 { + // The extra 4 bytes are coming from Borsh serialization to store the length of the string. + account_id.as_str().len() as u64 + 4 + size_of::() as u64 +} + +pub enum Entity { + Contract, + Token, +} + +impl Display for Entity { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + let as_string = match self { + Entity::Contract => "contract", + Entity::Token => "token", + }; + write!(f, "{}", as_string) + } +} + +pub fn expect_approval(o: Option, entity: Entity) -> T { + o.unwrap_or_else(|| panic!("Approval Management is not supported by {}", entity)) +} + +pub fn expect_approval_for_token(o: Option, token_id: &TokenId) -> T { + o.unwrap_or_else(|| panic!("No approvals for token {}", token_id)) +} + +pub fn unauthorized_assert(account_id: &AccountId) { + require!(account_id == &env::predecessor_account_id()) +}