From 0c4a94955ec2a5e40f165d38e20513d60b616a63 Mon Sep 17 00:00:00 2001 From: Jake Hartnell Date: Mon, 31 Jan 2022 19:18:11 -0800 Subject: [PATCH] rm stake_cw20_gov --- Cargo.lock | 21 +- Cargo.toml | 4 - README.md | 1 - contracts/cw3-dao/Cargo.toml | 2 +- contracts/cw3-dao/src/contract.rs | 4 +- contracts/cw3-dao/src/helpers.rs | 7 +- contracts/cw3-dao/src/tests.rs | 8 +- contracts/stake-cw20-gov/.cargo/config | 6 - contracts/stake-cw20-gov/Cargo.lock | 609 ------------------ contracts/stake-cw20-gov/Cargo.toml | 32 - contracts/stake-cw20-gov/NOTICE | 14 - contracts/stake-cw20-gov/README.md | 24 - contracts/stake-cw20-gov/examples/schema.rs | 28 - contracts/stake-cw20-gov/helpers.ts | 306 --------- .../schema/all_accounts_response.json | 16 - .../schema/all_allowances_response.json | 99 --- .../schema/allowance_response.json | 81 --- .../schema/balance_response.json | 19 - .../stake-cw20-gov/schema/execute_msg.json | 168 ----- .../schema/instantiate_msg.json | 192 ------ .../stake-cw20-gov/schema/query_msg.json | 141 ---- .../schema/token_info_response.json | 33 - .../voting_power_at_height_response.json | 25 - contracts/stake-cw20-gov/src/contract.rs | 486 -------------- contracts/stake-cw20-gov/src/lib.rs | 3 - contracts/stake-cw20-gov/src/msg.rs | 67 -- contracts/stake-cw20-gov/src/state.rs | 12 - contracts/stake-cw20/Cargo.toml | 6 +- scripts/deploy_local.sh | 4 +- 29 files changed, 16 insertions(+), 2402 deletions(-) delete mode 100644 contracts/stake-cw20-gov/.cargo/config delete mode 100644 contracts/stake-cw20-gov/Cargo.lock delete mode 100644 contracts/stake-cw20-gov/Cargo.toml delete mode 100644 contracts/stake-cw20-gov/NOTICE delete mode 100644 contracts/stake-cw20-gov/README.md delete mode 100644 contracts/stake-cw20-gov/examples/schema.rs delete mode 100644 contracts/stake-cw20-gov/helpers.ts delete mode 100644 contracts/stake-cw20-gov/schema/all_accounts_response.json delete mode 100644 contracts/stake-cw20-gov/schema/all_allowances_response.json delete mode 100644 contracts/stake-cw20-gov/schema/allowance_response.json delete mode 100644 contracts/stake-cw20-gov/schema/balance_response.json delete mode 100644 contracts/stake-cw20-gov/schema/execute_msg.json delete mode 100644 contracts/stake-cw20-gov/schema/instantiate_msg.json delete mode 100644 contracts/stake-cw20-gov/schema/query_msg.json delete mode 100644 contracts/stake-cw20-gov/schema/token_info_response.json delete mode 100644 contracts/stake-cw20-gov/schema/voting_power_at_height_response.json delete mode 100644 contracts/stake-cw20-gov/src/contract.rs delete mode 100644 contracts/stake-cw20-gov/src/lib.rs delete mode 100644 contracts/stake-cw20-gov/src/msg.rs delete mode 100644 contracts/stake-cw20-gov/src/state.rs diff --git a/Cargo.lock b/Cargo.lock index 8aa3a6cc3..30bc8a28d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -296,7 +296,7 @@ dependencies = [ "cw3", "schemars", "serde", - "stake-cw20-gov", + "stake-cw20", "thiserror", ] @@ -762,25 +762,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "stake-cw20-gov" -version = "0.2.5" -dependencies = [ - "anyhow", - "cosmwasm-schema", - "cosmwasm-std", - "cw-multi-test", - "cw-storage-plus", - "cw-utils", - "cw2", - "cw20", - "cw20-base", - "schemars", - "serde", - "stake-cw20", - "thiserror", -] - [[package]] name = "static_assertions" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index 97f88281d..41fb9414e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,10 +13,6 @@ incremental = false codegen-units = 1 incremental = false -[profile.release.package.stake-cw20-gov] -codegen-units = 1 -incremental = false - [profile.release.package.cw-distribution] codegen-units = 1 incremental = false diff --git a/README.md b/README.md index c2a4851fd..ce5453b16 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,6 @@ | [cw3-multisig](contracts/cw3-multisig) | A multisig contract. | | [cw4-registry](contracts/cw4-registry) | A contract for indexing multisig group members. | | [stake-cw20](contracts/stake-cw20) | A cw20 staking contract. | -| [stake-cw20-gov](contracts/stake-cw20-gov) | A cw20 staking contract, with vote delegation. | NOTE: _These contracts have yet to be audited. Please see the [disclaimer](#Disclaimer)._ diff --git a/contracts/cw3-dao/Cargo.toml b/contracts/cw3-dao/Cargo.toml index 64ef4ad73..da22795c9 100644 --- a/contracts/cw3-dao/Cargo.toml +++ b/contracts/cw3-dao/Cargo.toml @@ -21,7 +21,7 @@ cw2 = { version = "0.11" } cw3 = { version = "0.11" } cw20 = "0.11" cw20-base = { version = "0.11", features = ["library"] } -stake-cw20-gov = { path = "../stake-cw20-gov" } +stake-cw20 = { path = "../stake-cw20" } cw-storage-plus = { version = "0.11" } cosmwasm-std = { version = "1.0.0-beta" } schemars = "0.8.8" diff --git a/contracts/cw3-dao/src/contract.rs b/contracts/cw3-dao/src/contract.rs index d048c0f1c..c68dc7f1e 100644 --- a/contracts/cw3-dao/src/contract.rs +++ b/contracts/cw3-dao/src/contract.rs @@ -139,7 +139,7 @@ pub fn instantiate( funds: vec![], admin: Some(env.contract.address.to_string()), label, - msg: to_binary(&stake_cw20_gov::msg::InstantiateMsg { + msg: to_binary(&stake_cw20::msg::InstantiateMsg { admin: env.contract.address, unstaking_duration, token_address: cw20_addr.addr(), @@ -739,7 +739,7 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result Std let staking_contract = STAKING_CONTRACT.load(deps.storage)?; // Get voting power at height - let balance: VotingPowerAtHeightResponse = deps.querier.query_wasm_smart( + let balance: StakedBalanceAtHeightResponse = deps.querier.query_wasm_smart( staking_contract, &StakingContractQueryMsg::StakedBalanceAtHeight { address: address.to_string(), diff --git a/contracts/cw3-dao/src/tests.rs b/contracts/cw3-dao/src/tests.rs index 16a2b49f5..d0133db65 100644 --- a/contracts/cw3-dao/src/tests.rs +++ b/contracts/cw3-dao/src/tests.rs @@ -21,7 +21,7 @@ use cw20::{ use cw3::{Status, Vote}; use cw_multi_test::{next_block, App, BankSudo, Contract, ContractWrapper, Executor, SudoMsg}; use cw_utils::{Duration, Expiration}; -use stake_cw20_gov::msg::ReceiveMsg; +use stake_cw20::msg::ReceiveMsg; use std::borrow::BorrowMut; const OWNER: &str = "admin0001"; @@ -55,9 +55,9 @@ pub fn contract_cw20_gov() -> Box> { pub fn contract_staking() -> Box> { let contract = ContractWrapper::new( - stake_cw20_gov::contract::execute, - stake_cw20_gov::contract::instantiate, - stake_cw20_gov::contract::query, + stake_cw20::contract::execute, + stake_cw20::contract::instantiate, + stake_cw20::contract::query, ); Box::new(contract) } diff --git a/contracts/stake-cw20-gov/.cargo/config b/contracts/stake-cw20-gov/.cargo/config deleted file mode 100644 index 8d4bc738b..000000000 --- a/contracts/stake-cw20-gov/.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" -integration-test = "test --test integration" -schema = "run --example schema" diff --git a/contracts/stake-cw20-gov/Cargo.lock b/contracts/stake-cw20-gov/Cargo.lock deleted file mode 100644 index 098872e21..000000000 --- a/contracts/stake-cw20-gov/Cargo.lock +++ /dev/null @@ -1,609 +0,0 @@ -# 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.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ec9bdd1f4da5fc0d085251b0322661c5aaf773ab299e3e205fb18130b7f6ba3" -dependencies = [ - "digest", - "ed25519-zebra", - "k256", - "rand_core 0.5.1", - "thiserror", -] - -[[package]] -name = "cosmwasm-derive" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ac17a14b4ab09a5d89b5301218067acca33d9311376e5c34c9877f09e562395" -dependencies = [ - "syn", -] - -[[package]] -name = "cosmwasm-schema" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c04830bc186c970ea400c0ea56f8a61b19aea1aa8d2442b9f9f9de96a61f0bf0" -dependencies = [ - "schemars", - "serde_json", -] - -[[package]] -name = "cosmwasm-std" -version = "0.16.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e47306c113f4d964c35a74a87ceb8ccfb5811e9810a9dc427101148b5b9134ca" -dependencies = [ - "base64", - "cosmwasm-crypto", - "cosmwasm-derive", - "schemars", - "serde", - "serde-json-wasm", - "thiserror", - "uint", -] - -[[package]] -name = "cpufeatures" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" -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.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e49339137316df1914fdb54a5eae75a73f45068fd0d2178fe235b11d93238a6e" -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 = "cw-storage-plus" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e867b9972b83b32e00e878dfbff48299ba26618dabeb19b9c56fae176dc225" -dependencies = [ - "cosmwasm-std", - "schemars", - "serde", -] - -[[package]] -name = "cw0" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c497f885a40918a02df7d938c81809965fa05cfc21b3dc591e9950237b5de0a9" -dependencies = [ - "cosmwasm-std", - "schemars", - "serde", - "thiserror", -] - -[[package]] -name = "cw2" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d48454f96494aa1018556cd457977375cc8c57ef3e5c767cfa2ea5ec24b0258" -dependencies = [ - "cosmwasm-std", - "cw-storage-plus", - "schemars", - "serde", -] - -[[package]] -name = "cw20" -version = "0.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a11a2adbd52258f5b4ed5323f62bc6e559f2cefbe52ef0e58290016fde5bb083" -dependencies = [ - "cosmwasm-std", - "cw0", - "schemars", - "serde", -] - -[[package]] -name = "cw20-base" -version = "0.8.1" -dependencies = [ - "cosmwasm-schema", - "cosmwasm-std", - "cw-storage-plus", - "cw0", - "cw2", - "cw20", - "schemars", - "serde", - "thiserror", -] - -[[package]] -name = "der" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e21d2d0f22cde6e88694108429775c0219760a07779bf96503b434a03d7412" -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.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ee23aa5b4f68c7a092b5c3beb25f50c406adc75e2363634f242f28ab255372" -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.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beca177dcb8eb540133e7680baff45e7cc4d93bf22002676cec549f82343721b" -dependencies = [ - "crypto-bigint", - "ff", - "generic-array", - "group", - "pkcs8", - "rand_core 0.6.3", - "subtle", - "zeroize", -] - -[[package]] -name = "ff" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0f40b2dcd8bc322217a5f6559ae5f9e9d1de202a2ecee2e9eafcbece7562a4f" -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.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" - -[[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.101" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21" - -[[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.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d" -dependencies = [ - "unicode-xid", -] - -[[package]] -name = "quote" -version = "1.0.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" -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.130" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" -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.130" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" -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.67" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sha2" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" -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.76" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84" -dependencies = [ - "proc-macro2", - "quote", - "unicode-xid", -] - -[[package]] -name = "thiserror" -version = "1.0.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "typenum" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" - -[[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.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" - -[[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/contracts/stake-cw20-gov/Cargo.toml b/contracts/stake-cw20-gov/Cargo.toml deleted file mode 100644 index 1fb973d3e..000000000 --- a/contracts/stake-cw20-gov/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -name = "stake-cw20-gov" -version = "0.2.5" -authors = ["Ben2x4 "] -edition = "2018" -description = "CosmWasm-20 compliant token with checkpointing to enable DAOs" -license = "Apache-2.0" - -[lib] -crate-type = ["cdylib", "rlib"] - -[features] -backtraces = ["cosmwasm-std/backtraces"] -# use library feature to disable all instantiate/execute/query exports -library = [] - -[dependencies] -cw2 = { version = "0.11" } -cw20 = { version = "0.11" } -stake-cw20 = { path = "../stake-cw20", version = "0.2.5", features = ["library"] } -cw20-base = { version = "0.11", features = ["library"] } -cw-storage-plus = { version = "0.11" } -cw-utils = { version = "0.11" } -cosmwasm-std = { version = "1.0.0-beta" } -schemars = "0.8.6" -serde = { version = "1.0.130", default-features = false, features = ["derive"] } -thiserror = { version = "1.0.30" } - -[dev-dependencies] -cosmwasm-schema = { version = "1.0.0-beta" } -cw-multi-test = { version = "0.11" } -anyhow = { version = "1.0.51"} diff --git a/contracts/stake-cw20-gov/NOTICE b/contracts/stake-cw20-gov/NOTICE deleted file mode 100644 index 84b1c2103..000000000 --- a/contracts/stake-cw20-gov/NOTICE +++ /dev/null @@ -1,14 +0,0 @@ -CW20-Base: A reference implementation for fungible token on CosmWasm -Copyright (C) 2020 Confio OÜ - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. diff --git a/contracts/stake-cw20-gov/README.md b/contracts/stake-cw20-gov/README.md deleted file mode 100644 index 84b38efae..000000000 --- a/contracts/stake-cw20-gov/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# Stake CW20 Gov - -This is a governance implementation of a cw20 staking contract with support for vote delegation. Staked tokens can be unbonded with a configurable unbonding period. Staked balances and voting power can be queried at any arbitrary height by external contracts. - -This contract is used to enable DAO voting. - -## Running this contract - -You will need Rust 1.58.1+ with `wasm32-unknown-unknown` target installed. - -You can run unit tests on this via: - -`cargo test` - -Once you are happy with the content, you can compile it to wasm via: - -``` -RUSTFLAGS='-C link-arg=-s' cargo wasm -cp ../../target/wasm32-unknown-unknown/release/stake_cw20_gov.wasm . -ls -l stake_cw20_gov.wasm -sha256sum stake_cw20_gov.wasm -``` - -Or for a production-ready (optimized) build, run a build command in the the repository root: https://github.com/CosmWasm/cw-plus#compiling. diff --git a/contracts/stake-cw20-gov/examples/schema.rs b/contracts/stake-cw20-gov/examples/schema.rs deleted file mode 100644 index 0903602c2..000000000 --- a/contracts/stake-cw20-gov/examples/schema.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::env::current_dir; -use std::fs::create_dir_all; - -use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; -use cw20::{ - AllAccountsResponse, AllAllowancesResponse, AllowanceResponse, BalanceResponse, - TokenInfoResponse, -}; -use cw20_base::msg::InstantiateMsg; - -use stake_cw20_gov::msg::{ExecuteMsg, QueryMsg, VotingPowerAtHeightResponse}; - -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!(ExecuteMsg), &out_dir); - export_schema(&schema_for!(QueryMsg), &out_dir); - export_schema(&schema_for!(AllowanceResponse), &out_dir); - export_schema(&schema_for!(BalanceResponse), &out_dir); - export_schema(&schema_for!(VotingPowerAtHeightResponse), &out_dir); - export_schema(&schema_for!(TokenInfoResponse), &out_dir); - export_schema(&schema_for!(AllAllowancesResponse), &out_dir); - export_schema(&schema_for!(AllAccountsResponse), &out_dir); -} diff --git a/contracts/stake-cw20-gov/helpers.ts b/contracts/stake-cw20-gov/helpers.ts deleted file mode 100644 index 74f640a4c..000000000 --- a/contracts/stake-cw20-gov/helpers.ts +++ /dev/null @@ -1,306 +0,0 @@ -import axios from "axios"; -import fs from "fs"; -import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate"; -import { GasPrice, calculateFee, StdFee } from "@cosmjs/stargate"; -import { DirectSecp256k1HdWallet, makeCosmoshubPath } from "@cosmjs/proto-signing"; -import { Slip10RawIndex } from "@cosmjs/crypto"; -import path from "path"; -/* - * This is a set of helpers meant for use with @cosmjs/cli - * With these you can easily use the cw20 contract without worrying about forming messages and parsing queries. - * - * Usage: npx @cosmjs/cli@^0.26 --init https://raw.githubusercontent.com/CosmWasm/cosmwasm-plus/master/contracts/cw20-base/helpers.ts - * - * Create a client: - * const [addr, client] = await useOptions(pebblenetOptions).setup('password'); - * - * Get the mnemonic: - * await useOptions(pebblenetOptions).recoverMnemonic(password); - * - * Create contract: - * const contract = CW20(client, pebblenetOptions.fees); - * - * Upload contract: - * const codeId = await contract.upload(addr); - * - * Instantiate contract example: - * const initMsg = { - * name: "Potato Coin", - * symbol: "TATER", - * decimals: 2, - * initial_balances: [{ address: addr, amount: "10000" }], - * mint: { "minter": addr } - * }; - * const instance = await contract.instantiate(addr, codeId, initMsg, 'Potato Coin!'); - * - * If you want to use this code inside an app, you will need several imports from https://github.com/CosmWasm/cosmjs -*/ - - -interface Options { - readonly httpUrl: string - readonly networkId: string - readonly feeToken: string - readonly bech32prefix: string - readonly hdPath: readonly Slip10RawIndex[] - readonly faucetUrl?: string - readonly defaultKeyFile: string, - readonly fees: { - upload: StdFee, - init: StdFee, - exec: StdFee - } -} - -const pebblenetGasPrice = GasPrice.fromString("0.01upebble"); -const pebblenetOptions: Options = { - httpUrl: 'https://rpc.pebblenet.cosmwasm.com', - networkId: 'pebblenet-1', - bech32prefix: 'wasm', - feeToken: 'upebble', - faucetUrl: 'https://faucet.pebblenet.cosmwasm.com/credit', - hdPath: makeCosmoshubPath(0), - defaultKeyFile: path.join(process.env.HOME, ".pebblenet.key"), - fees: { - upload: calculateFee(1500000, pebblenetGasPrice), - init: calculateFee(500000, pebblenetGasPrice), - exec: calculateFee(200000, pebblenetGasPrice), - }, -} - -interface Network { - setup: (password: string, filename?: string) => Promise<[string, SigningCosmWasmClient]> - recoverMnemonic: (password: string, filename?: string) => Promise -} - -const useOptions = (options: Options): Network => { - - const loadOrCreateWallet = async (options: Options, filename: string, password: string): Promise => { - let encrypted: string; - try { - encrypted = fs.readFileSync(filename, 'utf8'); - } catch (err) { - // generate if no file exists - const wallet = await DirectSecp256k1HdWallet.generate(12, {hdPaths: [options.hdPath], prefix: options.bech32prefix}); - const encrypted = await wallet.serialize(password); - fs.writeFileSync(filename, encrypted, 'utf8'); - return wallet; - } - // otherwise, decrypt the file (we cannot put deserialize inside try or it will over-write on a bad password) - const wallet = await DirectSecp256k1HdWallet.deserialize(encrypted, password); - return wallet; - }; - - const connect = async ( - wallet: DirectSecp256k1HdWallet, - options: Options - ): Promise => { - const clientOptions = { - prefix: options.bech32prefix - } - return await SigningCosmWasmClient.connectWithSigner(options.httpUrl, wallet, clientOptions) - }; - - const hitFaucet = async ( - faucetUrl: string, - address: string, - denom: string - ): Promise => { - await axios.post(faucetUrl, {denom, address}); - } - - const setup = async (password: string, filename?: string): Promise<[string, SigningCosmWasmClient]> => { - const keyfile = filename || options.defaultKeyFile; - const wallet = await loadOrCreateWallet(pebblenetOptions, keyfile, password); - const client = await connect(wallet, pebblenetOptions); - - const [account] = await wallet.getAccounts(); - // ensure we have some tokens - if (options.faucetUrl) { - const tokens = await client.getBalance(account.address, options.feeToken) - if (tokens.amount === '0') { - console.log(`Getting ${options.feeToken} from faucet`); - await hitFaucet(options.faucetUrl, account.address, options.feeToken); - } - } - - return [account.address, client]; - } - - const recoverMnemonic = async (password: string, filename?: string): Promise => { - const keyfile = filename || options.defaultKeyFile; - const wallet = await loadOrCreateWallet(pebblenetOptions, keyfile, password); - return wallet.mnemonic; - } - - return {setup, recoverMnemonic}; -} - - -// TODO: Extract to separate folder: interfaces and funcs -interface Balances { - readonly address: string - readonly amount: string // decimal as string -} - -interface MintInfo { - readonly minter: string - readonly cap?: string // decimal as string -} - -type Expiration = {readonly at_height: number} | {readonly at_time: number} | {readonly never: {}}; - -interface AllowanceResponse { - readonly allowance: string; // integer as string - readonly expires: Expiration; -} - -interface AllowanceInfo { - readonly allowance: string; // integer as string - readonly spender: string; // bech32 address - readonly expires: Expiration; -} - -interface AllAllowancesResponse { - readonly allowances: readonly AllowanceInfo[]; -} - -interface AllAccountsResponse { - // list of bech32 address that have a balance - readonly accounts: readonly string[]; -} - - -interface CW20Instance { - readonly contractAddress: string - - // queries - balance: (address?: string) => Promise - allowance: (owner: string, spender: string) => Promise - allAllowances: (owner: string, startAfter?: string, limit?: number) => Promise - allAccounts: (startAfter?: string, limit?: number) => Promise - tokenInfo: () => Promise - minter: () => Promise - - // actions - mint: (txSigner: string, recipient: string, amount: string) => Promise - transfer: (txSigner: string, recipient: string, amount: string) => Promise - burn: (txSigner: string, amount: string) => Promise - increaseAllowance: (txSigner: string, recipient: string, amount: string) => Promise - decreaseAllowance: (txSigner: string, recipient: string, amount: string) => Promise - transferFrom: (txSigner: string, owner: string, recipient: string, amount: string) => Promise -} - -interface CW20Contract { - // upload a code blob and returns a codeId - upload: (txSigner: string) => Promise - - // instantiates a cw20 contract - // codeId must come from a previous deploy - // label is the public name of the contract in listing - // if you set admin, you can run migrations on this contract (likely client.senderAddress) - instantiate: (txSigner: string, codeId: number, initMsg: Record, label: string, admin?: string) => Promise - - use: (contractAddress: string) => CW20Instance -} - -export const CW20 = (client: SigningCosmWasmClient, fees: Options["fees"]): CW20Contract => { - const use = (contractAddress: string): CW20Instance => { - const balance = async (address: string): Promise => { - const result = await client.queryContractSmart(contractAddress, {balance: { address }}); - return result.balance; - }; - - const allowance = async (owner: string, spender: string): Promise => { - return client.queryContractSmart(contractAddress, {allowance: { owner, spender }}); - }; - - const allAllowances = async (owner: string, startAfter?: string, limit?: number): Promise => { - return client.queryContractSmart(contractAddress, {all_allowances: { owner, start_after: startAfter, limit }}); - }; - - const allAccounts = async (startAfter?: string, limit?: number): Promise => { - const accounts: AllAccountsResponse = await client.queryContractSmart(contractAddress, {all_accounts: { start_after: startAfter, limit }}); - return accounts.accounts; - }; - - const tokenInfo = async (): Promise => { - return client.queryContractSmart(contractAddress, {token_info: { }}); - }; - - const minter = async (): Promise => { - return client.queryContractSmart(contractAddress, {minter: { }}); - }; - - // mints tokens, returns transactionHash - const mint = async (senderAddress: string, recipient: string, amount: string): Promise => { - const result = await client.execute(senderAddress, contractAddress, {mint: {recipient, amount}}, fees.exec); - return result.transactionHash; - } - - // transfers tokens, returns transactionHash - const transfer = async (senderAddress: string, recipient: string, amount: string): Promise => { - const result = await client.execute(senderAddress, contractAddress, {transfer: {recipient, amount}}, fees.exec); - return result.transactionHash; - } - - // burns tokens, returns transactionHash - const burn = async (senderAddress: string, amount: string): Promise => { - const result = await client.execute(senderAddress, contractAddress, {burn: {amount}}, fees.exec); - return result.transactionHash; - } - - const increaseAllowance = async (senderAddress: string, spender: string, amount: string): Promise => { - const result = await client.execute(senderAddress, contractAddress, {increase_allowance: {spender, amount}}, fees.exec); - return result.transactionHash; - } - - const decreaseAllowance = async (senderAddress: string, spender: string, amount: string): Promise => { - const result = await client.execute(senderAddress, contractAddress, {decrease_allowance: {spender, amount}}, fees.exec); - return result.transactionHash; - } - - const transferFrom = async (senderAddress: string, owner: string, recipient: string, amount: string): Promise => { - const result = await client.execute(senderAddress, contractAddress, {transfer_from: {owner, recipient, amount}}, fees.exec); - return result.transactionHash; - } - - return { - contractAddress, - balance, - allowance, - allAllowances, - allAccounts, - tokenInfo, - minter, - mint, - transfer, - burn, - increaseAllowance, - decreaseAllowance, - transferFrom, - }; - } - - const downloadWasm = async (url: string): Promise => { - const r = await axios.get(url, { responseType: 'arraybuffer' }) - if (r.status !== 200) { - throw new Error(`Download error: ${r.status}`) - } - return r.data - } - - const upload = async (senderAddress: string): Promise => { - const sourceUrl = "https://github.com/CosmWasm/cosmwasm-plus/releases/download/v0.8.1/cw20_base.wasm"; - const wasm = await downloadWasm(sourceUrl); - const result = await client.upload(senderAddress, wasm, fees.upload); - return result.codeId; - } - - const instantiate = async (senderAddress: string, codeId: number, initMsg: Record, label: string, admin?: string): Promise => { - const result = await client.instantiate(senderAddress, codeId, initMsg, label, fees.init, { memo: `Init ${label}`, admin}); - return use(result.contractAddress); - } - - return { upload, instantiate, use }; -} diff --git a/contracts/stake-cw20-gov/schema/all_accounts_response.json b/contracts/stake-cw20-gov/schema/all_accounts_response.json deleted file mode 100644 index cea50fba4..000000000 --- a/contracts/stake-cw20-gov/schema/all_accounts_response.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "AllAccountsResponse", - "type": "object", - "required": [ - "accounts" - ], - "properties": { - "accounts": { - "type": "array", - "items": { - "type": "string" - } - } - } -} diff --git a/contracts/stake-cw20-gov/schema/all_allowances_response.json b/contracts/stake-cw20-gov/schema/all_allowances_response.json deleted file mode 100644 index 6bb2291ce..000000000 --- a/contracts/stake-cw20-gov/schema/all_allowances_response.json +++ /dev/null @@ -1,99 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "AllAllowancesResponse", - "type": "object", - "required": [ - "allowances" - ], - "properties": { - "allowances": { - "type": "array", - "items": { - "$ref": "#/definitions/AllowanceInfo" - } - } - }, - "definitions": { - "AllowanceInfo": { - "type": "object", - "required": [ - "allowance", - "expires", - "spender" - ], - "properties": { - "allowance": { - "$ref": "#/definitions/Uint128" - }, - "expires": { - "$ref": "#/definitions/Expiration" - }, - "spender": { - "type": "string" - } - } - }, - "Expiration": { - "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", - "oneOf": [ - { - "description": "AtHeight will expire when `env.block.height` >= height", - "type": "object", - "required": [ - "at_height" - ], - "properties": { - "at_height": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, - { - "description": "AtTime will expire when `env.block.time` >= time", - "type": "object", - "required": [ - "at_time" - ], - "properties": { - "at_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false - }, - { - "description": "Never will never expire. Used to express the empty variant", - "type": "object", - "required": [ - "never" - ], - "properties": { - "never": { - "type": "object" - } - }, - "additionalProperties": false - } - ] - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/stake-cw20-gov/schema/allowance_response.json b/contracts/stake-cw20-gov/schema/allowance_response.json deleted file mode 100644 index c4f98d6fc..000000000 --- a/contracts/stake-cw20-gov/schema/allowance_response.json +++ /dev/null @@ -1,81 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "AllowanceResponse", - "type": "object", - "required": [ - "allowance", - "expires" - ], - "properties": { - "allowance": { - "$ref": "#/definitions/Uint128" - }, - "expires": { - "$ref": "#/definitions/Expiration" - } - }, - "definitions": { - "Expiration": { - "description": "Expiration represents a point in time when some event happens. It can compare with a BlockInfo and will return is_expired() == true once the condition is hit (and for every block in the future)", - "oneOf": [ - { - "description": "AtHeight will expire when `env.block.height` >= height", - "type": "object", - "required": [ - "at_height" - ], - "properties": { - "at_height": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, - { - "description": "AtTime will expire when `env.block.time` >= time", - "type": "object", - "required": [ - "at_time" - ], - "properties": { - "at_time": { - "$ref": "#/definitions/Timestamp" - } - }, - "additionalProperties": false - }, - { - "description": "Never will never expire. Used to express the empty variant", - "type": "object", - "required": [ - "never" - ], - "properties": { - "never": { - "type": "object" - } - }, - "additionalProperties": false - } - ] - }, - "Timestamp": { - "description": "A point in time in nanosecond precision.\n\nThis type can represent times from 1970-01-01T00:00:00Z to 2554-07-21T23:34:33Z.\n\n## Examples\n\n``` # use cosmwasm_std::Timestamp; let ts = Timestamp::from_nanos(1_000_000_202); assert_eq!(ts.nanos(), 1_000_000_202); assert_eq!(ts.seconds(), 1); assert_eq!(ts.subsec_nanos(), 202);\n\nlet ts = ts.plus_seconds(2); assert_eq!(ts.nanos(), 3_000_000_202); assert_eq!(ts.seconds(), 3); assert_eq!(ts.subsec_nanos(), 202); ```", - "allOf": [ - { - "$ref": "#/definitions/Uint64" - } - ] - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - }, - "Uint64": { - "description": "A thin wrapper around u64 that is using strings for JSON encoding/decoding, such that the full u64 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u64` to get the value out:\n\n``` # use cosmwasm_std::Uint64; let a = Uint64::from(42u64); assert_eq!(a.u64(), 42);\n\nlet b = Uint64::from(70u32); assert_eq!(b.u64(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/stake-cw20-gov/schema/balance_response.json b/contracts/stake-cw20-gov/schema/balance_response.json deleted file mode 100644 index 4e1a0be2b..000000000 --- a/contracts/stake-cw20-gov/schema/balance_response.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "BalanceResponse", - "type": "object", - "required": [ - "balance" - ], - "properties": { - "balance": { - "$ref": "#/definitions/Uint128" - } - }, - "definitions": { - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/stake-cw20-gov/schema/execute_msg.json b/contracts/stake-cw20-gov/schema/execute_msg.json deleted file mode 100644 index 4d7afff9c..000000000 --- a/contracts/stake-cw20-gov/schema/execute_msg.json +++ /dev/null @@ -1,168 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "ExecuteMsg", - "oneOf": [ - { - "type": "object", - "required": [ - "receive" - ], - "properties": { - "receive": { - "$ref": "#/definitions/Cw20ReceiveMsg" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "unstake" - ], - "properties": { - "unstake": { - "type": "object", - "required": [ - "amount" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "claim" - ], - "properties": { - "claim": { - "type": "object" - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "delegate_votes" - ], - "properties": { - "delegate_votes": { - "type": "object", - "required": [ - "recipient" - ], - "properties": { - "recipient": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "update_config" - ], - "properties": { - "update_config": { - "type": "object", - "required": [ - "admin" - ], - "properties": { - "admin": { - "$ref": "#/definitions/Addr" - }, - "duration": { - "anyOf": [ - { - "$ref": "#/definitions/Duration" - }, - { - "type": "null" - } - ] - } - } - } - }, - "additionalProperties": false - } - ], - "definitions": { - "Addr": { - "description": "A human readable address.\n\nIn Cosmos, this is typically bech32 encoded. But for multi-chain smart contracts no assumptions should be made other than being UTF-8 encoded and of reasonable length.\n\nThis type represents a validated address. It can be created in the following ways 1. Use `Addr::unchecked(input)` 2. Use `let checked: Addr = deps.api.addr_validate(input)?` 3. Use `let checked: Addr = deps.api.addr_humanize(canonical_addr)?` 4. Deserialize from JSON. This must only be done from JSON that was validated before such as a contract's state. `Addr` must not be used in messages sent by the user because this would result in unvalidated instances.\n\nThis type is immutable. If you really need to mutate it (Really? Are you sure?), create a mutable copy using `let mut mutable = Addr::to_string()` and operate on that `String` instance.", - "type": "string" - }, - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec", - "type": "string" - }, - "Cw20ReceiveMsg": { - "description": "Cw20ReceiveMsg should be de/serialized under `Receive()` variant in a ExecuteMsg", - "type": "object", - "required": [ - "amount", - "msg", - "sender" - ], - "properties": { - "amount": { - "$ref": "#/definitions/Uint128" - }, - "msg": { - "$ref": "#/definitions/Binary" - }, - "sender": { - "type": "string" - } - } - }, - "Duration": { - "description": "Duration is a delta of time. You can add it to a BlockInfo or Expiration to move that further in the future. Note that an height-based Duration and a time-based Expiration cannot be combined", - "oneOf": [ - { - "type": "object", - "required": [ - "height" - ], - "properties": { - "height": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - }, - { - "description": "Time in seconds", - "type": "object", - "required": [ - "time" - ], - "properties": { - "time": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "additionalProperties": false - } - ] - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/stake-cw20-gov/schema/instantiate_msg.json b/contracts/stake-cw20-gov/schema/instantiate_msg.json deleted file mode 100644 index 7b9aa1eeb..000000000 --- a/contracts/stake-cw20-gov/schema/instantiate_msg.json +++ /dev/null @@ -1,192 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "InstantiateMsg", - "type": "object", - "required": [ - "decimals", - "initial_balances", - "name", - "symbol" - ], - "properties": { - "decimals": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "initial_balances": { - "type": "array", - "items": { - "$ref": "#/definitions/Cw20Coin" - } - }, - "marketing": { - "anyOf": [ - { - "$ref": "#/definitions/InstantiateMarketingInfo" - }, - { - "type": "null" - } - ] - }, - "mint": { - "anyOf": [ - { - "$ref": "#/definitions/MinterResponse" - }, - { - "type": "null" - } - ] - }, - "name": { - "type": "string" - }, - "symbol": { - "type": "string" - } - }, - "definitions": { - "Binary": { - "description": "Binary is a wrapper around Vec to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec", - "type": "string" - }, - "Cw20Coin": { - "type": "object", - "required": [ - "address", - "amount" - ], - "properties": { - "address": { - "type": "string" - }, - "amount": { - "$ref": "#/definitions/Uint128" - } - } - }, - "EmbeddedLogo": { - "description": "This is used to store the logo on the blockchain in an accepted format. Enforce maximum size of 5KB on all variants.", - "oneOf": [ - { - "description": "Store the Logo as an SVG file. The content must conform to the spec at https://en.wikipedia.org/wiki/Scalable_Vector_Graphics (The contract should do some light-weight sanity-check validation)", - "type": "object", - "required": [ - "svg" - ], - "properties": { - "svg": { - "$ref": "#/definitions/Binary" - } - }, - "additionalProperties": false - }, - { - "description": "Store the Logo as a PNG file. This will likely only support up to 64x64 or so within the 5KB limit.", - "type": "object", - "required": [ - "png" - ], - "properties": { - "png": { - "$ref": "#/definitions/Binary" - } - }, - "additionalProperties": false - } - ] - }, - "InstantiateMarketingInfo": { - "type": "object", - "properties": { - "description": { - "type": [ - "string", - "null" - ] - }, - "logo": { - "anyOf": [ - { - "$ref": "#/definitions/Logo" - }, - { - "type": "null" - } - ] - }, - "marketing": { - "type": [ - "string", - "null" - ] - }, - "project": { - "type": [ - "string", - "null" - ] - } - } - }, - "Logo": { - "description": "This is used for uploading logo data, or setting it in InstantiateData", - "oneOf": [ - { - "description": "A reference to an externally hosted logo. Must be a valid HTTP or HTTPS URL.", - "type": "object", - "required": [ - "url" - ], - "properties": { - "url": { - "type": "string" - } - }, - "additionalProperties": false - }, - { - "description": "Logo content stored on the blockchain. Enforce maximum size of 5KB on all variants", - "type": "object", - "required": [ - "embedded" - ], - "properties": { - "embedded": { - "$ref": "#/definitions/EmbeddedLogo" - } - }, - "additionalProperties": false - } - ] - }, - "MinterResponse": { - "type": "object", - "required": [ - "minter" - ], - "properties": { - "cap": { - "description": "cap is a hard cap on total supply that can be achieved by minting. Note that this refers to total_supply. If None, there is unlimited cap.", - "anyOf": [ - { - "$ref": "#/definitions/Uint128" - }, - { - "type": "null" - } - ] - }, - "minter": { - "type": "string" - } - } - }, - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/stake-cw20-gov/schema/query_msg.json b/contracts/stake-cw20-gov/schema/query_msg.json deleted file mode 100644 index 77f190153..000000000 --- a/contracts/stake-cw20-gov/schema/query_msg.json +++ /dev/null @@ -1,141 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "QueryMsg", - "oneOf": [ - { - "description": "Returns the balance of the given address at given height, 0 if unset. Return type: BalanceAtHeightResponse.", - "type": "object", - "required": [ - "voting_power_at_height" - ], - "properties": { - "voting_power_at_height": { - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "type": "string" - }, - "height": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Returns current delegation information Return type: DelegationResponse.", - "type": "object", - "required": [ - "delegation" - ], - "properties": { - "delegation": { - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "type": "string" - } - } - } - }, - "additionalProperties": false - }, - { - "type": "object", - "required": [ - "staked_balance_at_height" - ], - "properties": { - "staked_balance_at_height": { - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "type": "string" - }, - "height": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Returns the total staked amount of tokens at a given height, if no height is provided defaults to current block height.", - "type": "object", - "required": [ - "total_staked_at_height" - ], - "properties": { - "total_staked_at_height": { - "type": "object", - "properties": { - "height": { - "type": [ - "integer", - "null" - ], - "format": "uint64", - "minimum": 0.0 - } - } - } - }, - "additionalProperties": false - }, - { - "description": "Returns the config for the contract.", - "type": "object", - "required": [ - "get_config" - ], - "properties": { - "get_config": { - "type": "object" - } - }, - "additionalProperties": false - }, - { - "description": "Returns existing claims for tokens currently unstaking for a given address.", - "type": "object", - "required": [ - "claims" - ], - "properties": { - "claims": { - "type": "object", - "required": [ - "address" - ], - "properties": { - "address": { - "type": "string" - } - } - } - }, - "additionalProperties": false - } - ] -} diff --git a/contracts/stake-cw20-gov/schema/token_info_response.json b/contracts/stake-cw20-gov/schema/token_info_response.json deleted file mode 100644 index 9920c841f..000000000 --- a/contracts/stake-cw20-gov/schema/token_info_response.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "TokenInfoResponse", - "type": "object", - "required": [ - "decimals", - "name", - "symbol", - "total_supply" - ], - "properties": { - "decimals": { - "type": "integer", - "format": "uint8", - "minimum": 0.0 - }, - "name": { - "type": "string" - }, - "symbol": { - "type": "string" - }, - "total_supply": { - "$ref": "#/definitions/Uint128" - } - }, - "definitions": { - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/stake-cw20-gov/schema/voting_power_at_height_response.json b/contracts/stake-cw20-gov/schema/voting_power_at_height_response.json deleted file mode 100644 index 2da9b57c0..000000000 --- a/contracts/stake-cw20-gov/schema/voting_power_at_height_response.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "$schema": "http://json-schema.org/draft-07/schema#", - "title": "VotingPowerAtHeightResponse", - "type": "object", - "required": [ - "balance", - "height" - ], - "properties": { - "balance": { - "$ref": "#/definitions/Uint128" - }, - "height": { - "type": "integer", - "format": "uint64", - "minimum": 0.0 - } - }, - "definitions": { - "Uint128": { - "description": "A thin wrapper around u128 that is using strings for JSON encoding/decoding, such that the full u128 range can be used for clients that convert JSON numbers to floats, like JavaScript and jq.\n\n# Examples\n\nUse `from` to create instances of this and `u128` to get the value out:\n\n``` # use cosmwasm_std::Uint128; let a = Uint128::from(123u128); assert_eq!(a.u128(), 123);\n\nlet b = Uint128::from(42u64); assert_eq!(b.u128(), 42);\n\nlet c = Uint128::from(70u32); assert_eq!(c.u128(), 70); ```", - "type": "string" - } - } -} diff --git a/contracts/stake-cw20-gov/src/contract.rs b/contracts/stake-cw20-gov/src/contract.rs deleted file mode 100644 index 890f550c3..000000000 --- a/contracts/stake-cw20-gov/src/contract.rs +++ /dev/null @@ -1,486 +0,0 @@ -#[cfg(not(feature = "library"))] -use cosmwasm_std::entry_point; -use cosmwasm_std::{ - from_binary, to_binary, Addr, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, - Uint128, -}; -use cw2::set_contract_version; -use cw20::Cw20ReceiveMsg; - -use crate::msg::{ - DelegationResponse, ExecuteMsg, InstantiateMsg, QueryMsg, ReceiveMsg, - VotingPowerAtHeightResponse, -}; -use crate::state::{DELEGATIONS, VOTING_POWER}; -use stake_cw20::state::{CONFIG, STAKED_BALANCES}; -use stake_cw20::ContractError; - -const CONTRACT_NAME: &str = "crates.io:stake_cw20_gov"; -const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn instantiate( - mut deps: DepsMut, - _env: Env, - _info: MessageInfo, - msg: InstantiateMsg, -) -> Result { - let res = stake_cw20::contract::instantiate(deps.branch(), _env, _info, msg)?; - set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION) - .map_err(ContractError::Std)?; - - Ok(res) -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn execute( - deps: DepsMut, - env: Env, - info: MessageInfo, - msg: ExecuteMsg, -) -> Result { - match msg { - ExecuteMsg::Receive(msg) => execute_receive(deps, env, info, msg), - ExecuteMsg::Unstake { amount } => execute_unstake(deps, env, info, amount), - ExecuteMsg::Claim {} => stake_cw20::contract::execute_claim(deps, env, info), - ExecuteMsg::UpdateConfig { admin, duration } => { - stake_cw20::contract::execute_update_config(info, deps, admin, duration) - } - ExecuteMsg::DelegateVotes { recipient } => { - execute_delegate_votes(deps, env, info, recipient) - } - } -} - -pub fn execute_receive( - deps: DepsMut, - env: Env, - info: MessageInfo, - wrapper: Cw20ReceiveMsg, -) -> Result { - let config = CONFIG.load(deps.storage)?; - if info.sender != config.token_address { - return Err(ContractError::InvalidToken { - received: info.sender, - expected: config.token_address, - }); - } - let msg: ReceiveMsg = from_binary(&wrapper.msg)?; - let sender = deps.api.addr_validate(&wrapper.sender)?; - match msg { - ReceiveMsg::Stake {} => execute_stake(deps, env, &sender, wrapper.amount), - } -} - -pub fn execute_stake( - deps: DepsMut, - env: Env, - sender: &Addr, - amount: Uint128, -) -> Result { - let delegation = DELEGATIONS - .may_load(deps.storage, sender)? - .unwrap_or_else(|| sender.clone()); - VOTING_POWER.update( - deps.storage, - &delegation, - env.block.height, - |balance: Option| -> StdResult<_> { - Ok(balance.unwrap_or_default().checked_add(amount)?) - }, - )?; - stake_cw20::contract::execute_stake(deps, env, sender, amount) -} - -pub fn execute_unstake( - deps: DepsMut, - env: Env, - info: MessageInfo, - amount: Uint128, -) -> Result { - let delegation = DELEGATIONS - .may_load(deps.storage, &info.sender)? - .unwrap_or_else(|| info.sender.clone()); - VOTING_POWER.update( - deps.storage, - &delegation, - env.block.height, - |balance: Option| -> StdResult<_> { - Ok(balance.unwrap_or_default().checked_sub(amount)?) - }, - )?; - stake_cw20::contract::execute_unstake(deps, env, info, amount) -} - -pub fn execute_delegate_votes( - deps: DepsMut, - env: Env, - info: MessageInfo, - recipient: String, -) -> Result { - let rcpt_addr = deps.api.addr_validate(&recipient)?; - let amount = STAKED_BALANCES - .may_load(deps.storage, &info.sender)? - .unwrap_or_default(); - let old_delegation = DELEGATIONS - .may_load(deps.storage, &info.sender)? - .unwrap_or_else(|| info.sender.clone()); - DELEGATIONS.update(deps.storage, &info.sender, |_| -> StdResult<_> { - Ok(rcpt_addr.clone()) - })?; - VOTING_POWER.update( - deps.storage, - &old_delegation, - env.block.height, - |balance: Option| -> StdResult<_> { - Ok(balance.unwrap_or_default().checked_sub(amount)?) - }, - )?; - VOTING_POWER.update( - deps.storage, - &rcpt_addr, - env.block.height, - |balance: Option| -> StdResult<_> { Ok(balance.unwrap_or_default() + amount) }, - )?; - Ok(Response::default()) -} - -#[cfg_attr(not(feature = "library"), entry_point)] -pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { - match msg { - // Custom queries - QueryMsg::VotingPowerAtHeight { address, height } => { - to_binary(&query_voting_power_at_height(deps, env, address, height)?) - } - QueryMsg::Delegation { address } => to_binary(&query_delegation(deps, address)?), - QueryMsg::TotalStakedAtHeight { height } => to_binary( - &stake_cw20::contract::query_total_staked_at_height(deps, env, height)?, - ), - QueryMsg::StakedBalanceAtHeight { address, height } => to_binary( - &stake_cw20::contract::query_staked_balance_at_height(deps, env, address, height)?, - ), - QueryMsg::GetConfig {} => to_binary(&stake_cw20::contract::query_config(deps)?), - QueryMsg::Claims { address } => { - to_binary(&stake_cw20::contract::query_claims(deps, address)?) - } - } -} - -pub fn query_voting_power_at_height( - deps: Deps, - env: Env, - address: String, - height: Option, -) -> StdResult { - let address = deps.api.addr_validate(&address)?; - let height = height.unwrap_or(env.block.height); - let balance = VOTING_POWER - .may_load_at_height(deps.storage, &address, height)? - .unwrap_or_default(); - Ok(VotingPowerAtHeightResponse { balance, height }) -} - -pub fn query_delegation(deps: Deps, address: String) -> StdResult { - let address_addr = deps.api.addr_validate(&address)?; - let delegation = DELEGATIONS - .may_load(deps.storage, &address_addr)? - .unwrap_or(address_addr); - Ok(DelegationResponse { - delegation: delegation.into(), - }) -} - -#[cfg(test)] -mod tests { - use super::*; - use cw20::Cw20Coin; - use cw_utils::Duration; - use stake_cw20::state::MAX_CLAIMS; - - use crate::msg::{ - ExecuteMsg, QueryMsg, ReceiveMsg, StakedBalanceAtHeightResponse, - TotalStakedAtHeightResponse, - }; - use anyhow::Result as AnyResult; - use cosmwasm_std::testing::mock_info; - use cosmwasm_std::{to_binary, Addr, Empty, MessageInfo, Uint128}; - use cw_multi_test::{next_block, App, AppResponse, Contract, ContractWrapper, Executor}; - - const ADDR1: &str = "addr0001"; - const ADDR2: &str = "addr0002"; - - pub fn contract_staking_gov() -> Box> { - let contract = ContractWrapper::new( - crate::contract::execute, - crate::contract::instantiate, - crate::contract::query, - ); - Box::new(contract) - } - - pub fn contract_cw20() -> Box> { - let contract = ContractWrapper::new( - cw20_base::contract::execute, - cw20_base::contract::instantiate, - cw20_base::contract::query, - ); - Box::new(contract) - } - - fn mock_app() -> App { - App::default() - } - - fn instantiate_cw20(app: &mut App, initial_balances: Vec) -> Addr { - let cw20_id = app.store_code(contract_cw20()); - let msg = cw20_base::msg::InstantiateMsg { - name: String::from("Test"), - symbol: String::from("TEST"), - decimals: 6, - initial_balances, - mint: None, - marketing: None, - }; - - app.instantiate_contract(cw20_id, Addr::unchecked(ADDR1), &msg, &[], "cw20", None) - .unwrap() - } - - fn instantiate_staking( - app: &mut App, - cw20: Addr, - unstaking_duration: Option, - ) -> Addr { - let staking_code_id = app.store_code(contract_staking_gov()); - let msg = crate::msg::InstantiateMsg { - admin: Addr::unchecked("owner"), - token_address: cw20, - unstaking_duration, - }; - app.instantiate_contract( - staking_code_id, - Addr::unchecked(ADDR1), - &msg, - &[], - "staking", - None, - ) - .unwrap() - } - - fn setup_test_case( - app: &mut App, - initial_balances: Vec, - unstaking_duration: Option, - ) -> (Addr, Addr) { - // Instantiate cw20 contract - let cw20_addr = instantiate_cw20(app, initial_balances); - app.update_block(next_block); - // Instantiate staking contract - let staking_addr = instantiate_staking(app, cw20_addr.clone(), unstaking_duration); - app.update_block(next_block); - (staking_addr, cw20_addr) - } - - fn query_staked_balance, U: Into>( - app: &App, - contract_addr: T, - address: U, - ) -> Uint128 { - let msg = QueryMsg::StakedBalanceAtHeight { - address: address.into(), - height: None, - }; - let result: StakedBalanceAtHeightResponse = - app.wrap().query_wasm_smart(contract_addr, &msg).unwrap(); - result.balance - } - - fn query_total_staked>(app: &App, contract_addr: T) -> Uint128 { - let msg = QueryMsg::TotalStakedAtHeight { height: None }; - let result: TotalStakedAtHeightResponse = - app.wrap().query_wasm_smart(contract_addr, &msg).unwrap(); - result.total - } - - fn query_voting_power, U: Into>( - app: &App, - contract_addr: T, - address: U, - ) -> Uint128 { - let msg = QueryMsg::VotingPowerAtHeight { - address: address.into(), - height: None, - }; - let result: VotingPowerAtHeightResponse = - app.wrap().query_wasm_smart(contract_addr, &msg).unwrap(); - result.balance - } - - fn get_balance, U: Into>( - app: &App, - contract_addr: T, - address: U, - ) -> Uint128 { - let msg = cw20::Cw20QueryMsg::Balance { - address: address.into(), - }; - let result: cw20::BalanceResponse = - app.wrap().query_wasm_smart(contract_addr, &msg).unwrap(); - result.balance - } - - fn stake_tokens( - app: &mut App, - staking_addr: &Addr, - cw20_addr: &Addr, - info: MessageInfo, - amount: Uint128, - ) -> AnyResult { - let msg = cw20::Cw20ExecuteMsg::Send { - contract: staking_addr.to_string(), - amount, - msg: to_binary(&ReceiveMsg::Stake {}).unwrap(), - }; - app.execute_contract(info.sender, cw20_addr.clone(), &msg, &[]) - } - - fn delegate>( - app: &mut App, - staking_addr: &Addr, - info: MessageInfo, - delegate_adder: T, - ) -> AnyResult { - let msg = ExecuteMsg::DelegateVotes { - recipient: delegate_adder.into(), - }; - app.execute_contract(info.sender, staking_addr.clone(), &msg, &[]) - } - - fn unstake_tokens( - app: &mut App, - staking_addr: &Addr, - info: MessageInfo, - amount: Uint128, - ) -> AnyResult { - let msg = ExecuteMsg::Unstake { amount }; - app.execute_contract(info.sender, staking_addr.clone(), &msg, &[]) - } - - fn claim_tokens( - app: &mut App, - staking_addr: &Addr, - info: MessageInfo, - ) -> AnyResult { - let msg = ExecuteMsg::Claim {}; - app.execute_contract(info.sender, staking_addr.clone(), &msg, &[]) - } - - #[test] - fn test_contract() { - let mut app = mock_app(); - let amount1 = Uint128::from(100u128); - let initial_balances = vec![Cw20Coin { - address: ADDR1.to_string(), - amount: amount1, - }]; - let (staking_addr, cw20_addr) = setup_test_case(&mut app, initial_balances, None); - - let _info = mock_info(ADDR1, &[]); - - assert_eq!( - Uint128::zero(), - query_voting_power(&app, &staking_addr, ADDR1) - ); - - // Stake tokens - let info = mock_info(ADDR1, &[]); - let amount = Uint128::new(50); - let _res = stake_tokens(&mut app, &staking_addr, &cw20_addr, info, amount).unwrap(); - app.update_block(next_block); - assert_eq!(amount, query_staked_balance(&app, &staking_addr, ADDR1)); - assert_eq!(amount, query_total_staked(&app, &staking_addr)); - assert_eq!(amount, query_voting_power(&app, &staking_addr, ADDR1)); - assert_eq!( - Uint128::zero(), - query_voting_power(&app, &staking_addr, ADDR2) - ); - - // Delegate votes - let info = mock_info(ADDR1, &[]); - let _res = delegate(&mut app, &staking_addr, info, ADDR2).unwrap(); - app.update_block(next_block); - assert_eq!( - Uint128::zero(), - query_voting_power(&app, &staking_addr, ADDR1) - ); - assert_eq!(amount, query_voting_power(&app, &staking_addr, ADDR2)); - - // Partially unstake - let info = mock_info(ADDR1, &[]); - let amount2 = Uint128::new(10); - let _res = unstake_tokens(&mut app, &staking_addr, info, amount2).unwrap(); - app.update_block(next_block); - assert_eq!( - Uint128::zero(), - query_voting_power(&app, &staking_addr, ADDR1) - ); - assert_eq!( - Uint128::new(40), - query_voting_power(&app, &staking_addr, ADDR2) - ); - - // Fully unstake - let info = mock_info(ADDR1, &[]); - let amount3 = Uint128::new(40); - let _res = unstake_tokens(&mut app, &staking_addr, info, amount3).unwrap(); - app.update_block(next_block); - assert_eq!( - Uint128::zero(), - query_voting_power(&app, &staking_addr, ADDR1) - ); - assert_eq!( - Uint128::zero(), - query_voting_power(&app, &staking_addr, ADDR2) - ); - } - - #[test] - fn test_max_claims() { - let mut app = mock_app(); - let amount1 = Uint128::from(MAX_CLAIMS + 1); - let unstaking_blocks = 1u64; - let _token_address = Addr::unchecked("token_address"); - let initial_balances = vec![Cw20Coin { - address: ADDR1.to_string(), - amount: amount1, - }]; - let (staking_addr, cw20_addr) = setup_test_case( - &mut app, - initial_balances, - Some(Duration::Height(unstaking_blocks)), - ); - - let info = mock_info(ADDR1, &[]); - stake_tokens(&mut app, &staking_addr, &cw20_addr, info.clone(), amount1).unwrap(); - - // Create the max number of claims - for _ in 0..MAX_CLAIMS { - unstake_tokens(&mut app, &staking_addr, info.clone(), Uint128::new(1)).unwrap(); - } - - // Additional unstaking attempts ought to fail. - unstake_tokens(&mut app, &staking_addr, info.clone(), Uint128::new(1)).unwrap_err(); - - // Clear out the claims list. - app.update_block(next_block); - claim_tokens(&mut app, &staking_addr, info.clone()).unwrap(); - - // Unstaking now allowed again. - unstake_tokens(&mut app, &staking_addr, info.clone(), Uint128::new(1)).unwrap(); - app.update_block(next_block); - claim_tokens(&mut app, &staking_addr, info).unwrap(); - - assert_eq!(get_balance(&app, &cw20_addr, ADDR1), amount1); - } -} diff --git a/contracts/stake-cw20-gov/src/lib.rs b/contracts/stake-cw20-gov/src/lib.rs deleted file mode 100644 index 4934c19d5..000000000 --- a/contracts/stake-cw20-gov/src/lib.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub mod contract; -pub mod msg; -pub mod state; diff --git a/contracts/stake-cw20-gov/src/msg.rs b/contracts/stake-cw20-gov/src/msg.rs deleted file mode 100644 index 8f10df4f7..000000000 --- a/contracts/stake-cw20-gov/src/msg.rs +++ /dev/null @@ -1,67 +0,0 @@ -use cosmwasm_std::{Addr, Uint128}; -use cw20::Cw20ReceiveMsg; -use cw_utils::Duration; -use schemars::JsonSchema; -use serde::{Deserialize, Serialize}; -pub use stake_cw20::msg::{ - InstantiateMsg, StakedBalanceAtHeightResponse, TotalStakedAtHeightResponse, -}; - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ExecuteMsg { - Receive(Cw20ReceiveMsg), - Unstake { - amount: Uint128, - }, - Claim {}, - DelegateVotes { - recipient: String, - }, - UpdateConfig { - admin: Addr, - duration: Option, - }, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum ReceiveMsg { - Stake {}, -} - -#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)] -#[serde(rename_all = "snake_case")] -pub enum QueryMsg { - /// Returns the balance of the given address at given height, 0 if unset. - /// Return type: BalanceAtHeightResponse. - VotingPowerAtHeight { - address: String, - height: Option, - }, - /// Returns current delegation information - /// Return type: DelegationResponse. - Delegation { address: String }, - StakedBalanceAtHeight { - address: String, - height: Option, - }, - /// Returns the total staked amount of tokens at a given height, if no height is provided - /// defaults to current block height. - TotalStakedAtHeight { height: Option }, - /// Returns the config for the contract. - GetConfig {}, - /// Returns existing claims for tokens currently unstaking for a given address. - Claims { address: String }, -} - -#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] -pub struct VotingPowerAtHeightResponse { - pub balance: Uint128, - pub height: u64, -} - -#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)] -pub struct DelegationResponse { - pub delegation: String, -} diff --git a/contracts/stake-cw20-gov/src/state.rs b/contracts/stake-cw20-gov/src/state.rs deleted file mode 100644 index fdd7afa71..000000000 --- a/contracts/stake-cw20-gov/src/state.rs +++ /dev/null @@ -1,12 +0,0 @@ -use cosmwasm_std::{Addr, Uint128}; -use cw_storage_plus::{Map, SnapshotMap, Strategy}; - -pub const VOTING_POWER: SnapshotMap<&Addr, Uint128> = SnapshotMap::new( - "voting_power", - "voting_power__checkpoints", - "voting_power__changelog", - Strategy::EveryBlock, -); - -// TODO: implement this feature -pub const DELEGATIONS: Map<&Addr, Addr> = Map::new("delegations"); diff --git a/contracts/stake-cw20/Cargo.toml b/contracts/stake-cw20/Cargo.toml index 33bc4ea0d..b8e381648 100644 --- a/contracts/stake-cw20/Cargo.toml +++ b/contracts/stake-cw20/Cargo.toml @@ -16,8 +16,8 @@ backtraces = ["cosmwasm-std/backtraces"] library = [] [dependencies] -cosmwasm-std = { version = "1.0.0-beta4" } -cosmwasm-storage = { version = "1.0.0-beta4" } +cosmwasm-std = { version = "1.0.0-beta" } +cosmwasm-storage = { version = "1.0.0-beta" } cw-storage-plus = { version = "0.11" } cw-controllers = "0.11" cw20 = { version = "0.11" } @@ -29,6 +29,6 @@ serde = { version = "1.0.132", default-features = false, features = ["derive"] } thiserror = { version = "1.0.30" } [dev-dependencies] -cosmwasm-schema = { version = "1.0.0-beta4" } +cosmwasm-schema = { version = "1.0.0-beta" } cw-multi-test = { version = "0.11" } anyhow = { version = "1.0.51"} diff --git a/scripts/deploy_local.sh b/scripts/deploy_local.sh index 9b49f3ba2..54aaa2170 100644 --- a/scripts/deploy_local.sh +++ b/scripts/deploy_local.sh @@ -54,7 +54,7 @@ curl -LO https://github.com/CosmWasm/cw-plus/releases/download/v0.11.1/cw4_group # Copy wasm binaries to docker container docker cp artifacts/cw3_dao.wasm cosmwasm:/cw3_dao.wasm docker cp artifacts/cw3_multisig.wasm cosmwasm:/cw3_multisig.wasm -docker cp artifacts/stake_cw20_gov.wasm cosmwasm:/stake_cw20_gov.wasm +docker cp artifacts/stake_cw20.wasm cosmwasm:/stake_cw20.wasm docker cp cw20_base.wasm cosmwasm:/cw20_base.wasm docker cp cw4_group.wasm cosmwasm:/cw4_group.wasm @@ -83,7 +83,7 @@ CW3_MULTISIG_CODE=$(echo xxxxxxxxx | $BINARY tx wasm store "/cw3_multisig.wasm" CW4_GROUP_CODE=$(echo xxxxxxxxx | $BINARY tx wasm store "/cw4_group.wasm" --from validator $TXFLAG --output json | jq -r '.logs[0].events[-1].attributes[0].value') ### STAKE-CW20 ### -STAKE_CW20_CODE=$(echo xxxxxxxxx | $BINARY tx wasm store "/stake_cw20_gov.wasm" --from validator $TXFLAG --output json | jq -r '.logs[0].events[-1].attributes[0].value') +STAKE_CW20_CODE=$(echo xxxxxxxxx | $BINARY tx wasm store "/stake_cw20.wasm" --from validator $TXFLAG --output json | jq -r '.logs[0].events[-1].attributes[0].value') ##### INSTANTIATE CONTRACTS #####