diff --git a/Cargo.lock b/Cargo.lock index 66759a89..de075a93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,17 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.7.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "anybuf" version = "0.4.0" @@ -10,15 +21,15 @@ checksum = "5c1a43b7dc14f396c5d1ac0eaea10f33cb40a2b46751d0869864d6d5abed20db" [[package]] name = "anyhow" -version = "1.0.80" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ad32ce52e4161730f7098c077cd2ed6229b5804ccf99e5366be1ab72a98b4e1" +checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" [[package]] name = "autocfg" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" [[package]] name = "base16ct" @@ -34,9 +45,9 @@ checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" [[package]] name = "base64ct" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bdca834647821e0b13d9539a8634eb62d3501b6b6c2cec1722786ee6671b851" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bech32" @@ -65,6 +76,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + [[package]] name = "block-buffer" version = "0.9.0" @@ -76,36 +93,30 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.10.3" +version = "0.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" dependencies = [ "generic-array", ] [[package]] name = "bnum" -version = "0.8.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab9008b6bb9fc80b5277f2fe481c09e828743d9151203e804583eb4c9e15b31d" +checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" [[package]] name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" - -[[package]] -name = "bytes" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] -name = "cc" -version = "1.0.79" +name = "bytes" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cfg-if" @@ -121,9 +132,9 @@ checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "cosmwasm-crypto" -version = "1.5.1" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad24bc9dae9aac5dc124b4560e3f7678729d701f1bf3cb11140703d91f247d31" +checksum = "9934c79e58d9676edfd592557dee765d2a6ef54c09d5aa2edb06156b00148966" dependencies = [ "digest 0.10.7", "ecdsa", @@ -135,11 +146,11 @@ dependencies = [ [[package]] name = "cosmwasm-derive" -version = "1.5.1" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca65635b768406eabdd28ba015cc3f2f863ca5a2677a7dc4c237b8ee1298efb3" +checksum = "bc5e72e330bd3bdab11c52b5ecbdeb6a8697a004c57964caeb5d876f0b088b3c" dependencies = [ - "syn 1.0.99", + "syn 1.0.109", ] [[package]] @@ -163,14 +174,14 @@ checksum = "f5d803bea6bd9ed61bd1ee0b4a2eb09ee20dbb539cc6e0b8795614d20952ebb1" dependencies = [ "proc-macro2", "quote", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] name = "cosmwasm-std" -version = "1.5.1" +version = "1.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ed4564772e5d779235f2d7353e3d66e37793065c3a5155a2978256bf4c5b7d5" +checksum = "ef8666e572a3a2519010dde88c04d16e9339ae751b56b2bb35081fe3f7d6be74" dependencies = [ "base64", "bech32", @@ -190,9 +201,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] @@ -249,9 +260,9 @@ dependencies = [ [[package]] name = "cw-controllers" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5d8edce4b78785f36413f67387e4be7d0cb7d032b5d4164bcc024f9c3f3f2ea" +checksum = "57de8d3761e46be863e3ac1eba8c8a976362a48c6abf240df1e26c3e421ee9e8" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -264,9 +275,9 @@ dependencies = [ [[package]] name = "cw-multi-test" -version = "0.20.0" +version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67fff029689ae89127cf6d7655809a68d712f3edbdb9686c70b018ba438b26ca" +checksum = "cc392a5cb7e778e3f90adbf7faa43c4db7f35b6623224b08886d796718edb875" dependencies = [ "anyhow", "bech32", @@ -305,7 +316,7 @@ checksum = "a1d3bf2e0f341bb6cc100d7d441d31cf713fbd3ce0c511f91e79f14b40a889af" dependencies = [ "proc-macro2", "quote", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] @@ -363,9 +374,9 @@ dependencies = [ [[package]] name = "cw20" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "011c45920f8200bd5d32d4fe52502506f64f2f75651ab408054d4cfc75ca3a9b" +checksum = "526e39bb20534e25a1cd0386727f0038f4da294e5e535729ba3ef54055246abd" dependencies = [ "cosmwasm-schema", "cosmwasm-std", @@ -376,14 +387,13 @@ dependencies = [ [[package]] name = "cw20-base" -version = "1.1.0" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b3ad456059901a36cfa68b596d85d579c3df2b797dae9950dc34c27e14e995f" +checksum = "17ad79e86ea3707229bf78df94e08732e8f713207b4a77b2699755596725e7d9" dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-storage-plus", - "cw-utils", "cw2", "cw20", "schemars", @@ -394,9 +404,9 @@ dependencies = [ [[package]] name = "der" -version = "0.7.8" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fffa369a668c8af7dbf8b5e56c9f744fbd399949ed171606040001947de40b1c" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "zeroize", @@ -410,7 +420,7 @@ checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2", "quote", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] @@ -428,7 +438,7 @@ version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.3", + "block-buffer 0.10.4", "const-oid", "crypto-common", "subtle", @@ -436,9 +446,9 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.9" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" @@ -456,24 +466,24 @@ dependencies = [ [[package]] name = "ed25519-zebra" -version = "3.0.0" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "403ef3e961ab98f0ba902771d29f842058578bb1ce7e3c59dad5a6a93e784c69" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" dependencies = [ "curve25519-dalek", + "hashbrown", "hex", "rand_core 0.6.4", "serde", "sha2 0.9.9", - "thiserror", "zeroize", ] [[package]] name = "either" -version = "1.7.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" [[package]] name = "elliptic-curve" @@ -512,33 +522,19 @@ dependencies = [ [[package]] name = "errno" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.48.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" dependencies = [ - "cc", "libc", + "windows-sys", ] [[package]] name = "fastrand" -version = "1.9.0" +version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" [[package]] name = "fee-distributor-mock" @@ -635,9 +631,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", @@ -646,24 +642,13 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.9.0+wasi-snapshot-preview1", -] - -[[package]] -name = "getrandom" -version = "0.2.7" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eb1a864a501629691edf6c15a593b7a51eebaa1e8468e9ddc623de7c9b58ec6" +checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" dependencies = [ "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] @@ -678,10 +663,13 @@ dependencies = [ ] [[package]] -name = "hermit-abi" -version = "0.3.1" +name = "hashbrown" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] [[package]] name = "hex" @@ -747,15 +735,6 @@ version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfa799dd5ed20a7e349f3b4639aa80d74549c81716d9ec4f994c9b5815598306" -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if", -] - [[package]] name = "integer-sqrt" version = "0.1.5" @@ -766,21 +745,19 @@ dependencies = [ ] [[package]] -name = "io-lifetimes" -version = "1.0.10" +name = "itertools" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.48.0", + "either", ] [[package]] name = "itertools" -version = "0.10.3" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57" dependencies = [ "either", ] @@ -796,15 +773,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.3" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "k256" -version = "0.13.3" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" +checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" dependencies = [ "cfg-if", "ecdsa", @@ -828,21 +805,21 @@ checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" [[package]] name = "libm" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "linux-raw-sys" -version = "0.3.8" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.9" +version = "0.4.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" dependencies = [ "autocfg", "scopeguard", @@ -859,9 +836,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" dependencies = [ "autocfg", "libm", @@ -875,9 +852,9 @@ checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[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 = "osmosis-std-derive" @@ -885,10 +862,10 @@ version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4d482a16be198ee04e0f94e10dd9b8d02332dcf33bc5ea4b255e7e25eedc5df" dependencies = [ - "itertools 0.10.3", + "itertools 0.10.5", "proc-macro2", "quote", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] @@ -903,15 +880,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.7" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" dependencies = [ "cfg-if", "libc", - "redox_syscall 0.2.16", + "redox_syscall", "smallvec", - "windows-sys 0.45.0", + "windows-targets 0.48.5", ] [[package]] @@ -945,6 +922,7 @@ dependencies = [ "thiserror", "whale-lair", "white-whale-std", + "white-whale-testing", ] [[package]] @@ -955,25 +933,24 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" -version = "1.0.78" +version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" dependencies = [ "unicode-ident", ] [[package]] name = "proptest" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", - "bitflags", - "byteorder", + "bit-vec", + "bitflags 2.5.0", "lazy_static", "num-traits", - "quick-error 2.0.1", "rand", "rand_chacha", "rand_xorshift", @@ -1010,10 +987,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" dependencies = [ "anyhow", - "itertools 0.10.3", + "itertools 0.10.5", "proc-macro2", "quote", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] @@ -1023,10 +1000,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" dependencies = [ "anyhow", - "itertools 0.10.3", + "itertools 0.11.0", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -1105,7 +1082,7 @@ dependencies = [ "proc-macro2", "pyo3-macros-backend", "quote", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] @@ -1116,7 +1093,7 @@ checksum = "c8df9be978a2d2f0cdebabb03206ed73b11314701a5bfe71b0d753b81997777f" dependencies = [ "proc-macro2", "quote", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] @@ -1125,12 +1102,6 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -[[package]] -name = "quick-error" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" - [[package]] name = "quote" version = "1.0.35" @@ -1166,9 +1137,6 @@ name = "rand_core" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.16", -] [[package]] name = "rand_core" @@ -1176,7 +1144,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.7", + "getrandom", ] [[package]] @@ -1190,27 +1158,18 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" -dependencies = [ - "bitflags", -] - -[[package]] -name = "redox_syscall" -version = "0.3.5" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "rfc6979" @@ -1224,16 +1183,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.19" +version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acf8729d8542766f1b2cf77eb034d52f40d375bb8b615d0b147089946e16613d" +checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags", + "bitflags 2.5.0", "errno", - "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.48.0", + "windows-sys", ] [[package]] @@ -1243,16 +1201,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = [ "fnv", - "quick-error 1.2.3", + "quick-error", "tempfile", "wait-timeout", ] [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" [[package]] name = "schemars" @@ -1275,20 +1233,20 @@ dependencies = [ "proc-macro2", "quote", "serde_derive_internals", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "sec1" -version = "0.7.1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48518a2b5775ba8ca5b46596aae011caa431e6ce7e4a67ead66d92f08884220e" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ "base16ct", "der", @@ -1315,9 +1273,9 @@ dependencies = [ [[package]] name = "serde-json-wasm" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +checksum = "9e9213a07d53faa0b8dd81e767a54a8188a242fdb9be99ab75ec576a774bfdd7" dependencies = [ "serde", ] @@ -1330,7 +1288,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -1341,14 +1299,14 @@ checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" dependencies = [ "proc-macro2", "quote", - "syn 1.0.99", + "syn 1.0.109", ] [[package]] name = "serde_json" -version = "1.0.83" +version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38dd04e3c8279e75b31ef29dbdceebfe5ad89f4d0937213c53f7d49d01b3d5a7" +checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ "itoa", "ryu", @@ -1391,9 +1349,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.10.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "spki" @@ -1442,15 +1400,15 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" -version = "1.0.99" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ "proc-macro2", "quote", @@ -1459,9 +1417,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" dependencies = [ "proc-macro2", "quote", @@ -1470,21 +1428,20 @@ dependencies = [ [[package]] name = "target-lexicon" -version = "0.12.7" +version = "0.12.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd1ba337640d60c3e96bc6f0638a939b9c9a7f2c316a1598c279828b3d1dc8c5" +checksum = "e1fc403891a21bcfb7c37834ba66a547a8f402146eba7265b5a6d88059c9ff2f" [[package]] name = "tempfile" -version = "3.5.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if", "fastrand", - "redox_syscall 0.3.5", "rustix", - "windows-sys 0.45.0", + "windows-sys", ] [[package]] @@ -1577,7 +1534,7 @@ dependencies = [ "cfg-if", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] @@ -1588,35 +1545,35 @@ checksum = "5c89e72a01ed4c579669add59014b9a524d609c0c88c6a585ce37485879f6ffb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", "test-case-core", ] [[package]] name = "thiserror" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.58", ] [[package]] name = "typenum" -version = "1.15.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "uint" @@ -1638,9 +1595,9 @@ checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" [[package]] name = "unicode-ident" -version = "1.0.3" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unindent" @@ -1752,12 +1709,6 @@ dependencies = [ "libc", ] -[[package]] -name = "wasi" -version = "0.9.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -1821,135 +1772,126 @@ dependencies = [ [[package]] name = "windows-sys" -version = "0.45.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" -dependencies = [ - "windows-targets 0.42.2", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.48.0", + "windows-targets 0.52.4", ] [[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.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" 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.4", + "windows_aarch64_msvc 0.52.4", + "windows_i686_gnu 0.52.4", + "windows_i686_msvc 0.52.4", + "windows_x86_64_gnu 0.52.4", + "windows_x86_64_gnullvm 0.52.4", + "windows_x86_64_msvc 0.52.4", ] [[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.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" [[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.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" [[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.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" [[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.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" [[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.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" [[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.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" [[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.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" [[package]] name = "zeroize" diff --git a/contracts/liquidity_hub/pool-manager/Cargo.toml b/contracts/liquidity_hub/pool-manager/Cargo.toml index b5fa8d58..de0bd39c 100644 --- a/contracts/liquidity_hub/pool-manager/Cargo.toml +++ b/contracts/liquidity_hub/pool-manager/Cargo.toml @@ -54,3 +54,4 @@ cw-multi-test.workspace = true anyhow.workspace = true test-case.workspace = true whale-lair.workspace = true +white-whale-testing.workspace = true diff --git a/contracts/liquidity_hub/pool-manager/schema/pool-manager.json b/contracts/liquidity_hub/pool-manager/schema/pool-manager.json index fcddc80e..1d614629 100644 --- a/contracts/liquidity_hub/pool-manager/schema/pool-manager.json +++ b/contracts/liquidity_hub/pool-manager/schema/pool-manager.json @@ -9,9 +9,7 @@ "required": [ "fee_collector_addr", "owner", - "pair_code_id", - "pool_creation_fee", - "token_code_id" + "pool_creation_fee" ], "properties": { "fee_collector_addr": { @@ -20,84 +18,26 @@ "owner": { "type": "string" }, - "pair_code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, "pool_creation_fee": { - "$ref": "#/definitions/Asset" - }, - "token_code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 + "$ref": "#/definitions/Coin" } }, "additionalProperties": false, "definitions": { - "Asset": { + "Coin": { "type": "object", "required": [ "amount", - "info" + "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false + "denom": { + "type": "string" } - ] + } }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", @@ -118,16 +58,16 @@ "create_pair": { "type": "object", "required": [ - "asset_infos", + "asset_denoms", "pair_type", "pool_fees", "token_factory_lp" ], "properties": { - "asset_infos": { + "asset_denoms": { "type": "array", "items": { - "$ref": "#/definitions/AssetInfo" + "type": "string" } }, "pair_identifier": { @@ -168,7 +108,7 @@ "assets": { "type": "array", "items": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" } }, "pair_identifier": { @@ -206,13 +146,13 @@ "swap": { "type": "object", "required": [ - "ask_asset", + "ask_asset_denom", "offer_asset", "pair_identifier" ], "properties": { - "ask_asset": { - "$ref": "#/definitions/AssetInfo" + "ask_asset_denom": { + "type": "string" }, "belief_price": { "anyOf": [ @@ -235,7 +175,7 @@ ] }, "offer_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "pair_identifier": { "type": "string" @@ -268,7 +208,7 @@ "assets": { "type": "array", "items": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" } }, "pair_identifier": { @@ -388,18 +328,6 @@ }, "additionalProperties": false }, - { - "type": "object", - "required": [ - "receive" - ], - "properties": { - "receive": { - "$ref": "#/definitions/Cw20ReceiveMsg" - } - }, - "additionalProperties": false - }, { "description": "Update the contract's ownership. The `action` to be provided can be either to propose transferring ownership to an account, accept a pending ownership transfer, or renounce the ownership permanently.", "type": "object", @@ -466,93 +394,20 @@ } ] }, - "Asset": { + "Coin": { "type": "object", "required": [ "amount", - "info" + "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" - }, - "Cw20ReceiveMsg": { - "description": "Cw20ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg", - "type": "object", - "required": [ - "amount", - "msg", - "sender" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "msg": { - "$ref": "#/definitions/Binary" - }, - "sender": { + "denom": { "type": "string" } - }, - "additionalProperties": false + } }, "Decimal": { "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", @@ -684,18 +539,18 @@ "type": "object", "required": [ "pool_identifier", - "token_in_info", - "token_out_info" + "token_in_denom", + "token_out_denom" ], "properties": { "pool_identifier": { "type": "string" }, - "token_in_info": { - "$ref": "#/definitions/AssetInfo" + "token_in_denom": { + "type": "string" }, - "token_out_info": { - "$ref": "#/definitions/AssetInfo" + "token_out_denom": { + "type": "string" } }, "additionalProperties": false @@ -708,16 +563,16 @@ "SwapRoute": { "type": "object", "required": [ - "ask_asset_info", - "offer_asset_info", + "ask_asset_denom", + "offer_asset_denom", "swap_operations" ], "properties": { - "ask_asset_info": { - "$ref": "#/definitions/AssetInfo" + "ask_asset_denom": { + "type": "string" }, - "offer_asset_info": { - "$ref": "#/definitions/AssetInfo" + "offer_asset_denom": { + "type": "string" }, "swap_operations": { "type": "array", @@ -788,10 +643,10 @@ ], "properties": { "ask_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "offer_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "pair_identifier": { "type": "string" @@ -818,10 +673,10 @@ ], "properties": { "ask_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "offer_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "pair_identifier": { "type": "string" @@ -842,15 +697,15 @@ "swap_route": { "type": "object", "required": [ - "ask_asset_info", - "offer_asset_info" + "ask_asset_denom", + "offer_asset_denom" ], "properties": { - "ask_asset_info": { - "$ref": "#/definitions/AssetInfo" + "ask_asset_denom": { + "type": "string" }, - "offer_asset_info": { - "$ref": "#/definitions/AssetInfo" + "offer_asset_denom": { + "type": "string" } }, "additionalProperties": false @@ -909,68 +764,20 @@ } ], "definitions": { - "Asset": { + "Coin": { "type": "object", "required": [ "amount", - "info" + "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false + "denom": { + "type": "string" } - ] + } }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", @@ -1098,7 +905,7 @@ "type": "object", "required": [ "asset_decimals", - "asset_infos", + "asset_denoms", "assets", "balances", "liquidity_token", @@ -1114,16 +921,16 @@ "minimum": 0.0 } }, - "asset_infos": { + "asset_denoms": { "type": "array", "items": { - "$ref": "#/definitions/AssetInfo" + "type": "string" } }, "assets": { "type": "array", "items": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" } }, "balances": { @@ -1133,7 +940,7 @@ } }, "liquidity_token": { - "$ref": "#/definitions/AssetInfo" + "type": "string" }, "pair_type": { "$ref": "#/definitions/PairType" @@ -1144,68 +951,20 @@ }, "additionalProperties": false, "definitions": { - "Asset": { + "Coin": { "type": "object", "required": [ "amount", - "info" + "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false + "denom": { + "type": "string" } - ] + } }, "Decimal": { "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", @@ -1366,53 +1125,6 @@ "$ref": "#/definitions/SwapOperation" }, "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, "SwapOperation": { "oneOf": [ { @@ -1425,18 +1137,18 @@ "type": "object", "required": [ "pool_identifier", - "token_in_info", - "token_out_info" + "token_in_denom", + "token_out_denom" ], "properties": { "pool_identifier": { "type": "string" }, - "token_in_info": { - "$ref": "#/definitions/AssetInfo" + "token_in_denom": { + "type": "string" }, - "token_out_info": { - "$ref": "#/definitions/AssetInfo" + "token_out_denom": { + "type": "string" } }, "additionalProperties": false @@ -1456,53 +1168,6 @@ "$ref": "#/definitions/SwapRouteResponse" }, "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, "SwapOperation": { "oneOf": [ { @@ -1515,18 +1180,18 @@ "type": "object", "required": [ "pool_identifier", - "token_in_info", - "token_out_info" + "token_in_denom", + "token_out_denom" ], "properties": { "pool_identifier": { "type": "string" }, - "token_in_info": { - "$ref": "#/definitions/AssetInfo" + "token_in_denom": { + "type": "string" }, - "token_out_info": { - "$ref": "#/definitions/AssetInfo" + "token_out_denom": { + "type": "string" } }, "additionalProperties": false @@ -1539,15 +1204,15 @@ "SwapRouteResponse": { "type": "object", "required": [ - "ask_asset", - "offer_asset", + "ask_asset_denom", + "offer_asset_denom", "swap_route" ], "properties": { - "ask_asset": { + "ask_asset_denom": { "type": "string" }, - "offer_asset": { + "offer_asset_denom": { "type": "string" }, "swap_route": { diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/execute.json b/contracts/liquidity_hub/pool-manager/schema/raw/execute.json index e097996d..aa46593c 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/execute.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/execute.json @@ -11,16 +11,16 @@ "create_pair": { "type": "object", "required": [ - "asset_infos", + "asset_denoms", "pair_type", "pool_fees", "token_factory_lp" ], "properties": { - "asset_infos": { + "asset_denoms": { "type": "array", "items": { - "$ref": "#/definitions/AssetInfo" + "type": "string" } }, "pair_identifier": { @@ -61,7 +61,7 @@ "assets": { "type": "array", "items": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" } }, "pair_identifier": { @@ -99,13 +99,13 @@ "swap": { "type": "object", "required": [ - "ask_asset", + "ask_asset_denom", "offer_asset", "pair_identifier" ], "properties": { - "ask_asset": { - "$ref": "#/definitions/AssetInfo" + "ask_asset_denom": { + "type": "string" }, "belief_price": { "anyOf": [ @@ -128,7 +128,7 @@ ] }, "offer_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "pair_identifier": { "type": "string" @@ -161,7 +161,7 @@ "assets": { "type": "array", "items": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" } }, "pair_identifier": { @@ -281,18 +281,6 @@ }, "additionalProperties": false }, - { - "type": "object", - "required": [ - "receive" - ], - "properties": { - "receive": { - "$ref": "#/definitions/Cw20ReceiveMsg" - } - }, - "additionalProperties": false - }, { "description": "Update the contract's ownership. The `action` to be provided can be either to propose transferring ownership to an account, accept a pending ownership transfer, or renounce the ownership permanently.", "type": "object", @@ -359,93 +347,20 @@ } ] }, - "Asset": { - "type": "object", - "required": [ - "amount", - "info" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec. See also .", - "type": "string" - }, - "Cw20ReceiveMsg": { - "description": "Cw20ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg", + "Coin": { "type": "object", "required": [ "amount", - "msg", - "sender" + "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, - "msg": { - "$ref": "#/definitions/Binary" - }, - "sender": { + "denom": { "type": "string" } - }, - "additionalProperties": false + } }, "Decimal": { "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", @@ -577,18 +492,18 @@ "type": "object", "required": [ "pool_identifier", - "token_in_info", - "token_out_info" + "token_in_denom", + "token_out_denom" ], "properties": { "pool_identifier": { "type": "string" }, - "token_in_info": { - "$ref": "#/definitions/AssetInfo" + "token_in_denom": { + "type": "string" }, - "token_out_info": { - "$ref": "#/definitions/AssetInfo" + "token_out_denom": { + "type": "string" } }, "additionalProperties": false @@ -601,16 +516,16 @@ "SwapRoute": { "type": "object", "required": [ - "ask_asset_info", - "offer_asset_info", + "ask_asset_denom", + "offer_asset_denom", "swap_operations" ], "properties": { - "ask_asset_info": { - "$ref": "#/definitions/AssetInfo" + "ask_asset_denom": { + "type": "string" }, - "offer_asset_info": { - "$ref": "#/definitions/AssetInfo" + "offer_asset_denom": { + "type": "string" }, "swap_operations": { "type": "array", diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/instantiate.json b/contracts/liquidity_hub/pool-manager/schema/raw/instantiate.json index c32b5747..ba6a54e3 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/instantiate.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/instantiate.json @@ -5,9 +5,7 @@ "required": [ "fee_collector_addr", "owner", - "pair_code_id", - "pool_creation_fee", - "token_code_id" + "pool_creation_fee" ], "properties": { "fee_collector_addr": { @@ -16,84 +14,26 @@ "owner": { "type": "string" }, - "pair_code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - }, "pool_creation_fee": { - "$ref": "#/definitions/Asset" - }, - "token_code_id": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 + "$ref": "#/definitions/Coin" } }, "additionalProperties": false, "definitions": { - "Asset": { + "Coin": { "type": "object", "required": [ "amount", - "info" + "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false + "denom": { + "type": "string" } - ] + } }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/query.json b/contracts/liquidity_hub/pool-manager/schema/raw/query.json index 75fbaf4b..e43c3d5e 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/query.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/query.json @@ -40,10 +40,10 @@ ], "properties": { "ask_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "offer_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "pair_identifier": { "type": "string" @@ -70,10 +70,10 @@ ], "properties": { "ask_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "offer_asset": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" }, "pair_identifier": { "type": "string" @@ -94,15 +94,15 @@ "swap_route": { "type": "object", "required": [ - "ask_asset_info", - "offer_asset_info" + "ask_asset_denom", + "offer_asset_denom" ], "properties": { - "ask_asset_info": { - "$ref": "#/definitions/AssetInfo" + "ask_asset_denom": { + "type": "string" }, - "offer_asset_info": { - "$ref": "#/definitions/AssetInfo" + "offer_asset_denom": { + "type": "string" } }, "additionalProperties": false @@ -161,68 +161,20 @@ } ], "definitions": { - "Asset": { + "Coin": { "type": "object", "required": [ "amount", - "info" + "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, - "info": { - "$ref": "#/definitions/AssetInfo" - } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false + "denom": { + "type": "string" } - ] + } }, "Uint128": { "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_pair.json b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_pair.json index f1f3940a..511ccb51 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_pair.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_pair.json @@ -4,7 +4,7 @@ "type": "object", "required": [ "asset_decimals", - "asset_infos", + "asset_denoms", "assets", "balances", "liquidity_token", @@ -20,16 +20,16 @@ "minimum": 0.0 } }, - "asset_infos": { + "asset_denoms": { "type": "array", "items": { - "$ref": "#/definitions/AssetInfo" + "type": "string" } }, "assets": { "type": "array", "items": { - "$ref": "#/definitions/Asset" + "$ref": "#/definitions/Coin" } }, "balances": { @@ -39,7 +39,7 @@ } }, "liquidity_token": { - "$ref": "#/definitions/AssetInfo" + "type": "string" }, "pair_type": { "$ref": "#/definitions/PairType" @@ -50,68 +50,20 @@ }, "additionalProperties": false, "definitions": { - "Asset": { + "Coin": { "type": "object", "required": [ "amount", - "info" + "denom" ], "properties": { "amount": { "$ref": "#/definitions/Uint128" }, - "info": { - "$ref": "#/definitions/AssetInfo" + "denom": { + "type": "string" } - }, - "additionalProperties": false - }, - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] + } }, "Decimal": { "description": "A fixed-point decimal value with 18 fractional digits, i.e. Decimal(1_000_000_000_000_000_000) == 1.0\n\nThe greatest possible value that can be represented is 340282366920938463463.374607431768211455 (which is (2^128 - 1) / 10^18)", diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_swap_route.json b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_swap_route.json index 0a827945..e12f76f7 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_swap_route.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_swap_route.json @@ -6,53 +6,6 @@ "$ref": "#/definitions/SwapOperation" }, "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, "SwapOperation": { "oneOf": [ { @@ -65,18 +18,18 @@ "type": "object", "required": [ "pool_identifier", - "token_in_info", - "token_out_info" + "token_in_denom", + "token_out_denom" ], "properties": { "pool_identifier": { "type": "string" }, - "token_in_info": { - "$ref": "#/definitions/AssetInfo" + "token_in_denom": { + "type": "string" }, - "token_out_info": { - "$ref": "#/definitions/AssetInfo" + "token_out_denom": { + "type": "string" } }, "additionalProperties": false diff --git a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_swap_routes.json b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_swap_routes.json index a53b6105..28f3c58d 100644 --- a/contracts/liquidity_hub/pool-manager/schema/raw/response_to_swap_routes.json +++ b/contracts/liquidity_hub/pool-manager/schema/raw/response_to_swap_routes.json @@ -6,53 +6,6 @@ "$ref": "#/definitions/SwapRouteResponse" }, "definitions": { - "AssetInfo": { - "description": "AssetInfo contract_addr is usually passed from the cw20 hook so we can trust the contract_addr is properly validated.", - "oneOf": [ - { - "type": "object", - "required": [ - "token" - ], - "properties": { - "token": { - "type": "object", - "required": [ - "contract_addr" - ], - "properties": { - "contract_addr": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "native_token" - ], - "properties": { - "native_token": { - "type": "object", - "required": [ - "denom" - ], - "properties": { - "denom": { - "type": "string" - } - }, - "additionalProperties": false - } - }, - "additionalProperties": false - } - ] - }, "SwapOperation": { "oneOf": [ { @@ -65,18 +18,18 @@ "type": "object", "required": [ "pool_identifier", - "token_in_info", - "token_out_info" + "token_in_denom", + "token_out_denom" ], "properties": { "pool_identifier": { "type": "string" }, - "token_in_info": { - "$ref": "#/definitions/AssetInfo" + "token_in_denom": { + "type": "string" }, - "token_out_info": { - "$ref": "#/definitions/AssetInfo" + "token_out_denom": { + "type": "string" } }, "additionalProperties": false @@ -89,15 +42,15 @@ "SwapRouteResponse": { "type": "object", "required": [ - "ask_asset", - "offer_asset", + "ask_asset_denom", + "offer_asset_denom", "swap_route" ], "properties": { - "ask_asset": { + "ask_asset_denom": { "type": "string" }, - "offer_asset": { + "offer_asset_denom": { "type": "string" }, "swap_route": { diff --git a/contracts/liquidity_hub/pool-manager/src/contract.rs b/contracts/liquidity_hub/pool-manager/src/contract.rs index 081b1444..79a5430b 100644 --- a/contracts/liquidity_hub/pool-manager/src/contract.rs +++ b/contracts/liquidity_hub/pool-manager/src/contract.rs @@ -4,16 +4,10 @@ use crate::state::{Config, MANAGER_CONFIG, PAIRS, PAIR_COUNTER}; use crate::{liquidity, manager, queries, router, swap}; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; -use cosmwasm_std::{ - from_json, to_json_binary, Addr, Api, Binary, Deps, DepsMut, Env, MessageInfo, Response, -}; +use cosmwasm_std::{to_json_binary, Addr, Api, Binary, Deps, DepsMut, Env, MessageInfo, Response}; use cw2::set_contract_version; -use cw20::Cw20ReceiveMsg; use semver::Version; -use white_whale_std::pool_manager::{ - Cw20HookMsg, ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, -}; -use white_whale_std::pool_network::asset::{Asset, AssetInfo}; +use white_whale_std::pool_manager::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; use white_whale_std::pool_network::pair::FeatureToggle; // version info for migration info @@ -31,7 +25,6 @@ pub fn instantiate( let config: Config = Config { fee_collector_addr: deps.api.addr_validate(&msg.fee_collector_addr)?, owner: deps.api.addr_validate(&msg.owner)?, - token_code_id: msg.token_code_id, // We must set a creation fee on instantiation to prevent spamming of pools pool_creation_fee: msg.pool_creation_fee, feature_toggle: FeatureToggle { @@ -57,23 +50,20 @@ pub fn execute( ) -> Result { match msg { ExecuteMsg::CreatePair { - asset_infos, + asset_denoms, pool_fees, pair_type, - token_factory_lp, pair_identifier, } => manager::commands::create_pair( deps, env, info, - asset_infos, + asset_denoms, pool_fees, pair_type, - token_factory_lp, pair_identifier, ), ExecuteMsg::ProvideLiquidity { - assets, slippage_tolerance, receiver, pair_identifier, @@ -81,14 +71,13 @@ pub fn execute( deps, env, info, - assets, slippage_tolerance, receiver, pair_identifier, ), ExecuteMsg::Swap { offer_asset, - ask_asset, + ask_asset_denom, belief_price, max_spread, to, @@ -106,23 +95,23 @@ pub fn execute( info.clone(), info.sender, offer_asset, - ask_asset, + ask_asset_denom, belief_price, max_spread, to_addr, pair_identifier, ) } - ExecuteMsg::WithdrawLiquidity { - assets: _, - pair_identifier, - } => liquidity::commands::withdraw_liquidity( - deps, - env, - info.sender, - info.funds[0].amount, - pair_identifier, - ), + ExecuteMsg::WithdrawLiquidity { pair_identifier } => { + liquidity::commands::withdraw_liquidity( + deps, + env, + // TODO: why not sending info instead? there's no check that funds are sent + info.sender, + info.funds[0].amount, + pair_identifier, + ) + } ExecuteMsg::AddNativeTokenDecimals { denom, decimals } => { manager::commands::add_native_token_decimals(deps, env, denom, decimals) } @@ -137,17 +126,6 @@ pub fn execute( )?, ) } - ExecuteMsg::Receive(msg) => receive_cw20(deps, env, info, msg), - // ExecuteMsg::AssertMinimumReceive { asset_info, prev_balance, minimum_receive, receiver } => { - // router::commands::assert_minimum_receive( - // deps.as_ref(), - // asset_info, - // prev_balance, - // minimum_receive, - // deps.api.addr_validate(&receiver)?, - // ) - - // }, ExecuteMsg::ExecuteSwapOperations { operations, minimum_receive, @@ -198,74 +176,6 @@ fn optional_addr_validate( Ok(addr) } -/// Receives cw20 tokens. Used to swap and withdraw from the pool. -pub fn receive_cw20( - deps: DepsMut, - env: Env, - info: MessageInfo, - cw20_msg: Cw20ReceiveMsg, -) -> Result { - let contract_addr = info.sender.clone(); - let feature_toggle: FeatureToggle = MANAGER_CONFIG.load(deps.storage)?.feature_toggle; - - match from_json(&cw20_msg.msg) { - Ok(Cw20HookMsg::Swap { - ask_asset, - belief_price, - max_spread, - to, - pair_identifier, - }) => { - // check if the swap feature is enabled - if !feature_toggle.swaps_enabled { - return Err(ContractError::OperationDisabled("swap".to_string())); - } - - let to_addr = if let Some(to_addr) = to { - Some(deps.api.addr_validate(to_addr.as_str())?) - } else { - None - }; - - crate::swap::commands::swap( - deps, - env, - info, - Addr::unchecked(cw20_msg.sender), - Asset { - info: AssetInfo::Token { - contract_addr: contract_addr.to_string(), - }, - amount: cw20_msg.amount, - }, - ask_asset, - belief_price, - max_spread, - to_addr, - pair_identifier, - ) - } - Ok(Cw20HookMsg::WithdrawLiquidity { pair_identifier }) => { - // check if the withdrawal feature is enabled - if !feature_toggle.withdrawals_enabled { - return Err(ContractError::OperationDisabled( - "withdraw_liquidity".to_string(), - )); - } - - let sender_addr = deps.api.addr_validate(cw20_msg.sender.as_str())?; - crate::liquidity::commands::withdraw_liquidity( - deps, - env, - sender_addr, - cw20_msg.amount, - pair_identifier, - ) - } - Err(err) => Err(ContractError::Std(err)), - } -} - #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result { match msg { @@ -310,18 +220,18 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result Ok(to_json_binary(&get_swap_route( deps, - offer_asset_info, - ask_asset_info, + offer_asset_denom, + ask_asset_denom, )?)?), QueryMsg::SwapRoutes {} => Ok(to_json_binary(&get_swap_routes(deps)?)?), QueryMsg::Ownership {} => Ok(to_json_binary(&cw_ownable::get_ownership(deps.storage)?)?), - QueryMsg::Pair { pair_identifier } => { - Ok(to_json_binary(&PAIRS.load(deps.storage, pair_identifier)?)?) - } + QueryMsg::Pair { pair_identifier } => Ok(to_json_binary( + &PAIRS.load(deps.storage, &pair_identifier)?, + )?), } } diff --git a/contracts/liquidity_hub/pool-manager/src/error.rs b/contracts/liquidity_hub/pool-manager/src/error.rs index 163c799b..85f552b8 100644 --- a/contracts/liquidity_hub/pool-manager/src/error.rs +++ b/contracts/liquidity_hub/pool-manager/src/error.rs @@ -7,7 +7,6 @@ use cw_ownable::OwnershipError; use cw_utils::PaymentError; use semver::Version; use thiserror::Error; -use white_whale_std::pool_network::asset::AssetInfo; #[derive(Error, Debug, PartialEq)] pub enum ContractError { @@ -136,8 +135,8 @@ pub enum ContractError { #[error("Attempt to perform non-consecutive swap operation from previous output of {previous_output} to next input of {next_input}")] NonConsecutiveSwapOperations { - previous_output: AssetInfo, - next_input: AssetInfo, + previous_output: String, + next_input: String, }, #[error("Invalid pair creation fee, expected {expected} got {amount}")] diff --git a/contracts/liquidity_hub/pool-manager/src/helpers.rs b/contracts/liquidity_hub/pool-manager/src/helpers.rs index 01269f32..260b94d7 100644 --- a/contracts/liquidity_hub/pool-manager/src/helpers.rs +++ b/contracts/liquidity_hub/pool-manager/src/helpers.rs @@ -2,7 +2,7 @@ use std::cmp::Ordering; use std::ops::Mul; use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Decimal, Decimal256, StdError, StdResult, Storage, Uint128, Uint256}; +use cosmwasm_std::{Coin, Decimal, Decimal256, StdError, StdResult, Storage, Uint128, Uint256}; use white_whale_std::pool_network::asset::{Asset, AssetInfo, PairType}; use white_whale_std::pool_network::pair::PoolFee; @@ -426,8 +426,8 @@ pub struct OfferAmountComputation { pub fn assert_max_spread( belief_price: Option, max_spread: Option, - offer_asset: Asset, - return_asset: Asset, + offer_asset: Coin, + return_asset: Coin, spread_amount: Uint128, offer_decimal: u8, return_decimal: u8, @@ -492,7 +492,7 @@ pub fn assert_max_spread( pub fn assert_slippage_tolerance( slippage_tolerance: &Option, deposits: &[Uint128; 2], - pools: &[Asset; 2], + pools: &[Coin; 2], pair_type: PairType, amount: Uint128, pool_token_supply: Uint128, diff --git a/contracts/liquidity_hub/pool-manager/src/liquidity/commands.rs b/contracts/liquidity_hub/pool-manager/src/liquidity/commands.rs index bc204c88..090d5be4 100644 --- a/contracts/liquidity_hub/pool-manager/src/liquidity/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/liquidity/commands.rs @@ -1,5 +1,5 @@ -use cosmwasm_std::{to_json_binary, Addr, CosmosMsg, DepsMut, Env, MessageInfo, Response, WasmMsg}; -use white_whale_std::pool_network::asset::{Asset, AssetInfo, PairType}; +use cosmwasm_std::{Addr, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response}; +use white_whale_std::pool_network::asset::PairType; use crate::{ helpers::{self}, @@ -12,7 +12,6 @@ use crate::{ // After writing create_pair I see this can get quite verbose so attempting to // break it down into smaller modules which house some things like swap, liquidity etc use cosmwasm_std::{Decimal, OverflowError, Uint128}; -use cw20::Cw20ExecuteMsg; use white_whale_std::pool_network::{ asset::{get_total_share, MINIMUM_LIQUIDITY_AMOUNT}, U256, @@ -21,13 +20,10 @@ pub const MAX_ASSETS_PER_POOL: usize = 4; pub const LP_SYMBOL: &str = "uLP"; /// Gets the protocol fee amount for the given asset_id -pub fn get_protocol_fee_for_asset( - collected_protocol_fees: Vec, - asset_id: String, -) -> Uint128 { +pub fn get_protocol_fee_for_asset(collected_protocol_fees: Vec, asset_id: String) -> Uint128 { let protocol_fee_asset = collected_protocol_fees .iter() - .find(|&protocol_fee_asset| protocol_fee_asset.clone().get_id() == asset_id.clone()) + .find(|&protocol_fee_asset| protocol_fee_asset.clone().denom == asset_id.clone()) .cloned(); // get the protocol fee for the given pool_asset @@ -42,7 +38,6 @@ pub fn provide_liquidity( deps: DepsMut, env: Env, info: MessageInfo, - mut assets: Vec, slippage_tolerance: Option, receiver: Option, pair_identifier: String, @@ -54,32 +49,21 @@ pub fn provide_liquidity( "provide_liquidity".to_string(), )); } - // Verify native assets are sent - for asset in assets.iter() { - asset.assert_sent_native_token_balance(&info)?; - } + // Get the pair by the pair_identifier - let mut pair = get_pair_by_identifier(&deps.as_ref(), pair_identifier.clone())?; + let mut pair = get_pair_by_identifier(&deps.as_ref(), &pair_identifier)?; let mut pool_assets = pair.assets.clone(); + let mut assets = info.funds.clone(); let mut messages: Vec = vec![]; + //TODO verify that the assets sent in info match the ones from the pool!!! + for (i, pool) in assets.iter_mut().enumerate() { - // If the pool is token contract, then we need to execute TransferFrom msg to receive funds - if let AssetInfo::Token { contract_addr, .. } = &pool.info { - messages.push(CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: contract_addr.to_string(), - msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom { - owner: info.sender.to_string(), - recipient: env.contract.address.clone().to_string(), - amount: pool.amount, - })?, - funds: vec![], - })); - } // Increment the pool asset amount by the amount sent - pool_assets[i].amount = pool_assets[i].amount.checked_add(pool.amount).unwrap(); + pool_assets[i].amount = pool_assets[i].amount.checked_add(pool.amount)?; } + // After totting up the pool assets we need to check if any of them are zero if pool_assets.iter().any(|deposit| deposit.amount.is_zero()) { return Err(ContractError::InvalidZeroAmount {}); @@ -88,18 +72,15 @@ pub fn provide_liquidity( // // deduct protocol fee from pools // TODO: Replace with fill rewards msg let collected_protocol_fees = COLLECTABLE_PROTOCOL_FEES - .load(deps.storage, &pair.liquidity_token.to_string()) + .load(deps.storage, &pair.lp_denom) .unwrap_or_default(); for pool in pool_assets.iter_mut() { let protocol_fee = - get_protocol_fee_for_asset(collected_protocol_fees.clone(), pool.clone().get_id()); + get_protocol_fee_for_asset(collected_protocol_fees.clone(), pool.clone().denom); pool.amount = pool.amount.checked_sub(protocol_fee).unwrap(); } - let liquidity_token = match pair.liquidity_token.clone() { - AssetInfo::Token { contract_addr } => deps.api.addr_validate(&contract_addr)?.to_string(), - AssetInfo::NativeToken { denom } => denom, - }; + let liquidity_token = pair.lp_denom.clone(); // Compute share and other logic based on the number of assets let _share = Uint128::zero(); @@ -110,6 +91,7 @@ pub fn provide_liquidity( if total_share == Uint128::zero() { // Make sure at least MINIMUM_LIQUIDITY_AMOUNT is deposited to mitigate the risk of the first // depositor preventing small liquidity providers from joining the pool + let share = Uint128::new( (U256::from(pool_assets[0].amount.u128()) .checked_mul(U256::from(pool_assets[1].amount.u128())) @@ -129,10 +111,10 @@ pub fn provide_liquidity( } messages.push(white_whale_std::lp_common::mint_lp_token_msg( - liquidity_token, - &info.sender, + liquidity_token.clone(), &env.contract.address, - share, + &env.contract.address, + MINIMUM_LIQUIDITY_AMOUNT, )?); share @@ -173,13 +155,6 @@ pub fn provide_liquidity( total_share, )?; - messages.push(white_whale_std::lp_common::mint_lp_token_msg( - liquidity_token, - &info.sender, - &env.contract.address, - amount, - )?); - share } } @@ -192,8 +167,17 @@ pub fn provide_liquidity( // mint LP token to sender let receiver = receiver.unwrap_or_else(|| info.sender.to_string()); + + messages.push(white_whale_std::lp_common::mint_lp_token_msg( + liquidity_token, + &info.sender, + &env.contract.address, + share, + )?); + pair.assets = pool_assets.clone(); - PAIRS.save(deps.storage, pair_identifier, &pair)?; + PAIRS.save(deps.storage, &pair_identifier, &pair)?; + Ok(Response::new().add_messages(messages).add_attributes(vec![ ("action", "provide_liquidity"), ("sender", info.sender.as_str()), @@ -214,7 +198,7 @@ pub fn provide_liquidity( /// the swap fees accrued by its share of the pool. pub fn withdraw_liquidity( deps: DepsMut, - _env: Env, + env: Env, sender: Addr, amount: Uint128, pair_identifier: String, @@ -226,57 +210,49 @@ pub fn withdraw_liquidity( "withdraw_liquidity".to_string(), )); } + // Get the pair by the pair_identifier - let mut pair = get_pair_by_identifier(&deps.as_ref(), pair_identifier)?; + let mut pair = get_pair_by_identifier(&deps.as_ref(), &pair_identifier)?; + let liquidity_token = pair.lp_denom.clone(); - let liquidity_token = match pair.liquidity_token { - AssetInfo::Token { contract_addr } => contract_addr, - AssetInfo::NativeToken { denom } => denom, - }; // Get the total share of the pool let total_share = get_total_share(&deps.as_ref(), liquidity_token.clone())?; // Get the ratio of the amount to withdraw to the total share let share_ratio: Decimal = Decimal::from_ratio(amount, total_share); + // Use the ratio to calculate the amount of each pool asset to refund - let refund_assets: Result, OverflowError> = pair + let refund_assets: Vec = pair .assets .iter() .map(|pool_asset| { - // Calc fees and use FillRewards message - // let protocol_fee = get_protocol_fee_for_asset( - // collected_protocol_fees.clone(), - // pool_asset.clone().get_id(), - // ); - - // subtract the protocol_fee from the amount of the pool_asset let refund_amount = pool_asset.amount; - Ok(Asset { - info: pool_asset.info.clone(), + Ok(Coin { + denom: pool_asset.denom.clone(), amount: refund_amount * share_ratio, }) }) - .collect(); + .collect::, OverflowError>>()?; - let refund_assets = refund_assets?; let mut messages: Vec = vec![]; - // TODO: Combine the two below for loops to improve BigO time // Transfer the refund assets to the sender - for asset in refund_assets.clone() { - messages.push(asset.clone().into_msg(sender.clone())?); - } + messages.push(CosmosMsg::Bank(BankMsg::Send { + to_address: sender.to_string(), + amount: refund_assets.clone(), + })); + // Deduct balances on pair_info by the amount of each refund asset for (i, pool_asset) in pair.assets.iter_mut().enumerate() { - pool_asset.amount = pool_asset - .amount - .checked_sub(refund_assets[i].amount) - .unwrap(); + pool_asset.amount = pool_asset.amount.checked_sub(refund_assets[i].amount)?; } + + PAIRS.save(deps.storage, &pair_identifier, &pair)?; + // Burn the LP tokens messages.push(white_whale_std::lp_common::burn_lp_asset_msg( liquidity_token, - sender.clone(), + env.contract.address, amount, )?); diff --git a/contracts/liquidity_hub/pool-manager/src/manager/commands.rs b/contracts/liquidity_hub/pool-manager/src/manager/commands.rs index 47bfca4b..4c58470f 100644 --- a/contracts/liquidity_hub/pool-manager/src/manager/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/manager/commands.rs @@ -1,21 +1,12 @@ use cosmwasm_std::{ - attr, instantiate2_address, to_json_binary, Attribute, CodeInfoResponse, CosmosMsg, DepsMut, - Env, MessageInfo, Response, Uint128, WasmMsg, + attr, Attribute, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128, }; -use cw20::MinterResponse; -use sha2::{Digest, Sha256}; use white_whale_std::{ - pool_network::{ - asset::{Asset, AssetInfo, PairType}, - pair::PoolFee, - }, + pool_network::{asset::PairType, pair::PoolFee, querier::query_native_decimals}, whale_lair::fill_rewards_msg, }; -use crate::{ - state::{add_allow_native_token, get_pair_by_identifier, PAIR_COUNTER}, - token::InstantiateMsg as TokenInstantiateMsg, -}; +use crate::state::{add_allow_native_token, get_pair_by_identifier, PAIR_COUNTER}; use crate::{ state::{Config, MANAGER_CONFIG, PAIRS}, ContractError, @@ -82,29 +73,24 @@ pub const LP_SYMBOL: &str = "uLP"; /// # Ok(response) /// # } /// ``` +#[allow(unreachable_code)] #[allow(clippy::too_many_arguments)] pub fn create_pair( deps: DepsMut, env: Env, info: MessageInfo, - asset_infos: Vec, //Review just a vec + asset_denoms: Vec, //Review just a vec pool_fees: PoolFee, pair_type: PairType, - token_factory_lp: bool, pair_identifier: Option, ) -> Result { // Load config for pool creation fee let config: Config = MANAGER_CONFIG.load(deps.storage)?; // Check if fee was provided and is sufficient - let denom = match config.pool_creation_fee.info.clone() { - // this will never happen as the fee is always native, enforced when instantiating the contract - AssetInfo::Token { .. } => "".to_string(), - AssetInfo::NativeToken { denom } => denom, - }; if !config.pool_creation_fee.amount.is_zero() { // verify fee payment - let amount = cw_utils::must_pay(&info, denom.as_str())?; + let amount = cw_utils::must_pay(&info, &config.pool_creation_fee.denom)?; if amount < config.pool_creation_fee.amount { return Err(ContractError::InvalidPairCreationFee { amount, @@ -117,10 +103,7 @@ pub fn create_pair( let mut messages: Vec = vec![]; // send vault creation fee to whale lair - let creation_fee = vec![Asset { - info: config.pool_creation_fee.info, - amount: config.pool_creation_fee.amount, - }]; + let creation_fee = vec![config.pool_creation_fee]; // //send protocol fee to whale lair i.e the new fee_collector messages.push(fill_rewards_msg( @@ -128,18 +111,21 @@ pub fn create_pair( creation_fee, )?); - let asset_decimals_vec = asset_infos + let asset_decimals_vec = asset_denoms .iter() .map(|asset| { - asset - .query_decimals(env.contract.address.clone(), &deps.querier) - .unwrap() + query_native_decimals( + &deps.querier, + env.contract.address.clone(), + asset.to_string(), + ) }) - .collect::>(); + .collect::, _>>()?; + // Check if the asset infos are the same - if asset_infos + if asset_denoms .iter() - .any(|asset| asset_infos.iter().filter(|&a| a == asset).count() > 1) + .any(|asset| asset_denoms.iter().filter(|&a| a == asset).count() > 1) { return Err(ContractError::SameAsset {}); } @@ -153,10 +139,10 @@ pub fn create_pair( let identifier = pair_identifier.unwrap_or(pair_id.to_string()); // check if there is an existing vault with the given identifier - let pair = get_pair_by_identifier(&deps.as_ref(), identifier.clone()); + let pair = get_pair_by_identifier(&deps.as_ref(), &identifier); if pair.is_ok() { return Err(ContractError::PairExists { - asset_infos: asset_infos + asset_infos: asset_denoms .iter() .map(|i| i.to_string()) .collect::>() @@ -166,125 +152,51 @@ pub fn create_pair( } // prepare labels for creating the pair token with a meaningful name - let pair_label = asset_infos - .iter() - .map(|asset| asset.to_owned().get_label(&deps.as_ref())) - .collect::, _>>()? - .join("-"); + let pair_label = asset_denoms.join("-"); let mut attributes = Vec::::new(); // Convert all asset_infos into assets with 0 balances - let assets = asset_infos + let assets = asset_denoms .iter() - .map(|asset_info| Asset { - info: asset_info.clone(), + .map(|asset_info| Coin { + denom: asset_info.clone(), amount: Uint128::zero(), }) .collect::>(); - #[allow(unreachable_code)] - let pair_creation_msg = if token_factory_lp { - #[cfg(all( - not(feature = "token_factory"), - not(feature = "osmosis_token_factory"), - not(feature = "injective") - ))] + let lp_symbol = format!("{pair_label}.vault.{identifier}.{LP_SYMBOL}"); + let lp_asset = format!("{}/{}/{}", "factory", env.contract.address, lp_symbol); + + PAIRS.save( + deps.storage, + &identifier, + &PairInfo { + asset_denoms: asset_denoms.clone(), + pair_type: pair_type.clone(), + lp_denom: lp_asset.clone(), + asset_decimals: asset_decimals_vec, + pool_fees, + assets, + balances: vec![Uint128::zero(); asset_denoms.len()], + }, + )?; + + attributes.push(attr("lp_asset", lp_asset)); + + #[cfg(all( + not(feature = "token_factory"), + not(feature = "osmosis_token_factory"), + not(feature = "injective") + ))] + { return Err(ContractError::TokenFactoryNotEnabled {}); - let lp_symbol = format!("{pair_label}.vault.{identifier}.{LP_SYMBOL}"); - let denom = format!("{}/{}/{}", "factory", env.contract.address, lp_symbol); - let lp_asset = AssetInfo::NativeToken { denom }; - - PAIRS.save( - deps.storage, - identifier.clone(), - &PairInfo { - asset_infos: asset_infos.clone(), - pair_type: pair_type.clone(), - liquidity_token: lp_asset.clone(), - asset_decimals: asset_decimals_vec, - pool_fees, - assets, - balances: vec![Uint128::zero(); asset_infos.len()], - }, - )?; - - attributes.push(attr("lp_asset", lp_asset.to_string())); - - #[cfg(any( - feature = "token_factory", - feature = "osmosis_token_factory", - feature = "injective" - ))] - Ok(white_whale_std::tokenfactory::create_denom::create_denom( - env.contract.address, - lp_symbol, - )) - } else { - // Create the LP token using instantiate2 - let creator = deps.api.addr_canonicalize(env.contract.address.as_str())?; - let code_id = config.token_code_id; - let CodeInfoResponse { checksum, .. } = deps.querier.query_wasm_code_info(code_id)?; - let seed = format!( - "{}{}{}{}", - pair_label, - identifier, - info.sender.into_string(), - env.block.height - ); - let mut hasher = Sha256::new(); - hasher.update(seed.as_bytes()); - let salt = hasher.finalize().to_vec(); - - // Generate the LP address with instantiate2 - let pair_lp_address = deps - .api - .addr_humanize(&instantiate2_address(&checksum, &creator, &salt)?)?; - - let lp_asset = AssetInfo::Token { - contract_addr: pair_lp_address.into_string(), - }; - // Now, after generating an address using instantiate 2 we can save this into PAIRS - // We still need to call instantiate2 otherwise this asset will not exist, if it fails the saving will be reverted - - PAIRS.save( - deps.storage, - identifier.clone(), - &PairInfo { - asset_infos: asset_infos.clone(), - pair_type: pair_type.clone(), - liquidity_token: lp_asset.clone(), - asset_decimals: asset_decimals_vec, - assets, - pool_fees, - balances: vec![Uint128::zero(); asset_infos.len()], - }, - )?; - - attributes.push(attr("lp_asset", lp_asset.to_string())); - - let lp_token_name = format!("{pair_label}-LP"); - - Ok::(CosmosMsg::Wasm(WasmMsg::Instantiate2 { - admin: None, - code_id, - label: lp_token_name.to_owned(), - msg: to_json_binary(&TokenInstantiateMsg { - name: lp_token_name, - symbol: LP_SYMBOL.to_string(), - decimals: 6, - initial_balances: vec![], - mint: Some(MinterResponse { - minter: env.contract.address.to_string(), - cap: None, - }), - })?, - funds: vec![], - salt: salt.into(), - })) - }?; + } - messages.push(pair_creation_msg); + messages.push(white_whale_std::tokenfactory::create_denom::create_denom( + env.contract.address, + lp_symbol, + )); // increase pair counter PAIR_COUNTER.update(deps.storage, |mut counter| -> Result<_, ContractError> { diff --git a/contracts/liquidity_hub/pool-manager/src/queries.rs b/contracts/liquidity_hub/pool-manager/src/queries.rs index 23751957..5e221392 100644 --- a/contracts/liquidity_hub/pool-manager/src/queries.rs +++ b/contracts/liquidity_hub/pool-manager/src/queries.rs @@ -1,9 +1,9 @@ use std::cmp::Ordering; -use cosmwasm_std::{Decimal256, Deps, Env, Fraction, Order, StdResult, Uint128}; +use cosmwasm_std::{Coin, Decimal256, Deps, Env, Fraction, Order, StdResult, Uint128}; use white_whale_std::pool_manager::{SwapOperation, SwapRouteResponse}; use white_whale_std::pool_network::{ - asset::{Asset, AssetInfo, PairType}, + asset::PairType, factory::NativeTokenDecimalsResponse, pair::{ReverseSimulationResponse, SimulationResponse}, // router::SimulateSwapOperationsResponse, @@ -30,26 +30,26 @@ pub fn query_native_token_decimal( pub fn query_simulation( deps: Deps, _env: Env, - offer_asset: Asset, - _ask_asset: Asset, + offer_asset: Coin, + _ask_asset: Coin, pair_identifier: String, ) -> Result { - let pair_info = get_pair_by_identifier(&deps, pair_identifier)?; + let pair_info = get_pair_by_identifier(&deps, &pair_identifier)?; let pools = pair_info.assets.clone(); // determine what's the offer and ask pool based on the offer_asset - let offer_pool: Asset; - let ask_pool: Asset; + let offer_pool: Coin; + let ask_pool: Coin; let offer_decimal: u8; let ask_decimal: u8; let decimals = get_decimals(&pair_info); // We now have the pools and pair info; we can now calculate the swap // Verify the pool - if offer_asset.info.equal(&pools[0].info) { + if offer_asset.denom == pools[0].denom { offer_pool = pools[0].clone(); ask_pool = pools[1].clone(); offer_decimal = decimals[0]; ask_decimal = decimals[1]; - } else if offer_asset.info.equal(&pools[1].info) { + } else if offer_asset.denom == pools[1].denom { offer_pool = pools[1].clone(); ask_pool = pools[0].clone(); @@ -100,17 +100,17 @@ pub fn query_simulation( pub fn query_reverse_simulation( deps: Deps, _env: Env, - ask_asset: Asset, - _offer_asset: Asset, + ask_asset: Coin, + _offer_asset: Coin, pair_identifier: String, ) -> Result { - let pair_info = get_pair_by_identifier(&deps, pair_identifier)?; + let pair_info = get_pair_by_identifier(&deps, &pair_identifier)?; let pools = pair_info.assets.clone(); let decimals = get_decimals(&pair_info); - let offer_pool: Asset = pools[0].clone(); + let offer_pool: Coin = pools[0].clone(); let offer_decimal = decimals[0]; - let ask_pool: Asset = pools[1].clone(); + let ask_pool: Coin = pools[1].clone(); let ask_decimal = decimals[1]; let pool_fees = pair_info.pool_fees; @@ -233,13 +233,13 @@ pub fn get_swap_routes(deps: Deps) -> Result, ContractErr .map(|item| { let swap_info = item?; // Destructure key into (offer_asset, ask_asset) - let (offer_asset, ask_asset) = swap_info.0; + let (offer_asset_denom, ask_asset_denom) = swap_info.0; // Destructure value into vec of SwapOperation let swap_route = swap_info.1; Ok(SwapRouteResponse { - offer_asset, - ask_asset, + offer_asset_denom, + ask_asset_denom, swap_route, }) }) @@ -250,19 +250,16 @@ pub fn get_swap_routes(deps: Deps) -> Result, ContractErr pub fn get_swap_route( deps: Deps, - offer_asset_info: AssetInfo, - ask_asset_info: AssetInfo, + offer_asset_denom: String, + ask_asset_denom: String, ) -> Result, ContractError> { - let swap_route_key = SWAP_ROUTES.key(( - offer_asset_info.clone().get_label(&deps)?.as_str(), - ask_asset_info.clone().get_label(&deps)?.as_str(), - )); + let swap_route_key = SWAP_ROUTES.key((&offer_asset_denom, &ask_asset_denom)); swap_route_key .load(deps.storage) .map_err(|_| ContractError::NoSwapRouteForAssets { - offer_asset: offer_asset_info.to_string(), - ask_asset: ask_asset_info.to_string(), + offer_asset: offer_asset_denom, + ask_asset: ask_asset_denom, }) } diff --git a/contracts/liquidity_hub/pool-manager/src/router/commands.rs b/contracts/liquidity_hub/pool-manager/src/router/commands.rs index 46d122d5..909991a5 100644 --- a/contracts/liquidity_hub/pool-manager/src/router/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/router/commands.rs @@ -1,10 +1,7 @@ use cosmwasm_std::{ - coin, Addr, BankMsg, Decimal, DepsMut, MessageInfo, Response, StdError, Uint128, -}; -use white_whale_std::{ - pool_manager::SwapOperation, - pool_network::asset::{Asset, AssetInfo}, + attr, coin, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, MessageInfo, Response, Uint128, }; +use white_whale_std::pool_manager::SwapOperation; use crate::{state::MANAGER_CONFIG, swap::perform_swap::perform_swap, ContractError}; @@ -47,41 +44,19 @@ pub fn execute_swap_operations( // ensure that there was at least one operation // and retrieve the output token info - let target_asset_info = operations + let target_asset_denom = operations .last() .ok_or(ContractError::NoSwapOperationsProvided {})? .get_target_asset_info(); - let target_denom = match &target_asset_info { - AssetInfo::NativeToken { denom } => denom, - _ => { - return Err(ContractError::InvalidAsset { - asset: target_asset_info.to_string(), - }) - } - }; - let offer_asset_info = operations + let offer_asset_denom = operations .first() .ok_or(ContractError::NoSwapOperationsProvided {})? .get_input_asset_info(); - let offer_denom = match &offer_asset_info { - AssetInfo::NativeToken { denom } => denom, - _ => { - return Err(ContractError::InvalidAsset { - asset: offer_asset_info.to_string(), - }) - } - }; - let offer_asset = Asset { - amount: info - .funds - .iter() - .find(|token| &token.denom == offer_denom) - .ok_or(ContractError::MissingNativeSwapFunds { - denom: offer_denom.to_owned(), - })? - .amount, - info: offer_asset_info.to_owned(), + + let offer_asset = Coin { + denom: offer_asset_denom.to_string(), + amount: cw_utils::must_pay(&info, offer_asset_denom)?, }; assert_operations(operations.clone())?; @@ -101,59 +76,57 @@ pub fn execute_swap_operations( for operation in operations { match operation { SwapOperation::WhaleSwap { - token_in_info, + // TODO: do we need to use token_in_denom? + token_in_denom: _, pool_identifier, .. - } => match &token_in_info { - AssetInfo::NativeToken { .. } => { - // inside assert_operations() we have already checked that - // the output of each swap is the input of the next swap. - - let swap_result = perform_swap( - deps.branch(), - previous_swap_output.clone(), - pool_identifier, - None, - max_spread, - )?; - swap_attributes.push(( - "swap", - format!( - "in={}, out={}, burn_fee={}, protocol_fee={}, swap_fee={}", - previous_swap_output, - swap_result.return_asset, - swap_result.burn_fee_asset, - swap_result.protocol_fee_asset, - swap_result.swap_fee_asset - ), - )); - - // update the previous swap output - previous_swap_output = swap_result.return_asset; - - // add the fee messages - if !swap_result.burn_fee_asset.amount.is_zero() { - fee_messages.push(swap_result.burn_fee_asset.into_burn_msg()?); - } - if !swap_result.protocol_fee_asset.amount.is_zero() { - fee_messages.push( - swap_result - .protocol_fee_asset - .into_msg(config.fee_collector_addr.clone())?, - ); - } - if !swap_result.swap_fee_asset.amount.is_zero() { - fee_messages.push( - swap_result - .swap_fee_asset - .into_msg(config.fee_collector_addr.clone())?, - ); - } + } => { + // inside assert_operations() we have already checked that + // the output of each swap is the input of the next swap. + + let swap_result = perform_swap( + deps.branch(), + previous_swap_output.clone(), + pool_identifier, + None, + max_spread, + )?; + swap_attributes.push(( + "swap", + format!( + "in={}, out={}, burn_fee={}, protocol_fee={}, swap_fee={}", + previous_swap_output, + swap_result.return_asset, + swap_result.burn_fee_asset, + swap_result.protocol_fee_asset, + swap_result.swap_fee_asset + ), + )); + + // update the previous swap output + previous_swap_output = swap_result.return_asset; + + // add the fee messages + if !swap_result.burn_fee_asset.amount.is_zero() { + fee_messages.push(CosmosMsg::Bank(BankMsg::Burn { + amount: vec![swap_result.burn_fee_asset], + })); + } + + if !swap_result.protocol_fee_asset.amount.is_zero() { + fee_messages.push(CosmosMsg::Bank(BankMsg::Send { + to_address: config.fee_collector_addr.to_string(), + amount: vec![swap_result.protocol_fee_asset], + })); } - AssetInfo::Token { .. } => { - return Err(StdError::generic_err("cw20 token swaps are disabled"))? + + if !swap_result.swap_fee_asset.amount.is_zero() { + fee_messages.push(CosmosMsg::Bank(BankMsg::Send { + to_address: config.fee_collector_addr.to_string(), + amount: vec![swap_result.swap_fee_asset], + })); } - }, + } } } @@ -172,17 +145,17 @@ pub fn execute_swap_operations( Ok(Response::new() .add_message(BankMsg::Send { to_address: to.to_string(), - amount: vec![coin(receiver_balance.u128(), target_denom)], + amount: vec![coin(receiver_balance.u128(), target_asset_denom.clone())], }) .add_messages(fee_messages) .add_attributes(vec![ - ("action", "execute_swap_operations"), - ("sender", info.sender.as_str()), - ("receiver", to.as_str()), - ("offer_info", &offer_asset.info.to_string()), - ("offer_amount", &offer_asset.amount.to_string()), - ("return_info", &target_asset_info.to_string()), - ("return_amount", &receiver_balance.to_string()), + attr("action", "execute_swap_operations"), + attr("sender", info.sender.as_str()), + attr("receiver", to.as_str()), + attr("offer_info", offer_asset.denom), + attr("offer_amount", offer_asset.amount), + attr("return_denom", &target_asset_denom), + attr("return_amount", receiver_balance.to_string()), ]) .add_attributes(swap_attributes)) } diff --git a/contracts/liquidity_hub/pool-manager/src/state.rs b/contracts/liquidity_hub/pool-manager/src/state.rs index 07853117..a981adf1 100644 --- a/contracts/liquidity_hub/pool-manager/src/state.rs +++ b/contracts/liquidity_hub/pool-manager/src/state.rs @@ -1,16 +1,16 @@ use cosmwasm_schema::cw_serde; -use cosmwasm_std::{Addr, Api, Deps, Order, StdResult, Storage}; +use cosmwasm_std::{Addr, Api, Coin, Deps, Order, StdResult, Storage}; use cw_storage_plus::{Bound, Index, IndexList, IndexedMap, Item, Map, UniqueIndex}; use white_whale_std::pool_manager::{NPairInfo, SwapOperation}; -use white_whale_std::pool_network::asset::{Asset, AssetInfo, AssetInfoRaw}; +use white_whale_std::pool_network::asset::{Asset, AssetInfoRaw}; use white_whale_std::pool_network::pair::FeatureToggle; use crate::ContractError; pub const LP_SYMBOL: &str = "uLP"; -pub const PAIRS: IndexedMap = IndexedMap::new( +pub const PAIRS: IndexedMap<&str, NPairInfo, PairIndexes> = IndexedMap::new( "pairs", PairIndexes { - lp_asset: UniqueIndex::new(|v| v.liquidity_token.to_string(), "pairs__lp_asset"), + lp_asset: UniqueIndex::new(|v| v.lp_denom.to_string(), "pairs__lp_asset"), }, ); @@ -26,23 +26,13 @@ impl<'a> IndexList for PairIndexes<'a> { } } -/// Gets the pair given an lp asset as [AssetInfo] -pub fn get_pair_by_lp(deps: &Deps, lp_asset: &AssetInfo) -> Result { - Ok(PAIRS - .idx - .lp_asset - .item(deps.storage, lp_asset.to_string())? - .map_or_else(|| Err(ContractError::ExistingPair {}), Ok)? - .1) -} - /// Gets the pair given its identifier pub fn get_pair_by_identifier( deps: &Deps, - vault_identifier: String, + pair_identifier: &str, ) -> Result { PAIRS - .may_load(deps.storage, vault_identifier)? + .may_load(deps.storage, pair_identifier)? .ok_or(ContractError::ExistingPair {}) } @@ -64,7 +54,7 @@ pub fn get_decimals(pair_info: &NPairInfo) -> Vec { pub const SWAP_ROUTES: Map<(&str, &str), Vec> = Map::new("swap_routes"); // Dyanmic Maps for Fee and Pair info -pub const COLLECTABLE_PROTOCOL_FEES: Map<&str, Vec> = Map::new("collected_protocol_fees"); +pub const COLLECTABLE_PROTOCOL_FEES: Map<&str, Vec> = Map::new("collected_protocol_fees"); pub const TOTAL_COLLECTED_PROTOCOL_FEES: Map<&str, Vec> = Map::new("total_collected_protocol_fees"); pub const ALL_TIME_BURNED_FEES: Map<&str, Vec> = Map::new("all_time_burned_fees"); @@ -124,10 +114,8 @@ fn calc_range_start(start_after: Option<[AssetInfoRaw; 2]>) -> Option> { pub struct Config { pub fee_collector_addr: Addr, pub owner: Addr, - // The code ID for CW20 - pub token_code_id: u64, // We must set a creation fee on instantiation to prevent spamming of pools - pub pool_creation_fee: Asset, + pub pool_creation_fee: Coin, // Whether or not swaps, deposits, and withdrawals are enabled pub feature_toggle: FeatureToggle, } diff --git a/contracts/liquidity_hub/pool-manager/src/swap/commands.rs b/contracts/liquidity_hub/pool-manager/src/swap/commands.rs index 89cf4f7d..54bf7b51 100644 --- a/contracts/liquidity_hub/pool-manager/src/swap/commands.rs +++ b/contracts/liquidity_hub/pool-manager/src/swap/commands.rs @@ -1,5 +1,4 @@ -use cosmwasm_std::{Addr, CosmosMsg, DepsMut, Env, MessageInfo, Response}; -use white_whale_std::pool_network::asset::{Asset, AssetInfo}; +use cosmwasm_std::{Addr, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Response}; use crate::{state::MANAGER_CONFIG, ContractError}; @@ -16,26 +15,22 @@ pub fn swap( _env: Env, info: MessageInfo, sender: Addr, - offer_asset: Asset, - _ask_asset: AssetInfo, + offer_asset: Coin, + _ask_asset: String, belief_price: Option, max_spread: Option, to: Option, pair_identifier: String, ) -> Result { - // ensure only native tokens are being swapped - // in the future, we are removing cw20 tokens - if !offer_asset.is_native_token() { - return Err(ContractError::Unauthorized {}); - } - let config = MANAGER_CONFIG.load(deps.storage)?; // check if the swap feature is enabled if !config.feature_toggle.swaps_enabled { return Err(ContractError::OperationDisabled("swap".to_string())); } - offer_asset.assert_sent_native_token_balance(&info)?; + if cw_utils::one_coin(&info)? != offer_asset { + return Err(ContractError::AssetMismatch {}); + } // perform the swap let swap_result = perform_swap( @@ -52,32 +47,30 @@ pub fn swap( // first we add the swap result if !swap_result.return_asset.amount.is_zero() { - messages.push( - swap_result - .return_asset - .clone() - .into_msg(receiver.clone())?, - ); + messages.push(CosmosMsg::Bank(BankMsg::Send { + to_address: receiver.to_string(), + amount: vec![swap_result.return_asset.clone()], + })); } // then we add the fees if !swap_result.burn_fee_asset.amount.is_zero() { - messages.push(swap_result.burn_fee_asset.clone().into_burn_msg()?); + messages.push(CosmosMsg::Bank(BankMsg::Burn { + amount: vec![swap_result.burn_fee_asset.clone()], + })); } + if !swap_result.protocol_fee_asset.amount.is_zero() { - messages.push( - swap_result - .protocol_fee_asset - .clone() - .into_msg(config.fee_collector_addr.clone())?, - ); + messages.push(CosmosMsg::Bank(BankMsg::Send { + to_address: config.fee_collector_addr.to_string(), + amount: vec![swap_result.protocol_fee_asset.clone()], + })); } + if !swap_result.swap_fee_asset.amount.is_zero() { - messages.push( - swap_result - .swap_fee_asset - .clone() - .into_msg(config.fee_collector_addr)?, - ); + messages.push(CosmosMsg::Bank(BankMsg::Send { + to_address: config.fee_collector_addr.to_string(), + amount: vec![swap_result.swap_fee_asset.clone()], + })); } // 1. send collateral token from the contract to a user @@ -86,8 +79,8 @@ pub fn swap( ("action", "swap"), ("sender", sender.as_str()), ("receiver", receiver.as_str()), - ("offer_asset", &offer_asset.info.to_string()), - ("ask_asset", &swap_result.return_asset.info.to_string()), + ("offer_denom", &offer_asset.denom), + ("ask_denom", &swap_result.return_asset.denom), ("offer_amount", &offer_asset.amount.to_string()), ( "return_amount", diff --git a/contracts/liquidity_hub/pool-manager/src/swap/perform_swap.rs b/contracts/liquidity_hub/pool-manager/src/swap/perform_swap.rs index 146bd6a5..f3152a8f 100644 --- a/contracts/liquidity_hub/pool-manager/src/swap/perform_swap.rs +++ b/contracts/liquidity_hub/pool-manager/src/swap/perform_swap.rs @@ -1,5 +1,5 @@ -use cosmwasm_std::{Decimal, DepsMut, Uint128}; -use white_whale_std::{pool_manager::NPairInfo, pool_network::asset::Asset}; +use cosmwasm_std::{Coin, Decimal, DepsMut, Uint128}; +use white_whale_std::pool_manager::NPairInfo; use crate::{ helpers, @@ -9,13 +9,13 @@ use crate::{ pub struct SwapResult { /// The asset that should be returned to the user from the swap. - pub return_asset: Asset, + pub return_asset: Coin, /// The burn fee of `return_asset` associated with this swap transaction. - pub burn_fee_asset: Asset, + pub burn_fee_asset: Coin, /// The protocol fee of `return_asset` associated with this swap transaction. - pub protocol_fee_asset: Asset, + pub protocol_fee_asset: Coin, /// The swap fee of `return_asset` associated with this swap transaction. - pub swap_fee_asset: Asset, + pub swap_fee_asset: Coin, /// The pair that was traded. pub pair_info: NPairInfo, @@ -33,29 +33,29 @@ pub struct SwapResult { /// of each field in [`SwapResult`] (besides fields like `spread_amount`). pub fn perform_swap( deps: DepsMut, - offer_asset: Asset, + offer_asset: Coin, pair_identifier: String, belief_price: Option, max_spread: Option, ) -> Result { - let mut pair_info = get_pair_by_identifier(&deps.as_ref(), pair_identifier.clone())?; + let mut pair_info = get_pair_by_identifier(&deps.as_ref(), &pair_identifier)?; let pools = &pair_info.assets; // compute the offer and ask pool - let offer_pool: Asset; - let ask_pool: Asset; + let offer_pool: Coin; + let ask_pool: Coin; let offer_decimal: u8; let ask_decimal: u8; let decimals = &pair_info.asset_decimals; // calculate the swap // first, set relevant variables - if offer_asset.info.equal(&pools[0].info) { + if offer_asset.denom == pools[0].denom { offer_pool = pools[0].clone(); ask_pool = pools[1].clone(); offer_decimal = decimals[0]; ask_decimal = decimals[1]; - } else if offer_asset.info.equal(&pools[1].info) { + } else if offer_asset.denom == pools[1].denom { offer_pool = pools[1].clone(); ask_pool = pools[0].clone(); @@ -78,8 +78,8 @@ pub fn perform_swap( ask_decimal, )?; - let return_asset = Asset { - info: ask_pool.info.clone(), + let return_asset = Coin { + denom: ask_pool.denom.clone(), amount: swap_computation.return_amount, }; @@ -97,30 +97,30 @@ pub fn perform_swap( // State changes to the pairs balances // Deduct the return amount from the pool and add the offer amount to the pool - if offer_asset.info.equal(&pools[0].info) { + if offer_asset.denom == pools[0].denom { pair_info.assets[0].amount += offer_amount; pair_info.assets[1].amount -= swap_computation.return_amount; - PAIRS.save(deps.storage, pair_identifier, &pair_info)?; + PAIRS.save(deps.storage, &pair_identifier, &pair_info)?; } else { pair_info.assets[1].amount += offer_amount; pair_info.assets[0].amount -= swap_computation.return_amount; - PAIRS.save(deps.storage, pair_identifier, &pair_info)?; + PAIRS.save(deps.storage, &pair_identifier, &pair_info)?; } // TODO: Might be handy to make the below fees into a helper method // burn ask_asset from the pool - let burn_fee_asset = Asset { - info: ask_pool.info.clone(), + let burn_fee_asset = Coin { + denom: ask_pool.denom.clone(), amount: swap_computation.burn_fee_amount, }; // Prepare a message to send the protocol fee and the swap fee to the protocol fee collector - let protocol_fee_asset = Asset { - info: ask_pool.info.clone(), + let protocol_fee_asset = Coin { + denom: ask_pool.denom.clone(), amount: swap_computation.protocol_fee_amount, }; // Prepare a message to send the swap fee to the swap fee collector - let swap_fee_asset = Asset { - info: ask_pool.info, + let swap_fee_asset = Coin { + denom: ask_pool.denom, amount: swap_computation.swap_fee_amount, }; diff --git a/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs b/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs index 1c66be00..44f5a9f0 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/integration_tests.rs @@ -1,7 +1,7 @@ use crate::ContractError; use cosmwasm_std::{coin, Addr, Coin, Decimal, Uint128}; use white_whale_std::fee::Fee; -use white_whale_std::pool_network::asset::{Asset, AssetInfo, MINIMUM_LIQUIDITY_AMOUNT}; +use white_whale_std::pool_network::asset::MINIMUM_LIQUIDITY_AMOUNT; use white_whale_std::pool_network::pair::PoolFee; use super::suite::TestingSuite; @@ -13,26 +13,7 @@ use super::suite::TestingSuite; fn instantiate_normal() { let mut suite = TestingSuite::default_with_balances(vec![]); - suite.instantiate( - suite.senders[0].to_string(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::new(1_000u128), - }, - ); - - let _cw20_code_id = suite.create_cw20_token(); - suite.instantiate( - suite.senders[0].to_string(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::new(1_000u128), - }, - ); + suite.instantiate(suite.senders[0].to_string()); } #[test] @@ -97,26 +78,20 @@ fn verify_ownership() { }); } +// add features `token_factory` so tests are compiled using the correct flag #[test] fn deposit_and_withdraw_sanity_check() { let mut suite = TestingSuite::default_with_balances(vec![ - coin(1_000_000_001u128, "uwhale".to_string()), - coin(1_000_000_000u128, "uluna".to_string()), - coin(1_000_000_001u128, "uusd".to_string()), + coin(1_000_001u128, "uwhale".to_string()), + coin(1_000_001u128, "uluna".to_string()), + coin(1_000u128, "uusd".to_string()), ]); let creator = suite.creator(); let _other = suite.senders[1].clone(); let _unauthorized = suite.senders[2].clone(); - // Asset infos with uwhale and uluna - let asset_infos = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; + // Asset denoms with uwhale and uluna + let asset_denoms = vec!["uwhale".to_string(), "uluna".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee #[cfg(not(feature = "osmosis"))] @@ -150,15 +125,14 @@ fn deposit_and_withdraw_sanity_check() { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .create_pair( creator.clone(), - asset_infos, + asset_denoms, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -166,196 +140,92 @@ fn deposit_and_withdraw_sanity_check() { }, ); + let contract_addr = suite.pool_manager_addr.clone(); + let lp_denom = suite.get_lp_denom("whale-uluna".to_string()); + // Lets try to add liquidity - suite.provide_liquidity( - creator.clone(), - "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { + suite + .provide_liquidity( + creator.clone(), + "whale-uluna".to_string(), + vec![ + Coin { denom: "uwhale".to_string(), + amount: Uint128::from(1_000_000u128), }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { + Coin { denom: "uluna".to_string(), + amount: Uint128::from(1_000_000u128), }, - amount: Uint128::from(1000000u128), - }, - ], - vec![ - Coin { - denom: "uwhale".to_string(), - amount: Uint128::from(1000000u128), + ], + |result| { + // Ensure we got 999_000 in the response which is 1_000_000 less the initial liquidity amount + assert!(result.unwrap().events.iter().any(|event| { + event.attributes.iter().any(|attr| { + attr.key == "share" + && attr.value + == (Uint128::from(1_000_000u128) - MINIMUM_LIQUIDITY_AMOUNT) + .to_string() + }) + })); }, - Coin { - denom: "uluna".to_string(), - amount: Uint128::from(1000000u128), - }, - ], - |result| { - // Ensure we got 999000 in the response which is 1mil less the initial liquidity amount - for event in result.unwrap().events { - println!("{:?}", event); - } - }, - ); - - suite.query_amount_of_lp_token("whale-uluna".to_string(), creator.to_string(), |result| { - assert_eq!( - result.unwrap(), - Uint128::from(1000000u128) - MINIMUM_LIQUIDITY_AMOUNT - ); - }); -} - -#[test] -fn deposit_and_withdraw_cw20() { - let mut suite = TestingSuite::default_with_balances(vec![ - coin(1_000_000_001u128, "uwhale".to_string()), - coin(1_000_000_000u128, "uluna".to_string()), - coin(1_000_000_001u128, "uusd".to_string()), - ]); - let creator = suite.creator(); - let _other = suite.senders[1].clone(); - let _unauthorized = suite.senders[2].clone(); - // Asset infos with uwhale and cw20 - - let _cw20_code_id = suite.create_cw20_token(); - - let asset_infos = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::Token { - contract_addr: suite.cw20_tokens[0].to_string(), - }, - ]; - - // Default Pool fees white_whale_std::pool_network::pair::PoolFee - #[cfg(not(feature = "osmosis"))] - let pool_fees = PoolFee { - protocol_fee: Fee { - share: Decimal::zero(), - }, - swap_fee: Fee { - share: Decimal::zero(), - }, - burn_fee: Fee { - share: Decimal::zero(), - }, - }; - - #[cfg(feature = "osmosis")] - let pool_fees = PoolFee { - protocol_fee: Fee { - share: Decimal::zero(), - }, - swap_fee: Fee { - share: Decimal::zero(), - }, - burn_fee: Fee { - share: Decimal::zero(), - }, - osmosis_fee: Fee { - share: Decimal::zero(), - }, - }; + ) + // creator should have 999_000 LP shares (1M - MINIMUM_LIQUIDITY_AMOUNT) + .query_all_balances(creator.to_string(), |result| { + let balances = result.unwrap(); + assert!(balances.iter().any(|coin| { + coin.denom == lp_denom && coin.amount == Uint128::from(999_000u128) + })); + }) + // contract should have 1_000 LP shares (MINIMUM_LIQUIDITY_AMOUNT) + .query_all_balances(contract_addr.to_string(), |result| { + let balances = result.unwrap(); + // check that balances has 999_000 factory/migaloo1wug8sewp6cedgkmrmvhl3lf3tulagm9hnvy8p0rppz9yjw0g4wtqvk723g/uwhale-uluna.vault.whale-uluna.uLP + assert!(balances.iter().any(|coin| { + coin.denom == lp_denom.clone() && coin.amount == MINIMUM_LIQUIDITY_AMOUNT + })); + }); - // Create a pair + // Lets try to withdraw liquidity suite - .instantiate_with_cw20_lp_token() - .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) - .create_pair( + .withdraw_liquidity( creator.clone(), - asset_infos, - pool_fees, - white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, - None, - vec![coin(1000, "uusd")], + "whale-uluna".to_string(), + vec![Coin { + denom: lp_denom.clone(), + amount: Uint128::from(999_000u128), + }], |result| { - result.unwrap(); - }, - ); - suite.increase_allowance( - creator.clone(), - suite.cw20_tokens[0].clone(), - Uint128::from(1000000u128), - suite.pool_manager_addr.clone(), - ); - // Lets try to add liquidity - suite.provide_liquidity( - creator.clone(), - "0".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::Token { - contract_addr: suite.cw20_tokens[0].to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], - vec![Coin { - denom: "uwhale".to_string(), - amount: Uint128::from(1000000u128), - }], - |result| { - // Ensure we got 999000 in the response which is 1mil less the initial liquidity amount - for event in result.unwrap().events { - println!("{:?}", event); - } - }, - ); - - suite.query_amount_of_lp_token("0".to_string(), creator.to_string(), |result| { - assert_eq!( - result.unwrap(), - Uint128::from(1000000u128) - MINIMUM_LIQUIDITY_AMOUNT - ); - }); - let assets = vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::Token { - contract_addr: suite.cw20_tokens[0].to_string(), + // we're trading 999_000 shares for 1_000_000 of our liquidity + assert!(result.unwrap().events.iter().any(|event| { + event.attributes.iter().any(|attr| { + attr.key == "withdrawn_share" + && attr.value + == (Uint128::from(1_000_000u128) - MINIMUM_LIQUIDITY_AMOUNT) + .to_string() + }) + })); }, - amount: Uint128::from(1000000u128), - }, - ]; - - let lp_token = suite.query_lp_token("0".to_string(), creator.to_string()); - let lp_token_addr = match lp_token { - AssetInfo::Token { contract_addr } => contract_addr, - _ => { - panic!("Liquidity token is not a cw20 token") - } - }; - suite.withdraw_liquidity_cw20( - creator.clone(), - "0".to_string(), - assets, - Uint128::from(1000000u128) - MINIMUM_LIQUIDITY_AMOUNT, - Addr::unchecked(lp_token_addr), - |result| { - println!("{:?}", result); - for event in result.unwrap().events { - println!("{:?}", event); - } - }, - ); + ) + // creator should have 0 LP shares in the contract and 0 LP shares in their account balance + .query_amount_of_lp_token("whale-uluna".to_string(), creator.to_string(), |result| { + assert_eq!(result.unwrap(), Uint128::zero()); + }) + .query_balance(creator.to_string(), lp_denom, |result| { + assert_eq!(result.unwrap().amount, Uint128::zero()); + }) + // creator should 999_000 uwhale and 999_000 uluna (1M - MINIMUM_LIQUIDITY_AMOUNT) + .query_all_balances(creator.to_string(), |result| { + let balances = result.unwrap(); + assert!(balances.iter().any(|coin| { + coin.denom == "uwhale".to_string() + && coin.amount == Uint128::from(1_000_000u128) - MINIMUM_LIQUIDITY_AMOUNT + })); + assert!(balances.iter().any(|coin| { + coin.denom == "uluna".to_string() + && coin.amount == Uint128::from(1_000_000u128) - MINIMUM_LIQUIDITY_AMOUNT + })); + }); } mod pair_creation_failures { @@ -374,16 +244,7 @@ mod pair_creation_failures { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and cw20 - let _cw20_code_id = suite.create_cw20_token(); - - let asset_infos = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::Token { - contract_addr: suite.cw20_tokens[0].to_string(), - }, - ]; + let asset_infos = vec!["uwhale".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee #[cfg(not(feature = "osmosis"))] @@ -416,14 +277,13 @@ mod pair_creation_failures { }; // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .create_pair( creator.clone(), asset_infos, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, None, vec![coin(90, "uusd")], |result| { @@ -449,16 +309,7 @@ mod pair_creation_failures { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and cw20 - let _cw20_code_id = suite.create_cw20_token(); - - let asset_infos = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::Token { - contract_addr: suite.cw20_tokens[0].to_string(), - }, - ]; + let asset_infos = vec!["uwhale".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee #[cfg(not(feature = "osmosis"))] @@ -492,14 +343,13 @@ mod pair_creation_failures { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .create_pair( creator.clone(), asset_infos.clone(), pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("mycoolpair".to_string()), vec![coin(1000, "uusd")], |result| { @@ -511,12 +361,10 @@ mod pair_creation_failures { asset_infos, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("mycoolpair".to_string()), vec![coin(1000, "uusd")], |result| { let err = result.unwrap_err().downcast::().unwrap(); - println!("{:?}", err); match err { ContractError::PairExists { .. } => {} _ => panic!("Wrong error type, should return ContractError::PairExists"), @@ -542,23 +390,8 @@ mod router { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and uluna - let first_pair = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; - - let second_pair = vec![ - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ]; + let first_pair = vec!["uwhale".to_string(), "uluna".to_string()]; + let second_pair = vec!["uluna".to_string(), "uusd".to_string()]; #[cfg(not(feature = "osmosis"))] let pool_fees = PoolFee { @@ -590,7 +423,7 @@ mod router { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) @@ -599,7 +432,6 @@ mod router { first_pair, pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -611,7 +443,6 @@ mod router { second_pair, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("uluna-uusd".to_string()), vec![coin(1000, "uusd")], |result| { @@ -623,20 +454,6 @@ mod router { suite.provide_liquidity( creator.clone(), "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uwhale".to_string(), @@ -658,20 +475,6 @@ mod router { suite.provide_liquidity( creator.clone(), "uluna-uusd".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uluna".to_string(), @@ -694,21 +497,13 @@ mod router { let swap_operations = vec![ white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - token_out_info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + token_in_denom: "uwhale".to_string(), + token_out_denom: "uluna".to_string(), pool_identifier: "whale-uluna".to_string(), }, white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - token_out_info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, + token_in_denom: "uluna".to_string(), + token_out_denom: "uusd".to_string(), pool_identifier: "uluna-uusd".to_string(), }, ]; @@ -779,23 +574,8 @@ mod router { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and uluna - let first_pair = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; - - let second_pair = vec![ - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ]; + let first_pair = vec!["uwhale".to_string(), "uluna".to_string()]; + let second_pair = vec!["uluna".to_string(), "uusd".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee // Protocol fee is 0.01% and swap fee is 0.02% and burn fee is 0% @@ -830,7 +610,7 @@ mod router { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) @@ -839,7 +619,6 @@ mod router { first_pair, pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -851,7 +630,6 @@ mod router { second_pair, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("uluna-uusd".to_string()), vec![coin(1000, "uusd")], |result| { @@ -863,20 +641,6 @@ mod router { suite.provide_liquidity( creator.clone(), "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uwhale".to_string(), @@ -898,20 +662,6 @@ mod router { suite.provide_liquidity( creator.clone(), "uluna-uusd".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uluna".to_string(), @@ -960,23 +710,8 @@ mod router { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and uluna - let first_pair = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; - - let second_pair = vec![ - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ]; + let first_pair = vec!["uwhale".to_string(), "uluna".to_string()]; + let second_pair = vec!["uluna".to_string(), "uusd".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee // Protocol fee is 0.01% and swap fee is 0.02% and burn fee is 0% @@ -1011,7 +746,7 @@ mod router { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) @@ -1020,7 +755,6 @@ mod router { first_pair, pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -1032,7 +766,6 @@ mod router { second_pair, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("uluna-uusd".to_string()), vec![coin(1000, "uusd")], |result| { @@ -1044,20 +777,6 @@ mod router { suite.provide_liquidity( creator.clone(), "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uwhale".to_string(), @@ -1079,20 +798,6 @@ mod router { suite.provide_liquidity( creator.clone(), "uluna-uusd".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uluna".to_string(), @@ -1115,21 +820,13 @@ mod router { let swap_operations = vec![ white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - token_out_info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + token_in_denom: "uwhale".to_string(), + token_out_denom: "uluna".to_string(), pool_identifier: "whale-uluna".to_string(), }, white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - token_out_info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + token_in_denom: "uwhale".to_string(), + token_out_denom: "uluna".to_string(), pool_identifier: "whale-uluna".to_string(), }, ]; @@ -1145,12 +842,8 @@ mod router { assert_eq!( result.unwrap_err().downcast_ref::(), Some(&ContractError::NonConsecutiveSwapOperations { - previous_output: AssetInfo::NativeToken { - denom: "uluna".to_string() - }, - next_input: AssetInfo::NativeToken { - denom: "uwhale".to_string() - } + previous_output: "uluna".to_string(), + next_input: "uwhale".to_string() }) ); }, @@ -1169,23 +862,8 @@ mod router { let unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and uluna - let first_pair = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; - - let second_pair = vec![ - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ]; + let first_pair = vec!["uwhale".to_string(), "uluna".to_string()]; + let second_pair = vec!["uluna".to_string(), "uusd".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee // Protocol fee is 0.01% and swap fee is 0.02% and burn fee is 0% @@ -1220,7 +898,7 @@ mod router { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) @@ -1229,7 +907,6 @@ mod router { first_pair, pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -1241,7 +918,6 @@ mod router { second_pair, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("uluna-uusd".to_string()), vec![coin(1000, "uusd")], |result| { @@ -1254,20 +930,6 @@ mod router { suite.provide_liquidity( creator.clone(), "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(liquidity_amount), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(liquidity_amount), - }, - ], vec![ Coin { denom: "uwhale".to_string(), @@ -1289,20 +951,6 @@ mod router { suite.provide_liquidity( creator.clone(), "uluna-uusd".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(liquidity_amount), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - amount: Uint128::from(liquidity_amount), - }, - ], vec![ Coin { denom: "uluna".to_string(), @@ -1325,21 +973,13 @@ mod router { let swap_operations = vec![ white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - token_out_info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + token_in_denom: "uwhale".to_string(), + token_out_denom: "uluna".to_string(), pool_identifier: "whale-uluna".to_string(), }, white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - token_out_info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, + token_in_denom: "uluna".to_string(), + token_out_denom: "uusd".to_string(), pool_identifier: "uluna-uusd".to_string(), }, ]; @@ -1447,23 +1087,8 @@ mod router { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and uluna - let first_pair = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; - - let second_pair = vec![ - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - ]; + let first_pair = vec!["uwhale".to_string(), "uluna".to_string()]; + let second_pair = vec!["uluna".to_string(), "uusd".to_string()]; #[cfg(not(feature = "osmosis"))] let pool_fees = PoolFee { @@ -1495,7 +1120,7 @@ mod router { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .add_native_token_decimals(creator.clone(), "uusd".to_string(), 6) @@ -1504,7 +1129,6 @@ mod router { first_pair, pool_fees.clone(), white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -1516,7 +1140,6 @@ mod router { second_pair, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("uluna-uusd".to_string()), vec![coin(1000, "uusd")], |result| { @@ -1528,20 +1151,6 @@ mod router { suite.provide_liquidity( creator.clone(), "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uwhale".to_string(), @@ -1563,20 +1172,6 @@ mod router { suite.provide_liquidity( creator.clone(), "uluna-uusd".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uluna".to_string(), @@ -1599,21 +1194,13 @@ mod router { let swap_operations = vec![ white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - token_out_info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + token_in_denom: "uwhale".to_string(), + token_out_denom: "uluna".to_string(), pool_identifier: "whale-uluna".to_string(), }, white_whale_std::pool_manager::SwapOperation::WhaleSwap { - token_in_info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - token_out_info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, + token_in_denom: "uluna".to_string(), + token_out_denom: "uusd".to_string(), pool_identifier: "uluna-uusd".to_string(), }, ]; @@ -1668,14 +1255,7 @@ mod swapping { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and uluna - let asset_infos = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; + let asset_infos = vec!["uwhale".to_string(), "uluna".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee // Protocol fee is 0.01% and swap fee is 0.02% and burn fee is 0% @@ -1710,7 +1290,7 @@ mod swapping { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .create_pair( @@ -1718,7 +1298,6 @@ mod swapping { asset_infos, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -1730,20 +1309,6 @@ mod swapping { suite.provide_liquidity( creator.clone(), "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uwhale".to_string(), @@ -1755,26 +1320,31 @@ mod swapping { }, ], |result| { - // Ensure we got 999000 in the response which is 1mil less the initial liquidity amount - for event in result.unwrap().events { - println!("{:?}", event); - } + // Ensure we got 999_000 in the response which is 1mil less the initial liquidity amount + assert!(result.unwrap().events.iter().any(|event| { + event.attributes.iter().any(|attr| { + attr.key == "share" + && attr.value + == (Uint128::from(1_000_000u128) - MINIMUM_LIQUIDITY_AMOUNT) + .to_string() + }) + })); }, ); let simulated_return_amount = RefCell::new(Uint128::zero()); suite.query_simulation( "whale-uluna".to_string(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + Coin { + denom: "uwhale".to_string(), amount: Uint128::from(1000u128), }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + "uluna".to_string(), |result| { - println!("{:?}", result); + // Ensure that the return amount is 1_000 minus spread + assert_eq!( + result.as_ref().unwrap().return_amount + result.as_ref().unwrap().spread_amount, + Uint128::from(1000u128) + ); *simulated_return_amount.borrow_mut() = result.unwrap().return_amount; }, ); @@ -1782,15 +1352,11 @@ mod swapping { // Now lets try a swap suite.swap( creator.clone(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + Coin { + denom: "uwhale".to_string(), amount: Uint128::from(1000u128), }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + "uluna".to_string(), None, None, None, @@ -1833,13 +1399,9 @@ mod swapping { let simulated_offer_amount = RefCell::new(Uint128::zero()); suite.query_reverse_simulation( "whale-uluna".to_string(), - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + "uluna".to_string(), + Coin { + denom: "uwhale".to_string(), amount: Uint128::from(1000u128), }, |result| { @@ -1851,15 +1413,11 @@ mod swapping { // Now lets try a swap suite.swap( creator.clone(), - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + Coin { + denom: "uluna".to_string(), amount: Uint128::from(simulated_offer_amount.borrow().u128()), }, - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + "uwhale".to_string(), None, None, None, @@ -1909,14 +1467,7 @@ mod swapping { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and uluna - let asset_infos = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; + let asset_infos = vec!["uwhale".to_string(), "uluna".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee // Protocol fee is 0.01% and swap fee is 0.02% and burn fee is 0% @@ -1951,7 +1502,7 @@ mod swapping { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .create_pair( @@ -1959,7 +1510,6 @@ mod swapping { asset_infos, pool_fees, white_whale_std::pool_network::asset::PairType::StableSwap { amp: 100 }, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -1971,20 +1521,6 @@ mod swapping { suite.provide_liquidity( creator.clone(), "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000000u128), - }, - ], vec![ Coin { denom: "uwhale".to_string(), @@ -2005,15 +1541,11 @@ mod swapping { let simulated_return_amount = RefCell::new(Uint128::zero()); suite.query_simulation( "whale-uluna".to_string(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + Coin { + denom: "uwhale".to_string(), amount: Uint128::from(1000u128), }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + "uluna".to_string(), |result| { println!("{:?}", result); *simulated_return_amount.borrow_mut() = result.unwrap().return_amount; @@ -2023,15 +1555,11 @@ mod swapping { // Now lets try a swap suite.swap( creator.clone(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + Coin { + denom: "uwhale".to_string(), amount: Uint128::from(1000u128), }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + "uluna".to_string(), None, None, None, @@ -2074,13 +1602,9 @@ mod swapping { let simulated_offer_amount = RefCell::new(Uint128::zero()); suite.query_reverse_simulation( "whale-uluna".to_string(), - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + "uluna".to_string(), + Coin { + denom: "uwhale".to_string(), amount: Uint128::from(1000u128), }, |result| { @@ -2092,15 +1616,11 @@ mod swapping { // Now lets try a swap suite.swap( creator.clone(), - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + Coin { + denom: "uluna".to_string(), amount: Uint128::from(simulated_offer_amount.borrow().u128()), }, - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + "uwhale".to_string(), None, None, None, @@ -2150,14 +1670,7 @@ mod swapping { let _unauthorized = suite.senders[2].clone(); // Asset infos with uwhale and uluna - let asset_infos = vec![ - AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - ]; + let asset_infos = vec!["uwhale".to_string(), "uluna".to_string()]; // Default Pool fees white_whale_std::pool_network::pair::PoolFee // Protocol fee is 0.001% and swap fee is 0.002% and burn fee is 0% @@ -2192,7 +1705,7 @@ mod swapping { // Create a pair suite - .instantiate_with_cw20_lp_token() + .instantiate_default() .add_native_token_decimals(creator.clone(), "uwhale".to_string(), 6) .add_native_token_decimals(creator.clone(), "uluna".to_string(), 6) .create_pair( @@ -2200,7 +1713,6 @@ mod swapping { asset_infos, pool_fees, white_whale_std::pool_network::asset::PairType::ConstantProduct, - false, Some("whale-uluna".to_string()), vec![coin(1000, "uusd")], |result| { @@ -2212,20 +1724,6 @@ mod swapping { suite.provide_liquidity( creator.clone(), "whale-uluna".to_string(), - vec![ - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::from(1000_000000u128), - }, - Asset { - info: AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, - amount: Uint128::from(1000_000000u128), - }, - ], vec![ Coin { denom: "uwhale".to_string(), @@ -2259,15 +1757,11 @@ mod swapping { // Total -> 9,900,693 (Returned Amount) + 99,010 (Spread)(0.009x%) + 198 (Swap Fee) + 99 (Protocol Fee) = 10,000,000 uLUNA suite.swap( creator.clone(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, + Coin { + denom: "uwhale".to_string(), amount: Uint128::from(10000000u128), }, - AssetInfo::NativeToken { - denom: "uluna".to_string(), - }, + "uluna".to_string(), None, Some(Decimal::percent(1)), None, diff --git a/contracts/liquidity_hub/pool-manager/src/tests/mock_querier.rs b/contracts/liquidity_hub/pool-manager/src/tests/mock_querier.rs index 15189973..fe5eff24 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/mock_querier.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/mock_querier.rs @@ -3,20 +3,27 @@ use std::iter::FromIterator; use std::marker::PhantomData; use std::panic; -use cosmwasm_std::testing::{MockQuerier, MockApi, MockStorage, MOCK_CONTRACT_ADDR}; +use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - from_binary, from_slice, to_binary, Coin, ContractInfoResponse, ContractResult, Empty, - OwnedDeps, Querier, QuerierResult, QueryRequest, SystemError, SystemResult, Uint128, WasmQuery, CodeInfoResponse, HexBinary, Addr, + from_binary, from_slice, to_binary, Addr, CodeInfoResponse, Coin, ContractInfoResponse, + ContractResult, Empty, HexBinary, OwnedDeps, Querier, QuerierResult, QueryRequest, SystemError, + SystemResult, Uint128, WasmQuery, }; use cw20::{BalanceResponse as Cw20BalanceResponse, Cw20QueryMsg, TokenInfoResponse}; -use white_whale_std::pool_network::temp_mock_api::MockSimpleApi; use cw_multi_test::addons::{MockAddressGenerator, MockApiBech32}; use white_whale_std::pool_network::asset::{Asset, AssetInfo, PairInfo, PairType, TrioInfo}; -use white_whale_std::pool_network::factory::{NativeTokenDecimalsResponse, QueryMsg as FactoryQueryMsg}; -use white_whale_std::pool_network::pair::{PoolResponse as PairPoolResponse, QueryMsg as PairQueryMsg, self}; +use white_whale_std::pool_network::factory::{ + NativeTokenDecimalsResponse, QueryMsg as FactoryQueryMsg, +}; +use white_whale_std::pool_network::pair::{ + self, PoolResponse as PairPoolResponse, QueryMsg as PairQueryMsg, +}; use white_whale_std::pool_network::pair::{ReverseSimulationResponse, SimulationResponse}; +use white_whale_std::pool_network::temp_mock_api::MockSimpleApi; use white_whale_std::pool_network::trio; -use white_whale_std::pool_network::trio::{PoolResponse as TrioPoolResponse, QueryMsg as TrioQueryMsg}; +use white_whale_std::pool_network::trio::{ + PoolResponse as TrioPoolResponse, QueryMsg as TrioQueryMsg, +}; /// mock_dependencies is a drop-in replacement for cosmwasm_std::testing::mock_dependencies /// this uses our CustomQuerier. pub fn mock_dependencies( @@ -39,7 +46,6 @@ pub struct WasmMockQuerier { pool_factory_querier: PoolFactoryQuerier, } - #[derive(Clone, Default)] pub struct TokenQuerier { // this lets us iterate over all pairs that match the first string @@ -121,57 +127,57 @@ impl Querier for WasmMockQuerier { impl WasmMockQuerier { pub fn handle_query(&self, request: &QueryRequest) -> QuerierResult { match &request { - QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => { - match from_binary(msg) { - Ok(white_whale_std::pool_manager::QueryMsg::Pair { pair_identifier }) => { - - match self - .pool_factory_querier - .pairs - .get(&pair_identifier) - { - Some(v) => SystemResult::Ok(ContractResult::Ok(to_binary(v).unwrap())), - None => SystemResult::Err(SystemError::InvalidRequest { - error: "No pair info exists".to_string(), - request: msg.as_slice().into(), - }), - } + QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => match from_binary(msg) { + Ok(white_whale_std::pool_manager::QueryMsg::Pair { pair_identifier }) => { + match self.pool_factory_querier.pairs.get(&pair_identifier) { + Some(v) => SystemResult::Ok(ContractResult::Ok(to_binary(v).unwrap())), + None => SystemResult::Err(SystemError::InvalidRequest { + error: "No pair info exists".to_string(), + request: msg.as_slice().into(), + }), } - Ok(white_whale_std::pool_manager::QueryMsg::NativeTokenDecimals { denom }) => { - match self.pool_factory_querier.native_token_decimals.get(&denom) { - Some(decimals) => SystemResult::Ok(ContractResult::Ok( - to_binary(&NativeTokenDecimalsResponse { - decimals: *decimals, - }) - .unwrap(), - )), - None => SystemResult::Err(SystemError::InvalidRequest { - error: "No decimal info exist".to_string(), - request: msg.as_slice().into(), - }), - } + } + Ok(white_whale_std::pool_manager::QueryMsg::NativeTokenDecimals { denom }) => { + match self.pool_factory_querier.native_token_decimals.get(&denom) { + Some(decimals) => SystemResult::Ok(ContractResult::Ok( + to_binary(&NativeTokenDecimalsResponse { + decimals: *decimals, + }) + .unwrap(), + )), + None => SystemResult::Err(SystemError::InvalidRequest { + error: "No decimal info exist".to_string(), + request: msg.as_slice().into(), + }), } - _ => match from_binary(msg) { - - Ok(white_whale_std::pool_manager::QueryMsg::Simulation { offer_asset, ask_asset, pair_identifier }) => { - SystemResult::Ok(ContractResult::from(to_binary(&SimulationResponse { - return_amount: offer_asset.amount, - swap_fee_amount: Uint128::zero(), - spread_amount: Uint128::zero(), - protocol_fee_amount: Uint128::zero(), - burn_fee_amount: Uint128::zero(), - }))) - } - Ok(white_whale_std::pool_manager::QueryMsg::ReverseSimulation { ask_asset, offer_asset, pair_identifier }) => SystemResult::Ok( - ContractResult::from(to_binary(&ReverseSimulationResponse { - offer_amount: ask_asset.amount, - swap_fee_amount: Uint128::zero(), - spread_amount: Uint128::zero(), - protocol_fee_amount: Uint128::zero(), - burn_fee_amount: Uint128::zero(), - })), - ), - _ => match from_binary(msg).unwrap() { + } + _ => match from_binary(msg) { + Ok(white_whale_std::pool_manager::QueryMsg::Simulation { + offer_asset, + ask_asset, + pair_identifier, + }) => SystemResult::Ok(ContractResult::from(to_binary(&SimulationResponse { + return_amount: offer_asset.amount, + swap_fee_amount: Uint128::zero(), + spread_amount: Uint128::zero(), + protocol_fee_amount: Uint128::zero(), + burn_fee_amount: Uint128::zero(), + }))), + Ok(white_whale_std::pool_manager::QueryMsg::ReverseSimulation { + ask_asset, + offer_asset, + pair_identifier, + }) => SystemResult::Ok(ContractResult::from(to_binary( + &ReverseSimulationResponse { + offer_amount: ask_asset.amount, + swap_fee_amount: Uint128::zero(), + spread_amount: Uint128::zero(), + protocol_fee_amount: Uint128::zero(), + burn_fee_amount: Uint128::zero(), + }, + ))), + _ => { + match from_binary(msg).unwrap() { Cw20QueryMsg::TokenInfo {} => { let balances: &HashMap = match self.token_querier.balances.get(contract_addr) { @@ -235,10 +241,10 @@ impl WasmMockQuerier { } _ => panic!("DO NOT ENTER HERE"), - }, - }, - } - } + } + } + }, + }, QueryRequest::Wasm(WasmQuery::ContractInfo { .. }) => { let mut contract_info_response = ContractInfoResponse::default(); contract_info_response.code_id = 0u64; @@ -248,7 +254,7 @@ impl WasmMockQuerier { SystemResult::Ok(ContractResult::Ok( to_binary(&contract_info_response).unwrap(), )) - }, + } QueryRequest::Wasm(WasmQuery::CodeInfo { code_id }) => { let mut default = CodeInfoResponse::default(); @@ -256,7 +262,10 @@ impl WasmMockQuerier { 11 => { default.code_id = 67; default.creator = Addr::unchecked("creator").to_string(); - default.checksum =HexBinary::from_hex(&sha256::digest(format!("code_checksum_{}", code_id))) + default.checksum = HexBinary::from_hex(&sha256::digest(format!( + "code_checksum_{}", + code_id + ))) .unwrap(); SystemResult::Ok(to_binary(&default).into()) } diff --git a/contracts/liquidity_hub/pool-manager/src/tests/suite.rs b/contracts/liquidity_hub/pool-manager/src/tests/suite.rs index 7e141811..1a72f174 100644 --- a/contracts/liquidity_hub/pool-manager/src/tests/suite.rs +++ b/contracts/liquidity_hub/pool-manager/src/tests/suite.rs @@ -1,20 +1,22 @@ -use white_whale_std::pool_manager::{Cw20HookMsg, SwapOperation}; +use cosmwasm_std::testing::MockStorage; +use white_whale_std::pool_manager::SwapOperation; use white_whale_std::pool_manager::{InstantiateMsg, NPairInfo}; -use cosmwasm_std::{ - to_json_binary, Addr, Coin, Decimal, Empty, StdResult, Timestamp, Uint128, Uint64, -}; -use cw20::{BalanceResponse, Cw20Coin, MinterResponse}; +use cosmwasm_std::{Addr, Coin, Decimal, Empty, StdResult, Timestamp, Uint128, Uint64}; use cw_multi_test::{ - App, AppBuilder, AppResponse, BankKeeper, Contract, ContractWrapper, Executor, WasmKeeper, + App, AppBuilder, AppResponse, BankKeeper, Contract, ContractWrapper, DistributionKeeper, + Executor, FailingModule, GovFailingModule, IbcFailingModule, StakeKeeper, WasmKeeper, }; use white_whale_std::pool_network::pair::{ReverseSimulationResponse, SimulationResponse}; use white_whale_std::pool_network::{ - asset::{Asset, AssetInfo, PairType}, + asset::{AssetInfo, PairType}, pair::PoolFee, }; +use white_whale_testing::multi_test::stargate_mock::StargateMock; use cw_multi_test::addons::{MockAddressGenerator, MockApiBech32}; + +use crate::liquidity::commands::LP_SYMBOL; fn contract_pool_manager() -> Box> { let contract = ContractWrapper::new_with_empty( crate::contract::execute, @@ -25,16 +27,6 @@ fn contract_pool_manager() -> Box> { Box::new(contract) } -fn cw20_token_contract() -> Box> { - let contract = ContractWrapper::new_with_empty( - cw20_base::contract::execute, - cw20_base::contract::instantiate, - cw20_base::contract::query, - ); - - Box::new(contract) -} - /// Creates the whale lair contract pub fn whale_lair_contract() -> Box> { let contract = ContractWrapper::new( @@ -47,8 +39,21 @@ pub fn whale_lair_contract() -> Box> { Box::new(contract) } +type OsmosisTokenFactoryApp = App< + BankKeeper, + MockApiBech32, + MockStorage, + FailingModule, + WasmKeeper, + StakeKeeper, + DistributionKeeper, + IbcFailingModule, + GovFailingModule, + StargateMock, +>; + pub struct TestingSuite { - app: App, + app: OsmosisTokenFactoryApp, pub senders: [Addr; 3], pub whale_lair_addr: Addr, pub pool_manager_addr: Addr, @@ -69,28 +74,12 @@ impl TestingSuite { self } - pub(crate) fn get_time(&mut self) -> Timestamp { - self.app.block_info().time - } - - pub(crate) fn increase_allowance( - &mut self, - sender: Addr, - cw20contract: Addr, - allowance: Uint128, - spender: Addr, - ) -> &mut Self { - let msg = cw20_base::msg::ExecuteMsg::IncreaseAllowance { - spender: spender.to_string(), - amount: allowance, - expires: None, - }; - - self.app - .execute_contract(sender, cw20contract, &msg, &[]) - .unwrap(); - - self + pub(crate) fn get_lp_denom(&self, pair_id: String) -> String { + // TODO: this should have + format!( + "factory/{}/u{}.vault.{}.{}", + self.pool_manager_addr, pair_id, pair_id, LP_SYMBOL + ) } } @@ -113,6 +102,7 @@ impl TestingSuite { .with_api(MockApiBech32::new("migaloo")) .with_wasm(WasmKeeper::default().with_address_generator(MockAddressGenerator)) .with_bank(bank) + .with_stargate(StargateMock {}) .build(|router, _api, storage| { balances.into_iter().for_each(|(account, amount)| { router.bank.init_balance(storage, &account, amount).unwrap() @@ -129,22 +119,13 @@ impl TestingSuite { } #[track_caller] - pub(crate) fn instantiate( - &mut self, - whale_lair_addr: String, - _vault_creation_fee: Asset, - ) -> &mut Self { - let cw20_token_id = self.app.store_code(cw20_token_contract()); + pub(crate) fn instantiate(&mut self, whale_lair_addr: String) -> &mut Self { let msg = InstantiateMsg { fee_collector_addr: whale_lair_addr, - token_code_id: cw20_token_id, - pair_code_id: cw20_token_id, owner: self.creator().to_string(), - pool_creation_fee: Asset { + pool_creation_fee: Coin { amount: Uint128::from(1_000u128), - info: AssetInfo::NativeToken { - denom: "uusd".to_string(), - }, + denom: "uusd".to_string(), }, }; @@ -163,47 +144,19 @@ impl TestingSuite { Some(creator.into_string()), ) .unwrap(); + self } #[track_caller] pub(crate) fn instantiate_default(&mut self) -> &mut Self { self.create_whale_lair(); - self.create_cw20_token(); // 17 May 2023 17:00:00 UTC let timestamp = Timestamp::from_seconds(1684342800u64); self.set_time(timestamp); - self.instantiate( - self.whale_lair_addr.to_string(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::new(1_000u128), - }, - ) - } - - #[track_caller] - pub(crate) fn instantiate_with_cw20_lp_token(&mut self) -> &mut Self { - self.create_whale_lair(); - let _cw20_code_id = self.create_cw20_token(); - println!("cw20_code_id: {}", self.whale_lair_addr); - // 17 May 2023 17:00:00 UTC - let timestamp = Timestamp::from_seconds(1684342800u64); - self.set_time(timestamp); - - self.instantiate( - self.whale_lair_addr.to_string(), - Asset { - info: AssetInfo::NativeToken { - denom: "uwhale".to_string(), - }, - amount: Uint128::new(1_000u128), - }, - ) + self.instantiate(self.whale_lair_addr.to_string()) } fn create_whale_lair(&mut self) { @@ -238,50 +191,6 @@ impl TestingSuite { .unwrap(); } - #[track_caller] - pub fn create_cw20_token(&mut self) -> u64 { - let msg = white_whale_std::pool_network::token::InstantiateMsg { - name: "mocktoken".to_string(), - symbol: "MOCK".to_string(), - decimals: 6, - initial_balances: vec![ - Cw20Coin { - address: self.senders[0].to_string(), - amount: Uint128::new(1_000_000_000_000u128), - }, - Cw20Coin { - address: self.senders[1].to_string(), - amount: Uint128::new(1_000_000_000_000u128), - }, - Cw20Coin { - address: self.senders[2].to_string(), - amount: Uint128::new(1_000_000_000_000u128), - }, - ], - mint: Some(MinterResponse { - minter: self.senders[0].to_string(), - cap: None, - }), - }; - - let cw20_token_id = self.app.store_code(cw20_token_contract()); - - let creator = self.creator().clone(); - - self.cw20_tokens.append(&mut vec![self - .app - .instantiate_contract( - cw20_token_id, - creator.clone(), - &msg, - &[], - "mock cw20 token", - Some(creator.into_string()), - ) - .unwrap()]); - cw20_token_id - } - #[track_caller] pub fn add_native_token_decimals( &mut self, @@ -336,12 +245,10 @@ impl TestingSuite { &mut self, sender: Addr, pair_identifier: String, - assets: Vec, funds: Vec, result: impl Fn(Result), ) -> &mut Self { let msg = white_whale_std::pool_manager::ExecuteMsg::ProvideLiquidity { - assets, pair_identifier, slippage_tolerance: None, receiver: None, @@ -359,8 +266,8 @@ impl TestingSuite { pub(crate) fn swap( &mut self, sender: Addr, - offer_asset: Asset, - ask_asset: AssetInfo, + offer_asset: Coin, + ask_asset_denom: String, belief_price: Option, max_spread: Option, to: Option, @@ -370,7 +277,7 @@ impl TestingSuite { ) -> &mut Self { let msg = white_whale_std::pool_manager::ExecuteMsg::Swap { offer_asset, - ask_asset, + ask_asset_denom, belief_price, max_spread, to, @@ -415,19 +322,17 @@ impl TestingSuite { pub(crate) fn create_pair( &mut self, sender: Addr, - asset_infos: Vec, + asset_denoms: Vec, pool_fees: PoolFee, pair_type: PairType, - token_factory_lp: bool, pair_identifier: Option, pair_creation_fee_funds: Vec, result: impl Fn(Result), ) -> &mut Self { let msg = white_whale_std::pool_manager::ExecuteMsg::CreatePair { - asset_infos, + asset_denoms, pool_fees, pair_type, - token_factory_lp, pair_identifier, }; @@ -446,47 +351,14 @@ impl TestingSuite { &mut self, sender: Addr, pair_identifier: String, - assets: Vec, - result: impl Fn(Result), - ) -> &mut Self { - let msg = white_whale_std::pool_manager::ExecuteMsg::WithdrawLiquidity { - assets, - pair_identifier, - }; - - result( - self.app - .execute_contract(sender, self.pool_manager_addr.clone(), &msg, &[]), - ); - - self - } - - #[track_caller] - pub(crate) fn withdraw_liquidity_cw20( - &mut self, - sender: Addr, - pair_identifier: String, - _assets: Vec, - amount: Uint128, - liquidity_token: Addr, + funds: Vec, result: impl Fn(Result), ) -> &mut Self { - // Prepare a CW20 Transfer message with a CW20HookMsg to withdraw liquidity - - // Send the cw20 amount with a message - let msg = cw20::Cw20ExecuteMsg::Send { - contract: self.pool_manager_addr.to_string(), - amount: amount, - msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity { - pair_identifier: pair_identifier, - }) - .unwrap(), - }; + let msg = white_whale_std::pool_manager::ExecuteMsg::WithdrawLiquidity { pair_identifier }; result( self.app - .execute_contract(sender, liquidity_token, &msg, &[]), + .execute_contract(sender, self.pool_manager_addr.clone(), &msg, &funds), ); self @@ -523,7 +395,19 @@ impl TestingSuite { self } - pub(crate) fn query_pair_info( + pub(crate) fn query_all_balances( + &mut self, + addr: String, + result: impl Fn(StdResult>), + ) -> &mut Self { + let balance_resp: StdResult> = self.app.wrap().query_all_balances(addr); + + result(balance_resp); + + self + } + + pub(crate) fn _query_pair_info( &self, pair_identifier: String, result: impl Fn(StdResult), @@ -543,17 +427,17 @@ impl TestingSuite { pub(crate) fn query_simulation( &mut self, pair_identifier: String, - offer_asset: Asset, - ask_asset: AssetInfo, + offer_asset: Coin, + ask_asset: String, result: impl Fn(StdResult), ) -> &mut Self { let pair_info_response: StdResult = self.app.wrap().query_wasm_smart( &self.pool_manager_addr, &white_whale_std::pool_manager::QueryMsg::Simulation { offer_asset, - ask_asset: Asset { + ask_asset: Coin { amount: Uint128::zero(), - info: ask_asset, + denom: ask_asset, }, pair_identifier, }, @@ -567,17 +451,17 @@ impl TestingSuite { pub(crate) fn query_reverse_simulation( &mut self, pair_identifier: String, - offer_asset: AssetInfo, - ask_asset: Asset, + offer_asset: String, + ask_asset: Coin, result: impl Fn(StdResult), ) -> &mut Self { let pair_info_response: StdResult = self.app.wrap().query_wasm_smart( &self.pool_manager_addr, &white_whale_std::pool_manager::QueryMsg::ReverseSimulation { - offer_asset: Asset { + offer_asset: Coin { amount: Uint128::zero(), - info: offer_asset, + denom: offer_asset, }, ask_asset, pair_identifier, @@ -609,32 +493,18 @@ impl TestingSuite { // Get balance of LP token, if native we can just query balance otherwise we need to go to cw20 - let balance = match lp_token_response.liquidity_token { - AssetInfo::NativeToken { denom } => { - let balance_response: Uint128 = - self.app.wrap().query_balance(sender, denom).unwrap().amount; - - balance_response - } - AssetInfo::Token { contract_addr } => { - let balance_response: BalanceResponse = self - .app - .wrap() - .query_wasm_smart( - contract_addr, - &cw20_base::msg::QueryMsg::Balance { address: sender }, - ) - .unwrap(); - - balance_response.balance - } - }; + let balance: Uint128 = self + .app + .wrap() + .query_balance(sender, lp_token_response.lp_denom) + .unwrap() + .amount; result(Result::Ok(balance)); self } - pub(crate) fn query_lp_token(&mut self, identifier: String, _sender: String) -> AssetInfo { + pub(crate) fn _query_lp_token(&mut self, identifier: String, _sender: String) -> String { // Get the LP token from Config let lp_token_response: NPairInfo = self .app @@ -648,6 +518,6 @@ impl TestingSuite { .unwrap(); // Get balance of LP token, if native we can just query balance otherwise we need to go to cw20 - lp_token_response.liquidity_token + lp_token_response.lp_denom } } diff --git a/packages/white-whale-std/src/pool_manager.rs b/packages/white-whale-std/src/pool_manager.rs index 0a0272e2..9b1db880 100644 --- a/packages/white-whale-std/src/pool_manager.rs +++ b/packages/white-whale-std/src/pool_manager.rs @@ -1,49 +1,36 @@ use std::fmt; use crate::pool_network::{ - asset::{Asset, AssetInfo, PairType}, + asset::PairType, factory::NativeTokenDecimalsResponse, pair::{PoolFee, ReverseSimulationResponse, SimulationResponse}, }; use cosmwasm_schema::{cw_serde, QueryResponses}; -use cosmwasm_std::{Decimal, Uint128}; -use cw20::Cw20ReceiveMsg; +use cosmwasm_std::{Coin, Decimal, Uint128}; use cw_ownable::{cw_ownable_execute, cw_ownable_query}; -#[cw_serde] -pub enum Cw20HookMsg { - /// Sell a given amount of asset - Swap { - ask_asset: AssetInfo, - belief_price: Option, - max_spread: Option, - to: Option, - pair_identifier: String, - }, - /// Withdraws liquidity - WithdrawLiquidity { pair_identifier: String }, -} - #[cw_serde] pub enum SwapOperation { WhaleSwap { - token_in_info: AssetInfo, - token_out_info: AssetInfo, + token_in_denom: String, + token_out_denom: String, pool_identifier: String, }, } impl SwapOperation { - /// Retrieves the `token_in_info` [`AssetInfo`] used for this swap operation. - pub fn get_input_asset_info(&self) -> &AssetInfo { + /// Retrieves the `token_in_denom` used for this swap operation. + pub fn get_input_asset_info(&self) -> &String { match self { - SwapOperation::WhaleSwap { token_in_info, .. } => token_in_info, + SwapOperation::WhaleSwap { token_in_denom, .. } => token_in_denom, } } - pub fn get_target_asset_info(&self) -> AssetInfo { + pub fn get_target_asset_info(&self) -> String { match self { - SwapOperation::WhaleSwap { token_out_info, .. } => token_out_info.clone(), + SwapOperation::WhaleSwap { + token_out_denom, .. + } => token_out_denom.clone(), } } } @@ -52,12 +39,12 @@ impl fmt::Display for SwapOperation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { SwapOperation::WhaleSwap { - token_in_info, - token_out_info, + token_in_denom, + token_out_denom, pool_identifier, } => write!( f, - "WhaleSwap {{ token_in_info: {token_in_info}, token_out_info: {token_out_info}, pool_identifier: {pool_identifier} }}" + "WhaleSwap {{ token_in_info: {token_in_denom}, token_out_info: {token_out_denom}, pool_identifier: {pool_identifier} }}" ), } @@ -66,16 +53,16 @@ impl fmt::Display for SwapOperation { #[cw_serde] pub struct SwapRoute { - pub offer_asset_info: AssetInfo, - pub ask_asset_info: AssetInfo, + pub offer_asset_denom: String, + pub ask_asset_denom: String, pub swap_operations: Vec, } // Used for all swap routes #[cw_serde] pub struct SwapRouteResponse { - pub offer_asset: String, - pub ask_asset: String, + pub offer_asset_denom: String, + pub ask_asset_denom: String, pub swap_route: Vec, } @@ -84,7 +71,7 @@ impl fmt::Display for SwapRoute { write!( f, "SwapRoute {{ offer_asset_info: {}, ask_asset_info: {}, swap_operations: {:?} }}", - self.offer_asset_info, self.ask_asset_info, self.swap_operations + self.offer_asset_denom, self.ask_asset_denom, self.swap_operations ) } } @@ -110,11 +97,12 @@ pub struct StableSwapParams { // We define a custom struct for which allows for dynamic but defined pairs #[cw_serde] pub struct NPairInfo { - pub asset_infos: Vec, - pub liquidity_token: AssetInfo, + pub asset_denoms: Vec, + pub lp_denom: String, pub asset_decimals: Vec, + // TODO: balances is included in assets, might be redundant pub balances: Vec, - pub assets: Vec, + pub assets: Vec, pub pair_type: PairType, pub pool_fees: PoolFee, // TODO: Add stable swap params @@ -125,10 +113,8 @@ impl NPairInfo {} #[cw_serde] pub struct InstantiateMsg { pub fee_collector_addr: String, - pub token_code_id: u64, - pub pair_code_id: u64, pub owner: String, - pub pool_creation_fee: Asset, + pub pool_creation_fee: Coin, } /// The migrate message @@ -139,32 +125,29 @@ pub struct MigrateMsg {} #[cw_serde] pub enum ExecuteMsg { CreatePair { - asset_infos: Vec, + asset_denoms: Vec, // TODO: Remap to NPoolFee maybe pool_fees: PoolFee, pair_type: PairType, - token_factory_lp: bool, pair_identifier: Option, }, /// Provides liquidity to the pool ProvideLiquidity { - assets: Vec, slippage_tolerance: Option, receiver: Option, pair_identifier: String, }, /// Swap an offer asset to the other Swap { - offer_asset: Asset, - ask_asset: AssetInfo, + offer_asset: Coin, + ask_asset_denom: String, belief_price: Option, max_spread: Option, to: Option, pair_identifier: String, }, - // /// Withdraws liquidity from the pool. Used only when the LP is a token factory token. + // /// Withdraws liquidity from the pool. WithdrawLiquidity { - assets: Vec, pair_identifier: String, }, /// Adds native token info to the contract so it can instantiate pair contracts that include it @@ -210,8 +193,6 @@ pub enum ExecuteMsg { AddSwapRoutes { swap_routes: Vec, }, - // CW20 Methods - Receive(Cw20ReceiveMsg), } #[cw_ownable_query] @@ -225,24 +206,24 @@ pub enum QueryMsg { /// Simulates a swap. #[returns(SimulationResponse)] Simulation { - offer_asset: Asset, - ask_asset: Asset, + offer_asset: Coin, + ask_asset: Coin, pair_identifier: String, }, /// Simulates a reverse swap, i.e. given the ask asset, how much of the offer asset is needed to /// perform the swap. #[returns(ReverseSimulationResponse)] ReverseSimulation { - ask_asset: Asset, - offer_asset: Asset, + ask_asset: Coin, + offer_asset: Coin, pair_identifier: String, }, /// Gets the swap route for the given offer and ask assets. #[returns(Vec)] SwapRoute { - offer_asset_info: AssetInfo, - ask_asset_info: AssetInfo, + offer_asset_denom: String, + ask_asset_denom: String, }, /// Gets all swap routes registered #[returns(Vec)] diff --git a/packages/white-whale-std/src/whale_lair.rs b/packages/white-whale-std/src/whale_lair.rs index 7f3b7093..7b997053 100644 --- a/packages/white-whale-std/src/whale_lair.rs +++ b/packages/white-whale-std/src/whale_lair.rs @@ -1,4 +1,4 @@ -use crate::pool_network::asset::{Asset, AssetInfo, ToCoins}; +use crate::pool_network::asset::{Asset, AssetInfo}; use cosmwasm_schema::{cw_serde, QueryResponses}; use cosmwasm_std::{ to_json_binary, Addr, Coin, CosmosMsg, Decimal, StdResult, Timestamp, Uint128, Uint64, WasmMsg, @@ -86,7 +86,7 @@ pub enum ExecuteMsg { /// V2 MESSAGES /// Fills the whale lair with new rewards. - FillRewards { assets: Vec }, + FillRewards { assets: Vec }, //todo to be renamed to FillRewards once the cw20 token support has been removed from the other v2 contracts /// Fills the whale lair with new rewards. FillRewardsCoin, @@ -170,13 +170,13 @@ pub struct BondingWeightResponse { } /// Creates a message to fill rewards on the whale lair contract. -pub fn fill_rewards_msg(contract_addr: String, assets: Vec) -> StdResult { +pub fn fill_rewards_msg(contract_addr: String, assets: Vec) -> StdResult { Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr, msg: to_json_binary(&ExecuteMsg::FillRewards { assets: assets.clone(), })?, - funds: assets.to_coins()?, + funds: assets, })) }