Skip to content

Commit

Permalink
Merge pull request #36 from WHELP-project/contracts/refactor-deprecat…
Browse files Browse the repository at this point in the history
…ed-functions

Refactor: Fix clippy lints and remove deprecated library functions
  • Loading branch information
ueco-jb authored Dec 1, 2023
2 parents 7cea57c + 343ec25 commit 7574127
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 196 deletions.
22 changes: 11 additions & 11 deletions contracts/pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use coreum_wasm_sdk::{
core::{CoreumMsg, CoreumQueries},
};
use cosmwasm_std::{
attr, coin, ensure, entry_point, from_binary, to_binary, Addr, BankMsg, Binary, Coin,
attr, coin, ensure, entry_point, from_json, to_json_binary, Addr, BankMsg, Binary, Coin,
CosmosMsg, Decimal, Decimal256, Deps, DepsMut, Env, Isqrt, MessageInfo, Reply, StdError,
StdResult, Uint128, Uint256, WasmMsg,
};
Expand Down Expand Up @@ -99,7 +99,7 @@ pub fn instantiate(
.add_submessage(SubMsg::reply_on_success(
WasmMsg::Instantiate {
code_id: msg.staking_config.staking_code_id,
msg: to_binary(&dex::stake::InstantiateMsg {
msg: to_json_binary(&dex::stake::InstantiateMsg {
lp_share_denom,
tokens_per_power: msg.staking_config.tokens_per_power,
min_bond: msg.staking_config.min_bond,
Expand Down Expand Up @@ -242,7 +242,7 @@ pub fn receive_cw20(
info: MessageInfo,
cw20_msg: Cw20ReceiveMsg,
) -> Result<Response, ContractError> {
match from_binary(&cw20_msg.msg)? {
match from_json(&cw20_msg.msg)? {
Cw20HookMsg::Swap {
belief_price,
max_spread,
Expand Down Expand Up @@ -919,15 +919,15 @@ pub fn calculate_protocol_fee(
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<CoreumQueries>, env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::Pair {} => to_binary(&CONFIG.load(deps.storage)?.pool_info),
QueryMsg::Pool {} => to_binary(&query_pool(deps)?),
QueryMsg::Share { amount } => to_binary(&query_share(deps, amount)?),
QueryMsg::Pair {} => to_json_binary(&CONFIG.load(deps.storage)?.pool_info),
QueryMsg::Pool {} => to_json_binary(&query_pool(deps)?),
QueryMsg::Share { amount } => to_json_binary(&query_share(deps, amount)?),
QueryMsg::Simulation {
offer_asset,
referral,
referral_commission,
..
} => to_binary(&query_simulation(
} => to_json_binary(&query_simulation(
deps,
offer_asset,
referral,
Expand All @@ -938,26 +938,26 @@ pub fn query(deps: Deps<CoreumQueries>, env: Env, msg: QueryMsg) -> StdResult<Bi
referral,
referral_commission,
..
} => to_binary(&query_reverse_simulation(
} => to_json_binary(&query_reverse_simulation(
deps,
ask_asset,
referral,
referral_commission,
)?),
QueryMsg::CumulativePrices {} => to_binary(&query_cumulative_prices(deps, env)?),
QueryMsg::CumulativePrices {} => to_json_binary(&query_cumulative_prices(deps, env)?),
QueryMsg::Twap {
duration,
start_age,
end_age,
} => to_binary(&dex::oracle::query_oracle_range(
} => to_json_binary(&dex::oracle::query_oracle_range(
deps.storage,
&env,
&CONFIG.load(deps.storage)?.pool_info.asset_infos,
duration,
start_age,
end_age,
)?),
QueryMsg::Config {} => to_binary(&query_config(deps)?),
QueryMsg::Config {} => to_json_binary(&query_config(deps)?),
_ => Err(StdError::generic_err("Query is not supported")),
}
}
Expand Down
18 changes: 9 additions & 9 deletions contracts/pool/src/mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::marker::PhantomData;
use coreum_wasm_sdk::core::CoreumQueries;
use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR};
use cosmwasm_std::{
from_binary, from_slice, to_binary, Addr, Coin, Decimal, OwnedDeps, Querier, QuerierResult,
from_json, to_json_binary, Addr, Coin, Decimal, OwnedDeps, Querier, QuerierResult,
QueryRequest, SystemError, SystemResult, Uint128, WasmQuery,
};

Expand Down Expand Up @@ -67,7 +67,7 @@ pub(crate) fn balances_to_map(
impl Querier for WasmMockQuerier {
fn raw_query(&self, bin_request: &[u8]) -> QuerierResult {
// MockQuerier doesn't support Custom, so we ignore it completely
let request: QueryRequest<CoreumQueries> = match from_slice(bin_request) {
let request: QueryRequest<CoreumQueries> = match from_json(bin_request) {
Ok(v) => v,
Err(e) => {
return SystemResult::Err(SystemError::InvalidRequest {
Expand All @@ -85,17 +85,17 @@ impl WasmMockQuerier {
match &request {
QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => {
if contract_addr == "factory" {
match from_binary(msg).unwrap() {
match from_json(msg).unwrap() {
FeeInfo { .. } => SystemResult::Ok(
to_binary(&FeeInfoResponse {
to_json_binary(&FeeInfoResponse {
fee_address: Some(Addr::unchecked("fee_address")),
total_fee_bps: 30,
protocol_fee_bps: 1660,
})
.into(),
),
Config {} => SystemResult::Ok(
to_binary(&ConfigResponse {
to_json_binary(&ConfigResponse {
owner: Addr::unchecked("owner"),
pool_configs: vec![],
token_code_id: 0,
Expand All @@ -109,7 +109,7 @@ impl WasmMockQuerier {
_ => panic!("DO NOT ENTER HERE"),
}
} else {
match from_binary(msg).unwrap() {
match from_json(msg).unwrap() {
Cw20QueryMsg::TokenInfo {} => {
let balances: &HashMap<String, Uint128> =
match self.token_querier.balances.get(contract_addr) {
Expand All @@ -126,7 +126,7 @@ impl WasmMockQuerier {
}

SystemResult::Ok(
to_binary(&TokenInfoResponse {
to_json_binary(&TokenInfoResponse {
name: "mAPPL".to_string(),
symbol: "mAPPL".to_string(),
decimals: 6,
Expand All @@ -152,7 +152,7 @@ impl WasmMockQuerier {
};

SystemResult::Ok(
to_binary(&BalanceResponse { balance: *balance }).into(),
to_json_binary(&BalanceResponse { balance: *balance }).into(),
)
}
_ => panic!("DO NOT ENTER HERE"),
Expand All @@ -161,7 +161,7 @@ impl WasmMockQuerier {
}
QueryRequest::Wasm(WasmQuery::Raw { contract_addr, .. }) => {
if contract_addr == "factory" {
SystemResult::Ok(to_binary(&Vec::<Addr>::new()).into())
SystemResult::Ok(to_json_binary(&Vec::<Addr>::new()).into())
} else {
panic!("DO NOT ENTER HERE");
}
Expand Down
24 changes: 12 additions & 12 deletions contracts/pool/src/testing.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use coreum_wasm_sdk::{assetft, core::CoreumMsg};
use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR};
use cosmwasm_std::{
assert_approx_eq, attr, coin, coins, from_binary, to_binary, Addr, BankMsg, BlockInfo, Coin,
assert_approx_eq, attr, coin, coins, from_json, to_json_binary, Addr, BankMsg, BlockInfo, Coin,
CosmosMsg, Decimal, Env, Fraction, ReplyOn, StdError, Timestamp, Uint128, WasmMsg,
};
use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg};
Expand Down Expand Up @@ -96,7 +96,7 @@ fn proper_initialization() {
code_id: 11,
funds: vec![],
label: "Dex-Stake".to_owned(),
msg: to_binary(&dex::stake::InstantiateMsg {
msg: to_json_binary(&dex::stake::InstantiateMsg {
lp_share_denom: "uuusdmapplp-cosmos2contract".to_owned(),
tokens_per_power: Uint128::new(1000),
min_bond: Uint128::new(1000),
Expand Down Expand Up @@ -309,7 +309,7 @@ fn test_freezing_a_pool_blocking_actions_then_unfreeze() {
let msg = ExecuteMsg::Receive(Cw20ReceiveMsg {
sender: String::from("addr0000"),
amount: offer_amount,
msg: to_binary(&Cw20HookMsg::Swap {
msg: to_json_binary(&Cw20HookMsg::Swap {
ask_asset_info: None,
belief_price: None,
max_spread: Some(Decimal::percent(50)),
Expand Down Expand Up @@ -402,7 +402,7 @@ fn test_freezing_a_pool_blocking_actions_then_unfreeze() {
let msg = ExecuteMsg::Receive(Cw20ReceiveMsg {
sender: String::from("addr0000"),
amount: offer_amount,
msg: to_binary(&Cw20HookMsg::Swap {
msg: to_json_binary(&Cw20HookMsg::Swap {
ask_asset_info: None,
belief_price: None,
max_spread: Some(Decimal::percent(50)),
Expand Down Expand Up @@ -489,7 +489,7 @@ fn provide_liquidity() {
&SubMsg {
msg: WasmMsg::Execute {
contract_addr: String::from("asset0000"),
msg: to_binary(&Cw20ExecuteMsg::TransferFrom {
msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom {
owner: String::from("addr0000"),
recipient: String::from(MOCK_CONTRACT_ADDR),
amount: Uint128::from(100_000000000000000000u128),
Expand Down Expand Up @@ -592,7 +592,7 @@ fn provide_liquidity() {
&SubMsg {
msg: WasmMsg::Execute {
contract_addr: String::from("asset0000"),
msg: to_binary(&Cw20ExecuteMsg::TransferFrom {
msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom {
owner: String::from("addr0000"),
recipient: String::from(MOCK_CONTRACT_ADDR),
amount: Uint128::from(100_000000000000000000u128),
Expand Down Expand Up @@ -979,7 +979,7 @@ fn withdraw_liquidity() {
&SubMsg {
msg: WasmMsg::Execute {
contract_addr: String::from("asset0000"),
msg: to_binary(&Cw20ExecuteMsg::Transfer {
msg: to_json_binary(&Cw20ExecuteMsg::Transfer {
recipient: String::from("addr0000"),
amount: Uint128::from(100u128),
})
Expand Down Expand Up @@ -1141,8 +1141,8 @@ fn query_twap() {
env.block.time = env.block.time.plus_seconds(HALF_HOUR);

// query twap after swap price change
let twap: TwapResponse = from_binary(
&query(
let twap: TwapResponse = from_json(
query(
deps.as_ref(),
env,
QueryMsg::Twap {
Expand Down Expand Up @@ -1369,7 +1369,7 @@ fn try_native_to_token() {
&SubMsg {
msg: WasmMsg::Execute {
contract_addr: String::from("asset0000"),
msg: to_binary(&Cw20ExecuteMsg::Transfer {
msg: to_json_binary(&Cw20ExecuteMsg::Transfer {
recipient: String::from("addr0000"),
amount: expected_return_amount,
})
Expand Down Expand Up @@ -1462,7 +1462,7 @@ fn try_token_to_native() {
let msg = ExecuteMsg::Receive(Cw20ReceiveMsg {
sender: String::from("addr0000"),
amount: offer_amount,
msg: to_binary(&Cw20HookMsg::Swap {
msg: to_json_binary(&Cw20HookMsg::Swap {
ask_asset_info: None,
belief_price: None,
max_spread: Some(Decimal::percent(50)),
Expand Down Expand Up @@ -1588,7 +1588,7 @@ fn try_token_to_native() {
let msg = ExecuteMsg::Receive(Cw20ReceiveMsg {
sender: String::from("addr0000"),
amount: offer_amount,
msg: to_binary(&Cw20HookMsg::Swap {
msg: to_json_binary(&Cw20HookMsg::Swap {
ask_asset_info: None,
belief_price: None,
max_spread: None,
Expand Down
Loading

0 comments on commit 7574127

Please sign in to comment.