From ed91ec87d1ead071b663213808c9095c178c45af Mon Sep 17 00:00:00 2001 From: bekauz Date: Fri, 16 Jun 2023 16:56:50 +0200 Subject: [PATCH 1/6] reorganizing project structure; init lper --- stride-covenant/.gitignore => .gitignore | 0 Cargo.lock | 1078 +++++++++++++++++ Cargo.toml | 52 + stride-covenant/LICENSE => LICENSE | 0 contracts/depositor/.cargo/config | 3 + contracts/depositor/Cargo.toml | 45 + .../packages => contracts}/depositor/LICENSE | 0 .../depositor/README.md | 0 .../depositor/examples/schema.rs | 0 .../depositor/schema/execute_msg.json | 0 .../depositor/schema/instantiate_msg.json | 0 ...y_interchain_account_address_response.json | 0 .../depositor/schema/query_msg.json | 0 .../depositor/schema/sudo_msg.json | 0 .../depositor/src/contract.rs | 20 +- .../depositor/src/error.rs | 0 .../depositor/src/lib.rs | 0 .../depositor/src/msg.rs | 4 - .../depositor/src/state.rs | 8 +- .../depositor/src/tests/mod.rs | 0 .../depositor/src/tests/suite.rs | 0 .../depositor/src/tests/tests.rs | 0 contracts/lper/.cargo/config | 3 + contracts/lper/Cargo.toml | 44 + contracts/lper/LICENSE | 29 + contracts/lper/examples/schema.rs | 15 + contracts/lper/src/contract.rs | 112 ++ contracts/lper/src/lib.rs | 7 + contracts/lper/src/msg.rs | 34 + contracts/lper/src/state.rs | 24 + stride-covenant/justfile | 34 +- stride-covenant/optimize.sh | 16 + .../packages/depositor/.cargo/config | 6 - stride-covenant/packages/depositor/Cargo.toml | 83 -- stride-covenant/tests/interchaintest/go.mod | 2 +- .../tests/interchaintest/ics_test.go | 37 +- 36 files changed, 1535 insertions(+), 121 deletions(-) rename stride-covenant/.gitignore => .gitignore (100%) create mode 100644 Cargo.lock create mode 100644 Cargo.toml rename stride-covenant/LICENSE => LICENSE (100%) create mode 100644 contracts/depositor/.cargo/config create mode 100644 contracts/depositor/Cargo.toml rename {stride-covenant/packages => contracts}/depositor/LICENSE (100%) rename {stride-covenant/packages => contracts}/depositor/README.md (100%) rename {stride-covenant/packages => contracts}/depositor/examples/schema.rs (100%) rename {stride-covenant/packages => contracts}/depositor/schema/execute_msg.json (100%) rename {stride-covenant/packages => contracts}/depositor/schema/instantiate_msg.json (100%) rename {stride-covenant/packages => contracts}/depositor/schema/query_interchain_account_address_response.json (100%) rename {stride-covenant/packages => contracts}/depositor/schema/query_msg.json (100%) rename {stride-covenant/packages => contracts}/depositor/schema/sudo_msg.json (100%) rename {stride-covenant/packages => contracts}/depositor/src/contract.rs (97%) rename {stride-covenant/packages => contracts}/depositor/src/error.rs (100%) rename {stride-covenant/packages => contracts}/depositor/src/lib.rs (100%) rename {stride-covenant/packages => contracts}/depositor/src/msg.rs (94%) rename {stride-covenant/packages => contracts}/depositor/src/state.rs (98%) rename {stride-covenant/packages => contracts}/depositor/src/tests/mod.rs (100%) rename {stride-covenant/packages => contracts}/depositor/src/tests/suite.rs (100%) rename {stride-covenant/packages => contracts}/depositor/src/tests/tests.rs (100%) create mode 100644 contracts/lper/.cargo/config create mode 100644 contracts/lper/Cargo.toml create mode 100644 contracts/lper/LICENSE create mode 100644 contracts/lper/examples/schema.rs create mode 100644 contracts/lper/src/contract.rs create mode 100644 contracts/lper/src/lib.rs create mode 100644 contracts/lper/src/msg.rs create mode 100644 contracts/lper/src/state.rs create mode 100755 stride-covenant/optimize.sh delete mode 100644 stride-covenant/packages/depositor/.cargo/config delete mode 100644 stride-covenant/packages/depositor/Cargo.toml diff --git a/stride-covenant/.gitignore b/.gitignore similarity index 100% rename from stride-covenant/.gitignore rename to .gitignore diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 00000000..6aeb428a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,1078 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + +[[package]] +name = "anyhow" +version = "1.0.71" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "base16ct" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349a06037c7bf932dd7e7d1f653678b2038b9ad46a74102f1fc7bd7872678cce" + +[[package]] +name = "base64" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" + +[[package]] +name = "base64" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ea22880d78093b0cbe17c89f64a7d457941e65759157ec6cb31a31d652b05e5" + +[[package]] +name = "base64ct" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" + +[[package]] +name = "bech32" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86b93f97252c47b41663388e6d155714a9d0c398b99f1005cbc5f978b29f445" + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[package]] +name = "bytes" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +dependencies = [ + "serde", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "const-oid" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520fbf3c07483f94e3e3ca9d0cfd913d7718ef2483d2cfd91c0d9e91474ab913" + +[[package]] +name = "cosmos-sdk-proto" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20b42021d8488665b1a0d9748f1f81df7235362d194f44481e2e61bf376b77b4" +dependencies = [ + "prost 0.11.9", + "prost-types", + "tendermint-proto 0.23.9", +] + +[[package]] +name = "cosmos-sdk-proto" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4776e787b24d9568dd61d3237eeb4eb321d622fb881b858c7b82806420e87d4" +dependencies = [ + "prost 0.11.9", + "prost-types", + "tendermint-proto 0.27.0", +] + +[[package]] +name = "cosmwasm-crypto" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41c0e41be7e6c7d7ab3c61cdc32fcfaa14f948491a401cbc1c74bb33b6f4b851" +dependencies = [ + "digest 0.10.7", + "ed25519-zebra", + "k256", + "rand_core 0.6.4", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a7ee2798c92c00dd17bebb4210f81d5f647e5e92d847959b7977e0fd29a3500" +dependencies = [ + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-schema" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "407aca6f1671a08b60db8167f03bb7cb6b2378f0ddd9a030367b66ba33c2fd41" +dependencies = [ + "cosmwasm-schema-derive", + "schemars", + "serde", + "serde_json", + "thiserror", +] + +[[package]] +name = "cosmwasm-schema-derive" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d1e00b8fd27ff923c10303023626358e23a6f9079f8ebec23a8b4b0bfcd4b3" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "cosmwasm-std" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d5fdfd112b070055f068fad079d490117c8e905a588b92a5a7c9276d029930" +dependencies = [ + "base64 0.13.1", + "cosmwasm-crypto", + "cosmwasm-derive", + "derivative", + "forward_ref", + "hex", + "schemars", + "serde", + "serde-json-wasm 0.5.1", + "sha2 0.10.7", + "thiserror", + "uint", +] + +[[package]] +name = "cpufeatures" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-bigint" +version = "0.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-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest 0.9.0", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "cw-multi-test" +version = "0.16.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "127c7bb95853b8e828bdab97065c81cb5ddc20f7339180b61b2300565aaa99d1" +dependencies = [ + "anyhow", + "cosmwasm-std", + "cw-storage-plus", + "cw-utils", + "derivative", + "itertools", + "k256", + "prost 0.9.0", + "schemars", + "serde", + "thiserror", +] + +[[package]] +name = "cw-storage-plus" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f0e92a069d62067f3472c62e30adedb4cab1754725c0f2a682b3128d2bf3c79" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "cw-utils" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw2", + "schemars", + "semver", + "serde", + "thiserror", +] + +[[package]] +name = "cw2" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fb70cee2cf0b4a8ff7253e6bc6647107905e8eb37208f87d54f67810faa62f8" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "schemars", + "serde", +] + +[[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 = "derivative" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common", + "subtle", +] + +[[package]] +name = "dyn-clone" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" + +[[package]] +name = "ecdsa" +version = "0.14.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413301934810f597c1d19ca71c8710e99a3f1ba28a0d2ebc01551a2daeea3c5c" +dependencies = [ + "der", + "elliptic-curve", + "rfc6979", + "signature", +] + +[[package]] +name = "ed25519-zebra" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c24f403d068ad0b359e577a77f92392118be3f3c927538f2bb544a5ecd828c6" +dependencies = [ + "curve25519-dalek", + "hashbrown", + "hex", + "rand_core 0.6.4", + "serde", + "sha2 0.9.9", + "zeroize", +] + +[[package]] +name = "either" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" + +[[package]] +name = "elliptic-curve" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7bb888ab5300a19b8e5bceef25ac745ad065f3c9f7efc6de1b91958110891d3" +dependencies = [ + "base16ct", + "crypto-bigint", + "der", + "digest 0.10.7", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.4", + "sec1", + "subtle", + "zeroize", +] + +[[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 = "flex-error" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c606d892c9de11507fa0dcffc116434f94e105d0bbdc4e405b61519464c49d7b" +dependencies = [ + "paste", +] + +[[package]] +name = "forward_ref" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8cbd1169bd7b4a0a20d92b9af7a7e0422888bd38a6f5ec29c1fd8c1558a272e" + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427" +dependencies = [ + "cfg-if", + "libc", + "wasi", +] + +[[package]] +name = "group" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7" +dependencies = [ + "ff", + "rand_core 0.6.4", + "subtle", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +dependencies = [ + "ahash", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" +dependencies = [ + "digest 0.10.7", +] + +[[package]] +name = "itertools" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" +dependencies = [ + "either", +] + +[[package]] +name = "itoa" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" + +[[package]] +name = "k256" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c1e0b51e7ec0a97369623508396067a486bd0cbed95a2659a4b863d28cfc8b" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sha2 0.10.7", +] + +[[package]] +name = "libc" +version = "0.2.146" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" + +[[package]] +name = "neutron-sdk" +version = "0.5.0" +source = "git+https://github.com/neutron-org/neutron-sdk#dd253066f673f88aac4495876592afcfb4f8d527" +dependencies = [ + "base64 0.20.0", + "bech32", + "cosmos-sdk-proto 0.16.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus", + "prost 0.11.9", + "protobuf", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "serde_json", + "thiserror", +] + +[[package]] +name = "num-derive" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + +[[package]] +name = "once_cell" +version = "1.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "paste" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" + +[[package]] +name = "pkcs8" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9eca2c590a5f85da82668fa685c09ce2888b9430e83299debf1f34b65fd4a4ba" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "proc-macro2" +version = "1.0.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dec2b086b7a862cf4de201096214fa870344cf922b2b30c167badb3af3195406" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "prost" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444879275cb4fd84958b1a1d5420d15e6fcf7c235fe47f053c9c2a80aceb6001" +dependencies = [ + "bytes", + "prost-derive 0.9.0", +] + +[[package]] +name = "prost" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b82eaa1d779e9a4bc1c3217db8ffbeabaae1dca241bf70183242128d48681cd" +dependencies = [ + "bytes", + "prost-derive 0.11.9", +] + +[[package]] +name = "prost-derive" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9cc1a3263e07e0bf68e96268f37665207b49560d98739662cdfaae215c720fe" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "prost-derive" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d2d8d10f3c6ded6da8b05b5fb3b8a5082514344d56c9f871412d29b4e075b4" +dependencies = [ + "anyhow", + "itertools", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "prost-types" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "213622a1460818959ac1181aaeb2dc9c7f63df720db7d788b3e24eacd1983e13" +dependencies = [ + "prost 0.11.9", +] + +[[package]] +name = "protobuf" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55bad9126f378a853655831eb7363b7b01b81d19f8cb1218861086ca4a1a61e" +dependencies = [ + "bytes", + "once_cell", + "protobuf-support", + "thiserror", +] + +[[package]] +name = "protobuf-support" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5d4d7b8601c814cfb36bcebb79f0e61e45e1e93640cf778837833bbed05c372" +dependencies = [ + "thiserror", +] + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" + +[[package]] +name = "rand_core" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] + +[[package]] +name = "rfc6979" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7743f17af12fa0b03b803ba12cd6a8d9483a587e89c69445e3909655c0b9fabb" +dependencies = [ + "crypto-bigint", + "hmac", + "zeroize", +] + +[[package]] +name = "ryu" +version = "1.0.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" + +[[package]] +name = "schemars" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02c613288622e5f0c3fdc5dbd4db1c5fbe752746b1d1a56a0630b78fd00de44f" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "109da1e6b197438deb6db99952990c7f959572794b80ff93707d55a232545e7c" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "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", + "der", + "generic-array", + "pkcs8", + "subtle", + "zeroize", +] + +[[package]] +name = "semver" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" + +[[package]] +name = "serde" +version = "1.0.164" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479b4dbc401ca13ee8ce902851b834893251404c4f3c65370a49e047a6be09a5" +dependencies = [ + "serde", +] + +[[package]] +name = "serde-json-wasm" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a62a1fad1e1828b24acac8f2b468971dade7b8c3c2e672bcadefefb1f8c137" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_bytes" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.164" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "serde_derive_internals" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85bf8229e7920a9f636479437026331ce11aa132b4dde37d121944a44d6e5f3c" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "serde_json" +version = "1.0.97" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdf3bf93142acad5821c99197022e170842cdbc1c30482b98750c688c640842a" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer 0.9.0", + "cfg-if", + "cpufeatures", + "digest 0.9.0", + "opaque-debug", +] + +[[package]] +name = "sha2" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8" +dependencies = [ + "cfg-if", + "cpufeatures", + "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 = "spki" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67cf02bbac7a337dc36e4f5a693db6c21e7863f45070f7064577eb4367a3212b" +dependencies = [ + "base64ct", + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "stride-depositor" +version = "1.0.0" +dependencies = [ + "anyhow", + "base64 0.13.1", + "bech32", + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test", + "cw-storage-plus", + "cw-utils", + "cw2", + "neutron-sdk", + "prost 0.11.9", + "prost-types", + "protobuf", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "sha2 0.10.7", + "thiserror", +] + +[[package]] +name = "stride-lper" +version = "1.0.0" +dependencies = [ + "base64 0.13.1", + "bech32", + "cosmos-sdk-proto 0.14.0", + "cosmwasm-schema", + "cosmwasm-std", + "cw-multi-test", + "cw-storage-plus", + "cw-utils", + "cw2", + "neutron-sdk", + "prost 0.11.9", + "prost-types", + "protobuf", + "schemars", + "serde", + "serde-json-wasm 0.4.1", + "sha2 0.10.7", + "thiserror", +] + +[[package]] +name = "subtle" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" + +[[package]] +name = "subtle-encoding" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dcb1ed7b8330c5eed5441052651dd7a12c75e2ed88f2ec024ae1fa3a5e59945" +dependencies = [ + "zeroize", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tendermint-proto" +version = "0.23.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68ce80bf536476db81ecc9ebab834dc329c9c1509a694f211a73858814bfe023" +dependencies = [ + "bytes", + "flex-error", + "num-derive", + "num-traits", + "prost 0.11.9", + "prost-types", + "serde", + "serde_bytes", + "subtle-encoding", + "time", +] + +[[package]] +name = "tendermint-proto" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5895470f28c530f8ae8c4071bf8190304ce00bd131d25e81730453124a3375c" +dependencies = [ + "bytes", + "flex-error", + "num-derive", + "num-traits", + "prost 0.11.9", + "prost-types", + "serde", + "serde_bytes", + "subtle-encoding", + "time", +] + +[[package]] +name = "thiserror" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.18", +] + +[[package]] +name = "time" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217" +dependencies = [ + "libc", + "num_threads", + "time-macros", +] + +[[package]] +name = "time-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42657b1a6f4d817cda8e7a0ace261fe0cc946cf3a80314390b22cc61ae080792" + +[[package]] +name = "typenum" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" + +[[package]] +name = "uint" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76f64bba2c53b04fcab63c01a7d7427eadc821e3bc48c34dc9ba29c501164b52" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" + +[[package]] +name = "zeroize" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..8a4ca966 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,52 @@ +[workspace] +members = [ + "contracts/*", +] + +[workspace.package] +edition = "2021" +license = "BSD-3" +version = "1.0.0" +repository = "https://github.com/timewave-computer/covenants/stride-covenant" + + +[profile.release] +codegen-units = 1 +debug = false +debug-assertions = false +incremental = false +lto = true +opt-level = 3 +overflow-checks = true # very important, do not turn these off. +panic = 'abort' +rpath = false + +[workspace.dependencies] +stride-depositor = { path = "./packages/depositor", version = "*" } +stride-lper = { path = "./packages/lper", version = "*" } + +cosmwasm-schema = "1.2.1" +cosmwasm-std = { version = "1.2.4", features = ["ibc3"] } +cw-storage-plus = "1.0.1" +cw-utils = "1.0.1" +cw2 = "1.0.1" +serde = { version = "1.0.145", default-features = false, features = ["derive"] } +thiserror = "1.0.31" +# the sha2 version here is the same as the one used by +# cosmwasm-std. when bumping cosmwasm-std, this should also be +# updated. to find cosmwasm_std's sha function: +# ```cargo tree --package cosmwasm-std``` +sha2 = "0.10.6" +neutron-sdk = { git = "https://github.com/neutron-org/neutron-sdk", default-features = false, version = "0.5.0" } +cosmos-sdk-proto = { version = "0.14.0", default-features = false } +protobuf = { version = "3.2.0", features = ["with-bytes"] } +schemars = "0.8.10" +serde-json-wasm = { version = "0.4.1" } +base64 = "0.13.0" +prost = "0.11" +prost-types = "0.11" +bech32 = "0.9.0" + +# dev-dependencies +cw-multi-test = "0.16.2" +anyhow = { version = "1.0.51" } \ No newline at end of file diff --git a/stride-covenant/LICENSE b/LICENSE similarity index 100% rename from stride-covenant/LICENSE rename to LICENSE diff --git a/contracts/depositor/.cargo/config b/contracts/depositor/.cargo/config new file mode 100644 index 00000000..6a6f2852 --- /dev/null +++ b/contracts/depositor/.cargo/config @@ -0,0 +1,3 @@ +[alias] +wasm = "build --release --lib --target wasm32-unknown-unknown" +schema = "run --bin schema" \ No newline at end of file diff --git a/contracts/depositor/Cargo.toml b/contracts/depositor/Cargo.toml new file mode 100644 index 00000000..d4d0acd8 --- /dev/null +++ b/contracts/depositor/Cargo.toml @@ -0,0 +1,45 @@ +[package] +name = "stride-depositor" +edition = { workspace = true } +authors = ["benskey bekauz@protonmail.com"] +description = "Depositor module for stride covenant" +license = { workspace = true } +repository = { workspace = true } +version = { workspace = true } + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[dependencies] +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +cw-utils = { workspace = true } +cw2 = { workspace = true } +serde = { workspace = true } +thiserror = { workspace = true } +# the sha2 version here is the same as the one used by +# cosmwasm-std. when bumping cosmwasm-std, this should also be +# updated. to find cosmwasm_std's sha function: +# ```cargo tree --package cosmwasm-std``` +sha2 = { workspace = true } +neutron-sdk = { workspace = true } +cosmos-sdk-proto = { workspace = true } +protobuf = { workspace = true } +schemars = { workspace = true } +serde-json-wasm = { workspace = true } +base64 = { workspace = true } +prost = { workspace = true } +prost-types = { workspace = true } +bech32 ={ workspace = true } + +# dev-dependencies +[dev-dependencies] +cw-multi-test = { workspace = true } +anyhow = { workspace = true } \ No newline at end of file diff --git a/stride-covenant/packages/depositor/LICENSE b/contracts/depositor/LICENSE similarity index 100% rename from stride-covenant/packages/depositor/LICENSE rename to contracts/depositor/LICENSE diff --git a/stride-covenant/packages/depositor/README.md b/contracts/depositor/README.md similarity index 100% rename from stride-covenant/packages/depositor/README.md rename to contracts/depositor/README.md diff --git a/stride-covenant/packages/depositor/examples/schema.rs b/contracts/depositor/examples/schema.rs similarity index 100% rename from stride-covenant/packages/depositor/examples/schema.rs rename to contracts/depositor/examples/schema.rs diff --git a/stride-covenant/packages/depositor/schema/execute_msg.json b/contracts/depositor/schema/execute_msg.json similarity index 100% rename from stride-covenant/packages/depositor/schema/execute_msg.json rename to contracts/depositor/schema/execute_msg.json diff --git a/stride-covenant/packages/depositor/schema/instantiate_msg.json b/contracts/depositor/schema/instantiate_msg.json similarity index 100% rename from stride-covenant/packages/depositor/schema/instantiate_msg.json rename to contracts/depositor/schema/instantiate_msg.json diff --git a/stride-covenant/packages/depositor/schema/query_interchain_account_address_response.json b/contracts/depositor/schema/query_interchain_account_address_response.json similarity index 100% rename from stride-covenant/packages/depositor/schema/query_interchain_account_address_response.json rename to contracts/depositor/schema/query_interchain_account_address_response.json diff --git a/stride-covenant/packages/depositor/schema/query_msg.json b/contracts/depositor/schema/query_msg.json similarity index 100% rename from stride-covenant/packages/depositor/schema/query_msg.json rename to contracts/depositor/schema/query_msg.json diff --git a/stride-covenant/packages/depositor/schema/sudo_msg.json b/contracts/depositor/schema/sudo_msg.json similarity index 100% rename from stride-covenant/packages/depositor/schema/sudo_msg.json rename to contracts/depositor/schema/sudo_msg.json diff --git a/stride-covenant/packages/depositor/src/contract.rs b/contracts/depositor/src/contract.rs similarity index 97% rename from stride-covenant/packages/depositor/src/contract.rs rename to contracts/depositor/src/contract.rs index cfce0b32..8f42ac7a 100644 --- a/stride-covenant/packages/depositor/src/contract.rs +++ b/contracts/depositor/src/contract.rs @@ -1,5 +1,3 @@ -use std::str::FromStr; - use cosmos_sdk_proto::cosmos::base::v1beta1::Coin; use cosmos_sdk_proto::ibc::applications::transfer::v1::MsgTransfer; @@ -48,7 +46,7 @@ const ICS_CONNECTION_ID: &str = "connection-1"; const INTERCHAIN_ACCOUNT_ID: &str = "test"; const TRANSFER_PORT: &str = "transfer"; -const CONTRACT_NAME: &str = concat!("crates.io:neutron-sdk__", env!("CARGO_PKG_NAME")); +const CONTRACT_NAME: &str = "crates.io:stride-depositor"; const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] @@ -78,7 +76,7 @@ pub fn instantiate( STRIDE_ATOM_RECEIVER.save(deps.storage, &msg.st_atom_receiver)?; NATIVE_ATOM_RECEIVER.save(deps.storage, &msg.atom_receiver)?; CLOCK_ADDRESS.save(deps.storage, &Addr::unchecked(msg.clock_address))?; - CONTRACT_STATE.save(deps.storage, &ContractState::INSTANTIATED)?; + CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; GAIA_NEUTRON_IBC_TRANSFER_CHANNEL_ID.save(deps.storage, &msg.gaia_neutron_ibc_transfer_channel_id)?; Ok(Response::default()) @@ -96,10 +94,6 @@ pub fn execute( match msg { ExecuteMsg::Tick { } => try_tick(deps, env, info), ExecuteMsg::Received { } => try_handle_received(), - ExecuteMsg::Register { - connection_id, - interchain_account_id, - } => execute_register_ica(deps, env, connection_id, interchain_account_id), } } @@ -114,10 +108,10 @@ fn try_tick(mut deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult try_register_gaia_ica(deps, env), - ContractState::ICA_CREATED => try_receive_atom_from_ica(deps, env, info, gaia_account_address), - ContractState::RECEIVED_FUNDS => try_execute_transfers(deps, env, info, gaia_account_address), - ContractState::COMPLETE => Ok(Response::default()), + ContractState::Instantiated => try_register_gaia_ica(deps, env), + ContractState::ICACreated => try_receive_atom_from_ica(deps, env, info, gaia_account_address), + ContractState::ReceivedFunds => try_execute_transfers(deps, env, info, gaia_account_address), + ContractState::Complete => Ok(Response::default()), } } @@ -542,7 +536,7 @@ fn sudo_open_ack( )), )?; ICA_ADDRESS.save(deps.storage, &parsed_version.address)?; - CONTRACT_STATE.save(deps.storage, &ContractState::ICA_CREATED)?; + CONTRACT_STATE.save(deps.storage, &ContractState::ICACreated)?; return Ok(Response::default()); } Err(StdError::generic_err("Can't parse counterparty_version")) diff --git a/stride-covenant/packages/depositor/src/error.rs b/contracts/depositor/src/error.rs similarity index 100% rename from stride-covenant/packages/depositor/src/error.rs rename to contracts/depositor/src/error.rs diff --git a/stride-covenant/packages/depositor/src/lib.rs b/contracts/depositor/src/lib.rs similarity index 100% rename from stride-covenant/packages/depositor/src/lib.rs rename to contracts/depositor/src/lib.rs diff --git a/stride-covenant/packages/depositor/src/msg.rs b/contracts/depositor/src/msg.rs similarity index 94% rename from stride-covenant/packages/depositor/src/msg.rs rename to contracts/depositor/src/msg.rs index 2388e690..7713a253 100644 --- a/stride-covenant/packages/depositor/src/msg.rs +++ b/contracts/depositor/src/msg.rs @@ -21,10 +21,6 @@ pub struct WeightedReceiver { pub enum ExecuteMsg { Tick {}, Received {}, - Register { - connection_id: String, - interchain_account_id: String, - }, } #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] diff --git a/stride-covenant/packages/depositor/src/state.rs b/contracts/depositor/src/state.rs similarity index 98% rename from stride-covenant/packages/depositor/src/state.rs rename to contracts/depositor/src/state.rs index 42a156a7..72ca95ba 100644 --- a/stride-covenant/packages/depositor/src/state.rs +++ b/contracts/depositor/src/state.rs @@ -27,10 +27,10 @@ pub const IBC_PORT_ID: Item = Item::new("ibc_port_id"); #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum ContractState { - INSTANTIATED, - ICA_CREATED, - RECEIVED_FUNDS, - COMPLETE, + Instantiated, + ICACreated, + ReceivedFunds, + Complete, } pub const CONTRACT_STATE: Item = Item::new("contract_state"); diff --git a/stride-covenant/packages/depositor/src/tests/mod.rs b/contracts/depositor/src/tests/mod.rs similarity index 100% rename from stride-covenant/packages/depositor/src/tests/mod.rs rename to contracts/depositor/src/tests/mod.rs diff --git a/stride-covenant/packages/depositor/src/tests/suite.rs b/contracts/depositor/src/tests/suite.rs similarity index 100% rename from stride-covenant/packages/depositor/src/tests/suite.rs rename to contracts/depositor/src/tests/suite.rs diff --git a/stride-covenant/packages/depositor/src/tests/tests.rs b/contracts/depositor/src/tests/tests.rs similarity index 100% rename from stride-covenant/packages/depositor/src/tests/tests.rs rename to contracts/depositor/src/tests/tests.rs diff --git a/contracts/lper/.cargo/config b/contracts/lper/.cargo/config new file mode 100644 index 00000000..6a6f2852 --- /dev/null +++ b/contracts/lper/.cargo/config @@ -0,0 +1,3 @@ +[alias] +wasm = "build --release --lib --target wasm32-unknown-unknown" +schema = "run --bin schema" \ No newline at end of file diff --git a/contracts/lper/Cargo.toml b/contracts/lper/Cargo.toml new file mode 100644 index 00000000..9a61b662 --- /dev/null +++ b/contracts/lper/Cargo.toml @@ -0,0 +1,44 @@ +[package] +name = "stride-lper" +authors = ["benskey bekauz@protonmail.com"] +description = "LP module for stride covenant" +license = { workspace = true } +repository = { workspace = true } +version = { workspace = true } +edition = { workspace = true } + +[lib] +crate-type = ["cdylib", "rlib"] + +[features] +# for more explicit tests, cargo test --features=backtraces +backtraces = ["cosmwasm-std/backtraces"] +# use library feature to disable all instantiate/execute/query exports +library = [] + +[dependencies] +cosmwasm-schema = { workspace = true } +cosmwasm-std = { workspace = true } +cw-storage-plus = { workspace = true } +cw-utils = { workspace = true } +cw2 = { workspace = true } +serde = { workspace = true } +thiserror = { workspace = true } +# the sha2 version here is the same as the one used by +# cosmwasm-std. when bumping cosmwasm-std, this should also be +# updated. to find cosmwasm_std's sha function: +# ```cargo tree --package cosmwasm-std``` +sha2 = { workspace = true } +neutron-sdk = { workspace = true } +cosmos-sdk-proto = { workspace = true } +protobuf = { workspace = true } +schemars = { workspace = true } +serde-json-wasm = { workspace = true } +base64 = { workspace = true } +prost = { workspace = true } +prost-types = { workspace = true } +bech32 ={ workspace = true } + +# dev-dependencies +[dev-dependencies] +cw-multi-test = { workspace = true } diff --git a/contracts/lper/LICENSE b/contracts/lper/LICENSE new file mode 100644 index 00000000..0bdef96b --- /dev/null +++ b/contracts/lper/LICENSE @@ -0,0 +1,29 @@ +Copyright 2023 Timewave + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the + distribution. + +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/contracts/lper/examples/schema.rs b/contracts/lper/examples/schema.rs new file mode 100644 index 00000000..702fccc5 --- /dev/null +++ b/contracts/lper/examples/schema.rs @@ -0,0 +1,15 @@ +use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; +use stride_lper::msg::{InstantiateMsg, ExecuteMsg, QueryMsg}; +use std::env::current_dir; +use std::fs::create_dir_all; + +fn main() { + let mut out_dir = current_dir().unwrap(); + out_dir.push("schema"); + create_dir_all(&out_dir).unwrap(); + remove_schemas(&out_dir).unwrap(); + + export_schema(&schema_for!(InstantiateMsg), &out_dir); + export_schema(&schema_for!(QueryMsg), &out_dir); + export_schema(&schema_for!(ExecuteMsg), &out_dir); +} \ No newline at end of file diff --git a/contracts/lper/src/contract.rs b/contracts/lper/src/contract.rs new file mode 100644 index 00000000..f9828e9c --- /dev/null +++ b/contracts/lper/src/contract.rs @@ -0,0 +1,112 @@ +#[cfg(not(feature = "library"))] +use cosmwasm_std::entry_point; +use cosmwasm_std::{MessageInfo, Response, + StdResult, Addr, DepsMut, Env, Binary, Deps, to_binary, +}; +use cw2::set_contract_version; + + +use crate::{msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::{HOLDER_ADDRESS, LP_POSITION}}; + +use neutron_sdk::{ + bindings::{ + msg::{NeutronMsg}, + query::{NeutronQuery}, + }, + NeutronResult, +}; + +use crate::state::{ + CLOCK_ADDRESS, CONTRACT_STATE, ContractState, +}; + + +const CONTRACT_NAME: &str = "crates.io:stride-lper"; +const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn instantiate( + deps: DepsMut, + _env: Env, + _info: MessageInfo, + msg: InstantiateMsg, +) -> NeutronResult> { + deps.api.debug("WASMDEBUG: instantiate"); + set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; + + // TODO: validations + CLOCK_ADDRESS.save(deps.storage, &Addr::unchecked(msg.clock_address))?; + CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?; + LP_POSITION.save(deps.storage, &msg.lp_position)?; + HOLDER_ADDRESS.save(deps.storage, &msg.holder_address)?; + + Ok(Response::default()) +} + +#[entry_point] +pub fn execute( + mut deps: DepsMut, + env: Env, + info: MessageInfo, + msg: ExecuteMsg, +) -> NeutronResult> { + deps.api + .debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str()); + match msg { + ExecuteMsg::Tick {} => try_tick(deps, env, info), + ExecuteMsg::WithdrawRewards {} => try_withdraw(deps, env, info), + } +} + + +fn try_tick(mut deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult> { + let current_state = CONTRACT_STATE.load(deps.storage)?; + + match current_state { + ContractState::Instantiated => try_enter_lp_position(deps, env, info), + ContractState::LpPositionEntered => no_op(), + ContractState::LpPositionExited => no_op(), + ContractState::WithdrawComplete => no_op(), + } +} + +fn no_op() -> NeutronResult> { + Ok(Response::default()) +} + +fn try_enter_lp_position( + mut deps: DepsMut, + env: Env, + info: MessageInfo, +) -> NeutronResult> { + Ok(Response::default()) + +} + +fn try_withdraw( + mut deps: DepsMut, + env: Env, + info: MessageInfo, +) -> NeutronResult> { + Ok(Response::default()) + +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> NeutronResult { + match msg { + + QueryMsg::ClockAddress {} => Ok( + to_binary(&CLOCK_ADDRESS.may_load(deps.storage)?)? + ), + QueryMsg::LPPosition {} => Ok( + to_binary(&LP_POSITION.may_load(deps.storage)?)? + ) + } +} + +#[cfg_attr(not(feature = "library"), entry_point)] +pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult { + deps.api.debug("WASMDEBUG: migrate"); + Ok(Response::default()) +} diff --git a/contracts/lper/src/lib.rs b/contracts/lper/src/lib.rs new file mode 100644 index 00000000..cb0f31b4 --- /dev/null +++ b/contracts/lper/src/lib.rs @@ -0,0 +1,7 @@ +#![warn(clippy::unwrap_used, clippy::expect_used)] + +extern crate core; + +pub mod contract; +pub mod msg; +pub mod state; diff --git a/contracts/lper/src/msg.rs b/contracts/lper/src/msg.rs new file mode 100644 index 00000000..d905137f --- /dev/null +++ b/contracts/lper/src/msg.rs @@ -0,0 +1,34 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct InstantiateMsg { + pub lp_position: LPInfo, + pub clock_address: String, + pub holder_address: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct LPInfo { + pub addr: String, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum ExecuteMsg { + Tick {}, + WithdrawRewards {}, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum QueryMsg { + LPPosition {}, + ClockAddress {}, +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +pub struct MigrateMsg { +} diff --git a/contracts/lper/src/state.rs b/contracts/lper/src/state.rs new file mode 100644 index 00000000..85edbbfa --- /dev/null +++ b/contracts/lper/src/state.rs @@ -0,0 +1,24 @@ + +use cosmwasm_std::Addr; +use cw_storage_plus::{Item}; +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +use crate::msg::LPInfo; + + +// store the clock address to verify calls +pub const CLOCK_ADDRESS: Item = Item::new("clock_address"); +pub const LP_POSITION: Item = Item::new("lp_position"); +pub const HOLDER_ADDRESS: Item = Item::new("holder_address"); +pub const CONTRACT_STATE: Item = Item::new("contract_state"); + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum ContractState { + Instantiated, + LpPositionEntered, + LpPositionExited, + WithdrawComplete, +} + diff --git a/stride-covenant/justfile b/stride-covenant/justfile index ca13756c..e363677e 100644 --- a/stride-covenant/justfile +++ b/stride-covenant/justfile @@ -1,13 +1,33 @@ build: cargo build +gen: build gen-schema + +gen-schema: + START_DIR=$(pwd); \ + for f in ./packages/*; do \ + echo "generating schema"; \ + cd "$f"; \ + CMD="cargo run --example schema"; \ + eval ${CMD} > /dev/null; \ + rm -rf ./schema/raw; \ + cd "$START_DIR"; \ + done + +test: + cargo test + optimize: - cd packages/* && docker run --platform linux/amd64 --rm -v "$(pwd)":/code \ - --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ - --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ - cosmwasm/rust-optimizer:0.12.13 + ./optimize.sh + +simtest: optimize + if [[ $(uname -m) =~ "arm64" ]]; then \ + mv ./../artifacts/stride_depositor-aarch64.wasm ./../artifacts/stride_depositor.wasm && \ + mv ./../artifacts/stride_lper-aarch64.wasm ./../artifacts/stride_lper.wasm \ + ;fi -test: optimize mkdir -p tests/interchaintest/wasms - cp packages/*/artifacts/*.wasm tests/interchaintest/wasms - cd tests/interchaintest && go test -v ./... \ No newline at end of file + + cp -R ./../artifacts/*.wasm tests/interchaintest/wasms + go clean -testcache + cd tests/interchaintest/ && go test -v ./... \ No newline at end of file diff --git a/stride-covenant/optimize.sh b/stride-covenant/optimize.sh new file mode 100755 index 00000000..4676b516 --- /dev/null +++ b/stride-covenant/optimize.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +cd .. +if [[ $(uname -m) =~ "arm64" ]]; then \ + docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + cosmwasm/workspace-optimizer-arm64:0.12.11 + +else + docker run --rm -v "$(pwd)":/code \ + --mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \ + --mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \ + --platform linux/amd64 \ + cosmwasm/workspace-optimizer:0.12.13 +fi \ No newline at end of file diff --git a/stride-covenant/packages/depositor/.cargo/config b/stride-covenant/packages/depositor/.cargo/config deleted file mode 100644 index 1e91742c..00000000 --- a/stride-covenant/packages/depositor/.cargo/config +++ /dev/null @@ -1,6 +0,0 @@ -[alias] -wasm = "build --release --target wasm32-unknown-unknown" -wasm-debug = "build --target wasm32-unknown-unknown" -unit-test = "test --lib --features backtraces" -integration-test = "test --test integration" -schema = "run --example schema" \ No newline at end of file diff --git a/stride-covenant/packages/depositor/Cargo.toml b/stride-covenant/packages/depositor/Cargo.toml deleted file mode 100644 index 33472dbe..00000000 --- a/stride-covenant/packages/depositor/Cargo.toml +++ /dev/null @@ -1,83 +0,0 @@ -[package] -name = "stride-depositor" -version = "0.0.1" -edition = "2021" -authors = ["benskey bekauz@protonmail.com"] -description = "Depositor module for stride covenant" -license = "BSD-3" - -exclude = [ - "contract.wasm", - "hash.txt", -] - -[lib] -crate-type = ["cdylib", "rlib"] - -[profile.release] -opt-level = 3 -debug = true -rpath = false -lto = true -debug-assertions = false -codegen-units = 1 -panic = 'abort' -incremental = false -overflow-checks = true - -[features] -# for more explicit tests, cargo test --features=backtraces -backtraces = ["cosmwasm-std/backtraces"] -library = [] - -[dependencies] -cosmwasm-schema = "1.2.1" -cosmwasm-std = { version = "1.2.4", features = ["ibc3"] } -cw-storage-plus = "1.0.1" -cw-utils = "1.0.1" -cw2 = "1.0.1" -serde = { version = "1.0.145", default-features = false, features = ["derive"] } -thiserror = "1.0.31" -# the sha2 version here is the same as the one used by -# cosmwasm-std. when bumping cosmwasm-std, this should also be -# updated. to find cosmwasm_std's sha function: -# ```cargo tree --package cosmwasm-std``` -sha2 = "0.10.6" -neutron-sdk = { git = "https://github.com/neutron-org/neutron-sdk", default-features = false, version = "0.5.0" } -cosmos-sdk-proto = { version = "0.14.0", default-features = false } -protobuf = { version = "3.2.0", features = ["with-bytes"] } -schemars = "0.8.10" -serde-json-wasm = { version = "0.4.1" } -base64 = "0.13.0" -prost = "0.11" -prost-types = "0.11" -bech32 = "0.9.0" - -# cosmwasm-schema = { workspace = true } -# cosmwasm-std = { workspace = true } -# cw-storage-plus = { workspace = true } -# serde = { workspace = true } -# cw2 = { workspace = true } -# thiserror = { workspace = true } -# cw-multi-test = { workspace = true } -# neutron-sdk = { workspace = true } -# cosmos-sdk-proto = { workspace = true } -# protobuf = { workspace = true } -# schemars = { workspace = true } -# prost = { workspace = true } -# prost-types = { workspace = true } -# serde-json-wasm = { workspace = true } - - -# # the sha2 version here is the same as the one used by -# # cosmwasm-std. when bumping cosmwasm-std, this should also be -# # updated. to find cosmwasm_std's sha function: -# # ```cargo tree --package cosmwasm-std``` -# sha2 = { workspace = true } - -# dev-dependencies -[dev-dependencies] -cw-multi-test = "0.16.2" -anyhow = { version = "1.0.51" } -# cw-multi-test = { workspace = true } -# anyhow = { workspace = true } diff --git a/stride-covenant/tests/interchaintest/go.mod b/stride-covenant/tests/interchaintest/go.mod index a87621a6..80b7e639 100644 --- a/stride-covenant/tests/interchaintest/go.mod +++ b/stride-covenant/tests/interchaintest/go.mod @@ -14,6 +14,7 @@ replace ( require ( github.com/cosmos/cosmos-sdk v0.45.15 + github.com/cosmos/ibc-go/v3 v3.4.0 github.com/icza/dyno v0.0.0-20220812133438-f0b6f8a18845 github.com/strangelove-ventures/interchaintest/v3 v3.0.0-20230424185430-002b69e57bc7 github.com/stretchr/testify v1.8.2 @@ -43,7 +44,6 @@ require ( github.com/cosmos/go-bip39 v1.0.0 // indirect github.com/cosmos/gorocksdb v1.2.0 // indirect github.com/cosmos/iavl v0.19.4 // indirect - github.com/cosmos/ibc-go/v3 v3.4.0 // indirect github.com/cosmos/interchain-security v1.0.0-rc2 // indirect github.com/cosmos/ledger-cosmos-go v0.11.1 // indirect github.com/cosmos/ledger-go v0.9.3 // indirect diff --git a/stride-covenant/tests/interchaintest/ics_test.go b/stride-covenant/tests/interchaintest/ics_test.go index e190cfb9..a0ce35ed 100644 --- a/stride-covenant/tests/interchaintest/ics_test.go +++ b/stride-covenant/tests/interchaintest/ics_test.go @@ -22,13 +22,23 @@ import ( "go.uber.org/zap/zaptest" ) -type InstantiateMsg struct { +type DepositorInstantiateMsg struct { StAtomReceiver WeightedReceiver `json:"st_atom_receiver"` AtomReceiver WeightedReceiver `json:"atom_receiver"` ClockAddress string `json:"clock_address,string"` GaiaNeutronIBCTransferChannelId string `json:"gaia_neutron_ibc_transfer_channel_id"` } +type LPerInstantiateMsg struct { + LpPosition LpInfo `json:"lp_position"` + ClockAddress string `json:"clock_address,string"` + HolderAddress string `json:"holder_address,string"` +} + +type LpInfo struct { + Addr string `json:"addr,string"` +} + type WeightedReceiver struct { Amount int64 `json:"amount"` Address string `json:"address,string"` @@ -255,6 +265,7 @@ func TestICS(t *testing.T) { ).Build(t, client, network) const clockContractAddress = "clock_contract_address" + const holderContractAddress = "holder_contract_address" const icaAccountId = "test" var icaAccountAddress string // Prep Interchain @@ -401,6 +412,26 @@ func TestICS(t *testing.T) { neutronGaiaICSChannelId := neutronGaiaICSChannel.ChannelID _, _ = gaiaNeutronICSChannelId, neutronGaiaICSChannelId + t.Run("instantiate LPer", func(t *testing.T) { + codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_lper.wasm") + require.NoError(t, err, "failed to store neutron ICA contract") + lpinfo := LpInfo{ + Addr: "test", + } + msg := LPerInstantiateMsg{ + LpPosition: lpinfo, + ClockAddress: clockContractAddress, + HolderAddress: holderContractAddress, + } + + str, err := json.Marshal(msg) + require.NoError(t, err, "Failed to marshall LPerInstantiateMsg") + + lpAddress, err := cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) + require.NoError(t, err, "failed to instantiate lper contract: ", err) + print(lpAddress) + }) + t.Run("instantiate depositor", func(t *testing.T) { // Store and instantiate the Neutron ICA example contract. The // wasm file is placed in `wasms/` by the `just test` command. @@ -415,7 +446,7 @@ func TestICS(t *testing.T) { Amount: int64(10), Address: "neutron1ud6resqzgewt92njs826m5st98n9r6kkjnurup", } - msg := InstantiateMsg{ + msg := DepositorInstantiateMsg{ StAtomReceiver: stAtomWeightedReceiver, AtomReceiver: atomWeightedReceiver, ClockAddress: clockContractAddress, @@ -423,7 +454,7 @@ func TestICS(t *testing.T) { } str, err := json.Marshal(msg) - require.NoError(t, err, "Failed to marshall instantiateMsg") + require.NoError(t, err, "Failed to marshall DepositorInstantiateMsg") address, err := cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) require.NoError(t, err, "failed to instantiate depositor contract: ", err) From bd6f24e169db428aa5223effa29428049b4d3642 Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 18 Jun 2023 20:54:09 +0200 Subject: [PATCH 2/6] splitting up ics_test; cleanup --- .../tests/interchaintest/genesis_helpers.go | 104 +++++ .../tests/interchaintest/ics_test.go | 364 ++++++------------ stride-covenant/tests/interchaintest/types.go | 86 +++++ 3 files changed, 299 insertions(+), 255 deletions(-) create mode 100644 stride-covenant/tests/interchaintest/genesis_helpers.go create mode 100644 stride-covenant/tests/interchaintest/types.go diff --git a/stride-covenant/tests/interchaintest/genesis_helpers.go b/stride-covenant/tests/interchaintest/genesis_helpers.go new file mode 100644 index 00000000..c29afb1c --- /dev/null +++ b/stride-covenant/tests/interchaintest/genesis_helpers.go @@ -0,0 +1,104 @@ +package ibc_test + +import ( + "encoding/json" + "fmt" + + "github.com/cosmos/cosmos-sdk/crypto/keyring" + "github.com/icza/dyno" + "github.com/strangelove-ventures/interchaintest/v3/ibc" +) + +// Sets custom fields for the Neutron genesis file that interchaintest isn't aware of by default. +// +// soft_opt_out_threshold - the bottom `soft_opt_out_threshold` +// percentage of validators may opt out of running a Neutron +// node [^1]. +// +// reward_denoms - the reward denominations allowed to be sent to the +// provider (atom) from the consumer (neutron) [^2]. +// +// provider_reward_denoms - the reward denominations allowed to be +// sent to the consumer by the provider [^2]. +// +// [^1]: https://docs.neutron.org/neutron/consumer-chain-launch#relevant-parameters +// [^2]: https://github.com/cosmos/interchain-security/blob/54e9852d3c89a2513cd0170a56c6eec894fc878d/proto/interchain_security/ccv/consumer/v1/consumer.proto#L61-L66 +func setupNeutronGenesis( + soft_opt_out_threshold string, + reward_denoms []string, + provider_reward_denoms []string) func(ibc.ChainConfig, []byte) ([]byte, error) { + return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { + g := make(map[string]interface{}) + if err := json.Unmarshal(genbz, &g); err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err) + } + + if err := dyno.Set(g, soft_opt_out_threshold, "app_state", "ccvconsumer", "params", "soft_opt_out_threshold"); err != nil { + return nil, fmt.Errorf("failed to set soft_opt_out_threshold in genesis json: %w", err) + } + + if err := dyno.Set(g, reward_denoms, "app_state", "ccvconsumer", "params", "reward_denoms"); err != nil { + return nil, fmt.Errorf("failed to set reward_denoms in genesis json: %w", err) + } + + if err := dyno.Set(g, provider_reward_denoms, "app_state", "ccvconsumer", "params", "provider_reward_denoms"); err != nil { + return nil, fmt.Errorf("failed to set provider_reward_denoms in genesis json: %w", err) + } + + out, err := json.Marshal(g) + + if err != nil { + return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err) + } + return out, nil + } +} + +// Sets custom fields for the Gaia genesis file that interchaintest isn't aware of by default. +// +// allowed_messages - explicitly allowed messages to be accepted by the the interchainaccounts section +func setupGaiaGenesis(allowed_messages []string) func(ibc.ChainConfig, []byte) ([]byte, error) { + return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { + g := make(map[string]interface{}) + if err := json.Unmarshal(genbz, &g); err != nil { + return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err) + } + + if err := dyno.Set(g, allowed_messages, "app_state", "interchainaccounts", "host_genesis_state", "params", "allow_messages"); err != nil { + return nil, fmt.Errorf("failed to set allow_messages for interchainaccount host in genesis json: %w", err) + } + + out, err := json.Marshal(g) + if err != nil { + return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err) + } + return out, nil + } +} + +func getCreateValidatorCmd(chain ibc.Chain) []string { + // Before receiving a validator set change (VSC) packet, + // consumer chains disallow bank transfers. To trigger a VSC + // packet, this creates a validator (from a random public key) + // that will never do anything, triggering a VSC + // packet. Eventually this validator will become jailed, + // triggering another one. + cmd := []string{"gaiad", "tx", "staking", "create-validator", + "--amount", "1000000uatom", + "--pubkey", `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"qwrYHaJ7sNHfYBR1nzDr851+wT4ed6p8BbwTeVhaHoA="}`, + "--moniker", "a", + "--commission-rate", "0.1", + "--commission-max-rate", "0.2", + "--commission-max-change-rate", "0.01", + "--min-self-delegation", "1000000", + "--node", chain.GetRPCAddress(), + "--home", chain.HomeDir(), + "--chain-id", chain.Config().ChainID, + "--from", "faucet", + "--fees", "20000uatom", + "--keyring-backend", keyring.BackendTest, + "-y", + } + + return cmd +} diff --git a/stride-covenant/tests/interchaintest/ics_test.go b/stride-covenant/tests/interchaintest/ics_test.go index a0ce35ed..fc62a580 100644 --- a/stride-covenant/tests/interchaintest/ics_test.go +++ b/stride-covenant/tests/interchaintest/ics_test.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/crypto/keyring" transfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types" - "github.com/icza/dyno" ibctest "github.com/strangelove-ventures/interchaintest/v3" "github.com/strangelove-ventures/interchaintest/v3/chain/cosmos" "github.com/strangelove-ventures/interchaintest/v3/ibc" @@ -22,158 +21,6 @@ import ( "go.uber.org/zap/zaptest" ) -type DepositorInstantiateMsg struct { - StAtomReceiver WeightedReceiver `json:"st_atom_receiver"` - AtomReceiver WeightedReceiver `json:"atom_receiver"` - ClockAddress string `json:"clock_address,string"` - GaiaNeutronIBCTransferChannelId string `json:"gaia_neutron_ibc_transfer_channel_id"` -} - -type LPerInstantiateMsg struct { - LpPosition LpInfo `json:"lp_position"` - ClockAddress string `json:"clock_address,string"` - HolderAddress string `json:"holder_address,string"` -} - -type LpInfo struct { - Addr string `json:"addr,string"` -} - -type WeightedReceiver struct { - Amount int64 `json:"amount"` - Address string `json:"address,string"` -} - -// A query against the Neutron example contract. Note the usage of -// `omitempty` on fields. This means that if that field has no value, -// it will not have a key in the serialized representaiton of the -// struct, thus mimicing the serialization of Rust enums. -type IcaExampleContractQuery struct { - InterchainAccountAddress InterchainAccountAddressQuery `json:"interchain_account_address,omitempty"` -} - -type InterchainAccountAddressQuery struct { - InterchainAccountId string `json:"interchain_account_id"` - ConnectionId string `json:"connection_id"` -} - -type QueryResponse struct { - Data InterchainAccountAddressQueryResponse `json:"data"` -} - -type ICAQueryResponse struct { - Data DepositorInterchainAccountAddressQueryResponse `json:"data"` -} - -type InterchainAccountAddressQueryResponse struct { - InterchainAccountAddress string `json:"interchain_account_address"` -} - -type DepositorICAAddressQuery struct { - DepositorInterchainAccountAddress DepositorInterchainAccountAddressQuery `json:"depositor_interchain_account_address"` -} - -type DepositorContractQuery struct { - ClockAddress ClockAddressQuery `json:"clock_address"` -} - -type StAtomWeightedReceiverQuery struct { - StAtomReceiver StAtomReceiverQuery `json:"st_atom_receiver"` -} - -type AtomWeightedReceiverQuery struct { - AtomReceiver AtomReceiverQuery `json:"atom_receiver"` -} - -type ClockAddressQuery struct{} -type StAtomReceiverQuery struct{} -type AtomReceiverQuery struct{} -type DepositorInterchainAccountAddressQuery struct{} - -type WeightedReceiverResponse struct { - Data WeightedReceiver `json:"data"` -} - -type ClockQueryResponse struct { - Data string `json:"data"` -} - -// A query response from the Neutron contract. Note that when -// interchaintest returns query responses, it does so in the form -// `{"data": }`, so we need this outer data key, which is -// not present in the neutron contract, to properly deserialze. - -type DepositorInterchainAccountAddressQueryResponse struct { - DepositorInterchainAccountAddress string `json:"depositor_interchain_account_address"` -} - -// Sets custom fields for the Neutron genesis file that interchaintest isn't aware of by default. -// -// soft_opt_out_threshold - the bottom `soft_opt_out_threshold` -// percentage of validators may opt out of running a Neutron -// node [^1]. -// -// reward_denoms - the reward denominations allowed to be sent to the -// provider (atom) from the consumer (neutron) [^2]. -// -// provider_reward_denoms - the reward denominations allowed to be -// sent to the consumer by the provider [^2]. -// -// [^1]: https://docs.neutron.org/neutron/consumer-chain-launch#relevant-parameters -// [^2]: https://github.com/cosmos/interchain-security/blob/54e9852d3c89a2513cd0170a56c6eec894fc878d/proto/interchain_security/ccv/consumer/v1/consumer.proto#L61-L66 -func setupNeutronGenesis( - soft_opt_out_threshold string, - reward_denoms []string, - provider_reward_denoms []string) func(ibc.ChainConfig, []byte) ([]byte, error) { - return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { - g := make(map[string]interface{}) - if err := json.Unmarshal(genbz, &g); err != nil { - return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err) - } - - if err := dyno.Set(g, soft_opt_out_threshold, "app_state", "ccvconsumer", "params", "soft_opt_out_threshold"); err != nil { - return nil, fmt.Errorf("failed to set soft_opt_out_threshold in genesis json: %w", err) - } - - if err := dyno.Set(g, reward_denoms, "app_state", "ccvconsumer", "params", "reward_denoms"); err != nil { - return nil, fmt.Errorf("failed to set reward_denoms in genesis json: %w", err) - } - - if err := dyno.Set(g, provider_reward_denoms, "app_state", "ccvconsumer", "params", "provider_reward_denoms"); err != nil { - return nil, fmt.Errorf("failed to set provider_reward_denoms in genesis json: %w", err) - } - - out, err := json.Marshal(g) - - if err != nil { - return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err) - } - return out, nil - } -} - -// Sets custom fields for the Gaia genesis file that interchaintest isn't aware of by default. -// -// allowed_messages - explicitly allowed messages to be accepted by the the interchainaccounts section -func setupGaiaGenesis(allowed_messages []string) func(ibc.ChainConfig, []byte) ([]byte, error) { - return func(chainConfig ibc.ChainConfig, genbz []byte) ([]byte, error) { - g := make(map[string]interface{}) - if err := json.Unmarshal(genbz, &g); err != nil { - return nil, fmt.Errorf("failed to unmarshal genesis file: %w", err) - } - - if err := dyno.Set(g, allowed_messages, "app_state", "interchainaccounts", "host_genesis_state", "params", "allow_messages"); err != nil { - return nil, fmt.Errorf("failed to set allow_messages for interchainaccount host in genesis json: %w", err) - } - - out, err := json.Marshal(g) - if err != nil { - return nil, fmt.Errorf("failed to marshal genesis bytes to json: %w", err) - } - return out, nil - } -} - // This tests Cosmos Interchain Security, spinning up gaia, neutron, and stride func TestICS(t *testing.T) { if testing.Short() { @@ -264,8 +111,6 @@ func TestICS(t *testing.T) { relayer.RelayerOptionExtraStartFlags{Flags: []string{"-d", "--log-format", "console"}}, ).Build(t, client, network) - const clockContractAddress = "clock_contract_address" - const holderContractAddress = "holder_contract_address" const icaAccountId = "test" var icaAccountAddress string // Prep Interchain @@ -343,28 +188,7 @@ func TestICS(t *testing.T) { } } - // Before receiving a validator set change (VSC) packet, - // consumer chains disallow bank transfers. To trigger a VSC - // packet, this creates a validator (from a random public key) - // that will never do anything, triggering a VSC - // packet. Eventually this validator will become jailed, - // triggering another one. - cmd := []string{"gaiad", "tx", "staking", "create-validator", - "--amount", "1000000uatom", - "--pubkey", `{"@type":"/cosmos.crypto.ed25519.PubKey","key":"qwrYHaJ7sNHfYBR1nzDr851+wT4ed6p8BbwTeVhaHoA="}`, - "--moniker", "a", - "--commission-rate", "0.1", - "--commission-max-rate", "0.2", - "--commission-max-change-rate", "0.01", - "--min-self-delegation", "1000000", - "--node", atom.GetRPCAddress(), - "--home", atom.HomeDir(), - "--chain-id", atom.Config().ChainID, - "--from", "faucet", - "--fees", "20000uatom", - "--keyring-backend", keyring.BackendTest, - "-y", - } + cmd := getCreateValidatorCmd(atom) _, _, err = atom.Exec(ctx, cmd, nil) require.NoError(t, err) @@ -398,66 +222,118 @@ func TestICS(t *testing.T) { } } // find the ibc transfer channel to gaia (same connection hops) + print("\n neutron channels:\n") for _, s := range neutronChannelInfo { + channelJson, _ := json.Marshal(s) + print("\n", string(channelJson), "\n") if s.State == "STATE_OPEN" && s.Ordering == "ORDER_UNORDERED" && s.PortID == "transfer" { if len(s.Counterparty.ChannelID) > 5 && s.Counterparty.PortID == "transfer" && s.ConnectionHops[0] == neutronGaiaICSChannel.ConnectionHops[0] { neutronGaiaIBCChannel = s } } } - gaiaNeutronIBCChannel := neutronGaiaIBCChannel.Counterparty + + print("\n gaia channels:\n") + gaiaChannelInfo, _ := r.GetChannels(ctx, eRep, atom.Config().ChainID) + for _, s := range gaiaChannelInfo { + channelJson, _ := json.Marshal(s) + print("\n", string(channelJson), "\n") + } + neutronGaiaIBCChannelId := neutronGaiaIBCChannel.ChannelID - gaiaNeutronIBCChannelId := gaiaNeutronIBCChannel.ChannelID + gaiaNeutronIBCChannelId := neutronGaiaIBCChannel.Counterparty.ChannelID gaiaNeutronICSChannelId := neutronGaiaICSChannel.Counterparty.ChannelID neutronGaiaICSChannelId := neutronGaiaICSChannel.ChannelID + + print("\n picked gaiaChannelId: ", gaiaNeutronIBCChannelId, "\n neutronChannelId: ", neutronGaiaIBCChannelId) _, _ = gaiaNeutronICSChannelId, neutronGaiaICSChannelId - t.Run("instantiate LPer", func(t *testing.T) { - codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_lper.wasm") - require.NoError(t, err, "failed to store neutron ICA contract") - lpinfo := LpInfo{ - Addr: "test", - } - msg := LPerInstantiateMsg{ - LpPosition: lpinfo, - ClockAddress: clockContractAddress, - HolderAddress: holderContractAddress, - } + t.Run("stride covenant tests", func(t *testing.T) { + const clockContractAddress = "clock_contract_address" + const holderContractAddress = "holder_contract_address" - str, err := json.Marshal(msg) - require.NoError(t, err, "Failed to marshall LPerInstantiateMsg") + var lperContractAddress string + var depositorContractAddress string + var stAtomWeightedReceiver WeightedReceiver + var atomWeightedReceiver WeightedReceiver - lpAddress, err := cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) - require.NoError(t, err, "failed to instantiate lper contract: ", err) - print(lpAddress) - }) + t.Run("instantiate lper contract", func(t *testing.T) { + codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_lper.wasm") + require.NoError(t, err, "failed to store neutron ICA contract") + lpInfo := LpInfo{ + Addr: "test", + } + lpMsg := LPerInstantiateMsg{ + LpPosition: lpInfo, + ClockAddress: clockContractAddress, + HolderAddress: holderContractAddress, + } - t.Run("instantiate depositor", func(t *testing.T) { - // Store and instantiate the Neutron ICA example contract. The - // wasm file is placed in `wasms/` by the `just test` command. - codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_depositor.wasm") - require.NoError(t, err, "failed to store neutron ICA contract") + str, err := json.Marshal(lpMsg) + require.NoError(t, err, "Failed to marshall LPerInstantiateMsg") - stAtomWeightedReceiver := WeightedReceiver{ - Amount: int64(10), - Address: "neutron1ud6resqzgewt92njs826m5st98n9r6kkjnurup", - } - atomWeightedReceiver := WeightedReceiver{ - Amount: int64(10), - Address: "neutron1ud6resqzgewt92njs826m5st98n9r6kkjnurup", - } - msg := DepositorInstantiateMsg{ - StAtomReceiver: stAtomWeightedReceiver, - AtomReceiver: atomWeightedReceiver, - ClockAddress: clockContractAddress, - GaiaNeutronIBCTransferChannelId: gaiaNeutronIBCChannelId, - } + lperContractAddress, err = cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) + require.NoError(t, err, "failed to instantiate lper contract: ", err) - str, err := json.Marshal(msg) - require.NoError(t, err, "Failed to marshall DepositorInstantiateMsg") + print("\n LP contract instantiated with addr: ", lperContractAddress, "\n") + }) + + t.Run("instantiate depositor contract", func(t *testing.T) { + codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_depositor.wasm") + require.NoError(t, err, "failed to store neutron ICA contract") + + stAtomWeightedReceiver = WeightedReceiver{ + Amount: int64(10), + Address: lperContractAddress, + } + + atomWeightedReceiver = WeightedReceiver{ + Amount: int64(10), + Address: lperContractAddress, + } - address, err := cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) - require.NoError(t, err, "failed to instantiate depositor contract: ", err) + msg := DepositorInstantiateMsg{ + StAtomReceiver: stAtomWeightedReceiver, + AtomReceiver: atomWeightedReceiver, + ClockAddress: clockContractAddress, + GaiaNeutronIBCTransferChannelId: gaiaNeutronIBCChannelId, + } + + str, err := json.Marshal(msg) + require.NoError(t, err, "Failed to marshall DepositorInstantiateMsg") + + depositorContractAddress, err = cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) + require.NoError(t, err, "failed to instantiate depositor contract: ", err) + + print("\n depositor contract instantiated with addr: ", depositorContractAddress, "\n") + + t.Run("query instantiated clock", func(t *testing.T) { + var response ClockQueryResponse + err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, DepositorContractQuery{ + ClockAddress: ClockAddressQuery{}, + }, &response) + require.NoError(t, err, "failed to query clock address") + expectedAddrJson, _ := json.Marshal(clockContractAddress) + require.Equal(t, string(expectedAddrJson), response.Data) + }) + + t.Run("query instantiated weighted receivers", func(t *testing.T) { + var stAtomReceiver WeightedReceiverResponse + err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, StAtomWeightedReceiverQuery{ + StAtomReceiver: StAtomReceiverQuery{}, + }, &stAtomReceiver) + require.NoError(t, err, "failed to query stAtom weighted receiver") + require.Equal(t, stAtomWeightedReceiver, stAtomReceiver.Data) + + var atomReceiver WeightedReceiverResponse + err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, AtomWeightedReceiverQuery{ + AtomReceiver: AtomReceiverQuery{}, + }, &atomReceiver) + require.NoError(t, err, "failed to query atom weighted receiver") + require.Equal(t, int64(10), atomReceiver.Data.Amount) + require.Equal(t, lperContractAddress, atomReceiver.Data.Address) + }) + }) neutronSrcDenomTrace := transfertypes.ParseDenomTrace( transfertypes.GetPrefixedDenom("transfer", @@ -465,37 +341,10 @@ func TestICS(t *testing.T) { atom.Config().Denom)) neutronDstIbcDenom := neutronSrcDenomTrace.IBCDenom() - t.Run("query instantiated clock", func(t *testing.T) { - var response ClockQueryResponse - err = cosmosNeutron.QueryContract(ctx, address, DepositorContractQuery{ - ClockAddress: ClockAddressQuery{}, - }, &response) - require.NoError(t, err, "failed to query clock address") - expectedAddrJson, _ := json.Marshal(clockContractAddress) - require.Equal(t, string(expectedAddrJson), response.Data) - }) - - t.Run("query instantiated weighted receivers", func(t *testing.T) { - var stAtomReceiver WeightedReceiverResponse - err = cosmosNeutron.QueryContract(ctx, address, StAtomWeightedReceiverQuery{ - StAtomReceiver: StAtomReceiverQuery{}, - }, &stAtomReceiver) - require.NoError(t, err, "failed to query stAtom weighted receiver") - require.Equal(t, stAtomWeightedReceiver, stAtomReceiver.Data) - - var atomReceiver WeightedReceiverResponse - err = cosmosNeutron.QueryContract(ctx, address, AtomWeightedReceiverQuery{ - AtomReceiver: AtomReceiverQuery{}, - }, &atomReceiver) - require.NoError(t, err, "failed to query atom weighted receiver") - require.Equal(t, int64(10), atomReceiver.Data.Amount) - require.Equal(t, "neutron1ud6resqzgewt92njs826m5st98n9r6kkjnurup", atomReceiver.Data.Address) - }) - var addrResponse QueryResponse t.Run("first tick instantiates ICA", func(t *testing.T) { // should remain constant - cmd = []string{"neutrond", "tx", "wasm", "execute", address, + cmd = []string{"neutrond", "tx", "wasm", "execute", depositorContractAddress, `{"tick":{}}`, "--from", neutronUser.KeyName, "--gas-prices", "0.0untrn", @@ -518,7 +367,7 @@ func TestICS(t *testing.T) { require.NoError(t, err, "failed to wait for blocks") var response QueryResponse - err = cosmosNeutron.QueryContract(ctx, address, IcaExampleContractQuery{ + err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, IcaExampleContractQuery{ InterchainAccountAddress: InterchainAccountAddressQuery{ InterchainAccountId: icaAccountId, ConnectionId: neutronIcsConnectionId, @@ -527,7 +376,7 @@ func TestICS(t *testing.T) { require.NoError(t, err, "failed to query ICA account address") require.NotEmpty(t, response.Data.InterchainAccountAddress) icaAccountAddress = response.Data.InterchainAccountAddress - err = cosmosNeutron.QueryContract(ctx, address, DepositorICAAddressQuery{ + err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, DepositorICAAddressQuery{ DepositorInterchainAccountAddress: DepositorInterchainAccountAddressQuery{}, }, &addrResponse) require.NoError(t, err, "failed to query ICA account address") @@ -539,6 +388,8 @@ func TestICS(t *testing.T) { response.Data.InterchainAccountAddress, icaAccountAddress, ) + + print("\ndepositor ICA instantiated with address ", icaAccountAddress, "\n") }) t.Run("multisig transfers atom to ICA account", func(t *testing.T) { @@ -560,7 +411,7 @@ func TestICS(t *testing.T) { t.Run("fund depositor contract with some neutron", func(t *testing.T) { err := neutron.SendFunds(ctx, neutronUser.KeyName, ibc.WalletAmount{ - Address: address, + Address: depositorContractAddress, Amount: 500001, Denom: neutron.Config().Denom, }) @@ -569,7 +420,7 @@ func TestICS(t *testing.T) { err = testutil.WaitForBlocks(ctx, 10, atom, neutron) require.NoError(t, err, "failed to wait for blocks") - neutronBal, err := neutron.GetBalance(ctx, address, neutron.Config().Denom) + neutronBal, err := neutron.GetBalance(ctx, depositorContractAddress, neutron.Config().Denom) require.NoError(t, err, "failed to get depositor neutron balance") require.EqualValues(t, 500001, neutronBal) }) @@ -579,7 +430,7 @@ func TestICS(t *testing.T) { require.NoError(t, err, "failed to get ICA balance") require.EqualValues(t, 20, atomBal) - cmd = []string{"neutrond", "tx", "wasm", "execute", address, + cmd = []string{"neutrond", "tx", "wasm", "execute", depositorContractAddress, `{"tick":{}}`, "--from", neutronUser.KeyName, "--gas-adjustment", `1.3`, @@ -597,7 +448,7 @@ func TestICS(t *testing.T) { _, _, err = neutron.Exec(ctx, cmd, nil) require.NoError(t, err) - err = testutil.WaitForBlocks(ctx, 50, atom, neutron) + err = testutil.WaitForBlocks(ctx, 10, atom, neutron) require.NoError(t, err, "failed to wait for blocks") atomICABal, err := atom.GetBalance(ctx, icaAccountAddress, atom.Config().Denom) @@ -606,14 +457,16 @@ func TestICS(t *testing.T) { neutronUserBalNew, err := neutron.GetBalance( ctx, - address, + depositorContractAddress, neutronDstIbcDenom) require.NoError(t, err, "failed to query depositor contract atom balance") require.Equal(t, int64(10), neutronUserBalNew) }) + // to keep docker containers alive for debugging + // err = testutil.WaitForBlocks(ctx, 200, atom, neutron) t.Run("subsequent ticks do nothing", func(t *testing.T) { - cmd = []string{"neutrond", "tx", "wasm", "execute", address, + cmd = []string{"neutrond", "tx", "wasm", "execute", depositorContractAddress, `{"tick":{}}`, "--from", neutronUser.KeyName, "--gas-prices", "0.0untrn", @@ -635,6 +488,7 @@ func TestICS(t *testing.T) { err = testutil.WaitForBlocks(ctx, 10, atom, neutron) require.NoError(t, err, "failed to wait for blocks") }) + }) } diff --git a/stride-covenant/tests/interchaintest/types.go b/stride-covenant/tests/interchaintest/types.go new file mode 100644 index 00000000..ccd013a1 --- /dev/null +++ b/stride-covenant/tests/interchaintest/types.go @@ -0,0 +1,86 @@ +package ibc_test + +type DepositorInstantiateMsg struct { + StAtomReceiver WeightedReceiver `json:"st_atom_receiver"` + AtomReceiver WeightedReceiver `json:"atom_receiver"` + ClockAddress string `json:"clock_address,string"` + GaiaNeutronIBCTransferChannelId string `json:"gaia_neutron_ibc_transfer_channel_id"` +} + +type LPerInstantiateMsg struct { + LpPosition LpInfo `json:"lp_position"` + ClockAddress string `json:"clock_address,string"` + HolderAddress string `json:"holder_address,string"` +} + +type LpInfo struct { + Addr string `json:"addr,string"` +} + +type WeightedReceiver struct { + Amount int64 `json:"amount"` + Address string `json:"address,string"` +} + +// A query against the Neutron example contract. Note the usage of +// `omitempty` on fields. This means that if that field has no value, +// it will not have a key in the serialized representaiton of the +// struct, thus mimicing the serialization of Rust enums. +type IcaExampleContractQuery struct { + InterchainAccountAddress InterchainAccountAddressQuery `json:"interchain_account_address,omitempty"` +} + +type InterchainAccountAddressQuery struct { + InterchainAccountId string `json:"interchain_account_id"` + ConnectionId string `json:"connection_id"` +} + +type QueryResponse struct { + Data InterchainAccountAddressQueryResponse `json:"data"` +} + +type ICAQueryResponse struct { + Data DepositorInterchainAccountAddressQueryResponse `json:"data"` +} + +type InterchainAccountAddressQueryResponse struct { + InterchainAccountAddress string `json:"interchain_account_address"` +} + +type DepositorICAAddressQuery struct { + DepositorInterchainAccountAddress DepositorInterchainAccountAddressQuery `json:"depositor_interchain_account_address"` +} + +type DepositorContractQuery struct { + ClockAddress ClockAddressQuery `json:"clock_address"` +} + +type StAtomWeightedReceiverQuery struct { + StAtomReceiver StAtomReceiverQuery `json:"st_atom_receiver"` +} + +type AtomWeightedReceiverQuery struct { + AtomReceiver AtomReceiverQuery `json:"atom_receiver"` +} + +type ClockAddressQuery struct{} +type StAtomReceiverQuery struct{} +type AtomReceiverQuery struct{} +type DepositorInterchainAccountAddressQuery struct{} + +type WeightedReceiverResponse struct { + Data WeightedReceiver `json:"data"` +} + +type ClockQueryResponse struct { + Data string `json:"data"` +} + +// A query response from the Neutron contract. Note that when +// interchaintest returns query responses, it does so in the form +// `{"data": }`, so we need this outer data key, which is +// not present in the neutron contract, to properly deserialze. + +type DepositorInterchainAccountAddressQueryResponse struct { + DepositorInterchainAccountAddress string `json:"depositor_interchain_account_address"` +} From b2cd8a98433fa5758ce5993579a62c56694d4cc1 Mon Sep 17 00:00:00 2001 From: bekauz Date: Sun, 18 Jun 2023 22:27:55 +0200 Subject: [PATCH 3/6] lper queries; depositor cleanup --- contracts/depositor/src/contract.rs | 46 +++++++------------ contracts/lper/src/contract.rs | 3 +- contracts/lper/src/msg.rs | 2 +- .../tests/interchaintest/ics_test.go | 39 ++++++++++++---- stride-covenant/tests/interchaintest/types.go | 13 ++++++ 5 files changed, 60 insertions(+), 43 deletions(-) diff --git a/contracts/depositor/src/contract.rs b/contracts/depositor/src/contract.rs index 8f42ac7a..5da9ecf2 100644 --- a/contracts/depositor/src/contract.rs +++ b/contracts/depositor/src/contract.rs @@ -38,7 +38,7 @@ use crate::state::{ // Default timeout for SubmitTX is two weeks const DEFAULT_TIMEOUT_SECONDS: u64 = 60 * 60 * 24 * 7 * 2; -const DEFAULT_TIMEOUT_HEIGHT: u64 = 10000000; +// const DEFAULT_TIMEOUT_HEIGHT: u64 = 10000000; const NEUTRON_DENOM: &str = "untrn"; const ATOM_DENOM: &str = "uatom"; const IBC_CONNECTION: &str = "connection-0"; @@ -84,7 +84,7 @@ pub fn instantiate( #[entry_point] pub fn execute( - mut deps: DepsMut, + deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg, @@ -98,7 +98,7 @@ pub fn execute( } -fn try_tick(mut deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult> { +fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult> { let current_state = CONTRACT_STATE.load(deps.storage)?; let ica_address: Result = ICA_ADDRESS.load(deps.storage); let gaia_account_address = match ica_address { @@ -116,10 +116,10 @@ fn try_tick(mut deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult NeutronResult> { let fee = IbcFee { recv_fee: vec![], // must be empty @@ -141,7 +141,7 @@ fn try_receive_atom_from_ica( let source_channel = GAIA_NEUTRON_IBC_TRANSFER_CHANNEL_ID.load(deps.storage)?; let lp_receiver = NATIVE_ATOM_RECEIVER.load(deps.storage)?; let amount = String::from(lp_receiver.amount.to_string()); - let receiver = String::from(lp_receiver.address.to_string()); + // let receiver = String::from(lp_receiver.address.to_string()); let coin = Coin { denom: ATOM_DENOM.to_string(), @@ -152,12 +152,13 @@ fn try_receive_atom_from_ica( source_port: "transfer".to_string(), source_channel: source_channel, token: Some(coin), - sender: address.clone().to_string(), - receiver, + sender: address.clone(), + // receiver: String::from(lp_receiver.address.to_string()), + receiver: env.contract.address.to_string(), // TODO: look into what the timeout_height should be timeout_height: Some(Height { revision_number: 2, - revision_height: 123, + revision_height: 500, }), timeout_timestamp: 0, }; @@ -192,7 +193,7 @@ fn try_receive_atom_from_ica( } fn try_register_gaia_ica( - mut deps: DepsMut, + deps: DepsMut, env: Env, ) -> NeutronResult> { let gaia_acc_id = INTERCHAIN_ACCOUNT_ID.to_string(); @@ -214,7 +215,7 @@ fn try_register_gaia_ica( fn try_execute_transfers( mut deps: DepsMut, env: Env, - info: MessageInfo, + _info: MessageInfo, gaia_account_address: String ) -> NeutronResult> { // validate that tick was triggered by the authorized clock @@ -231,7 +232,7 @@ fn try_execute_transfers( // 2. transfer 1/2 of atoms from ICA to liquidity-pooler module // let fee = min_ntrn_ibc_fee(query_min_ibc_fee(deps.as_ref())?.min_fee); - let neutron_coin = Coin { + let _neutron_coin = Coin { denom: NEUTRON_DENOM.to_string(), amount: 1000u128.to_string(), }; @@ -400,7 +401,7 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> NeutronResult pub fn query_depositor_interchain_address( deps: Deps, - env: Env, + _env: Env, ) -> NeutronResult { let addr = ICA_ADDRESS.load(deps.storage); @@ -779,19 +780,4 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> StdResult { ))), } } - -fn min_ntrn_ibc_fee(fee: IbcFee) -> IbcFee { - IbcFee { - recv_fee: fee.recv_fee, - ack_fee: fee - .ack_fee - .into_iter() - .filter(|a| a.denom == NEUTRON_DENOM) - .collect(), - timeout_fee: fee - .timeout_fee - .into_iter() - .filter(|a| a.denom == NEUTRON_DENOM) - .collect(), - } -} \ No newline at end of file + \ No newline at end of file diff --git a/contracts/lper/src/contract.rs b/contracts/lper/src/contract.rs index f9828e9c..60e35398 100644 --- a/contracts/lper/src/contract.rs +++ b/contracts/lper/src/contract.rs @@ -95,11 +95,10 @@ fn try_withdraw( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> NeutronResult { match msg { - QueryMsg::ClockAddress {} => Ok( to_binary(&CLOCK_ADDRESS.may_load(deps.storage)?)? ), - QueryMsg::LPPosition {} => Ok( + QueryMsg::LpPosition {} => Ok( to_binary(&LP_POSITION.may_load(deps.storage)?)? ) } diff --git a/contracts/lper/src/msg.rs b/contracts/lper/src/msg.rs index d905137f..7ed30b5f 100644 --- a/contracts/lper/src/msg.rs +++ b/contracts/lper/src/msg.rs @@ -25,7 +25,7 @@ pub enum ExecuteMsg { #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum QueryMsg { - LPPosition {}, + LpPosition {}, ClockAddress {}, } diff --git a/stride-covenant/tests/interchaintest/ics_test.go b/stride-covenant/tests/interchaintest/ics_test.go index fc62a580..c6c0857a 100644 --- a/stride-covenant/tests/interchaintest/ics_test.go +++ b/stride-covenant/tests/interchaintest/ics_test.go @@ -245,24 +245,30 @@ func TestICS(t *testing.T) { gaiaNeutronICSChannelId := neutronGaiaICSChannel.Counterparty.ChannelID neutronGaiaICSChannelId := neutronGaiaICSChannel.ChannelID - print("\n picked gaiaChannelId: ", gaiaNeutronIBCChannelId, "\n neutronChannelId: ", neutronGaiaIBCChannelId) _, _ = gaiaNeutronICSChannelId, neutronGaiaICSChannelId t.Run("stride covenant tests", func(t *testing.T) { const clockContractAddress = "clock_contract_address" const holderContractAddress = "holder_contract_address" + lpInfo := LpInfo{ + Addr: "test", + } var lperContractAddress string var depositorContractAddress string var stAtomWeightedReceiver WeightedReceiver var atomWeightedReceiver WeightedReceiver + neutronSrcDenomTrace := transfertypes.ParseDenomTrace( + transfertypes.GetPrefixedDenom("transfer", + neutronGaiaIBCChannelId, + atom.Config().Denom)) + neutronDstIbcDenom := neutronSrcDenomTrace.IBCDenom() + t.Run("instantiate lper contract", func(t *testing.T) { codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_lper.wasm") require.NoError(t, err, "failed to store neutron ICA contract") - lpInfo := LpInfo{ - Addr: "test", - } + lpMsg := LPerInstantiateMsg{ LpPosition: lpInfo, ClockAddress: clockContractAddress, @@ -276,6 +282,25 @@ func TestICS(t *testing.T) { require.NoError(t, err, "failed to instantiate lper contract: ", err) print("\n LP contract instantiated with addr: ", lperContractAddress, "\n") + + t.Run("query instantiated clock", func(t *testing.T) { + var response ClockQueryResponse + err = cosmosNeutron.QueryContract(ctx, lperContractAddress, LPContractQuery{ + ClockAddress: ClockAddressQuery{}, + }, &response) + require.NoError(t, err, "failed to query clock address") + expectedAddrJson, _ := json.Marshal(clockContractAddress) + require.Equal(t, string(expectedAddrJson), response.Data) + }) + + t.Run("query lp position", func(t *testing.T) { + var response LpPositionQueryResponse + err := cosmosNeutron.QueryContract(ctx, lperContractAddress, LPPositionQuery{ + LpPosition: LpPositionQuery{}, + }, &response) + require.NoError(t, err, "failed to query lp position address") + require.Equal(t, lpInfo.Addr, response.Data.Addr) + }) }) t.Run("instantiate depositor contract", func(t *testing.T) { @@ -335,12 +360,6 @@ func TestICS(t *testing.T) { }) }) - neutronSrcDenomTrace := transfertypes.ParseDenomTrace( - transfertypes.GetPrefixedDenom("transfer", - neutronGaiaIBCChannelId, - atom.Config().Denom)) - neutronDstIbcDenom := neutronSrcDenomTrace.IBCDenom() - var addrResponse QueryResponse t.Run("first tick instantiates ICA", func(t *testing.T) { // should remain constant diff --git a/stride-covenant/tests/interchaintest/types.go b/stride-covenant/tests/interchaintest/types.go index ccd013a1..b4ed90ff 100644 --- a/stride-covenant/tests/interchaintest/types.go +++ b/stride-covenant/tests/interchaintest/types.go @@ -55,6 +55,14 @@ type DepositorContractQuery struct { ClockAddress ClockAddressQuery `json:"clock_address"` } +type LPContractQuery struct { + ClockAddress ClockAddressQuery `json:"clock_address"` +} + +type LPPositionQuery struct { + LpPosition LpPositionQuery `json:"lp_position"` +} + type StAtomWeightedReceiverQuery struct { StAtomReceiver StAtomReceiverQuery `json:"st_atom_receiver"` } @@ -67,6 +75,7 @@ type ClockAddressQuery struct{} type StAtomReceiverQuery struct{} type AtomReceiverQuery struct{} type DepositorInterchainAccountAddressQuery struct{} +type LpPositionQuery struct{} type WeightedReceiverResponse struct { Data WeightedReceiver `json:"data"` @@ -76,6 +85,10 @@ type ClockQueryResponse struct { Data string `json:"data"` } +type LpPositionQueryResponse struct { + Data LpInfo `json:"data"` +} + // A query response from the Neutron contract. Note that when // interchaintest returns query responses, it does so in the form // `{"data": }`, so we need this outer data key, which is From 5e4205a7a2b6ef13750fb24b60c225885eb616a7 Mon Sep 17 00:00:00 2001 From: bekauz Date: Mon, 19 Jun 2023 21:57:11 +0200 Subject: [PATCH 4/6] wip: deploying astroport stableswap --- contracts/lper/src/contract.rs | 6 +- stride-covenant/justfile | 2 + .../tests/interchaintest/ics_test.go | 87 ++++++++++++++++--- stride-covenant/tests/interchaintest/types.go | 50 +++++++++++ 4 files changed, 132 insertions(+), 13 deletions(-) diff --git a/contracts/lper/src/contract.rs b/contracts/lper/src/contract.rs index 60e35398..e566ba37 100644 --- a/contracts/lper/src/contract.rs +++ b/contracts/lper/src/contract.rs @@ -59,7 +59,7 @@ pub fn execute( } -fn try_tick(mut deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult> { +fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult> { let current_state = CONTRACT_STATE.load(deps.storage)?; match current_state { @@ -75,7 +75,7 @@ fn no_op() -> NeutronResult> { } fn try_enter_lp_position( - mut deps: DepsMut, + deps: DepsMut, env: Env, info: MessageInfo, ) -> NeutronResult> { @@ -84,7 +84,7 @@ fn try_enter_lp_position( } fn try_withdraw( - mut deps: DepsMut, + deps: DepsMut, env: Env, info: MessageInfo, ) -> NeutronResult> { diff --git a/stride-covenant/justfile b/stride-covenant/justfile index e363677e..5a8f0a12 100644 --- a/stride-covenant/justfile +++ b/stride-covenant/justfile @@ -26,6 +26,8 @@ simtest: optimize mv ./../artifacts/stride_lper-aarch64.wasm ./../artifacts/stride_lper.wasm \ ;fi + cp ./astroport/*.wasm ./../artifacts + mkdir -p tests/interchaintest/wasms cp -R ./../artifacts/*.wasm tests/interchaintest/wasms diff --git a/stride-covenant/tests/interchaintest/ics_test.go b/stride-covenant/tests/interchaintest/ics_test.go index c6c0857a..6c43c527 100644 --- a/stride-covenant/tests/interchaintest/ics_test.go +++ b/stride-covenant/tests/interchaintest/ics_test.go @@ -4,6 +4,8 @@ import ( "context" "encoding/json" "fmt" + "strconv" + "strings" "testing" "time" @@ -233,6 +235,8 @@ func TestICS(t *testing.T) { } } + gaiaNeutronIBCChannel := neutronGaiaIBCChannel.Counterparty + print("\n gaia channels:\n") gaiaChannelInfo, _ := r.GetChannels(ctx, eRep, atom.Config().ChainID) for _, s := range gaiaChannelInfo { @@ -240,13 +244,6 @@ func TestICS(t *testing.T) { print("\n", string(channelJson), "\n") } - neutronGaiaIBCChannelId := neutronGaiaIBCChannel.ChannelID - gaiaNeutronIBCChannelId := neutronGaiaIBCChannel.Counterparty.ChannelID - gaiaNeutronICSChannelId := neutronGaiaICSChannel.Counterparty.ChannelID - neutronGaiaICSChannelId := neutronGaiaICSChannel.ChannelID - - _, _ = gaiaNeutronICSChannelId, neutronGaiaICSChannelId - t.Run("stride covenant tests", func(t *testing.T) { const clockContractAddress = "clock_contract_address" const holderContractAddress = "holder_contract_address" @@ -261,7 +258,7 @@ func TestICS(t *testing.T) { neutronSrcDenomTrace := transfertypes.ParseDenomTrace( transfertypes.GetPrefixedDenom("transfer", - neutronGaiaIBCChannelId, + neutronGaiaIBCChannel.ChannelID, atom.Config().Denom)) neutronDstIbcDenom := neutronSrcDenomTrace.IBCDenom() @@ -321,7 +318,7 @@ func TestICS(t *testing.T) { StAtomReceiver: stAtomWeightedReceiver, AtomReceiver: atomWeightedReceiver, ClockAddress: clockContractAddress, - GaiaNeutronIBCTransferChannelId: gaiaNeutronIBCChannelId, + GaiaNeutronIBCTransferChannelId: gaiaNeutronIBCChannel.ChannelID, } str, err := json.Marshal(msg) @@ -360,6 +357,76 @@ func TestICS(t *testing.T) { }) }) + t.Run("deploy astroport contracts", func(t *testing.T) { + t.Run("factory", func(t *testing.T) { + // codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_factory.wasm") + // require.NoError(t, err, "failed to store astroport factory contract") + }) + + t.Run("stableswap", func(t *testing.T) { + codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_pair_stable.wasm") + require.NoError(t, err, "failed to store astroport stableswap contract") + + numCodeId, err := strconv.ParseUint(codeId, 10, 64) + require.NoError(t, err, "failed to parse codeId into uint64") + + initParams := StablePoolParams{ + Amp: 9001, + Owner: nil, + } + binaryData, err := json.Marshal(initParams) + require.NoError(t, err, "error encoding stable pool params to binary") + + msg := StableswapInstantiateMsg{ + TokenCodeId: numCodeId, + FactoryAddr: depositorContractAddress, // random + AssetInfos: []AssetInfo{ + { + NativeToken: &NativeToken{ + Denom: "statom", + }, + }, + { + NativeToken: &NativeToken{ + Denom: atom.Config().Denom, + }, + }, + }, + InitParams: binaryData, + } + + str, err := json.Marshal(msg) + require.NoError(t, err, "Failed to marshall DepositorInstantiateMsg") + print("\n stableswap init msg: ", string(str), "\n") + + cmd = []string{"neutrond", "tx", "wasm", "instantiate", + codeId, + string(str), + "--from", neutronUser.KeyName, + "--label", "stableswap", + "--no-admin", + "--gas-prices", "0.0untrn", + "--gas-adjustment", `1.5`, + "--output", "json", + "--home", "/var/cosmos-chain/neutron-2", + "--node", neutron.GetRPCAddress(), + "--home", neutron.HomeDir(), + "--chain-id", neutron.Config().ChainID, + "--from", neutronUser.KeyName, + "--gas", "auto", + "--keyring-backend", keyring.BackendTest, + "-y", + } + + print(strings.Join(cmd, " ")) + stdout, stderr, err := neutron.Exec(ctx, cmd, nil) + require.NoError(t, err) + print("\nstdout: ", stdout) + print("\nstderr: ", stderr) + }) + + }) + var addrResponse QueryResponse t.Run("first tick instantiates ICA", func(t *testing.T) { // should remain constant @@ -467,7 +534,7 @@ func TestICS(t *testing.T) { _, _, err = neutron.Exec(ctx, cmd, nil) require.NoError(t, err) - err = testutil.WaitForBlocks(ctx, 10, atom, neutron) + err = testutil.WaitForBlocks(ctx, 20, atom, neutron) require.NoError(t, err, "failed to wait for blocks") atomICABal, err := atom.GetBalance(ctx, icaAccountAddress, atom.Config().Denom) diff --git a/stride-covenant/tests/interchaintest/types.go b/stride-covenant/tests/interchaintest/types.go index b4ed90ff..efba3b2c 100644 --- a/stride-covenant/tests/interchaintest/types.go +++ b/stride-covenant/tests/interchaintest/types.go @@ -97,3 +97,53 @@ type LpPositionQueryResponse struct { type DepositorInterchainAccountAddressQueryResponse struct { DepositorInterchainAccountAddress string `json:"depositor_interchain_account_address"` } + +// astroport stableswap +type StableswapInstantiateMsg struct { + TokenCodeId uint64 `json:"token_code_id"` + FactoryAddr string `json:"factory_addr"` + AssetInfos []AssetInfo `json:"asset_infos"` + InitParams []byte `json:"init_params"` +} + +type AssetInfo struct { + Token *Token `json:"token,omitempty"` + NativeToken *NativeToken `json:"native_token,omitempty"` +} + +type StablePoolParams struct { + Amp uint64 `json:"amp"` + Owner *string `json:"owner"` +} + +type Token struct { + ContractAddr string `json:"contract_addr"` +} + +type NativeToken struct { + Denom string `json:"denom"` +} + +// astroport factory +type FactoryInstantiateMsg struct { + PairConfigs []PairConfig `json:"pair_configs"` + TokenCodeId uint64 `json:"token_code_id"` + FeeAddress string `json:"fee_address"` + GeneratorAddress string `json:"generator_address"` + Owner string `json:"owner"` + WhitelistCodeId uint64 `json:"whitelist_code_id"` +} + +type PairConfig struct { + CodeId uint64 `json:"token_code_id"` + PairType PairType `json:"pair_type"` + TotalFeeBps uint64 `json:"total_fee_bps"` + MakerFeeBps uint64 `json:"maker_fee_bps"` + IsDisabled bool `json:"is_disabled"` + IsGeneratorDisabled bool `json:"is_generator_disabled"` +} + +type PairType struct { + Xyk string `json:"xyk,omitempty"` + Stable string `json:"stable,omitempty"` +} From 00aff4d89fb862328efab127107e338c5cb72cc5 Mon Sep 17 00:00:00 2001 From: bekauz Date: Tue, 20 Jun 2023 23:04:46 +0200 Subject: [PATCH 5/6] astroport contracts deployed & instantiated --- .../tests/interchaintest/ics_test.go | 215 +++++++++++++++--- stride-covenant/tests/interchaintest/types.go | 78 ++++++- 2 files changed, 257 insertions(+), 36 deletions(-) diff --git a/stride-covenant/tests/interchaintest/ics_test.go b/stride-covenant/tests/interchaintest/ics_test.go index 6c43c527..7a4ce440 100644 --- a/stride-covenant/tests/interchaintest/ics_test.go +++ b/stride-covenant/tests/interchaintest/ics_test.go @@ -5,7 +5,6 @@ import ( "encoding/json" "fmt" "strconv" - "strings" "testing" "time" @@ -358,17 +357,166 @@ func TestICS(t *testing.T) { }) t.Run("deploy astroport contracts", func(t *testing.T) { + stablePairCodeIdStr, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_pair_stable.wasm") + require.NoError(t, err, "failed to store astroport stableswap contract") + stablePairCodeId, err := strconv.ParseUint(stablePairCodeIdStr, 10, 64) + require.NoError(t, err, "failed to parse codeId into uint64") + + factoryCodeIdStr, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_factory.wasm") + require.NoError(t, err, "failed to store astroport factory contract") + // factoryCodeId, err := strconv.ParseUint(factoryCodeIdStr, 10, 64) + // require.NoError(t, err, "failed to parse codeId into uint64") + + whitelistCodeIdStr, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_whitelist.wasm") + require.NoError(t, err, "failed to store astroport whitelist contract") + whitelistCodeId, err := strconv.ParseUint(whitelistCodeIdStr, 10, 64) + require.NoError(t, err, "failed to parse codeId into uint64") + + tokenCodeIdStr, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_token.wasm") + require.NoError(t, err, "failed to store astroport token contract") + tokenCodeId, err := strconv.ParseUint(tokenCodeIdStr, 10, 64) + require.NoError(t, err, "failed to parse codeId into uint64") + + var coinRegistryAddress string + var factoryAddress string + var stableswapAddress string + _ = stableswapAddress + t.Run("astroport token", func(t *testing.T) { + + // cap := uint64(1) + msg := NativeTokenInstantiateMsg{ + Name: "nativetoken", + Symbol: "ntk", + Decimals: 5, + InitialBalances: []Cw20Coin{ + // Cw20Coin{ + // Address: neutronUser.Bech32Address(neutron.Config().Bech32Prefix), + // Amount: 1, + // }, + }, + // Mint: &MinterResponse{ + // Minter: depositorContractAddress, + // Cap: &cap, + // }, + Mint: nil, + Marketing: nil, + } + + str, err := json.Marshal(msg) + require.NoError(t, err, "Failed to marshall NativeTokenInstantiateMsg") + + tokenAddress, err := cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, tokenCodeIdStr, string(str), true) + require.NoError(t, err, "Failed to instantiate Native Token") + print("\nNative token: ", tokenAddress, "\n") + err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) + require.NoError(t, err, "failed to wait for blocks") + }) + + t.Run("whitelist", func(t *testing.T) { + + admins := []string{neutronUser.Bech32Address(neutron.Config().Bech32Prefix)} + + msg := WhitelistInstantiateMsg{ + Admins: admins, + Mutable: false, + } + + str, err := json.Marshal(msg) + require.NoError(t, err, "Failed to marshall WhitelistInstantiateMsg") + + whitelistAddress, err := cosmosNeutron.InstantiateContract( + ctx, neutronUser.KeyName, whitelistCodeIdStr, string(str), true) + require.NoError(t, err, "Failed to instantiate Whitelist") + print("\nWhitelist: ", whitelistAddress, "\n") + err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) + require.NoError(t, err, "failed to wait for blocks") + }) + + t.Run("native coins registry", func(t *testing.T) { + coinRegistryCodeId, err := cosmosNeutron.StoreContract( + ctx, neutronUser.KeyName, "wasms/astroport_native_coin_registry.wasm") + require.NoError(t, err, "failed to store astroport native coin registry contract") + + msg := NativeCoinRegistryInstantiateMsg{ + Owner: neutronUser.Bech32Address(neutron.Config().Bech32Prefix), + } + str, err := json.Marshal(msg) + require.NoError(t, err, "Failed to marshall NativeCoinRegistryInstantiateMsg") + + nativeCoinRegistryAddress, err := cosmosNeutron.InstantiateContract( + ctx, neutronUser.KeyName, coinRegistryCodeId, string(str), true) + require.NoError(t, err, "Failed to instantiate NativeCoinRegistry") + coinRegistryAddress = nativeCoinRegistryAddress + print("\nNativeCoinRegistry: ", nativeCoinRegistryAddress, "\n") + err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) + require.NoError(t, err, "failed to wait for blocks") + }) + + t.Run("add coins to registry", func(t *testing.T) { + // no clue how to marshall go struct fields into rust Vec<(String, u8)> + // so passing a string + addMessage := `{"add":{"native_coins":[["statom",10],["uatom",10]]}}` + addCmd := []string{"neutrond", "tx", "wasm", "execute", + coinRegistryAddress, + addMessage, + "--from", neutronUser.KeyName, + "--gas-prices", "0.0untrn", + "--gas-adjustment", `1.5`, + "--output", "json", + "--home", "/var/cosmos-chain/neutron-2", + "--node", neutron.GetRPCAddress(), + "--home", neutron.HomeDir(), + "--chain-id", neutron.Config().ChainID, + "--from", neutronUser.KeyName, + "--gas", "auto", + "--keyring-backend", keyring.BackendTest, + "-y", + } + _, _, err = cosmosNeutron.Exec(ctx, addCmd, nil) + require.NoError(t, err, err) + + err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) + require.NoError(t, err, "failed to wait for blocks") + }) + t.Run("factory", func(t *testing.T) { - // codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_factory.wasm") - // require.NoError(t, err, "failed to store astroport factory contract") + pairConfigs := []PairConfig{ + PairConfig{ + CodeId: stablePairCodeId, + PairType: PairType{ + Stable: struct{}{}, + }, + TotalFeeBps: 0, + MakerFeeBps: 0, + IsDisabled: false, + IsGeneratorDisabled: true, + }, + } + + msg := FactoryInstantiateMsg{ + PairConfigs: pairConfigs, + TokenCodeId: tokenCodeId, + FeeAddress: nil, + GeneratorAddress: nil, + Owner: neutronUser.Bech32Address(neutron.Config().Bech32Prefix), + WhitelistCodeId: whitelistCodeId, + CoinRegistryAddress: coinRegistryAddress, + } + + str, err := json.Marshal(msg) + require.NoError(t, err, "Failed to marshall FactoryInstantiateMsg") + + factoryAddr, err := cosmosNeutron.InstantiateContract( + ctx, neutronUser.KeyName, factoryCodeIdStr, string(str), true) + require.NoError(t, err, "Failed to instantiate Factory") + factoryAddress = factoryAddr + print("\nFactory: ", factoryAddress, "\n") + + err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) + require.NoError(t, err, "failed to wait for blocks") }) t.Run("stableswap", func(t *testing.T) { - codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_pair_stable.wasm") - require.NoError(t, err, "failed to store astroport stableswap contract") - - numCodeId, err := strconv.ParseUint(codeId, 10, 64) - require.NoError(t, err, "failed to parse codeId into uint64") initParams := StablePoolParams{ Amp: 9001, @@ -377,30 +525,42 @@ func TestICS(t *testing.T) { binaryData, err := json.Marshal(initParams) require.NoError(t, err, "error encoding stable pool params to binary") - msg := StableswapInstantiateMsg{ - TokenCodeId: numCodeId, - FactoryAddr: depositorContractAddress, // random - AssetInfos: []AssetInfo{ - { - NativeToken: &NativeToken{ - Denom: "statom", - }, + assetInfos := []AssetInfo{ + { + NativeToken: &NativeToken{ + Denom: "statom", }, - { - NativeToken: &NativeToken{ - Denom: atom.Config().Denom, - }, + }, + { + NativeToken: &NativeToken{ + Denom: atom.Config().Denom, }, }, - InitParams: binaryData, + } + + msg := StableswapInstantiateMsg{ + TokenCodeId: tokenCodeId, + FactoryAddr: factoryAddress, + AssetInfos: assetInfos, + InitParams: binaryData, } str, err := json.Marshal(msg) require.NoError(t, err, "Failed to marshall DepositorInstantiateMsg") print("\n stableswap init msg: ", string(str), "\n") + // stableswapAddr, err := cosmosNeutron.InstantiateContract( + // ctx, neutronUser.KeyName, stablePairCodeIdStr, string(str), true, + // ) + // require.NoError(t, err, "Failed to instantiate Factory") + // stableswapAddress = stableswapAddr + // print("\nstableswap: ", stableswapAddress, "\n") + + // err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) + // require.NoError(t, err, "failed to wait for blocks") + cmd = []string{"neutrond", "tx", "wasm", "instantiate", - codeId, + stablePairCodeIdStr, string(str), "--from", neutronUser.KeyName, "--label", "stableswap", @@ -417,12 +577,13 @@ func TestICS(t *testing.T) { "--keyring-backend", keyring.BackendTest, "-y", } - - print(strings.Join(cmd, " ")) - stdout, stderr, err := neutron.Exec(ctx, cmd, nil) + // print(strings.Join(cmd, " ")) + stdout, _, err := cosmosNeutron.Exec(ctx, cmd, nil) require.NoError(t, err) - print("\nstdout: ", stdout) - print("\nstderr: ", stderr) + + stableswapAddress = string(stdout) + print("\nstdout: ", string(stdout)) + // print("\nstderr: ", string(stderr)) }) }) diff --git a/stride-covenant/tests/interchaintest/types.go b/stride-covenant/tests/interchaintest/types.go index efba3b2c..09b999c1 100644 --- a/stride-covenant/tests/interchaintest/types.go +++ b/stride-covenant/tests/interchaintest/types.go @@ -126,16 +126,17 @@ type NativeToken struct { // astroport factory type FactoryInstantiateMsg struct { - PairConfigs []PairConfig `json:"pair_configs"` - TokenCodeId uint64 `json:"token_code_id"` - FeeAddress string `json:"fee_address"` - GeneratorAddress string `json:"generator_address"` - Owner string `json:"owner"` - WhitelistCodeId uint64 `json:"whitelist_code_id"` + PairConfigs []PairConfig `json:"pair_configs"` + TokenCodeId uint64 `json:"token_code_id"` + FeeAddress *string `json:"fee_address"` + GeneratorAddress *string `json:"generator_address"` + Owner string `json:"owner"` + WhitelistCodeId uint64 `json:"whitelist_code_id"` + CoinRegistryAddress string `json:"coin_registry_address"` } type PairConfig struct { - CodeId uint64 `json:"token_code_id"` + CodeId uint64 `json:"code_id"` PairType PairType `json:"pair_type"` TotalFeeBps uint64 `json:"total_fee_bps"` MakerFeeBps uint64 `json:"maker_fee_bps"` @@ -144,6 +145,65 @@ type PairConfig struct { } type PairType struct { - Xyk string `json:"xyk,omitempty"` - Stable string `json:"stable,omitempty"` + // Xyk struct{} `json:"xyk,omitempty"` + Stable struct{} `json:"stable,omitempty"` + // Custom struct{} `json:"custom,omitempty"` +} + +// astroport native coin registry + +type NativeCoinRegistryInstantiateMsg struct { + Owner string `json:"owner"` +} + +type AddExecuteMsg struct { + Add Add `json:"add"` +} + +type Add struct { + NativeCoins []NativeCoin `json:"native_coins"` +} + +type NativeCoin struct { + Name string `json:"name"` + Value uint8 `json:"value"` +} + +// Add { native_coins: Vec<(String, u8)> }, + +// astroport native token +type NativeTokenInstantiateMsg struct { + Name string `json:"name"` + Symbol string `json:"symbol"` + Decimals uint8 `json:"decimals"` + InitialBalances []Cw20Coin `json:"initial_balances"` + Mint *MinterResponse `json:"mint"` + Marketing *InstantiateMarketingInfo `json:"marketing"` +} + +type Cw20Coin struct { + Address string `json:"address"` + Amount uint64 `json:"amount"` +} + +type MinterResponse struct { + Minter string `json:"minter"` + Cap *uint64 `json:"cap,omitempty"` +} + +type InstantiateMarketingInfo struct { + Project string `json:"project"` + Description string `json:"description"` + Marketing string `json:"marketing"` + Logo Logo `json:"logo"` +} + +type Logo struct { + Url string `json:"url"` +} + +// astroport whitelist +type WhitelistInstantiateMsg struct { + Admins []string `json:"admins"` + Mutable bool `json:"mutable"` } From 02c62c6204d949eb6679c660aef4114a8c9dce4f Mon Sep 17 00:00:00 2001 From: bekauz Date: Wed, 21 Jun 2023 14:02:15 +0200 Subject: [PATCH 6/6] lper/astroport interchaintests cleanup; lp enter liquidity pool --- Cargo.lock | 91 +++++- contracts/lper/Cargo.toml | 2 + contracts/lper/src/contract.rs | 61 ++++- .../tests/interchaintest/ics_test.go | 258 ++++++++---------- 4 files changed, 259 insertions(+), 153 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6aeb428a..592a9da8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,6 +19,21 @@ version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" +[[package]] +name = "astroport" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcea351626899d205aab091c891fc878fc9b3c930585fd3ef6222de028d8a7a" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "cw-utils 0.15.1", + "cw20", + "itertools", + "uint", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -246,8 +261,8 @@ checksum = "127c7bb95853b8e828bdab97065c81cb5ddc20f7339180b61b2300565aaa99d1" dependencies = [ "anyhow", "cosmwasm-std", - "cw-storage-plus", - "cw-utils", + "cw-storage-plus 1.1.0", + "cw-utils 1.0.1", "derivative", "itertools", "k256", @@ -257,6 +272,17 @@ dependencies = [ "thiserror", ] +[[package]] +name = "cw-storage-plus" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6cf70ef7686e2da9ad7b067c5942cd3e88dd9453f7af42f54557f8af300fb0" +dependencies = [ + "cosmwasm-std", + "schemars", + "serde", +] + [[package]] name = "cw-storage-plus" version = "1.1.0" @@ -268,6 +294,21 @@ dependencies = [ "serde", ] +[[package]] +name = "cw-utils" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ae0b69fa7679de78825b4edeeec045066aa2b2c4b6e063d80042e565bb4da5c" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw2 0.15.1", + "schemars", + "semver", + "serde", + "thiserror", +] + [[package]] name = "cw-utils" version = "1.0.1" @@ -276,13 +317,26 @@ checksum = "c80e93d1deccb8588db03945016a292c3c631e6325d349ebb35d2db6f4f946f7" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw2", + "cw2 1.0.1", "schemars", "semver", "serde", "thiserror", ] +[[package]] +name = "cw2" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5abb8ecea72e09afff830252963cb60faf945ce6cef2c20a43814516082653da" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-storage-plus 0.15.1", + "schemars", + "serde", +] + [[package]] name = "cw2" version = "1.0.1" @@ -291,7 +345,20 @@ checksum = "8fb70cee2cf0b4a8ff7253e6bc6647107905e8eb37208f87d54f67810faa62f8" dependencies = [ "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus", + "cw-storage-plus 1.1.0", + "schemars", + "serde", +] + +[[package]] +name = "cw20" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6025276fb6e603e974c21f3e4606982cdc646080e8fba3198816605505e1d9a" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "cw-utils 0.15.1", "schemars", "serde", ] @@ -520,7 +587,7 @@ dependencies = [ "cosmos-sdk-proto 0.16.0", "cosmwasm-schema", "cosmwasm-std", - "cw-storage-plus", + "cw-storage-plus 1.1.0", "prost 0.11.9", "protobuf", "schemars", @@ -887,9 +954,9 @@ dependencies = [ "cosmwasm-schema", "cosmwasm-std", "cw-multi-test", - "cw-storage-plus", - "cw-utils", - "cw2", + "cw-storage-plus 1.1.0", + "cw-utils 1.0.1", + "cw2 1.0.1", "neutron-sdk", "prost 0.11.9", "prost-types", @@ -905,15 +972,17 @@ dependencies = [ name = "stride-lper" version = "1.0.0" dependencies = [ + "astroport", "base64 0.13.1", "bech32", "cosmos-sdk-proto 0.14.0", "cosmwasm-schema", "cosmwasm-std", "cw-multi-test", - "cw-storage-plus", - "cw-utils", - "cw2", + "cw-storage-plus 1.1.0", + "cw-utils 1.0.1", + "cw2 1.0.1", + "cw20", "neutron-sdk", "prost 0.11.9", "prost-types", diff --git a/contracts/lper/Cargo.toml b/contracts/lper/Cargo.toml index 9a61b662..750bbea4 100644 --- a/contracts/lper/Cargo.toml +++ b/contracts/lper/Cargo.toml @@ -38,6 +38,8 @@ base64 = { workspace = true } prost = { workspace = true } prost-types = { workspace = true } bech32 ={ workspace = true } +astroport = "2.8.0" +cw20 = { version = "0.15" } # dev-dependencies [dev-dependencies] diff --git a/contracts/lper/src/contract.rs b/contracts/lper/src/contract.rs index e566ba37..f43af048 100644 --- a/contracts/lper/src/contract.rs +++ b/contracts/lper/src/contract.rs @@ -1,10 +1,12 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{MessageInfo, Response, - StdResult, Addr, DepsMut, Env, Binary, Deps, to_binary, + StdResult, Addr, DepsMut, Env, Binary, Deps, to_binary, SubMsg, WasmMsg, CosmosMsg, Coin, Uint128, Reply, }; use cw2::set_contract_version; +use astroport::{pair::{ExecuteMsg::ProvideLiquidity, Cw20HookMsg}, asset::{Asset, AssetInfo}}; +use cw20::Cw20ReceiveMsg; use crate::{msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}, state::{HOLDER_ADDRESS, LP_POSITION}}; @@ -79,7 +81,38 @@ fn try_enter_lp_position( env: Env, info: MessageInfo, ) -> NeutronResult> { - Ok(Response::default()) + let pool_address = LP_POSITION.load(deps.storage)?; + + // get balances of uatom and statom + let balances: Vec = deps.querier.query_all_balances(env.contract.address)? + .into_iter() + .filter(|coin| coin.denom == "uatom" || coin.denom == "statom") + .collect(); + + // generate astroport Assets from balances + let assets: Vec = balances.clone().into_iter() + .map(|bal| Asset { + info: AssetInfo::NativeToken { + denom: bal.denom, + }, + amount: bal.amount, + }) + .collect(); + + let provide_liquidity_msg = ProvideLiquidity { + assets, + slippage_tolerance: None, + auto_stake: Some(true), + receiver: None, + }; + + Ok(Response::default().add_message( + CosmosMsg::Wasm(WasmMsg::Execute { + contract_addr: pool_address.addr, + msg: to_binary(&provide_liquidity_msg)?, + funds: balances, + }) + )) } @@ -88,7 +121,29 @@ fn try_withdraw( env: Env, info: MessageInfo, ) -> NeutronResult> { - Ok(Response::default()) + let pool_address = LP_POSITION.load(deps.storage)?; + // todo + let withdraw_liquidity_msg = Cw20HookMsg::WithdrawLiquidity { + assets: vec![ + + ], + }; + + let cw20_receive_msg = Cw20ReceiveMsg { + sender: env.contract.address.to_string(), + amount: Uint128::new(1), + msg: to_binary(&withdraw_liquidity_msg)?, + }; + + let msg = WasmMsg::Execute { + contract_addr: pool_address.addr, + msg: to_binary(&astroport::pair::ExecuteMsg::Receive(cw20_receive_msg))?, + funds: vec![], + }; + + Ok(Response::default().add_message( + CosmosMsg::Wasm(msg) + )) } diff --git a/stride-covenant/tests/interchaintest/ics_test.go b/stride-covenant/tests/interchaintest/ics_test.go index 7a4ce440..7e1af7ed 100644 --- a/stride-covenant/tests/interchaintest/ics_test.go +++ b/stride-covenant/tests/interchaintest/ics_test.go @@ -246,9 +246,6 @@ func TestICS(t *testing.T) { t.Run("stride covenant tests", func(t *testing.T) { const clockContractAddress = "clock_contract_address" const holderContractAddress = "holder_contract_address" - lpInfo := LpInfo{ - Addr: "test", - } var lperContractAddress string var depositorContractAddress string @@ -261,100 +258,12 @@ func TestICS(t *testing.T) { atom.Config().Denom)) neutronDstIbcDenom := neutronSrcDenomTrace.IBCDenom() - t.Run("instantiate lper contract", func(t *testing.T) { - codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_lper.wasm") - require.NoError(t, err, "failed to store neutron ICA contract") - - lpMsg := LPerInstantiateMsg{ - LpPosition: lpInfo, - ClockAddress: clockContractAddress, - HolderAddress: holderContractAddress, - } - - str, err := json.Marshal(lpMsg) - require.NoError(t, err, "Failed to marshall LPerInstantiateMsg") - - lperContractAddress, err = cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) - require.NoError(t, err, "failed to instantiate lper contract: ", err) - - print("\n LP contract instantiated with addr: ", lperContractAddress, "\n") - - t.Run("query instantiated clock", func(t *testing.T) { - var response ClockQueryResponse - err = cosmosNeutron.QueryContract(ctx, lperContractAddress, LPContractQuery{ - ClockAddress: ClockAddressQuery{}, - }, &response) - require.NoError(t, err, "failed to query clock address") - expectedAddrJson, _ := json.Marshal(clockContractAddress) - require.Equal(t, string(expectedAddrJson), response.Data) - }) - - t.Run("query lp position", func(t *testing.T) { - var response LpPositionQueryResponse - err := cosmosNeutron.QueryContract(ctx, lperContractAddress, LPPositionQuery{ - LpPosition: LpPositionQuery{}, - }, &response) - require.NoError(t, err, "failed to query lp position address") - require.Equal(t, lpInfo.Addr, response.Data.Addr) - }) - }) - - t.Run("instantiate depositor contract", func(t *testing.T) { - codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_depositor.wasm") - require.NoError(t, err, "failed to store neutron ICA contract") - - stAtomWeightedReceiver = WeightedReceiver{ - Amount: int64(10), - Address: lperContractAddress, - } - - atomWeightedReceiver = WeightedReceiver{ - Amount: int64(10), - Address: lperContractAddress, - } - - msg := DepositorInstantiateMsg{ - StAtomReceiver: stAtomWeightedReceiver, - AtomReceiver: atomWeightedReceiver, - ClockAddress: clockContractAddress, - GaiaNeutronIBCTransferChannelId: gaiaNeutronIBCChannel.ChannelID, - } - - str, err := json.Marshal(msg) - require.NoError(t, err, "Failed to marshall DepositorInstantiateMsg") - - depositorContractAddress, err = cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) - require.NoError(t, err, "failed to instantiate depositor contract: ", err) - - print("\n depositor contract instantiated with addr: ", depositorContractAddress, "\n") - - t.Run("query instantiated clock", func(t *testing.T) { - var response ClockQueryResponse - err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, DepositorContractQuery{ - ClockAddress: ClockAddressQuery{}, - }, &response) - require.NoError(t, err, "failed to query clock address") - expectedAddrJson, _ := json.Marshal(clockContractAddress) - require.Equal(t, string(expectedAddrJson), response.Data) - }) - - t.Run("query instantiated weighted receivers", func(t *testing.T) { - var stAtomReceiver WeightedReceiverResponse - err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, StAtomWeightedReceiverQuery{ - StAtomReceiver: StAtomReceiverQuery{}, - }, &stAtomReceiver) - require.NoError(t, err, "failed to query stAtom weighted receiver") - require.Equal(t, stAtomWeightedReceiver, stAtomReceiver.Data) - - var atomReceiver WeightedReceiverResponse - err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, AtomWeightedReceiverQuery{ - AtomReceiver: AtomReceiverQuery{}, - }, &atomReceiver) - require.NoError(t, err, "failed to query atom weighted receiver") - require.Equal(t, int64(10), atomReceiver.Data.Amount) - require.Equal(t, lperContractAddress, atomReceiver.Data.Address) - }) - }) + var coinRegistryAddress string + var factoryAddress string + var stableswapAddress string + var tokenAddress string + var whitelistAddress string + _, _ = tokenAddress, whitelistAddress t.Run("deploy astroport contracts", func(t *testing.T) { stablePairCodeIdStr, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/astroport_pair_stable.wasm") @@ -377,10 +286,6 @@ func TestICS(t *testing.T) { tokenCodeId, err := strconv.ParseUint(tokenCodeIdStr, 10, 64) require.NoError(t, err, "failed to parse codeId into uint64") - var coinRegistryAddress string - var factoryAddress string - var stableswapAddress string - _ = stableswapAddress t.Run("astroport token", func(t *testing.T) { // cap := uint64(1) @@ -405,9 +310,8 @@ func TestICS(t *testing.T) { str, err := json.Marshal(msg) require.NoError(t, err, "Failed to marshall NativeTokenInstantiateMsg") - tokenAddress, err := cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, tokenCodeIdStr, string(str), true) + tokenAddress, err = cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, tokenCodeIdStr, string(str), true) require.NoError(t, err, "Failed to instantiate Native Token") - print("\nNative token: ", tokenAddress, "\n") err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) require.NoError(t, err, "failed to wait for blocks") }) @@ -424,10 +328,10 @@ func TestICS(t *testing.T) { str, err := json.Marshal(msg) require.NoError(t, err, "Failed to marshall WhitelistInstantiateMsg") - whitelistAddress, err := cosmosNeutron.InstantiateContract( + whitelistAddress, err = cosmosNeutron.InstantiateContract( ctx, neutronUser.KeyName, whitelistCodeIdStr, string(str), true) require.NoError(t, err, "Failed to instantiate Whitelist") - print("\nWhitelist: ", whitelistAddress, "\n") + err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) require.NoError(t, err, "failed to wait for blocks") }) @@ -447,14 +351,13 @@ func TestICS(t *testing.T) { ctx, neutronUser.KeyName, coinRegistryCodeId, string(str), true) require.NoError(t, err, "Failed to instantiate NativeCoinRegistry") coinRegistryAddress = nativeCoinRegistryAddress - print("\nNativeCoinRegistry: ", nativeCoinRegistryAddress, "\n") err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) require.NoError(t, err, "failed to wait for blocks") }) t.Run("add coins to registry", func(t *testing.T) { // no clue how to marshall go struct fields into rust Vec<(String, u8)> - // so passing a string + // so passing as a string for now addMessage := `{"add":{"native_coins":[["statom",10],["uatom",10]]}}` addCmd := []string{"neutrond", "tx", "wasm", "execute", coinRegistryAddress, @@ -510,7 +413,6 @@ func TestICS(t *testing.T) { ctx, neutronUser.KeyName, factoryCodeIdStr, string(str), true) require.NoError(t, err, "Failed to instantiate Factory") factoryAddress = factoryAddr - print("\nFactory: ", factoryAddress, "\n") err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) require.NoError(t, err, "failed to wait for blocks") @@ -525,16 +427,18 @@ func TestICS(t *testing.T) { binaryData, err := json.Marshal(initParams) require.NoError(t, err, "error encoding stable pool params to binary") + stAtom := NativeToken{ + Denom: "statom", + } + nativeAtom := NativeToken{ + Denom: atom.Config().Denom, + } assetInfos := []AssetInfo{ { - NativeToken: &NativeToken{ - Denom: "statom", - }, + NativeToken: &stAtom, }, { - NativeToken: &NativeToken{ - Denom: atom.Config().Denom, - }, + NativeToken: &nativeAtom, }, } @@ -547,45 +451,121 @@ func TestICS(t *testing.T) { str, err := json.Marshal(msg) require.NoError(t, err, "Failed to marshall DepositorInstantiateMsg") - print("\n stableswap init msg: ", string(str), "\n") - - // stableswapAddr, err := cosmosNeutron.InstantiateContract( - // ctx, neutronUser.KeyName, stablePairCodeIdStr, string(str), true, - // ) - // require.NoError(t, err, "Failed to instantiate Factory") - // stableswapAddress = stableswapAddr - // print("\nstableswap: ", stableswapAddress, "\n") - // err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) - // require.NoError(t, err, "failed to wait for blocks") - - cmd = []string{"neutrond", "tx", "wasm", "instantiate", - stablePairCodeIdStr, - string(str), - "--from", neutronUser.KeyName, + stableswapAddr, err := cosmosNeutron.InstantiateContract( + ctx, neutronUser.KeyName, stablePairCodeIdStr, string(str), true, "--label", "stableswap", - "--no-admin", "--gas-prices", "0.0untrn", "--gas-adjustment", `1.5`, "--output", "json", - "--home", "/var/cosmos-chain/neutron-2", "--node", neutron.GetRPCAddress(), "--home", neutron.HomeDir(), "--chain-id", neutron.Config().ChainID, - "--from", neutronUser.KeyName, "--gas", "auto", "--keyring-backend", keyring.BackendTest, "-y", - } - // print(strings.Join(cmd, " ")) - stdout, _, err := cosmosNeutron.Exec(ctx, cmd, nil) - require.NoError(t, err) + ) + require.NoError(t, err, "Failed to instantiate stableswap") + stableswapAddress = stableswapAddr + + err = testutil.WaitForBlocks(ctx, 2, atom, neutron, stride) + require.NoError(t, err, "failed to wait for blocks") + }) + + }) + + t.Run("instantiate lper contract", func(t *testing.T) { + codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_lper.wasm") + require.NoError(t, err, "failed to store neutron ICA contract") + lpInfo := LpInfo{ + Addr: stableswapAddress, + } + + lpMsg := LPerInstantiateMsg{ + LpPosition: lpInfo, + ClockAddress: clockContractAddress, + HolderAddress: holderContractAddress, + } + + str, err := json.Marshal(lpMsg) + require.NoError(t, err, "Failed to marshall LPerInstantiateMsg") + + lperContractAddress, err = cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) + require.NoError(t, err, "failed to instantiate lper contract: ", err) + + t.Run("query instantiated clock", func(t *testing.T) { + var response ClockQueryResponse + err = cosmosNeutron.QueryContract(ctx, lperContractAddress, LPContractQuery{ + ClockAddress: ClockAddressQuery{}, + }, &response) + require.NoError(t, err, "failed to query clock address") + expectedAddrJson, _ := json.Marshal(clockContractAddress) + require.Equal(t, string(expectedAddrJson), response.Data) + }) + + t.Run("query lp position", func(t *testing.T) { + var response LpPositionQueryResponse + err := cosmosNeutron.QueryContract(ctx, lperContractAddress, LPPositionQuery{ + LpPosition: LpPositionQuery{}, + }, &response) + require.NoError(t, err, "failed to query lp position address") + require.Equal(t, stableswapAddress, response.Data.Addr) + }) + }) + + t.Run("instantiate depositor contract", func(t *testing.T) { + codeId, err := cosmosNeutron.StoreContract(ctx, neutronUser.KeyName, "wasms/stride_depositor.wasm") + require.NoError(t, err, "failed to store neutron ICA contract") + + stAtomWeightedReceiver = WeightedReceiver{ + Amount: int64(10), + Address: lperContractAddress, + } + + atomWeightedReceiver = WeightedReceiver{ + Amount: int64(10), + Address: lperContractAddress, + } + + msg := DepositorInstantiateMsg{ + StAtomReceiver: stAtomWeightedReceiver, + AtomReceiver: atomWeightedReceiver, + ClockAddress: clockContractAddress, + GaiaNeutronIBCTransferChannelId: gaiaNeutronIBCChannel.ChannelID, + } + + str, err := json.Marshal(msg) + require.NoError(t, err, "Failed to marshall DepositorInstantiateMsg") + + depositorContractAddress, err = cosmosNeutron.InstantiateContract(ctx, neutronUser.KeyName, codeId, string(str), true) + require.NoError(t, err, "failed to instantiate depositor contract: ", err) - stableswapAddress = string(stdout) - print("\nstdout: ", string(stdout)) - // print("\nstderr: ", string(stderr)) + t.Run("query instantiated clock", func(t *testing.T) { + var response ClockQueryResponse + err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, DepositorContractQuery{ + ClockAddress: ClockAddressQuery{}, + }, &response) + require.NoError(t, err, "failed to query clock address") + expectedAddrJson, _ := json.Marshal(clockContractAddress) + require.Equal(t, string(expectedAddrJson), response.Data) }) + t.Run("query instantiated weighted receivers", func(t *testing.T) { + var stAtomReceiver WeightedReceiverResponse + err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, StAtomWeightedReceiverQuery{ + StAtomReceiver: StAtomReceiverQuery{}, + }, &stAtomReceiver) + require.NoError(t, err, "failed to query stAtom weighted receiver") + require.Equal(t, stAtomWeightedReceiver, stAtomReceiver.Data) + + var atomReceiver WeightedReceiverResponse + err = cosmosNeutron.QueryContract(ctx, depositorContractAddress, AtomWeightedReceiverQuery{ + AtomReceiver: AtomReceiverQuery{}, + }, &atomReceiver) + require.NoError(t, err, "failed to query atom weighted receiver") + require.Equal(t, int64(10), atomReceiver.Data.Amount) + require.Equal(t, lperContractAddress, atomReceiver.Data.Address) + }) }) var addrResponse QueryResponse