From 4b242c7d3f21296c769bb3b06c4288c1a6ec853d Mon Sep 17 00:00:00 2001 From: Art3miX <40179351+Art3miX@users.noreply.github.com> Date: Fri, 10 May 2024 00:02:41 +0300 Subject: [PATCH] Events (#44) --- Cargo.lock | 316 +- Cargo.toml | 6 +- README.md | 12 +- contracts/account/schema/valence-account.json | 2583 ++++++++++++++++- contracts/account/src/contract.rs | 193 +- contracts/account/src/msg.rs | 2 + contracts/auction/auction/Cargo.toml | 1 + contracts/auction/auction/schema/auction.json | 2 +- contracts/auction/auction/src/contract.rs | 105 +- contracts/auction/auction/src/execute.rs | 55 +- contracts/auction/auctions_manager/Cargo.toml | 1 + .../schema/auctions-manager.json | 2 +- .../auction/auctions_manager/src/contract.rs | 44 +- contracts/auction/price_oracle/Cargo.toml | 1 + .../price_oracle/schema/price-oracle.json | 2 +- .../auction/price_oracle/src/contract.rs | 56 +- contracts/services/rebalancer/Cargo.toml | 1 + .../rebalancer/schema/rebalancer.json | 2 +- contracts/services/rebalancer/src/contract.rs | 117 +- contracts/services/rebalancer/src/error.rs | 3 + contracts/services/rebalancer/src/helpers.rs | 16 +- .../services/rebalancer/src/rebalance.rs | 117 +- .../schema/services-manager.json | 16 +- contracts/services_manager/src/contract.rs | 56 +- devtools/optimize.sh | 2 +- packages/valence-macros/src/lib.rs | 2 +- .../valence-package/src/event_indexing.rs | 426 +++ packages/valence-package/src/helpers.rs | 9 +- packages/valence-package/src/lib.rs | 1 + packages/valence-package/src/services/mod.rs | 1 + .../src/services/rebalancer.rs | 12 + scripts/general_commands.txt | 5 +- .../src/suite/instantiates/account.rs | 1 + tests/rust-tests/src/suite/suite.rs | 2 +- .../rust-tests/src/test_service_management.rs | 5 +- .../src/tests_account/test_account.rs | 2 +- .../src/tests_auctions/test_auction.rs | 35 +- 37 files changed, 3693 insertions(+), 519 deletions(-) create mode 100644 packages/valence-package/src/event_indexing.rs diff --git a/Cargo.lock b/Cargo.lock index 152a97ef..3085cf01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,9 +15,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.75" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" +checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519" [[package]] name = "astroport" @@ -30,7 +30,7 @@ dependencies = [ "cw-storage-plus 0.15.1", "cw-utils 0.15.1", "cw20", - "itertools", + "itertools 0.10.5", "uint", ] @@ -44,7 +44,7 @@ dependencies = [ "cw-storage-plus 0.15.1", "cw-utils 0.15.1", "cw20", - "itertools", + "itertools 0.10.5", "uint", ] @@ -58,7 +58,7 @@ dependencies = [ "cosmwasm-std", "cw-storage-plus 0.15.1", "cw2 0.15.1", - "itertools", + "itertools 0.10.5", "protobuf", "thiserror", ] @@ -105,7 +105,7 @@ dependencies = [ "cw-utils 1.0.3", "cw2 0.15.1", "cw20", - "itertools", + "itertools 0.10.5", "thiserror", ] @@ -150,6 +150,7 @@ dependencies = [ "cw2 1.1.2", "serde", "thiserror", + "valence-package", ] [[package]] @@ -180,6 +181,7 @@ dependencies = [ "price-oracle", "serde", "thiserror", + "valence-package", ] [[package]] @@ -188,12 +190,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" -[[package]] -name = "base16ct" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" - [[package]] name = "base16ct" version = "0.2.0" @@ -218,6 +214,12 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" +[[package]] +name = "bech32" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d" + [[package]] name = "bitflags" version = "2.4.1" @@ -244,9 +246,9 @@ dependencies = [ [[package]] name = "bnum" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "128a44527fc0d6abf05f9eda748b9027536e12dff93f5acc8449f51583309350" +checksum = "56953345e39537a3e18bdaeba4cb0c58a78c1f61f361dc0fa7c5c7340ae87c5f" [[package]] name = "bytemuck" @@ -291,32 +293,32 @@ checksum = "28c122c3980598d243d63d9a704629a2d748d101f278052ff068be5a4423ab6f" [[package]] name = "cosmwasm-crypto" -version = "1.5.0" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8bb3c77c3b7ce472056968c745eb501c440fbc07be5004eba02782c35bfbbe3" +checksum = "e6b4c3f9c4616d6413d4b5fc4c270a4cc32a374b9be08671e80e1a019f805d8f" dependencies = [ "digest 0.10.7", - "ecdsa 0.16.8", + "ecdsa", "ed25519-zebra", - "k256 0.13.1", + "k256", "rand_core 0.6.4", "thiserror", ] [[package]] name = "cosmwasm-derive" -version = "1.5.0" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fea73e9162e6efde00018d55ed0061e93a108b5d6ec4548b4f8ce3c706249687" +checksum = "c586ced10c3b00e809ee664a895025a024f60d65d34fe4c09daed4a4db68a3f3" dependencies = [ "syn 1.0.109", ] [[package]] name = "cosmwasm-schema" -version = "1.5.0" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df41ea55f2946b6b43579659eec048cc2f66e8c8e2e3652fc5e5e476f673856" +checksum = "8467874827d384c131955ff6f4d47d02e72a956a08eb3c0ff24f8c903a5517b4" dependencies = [ "cosmwasm-schema-derive", "schemars", @@ -327,9 +329,9 @@ dependencies = [ [[package]] name = "cosmwasm-schema-derive" -version = "1.5.0" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43609e92ce1b9368aa951b334dd354a2d0dd4d484931a5f83ae10e12a26c8ba9" +checksum = "f6db85d98ac80922aef465e564d5b21fa9cfac5058cb62df7f116c3682337393" dependencies = [ "proc-macro2", "quote", @@ -338,12 +340,12 @@ dependencies = [ [[package]] name = "cosmwasm-std" -version = "1.5.0" +version = "1.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04d6864742e3a7662d024b51a94ea81c9af21db6faea2f9a6d2232bb97c6e53e" +checksum = "712fe58f39d55c812f7b2c84e097cdede3a39d520f89b6dc3153837e31741927" dependencies = [ "base64", - "bech32", + "bech32 0.9.1", "bnum", "cosmwasm-crypto", "cosmwasm-derive", @@ -383,18 +385,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" -[[package]] -name = "crypto-bigint" -version = "0.4.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef" -dependencies = [ - "generic-array", - "rand_core 0.6.4", - "subtle", - "zeroize", -] - [[package]] name = "crypto-bigint" version = "0.5.3" @@ -432,20 +422,21 @@ dependencies = [ [[package]] name = "cw-multi-test" -version = "0.16.5" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "127c7bb95853b8e828bdab97065c81cb5ddc20f7339180b61b2300565aaa99d1" +checksum = "8ffa9e3bae206540c084198e5be5aea2ecb1f2597f79dc09263b528ea0604788" dependencies = [ "anyhow", + "bech32 0.11.0", "cosmwasm-std", "cw-storage-plus 1.2.0", "cw-utils 1.0.3", "derivative", - "itertools", - "k256 0.11.6", + "itertools 0.12.1", "prost", "schemars", "serde", + "sha2 0.10.8", "thiserror", ] @@ -589,16 +580,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "der" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1a467a65c5e759bce6e65eaf91cc29f466cdc57cb65777bd646872a8a1fd4de" -dependencies = [ - "const-oid", - "zeroize", -] - [[package]] name = "der" version = "0.7.8" @@ -663,30 +644,18 @@ version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23d2f3407d9a573d666de4b5bdf10569d73ca9478087346697dcbae6244bfbcd" -[[package]] -name = "ecdsa" -version = "0.14.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" -dependencies = [ - "der 0.6.1", - "elliptic-curve 0.12.3", - "rfc6979 0.3.1", - "signature 1.6.4", -] - [[package]] name = "ecdsa" version = "0.16.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a4b1e0c257a9e9f25f90ff76d7a68360ed497ee519c8e428d1825ef0000799d4" dependencies = [ - "der 0.7.8", + "der", "digest 0.10.7", - "elliptic-curve 0.13.6", - "rfc6979 0.4.0", - "signature 2.1.0", - "spki 0.7.2", + "elliptic-curve", + "rfc6979", + "signature", + "spki", ] [[package]] @@ -710,41 +679,21 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" -[[package]] -name = "elliptic-curve" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" -dependencies = [ - "base16ct 0.1.1", - "crypto-bigint 0.4.9", - "der 0.6.1", - "digest 0.10.7", - "ff 0.12.1", - "generic-array", - "group 0.12.1", - "pkcs8 0.9.0", - "rand_core 0.6.4", - "sec1 0.3.0", - "subtle", - "zeroize", -] - [[package]] name = "elliptic-curve" version = "0.13.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d97ca172ae9dc9f9b779a6e3a65d308f2af74e5b8c921299075bdb4a0370e914" dependencies = [ - "base16ct 0.2.0", - "crypto-bigint 0.5.3", + "base16ct", + "crypto-bigint", "digest 0.10.7", - "ff 0.13.0", + "ff", "generic-array", - "group 0.13.0", - "pkcs8 0.10.2", + "group", + "pkcs8", "rand_core 0.6.4", - "sec1 0.7.3", + "sec1", "subtle", "zeroize", ] @@ -759,16 +708,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "ff" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160" -dependencies = [ - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "ff" version = "0.13.0" @@ -813,24 +752,13 @@ dependencies = [ "wasi", ] -[[package]] -name = "group" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" -dependencies = [ - "ff 0.12.1", - "rand_core 0.6.4", - "subtle", -] - [[package]] name = "group" version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ - "ff 0.13.0", + "ff", "rand_core 0.6.4", "subtle", ] @@ -895,22 +823,19 @@ dependencies = [ ] [[package]] -name = "itoa" -version = "1.0.9" +name = "itertools" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" +checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569" +dependencies = [ + "either", +] [[package]] -name = "k256" -version = "0.11.6" +name = "itoa" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" -dependencies = [ - "cfg-if", - "ecdsa 0.14.8", - "elliptic-curve 0.12.3", - "sha2 0.10.8", -] +checksum = "af150ab688ff2122fcef229be89cb50dd66af9e01a4ff320cc137eecc9bacc38" [[package]] name = "k256" @@ -919,11 +844,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cadb76004ed8e97623117f3df85b17aaa6626ab0b0831e6573f104df16cd1bcc" dependencies = [ "cfg-if", - "ecdsa 0.16.8", - "elliptic-curve 0.13.6", + "ecdsa", + "elliptic-curve", "once_cell", "sha2 0.10.8", - "signature 2.1.0", + "signature", ] [[package]] @@ -965,24 +890,14 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "pkcs8" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" -dependencies = [ - "der 0.6.1", - "spki 0.6.0", -] - [[package]] name = "pkcs8" version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ - "der 0.7.8", - "spki 0.7.2", + "der", + "spki", ] [[package]] @@ -1006,22 +921,23 @@ dependencies = [ "cw2 1.1.2", "serde", "thiserror", + "valence-package", ] [[package]] name = "proc-macro2" -version = "1.0.69" +version = "1.0.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134c189feb4956b20f6f547d2cf727d4c0fe06722b20a0eec87ed445a97f92da" +checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba" dependencies = [ "unicode-ident", ] [[package]] name = "prost" -version = "0.9.0" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" +checksum = "d0f5d036824e4761737860779c906171497f6d55681139d8312388f8fe398922" dependencies = [ "bytes", "prost-derive", @@ -1029,15 +945,15 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.9.0" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" +checksum = "19de2de2a00075bf566bee3bd4db014b11587e84184d3f7a791bc17f1a8e9e48" dependencies = [ "anyhow", - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.60", ] [[package]] @@ -1051,9 +967,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1099,6 +1015,7 @@ name = "rebalancer" version = "0.1.0" dependencies = [ "anyhow", + "auction", "auction-package", "auctions-manager", "cosmwasm-schema", @@ -1113,17 +1030,6 @@ dependencies = [ "valence-package", ] -[[package]] -name = "rfc6979" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" -dependencies = [ - "crypto-bigint 0.4.9", - "hmac", - "zeroize", -] - [[package]] name = "rfc6979" version = "0.4.0" @@ -1164,9 +1070,9 @@ checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" [[package]] name = "schemars" -version = "0.8.15" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f7b0ce13155372a76ee2e1c5ffba1fe61ede73fbea5630d61eee6fac4929c0c" +checksum = "45a28f4c49489add4ce10783f7911893516f15afe45d015608d41faca6bc4d29" dependencies = [ "dyn-clone", "schemars_derive", @@ -1176,9 +1082,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.15" +version = "0.8.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e85e2a16b12bdb763244c69ab79363d71db2b4b918a2def53f80b02e0574b13c" +checksum = "c767fd6fa65d9ccf9cf026122c1b555f2ef9a4f0cea69da4d7dbc3e258d30967" dependencies = [ "proc-macro2", "quote", @@ -1186,30 +1092,16 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "sec1" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3be24c1842290c45df0a7bf069e0c268a747ad05a192f2fd7dcfdbc1cba40928" -dependencies = [ - "base16ct 0.1.1", - "der 0.6.1", - "generic-array", - "pkcs8 0.9.0", - "subtle", - "zeroize", -] - [[package]] name = "sec1" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" dependencies = [ - "base16ct 0.2.0", - "der 0.7.8", + "base16ct", + "der", "generic-array", - "pkcs8 0.10.2", + "pkcs8", "subtle", "zeroize", ] @@ -1222,31 +1114,31 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" [[package]] name = "serde" -version = "1.0.189" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" +checksum = "9846a40c979031340571da2545a4e5b7c4163bdae79b301d5f86d03979451fcc" dependencies = [ "serde_derive", ] [[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", ] [[package]] name = "serde_derive" -version = "1.0.189" +version = "1.0.198" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" +checksum = "e88edab869b01783ba905e7d0153f9fc1a6505a96e4ad3018011eedb838566d9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.60", ] [[package]] @@ -1312,16 +1204,6 @@ dependencies = [ "digest 0.10.7", ] -[[package]] -name = "signature" -version = "1.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" -dependencies = [ - "digest 0.10.7", - "rand_core 0.6.4", -] - [[package]] name = "signature" version = "2.1.0" @@ -1353,16 +1235,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "spki" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" -dependencies = [ - "base64ct", - "der 0.6.1", -] - [[package]] name = "spki" version = "0.7.2" @@ -1370,7 +1242,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d1e996ef02c474957d681f1b05213dfb0abab947b446a62d37770b23500184a" dependencies = [ "base64ct", - "der 0.7.8", + "der", ] [[package]] @@ -1398,9 +1270,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.38" +version = "2.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e96b79aaa137db8f61e26363a0c9b47d8b4ec75da28b7d1d614c2303e232408b" +checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3" dependencies = [ "proc-macro2", "quote", @@ -1419,22 +1291,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.50" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2" +checksum = "f0126ad08bff79f29fc3ae6a55cc72352056dfff61e3ff8bb7129476d44b23aa" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.50" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8" +checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66" dependencies = [ "proc-macro2", "quote", - "syn 2.0.38", + "syn 2.0.60", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e9e9db78..997fbe7c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -51,8 +51,8 @@ valence-macros = { path = "packages/valence-macros" } valence-package = { path = "packages/valence-package" } auction-package = { path = "packages/auction-package" } -cosmwasm-schema = "1.5.0" -cosmwasm-std = { version = "1.5.0", features = ["ibc3"] } +cosmwasm-schema = "1.5.4" +cosmwasm-std = { version = "1.5.4", features = ["ibc3"] } cw-storage-plus = "1.2.0" cw-utils = "1.0.3" cw2 = "1.1.2" @@ -61,5 +61,5 @@ thiserror = "1.0.31" schemars = "0.8.10" # dev-dependencies -cw-multi-test = "0.16.5" +cw-multi-test = "1.1.0" anyhow = { version = "1.0.51" } diff --git a/README.md b/README.md index 5e7b57eb..81f30b4d 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ ## Code ids -- auctions manager = `874` -- auction = `869` -- oracle = `883` -- rebalancer = `898` -- services manager = `872` -- account = `867` +- auctions manager = `904` +- auction = `903` +- oracle = `906` +- rebalancer = `901` +- services manager = `905` +- account = `902` ## Owner / Admin diff --git a/contracts/account/schema/valence-account.json b/contracts/account/schema/valence-account.json index ef6ec3b9..cdf1cc3d 100644 --- a/contracts/account/schema/valence-account.json +++ b/contracts/account/schema/valence-account.json @@ -1,6 +1,6 @@ { "contract_name": "valence-account", - "contract_version": "1.2.0", + "contract_version": "0.1.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", @@ -10,6 +10,13 @@ "services_manager" ], "properties": { + "referral": { + "description": "Optional referral (for indexing currently)", + "type": [ + "string", + "null" + ] + }, "services_manager": { "description": "Address of the service manager contract.", "type": "string" @@ -921,9 +928,2577 @@ "responses": { "get_admin": { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "Addr", - "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", - "type": "string" + "title": "EventIndex_for_Empty", + "oneOf": [ + { + "type": "object", + "required": [ + "account-creation" + ], + "properties": { + "account-creation": { + "type": "object", + "required": [ + "admin", + "referral" + ], + "properties": { + "admin": { + "description": "The admin address of the account", + "type": "string" + }, + "referral": { + "description": "where the account was created from (native, 3rd-party, etc)", + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-register-service" + ], + "properties": { + "account-register-service": { + "type": "object", + "required": [ + "service_name" + ], + "properties": { + "data": { + "anyOf": [ + { + "$ref": "#/definitions/Binary" + }, + { + "type": "null" + } + ] + }, + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-update-service" + ], + "properties": { + "account-update-service": { + "type": "object", + "required": [ + "data", + "service_name" + ], + "properties": { + "data": { + "$ref": "#/definitions/Binary" + }, + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-deregister-service" + ], + "properties": { + "account-deregister-service": { + "type": "object", + "required": [ + "service_name" + ], + "properties": { + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-pause-service" + ], + "properties": { + "account-pause-service": { + "type": "object", + "required": [ + "service_name" + ], + "properties": { + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-resume-service" + ], + "properties": { + "account-resume-service": { + "type": "object", + "required": [ + "service_name" + ], + "properties": { + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-send-funds-by-service" + ], + "properties": { + "account-send-funds-by-service": { + "type": "object", + "required": [ + "atomic", + "msgs", + "service_name" + ], + "properties": { + "atomic": { + "type": "boolean" + }, + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/SubMsg_for_Empty" + } + }, + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-execute-by-service" + ], + "properties": { + "account-execute-by-service": { + "type": "object", + "required": [ + "atomic", + "msgs", + "service_name" + ], + "properties": { + "atomic": { + "type": "boolean" + }, + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/SubMsg_for_Empty" + } + }, + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-execute-by-admin" + ], + "properties": { + "account-execute-by-admin": { + "type": "object", + "required": [ + "msgs" + ], + "properties": { + "msgs": { + "type": "array", + "items": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-start-admin-change" + ], + "properties": { + "account-start-admin-change": { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-cancel-admin-change" + ], + "properties": { + "account-cancel-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "account-approve-admin-change" + ], + "properties": { + "account-approve-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "oracle-update-price" + ], + "properties": { + "oracle-update-price": { + "type": "object", + "required": [ + "pair", + "price", + "source" + ], + "properties": { + "pair": { + "$ref": "#/definitions/Pair" + }, + "price": { + "$ref": "#/definitions/Decimal" + }, + "source": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "oracle-add-path" + ], + "properties": { + "oracle-add-path": { + "type": "object", + "required": [ + "pair", + "path" + ], + "properties": { + "pair": { + "$ref": "#/definitions/Pair" + }, + "path": { + "type": "array", + "items": { + "$ref": "#/definitions/Empty" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "oracle-update-path" + ], + "properties": { + "oracle-update-path": { + "type": "object", + "required": [ + "pair", + "path" + ], + "properties": { + "pair": { + "$ref": "#/definitions/Pair" + }, + "path": { + "type": "array", + "items": { + "$ref": "#/definitions/Empty" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "oracle-update-config" + ], + "properties": { + "oracle-update-config": { + "type": "object", + "required": [ + "config" + ], + "properties": { + "config": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "oracle-start-admin-change" + ], + "properties": { + "oracle-start-admin-change": { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "oracle-cancel-admin-change" + ], + "properties": { + "oracle-cancel-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "oracle-approve-admin-change" + ], + "properties": { + "oracle-approve-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-manager-update-auction-code-id" + ], + "properties": { + "auction-manager-update-auction-code-id": { + "type": "object", + "required": [ + "code_id" + ], + "properties": { + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-manager-update-oracle" + ], + "properties": { + "auction-manager-update-oracle": { + "type": "object", + "required": [ + "oracle_addr" + ], + "properties": { + "oracle_addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-manager-migrate-auction" + ], + "properties": { + "auction-manager-migrate-auction": { + "type": "object", + "required": [ + "code_id", + "msg", + "pair" + ], + "properties": { + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "msg": { + "$ref": "#/definitions/Empty" + }, + "pair": { + "$ref": "#/definitions/Pair" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-manager-update-min-amount" + ], + "properties": { + "auction-manager-update-min-amount": { + "type": "object", + "required": [ + "denom", + "min_amount" + ], + "properties": { + "denom": { + "type": "string" + }, + "min_amount": { + "$ref": "#/definitions/MinAmount" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-manager-start-admin-change" + ], + "properties": { + "auction-manager-start-admin-change": { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-manager-cancel-admin-change" + ], + "properties": { + "auction-manager-cancel-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-manager-approve-admin-change" + ], + "properties": { + "auction-manager-approve-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-init" + ], + "properties": { + "auction-init": { + "type": "object", + "required": [ + "config", + "strategy" + ], + "properties": { + "config": { + "$ref": "#/definitions/AuctionConfig" + }, + "strategy": { + "$ref": "#/definitions/AuctionStrategy" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-auction-funds" + ], + "properties": { + "auction-auction-funds": { + "type": "object", + "required": [ + "address", + "amount", + "auction_id" + ], + "properties": { + "address": { + "type": "string" + }, + "amount": { + "$ref": "#/definitions/Uint128" + }, + "auction_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-withdraw-funds" + ], + "properties": { + "auction-withdraw-funds": { + "type": "object", + "required": [ + "address", + "amount", + "auction_id" + ], + "properties": { + "address": { + "type": "string" + }, + "amount": { + "$ref": "#/definitions/Uint128" + }, + "auction_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-do-bid" + ], + "properties": { + "auction-do-bid": { + "type": "object", + "required": [ + "auction_id", + "bidder", + "bought_amount", + "price", + "refunded_amount" + ], + "properties": { + "auction_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "bidder": { + "type": "string" + }, + "bought_amount": { + "description": "How much of token.0 the bidder bought", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + }, + "price": { + "$ref": "#/definitions/Decimal" + }, + "refunded_amount": { + "description": "If bidder sent too much and we couldn't \"swap\" all, then we refund him the rest", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-pause" + ], + "properties": { + "auction-pause": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-resume" + ], + "properties": { + "auction-resume": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-update-strategy" + ], + "properties": { + "auction-update-strategy": { + "type": "object", + "required": [ + "strategy" + ], + "properties": { + "strategy": { + "$ref": "#/definitions/AuctionStrategy" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-update-chain-halt-config" + ], + "properties": { + "auction-update-chain-halt-config": { + "type": "object", + "required": [ + "halt_config" + ], + "properties": { + "halt_config": { + "$ref": "#/definitions/ChainHaltConfig" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-update-price-freshness-strategy" + ], + "properties": { + "auction-update-price-freshness-strategy": { + "type": "object", + "required": [ + "strategy" + ], + "properties": { + "strategy": { + "$ref": "#/definitions/PriceFreshnessStrategy" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-open" + ], + "properties": { + "auction-open": { + "type": "object", + "required": [ + "auction", + "auction_id" + ], + "properties": { + "auction": { + "$ref": "#/definitions/Empty" + }, + "auction_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-open-refund" + ], + "properties": { + "auction-open-refund": { + "type": "object", + "required": [ + "auction_id", + "min_amount", + "refund_amount", + "total_users" + ], + "properties": { + "auction_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "min_amount": { + "$ref": "#/definitions/Uint128" + }, + "refund_amount": { + "$ref": "#/definitions/Uint128" + }, + "total_users": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "auction-close" + ], + "properties": { + "auction-close": { + "type": "object", + "required": [ + "accounts", + "auction_id", + "is_closed", + "price" + ], + "properties": { + "accounts": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "auction_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "is_closed": { + "type": "boolean" + }, + "price": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "services-manager-add-service" + ], + "properties": { + "services-manager-add-service": { + "type": "object", + "required": [ + "addr", + "service_name" + ], + "properties": { + "addr": { + "type": "string" + }, + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "services-manager-update-service" + ], + "properties": { + "services-manager-update-service": { + "type": "object", + "required": [ + "addr", + "service_name" + ], + "properties": { + "addr": { + "type": "string" + }, + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "services-manager-remove-service" + ], + "properties": { + "services-manager-remove-service": { + "type": "object", + "required": [ + "service_name" + ], + "properties": { + "service_name": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "services-manager-update-code-id-whitelist" + ], + "properties": { + "services-manager-update-code-id-whitelist": { + "type": "object", + "required": [ + "to_add", + "to_remove" + ], + "properties": { + "to_add": { + "type": "array", + "items": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "to_remove": { + "type": "array", + "items": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "services-manager-withdraw" + ], + "properties": { + "services-manager-withdraw": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Coin" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "services-manager-start-admin-change" + ], + "properties": { + "services-manager-start-admin-change": { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "services-manager-cancel-admin-change" + ], + "properties": { + "services-manager-cancel-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "services-manager-approve-admin-change" + ], + "properties": { + "services-manager-approve-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-register" + ], + "properties": { + "rebalancer-register": { + "type": "object", + "required": [ + "account", + "config" + ], + "properties": { + "account": { + "type": "string" + }, + "config": { + "$ref": "#/definitions/RebalancerConfig" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-deregister" + ], + "properties": { + "rebalancer-deregister": { + "type": "object", + "required": [ + "account" + ], + "properties": { + "account": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-update" + ], + "properties": { + "rebalancer-update": { + "type": "object", + "required": [ + "account", + "config" + ], + "properties": { + "account": { + "type": "string" + }, + "config": { + "$ref": "#/definitions/RebalancerConfig" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-pause" + ], + "properties": { + "rebalancer-pause": { + "type": "object", + "required": [ + "account", + "reason" + ], + "properties": { + "account": { + "type": "string" + }, + "reason": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-resume" + ], + "properties": { + "rebalancer-resume": { + "type": "object", + "required": [ + "account" + ], + "properties": { + "account": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-update-system-status" + ], + "properties": { + "rebalancer-update-system-status": { + "type": "object", + "required": [ + "status" + ], + "properties": { + "status": { + "$ref": "#/definitions/SystemRebalanceStatus" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-update-denom-whitelist" + ], + "properties": { + "rebalancer-update-denom-whitelist": { + "type": "object", + "required": [ + "denoms" + ], + "properties": { + "denoms": { + "type": "array", + "items": { + "type": "string" + }, + "uniqueItems": true + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-update-base-denom-whitelist" + ], + "properties": { + "rebalancer-update-base-denom-whitelist": { + "type": "object", + "required": [ + "base_denoms" + ], + "properties": { + "base_denoms": { + "type": "array", + "items": { + "$ref": "#/definitions/BaseDenom" + }, + "uniqueItems": true + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-update-services-manager" + ], + "properties": { + "rebalancer-update-services-manager": { + "type": "object", + "required": [ + "addr" + ], + "properties": { + "addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-update-auctions-manager" + ], + "properties": { + "rebalancer-update-auctions-manager": { + "type": "object", + "required": [ + "addr" + ], + "properties": { + "addr": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-update-cycle-period" + ], + "properties": { + "rebalancer-update-cycle-period": { + "type": "object", + "required": [ + "period" + ], + "properties": { + "period": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-update-fees" + ], + "properties": { + "rebalancer-update-fees": { + "type": "object", + "required": [ + "fees" + ], + "properties": { + "fees": { + "$ref": "#/definitions/ServiceFeeConfig" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-start-admin-change" + ], + "properties": { + "rebalancer-start-admin-change": { + "type": "object", + "required": [ + "admin" + ], + "properties": { + "admin": { + "type": "string" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-cancel-admin-change" + ], + "properties": { + "rebalancer-cancel-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-approve-admin-change" + ], + "properties": { + "rebalancer-approve-admin-change": { + "type": "object", + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-cycle" + ], + "properties": { + "rebalancer-cycle": { + "type": "object", + "required": [ + "cycled_over", + "limit" + ], + "properties": { + "cycled_over": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "limit": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-account-rebalance" + ], + "properties": { + "rebalancer-account-rebalance": { + "type": "object", + "required": [ + "account", + "total_value", + "trades" + ], + "properties": { + "account": { + "type": "string" + }, + "total_value": { + "$ref": "#/definitions/Decimal" + }, + "trades": { + "type": "array", + "items": { + "$ref": "#/definitions/RebalanceTrade" + } + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "rebalancer-account-rebalance-pause" + ], + "properties": { + "rebalancer-account-rebalance-pause": { + "type": "object", + "required": [ + "account", + "total_value" + ], + "properties": { + "account": { + "type": "string" + }, + "total_value": { + "$ref": "#/definitions/Decimal" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ], + "definitions": { + "Addr": { + "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", + "type": "string" + }, + "AuctionConfig": { + "type": "object", + "required": [ + "chain_halt_config", + "is_paused", + "pair", + "price_freshness_strategy" + ], + "properties": { + "chain_halt_config": { + "$ref": "#/definitions/ChainHaltConfig" + }, + "is_paused": { + "type": "boolean" + }, + "pair": { + "$ref": "#/definitions/Pair" + }, + "price_freshness_strategy": { + "$ref": "#/definitions/PriceFreshnessStrategy" + } + }, + "additionalProperties": false + }, + "AuctionStrategy": { + "type": "object", + "required": [ + "end_price_perc", + "start_price_perc" + ], + "properties": { + "end_price_perc": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "start_price_perc": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + "BankMsg": { + "description": "The message types of the bank module.\n\nSee https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto", + "oneOf": [ + { + "description": "Sends native tokens from the contract to the given address.\n\nThis is translated to a [MsgSend](https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/cosmos/bank/v1beta1/tx.proto#L19-L28). `from_address` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "send" + ], + "properties": { + "send": { + "type": "object", + "required": [ + "amount", + "to_address" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "to_address": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will burn the given coins from the contract's account. There is no Cosmos SDK message that performs this, but it can be done by calling the bank keeper. Important if a contract controls significant token supply that must be retired.", + "type": "object", + "required": [ + "burn" + ], + "properties": { + "burn": { + "type": "object", + "required": [ + "amount" + ], + "properties": { + "amount": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + } + } + } + }, + "additionalProperties": false + } + ] + }, + "BaseDenom": { + "type": "object", + "required": [ + "denom", + "min_balance_limit" + ], + "properties": { + "denom": { + "type": "string" + }, + "min_balance_limit": { + "$ref": "#/definitions/Uint128" + } + }, + "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" + }, + "ChainHaltConfig": { + "type": "object", + "required": [ + "block_avg", + "cap" + ], + "properties": { + "block_avg": { + "description": "seconds each block is generated", + "allOf": [ + { + "$ref": "#/definitions/Decimal" + } + ] + }, + "cap": { + "description": "Time in seconds of how much of a halt we accept", + "type": "integer", + "format": "uint128", + "minimum": 0.0 + } + }, + "additionalProperties": false + }, + "Coin": { + "type": "object", + "required": [ + "amount", + "denom" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "denom": { + "type": "string" + } + } + }, + "CosmosMsg_for_Empty": { + "oneOf": [ + { + "type": "object", + "required": [ + "bank" + ], + "properties": { + "bank": { + "$ref": "#/definitions/BankMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "custom" + ], + "properties": { + "custom": { + "$ref": "#/definitions/Empty" + } + }, + "additionalProperties": false + }, + { + "description": "A Stargate message encoded the same way as a protobuf [Any](https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/any.proto). This is the same structure as messages in `TxBody` from [ADR-020](https://github.com/cosmos/cosmos-sdk/blob/master/docs/architecture/adr-020-protobuf-transaction-encoding.md)", + "type": "object", + "required": [ + "stargate" + ], + "properties": { + "stargate": { + "type": "object", + "required": [ + "type_url", + "value" + ], + "properties": { + "type_url": { + "type": "string" + }, + "value": { + "$ref": "#/definitions/Binary" + } + } + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "ibc" + ], + "properties": { + "ibc": { + "$ref": "#/definitions/IbcMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "wasm" + ], + "properties": { + "wasm": { + "$ref": "#/definitions/WasmMsg" + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "gov" + ], + "properties": { + "gov": { + "$ref": "#/definitions/GovMsg" + } + }, + "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)", + "type": "string" + }, + "Empty": { + "description": "An empty struct that serves as a placeholder in different places, such as contracts that don't set a custom message.\n\nIt is designed to be expressable in correct JSON and JSON Schema but contains no meaningful data. Previously we used enums without cases, but those cannot represented as valid JSON Schema (https://github.com/CosmWasm/cosmwasm/issues/451)", + "type": "object" + }, + "GovMsg": { + "description": "This message type allows the contract interact with the [x/gov] module in order to cast votes.\n\n[x/gov]: https://github.com/cosmos/cosmos-sdk/tree/v0.45.12/x/gov\n\n## Examples\n\nCast a simple vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); use cosmwasm_std::{GovMsg, VoteOption};\n\n#[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::Vote { proposal_id: 4, vote: VoteOption::Yes, })) } ```\n\nCast a weighted vote:\n\n``` # use cosmwasm_std::{ # HexBinary, # Storage, Api, Querier, DepsMut, Deps, entry_point, Env, StdError, MessageInfo, # Response, QueryResponse, # }; # type ExecuteMsg = (); # #[cfg(feature = \"cosmwasm_1_2\")] use cosmwasm_std::{Decimal, GovMsg, VoteOption, WeightedVoteOption};\n\n# #[cfg(feature = \"cosmwasm_1_2\")] #[entry_point] pub fn execute( deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, ) -> Result { // ... Ok(Response::new().add_message(GovMsg::VoteWeighted { proposal_id: 4, options: vec![ WeightedVoteOption { option: VoteOption::Yes, weight: Decimal::percent(65), }, WeightedVoteOption { option: VoteOption::Abstain, weight: Decimal::percent(35), }, ], })) } ```", + "oneOf": [ + { + "description": "This maps directly to [MsgVote](https://github.com/cosmos/cosmos-sdk/blob/v0.42.5/proto/cosmos/gov/v1beta1/tx.proto#L46-L56) in the Cosmos SDK with voter set to the contract address.", + "type": "object", + "required": [ + "vote" + ], + "properties": { + "vote": { + "type": "object", + "required": [ + "proposal_id", + "vote" + ], + "properties": { + "proposal_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "vote": { + "description": "The vote option.\n\nThis should be called \"option\" for consistency with Cosmos SDK. Sorry for that. See .", + "allOf": [ + { + "$ref": "#/definitions/VoteOption" + } + ] + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcMsg": { + "description": "These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts (contracts that directly speak the IBC protocol via 6 entry points)", + "oneOf": [ + { + "description": "Sends bank tokens owned by the contract to the given address on another chain. The channel must already be established between the ibctransfer module on this chain and a matching module on the remote chain. We cannot select the port_id, this is whatever the local chain has bound the ibctransfer module to.", + "type": "object", + "required": [ + "transfer" + ], + "properties": { + "transfer": { + "type": "object", + "required": [ + "amount", + "channel_id", + "timeout", + "to_address" + ], + "properties": { + "amount": { + "description": "packet data only supports one coin https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20", + "allOf": [ + { + "$ref": "#/definitions/Coin" + } + ] + }, + "channel_id": { + "description": "existing channel to send the tokens over", + "type": "string" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + }, + "to_address": { + "description": "address on the remote chain to receive these tokens", + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sends an IBC packet with given data over the existing channel. Data should be encoded in a format defined by the channel version, and the module on the other side should know how to parse this.", + "type": "object", + "required": [ + "send_packet" + ], + "properties": { + "send_packet": { + "type": "object", + "required": [ + "channel_id", + "data", + "timeout" + ], + "properties": { + "channel_id": { + "type": "string" + }, + "data": { + "$ref": "#/definitions/Binary" + }, + "timeout": { + "description": "when packet times out, measured on remote chain", + "allOf": [ + { + "$ref": "#/definitions/IbcTimeout" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "This will close an existing channel that is owned by this contract. Port is auto-assigned to the contract's IBC port", + "type": "object", + "required": [ + "close_channel" + ], + "properties": { + "close_channel": { + "type": "object", + "required": [ + "channel_id" + ], + "properties": { + "channel_id": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + }, + "IbcTimeout": { + "description": "In IBC each package must set at least one type of timeout: the timestamp or the block height. Using this rather complex enum instead of two timeout fields we ensure that at least one timeout is set.", + "type": "object", + "properties": { + "block": { + "anyOf": [ + { + "$ref": "#/definitions/IbcTimeoutBlock" + }, + { + "type": "null" + } + ] + }, + "timestamp": { + "anyOf": [ + { + "$ref": "#/definitions/Timestamp" + }, + { + "type": "null" + } + ] + } + } + }, + "IbcTimeoutBlock": { + "description": "IBCTimeoutHeight Height is a monotonically increasing data type that can be compared against another Height for the purposes of updating and freezing clients. Ordering is (revision_number, timeout_height)", + "type": "object", + "required": [ + "height", + "revision" + ], + "properties": { + "height": { + "description": "block height after which the packet times out. the height within the given revision", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "revision": { + "description": "the version that the client is currently on (e.g. after resetting the chain this could increment 1 as height drops to 0)", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + }, + "MinAmount": { + "type": "object", + "required": [ + "send", + "start_auction" + ], + "properties": { + "send": { + "description": "Minimum amount that is allowed to send to the auction", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + }, + "start_auction": { + "description": "Minimum amount that auction can start from\n\nIf auction amount is below this amount, it will not start the auction and will refund sent funds back to the sender", + "allOf": [ + { + "$ref": "#/definitions/Uint128" + } + ] + } + }, + "additionalProperties": false + }, + "Pair": { + "type": "array", + "items": [ + { + "type": "string" + }, + { + "type": "string" + } + ], + "maxItems": 2, + "minItems": 2 + }, + "ParsedPID": { + "type": "object", + "required": [ + "d", + "i", + "p" + ], + "properties": { + "d": { + "$ref": "#/definitions/Decimal" + }, + "i": { + "$ref": "#/definitions/Decimal" + }, + "p": { + "$ref": "#/definitions/Decimal" + } + }, + "additionalProperties": false + }, + "ParsedTarget": { + "description": "A parsed target struct that contains all info about a single denom target", + "type": "object", + "required": [ + "denom", + "last_i", + "percentage" + ], + "properties": { + "denom": { + "description": "The name of the denom", + "type": "string" + }, + "last_i": { + "description": "The last I value we got from the last rebalance PID calculation.", + "allOf": [ + { + "$ref": "#/definitions/SignedDecimal" + } + ] + }, + "last_input": { + "description": "The input we got from the last rebalance.", + "anyOf": [ + { + "$ref": "#/definitions/Decimal" + }, + { + "type": "null" + } + ] + }, + "min_balance": { + "description": "The minimum balance the account should hold for this denom. Can only be a single one for an account", + "anyOf": [ + { + "$ref": "#/definitions/Uint128" + }, + { + "type": "null" + } + ] + }, + "percentage": { + "description": "The percentage of the total balance we want to have in this denom", + "allOf": [ + { + "$ref": "#/definitions/Decimal" + } + ] + } + }, + "additionalProperties": false + }, + "PriceFreshnessStrategy": { + "description": "Gives us the strategy we should use for when the data is not fresh. \"multiplier\" list is sorted in descending order, so after we check the list, if the data is fresh, the multiplier is 1.\n\nEx: smallest day in the list is \"0.5\" (12 hours), so the multiplier will be 1 if the data is updated in the last 12 hours.", + "type": "object", + "required": [ + "limit", + "multipliers" + ], + "properties": { + "limit": { + "description": "Amount of days price considered no longer fresh", + "allOf": [ + { + "$ref": "#/definitions/Decimal" + } + ] + }, + "multipliers": { + "description": "Multiplier per day of unfresh data (older than day, multipler) for when data is older than 2 days, we add: (\"2\", \"1.5\")", + "type": "array", + "items": { + "type": "array", + "items": [ + { + "$ref": "#/definitions/Decimal" + }, + { + "$ref": "#/definitions/Decimal" + } + ], + "maxItems": 2, + "minItems": 2 + } + } + }, + "additionalProperties": false + }, + "RebalanceTrade": { + "type": "object", + "required": [ + "amount", + "pair" + ], + "properties": { + "amount": { + "$ref": "#/definitions/Uint128" + }, + "pair": { + "$ref": "#/definitions/Pair" + } + }, + "additionalProperties": false + }, + "RebalancerConfig": { + "type": "object", + "required": [ + "base_denom", + "has_min_balance", + "last_rebalance", + "max_limit", + "pid", + "target_override_strategy", + "targets" + ], + "properties": { + "base_denom": { + "description": "The base denom we will be calculating everything based on", + "type": "string" + }, + "has_min_balance": { + "type": "boolean" + }, + "last_rebalance": { + "description": "When the last rebalance happened.", + "allOf": [ + { + "$ref": "#/definitions/Timestamp" + } + ] + }, + "max_limit": { + "description": "Percentage from the total balance that we are allowed to sell in 1 rebalance cycle.", + "allOf": [ + { + "$ref": "#/definitions/Decimal" + } + ] + }, + "pid": { + "description": "The PID parameters the account want to rebalance with", + "allOf": [ + { + "$ref": "#/definitions/ParsedPID" + } + ] + }, + "target_override_strategy": { + "$ref": "#/definitions/TargetOverrideStrategy" + }, + "targets": { + "description": "A vector of targets to rebalance for this account", + "type": "array", + "items": { + "$ref": "#/definitions/ParsedTarget" + } + }, + "trustee": { + "description": "the address that can pause and resume the service", + "anyOf": [ + { + "$ref": "#/definitions/Addr" + }, + { + "type": "null" + } + ] + } + }, + "additionalProperties": false + }, + "ReplyOn": { + "description": "Use this to define when the contract gets a response callback. If you only need it for errors or success you can select just those in order to save gas.", + "oneOf": [ + { + "description": "Always perform a callback after SubMsg is processed", + "type": "string", + "enum": [ + "always" + ] + }, + { + "description": "Only callback if SubMsg returned an error, no callback on success case", + "type": "string", + "enum": [ + "error" + ] + }, + { + "description": "Only callback if SubMsg was successful, no callback on error case", + "type": "string", + "enum": [ + "success" + ] + }, + { + "description": "Never make a callback - this is like the original CosmosMsg semantics", + "type": "string", + "enum": [ + "never" + ] + } + ] + }, + "ServiceFeeConfig": { + "type": "object", + "required": [ + "denom", + "register_fee", + "resume_fee" + ], + "properties": { + "denom": { + "type": "string" + }, + "register_fee": { + "$ref": "#/definitions/Uint128" + }, + "resume_fee": { + "$ref": "#/definitions/Uint128" + } + }, + "additionalProperties": false + }, + "SignedDecimal": { + "description": "A helper struct to have a signed decimal This allows us to keep track if the number is positive or negative\n\nOur usecse / example: In the rebalancer, when we are doing the rebalance calculation, we can either have a positive number or a negetive number. positive number means we need to buy the asset, while negetive menas we need to sell.\n\nThis struct makes it easier for us to do the calculation, and act upon the sign only after the calculation is done, in order to know if we should buy or sell.", + "type": "array", + "items": [ + { + "$ref": "#/definitions/Decimal" + }, + { + "type": "boolean" + } + ], + "maxItems": 2, + "minItems": 2 + }, + "SubMsg_for_Empty": { + "description": "A submessage that will guarantee a `reply` call on success or error, depending on the `reply_on` setting. If you do not need to process the result, use regular messages instead.\n\nNote: On error the submessage execution will revert any partial state changes due to this message, but not revert any state changes in the calling contract. If this is required, it must be done manually in the `reply` entry point.", + "type": "object", + "required": [ + "id", + "msg", + "reply_on" + ], + "properties": { + "gas_limit": { + "description": "Gas limit measured in [Cosmos SDK gas](https://github.com/CosmWasm/cosmwasm/blob/main/docs/GAS.md).", + "type": [ + "integer", + "null" + ], + "format": "uint64", + "minimum": 0.0 + }, + "id": { + "description": "An arbitrary ID chosen by the contract. This is typically used to match `Reply`s in the `reply` entry point to the submessage.", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "msg": { + "$ref": "#/definitions/CosmosMsg_for_Empty" + }, + "reply_on": { + "$ref": "#/definitions/ReplyOn" + } + } + }, + "SystemRebalanceStatus": { + "oneOf": [ + { + "type": "object", + "required": [ + "not_started" + ], + "properties": { + "not_started": { + "type": "object", + "required": [ + "cycle_start" + ], + "properties": { + "cycle_start": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "processing" + ], + "properties": { + "processing": { + "type": "object", + "required": [ + "cycle_started", + "prices", + "start_from" + ], + "properties": { + "cycle_started": { + "$ref": "#/definitions/Timestamp" + }, + "prices": { + "type": "array", + "items": { + "type": "array", + "items": [ + { + "$ref": "#/definitions/Pair" + }, + { + "$ref": "#/definitions/Decimal" + } + ], + "maxItems": 2, + "minItems": 2 + } + }, + "start_from": { + "$ref": "#/definitions/Addr" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + }, + { + "type": "object", + "required": [ + "finished" + ], + "properties": { + "finished": { + "type": "object", + "required": [ + "next_cycle" + ], + "properties": { + "next_cycle": { + "$ref": "#/definitions/Timestamp" + } + }, + "additionalProperties": false + } + }, + "additionalProperties": false + } + ] + }, + "TargetOverrideStrategy": { + "description": "The strategy we will use when overriding targets", + "type": "string", + "enum": [ + "proportional", + "priority" + ] + }, + "Timestamp": { + "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", + "allOf": [ + { + "$ref": "#/definitions/Uint64" + } + ] + }, + "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); ```", + "type": "string" + }, + "Uint64": { + "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 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 `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", + "type": "string" + }, + "VoteOption": { + "type": "string", + "enum": [ + "yes", + "no", + "abstain", + "no_with_veto" + ] + }, + "WasmMsg": { + "description": "The message types of the wasm module.\n\nSee https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto", + "oneOf": [ + { + "description": "Dispatches a call to another contract at a known address (with known ABI).\n\nThis is translated to a [MsgExecuteContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L68-L78). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "execute" + ], + "properties": { + "execute": { + "type": "object", + "required": [ + "contract_addr", + "funds", + "msg" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "msg": { + "description": "msg is the json-encoded ExecuteMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Instantiates a new contracts from previously uploaded Wasm code.\n\nThe contract address is non-predictable. But it is guaranteed that when emitting the same Instantiate message multiple times, multiple instances on different addresses will be generated. See also Instantiate2.\n\nThis is translated to a [MsgInstantiateContract](https://github.com/CosmWasm/wasmd/blob/v0.29.2/proto/cosmwasm/wasm/v1/tx.proto#L53-L71). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "instantiate" + ], + "properties": { + "instantiate": { + "type": "object", + "required": [ + "code_id", + "funds", + "label", + "msg" + ], + "properties": { + "admin": { + "type": [ + "string", + "null" + ] + }, + "code_id": { + "type": "integer", + "format": "uint64", + "minimum": 0.0 + }, + "funds": { + "type": "array", + "items": { + "$ref": "#/definitions/Coin" + } + }, + "label": { + "description": "A human-readable label for the contract.\n\nValid values should: - not be empty - not be bigger than 128 bytes (or some chain-specific limit) - not start / end with whitespace", + "type": "string" + }, + "msg": { + "description": "msg is the JSON-encoded InstantiateMsg struct (as raw Binary)", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Migrates a given contracts to use new wasm code. Passes a MigrateMsg to allow us to customize behavior.\n\nOnly the contract admin (as defined in wasmd), if any, is able to make this call.\n\nThis is translated to a [MsgMigrateContract](https://github.com/CosmWasm/wasmd/blob/v0.14.0/x/wasm/internal/types/tx.proto#L86-L96). `sender` is automatically filled with the current contract's address.", + "type": "object", + "required": [ + "migrate" + ], + "properties": { + "migrate": { + "type": "object", + "required": [ + "contract_addr", + "msg", + "new_code_id" + ], + "properties": { + "contract_addr": { + "type": "string" + }, + "msg": { + "description": "msg is the json-encoded MigrateMsg struct that will be passed to the new code", + "allOf": [ + { + "$ref": "#/definitions/Binary" + } + ] + }, + "new_code_id": { + "description": "the code_id of the new logic to place in the given contract", + "type": "integer", + "format": "uint64", + "minimum": 0.0 + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Sets a new admin (for migrate) on the given contract. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "update_admin" + ], + "properties": { + "update_admin": { + "type": "object", + "required": [ + "admin", + "contract_addr" + ], + "properties": { + "admin": { + "type": "string" + }, + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + }, + { + "description": "Clears the admin on the given contract, so no more migration possible. Fails if this contract is not currently admin of the target contract.", + "type": "object", + "required": [ + "clear_admin" + ], + "properties": { + "clear_admin": { + "type": "object", + "required": [ + "contract_addr" + ], + "properties": { + "contract_addr": { + "type": "string" + } + } + } + }, + "additionalProperties": false + } + ] + } + } } } } diff --git a/contracts/account/src/contract.rs b/contracts/account/src/contract.rs index 4b7035ca..f980c950 100644 --- a/contracts/account/src/contract.rs +++ b/contracts/account/src/contract.rs @@ -1,3 +1,5 @@ +use std::env; + #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ @@ -5,6 +7,7 @@ use cosmwasm_std::{ Reply, Response, StdResult, SubMsg, WasmMsg, }; use cw2::set_contract_version; +use valence_package::event_indexing::ValenceEvent; use valence_package::helpers::{ approve_admin_change, cancel_admin_change, forward_to_services_manager, forward_to_services_manager_with_funds, sender_is_a_service, start_admin_change, verify_admin, @@ -38,7 +41,12 @@ pub fn instantiate( &deps.api.addr_validate(&msg.services_manager)?, )?; - Ok(Response::default().add_attribute("method", "instantiate")) + let event = ValenceEvent::AccountCreation { + admin: info.sender.to_string(), + referral: msg.referral.unwrap_or_default(), + }; + + Ok(Response::default().add_event(event.into())) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -53,45 +61,75 @@ pub fn execute( AccountBaseExecuteMsg::RegisterToService { service_name, data } => { verify_admin(deps.as_ref(), &info)?; let services_manager_addr = SERVICES_MANAGER.load(deps.storage)?; + // Query service fee - Ok( - match deps.querier.query_wasm_smart::>( - services_manager_addr.clone(), - &ServicesManagerQueryMsg::GetServiceFee { - account: env.contract.address.to_string(), - service: service_name.clone(), - action: valence_package::states::QueryFeeAction::Register, - }, - )? { - Some(fee) => forward_to_services_manager_with_funds( - services_manager_addr.to_string(), - ServicesManagerExecuteMsg::RegisterToService { service_name, data }, - vec![fee], - )?, - None => forward_to_services_manager( - services_manager_addr.to_string(), - ServicesManagerExecuteMsg::RegisterToService { service_name, data }, - )?, + let response = match deps.querier.query_wasm_smart::>( + services_manager_addr.clone(), + &ServicesManagerQueryMsg::GetServiceFee { + account: env.contract.address.to_string(), + service: service_name, + action: valence_package::states::QueryFeeAction::Register, }, - ) + )? { + Some(fee) => forward_to_services_manager_with_funds( + services_manager_addr.to_string(), + ServicesManagerExecuteMsg::RegisterToService { + service_name, + data: data.clone(), + }, + vec![fee], + ), + None => forward_to_services_manager( + services_manager_addr.to_string(), + ServicesManagerExecuteMsg::RegisterToService { + service_name, + data: data.clone(), + }, + ), + }?; + + let event = ValenceEvent::AccountRegisterService { + service_name: service_name.to_string(), + data, + }; + + Ok(response.add_event(event.into())) } // unregister from a service AccountBaseExecuteMsg::DeregisterFromService { service_name } => { verify_admin(deps.as_ref(), &info)?; let services_manager_addr = SERVICES_MANAGER.load(deps.storage)?; - Ok(forward_to_services_manager( + + let response = forward_to_services_manager( services_manager_addr.to_string(), ServicesManagerExecuteMsg::DeregisterFromService { service_name }, - )?) + )?; + + let event = ValenceEvent::AccountDeregisterService { + service_name: service_name.to_string(), + }; + + Ok(response.add_event(event.into())) } // Update the config for this service AccountBaseExecuteMsg::UpdateService { service_name, data } => { verify_admin(deps.as_ref(), &info)?; let services_manager_addr = SERVICES_MANAGER.load(deps.storage)?; - Ok(forward_to_services_manager( + + let response = forward_to_services_manager( services_manager_addr.to_string(), - ServicesManagerExecuteMsg::UpdateService { service_name, data }, - )?) + ServicesManagerExecuteMsg::UpdateService { + service_name, + data: data.clone(), + }, + )?; + + let event = ValenceEvent::AccountUpdateService { + service_name: service_name.to_string(), + data, + }; + + Ok(response.add_event(event.into())) } // Pause the service AccountBaseExecuteMsg::PauseService { @@ -100,46 +138,57 @@ pub fn execute( } => { verify_admin(deps.as_ref(), &info)?; let services_manager_addr = SERVICES_MANAGER.load(deps.storage)?; - Ok(forward_to_services_manager( + + let response = forward_to_services_manager( services_manager_addr.to_string(), ServicesManagerExecuteMsg::PauseService { service_name, pause_for: env.contract.address.to_string(), reason, }, - )?) + )?; + + let event = ValenceEvent::AccountPauseService { + service_name: service_name.to_string(), + }; + + Ok(response.add_event(event.into())) } // Resume service AccountBaseExecuteMsg::ResumeService { service_name } => { verify_admin(deps.as_ref(), &info)?; let services_manager_addr = SERVICES_MANAGER.load(deps.storage)?; - Ok( - match deps.querier.query_wasm_smart::>( - services_manager_addr.clone(), - &ServicesManagerQueryMsg::GetServiceFee { - account: env.contract.address.to_string(), - service: service_name.clone(), - action: valence_package::states::QueryFeeAction::Resume, - }, - )? { - Some(fee) => forward_to_services_manager_with_funds( - services_manager_addr.to_string(), - ServicesManagerExecuteMsg::ResumeService { - service_name, - resume_for: env.contract.address.to_string(), - }, - vec![fee], - )?, - None => forward_to_services_manager( - services_manager_addr.to_string(), - ServicesManagerExecuteMsg::ResumeService { - service_name, - resume_for: env.contract.address.to_string(), - }, - )?, + let response = match deps.querier.query_wasm_smart::>( + services_manager_addr.clone(), + &ServicesManagerQueryMsg::GetServiceFee { + account: env.contract.address.to_string(), + service: service_name, + action: valence_package::states::QueryFeeAction::Resume, }, - ) + )? { + Some(fee) => forward_to_services_manager_with_funds( + services_manager_addr.to_string(), + ServicesManagerExecuteMsg::ResumeService { + service_name, + resume_for: env.contract.address.to_string(), + }, + vec![fee], + )?, + None => forward_to_services_manager( + services_manager_addr.to_string(), + ServicesManagerExecuteMsg::ResumeService { + service_name, + resume_for: env.contract.address.to_string(), + }, + )?, + }; + + let event = ValenceEvent::AccountResumeService { + service_name: service_name.to_string(), + }; + + Ok(response.add_event(event.into())) } // Messages to be executed by the service, with sending funds. AccountBaseExecuteMsg::SendFundsByService { msgs, atomic } => { @@ -152,7 +201,15 @@ pub fn execute( // to allow the msgs to fail without failing the rest of the messages let msgs = msgs_into_sub_msgs(msgs, atomic); - Ok(Response::default().add_submessages(msgs)) + let event = ValenceEvent::AccountSendFundsByService { + service_name: info.sender.to_string(), + msgs: msgs.clone(), + atomic, + }; + + Ok(Response::default() + .add_event(event.into()) + .add_submessages(msgs)) } // Messages to be executed by the service, without sending funds. AccountBaseExecuteMsg::ExecuteByService { msgs, atomic } => { @@ -162,19 +219,39 @@ pub fn execute( let msgs = msgs_into_sub_msgs(msgs, atomic); - Ok(Response::default().add_submessages(msgs)) + let event = ValenceEvent::AccountExecuteByService { + service_name: info.sender.to_string(), + msgs: msgs.clone(), + atomic, + }; + + Ok(Response::default() + .add_event(event.into()) + .add_submessages(msgs)) } // Message to be executed by the admin of this account AccountBaseExecuteMsg::ExecuteByAdmin { msgs } => { verify_admin(deps.as_ref(), &info)?; - Ok(Response::default().add_messages(msgs)) + + let event = ValenceEvent::AccountExecuteByAdmin { msgs: msgs.clone() }; + + Ok(Response::default() + .add_event(event.into()) + .add_messages(msgs)) } AccountBaseExecuteMsg::StartAdminChange { addr, expiration } => { - Ok(start_admin_change(deps, &info, &addr, expiration)?) + let event = ValenceEvent::AccountStartAdminChange { + admin: addr.to_string(), + }; + Ok(start_admin_change(deps, &info, &addr, expiration)?.add_event(event.into())) + } + AccountBaseExecuteMsg::CancelAdminChange {} => { + let event = ValenceEvent::AccountCancelAdminChange {}; + Ok(cancel_admin_change(deps, &info)?.add_event(event.into())) } - AccountBaseExecuteMsg::CancelAdminChange {} => Ok(cancel_admin_change(deps, &info)?), AccountBaseExecuteMsg::ApproveAdminChange {} => { - Ok(approve_admin_change(deps, &env, &info)?) + let event = ValenceEvent::AccountApproveAdminChange {}; + Ok(approve_admin_change(deps, &env, &info)?.add_event(event.into())) } } } diff --git a/contracts/account/src/msg.rs b/contracts/account/src/msg.rs index b36ae947..e8dcc728 100644 --- a/contracts/account/src/msg.rs +++ b/contracts/account/src/msg.rs @@ -5,6 +5,8 @@ use cosmwasm_std::Addr; pub struct InstantiateMsg { /// Address of the service manager contract. pub services_manager: String, + /// Optional referral (for indexing currently) + pub referral: Option, } #[cw_serde] diff --git a/contracts/auction/auction/Cargo.toml b/contracts/auction/auction/Cargo.toml index 0cde1b0b..380624b5 100644 --- a/contracts/auction/auction/Cargo.toml +++ b/contracts/auction/auction/Cargo.toml @@ -25,6 +25,7 @@ serde = { workspace = true } thiserror = { workspace = true } cw-utils = { workspace = true } auction-package = { workspace = true } +valence-package = { workspace = true } [dev-dependencies] cw-multi-test = { workspace = true } diff --git a/contracts/auction/auction/schema/auction.json b/contracts/auction/auction/schema/auction.json index 948223d2..6f21fdce 100644 --- a/contracts/auction/auction/schema/auction.json +++ b/contracts/auction/auction/schema/auction.json @@ -1,6 +1,6 @@ { "contract_name": "auction", - "contract_version": "1.2.0", + "contract_version": "0.1.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/contracts/auction/auction/src/contract.rs b/contracts/auction/auction/src/contract.rs index 3ca13412..6e068389 100644 --- a/contracts/auction/auction/src/contract.rs +++ b/contracts/auction/auction/src/contract.rs @@ -9,6 +9,7 @@ use cosmwasm_std::{ to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint128, }; use cw2::set_contract_version; +use valence_package::event_indexing::ValenceEvent; use crate::error::ContractError; use crate::execute; @@ -49,15 +50,13 @@ pub fn instantiate( .sort_by(|p1, p2| p2.0.cmp(&p1.0)); // Set config - AUCTION_CONFIG.save( - deps.storage, - &AuctionConfig { - is_paused: false, - pair: msg.pair, - chain_halt_config: msg.chain_halt_config, - price_freshness_strategy, - }, - )?; + let auction_config = AuctionConfig { + is_paused: false, + pair: msg.pair, + chain_halt_config: msg.chain_halt_config, + price_freshness_strategy, + }; + AUCTION_CONFIG.save(deps.storage, &auction_config)?; // Set the strategy for this auction msg.auction_strategy.verify()?; @@ -89,7 +88,12 @@ pub fn instantiate( }, )?; - Ok(Response::default().add_attribute("method", "instantiate")) + let event = ValenceEvent::AuctionInit { + config: auction_config, + strategy: msg.auction_strategy, + }; + + Ok(Response::default().add_event(event.into())) } #[cfg_attr(not(feature = "library"), entry_point)] @@ -119,7 +123,8 @@ pub fn execute( mod admin { use auction_package::helpers::GetPriceResponse; - use cosmwasm_std::{coin, BankMsg, Event}; + use cosmwasm_std::{coin, BankMsg}; + use valence_package::event_indexing::{ValenceEvent, ValenceGenericEvent}; use crate::msg::AdminMsgs; @@ -143,7 +148,10 @@ mod admin { Ok(config) }, )?; - Ok(Response::default()) + + let event = ValenceEvent::AuctionPause {}; + + Ok(Response::default().add_event(event.into())) } AdminMsgs::ResumeAuction => { AUCTION_CONFIG.update( @@ -153,32 +161,44 @@ mod admin { Ok(config) }, )?; - Ok(Response::default()) + + let event = ValenceEvent::AuctionResume {}; + + Ok(Response::default().add_event(event.into())) } AdminMsgs::UpdateStrategy { strategy } => { AUCTION_STRATEGY.save(deps.storage, &strategy)?; - Ok(Response::default()) + + let event = ValenceEvent::AuctionUpdateStrategy { strategy }; + + Ok(Response::default().add_event(event.into())) } AdminMsgs::StartAuction(new_auction) => open_auction(deps, &env, new_auction), AdminMsgs::UpdateChainHaltConfig(halt_config) => { AUCTION_CONFIG.update( deps.storage, |mut config| -> Result { - config.chain_halt_config = halt_config; + config.chain_halt_config = halt_config.clone(); Ok(config) }, )?; - Ok(Response::default()) + + let event = ValenceEvent::AuctionUpdateChainHaltConfig { halt_config }; + + Ok(Response::default().add_event(event.into())) } AdminMsgs::UpdatePriceFreshnessStrategy(strategy) => { AUCTION_CONFIG.update( deps.storage, |mut config| -> Result { - config.price_freshness_strategy = strategy; + config.price_freshness_strategy = strategy.clone(); Ok(config) }, )?; - Ok(Response::default()) + + let event = ValenceEvent::AuctionUpdatePriceFreshnessStrategy { strategy }; + + Ok(Response::default().add_event(event.into())) } } } @@ -224,9 +244,21 @@ mod admin { .unwrap_or_default() .start_auction; + // Update auction id + auction_ids.curr = auction_ids.next; + auction_ids.next += 1; + + AUCTION_IDS.save(deps.storage, &auction_ids)?; + // if its less, refund the funds to the users if total_funds < min_start_acution { - return do_refund(deps, auction_ids.next, config.pair.0.clone(), total_funds); + return do_refund( + deps, + auction_ids.curr, + config.pair.0.clone(), + min_start_acution, + total_funds, + ); } // get the starting and closing price of the auction @@ -248,21 +280,14 @@ mod admin { last_checked_block: env.block.clone(), }; - // Update auction id - auction_ids.curr = auction_ids.next; - auction_ids.next += 1; - - AUCTION_IDS.save(deps.storage, &auction_ids)?; ACTIVE_AUCTION.save(deps.storage, &new_active_auction)?; - Ok(Response::default().add_event( - Event::new("new-auction") - .add_attribute("start_block", new_active_auction.start_block.to_string()) - .add_attribute("end_block", new_active_auction.end_block.to_string()) - .add_attribute("start_price", new_active_auction.start_price.to_string()) - .add_attribute("end_price", new_active_auction.end_price.to_string()) - .add_attribute("total_funds", new_active_auction.total_amount.to_string()), - )) + let event = ValenceGenericEvent::::AuctionOpen { + auction_id: auction_ids.curr, + auction: new_active_auction, + }; + + Ok(Response::default().add_event(event.into())) } /// Currently we only use this function for refunding when there is not enough funds to start an auction @@ -272,6 +297,7 @@ mod admin { deps: DepsMut, auction_id: u64, denom: String, + min_amount: Uint128, total_funds: Uint128, ) -> Result { let bank_msgs = AUCTION_FUNDS @@ -289,10 +315,16 @@ mod admin { AUCTION_FUNDS_SUM.save(deps.storage, auction_id, &Uint128::zero())?; AUCTION_FUNDS.clear(deps.storage); + let event = ValenceEvent::AuctionOpenRefund { + auction_id, + min_amount, + refund_amount: total_funds, + total_users: bank_msgs.len() as u64, + }; + Ok(Response::new() - .add_messages(bank_msgs) - .add_attribute("method", "refund") - .add_attribute("total_funds", total_funds.to_string())) + .add_event(event.into()) + .add_messages(bank_msgs)) } /// Helper functions to get the starting and ending prices /// Factors in freshness of the price from the oracle @@ -370,6 +402,9 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { } QueryMsg::GetPrice => { let active_auction = ACTIVE_AUCTION.load(deps.storage)?; + if active_auction.status != ActiveAuctionStatus::Started { + return Err(ContractError::AuctionClosed.into()); + } let price = calc_price(&active_auction, env.block.height); to_json_binary(&GetPriceResponse { price, diff --git a/contracts/auction/auction/src/execute.rs b/contracts/auction/auction/src/execute.rs index 288f9e80..9d977b02 100644 --- a/contracts/auction/auction/src/execute.rs +++ b/contracts/auction/auction/src/execute.rs @@ -3,11 +3,11 @@ use auction_package::{ Price, CLOSEST_TO_ONE_POSSIBLE, }; use cosmwasm_std::{ - coin, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, Env, Event, MessageInfo, Response, - Uint128, + coin, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, Response, Uint128, }; use cw_storage_plus::Bound; use cw_utils::must_pay; +use valence_package::event_indexing::ValenceEvent; use crate::{ contract::TWAP_PRICE_MAX_LEN, @@ -46,7 +46,7 @@ pub(crate) fn auction_funds( // Update funds of the sender for next auction AUCTION_FUNDS.update( deps.storage, - (next_auction_id, sender), + (next_auction_id, sender.clone()), |amount| -> Result { match amount { Some(amount) => Ok(amount.checked_add(funds)?), @@ -67,7 +67,13 @@ pub(crate) fn auction_funds( }, )?; - Ok(Response::default()) + let event = ValenceEvent::AuctionAuctionFunds { + address: sender.to_string(), + amount: funds, + auction_id: next_auction_id, + }; + + Ok(Response::default().add_event(event.into())) } pub fn withdraw_funds(deps: DepsMut, sender: Addr) -> Result { @@ -101,9 +107,15 @@ pub fn withdraw_funds(deps: DepsMut, sender: Addr) -> Result Result { @@ -133,6 +145,7 @@ pub fn do_bid(deps: DepsMut, info: &MessageInfo, env: &Env) -> Result Result Result Result { @@ -351,11 +367,16 @@ pub fn finish_auction(deps: DepsMut, env: &Env, limit: u64) -> Result Result { diff --git a/contracts/auction/auctions_manager/Cargo.toml b/contracts/auction/auctions_manager/Cargo.toml index eeed3372..cb53db74 100644 --- a/contracts/auction/auctions_manager/Cargo.toml +++ b/contracts/auction/auctions_manager/Cargo.toml @@ -26,6 +26,7 @@ serde = { workspace = true } thiserror = { workspace = true } auction = { workspace = true } auction-package = { workspace = true } +valence-package = { workspace = true } price-oracle = { workspace = true } [dev-dependencies] diff --git a/contracts/auction/auctions_manager/schema/auctions-manager.json b/contracts/auction/auctions_manager/schema/auctions-manager.json index d031e4bb..05197ebd 100644 --- a/contracts/auction/auctions_manager/schema/auctions-manager.json +++ b/contracts/auction/auctions_manager/schema/auctions-manager.json @@ -1,6 +1,6 @@ { "contract_name": "auctions-manager", - "contract_version": "1.2.0", + "contract_version": "0.1.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/contracts/auction/auctions_manager/src/contract.rs b/contracts/auction/auctions_manager/src/contract.rs index 8f303a5a..280d8cd1 100644 --- a/contracts/auction/auctions_manager/src/contract.rs +++ b/contracts/auction/auctions_manager/src/contract.rs @@ -12,6 +12,7 @@ use cosmwasm_std::{ use cw2::set_contract_version; use cw_storage_plus::Bound; use cw_utils::{nonpayable, parse_reply_instantiate_data}; +use valence_package::event_indexing::ValenceEvent; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg}; @@ -92,13 +93,17 @@ pub fn execute( Ok(Response::default().add_message(msg)) } ExecuteMsg::Admin(admin_msg) => admin::handle_msg(deps, env, info, *admin_msg), - ExecuteMsg::ApproveAdminChange {} => Ok(approve_admin_change(deps, &env, &info)?), + ExecuteMsg::ApproveAdminChange {} => { + let event = ValenceEvent::AuctionManagerApproveAdminChange {}; + Ok(approve_admin_change(deps, &env, &info)?.add_event(event.into())) + } } } mod admin { use auction_package::helpers::{cancel_admin_change, start_admin_change, verify_admin}; use cosmwasm_std::{to_json_binary, SubMsg, WasmMsg}; + use valence_package::event_indexing::{ValenceEvent, ValenceGenericEvent}; use crate::msg::AdminMsgs; @@ -189,12 +194,16 @@ mod admin { AdminMsgs::UpdateAuctionId { code_id } => { AUCTION_CODE_ID.save(deps.storage, &code_id)?; - Ok(Response::default()) + let event = ValenceEvent::AuctionManagerUpdateAuctionCodeId { code_id }; + + Ok(Response::default().add_event(event.into())) } AdminMsgs::UpdateOracle { oracle_addr } => { ORACLE_ADDR.save(deps.storage, &deps.api.addr_validate(&oracle_addr)?)?; - Ok(Response::default()) + let event = ValenceEvent::AuctionManagerUpdateOracle { oracle_addr }; + + Ok(Response::default().add_event(event.into())) } AdminMsgs::UpdateStrategy { pair, strategy } => { let pair_addr = PAIRS.load(deps.storage, pair)?; @@ -233,7 +242,7 @@ mod admin { Ok(Response::default().add_message(msg)) } AdminMsgs::MigrateAuction { pair, code_id, msg } => { - let pair_addr = PAIRS.load(deps.storage, pair)?; + let pair_addr = PAIRS.load(deps.storage, pair.clone())?; let migrate_msg = WasmMsg::Migrate { contract_addr: pair_addr.to_string(), @@ -241,17 +250,34 @@ mod admin { new_code_id: code_id, }; - Ok(Response::default().add_message(migrate_msg)) + let event = + ValenceGenericEvent::::AuctionManagerMigrateAuction { + pair, + code_id, + msg, + }; + + Ok(Response::default() + .add_event(event.into()) + .add_message(migrate_msg)) } AdminMsgs::UpdateMinAmount { denom, min_amount } => { - MIN_AUCTION_AMOUNT.save(deps.storage, denom, &min_amount)?; + MIN_AUCTION_AMOUNT.save(deps.storage, denom.clone(), &min_amount)?; + + let event = ValenceEvent::AuctionManagerUpdateMinAmount { denom, min_amount }; - Ok(Response::default()) + Ok(Response::default().add_event(event.into())) } AdminMsgs::StartAdminChange { addr, expiration } => { - Ok(start_admin_change(deps, &info, &addr, expiration)?) + let event = ValenceEvent::AuctionManagerStartAdminChange { + admin: addr.clone(), + }; + Ok(start_admin_change(deps, &info, &addr, expiration)?.add_event(event.into())) + } + AdminMsgs::CancelAdminChange => { + let event = ValenceEvent::AuctionManagerCancelAdminChange {}; + Ok(cancel_admin_change(deps, &info)?.add_event(event.into())) } - AdminMsgs::CancelAdminChange => Ok(cancel_admin_change(deps, &info)?), } } } diff --git a/contracts/auction/price_oracle/Cargo.toml b/contracts/auction/price_oracle/Cargo.toml index 05ae7083..f949a91d 100644 --- a/contracts/auction/price_oracle/Cargo.toml +++ b/contracts/auction/price_oracle/Cargo.toml @@ -25,6 +25,7 @@ serde = { workspace = true } thiserror = { workspace = true } cw-utils = { workspace = true } auction-package = { workspace = true } +valence-package = { workspace = true } astroport = "2.9.5" diff --git a/contracts/auction/price_oracle/schema/price-oracle.json b/contracts/auction/price_oracle/schema/price-oracle.json index 98097078..5ae69b14 100644 --- a/contracts/auction/price_oracle/schema/price-oracle.json +++ b/contracts/auction/price_oracle/schema/price-oracle.json @@ -1,6 +1,6 @@ { "contract_name": "price-oracle", - "contract_version": "1.2.0", + "contract_version": "0.1.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/contracts/auction/price_oracle/src/contract.rs b/contracts/auction/price_oracle/src/contract.rs index f0324add..cd36a705 100644 --- a/contracts/auction/price_oracle/src/contract.rs +++ b/contracts/auction/price_oracle/src/contract.rs @@ -9,6 +9,7 @@ use auction_package::Price; use cosmwasm_std::entry_point; use cosmwasm_std::{to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Response}; use cw2::set_contract_version; +use valence_package::event_indexing::{ValenceEvent, ValenceGenericEvent}; use crate::error::ContractError; use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; @@ -63,19 +64,29 @@ pub fn execute( .ok_or(ContractError::PairAuctionNotFound)?; let twap_prices = TWAP_PRICES.query(&deps.querier, auction_addr)?; + let source; + let price = if can_update_price_from_auction(&config, &env, &twap_prices) { + source = "auction"; get_avg_price(twap_prices) } else { let steps = ASTRO_PRICE_PATHS .load(deps.storage, pair.clone()) .map_err(|_| ContractError::NoAstroPath(pair.clone()))?; + source = "astroport"; get_price_from_astroport(deps.as_ref(), &env, steps)? }; // Save price - PRICES.save(deps.storage, pair, &price)?; + PRICES.save(deps.storage, pair.clone(), &price)?; + + let event = ValenceEvent::OracleUpdatePrice { + pair: pair.clone(), + price: price.price, + source: source.to_string(), + }; - Ok(Response::default().add_attribute("price", price.to_string())) + Ok(Response::default().add_event(event.into())) } ExecuteMsg::ManualPriceUpdate { pair, price } => { let config = CONFIG.load(deps.storage)?; @@ -109,14 +120,20 @@ pub fn execute( // Save price PRICES.save( deps.storage, - pair, + pair.clone(), &Price { price, time: env.block.time, }, )?; - Ok(Response::default().add_attribute("price", price.to_string())) + let event = ValenceEvent::OracleUpdatePrice { + pair, + price, + source: "manual".to_string(), + }; + + Ok(Response::default().add_event(event.into())) } ExecuteMsg::AddAstroPath { pair, path } => { verify_admin(deps.as_ref(), &info)?; @@ -135,9 +152,11 @@ pub fn execute( return Err(ContractError::PricePathIsWrong); } - ASTRO_PRICE_PATHS.save(deps.storage, pair, &path)?; + ASTRO_PRICE_PATHS.save(deps.storage, pair.clone(), &path)?; - Ok(Response::default()) + let event = ValenceGenericEvent::OracleAddPath { pair, path }; + + Ok(Response::default().add_event(event.into())) } ExecuteMsg::UpdateAstroPath { pair, path } => { verify_admin(deps.as_ref(), &info)?; @@ -156,9 +175,11 @@ pub fn execute( return Err(ContractError::PricePathIsWrong); } - ASTRO_PRICE_PATHS.save(deps.storage, pair, &path)?; + ASTRO_PRICE_PATHS.save(deps.storage, pair.clone(), &path)?; + + let event = ValenceGenericEvent::OracleUpdatePath { pair, path }; - Ok(Response::default()) + Ok(Response::default().add_event(event.into())) } ExecuteMsg::UpdateConfig { auction_manager_addr, @@ -183,13 +204,24 @@ pub fn execute( CONFIG.save(deps.storage, &config)?; - Ok(Response::default()) + let event = ValenceGenericEvent::OracleUpdateConfig { config }; + + Ok(Response::default().add_event(event.into())) } ExecuteMsg::StartAdminChange { addr, expiration } => { - Ok(start_admin_change(deps, &info, &addr, expiration)?) + let event = ValenceEvent::OracleStartAdminChange { + admin: addr.clone(), + }; + Ok(start_admin_change(deps, &info, &addr, expiration)?.add_event(event.into())) + } + ExecuteMsg::CancelAdminChange {} => { + let event = ValenceEvent::OracleCancelAdminChange {}; + Ok(cancel_admin_change(deps, &info)?.add_event(event.into())) + } + ExecuteMsg::ApproveAdminChange {} => { + let event = ValenceEvent::OracleApproveAdminChange {}; + Ok(approve_admin_change(deps, &env, &info)?.add_event(event.into())) } - ExecuteMsg::CancelAdminChange {} => Ok(cancel_admin_change(deps, &info)?), - ExecuteMsg::ApproveAdminChange {} => Ok(approve_admin_change(deps, &env, &info)?), } } diff --git a/contracts/services/rebalancer/Cargo.toml b/contracts/services/rebalancer/Cargo.toml index c46e0f88..7af2ac36 100644 --- a/contracts/services/rebalancer/Cargo.toml +++ b/contracts/services/rebalancer/Cargo.toml @@ -28,6 +28,7 @@ valence-macros = { workspace = true } valence-package = { workspace = true } auction-package = { workspace = true } auctions-manager = { workspace = true } +auction = { workspace = true } [dev-dependencies] cw-multi-test = { workspace = true } diff --git a/contracts/services/rebalancer/schema/rebalancer.json b/contracts/services/rebalancer/schema/rebalancer.json index 2c7d5653..8150345b 100644 --- a/contracts/services/rebalancer/schema/rebalancer.json +++ b/contracts/services/rebalancer/schema/rebalancer.json @@ -1,6 +1,6 @@ { "contract_name": "rebalancer", - "contract_version": "1.2.0", + "contract_version": "0.1.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", diff --git a/contracts/services/rebalancer/src/contract.rs b/contracts/services/rebalancer/src/contract.rs index ec13175c..6414b189 100644 --- a/contracts/services/rebalancer/src/contract.rs +++ b/contracts/services/rebalancer/src/contract.rs @@ -11,6 +11,7 @@ use cosmwasm_std::{ use cw2::set_contract_version; use cw_storage_plus::Bound; use valence_package::error::ValenceError; +use valence_package::event_indexing::ValenceEvent; use valence_package::helpers::{approve_admin_change, verify_services_manager, OptionalField}; use valence_package::services::rebalancer::{ PauseData, RebalancerExecuteMsg, SystemRebalanceStatus, @@ -97,7 +98,10 @@ pub fn execute( ) -> Result { match msg { RebalancerExecuteMsg::Admin(admin_msg) => admin::handle_msg(deps, env, info, admin_msg), - RebalancerExecuteMsg::ApproveAdminChange => Ok(approve_admin_change(deps, &env, &info)?), + RebalancerExecuteMsg::ApproveAdminChange => { + let event = ValenceEvent::RebalancerApproveAdminChange {}; + Ok(approve_admin_change(deps, &env, &info)?.add_event(event.into())) + } RebalancerExecuteMsg::Register { register_for, data } => { let manager_addr = verify_services_manager(deps.as_ref(), &info)?; let data = data.ok_or(ContractError::MustProvideRebalancerData)?; @@ -210,18 +214,30 @@ pub fn execute( } // save config - CONFIGS.save(deps.storage, registree, &data.to_config(deps.api)?)?; + let config = data.to_config(deps.api)?; + CONFIGS.save(deps.storage, registree.clone(), &config)?; + + let event = ValenceEvent::RebalancerRegister { + account: registree.to_string(), + config, + }; - Ok(Response::default().add_messages(fee_msg)) + Ok(Response::default() + .add_event(event.into()) + .add_messages(fee_msg)) } RebalancerExecuteMsg::Deregister { deregister_for } => { verify_services_manager(deps.as_ref(), &info)?; let account = deps.api.addr_validate(&deregister_for)?; CONFIGS.remove(deps.storage, account.clone()); - PAUSED_CONFIGS.remove(deps.storage, account); + PAUSED_CONFIGS.remove(deps.storage, account.clone()); + + let event = ValenceEvent::RebalancerDeregister { + account: account.to_string(), + }; - Ok(Response::default()) + Ok(Response::default().add_event(event.into())) } RebalancerExecuteMsg::Update { update_for, data } => { verify_services_manager(deps.as_ref(), &info)?; @@ -304,9 +320,14 @@ pub fn execute( config.target_override_strategy = target_override_strategy; } - CONFIGS.save(deps.storage, account, &config)?; + CONFIGS.save(deps.storage, account.clone(), &config)?; + + let event = ValenceEvent::RebalancerUpdate { + account: account.to_string(), + config, + }; - Ok(Response::default()) + Ok(Response::default().add_event(event.into())) } RebalancerExecuteMsg::Pause { pause_for, @@ -356,19 +377,28 @@ pub fn execute( Ok(()) }; - if sender == account { - move_config_to_paused(account.clone())?; - return Ok(Response::default()); - }; - - if let Some(trustee) = config.trustee.clone() { - if trustee == sender { - move_config_to_paused(trustee.clone())?; + let response: Response = { + if sender == account { + move_config_to_paused(account.clone())?; return Ok(Response::default()); + }; + + if let Some(trustee) = config.trustee.clone() { + if trustee == sender { + move_config_to_paused(trustee.clone())?; + return Ok(Response::default()); + } } - } - Err(ContractError::NotAuthorizedToPause) + Err(ContractError::NotAuthorizedToPause) + }?; + + let event = ValenceEvent::RebalancerPause { + account: account.to_string(), + reason: reason.unwrap_or_default(), + }; + + Ok(response.add_event(event.into())) } RebalancerExecuteMsg::Resume { resume_for, sender } => { let manager_addr = verify_services_manager(deps.as_ref(), &info)?; @@ -458,9 +488,15 @@ pub fn execute( } CONFIGS.save(deps.storage, account.clone(), &paused_data.config)?; - PAUSED_CONFIGS.remove(deps.storage, account); + PAUSED_CONFIGS.remove(deps.storage, account.clone()); + + let event = ValenceEvent::RebalancerResume { + account: account.to_string(), + }; - Ok(Response::default().add_messages(fee_msg)) + Ok(Response::default() + .add_event(event.into()) + .add_messages(fee_msg)) } RebalancerExecuteMsg::SystemRebalance { limit } => { execute_system_rebalance(deps, &env, limit) @@ -471,6 +507,7 @@ pub fn execute( mod admin { use cosmwasm_std::{DepsMut, Env, MessageInfo, Response}; use valence_package::{ + event_indexing::ValenceEvent, helpers::{cancel_admin_change, start_admin_change, verify_admin}, services::rebalancer::{BaseDenom, RebalancerAdminMsg, SystemRebalanceStatus}, states::{SERVICES_MANAGER, SERVICE_FEE_CONFIG}, @@ -504,7 +541,9 @@ mod admin { SYSTEM_REBALANCE_STATUS.save(deps.storage, &status)?; - Ok(Response::default()) + let event = ValenceEvent::RebalancerUpdateSystemStatus { status }; + + Ok(Response::default().add_event(event.into())) } RebalancerAdminMsg::UpdateDenomWhitelist { to_add, to_remove } => { let mut denoms = DENOM_WHITELIST.load(deps.storage)?; @@ -521,7 +560,9 @@ mod admin { DENOM_WHITELIST.save(deps.storage, &denoms)?; - Ok(Response::default()) + let event = ValenceEvent::RebalancerUpdateDenomWhitelist { denoms }; + + Ok(Response::default().add_event(event.into())) } RebalancerAdminMsg::UpdateBaseDenomWhitelist { to_add, to_remove } => { let mut base_denoms = BASE_DENOM_WHITELIST.load(deps.storage)?; @@ -539,36 +580,56 @@ mod admin { BASE_DENOM_WHITELIST.save(deps.storage, &base_denoms)?; - Ok(Response::default()) + let event = ValenceEvent::RebalancerUpdateBaseDenomWhitelist { base_denoms }; + + Ok(Response::default().add_event(event.into())) } RebalancerAdminMsg::UpdateServicesManager { addr } => { let addr = deps.api.addr_validate(&addr)?; SERVICES_MANAGER.save(deps.storage, &addr)?; - Ok(Response::default()) + let event = ValenceEvent::RebalancerUpdateServicesManager { + addr: addr.to_string(), + }; + + Ok(Response::default().add_event(event.into())) } RebalancerAdminMsg::UpdateAuctionsManager { addr } => { let addr = deps.api.addr_validate(&addr)?; AUCTIONS_MANAGER_ADDR.save(deps.storage, &addr)?; - Ok(Response::default()) + let event = ValenceEvent::RebalancerUpdateAuctionsManager { + addr: addr.to_string(), + }; + + Ok(Response::default().add_event(event.into())) } RebalancerAdminMsg::UpdateCyclePeriod { period } => { CYCLE_PERIOD.save(deps.storage, &period)?; - Ok(Response::default()) + let event = ValenceEvent::RebalancerUpdateCyclePeriod { period }; + + Ok(Response::default().add_event(event.into())) } RebalancerAdminMsg::UpdateFess { fees } => { SERVICE_FEE_CONFIG.save(deps.storage, &fees)?; - Ok(Response::default()) + let event = ValenceEvent::RebalancerUpdateFees { fees }; + + Ok(Response::default().add_event(event.into())) } RebalancerAdminMsg::StartAdminChange { addr, expiration } => { - Ok(start_admin_change(deps, &info, &addr, expiration)?) + let event = ValenceEvent::RebalancerStartAdminChange { + admin: addr.clone(), + }; + Ok(start_admin_change(deps, &info, &addr, expiration)?.add_event(event.into())) + } + RebalancerAdminMsg::CancelAdminChange => { + let event = ValenceEvent::RebalancerCancelAdminChange {}; + Ok(cancel_admin_change(deps, &info)?.add_event(event.into())) } - RebalancerAdminMsg::CancelAdminChange => Ok(cancel_admin_change(deps, &info)?), } } } diff --git a/contracts/services/rebalancer/src/error.rs b/contracts/services/rebalancer/src/error.rs index 297393f7..8eaf47a4 100644 --- a/contracts/services/rebalancer/src/error.rs +++ b/contracts/services/rebalancer/src/error.rs @@ -102,4 +102,7 @@ pub enum ContractError { #[error("Cannot remove denom that doesn't exist: {0}")] CannotRemoveDenom(String), + + #[error("Cannot find pair address: {0} / {1}")] + PairDoesntExists(String, String), } diff --git a/contracts/services/rebalancer/src/helpers.rs b/contracts/services/rebalancer/src/helpers.rs index 166f67a2..207b3abf 100644 --- a/contracts/services/rebalancer/src/helpers.rs +++ b/contracts/services/rebalancer/src/helpers.rs @@ -1,5 +1,9 @@ -use cosmwasm_std::{Decimal, Event, SubMsg, Uint128}; -use valence_package::services::rebalancer::{ParsedTarget, RebalancerConfig}; +use cosmwasm_std::{Decimal, SubMsg, Uint128}; +use serde::Serialize; +use valence_package::{ + event_indexing::ValenceGenericEvent, + services::rebalancer::{ParsedTarget, RebalancerConfig}, +}; pub const TRADE_HARD_LIMIT: Decimal = Decimal::raw(5_u128); @@ -25,18 +29,18 @@ pub struct TargetHelper { pub auction_min_amount: Decimal, } -pub struct RebalanceResponse { +pub struct RebalanceResponse { pub config: RebalancerConfig, pub msg: Option, - pub event: Event, + pub event: ValenceGenericEvent, pub should_pause: bool, } -impl RebalanceResponse { +impl RebalanceResponse { pub fn new( config: RebalancerConfig, msg: Option, - event: Event, + event: ValenceGenericEvent, should_pause: bool, ) -> Self { Self { diff --git a/contracts/services/rebalancer/src/rebalance.rs b/contracts/services/rebalancer/src/rebalance.rs index bedc10e0..bba7f0e8 100644 --- a/contracts/services/rebalancer/src/rebalance.rs +++ b/contracts/services/rebalancer/src/rebalance.rs @@ -2,18 +2,20 @@ use std::{borrow::BorrowMut, collections::HashMap, str::FromStr}; use auction_package::{ helpers::GetPriceResponse, - states::{MinAmount, MIN_AUCTION_AMOUNT}, + states::{MinAmount, MIN_AUCTION_AMOUNT, PAIRS}, Pair, }; use cosmwasm_std::{ - coin, to_json_binary, Addr, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, Event, Order, + coins, to_json_binary, Addr, CosmosMsg, Decimal, Deps, DepsMut, Empty, Env, Event, Order, Response, StdError, SubMsg, Uint128, WasmMsg, }; use cw_storage_plus::Bound; use valence_package::{ + event_indexing::ValenceEvent, helpers::start_of_cycle, services::rebalancer::{ - ParsedPID, PauseData, RebalancerConfig, SystemRebalanceStatus, TargetOverrideStrategy, + ParsedPID, PauseData, RebalanceTrade, RebalancerConfig, SystemRebalanceStatus, + TargetOverrideStrategy, }, signed_decimal::SignedDecimal, CLOSEST_TO_ONE_POSSIBLE, @@ -109,7 +111,7 @@ pub fn execute_system_rebalance( let mut min_amount_limits: Vec<(String, Uint128)> = vec![]; let mut msgs: Vec = vec![]; - let mut events: Vec = vec![]; + let mut account_events: Vec = vec![]; for res in configs { let Ok((account, config)) = res else { @@ -157,7 +159,7 @@ pub fn execute_system_rebalance( } // Add event to all events - events.push(event); + account_events.push(event.into()); if let Some(msg) = msg { msgs.push(msg); @@ -180,14 +182,15 @@ pub fn execute_system_rebalance( SYSTEM_REBALANCE_STATUS.save(deps.storage, &status)?; + let event = ValenceEvent::RebalancerCycle { + limit: limit as u64, + cycled_over: configs_len as u64, + }; + Ok(Response::default() - .add_submessages(msgs) - .add_events(events) - .add_event( - Event::new("rebalance_cycle") - .add_attribute("limit", limit.to_string()) - .add_attribute("cycled_over", configs_len.to_string()), - )) + .add_event(event.into()) + .add_events(account_events) + .add_submessages(msgs)) } /// Make sure the balance of the account is not zero and is above our minimum value @@ -218,10 +221,7 @@ pub fn do_rebalance( min_values: &HashMap, prices: &[(Pair, Decimal)], cycle_period: u64, -) -> Result { - // Create new event to show important data about the rebalance - let mut event = Event::new("rebalance-account").add_attribute("account", account.to_string()); - +) -> Result, ContractError> { // get a vec of inputs for our calculations let (total_value, mut target_helpers) = get_inputs(deps, account, &config, prices)?; @@ -231,14 +231,15 @@ pub fn do_rebalance( .unwrap_or(&Uint128::zero()); if verify_account_balance(total_value.to_uint_floor(), min_value).is_err() { - event = event.add_attribute("pausing", true.to_string()); + let event = ValenceEvent::RebalancerAccountRebalancePause { + account: account.to_string(), + total_value, + }; // We pause the account if the account balance doesn't meet the minimum requirements return Ok(RebalanceResponse::new(config, None, event, true)); }; - event = event.add_attribute("total_account_value", total_value.to_string()); - // Verify the targets, if we have a min_balance we need to do some extra steps // to make sure min_balance is accounted for in our calculations if config.has_min_balance { @@ -262,15 +263,8 @@ pub fn do_rebalance( set_auction_min_amounts(deps, auction_manager, &mut to_sell, min_amount_limits)?; // Generate the trades msgs, how much funds to send to what auction. - let (msgs, event) = generate_trades_msgs( - deps, - to_sell, - to_buy, - auction_manager, - &config, - total_value, - event, - ); + let (msgs, trades) = + generate_trades_msgs(deps, to_sell, to_buy, auction_manager, &config, total_value); // Construct the msg we need to execute on the account // Notice the atomic false, it means each trade msg (sending funds to specific pair auction) @@ -294,6 +288,12 @@ pub fn do_rebalance( // We edit config to save data for the next rebalance calculation config.last_rebalance = env.block.time; + let event = ValenceEvent::RebalancerAccountRebalance { + account: account.to_string(), + total_value, + trades, + }; + Ok(RebalanceResponse::new(config, Some(msg), event, false)) } @@ -569,15 +569,18 @@ pub fn verify_targets( /// Construct the messages the account need to exeucte (send funds to auctions) fn construct_msg( - _deps: Deps, - auction_manager: &Addr, - pair: Pair, - amount: Coin, + deps: Deps, + auction_manager: Addr, + trade: RebalanceTrade, ) -> Result { + let Some(pair_addr) = PAIRS.query(&deps.querier, auction_manager, trade.pair.clone())? else { + return Err(ContractError::PairDoesntExists(trade.pair.0, trade.pair.1)); + }; + let msg = WasmMsg::Execute { - contract_addr: auction_manager.to_string(), - msg: to_json_binary(&auctions_manager::msg::ExecuteMsg::AuctionFunds { pair })?, - funds: vec![amount], + contract_addr: pair_addr.to_string(), + msg: to_json_binary(&auction::msg::ExecuteMsg::AuctionFunds {})?, + funds: coins(trade.amount.u128(), trade.pair.0), }; Ok(msg.into()) @@ -591,9 +594,10 @@ fn generate_trades_msgs( auction_manager: &Addr, config: &RebalancerConfig, total_value: Decimal, - mut event: Event, -) -> (Vec, Event) { - let mut msgs: Vec = vec![]; +) -> (Vec, Vec) { + let max_trades = to_sell.len().max(to_buy.len()); + let mut msgs: Vec = Vec::with_capacity(max_trades); + let mut trades: Vec = Vec::with_capacity(max_trades); // Get max tokens to sell as a value and not amount let mut max_sell = config.max_limit * total_value; @@ -638,11 +642,11 @@ fn generate_trades_msgs( token_buy.target.denom.clone(), )); let amount = (token_sell.auction_min_amount * token_sell.price).to_uint_ceil(); - let coin = coin(amount.u128(), &pair.0); + let trade = RebalanceTrade::new(pair, amount); token_buy.value_to_trade = Decimal::zero(); - if let Ok(msg) = construct_msg(deps, auction_manager, pair, coin) { + if let Ok(msg) = construct_msg(deps, auction_manager.clone(), trade.clone()) { max_sell -= token_sell.auction_min_amount; msgs.push(msg); }; @@ -709,47 +713,34 @@ fn generate_trades_msgs( if token_sell.value_to_trade >= token_buy.value_to_trade { token_sell.value_to_trade -= token_buy.value_to_trade; - let token = coin( - (token_buy.value_to_trade * token_sell.price) - .to_uint_ceil() - .u128(), - token_sell.target.denom.clone(), - ); + let amount = (token_buy.value_to_trade * token_sell.price).to_uint_ceil(); + let trade = RebalanceTrade::new(pair, amount); token_buy.value_to_trade = Decimal::zero(); - event = event - .clone() - .add_attribute("trade", format!("Coin: {token} | Pair: {pair:?}")); - - let Ok(msg) = construct_msg(deps, auction_manager, pair, token) else { + let Ok(msg) = construct_msg(deps, auction_manager.clone(), trade.clone()) else { return; }; + msgs.push(msg); + trades.push(trade); } else { token_buy.value_to_trade -= token_sell.value_to_trade; - let token = coin( - (token_sell.value_to_trade * token_sell.price) - .to_uint_ceil() - .u128(), - token_sell.target.denom.clone(), - ); + let amount = (token_sell.value_to_trade * token_sell.price).to_uint_ceil(); + let trade = RebalanceTrade::new(pair, amount); token_sell.value_to_trade = Decimal::zero(); - event = event - .clone() - .add_attribute("trade", format!("Coin: {token} | Pair: {pair:?}")); - - let Ok(msg) = construct_msg(deps, auction_manager, pair, token) else { + let Ok(msg) = construct_msg(deps, auction_manager.clone(), trade.clone()) else { return; }; msgs.push(msg); + trades.push(trade); } }); }); - (msgs, event) + (msgs, trades) } diff --git a/contracts/services_manager/schema/services-manager.json b/contracts/services_manager/schema/services-manager.json index 87b7aa6c..e32ecd70 100644 --- a/contracts/services_manager/schema/services-manager.json +++ b/contracts/services_manager/schema/services-manager.json @@ -1,6 +1,6 @@ { "contract_name": "services-manager", - "contract_version": "1.2.0", + "contract_version": "0.1.0", "idl_version": "1.0.0", "instantiate": { "$schema": "http://json-schema.org/draft-07/schema#", @@ -676,16 +676,10 @@ }, "is_service": { "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ValenceServices", - "description": "An enum that represent all services that available for valence accounts", - "oneOf": [ - { - "description": "The rebalancer service", - "type": "string", - "enum": [ - "rebalancer" - ] - } + "title": "Nullable_String", + "type": [ + "string", + "null" ] } } diff --git a/contracts/services_manager/src/contract.rs b/contracts/services_manager/src/contract.rs index 63aabfe5..e063be6b 100644 --- a/contracts/services_manager/src/contract.rs +++ b/contracts/services_manager/src/contract.rs @@ -111,6 +111,7 @@ pub fn execute( mod admin { use valence_package::{ + event_indexing::ValenceEvent, helpers::{cancel_admin_change, start_admin_change, verify_admin}, msgs::core_execute::ServicesManagerAdminMsg, }; @@ -137,10 +138,15 @@ mod admin { } else if ADDR_TO_SERVICES.has(deps.storage, addr.clone()) { return Err(ContractError::ServiceAddressAlreadyExists(addr.to_string())); } else { - save_service(deps, name.to_string(), addr)?; + save_service(deps, name.to_string(), addr.clone())?; } - Ok(Response::default().add_attribute("method", "add_service")) + let event = ValenceEvent::ServicesManagerAddService { + service_name: name.to_string(), + addr: addr.to_string(), + }; + + Ok(Response::default().add_event(event.into())) } ServicesManagerAdminMsg::UpdateService { name, addr } => { let addr = deps.api.addr_validate(&addr)?; @@ -151,44 +157,63 @@ mod admin { return Err(ContractError::ServiceDoesntExistYet(name.to_string())); } - save_service(deps, name.to_string(), addr)?; + save_service(deps, name.to_string(), addr.clone())?; - Ok(Response::default().add_attribute("method", "update_service")) + let event = ValenceEvent::ServicesManagerUpdateService { + service_name: name.to_string(), + addr: addr.to_string(), + }; + + Ok(Response::default().add_event(event.into())) } ServicesManagerAdminMsg::RemoveService { name } => { let addr = get_service_addr(deps.as_ref(), name.to_string())?; remove_service(deps, name.to_string(), addr)?; - Ok(Response::default().add_attribute("method", "remove_service")) + let event = ValenceEvent::ServicesManagerRemoveService { + service_name: name.to_string(), + }; + + Ok(Response::default().add_event(event.into())) } ServicesManagerAdminMsg::UpdateCodeIdWhitelist { to_add, to_remove } => { let mut whitelist = ACCOUNT_WHITELISTED_CODE_IDS.load(deps.storage)?; - whitelist.extend(to_add); + whitelist.extend(to_add.clone()); - for code_id in to_remove { - if !whitelist.remove(&code_id) { - return Err(ContractError::CodeIdNotInWhitelist(code_id)); + for code_id in &to_remove { + if !whitelist.remove(code_id) { + return Err(ContractError::CodeIdNotInWhitelist(*code_id)); } } ACCOUNT_WHITELISTED_CODE_IDS.save(deps.storage, &whitelist)?; - Ok(Response::default().add_attribute("method", "update_code_id_whitelist")) + let event = + ValenceEvent::ServicesManagerUpdateCodeIdWhitelist { to_add, to_remove }; + Ok(Response::default().add_event(event.into())) } ServicesManagerAdminMsg::StartAdminChange { addr, expiration } => { - Ok(start_admin_change(deps, &info, &addr, expiration)?) + let event = ValenceEvent::ServicesManagerStartAdminChange { + admin: addr.clone(), + }; + Ok(start_admin_change(deps, &info, &addr, expiration)?.add_event(event.into())) + } + ServicesManagerAdminMsg::CancelAdminChange => { + let event = ValenceEvent::ServicesManagerCancelAdminChange {}; + Ok(cancel_admin_change(deps, &info)?.add_event(event.into())) } - ServicesManagerAdminMsg::CancelAdminChange => Ok(cancel_admin_change(deps, &info)?), ServicesManagerAdminMsg::Withdraw { denom } => { let amount = deps.querier.query_balance(env.contract.address, denom)?; let msg = BankMsg::Send { to_address: info.sender.to_string(), // sender must be admin - amount: vec![amount], + amount: vec![amount.clone()], }; - Ok(Response::default().add_message(msg)) + let event = ValenceEvent::ServicesManagerWithdraw { amount }; + + Ok(Response::default().add_event(event.into()).add_message(msg)) } } } @@ -198,7 +223,8 @@ mod admin { pub fn query(deps: Deps, _env: Env, msg: ServicesManagerQueryMsg) -> StdResult { match msg { ServicesManagerQueryMsg::IsService { addr } => { - let is_service = ADDR_TO_SERVICES.has(deps.storage, deps.api.addr_validate(&addr)?); + let is_service = + ADDR_TO_SERVICES.may_load(deps.storage, deps.api.addr_validate(&addr)?)?; to_json_binary(&is_service) } ServicesManagerQueryMsg::GetServiceAddr { service } => { diff --git a/devtools/optimize.sh b/devtools/optimize.sh index f5e3ab5b..b9860659 100755 --- a/devtools/optimize.sh +++ b/devtools/optimize.sh @@ -11,5 +11,5 @@ else docker run --rm -v "$(pwd)":/code \ --mount type=volume,source="$(basename "$(pwd)")_cache",target=/target \ --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/optimizer:0.15.0 + cosmwasm/optimizer:0.15.1 fi diff --git a/packages/valence-macros/src/lib.rs b/packages/valence-macros/src/lib.rs index 77c85d15..9317ebbb 100644 --- a/packages/valence-macros/src/lib.rs +++ b/packages/valence-macros/src/lib.rs @@ -169,7 +169,7 @@ pub fn valence_services_manager_query_msgs( let quote = quote! { enum ServicesManagerQueryMsg { /// Check if address is of a service - #[returns(ValenceServices)] + #[returns(Option)] IsService { addr: String, }, diff --git a/packages/valence-package/src/event_indexing.rs b/packages/valence-package/src/event_indexing.rs new file mode 100644 index 00000000..a39740a3 --- /dev/null +++ b/packages/valence-package/src/event_indexing.rs @@ -0,0 +1,426 @@ +use std::{collections::HashSet, fmt}; + +use auction_package::{ + helpers::{AuctionConfig, ChainHaltConfig}, + states::MinAmount, + AuctionStrategy, Pair, PriceFreshnessStrategy, +}; +use cosmwasm_std::{ + to_json_binary, Binary, Coin, CosmosMsg, Decimal, Empty, Event, SubMsg, Uint128, +}; +use serde::Serialize; + +use crate::services::rebalancer::{ + BaseDenom, RebalanceTrade, RebalancerConfig, ServiceFeeConfig, SystemRebalanceStatus, +}; + +pub type ValenceEvent = ValenceGenericEvent; + +#[derive( + cosmwasm_schema::serde::Serialize, + cosmwasm_schema::serde::Deserialize, + std::clone::Clone, + std::fmt::Debug, + std::cmp::PartialEq, + cosmwasm_schema::schemars::JsonSchema, +)] +#[serde(deny_unknown_fields, rename_all = "kebab-case")] +#[schemars(crate = "cosmwasm_schema::schemars")] +pub enum ValenceGenericEvent +where + E: Serialize, +{ + AccountCreation { + /// The admin address of the account + admin: String, + /// where the account was created from (native, 3rd-party, etc) + referral: String, + }, + AccountRegisterService { + service_name: String, + data: Option, + }, + AccountUpdateService { + service_name: String, + data: Binary, + }, + AccountDeregisterService { + service_name: String, + }, + AccountPauseService { + service_name: String, + }, + AccountResumeService { + service_name: String, + }, + AccountSendFundsByService { + service_name: String, + msgs: Vec, + atomic: bool, + }, + AccountExecuteByService { + service_name: String, + msgs: Vec, + atomic: bool, + }, + AccountExecuteByAdmin { + msgs: Vec, + }, + AccountStartAdminChange { + admin: String, + }, + AccountCancelAdminChange {}, + AccountApproveAdminChange {}, + + // Oracle + OracleUpdatePrice { + pair: Pair, + price: Decimal, + source: String, + }, + OracleAddPath { + pair: Pair, + path: Vec, + }, + OracleUpdatePath { + pair: Pair, + path: Vec, + }, + OracleUpdateConfig { + config: E, + }, + OracleStartAdminChange { + admin: String, + }, + OracleCancelAdminChange {}, + OracleApproveAdminChange {}, + + // Auction manager + AuctionManagerUpdateAuctionCodeId { + code_id: u64, + }, + AuctionManagerUpdateOracle { + oracle_addr: String, + }, + AuctionManagerMigrateAuction { + pair: Pair, + code_id: u64, + msg: E, + }, + AuctionManagerUpdateMinAmount { + denom: String, + min_amount: MinAmount, + }, + AuctionManagerStartAdminChange { + admin: String, + }, + AuctionManagerCancelAdminChange {}, + AuctionManagerApproveAdminChange {}, + + // Auctions + AuctionInit { + config: AuctionConfig, + strategy: AuctionStrategy, + }, + AuctionAuctionFunds { + address: String, + amount: Uint128, + auction_id: u64, + }, + AuctionWithdrawFunds { + address: String, + amount: Uint128, + auction_id: u64, + }, + AuctionDoBid { + auction_id: u64, + bidder: String, + price: Decimal, + /// How much of token.0 the bidder bought + bought_amount: Uint128, + /// If bidder sent too much and we couldn't "swap" all, then we refund him the rest + refunded_amount: Uint128, + }, + AuctionPause {}, + AuctionResume {}, + AuctionUpdateStrategy { + strategy: AuctionStrategy, + }, + AuctionUpdateChainHaltConfig { + halt_config: ChainHaltConfig, + }, + AuctionUpdatePriceFreshnessStrategy { + strategy: PriceFreshnessStrategy, + }, + AuctionOpen { + auction_id: u64, + auction: E, + }, + AuctionOpenRefund { + auction_id: u64, + min_amount: Uint128, + refund_amount: Uint128, + total_users: u64, + }, + AuctionClose { + auction_id: u64, + is_closed: bool, + price: String, + accounts: u64, + }, + + // Services manager + ServicesManagerAddService { + service_name: String, + addr: String, + }, + ServicesManagerUpdateService { + service_name: String, + addr: String, + }, + ServicesManagerRemoveService { + service_name: String, + }, + ServicesManagerUpdateCodeIdWhitelist { + to_add: Vec, + to_remove: Vec, + }, + ServicesManagerWithdraw { + amount: Coin, + }, + ServicesManagerStartAdminChange { + admin: String, + }, + ServicesManagerCancelAdminChange {}, + ServicesManagerApproveAdminChange {}, + + // Rebalancer + RebalancerRegister { + account: String, + config: RebalancerConfig, + }, + RebalancerDeregister { + account: String, + }, + RebalancerUpdate { + account: String, + config: RebalancerConfig, + }, + RebalancerPause { + account: String, + reason: String, + }, + RebalancerResume { + account: String, + }, + RebalancerUpdateSystemStatus { + status: SystemRebalanceStatus, + }, + RebalancerUpdateDenomWhitelist { + denoms: HashSet, + }, + RebalancerUpdateBaseDenomWhitelist { + base_denoms: HashSet, + }, + RebalancerUpdateServicesManager { + addr: String, + }, + RebalancerUpdateAuctionsManager { + addr: String, + }, + RebalancerUpdateCyclePeriod { + period: u64, + }, + RebalancerUpdateFees { + fees: ServiceFeeConfig, + }, + RebalancerStartAdminChange { + admin: String, + }, + RebalancerCancelAdminChange {}, + RebalancerApproveAdminChange {}, + RebalancerCycle { + limit: u64, + cycled_over: u64, + }, + RebalancerAccountRebalance { + account: String, + total_value: Decimal, + trades: Vec, + }, + RebalancerAccountRebalancePause { + account: String, + total_value: Decimal, + }, +} + +/// Turn a ValenceServices enum into a string +impl fmt::Display for ValenceGenericEvent { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + // Account + ValenceGenericEvent::AccountCreation { .. } => write!(f, "account-creation"), + ValenceGenericEvent::AccountRegisterService { .. } => { + write!(f, "account-register-service") + } + ValenceGenericEvent::AccountUpdateService { .. } => write!(f, "account-update-service"), + ValenceGenericEvent::AccountDeregisterService { .. } => { + write!(f, "account-deregister-service") + } + ValenceGenericEvent::AccountPauseService { .. } => write!(f, "account-pause-service"), + ValenceGenericEvent::AccountResumeService { .. } => write!(f, "account-resume-service"), + ValenceGenericEvent::AccountSendFundsByService { .. } => { + write!(f, "account-send-funds-by-service") + } + ValenceGenericEvent::AccountExecuteByService { .. } => { + write!(f, "account-execute-by-service") + } + ValenceGenericEvent::AccountExecuteByAdmin { .. } => { + write!(f, "account-execute-by-admin") + } + ValenceGenericEvent::AccountStartAdminChange { .. } => { + write!(f, "account-start-admin-change") + } + ValenceGenericEvent::AccountCancelAdminChange {} => { + write!(f, "account-cancel-admin-change") + } + ValenceGenericEvent::AccountApproveAdminChange {} => { + write!(f, "account-approve-admin-change") + } + + // oracle + ValenceGenericEvent::OracleUpdatePrice { .. } => write!(f, "oracle-update-price"), + ValenceGenericEvent::OracleAddPath { .. } => write!(f, "oracle-add-path"), + ValenceGenericEvent::OracleUpdatePath { .. } => write!(f, "oracle-update-path"), + ValenceGenericEvent::OracleUpdateConfig { .. } => write!(f, "oracle-update-config"), + ValenceGenericEvent::OracleStartAdminChange { .. } => { + write!(f, "oracle-start-admin-change") + } + ValenceGenericEvent::OracleCancelAdminChange {} => { + write!(f, "oracle-cancel-admin-change") + } + ValenceGenericEvent::OracleApproveAdminChange {} => { + write!(f, "oracle-approve-admin-change") + } + + // Auction manager + ValenceGenericEvent::AuctionManagerUpdateAuctionCodeId { .. } => { + write!(f, "auction-manager-update-auction-code-id") + } + ValenceGenericEvent::AuctionManagerUpdateOracle { .. } => { + write!(f, "auction-manager-update-oracle") + } + ValenceGenericEvent::AuctionManagerMigrateAuction { .. } => { + write!(f, "auction-manager-migrate-auction") + } + ValenceGenericEvent::AuctionManagerUpdateMinAmount { .. } => { + write!(f, "auction-manager-update-min-amount") + } + ValenceGenericEvent::AuctionManagerStartAdminChange { .. } => { + write!(f, "auction-manager-start-admin-change") + } + ValenceGenericEvent::AuctionManagerCancelAdminChange {} => { + write!(f, "auction-manager-cancel-admin-change") + } + ValenceGenericEvent::AuctionManagerApproveAdminChange {} => { + write!(f, "auction-manager-approve-admin-change") + } + + // auctions + ValenceGenericEvent::AuctionInit { .. } => write!(f, "auction-init"), + ValenceGenericEvent::AuctionAuctionFunds { .. } => write!(f, "auction-auction-funds"), + ValenceGenericEvent::AuctionWithdrawFunds { .. } => write!(f, "auction-withdraw-funds"), + ValenceGenericEvent::AuctionDoBid { .. } => write!(f, "auction-do-bid"), + ValenceGenericEvent::AuctionPause {} => write!(f, "auction-pause"), + ValenceGenericEvent::AuctionResume {} => write!(f, "auction-resume"), + ValenceGenericEvent::AuctionUpdateStrategy { .. } => { + write!(f, "auction-update-strategy") + } + ValenceGenericEvent::AuctionUpdateChainHaltConfig { .. } => { + write!(f, "auction-update-chain-halt-config") + } + ValenceGenericEvent::AuctionUpdatePriceFreshnessStrategy { .. } => { + write!(f, "auction-update-price-freshness-strategy") + } + ValenceGenericEvent::AuctionOpen { .. } => write!(f, "auction-open"), + ValenceGenericEvent::AuctionOpenRefund { .. } => write!(f, "auction-open-refund"), + ValenceGenericEvent::AuctionClose { .. } => write!(f, "auction-close"), + + // Services manager + ValenceGenericEvent::ServicesManagerAddService { .. } => { + write!(f, "services-manager-add-service") + } + ValenceGenericEvent::ServicesManagerUpdateService { .. } => { + write!(f, "services-manager-update-service") + } + ValenceGenericEvent::ServicesManagerRemoveService { .. } => { + write!(f, "services-manager-remove-service") + } + ValenceGenericEvent::ServicesManagerUpdateCodeIdWhitelist { .. } => { + write!(f, "services-manager-update-code-id-whitelist") + } + ValenceGenericEvent::ServicesManagerWithdraw { .. } => { + write!(f, "services-manager-withdraw") + } + ValenceGenericEvent::ServicesManagerStartAdminChange { .. } => { + write!(f, "services-manager-start-admin-change") + } + ValenceGenericEvent::ServicesManagerCancelAdminChange {} => { + write!(f, "services-manager-cancel-admin-change") + } + ValenceGenericEvent::ServicesManagerApproveAdminChange {} => { + write!(f, "services-manager-approve-admin-change") + } + + // Rebalancer + ValenceGenericEvent::RebalancerRegister { .. } => write!(f, "rebalancer-register"), + ValenceGenericEvent::RebalancerDeregister { .. } => write!(f, "rebalancer-deregister"), + ValenceGenericEvent::RebalancerUpdate { .. } => write!(f, "rebalancer-update"), + ValenceGenericEvent::RebalancerPause { .. } => write!(f, "rebalancer-pause"), + ValenceGenericEvent::RebalancerResume { .. } => write!(f, "rebalancer-resume"), + ValenceGenericEvent::RebalancerUpdateSystemStatus { .. } => { + write!(f, "rebalancer-update-system-status") + } + ValenceGenericEvent::RebalancerUpdateDenomWhitelist { .. } => { + write!(f, "rebalancer-update-denom-whitelist") + } + ValenceGenericEvent::RebalancerUpdateBaseDenomWhitelist { .. } => { + write!(f, "rebalancer-update-base-denom-whitelist") + } + ValenceGenericEvent::RebalancerUpdateServicesManager { .. } => { + write!(f, "rebalancer-update-services-manager") + } + ValenceGenericEvent::RebalancerUpdateAuctionsManager { .. } => { + write!(f, "rebalancer-update-auctions-manager") + } + ValenceGenericEvent::RebalancerUpdateCyclePeriod { .. } => { + write!(f, "rebalancer-update-cycle-period") + } + ValenceGenericEvent::RebalancerUpdateFees { .. } => write!(f, "rebalancer-update-fees"), + ValenceGenericEvent::RebalancerStartAdminChange { .. } => { + write!(f, "rebalancer-start-admin-change") + } + ValenceGenericEvent::RebalancerCancelAdminChange {} => { + write!(f, "rebalancer-cancel-admin-change") + } + ValenceGenericEvent::RebalancerApproveAdminChange {} => { + write!(f, "rebalancer-approve-admin-change") + } + ValenceGenericEvent::RebalancerCycle { .. } => write!(f, "rebalancer-cycle"), + ValenceGenericEvent::RebalancerAccountRebalance { .. } => { + write!(f, "rebalancer-account-rebalance") + } + ValenceGenericEvent::RebalancerAccountRebalancePause { .. } => { + write!(f, "rebalancer-account-rebalance-pause") + } + } + } +} + +impl From> for Event { + fn from(value: ValenceGenericEvent) -> Self { + Event::new("valence-event") + .add_attribute("action", value.to_string()) + .add_attribute("data", to_json_binary(&value).unwrap().to_string()) + } +} diff --git a/packages/valence-package/src/helpers.rs b/packages/valence-package/src/helpers.rs index 01ebf40b..4d20be77 100644 --- a/packages/valence-package/src/helpers.rs +++ b/packages/valence-package/src/helpers.rs @@ -53,16 +53,15 @@ pub fn sender_is_a_service( deps: DepsMut, info: &MessageInfo, manager_addr: String, -) -> Result<(), ValenceError> { - if deps.querier.query_wasm_smart::( +) -> Result { + match deps.querier.query_wasm_smart::>( manager_addr, &ServicesManagerQueryMsg::IsService { addr: info.sender.to_string(), }, )? { - Ok(()) - } else { - Err(ValenceError::UnauthorizedService) + Some(addr) => Ok(deps.api.addr_validate(&addr)?), + None => Err(ValenceError::UnauthorizedService), } } diff --git a/packages/valence-package/src/lib.rs b/packages/valence-package/src/lib.rs index 7c533291..17a1767f 100644 --- a/packages/valence-package/src/lib.rs +++ b/packages/valence-package/src/lib.rs @@ -1,4 +1,5 @@ pub mod error; +pub mod event_indexing; pub mod helpers; pub mod msgs; pub mod services; diff --git a/packages/valence-package/src/services/mod.rs b/packages/valence-package/src/services/mod.rs index c1b30717..5bc8b4c1 100644 --- a/packages/valence-package/src/services/mod.rs +++ b/packages/valence-package/src/services/mod.rs @@ -16,6 +16,7 @@ pub enum GeneralServiceExecuteMsg {} /// An enum that represent all services that available for valence accounts #[cw_serde] +#[derive(Copy)] pub enum ValenceServices { /// The rebalancer service Rebalancer, diff --git a/packages/valence-package/src/services/rebalancer.rs b/packages/valence-package/src/services/rebalancer.rs index af92370d..c087e19e 100644 --- a/packages/valence-package/src/services/rebalancer.rs +++ b/packages/valence-package/src/services/rebalancer.rs @@ -414,6 +414,18 @@ impl ServiceFeeConfig { } } +#[cw_serde] +pub struct RebalanceTrade { + pub pair: Pair, + pub amount: Uint128, +} + +impl RebalanceTrade { + pub fn new(pair: Pair, amount: Uint128) -> Self { + Self { pair, amount } + } +} + #[cfg(test)] mod test { use crate::error::ValenceError; diff --git a/scripts/general_commands.txt b/scripts/general_commands.txt index 865a0133..d3f7aebe 100644 --- a/scripts/general_commands.txt +++ b/scripts/general_commands.txt @@ -14,7 +14,7 @@ neutrond tx wasm execute neutron1qs6mzpmcw3dvg5l8nyywetcj326scszdj7v4pfk55xwshd4 neutrond tx wasm execute neutron1qs6mzpmcw3dvg5l8nyywetcj326scszdj7v4pfk55xwshd4prqnqfwc0z2 '{"admin":{"update_base_denom_whitelist": {"to_add": [{"denom": "ibc/B559A80D62249C8AA07A380E2A2BEA6E5CA9A6F079C912C3A9E9B494105E4F81", "min_balance_limit": "10000000"}], "to_remove":[]}}}' --from ntrn-main-tester --gas-prices 0.075untrn --gas auto --gas-adjustment 1.4 --output json -y // update auction code id in auctions manager -neutrond tx wasm execute neutron13exc5wdc7y5qpqazc34djnu934lqvfw2dru30j52ahhjep6jzx8ssjxcyz '{"admin": {"update_auction_id":"869"}}' --from ntrn-main-tester --gas-prices 0.075untrn --gas auto --gas-adjustment 1.4 --output json -y +neutrond tx wasm execute neutron13exc5wdc7y5qpqazc34djnu934lqvfw2dru30j52ahhjep6jzx8ssjxcyz '{"admin": {"update_auction_id":{"code_id": 903}}}' --from ntrn-main-tester --gas-prices 0.075untrn --gas auto --gas-adjustment 1.4 --output json -y // Send funds to the auction manually (outside of the rebalancer) neutrond tx wasm execute neutron13jppm4n77u8ud5wma9xe0dqnaz85ne9jem3r0scc009uemvh49qqxuuggf '{"auction_funds": {}}' --amount 1500000untrn --from ntrn-main-tester --gas-prices 0.075untrn --gas auto --gas-adjustment 1.4 --output json -y @@ -25,3 +25,6 @@ neutrond tx wasm execute neutron13exc5wdc7y5qpqazc34djnu934lqvfw2dru30j52ahhjep6 // Update price in the oracle for a pair neutrond tx wasm execute neutron1s8uqyh0mmh8g66s2dectf56c08y6fvusp39undp8kf4v678ededsy6tstf '{"update_price": {"pair": ["ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9", "factory/neutron1p8d89wvxyjcnawmgw72klknr3lg9gwwl6ypxda/newt"]}}' --from ntrn-main-tester --gas-prices 0.075untrn --gas auto --gas-adjustment 1.4 --output json -y +// update account code id on the services manager +neutrond tx wasm execute neutron1gantvpnat0la8kkkzrnj48d5d8wxdjllh5r2w4r2hcrpwy00s69quypupa '{"admin": {"update_code_id_whitelist": {"to_add": [902], "to_remove": []}}}' --from ntrn-main-tester --gas-prices 0.075untrn --gas auto --gas-adjustment 1.4 --output json -y + diff --git a/tests/rust-tests/src/suite/instantiates/account.rs b/tests/rust-tests/src/suite/instantiates/account.rs index 3e4f2f21..25601890 100644 --- a/tests/rust-tests/src/suite/instantiates/account.rs +++ b/tests/rust-tests/src/suite/instantiates/account.rs @@ -14,6 +14,7 @@ impl AccountInstantiate { Self { msg: valence_account::msg::InstantiateMsg { services_manager: services_manager.to_string(), + referral: None, }, } } diff --git a/tests/rust-tests/src/suite/suite.rs b/tests/rust-tests/src/suite/suite.rs index 71beb825..0ab935db 100644 --- a/tests/rust-tests/src/suite/suite.rs +++ b/tests/rust-tests/src/suite/suite.rs @@ -595,7 +595,7 @@ impl Suite { ) } - pub fn query_is_service_on_manager(&self, addr: &str) -> Result { + pub fn query_is_service_on_manager(&self, addr: &str) -> Result, StdError> { self.app.wrap().query_wasm_smart( self.manager_addr.clone(), &valence_package::msgs::core_query::ServicesManagerQueryMsg::IsService { diff --git a/tests/rust-tests/src/test_service_management.rs b/tests/rust-tests/src/test_service_management.rs index 53c5fdc5..1baf30c7 100644 --- a/tests/rust-tests/src/test_service_management.rs +++ b/tests/rust-tests/src/test_service_management.rs @@ -443,8 +443,7 @@ fn test_manager_queries() { let is_service = suite .query_is_service_on_manager(suite.rebalancer_addr.as_str()) .unwrap(); - assert!(is_service); - assert!(is_service); + assert!(is_service.is_some()); // suite // .query_service_addr_from_manager(ValenceServices::Test) @@ -499,7 +498,7 @@ fn test_remove_service() { let is_service = suite .query_is_service_on_manager(suite.rebalancer_addr.as_str()) .unwrap(); - assert!(!is_service); + assert!(is_service.is_none()); } #[test] diff --git a/tests/rust-tests/src/tests_account/test_account.rs b/tests/rust-tests/src/tests_account/test_account.rs index a349e2b8..7288578e 100644 --- a/tests/rust-tests/src/tests_account/test_account.rs +++ b/tests/rust-tests/src/tests_account/test_account.rs @@ -49,7 +49,7 @@ fn test_send_funds_by_service_not_atomic() { fn test_non_funds_by_service() { let mut suite = Suite::default(); - // should failed as we try to execute a message that send funds + // should fail as we try to execute a message that send funds // for a msg type that doesn't send funds suite .app diff --git a/tests/rust-tests/src/tests_auctions/test_auction.rs b/tests/rust-tests/src/tests_auctions/test_auction.rs index 7bbf90f7..cebf63df 100644 --- a/tests/rust-tests/src/tests_auctions/test_auction.rs +++ b/tests/rust-tests/src/tests_auctions/test_auction.rs @@ -1,8 +1,13 @@ +use core::panic; + use auction::state::{ActiveAuction, ActiveAuctionStatus}; use auction_package::{error::AuctionError, states::TWAP_PRICES}; -use cosmwasm_std::{coin, coins, testing::mock_env, Addr, Decimal, Timestamp, Uint128}; +use cosmwasm_std::{ + coin, coins, from_json, testing::mock_env, Addr, Binary, Decimal, Timestamp, Uint128, +}; use cw_multi_test::Executor; use price_oracle::state::PriceStep; +use valence_package::event_indexing::ValenceEvent; use crate::suite::suite::{ Suite, DAY, DEFAULT_BALANCE_AMOUNT, DEFAULT_BLOCK_TIME, DEFAULT_NTRN_PRICE_BPS, @@ -327,6 +332,7 @@ fn test_chain_halt() { let avg_block_time = ((100.0 * 3.6) as f32).floor() as u64; let mut suite = Suite::default(); let funds = coins(1000_u128, suite.pair.0.clone()); + suite.auction_funds( suite.get_account_addr(0), suite @@ -361,19 +367,22 @@ fn test_chain_halt() { // Should return 0 as the bought amount let res = suite.do_full_bid(1_u128); - let amount_bought = suite - .get_attr_value(&res, "bought_amount") - .unwrap() - .parse::() - .unwrap(); - let amount_refunded = suite - .get_attr_value(&res, "refunded") - .unwrap() - .parse::() - .unwrap(); - assert_eq!(amount_bought, 0_u128); - assert_eq!(amount_refunded, 2_u128); + let data = from_json::( + Binary::from_base64(suite.get_attr_value(&res, "data").unwrap().as_str()).unwrap(), + ) + .unwrap(); + let ValenceEvent::AuctionDoBid { + bought_amount, + refunded_amount, + .. + } = data + else { + panic!("Unexpected event data: {:?}", data) + }; + + assert_eq!(bought_amount.u128(), 0_u128); + assert_eq!(refunded_amount.u128(), 2_u128); } #[test]