From 397d2b6741d26e6cd1b226d8d701115bf8819cc7 Mon Sep 17 00:00:00 2001 From: Markus Waas Date: Fri, 12 Jan 2024 21:45:00 -0600 Subject: [PATCH] chore: update to latest CosmWasm --- Cargo.lock | 247 +++++++++--------- build_release.sh | 10 +- contracts/swap/Cargo.toml | 16 +- contracts/swap/src/contract.rs | 10 +- contracts/swap/src/helpers.rs | 8 +- contracts/swap/src/queries.rs | 21 +- contracts/swap/src/swap.rs | 5 +- .../src/testing/integration_logic_tests.rs | 38 +-- ...egration_realistic_tests_exact_quantity.rs | 2 +- ...ntegration_realistic_tests_min_quantity.rs | 16 +- contracts/swap/src/testing/test_utils.rs | 8 +- 11 files changed, 193 insertions(+), 188 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 95d6869..7517774 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -22,6 +22,12 @@ dependencies = [ "memchr", ] +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -45,7 +51,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", ] [[package]] @@ -83,6 +89,12 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + [[package]] name = "base64ct" version = "1.6.0" @@ -90,14 +102,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] -name = "bigint" -version = "4.4.3" +name = "bech32" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0e8c8a600052b52482eff2cf4d810e462fdff1f656ac1ecb6232132a1ed7def" -dependencies = [ - "byteorder", - "crunchy 0.1.6", -] +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" [[package]] name = "bindgen" @@ -164,6 +172,12 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bnum" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" + [[package]] name = "bs58" version = "0.4.0" @@ -217,17 +231,16 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.24" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" +checksum = "7f2c685bad3eb3d45a01354cedb7d5faa66194d1d58ba6e267a8de788f79db38" dependencies = [ + "android-tzdata", "iana-time-zone", "js-sys", - "num-integer", "num-traits", - "time 0.1.45", "wasm-bindgen", - "winapi", + "windows-targets 0.48.0", ] [[package]] @@ -330,31 +343,32 @@ dependencies = [ [[package]] name = "cosmwasm-crypto" -version = "1.2.5" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75836a10cb9654c54e77ee56da94d592923092a10b369cdb0dbd56acefc16340" +checksum = "ad24bc9dae9aac5dc124b4560e3f7678729d701f1bf3cb11140703d91f247d31" dependencies = [ "digest 0.10.7", + "ecdsa 0.16.7", "ed25519-zebra", - "k256 0.11.6", + "k256 0.13.1", "rand_core 0.6.4", "thiserror", ] [[package]] name = "cosmwasm-derive" -version = "1.2.5" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c9f7f0e51bfc7295f7b2664fe8513c966428642aa765dad8a74acdab5e0c773" +checksum = "ca65635b768406eabdd28ba015cc3f2f863ca5a2677a7dc4c237b8ee1298efb3" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.2.5" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f00b363610218eea83f24bbab09e1a7c3920b79f068334fdfcc62f6129ef9fc" +checksum = "77e2a6ce6dbcad572495fd9d9c1072793fe682aebfcc09752c3b0de3fa1814d7" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -365,9 +379,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.2.5" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae38f909b2822d32b275c9e2db9728497aa33ffe67dd463bc67c6a3b7092785c" +checksum = "904408dc6d73fd1d535c764a55370803cccf6b9be5af7423c4db8967058673f0" dependencies = [ "proc-macro2", "quote", @@ -376,11 +390,13 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.2.5" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a49b85345e811c8e80ec55d0d091e4fcb4f00f97ab058f9be5f614c444a730cb" +checksum = "1ed4564772e5d779235f2d7353e3d66e37793065c3a5155a2978256bf4c5b7d5" dependencies = [ - "base64", + "base64 0.21.7", + "bech32", + "bnum", "cosmwasm-crypto", "cosmwasm-derive", "derivative", @@ -390,15 +406,15 @@ dependencies = [ "serde", "serde-json-wasm", "sha2 0.10.6", + "static_assertions 1.1.0", "thiserror", - "uint 0.9.5", ] [[package]] name = "cosmwasm-storage" -version = "1.2.5" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3737a3aac48f5ed883b5b73bfb731e77feebd8fc6b43419844ec2971072164d" +checksum = "bd2b4ae72a03e8f56c85df59d172d51d2d7dc9cec6e2bc811e3fb60c588032a4" dependencies = [ "cosmwasm-std", "serde", @@ -413,12 +429,6 @@ dependencies = [ "libc", ] -[[package]] -name = "crunchy" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" - [[package]] name = "crunchy" version = "0.2.2" @@ -502,7 +512,7 @@ checksum = "2a18afd2e201221c6d72a57f0886ef2a22151bbc9e6db7af276fde8a91081042" dependencies = [ "anyhow", "cosmwasm-std", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.2.0", "cw-utils 1.0.1", "derivative", "itertools", @@ -526,20 +536,9 @@ dependencies = [ [[package]] name = "cw-storage-plus" -version = "0.15.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6cf70ef7686e2da9ad7b067c5942cd3e88dd9453f7af42f54557f8af300fb0" -dependencies = [ - "cosmwasm-std", - "schemars", - "serde", -] - -[[package]] -name = "cw-storage-plus" -version = "1.0.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "053a5083c258acd68386734f428a5a171b29f7d733151ae83090c6fcc9417ffa" +checksum = "d5ff29294ee99373e2cd5fd21786a3c0ced99a52fec2ca347d565489c61b723c" dependencies = [ "cosmwasm-std", "schemars", @@ -595,7 +594,7 @@ checksum = "8fb70cee2cf0b4a8ff7253e6bc6647107905e8eb37208f87d54f67810faa62f8" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus 1.0.1", + "cw-storage-plus 1.2.0", "schemars", "serde", ] @@ -786,8 +785,8 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3932e82d64d347a045208924002930dc105a138995ccdc1479d0f05f0359f17c" dependencies = [ - "crunchy 0.2.2", - "fixed-hash", + "crunchy", + "fixed-hash 0.3.2", "impl-rlp", "impl-serde", "tiny-keccak", @@ -799,10 +798,10 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b054df51e53f253837ea422681215b42823c02824bde982699d0dceecf6165a1" dependencies = [ - "crunchy 0.2.2", + "crunchy", "ethbloom", "ethereum-types-serialize", - "fixed-hash", + "fixed-hash 0.3.2", "serde", "uint 0.5.0", ] @@ -859,6 +858,15 @@ dependencies = [ "static_assertions 0.2.5", ] +[[package]] +name = "fixed-hash" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "835c052cb0c08c1acf6ffd71c022172e18723949c8282f2b9f27efbc51e64534" +dependencies = [ + "static_assertions 1.1.0", +] + [[package]] name = "flex-error" version = "0.4.4" @@ -952,7 +960,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", ] [[package]] @@ -1005,7 +1013,7 @@ dependencies = [ "cfg-if", "js-sys", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "wasm-bindgen", ] @@ -1071,7 +1079,7 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" dependencies = [ - "base64", + "base64 0.13.1", "bitflags", "bytes", "headers-core", @@ -1330,12 +1338,12 @@ dependencies = [ [[package]] name = "injective-cosmwasm" -version = "0.2.2" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ab3412772e82841ca5cb4a4653137c1691bd7f98efe0e8d36ba9098b5522374" +checksum = "53b6f08b14a23696948d51ba6a050382cbc6e23522efec3ca607a5b1a317de0c" dependencies = [ "cosmwasm-std", - "cw-storage-plus 0.15.1", + "cw-storage-plus 1.2.0", "ethereum-types", "hex", "injective-math", @@ -1343,18 +1351,18 @@ dependencies = [ "serde", "serde_repr", "subtle-encoding", + "tiny-keccak", ] [[package]] name = "injective-math" -version = "0.1.17" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486bf9505a69f7879ba01f740f9a925368fe1c527b4128dacf730c0fd7319057" +checksum = "db4e31ffb7dff274e0be1117bc8f1240f6572d6157be2c4daf13ff82eaaddd85" dependencies = [ - "bigint", "cosmwasm-std", "ethereum-types", - "num", + "primitive-types", "schemars", "serde", "subtle-encoding", @@ -1362,10 +1370,10 @@ dependencies = [ [[package]] name = "injective-protobuf" -version = "0.1.0" -source = "git+https://github.com/InjectiveLabs/cw-injective?branch=dev#697cb42055d87520bb24dcb17e71e1832c9e964e" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a52219a08aba8c17846fd23d472d1d69c817fe5b427d135273e4c7311edd6972" dependencies = [ - "bigint", "cosmwasm-std", "ethereum-types", "num", @@ -1378,9 +1386,9 @@ dependencies = [ [[package]] name = "injective-std" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7847ae6a9e2aa72d6f8919bbc31a56e62f38ebd852ce8e0530bf24865daa4af1" +checksum = "cd7a5b52d19dca05823c7e4b481d41b49c04a0e56f66a5c92396a6fdd3314710" dependencies = [ "chrono", "cosmwasm-std", @@ -1394,10 +1402,10 @@ dependencies = [ [[package]] name = "injective-test-tube" -version = "1.1.3" -source = "git+https://github.com/InjectiveLabs/test-tube.git?tag=v1.1.3#b13c34c5d2ea35222eaafdd7496aefe21e1940f5" +version = "1.1.7" +source = "git+https://github.com/InjectiveLabs/test-tube?branch=dev#39056574d937a8a6a4f28a148034cb252f1a4bfc" dependencies = [ - "base64", + "base64 0.13.1", "bindgen", "cosmrs", "cosmwasm-std", @@ -1524,7 +1532,7 @@ checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" dependencies = [ "libc", "log", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", "windows-sys 0.45.0", ] @@ -1743,7 +1751,7 @@ checksum = "39407670928234ebc5e6e580247dd567ad73a3578460c5990f9503df207e8f07" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", ] [[package]] @@ -1778,11 +1786,21 @@ dependencies = [ "spki 0.7.2", ] +[[package]] +name = "primitive-types" +version = "0.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b34d9fd68ae0b74a41b21c03c2f62847aa0ffea044eee893b4c140b37e244e2" +dependencies = [ + "fixed-hash 0.8.0", + "uint 0.9.5", +] + [[package]] name = "proc-macro2" -version = "1.0.59" +version = "1.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +checksum = "95fc56cda0b5c3325f5fbbd7ff9fda9e02bb00bb3dac51252d2f1bfa1cb8cc8c" dependencies = [ "unicode-ident", ] @@ -1872,9 +1890,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.28" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -2011,7 +2029,7 @@ version = "0.19.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" dependencies = [ - "base64", + "base64 0.13.1", "log", "ring", "sct", @@ -2056,9 +2074,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.12" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" dependencies = [ "dyn-clone", "schemars_derive", @@ -2068,9 +2086,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.12" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" dependencies = [ "proc-macro2", "quote", @@ -2147,9 +2165,9 @@ checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" [[package]] name = "serde" -version = "1.0.163" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" dependencies = [ "serde_derive", ] @@ -2183,13 +2201,13 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.163" +version = "1.0.195" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", ] [[package]] @@ -2216,13 +2234,13 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.12" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" +checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", ] [[package]] @@ -2383,9 +2401,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.17" +version = "2.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45b6ddbb36c5b969c182aec3c4a0bce7df3fbad4b77114706a49aacc80567388" +checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f" dependencies = [ "proc-macro2", "quote", @@ -2419,7 +2437,7 @@ dependencies = [ "subtle", "subtle-encoding", "tendermint-proto", - "time 0.3.21", + "time", "zeroize", ] @@ -2452,7 +2470,7 @@ dependencies = [ "serde", "serde_bytes", "subtle-encoding", - "time 0.3.21", + "time", ] [[package]] @@ -2482,7 +2500,7 @@ dependencies = [ "tendermint-config", "tendermint-proto", "thiserror", - "time 0.3.21", + "time", "tokio", "tracing", "url", @@ -2501,11 +2519,11 @@ dependencies = [ [[package]] name = "test-tube-inj" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fb998103b46e5dfe482afb296538d4b0fd21bc7372bf864e49ac8b921eb1798" +checksum = "ae2aa4f0386a041eea657c0d0b4438f1d757a231d0736c1b3413b9c84cfa36db" dependencies = [ - "base64", + "base64 0.13.1", "cosmrs", "cosmwasm-std", "prost 0.11.9", @@ -2538,18 +2556,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", -] - -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", + "syn 2.0.48", ] [[package]] @@ -2584,7 +2591,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d8a021c69bb74a44ccedb824a046447e2c84a01df9e5c20779750acb38e11b2" dependencies = [ - "crunchy 0.2.2", + "crunchy", ] [[package]] @@ -2627,7 +2634,7 @@ checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", ] [[package]] @@ -2709,7 +2716,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "082df6964410f6aa929a61ddfafc997e4f32c62c22490e439ac351cec827f436" dependencies = [ "byteorder", - "crunchy 0.2.2", + "crunchy", "heapsize", "rustc-hex", ] @@ -2721,7 +2728,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" dependencies = [ "byteorder", - "crunchy 0.2.2", + "crunchy", "hex", "static_assertions 1.1.0", ] @@ -2796,12 +2803,6 @@ dependencies = [ "try-lock", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -2829,7 +2830,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", "wasm-bindgen-shared", ] @@ -2851,7 +2852,7 @@ checksum = "e128beba882dd1eb6200e1dc92ae6c5dbaa4311aa7bb211ca035779e5efc39f8" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3106,5 +3107,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn 2.0.17", + "syn 2.0.48", ] diff --git a/build_release.sh b/build_release.sh index d127cf0..6d3a3dc 100755 --- a/build_release.sh +++ b/build_release.sh @@ -5,7 +5,9 @@ if [[ $(arch) = "arm64" ]]; then ARCH=-arm64 fi -docker run --rm -v "$(pwd)":/code -v "$HOME/.cargo/git":/usr/local/cargo/git \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/workspace-optimizer${ARCH}:0.12.13 +for contract_dir in contracts/*; do + docker run --rm -v "$(pwd)":/code -v "$HOME/.cargo/git":/usr/local/cargo/git \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/workspace-optimizer${ARCH}:0.15.0 "$contract_dir" +done \ No newline at end of file diff --git a/contracts/swap/Cargo.toml b/contracts/swap/Cargo.toml index 0339c0f..b1a898c 100644 --- a/contracts/swap/Cargo.toml +++ b/contracts/swap/Cargo.toml @@ -29,14 +29,14 @@ optimize = """docker run --rm -v "$(pwd)":/code \ """ [dependencies] -cosmwasm-std = "1.0.0" -cosmwasm-storage = "1.0.0" +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.2" } -injective-math = { version = "0.1.17" } -injective-protobuf = { version = "0.1", git = "https://github.com/InjectiveLabs/cw-injective", branch = "dev" } +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" @@ -45,8 +45,8 @@ serde-json-wasm = "0.5.1" thiserror = { version = "1.0.31" } [dev-dependencies] -cosmwasm-schema = "1.0.0" +cosmwasm-schema = "1.5.0" cw-multi-test = "0.16.2" -injective-std = { version = "0.1.3" } -injective-test-tube = { version = "1.1.3", git = "https://github.com/InjectiveLabs/test-tube.git", tag = "v1.1.3" } +injective-std = { version = "0.1.5" } +injective-test-tube = { git = "https://github.com/InjectiveLabs/test-tube", branch = "dev" } prost = "0.11.9" diff --git a/contracts/swap/src/contract.rs b/contracts/swap/src/contract.rs index c9a9789..4f9ad67 100644 --- a/contracts/swap/src/contract.rs +++ b/contracts/swap/src/contract.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, + to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, }; use cw2::set_contract_version; @@ -104,7 +104,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdR QueryMsg::GetRoute { source_denom, target_denom, - } => Ok(to_binary(&read_swap_route( + } => Ok(to_json_binary(&read_swap_route( deps.storage, &source_denom, &target_denom, @@ -121,7 +121,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdR target_denom, SwapQuantity::InputQuantity(from_quantity), )?; - Ok(to_binary(&target_quantity)?) + Ok(to_json_binary(&target_quantity)?) } QueryMsg::GetInputQuantity { to_quantity, @@ -135,11 +135,11 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdR target_denom, SwapQuantity::OutputQuantity(to_quantity), )?; - Ok(to_binary(&target_quantity)?) + Ok(to_json_binary(&target_quantity)?) } QueryMsg::GetAllRoutes {} => { let routes = get_all_swap_routes(deps.storage)?; - Ok(to_binary(&routes)?) + Ok(to_json_binary(&routes)?) } } } diff --git a/contracts/swap/src/helpers.rs b/contracts/swap/src/helpers.rs index e4f765b..c0c7f36 100644 --- a/contracts/swap/src/helpers.rs +++ b/contracts/swap/src/helpers.rs @@ -2,7 +2,6 @@ use cosmwasm_std::{CosmosMsg, SubMsg}; use injective_cosmwasm::InjectiveMsgWrapper; use injective_math::FPDecimal; -use num_traits::pow::Pow; pub fn i32_to_dec(source: i32) -> FPDecimal { FPDecimal::from(i128::from(source)) @@ -39,12 +38,15 @@ pub trait Scaled { impl Scaled for FPDecimal { fn scaled(self, digits: i32) -> Self { - self.to_owned() * FPDecimal::from(10i128).pow(FPDecimal::from(digits as i128)) + self.to_owned() + * FPDecimal::from(10i128) + .pow(FPDecimal::from(digits as i128)) + .unwrap() } } pub fn dec_scale_factor() -> FPDecimal { - FPDecimal::one().scaled(18) + FPDecimal::ONE.scaled(18) // FPDecimal::from(1000000000000000000_i128) } diff --git a/contracts/swap/src/queries.rs b/contracts/swap/src/queries.rs index 98d41a3..1a2873f 100644 --- a/contracts/swap/src/queries.rs +++ b/contracts/swap/src/queries.rs @@ -127,7 +127,7 @@ pub fn estimate_single_swap_execution( let fee_percent = market.taker_fee_rate * fee_multiplier - * (FPDecimal::one() - get_effective_fee_discount_rate(&market, is_self_relayer)); + * (FPDecimal::ONE - get_effective_fee_discount_rate(&market, is_self_relayer)); let is_estimating_from_target = matches!( swap_estimation_amount, @@ -164,7 +164,7 @@ fn estimate_execution_buy_from_source( fee_percent: FPDecimal, is_simulation: bool, ) -> StdResult { - let available_swap_quote_funds = input_quote_quantity / (FPDecimal::one() + fee_percent); + let available_swap_quote_funds = input_quote_quantity / (FPDecimal::ONE + fee_percent); let orders = querier.query_spot_market_orderbook( &market.market_id, @@ -190,7 +190,7 @@ fn estimate_execution_buy_from_source( let fee_estimate = input_quote_quantity - available_swap_quote_funds; // check if user funds + contract funds are enough to create order - let required_funds = worst_price * expected_base_quantity * (FPDecimal::one() + fee_percent); + let required_funds = worst_price * expected_base_quantity * (FPDecimal::ONE + fee_percent); let funds_in_contract = deps .querier .query_balance(contract_address, &market.quote_denom) @@ -260,8 +260,7 @@ fn estimate_execution_buy_from_target( let required_input_quote_quantity = expected_exchange_quote_quantity + fee_estimate; // check if user funds + contract funds are enough to create order - let required_funds = - worst_price * target_base_output_quantity * (FPDecimal::one() + fee_percent); + let required_funds = worst_price * target_base_output_quantity * (FPDecimal::ONE + fee_percent); let funds_in_contract = deps .querier @@ -386,7 +385,7 @@ fn estimate_execution_sell_from_target( fee_percent: FPDecimal, ) -> StdResult { let required_swap_quantity_in_quote = - target_quote_output_quantity / (FPDecimal::one() - fee_percent); + target_quote_output_quantity / (FPDecimal::ONE - fee_percent); let required_fee = required_swap_quantity_in_quote - target_quote_output_quantity; let orders = querier.query_spot_market_orderbook( @@ -456,14 +455,14 @@ pub fn get_minimum_liquidity_levels( calc: fn(&PriceLevel) -> FPDecimal, min_quantity_tick_size: FPDecimal, ) -> StdResult> { - let mut sum = FPDecimal::zero(); + let mut sum = FPDecimal::ZERO; let mut orders: Vec = Vec::new(); for level in levels { let value = calc(level); assert_ne!( value, - FPDecimal::zero(), + FPDecimal::ZERO, "Price level with zero value, this should not happen" ); @@ -506,13 +505,13 @@ fn get_average_price_from_orders( ) -> FPDecimal { let (total_quantity, total_notional) = levels .iter() - .fold((FPDecimal::zero(), FPDecimal::zero()), |acc, pl| { + .fold((FPDecimal::ZERO, FPDecimal::ZERO), |acc, pl| { (acc.0 + pl.q, acc.1 + pl.p * pl.q) }); assert_ne!( total_quantity, - FPDecimal::zero(), + FPDecimal::ZERO, "total_quantity was zero and would result in division by zero" ); let average_price = total_notional / total_quantity; @@ -530,7 +529,7 @@ fn get_worst_price_from_orders(levels: &[PriceLevel]) -> FPDecimal { fn get_effective_fee_discount_rate(market: &SpotMarket, is_self_relayer: bool) -> FPDecimal { if !is_self_relayer { - FPDecimal::zero() + FPDecimal::ZERO } else { market.relayer_fee_share_rate } diff --git a/contracts/swap/src/swap.rs b/contracts/swap/src/swap.rs index e172922..7c3f2b3 100644 --- a/contracts/swap/src/swap.rs +++ b/contracts/swap/src/swap.rs @@ -80,7 +80,7 @@ pub fn start_swap_flow( let is_input_quote = first_market.quote_denom == *source_denom; let required_input = if is_input_quote { - estimation.result_quantity.int() + FPDecimal::one() + estimation.result_quantity.int() + FPDecimal::ONE } else { round_up_to_min_tick( estimation.result_quantity, @@ -104,7 +104,7 @@ pub fn start_swap_flow( FPDecimal::from(coin_provided.amount) - estimation.result_quantity } else { - FPDecimal::zero() + FPDecimal::ZERO }; let swap_operation = CurrentSwapOperation { @@ -157,6 +157,7 @@ pub fn execute_swap_step( &market_id, subaccount_id, Some(fee_recipient.to_owned()), + None, ); let order_message = SubMsg::reply_on_success( diff --git a/contracts/swap/src/testing/integration_logic_tests.rs b/contracts/swap/src/testing/integration_logic_tests.rs index 40809d6..d4f00a1 100644 --- a/contracts/swap/src/testing/integration_logic_tests.rs +++ b/contracts/swap/src/testing/integration_logic_tests.rs @@ -130,7 +130,7 @@ fn it_executes_a_swap_between_two_base_assets_with_multiple_price_levels() { let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); assert_eq!( @@ -271,7 +271,7 @@ fn it_executes_a_swap_between_two_base_assets_with_single_price_level() { let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); assert_eq!( @@ -413,7 +413,7 @@ fn it_executes_swap_between_markets_using_different_quote_assets() { let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); assert_eq!( @@ -548,7 +548,7 @@ fn it_reverts_swap_between_markets_using_different_quote_asset_if_one_quote_buff ); assert_eq!( target_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance should not have changed after failed swap" ); @@ -619,7 +619,7 @@ fn it_executes_a_sell_of_base_asset_to_receive_min_output_quantity() { + 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::ONE - FPDecimal::must_from_str(&format!( "{}", DEFAULT_TAKER_FEE * DEFAULT_ATOMIC_MULTIPLIER * DEFAULT_SELF_RELAYING_FEE_PART @@ -665,7 +665,7 @@ fn it_executes_a_sell_of_base_asset_to_receive_min_output_quantity() { assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); assert_eq!( @@ -753,7 +753,7 @@ fn it_executes_a_buy_of_base_asset_to_receive_min_output_quantity() { // calculate how much ETH we can buy with USDT we have let available_usdt_after_fee = FPDecimal::from(swapper_usdt) - / (FPDecimal::one() + / (FPDecimal::ONE + FPDecimal::must_from_str(&format!( "{}", DEFAULT_TAKER_FEE * DEFAULT_ATOMIC_MULTIPLIER * DEFAULT_SELF_RELAYING_FEE_PART @@ -826,7 +826,7 @@ fn it_executes_a_buy_of_base_asset_to_receive_min_output_quantity() { assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); assert_eq!( @@ -979,7 +979,7 @@ fn it_executes_a_swap_between_base_assets_with_external_fee_recipient() { assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); assert_eq!( @@ -1134,7 +1134,7 @@ fn it_reverts_the_swap_if_there_isnt_enough_buffer_for_buying_target_asset() { ); assert_eq!( to_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance changes after failed swap" ); @@ -1219,7 +1219,7 @@ fn it_reverts_swap_if_no_funds_were_passed() { ); assert_eq!( to_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance changes after failed swap" ); @@ -1394,7 +1394,7 @@ fn it_reverts_if_user_passes_quantities_equal_to_zero() { &contr_addr, &ExecuteMsg::SwapMinOutput { target_denom: ATOM.to_string(), - min_output_quantity: FPDecimal::zero(), + min_output_quantity: FPDecimal::ZERO, }, &[coin(12, ETH)], &swapper, @@ -1500,7 +1500,7 @@ fn it_reverts_if_user_passes_negative_quantities() { ); assert_eq!( to_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance changed after failed swap" ); @@ -1610,7 +1610,7 @@ fn it_reverts_if_there_arent_enough_orders_to_satisfy_min_quantity() { ); assert_eq!( to_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance changed after failed swap" ); @@ -1701,7 +1701,7 @@ fn it_reverts_if_min_quantity_cannot_be_reached() { ); assert_eq!( to_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance changed after failed swap" ); @@ -1806,7 +1806,7 @@ fn it_reverts_if_market_is_paused() { ); assert_eq!( to_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance changed after failed swap" ); @@ -1909,7 +1909,7 @@ fn it_reverts_if_user_doesnt_have_enough_inj_to_pay_for_gas() { ); assert_eq!( to_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance changed after failed swap" ); @@ -2105,14 +2105,14 @@ fn it_doesnt_allow_non_admin_to_withdraw_anything_from_contract() { let random_dude_eth_balance = query_bank_balance(&bank, ETH, random_dude.address().as_str()); assert_eq!( random_dude_eth_balance, - FPDecimal::zero(), + 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(), + FPDecimal::ZERO, "random dude has some usdt balance after failed withdraw" ); } diff --git a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs index c4ecab5..53e129f 100644 --- a/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs +++ b/contracts/swap/src/testing/integration_realistic_tests_exact_quantity.rs @@ -1148,7 +1148,7 @@ fn it_reverts_when_funds_provided_are_below_required_to_get_exact_amount() { ); assert_eq!( - FPDecimal::zero(), + FPDecimal::ZERO, swapper_atom_balance_after, "swapper received some ATOM" ); diff --git a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs index dafd01f..ed4d64a 100644 --- a/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs +++ b/contracts/swap/src/testing/integration_realistic_tests_min_quantity.rs @@ -167,7 +167,7 @@ fn happy_path_two_hops_swap_eth_atom_realistic_values_self_relaying() { assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); @@ -359,7 +359,7 @@ fn happy_path_two_hops_swap_inj_eth_realistic_values_self_relaying() { assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); @@ -552,7 +552,7 @@ fn happy_path_two_hops_swap_inj_atom_realistic_values_self_relaying() { assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); @@ -740,7 +740,7 @@ fn it_executes_swap_between_markets_using_different_quote_assets_self_relaying() assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); @@ -1089,7 +1089,7 @@ fn it_correctly_calculates_required_funds_when_querying_buy_with_minimum_buffer_ let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); assert_eq!( @@ -1124,7 +1124,7 @@ fn it_correctly_calculates_required_funds_when_querying_buy_with_minimum_buffer_ // 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(), + human_to_dec("0.0001", Decimals::Six) - contract_balance_diff > FPDecimal::ZERO, "contract balance has changed too much after swap" ); } @@ -1234,7 +1234,7 @@ fn it_correctly_calculates_required_funds_when_executing_buy_with_minimum_buffer let to_balance = query_bank_balance(&bank, ATOM, swapper.address().as_str()); assert_eq!( from_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "some of the original amount wasn't swapped" ); assert_eq!( @@ -1399,7 +1399,7 @@ fn it_returns_all_funds_if_there_is_not_enough_buffer_realistic_values() { ); assert_eq!( to_balance, - FPDecimal::zero(), + FPDecimal::ZERO, "target balance changed after failed swap" ); diff --git a/contracts/swap/src/testing/test_utils.rs b/contracts/swap/src/testing/test_utils.rs index ad08882..6c1aac2 100644 --- a/contracts/swap/src/testing/test_utils.rs +++ b/contracts/swap/src/testing/test_utils.rs @@ -3,7 +3,7 @@ use std::str::FromStr; use cosmwasm_std::testing::{MockApi, MockStorage}; use cosmwasm_std::{ - coin, to_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, + coin, to_json_binary, Addr, Coin, ContractResult, OwnedDeps, QuerierResult, SystemError, SystemResult, }; use injective_std::shim::Any; @@ -170,7 +170,7 @@ pub fn mock_deps_eth_inj( let response = QueryMarketAtomicExecutionFeeMultiplierResponse { multiplier: FPDecimal::from_str("2.5").unwrap(), }; - SystemResult::Ok(ContractResult::from(to_binary(&response))) + SystemResult::Ok(ContractResult::from(to_json_binary(&response))) } } @@ -272,7 +272,7 @@ pub fn mock_realistic_deps_eth_atom( let response = QueryMarketAtomicExecutionFeeMultiplierResponse { multiplier: FPDecimal::from_str("2.5").unwrap(), }; - SystemResult::Ok(ContractResult::from(to_binary(&response))) + SystemResult::Ok(ContractResult::from(to_json_binary(&response))) } } @@ -299,7 +299,7 @@ fn create_mock_spot_market( taker_fee_rate: FPDecimal::from_str("0.001").unwrap(), relayer_fee_share_rate: FPDecimal::from_str("0.4").unwrap(), market_id: test_market_ids()[idx as usize].clone(), - status: 1, + status: injective_cosmwasm::MarketStatus::Active, min_price_tick_size, min_quantity_tick_size, }