From 1e759d295170de45b93e296b84364d964ebc8dc8 Mon Sep 17 00:00:00 2001 From: Timofey <5527315+epanchee@users.noreply.github.com> Date: Fri, 5 Jan 2024 12:18:09 +0400 Subject: [PATCH] fix(PCL for Osmosis): address issues found by Oak audit (#5) * fix double refund on excess offer assets * ensure token_in_denom belongs to pair in swap_exact_amount_out * don't update price on small trade sizes in swap_exact_amount_out * pass msg.whitelist_code_id to config on factory instantiation * factory: emit events on update config fields * general refactoring * add before_swap_check validation in reverse swap and swap_exact_amount_out * bump Rust version used in CI * bump Rust version used in CI --- .github/workflows/check_artifacts.yml | 2 +- .github/workflows/code_coverage.yml | 2 +- .github/workflows/tests_and_checks.yml | 2 +- Cargo.lock | 658 +++++++----------- Cargo.toml | 2 +- contracts/factory/src/contract.rs | 15 +- contracts/factory/src/error.rs | 3 - contracts/factory/tests/unit_tests.rs | 6 +- contracts/pair_concentrated/src/contract.rs | 19 +- contracts/pair_concentrated/src/queries.rs | 7 +- contracts/pair_concentrated/src/sudo.rs | 89 +-- .../tests/common/osmosis_ext.rs | 44 +- e2e_tests/Cargo.toml | 4 +- e2e_tests/src/helper.rs | 10 +- e2e_tests/tests/e2e_testing.rs | 55 +- 15 files changed, 433 insertions(+), 485 deletions(-) diff --git a/.github/workflows/check_artifacts.yml b/.github/workflows/check_artifacts.yml index 7b77979..bf7d734 100644 --- a/.github/workflows/check_artifacts.yml +++ b/.github/workflows/check_artifacts.yml @@ -49,7 +49,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.68.0 + toolchain: 1.75.0 override: true - name: Fetch cargo deps diff --git a/.github/workflows/code_coverage.yml b/.github/workflows/code_coverage.yml index d628678..0967185 100644 --- a/.github/workflows/code_coverage.yml +++ b/.github/workflows/code_coverage.yml @@ -39,7 +39,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.68.0 + toolchain: 1.75.0 override: true - name: Run cargo-tarpaulin diff --git a/.github/workflows/tests_and_checks.yml b/.github/workflows/tests_and_checks.yml index 2ad0605..4f719e3 100644 --- a/.github/workflows/tests_and_checks.yml +++ b/.github/workflows/tests_and_checks.yml @@ -50,7 +50,7 @@ jobs: uses: actions-rs/toolchain@v1 with: profile: minimal - toolchain: 1.68.0 + toolchain: 1.75.0 override: true target: wasm32-unknown-unknown components: rustfmt, clippy, llvm-tools-preview diff --git a/Cargo.lock b/Cargo.lock index 022731d..144c230 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -231,24 +231,12 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "base16ct" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" - [[package]] name = "base16ct" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" -[[package]] -name = "base64" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" - [[package]] name = "base64" version = "0.21.5" @@ -269,9 +257,9 @@ checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" [[package]] name = "bindgen" -version = "0.68.1" +version = "0.69.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "726e4313eb6ec35d2730258ad4e15b547ee75d6afaa1361a922e78e59b7d8078" +checksum = "9ffcebc3849946a7170a05992aac39da343a90676ab392c51a4280981d6379c2" dependencies = [ "bitflags 2.4.1", "cexpr", @@ -292,15 +280,13 @@ dependencies = [ [[package]] name = "bip32" -version = "0.4.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b30ed1d6f8437a487a266c8293aeb95b61a23261273e3e02912cdb8b68bf798b" +checksum = "7e141fb0f8be1c7b45887af94c88b182472b57c96b56773250ae00cd6a14a164" dependencies = [ "bs58", "hmac", - "k256 0.11.6", - "once_cell", - "pbkdf2", + "k256", "rand_core 0.6.4", "ripemd", "sha2 0.10.8", @@ -346,11 +332,11 @@ checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" [[package]] name = "bs58" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" +checksum = "f5353f36341f7451062466f0b755b96ac3a9547e4d7f6b70d603fc721a7d7896" dependencies = [ - "sha2 0.9.9", + "sha2 0.10.8", ] [[package]] @@ -370,6 +356,9 @@ name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +dependencies = [ + "serde", +] [[package]] name = "cc" @@ -439,30 +428,30 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cosmos-sdk-proto" -version = "0.14.0" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20b42021d8488665b1a0d9748f1f81df7235362d194f44481e2e61bf376b77b4" +checksum = "32560304ab4c365791fd307282f76637213d8083c1a98490c35159cd67852237" dependencies = [ - "prost 0.11.9", - "prost-types", + "prost 0.12.3", + "prost-types 0.12.3", "tendermint-proto", ] [[package]] name = "cosmrs" -version = "0.9.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3903590099dcf1ea580d9353034c9ba1dbf55d1389a5bd2ade98535c3445d1f9" +checksum = "47126f5364df9387b9d8559dcef62e99010e1d4098f39eb3f7ee4b5c254e40ea" dependencies = [ "bip32", "cosmos-sdk-proto", - "ecdsa 0.14.8", + "ecdsa", "eyre", - "getrandom", - "k256 0.11.6", + "k256", "rand_core 0.6.4", "serde", "serde_json", + "signature", "subtle-encoding", "tendermint", "tendermint-rpc", @@ -476,9 +465,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8bb3c77c3b7ce472056968c745eb501c440fbc07be5004eba02782c35bfbbe3" dependencies = [ "digest 0.10.7", - "ecdsa 0.16.9", + "ecdsa", "ed25519-zebra", - "k256 0.13.2", + "k256", "rand_core 0.6.4", "thiserror", ] @@ -522,7 +511,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04d6864742e3a7662d024b51a94ea81c9af21db6faea2f9a6d2232bb97c6e53e" dependencies = [ - "base64 0.21.5", + "base64", "bech32", "bnum", "cosmwasm-crypto", @@ -563,18 +552,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-bigint" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" -dependencies = [ - "generic-array", - "rand_core 0.6.4", - "subtle", - "zeroize", -] - [[package]] name = "crypto-bigint" version = "0.5.5" @@ -597,15 +574,6 @@ dependencies = [ "typenum", ] -[[package]] -name = "ct-logs" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1a816186fa68d9e426e3cb4ae4dff1fcd8e4a2c34b781bf7a822574a0d0aac8" -dependencies = [ - "sct", -] - [[package]] name = "curve25519-dalek" version = "3.2.0" @@ -619,6 +587,19 @@ dependencies = [ "zeroize", ] +[[package]] +name = "curve25519-dalek-ng" +version = "4.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c359b7249347e46fb28804470d071c921156ad62b3eef5d34e2ba867533dec8" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.6.4", + "subtle-ng", + "zeroize", +] + [[package]] name = "cw-multi-test" version = "0.19.0" @@ -776,16 +757,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "der" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "der" version = "0.7.8" @@ -834,49 +805,39 @@ version = "1.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "545b22097d44f8a9581187cdf93de7a71e4722bf51200cfaba810865b49a495d" -[[package]] -name = "ecdsa" -version = "0.14.8" -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", -] - [[package]] name = "ecdsa" version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ - "der 0.7.8", + "der", "digest 0.10.7", - "elliptic-curve 0.13.8", - "rfc6979 0.4.0", - "signature 2.2.0", - "spki 0.7.3", + "elliptic-curve", + "rfc6979", + "signature", + "spki", ] [[package]] name = "ed25519" -version = "1.5.3" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ - "signature 1.6.4", + "pkcs8", + "signature", ] [[package]] -name = "ed25519-dalek" -version = "1.0.1" +name = "ed25519-consensus" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +checksum = "3c8465edc8ee7436ffea81d21a019b16676ee3db267aa8d5a8d729581ecf998b" dependencies = [ - "curve25519-dalek", - "ed25519", + "curve25519-dalek-ng", + "hex", + "rand_core 0.6.4", "sha2 0.9.9", "zeroize", ] @@ -904,41 +865,30 @@ checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" [[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.8" +name = "encoding_rs" +version = "0.8.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" +checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" dependencies = [ - "base16ct 0.2.0", - "crypto-bigint 0.5.5", - "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.3", - "subtle", - "zeroize", + "cfg-if", ] [[package]] @@ -967,16 +917,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "ff" version = "0.13.0" @@ -1026,7 +966,6 @@ checksum = "da0290714b38af9b4a7b094b8a37086d1b4e61f2df9122c3cad2577669145335" dependencies = [ "futures-channel", "futures-core", - "futures-executor", "futures-io", "futures-sink", "futures-task", @@ -1049,34 +988,12 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eb1d22c66e66d9d72e1758f0bd7d4fd0bee04cad842ee34587d68c07e45d088c" -[[package]] -name = "futures-executor" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f4fb8693db0cf099eadcca0efe2a5a22e4550f98ed16aba6c48700da29597bc" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - [[package]] name = "futures-io" version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8bf34a163b5c4c52d0478a4d757da8fb65cabef42ba90515efee0f6f9fa45aaa" -[[package]] -name = "futures-macro" -version = "0.3.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53b153fd91e4b0147f4aced87be237c98248656bb01050b96bf3ee89220a8ddb" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.40", -] - [[package]] name = "futures-sink" version = "0.3.29" @@ -1095,16 +1012,11 @@ version = "0.3.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a19526d624e703a3179b3d322efec918b6246ea0fa51d41124525f00f1cc8104" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", - "slab", ] [[package]] @@ -1143,24 +1055,13 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "group" 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", ] @@ -1199,30 +1100,6 @@ version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" -[[package]] -name = "headers" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06683b93020a07e3dbcf5f8c0f6d40080d725bea7936fc01ad345c01b97dc270" -dependencies = [ - "base64 0.21.5", - "bytes", - "headers-core", - "http", - "httpdate", - "mime", - "sha1", -] - -[[package]] -name = "headers-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" -dependencies = [ - "http", -] - [[package]] name = "hermit-abi" version = "0.3.3" @@ -1311,41 +1188,18 @@ 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]] @@ -1374,6 +1228,12 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "itertools" version = "0.10.5" @@ -1416,19 +1276,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "k256" -version = "0.11.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" -dependencies = [ - "cfg-if", - "ecdsa 0.14.8", - "elliptic-curve 0.12.3", - "sha2 0.10.8", - "sha3", -] - [[package]] name = "k256" version = "0.13.2" @@ -1436,20 +1283,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f01b677d82ef7a676aa37e099defd83a28e15687112cafdd112d60236b6115b" dependencies = [ "cfg-if", - "ecdsa 0.16.9", - "elliptic-curve 0.13.8", + "ecdsa", + "elliptic-curve", "once_cell", "sha2 0.10.8", - "signature 2.2.0", -] - -[[package]] -name = "keccak" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f6d5ed8676d904364de097082f4e7d240b571b67989ced0240f08b7f966f940" -dependencies = [ - "cpufeatures", + "signature", ] [[package]] @@ -1608,15 +1446,15 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "osmosis-std" -version = "0.20.1" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47d7aa053bc3fad557ac90a0377688b400c395e2537f0f1de3293a15cad2e970" +checksum = "e87adf61f03306474ce79ab322d52dfff6b0bcf3aed1e12d8864ac0400dec1bf" dependencies = [ "chrono", "cosmwasm-std", "osmosis-std-derive", - "prost 0.11.9", - "prost-types", + "prost 0.12.3", + "prost-types 0.12.3", "schemars", "serde", "serde-cw-value", @@ -1630,23 +1468,23 @@ checksum = "c5ebdfd1bc8ed04db596e110c6baa9b174b04f6ed1ec22c666ddc5cb3fa91bd7" dependencies = [ "itertools 0.10.5", "proc-macro2", - "prost-types", + "prost-types 0.11.9", "quote", "syn 1.0.109", ] [[package]] name = "osmosis-test-tube" -version = "20.1.2" +version = "21.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c1534a419d9e2c27b0b4869e68496b92abca93464b82efbdd1f1b43467f2938" +checksum = "c3a528c942d25d3159634f77953ca0e16c5a450fc44578ad922320128e4025fd" dependencies = [ - "base64 0.21.5", + "base64", "bindgen", "cosmrs", "cosmwasm-std", "osmosis-std", - "prost 0.11.9", + "prost 0.12.3", "serde", "serde_json", "test-tube", @@ -1659,15 +1497,6 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" -[[package]] -name = "pbkdf2" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83a0692ec44e4cf1ef28ca317f14f8f07da2d95ec3fa01f86e4467b725e60917" -dependencies = [ - "digest 0.10.7", -] - [[package]] name = "peeking_take_while" version = "0.1.2" @@ -1739,24 +1568,14 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" -[[package]] -name = "pkcs8" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" -dependencies = [ - "der 0.6.1", - "spki 0.6.0", -] - [[package]] name = "pkcs8" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der 0.7.8", - "spki 0.7.3", + "der", + "spki", ] [[package]] @@ -1833,6 +1652,15 @@ dependencies = [ "prost 0.11.9", ] +[[package]] +name = "prost-types" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "193898f59edcf43c26227dcd4c8427f00d99d61e95dcde58dabd49fa291d470e" +dependencies = [ + "prost 0.12.3", +] + [[package]] name = "protobuf" version = "2.28.0" @@ -1896,14 +1724,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" [[package]] -name = "rfc6979" -version = "0.3.1" +name = "reqwest" +version = "0.11.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +checksum = "37b1ae8d9ac08420c66222fb9096fc5de435c3c48542bc5336c51892cffafb41" dependencies = [ - "crypto-bigint 0.4.9", - "hmac", - "zeroize", + "base64", + "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", + "system-configuration", + "tokio", + "tokio-rustls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", ] [[package]] @@ -1918,17 +1775,16 @@ dependencies = [ [[package]] name = "ring" -version = "0.16.20" +version = "0.17.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3053cf52e236a3ed746dfc745aa9cacf1b791d846bdaf412f60a8d7d6e17c8fc" +checksum = "688c63d65483050968b2a8937f7995f443e27041a0f7700aa59b0822aedebb74" dependencies = [ "cc", + "getrandom", "libc", - "once_cell", "spin", "untrusted", - "web-sys", - "winapi", + "windows-sys 0.48.0", ] [[package]] @@ -1940,17 +1796,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "ripemd160" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2eca4ecc81b7f313189bf73ce724400a07da2a6dac19588b03c8bd76a2dcc251" -dependencies = [ - "block-buffer 0.9.0", - "digest 0.9.0", - "opaque-debug", -] - [[package]] name = "rustc-demangle" version = "0.1.23" @@ -1978,29 +1823,47 @@ dependencies = [ [[package]] name = "rustls" -version = "0.19.1" +version = "0.21.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35edb675feee39aec9c99fa5ff985081995a06d594114ae14cbe797ad7b7a6d7" +checksum = "f9d5a6813c0759e4609cd494e8e725babae6a2ca7b62a5536a13daaec6fcb7ba" 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", +] + +[[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.16" @@ -2051,38 +1914,24 @@ dependencies = [ [[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", ] -[[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.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ - "base16ct 0.2.0", - "der 0.7.8", + "base16ct", + "der", "generic-array", - "pkcs8 0.10.2", + "pkcs8", "subtle", "zeroize", ] @@ -2197,14 +2046,15 @@ dependencies = [ ] [[package]] -name = "sha1" -version = "0.10.6" +name = "serde_urlencoded" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ - "cfg-if", - "cpufeatures", - "digest 0.10.7", + "form_urlencoded", + "itoa", + "ryu", + "serde", ] [[package]] @@ -2231,32 +2081,12 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "sha3" -version = "0.10.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75872d278a8f37ef87fa0ddbda7802605cb18344497949862c0d4dcb291eba60" -dependencies = [ - "digest 0.10.7", - "keccak", -] - [[package]] name = "shlex" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" -[[package]] -name = "signature" -version = "1.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" -dependencies = [ - "digest 0.10.7", - "rand_core 0.6.4", -] - [[package]] name = "signature" version = "2.2.0" @@ -2298,19 +2128,9 @@ dependencies = [ [[package]] name = "spin" -version = "0.5.2" +version = "0.9.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "spki" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" -dependencies = [ - "base64ct", - "der 0.6.1", -] +checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "spki" @@ -2319,7 +2139,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" dependencies = [ "base64ct", - "der 0.7.8", + "der", ] [[package]] @@ -2343,6 +2163,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "subtle-ng" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "734676eb262c623cec13c3155096e08d1f8f29adce39ba17948b18dad1e54142" + [[package]] name = "syn" version = "1.0.109" @@ -2365,30 +2191,51 @@ dependencies = [ "unicode-ident", ] +[[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.23.9" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "467f82178deeebcd357e1273a0c0b77b9a8a0313ef7c07074baebe99d87851f4" +checksum = "bc2294fa667c8b548ee27a9ba59115472d0a09c2ba255771092a7f1dcf03a789" dependencies = [ - "async-trait", "bytes", + "digest 0.10.7", "ed25519", - "ed25519-dalek", + "ed25519-consensus", "flex-error", "futures", - "k256 0.11.6", + "k256", "num-traits", "once_cell", - "prost 0.11.9", - "prost-types", - "ripemd160", + "prost 0.12.3", + "prost-types 0.12.3", + "ripemd", "serde", "serde_bytes", "serde_json", "serde_repr", - "sha2 0.9.9", - "signature 1.6.4", + "sha2 0.10.8", + "signature", "subtle", "subtle-encoding", "tendermint-proto", @@ -2398,9 +2245,9 @@ dependencies = [ [[package]] name = "tendermint-config" -version = "0.23.9" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d42ee0abc27ef5fc34080cce8d43c189950d331631546e7dfb983b6274fa327" +checksum = "5a25dbe8b953e80f3d61789fbdb83bf9ad6c0ef16df5ca6546f49912542cc137" dependencies = [ "flex-error", "serde", @@ -2412,16 +2259,16 @@ dependencies = [ [[package]] name = "tendermint-proto" -version = "0.23.9" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68ce80bf536476db81ecc9ebab834dc329c9c1509a694f211a73858814bfe023" +checksum = "2cc728a4f9e891d71adf66af6ecaece146f9c7a11312288a3107b3e1d6979aaf" dependencies = [ "bytes", "flex-error", "num-derive", "num-traits", - "prost 0.11.9", - "prost-types", + "prost 0.12.3", + "prost-types 0.12.3", "serde", "serde_bytes", "subtle-encoding", @@ -2430,24 +2277,23 @@ dependencies = [ [[package]] name = "tendermint-rpc" -version = "0.23.9" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f14aafe3528a0f75e9f3f410b525617b2de16c4b7830a21f717eee62882ec60" +checksum = "dfbf0a4753b46a190f367337e0163d0b552a2674a6bac54e74f9f2cdcde2969b" dependencies = [ "async-trait", "bytes", "flex-error", "futures", "getrandom", - "http", - "hyper", - "hyper-proxy", - "hyper-rustls", "peg", "pin-project", + "reqwest", + "semver", "serde", "serde_bytes", "serde_json", + "subtle", "subtle-encoding", "tendermint", "tendermint-config", @@ -2463,15 +2309,15 @@ dependencies = [ [[package]] name = "test-tube" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e79c7af10967dd3383ee5aae3810637cc3f2fd040f87f862c02151db060628" +checksum = "c17f30e7fea966bde5f9933a4cb2db79dd272115ea19d1656da2aac7ce0700fa" dependencies = [ - "base64 0.13.1", + "base64", "cosmrs", "cosmwasm-std", "osmosis-std", - "prost 0.11.9", + "prost 0.12.3", "serde", "serde_json", "thiserror", @@ -2559,13 +2405,12 @@ dependencies = [ [[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]] @@ -2663,9 +2508,9 @@ dependencies = [ [[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" @@ -2740,6 +2585,18 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac36a15a220124ac510204aec1c3e5db8a22ab06fd6706d881dc6149f8ed9a12" +dependencies = [ + "cfg-if", + "js-sys", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.89" @@ -2779,25 +2636,6 @@ dependencies = [ "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.2" @@ -2973,6 +2811,16 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[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 = "zeroize" version = "1.7.0" diff --git a/Cargo.toml b/Cargo.toml index 0bdd766..f2385da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,4 @@ astroport = { git = "https://github.com/astroport-fi/astroport-core", version = astroport-pcl-common = { git = "https://github.com/astroport-fi/astroport-core", version = "1.0.1" } astroport-circular-buffer = { git = "https://github.com/astroport-fi/astroport-core", version = "0.1.0" } astroport-native-coin-registry = "1.0.1" -osmosis-std = "0.20.1" \ No newline at end of file +osmosis-std = "0.21.0" \ No newline at end of file diff --git a/contracts/factory/src/contract.rs b/contracts/factory/src/contract.rs index f4d6051..1687e21 100644 --- a/contracts/factory/src/contract.rs +++ b/contracts/factory/src/contract.rs @@ -56,7 +56,7 @@ pub fn instantiate( token_code_id: msg.token_code_id, fee_address: None, generator_address: None, - whitelist_code_id: 0, + whitelist_code_id: msg.whitelist_code_id, coin_registry_address: deps.api.addr_validate(&msg.coin_registry_address)?, }; @@ -178,7 +178,11 @@ pub fn execute( /// Updates general contract settings. /// -/// * **param** is an object of type [`UpdateConfig`] that contains the parameters to update. +/// * **fee_address** if Some defines new Astroport fees receiver, +/// +/// * **generator_address** if Some defines new Astroport generator address, +/// +/// * **coin_registry_address** if Some defines new Astroport coin registry address. /// /// ## Executor /// Only the owner can execute this. @@ -196,23 +200,28 @@ pub fn execute_update_config( return Err(ContractError::Unauthorized {}); } + let mut attrs = vec![attr("action", "update_config")]; + if let Some(fee_address) = fee_address { // Validate address format config.fee_address = Some(deps.api.addr_validate(&fee_address)?); + attrs.push(attr("fee_address", fee_address)); } if let Some(generator_address) = generator_address { // Validate the address format config.generator_address = Some(deps.api.addr_validate(&generator_address)?); + attrs.push(attr("generator_address", generator_address)); } if let Some(coin_registry_address) = coin_registry_address { config.coin_registry_address = deps.api.addr_validate(&coin_registry_address)?; + attrs.push(attr("coin_registry_address", coin_registry_address)); } CONFIG.save(deps.storage, &config)?; - Ok(Response::new().add_attribute("action", "update_config")) + Ok(Response::new().add_attributes(attrs)) } /// Updates a pair type's configuration. diff --git a/contracts/factory/src/error.rs b/contracts/factory/src/error.rs index 20cd754..3d9172c 100644 --- a/contracts/factory/src/error.rs +++ b/contracts/factory/src/error.rs @@ -40,9 +40,6 @@ pub enum ContractError { #[error("Doubling assets in asset infos")] DoublingAssets {}, - #[error("Contract can't be migrated!")] - MigrationError {}, - #[error("Failed to parse or process reply message")] FailedToParseReply {}, diff --git a/contracts/factory/tests/unit_tests.rs b/contracts/factory/tests/unit_tests.rs index 5994b28..8041536 100644 --- a/contracts/factory/tests/unit_tests.rs +++ b/contracts/factory/tests/unit_tests.rs @@ -126,7 +126,7 @@ fn update_config() { }]; let msg = InstantiateMsg { - pair_configs: pair_configs, + pair_configs, token_code_id: 123u64, fee_address: None, owner: owner.to_string(), @@ -512,7 +512,7 @@ fn create_pair() { msg: MsgCreateCosmWasmPool { code_id: pair_config.code_id, instantiate_msg: to_json_binary(&pair::InstantiateMsg { - asset_infos: asset_infos, + asset_infos, token_code_id: 0, factory_addr: MOCK_CONTRACT_ADDR.to_string(), init_params: None, @@ -787,7 +787,7 @@ fn register() { vec![PairInfo { liquidity_token: Addr::unchecked("liquidity0000"), contract_addr: Addr::unchecked("pair0000"), - asset_infos: asset_infos, + asset_infos, pair_type: PairType::Xyk {}, },] ); diff --git a/contracts/pair_concentrated/src/contract.rs b/contracts/pair_concentrated/src/contract.rs index c5e71b6..76928ef 100644 --- a/contracts/pair_concentrated/src/contract.rs +++ b/contracts/pair_concentrated/src/contract.rs @@ -92,7 +92,7 @@ pub fn instantiate( } let params: ConcentratedPoolParams = from_json( - &msg.init_params + msg.init_params .ok_or(ContractError::InitParamsNotFound {})?, )?; ensure!( @@ -294,9 +294,6 @@ fn set_pool_id(deps: DepsMut, info: MessageInfo, pool_id: u64) -> Result= MIN_TRADE_SIZE + && offer_asset_dec.amount >= MIN_TRADE_SIZE + { + let last_price = swap_result.calc_last_price(offer_asset_dec.amount, offer_ind); + + // update_price() works only with internal representation + xs[1] *= config.pool_state.price_state.price_scale; + config + .pool_state + .update_price(&config.pool_params, &env, total_share, &xs, last_price)?; + } let mut messages = vec![pools[ask_ind] .info @@ -220,36 +238,21 @@ fn swap_exact_amount_out( token_in_amount: offer_asset.amount, })?; - let mut attrs = vec![ - attr("method", "swap_exact_amount_out"), - attr("sender", sender.clone()), - attr("offer_asset", offer_asset.info.to_string()), - attr("ask_asset", ask_asset.info.to_string()), - attr("offer_amount", offer_asset.amount), - attr("return_amount", return_amount), - attr("spread_amount", spread_amount), - attr( - "commission_amount", - swap_result.total_fee.to_uint(ask_asset_prec)?, - ), - attr("maker_fee_amount", maker_fee), - ]; - - let excess_amount = token_in_max_amount.saturating_sub(offer_asset.amount); - if !excess_amount.is_zero() { - let excess_coin = coin(excess_amount.u128(), token_in_denom); - attrs.push(attr("excess_tokens", excess_coin.to_string())); - messages.push( - BankMsg::Send { - to_address: sender, - amount: vec![excess_coin], - } - .into(), - ); - } - Ok(Response::new() .add_messages(messages) - .add_attributes(attrs) + .add_attributes([ + attr("method", "swap_exact_amount_out"), + attr("sender", sender), + attr("offer_asset", offer_asset.info.to_string()), + attr("ask_asset", ask_asset.info.to_string()), + attr("offer_amount", offer_asset.amount), + attr("return_amount", return_amount), + attr("spread_amount", spread_amount), + attr( + "commission_amount", + swap_result.total_fee.to_uint(ask_asset_prec)?, + ), + attr("maker_fee_amount", maker_fee), + ]) .set_data(response_data)) } diff --git a/contracts/pair_concentrated/tests/common/osmosis_ext.rs b/contracts/pair_concentrated/tests/common/osmosis_ext.rs index 74fb98c..7adc94d 100644 --- a/contracts/pair_concentrated/tests/common/osmosis_ext.rs +++ b/contracts/pair_concentrated/tests/common/osmosis_ext.rs @@ -7,7 +7,7 @@ use cosmwasm_schema::schemars::JsonSchema; use cosmwasm_schema::serde::de::DeserializeOwned; use cosmwasm_std::{ coin, coins, from_json, to_json_binary, Addr, Api, BankMsg, Binary, BlockInfo, CustomQuery, - Querier, QueryRequest, Storage, SubMsgResponse, WasmMsg, WasmQuery, + Querier, QueryRequest, Storage, SubMsgResponse, Uint128, WasmMsg, WasmQuery, }; use cw_multi_test::{AppResponse, BankSudo, CosmosRouter, Stargate, WasmSudo}; use osmosis_std::types::osmosis::cosmwasmpool::v1beta1::{ @@ -23,7 +23,9 @@ use osmosis_std::types::osmosis::tokenfactory::v1beta1::{ }; use astroport_on_osmosis::pair_pcl; -use astroport_on_osmosis::pair_pcl::{GetSwapFeeResponse, QueryMsg}; +use astroport_on_osmosis::pair_pcl::{ + GetSwapFeeResponse, QueryMsg, SwapExactAmountOutResponseData, +}; #[derive(Default)] pub struct OsmosisStargate { @@ -184,10 +186,13 @@ impl Stargate for OsmosisStargate { ) .unwrap(); + let token_in_denom = pm_msg.routes[0].token_in_denom.clone(); + let token_in_max_amount: Uint128 = pm_msg.token_in_max_amount.parse()?; + let inner_contract_msg = pair_pcl::SudoMessage::SwapExactAmountOut { sender: pm_msg.sender.clone(), - token_in_denom: pm_msg.routes[0].token_in_denom.clone(), - token_in_max_amount: pm_msg.token_in_max_amount.parse()?, + token_in_denom: token_in_denom.clone(), + token_in_max_amount, token_out: coin(token_out.amount.parse()?, token_out.denom), swap_fee: from_json::(&res)?.swap_fee, }; @@ -196,7 +201,7 @@ impl Stargate for OsmosisStargate { api, storage, block, - Addr::unchecked(pm_msg.sender), + Addr::unchecked(&pm_msg.sender), BankMsg::Send { to_address: contract_addr.to_string(), amount: coins( @@ -208,7 +213,34 @@ impl Stargate for OsmosisStargate { )?; let wasm_sudo_msg = WasmSudo::new(&contract_addr, &inner_contract_msg)?; - router.sudo(api, storage, block, wasm_sudo_msg.into()) + let resp = router.sudo(api, storage, block, wasm_sudo_msg.into()); + + // Cosmwasmpool derives excess tokens itself and sends them back to the sender. + // https://github.com/osmosis-labs/osmosis/blob/294302637a47ffec5cafc0c1953e88a54390b20e/x/cosmwasmpool/pool_module.go#L316-L321 + // Mimic this logic here. + if let Ok(resp) = &resp { + let raw = resp.data.clone().expect("Data must be set in response"); + let token_in_amount = from_json::(&raw) + .unwrap() + .token_in_amount; + let excess_tokens = token_in_max_amount - token_in_amount; + + if !excess_tokens.is_zero() { + router.execute( + api, + storage, + block, + Addr::unchecked(contract_addr), + BankMsg::Send { + to_address: pm_msg.sender.to_string(), + amount: coins(excess_tokens.u128(), token_in_denom), + } + .into(), + )?; + } + } + + resp } _ => Err(anyhow::anyhow!( "Unexpected exec msg {type_url} from {sender:?}", diff --git a/e2e_tests/Cargo.toml b/e2e_tests/Cargo.toml index f85b685..b242af0 100644 --- a/e2e_tests/Cargo.toml +++ b/e2e_tests/Cargo.toml @@ -8,8 +8,8 @@ anyhow = "1" cosmwasm-std = "1" serde = "1" osmosis-std = { workspace = true } -osmosis-test-tube = "20.1" -test-tube = "0.2.0" +osmosis-test-tube = "21.0.0" +test-tube = "0.3.0" astroport = { workspace = true } astroport-on-osmosis = { path = "../packages/astroport_on_osmosis", version = "1" } serde_json = "1" \ No newline at end of file diff --git a/e2e_tests/src/helper.rs b/e2e_tests/src/helper.rs index 241a750..bebc86a 100644 --- a/e2e_tests/src/helper.rs +++ b/e2e_tests/src/helper.rs @@ -183,7 +183,6 @@ impl<'a> TestAppWrapper<'a> { wasm_byte_code: std::fs::read(cl_pool_wasm).unwrap(), }, helper.signer.address(), - false, &helper.signer, )?; @@ -449,7 +448,14 @@ impl<'a> TestAppWrapper<'a> { T: ?Sized + Serialize, { self.wasm - .instantiate(self.code_ids[name], msg, None, None, funds, &self.signer) + .instantiate( + self.code_ids[name], + msg, + None, + Some("label"), + funds, + &self.signer, + ) .map(|res| res.data.address) .map_err(Into::into) } diff --git a/e2e_tests/tests/e2e_testing.rs b/e2e_tests/tests/e2e_testing.rs index 427240b..ce560ba 100644 --- a/e2e_tests/tests/e2e_testing.rs +++ b/e2e_tests/tests/e2e_testing.rs @@ -1,4 +1,4 @@ -use astroport::asset::{native_asset_info, AssetInfoExt}; +use astroport::asset::{native_asset_info, AssetInfo, AssetInfoExt}; use astroport::pair; use astroport::pair_concentrated::ConcentratedPoolParams; use cosmwasm_std::{coin, to_json_binary, Coin, Decimal}; @@ -153,7 +153,7 @@ fn dex_swap_test() { .unwrap(); let foo_bal = helper.coin_balance(&user2.address(), &foo_denom); let bar_bal = helper.coin_balance(&user2.address(), &bar_denom); - assert_eq!(foo_bal, 91406); // excess tokens sent back to the user2 + assert_eq!(foo_bal, 45703); // excess tokens sent back to the user2 assert_eq!(bar_bal, 1_903626); // PCL pool gives slightly more tokens than expected (due to dynamic fees) } @@ -211,3 +211,54 @@ fn init_outside_of_factory() { "execute error: failed to execute message; message index: 0: Pair is not registered in the factory. Only swap and withdraw are allowed: execute wasm contract failed" ); } + +#[test] +fn swap_with_fake_token() { + let app = OsmosisTestApp::new(); + let helper = TestAppWrapper::bootstrap(&app).unwrap(); + + let foo_denom = helper.register_and_mint("foo", 1_000_000_000000, 6, None); + let bar_denom = helper.register_and_mint("bar", 1_000_000_000000, 6, None); + let foo = native_asset_info(foo_denom.clone()); + let bar = native_asset_info(bar_denom.clone()); + + let (pair_addr, _) = helper + .create_pair(&[foo.clone(), bar.clone()], default_pcl_params()) + .unwrap(); + let pool_id = helper.get_pool_id_by_contract(&pair_addr); + + helper + .provide( + &helper.signer, + &pair_addr, + &[ + foo.with_balance(50_000_000000u128), + bar.with_balance(100_000_000000u128), + ], + None, + ) + .unwrap(); + + // Try to swap fake tokens via DEX module + let asset = AssetInfo::native("random").with_balance(1_000000u128); + let user = helper + .app + .init_account(&[asset.as_coin().unwrap(), gas_fee()]) + .unwrap(); + + let err = helper.swap_on_dex(&user, pool_id, &asset).unwrap_err(); + assert_eq!( + err.to_string(), + "execute error: failed to execute message; message index: 0: The asset random does not belong to the pair: execute wasm contract failed" + ); + + // Try reverse swap fake tokens via DEX module + let ask_asset = bar.with_balance(1_000000u128); + let err = helper + .reverse_swap_on_dex(&user, pool_id, "random", 1_000000u128, &ask_asset) + .unwrap_err(); + assert_eq!( + err.to_string(), + "execute error: failed to execute message; message index: 0: The asset random does not belong to the pair: execute wasm contract failed" + ); +}