Skip to content

Commit

Permalink
core fixes in contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek-1857 committed May 13, 2024
1 parent bfe2120 commit 79a90ac
Show file tree
Hide file tree
Showing 45 changed files with 177 additions and 2,040 deletions.
223 changes: 126 additions & 97 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [
"./contracts/external/cw-token-swap/",
"./contracts/external/dao-migrator/",
"./contracts/external/cw-payroll-factory/",
"./contracts/external/cw4-group/",
"./contracts/proposal/*",
"./contracts/pre-propose/*",
"./contracts/staking/*",
Expand Down Expand Up @@ -46,7 +47,7 @@ cosm-orc = { version = "4.0",default-features = false }
cosm-tome = {version = "0.2",default-features = false}
cw3 = {version = "1.1",default-features = false}
cw4 = { path = "./packages/cw4-1.1.2/" ,default-features = false}
cw4-group = { path = "./packages/cw4-group-1.1.2/" ,default-features = false}
cw4-group = { path = "./contracts/external/cw4-group/" ,default-features = false}
env_logger = {version = "0.10",default-features = false}
once_cell = {version = "1.18",default-features = false}

Expand Down Expand Up @@ -126,11 +127,11 @@ secret-toolkit = { version = "0.10.0", default-features = false, features = [
"snip721",
] }

secret-utils = { path = "./packages/utils/",default-features = false }
secret-cw-controllers = { path = "./packages/controllers/",default-features = false }
secret-storage-plus = { git = "https://github.com/securesecrets/secret-plus-utils", version = "0.13.4" }
secret-multi-test = { git = "https://github.com/securesecrets/secret-plus-utils", version = "0.13.4" }
secret-cw2 = { git = "https://github.com/securesecrets/secret-plus-utils" }
secret-storage-plus = { git = "https://github.com/securesecrets/secret-plus-utils", version = "0.13.4", branch = "main"}
secret-multi-test = { git = "https://github.com/securesecrets/secret-plus-utils", version = "0.13.4", branch = "main"}
secret-utils = { git = "https://github.com/securesecrets/secret-plus-utils", version = "0.13.4", branch = "main" }
secret-cw2 = { git = "https://github.com/securesecrets/secret-plus-utils", version = "1.0.1", branch = "main"}

cosmwasm-std = { package = "secret-cosmwasm-std", version = "1.1.11", features = [
"stargate",
Expand Down
39 changes: 20 additions & 19 deletions contracts/dao-dao-core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use cosmwasm_std::{
from_binary, to_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Empty, Env, MessageInfo, Reply,
Response, StdError, StdResult, SubMsg, SubMsgResult,
};
use dao_interface::ReplyEvent;
use dao_interface::{
msg::{ExecuteMsg, InitialItem, InstantiateMsg, MigrateMsg, QueryMsg, Snip20ReceiveMsg},
query::{
Expand All @@ -17,9 +18,8 @@ use dao_interface::{
voting,
};
use secret_cw2::{get_contract_version, set_contract_version, ContractVersion};
use secret_cw_controllers::ReplyEvent;
use secret_toolkit::{serialization::Json, storage::Keymap, utils::HandleCallback};
use secret_utils::{parse_reply_event_for_contract_address, Duration};
use secret_utils::Duration;
use shade_protocol::basic_staking::Auth;
use snip20_reference_impl::msg::ExecuteAnswer;

Expand Down Expand Up @@ -563,8 +563,12 @@ pub fn execute_receive_snip20(
entropy: "entropy".to_string(),
padding: None,
};
let reply_id =
REPLY_IDS.add_event(deps.storage, ReplyEvent::Snip20ModuleCreateViewingKey {})?;
let reply_id = REPLY_IDS.add_event(
deps.storage,
ReplyEvent::Snip20ModuleCreateViewingKey {
contract_address: sender.clone().to_string(),
},
)?;
let submsg = SubMsg::reply_always(
gen_viewing_key_msg.to_cosmos_msg(
snip20_code_hash.clone(),
Expand Down Expand Up @@ -1099,23 +1103,20 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result<Response, ContractE
.add_messages(callback_msgs))
}
},
ReplyEvent::Snip20ModuleCreateViewingKey {} => {
match msg.result {
SubMsgResult::Ok(res) => {
let addr = parse_reply_event_for_contract_address(res.events)?;
let token_addr = deps.api.addr_validate(&addr)?;
let data: snip20_reference_impl::msg::ExecuteAnswer =
from_binary(&res.data.unwrap())?;
let mut viewing_key = String::new();
if let ExecuteAnswer::CreateViewingKey { key } = data {
viewing_key = key;
}
TOKEN_VIEWING_KEY.insert(deps.storage, &token_addr, &viewing_key)?;
Ok(Response::new().add_attribute("action", "create_token_viewing_key"))
ReplyEvent::Snip20ModuleCreateViewingKey { contract_address } => match msg.result {
SubMsgResult::Ok(res) => {
let token_addr = deps.api.addr_validate(&contract_address)?;
let data: snip20_reference_impl::msg::ExecuteAnswer =
from_binary(&res.data.unwrap())?;
let mut viewing_key = String::new();
if let ExecuteAnswer::CreateViewingKey { key } = data {
viewing_key = key;
}
SubMsgResult::Err(_) => Err(ContractError::TokenExecuteError {}),
TOKEN_VIEWING_KEY.insert(deps.storage, &token_addr, &viewing_key)?;
Ok(Response::new().add_attribute("action", "create_token_viewing_key"))
}
}
SubMsgResult::Err(_) => Err(ContractError::TokenExecuteError {}),
},
_ => Err(ContractError::UnknownReplyID {}),
}
}
Expand Down
2 changes: 1 addition & 1 deletion contracts/dao-dao-core/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::{Addr, StdError};
use secret_cw_controllers::ReplyError;
use dao_interface::ReplyError;
use secret_utils::ParseReplyError;
use thiserror::Error;

Expand Down
4 changes: 2 additions & 2 deletions contracts/dao-dao-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod error;
pub mod snip20_msg;
pub mod state;

// #[cfg(test)]
// mod tests;
#[cfg(test)]
mod tests;

pub use crate::error::ContractError;
2 changes: 1 addition & 1 deletion contracts/dao-dao-core/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cosmwasm_std::{Addr, Empty};
use dao_interface::ReplyIds;
use dao_interface::{
query::SubDao,
state::{Config, ProposalModule, VotingModuleInfo},
};
use secret_cw_controllers::ReplyIds;
use secret_storage_plus::Item;
use secret_toolkit::{serialization::Json, storage::Keymap};
use secret_utils::Expiration;
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-condorcet/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use cosmwasm_std::{
};

use dao_interface::state::AnyContractInfo;
use dao_interface::ReplyEvent;
use dao_voting::voting::{get_total_power, get_voting_power};
use secret_cw2::set_contract_version;
use secret_cw_controllers::ReplyEvent;
use shade_protocol::basic_staking::Auth;

use crate::config::UncheckedConfig;
Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-condorcet/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::StdError;
use dao_interface::ReplyError;
use dao_voting::{error::VotingError, reply::error::TagError, threshold::ThresholdError};
use secret_cw_controllers::ReplyError;
use secret_utils::ParseReplyError;
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-condorcet/src/proposal.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use cosmwasm_schema::cw_serde;
use cosmwasm_std::{Addr, BlockInfo, StdResult, Storage, SubMsg, Uint128};
use dao_interface::ReplyEvent;
use dao_voting::{threshold::PercentageThreshold, voting::does_vote_count_pass};
use secret_cw_controllers::ReplyEvent;
use secret_toolkit::utils::HandleCallback;
use secret_utils::Expiration;

Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-condorcet/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_std::{Addr, StdResult, Storage};
use dao_interface::state::AnyContractInfo;
use secret_cw_controllers::ReplyIds;
use dao_interface::ReplyIds;
use secret_storage_plus::Item;
use secret_toolkit::{serialization::Json, storage::Keymap};

Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-multiple/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use dao_hooks::proposal::{
use dao_hooks::vote::new_vote_hooks;
use dao_interface::state::{AnyContractInfo, VotingModuleInfo};
use dao_interface::voting::IsActiveResponse;
use dao_interface::ReplyEvent;
use dao_voting::veto::{VetoConfig, VetoError};
use dao_voting::{
multiple_choice::{
Expand All @@ -25,7 +26,6 @@ use dao_voting::{
voting::{get_total_power, get_voting_power, validate_voting_period},
};
use secret_cw2::set_contract_version;
use secret_cw_controllers::ReplyEvent;
use secret_toolkit::utils::HandleCallback;
use secret_utils::Duration;
use shade_protocol::basic_staking::{Auth, AuthPermit};
Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-multiple/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::u64;

use cosmwasm_std::StdError;
use cw_hooks::HookError;
use dao_interface::ReplyError;
use dao_voting::{reply::error::TagError, threshold::ThresholdError, veto::VetoError};
use secret_cw_controllers::ReplyError;
use secret_utils::ParseReplyError;
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-multiple/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::proposal::MultipleChoiceProposal;
use cosmwasm_std::{Addr, Uint128};
use cw_hooks::Hooks;
use dao_interface::state::AnyContractInfo;
use dao_interface::ReplyIds;
use dao_voting::{
multiple_choice::{MultipleChoiceVote, VotingStrategy},
pre_propose::ProposalCreationPolicy,
veto::VetoConfig,
};
use schemars::JsonSchema;
use secret_cw_controllers::ReplyIds;
use secret_storage_plus::Item;
use secret_toolkit::{serialization::Json, storage::Keymap};
use secret_utils::Duration;
Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-single/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use dao_hooks::proposal::{
use dao_hooks::vote::new_vote_hooks;
use dao_interface::state::{AnyContractInfo, VotingModuleInfo};
use dao_interface::voting::IsActiveResponse;
use dao_interface::ReplyEvent;
use dao_voting::pre_propose::{PreProposeInfo, ProposalCreationPolicy};
use dao_voting::proposal::{
SingleChoiceProposeMsg as ProposeMsg, DEFAULT_LIMIT, MAX_PROPOSAL_SIZE,
Expand All @@ -23,7 +24,6 @@ use dao_voting::threshold::Threshold;
use dao_voting::veto::{VetoConfig, VetoError};
use dao_voting::voting::{get_total_power, get_voting_power, validate_voting_period, Vote, Votes};
use secret_cw2::{get_contract_version, set_contract_version, ContractVersion};
use secret_cw_controllers::ReplyEvent;
use secret_toolkit::utils::HandleCallback;
use secret_utils::Duration;
use shade_protocol::basic_staking::{Auth, AuthPermit};
Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-single/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use std::u64;

use cosmwasm_std::StdError;
use cw_hooks::HookError;
use dao_interface::ReplyError;
use dao_voting::{reply::error::TagError, veto::VetoError};
use secret_cw_controllers::ReplyError;
use secret_utils::ParseReplyError;
use thiserror::Error;

Expand Down
2 changes: 1 addition & 1 deletion contracts/proposal/dao-proposal-single/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use cosmwasm_std::{Addr, Uint128};
use cw_hooks::Hooks;
use dao_interface::state::AnyContractInfo;
use dao_interface::ReplyIds;
use dao_voting::{
pre_propose::ProposalCreationPolicy, threshold::Threshold, veto::VetoConfig, voting::Vote,
};
use schemars::JsonSchema;
use secret_cw_controllers::ReplyIds;
use secret_storage_plus::{Item, Map};
use secret_toolkit::{serialization::Json, storage::Keymap};
use secret_utils::Duration;
Expand Down
4 changes: 4 additions & 0 deletions contracts/staking/snip20-stake-external-rewards/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ pub enum ExecuteMsg {
Receive(Snip20ReceiveMsg),
Fund { auth: Auth },
UpdateRewardDuration { new_duration: u64 },
// User viewing key for snip20 token.
// user need to create viewing key for snip20 token in token
// contract and set that viewing key here for further use
// like checking user token balance etc.
SetViewingKey { key: String },
}

Expand Down
2 changes: 0 additions & 2 deletions packages/controllers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ Supported controllers:
mod admin;
mod claim;
mod hooks;
mod replies;

pub use admin::{Admin, AdminError, AdminResponse};
pub use claim::{Claim, Claims, ClaimsResponse};
pub use hooks::{HookError, HookItem, Hooks, HooksResponse};
pub use replies::{ReplyError, ReplyEvent, ReplyIds};
2 changes: 2 additions & 0 deletions packages/dao-interface/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ secret-utils = { workspace = true }
serde ={ workspace = true }
schemars = {workspace = true}
shade-protocol ={ workspace = true }
thiserror = { workspace = true }


[dev-dependencies]
cosmwasm-schema = { workspace = true }
3 changes: 3 additions & 0 deletions packages/dao-interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ pub mod msg;
pub mod nft;
pub mod proposal;
pub mod query;
pub mod replies;
pub mod state;
// pub mod token;
pub mod voting;

pub use replies::{ReplyError, ReplyEvent, ReplyIds};
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub enum ReplyEvent {
ProposalModuleInstantiate {},
PreProposalModuleInstantiate {},
Snip20ModuleInstantiate {},
Snip20ModuleCreateViewingKey {},
Snip20ModuleCreateViewingKey { contract_address: String },
FailedPreProposeModuleHook {},
FailedVoteHook { idx: u64 },
FailedProposalHook { idx: u64 },
Expand Down
2 changes: 1 addition & 1 deletion packages/dao-voting/src/pre_propose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use cosmwasm_std::{Addr, Empty, StdResult, Storage, SubMsg};
use dao_interface::state::ModuleInstantiateInfo;
use dao_interface::{ReplyEvent, ReplyIds};
use schemars::JsonSchema;
use secret_cw_controllers::{ReplyEvent, ReplyIds};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
Expand Down
33 changes: 0 additions & 33 deletions packages/utils/Cargo.toml

This file was deleted.

14 changes: 0 additions & 14 deletions packages/utils/NOTICE

This file was deleted.

7 changes: 0 additions & 7 deletions packages/utils/README.md

This file was deleted.

Loading

0 comments on commit 79a90ac

Please sign in to comment.