From 0aa058fbbcb3431a7ed1b6e46d2ab9da8215856e Mon Sep 17 00:00:00 2001 From: maxrobot Date: Wed, 30 Oct 2024 15:20:13 +0000 Subject: [PATCH] feat: updated the swap routes query --- Cargo.lock | 2316 ++++++++++------- Cargo.toml | 46 +- Changelog.md | 3 +- contracts/swap/.gitignore | 15 - contracts/swap/.gitpod.Dockerfile | 17 - contracts/swap/.gitpod.yml | 10 - contracts/swap/Cargo.toml | 49 +- contracts/swap/msg.rs | 70 - contracts/swap/rustfmt.toml | 15 - contracts/swap/src/contract.rs | 179 +- contracts/swap/src/msg.rs | 22 +- contracts/swap/src/state.rs | 27 +- contracts/swap/src/swap.rs | 110 +- .../src/testing/integration_logic_tests.rs | 2142 --------------- ...egration_realistic_tests_exact_quantity.rs | 1795 ------------- ...ntegration_realistic_tests_min_quantity.rs | 1425 ---------- contracts/swap/src/testing/queries_tests.rs | 4 +- contracts/swap/src/testing/test_utils.rs | 423 +-- contracts/swap/src/types.rs | 32 +- docs/admin.md | 71 + docs/copy_to_devnet_setup.sh | 13 + docs/examples.sh | 41 + rust-toolchain.toml | 2 +- 23 files changed, 1736 insertions(+), 7091 deletions(-) delete mode 100644 contracts/swap/.gitignore delete mode 100644 contracts/swap/.gitpod.Dockerfile delete mode 100644 contracts/swap/.gitpod.yml delete mode 100644 contracts/swap/msg.rs delete mode 100644 contracts/swap/rustfmt.toml delete mode 100644 contracts/swap/src/testing/integration_logic_tests.rs delete mode 100644 contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs delete mode 100644 contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs create mode 100644 docs/admin.md create mode 100755 docs/copy_to_devnet_setup.sh create mode 100644 docs/examples.sh diff --git a/Cargo.lock b/Cargo.lock index af5fa65..29e5d74 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,56 +2,184 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.24.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "ahash" -version = "0.7.6" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ - "getrandom", + "cfg-if", "once_cell", "version_check", + "zerocopy", ] [[package]] name = "aho-corasick" -version = "1.0.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] [[package]] -name = "android-tzdata" -version = "0.1.1" +name = "allocator-api2" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] -name = "android_system_properties" -version = "0.1.5" +name = "anyhow" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +checksum = "c042108f3ed77fd83760a5fd79b53be043192bb3b9dba91d8c574c0ada7850c8" + +[[package]] +name = "ark-bls12-381" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c775f0d12169cba7aae4caeb547bb6a50781c7449a8aa53793827c9ec4abf488" dependencies = [ - "libc", + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", ] [[package]] -name = "anyhow" -version = "1.0.71" +name = "ark-ec" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +checksum = "defd9a439d56ac24968cca0571f598a61bc8c55f71d50a89cda591cb750670ba" +dependencies = [ + "ark-ff", + "ark-poly", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", + "itertools 0.10.5", + "num-traits", + "rayon", + "zeroize", +] + +[[package]] +name = "ark-ff" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec847af850f44ad29048935519032c33da8aa03340876d351dfab5660d2966ba" +dependencies = [ + "ark-ff-asm", + "ark-ff-macros", + "ark-serialize", + "ark-std", + "derivative", + "digest 0.10.7", + "itertools 0.10.5", + "num-bigint", + "num-traits", + "paste", + "rayon", + "rustc_version", + "zeroize", +] + +[[package]] +name = "ark-ff-asm" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed4aa4fe255d0bc6d79373f7e31d2ea147bcf486cba1be5ba7ea85abdb92348" +dependencies = [ + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-ff-macros" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7abe79b0e4288889c4574159ab790824d0033b9fdcb2a112a3182fac2e514565" +dependencies = [ + "num-bigint", + "num-traits", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-poly" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d320bfc44ee185d899ccbadfa8bc31aab923ce1558716e1997a1e74057fe86bf" +dependencies = [ + "ark-ff", + "ark-serialize", + "ark-std", + "derivative", + "hashbrown 0.13.2", +] + +[[package]] +name = "ark-serialize" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adb7b85a02b83d2f22f89bd5cac66c9c89474240cb6207cb1efc16d098e822a5" +dependencies = [ + "ark-serialize-derive", + "ark-std", + "digest 0.10.7", + "num-bigint", +] + +[[package]] +name = "ark-serialize-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae3281bc6d0fd7e549af32b52511e1302185bd688fd3359fa36423346ff682ea" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "ark-std" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94893f1e0c6eeab764ade8dc4c0db24caf4fe7cbbaafc0eba0a9030f447b5185" +dependencies = [ + "num-traits", + "rand 0.8.5", + "rayon", +] [[package]] name = "async-trait" -version = "0.1.68" +version = "0.1.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" +checksum = "721cae7de5c34fbb2acd27e21e6d2cf7b886dce0c27388d46c4e6c47ea4318dd" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", ] [[package]] @@ -67,15 +195,24 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" [[package]] -name = "base16ct" -version = "0.1.1" +name = "backtrace" +version = "0.3.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" +checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" +dependencies = [ + "addr2line", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", + "windows-targets 0.52.6", +] [[package]] name = "base16ct" @@ -85,15 +222,15 @@ checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" [[package]] name = "base64" -version = "0.13.1" +version = "0.21.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64" -version = "0.21.7" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" [[package]] name = "base64ct" @@ -103,9 +240,9 @@ checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bech32" -version = "0.9.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" [[package]] name = "bindgen" @@ -113,7 +250,7 @@ version = "0.60.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cexpr", "clang-sys", "clap", @@ -132,18 +269,16 @@ dependencies = [ [[package]] name = "bip32" -version = "0.5.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e40748d60a3296653e45e87e64c6989aebfad607bccce59cc4156c5d81b2f70" +checksum = "aa13fae8b6255872fd86f7faf4b41168661d7d78609f7bfe6771b85c6739a15b" dependencies = [ "bs58", "hmac", - "k256 0.13.1", - "once_cell", - "pbkdf2", + "k256", "rand_core 0.6.4", "ripemd", - "sha2 0.10.6", + "sha2 0.10.8", "subtle", "zeroize", ] @@ -154,6 +289,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + [[package]] name = "block-buffer" version = "0.9.0" @@ -174,45 +315,48 @@ dependencies = [ [[package]] name = "bnum" -version = "0.8.1" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" +checksum = "3e31ea183f6ee62ac8b8a8cf7feddd766317adfb13ff469de57ce033efd6a790" [[package]] name = "bs58" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" dependencies = [ - "sha2 0.9.9", + "sha2 0.10.8", ] [[package]] name = "bumpalo" -version = "3.13.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e2c3daef883ecc1b5d58c15adae93470a91d425f3532ba1695849656af3fc1" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.4.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" dependencies = [ "serde", ] [[package]] name = "cc" -version = "1.0.79" +version = "1.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "c2e7962b54006dcfcc61cb72735f4d89bb97061dd6a7ed882ec6b8ee53714c6f" +dependencies = [ + "shlex", +] [[package]] name = "cexpr" @@ -231,23 +375,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.31" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", "num-traits", - "wasm-bindgen", - "windows-targets 0.48.0", ] [[package]] name = "clang-sys" -version = "1.6.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c688fc74432808e3eb684cae8830a86be1d66a2bd58e1f248ed0960a590baf6f" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" dependencies = [ "glob", "libc", @@ -261,9 +400,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_lex", - "indexmap", + "indexmap 1.9.3", "strsim", "termcolor", "textwrap", @@ -284,20 +423,20 @@ version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "const-oid" -version = "0.9.2" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -305,70 +444,118 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" [[package]] name = "cosmos-sdk-proto" -version = "0.19.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73c9d2043a9e617b0d602fbc0a0ecd621568edbf3a9774890a6d562389bd8e1c" +checksum = "32560304ab4c365791fd307282f76637213d8083c1a98490c35159cd67852237" dependencies = [ - "prost 0.11.9", + "prost 0.12.6", "prost-types", - "tendermint-proto", + "tendermint-proto 0.34.1", +] + +[[package]] +name = "cosmos-sdk-proto" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8ce7f4797cdf5cd18be6555ff3f0a8d37023c2d60f3b2708895d601b85c1c46" +dependencies = [ + "prost 0.13.3", + "tendermint-proto 0.39.1", ] [[package]] name = "cosmrs" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af13955d6f356272e6def9ff5e2450a7650df536d8934f47052a20c76513d2f6" +checksum = "47126f5364df9387b9d8559dcef62e99010e1d4098f39eb3f7ee4b5c254e40ea" dependencies = [ "bip32", - "cosmos-sdk-proto", - "ecdsa 0.16.7", + "cosmos-sdk-proto 0.20.0", + "ecdsa", "eyre", - "getrandom", - "k256 0.13.1", + "k256", "rand_core 0.6.4", "serde", "serde_json", + "signature", "subtle-encoding", - "tendermint", - "tendermint-rpc", + "tendermint 0.34.1", + "tendermint-rpc 0.34.1", "thiserror", ] +[[package]] +name = "cosmrs" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09f90935b72d9fa65a2a784e09f25778637b7e88e9d6f87c717081470f7fa726" +dependencies = [ + "bip32", + "cosmos-sdk-proto 0.25.0", + "ecdsa", + "eyre", + "k256", + "rand_core 0.6.4", + "serde", + "serde_json", + "signature", + "subtle-encoding", + "tendermint 0.39.1", + "tendermint-rpc 0.39.1", + "thiserror", +] + +[[package]] +name = "cosmwasm-core" +version = "2.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f6ceb8624260d0d3a67c4e1a1d43fc7e9406720afbcb124521501dd138f90aa" + [[package]] name = "cosmwasm-crypto" -version = "1.5.1" +version = "2.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad24bc9dae9aac5dc124b4560e3f7678729d701f1bf3cb11140703d91f247d31" +checksum = "4125381e5fd7fefe9f614640049648088015eca2b60d861465329a5d87dfa538" dependencies = [ + "ark-bls12-381", + "ark-ec", + "ark-ff", + "ark-serialize", + "cosmwasm-core", "digest 0.10.7", - "ecdsa 0.16.7", + "ecdsa", "ed25519-zebra", - "k256 0.13.1", + "k256", + "num-traits", + "p256", "rand_core 0.6.4", + "rayon", + "sha2 0.10.8", "thiserror", ] [[package]] name = "cosmwasm-derive" -version = "1.5.1" +version = "2.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca65635b768406eabdd28ba015cc3f2f863ca5a2677a7dc4c237b8ee1298efb3" +checksum = "1b5658b1dc64e10b56ae7a449f678f96932a96f6cfad1769d608d1d1d656480a" dependencies = [ - "syn 1.0.109", + "proc-macro2", + "quote", + "syn 2.0.85", ] [[package]] name = "cosmwasm-schema" -version = "1.5.1" +version = "2.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77e2a6ce6dbcad572495fd9d9c1072793fe682aebfcc09752c3b0de3fa1814d7" +checksum = "f86b4d949b6041519c58993a73f4bbfba8083ba14f7001eae704865a09065845" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -379,79 +566,83 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.5.1" +version = "2.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904408dc6d73fd1d535c764a55370803cccf6b9be5af7423c4db8967058673f0" +checksum = "c8ef1b5835a65fcca3ab8b9a02b4f4dacc78e233a5c2f20b270efb9db0666d12" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.85", ] [[package]] name = "cosmwasm-std" -version = "1.5.1" +version = "2.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ed4564772e5d779235f2d7353e3d66e37793065c3a5155a2978256bf4c5b7d5" +checksum = "70eb7ab0c1e99dd6207496963ba2a457c4128ac9ad9c72a83f8d9808542b849b" dependencies = [ - "base64 0.21.7", + "base64 0.22.1", "bech32", "bnum", + "cosmwasm-core", "cosmwasm-crypto", "cosmwasm-derive", - "derivative", - "forward_ref", + "derive_more", "hex", + "rand_core 0.6.4", "schemars", "serde", - "serde-json-wasm 0.5.1", - "sha2 0.10.6", + "serde-json-wasm", + "sha2 0.10.8", "static_assertions 1.1.0", "thiserror", ] [[package]] -name = "cosmwasm-storage" -version = "1.5.0" +name = "cpufeatures" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd2b4ae72a03e8f56c85df59d172d51d2d7dc9cec6e2bc811e3fb60c588032a4" +checksum = "608697df725056feaccfa42cffdaeeec3fccc4ffc38358ecd19b243e716a78e0" dependencies = [ - "cosmwasm-std", - "serde", + "libc", ] [[package]] -name = "cpufeatures" -version = "0.2.7" +name = "crossbeam-deque" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e4c1eaa2012c47becbbad2ab175484c2a84d1185b566fb2cc5b8707343dfe58" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" dependencies = [ - "libc", + "crossbeam-epoch", + "crossbeam-utils", ] [[package]] -name = "crunchy" -version = "0.2.2" +name = "crossbeam-epoch" +version = "0.9.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] [[package]] -name = "crypto-bigint" -version = "0.4.9" +name = "crossbeam-utils" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" -dependencies = [ - "generic-array", - "rand_core 0.6.4", - "subtle", - "zeroize", -] +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] name = "crypto-bigint" -version = "0.5.2" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4c2f4e1afd912bc40bfd6fed5d9dc1f288e0ba01bfcc835cc5bc3eb13efe15" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ "generic-array", "rand_core 0.6.4", @@ -470,25 +661,30 @@ dependencies = [ ] [[package]] -name = "ct-logs" -version = "0.8.0" +name = "curve25519-dalek" +version = "4.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" dependencies = [ - "sct", + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", ] [[package]] -name = "curve25519-dalek" -version = "3.2.0" +name = "curve25519-dalek-derive" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", - "subtle", - "zeroize", + "proc-macro2", + "quote", + "syn 2.0.85", ] [[package]] @@ -504,30 +700,11 @@ dependencies = [ "zeroize", ] -[[package]] -name = "cw-multi-test" -version = "0.16.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a18afd2e201221c6d72a57f0886ef2a22151bbc9e6db7af276fde8a91081042" -dependencies = [ - "anyhow", - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "cw-utils 1.0.1", - "derivative", - "itertools", - "k256 0.11.6", - "prost 0.9.0", - "schemars", - "serde", - "thiserror", -] - [[package]] name = "cw-storage-plus" -version = "0.14.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c8b264257c4f44c49b7ce09377af63aa040768ecd3fd7bdd2d48a09323a1e90" +checksum = "f13360e9007f51998d42b1bc6b7fa0141f74feae61ed5fd1e5b0a89eec7b5de1" dependencies = [ "cosmwasm-std", "schemars", @@ -535,24 +712,27 @@ dependencies = [ ] [[package]] -name = "cw-storage-plus" -version = "1.2.0" +name = "cw-utils" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" +checksum = "07dfee7f12f802431a856984a32bce1cb7da1e6c006b5409e3981035ce562dec" dependencies = [ + "cosmwasm-schema", "cosmwasm-std", "schemars", "serde", + "thiserror", ] [[package]] -name = "cw-utils" -version = "0.14.0" +name = "cw2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414b91f3d7a619bb26c835119d7095804596a1382ddc1d184c33c1d2c17f6c5e" +checksum = "b04852cd38f044c0751259d5f78255d07590d136b8a86d4e09efdd7666bd6d27" dependencies = [ + "cosmwasm-schema", "cosmwasm-std", - "cw2 0.14.0", + "cw-storage-plus", "schemars", "semver", "serde", @@ -560,63 +740,56 @@ dependencies = [ ] [[package]] -name = "cw-utils" -version = "1.0.1" +name = "darling" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" +checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw2 1.0.1", - "schemars", - "semver", - "serde", - "thiserror", + "darling_core", + "darling_macro", ] [[package]] -name = "cw2" -version = "0.14.0" +name = "darling_core" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa74c324af8e3506fd8d50759a265bead3f87402e413c840042af5d2808463d6" +checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" dependencies = [ - "cosmwasm-std", - "cw-storage-plus 0.14.0", - "schemars", - "serde", + "fnv", + "ident_case", + "proc-macro2", + "quote", + "syn 2.0.85", ] [[package]] -name = "cw2" -version = "1.0.1" +name = "darling_macro" +version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb70cee2cf0b4a8ff7253e6bc6647107905e8eb37208f87d54f67810faa62f8" +checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus 1.2.0", - "schemars", - "serde", + "darling_core", + "quote", + "syn 2.0.85", ] [[package]] name = "der" -version = "0.6.1" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", ] [[package]] -name = "der" -version = "0.7.6" +name = "deranged" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56acb310e15652100da43d130af8d97b509e95af61aab1c5a7939ef24337ee17" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ - "const-oid", - "zeroize", + "powerfmt", ] [[package]] @@ -630,6 +803,27 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_more" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.85", + "unicode-xid", +] + [[package]] name = "digest" version = "0.9.0" @@ -653,44 +847,32 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" - -[[package]] -name = "ecdsa" -version = "0.14.8" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" -dependencies = [ - "der 0.6.1", - "elliptic-curve 0.12.3", - "rfc6979 0.3.1", - "signature 1.6.4", -] +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" -version = "0.16.7" +version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0997c976637b606099b9985693efa3581e84e41f5c11ba5255f88711058ad428" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ - "der 0.7.6", + "der", "digest 0.10.7", - "elliptic-curve 0.13.5", - "rfc6979 0.4.0", - "signature 2.1.0", - "spki 0.7.2", + "elliptic-curve", + "rfc6979", + "signature", + "spki", ] [[package]] name = "ed25519" -version = "2.2.1" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fb04eee5d9d907f29e80ee6b0e78f7e2c82342c63e3580d8c4f69d9d5aad963" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ - "pkcs8 0.10.2", - "signature 2.1.0", + "pkcs8", + "signature", ] [[package]] @@ -708,62 +890,72 @@ dependencies = [ [[package]] name = "ed25519-zebra" -version = "3.1.0" +version = "4.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +checksum = "7d9ce6874da5d4415896cd45ffbc4d1cfc0c4f9c079427bd870742c30f2f65a9" dependencies = [ "curve25519-dalek", - "hashbrown", + "ed25519", + "hashbrown 0.14.5", "hex", "rand_core 0.6.4", - "serde", - "sha2 0.9.9", + "sha2 0.10.8", "zeroize", ] [[package]] name = "either" -version = "1.8.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" [[package]] name = "elliptic-curve" -version = "0.12.3" +version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ - "base16ct 0.1.1", - "crypto-bigint 0.4.9", - "der 0.6.1", + "base16ct", + "crypto-bigint", "digest 0.10.7", - "ff 0.12.1", + "ff", "generic-array", - "group 0.12.1", - "pkcs8 0.9.0", + "group", + "pkcs8", "rand_core 0.6.4", - "sec1 0.3.0", + "sec1", "subtle", "zeroize", ] [[package]] -name = "elliptic-curve" -version = "0.13.5" +name = "encoding_rs" +version = "0.8.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "968405c8fdc9b3bf4df0a6638858cc0b52462836ab6b1c87377785dd09cf1c0b" +checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3" dependencies = [ - "base16ct 0.2.0", - "crypto-bigint 0.5.2", - "digest 0.10.7", - "ff 0.13.0", - "generic-array", - "group 0.13.0", - "pkcs8 0.10.2", - "rand_core 0.6.4", - "sec1 0.7.2", - "subtle", - "zeroize", + "cfg-if", +] + +[[package]] +name = "enumset" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d07a4b049558765cef5f0c1a273c3fc57084d768b44d2f98127aef4cceb17293" +dependencies = [ + "enumset_derive", +] + +[[package]] +name = "enumset_derive" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59c3b24c345d8c314966bdc1832f6c2635bfcce8e7cf363bd115987bba2ee242" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 2.0.85", ] [[package]] @@ -779,6 +971,22 @@ dependencies = [ "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys 0.52.0", +] + [[package]] name = "ethbloom" version = "0.6.4" @@ -817,9 +1025,9 @@ dependencies = [ [[package]] name = "eyre" -version = "0.6.8" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c2b6b5a29c02cdc822728b7d7b8ae1bab3e3b05d44522770ddd49722eeac7eb" +checksum = "7cd915d99f24784cdc19fd37ef22b97e3ff0ae756c7e492e9fbfe897d61e2aec" dependencies = [ "indenter", "once_cell", @@ -827,23 +1035,19 @@ dependencies = [ [[package]] name = "ff" -version = "0.12.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ "rand_core 0.6.4", "subtle", ] [[package]] -name = "ff" -version = "0.13.0" +name = "fiat-crypto" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" -dependencies = [ - "rand_core 0.6.4", - "subtle", -] +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] name = "fixed-hash" @@ -853,7 +1057,7 @@ checksum = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" dependencies = [ "byteorder", "heapsize", - "rand", + "rand 0.5.6", "rustc-hex", "static_assertions 0.2.5", ] @@ -885,19 +1089,13 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "form_urlencoded" -version = "1.1.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] -[[package]] -name = "forward_ref" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" - [[package]] name = "fuchsia-cprng" version = "0.1.1" @@ -906,13 +1104,12 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "futures" -version = "0.3.28" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "65bc07b1a8bc7c85c5f2e110c476c7389b4554ba72af57d8445ea63a576b0876" dependencies = [ "futures-channel", "futures-core", - "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -921,9 +1118,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "2dff15bf788c671c1934e366d07e30c1814a8ef514e1af724a602e8a2fbe1b10" dependencies = [ "futures-core", "futures-sink", @@ -931,66 +1128,39 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" - -[[package]] -name = "futures-executor" -version = "0.3.28" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] +checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e" [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.48", -] +checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6" [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "e575fab7d1e0dcb8d0c7bcf9a63ee213816ab51902e6d244a95819acacf1d4f7" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "f90f7dce0722e95104fcb095585910c0977252f286e354b5e3bd38902cd99988" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -1006,9 +1176,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.9" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c85e1d9ab2eadba7e5040d4e09cbd6d072b76a557ad64e797c2cb9d4da21d7e4" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "js-sys", @@ -1018,21 +1188,16 @@ dependencies = [ ] [[package]] -name = "glob" -version = "0.3.1" +name = "gimli" +version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] -name = "group" -version = "0.12.1" +name = "glob" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "rand_core 0.6.4", - "subtle", -] +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" [[package]] name = "group" @@ -1040,16 +1205,16 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff 0.13.0", + "ff", "rand_core 0.6.4", "subtle", ] [[package]] name = "h2" -version = "0.3.19" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d357c7ae988e7d2182f7d7871d0b963962420b0678b0997ce7de72001aeab782" +checksum = "81fe527a889e1532da5c525686d96d4c2e74cdd345badf8dfef9f6b39dd5f5e8" dependencies = [ "bytes", "fnv", @@ -1057,7 +1222,7 @@ dependencies = [ "futures-sink", "futures-util", "http", - "indexmap", + "indexmap 2.6.0", "slab", "tokio", "tokio-util", @@ -1069,34 +1234,31 @@ name = "hashbrown" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43a3c133739dddd0d2990f9a4bdf8eb4b21ef50e4851ca85ab661199821d510e" dependencies = [ "ahash", ] [[package]] -name = "headers" -version = "0.3.8" +name = "hashbrown" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ - "base64 0.13.1", - "bitflags", - "bytes", - "headers-core", - "http", - "httpdate", - "mime", - "sha1", + "ahash", + "allocator-api2", ] [[package]] -name = "headers-core" -version = "0.2.0" +name = "hashbrown" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" -dependencies = [ - "http", -] +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" [[package]] name = "heapsize" @@ -1118,12 +1280,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.6" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" @@ -1143,11 +1302,20 @@ dependencies = [ "digest 0.10.7", ] +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" -version = "0.2.9" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes", "fnv", @@ -1156,9 +1324,9 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +checksum = "7ceab25649e9960c0311ea418d17bee82c0dcec1bd053b5f9a66e265a693bed2" dependencies = [ "bytes", "http", @@ -1167,15 +1335,15 @@ dependencies = [ [[package]] name = "httparse" -version = "1.8.0" +version = "1.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" +checksum = "7d71d3574edd2771538b901e6549113b4006ece66150fb69c0fb6d9a2adae946" [[package]] name = "httpdate" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" +checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" [[package]] name = "humantime" @@ -1185,9 +1353,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.26" +version = "0.14.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" +checksum = "8c08302e8fa335b151b788c775ff56e7a03ae64ff85c548ee820fecb70356e85" dependencies = [ "bytes", "futures-channel", @@ -1207,71 +1375,31 @@ dependencies = [ "want", ] -[[package]] -name = "hyper-proxy" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca815a891b24fdfb243fa3239c86154392b0953ee584aa1a2a1f66d20cbe75cc" -dependencies = [ - "bytes", - "futures", - "headers", - "http", - "hyper", - "hyper-rustls", - "rustls-native-certs", - "tokio", - "tokio-rustls", - "tower-service", - "webpki", -] - [[package]] name = "hyper-rustls" -version = "0.22.1" +version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f9f7a97316d44c0af9b0301e65010573a853a9fc97046d7331d7f6bc0fd5a64" +checksum = "ec3efd23720e2049821a693cbc7e65ea87c72f1c58ff2f9522ff332b1491e590" dependencies = [ - "ct-logs", "futures-util", + "http", "hyper", - "log", "rustls", - "rustls-native-certs", "tokio", "tokio-rustls", - "webpki", - "webpki-roots", -] - -[[package]] -name = "iana-time-zone" -version = "0.1.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows", ] [[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" +name = "ident_case" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -1308,17 +1436,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.3", +] + +[[package]] +name = "indexmap" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" +dependencies = [ + "equivalent", + "hashbrown 0.15.0", ] [[package]] name = "injective-cosmwasm" -version = "0.2.18" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b6f08b14a23696948d51ba6a050382cbc6e23522efec3ca607a5b1a317de0c" +checksum = "a551fbe7bae0747a41ce81a1e7d5ba96ef089a7f0b3f05ab5a9b510248a709a7" dependencies = [ "cosmwasm-std", - "cw-storage-plus 1.2.0", + "cw-storage-plus", "ethereum-types", "hex", "injective-math", @@ -1331,9 +1469,9 @@ dependencies = [ [[package]] name = "injective-math" -version = "0.2.4" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db4e31ffb7dff274e0be1117bc8f1240f6572d6157be2c4daf13ff82eaaddd85" +checksum = "194fb5cb49537b0b9137d02a563b7019003220fb4affff05ad6cdc6fee3509c9" dependencies = [ "cosmwasm-std", "ethereum-types", @@ -1344,57 +1482,60 @@ dependencies = [ ] [[package]] -name = "injective-protobuf" -version = "0.2.2" +name = "injective-std" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a52219a08aba8c17846fd23d472d1d69c817fe5b427d135273e4c7311edd6972" +checksum = "c0e5193cb9520754f60b9e9af08a662ddf298d2e1a579200b9a447064b64db8b" dependencies = [ + "chrono", "cosmwasm-std", - "ethereum-types", - "num", - "protobuf", - "protobuf-codegen-pure", + "injective-std-derive", + "prost 0.12.6", + "prost-types", "schemars", "serde", - "subtle-encoding", + "serde-cw-value", ] [[package]] -name = "injective-std" -version = "0.1.5" +name = "injective-std-derive" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd7a5b52d19dca05823c7e4b481d41b49c04a0e56f66a5c92396a6fdd3314710" +checksum = "2721d8c2fed1fd1dff4cd6d119711a74acf27a6eeea6bf09cd44d192119e52ea" dependencies = [ - "chrono", "cosmwasm-std", - "osmosis-std-derive", - "prost 0.11.9", - "prost-types", - "schemars", - "serde", - "serde-cw-value", + "itertools 0.10.5", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] name = "injective-test-tube" -version = "1.1.7" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61cb772fd4c8c1da872b742633e73928cbf1cf0505a09ec8ad41934a4d7f10b4" +checksum = "2a45747c74fca8aedafd94df74c6b9edf091c586ead96957e3c17e96abd6228b" dependencies = [ - "base64 0.13.1", + "base64 0.21.7", "bindgen", - "cosmrs", + "cosmrs 0.15.0", "cosmwasm-std", "hex", "injective-cosmwasm", "injective-std", - "prost 0.11.9", + "prost 0.12.6", "serde", "serde_json", "test-tube-inj", "thiserror", ] +[[package]] +name = "ipnet" +version = "2.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc24109865250148c2e0f3d25d4f0f479571723792d3802153c60922a4fb708" + [[package]] name = "itertools" version = "0.10.5" @@ -1405,51 +1546,55 @@ dependencies = [ ] [[package]] -name = "itoa" -version = "1.0.6" +name = "itertools" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] [[package]] -name = "js-sys" -version = "0.3.63" +name = "itertools" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f37a4a5928311ac501dee68b3c7613a1037d0edb30c8e5427bd832d55d1b790" +checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" dependencies = [ - "wasm-bindgen", + "either", ] [[package]] -name = "k256" -version = "0.11.6" +name = "itoa" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" + +[[package]] +name = "js-sys" +version = "0.3.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a88f1bda2bd75b0452a14784937d796722fdebfe50df998aeb3f0b7603019a9" dependencies = [ - "cfg-if", - "ecdsa 0.14.8", - "elliptic-curve 0.12.3", - "sha2 0.10.6", + "wasm-bindgen", ] [[package]] name = "k256" -version = "0.13.1" +version = "0.13.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" +checksum = "f6e3919bbaa2945715f0bb6d3934a173d1e9a59ac23767fbaaef277265a7411b" dependencies = [ "cfg-if", - "ecdsa 0.16.7", - "elliptic-curve 0.13.5", - "once_cell", - "sha2 0.10.6", - "signature 2.1.0", + "ecdsa", + "elliptic-curve", + "sha2 0.10.8", ] [[package]] name = "lazy_static" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "lazycell" @@ -1459,34 +1604,37 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.144" +version = "0.2.161" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b00cc1c228a6782d0f076e7b232802e0c5689d41bb5df366f2a6b6621cfdfe1" +checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" [[package]] name = "libloading" -version = "0.7.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "winapi", + "windows-targets 0.52.6", ] +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + [[package]] name = "log" -version = "0.4.17" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" -version = "2.5.0" +version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mime" @@ -1500,16 +1648,25 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" +[[package]] +name = "miniz_oxide" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" +dependencies = [ + "adler2", +] + [[package]] name = "mio" -version = "0.8.6" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" dependencies = [ + "hermit-abi 0.3.9", "libc", - "log", "wasi", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] @@ -1522,39 +1679,21 @@ dependencies = [ "minimal-lexical", ] -[[package]] -name = "num" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" -dependencies = [ - "num-bigint", - "num-complex", - "num-integer", - "num-iter", - "num-rational", - "num-traits", -] - [[package]] name = "num-bigint" -version = "0.4.3" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] -name = "num-complex" -version = "0.4.3" +name = "num-conv" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" -dependencies = [ - "num-traits", -] +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-derive" @@ -1569,67 +1708,42 @@ dependencies = [ [[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-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.4.1" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", - "num-bigint", - "num-integer", "num-traits", ] [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] -name = "num_cpus" -version = "1.15.0" +name = "object" +version = "0.36.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" dependencies = [ - "hermit-abi 0.2.6", - "libc", + "memchr", ] [[package]] name = "once_cell" -version = "1.17.1" +version = "1.20.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" [[package]] name = "opaque-debug" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl-probe" @@ -1639,37 +1753,27 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "os_str_bytes" -version = "6.5.0" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] -name = "osmosis-std-derive" -version = "0.15.3" +name = "p256" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4d482a16be198ee04e0f94e10dd9b8d02332dcf33bc5ea4b255e7e25eedc5df" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" dependencies = [ - "itertools", - "proc-macro2", - "quote", - "syn 1.0.109", + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2 0.10.8", ] [[package]] name = "paste" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" - -[[package]] -name = "pbkdf2" -version = "0.12.1" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0ca0b5a68607598bf3bad68f32227a8164f6254833f84eafaac409cd6746c31" -dependencies = [ - "digest 0.10.7", - "hmac", -] +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "peeking_take_while" @@ -1679,9 +1783,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "peg" -version = "0.7.0" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07c0b841ea54f523f7aa556956fbd293bcbe06f2e67d2eb732b7278aaf1d166a" +checksum = "295283b02df346d1ef66052a757869b2876ac29a6bb0ac3f5f7cd44aebe40e8f" dependencies = [ "peg-macros", "peg-runtime", @@ -1689,9 +1793,9 @@ dependencies = [ [[package]] name = "peg-macros" -version = "0.7.0" +version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aa52829b8decbef693af90202711348ab001456803ba2a98eb4ec8fb70844c" +checksum = "bdad6a1d9cf116a059582ce415d5f5566aabcd4008646779dab7fdc2a9a9d426" dependencies = [ "peg-runtime", "proc-macro2", @@ -1700,41 +1804,41 @@ dependencies = [ [[package]] name = "peg-runtime" -version = "0.7.0" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c719dcf55f09a3a7e764c6649ab594c18a177e3599c467983cdf644bfc0a4088" +checksum = "e3aeb8f54c078314c2065ee649a7241f46b9d8e418e1a9581ba0546657d7aa3a" [[package]] name = "percent-encoding" -version = "2.2.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project" -version = "1.1.0" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c95a7476719eab1e366eaf73d0260af3021184f18177925b07f54b30089ceead" +checksum = "be57f64e946e500c8ee36ef6331845d40a93055567ec57e8fae13efd33759b95" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.1.0" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" +checksum = "3c0f5fad0874fc7abcd4d750e76917eaebbecaa2c20bde22e1dbeeba8beb758c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", ] [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" [[package]] name = "pin-utils" @@ -1744,22 +1848,36 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkcs8" -version = "0.9.0" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der 0.6.1", - "spki 0.6.0", + "der", + "spki", ] [[package]] -name = "pkcs8" -version = "0.10.2" +name = "powerfmt" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" + +[[package]] +name = "ppv-lite86" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" dependencies = [ - "der 0.7.6", - "spki 0.7.2", + "elliptic-curve", ] [[package]] @@ -1774,101 +1892,73 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.76" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" +checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" dependencies = [ "unicode-ident", ] [[package]] name = "prost" -version = "0.9.0" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" +checksum = "deb1435c188b76130da55f17a466d252ff7b1418b2ad3e037d127b94e3411f29" dependencies = [ "bytes", - "prost-derive 0.9.0", + "prost-derive 0.12.6", ] [[package]] name = "prost" -version = "0.11.9" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" dependencies = [ "bytes", - "prost-derive 0.11.9", + "prost-derive 0.13.3", ] [[package]] name = "prost-derive" -version = "0.9.0" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" +checksum = "81bddcdb20abf9501610992b6759a4c888aef7d1a7247ef75e2404275ac24af1" dependencies = [ "anyhow", - "itertools", + "itertools 0.12.1", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.85", ] [[package]] name = "prost-derive" -version = "0.11.9" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" dependencies = [ "anyhow", - "itertools", + "itertools 0.13.0", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.85", ] [[package]] name = "prost-types" -version = "0.11.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" -dependencies = [ - "prost 0.11.9", -] - -[[package]] -name = "protobuf" -version = "2.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" -dependencies = [ - "bytes", -] - -[[package]] -name = "protobuf-codegen" -version = "2.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "033460afb75cf755fcfc16dfaed20b86468082a2ea24e05ac35ab4a099a017d6" -dependencies = [ - "protobuf", -] - -[[package]] -name = "protobuf-codegen-pure" -version = "2.28.0" +version = "0.12.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95a29399fc94bcd3eeaa951c715f7bea69409b2445356b00519740bcd6ddd865" +checksum = "9091c90b0a32608e984ff2fa4091273cbdd755d54935c51d520887f4a1dbd5b0" dependencies = [ - "protobuf", - "protobuf-codegen", + "prost 0.12.6", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1886,6 +1976,27 @@ dependencies = [ "winapi", ] +[[package]] +name = "rand" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" +dependencies = [ + "libc", + "rand_chacha", + "rand_core 0.6.4", +] + +[[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.3.1" @@ -1901,12 +2012,6 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" - [[package]] name = "rand_core" version = "0.6.4" @@ -1916,11 +2021,43 @@ dependencies = [ "getrandom", ] +[[package]] +name = "rayon" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +dependencies = [ + "crossbeam-deque", + "crossbeam-utils", +] + [[package]] name = "regex" -version = "1.8.3" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390" +checksum = "368758f23274712b504848e9d5a6f010445cc8b87a7cdb4d7cbee666c1288da3" dependencies = [ "aho-corasick", "memchr", @@ -1929,19 +2066,49 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.7.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] -name = "rfc6979" -version = "0.3.1" +name = "reqwest" +version = "0.11.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +checksum = "dd67538700a17451e7cba03ac727fb961abb7607553461627b97de0b89cf4a62" dependencies = [ - "crypto-bigint 0.4.9", - "hmac", - "zeroize", + "base64 0.21.7", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2", + "http", + "http-body", + "hyper", + "hyper-rustls", + "ipnet", + "js-sys", + "log", + "mime", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls", + "rustls-native-certs", + "rustls-pemfile", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "system-configuration", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", ] [[package]] @@ -1956,17 +2123,17 @@ dependencies = [ [[package]] name = "ring" -version = "0.16.20" +version = "0.17.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +checksum = "c17fa4cb658e3583423e915b9f3acc01cceaee1860e33d59ebae66adc3a2dc0d" dependencies = [ "cc", + "cfg-if", + "getrandom", "libc", - "once_cell", "spin", "untrusted", - "web-sys", - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -1987,6 +2154,12 @@ dependencies = [ "rustc-hex", ] +[[package]] +name = "rustc-demangle" +version = "0.1.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" + [[package]] name = "rustc-hash" version = "1.1.0" @@ -1999,36 +2172,76 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "0.38.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa260229e6538e52293eeb577aabd09945a09d6d9cc0fc550ed7529056c2e32a" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.52.0", +] + [[package]] name = "rustls" -version = "0.19.1" +version = "0.21.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +checksum = "3f56a14d1f48b391359b22f731fd4bd7e43c97f3c50eee276f3aa09c94784d3e" dependencies = [ - "base64 0.13.1", "log", "ring", + "rustls-webpki", "sct", - "webpki", ] [[package]] name = "rustls-native-certs" -version = "0.5.0" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a07b7c1885bd8ed3831c289b7870b13ef46fe0e856d288c30d9cc17d75a2092" +checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00" dependencies = [ "openssl-probe", - "rustls", + "rustls-pemfile", "schannel", "security-framework", ] +[[package]] +name = "rustls-pemfile" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c74cae0a4cf6ccbbf5f359f08efdf8ee7e1dc532573bf0db71968cb56b1448c" +dependencies = [ + "base64 0.21.7", +] + +[[package]] +name = "rustls-webpki" +version = "0.101.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b6275d1ee7a1cd780b64aca7726599a1dbc893b1e64144529e55c3c2f745765" +dependencies = [ + "ring", + "untrusted", +] + [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -2041,20 +2254,21 @@ dependencies = [ [[package]] name = "schannel" -version = "0.1.21" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "01227be5826fa0690321a2ba6c5cd57a19cf3f6a09e76973b58e61de6ab9d1c1" dependencies = [ - "windows-sys 0.42.0", + "windows-sys 0.59.0", ] [[package]] name = "schemars" -version = "0.8.16" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", + "enumset", "schemars_derive", "serde", "serde_json", @@ -2062,21 +2276,21 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.16" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.85", ] [[package]] name = "sct" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b362b83898e0e69f38515b82ee15aa80636befe47c3b6d3d89a911e78fc228ce" +checksum = "da046153aa2352493d6cb7da4b6e5c0c057d8a1d0a9aa8560baffdd945acd414" dependencies = [ "ring", "untrusted", @@ -2084,39 +2298,25 @@ dependencies = [ [[package]] name = "sec1" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" -dependencies = [ - "base16ct 0.1.1", - "der 0.6.1", - "generic-array", - "pkcs8 0.9.0", - "subtle", - "zeroize", -] - -[[package]] -name = "sec1" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0aec48e813d6b90b15f0b8948af3c63483992dee44c03e9930b3eebdabe046e" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ - "base16ct 0.2.0", - "der 0.7.6", + "base16ct", + "der", "generic-array", - "pkcs8 0.10.2", + "pkcs8", "subtle", "zeroize", ] [[package]] name = "security-framework" -version = "2.9.1" +version = "2.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fc758eb7bffce5b308734e9b0c1468893cae9ff70ebf13e7090be8dcbcc83a8" +checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ - "bitflags", + "bitflags 2.6.0", "core-foundation", "core-foundation-sys", "libc", @@ -2125,9 +2325,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.9.0" +version = "2.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f51d0c0d83bec45f16480d0ce0058397a69e48fcdc52d1dc8855fb68acbd31a7" +checksum = "ea4a292869320c0272d7bc55a5a6aafaff59b4f63404a003887b679a2e05b4b6" dependencies = [ "core-foundation-sys", "libc", @@ -2135,15 +2335,15 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.17" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.195" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "f55c3193aca71c12ad7890f1785d2b73e1b9f63a0bbc353c08ef26fe03fc56b5" dependencies = [ "serde_derive", ] @@ -2157,15 +2357,6 @@ dependencies = [ "serde", ] -[[package]] -name = "serde-json-wasm" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" -dependencies = [ - "serde", -] - [[package]] name = "serde-json-wasm" version = "1.0.1" @@ -2177,66 +2368,77 @@ dependencies = [ [[package]] name = "serde_bytes" -version = "0.11.9" +version = "0.11.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.214" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "de523f781f095e28fa605cdce0f8307e451cc0fd14e2eb4cd2e98a355b147766" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", ] [[package]] name = "serde_derive_internals" -version = "0.26.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.85", ] [[package]] name = "serde_json" -version = "1.0.96" +version = "1.0.132" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" +checksum = "d726bfaff4b320266d395898905d0eba0345aae23b54aee3a737e260fd46db03" dependencies = [ "itoa", + "memchr", "ryu", "serde", ] [[package]] name = "serde_repr" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", +] + +[[package]] +name = "serde_spanned" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" +dependencies = [ + "serde", ] [[package]] -name = "sha1" -version = "0.10.5" +name = "serde_urlencoded" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", + "form_urlencoded", + "itoa", + "ryu", + "serde", ] [[package]] @@ -2254,9 +2456,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.6" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ "cfg-if", "cpufeatures", @@ -2265,25 +2467,15 @@ dependencies = [ [[package]] name = "shlex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" - -[[package]] -name = "signature" -version = "1.6.4" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" -dependencies = [ - "digest 0.10.7", - "rand_core 0.6.4", -] +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "signature" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e1788eed21689f9cf370582dfc467ef36ed9c707f073528ddafa8d83e3b8500" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ "digest 0.10.7", "rand_core 0.6.4", @@ -2291,47 +2483,37 @@ dependencies = [ [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "socket2" -version = "0.4.9" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "winapi", + "windows-sys 0.52.0", ] [[package]] name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "spki" -version = "0.6.0" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" -dependencies = [ - "base64ct", - "der 0.6.1", -] +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "spki" -version = "0.7.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", - "der 0.7.6", + "der", ] [[package]] @@ -2354,9 +2536,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" -version = "2.5.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "subtle-encoding" @@ -2375,27 +2557,21 @@ checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" [[package]] name = "swap-contract" -version = "1.0.2" +version = "1.1.0" dependencies = [ - "cosmos-sdk-proto", "cosmwasm-schema", "cosmwasm-std", - "cosmwasm-storage", - "cw-multi-test", - "cw-storage-plus 0.14.0", - "cw-utils 0.14.0", - "cw2 0.14.0", + "cw-storage-plus", + "cw-utils", + "cw2", "injective-cosmwasm", "injective-math", - "injective-protobuf", "injective-std", "injective-test-tube", - "num-traits", - "prost 0.11.9", - "protobuf", + "prost 0.12.6", "schemars", "serde", - "serde-json-wasm 1.0.1", + "serde-json-wasm", "thiserror", ] @@ -2412,20 +2588,47 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.48" +version = "2.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" +checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "tendermint" -version = "0.32.0" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a46ec6b25b028097ab682ffae11d09d64fe1e2535833b902f26a278a0f88a705" +checksum = "15ab8f0a25d0d2ad49ac615da054d6a76aa6603ff95f7d18bafdd34450a1a04b" dependencies = [ "bytes", "digest 0.10.7", @@ -2433,50 +2636,94 @@ dependencies = [ "ed25519-consensus", "flex-error", "futures", - "k256 0.13.1", + "k256", "num-traits", "once_cell", - "prost 0.11.9", + "prost 0.12.6", "prost-types", "ripemd", "serde", "serde_bytes", "serde_json", "serde_repr", - "sha2 0.10.6", - "signature 2.1.0", + "sha2 0.10.8", + "signature", + "subtle", + "subtle-encoding", + "tendermint-proto 0.34.1", + "time", + "zeroize", +] + +[[package]] +name = "tendermint" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2f3afea7809ffaaf1e5d9c3c9997cb3a834df7e94fbfab2fad2bc4577f1cde41" +dependencies = [ + "bytes", + "digest 0.10.7", + "ed25519", + "ed25519-consensus", + "flex-error", + "futures", + "k256", + "num-traits", + "once_cell", + "prost 0.13.3", + "ripemd", + "serde", + "serde_bytes", + "serde_json", + "serde_repr", + "sha2 0.10.8", + "signature", "subtle", "subtle-encoding", - "tendermint-proto", + "tendermint-proto 0.39.1", "time", "zeroize", ] [[package]] name = "tendermint-config" -version = "0.32.0" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dbb7610ef8422d5886116868e48ab6a9ea72859b3bf9021c6d87318e5600225" +checksum = "e1a02da769166e2052cd537b1a97c78017632c2d9e19266367b27e73910434fc" dependencies = [ "flex-error", "serde", "serde_json", - "tendermint", - "toml", + "tendermint 0.34.1", + "toml 0.5.11", + "url", +] + +[[package]] +name = "tendermint-config" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8add7b85b0282e5901521f78fe441956ac1e2752452f4e1f2c0ce7e1f10d485" +dependencies = [ + "flex-error", + "serde", + "serde_json", + "tendermint 0.39.1", + "toml 0.8.19", "url", ] [[package]] name = "tendermint-proto" -version = "0.32.0" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce23c8ff0e6634eb4c3c4aeed45076dc97dac91aac5501a905a67fa222e165b" +checksum = "b797dd3d2beaaee91d2f065e7bdf239dc8d80bba4a183a288bc1279dd5a69a1e" dependencies = [ "bytes", "flex-error", "num-derive", "num-traits", - "prost 0.11.9", + "prost 0.12.6", "prost-types", "serde", "serde_bytes", @@ -2484,32 +2731,78 @@ dependencies = [ "time", ] +[[package]] +name = "tendermint-proto" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf3abf34ecf33125621519e9952688e7a59a98232d51538037ba21fbe526a802" +dependencies = [ + "bytes", + "flex-error", + "prost 0.13.3", + "serde", + "serde_bytes", + "subtle-encoding", + "time", +] + [[package]] name = "tendermint-rpc" -version = "0.32.0" +version = "0.34.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd2cc789170db5a35d4e0bb2490035c03ef96df08f119bee25fd8dab5a09aa25" +checksum = "71afae8bb5f6b14ed48d4e1316a643b6c2c3cbad114f510be77b4ed20b7b3e42" +dependencies = [ + "async-trait", + "bytes", + "flex-error", + "futures", + "getrandom", + "peg", + "pin-project", + "rand 0.8.5", + "reqwest", + "semver", + "serde", + "serde_bytes", + "serde_json", + "subtle", + "subtle-encoding", + "tendermint 0.34.1", + "tendermint-config 0.34.1", + "tendermint-proto 0.34.1", + "thiserror", + "time", + "tokio", + "tracing", + "url", + "uuid", + "walkdir", +] + +[[package]] +name = "tendermint-rpc" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9693f42544bf3b41be3cbbfa418650c86e137fb8f5a57981659a84b677721ecf" dependencies = [ "async-trait", "bytes", "flex-error", "futures", "getrandom", - "http", - "hyper", - "hyper-proxy", - "hyper-rustls", "peg", "pin-project", + "rand 0.8.5", + "reqwest", "semver", "serde", "serde_bytes", "serde_json", "subtle", "subtle-encoding", - "tendermint", - "tendermint-config", - "tendermint-proto", + "tendermint 0.39.1", + "tendermint-config 0.39.1", + "tendermint-proto 0.39.1", "thiserror", "time", "tokio", @@ -2521,61 +2814,63 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.2.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "test-tube-inj" -version = "1.1.1" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae2aa4f0386a041eea657c0d0b4438f1d757a231d0736c1b3413b9c84cfa36db" +checksum = "662c9081865602de48ca4c7cd2dbd6a1645060eea46614eb789c68f20c039707" dependencies = [ - "base64 0.13.1", - "cosmrs", + "base64 0.21.7", + "cosmrs 0.20.0", "cosmwasm-std", - "prost 0.11.9", + "prost 0.13.3", "serde", "serde_json", - "tendermint-proto", "thiserror", ] [[package]] name = "textwrap" -version = "0.16.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "5d11abd9594d9b38965ef50805c5e469ca9cc6f197f883f717e0269a3057b3d5" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +checksum = "ae71770322cbd277e69d762a16c444af02aa0575ac0d174f0b9562d3b37f8602" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", ] [[package]] name = "time" -version = "0.3.21" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f3403384eaacbca9923fa06940178ac13e4edb725486d70e8e15881d0c836cc" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ + "deranged", + "num-conv", + "powerfmt", "serde", "time-core", "time-macros", @@ -2583,16 +2878,17 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.9" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "372950940a5f07bf38dbe211d7283c9e6d7327df53794992d293e534c733d09b" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] @@ -2607,9 +2903,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.6.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +checksum = "445e881f4f6d382d5f27c034e25eb92edd7c784ceab92a0937db7f2e9471b938" dependencies = [ "tinyvec_macros", ] @@ -2622,55 +2918,52 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.28.1" +version = "1.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0aa32867d44e6f2ce3385e89dceb990188b8bb0fb25b0cf576647a6f98ac5105" +checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" dependencies = [ - "autocfg", + "backtrace", "bytes", "libc", "mio", - "num_cpus", "pin-project-lite", "socket2", "tokio-macros", - "windows-sys 0.48.0", + "windows-sys 0.52.0", ] [[package]] name = "tokio-macros" -version = "2.1.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", ] [[package]] name = "tokio-rustls" -version = "0.22.0" +version = "0.24.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6844de72e57df1980054b38be3a9f4702aba4858be64dd700181a8a6d0e1b6" +checksum = "c28327cf380ac148141087fbfb9de9d7bd4e84ab5d2c28fbc911d753de8a7081" dependencies = [ "rustls", "tokio", - "webpki", ] [[package]] name = "tokio-util" -version = "0.7.8" +version = "0.7.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" +checksum = "61e7c3654c13bcd040d4a03abee2c75b1d14a37b423cf5a813ceae1cc903ec6a" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -2682,43 +2975,76 @@ dependencies = [ "serde", ] +[[package]] +name = "toml" +version = "0.8.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + +[[package]] +name = "toml_datetime" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_edit" +version = "0.22.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae48d6208a266e853d946088ed816055e556cc6028c5e8e2b84d9fa5dd7c7f5" +dependencies = [ + "indexmap 2.6.0", + "serde", + "serde_spanned", + "toml_datetime", + "winnow", +] + [[package]] name = "tower-service" -version = "0.3.2" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if", "pin-project-lite", "tracing-core", ] [[package]] name = "tracing-core" -version = "0.1.31" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", ] [[package]] name = "try-lock" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "uint" @@ -2746,36 +3072,42 @@ dependencies = [ [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "5ab17db44d7388991a428b2ee655ce0c212e862eff1768a455c58f9aad6e7893" [[package]] name = "unicode-ident" -version = "1.0.9" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" +checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "5033c97c4262335cded6d6fc3e5c18ab755e1a3dc96376350f3d8e9f009ad956" dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + [[package]] name = "untrusted" -version = "0.7.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.3.1" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna", @@ -2784,21 +3116,21 @@ dependencies = [ [[package]] name = "uuid" -version = "0.8.2" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7" +checksum = "f8c5f0a0af699448548ad1a2fbf920fb4bee257eae39953ba95cb84891a0446a" [[package]] name = "version_check" -version = "0.9.4" +version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "walkdir" -version = "2.3.3" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" dependencies = [ "same-file", "winapi-util", @@ -2806,11 +3138,10 @@ dependencies = [ [[package]] name = "want" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "log", "try-lock", ] @@ -2822,34 +3153,47 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.86" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bba0e8cb82ba49ff4e229459ff22a191bbe9a1cb3a341610c9c33efc27ddf73" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", + "once_cell", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.86" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b04bc93f9d6bdee709f6bd2118f57dd6679cf1176a1af464fca3ab0d66d8fb" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", "once_cell", "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc7ec4f8827a71586374db3e87abdb5a2bb3a15afed140221307c3ec06b1f63b" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" -version = "0.2.86" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14d6b024f1a526bb0234f52840389927257beb670610081360e5a03c5df9c258" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2857,61 +3201,43 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.86" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.86" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9d5b4305409d1fc9482fee2d7f9bcbf24b3972bf59817ef757e23982242a93" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "web-sys" -version = "0.3.63" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bdd9ef4e984da1187bf8110c5cf5b845fbc87a23602cdf912386a76fcd3a7c2" +checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112" dependencies = [ "js-sys", "wasm-bindgen", ] -[[package]] -name = "webpki" -version = "0.21.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8e38c0608262c46d4a56202ebabdeb094cef7e560ca7a226c6bf055188aa4ea" -dependencies = [ - "ring", - "untrusted", -] - -[[package]] -name = "webpki-roots" -version = "0.21.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aabe153544e473b775453675851ecc86863d2a81d786d741f6b76778f2a48940" -dependencies = [ - "webpki", -] - [[package]] name = "which" -version = "4.4.0" +version = "4.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2441c784c52b289a054b7201fc93253e288f094e2f4be9058343127c4226a269" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" dependencies = [ "either", - "libc", + "home", "once_cell", + "rustix", ] [[package]] @@ -2932,11 +3258,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "winapi", + "windows-sys 0.59.0", ] [[package]] @@ -2945,167 +3271,199 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" -dependencies = [ - "windows-targets 0.48.0", -] - [[package]] name = "windows-sys" -version = "0.42.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows-targets 0.48.5", ] [[package]] name = "windows-sys" -version = "0.45.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.42.2", + "windows-targets 0.52.6", ] [[package]] name = "windows-sys" -version = "0.48.0" +version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets 0.48.0", + "windows-targets 0.52.6", ] [[package]] name = "windows-targets" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "winnow" +version = "0.6.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36c1fec1a2bb5866f07c25f68c26e565c4c200aebb96d7e55710c19d3e8ac49b" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.50.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "524e57b2c537c0f9b1e69f1965311ec12182b4122e45035b1508cd24d2adadb1" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + +[[package]] +name = "zerocopy" +version = "0.7.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" +dependencies = [ + "byteorder", + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.85", +] [[package]] name = "zeroize" -version = "1.6.0" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" dependencies = [ "zeroize_derive", ] @@ -3118,5 +3476,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.48", + "syn 2.0.85", ] diff --git a/Cargo.toml b/Cargo.toml index 38ef009..9c67df5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,21 +1,35 @@ [workspace] -members = ["contracts/*"] +members = [ "contracts/*" ] +resolver = "2" -[profile.release.package.injective-cosmwasm] -codegen-units = 1 -incremental = false +[workspace.package] +edition = "2021" + +[workspace.dependencies] +cosmwasm-schema = { version = "2.1.1" } +cosmwasm-std = { version = "2.1.0", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "iterator", "stargate" ] } +cw-multi-test = { version = "0.16.2" } +cw-storage-plus = { version = "2.0.0" } +cw-utils = { version = "2.0.0" } +cw2 = { version = "2.0.0" } +injective-cosmwasm = { version = "0.3.0" } +injective-math = { version = "0.3.0" } +injective-std = { version = "1.13.0" } +injective-test-tube = { version = "1.13.2" } +prost = { version = "0.12.6" } +schemars = { version = "0.8.16", features = [ "enumset" ] } +serde = { version = "1.0.193", default-features = false, features = [ "derive" ] } +serde-json-wasm = { version = "1.0.1" } +serde_json = { version = "1.0.120" } +thiserror = { version = "1.0.52" } [profile.release] -opt-level = 3 -debug = false -rpath = false -lto = true +codegen-units = 1 +debug = false debug-assertions = false -codegen-units = 1 -panic = 'abort' -incremental = false -overflow-checks = true - -[patch.crates-io] -#cw-multi-test = { path = "../cw-multi-test" } -#cw-multi-test = { git = "https://github.com/InjectiveLabs/cw-multi-test.git", branch ="feature/custom_address_generator" } \ No newline at end of file +incremental = false +lto = true +opt-level = 3 +overflow-checks = true +panic = 'abort' +rpath = false diff --git a/Changelog.md b/Changelog.md index b2fc3c4..e18d757 100644 --- a/Changelog.md +++ b/Changelog.md @@ -16,10 +16,11 @@ All notable changes to this project will be documented in this file. - -## [1.0.2] - 2024-03-19 +## [1.1.0] - 2024-10-30 ### Fixed +- Added pagination to `get_all_routes` - Bump version of `serde-json-wasm` ## [1.0.1] - 2024-02-24 diff --git a/contracts/swap/.gitignore b/contracts/swap/.gitignore deleted file mode 100644 index dfdaaa6..0000000 --- a/contracts/swap/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Build results -/target - -# Cargo+Git helper file (https://github.com/rust-lang/cargo/blob/0.44.1/src/cargo/sources/git/utils.rs#L320-L327) -.cargo-ok - -# Text file backups -**/*.rs.bk - -# macOS -.DS_Store - -# IDEs -*.iml -.idea diff --git a/contracts/swap/.gitpod.Dockerfile b/contracts/swap/.gitpod.Dockerfile deleted file mode 100644 index bff8bc5..0000000 --- a/contracts/swap/.gitpod.Dockerfile +++ /dev/null @@ -1,17 +0,0 @@ -### wasmd ### -FROM cosmwasm/wasmd:v0.18.0 as wasmd - -### rust-optimizer ### -FROM cosmwasm/rust-optimizer:0.11.5 as rust-optimizer - -FROM gitpod/workspace-full:latest - -COPY --from=wasmd /usr/bin/wasmd /usr/local/bin/wasmd -COPY --from=wasmd /opt/* /opt/ - -RUN sudo apt-get update \ - && sudo apt-get install -y jq \ - && sudo rm -rf /var/lib/apt/lists/* - -RUN rustup update stable \ - && rustup target add wasm32-unknown-unknown diff --git a/contracts/swap/.gitpod.yml b/contracts/swap/.gitpod.yml deleted file mode 100644 index d03610c..0000000 --- a/contracts/swap/.gitpod.yml +++ /dev/null @@ -1,10 +0,0 @@ -image: cosmwasm/cw-gitpod-base:v0.16 - -vscode: - extensions: - - rust-lang.rust - -tasks: - - name: Dependencies & Build - init: | - cargo build diff --git a/contracts/swap/Cargo.toml b/contracts/swap/Cargo.toml index f9f0608..40fb8f2 100644 --- a/contracts/swap/Cargo.toml +++ b/contracts/swap/Cargo.toml @@ -2,7 +2,7 @@ authors = [ "Markus Waas " ] edition = "2021" name = "swap-contract" -version = "1.0.2" +version = "1.1.0" exclude = [ # Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. @@ -16,38 +16,25 @@ exclude = [ crate-type = [ "cdylib", "rlib" ] [features] -# for more explicit tests, cargo test --features=backtraces -backtraces = [ "cosmwasm-std/backtraces" ] -# use library feature to disable all instantiate/execute/query exports library = [ ] -[package.metadata.scripts] -optimize = """docker run --rm -v "$(pwd)":/code \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/workspace-optimizer-arm64:0.12.11 -""" - [dependencies] -cosmwasm-std = { version = "1.5.0", features = [ "abort", "cosmwasm_1_2", "cosmwasm_1_3", "cosmwasm_1_4", "iterator", "stargate" ] } -cosmwasm-storage = "1.5.0" -cw-storage-plus = "0.14.0" -cw-utils = "0.14.0" -cw2 = "0.14.0" -injective-cosmwasm = { version = "0.2.18" } -injective-math = { version = "0.2.4" } -injective-protobuf = { version = "0.2.2" } -num-traits = "0.2.15" -protobuf = { version = "2", features = [ "with-bytes" ] } -schemars = "0.8.8" -serde = { version = "1.0.137", default-features = false, features = [ "derive" ] } -serde-json-wasm = "1.0.1" -thiserror = { version = "1.0.31" } +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +cw-utils = { workspace = true } +cw2 = { workspace = true } +injective-cosmwasm = { workspace = true } +injective-math = { workspace = true } +injective-std = { workspace = true } +prost = { workspace = true } +schemars = { workspace = true } +serde = { workspace = true } +serde-json-wasm = { workspace = true } +thiserror = { workspace = true } [dev-dependencies] -cosmos-sdk-proto = { version = "0.19.0", default-features = false } -cosmwasm-schema = "1.5.0" -cw-multi-test = "0.16.2" -injective-std = { version = "0.1.5" } -injective-test-tube = "1.1.7" -prost = "0.11.9" +cosmwasm-schema = { workspace = true } +# cw-multi-test = { workspace = true } +injective-std = { workspace = true } +injective-test-tube = { workspace = true } diff --git a/contracts/swap/msg.rs b/contracts/swap/msg.rs deleted file mode 100644 index f0c841e..0000000 --- a/contracts/swap/msg.rs +++ /dev/null @@ -1,70 +0,0 @@ -use cosmwasm_std::{Addr, Coin}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - -use injective_cosmwasm::MarketId; -use injective_math::FPDecimal; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum FeeRecipient { - Address(Addr), - SwapContract, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -pub struct InstantiateMsg { - pub fee_recipient: FeeRecipient, - pub admin: Addr, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - SwapMinOutput { - target_denom: String, - min_output_quantity: FPDecimal, - }, - SwapExactOutput { - target_denom: String, - target_output_quantity: FPDecimal, - }, - SetRoute { - source_denom: String, - target_denom: String, - route: Vec, - }, - DeleteRoute { - source_denom: String, - target_denom: String, - }, - UpdateConfig { - admin: Option, - fee_recipient: Option, - }, - WithdrawSupportFunds { - coins: Vec, - target_address: Addr, - }, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - GetRoute { - source_denom: String, - target_denom: String, - }, - GetOutputQuantity { - from_quantity: FPDecimal, - source_denom: String, - target_denom: String, - }, - GetInputQuantity { - to_quantity: FPDecimal, - source_denom: String, - target_denom: String, - }, - GetAllRoutes {}, - GetConfig {}, -} diff --git a/contracts/swap/rustfmt.toml b/contracts/swap/rustfmt.toml deleted file mode 100644 index 11a85e6..0000000 --- a/contracts/swap/rustfmt.toml +++ /dev/null @@ -1,15 +0,0 @@ -# stable -newline_style = "unix" -hard_tabs = false -tab_spaces = 4 - -# unstable... should we require `rustup run nightly cargo fmt` ? -# or just update the style guide when they are stable? -#fn_single_line = true -#format_code_in_doc_comments = true -#overflow_delimited_expr = true -#reorder_impl_items = true -#struct_field_align_threshold = 20 -#struct_lit_single_line = true -#report_todo = "Always" - diff --git a/contracts/swap/src/contract.rs b/contracts/swap/src/contract.rs index 3702ecb..88d9f23 100644 --- a/contracts/swap/src/contract.rs +++ b/contracts/swap/src/contract.rs @@ -1,22 +1,17 @@ -#[cfg(not(feature = "library"))] -use cosmwasm_std::entry_point; -use cosmwasm_std::{ - to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, +use crate::{ + admin::{delete_route, save_config, set_route, update_config, withdraw_support_funds}, + error::ContractError, + msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, + queries::{estimate_swap_result, SwapQuantity}, + state::{get_all_swap_routes, get_config, read_swap_route}, + swap::{handle_atomic_order_reply, start_swap_flow}, + types::{ConfigResponse, SwapQuantityMode}, }; -use cw2::{get_contract_version, set_contract_version}; -use crate::admin::{delete_route, save_config, set_route, update_config, withdraw_support_funds}; -use crate::helpers::handle_config_migration; -use crate::types::{ConfigResponse, SwapQuantityMode}; +use cosmwasm_std::{entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError}; +use cw2::{get_contract_version, set_contract_version}; use injective_cosmwasm::{InjectiveMsgWrapper, InjectiveQueryWrapper}; -use crate::error::ContractError; - -use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; -use crate::queries::{estimate_swap_result, SwapQuantity}; -use crate::state::{get_all_swap_routes, get_config, read_swap_route}; -use crate::swap::{handle_atomic_order_reply, start_swap_flow}; - pub const CONTRACT_NAME: &str = env!("CARGO_PKG_NAME"); pub const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); @@ -33,9 +28,7 @@ pub fn instantiate( set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; save_config(deps, env, msg.admin, msg.fee_recipient)?; - Ok(Response::new() - .add_attribute("method", "instantiate") - .add_attribute("owner", info.sender)) + Ok(Response::new().add_attribute("method", "instantiate").add_attribute("owner", info.sender)) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -49,13 +42,7 @@ pub fn execute( ExecuteMsg::SwapMinOutput { target_denom, min_output_quantity, - } => start_swap_flow( - deps, - env, - info, - target_denom, - SwapQuantityMode::MinOutputQuantity(min_output_quantity), - ), + } => start_swap_flow(deps, env, info, target_denom, SwapQuantityMode::MinOutputQuantity(min_output_quantity)), ExecuteMsg::SwapExactOutput { target_denom, target_output_quantity, @@ -72,27 +59,14 @@ pub fn execute( target_denom, route, } => set_route(deps, &info.sender, source_denom, target_denom, route), - ExecuteMsg::DeleteRoute { - source_denom, - target_denom, - } => delete_route(deps, &info.sender, source_denom, target_denom), - ExecuteMsg::UpdateConfig { - admin, - fee_recipient, - } => update_config(deps, env, info.sender, admin, fee_recipient), - ExecuteMsg::WithdrawSupportFunds { - coins, - target_address, - } => withdraw_support_funds(deps, info.sender, coins, target_address), + ExecuteMsg::DeleteRoute { source_denom, target_denom } => delete_route(deps, &info.sender, source_denom, target_denom), + ExecuteMsg::UpdateConfig { admin, fee_recipient } => update_config(deps, env, info.sender, admin, fee_recipient), + ExecuteMsg::WithdrawSupportFunds { coins, target_address } => withdraw_support_funds(deps, info.sender, coins, target_address), } } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn reply( - deps: DepsMut, - env: Env, - msg: Reply, -) -> Result, ContractError> { +pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result, ContractError> { match msg.id { ATOMIC_ORDER_REPLY_ID => handle_atomic_order_reply(deps, env, msg), _ => Err(ContractError::UnrecognizedReply(msg.id)), @@ -100,95 +74,35 @@ pub fn reply( } #[cfg_attr(not(feature = "library"), entry_point)] -pub fn migrate( - deps: DepsMut, - _env: Env, - _msg: MigrateMsg, -) -> Result { - let contract_version = get_contract_version(deps.storage)?; - - match contract_version.contract.as_ref() { - // old contract name - "crates.io:atomic-order-example" => match contract_version.version.as_ref() { - "0.1.0" => { - unimplemented!( - "Migration from version {} is no longer supported", - contract_version.version - ); - } - "1.0.0" => { - set_contract_version( - deps.storage, - format!("crates.io:{CONTRACT_NAME}"), - CONTRACT_VERSION, - )?; - - handle_config_migration(deps)?; - } - _ => return Err(ContractError::MigrationError {}), - }, - "crates.io:swap-contract" => match contract_version.version.as_ref() { - "1.0.1" => { - unimplemented!( - "Migration from version {} is no yet supported", - contract_version.version - ); - } - _ => return Err(ContractError::MigrationError {}), - }, - _ => return Err(ContractError::MigrationError {}), - } - - Ok(Response::new() - .add_attribute("previous_contract_name", &contract_version.contract) - .add_attribute("previous_contract_version", &contract_version.version) - .add_attribute("new_contract_name", format!("crates.io:{CONTRACT_NAME}")) - .add_attribute("new_contract_version", CONTRACT_VERSION)) -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result { match msg { - QueryMsg::GetRoute { - source_denom, - target_denom, - } => Ok(to_json_binary(&read_swap_route( - deps.storage, - &source_denom, - &target_denom, - )?)?), + QueryMsg::GetRoute { source_denom, target_denom } => to_json_binary(&read_swap_route(deps.storage, &source_denom, &target_denom)?), QueryMsg::GetOutputQuantity { from_quantity, source_denom, target_denom, - } => { - let target_quantity = estimate_swap_result( - deps, - &env, - source_denom, - target_denom, - SwapQuantity::InputQuantity(from_quantity), - )?; - Ok(to_json_binary(&target_quantity)?) - } + } => to_json_binary(&estimate_swap_result( + deps, + &env, + source_denom, + target_denom, + SwapQuantity::InputQuantity(from_quantity), + )?), + QueryMsg::GetInputQuantity { to_quantity, source_denom, target_denom, - } => { - let target_quantity = estimate_swap_result( - deps, - &env, - source_denom, - target_denom, - SwapQuantity::OutputQuantity(to_quantity), - )?; - Ok(to_json_binary(&target_quantity)?) - } - QueryMsg::GetAllRoutes {} => { - let routes = get_all_swap_routes(deps.storage)?; - Ok(to_json_binary(&routes)?) - } + } => to_json_binary(&estimate_swap_result( + deps, + &env, + source_denom, + target_denom, + SwapQuantity::OutputQuantity(to_quantity), + )?), + + QueryMsg::GetAllRoutes { start_after, limit } => to_json_binary(&get_all_swap_routes(deps.storage, start_after, limit)?), + QueryMsg::GetConfig {} => { let config = get_config(deps.storage)?; let config_response = ConfigResponse { @@ -199,3 +113,24 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdR } } } + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result { + let contract_version = get_contract_version(deps.storage)?; + + match contract_version.contract.as_ref() { + "crates.io:swap-contract" => match contract_version.version.as_ref() { + "1.0.1" => { + set_contract_version(deps.storage, format!("crates.io:{CONTRACT_NAME}"), CONTRACT_VERSION)?; + } + _ => return Err(ContractError::MigrationError {}), + }, + _ => return Err(ContractError::MigrationError {}), + } + + Ok(Response::new() + .add_attribute("previous_contract_name", &contract_version.contract) + .add_attribute("previous_contract_version", &contract_version.version) + .add_attribute("new_contract_name", format!("crates.io:{CONTRACT_NAME}")) + .add_attribute("new_contract_version", CONTRACT_VERSION)) +} diff --git a/contracts/swap/src/msg.rs b/contracts/swap/src/msg.rs index 37590b7..281c2f3 100644 --- a/contracts/swap/src/msg.rs +++ b/contracts/swap/src/msg.rs @@ -1,28 +1,24 @@ +use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, Coin}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - use injective_cosmwasm::MarketId; use injective_math::FPDecimal; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub enum FeeRecipient { Address(Addr), SwapContract, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct InstantiateMsg { pub fee_recipient: FeeRecipient, pub admin: Addr, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct MigrateMsg {} -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub enum ExecuteMsg { SwapMinOutput { target_denom: String, @@ -51,8 +47,7 @@ pub enum ExecuteMsg { }, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] -#[serde(rename_all = "snake_case")] +#[cw_serde] pub enum QueryMsg { GetRoute { source_denom: String, @@ -68,6 +63,9 @@ pub enum QueryMsg { source_denom: String, target_denom: String, }, - GetAllRoutes {}, + GetAllRoutes { + start_after: Option<(String, String)>, + limit: Option, + }, GetConfig {}, } diff --git a/contracts/swap/src/state.rs b/contracts/swap/src/state.rs index bcc85a2..bebcb95 100644 --- a/contracts/swap/src/state.rs +++ b/contracts/swap/src/state.rs @@ -1,14 +1,16 @@ -use cosmwasm_std::{Order, StdError, StdResult, Storage}; -use cw_storage_plus::{Item, Map}; - use crate::types::{Config, CurrentSwapOperation, CurrentSwapStep, SwapResults, SwapRoute}; +use cosmwasm_std::{Order, StdError, StdResult, Storage}; +use cw_storage_plus::{Bound, Item, Map}; + pub const SWAP_ROUTES: Map<(String, String), SwapRoute> = Map::new("swap_routes"); pub const SWAP_OPERATION_STATE: Item = Item::new("current_swap_cache"); pub const STEP_STATE: Item = Item::new("current_step_cache"); pub const SWAP_RESULTS: Item> = Item::new("swap_results"); pub const CONFIG: Item = Item::new("config"); +pub const DEFAULT_LIMIT: u32 = 100u32; + impl Config { pub fn validate(self) -> StdResult<()> { Ok(()) @@ -38,11 +40,22 @@ pub fn get_config(storage: &dyn Storage) -> StdResult { Ok(config) } -pub fn get_all_swap_routes(storage: &dyn Storage) -> StdResult> { +pub fn get_all_swap_routes( + storage: &dyn Storage, + start_after: Option<(String, String)>, + limit: Option, +) -> StdResult> { + let limit = limit.unwrap_or(DEFAULT_LIMIT) as usize; + + let start_bound = start_after + .as_ref() + .map(|(s, t)| Bound::inclusive((s.clone(), t.clone()))); + let routes = SWAP_ROUTES - .range(storage, None, None, Order::Ascending) - .map(|item| item.unwrap().1) - .collect(); + .range(storage, start_bound, None, Order::Ascending) + .take(limit) + .map(|item| item.map(|(_, route)| route)) // Extract the `SwapRoute` from each item + .collect::>>()?; Ok(routes) } diff --git a/contracts/swap/src/swap.rs b/contracts/swap/src/swap.rs index 7c3f2b3..0cb3256 100644 --- a/contracts/swap/src/swap.rs +++ b/contracts/swap/src/swap.rs @@ -1,28 +1,21 @@ -use std::str::FromStr; - -use cosmwasm_std::{ - BankMsg, Coin, DepsMut, Env, Event, MessageInfo, Reply, Response, StdResult, SubMsg, Uint128, +use crate::{ + contract::ATOMIC_ORDER_REPLY_ID, + error::ContractError, + helpers::{dec_scale_factor, round_up_to_min_tick}, + queries::{estimate_single_swap_execution, estimate_swap_result, SwapQuantity}, + state::{read_swap_route, CONFIG, STEP_STATE, SWAP_OPERATION_STATE, SWAP_RESULTS}, + types::{CurrentSwapOperation, CurrentSwapStep, FPCoin, SwapEstimationAmount, SwapQuantityMode, SwapResults}, }; -use protobuf::Message; - -use crate::contract::ATOMIC_ORDER_REPLY_ID; +use cosmwasm_std::{BankMsg, Coin, DepsMut, Env, Event, MessageInfo, Reply, Response, StdResult, SubMsg, Uint128}; use injective_cosmwasm::{ - create_spot_market_order_msg, get_default_subaccount_id_for_checked_address, - InjectiveMsgWrapper, InjectiveQuerier, InjectiveQueryWrapper, OrderType, SpotOrder, + create_spot_market_order_msg, get_default_subaccount_id_for_checked_address, InjectiveMsgWrapper, InjectiveQuerier, InjectiveQueryWrapper, + OrderType, SpotOrder, }; use injective_math::{round_to_min_tick, FPDecimal}; -use injective_protobuf::proto::tx; - -use crate::error::ContractError; -use crate::helpers::{dec_scale_factor, round_up_to_min_tick}; - -use crate::queries::{estimate_single_swap_execution, estimate_swap_result, SwapQuantity}; -use crate::state::{read_swap_route, CONFIG, STEP_STATE, SWAP_OPERATION_STATE, SWAP_RESULTS}; -use crate::types::{ - CurrentSwapOperation, CurrentSwapStep, FPCoin, SwapEstimationAmount, SwapQuantityMode, - SwapResults, -}; +use injective_std::types::injective::exchange::v1beta1::MsgCreateSpotMarketOrderResponse; +use prost::Message; +use std::str::FromStr; pub fn start_swap_flow( deps: DepsMut, @@ -56,10 +49,7 @@ pub fn start_swap_flow( let mut current_balance = coin_provided.to_owned().into(); - let refund_amount = if matches!( - swap_quantity_mode, - SwapQuantityMode::ExactOutputQuantity(..) - ) { + let refund_amount = if matches!(swap_quantity_mode, SwapQuantityMode::ExactOutputQuantity(..)) { let target_output_quantity = quantity; let estimation = estimate_swap_result( @@ -72,29 +62,20 @@ pub fn start_swap_flow( let querier = InjectiveQuerier::new(&deps.querier); let first_market_id = steps[0].to_owned(); - let first_market = querier - .query_spot_market(&first_market_id)? - .market - .expect("market should be available"); + let first_market = querier.query_spot_market(&first_market_id)?.market.expect("market should be available"); let is_input_quote = first_market.quote_denom == *source_denom; let required_input = if is_input_quote { estimation.result_quantity.int() + FPDecimal::ONE } else { - round_up_to_min_tick( - estimation.result_quantity, - first_market.min_quantity_tick_size, - ) + round_up_to_min_tick(estimation.result_quantity, first_market.min_quantity_tick_size) }; let fp_coins: FPDecimal = coin_provided.amount.into(); if required_input > fp_coins { - return Err(ContractError::InsufficientFundsProvided( - fp_coins, - required_input, - )); + return Err(ContractError::InsufficientFundsProvided(fp_coins, required_input)); } current_balance = FPCoin { @@ -111,7 +92,7 @@ pub fn start_swap_flow( sender_address, swap_steps: steps, swap_quantity_mode, - refund: Coin::new(refund_amount.into(), source_denom.to_owned()), + refund: Coin::new(refund_amount, source_denom.to_owned()), input_funds: coin_provided.to_owned(), }; @@ -160,10 +141,7 @@ pub fn execute_swap_step( None, ); - let order_message = SubMsg::reply_on_success( - create_spot_market_order_msg(contract.to_owned(), order), - ATOMIC_ORDER_REPLY_ID, - ); + let order_message = SubMsg::reply_on_success(create_spot_market_order_msg(contract.to_owned(), order), ATOMIC_ORDER_REPLY_ID); let current_step = CurrentSwapStep { step_idx, @@ -177,30 +155,12 @@ pub fn execute_swap_step( Ok(response) } -pub fn handle_atomic_order_reply( - deps: DepsMut, - env: Env, - msg: Reply, -) -> Result, ContractError> { +pub fn handle_atomic_order_reply(deps: DepsMut, env: Env, msg: Reply) -> Result, ContractError> { let dec_scale_factor = dec_scale_factor(); // protobuf serializes Dec values with extra 10^18 factor - let id = msg.id; - let order_response: tx::MsgCreateSpotMarketOrderResponse = Message::parse_from_bytes( - msg.result - .into_result() - .map_err(ContractError::SubMsgFailure)? - .data - .ok_or_else(|| ContractError::ReplyParseFailure { - id, - err: "Missing reply data".to_owned(), - })? - .as_slice(), - ) - .map_err(|err| ContractError::ReplyParseFailure { - id, - err: err.to_string(), - })?; - - let trade_data = match order_response.results.into_option() { + + let order_response = MsgCreateSpotMarketOrderResponse::decode(msg.payload.as_slice()).unwrap(); + + let trade_data = match order_response.results { Some(trade_data) => Ok(trade_data), None => Err(ContractError::CustomError { val: "No trade data in order response".to_string(), @@ -216,11 +176,7 @@ pub fn handle_atomic_order_reply( let current_step = STEP_STATE.load(deps.storage).map_err(ContractError::Std)?; - let new_quantity = if current_step.is_buy { - quantity - } else { - quantity * average_price - fee - }; + let new_quantity = if current_step.is_buy { quantity } else { quantity * average_price - fee }; let swap = SWAP_OPERATION_STATE.load(deps.storage)?; @@ -229,10 +185,7 @@ pub fn handle_atomic_order_reply( let new_rounded_quantity = if has_next_market { let querier = InjectiveQuerier::new(&deps.querier); let next_market_id = swap.swap_steps[(current_step.step_idx + 1) as usize].to_owned(); - let next_market = querier - .query_spot_market(&next_market_id)? - .market - .expect("market should be available"); + let next_market = querier.query_spot_market(&next_market_id)?.market.expect("market should be available"); let is_next_swap_sell = next_market.base_denom == current_step.step_target_denom; @@ -259,8 +212,7 @@ pub fn handle_atomic_order_reply( if current_step.step_idx < (swap.swap_steps.len() - 1) as u16 { SWAP_RESULTS.save(deps.storage, &swap_results)?; - return execute_swap_step(deps, env, swap, current_step.step_idx + 1, new_balance) - .map_err(ContractError::Std); + return execute_swap_step(deps, env, swap, current_step.step_idx + 1, new_balance).map_err(ContractError::Std); } let min_output_quantity = match swap.swap_quantity_mode { @@ -269,9 +221,7 @@ pub fn handle_atomic_order_reply( }; if new_balance.amount < min_output_quantity { - return Err(ContractError::MinOutputAmountNotReached( - min_output_quantity, - )); + return Err(ContractError::MinOutputAmountNotReached(min_output_quantity)); } // last step, finalize and send back funds to a caller @@ -294,9 +244,7 @@ pub fn handle_atomic_order_reply( STEP_STATE.remove(deps.storage); SWAP_RESULTS.remove(deps.storage); - let mut response = Response::new() - .add_message(send_message) - .add_event(swap_event); + let mut response = Response::new().add_message(send_message).add_event(swap_event); if swap.refund.amount > Uint128::zero() { let refund_message = BankMsg::Send { diff --git a/contracts/swap/src/testing/integration_logic_tests.rs b/contracts/swap/src/testing/integration_logic_tests.rs deleted file mode 100644 index d4f00a1..0000000 --- a/contracts/swap/src/testing/integration_logic_tests.rs +++ /dev/null @@ -1,2142 +0,0 @@ -use cosmwasm_std::{coin, Addr}; - -use injective_test_tube::RunnerError::{ExecuteError, QueryError}; -use injective_test_tube::{ - Account, Bank, Exchange, InjectiveTestApp, Module, RunnerError, RunnerResult, SigningAccount, - Wasm, -}; - -use injective_math::{round_to_min_tick, FPDecimal}; - -use crate::msg::{ExecuteMsg, QueryMsg}; -use crate::testing::test_utils::{ - are_fpdecimals_approximately_equal, assert_fee_is_as_expected, create_limit_order, - fund_account_with_some_inj, human_to_dec, init_contract_with_fee_recipient_and_get_address, - init_default_signer_account, init_default_validator_account, init_rich_account, - init_self_relaying_contract_and_get_address, launch_spot_market, must_init_account_with_funds, - pause_spot_market, query_all_bank_balances, query_bank_balance, set_route_and_assert_success, - str_coin, Decimals, OrderSide, ATOM, DEFAULT_ATOMIC_MULTIPLIER, DEFAULT_RELAYER_SHARE, - DEFAULT_SELF_RELAYING_FEE_PART, DEFAULT_TAKER_FEE, ETH, INJ, USDC, USDT, -}; -use crate::types::{FPCoin, SwapEstimationResult}; - -/* - This suite of tests focuses on calculation logic itself and doesn't attempt to use neither - realistic market configuration nor order prices, so that we don't have to deal with scaling issues. - - Hardcoded values used in these tests come from the first tab of this spreadsheet: - https://docs.google.com/spreadsheets/d/1-0epjX580nDO_P2mm1tSjhvjJVppsvrO1BC4_wsBeyA/edit?usp=sharing -*/ - -#[test] -fn it_executes_a_swap_between_two_base_assets_with_multiple_price_levels() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - create_atom_sell_orders(&app, &spot_market_2_id, &trader1, &trader2, &trader3); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ) - .unwrap(); - - assert_eq!( - query_result.result_quantity, - FPDecimal::must_from_str("2893.886"), //slightly rounded down - "incorrect swap result estimate returned by query" - ); - - assert_eq!( - query_result.expected_fees.len(), - 2, - "Wrong number of fee denoms received" - ); - - let mut expected_fees = vec![ - FPCoin { - amount: FPDecimal::must_from_str("3541.5"), - denom: "usdt".to_string(), - }, - FPCoin { - amount: FPDecimal::must_from_str("3530.891412"), - denom: "usdt".to_string(), - }, - ]; - - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - FPDecimal::must_from_str("0.000001"), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2800u128), - }, - &[coin(12, ETH)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - assert_eq!( - to_balance, - FPDecimal::must_from_str("2893"), - "swapper did not receive expected amount" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_balance_usdt_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - let contract_balance_usdt_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - - assert!( - contract_balance_usdt_after >= contract_balance_usdt_before, - "Contract lost some money after swap. Balance before: {contract_balance_usdt_before}, after: {contract_balance_usdt_after}", - ); - - let max_diff = human_to_dec("0.00001", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_balance_usdt_after, - contract_balance_usdt_before, - max_diff, - ), - "Contract balance changed too much. Before: {}, After: {}", - contract_balances_before[0].amount, - contract_balances_after[0].amount - ); -} - -#[test] -fn it_executes_a_swap_between_two_base_assets_with_single_price_level() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - create_atom_sell_orders(&app, &spot_market_2_id, &trader1, &trader2, &trader3); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(3, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let expected_atom_estimate_quantity = FPDecimal::must_from_str("751.492"); - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(3u128), - }, - ) - .unwrap(); - - assert_eq!( - query_result.result_quantity, expected_atom_estimate_quantity, - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![ - FPCoin { - amount: FPDecimal::must_from_str("904.5"), - denom: "usdt".to_string(), - }, - FPCoin { - amount: FPDecimal::must_from_str("901.790564"), - denom: "usdt".to_string(), - }, - ]; - - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - human_to_dec("0.00001", Decimals::Six), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(750u128), - }, - &[coin(3, ETH)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - assert_eq!( - to_balance, - expected_atom_estimate_quantity.int(), - "swapper did not receive expected amount" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_executes_swap_between_markets_using_different_quote_assets() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDC); - let spot_market_3_id = launch_spot_market(&exchange, &owner, USDC, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[ - str_coin("100_000", USDC, Decimals::Six), - str_coin("100_000", USDT, Decimals::Six), - ], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_3_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - create_atom_sell_orders(&app, &spot_market_2_id, &trader1, &trader2, &trader3); - - //USDT-USDC - create_limit_order( - &app, - &trader3, - &spot_market_3_id, - OrderSide::Sell, - 1, - 100_000_000, - ); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ) - .unwrap(); - - // expected amount is a bit lower, even though 1 USDT = 1 USDC, because of the fees - assert_eq!( - query_result.result_quantity, - FPDecimal::must_from_str("2889.64"), - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![ - FPCoin { - amount: FPDecimal::must_from_str("3541.5"), - denom: "usdt".to_string(), - }, - FPCoin { - amount: FPDecimal::must_from_str("3530.891412"), - denom: "usdt".to_string(), - }, - FPCoin { - amount: FPDecimal::must_from_str("3525.603007"), - denom: "usdc".to_string(), - }, - ]; - - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - human_to_dec("0.000001", Decimals::Six), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 2, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2800u128), - }, - &[coin(12, ETH)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - assert_eq!( - to_balance, - FPDecimal::must_from_str("2889"), - "swapper did not receive expected amount" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 2, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_reverts_swap_between_markets_using_different_quote_asset_if_one_quote_buffer_is_insufficient() -{ - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDC); - let spot_market_3_id = launch_spot_market(&exchange, &owner, USDC, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[ - str_coin("0.0001", USDC, Decimals::Six), - str_coin("100_000", USDT, Decimals::Six), - ], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_3_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - create_atom_sell_orders(&app, &spot_market_2_id, &trader1, &trader2, &trader3); - - //USDT-USDC - create_limit_order( - &app, - &trader3, - &spot_market_3_id, - OrderSide::Sell, - 1, - 100_000_000, - ); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let query_result: RunnerResult = wasm.query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ); - - assert!(query_result.is_err(), "swap should have failed"); - assert!( - query_result - .unwrap_err() - .to_string() - .contains("Swap amount too high"), - "incorrect query result error message" - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 2, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2800u128), - }, - &[coin(12, ETH)], - &swapper, - ); - - assert!(execute_result.is_err(), "swap should have failed"); - assert!( - execute_result - .unwrap_err() - .to_string() - .contains("Swap amount too high"), - "incorrect query result error message" - ); - - let source_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let target_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - source_balance, - FPDecimal::must_from_str("12"), - "source balance should not have changed after failed swap" - ); - assert_eq!( - target_balance, - FPDecimal::ZERO, - "target balance should not have changed after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 2, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_executes_a_sell_of_base_asset_to_receive_min_output_quantity() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - USDT, - vec![spot_market_1_id.as_str().into()], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: USDT.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ) - .unwrap(); - - // calculate how much can be USDT can be bought for 12 ETH without fees - let orders_nominal_total_value = FPDecimal::from(201_000u128) * FPDecimal::from(5u128) - + FPDecimal::from(195_000u128) * FPDecimal::from(4u128) - + FPDecimal::from(192_000u128) * FPDecimal::from(3u128); - let expected_target_quantity = orders_nominal_total_value - * (FPDecimal::ONE - - FPDecimal::must_from_str(&format!( - "{}", - DEFAULT_TAKER_FEE * DEFAULT_ATOMIC_MULTIPLIER * DEFAULT_SELF_RELAYING_FEE_PART - ))); - - assert_eq!( - query_result.result_quantity, expected_target_quantity, - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![FPCoin { - amount: FPDecimal::must_from_str("3541.5"), - denom: "usdt".to_string(), - }]; - - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - FPDecimal::must_from_str("0.000001"), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: USDT.to_string(), - min_output_quantity: FPDecimal::from(2357458u128), - }, - &[coin(12, ETH)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, USDT, swapper.address().as_str()); - let expected_execute_result = expected_target_quantity.int(); - - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - assert_eq!( - to_balance, expected_execute_result, - "swapper did not receive expected amount" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_executes_a_buy_of_base_asset_to_receive_min_output_quantity() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - USDT, - vec![spot_market_1_id.as_str().into()], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - - create_limit_order( - &app, - &trader1, - &spot_market_1_id, - OrderSide::Sell, - 201_000, - 5, - ); - create_limit_order( - &app, - &trader2, - &spot_market_1_id, - OrderSide::Sell, - 195_000, - 4, - ); - create_limit_order( - &app, - &trader2, - &spot_market_1_id, - OrderSide::Sell, - 192_000, - 3, - ); - - app.increase_time(1); - - let swapper_usdt = 2_360_995; - let swapper = must_init_account_with_funds( - &app, - &[ - coin(swapper_usdt, USDT), - str_coin("500_000", INJ, Decimals::Eighteen), - ], - ); - - // calculate how much ETH we can buy with USDT we have - let available_usdt_after_fee = FPDecimal::from(swapper_usdt) - / (FPDecimal::ONE - + FPDecimal::must_from_str(&format!( - "{}", - DEFAULT_TAKER_FEE * DEFAULT_ATOMIC_MULTIPLIER * DEFAULT_SELF_RELAYING_FEE_PART - ))); - let usdt_left_for_most_expensive_order = available_usdt_after_fee - - (FPDecimal::from(195_000u128) * FPDecimal::from(4u128) - + FPDecimal::from(192_000u128) * FPDecimal::from(3u128)); - let most_expensive_order_quantity = - usdt_left_for_most_expensive_order / FPDecimal::from(201_000u128); - let expected_quantity = - most_expensive_order_quantity + (FPDecimal::from(4u128) + FPDecimal::from(3u128)); - - // round to min tick - let expected_quantity_rounded = - round_to_min_tick(expected_quantity, FPDecimal::must_from_str("0.001")); - - // calculate dust notional value as this will be the portion of user's funds that will stay in the contract - let dust = expected_quantity - expected_quantity_rounded; - // we need to use worst priced order - let dust_value = dust * FPDecimal::from(201_000u128); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: USDT.to_string(), - target_denom: ETH.to_string(), - from_quantity: FPDecimal::from(swapper_usdt), - }, - ) - .unwrap(); - - assert_eq!( - query_result.result_quantity, expected_quantity_rounded, - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![FPCoin { - amount: FPDecimal::must_from_str("3536.188217"), - denom: "usdt".to_string(), - }]; - - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - FPDecimal::must_from_str("0.000001"), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ETH.to_string(), - min_output_quantity: FPDecimal::from(11u128), - }, - &[coin(swapper_usdt, USDT)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, USDT, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let expected_execute_result = expected_quantity.int(); - - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - assert_eq!( - to_balance, expected_execute_result, - "swapper did not receive expected amount" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - let mut expected_contract_balances_after = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()) + dust_value; - expected_contract_balances_after = expected_contract_balances_after.int(); - - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()), - expected_contract_balances_after, - "contract balance changed unexpectedly after swap" - ); -} - -#[test] -fn it_executes_a_swap_between_base_assets_with_external_fee_recipient() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let fee_recipient = must_init_account_with_funds(&app, &[]); - let contr_addr = init_contract_with_fee_recipient_and_get_address( - &wasm, - &owner, - &[str_coin("10_000", USDT, Decimals::Six)], - &fee_recipient, - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - create_atom_sell_orders(&app, &spot_market_2_id, &trader1, &trader2, &trader3); - - // calculate relayer's share of the fee based on assumptions that all orders are matched - let buy_orders_nominal_total_value = FPDecimal::from(201_000u128) * FPDecimal::from(5u128) - + FPDecimal::from(195_000u128) * FPDecimal::from(4u128) - + FPDecimal::from(192_000u128) * FPDecimal::from(3u128); - let relayer_sell_fee = buy_orders_nominal_total_value - * FPDecimal::must_from_str(&format!( - "{}", - DEFAULT_TAKER_FEE * DEFAULT_ATOMIC_MULTIPLIER * DEFAULT_RELAYER_SHARE - )); - - // calculate relayer's share of the fee based on assumptions that some of orders are matched - let expected_nominal_buy_most_expensive_match_quantity = - FPDecimal::must_from_str("488.2222155454736648"); - let sell_orders_nominal_total_value = FPDecimal::from(800u128) * FPDecimal::from(800u128) - + FPDecimal::from(810u128) * FPDecimal::from(800u128) - + FPDecimal::from(820u128) * FPDecimal::from(800u128) - + FPDecimal::from(830u128) * expected_nominal_buy_most_expensive_match_quantity; - let relayer_buy_fee = sell_orders_nominal_total_value - * FPDecimal::must_from_str(&format!( - "{}", - DEFAULT_TAKER_FEE * DEFAULT_ATOMIC_MULTIPLIER * DEFAULT_RELAYER_SHARE - )); - let expected_fee_for_fee_recipient = relayer_buy_fee + relayer_sell_fee; - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ) - .unwrap(); - - assert_eq!( - query_result.result_quantity, - FPDecimal::must_from_str("2888.221"), //slightly rounded down vs spreadsheet - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![ - FPCoin { - amount: FPDecimal::must_from_str("5902.5"), - denom: "usdt".to_string(), - }, - FPCoin { - amount: FPDecimal::must_from_str("5873.061097"), - denom: "usdt".to_string(), - }, - ]; - - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - FPDecimal::must_from_str("0.000001"), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2888u128), - }, - &[coin(12, ETH)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - assert_eq!( - to_balance, - FPDecimal::must_from_str("2888"), - "swapper did not receive expected amount" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_balance_usdt_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - let contract_balance_usdt_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - - assert!( - contract_balance_usdt_after >= contract_balance_usdt_before, - "Contract lost some money after swap. Balance before: {contract_balance_usdt_before}, after: {contract_balance_usdt_after}", - ); - - let max_diff = human_to_dec("0.00001", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_balance_usdt_after, - contract_balance_usdt_before, - max_diff, - ), - "Contract balance changed too much. Before: {}, After: {}", - contract_balances_before[0].amount, - contract_balances_after[0].amount - ); - - let fee_recipient_balance = query_all_bank_balances(&bank, &fee_recipient.address()); - - assert_eq!( - fee_recipient_balance.len(), - 1, - "wrong number of denoms in fee recipient's balances" - ); - assert_eq!( - fee_recipient_balance[0].denom, USDT, - "fee recipient did not receive fee in expected denom" - ); - assert_eq!( - FPDecimal::must_from_str(fee_recipient_balance[0].amount.as_str()), - expected_fee_for_fee_recipient.int(), - "fee recipient did not receive expected fee" - ); -} - -#[test] -fn it_reverts_the_swap_if_there_isnt_enough_buffer_for_buying_target_asset() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("0.001", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - create_atom_sell_orders(&app, &spot_market_2_id, &trader1, &trader2, &trader3); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let query_result: RunnerResult = wasm.query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ); - - assert!(query_result.is_err(), "query should fail"); - assert!( - query_result - .unwrap_err() - .to_string() - .contains("Swap amount too high"), - "wrong query error message" - ); - - let contract_balances_before = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2800u128), - }, - &[coin(12, ETH)], - &swapper, - ); - - assert!(execute_result.is_err(), "execute should fail"); - assert!( - execute_result - .unwrap_err() - .to_string() - .contains("Swap amount too high"), - "wrong execute error message" - ); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::from(12u128), - "source balance changes after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::ZERO, - "target balance changes after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_reverts_swap_if_no_funds_were_passed() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let contract_balances_before = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2800u128), - }, - &[], - &swapper, - ); - let expected_error = RunnerError::ExecuteError { msg: "failed to execute message; message index: 0: Custom Error: \"Only one denom can be passed in funds\": execute wasm contract failed".to_string() }; - assert_eq!( - execute_result.unwrap_err(), - expected_error, - "wrong error message" - ); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - from_balance, - FPDecimal::from(12u128), - "source balance changes after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::ZERO, - "target balance changes after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_reverts_swap_if_multiple_funds_were_passed() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let eth_balance = 12u128; - let atom_balance = 10u128; - - let swapper = must_init_account_with_funds( - &app, - &[ - coin(eth_balance, ETH), - coin(atom_balance, ATOM), - str_coin("500_000", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(10u128), - }, - &[coin(10, ATOM), coin(12, ETH)], - &swapper, - ); - assert!( - execute_result - .unwrap_err() - .to_string() - .contains("Only one denom can be passed in funds"), - "wrong error message" - ); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::from(eth_balance), - "wrong ETH balance after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::from(atom_balance), - "wrong ATOM balance after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_reverts_if_user_passes_quantities_equal_to_zero() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let query_result: RunnerResult = wasm.query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(0u128), - }, - ); - assert!( - query_result - .unwrap_err() - .to_string() - .contains("source_quantity must be positive"), - "incorrect error returned by query" - ); - - let contract_balances_before = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let err = wasm - .execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::ZERO, - }, - &[coin(12, ETH)], - &swapper, - ) - .unwrap_err(); - assert!( - err.to_string() - .contains("Output quantity must be positive!"), - "incorrect error returned by execute" - ); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::must_from_str("12"), - "swap should not have occurred" - ); - assert_eq!( - to_balance, - FPDecimal::must_from_str("0"), - "swapper should not have received any target tokens" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_reverts_if_user_passes_negative_quantities() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - app.increase_time(1); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::must_from_str("-1"), - }, - &[coin(12, ETH)], - &swapper, - ); - - assert!( - execute_result.is_err(), - "swap with negative minimum amount to receive did not fail" - ); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::from(12u128), - "source balance changed after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::ZERO, - "target balance changed after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after failed swap" - ); -} - -#[test] -fn it_reverts_if_there_arent_enough_orders_to_satisfy_min_quantity() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - - create_limit_order(&app, &trader1, &spot_market_2_id, OrderSide::Sell, 800, 800); - create_limit_order(&app, &trader2, &spot_market_2_id, OrderSide::Sell, 810, 800); - create_limit_order(&app, &trader3, &spot_market_2_id, OrderSide::Sell, 820, 800); - create_limit_order(&app, &trader1, &spot_market_2_id, OrderSide::Sell, 830, 450); //not enough for minimum requested - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let query_result: RunnerResult = wasm.query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ); - assert_eq!( - query_result.unwrap_err(), - QueryError { - msg: "Generic error: Not enough liquidity to fulfill order: query wasm contract failed" - .to_string() - }, - "wrong error message" - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2800u128), - }, - &[coin(12, ETH)], - &swapper, - ); - - assert_eq!(execute_result.unwrap_err(), RunnerError::ExecuteError { msg: "failed to execute message; message index: 0: dispatch: submessages: reply: Generic error: Not enough liquidity to fulfill order: execute wasm contract failed".to_string() }, "wrong error message"); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::from(12u128), - "source balance changed after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::ZERO, - "target balance changed after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after swap" - ); -} - -#[test] -fn it_reverts_if_min_quantity_cannot_be_reached() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - // set the market - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - create_atom_sell_orders(&app, &spot_market_2_id, &trader1, &trader2, &trader3); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let min_quantity = 3500u128; - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(min_quantity), - }, - &[coin(12, ETH)], - &swapper, - ); - - assert_eq!(execute_result.unwrap_err(), RunnerError::ExecuteError { msg: format!("failed to execute message; message index: 0: dispatch: submessages: reply: dispatch: submessages: reply: Min expected swap amount ({min_quantity}) not reached: execute wasm contract failed") }, "wrong error message"); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::from(12u128), - "source balance changed after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::ZERO, - "target balance changed after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after failed swap" - ); -} - -#[test] -fn it_reverts_if_market_is_paused() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let signer = init_default_signer_account(&app); - let validator = init_default_validator_account(&app); - fund_account_with_some_inj(&bank, &signer, &validator); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - pause_spot_market(&app, spot_market_1_id.as_str(), &signer, &validator); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let swapper = must_init_account_with_funds( - &app, - &[coin(12, ETH), str_coin("500_000", INJ, Decimals::Eighteen)], - ); - - let query_error: RunnerError = wasm - .query::( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ) - .unwrap_err(); - - assert!( - query_error.to_string().contains("Querier contract error"), - "wrong error returned by query" - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2800u128), - }, - &[coin(12, ETH)], - &swapper, - ); - - assert!( - execute_result - .unwrap_err() - .to_string() - .contains("Querier contract error"), - "wrong error returned by execute" - ); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::from(12u128), - "source balance changed after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::ZERO, - "target balance changed after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after failed swap" - ); -} - -#[test] -fn it_reverts_if_user_doesnt_have_enough_inj_to_pay_for_gas() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = init_default_signer_account(&app); - let _validator = init_default_validator_account(&app); - let owner = init_rich_account(&app); - - let spot_market_1_id = launch_spot_market(&exchange, &owner, ETH, USDT); - let spot_market_2_id = launch_spot_market(&exchange, &owner, ATOM, USDT); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("100_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let swapper = must_init_account_with_funds(&app, &[coin(12, ETH), coin(10, INJ)]); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_eth_buy_orders(&app, &spot_market_1_id, &trader1, &trader2); - create_atom_sell_orders(&app, &spot_market_2_id, &trader1, &trader2, &trader3); - - app.increase_time(1); - - let query_result: RunnerResult = wasm.query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: FPDecimal::from(12u128), - }, - ); - - let target_quantity = query_result.unwrap().result_quantity; - - assert_eq!( - target_quantity, - FPDecimal::must_from_str("2893.886"), //slightly underestimated vs spreadsheet - "incorrect swap result estimate returned by query" - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(2800u128), - }, - &[coin(12, ETH)], - &swapper, - ); - - assert_eq!(execute_result.unwrap_err(), ExecuteError { msg: "spendable balance 10inj is smaller than 2500inj: insufficient funds: insufficient funds".to_string() }, "wrong error returned by execute"); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::from(12u128), - "source balance changed after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::ZERO, - "target balance changed after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balance has changed after failed swap" - ); -} - -#[test] -fn it_allows_admin_to_withdraw_all_funds_from_contract_to_his_address() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let bank = Bank::new(&app); - - let usdt_to_withdraw = str_coin("10_000", USDT, Decimals::Six); - let eth_to_withdraw = str_coin("0.00062", ETH, Decimals::Eighteen); - - let owner = must_init_account_with_funds( - &app, - &[ - eth_to_withdraw.clone(), - str_coin("1", INJ, Decimals::Eighteen), - usdt_to_withdraw.clone(), - ], - ); - - let initial_contract_balance = &[eth_to_withdraw, usdt_to_withdraw]; - let contr_addr = - init_self_relaying_contract_and_get_address(&wasm, &owner, initial_contract_balance); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 2, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::WithdrawSupportFunds { - coins: initial_contract_balance.to_vec(), - target_address: Addr::unchecked(owner.address()), - }, - &[], - &owner, - ); - - assert!(execute_result.is_ok(), "failed to withdraw support funds"); - let contract_balances_after = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_after.len(), - 0, - "contract had some balances after withdraw" - ); - - let owner_eth_balance = query_bank_balance(&bank, ETH, owner.address().as_str()); - assert_eq!( - owner_eth_balance, - FPDecimal::from(initial_contract_balance[0].amount), - "wrong owner eth balance after withdraw" - ); - - let owner_usdt_balance = query_bank_balance(&bank, USDT, owner.address().as_str()); - assert_eq!( - owner_usdt_balance, - FPDecimal::from(initial_contract_balance[1].amount), - "wrong owner usdt balance after withdraw" - ); -} - -#[test] -fn it_allows_admin_to_withdraw_all_funds_from_contract_to_other_address() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let bank = Bank::new(&app); - - let usdt_to_withdraw = str_coin("10_000", USDT, Decimals::Six); - let eth_to_withdraw = str_coin("0.00062", ETH, Decimals::Eighteen); - - let owner = must_init_account_with_funds( - &app, - &[ - eth_to_withdraw.clone(), - str_coin("1", INJ, Decimals::Eighteen), - usdt_to_withdraw.clone(), - ], - ); - - let initial_contract_balance = &[eth_to_withdraw, usdt_to_withdraw]; - let contr_addr = - init_self_relaying_contract_and_get_address(&wasm, &owner, initial_contract_balance); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 2, - "wrong number of denoms in contract balances" - ); - - let random_dude = must_init_account_with_funds(&app, &[]); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::WithdrawSupportFunds { - coins: initial_contract_balance.to_vec(), - target_address: Addr::unchecked(random_dude.address()), - }, - &[], - &owner, - ); - - assert!(execute_result.is_ok(), "failed to withdraw support funds"); - let contract_balances_after = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_after.len(), - 0, - "contract had some balances after withdraw" - ); - - let random_dude_eth_balance = query_bank_balance(&bank, ETH, random_dude.address().as_str()); - assert_eq!( - random_dude_eth_balance, - FPDecimal::from(initial_contract_balance[0].amount), - "wrong owner eth balance after withdraw" - ); - - let random_dude_usdt_balance = query_bank_balance(&bank, USDT, random_dude.address().as_str()); - assert_eq!( - random_dude_usdt_balance, - FPDecimal::from(initial_contract_balance[1].amount), - "wrong owner usdt balance after withdraw" - ); -} - -#[test] -fn it_doesnt_allow_non_admin_to_withdraw_anything_from_contract() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let bank = Bank::new(&app); - - let usdt_to_withdraw = str_coin("10_000", USDT, Decimals::Six); - let eth_to_withdraw = str_coin("0.00062", ETH, Decimals::Eighteen); - - let owner = must_init_account_with_funds( - &app, - &[ - eth_to_withdraw.clone(), - str_coin("1", INJ, Decimals::Eighteen), - usdt_to_withdraw.clone(), - ], - ); - - let initial_contract_balance = &[eth_to_withdraw, usdt_to_withdraw]; - let contr_addr = - init_self_relaying_contract_and_get_address(&wasm, &owner, initial_contract_balance); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 2, - "wrong number of denoms in contract balances" - ); - - let random_dude = must_init_account_with_funds(&app, &[coin(1_000_000_000_000, INJ)]); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::WithdrawSupportFunds { - coins: initial_contract_balance.to_vec(), - target_address: Addr::unchecked(owner.address()), - }, - &[], - &random_dude, - ); - - assert!( - execute_result.is_err(), - "succeeded to withdraw support funds" - ); - let contract_balances_after = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_after, contract_balances_before, - "contract balances changed after failed withdraw" - ); - - let random_dude_eth_balance = query_bank_balance(&bank, ETH, random_dude.address().as_str()); - assert_eq!( - random_dude_eth_balance, - FPDecimal::ZERO, - "random dude has some eth balance after failed withdraw" - ); - - let random_dude_usdt_balance = query_bank_balance(&bank, USDT, random_dude.address().as_str()); - assert_eq!( - random_dude_usdt_balance, - FPDecimal::ZERO, - "random dude has some usdt balance after failed withdraw" - ); -} - -fn create_eth_buy_orders( - app: &InjectiveTestApp, - market_id: &str, - trader1: &SigningAccount, - trader2: &SigningAccount, -) { - create_limit_order(app, trader1, market_id, OrderSide::Buy, 201_000, 5); - create_limit_order(app, trader2, market_id, OrderSide::Buy, 195_000, 4); - create_limit_order(app, trader2, market_id, OrderSide::Buy, 192_000, 3); -} - -fn create_atom_sell_orders( - app: &InjectiveTestApp, - market_id: &str, - trader1: &SigningAccount, - trader2: &SigningAccount, - trader3: &SigningAccount, -) { - create_limit_order(app, trader1, market_id, OrderSide::Sell, 800, 800); - create_limit_order(app, trader2, market_id, OrderSide::Sell, 810, 800); - create_limit_order(app, trader3, market_id, OrderSide::Sell, 820, 800); - create_limit_order(app, trader1, market_id, OrderSide::Sell, 830, 800); -} diff --git a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs deleted file mode 100644 index c3c3f7b..0000000 --- a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs +++ /dev/null @@ -1,1795 +0,0 @@ -use injective_test_tube::{Account, Bank, Exchange, InjectiveTestApp, Module, Wasm}; -use std::ops::Neg; - -use crate::helpers::Scaled; -use injective_math::FPDecimal; - -use crate::msg::{ExecuteMsg, QueryMsg}; -use crate::testing::test_utils::{ - are_fpdecimals_approximately_equal, assert_fee_is_as_expected, - create_ninja_inj_both_side_orders, create_realistic_atom_usdt_sell_orders_from_spreadsheet, - create_realistic_eth_usdt_buy_orders_from_spreadsheet, - create_realistic_eth_usdt_sell_orders_from_spreadsheet, - create_realistic_inj_usdt_buy_orders_from_spreadsheet, - create_realistic_inj_usdt_sell_orders_from_spreadsheet, create_realistic_limit_order, - create_realistic_usdt_usdc_both_side_orders, human_to_dec, init_rich_account, - init_self_relaying_contract_and_get_address, launch_realistic_atom_usdt_spot_market, - launch_realistic_inj_usdt_spot_market, launch_realistic_ninja_inj_spot_market, - launch_realistic_usdt_usdc_spot_market, launch_realistic_weth_usdt_spot_market, - must_init_account_with_funds, query_all_bank_balances, query_bank_balance, - set_route_and_assert_success, str_coin, Decimals, OrderSide, ATOM, ETH, INJ, INJ_2, NINJA, - USDC, USDT, -}; -use crate::types::{FPCoin, SwapEstimationResult}; - -/* - This test suite focuses on using using realistic values both for spot markets and for orders and - focuses on swaps requesting exact amount. This works as expected apart, when we are converting very - low quantities from a source asset that is orders of magnitude more expensive than the target - asset (as we round up to min quantity tick size). - - ATOM/USDT market parameters was taken from mainnet. ETH/USDT market parameters mirror WETH/USDT - spot market on mainnet. INJ_2/USDT mirrors mainnet's INJ/USDT market (we used a different denom - to avoid mixing balance changes related to gas payments). - - All values used in these tests come from the 2nd, 3rd and 4th tab of this spreadsheet: - https://docs.google.com/spreadsheets/d/1-0epjX580nDO_P2mm1tSjhvjJVppsvrO1BC4_wsBeyA/edit?usp=sharing - - In all tests contract is configured to self-relay trades and thus receive a 60% fee discount. -*/ - -struct Percent<'a>(&'a str); - -#[test] -fn it_swaps_eth_to_get_minimum_exact_amount_of_atom_by_mildly_rounding_up() { - exact_two_hop_eth_atom_swap_test_template(human_to_dec("0.01", Decimals::Six), Percent("2200")) -} - -#[test] -fn it_swaps_eth_to_get_very_low_exact_amount_of_atom_by_heavily_rounding_up() { - exact_two_hop_eth_atom_swap_test_template(human_to_dec("0.11", Decimals::Six), Percent("110")) -} - -#[test] -fn it_swaps_eth_to_get_low_exact_amount_of_atom_by_rounding_up() { - exact_two_hop_eth_atom_swap_test_template(human_to_dec("4.12", Decimals::Six), Percent("10")) -} - -#[test] -fn it_correctly_swaps_eth_to_get_normal_exact_amount_of_atom() { - exact_two_hop_eth_atom_swap_test_template(human_to_dec("12.05", Decimals::Six), Percent("1")) -} - -#[test] -fn it_correctly_swaps_eth_to_get_high_exact_amount_of_atom() { - exact_two_hop_eth_atom_swap_test_template(human_to_dec("612", Decimals::Six), Percent("1")) -} - -#[test] -fn it_correctly_swaps_eth_to_get_very_high_exact_amount_of_atom() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_eth_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_limit_order( - &app, - &trader1, - &spot_market_1_id, - OrderSide::Buy, - "2137.2", - "2.78", - Decimals::Eighteen, - Decimals::Six, - ); //order not present in the spreadsheet - - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - create_realistic_limit_order( - &app, - &trader1, - &spot_market_2_id, - OrderSide::Sell, - "9.11", - "321.11", - Decimals::Six, - Decimals::Six, - ); //order not present in the spreadsheet - - app.increase_time(1); - - let eth_to_swap = "4.4"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(eth_to_swap, ETH, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let exact_quantity_to_receive = human_to_dec("1014.19", Decimals::Six); - - let query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetInputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - to_quantity: exact_quantity_to_receive, - }, - ) - .unwrap(); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: ATOM.to_string(), - target_output_quantity: exact_quantity_to_receive, - }, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let expected_difference = - human_to_dec(eth_to_swap, Decimals::Eighteen) - query_result.result_quantity; - let swapper_eth_balance_after = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let swapper_atom_balance_after = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - swapper_eth_balance_after, expected_difference, - "wrong amount of ETH was exchanged" - ); - - assert!( - swapper_atom_balance_after >= exact_quantity_to_receive, - "swapper got less than exact amount required -> expected: {} ATOM, actual: {} ATOM", - exact_quantity_to_receive.scaled(Decimals::Six.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Six.get_decimals().neg()) - ); - - let one_percent_diff = exact_quantity_to_receive * FPDecimal::must_from_str("0.01"); - - assert!( - are_fpdecimals_approximately_equal( - swapper_atom_balance_after, - exact_quantity_to_receive, - one_percent_diff, - ), - "swapper did not receive expected exact amount +/- 1% -> expected: {} ATOM, actual: {} ATOM, max diff: {} ATOM", - exact_quantity_to_receive.scaled(Decimals::Six.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Six.get_decimals().neg()), - one_percent_diff.scaled(Decimals::Six.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {contract_usdt_balance_after}, previous balance: {contract_usdt_balance_before}", - ); - - // contract is allowed to earn extra 0.73 USDT from the swap of ~$8450 worth of ETH - let max_diff = human_to_dec("0.8", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {}, previous balance: {}. Max diff: {}", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn it_swaps_inj_to_get_minimum_exact_amount_of_atom_by_mildly_rounding_up() { - exact_two_hop_inj_atom_swap_test_template(human_to_dec("0.01", Decimals::Six), Percent("0")) -} - -#[test] -fn it_swaps_inj_to_get_very_low_exact_amount_of_atom() { - exact_two_hop_inj_atom_swap_test_template(human_to_dec("0.11", Decimals::Six), Percent("0")) -} - -#[test] -fn it_swaps_inj_to_get_low_exact_amount_of_atom() { - exact_two_hop_inj_atom_swap_test_template(human_to_dec("4.12", Decimals::Six), Percent("0")) -} - -#[test] -fn it_correctly_swaps_inj_to_get_normal_exact_amount_of_atom() { - exact_two_hop_inj_atom_swap_test_template(human_to_dec("12.05", Decimals::Six), Percent("0")) -} - -#[test] -fn it_correctly_swaps_inj_to_get_high_exact_amount_of_atom() { - exact_two_hop_inj_atom_swap_test_template(human_to_dec("612", Decimals::Six), Percent("0.01")) -} - -#[test] -fn it_correctly_swaps_inj_to_get_very_high_exact_amount_of_atom() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_limit_order( - &app, - &trader1, - &spot_market_1_id, - OrderSide::Buy, - "8.99", - "280.2", - Decimals::Eighteen, - Decimals::Six, - ); //order not present in the spreadsheet - - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - create_realistic_limit_order( - &app, - &trader1, - &spot_market_2_id, - OrderSide::Sell, - "9.11", - "321.11", - Decimals::Six, - Decimals::Six, - ); //order not present in the spreadsheet - - app.increase_time(1); - - let inj_to_swap = "1100.1"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let exact_quantity_to_receive = human_to_dec("1010.12", Decimals::Six); - let max_diff_percentage = Percent("0.01"); - - let query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetInputQuantity { - source_denom: INJ_2.to_string(), - target_denom: ATOM.to_string(), - to_quantity: exact_quantity_to_receive, - }, - ) - .unwrap(); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: ATOM.to_string(), - target_output_quantity: exact_quantity_to_receive, - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let expected_difference = - human_to_dec(inj_to_swap, Decimals::Eighteen) - query_result.result_quantity; - let swapper_inj_balance_after = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let swapper_atom_balance_after = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - swapper_inj_balance_after, expected_difference, - "wrong amount of INJ was exchanged" - ); - - assert!( - swapper_atom_balance_after >= exact_quantity_to_receive, - "swapper got less than exact amount required -> expected: {} ATOM, actual: {} ATOM", - exact_quantity_to_receive.scaled(Decimals::Six.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Six.get_decimals().neg()) - ); - - let one_percent_diff = exact_quantity_to_receive - * (FPDecimal::must_from_str(max_diff_percentage.0) / FPDecimal::from(100u128)); - - assert!( - are_fpdecimals_approximately_equal( - swapper_atom_balance_after, - exact_quantity_to_receive, - one_percent_diff, - ), - "swapper did not receive expected exact ATOM amount +/- {}% -> expected: {} ATOM, actual: {} ATOM, max diff: {} ATOM", - max_diff_percentage.0, - exact_quantity_to_receive.scaled(Decimals::Six.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Six.get_decimals().neg()), - one_percent_diff.scaled(Decimals::Six.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {contract_usdt_balance_after}, previous balance: {contract_usdt_balance_before}", - ); - - // contract is allowed to earn extra 0.7 USDT from the swap of ~$8150 worth of INJ - let max_diff = human_to_dec("0.7", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn it_swaps_inj_to_get_minimum_exact_amount_of_eth() { - exact_two_hop_inj_eth_swap_test_template( - human_to_dec("0.001", Decimals::Eighteen), - Percent("0"), - ) -} - -#[test] -fn it_swaps_inj_to_get_low_exact_amount_of_eth() { - exact_two_hop_inj_eth_swap_test_template( - human_to_dec("0.012", Decimals::Eighteen), - Percent("0"), - ) -} - -#[test] -fn it_swaps_inj_to_get_normal_exact_amount_of_eth() { - exact_two_hop_inj_eth_swap_test_template(human_to_dec("0.1", Decimals::Eighteen), Percent("0")) -} - -#[test] -fn it_swaps_inj_to_get_high_exact_amount_of_eth() { - exact_two_hop_inj_eth_swap_test_template(human_to_dec("3.1", Decimals::Eighteen), Percent("0")) -} - -#[test] -fn it_swaps_inj_to_get_very_high_exact_amount_of_eth() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - ETH, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_limit_order( - &app, - &trader1, - &spot_market_1_id, - OrderSide::Buy, - "8.99", - "1882.001", - Decimals::Eighteen, - Decimals::Six, - ); //order not present in the spreadsheet - create_realistic_eth_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - create_realistic_limit_order( - &app, - &trader3, - &spot_market_2_id, - OrderSide::Sell, - "2123.1", - "18.11", - Decimals::Eighteen, - Decimals::Six, - ); //order not present in the spreadsheet - - app.increase_time(1); - - let inj_to_swap = "2855.259"; - let exact_quantity_to_receive = human_to_dec("11.2", Decimals::Eighteen); - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetInputQuantity { - source_denom: INJ_2.to_string(), - target_denom: ETH.to_string(), - to_quantity: exact_quantity_to_receive, - }, - ) - .unwrap(); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: ETH.to_string(), - target_output_quantity: exact_quantity_to_receive, - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let expected_difference = - human_to_dec(inj_to_swap, Decimals::Eighteen) - query_result.result_quantity; - let swapper_inj_balance_after = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let swapper_atom_balance_after = query_bank_balance(&bank, ETH, swapper.address().as_str()); - - assert_eq!( - swapper_inj_balance_after, expected_difference, - "wrong amount of INJ was exchanged" - ); - - assert!( - swapper_atom_balance_after >= exact_quantity_to_receive, - "swapper got less than exact amount required -> expected: {} ETH, actual: {} ETH", - exact_quantity_to_receive.scaled(Decimals::Eighteen.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Eighteen.get_decimals().neg()) - ); - - let max_diff_percent = Percent("0"); - let one_percent_diff = exact_quantity_to_receive - * (FPDecimal::must_from_str(max_diff_percent.0) / FPDecimal::from(100u128)); - - assert!( - are_fpdecimals_approximately_equal( - swapper_atom_balance_after, - exact_quantity_to_receive, - one_percent_diff, - ), - "swapper did not receive expected exact ETH amount +/- {}% -> expected: {} ETH, actual: {} ETH, max diff: {} ETH", - max_diff_percent.0, - exact_quantity_to_receive.scaled(Decimals::Eighteen.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Eighteen.get_decimals().neg()), - one_percent_diff.scaled(Decimals::Eighteen.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {contract_usdt_balance_after}, previous balance: {contract_usdt_balance_before}", - ); - - // contract is allowed to earn extra 1.6 USDT from the swap of ~$23500 worth of INJ - let max_diff = human_to_dec("1.6", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn it_correctly_swaps_between_markets_using_different_quote_assets_self_relaying() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1_000", USDT, Decimals::Six), - str_coin("1_000", USDC, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_usdt_usdc_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[ - str_coin("10", USDC, Decimals::Six), - str_coin("500", USDT, Decimals::Six), - ], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - USDC, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_usdt_usdc_both_side_orders(&app, &spot_market_2_id, &trader1); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin("1", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), - ], - ); - - let inj_to_swap = "1"; - let to_output_quantity = human_to_dec("8", Decimals::Six); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetInputQuantity { - to_quantity: to_output_quantity, - source_denom: INJ_2.to_string(), - target_denom: USDC.to_string(), - }, - ) - .unwrap(); - - let expected_input_quantity = human_to_dec("0.903", Decimals::Eighteen); - let max_diff = human_to_dec("0.001", Decimals::Eighteen); - - assert!( - are_fpdecimals_approximately_equal(expected_input_quantity, query_result.result_quantity, max_diff), - "incorrect swap result estimate returned by query. Expected: {} INJ, actual: {} INJ, max diff: {} INJ", - expected_input_quantity.scaled(Decimals::Eighteen.get_decimals().neg()), - query_result.result_quantity.scaled(Decimals::Eighteen.get_decimals().neg()), - max_diff.scaled(Decimals::Eighteen.get_decimals().neg()) - ); - - let mut expected_fees = vec![ - FPCoin { - amount: human_to_dec("0.013365", Decimals::Six), - denom: USDT.to_string(), - }, - FPCoin { - amount: human_to_dec("0.01332", Decimals::Six), - denom: USDC.to_string(), - }, - ]; - - // we don't care too much about decimal fraction of the fee - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - human_to_dec("0.1", Decimals::Six), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 2, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: USDC.to_string(), - target_output_quantity: to_output_quantity, - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, USDC, swapper.address().as_str()); - - let expected_inj_leftover = - human_to_dec(inj_to_swap, Decimals::Eighteen) - expected_input_quantity; - assert_eq!( - from_balance, expected_inj_leftover, - "incorrect original amount was left after swap" - ); - - let expected_amount = human_to_dec("8.00711", Decimals::Six); - - assert_eq!( - to_balance, - expected_amount, - "Swapper received less than expected minimum amount. Expected: {} USDC, actual: {} USDC", - expected_amount.scaled(Decimals::Six.get_decimals().neg()), - to_balance.scaled(Decimals::Six.get_decimals().neg()), - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 2, - "wrong number of denoms in contract balances" - ); - - // let's check contract's USDT balance - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {} USDT, previous balance: {} USDT", - contract_usdt_balance_after, - contract_usdt_balance_before - ); - - // contract is allowed to earn extra 0.001 USDT from the swap of ~$8 worth of INJ - let max_diff = human_to_dec("0.001", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); - - // let's check contract's USDC balance - let contract_usdc_balance_before = - FPDecimal::must_from_str(contract_balances_before[1].amount.as_str()); - let contract_usdc_balance_after = - FPDecimal::must_from_str(contract_balances_after[1].amount.as_str()); - - assert!( - contract_usdc_balance_after >= contract_usdc_balance_before, - "Contract lost some money after swap. Actual balance: {} USDC, previous balance: {} USDC", - contract_usdc_balance_after, - contract_usdc_balance_before - ); - - // contract is allowed to earn extra 0.001 USDC from the swap of ~$8 worth of INJ - let max_diff = human_to_dec("0.001", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdc_balance_after, - contract_usdc_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDC, previous balance: {} USDC. Max diff: {} USDC", - contract_usdc_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdc_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn it_correctly_swaps_between_markets_using_different_quote_assets_self_relaying_ninja() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1_000", USDT, Decimals::Six), - str_coin("1_000", USDC, Decimals::Six), - str_coin("1_000", NINJA, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("101", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_ninja_inj_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[ - str_coin("100", INJ_2, Decimals::Eighteen), - str_coin("10", USDC, Decimals::Six), - str_coin("500", USDT, Decimals::Six), - ], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - USDT, - NINJA, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - - create_realistic_inj_usdt_sell_orders_from_spreadsheet(&app, &spot_market_1_id, &trader1); - create_ninja_inj_both_side_orders(&app, &spot_market_2_id, &trader1); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin("1", INJ, Decimals::Eighteen), - str_coin("100000", USDT, Decimals::Six), - ], - ); - - let usdt_to_swap = "100000"; - let to_output_quantity = human_to_dec("501000", Decimals::Six); - - let from_balance_before = query_bank_balance(&bank, USDT, swapper.address().as_str()); - let to_balance_before = query_bank_balance(&bank, NINJA, swapper.address().as_str()); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: NINJA.to_string(), - target_output_quantity: to_output_quantity, - }, - &[str_coin(usdt_to_swap, USDT, Decimals::Six)], - &swapper, - ) - .unwrap(); - - let from_balance_after = query_bank_balance(&bank, USDT, swapper.address().as_str()); - let to_balance_after = query_bank_balance(&bank, NINJA, swapper.address().as_str()); - - // from 100000 USDT -> 96201.062128 USDT = 3798.937872 USDT - let expected_from_balance_before = human_to_dec("100000", Decimals::Six); - let expected_from_balance_after = human_to_dec("96201.062128", Decimals::Six); - - // from 0 NINJA to 501000 NINJA - let expected_to_balance_before = human_to_dec("0", Decimals::Six); - let expected_to_balance_after = human_to_dec("501000", Decimals::Six); - - assert_eq!( - from_balance_before, expected_from_balance_before, - "incorrect original amount was left after swap" - ); - assert_eq!( - to_balance_before, expected_to_balance_before, - "incorrect target amount after swap" - ); - assert_eq!( - from_balance_after, expected_from_balance_after, - "incorrect original amount was left after swap" - ); - assert_eq!( - to_balance_after, expected_to_balance_after, - "incorrect target amount after swap" - ); -} - -#[test] -fn it_doesnt_lose_buffer_if_exact_swap_of_eth_to_atom_is_executed_multiple_times() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - let eth_to_swap = "4.08"; - let iterations = 100i128; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin( - (FPDecimal::must_from_str(eth_to_swap) * FPDecimal::from(iterations)) - .to_string() - .as_str(), - ETH, - Decimals::Eighteen, - ), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let mut counter = 0; - - while counter < iterations { - create_realistic_eth_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: ATOM.to_string(), - target_output_quantity: human_to_dec("906", Decimals::Six), - }, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - counter += 1 - } - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_balance_usdt_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - let contract_balance_usdt_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - - assert!( - contract_balance_usdt_after >= contract_balance_usdt_before, - "Contract lost some money after swap. Starting balance: {contract_balance_usdt_after}, Current balance: {contract_balance_usdt_before}", - ); - - // single swap with the same values results in < 0.7 USDT earning, so we expected that 100 same swaps - // won't change balance by more than 0.7 * 100 = 70 USDT - let max_diff = human_to_dec("0.7", Decimals::Six) * FPDecimal::from(iterations); - - assert!(are_fpdecimals_approximately_equal( - contract_balance_usdt_after, - contract_balance_usdt_before, - max_diff, - ), "Contract balance changed too much. Starting balance: {}, Current balance: {}. Max diff: {}", - contract_balance_usdt_before.scaled(Decimals::Six.get_decimals().neg()), - contract_balance_usdt_after.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn it_reverts_when_funds_provided_are_below_required_to_get_exact_amount() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let inj_to_swap = "608"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let exact_quantity_to_receive = human_to_dec("600", Decimals::Six); - let swapper_inj_balance_before = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - - let _: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetInputQuantity { - source_denom: INJ_2.to_string(), - target_denom: ATOM.to_string(), - to_quantity: exact_quantity_to_receive, - }, - ) - .unwrap(); - - let execute_result = wasm - .execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: ATOM.to_string(), - target_output_quantity: exact_quantity_to_receive, - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap_err(); - - assert!(execute_result.to_string().contains("Provided amount of 608000000000000000000 is below required amount of 609714000000000000000"), "wrong error message"); - - let swapper_inj_balance_after = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let swapper_atom_balance_after = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - swapper_inj_balance_before, swapper_inj_balance_after, - "some amount of INJ was exchanged" - ); - - assert_eq!( - FPDecimal::ZERO, - swapper_atom_balance_after, - "swapper received some ATOM" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert_eq!( - contract_usdt_balance_after, contract_usdt_balance_before, - "Contract's balance changed after failed swap", - ); -} - -// TEST TEMPLATES - -// source much more expensive than target -fn exact_two_hop_eth_atom_swap_test_template( - exact_quantity_to_receive: FPDecimal, - max_diff_percentage: Percent, -) { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_eth_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let eth_to_swap = "4.08"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(eth_to_swap, ETH, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetInputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - to_quantity: exact_quantity_to_receive, - }, - ) - .unwrap(); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: ATOM.to_string(), - target_output_quantity: exact_quantity_to_receive, - }, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let expected_difference = - human_to_dec(eth_to_swap, Decimals::Eighteen) - query_result.result_quantity; - let swapper_eth_balance_after = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let swapper_atom_balance_after = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - swapper_eth_balance_after, expected_difference, - "wrong amount of ETH was exchanged" - ); - - let one_percent_diff = exact_quantity_to_receive - * (FPDecimal::must_from_str(max_diff_percentage.0) / FPDecimal::from(100u128)); - - assert!( - swapper_atom_balance_after >= exact_quantity_to_receive, - "swapper got less than exact amount required -> expected: {} ATOM, actual: {} ATOM", - exact_quantity_to_receive.scaled(Decimals::Six.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Six.get_decimals().neg()) - ); - - assert!( - are_fpdecimals_approximately_equal( - swapper_atom_balance_after, - exact_quantity_to_receive, - one_percent_diff, - ), - "swapper did not receive expected exact amount +/- {}% -> expected: {} ATOM, actual: {} ATOM, max diff: {} ATOM", - max_diff_percentage.0, - exact_quantity_to_receive.scaled(Decimals::Six.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Six.get_decimals().neg()), - one_percent_diff.scaled(Decimals::Six.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {contract_usdt_balance_after}, previous balance: {contract_usdt_balance_before}", - ); - - // contract is allowed to earn extra 0.7 USDT from the swap of ~$8150 worth of ETH - let max_diff = human_to_dec("0.7", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -// source more or less similarly priced as target -fn exact_two_hop_inj_atom_swap_test_template( - exact_quantity_to_receive: FPDecimal, - max_diff_percentage: Percent, -) { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let inj_to_swap = "973.258"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetInputQuantity { - source_denom: INJ_2.to_string(), - target_denom: ATOM.to_string(), - to_quantity: exact_quantity_to_receive, - }, - ) - .unwrap(); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: ATOM.to_string(), - target_output_quantity: exact_quantity_to_receive, - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let expected_difference = - human_to_dec(inj_to_swap, Decimals::Eighteen) - query_result.result_quantity; - let swapper_inj_balance_after = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let swapper_atom_balance_after = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - swapper_inj_balance_after, expected_difference, - "wrong amount of INJ was exchanged" - ); - - assert!( - swapper_atom_balance_after >= exact_quantity_to_receive, - "swapper got less than exact amount required -> expected: {} ATOM, actual: {} ATOM", - exact_quantity_to_receive.scaled(Decimals::Six.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Six.get_decimals().neg()) - ); - - let one_percent_diff = exact_quantity_to_receive - * (FPDecimal::must_from_str(max_diff_percentage.0) / FPDecimal::from(100u128)); - - assert!( - are_fpdecimals_approximately_equal( - swapper_atom_balance_after, - exact_quantity_to_receive, - one_percent_diff, - ), - "swapper did not receive expected exact ATOM amount +/- {}% -> expected: {} ATOM, actual: {} ATOM, max diff: {} ATOM", - max_diff_percentage.0, - exact_quantity_to_receive.scaled(Decimals::Six.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Six.get_decimals().neg()), - one_percent_diff.scaled(Decimals::Six.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {contract_usdt_balance_after}, previous balance: {contract_usdt_balance_before}", - ); - - // contract is allowed to earn extra 0.7 USDT from the swap of ~$8150 worth of INJ - let max_diff = human_to_dec("0.7", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -// source much cheaper than target -fn exact_two_hop_inj_eth_swap_test_template( - exact_quantity_to_receive: FPDecimal, - max_diff_percentage: Percent, -) { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("10_000", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - ETH, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_eth_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let inj_to_swap = "973.258"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetInputQuantity { - source_denom: INJ_2.to_string(), - target_denom: ETH.to_string(), - to_quantity: exact_quantity_to_receive, - }, - ) - .unwrap(); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapExactOutput { - target_denom: ETH.to_string(), - target_output_quantity: exact_quantity_to_receive, - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let expected_difference = - human_to_dec(inj_to_swap, Decimals::Eighteen) - query_result.result_quantity; - let swapper_inj_balance_after = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let swapper_atom_balance_after = query_bank_balance(&bank, ETH, swapper.address().as_str()); - - assert_eq!( - swapper_inj_balance_after, expected_difference, - "wrong amount of INJ was exchanged" - ); - - assert!( - swapper_atom_balance_after >= exact_quantity_to_receive, - "swapper got less than exact amount required -> expected: {} ETH, actual: {} ETH", - exact_quantity_to_receive.scaled(Decimals::Eighteen.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Eighteen.get_decimals().neg()) - ); - - let one_percent_diff = exact_quantity_to_receive - * (FPDecimal::must_from_str(max_diff_percentage.0) / FPDecimal::from(100u128)); - - assert!( - are_fpdecimals_approximately_equal( - swapper_atom_balance_after, - exact_quantity_to_receive, - one_percent_diff, - ), - "swapper did not receive expected exact ETH amount +/- {}% -> expected: {} ETH, actual: {} ETH, max diff: {} ETH", - max_diff_percentage.0, - exact_quantity_to_receive.scaled(Decimals::Eighteen.get_decimals().neg()), - swapper_atom_balance_after.scaled(Decimals::Eighteen.get_decimals().neg()), - one_percent_diff.scaled(Decimals::Eighteen.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {contract_usdt_balance_after}, previous balance: {contract_usdt_balance_before}", - ); - - // contract is allowed to earn extra 0.7 USDT from the swap of ~$8500 worth of INJ - let max_diff = human_to_dec("0.82", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} diff --git a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs deleted file mode 100644 index 6213738..0000000 --- a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs +++ /dev/null @@ -1,1425 +0,0 @@ -use injective_test_tube::{ - Account, Bank, Exchange, InjectiveTestApp, Module, RunnerResult, SigningAccount, Wasm, -}; -use std::ops::Neg; - -use crate::helpers::Scaled; -use injective_math::FPDecimal; - -use crate::msg::{ExecuteMsg, QueryMsg}; -use crate::testing::test_utils::{ - are_fpdecimals_approximately_equal, assert_fee_is_as_expected, - create_realistic_atom_usdt_sell_orders_from_spreadsheet, - create_realistic_eth_usdt_buy_orders_from_spreadsheet, - create_realistic_eth_usdt_sell_orders_from_spreadsheet, - create_realistic_inj_usdt_buy_orders_from_spreadsheet, - create_realistic_usdt_usdc_both_side_orders, human_to_dec, init_rich_account, - init_self_relaying_contract_and_get_address, launch_realistic_atom_usdt_spot_market, - launch_realistic_inj_usdt_spot_market, launch_realistic_usdt_usdc_spot_market, - launch_realistic_weth_usdt_spot_market, must_init_account_with_funds, query_all_bank_balances, - query_bank_balance, set_route_and_assert_success, str_coin, Decimals, ATOM, - DEFAULT_ATOMIC_MULTIPLIER, DEFAULT_SELF_RELAYING_FEE_PART, DEFAULT_TAKER_FEE, ETH, INJ, INJ_2, - USDC, USDT, -}; -use crate::types::{FPCoin, SwapEstimationResult}; - -/* - This test suite focuses on using using realistic values both for spot markets and for orders and - focuses on swaps requesting minimum amount. - - ATOM/USDT market parameters were taken from mainnet. ETH/USDT market parameters mirror WETH/USDT - spot market on mainnet. INJ_2/USDT mirrors mainnet's INJ/USDT market (we used a different denom - to avoid mixing balance changes related to swap with ones related to gas payments). - - Hardcoded values used in these tests come from the second tab of this spreadsheet: - https://docs.google.com/spreadsheets/d/1-0epjX580nDO_P2mm1tSjhvjJVppsvrO1BC4_wsBeyA/edit?usp=sharing - - In all tests contract is configured to self-relay trades and thus receive a 60% fee discount. -*/ - -pub fn happy_path_two_hops_test(app: InjectiveTestApp, owner: SigningAccount, contr_addr: String) { - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_eth_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let eth_to_swap = "4.08"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(eth_to_swap, ETH, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: human_to_dec(eth_to_swap, Decimals::Eighteen), - }, - ) - .unwrap(); - - // it's expected that it is slightly less than what's in the spreadsheet - let expected_amount = human_to_dec("906.17", Decimals::Six); - - assert_eq!( - query_result.result_quantity, expected_amount, - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![ - FPCoin { - amount: human_to_dec("12.221313", Decimals::Six), - denom: "usdt".to_string(), - }, - FPCoin { - amount: human_to_dec("12.184704", Decimals::Six), - denom: "usdt".to_string(), - }, - ]; - - // we don't care too much about decimal fraction of the fee - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - human_to_dec("0.1", Decimals::Six), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(906u128), - }, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - - assert!( - to_balance >= expected_amount, - "Swapper received less than expected minimum amount. Expected: {} ATOM, actual: {} ATOM", - expected_amount.scaled(Decimals::Six.get_decimals().neg()), - to_balance.scaled(Decimals::Six.get_decimals().neg()), - ); - - let max_diff = human_to_dec("0.1", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - expected_amount, - to_balance, - max_diff, - ), - "Swapper did not receive expected amount. Expected: {} ATOM, actual: {} ATOM, max diff: {} ATOM", - expected_amount.scaled(Decimals::Six.get_decimals().neg()), - to_balance.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {} USDT, previous balance: {} USDT", - contract_usdt_balance_after, - contract_usdt_balance_before - ); - - // contract is allowed to earn extra 0.7 USDT from the swap of ~$8150 worth of ETH - let max_diff = human_to_dec("0.7", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn happy_path_two_hops_swap_eth_atom_realistic_values_self_relaying() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - - happy_path_two_hops_test(app, owner, contr_addr); -} - -#[test] -fn happy_path_two_hops_swap_inj_eth_realistic_values_self_relaying() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - ETH, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_eth_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let inj_to_swap = "973.258"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: INJ_2.to_string(), - target_denom: ETH.to_string(), - from_quantity: human_to_dec(inj_to_swap, Decimals::Eighteen), - }, - ) - .unwrap(); - - // it's expected that it is slightly less than what's in the spreadsheet - let expected_amount = human_to_dec("3.994", Decimals::Eighteen); - - assert_eq!( - query_result.result_quantity, expected_amount, - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![ - FPCoin { - amount: human_to_dec("12.73828775", Decimals::Six), - denom: "usdt".to_string(), - }, - FPCoin { - amount: human_to_dec("12.70013012", Decimals::Six), - denom: "usdt".to_string(), - }, - ]; - - // we don't care too much about decimal fraction of the fee - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - human_to_dec("0.1", Decimals::Six), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ETH.to_string(), - min_output_quantity: FPDecimal::from(906u128), - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - - assert!( - to_balance >= expected_amount, - "Swapper received less than expected minimum amount. Expected: {} ETH, actual: {} ETH", - expected_amount.scaled(Decimals::Eighteen.get_decimals().neg()), - to_balance.scaled(Decimals::Eighteen.get_decimals().neg()), - ); - - let max_diff = human_to_dec("0.1", Decimals::Eighteen); - - assert!( - are_fpdecimals_approximately_equal( - expected_amount, - to_balance, - max_diff, - ), - "Swapper did not receive expected amount. Expected: {} ETH, actual: {} ETH, max diff: {} ETH", - expected_amount.scaled(Decimals::Eighteen.get_decimals().neg()), - to_balance.scaled(Decimals::Eighteen.get_decimals().neg()), - max_diff.scaled(Decimals::Eighteen.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {} USDT, previous balance: {} USDT", - contract_usdt_balance_after, - contract_usdt_balance_before - ); - - // contract is allowed to earn extra 0.7 USDT from the swap of ~$8150 worth of ETH - let max_diff = human_to_dec("0.7", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn happy_path_two_hops_swap_inj_atom_realistic_values_self_relaying() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let inj_to_swap = "973.258"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(inj_to_swap, INJ_2, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: INJ_2.to_string(), - target_denom: ATOM.to_string(), - from_quantity: human_to_dec(inj_to_swap, Decimals::Eighteen), - }, - ) - .unwrap(); - - // it's expected that it is slightly less than what's in the spreadsheet - let expected_amount = human_to_dec("944.26", Decimals::Six); - - assert_eq!( - query_result.result_quantity, expected_amount, - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![ - FPCoin { - amount: human_to_dec("12.73828775", Decimals::Six), - denom: "usdt".to_string(), - }, - FPCoin { - amount: human_to_dec("12.70013012", Decimals::Six), - denom: "usdt".to_string(), - }, - ]; - - // we don't care too much about decimal fraction of the fee - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - human_to_dec("0.1", Decimals::Six), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(944u128), - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - - assert!( - to_balance >= expected_amount, - "Swapper received less than expected minimum amount. Expected: {} ATOM, actual: {} ATOM", - expected_amount.scaled(Decimals::Six.get_decimals().neg()), - to_balance.scaled(Decimals::Six.get_decimals().neg()), - ); - - let max_diff = human_to_dec("0.1", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - expected_amount, - to_balance, - max_diff, - ), - "Swapper did not receive expected amount. Expected: {} ATOM, actual: {} ATOM, max diff: {} ATOM", - expected_amount.scaled(Decimals::Six.get_decimals().neg()), - to_balance.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {} USDT, previous balance: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()) - ); - - // contract is allowed to earn extra 0.82 USDT from the swap of ~$8500 worth of INJ - let max_diff = human_to_dec("0.82", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {}, previous balance: {}. Max diff: {}", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn it_executes_swap_between_markets_using_different_quote_assets_self_relaying() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1_000", USDT, Decimals::Six), - str_coin("1_000", USDC, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_inj_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_usdt_usdc_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[ - str_coin("10", USDC, Decimals::Six), - str_coin("500", USDT, Decimals::Six), - ], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - INJ_2, - USDC, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - - create_realistic_inj_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_usdt_usdc_both_side_orders(&app, &spot_market_2_id, &trader1); - - app.increase_time(1); - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin("1", INJ, Decimals::Eighteen), - str_coin("1", INJ_2, Decimals::Eighteen), - ], - ); - - let inj_to_swap = "1"; - - let mut query_result: SwapEstimationResult = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: INJ_2.to_string(), - target_denom: USDC.to_string(), - from_quantity: human_to_dec(inj_to_swap, Decimals::Eighteen), - }, - ) - .unwrap(); - - let expected_amount = human_to_dec("8.867", Decimals::Six); - let max_diff = human_to_dec("0.001", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal(expected_amount, query_result.result_quantity, max_diff), - "incorrect swap result estimate returned by query" - ); - - let mut expected_fees = vec![ - FPCoin { - amount: human_to_dec("0.013365", Decimals::Six), - denom: USDT.to_string(), - }, - FPCoin { - amount: human_to_dec("0.01332", Decimals::Six), - denom: USDC.to_string(), - }, - ]; - - // we don't care too much about decimal fraction of the fee - assert_fee_is_as_expected( - &mut query_result.expected_fees, - &mut expected_fees, - human_to_dec("0.1", Decimals::Six), - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 2, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: USDC.to_string(), - min_output_quantity: FPDecimal::from(8u128), - }, - &[str_coin(inj_to_swap, INJ_2, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, INJ_2, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, USDC, swapper.address().as_str()); - - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - - assert!( - to_balance >= expected_amount, - "Swapper received less than expected minimum amount. Expected: {} USDC, actual: {} USDC", - expected_amount.scaled(Decimals::Eighteen.get_decimals().neg()), - to_balance.scaled(Decimals::Eighteen.get_decimals().neg()), - ); - - let max_diff = human_to_dec("0.1", Decimals::Eighteen); - - assert!( - are_fpdecimals_approximately_equal( - expected_amount, - to_balance, - max_diff, - ), - "Swapper did not receive expected amount. Expected: {} USDC, actual: {} USDC, max diff: {} USDC", - expected_amount.scaled(Decimals::Eighteen.get_decimals().neg()), - to_balance.scaled(Decimals::Eighteen.get_decimals().neg()), - max_diff.scaled(Decimals::Eighteen.get_decimals().neg()) - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 2, - "wrong number of denoms in contract balances" - ); - - // let's check contract's USDT balance - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {} USDT, previous balance: {} USDT", - contract_usdt_balance_after, - contract_usdt_balance_before - ); - - // contract is allowed to earn extra 0.001 USDT from the swap of ~$8 worth of INJ - let max_diff = human_to_dec("0.001", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDT, previous balance: {} USDT. Max diff: {} USDT", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); - - // let's check contract's USDC balance - let contract_usdc_balance_before = - FPDecimal::must_from_str(contract_balances_before[1].amount.as_str()); - let contract_usdc_balance_after = - FPDecimal::must_from_str(contract_balances_after[1].amount.as_str()); - - assert!( - contract_usdc_balance_after >= contract_usdc_balance_before, - "Contract lost some money after swap. Actual balance: {} USDC, previous balance: {} USDC", - contract_usdc_balance_after, - contract_usdc_balance_before - ); - - // contract is allowed to earn extra 0.001 USDC from the swap of ~$8 worth of INJ - let max_diff = human_to_dec("0.001", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdc_balance_after, - contract_usdc_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {} USDC, previous balance: {} USDC. Max diff: {} USDC", - contract_usdc_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdc_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn it_doesnt_lose_buffer_if_executed_multiple_times() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("1_000", USDT, Decimals::Six)], - ); - - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - let eth_to_swap = "4.08"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin( - (FPDecimal::must_from_str(eth_to_swap) * FPDecimal::from(100u128)) - .to_string() - .as_str(), - ETH, - Decimals::Eighteen, - ), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let mut counter = 0; - let iterations = 100; - - while counter < iterations { - create_realistic_eth_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(906u128), - }, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - counter += 1 - } - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_balance_usdt_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - let contract_balance_usdt_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - - assert!( - contract_balance_usdt_after >= contract_balance_usdt_before, - "Contract lost some money after swap. Starting balance: {}, Current balance: {}", - contract_balance_usdt_after, - contract_balance_usdt_before - ); - - // single swap with the same values results in < 0.7 USDT earning, so we expected that 100 same swaps - // won't change balance by more than 0.7 * 100 = 70 USDT - let max_diff = human_to_dec("0.7", Decimals::Six) * FPDecimal::from(iterations as u128); - - assert!(are_fpdecimals_approximately_equal( - contract_balance_usdt_after, - contract_balance_usdt_before, - max_diff, - ), "Contract balance changed too much. Starting balance: {}, Current balance: {}. Max diff: {}", - contract_balance_usdt_before.scaled(Decimals::Six.get_decimals().neg()), - contract_balance_usdt_after.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -/* - This test shows that query overestimates the amount of USDT needed to execute the swap. It seems - that in reality we get a better price when selling ETH than the one returned by query and can - execute the swap with less USDT. - - It's easiest to check by commenting out the query_result assert and running the test. It will - pass and amounts will perfectly match our assertions. -*/ -#[ignore] -#[test] -fn it_correctly_calculates_required_funds_when_querying_buy_with_minimum_buffer_and_realistic_values( -) { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("51", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_eth_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let eth_to_swap = "4.08"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(eth_to_swap, ETH, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let query_result: FPDecimal = wasm - .query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: human_to_dec(eth_to_swap, Decimals::Eighteen), - }, - ) - .unwrap(); - - assert_eq!( - query_result, - human_to_dec("906.195", Decimals::Six), - "incorrect swap result estimate returned by query" - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(906u128), - }, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - assert_eq!( - to_balance, - human_to_dec("906.195", Decimals::Six), - "swapper did not receive expected amount" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let atom_amount_below_min_tick_size = FPDecimal::must_from_str("0.0005463"); - let mut dust_value = atom_amount_below_min_tick_size * human_to_dec("8.89", Decimals::Six); - - let fee_refund = dust_value - * FPDecimal::must_from_str(&format!( - "{}", - DEFAULT_TAKER_FEE * DEFAULT_ATOMIC_MULTIPLIER * DEFAULT_SELF_RELAYING_FEE_PART - )); - - dust_value += fee_refund; - - let expected_contract_usdt_balance = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()) + dust_value; - let actual_contract_balance = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - let contract_balance_diff = expected_contract_usdt_balance - actual_contract_balance; - - // here the actual difference is 0.000067 USDT, which we attribute differences between decimal precision of Rust/Go and Google Sheets - assert!( - human_to_dec("0.0001", Decimals::Six) - contract_balance_diff > FPDecimal::ZERO, - "contract balance has changed too much after swap" - ); -} - -/* - This test shows that in some edge cases we calculate required funds differently than the chain does. - When estimating balance hold for atomic market order chain doesn't take into account whether sender is - also fee recipient, while we do. This leads to a situation where we estimate required funds to be - lower than what's expected by the chain, which makes the swap fail. - - In this test we skip query estimation and go straight to executing swap. -*/ -#[ignore] -#[test] -fn it_correctly_calculates_required_funds_when_executing_buy_with_minimum_buffer_and_realistic_values( -) { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - // in reality we need to add at least 49 USDT to the buffer, even if according to contract's calculations 42 USDT would be enough to execute the swap - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("42", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_eth_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let eth_to_swap = "4.08"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(eth_to_swap, ETH, Decimals::Eighteen), - str_coin("0.01", INJ, Decimals::Eighteen), - ], - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(906u128), - }, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen)], - &swapper, - ) - .unwrap(); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - assert_eq!( - from_balance, - FPDecimal::ZERO, - "some of the original amount wasn't swapped" - ); - assert_eq!( - to_balance, - human_to_dec("906.195", Decimals::Six), - "swapper did not receive expected amount" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let contract_usdt_balance_before = - FPDecimal::must_from_str(contract_balances_before[0].amount.as_str()); - let contract_usdt_balance_after = - FPDecimal::must_from_str(contract_balances_after[0].amount.as_str()); - - assert!( - contract_usdt_balance_after >= contract_usdt_balance_before, - "Contract lost some money after swap. Actual balance: {}, previous balance: {}", - contract_usdt_balance_after, - contract_usdt_balance_before - ); - - // contract can earn max of 0.7 USDT, when exchanging ETH worth ~$8150 - let max_diff = human_to_dec("0.7", Decimals::Six); - - assert!( - are_fpdecimals_approximately_equal( - contract_usdt_balance_after, - contract_usdt_balance_before, - max_diff, - ), - "Contract balance changed too much. Actual balance: {}, previous balance: {}. Max diff: {}", - contract_usdt_balance_after.scaled(Decimals::Six.get_decimals().neg()), - contract_usdt_balance_before.scaled(Decimals::Six.get_decimals().neg()), - max_diff.scaled(Decimals::Six.get_decimals().neg()) - ); -} - -#[test] -fn it_returns_all_funds_if_there_is_not_enough_buffer_realistic_values() { - let app = InjectiveTestApp::new(); - let wasm = Wasm::new(&app); - let exchange = Exchange::new(&app); - let bank = Bank::new(&app); - - let _signer = must_init_account_with_funds(&app, &[str_coin("1", INJ, Decimals::Eighteen)]); - - let _validator = app - .get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap(); - let owner = must_init_account_with_funds( - &app, - &[ - str_coin("1", ETH, Decimals::Eighteen), - str_coin("1", ATOM, Decimals::Six), - str_coin("1_000", USDT, Decimals::Six), - str_coin("10_000", INJ, Decimals::Eighteen), - ], - ); - - let spot_market_1_id = launch_realistic_weth_usdt_spot_market(&exchange, &owner); - let spot_market_2_id = launch_realistic_atom_usdt_spot_market(&exchange, &owner); - - // 41 USDT is just below the amount required to buy required ATOM amount - let contr_addr = init_self_relaying_contract_and_get_address( - &wasm, - &owner, - &[str_coin("41", USDT, Decimals::Six)], - ); - set_route_and_assert_success( - &wasm, - &owner, - &contr_addr, - ETH, - ATOM, - vec![ - spot_market_1_id.as_str().into(), - spot_market_2_id.as_str().into(), - ], - ); - - let trader1 = init_rich_account(&app); - let trader2 = init_rich_account(&app); - let trader3 = init_rich_account(&app); - - create_realistic_eth_usdt_buy_orders_from_spreadsheet( - &app, - &spot_market_1_id, - &trader1, - &trader2, - ); - create_realistic_atom_usdt_sell_orders_from_spreadsheet( - &app, - &spot_market_2_id, - &trader1, - &trader2, - &trader3, - ); - - app.increase_time(1); - - let eth_to_swap = "4.08"; - - let swapper = must_init_account_with_funds( - &app, - &[ - str_coin(eth_to_swap, ETH, Decimals::Eighteen), - str_coin("1", INJ, Decimals::Eighteen), - ], - ); - - let query_result: RunnerResult = wasm.query( - &contr_addr, - &QueryMsg::GetOutputQuantity { - source_denom: ETH.to_string(), - target_denom: ATOM.to_string(), - from_quantity: human_to_dec(eth_to_swap, Decimals::Eighteen), - }, - ); - - assert!(query_result.is_err(), "query should fail"); - - assert!( - query_result - .unwrap_err() - .to_string() - .contains("Swap amount too high"), - "incorrect error message in query result" - ); - - let contract_balances_before = query_all_bank_balances(&bank, &contr_addr); - assert_eq!( - contract_balances_before.len(), - 1, - "wrong number of denoms in contract balances" - ); - - let execute_result = wasm.execute( - &contr_addr, - &ExecuteMsg::SwapMinOutput { - target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::from(906u128), - }, - &[str_coin(eth_to_swap, ETH, Decimals::Eighteen)], - &swapper, - ); - - assert!(execute_result.is_err(), "execute should fail"); - - let from_balance = query_bank_balance(&bank, ETH, swapper.address().as_str()); - let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); - - assert_eq!( - from_balance, - human_to_dec(eth_to_swap, Decimals::Eighteen), - "source balance changed after failed swap" - ); - assert_eq!( - to_balance, - FPDecimal::ZERO, - "target balance changed after failed swap" - ); - - let contract_balances_after = query_all_bank_balances(&bank, contr_addr.as_str()); - assert_eq!( - contract_balances_after.len(), - 1, - "wrong number of denoms in contract balances" - ); - assert_eq!( - contract_balances_before[0].amount, contract_balances_after[0].amount, - "contract balance has changed after failed swap" - ); -} diff --git a/contracts/swap/src/testing/queries_tests.rs b/contracts/swap/src/testing/queries_tests.rs index b7f6c2e..0363acc 100644 --- a/contracts/swap/src/testing/queries_tests.rs +++ b/contracts/swap/src/testing/queries_tests.rs @@ -574,7 +574,7 @@ fn get_all_queries_returns_empty_array_if_no_routes_are_set() { ) .unwrap(); - let all_routes_result = get_all_swap_routes(deps.as_ref().storage); + let all_routes_result = get_all_swap_routes(deps.as_ref().storage, None, None); assert!(all_routes_result.is_ok(), "Error getting all routes"); assert!( @@ -626,7 +626,7 @@ fn get_all_queries_returns_expected_array_if_routes_are_set() { ) .unwrap(); - let all_routes_result = get_all_swap_routes(deps.as_ref().storage); + let all_routes_result = get_all_swap_routes(deps.as_ref().storage, None, None); assert!(all_routes_result.is_ok(), "Error getting all routes"); let eth_inj_route = SwapRoute { diff --git a/contracts/swap/src/testing/test_utils.rs b/contracts/swap/src/testing/test_utils.rs index ccee9a3..dadc6ed 100644 --- a/contracts/swap/src/testing/test_utils.rs +++ b/contracts/swap/src/testing/test_utils.rs @@ -2,33 +2,23 @@ use std::collections::HashMap; use std::str::FromStr; use cosmwasm_std::testing::{MockApi, MockStorage}; -use cosmwasm_std::{ - coin, to_json_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, - SystemResult, -}; +use cosmwasm_std::{coin, to_json_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, SystemResult}; use injective_std::shim::Any; -use injective_std::types::cosmos::bank::v1beta1::{ - MsgSend, QueryAllBalancesRequest, QueryBalanceRequest, -}; +use injective_std::types::cosmos::bank::v1beta1::{MsgSend, QueryAllBalancesRequest, QueryBalanceRequest}; use injective_std::types::cosmos::base::v1beta1::Coin as TubeCoin; use injective_std::types::cosmos::gov::v1::MsgVote; use injective_std::types::cosmos::gov::v1beta1::MsgSubmitProposal; use injective_std::types::injective::exchange; use injective_std::types::injective::exchange::v1beta1::{ - MsgCreateSpotLimitOrder, MsgInstantSpotMarketLaunch, OrderInfo, OrderType, - QuerySpotMarketsRequest, SpotMarketParamUpdateProposal, SpotOrder, -}; -use injective_test_tube::{ - Account, Bank, Exchange, Gov, InjectiveTestApp, Module, SigningAccount, Wasm, + MsgCreateSpotLimitOrder, MsgInstantSpotMarketLaunch, OrderInfo, OrderType, QuerySpotMarketsRequest, SpotMarketParamUpdateProposal, SpotOrder, }; +use injective_test_tube::{Account, Bank, Exchange, Gov, InjectiveTestApp, Module, SigningAccount, Wasm}; use crate::helpers::Scaled; use injective_cosmwasm::{ - create_orderbook_response_handler, create_spot_multi_market_handler, - get_default_subaccount_id_for_checked_address, inj_mock_deps, test_market_ids, - HandlesMarketIdQuery, InjectiveQueryWrapper, MarketId, PriceLevel, - QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, WasmMockQuerier, TEST_MARKET_ID_1, - TEST_MARKET_ID_2, + create_orderbook_response_handler, create_spot_multi_market_handler, get_default_subaccount_id_for_checked_address, inj_mock_deps, + test_market_ids, HandlesMarketIdQuery, InjectiveQueryWrapper, MarketId, PriceLevel, QueryMarketAtomicExecutionFeeMultiplierResponse, SpotMarket, + WasmMockQuerier, TEST_MARKET_ID_1, TEST_MARKET_ID_2, }; use injective_math::FPDecimal; use prost::Message; @@ -89,21 +79,11 @@ pub fn mock_deps_eth_inj( let mut markets = HashMap::new(); markets.insert( MarketId::new(TEST_MARKET_ID_1).unwrap(), - create_mock_spot_market( - "eth", - FPDecimal::must_from_str("0.001"), - FPDecimal::must_from_str("0.001"), - 0, - ), + create_mock_spot_market("eth", FPDecimal::must_from_str("0.001"), FPDecimal::must_from_str("0.001"), 0), ); markets.insert( MarketId::new(TEST_MARKET_ID_2).unwrap(), - create_mock_spot_market( - "inj", - FPDecimal::must_from_str("0.001"), - FPDecimal::must_from_str("0.001"), - 1, - ), + create_mock_spot_market("inj", FPDecimal::must_from_str("0.001"), FPDecimal::must_from_str("0.001"), 1), ); querier.spot_market_response_handler = create_spot_multi_market_handler(markets); @@ -144,8 +124,7 @@ pub fn mock_deps_eth_inj( ]; orderbooks.insert(MarketId::new(TEST_MARKET_ID_2).unwrap(), inj_sell_orderbook); - querier.spot_market_orderbook_response_handler = - create_orderbook_response_handler(orderbooks); + querier.spot_market_orderbook_response_handler = create_orderbook_response_handler(orderbooks); if multiplier_query_behavior == MultiplierQueryBehavior::Fail { pub fn create_spot_error_multiplier_handler() -> Option> { @@ -160,8 +139,7 @@ pub fn mock_deps_eth_inj( Some(Box::new(Temp {})) } - querier.market_atomic_execution_fee_multiplier_response_handler = - create_spot_error_multiplier_handler() + querier.market_atomic_execution_fee_multiplier_response_handler = create_spot_error_multiplier_handler() } else { pub fn create_spot_ok_multiplier_handler() -> Option> { struct Temp {} @@ -178,8 +156,7 @@ pub fn mock_deps_eth_inj( Some(Box::new(Temp {})) } - querier.market_atomic_execution_fee_multiplier_response_handler = - create_spot_ok_multiplier_handler() + querier.market_atomic_execution_fee_multiplier_response_handler = create_spot_ok_multiplier_handler() } }) } @@ -200,12 +177,7 @@ pub fn mock_realistic_deps_eth_atom( ); markets.insert( MarketId::new(TEST_MARKET_ID_2).unwrap(), - create_mock_spot_market( - "atom", - FPDecimal::must_from_str("0.001"), - FPDecimal::must_from_str("10000"), - 1, - ), + create_mock_spot_market("atom", FPDecimal::must_from_str("0.001"), FPDecimal::must_from_str("10000"), 1), ); querier.spot_market_response_handler = create_spot_multi_market_handler(markets); @@ -246,8 +218,7 @@ pub fn mock_realistic_deps_eth_atom( ]; orderbooks.insert(MarketId::new(TEST_MARKET_ID_2).unwrap(), inj_sell_orderbook); - querier.spot_market_orderbook_response_handler = - create_orderbook_response_handler(orderbooks); + querier.spot_market_orderbook_response_handler = create_orderbook_response_handler(orderbooks); if multiplier_query_behavior == MultiplierQueryBehavior::Fail { pub fn create_spot_error_multiplier_handler() -> Option> { @@ -262,8 +233,7 @@ pub fn mock_realistic_deps_eth_atom( Some(Box::new(Temp {})) } - querier.market_atomic_execution_fee_multiplier_response_handler = - create_spot_error_multiplier_handler() + querier.market_atomic_execution_fee_multiplier_response_handler = create_spot_error_multiplier_handler() } else { pub fn create_spot_ok_multiplier_handler() -> Option> { struct Temp {} @@ -280,18 +250,12 @@ pub fn mock_realistic_deps_eth_atom( Some(Box::new(Temp {})) } - querier.market_atomic_execution_fee_multiplier_response_handler = - create_spot_ok_multiplier_handler() + querier.market_atomic_execution_fee_multiplier_response_handler = create_spot_ok_multiplier_handler() } }) } -fn create_mock_spot_market( - base: &str, - min_price_tick_size: FPDecimal, - min_quantity_tick_size: FPDecimal, - idx: u32, -) -> SpotMarket { +fn create_mock_spot_market(base: &str, min_price_tick_size: FPDecimal, min_quantity_tick_size: FPDecimal, idx: u32) -> SpotMarket { SpotMarket { ticker: format!("{base}usdt"), base_denom: base.to_string(), @@ -303,35 +267,23 @@ fn create_mock_spot_market( status: injective_cosmwasm::MarketStatus::Active, min_price_tick_size, min_quantity_tick_size, + min_notional: "0".to_string(), } } pub fn wasm_file(contract_name: String) -> String { let arch = std::env::consts::ARCH; - let artifacts_dir = - std::env::var("ARTIFACTS_DIR_PATH").unwrap_or_else(|_| "artifacts".to_string()); + let artifacts_dir = std::env::var("ARTIFACTS_DIR_PATH").unwrap_or_else(|_| "artifacts".to_string()); let snaked_name = contract_name.replace('-', "_"); format!("../../{artifacts_dir}/{snaked_name}-{arch}.wasm") } -pub fn store_code( - wasm: &Wasm, - owner: &SigningAccount, - contract_name: String, -) -> u64 { +pub fn store_code(wasm: &Wasm, owner: &SigningAccount, contract_name: String) -> u64 { let wasm_byte_code = std::fs::read(wasm_file(contract_name)).unwrap(); - wasm.store_code(&wasm_byte_code, None, owner) - .unwrap() - .data - .code_id + wasm.store_code(&wasm_byte_code, None, owner).unwrap().data.code_id } -pub fn launch_spot_market( - exchange: &Exchange, - signer: &SigningAccount, - base: &str, - quote: &str, -) -> String { +pub fn launch_spot_market(exchange: &Exchange, signer: &SigningAccount, base: &str, quote: &str) -> String { let ticker = format!("{base}/{quote}"); exchange .instant_spot_market_launch( @@ -342,6 +294,7 @@ pub fn launch_spot_market( quote_denom: quote.to_string(), min_price_tick_size: "1_000_000_000_000_000".to_owned(), min_quantity_tick_size: "1_000_000_000_000_000".to_owned(), + min_notional: "0".to_string(), }, signer, ) @@ -368,6 +321,7 @@ pub fn launch_custom_spot_market( quote_denom: quote.to_string(), min_price_tick_size: min_price_tick_size.to_string(), min_quantity_tick_size: min_quantity_tick_size.to_string(), + min_notional: "0".to_string(), }, signer, ) @@ -390,10 +344,7 @@ pub fn get_spot_market_id(exchange: &Exchange, ticker: String) market.market_id.to_string() } -pub fn launch_realistic_inj_usdt_spot_market( - exchange: &Exchange, - signer: &SigningAccount, -) -> String { +pub fn launch_realistic_inj_usdt_spot_market(exchange: &Exchange, signer: &SigningAccount) -> String { launch_custom_spot_market( exchange, signer, @@ -404,10 +355,7 @@ pub fn launch_realistic_inj_usdt_spot_market( ) } -pub fn launch_realistic_weth_usdt_spot_market( - exchange: &Exchange, - signer: &SigningAccount, -) -> String { +pub fn launch_realistic_weth_usdt_spot_market(exchange: &Exchange, signer: &SigningAccount) -> String { launch_custom_spot_market( exchange, signer, @@ -418,10 +366,7 @@ pub fn launch_realistic_weth_usdt_spot_market( ) } -pub fn launch_realistic_atom_usdt_spot_market( - exchange: &Exchange, - signer: &SigningAccount, -) -> String { +pub fn launch_realistic_atom_usdt_spot_market(exchange: &Exchange, signer: &SigningAccount) -> String { launch_custom_spot_market( exchange, signer, @@ -432,10 +377,7 @@ pub fn launch_realistic_atom_usdt_spot_market( ) } -pub fn launch_realistic_usdt_usdc_spot_market( - exchange: &Exchange, - signer: &SigningAccount, -) -> String { +pub fn launch_realistic_usdt_usdc_spot_market(exchange: &Exchange, signer: &SigningAccount) -> String { launch_custom_spot_market( exchange, signer, @@ -446,10 +388,7 @@ pub fn launch_realistic_usdt_usdc_spot_market( ) } -pub fn launch_realistic_ninja_inj_spot_market( - exchange: &Exchange, - signer: &SigningAccount, -) -> String { +pub fn launch_realistic_ninja_inj_spot_market(exchange: &Exchange, signer: &SigningAccount) -> String { launch_custom_spot_market( exchange, signer, @@ -477,16 +416,7 @@ pub fn create_realistic_eth_usdt_buy_orders_from_spreadsheet( Decimals::Six, ); - create_realistic_limit_order( - app, - trader2, - market_id, - OrderSide::Buy, - "1978", - "1.23", - Decimals::Eighteen, - Decimals::Six, - ); + create_realistic_limit_order(app, trader2, market_id, OrderSide::Buy, "1978", "1.23", Decimals::Eighteen, Decimals::Six); create_realistic_limit_order( app, @@ -592,11 +522,7 @@ pub fn create_realistic_inj_usdt_buy_orders_from_spreadsheet( ); } -pub fn create_realistic_inj_usdt_sell_orders_from_spreadsheet( - app: &InjectiveTestApp, - market_id: &str, - trader1: &SigningAccount, -) { +pub fn create_realistic_inj_usdt_sell_orders_from_spreadsheet(app: &InjectiveTestApp, market_id: &str, trader1: &SigningAccount) { create_realistic_limit_order( app, trader1, @@ -616,56 +542,16 @@ pub fn create_realistic_atom_usdt_sell_orders_from_spreadsheet( trader2: &SigningAccount, trader3: &SigningAccount, ) { - create_realistic_limit_order( - app, - trader1, - market_id, - OrderSide::Sell, - "8.89", - "197.89", - Decimals::Six, - Decimals::Six, - ); + create_realistic_limit_order(app, trader1, market_id, OrderSide::Sell, "8.89", "197.89", Decimals::Six, Decimals::Six); - create_realistic_limit_order( - app, - trader2, - market_id, - OrderSide::Sell, - "8.93", - "181.02", - Decimals::Six, - Decimals::Six, - ); + create_realistic_limit_order(app, trader2, market_id, OrderSide::Sell, "8.93", "181.02", Decimals::Six, Decimals::Six); - create_realistic_limit_order( - app, - trader3, - market_id, - OrderSide::Sell, - "8.99", - "203.12", - Decimals::Six, - Decimals::Six, - ); + create_realistic_limit_order(app, trader3, market_id, OrderSide::Sell, "8.99", "203.12", Decimals::Six, Decimals::Six); - create_realistic_limit_order( - app, - trader1, - market_id, - OrderSide::Sell, - "9.01", - "421.11", - Decimals::Six, - Decimals::Six, - ); + create_realistic_limit_order(app, trader1, market_id, OrderSide::Sell, "9.01", "421.11", Decimals::Six, Decimals::Six); } -pub fn create_realistic_usdt_usdc_both_side_orders( - app: &InjectiveTestApp, - market_id: &str, - trader1: &SigningAccount, -) { +pub fn create_realistic_usdt_usdc_both_side_orders(app: &InjectiveTestApp, market_id: &str, trader1: &SigningAccount) { create_realistic_limit_order( app, trader1, @@ -690,11 +576,7 @@ pub fn create_realistic_usdt_usdc_both_side_orders( } // not really realistic yet -pub fn create_ninja_inj_both_side_orders( - app: &InjectiveTestApp, - market_id: &str, - trader1: &SigningAccount, -) { +pub fn create_ninja_inj_both_side_orders(app: &InjectiveTestApp, market_id: &str, trader1: &SigningAccount) { create_realistic_limit_order( app, trader1, @@ -713,14 +595,7 @@ pub enum OrderSide { Sell, } -pub fn create_limit_order( - app: &InjectiveTestApp, - trader: &SigningAccount, - market_id: &str, - order_side: OrderSide, - price: u128, - quantity: u32, -) { +pub fn create_limit_order(app: &InjectiveTestApp, trader: &SigningAccount, market_id: &str, order_side: OrderSide, price: u128, quantity: u32) { let exchange = Exchange::new(app); exchange .create_spot_limit_order( @@ -729,13 +604,11 @@ pub fn create_limit_order( order: Some(SpotOrder { market_id: market_id.to_string(), order_info: Some(OrderInfo { - subaccount_id: get_default_subaccount_id_for_checked_address( - &Addr::unchecked(trader.address()), - ) - .to_string(), + subaccount_id: get_default_subaccount_id_for_checked_address(&Addr::unchecked(trader.address())).to_string(), fee_recipient: trader.address(), price: format!("{price}000000000000000000"), quantity: format!("{quantity}000000000000000000"), + cid: "".to_string(), }), order_type: if order_side == OrderSide::Buy { OrderType::BuyAtomic.into() @@ -750,17 +623,11 @@ pub fn create_limit_order( .unwrap(); } -pub fn scale_price_quantity_for_market( - price: &str, - quantity: &str, - base_decimals: &Decimals, - quote_decimals: &Decimals, -) -> (String, String) { +pub fn scale_price_quantity_for_market(price: &str, quantity: &str, base_decimals: &Decimals, quote_decimals: &Decimals) -> (String, String) { let price_dec = FPDecimal::must_from_str(price.replace('_', "").as_str()); let quantity_dec = FPDecimal::must_from_str(quantity.replace('_', "").as_str()); - let scaled_price = - price_dec.scaled(quote_decimals.get_decimals() - base_decimals.get_decimals()); + let scaled_price = price_dec.scaled(quote_decimals.get_decimals() - base_decimals.get_decimals()); let scaled_quantity = quantity_dec.scaled(base_decimals.get_decimals()); (dec_to_proto(scaled_price), dec_to_proto(scaled_quantity)) } @@ -780,8 +647,7 @@ pub fn create_realistic_limit_order( base_decimals: Decimals, quote_decimals: Decimals, ) { - let (price_to_send, quantity_to_send) = - scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); + let (price_to_send, quantity_to_send) = scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); let exchange = Exchange::new(app); exchange @@ -791,13 +657,11 @@ pub fn create_realistic_limit_order( order: Some(SpotOrder { market_id: market_id.to_string(), order_info: Some(OrderInfo { - subaccount_id: get_default_subaccount_id_for_checked_address( - &Addr::unchecked(trader.address()), - ) - .to_string(), + subaccount_id: get_default_subaccount_id_for_checked_address(&Addr::unchecked(trader.address())).to_string(), fee_recipient: trader.address(), price: price_to_send, quantity: quantity_to_send, + cid: "".to_string(), }), order_type: if order_side == OrderSide::Buy { OrderType::BuyAtomic.into() @@ -812,11 +676,7 @@ pub fn create_realistic_limit_order( .unwrap(); } -pub fn init_self_relaying_contract_and_get_address( - wasm: &Wasm, - owner: &SigningAccount, - initial_balance: &[Coin], -) -> String { +pub fn init_self_relaying_contract_and_get_address(wasm: &Wasm, owner: &SigningAccount, initial_balance: &[Coin]) -> String { let code_id = store_code(wasm, owner, "swap_contract".to_string()); wasm.instantiate( code_id, @@ -878,19 +738,14 @@ pub fn set_route_and_assert_success( .unwrap(); } -pub fn must_init_account_with_funds( - app: &InjectiveTestApp, - initial_funds: &[Coin], -) -> SigningAccount { +pub fn must_init_account_with_funds(app: &InjectiveTestApp, initial_funds: &[Coin]) -> SigningAccount { app.init_account(initial_funds).unwrap() } -pub fn query_all_bank_balances( - bank: &Bank, - address: &str, -) -> Vec { +pub fn query_all_bank_balances(bank: &Bank, address: &str) -> Vec { bank.query_all_balances(&QueryAllBalancesRequest { address: address.to_string(), + resolve_denom: false, pagination: None, }) .unwrap() @@ -912,12 +767,7 @@ pub fn query_bank_balance(bank: &Bank, denom: &str, address: & .unwrap() } -pub fn pause_spot_market( - app: &InjectiveTestApp, - market_id: &str, - proposer: &SigningAccount, - validator: &SigningAccount, -) { +pub fn pause_spot_market(app: &InjectiveTestApp, market_id: &str, proposer: &SigningAccount, validator: &SigningAccount) { let gov = Gov::new(app); pass_spot_market_params_update_proposal( &gov, @@ -931,6 +781,9 @@ pub fn pause_spot_market( min_price_tick_size: "".to_string(), min_quantity_tick_size: "".to_string(), status: 2, + min_notional: "0".to_string(), + ticker: "0".to_string(), + admin_info: "0".to_string(), }, proposer, validator, @@ -982,8 +835,7 @@ pub fn pass_spot_market_params_update_proposal( } pub fn init_default_validator_account(app: &InjectiveTestApp) -> SigningAccount { - app.get_first_validator_signing_account(INJ.to_string(), 1.2f64) - .unwrap() + app.get_first_validator_signing_account(INJ.to_string(), 1.2f64).unwrap() } pub fn init_default_signer_account(app: &InjectiveTestApp) -> SigningAccount { @@ -1005,11 +857,7 @@ pub fn init_rich_account(app: &InjectiveTestApp) -> SigningAccount { ) } -pub fn fund_account_with_some_inj( - bank: &Bank, - from: &SigningAccount, - to: &SigningAccount, -) { +pub fn fund_account_with_some_inj(bank: &Bank, from: &SigningAccount, to: &SigningAccount) { bank.send( MsgSend { from_address: from.address(), @@ -1029,9 +877,7 @@ pub fn human_to_dec(raw_number: &str, decimals: Decimals) -> FPDecimal { } pub fn human_to_proto(raw_number: &str, decimals: i32) -> String { - FPDecimal::must_from_str(&raw_number.replace('_', "")) - .scaled(18 + decimals) - .to_string() + FPDecimal::must_from_str(&raw_number.replace('_', "")).scaled(18 + decimals).to_string() } pub fn str_coin(human_amount: &str, denom: &str, decimals: Decimals) -> Coin { @@ -1041,9 +887,7 @@ pub fn str_coin(human_amount: &str, denom: &str, decimals: Decimals) -> Coin { } mod tests { - use crate::testing::test_utils::{ - human_to_dec, human_to_proto, scale_price_quantity_for_market, Decimals, - }; + use crate::testing::test_utils::{human_to_dec, human_to_proto, scale_price_quantity_for_market, Decimals}; use injective_math::FPDecimal; #[test] @@ -1053,19 +897,13 @@ mod tests { let mut expected = FPDecimal::must_from_str("1000000000000000000"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 18 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 18 decimal to dec"); decimals = Decimals::Six; expected = FPDecimal::must_from_str("1000000"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 6 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 6 decimal to dec"); } #[test] @@ -1075,19 +913,13 @@ mod tests { let mut expected = FPDecimal::must_from_str("1100000000000000000"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 18 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 18 decimal to dec"); decimals = Decimals::Six; expected = FPDecimal::must_from_str("1100000"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 6 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 6 decimal to dec"); } #[test] @@ -1097,10 +929,7 @@ mod tests { let expected = FPDecimal::must_from_str("1000000000000000001"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 18 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 18 decimal to dec"); } #[test] @@ -1110,10 +939,7 @@ mod tests { let expected = FPDecimal::must_from_str("1000001"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 18 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 18 decimal to dec"); } #[test] @@ -1123,19 +949,13 @@ mod tests { let mut expected = FPDecimal::must_from_str("112300000000000000"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 18 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 18 decimal to dec"); decimals = Decimals::Six; expected = FPDecimal::must_from_str("112300"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 6 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 6 decimal to dec"); } #[test] @@ -1145,10 +965,7 @@ mod tests { let expected = FPDecimal::must_from_str("1"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 18 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 18 decimal to dec"); } #[test] @@ -1158,10 +975,7 @@ mod tests { let expected = FPDecimal::must_from_str("1"); let actual = human_to_dec(integer, decimals); - assert_eq!( - actual, expected, - "failed to convert integer with 18 decimal to dec" - ); + assert_eq!(actual, expected, "failed to convert integer with 18 decimal to dec"); } #[test] @@ -1171,19 +985,13 @@ mod tests { let mut expected = "1000000000000000000000000000000000000"; let actual = human_to_proto(integer, decimals.get_decimals()); - assert_eq!( - actual, expected, - "failed to convert integer with 18 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert integer with 18 decimal to proto"); decimals = Decimals::Six; expected = "1000000000000000000000000"; let actual = human_to_proto(integer, decimals.get_decimals()); - assert_eq!( - actual, expected, - "failed to convert integer with 6 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert integer with 6 decimal to proto"); } #[test] @@ -1193,19 +1001,13 @@ mod tests { let mut expected = "1100000000000000000000000000000000000"; let actual = human_to_proto(number, decimals.get_decimals()); - assert_eq!( - actual, expected, - "failed to convert decimal with 18 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert decimal with 18 decimal to proto"); decimals = Decimals::Six; expected = "1100000000000000000000000"; let actual = human_to_proto(number, decimals.get_decimals()); - assert_eq!( - actual, expected, - "failed to convert decimal with 6 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert decimal with 6 decimal to proto"); } #[test] @@ -1215,19 +1017,13 @@ mod tests { let mut expected = "100000000000000000000000000000000000"; let actual = human_to_proto(number, decimals.get_decimals()); - assert_eq!( - actual, expected, - "failed to convert decimal with 18 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert decimal with 18 decimal to proto"); decimals = Decimals::Six; expected = "100000000000000000000000"; let actual = human_to_proto(number, decimals.get_decimals()); - assert_eq!( - actual, expected, - "failed to convert decimal with 6 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert decimal with 6 decimal to proto"); } #[test] @@ -1237,16 +1033,12 @@ mod tests { let expected = "1000000000000000000"; let actual = human_to_proto(number, decimals.get_decimals()); - assert_eq!( - actual, expected, - "failed to convert decimal with 18 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert decimal with 18 decimal to proto"); } #[test] #[should_panic] - fn it_panics_when_converting_decimal_below_zero_with_18_decimals_with_too_high_precision_to_proto( - ) { + fn it_panics_when_converting_decimal_below_zero_with_18_decimals_with_too_high_precision_to_proto() { let number = "0.0000000000000000001"; let decimals = Decimals::Eighteen; @@ -1260,10 +1052,7 @@ mod tests { let expected = "1000000000000000000"; let actual = human_to_proto(number, decimals.get_decimals()); - assert_eq!( - actual, expected, - "failed to convert decimal with 6 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert decimal with 6 decimal to proto"); } #[test] @@ -1272,10 +1061,7 @@ mod tests { let expected = "1000001000000000000"; let actual = human_to_proto(number, 0); - assert_eq!( - actual, expected, - "failed to convert decimal with 0 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert decimal with 0 decimal to proto"); } #[test] @@ -1284,10 +1070,7 @@ mod tests { let expected = "1000000000000"; let actual = human_to_proto(number, 0); - assert_eq!( - actual, expected, - "failed to convert decimal with 0 decimal to proto" - ); + assert_eq!(actual, expected, "failed to convert decimal with 0 decimal to proto"); } #[test] @@ -1298,8 +1081,7 @@ mod tests { let base_decimals = Decimals::Eighteen; let quote_decimals = Decimals::Six; - let (scaled_price, scaled_quantity) = - scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); + let (scaled_price, scaled_quantity) = scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); // 1 => 1 * 10^6 - 10^18 => 0.000000000001000000 * 10^18 => 1000000 assert_eq!(scaled_price, "1000000", "price was scaled incorrectly"); @@ -1318,8 +1100,7 @@ mod tests { let base_decimals = Decimals::Eighteen; let quote_decimals = Decimals::Six; - let (scaled_price, scaled_quantity) = - scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); + let (scaled_price, scaled_quantity) = scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); // 0.000000000008782000 * 10^18 = 8782000 assert_eq!(scaled_price, "8782000", "price was scaled incorrectly"); @@ -1337,19 +1118,12 @@ mod tests { let base_decimals = Decimals::Six; let quote_decimals = Decimals::Six; - let (scaled_price, scaled_quantity) = - scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); + let (scaled_price, scaled_quantity) = scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); // 1 => 1.(10^18) => 1000000000000000000 - assert_eq!( - scaled_price, "1000000000000000000", - "price was scaled incorrectly" - ); + assert_eq!(scaled_price, "1000000000000000000", "price was scaled incorrectly"); // 1 => 1(10^6).(10^18) => 1000000000000000000000000 - assert_eq!( - scaled_quantity, "1000000000000000000000000", - "quantity was scaled incorrectly" - ); + assert_eq!(scaled_quantity, "1000000000000000000000000", "quantity was scaled incorrectly"); } #[test] @@ -1360,40 +1134,21 @@ mod tests { let base_decimals = Decimals::Six; let quote_decimals = Decimals::Six; - let (scaled_price, scaled_quantity) = - scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); + let (scaled_price, scaled_quantity) = scale_price_quantity_for_market(price, quantity, &base_decimals, "e_decimals); // 1.129 => 1.129(10^15) => 1129000000000000000 - assert_eq!( - scaled_price, "1129000000000000000", - "price was scaled incorrectly" - ); + assert_eq!(scaled_price, "1129000000000000000", "price was scaled incorrectly"); // 1.62 => 1.62(10^4)(10^18) => 1000000000000000000000000 - assert_eq!( - scaled_quantity, "1620000000000000000000000", - "quantity was scaled incorrectly" - ); + assert_eq!(scaled_quantity, "1620000000000000000000000", "quantity was scaled incorrectly"); } } -pub fn are_fpdecimals_approximately_equal( - first: FPDecimal, - second: FPDecimal, - max_diff: FPDecimal, -) -> bool { +pub fn are_fpdecimals_approximately_equal(first: FPDecimal, second: FPDecimal, max_diff: FPDecimal) -> bool { (first - second).abs() <= max_diff } -pub fn assert_fee_is_as_expected( - raw_fees: &mut Vec, - expected_fees: &mut Vec, - max_diff: FPDecimal, -) { - assert_eq!( - raw_fees.len(), - expected_fees.len(), - "Wrong number of fee denoms received" - ); +pub fn assert_fee_is_as_expected(raw_fees: &mut Vec, expected_fees: &mut Vec, max_diff: FPDecimal) { + assert_eq!(raw_fees.len(), expected_fees.len(), "Wrong number of fee denoms received"); raw_fees.sort_by_key(|f| f.denom.clone()); expected_fees.sort_by_key(|f| f.denom.clone()); diff --git a/contracts/swap/src/types.rs b/contracts/swap/src/types.rs index 911f861..34669e9 100644 --- a/contracts/swap/src/types.rs +++ b/contracts/swap/src/types.rs @@ -1,17 +1,17 @@ +use cosmwasm_schema::cw_serde; use cosmwasm_std::{Addr, Coin}; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; - use injective_cosmwasm::MarketId; use injective_math::FPDecimal; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub enum SwapEstimationAmount { InputQuantity(FPCoin), ReceiveQuantity(FPCoin), } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct FPCoin { pub amount: FPDecimal, pub denom: String, @@ -19,7 +19,7 @@ pub struct FPCoin { impl From for Coin { fn from(value: FPCoin) -> Self { - Coin::new(value.amount.into(), value.denom) + Coin::new(value.amount, value.denom) } } @@ -32,19 +32,19 @@ impl From for FPCoin { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct ConfigResponse { pub config: Config, pub contract_version: String, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub enum SwapQuantityMode { MinOutputQuantity(FPDecimal), ExactOutputQuantity(FPDecimal), } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct StepExecutionEstimate { pub worst_price: FPDecimal, pub result_denom: String, @@ -53,7 +53,7 @@ pub struct StepExecutionEstimate { pub fee_estimate: Option, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct CurrentSwapOperation { // whole swap operation pub sender_address: Addr, @@ -63,7 +63,7 @@ pub struct CurrentSwapOperation { pub refund: Coin, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct CurrentSwapStep { // current step pub step_idx: u16, @@ -72,7 +72,7 @@ pub struct CurrentSwapStep { pub is_buy: bool, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct SwapResults { pub market_id: MarketId, pub quantity: FPDecimal, @@ -80,7 +80,7 @@ pub struct SwapResults { pub fee: FPDecimal, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct Config { // if fee_recipient is contract, fee discount is replayed to a sender (will not stay in the contract) pub fee_recipient: Addr, @@ -88,7 +88,7 @@ pub struct Config { pub admin: Addr, } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct SwapRoute { pub steps: Vec, pub source_denom: String, @@ -107,13 +107,13 @@ impl SwapRoute { } } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct SwapStep { pub market_id: MarketId, pub quote_denom: String, // quote for this step of swap, eg for swap eth/inj using eth/usdt and inj/usdt markets, quotes will be eth in 1st step and usdt in 2nd } -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[cw_serde] pub struct SwapEstimationResult { pub result_quantity: FPDecimal, pub expected_fees: Vec, diff --git a/docs/admin.md b/docs/admin.md new file mode 100644 index 0000000..6ac7507 --- /dev/null +++ b/docs/admin.md @@ -0,0 +1,71 @@ +# Admin Functionality + +This file contains template transactions for performing the primary functions of managing the Swap contracts. + +## Sentry Node + +Link to [swagger](https://sentry.lcd.injective.network/swagger/). + +### Examples + +```bash +NODE=https://sentry.tm.injective.network:443 +CHAIN_ID=injective-1 +CONTRACT_ADDRESS=inj12yj3mtjarujkhcp6lg3klxjjfrx2v7v8yswgp9 # Helix Swap Contract +``` + +#### Subaccount Open Spot Orders + +```bash +curl -X GET "https://sentry.lcd.injective.network/injective/exchange/v1beta1/spot/orders/$MARKET_ID/$SUBACCOUNT_ID" -H "accept: application/json" | jq . +``` + +#### Subaccount Open Derivative Orders + +```bash +curl -X GET "https://sentry.lcd.injective.network/injective/exchange/v1beta1/derivative/orders/$MARKET_ID/$SUBACCOUNT_ID" -H "accept: application/json" | jq . +``` + +#### Subaccount Deposits + +```bash +curl -X GET "https://sentry.lcd.injective.network/injective/exchange/v1beta1/exchange/subaccountDeposits?subaccount_id=$SUBACCOUNT_ID" -H "accept: application/json" | jq . +``` + +## Wasm + +### Store + +```bash +injectived tx wasm store ./artifacts/grid-aarch64.wasm --from=sgt-account --gas=auto --gas-prices 500000000inj --gas-adjustment 1.3 --yes --output=json --node=https://testnet.sentry.tm.injective.network:443 --chain-id='injective-888' | jq . +``` + +### Instantiate - Derivative + +```bash +injectived tx wasm instantiate $CODE_ID '{"market_type": "derivative", "base_decimals": 18, "quote_decimals": 6, "market_id": "0x17ef48032cb24375ba7c2e39f384e56433bcab20cbee9a7357e4cba2eb00abe6", "small_order_threshold": "10.0"}' --label="inj-usdt-pgt" --admin sgt-account --from=sgt-account --gas=auto --gas-prices 500000000inj --gas-adjustment 1.3 --output=json --node=https://testnet.sentry.tm.injective.network:443 --chain-id='injective-888' +``` + +### Instantiate - Spot + +```bash +injectived tx wasm instantiate $CODE_ID '{"market_type": "spot", "base_decimals": 6, "quote_decimals": 6, "market_id": "0x42edf70cc37e155e9b9f178e04e18999bc8c404bd7b638cc4cbf41da8ef45a21", "valuation_market_id": "0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0", "small_order_threshold": "10.0"}' --label="qunt-inj-sgt" --admin sgt-account --from=sgt-account --gas=auto --gas-prices 500000000inj --gas-adjustment 1.3 --output=json --node=https://sentry.tm.injective.network:443 --chain-id='injective-1' +``` + +injectived tx wasm instantiate 685 '{"market_type": "spot", "base_decimals": 8, "quote_decimals": 6, "market_id": "0xb03ead807922111939d1b62121ae2956cf6f0a6b03dfdea8d9589c05b98f670f", "small_order_threshold": "10.0"}' --label="w-usdt-sgt" --admin sgt-account --from=sgt-account --gas=auto --gas-prices 500000000inj --gas-adjustment 1.3 --output=json --node=https://sentry.tm.injective.network:443 --chain-id='injective-1' + +### Execute + +#### Create Strategy - Trailing + +```bash +injectived tx wasm execute $CONTRACT_ADDRESS "{'create_strategy': {'subaccount_id': '$SUBACCOUNT_ID', 'bounds': ['1.0', 1.1], 'levels': 10, 'strategy_type': {'trailing_arithmetc': {'lower_trailing_bound': '0.5', 'upper_trailing_bound': '1.5'}}}}" --from=sgt-account --gas=auto --gas-prices 500000000inj --gas-adjustment 1.3 --output=json --yes --node=https://sentry.tm.injective.network:443 --chain-id='injective-1' | jq . +``` + +### Query + +#### Config + +```bash +injectived query wasm contract-state smart $CONTRACT_ADDRESS '{"get_config": {}}' --node=https://sentry.tm.injective.network:443 --output=json | jq . +``` diff --git a/docs/copy_to_devnet_setup.sh b/docs/copy_to_devnet_setup.sh new file mode 100755 index 0000000..2b34097 --- /dev/null +++ b/docs/copy_to_devnet_setup.sh @@ -0,0 +1,13 @@ +#!/bin/bash +ARCH="" + +if [[ $(arch) = "arm64" ]]; then + ARCH=-aarch64 +fi + +COMMIT_HASH=$(git rev-parse --short HEAD) + +rm -f ../devnet-setup/wasm-contracts/swap_contract* +cp artifacts/swap_contract$ARCH.wasm ../devnet-setup/wasm-contracts/swap_contract_${COMMIT_HASH}.wasm + +echo "SWAP_CONVERTER_COMMIT_HASH=$COMMIT_HASH" > "../devnet-setup/wasm-contracts/swap_contract.version" \ No newline at end of file diff --git a/docs/examples.sh b/docs/examples.sh new file mode 100644 index 0000000..6829463 --- /dev/null +++ b/docs/examples.sh @@ -0,0 +1,41 @@ +# Variables +KBT="--keyring-backend test" +CHAIN_ID="injective-1" +HOME="--home ." +GAS_AND_FEE="--gas=6000000 --gas-prices=500000000inj" +NODE="https://k8s.global.mainnet.tm.injective.network:443" +SYNC_MODE="--broadcast-mode sync" +USER="swap-exec" +code_id="67" +ADMIN="inj1exmuhajlxg08l4a59rchsjycxk42dgydg7u62l" + +# MAINNET MARKETS +INJUSDT=0xa508cb32923323679f29a032c70342c147c17d0145625922b0ef22e955c844c0 +ATOMUSDT=0x0511ddc4e6586f3bfe1acb2dd905f8b8a82c97e1edaef654b12ca7e6031ca0fa +WETHUSDT=0xd1956e20d74eeb1febe31cd37060781ff1cb266f49e0512b446a5fafa9a16034 +WMATICUSDT=0xb9a07515a5c239fcbfa3e25eaa829a03d46c4b52b9ab8ee6be471e9eb0e9ea31 +USDCUSDCET=0xda0bb7a7d8361d17a9d2327ed161748f33ecbf02738b45a7dd1d812735d1531c +SOMMUSDT=0x0686357b934c761784d58a2b8b12618dfe557de108a220e06f8f6580abb83aab +GFUSDT=0x7f71c4fba375c964be8db7fc7a5275d974f8c6cdc4d758f2ac4997f106bb052b + +# MAINNET DENOMS +USDT=peggy0xdAC17F958D2ee523a2206206994597C13D831ec7 +WETH=peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 +ATOM=ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9 +WMATIC=factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1dxv423h8ygzgxmxnvrf33ws3k94aedfdevxd8h +SOL=factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1sthrn5ep8ls5vzz8f9gp89khhmedahhdkqa8z3 +SOMM=ibc/34346A60A95EB030D62D6F5BDD4B745BE18E8A693372A8A347D5D53DBBB1328B +USDCET=factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1q6zlut7gtkzknkk773jecujwsdkgq882akqksk +GF=peggy0xAaEf88cEa01475125522e117BFe45cF32044E238 + + + +# INSTANTIATE +INIT='{"admin":"'$ADMIN_ADDRESS'", "fee_recipient":{"address": "'$FEE_RECIPIENT_ADDRESS'"}}' +INSTANTIATE_TX_HASH=$(yes 12345678 | injectived tx wasm instantiate $CODE_ID "$INIT" --label="Your Swap Contract" \ +--from=$USER --chain-id="$CHAIN_ID" --yes --admin=$USER $HOME --node=$NODE \ +$GAS_AND_FEE $SYNC_MODE $KBT ) + +# SET ROUTE +INJ_USDT_ROUTE='{"set_route":{"source_denom":"inj","target_denom":"'$USDT'","route":["'$INJUSDT'"]}}' +TX_HASH=$(injectived tx wasm execute $SWAP_CONTRACT_ADDRESS "$INJ_USDT_ROUTE" $HOME --from=$USER $KBT --chain-id=$CHAIN_ID --yes $GAS_AND_FEE --node=$NODE | grep txhash | awk '{print $2}') \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f49bdba..ce4af78 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "1.73.0" +channel = "1.78.0" components = [ "rustfmt" ] profile = "minimal" targets = [ "wasm32-unknown-unknown" ]