Skip to content

Commit

Permalink
chore: minor tweaks to cosmwasm-std 1.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
PFC-developer committed Mar 26, 2024
1 parent 13bd187 commit de10dd9
Show file tree
Hide file tree
Showing 20 changed files with 265 additions and 307 deletions.
345 changes: 160 additions & 185 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions contracts/hub-tf/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pfc-steak-hub-tf"
version = "3.0.12"
version = "3.0.14"
authors = ["larry <[email protected]>", "PFC <[email protected]>"]
edition = "2018"
license = "GPL-3.0-or-later"
Expand All @@ -10,26 +10,26 @@ repository = "https://github.com/pfc-developer/steak-contracts"
crate-type = ["cdylib", "rlib"]

[features]
backtraces = ["cosmwasm-std/backtraces"]
#backtraces = ["cosmwasm-std/backtraces"]

[dependencies]
#cosmwasm-std = { version = "1.2.1", features=["iterator","stargate","cosmwasm_1_1","staking"]}
cosmwasm-std = { version = "1.0.1", features=["iterator","stargate","staking"]}
cosmwasm-std = { version = "1.5.3", features=["iterator","stargate","staking"]}

cw2= "1.0.1"
cw2= "1.1.2"
#cw20 = "1.0.0"
#cw20-base = { version = "1.0.0", features = ["library"] }
cw-storage-plus = "1.0.1"
cw-storage-plus = "1.2.0"
cw-ownable = "0.5.0"
cw-item-set = "0.7.0"
prost = {version = "0.11.0", default-features = false, features = ["prost-derive"]}
prost-types = {version = "0.11.1", default-features = false}
prost = {version = "0.12.3", default-features = false, features = ["prost-derive"]}
prost-types = {version = "0.12.3", default-features = false}
schemars = "0.8.11"
pfc-steak = { path = "../../packages/steak" }
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
pfc-fee-split = "0.2.5"
pfc-fee-split = "1.5.0"
pfc-dust-collector="0.1.0"
#{ path="../../packages/pfc-dust-collector" }
osmosis-std-derive="0.13.2"
osmosis-std-derive="0.15.3"
[dev-dependencies]
protobuf = { version = "3.1.0", features = ["with-bytes"] }
16 changes: 8 additions & 8 deletions contracts/hub-tf/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::convert::TryInto;

use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError,
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError,
StdResult,
};
use cw2::{get_contract_version, set_contract_version, ContractVersion};
Expand Down Expand Up @@ -160,24 +160,24 @@ pub fn reply(_deps: DepsMut, _env: Env, reply: Reply) -> StdResult<Response> {
#[entry_point]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Config {} => to_binary(&queries::config(deps)?),
QueryMsg::State {} => to_binary(&queries::state(deps, env)?),
QueryMsg::PendingBatch {} => to_binary(&queries::pending_batch(deps)?),
QueryMsg::PreviousBatch(id) => to_binary(&queries::previous_batch(deps, id)?),
QueryMsg::Config {} => to_json_binary(&queries::config(deps)?),
QueryMsg::State {} => to_json_binary(&queries::state(deps, env)?),
QueryMsg::PendingBatch {} => to_json_binary(&queries::pending_batch(deps)?),
QueryMsg::PreviousBatch(id) => to_json_binary(&queries::previous_batch(deps, id)?),
QueryMsg::PreviousBatches {
start_after,
limit,
} => to_binary(&queries::previous_batches(deps, start_after, limit)?),
} => to_json_binary(&queries::previous_batches(deps, start_after, limit)?),
QueryMsg::UnbondRequestsByBatch {
id,
start_after,
limit,
} => to_binary(&queries::unbond_requests_by_batch(deps, id, start_after, limit)?),
} => to_json_binary(&queries::unbond_requests_by_batch(deps, id, start_after, limit)?),
QueryMsg::UnbondRequestsByUser {
user,
start_after,
limit,
} => to_binary(&queries::unbond_requests_by_user(deps, user, start_after, limit)?),
} => to_json_binary(&queries::unbond_requests_by_user(deps, user, start_after, limit)?),
}
}

Expand Down
8 changes: 4 additions & 4 deletions contracts/hub-tf/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::HashSet, iter::FromIterator, str::FromStr};

use cosmwasm_std::{
to_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, DistributionMsg, Env, Event,
to_json_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, DepsMut, DistributionMsg, Env, Event,
Order, ReplyOn, Response, StdError, StdResult, SubMsg, Uint128, WasmMsg,
};
use pfc_steak::{
Expand Down Expand Up @@ -266,7 +266,7 @@ pub fn bond(
} else {
CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: receiver.to_string(),
msg: to_binary(&exec_msg)?,
msg: to_json_binary(&exec_msg)?,
funds: vec![Coin {
denom: steak_denom,
amount: usteak_to_mint,
Expand Down Expand Up @@ -543,7 +543,7 @@ pub fn queue_unbond(
if env.block.time.seconds() >= pending_batch.est_unbond_start_time {
msgs.push(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: env.contract.address.into(),
msg: to_binary(&ExecuteMsg::SubmitBatch {})?,
msg: to_json_binary(&ExecuteMsg::SubmitBatch {})?,
funds: vec![],
}));
}
Expand Down Expand Up @@ -1138,7 +1138,7 @@ pub fn collect_dust(deps: DepsMut, env: Env, max_tokens: usize) -> StdResult<Res
let msg = CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: dust_addr.to_string(),
funds: balances_filtered,
msg: to_binary(&pfc_dust_collector::dust_collector::ExecuteMsg::DustReceived {})?,
msg: to_json_binary(&pfc_dust_collector::dust_collector::ExecuteMsg::DustReceived {})?,
});
Ok(Response::new()
.add_attribute("dust", format!("sent {} tokens", balances_count))
Expand Down
2 changes: 1 addition & 1 deletion contracts/hub-tf/src/math.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub(crate) fn reconcile_batches(batches: &mut [Batch], native_to_deduct: Uint128

if !remaining_underflow.is_zero() {
// the remaining underflow will be applied by oldest batch first.
for (_, batch) in batches.iter_mut().enumerate() {
for batch in batches.iter_mut() {//} .enumerate() {
if !batch.amount_unclaimed.is_zero() && !remaining_underflow.is_zero() {
if batch.amount_unclaimed >= remaining_underflow {
batch.amount_unclaimed -= remaining_underflow;
Expand Down
4 changes: 2 additions & 2 deletions contracts/hub-tf/src/testing/custom_querier.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_std::{
from_slice,
from_json,
testing::{BankQuerier, StakingQuerier, MOCK_CONTRACT_ADDR},
Addr, Coin, Empty, FullDelegation, Querier, QuerierResult, QueryRequest, SystemError,
WasmQuery,
Expand All @@ -16,7 +16,7 @@ pub(super) struct CustomQuerier {

impl Querier for CustomQuerier {
fn raw_query(&self, bin_request: &[u8]) -> QuerierResult {
let request: QueryRequest<_> = match from_slice(bin_request) {
let request: QueryRequest<_> = match from_json(bin_request) {
Ok(v) => v,
Err(e) => {
return Err(SystemError::InvalidRequest {
Expand Down
9 changes: 2 additions & 7 deletions contracts/hub-tf/src/testing/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use cosmwasm_std::{
from_binary,
testing::{mock_env, MockApi, MockStorage, MOCK_CONTRACT_ADDR},
Addr, BlockInfo, ContractInfo, Deps, Env, OwnedDeps, QuerierResult, SystemError, SystemResult,
Timestamp,
};
use cosmwasm_std::{ testing::{mock_env, MockApi, MockStorage, MOCK_CONTRACT_ADDR}, Addr, BlockInfo, ContractInfo, Deps, Env, OwnedDeps, QuerierResult, SystemError, SystemResult, Timestamp, from_json};
use pfc_steak::hub::QueryMsg;
use serde::de::DeserializeOwned;

Expand Down Expand Up @@ -43,5 +38,5 @@ pub(super) fn mock_env_at_timestamp(timestamp: u64) -> Env {
pub(super) fn query_helper<T: DeserializeOwned>(deps: Deps, msg: QueryMsg) -> T {
let bin = query(deps, mock_env(), msg).unwrap();
//eprintln!("Query Response {:?}",&bin);
from_binary(&bin).unwrap()
from_json(&bin).unwrap()
}
61 changes: 24 additions & 37 deletions contracts/hub-tf/src/testing/tests.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
use std::str::FromStr;

use cosmwasm_std::{
testing::{mock_env, mock_info, MockApi, MockStorage, MOCK_CONTRACT_ADDR},
to_binary, Addr, BankMsg, Coin, CosmosMsg, Decimal, DistributionMsg, Order, OwnedDeps, ReplyOn,
StdError, SubMsg, Uint128, WasmMsg,
};
use cosmwasm_std::{testing::{mock_env, mock_info, MockApi, MockStorage, MOCK_CONTRACT_ADDR}, Addr, BankMsg, Coin, CosmosMsg, Decimal, DistributionMsg, Order, OwnedDeps, ReplyOn, StdError, SubMsg, Uint128, WasmMsg, to_json_binary};
use pfc_steak::{
hub::{
Batch, CallbackMsg, ConfigResponse, PendingBatch, QueryMsg, StateResponse, UnbondRequest,
Expand Down Expand Up @@ -381,7 +377,7 @@ fn harvesting() {
id: 0,
msg: CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: MOCK_CONTRACT_ADDR.to_string(),
msg: to_binary(&ExecuteMsg::Callback(CallbackMsg::Reinvest {})).unwrap(),
msg: to_json_binary(&ExecuteMsg::Callback(CallbackMsg::Reinvest {})).unwrap(),
funds: vec![],
}),
gas_limit: None,
Expand Down Expand Up @@ -608,7 +604,7 @@ fn queuing_unbond() {
id: 0,
msg: CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: MOCK_CONTRACT_ADDR.to_string(),
msg: to_binary(&ExecuteMsg::SubmitBatch {}).unwrap(),
msg: to_json_binary(&ExecuteMsg::SubmitBatch {}).unwrap(),
funds: vec![],
}),
gas_limit: None,
Expand Down Expand Up @@ -1068,12 +1064,11 @@ fn withdrawing_unbonded() {
);

let err = previous_batches().load(deps.as_ref().storage, 2u64.into()).unwrap_err();
assert_eq!(
err,
StdError::NotFound {
kind: "pfc_steak::hub::Batch".to_string()
}
);
match err { StdError::NotFound {..} => {}, _=> {
panic!("Should have been not found")
} };



// User 1's unbond requests in batches 1 and 2 should have been deleted
let err1 = unbond_requests()
Expand All @@ -1083,18 +1078,14 @@ fn withdrawing_unbonded() {
.load(deps.as_ref().storage, (1u64.into(), &Addr::unchecked("user_1").as_str()))
.unwrap_err();

assert_eq!(
err1,
StdError::NotFound {
kind: "pfc_steak::hub::UnbondRequest".to_string()
}
);
assert_eq!(
err2,
StdError::NotFound {
kind: "pfc_steak::hub::UnbondRequest".to_string()
}
);
match err1 { StdError::NotFound {..} => {}, _=> {
panic!("Should have been not found")
} };

match err2 { StdError::NotFound {..} => {}, _=> {
panic!("Should have been not found")
} };


// User 3 attempt to withdraw; also specifying a receiver
let res = execute(
Expand Down Expand Up @@ -1123,23 +1114,19 @@ fn withdrawing_unbonded() {

// Batch 1 and user 2's unbonding request should have been purged from storage
let err = previous_batches().load(deps.as_ref().storage, 1u64.into()).unwrap_err();
assert_eq!(
err,
StdError::NotFound {
kind: "pfc_steak::hub::Batch".to_string()
}
);
match err { StdError::NotFound {..} => {}, _=> {
panic!("Should have been not found")
} };


let err = unbond_requests()
.load(deps.as_ref().storage, (1u64.into(), &Addr::unchecked("user_3").as_str()))
.unwrap_err();

assert_eq!(
err,
StdError::NotFound {
kind: "pfc_steak::hub::UnbondRequest".to_string()
}
);
match err { StdError::NotFound {..} => {}, _=> {
panic!("Should have been not found")
} };

}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion contracts/hub-tf/src/types/coins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ impl Coins {
pub fn find(&self, denom: &str) -> Coin {
self.0
.iter()
.cloned()
.find(|coin| coin.denom == denom)
.cloned()
.unwrap_or_else(|| Coin::new(0, denom))
}
}
2 changes: 1 addition & 1 deletion contracts/hub/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pfc-steak-hub"
version = "3.0.11"
version = "3.0.14"
authors = ["larry <[email protected]>", "PFC <[email protected]>"]
edition = "2018"
license = "GPL-3.0-or-later"
Expand Down
18 changes: 9 additions & 9 deletions contracts/hub/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::convert::TryInto;

use cosmwasm_std::{
entry_point, from_binary, to_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Reply,
entry_point, from_json, to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Reply,
Response, StdError, StdResult,
};
use cw2::{get_contract_version, set_contract_version, ContractVersion};
Expand Down Expand Up @@ -138,7 +138,7 @@ fn receive(
cw20_msg: Cw20ReceiveMsg,
) -> StdResult<Response> {
let api = deps.api;
match from_binary(&cw20_msg.msg)? {
match from_json(&cw20_msg.msg)? {
ReceiveMsg::QueueUnbond {
receiver,
} => {
Expand Down Expand Up @@ -191,24 +191,24 @@ pub fn reply(deps: DepsMut, env: Env, reply: Reply) -> StdResult<Response> {
#[entry_point]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Config {} => to_binary(&queries::config(deps)?),
QueryMsg::State {} => to_binary(&queries::state(deps, env)?),
QueryMsg::PendingBatch {} => to_binary(&queries::pending_batch(deps)?),
QueryMsg::PreviousBatch(id) => to_binary(&queries::previous_batch(deps, id)?),
QueryMsg::Config {} => to_json_binary(&queries::config(deps)?),
QueryMsg::State {} => to_json_binary(&queries::state(deps, env)?),
QueryMsg::PendingBatch {} => to_json_binary(&queries::pending_batch(deps)?),
QueryMsg::PreviousBatch(id) => to_json_binary(&queries::previous_batch(deps, id)?),
QueryMsg::PreviousBatches {
start_after,
limit,
} => to_binary(&queries::previous_batches(deps, start_after, limit)?),
} => to_json_binary(&queries::previous_batches(deps, start_after, limit)?),
QueryMsg::UnbondRequestsByBatch {
id,
start_after,
limit,
} => to_binary(&queries::unbond_requests_by_batch(deps, id, start_after, limit)?),
} => to_json_binary(&queries::unbond_requests_by_batch(deps, id, start_after, limit)?),
QueryMsg::UnbondRequestsByUser {
user,
start_after,
limit,
} => to_binary(&queries::unbond_requests_by_user(deps, user, start_after, limit)?),
} => to_json_binary(&queries::unbond_requests_by_user(deps, user, start_after, limit)?),
}
}

Expand Down
Loading

0 comments on commit de10dd9

Please sign in to comment.