diff --git a/terra/Cargo.lock b/terra/Cargo.lock index 2f9467e9c5..2c99c41832 100644 --- a/terra/Cargo.lock +++ b/terra/Cargo.lock @@ -128,6 +128,16 @@ dependencies = [ "syn", ] +[[package]] +name = "cosmwasm-schema" +version = "0.16.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b021bdefb9d855c5135e83046e5407a9fddba869e42e78b6036b53a606dc8c10" +dependencies = [ + "schemars", + "serde_json", +] + [[package]] name = "cosmwasm-schema" version = "1.0.0-beta4" @@ -454,7 +464,7 @@ dependencies = [ name = "cw721" version = "0.10.1" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 1.0.0-beta4", "cosmwasm-std", "cw0", "schemars", @@ -465,7 +475,7 @@ dependencies = [ name = "cw721-base" version = "0.10.1" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 1.0.0-beta4", "cosmwasm-std", "cw-storage-plus", "cw0", @@ -480,7 +490,7 @@ dependencies = [ name = "cw721-wrapped" version = "0.10.1" dependencies = [ - "cosmwasm-schema", + "cosmwasm-schema 1.0.0-beta4", "cosmwasm-std", "cosmwasm-storage", "cw2", @@ -1447,6 +1457,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "terra-cosmwasm" +version = "2.2.0" +dependencies = [ + "cosmwasm-schema 0.16.7", + "cosmwasm-std", + "schemars", + "serde", +] + [[package]] name = "terra-cosmwasm" version = "2.2.0" @@ -1469,7 +1489,7 @@ dependencies = [ "cw20", "schemars", "serde", - "terra-cosmwasm", + "terra-cosmwasm 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1510,7 +1530,7 @@ dependencies = [ "serde", "serde_json", "sha3", - "terra-cosmwasm", + "terra-cosmwasm 2.2.0", "terraswap", "thiserror", "wormhole-bridge-terra", diff --git a/terra/Cargo.toml b/terra/Cargo.toml index bb456d9e68..5fc7301bf9 100644 --- a/terra/Cargo.toml +++ b/terra/Cargo.toml @@ -6,6 +6,7 @@ members = [ "contracts/nft-bridge", "contracts/cw721-wrapped", "packages/cw721", + "packages/terra-cosmwasm-2.2.0", "contracts/cw721-base", "contracts/mock-bridge-integration", ] diff --git a/terra/contracts/token-bridge/Cargo.toml b/terra/contracts/token-bridge/Cargo.toml index b311fd3b76..cceb4ae31a 100644 --- a/terra/contracts/token-bridge/Cargo.toml +++ b/terra/contracts/token-bridge/Cargo.toml @@ -22,7 +22,7 @@ cw20 = "0.8.0" cw20-base = { version = "0.8.0", features = ["library"] } cw20-wrapped = { path = "../cw20-wrapped", features = ["library"] } terraswap = "2.4.0" -terra-cosmwasm = "2.2.0" +terra-cosmwasm = { path = "../../packages/terra-cosmwasm-2.2.0" } wormhole-bridge-terra = { path = "../wormhole", features = ["library"] } thiserror = { version = "1.0.20" } k256 = { version = "0.9.4", default-features = false, features = ["ecdsa"] } diff --git a/terra/packages/terra-cosmwasm-2.2.0/Cargo.lock b/terra/packages/terra-cosmwasm-2.2.0/Cargo.lock new file mode 100644 index 0000000000..c2e305e287 --- /dev/null +++ b/terra/packages/terra-cosmwasm-2.2.0/Cargo.lock @@ -0,0 +1,557 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[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 = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + +[[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.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c32f031ea41b4291d695026c023b95d59db2d8a2c7640800ed56bc8f510f22" + +[[package]] +name = "cosmwasm-crypto" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa1715a9b71c7c31385a3f021dee2fd0a17b82043ab937467e103aa25043d2e" +dependencies = [ + "digest", + "ed25519-zebra", + "k256", + "rand_core 0.5.1", + "thiserror", +] + +[[package]] +name = "cosmwasm-derive" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f6e6dff07965015c4fcdf477c4becde738a2bfb40cf6239bdcea9335016c5a2" +dependencies = [ + "syn", +] + +[[package]] +name = "cosmwasm-schema" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac9ba1eea088e7f1ec4a7679c43adcb51e80cbc2af6a6d83d1bb652b7adaf6dc" +dependencies = [ + "schemars", + "serde_json", +] + +[[package]] +name = "cosmwasm-std" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92bdeee0ebba164ebbef9380522cc50f889db38acc1f1210f6b55ee2244b8c59" +dependencies = [ + "base64", + "cosmwasm-crypto", + "cosmwasm-derive", + "schemars", + "serde", + "serde-json-wasm", + "thiserror", + "uint", +] + +[[package]] +name = "cpufeatures" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66c99696f6c9dd7f35d486b9d04d7e6e202aa3e8c40d553f2fdf5e7e0c6a71ef" +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.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b32a398eb1ccfbe7e4f452bc749c44d38dd732e9a253f19da224c416f00ee7f4" +dependencies = [ + "generic-array", + "rand_core 0.6.3", + "subtle", + "zeroize", +] + +[[package]] +name = "crypto-mac" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1d1a86f49236c215f271d40892d5fc950490551400b02ef360692c29815c714" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "der" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49f215f706081a44cb702c71c39a52c05da637822e9c1645a50b7202689e982d" +dependencies = [ + "const-oid", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[package]] +name = "dyn-clone" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2626afccd7561a06cf1367e2950c4718ea04565e20fb5029b6c7d8ad09abcf" + +[[package]] +name = "ecdsa" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "713c32426287891008edb98f8b5c6abb2130aa043c93a818728fcda78606f274" +dependencies = [ + "der", + "elliptic-curve", + "hmac", + "signature", +] + +[[package]] +name = "ed25519-zebra" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a128b76af6dd4b427e34a6fd43dc78dbfe73672ec41ff615a2414c1a0ad0409" +dependencies = [ + "curve25519-dalek", + "hex", + "rand_core 0.5.1", + "serde", + "sha2", + "thiserror", +] + +[[package]] +name = "elliptic-curve" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "069397e10739989e400628cbc0556a817a8a64119d7a2315767f4456e1332c23" +dependencies = [ + "crypto-bigint", + "ff", + "generic-array", + "group", + "pkcs8", + "rand_core 0.6.3", + "subtle", + "zeroize", +] + +[[package]] +name = "ff" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63eec06c61e487eecf0f7e6e6372e596a81922c28d33e645d6983ca6493a1af0" +dependencies = [ + "rand_core 0.6.3", + "subtle", +] + +[[package]] +name = "generic-array" +version = "0.14.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + +[[package]] +name = "group" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c363a5301b8f153d80747126a04b3c82073b9fe3130571a9d170cacdeaf7912" +dependencies = [ + "ff", + "rand_core 0.6.3", + "subtle", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "hmac" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a2a2320eb7ec0ebe8da8f744d7812d9fc4cb4d09344ac01898dbcb6a20ae69b" +dependencies = [ + "crypto-mac", + "digest", +] + +[[package]] +name = "itoa" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" + +[[package]] +name = "k256" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "903ae2481bcdfdb7b68e0a9baa4b7c9aff600b9ae2e8e5bb5833b8c91ab851ea" +dependencies = [ + "cfg-if", + "ecdsa", + "elliptic-curve", + "sha2", +] + +[[package]] +name = "libc" +version = "0.2.98" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320cfe77175da3a483efed4bc0adc1968ca050b098ce4f2f1c13a56626128790" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "pkcs8" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbee84ed13e44dd82689fa18348a49934fa79cc774a344c42fc9b301c71b140a" +dependencies = [ + "der", + "spki", +] + +[[package]] +name = "proc-macro2" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7ed8b8c7b886ea3ed7dde405212185f423ab44682667c8c6dd14aa1d9f6612" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom 0.2.3", +] + +[[package]] +name = "ryu" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" + +[[package]] +name = "schemars" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc6ab463ae35acccb5cba66c0084c985257b797d288b6050cc2f6ac1b266cb78" +dependencies = [ + "dyn-clone", + "schemars_derive", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "902fdfbcf871ae8f653bddf4b2c05905ddaabc08f69d32a915787e3be0d31356" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn", +] + +[[package]] +name = "serde" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5317f7588f0a5078ee60ef675ef96735a1442132dc645eb1d12c018620ed8cd3" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde-json-wasm" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50eef3672ec8fa45f3457fd423ba131117786784a895548021976117c1ded449" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_derive" +version = "1.0.114" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a0be94b04690fbaed37cddffc5c134bf537c8e3329d53e982fe04c374978f8e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_derive_internals" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.56" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3433e879a558dde8b5e8feb2a04899cf34fdde1fafb894687e52105fc1162ac3" +dependencies = [ + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b362ae5752fd2137731f9fa25fd4d9058af34666ca1966fb969119cc35719f12" +dependencies = [ + "block-buffer", + "cfg-if", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "signature" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c19772be3c4dd2ceaacf03cb41d5885f2a02c4d8804884918e3a258480803335" +dependencies = [ + "digest", + "rand_core 0.6.3", +] + +[[package]] +name = "spki" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "987637c5ae6b3121aba9d513f869bd2bff11c4cc086c22473befd6649c0bd521" +dependencies = [ + "der", +] + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1873d832550d4588c3dbc20f01361ab00bfe741048f71e3fecf145a7cc18b29c" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "terra-cosmwasm" +version = "2.2.0" +dependencies = [ + "cosmwasm-schema", + "cosmwasm-std", + "schemars", + "serde", +] + +[[package]] +name = "thiserror" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93119e4feac1cbe6c798c34d3a53ea0026b0b1de6a120deef895137c0529bfe2" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "060d69a0afe7796bf42e9e2ff91f5ee691fb15c53d38b4b62a9a53eb23164745" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "typenum" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f6906492a7cd215bfa4cf595b600146ccfac0c79bcbd1f3000162af5e8b06" + +[[package]] +name = "uint" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6470ab50f482bde894a037a57064480a246dbfdd5960bd65a44824693f08da5f" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-xid" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" + +[[package]] +name = "version_check" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[package]] +name = "zeroize" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "377db0846015f7ae377174787dd452e1c5f5a9050bc6f954911d01f116daa0cd" diff --git a/terra/packages/terra-cosmwasm-2.2.0/Cargo.toml b/terra/packages/terra-cosmwasm-2.2.0/Cargo.toml new file mode 100644 index 0000000000..b1541484b0 --- /dev/null +++ b/terra/packages/terra-cosmwasm-2.2.0/Cargo.toml @@ -0,0 +1,36 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +edition = "2018" +name = "terra-cosmwasm" +version = "2.2.0" +authors = ["Yun Yeo ", "Ethan Frey "] +description = "Bindings for CosmWasm contracts to call into custom modules of Terra Core" +readme = "README.md" +license = "Apache-2.0" +repository = "https://github.com/terra-project/terra-cosmwasm" +[dependencies.cosmwasm-std] +version = "0.16.0" + +[dependencies.schemars] +version = "0.8.1" + +[dependencies.serde] +version = "1.0.103" +features = ["derive"] +default-features = false +[dev-dependencies.cosmwasm-schema] +version = "0.16.0" + +[features] +backtraces = ["cosmwasm-std/backtraces"] diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/lib.rs b/terra/packages/terra-cosmwasm-2.2.0/src/lib.rs new file mode 100644 index 0000000000..a6f4fa5f1c --- /dev/null +++ b/terra/packages/terra-cosmwasm-2.2.0/src/lib.rs @@ -0,0 +1,17 @@ +mod msg; +mod querier; +mod query; +mod route; + +pub use msg::{create_swap_msg, create_swap_send_msg, TerraMsg, TerraMsgWrapper}; +pub use querier::TerraQuerier; +pub use query::{ + ContractInfoResponse, ExchangeRateItem, ExchangeRatesResponse, SwapResponse, TaxCapResponse, + TaxRateResponse, TerraQuery, TerraQueryWrapper, +}; +pub use route::TerraRoute; + +// This export is added to all contracts that import this package, signifying that they require +// "terra" support on the chain they run on. +#[no_mangle] +extern "C" fn requires_terra() {} diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/msg.rs b/terra/packages/terra-cosmwasm-2.2.0/src/msg.rs new file mode 100644 index 0000000000..06fe27dace --- /dev/null +++ b/terra/packages/terra-cosmwasm-2.2.0/src/msg.rs @@ -0,0 +1,63 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +use crate::route::TerraRoute; +use cosmwasm_std::{Coin, CosmosMsg}; + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +/// TerraMsgWrapper is an override of CosmosMsg::Custom to show this works and can be extended in the contract +pub struct TerraMsgWrapper { + pub route: TerraRoute, + pub msg_data: TerraMsg, +} + +// this is a helper to be able to return these as CosmosMsg easier +impl From for CosmosMsg { + fn from(original: TerraMsgWrapper) -> Self { + CosmosMsg::Custom(original) + } +} + +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum TerraMsg { + Swap { + offer_coin: Coin, + ask_denom: String, + }, + SwapSend { + to_address: String, + offer_coin: Coin, + ask_denom: String, + }, +} + +// create_swap_msg returns wrapped swap msg +pub fn create_swap_msg(offer_coin: Coin, ask_denom: String) -> CosmosMsg { + TerraMsgWrapper { + route: TerraRoute::Market, + msg_data: TerraMsg::Swap { + offer_coin, + ask_denom, + }, + } + .into() +} + +// create_swap_send_msg returns wrapped swap send msg +pub fn create_swap_send_msg( + to_address: String, + offer_coin: Coin, + ask_denom: String, +) -> CosmosMsg { + TerraMsgWrapper { + route: TerraRoute::Market, + msg_data: TerraMsg::SwapSend { + to_address, + offer_coin, + ask_denom, + }, + } + .into() +} diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/querier.rs b/terra/packages/terra-cosmwasm-2.2.0/src/querier.rs new file mode 100644 index 0000000000..19dac14b47 --- /dev/null +++ b/terra/packages/terra-cosmwasm-2.2.0/src/querier.rs @@ -0,0 +1,89 @@ +use cosmwasm_std::{Coin, QuerierWrapper, StdResult}; + +use crate::query::{ + ContractInfoResponse, ExchangeRatesResponse, SwapResponse, TaxCapResponse, TaxRateResponse, + TerraQuery, TerraQueryWrapper, +}; +use crate::route::TerraRoute; + +/// This is a helper wrapper to easily use our custom queries +pub struct TerraQuerier<'a> { + querier: &'a QuerierWrapper<'a>, +} + +impl<'a> TerraQuerier<'a> { + pub fn new(querier: &'a QuerierWrapper<'a>) -> Self { + TerraQuerier { querier } + } + + pub fn query_swap>( + &self, + offer_coin: Coin, + ask_denom: T, + ) -> StdResult { + let request = TerraQueryWrapper { + route: TerraRoute::Market, + query_data: TerraQuery::Swap { + offer_coin, + ask_denom: ask_denom.into(), + }, + } + .into(); + + self.querier.custom_query(&request) + } + + pub fn query_tax_cap>(&self, denom: T) -> StdResult { + let request = TerraQueryWrapper { + route: TerraRoute::Treasury, + query_data: TerraQuery::TaxCap { + denom: denom.into(), + }, + } + .into(); + + self.querier.custom_query(&request) + } + + pub fn query_tax_rate(&self) -> StdResult { + let request = TerraQueryWrapper { + route: TerraRoute::Treasury, + query_data: TerraQuery::TaxRate {}, + } + .into(); + + self.querier.custom_query(&request) + } + + pub fn query_exchange_rates>( + &self, + base_denom: T, + quote_denoms: Vec, + ) -> StdResult { + let request = TerraQueryWrapper { + route: TerraRoute::Oracle, + query_data: TerraQuery::ExchangeRates { + base_denom: base_denom.into(), + quote_denoms: quote_denoms.into_iter().map(|x| x.into()).collect(), + }, + } + .into(); + + self.querier.custom_query(&request) + } + + pub fn query_contract_info>( + &self, + contract_address: T, + ) -> StdResult { + let request = TerraQueryWrapper { + route: TerraRoute::Wasm, + query_data: TerraQuery::ContractInfo { + contract_address: contract_address.into(), + }, + } + .into(); + + self.querier.custom_query(&request) + } +} diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/query.rs b/terra/packages/terra-cosmwasm-2.2.0/src/query.rs new file mode 100644 index 0000000000..07fbe3fc53 --- /dev/null +++ b/terra/packages/terra-cosmwasm-2.2.0/src/query.rs @@ -0,0 +1,78 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +use crate::route::TerraRoute; +use cosmwasm_std::{Coin, CustomQuery, Decimal, Uint128}; + +/// TerraQueryWrapper is an override of QueryRequest::Custom to access Terra-specific modules +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub struct TerraQueryWrapper { + pub route: TerraRoute, + pub query_data: TerraQuery, +} + +// implement custom query +impl CustomQuery for TerraQueryWrapper {} + +/// TerraQuery is defines available query datas +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum TerraQuery { + Swap { + offer_coin: Coin, + ask_denom: String, + }, + TaxRate {}, + TaxCap { + denom: String, + }, + ExchangeRates { + base_denom: String, + quote_denoms: Vec, + }, + ContractInfo { + contract_address: String, + }, +} + +/// SwapResponse is data format returned from SwapRequest::Simulate query +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct SwapResponse { + pub receive: Coin, +} + +/// TaxRateResponse is data format returned from TreasuryRequest::TaxRate query +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct TaxRateResponse { + pub rate: Decimal, +} + +/// TaxCapResponse is data format returned from TreasuryRequest::TaxCap query +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct TaxCapResponse { + pub cap: Uint128, +} + +/// ExchangeRateItem is data format returned from OracleRequest::ExchangeRates query +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct ExchangeRateItem { + pub quote_denom: String, + pub exchange_rate: Decimal, +} + +/// ExchangeRatesResponse is data format returned from OracleRequest::ExchangeRates query +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct ExchangeRatesResponse { + pub base_denom: String, + pub exchange_rates: Vec, +} + +/// ContractInfoResponse is data format returned from WasmRequest::ContractInfo query +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +pub struct ContractInfoResponse { + pub address: String, + pub creator: String, + pub code_id: u64, + pub admin: Option, +} diff --git a/terra/packages/terra-cosmwasm-2.2.0/src/route.rs b/terra/packages/terra-cosmwasm-2.2.0/src/route.rs new file mode 100644 index 0000000000..164fa54df0 --- /dev/null +++ b/terra/packages/terra-cosmwasm-2.2.0/src/route.rs @@ -0,0 +1,12 @@ +use schemars::JsonSchema; +use serde::{Deserialize, Serialize}; + +/// TerraRoute is enum type to represent terra query route path +#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] +#[serde(rename_all = "snake_case")] +pub enum TerraRoute { + Market, + Treasury, + Oracle, + Wasm, +}