From bc54640bff3d3269d26380ea0d60e697bc5e1eb0 Mon Sep 17 00:00:00 2001 From: Kerber0x Date: Tue, 16 Jan 2024 11:28:44 +0000 Subject: [PATCH] chore: make clippy happy --- .../epoch-manager/src/contract.rs | 8 +- .../fee-distributor-mock/src/contract.rs | 6 +- .../fee_collector/src/commands.rs | 32 +-- .../fee_collector/src/contract.rs | 10 +- .../fee_collector/src/queries.rs | 15 +- .../fee_collector/src/tests/dummy_contract.rs | 4 +- .../fee_collector/src/tests/integration.rs | 42 +--- .../fee_collector/src/tests/testing.rs | 10 +- .../fee_distributor/src/commands.rs | 8 +- .../fee_distributor/src/contract.rs | 18 +- .../fee_distributor/src/migrations.rs | 6 +- .../fee_distributor/src/state.rs | 4 +- .../fee_distributor/src/tests/robot.rs | 10 +- .../frontend_helper/src/contract.rs | 11 +- .../frontend_helper/src/reply/deposit_pair.rs | 6 +- .../frontend_helper/src/testing.rs | 6 +- .../src/tests/mock_instantiate.rs | 91 ++++---- .../pool-network/incentive/src/claim.rs | 4 +- .../pool-network/incentive/src/contract.rs | 28 +-- .../incentive/src/execute/close_flow.rs | 5 +- .../incentive/src/execute/expand_flow.rs | 4 +- .../incentive/src/execute/open_flow.rs | 10 +- .../incentive/src/funds_validation.rs | 4 +- .../incentive/src/tests/mock_instantiate.rs | 4 +- .../incentive_factory/src/contract.rs | 10 +- .../src/execute/create_incentive.rs | 4 +- .../src/execute/migrate_incentive.rs | 4 +- .../src/execute/update_config.rs | 6 +- .../src/queries/get_incentives.rs | 4 +- .../src/reply/create_incentive_reply.rs | 4 +- .../stableswap_3pool/src/commands.rs | 14 +- .../stableswap_3pool/src/contract.rs | 16 +- .../stableswap_3pool/src/helpers.rs | 8 +- .../src/tests/feature_toggle.rs | 6 +- .../src/tests/protocol_fees.rs | 12 +- .../src/tests/provide_liquidity.rs | 12 +- .../stableswap_3pool/src/tests/swap.rs | 22 +- .../stableswap_3pool/src/tests/testing.rs | 8 +- .../stableswap_3pool/src/tests/withdrawals.rs | 14 +- .../terraswap_factory/src/commands.rs | 10 +- .../terraswap_factory/src/contract.rs | 14 +- .../terraswap_factory/src/testing.rs | 40 ++-- .../terraswap_pair/src/commands.rs | 24 +- .../terraswap_pair/src/contract.rs | 22 +- .../terraswap_pair/src/helpers.rs | 6 +- .../terraswap_pair/src/migrations.rs | 2 +- .../src/tests/feature_toggle.rs | 6 +- .../terraswap_pair/src/tests/protocol_fees.rs | 8 +- .../src/tests/provide_liquidity.rs | 12 +- .../terraswap_pair/src/tests/swap.rs | 30 +-- .../terraswap_pair/src/tests/testing.rs | 8 +- .../terraswap_pair/src/tests/withdrawals.rs | 20 +- .../terraswap_router/src/contract.rs | 18 +- .../terraswap_router/src/operations.rs | 9 +- .../terraswap_router/src/testing/tests.rs | 45 ++-- .../vault-network/vault/src/contract.rs | 4 +- .../vault/src/execute/callback/after_trade.rs | 5 +- .../vault/src/execute/deposit.rs | 20 +- .../vault/src/execute/flash_loan.rs | 46 ++-- .../vault/src/execute/receive/mod.rs | 10 +- .../vault/src/execute/receive/withdraw.rs | 50 +++-- .../vault/src/queries/get_config.rs | 8 +- .../vault/src/queries/get_payback_amount.rs | 8 +- .../vault/src/queries/get_protocol_fees.rs | 15 +- .../vault/src/queries/get_share.rs | 10 +- .../vault/src/tests/mock_dependencies_lp.rs | 18 +- .../vault_factory/src/execute/create_vault.rs | 15 +- .../src/execute/migrate_vaults.rs | 4 +- .../src/execute/update_config.rs | 10 +- .../vault_factory/src/queries/config.rs | 4 +- .../vault_factory/src/queries/vault.rs | 8 +- .../vault_factory/src/tests/mock_query.rs | 4 +- .../vault_router/src/execute/complete_loan.rs | 7 +- .../vault_router/src/execute/flash_loan.rs | 16 +- .../vault_router/src/execute/next_loan.rs | 8 +- .../vault_router/src/queries/config.rs | 4 +- .../vault_router/src/tests/mock_query.rs | 4 +- .../liquidity_hub/whale_lair/src/contract.rs | 16 +- .../liquidity_hub/whale_lair/src/queries.rs | 6 +- .../white-whale/src/epoch_manager/hooks.rs | 8 +- .../white-whale/src/pool_network/asset.rs | 6 +- .../src/pool_network/mock_querier.rs | 206 +++++++++--------- packages/white-whale/src/pool_network/pair.rs | 19 +- .../white-whale/src/pool_network/querier.rs | 18 +- .../white-whale/src/pool_network/testing.rs | 8 +- packages/white-whale/src/pool_network/trio.rs | 19 +- 86 files changed, 654 insertions(+), 694 deletions(-) diff --git a/contracts/liquidity_hub/epoch-manager/src/contract.rs b/contracts/liquidity_hub/epoch-manager/src/contract.rs index 0f2fc474..8421f12b 100644 --- a/contracts/liquidity_hub/epoch-manager/src/contract.rs +++ b/contracts/liquidity_hub/epoch-manager/src/contract.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{entry_point, to_binary, StdError}; +use cosmwasm_std::{entry_point, to_json_binary, StdError}; use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::{get_contract_version, set_contract_version}; use semver::Version; @@ -79,9 +79,9 @@ pub fn execute( #[entry_point] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Config {} => Ok(to_binary(&queries::query_config(deps)?)?), - QueryMsg::CurrentEpoch {} => Ok(to_binary(&queries::query_current_epoch(deps)?)?), - QueryMsg::Epoch { id } => Ok(to_binary(&queries::query_epoch(deps, id)?)?), + QueryMsg::Config {} => Ok(to_json_binary(&queries::query_config(deps)?)?), + QueryMsg::CurrentEpoch {} => Ok(to_json_binary(&queries::query_current_epoch(deps)?)?), + QueryMsg::Epoch { id } => Ok(to_json_binary(&queries::query_epoch(deps, id)?)?), } } diff --git a/contracts/liquidity_hub/fee-distributor-mock/src/contract.rs b/contracts/liquidity_hub/fee-distributor-mock/src/contract.rs index b3e2964c..d2486011 100644 --- a/contracts/liquidity_hub/fee-distributor-mock/src/contract.rs +++ b/contracts/liquidity_hub/fee-distributor-mock/src/contract.rs @@ -1,6 +1,6 @@ use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint64, + to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint64, }; use white_whale::fee_distributor::EpochResponse; @@ -71,7 +71,7 @@ pub fn query( match msg { white_whale::fee_distributor::QueryMsg::Config {} => {} white_whale::fee_distributor::QueryMsg::CurrentEpoch {} => { - return to_binary(&EpochResponse { + return to_json_binary(&EpochResponse { epoch: CURRENT_EPOCH.load(deps.storage)?, }); } @@ -80,5 +80,5 @@ pub fn query( white_whale::fee_distributor::QueryMsg::Claimable { .. } => {} } - to_binary(&"") + to_json_binary(&"") } diff --git a/contracts/liquidity_hub/fee_collector/src/commands.rs b/contracts/liquidity_hub/fee_collector/src/commands.rs index 44047ff3..3a3f082b 100644 --- a/contracts/liquidity_hub/fee_collector/src/commands.rs +++ b/contracts/liquidity_hub/fee_collector/src/commands.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - to_binary, Addr, BalanceResponse, BankQuery, Coin, CosmosMsg, Decimal, DepsMut, Env, + to_json_binary, Addr, BalanceResponse, BankQuery, Coin, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, QueryRequest, ReplyOn, Response, StdResult, SubMsg, Uint128, WasmMsg, WasmQuery, }; use cw20::{Cw20ExecuteMsg, Cw20QueryMsg}; @@ -49,10 +49,10 @@ pub fn collect_fees(deps: DepsMut, collect_fees_for: FeesFor) -> Result StdResult { let collect_protocol_fees_msg = match contract_type { ContractType::Vault {} => { - to_binary(&white_whale::vault_network::vault::ExecuteMsg::CollectProtocolFees {})? + to_json_binary(&white_whale::vault_network::vault::ExecuteMsg::CollectProtocolFees {})? } ContractType::Pool {} => { - to_binary(&white_whale::pool_network::pair::ExecuteMsg::CollectProtocolFees {})? + to_json_binary(&white_whale::pool_network::pair::ExecuteMsg::CollectProtocolFees {})? } }; @@ -76,7 +76,7 @@ fn collect_fees_for_factory( let response: VaultsResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: factory.to_string(), - msg: to_binary( + msg: to_json_binary( &white_whale::vault_network::vault_factory::QueryMsg::Vaults { start_after, limit, @@ -95,7 +95,7 @@ fn collect_fees_for_factory( let response: PairsResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: factory.to_string(), - msg: to_binary(&QueryMsg::Pairs { start_after, limit })?, + msg: to_json_binary(&QueryMsg::Pairs { start_after, limit })?, }))?; for pair in response.pairs { @@ -182,7 +182,7 @@ pub fn aggregate_fees( let response: VaultsResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: factory.to_string(), - msg: to_binary( + msg: to_json_binary( &white_whale::vault_network::vault_factory::QueryMsg::Vaults { start_after, limit, @@ -198,7 +198,7 @@ pub fn aggregate_fees( let response: PairsResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: factory.to_string(), - msg: to_binary(&QueryMsg::Pairs { start_after, limit })?, + msg: to_json_binary(&QueryMsg::Pairs { start_after, limit })?, }))?; for pair in response.pairs { @@ -224,7 +224,7 @@ pub fn aggregate_fees( let balance_response: cw20::BalanceResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: contract_addr.to_string(), - msg: to_binary(&Cw20QueryMsg::Balance { + msg: to_json_binary(&Cw20QueryMsg::Balance { address: env.contract.address.to_string(), })?, }))?; @@ -234,7 +234,7 @@ pub fn aggregate_fees( // Increase the allowance for the cw20 token so the router can perform the swap aggregate_fees_messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract_addr.to_string(), - msg: to_binary(&Cw20ExecuteMsg::IncreaseAllowance { + msg: to_json_binary(&Cw20ExecuteMsg::IncreaseAllowance { spender: config.pool_router.to_string(), amount: balance_response.balance, expires: None, @@ -261,7 +261,7 @@ pub fn aggregate_fees( let operations_res: StdResult> = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: config.pool_router.to_string(), - msg: to_binary(&router::QueryMsg::SwapRoute { + msg: to_json_binary(&router::QueryMsg::SwapRoute { offer_asset_info: offer_asset_info.clone(), ask_asset_info: ask_asset_info.clone(), })?, @@ -270,7 +270,7 @@ pub fn aggregate_fees( match operations_res { Ok(operations) => { let execute_swap_operations_msg = - to_binary(&router::ExecuteMsg::ExecuteSwapOperations { + to_json_binary(&router::ExecuteMsg::ExecuteSwapOperations { operations, minimum_receive: None, to: None, @@ -282,7 +282,7 @@ pub fn aggregate_fees( aggregate_fees_messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr, funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::Send { + msg: to_json_binary(&Cw20ExecuteMsg::Send { contract: config.pool_router.to_string(), amount: balance, msg: execute_swap_operations_msg, @@ -336,7 +336,7 @@ pub fn forward_fees( msg: CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: env.contract.address.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::CollectFees { + msg: to_json_binary(&ExecuteMsg::CollectFees { collect_fees_for: FeesFor::Factory { factory_addr: config.vault_factory.to_string(), factory_type: FactoryType::Vault { @@ -355,7 +355,7 @@ pub fn forward_fees( msg: CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: env.contract.address.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::CollectFees { + msg: to_json_binary(&ExecuteMsg::CollectFees { collect_fees_for: FeesFor::Factory { factory_addr: config.pool_factory.to_string(), factory_type: FactoryType::Pool { @@ -375,7 +375,7 @@ pub fn forward_fees( msg: CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: env.contract.address.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::AggregateFees { + msg: to_json_binary(&ExecuteMsg::AggregateFees { aggregate_fees_for: FeesFor::Factory { factory_addr: config.vault_factory.to_string(), factory_type: FactoryType::Vault { @@ -394,7 +394,7 @@ pub fn forward_fees( msg: CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: env.contract.address.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::AggregateFees { + msg: to_json_binary(&ExecuteMsg::AggregateFees { aggregate_fees_for: FeesFor::Factory { factory_addr: config.pool_factory.to_string(), factory_type: FactoryType::Pool { diff --git a/contracts/liquidity_hub/fee_collector/src/contract.rs b/contracts/liquidity_hub/fee_collector/src/contract.rs index f6e0dfd4..c7e8a1c0 100644 --- a/contracts/liquidity_hub/fee_collector/src/contract.rs +++ b/contracts/liquidity_hub/fee_collector/src/contract.rs @@ -1,8 +1,8 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Addr, BalanceResponse, BankMsg, BankQuery, Binary, CosmosMsg, Deps, DepsMut, Env, - MessageInfo, QueryRequest, Reply, Response, StdResult, Uint128, + to_json_binary, Addr, BalanceResponse, BankMsg, BankQuery, Binary, CosmosMsg, Deps, DepsMut, + Env, MessageInfo, QueryRequest, Reply, Response, StdResult, Uint128, }; use cw2::{get_contract_version, set_contract_version}; use semver::Version; @@ -96,7 +96,7 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result StdResult { match msg { - QueryMsg::Config {} => to_binary(&queries::query_config(deps)?), + QueryMsg::Config {} => to_json_binary(&queries::query_config(deps)?), QueryMsg::Fees { query_fees_for, all_time, - } => to_binary(&queries::query_fees( + } => to_json_binary(&queries::query_fees( deps, query_fees_for, all_time.unwrap_or(false), diff --git a/contracts/liquidity_hub/fee_collector/src/queries.rs b/contracts/liquidity_hub/fee_collector/src/queries.rs index fb436ee3..050539ed 100644 --- a/contracts/liquidity_hub/fee_collector/src/queries.rs +++ b/contracts/liquidity_hub/fee_collector/src/queries.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Addr, Deps, QueryRequest, StdResult, WasmQuery}; +use cosmwasm_std::{to_json_binary, Addr, Deps, QueryRequest, StdResult, WasmQuery}; use white_whale::fee_collector::{Config, ContractType, FactoryType, FeesFor}; use white_whale::pool_network; @@ -75,7 +75,7 @@ fn query_fees_for_vault(deps: &Deps, vault: String, all_time: bool) -> StdResult .querier .query::(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: vault, - msg: to_binary(&white_whale::vault_network::vault::QueryMsg::ProtocolFees { + msg: to_json_binary(&white_whale::vault_network::vault::QueryMsg::ProtocolFees { all_time, })?, }))? @@ -90,7 +90,7 @@ fn query_fees_for_pair(deps: &Deps, pair: String, all_time: bool) -> StdResult(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: pair, - msg: to_binary(&pool_network::pair::QueryMsg::ProtocolFees { + msg: to_json_binary(&pool_network::pair::QueryMsg::ProtocolFees { all_time: Some(all_time), asset_id: None, })?, @@ -114,7 +114,7 @@ fn query_fees_for_factory( let response: VaultsResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: factory.to_string(), - msg: to_binary( + msg: to_json_binary( &white_whale::vault_network::vault_factory::QueryMsg::Vaults { start_after, limit, @@ -131,7 +131,10 @@ fn query_fees_for_factory( let response: PairsResponse = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: factory.to_string(), - msg: to_binary(&pool_network::factory::QueryMsg::Pairs { start_after, limit })?, + msg: to_json_binary(&pool_network::factory::QueryMsg::Pairs { + start_after, + limit, + })?, }))?; for pair in response.pairs { @@ -151,7 +154,7 @@ pub(crate) fn query_distribution_asset(deps: Deps) -> StdResult { let fee_distributor_config: white_whale::fee_distributor::Config = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: config.fee_distributor.to_string(), - msg: to_binary(&white_whale::fee_distributor::QueryMsg::Config {})?, + msg: to_json_binary(&white_whale::fee_distributor::QueryMsg::Config {})?, }))?; Ok(fee_distributor_config.distribution_asset) diff --git a/contracts/liquidity_hub/fee_collector/src/tests/dummy_contract.rs b/contracts/liquidity_hub/fee_collector/src/tests/dummy_contract.rs index 5dbd012a..db210ec5 100644 --- a/contracts/liquidity_hub/fee_collector/src/tests/dummy_contract.rs +++ b/contracts/liquidity_hub/fee_collector/src/tests/dummy_contract.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Addr, BankMsg, Coin, Response}; +use cosmwasm_std::{to_json_binary, Addr, BankMsg, Coin, Response}; use cw_multi_test::ContractWrapper; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -28,6 +28,6 @@ pub fn create_dummy_flash_loan_contract( } }, |_deps, _env, _info, _msg| Ok(Response::new()), - |_deps, _env, _query| Ok(to_binary::>(&vec![]).unwrap()), + |_deps, _env, _query| Ok(to_json_binary::>(&vec![]).unwrap()), ) } diff --git a/contracts/liquidity_hub/fee_collector/src/tests/integration.rs b/contracts/liquidity_hub/fee_collector/src/tests/integration.rs index 6b3007b9..11de53d9 100644 --- a/contracts/liquidity_hub/fee_collector/src/tests/integration.rs +++ b/contracts/liquidity_hub/fee_collector/src/tests/integration.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; use cosmwasm_std::{ - coin, coins, to_binary, Addr, BankMsg, BlockInfo, Coin, Decimal, Timestamp, Uint128, Uint256, - Uint64, + coin, coins, to_json_binary, Addr, BankMsg, BlockInfo, Coin, Decimal, Timestamp, Uint128, + Uint256, Uint64, }; use cw20::{BalanceResponse, Cw20Coin, Cw20ExecuteMsg, MinterResponse}; use cw_multi_test::Executor; @@ -61,19 +61,6 @@ fn collect_all_factories_cw20_fees_successfully() { ) .unwrap(); - #[cfg(feature = "osmosis")] - let osmosis_fee_collector_address = app - .instantiate_contract( - fee_collector_id, - creator.clone().sender, - &InstantiateMsg {}, - &[], - "osmosis_fee_collector", - None, - ) - .unwrap(); - - #[cfg(not(feature = "osmosis"))] let instantiate_msg = pool_network::factory::InstantiateMsg { pair_code_id: pair_id, trio_code_id: trio_id, @@ -81,15 +68,6 @@ fn collect_all_factories_cw20_fees_successfully() { fee_collector_addr: fee_collector_address.to_string(), }; - #[cfg(feature = "osmosis")] - let instantiate_msg = pool_network::factory::InstantiateMsg { - pair_code_id: pair_id, - trio_code_id: trio_id, - token_code_id: token_id, - fee_collector_addr: fee_collector_address.to_string(), - osmosis_fee_collector_addr: osmosis_fee_collector_address.to_string(), - }; - let pool_factory_address = app .instantiate_contract( pool_factory_id, @@ -299,7 +277,7 @@ fn collect_all_factories_cw20_fees_successfully() { &Cw20ExecuteMsg::Send { contract: pair_tokens[i as usize - 1].to_string(), amount: Uint128::new(100_000_000u128), - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread: None, to: None, @@ -316,7 +294,7 @@ fn collect_all_factories_cw20_fees_successfully() { &Cw20ExecuteMsg::Send { contract: pair_tokens[i as usize].to_string(), amount: Uint128::new(200_000_000_000u128), - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread: Some(Decimal::percent(20u64)), to: None, @@ -817,7 +795,7 @@ fn collect_cw20_fees_for_specific_contracts_successfully() { &Cw20ExecuteMsg::Send { contract: pair_tokens[i - 1].to_string(), amount: Uint128::new(100_000u128), - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread: Some(Decimal::percent(30u64)), to: None, @@ -834,7 +812,7 @@ fn collect_cw20_fees_for_specific_contracts_successfully() { &Cw20ExecuteMsg::Send { contract: pair_tokens[i].to_string(), amount: Uint128::new(200_000u128), - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread: Some(Decimal::percent(30u64)), to: None, @@ -1321,7 +1299,7 @@ fn collect_pools_native_fees_successfully() { &Cw20ExecuteMsg::Send { contract: pair_tokens[i].to_string(), amount: Uint128::new(200_000_000u128), - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread: None, to: None, @@ -1884,7 +1862,7 @@ fn collect_fees_with_pagination_successfully() { &Cw20ExecuteMsg::Send { contract: pair_tokens[i].to_string(), amount: Uint128::new(200_000u128), - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread: Some(Decimal::percent(40u64)), to: None, @@ -2204,7 +2182,7 @@ fn collect_fees_for_vault() { vaults[i].clone(), &white_whale::vault_network::vault::ExecuteMsg::FlashLoan { amount: Uint128::new(flash_loan_value), - msg: to_binary(&BankMsg::Send { + msg: to_json_binary(&BankMsg::Send { to_address: vaults[i].to_string(), // return a higher amount than the flashloan + fees amount: coins(return_flash_loan_value, coin.denom.clone()), @@ -2632,7 +2610,7 @@ fn aggregate_fees_for_vault() { vaults[i].clone(), &white_whale::vault_network::vault::ExecuteMsg::FlashLoan { amount: Uint128::new(flash_loan_value), - msg: to_binary(&BankMsg::Send { + msg: to_json_binary(&BankMsg::Send { to_address: vaults[i].to_string(), // return a higher amount than the flashloan + fees amount: coins(return_flash_loan_value, coin.denom.clone()), diff --git a/contracts/liquidity_hub/fee_collector/src/tests/testing.rs b/contracts/liquidity_hub/fee_collector/src/tests/testing.rs index e1e6f204..dcfbd99d 100644 --- a/contracts/liquidity_hub/fee_collector/src/tests/testing.rs +++ b/contracts/liquidity_hub/fee_collector/src/tests/testing.rs @@ -1,5 +1,5 @@ use cosmwasm_std::testing::{mock_env, mock_info}; -use cosmwasm_std::{from_binary, Addr, DepsMut, MessageInfo, Response}; +use cosmwasm_std::{from_json, Addr, DepsMut, MessageInfo, Response}; use cw2::{get_contract_version, set_contract_version, ContractVersion}; use std::env; @@ -24,7 +24,7 @@ fn proper_initialization() { instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); let query_res = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap(); - let config_res: Config = from_binary(&query_res).unwrap(); + let config_res: Config = from_json(&query_res).unwrap(); assert_eq!("owner".to_string(), config_res.owner); } @@ -35,7 +35,7 @@ fn test_update_config_successfully() { mock_instantiation(deps.as_mut(), info.clone()).unwrap(); let query_res = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap(); - let config_res: Config = from_binary(&query_res).unwrap(); + let config_res: Config = from_json(&query_res).unwrap(); assert_eq!(config_res.owner, Addr::unchecked("owner")); let msg = ExecuteMsg::UpdateConfig { @@ -49,7 +49,7 @@ fn test_update_config_successfully() { execute(deps.as_mut(), mock_env(), info, msg).unwrap(); let query_res = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap(); - let config_res: Config = from_binary(&query_res).unwrap(); + let config_res: Config = from_json(&query_res).unwrap(); assert_eq!(config_res.owner, Addr::unchecked("new_owner")); assert_eq!(config_res.pool_router, Addr::unchecked("new_router")); } @@ -61,7 +61,7 @@ fn test_update_config_unsuccessfully_unauthorized() { mock_instantiation(deps.as_mut(), info).unwrap(); let query_res = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap(); - let config_res: Config = from_binary(&query_res).unwrap(); + let config_res: Config = from_json(&query_res).unwrap(); assert_eq!(config_res.owner, Addr::unchecked("owner")); let info = mock_info("unauthorized", &[]); diff --git a/contracts/liquidity_hub/fee_distributor/src/commands.rs b/contracts/liquidity_hub/fee_distributor/src/commands.rs index 760e37e6..8169abdc 100644 --- a/contracts/liquidity_hub/fee_distributor/src/commands.rs +++ b/contracts/liquidity_hub/fee_distributor/src/commands.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ - to_binary, CosmosMsg, DepsMut, Env, MessageInfo, QueryRequest, ReplyOn, Response, StdError, - SubMsg, Timestamp, Uint64, WasmMsg, WasmQuery, + to_json_binary, CosmosMsg, DepsMut, Env, MessageInfo, QueryRequest, ReplyOn, Response, + StdError, SubMsg, Timestamp, Uint64, WasmMsg, WasmQuery, }; use white_whale::epoch_manager::epoch_manager::EpochConfig; @@ -59,7 +59,7 @@ pub fn create_new_epoch(deps: DepsMut, env: Env) -> Result Result Result Result StdResult { match msg { - QueryMsg::CurrentEpoch {} => Ok(to_binary(&state::get_current_epoch(deps)?)?), - QueryMsg::Epoch { id } => Ok(to_binary(&state::get_epoch(deps, id)?)?), - QueryMsg::ClaimableEpochs {} => Ok(to_binary(&state::get_claimable_epochs(deps)?)?), - QueryMsg::Config {} => Ok(to_binary(&queries::query_config(deps)?)?), - QueryMsg::Claimable { address } => Ok(to_binary(&state::query_claimable( + QueryMsg::CurrentEpoch {} => Ok(to_json_binary(&state::get_current_epoch(deps)?)?), + QueryMsg::Epoch { id } => Ok(to_json_binary(&state::get_epoch(deps, id)?)?), + QueryMsg::ClaimableEpochs {} => Ok(to_json_binary(&state::get_claimable_epochs(deps)?)?), + QueryMsg::Config {} => Ok(to_json_binary(&queries::query_config(deps)?)?), + QueryMsg::Claimable { address } => Ok(to_json_binary(&state::query_claimable( deps, &deps.api.addr_validate(&address)?, )?)?), diff --git a/contracts/liquidity_hub/fee_distributor/src/migrations.rs b/contracts/liquidity_hub/fee_distributor/src/migrations.rs index d5f12859..326b6c31 100644 --- a/contracts/liquidity_hub/fee_distributor/src/migrations.rs +++ b/contracts/liquidity_hub/fee_distributor/src/migrations.rs @@ -2,8 +2,8 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_binary, CosmosMsg, DepsMut, Order, QueryRequest, StdError, StdResult, Timestamp, Uint64, - WasmQuery, + to_json_binary, CosmosMsg, DepsMut, Order, QueryRequest, StdError, StdResult, Timestamp, + Uint64, WasmQuery, }; use cw_storage_plus::Map; @@ -47,7 +47,7 @@ pub fn migrate_to_v090(deps: DepsMut) -> Result<(), StdError> { // Query the current global index let global_index: GlobalIndex = deps.querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: bonding_contract_addr.to_string(), - msg: to_binary(&LairQueryMsg::GlobalIndex {})?, + msg: to_json_binary(&LairQueryMsg::GlobalIndex {})?, }))?; for epoch in epochs_v08 { diff --git a/contracts/liquidity_hub/fee_distributor/src/state.rs b/contracts/liquidity_hub/fee_distributor/src/state.rs index 930b0eee..782cff7c 100644 --- a/contracts/liquidity_hub/fee_distributor/src/state.rs +++ b/contracts/liquidity_hub/fee_distributor/src/state.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Addr, Deps, Order, QueryRequest, StdResult, Uint64, WasmQuery}; +use cosmwasm_std::{to_json_binary, Addr, Deps, Order, QueryRequest, StdResult, Uint64, WasmQuery}; use cw_storage_plus::{Item, Map}; use white_whale::fee_distributor::{ClaimableEpochsResponse, Config, Epoch, EpochResponse}; @@ -93,7 +93,7 @@ pub fn query_claimable(deps: Deps, address: &Addr) -> StdResult(vec![ WasmMsg::Execute { contract_addr: token_contract_addr.clone(), - msg: to_binary(&cw20::Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::TransferFrom { owner: info.sender.clone().into_string(), recipient: env.contract.address.clone().into_string(), amount: token_amount, @@ -104,7 +105,7 @@ pub fn execute( }, WasmMsg::Execute { contract_addr: token_contract_addr, - msg: to_binary(&cw20::Cw20ExecuteMsg::IncreaseAllowance { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::IncreaseAllowance { spender: pair_address.clone(), amount: token_amount, expires: None, @@ -131,7 +132,7 @@ pub fn execute( gas_limit: None, msg: WasmMsg::Execute { contract_addr: pair_address, - msg: to_binary( + msg: to_json_binary( &white_whale::pool_network::pair::ExecuteMsg::ProvideLiquidity { assets, slippage_tolerance, @@ -186,7 +187,7 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> Result StdResult { match msg { - QueryMsg::Config {} => Ok(to_binary(&CONFIG.load(deps.storage)?)?), + QueryMsg::Config {} => Ok(to_json_binary(&CONFIG.load(deps.storage)?)?), } } diff --git a/contracts/liquidity_hub/pool-network/frontend_helper/src/reply/deposit_pair.rs b/contracts/liquidity_hub/pool-network/frontend_helper/src/reply/deposit_pair.rs index dc5a5cc2..77e7412f 100644 --- a/contracts/liquidity_hub/pool-network/frontend_helper/src/reply/deposit_pair.rs +++ b/contracts/liquidity_hub/pool-network/frontend_helper/src/reply/deposit_pair.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, DepsMut, Env, Reply, Response, WasmMsg}; +use cosmwasm_std::{to_json_binary, DepsMut, Env, Reply, Response, WasmMsg}; use white_whale::pool_network::{ asset::AssetInfo, frontend_helper::TempState, incentive::QueryPosition, }; @@ -75,7 +75,7 @@ pub fn deposit_pair(deps: DepsMut, env: Env, msg: Reply) -> Result Result white_whale::pool_network::incentive::ExecuteMsg::ExpandPosition { amount: lp_amount, unbonding_duration, diff --git a/contracts/liquidity_hub/pool-network/frontend_helper/src/testing.rs b/contracts/liquidity_hub/pool-network/frontend_helper/src/testing.rs index 2234b0a4..d9cfb155 100644 --- a/contracts/liquidity_hub/pool-network/frontend_helper/src/testing.rs +++ b/contracts/liquidity_hub/pool-network/frontend_helper/src/testing.rs @@ -1,7 +1,7 @@ #[cfg(test)] mod tests { use crate::error::ContractError; - use cosmwasm_std::{coin, coins, to_binary, Addr, Uint128, WasmMsg}; + use cosmwasm_std::{coin, coins, to_json_binary, Addr, Uint128, WasmMsg}; use cw_multi_test::Executor; use white_whale::pool_network::asset::{Asset, AssetInfo}; use white_whale::pool_network::frontend_helper::ConfigResponse; @@ -129,7 +129,7 @@ mod tests { vec![ WasmMsg::Execute { contract_addr: pool_assets[1].to_string(), - msg: to_binary(&cw20::Cw20ExecuteMsg::IncreaseAllowance { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::IncreaseAllowance { spender: frontend_helper.clone().into_string(), amount: Uint128::new(5_000), expires: None, @@ -140,7 +140,7 @@ mod tests { .into(), WasmMsg::Execute { contract_addr: frontend_helper.into_string(), - msg: to_binary( + msg: to_json_binary( &white_whale::pool_network::frontend_helper::ExecuteMsg::Deposit { pair_address: pair_address.into_string(), assets: [ diff --git a/contracts/liquidity_hub/pool-network/frontend_helper/src/tests/mock_instantiate.rs b/contracts/liquidity_hub/pool-network/frontend_helper/src/tests/mock_instantiate.rs index 9fe35eaf..f3976c01 100644 --- a/contracts/liquidity_hub/pool-network/frontend_helper/src/tests/mock_instantiate.rs +++ b/contracts/liquidity_hub/pool-network/frontend_helper/src/tests/mock_instantiate.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Addr, Decimal, Uint128, WasmMsg}; +use cosmwasm_std::{to_json_binary, Addr, Decimal, Uint128, WasmMsg}; use cw20::Cw20Coin; use cw_multi_test::{App, Executor}; @@ -71,61 +71,44 @@ pub fn app_mock_instantiate(app: &mut App, pool_assets: [AssetInfo; 2]) -> AppIn .try_into() .unwrap(); - let instantiate_msg: white_whale::pool_network::pair::InstantiateMsg; - let pool_fee: white_whale::pool_network::pair::PoolFee; #[cfg(not(feature = "osmosis"))] - { - pool_fee = white_whale::pool_network::pair::PoolFee { - burn_fee: Fee { - share: Decimal::zero(), - }, - protocol_fee: Fee { - share: Decimal::zero(), - }, - swap_fee: Fee { - share: Decimal::zero(), - }, - }; - - instantiate_msg = white_whale::pool_network::pair::InstantiateMsg { - token_factory_lp: false, - token_code_id: token_id, - pool_fees: pool_fee.clone(), - pair_type: PairType::ConstantProduct, - fee_collector_addr: "fee_collector_addr".to_string(), - asset_decimals: [6, 6], - asset_infos: pool_assets.clone(), - } - } + let pool_fee = white_whale::pool_network::pair::PoolFee { + burn_fee: Fee { + share: Decimal::zero(), + }, + protocol_fee: Fee { + share: Decimal::zero(), + }, + swap_fee: Fee { + share: Decimal::zero(), + }, + }; #[cfg(feature = "osmosis")] - { - pool_fee = white_whale::pool_network::pair::PoolFee { - burn_fee: Fee { - share: Decimal::zero(), - }, - protocol_fee: Fee { - share: Decimal::zero(), - }, - swap_fee: Fee { - share: Decimal::zero(), - }, - osmosis_fee: Fee { - share: Decimal::zero(), - }, - }; - - instantiate_msg = white_whale::pool_network::pair::InstantiateMsg { - token_factory_lp: false, - token_code_id: token_id, - pool_fees: pool_fee.clone(), - pair_type: PairType::ConstantProduct, - fee_collector_addr: "fee_collector_addr".to_string(), - asset_decimals: [6, 6], - asset_infos: pool_assets.clone(), - osmosis_fee_collector_addr: "osmosis_fee_collector_addr".to_string(), - } - } + let pool_fee = white_whale::pool_network::pair::PoolFee { + burn_fee: Fee { + share: Decimal::zero(), + }, + protocol_fee: Fee { + share: Decimal::zero(), + }, + swap_fee: Fee { + share: Decimal::zero(), + }, + osmosis_fee: Fee { + share: Decimal::zero(), + }, + }; + + let instantiate_msg = white_whale::pool_network::pair::InstantiateMsg { + token_factory_lp: false, + token_code_id: token_id, + pool_fees: pool_fee.clone(), + pair_type: PairType::ConstantProduct, + fee_collector_addr: "fee_collector_addr".to_string(), + asset_decimals: [6, 6], + asset_infos: pool_assets.clone(), + }; // create the pair let pair = app @@ -190,7 +173,7 @@ pub fn app_mock_instantiate(app: &mut App, pool_assets: [AssetInfo; 2]) -> AppIn mock_admin().sender, WasmMsg::Execute { contract_addr: incentive_factory.to_string(), - msg: to_binary( + msg: to_json_binary( &white_whale::pool_network::incentive_factory::ExecuteMsg::CreateIncentive { lp_asset: lp_token.clone(), }, diff --git a/contracts/liquidity_hub/pool-network/incentive/src/claim.rs b/contracts/liquidity_hub/pool-network/incentive/src/claim.rs index 9ba23587..6a510954 100644 --- a/contracts/liquidity_hub/pool-network/incentive/src/claim.rs +++ b/contracts/liquidity_hub/pool-network/incentive/src/claim.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - to_binary, BankMsg, Coin, CosmosMsg, Decimal256, DepsMut, MessageInfo, StdError, Uint128, + to_json_binary, BankMsg, Coin, CosmosMsg, Decimal256, DepsMut, MessageInfo, StdError, Uint128, Uint256, WasmMsg, }; @@ -203,7 +203,7 @@ pub fn claim(deps: &mut DepsMut, info: &MessageInfo) -> Result, C AssetInfo::Token { contract_addr } => messages.push( WasmMsg::Execute { contract_addr: contract_addr.to_owned(), - msg: to_binary(&cw20::Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::Transfer { recipient: address.clone().into_string(), amount: user_reward_at_epoch, })?, diff --git a/contracts/liquidity_hub/pool-network/incentive/src/contract.rs b/contracts/liquidity_hub/pool-network/incentive/src/contract.rs index bd525433..9506d1e8 100644 --- a/contracts/liquidity_hub/pool-network/incentive/src/contract.rs +++ b/contracts/liquidity_hub/pool-network/incentive/src/contract.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, Uint128, WasmMsg, + to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, Uint128, WasmMsg, }; use cw2::{get_contract_version, set_contract_version}; use white_whale::pool_network::incentive::{ @@ -57,7 +57,7 @@ pub fn instantiate( ), ("lp_asset", config.lp_asset.to_string()), ]) - .set_data(to_binary( + .set_data(to_json_binary( &white_whale::pool_network::incentive::InstantiateReplyCallback { lp_asset: msg.lp_asset, }, @@ -65,7 +65,7 @@ pub fn instantiate( // takes a snapshot of the global weight at the current epoch from the start .add_message(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: env.contract.address.to_string(), - msg: to_binary(&ExecuteMsg::TakeGlobalWeightSnapshot {})?, + msg: to_json_binary(&ExecuteMsg::TakeGlobalWeightSnapshot {})?, funds: vec![], }))) } @@ -125,12 +125,12 @@ pub fn execute( #[entry_point] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result { match msg { - QueryMsg::Config {} => Ok(to_binary(&queries::get_config(deps)?)?), + QueryMsg::Config {} => Ok(to_json_binary(&queries::get_config(deps)?)?), QueryMsg::Flow { flow_identifier, start_epoch, end_epoch, - } => Ok(to_binary(&queries::get_flow( + } => Ok(to_json_binary(&queries::get_flow( deps, flow_identifier, start_epoch, @@ -139,19 +139,19 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result Ok(to_binary(&queries::get_flows( + } => Ok(to_json_binary(&queries::get_flows( deps, start_epoch, end_epoch, )?)?), - QueryMsg::Positions { address } => { - Ok(to_binary(&queries::get_positions(deps, env, address)?)?) - } - QueryMsg::Rewards { address } => Ok(to_binary(&queries::get_rewards(deps, address)?)?), - QueryMsg::GlobalWeight { epoch_id } => { - Ok(to_binary(&queries::get_global_weight(deps, epoch_id)?)?) - } - QueryMsg::CurrentEpochRewardsShare { address } => Ok(to_binary( + QueryMsg::Positions { address } => Ok(to_json_binary(&queries::get_positions( + deps, env, address, + )?)?), + QueryMsg::Rewards { address } => Ok(to_json_binary(&queries::get_rewards(deps, address)?)?), + QueryMsg::GlobalWeight { epoch_id } => Ok(to_json_binary(&queries::get_global_weight( + deps, epoch_id, + )?)?), + QueryMsg::CurrentEpochRewardsShare { address } => Ok(to_json_binary( &queries::get_rewards_share(deps, deps.api.addr_validate(&address)?)?, )?), } diff --git a/contracts/liquidity_hub/pool-network/incentive/src/execute/close_flow.rs b/contracts/liquidity_hub/pool-network/incentive/src/execute/close_flow.rs index 3ee09e3f..0645f6aa 100644 --- a/contracts/liquidity_hub/pool-network/incentive/src/execute/close_flow.rs +++ b/contracts/liquidity_hub/pool-network/incentive/src/execute/close_flow.rs @@ -1,5 +1,6 @@ use cosmwasm_std::{ - coins, to_binary, BankMsg, CosmosMsg, DepsMut, MessageInfo, Order, Response, StdResult, WasmMsg, + coins, to_json_binary, BankMsg, CosmosMsg, DepsMut, MessageInfo, Order, Response, StdResult, + WasmMsg, }; use white_whale::pool_network::asset::AssetInfo; @@ -52,7 +53,7 @@ pub fn close_flow( .into(), AssetInfo::Token { contract_addr } => WasmMsg::Execute { contract_addr, - msg: to_binary(&cw20::Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::Transfer { recipient: flow.flow_creator.clone().into_string(), amount: amount_to_return, })?, diff --git a/contracts/liquidity_hub/pool-network/incentive/src/execute/expand_flow.rs b/contracts/liquidity_hub/pool-network/incentive/src/execute/expand_flow.rs index 1418fa83..1b0ec559 100644 --- a/contracts/liquidity_hub/pool-network/incentive/src/execute/expand_flow.rs +++ b/contracts/liquidity_hub/pool-network/incentive/src/execute/expand_flow.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - to_binary, CosmosMsg, DepsMut, Env, MessageInfo, Order, OverflowError, OverflowOperation, + to_json_binary, CosmosMsg, DepsMut, Env, MessageInfo, Order, OverflowError, OverflowOperation, Response, StdResult, Uint128, WasmMsg, }; @@ -72,7 +72,7 @@ pub fn expand_flow( messages.push( WasmMsg::Execute { contract_addr, - msg: to_binary(&cw20::Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::TransferFrom { owner: info.sender.into_string(), recipient: env.contract.address.into_string(), amount: flow_asset.amount, diff --git a/contracts/liquidity_hub/pool-network/incentive/src/execute/open_flow.rs b/contracts/liquidity_hub/pool-network/incentive/src/execute/open_flow.rs index b4d566f0..965e594f 100644 --- a/contracts/liquidity_hub/pool-network/incentive/src/execute/open_flow.rs +++ b/contracts/liquidity_hub/pool-network/incentive/src/execute/open_flow.rs @@ -2,7 +2,7 @@ use std::cmp::Ordering; use std::collections::HashMap; use cosmwasm_std::{ - to_binary, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Order, Response, StdError, + to_json_binary, BankMsg, Coin, CosmosMsg, DepsMut, Env, MessageInfo, Order, Response, StdError, StdResult, Uint128, WasmMsg, }; @@ -177,7 +177,7 @@ pub fn open_flow( messages.push( WasmMsg::Execute { contract_addr: flow_fee_contract_addr, - msg: to_binary(&cw20::Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::TransferFrom { owner: info.sender.clone().into_string(), recipient: incentive_factory_config.fee_collector_addr.into_string(), amount: flow_fee.amount, @@ -259,7 +259,7 @@ pub fn open_flow( messages.push( WasmMsg::Execute { contract_addr: flow_asset_contract_addr, - msg: to_binary(&cw20::Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::TransferFrom { owner: info.sender.clone().into_string(), recipient: env.contract.address.into_string(), amount: flow_asset.amount, @@ -288,7 +288,7 @@ pub fn open_flow( messages.push( WasmMsg::Execute { contract_addr: flow_asset_contract_addr, - msg: to_binary(&cw20::Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::TransferFrom { owner: info.sender.clone().into_string(), recipient: env.contract.address.into_string(), amount: flow_asset.amount, @@ -307,7 +307,7 @@ pub fn open_flow( messages.push( WasmMsg::Execute { contract_addr: flow_asset_contract_addr, - msg: to_binary(&cw20::Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::TransferFrom { owner: info.sender.clone().into_string(), recipient: env.contract.address.into_string(), amount: flow_asset.amount, diff --git a/contracts/liquidity_hub/pool-network/incentive/src/funds_validation.rs b/contracts/liquidity_hub/pool-network/incentive/src/funds_validation.rs index 2361e1a6..8c057268 100644 --- a/contracts/liquidity_hub/pool-network/incentive/src/funds_validation.rs +++ b/contracts/liquidity_hub/pool-network/incentive/src/funds_validation.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Deps, Env, MessageInfo, Uint128, WasmMsg}; +use cosmwasm_std::{to_json_binary, Deps, Env, MessageInfo, Uint128, WasmMsg}; use cw_utils::PaymentError; use white_whale::pool_network::asset::AssetInfo; @@ -43,7 +43,7 @@ pub fn validate_funds_sent( // send the lp deposit to us Some(WasmMsg::Execute { contract_addr, - msg: to_binary(&cw20::Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::TransferFrom { owner: info.sender.into_string(), recipient: env.contract.address.into_string(), amount, diff --git a/contracts/liquidity_hub/pool-network/incentive/src/tests/mock_instantiate.rs b/contracts/liquidity_hub/pool-network/incentive/src/tests/mock_instantiate.rs index 96bd70bd..3cc8e797 100644 --- a/contracts/liquidity_hub/pool-network/incentive/src/tests/mock_instantiate.rs +++ b/contracts/liquidity_hub/pool-network/incentive/src/tests/mock_instantiate.rs @@ -1,6 +1,6 @@ use cosmwasm_std::{ testing::{mock_dependencies, mock_env, MockApi, MockQuerier, MockStorage}, - to_binary, Addr, Env, OwnedDeps, Uint128, Uint64, WasmMsg, + to_json_binary, Addr, Env, OwnedDeps, Uint128, Uint64, WasmMsg, }; use cw20::Cw20Coin; use cw_multi_test::{App, Executor}; @@ -128,7 +128,7 @@ pub fn app_mock_instantiate(app: &mut App, lp_balance: Uint128) -> AppInstantiat mock_admin().sender, WasmMsg::Execute { contract_addr: incentive_factory.to_string(), - msg: to_binary( + msg: to_json_binary( &white_whale::pool_network::incentive_factory::ExecuteMsg::CreateIncentive { lp_asset: AssetInfo::Token { contract_addr: lp_addr.to_string(), diff --git a/contracts/liquidity_hub/pool-network/incentive_factory/src/contract.rs b/contracts/liquidity_hub/pool-network/incentive_factory/src/contract.rs index e5f11bbd..3dd768ff 100644 --- a/contracts/liquidity_hub/pool-network/incentive_factory/src/contract.rs +++ b/contracts/liquidity_hub/pool-network/incentive_factory/src/contract.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, + to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult, }; use cw2::{get_contract_version, set_contract_version}; use semver::Version; @@ -143,10 +143,12 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> Result StdResult { match msg { - QueryMsg::Config {} => to_binary(&queries::get_config(deps)?), - QueryMsg::Incentive { lp_asset } => to_binary(&queries::get_incentive(deps, lp_asset)?), + QueryMsg::Config {} => to_json_binary(&queries::get_config(deps)?), + QueryMsg::Incentive { lp_asset } => { + to_json_binary(&queries::get_incentive(deps, lp_asset)?) + } QueryMsg::Incentives { start_after, limit } => { - to_binary(&queries::get_incentives(deps, start_after, limit)?) + to_json_binary(&queries::get_incentives(deps, start_after, limit)?) } } } diff --git a/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/create_incentive.rs b/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/create_incentive.rs index 7aabbf44..4ca11e8b 100644 --- a/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/create_incentive.rs +++ b/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/create_incentive.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, DepsMut, Env, ReplyOn, Response, SubMsg, WasmMsg}; +use cosmwasm_std::{to_json_binary, DepsMut, Env, ReplyOn, Response, SubMsg, WasmMsg}; use white_whale::pool_network::asset::AssetInfo; use crate::{ @@ -39,7 +39,7 @@ pub fn create_incentive( msg: WasmMsg::Instantiate { admin: Some(env.contract.address.into_string()), code_id: config.incentive_code_id, - msg: to_binary(&white_whale::pool_network::incentive::InstantiateMsg { + msg: to_json_binary(&white_whale::pool_network::incentive::InstantiateMsg { lp_asset: lp_asset.clone(), fee_distributor_address: config.fee_distributor_addr.into_string(), })?, diff --git a/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/migrate_incentive.rs b/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/migrate_incentive.rs index fcff7188..640681e4 100644 --- a/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/migrate_incentive.rs +++ b/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/migrate_incentive.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Addr, CosmosMsg, DepsMut, Order, Response, StdResult, WasmMsg}; +use cosmwasm_std::{to_json_binary, Addr, CosmosMsg, DepsMut, Order, Response, StdResult, WasmMsg}; use crate::error::ContractError; use crate::state::INCENTIVE_MAPPINGS; @@ -48,7 +48,7 @@ fn migrate_incentive_msg(incentive_address: Addr, new_code_id: u64) -> StdResult Ok(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: incentive_address.to_string(), new_code_id, - msg: to_binary(&white_whale::pool_network::incentive::MigrateMsg {})?, + msg: to_json_binary(&white_whale::pool_network::incentive::MigrateMsg {})?, })) } diff --git a/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/update_config.rs b/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/update_config.rs index 7ac209fa..1e6b6bd3 100644 --- a/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/update_config.rs +++ b/contracts/liquidity_hub/pool-network/incentive_factory/src/execute/update_config.rs @@ -110,7 +110,7 @@ mod tests { use crate::contract::{execute, instantiate, query}; use crate::error::ContractError; use cosmwasm_std::testing::{mock_dependencies, mock_env, mock_info}; - use cosmwasm_std::{from_binary, Addr, Uint128}; + use cosmwasm_std::{from_json, Addr, Uint128}; use white_whale::pool_network::asset::{Asset, AssetInfo}; use white_whale::pool_network::incentive_factory::ExecuteMsg::UpdateConfig; use white_whale::pool_network::incentive_factory::{Config, InstantiateMsg, QueryMsg}; @@ -138,7 +138,7 @@ mod tests { instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); let config: Config = - from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); assert_eq!( config, @@ -181,7 +181,7 @@ mod tests { execute(deps.as_mut(), mock_env(), info, msg).unwrap(); let config: Config = - from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); assert_eq!( config, diff --git a/contracts/liquidity_hub/pool-network/incentive_factory/src/queries/get_incentives.rs b/contracts/liquidity_hub/pool-network/incentive_factory/src/queries/get_incentives.rs index 3bac398d..bfe6f755 100644 --- a/contracts/liquidity_hub/pool-network/incentive_factory/src/queries/get_incentives.rs +++ b/contracts/liquidity_hub/pool-network/incentive_factory/src/queries/get_incentives.rs @@ -57,7 +57,7 @@ fn calc_range_start(start_after: Option) -> Option> { #[cfg(test)] mod tests { use cosmwasm_std::{ - testing::mock_dependencies, to_binary, Addr, Binary, DepsMut, Reply, SubMsgResponse, + testing::mock_dependencies, to_json_binary, Addr, Binary, DepsMut, Reply, SubMsgResponse, SubMsgResult, }; use protobuf::{Message, SpecialFields}; @@ -80,7 +80,7 @@ mod tests { data: Some(Binary::from( Message::write_to_bytes(&MsgInstantiateContractResponse { address: format!("incentive{id}"), - data: to_binary( + data: to_json_binary( &white_whale::pool_network::incentive::InstantiateReplyCallback { lp_asset: get_lp_asset(id), }, diff --git a/contracts/liquidity_hub/pool-network/incentive_factory/src/reply/create_incentive_reply.rs b/contracts/liquidity_hub/pool-network/incentive_factory/src/reply/create_incentive_reply.rs index 7e34932a..1ce283a0 100644 --- a/contracts/liquidity_hub/pool-network/incentive_factory/src/reply/create_incentive_reply.rs +++ b/contracts/liquidity_hub/pool-network/incentive_factory/src/reply/create_incentive_reply.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{from_binary, DepsMut, Reply, Response}; +use cosmwasm_std::{from_json, DepsMut, Reply, Response}; use protobuf::Message; use crate::{ @@ -29,7 +29,7 @@ pub fn create_incentive_reply(deps: DepsMut, msg: Reply) -> Result StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result { match msg { - QueryMsg::Trio {} => Ok(to_binary(&queries::query_trio_info(deps)?)?), - QueryMsg::Pool {} => Ok(to_binary(&queries::query_pool(deps)?)?), + QueryMsg::Trio {} => Ok(to_json_binary(&queries::query_trio_info(deps)?)?), + QueryMsg::Pool {} => Ok(to_json_binary(&queries::query_pool(deps)?)?), QueryMsg::Simulation { offer_asset, ask_asset, - } => Ok(to_binary(&queries::query_simulation( + } => Ok(to_json_binary(&queries::query_simulation( deps, offer_asset, ask_asset, @@ -254,21 +254,21 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> Result Ok(to_binary(&queries::query_reverse_simulation( + } => Ok(to_json_binary(&queries::query_reverse_simulation( deps, ask_asset, offer_asset, env.block.height, )?)?), - QueryMsg::Config {} => Ok(to_binary(&queries::query_config(deps)?)?), - QueryMsg::ProtocolFees { asset_id, all_time } => Ok(to_binary(&queries::query_fees( + QueryMsg::Config {} => Ok(to_json_binary(&queries::query_config(deps)?)?), + QueryMsg::ProtocolFees { asset_id, all_time } => Ok(to_json_binary(&queries::query_fees( deps, asset_id, all_time, COLLECTED_PROTOCOL_FEES, Some(ALL_TIME_COLLECTED_PROTOCOL_FEES), )?)?), - QueryMsg::BurnedFees { asset_id } => Ok(to_binary(&queries::query_fees( + QueryMsg::BurnedFees { asset_id } => Ok(to_json_binary(&queries::query_fees( deps, asset_id, None, diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs index d789e7a9..8fe0dcf3 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/helpers.rs @@ -1,7 +1,7 @@ use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - to_binary, Decimal, Decimal256, Deps, DepsMut, Env, ReplyOn, Response, StdError, StdResult, - Storage, SubMsg, Uint128, Uint256, WasmMsg, + to_json_binary, Decimal, Decimal256, Deps, DepsMut, Env, ReplyOn, Response, StdError, + StdResult, Storage, SubMsg, Uint128, Uint256, WasmMsg, }; use cw20::MinterResponse; use cw_storage_plus::Item; @@ -78,7 +78,7 @@ pub fn compute_swap( spread_amount: spread_amount.try_into()?, swap_fee_amount: swap_fee_amount.try_into()?, protocol_fee_amount: protocol_fee_amount.try_into()?, - burn_fee_amount: Uint128::zero(), + burn_fee_amount: burn_fee_amount.try_into()?, osmosis_fee_amount: osmosis_fee_amount.try_into()?, }) } @@ -346,7 +346,7 @@ pub fn create_lp_token( msg: WasmMsg::Instantiate { admin: None, code_id: msg.token_code_id, - msg: to_binary(&TokenInstantiateMsg { + msg: to_json_binary(&TokenInstantiateMsg { name: lp_token_name.to_owned(), symbol: "uLP".to_string(), decimals: 6, diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/feature_toggle.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/feature_toggle.rs index 71642542..a69fc22d 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/feature_toggle.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/feature_toggle.rs @@ -1,7 +1,7 @@ use crate::contract::{execute, instantiate}; use crate::error::ContractError; use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; -use cosmwasm_std::{to_binary, Coin, Decimal, Uint128}; +use cosmwasm_std::{to_json_binary, Coin, Decimal, Uint128}; use cw20::Cw20ReceiveMsg; use white_whale::fee::Fee; use white_whale::pool_network::asset::{Asset, AssetInfo}; @@ -112,7 +112,7 @@ fn test_feature_toggle_swap_disabled() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { ask_asset: AssetInfo::Token { contract_addr: "asset0000".to_string(), }, @@ -207,7 +207,7 @@ fn test_feature_toggle_withdrawals_disabled() { // withdraw liquidity should fail let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), + msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), amount: Uint128::from(100u128), }); diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/protocol_fees.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/protocol_fees.rs index 70932a54..cf550a96 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/protocol_fees.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/protocol_fees.rs @@ -3,7 +3,7 @@ use crate::queries::query_fees; use crate::state::{ALL_TIME_COLLECTED_PROTOCOL_FEES, COLLECTED_PROTOCOL_FEES}; use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - to_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, StdError, SubMsg, SubMsgResponse, + to_json_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, StdError, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; @@ -321,7 +321,7 @@ fn test_collect_protocol_fees_successful() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "asset0001".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { ask_asset: AssetInfo::NativeToken { denom: "uusd".to_string(), }, @@ -371,7 +371,7 @@ fn test_collect_protocol_fees_successful() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "asset0000".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { ask_asset: AssetInfo::Token { contract_addr: "asset0001".to_string(), }, @@ -428,7 +428,7 @@ fn test_collect_protocol_fees_successful() { transfer_asset0000_token_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "collector".to_string(), amount: protocol_fees_for_asset0000.clone().first().unwrap().amount, }) @@ -440,7 +440,7 @@ fn test_collect_protocol_fees_successful() { transfer_asset0001_token_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0001".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "collector".to_string(), amount: protocol_fees_for_asset0001.clone().first().unwrap().amount, }) @@ -645,7 +645,7 @@ fn test_collect_protocol_fees_successful_1_fee_only() { transfer_cw20_token_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "collector".to_string(), amount: protocol_fees[1].amount, }) diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/provide_liquidity.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/provide_liquidity.rs index a94c2b64..00c9a222 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/provide_liquidity.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/provide_liquidity.rs @@ -6,7 +6,7 @@ use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; #[cfg(feature = "token_factory")] use cosmwasm_std::{coin, BankMsg}; use cosmwasm_std::{ - to_binary, Coin, CosmosMsg, Decimal, Reply, Response, StdError, SubMsg, SubMsgResponse, + to_json_binary, Coin, CosmosMsg, Decimal, Reply, Response, StdError, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::Cw20ExecuteMsg; @@ -170,7 +170,7 @@ fn provide_liquidity_cw20_lp() { transfer_from_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom { owner: "addr0000".to_string(), recipient: MOCK_CONTRACT_ADDR.to_string(), amount: Uint128::from(2_000u128), @@ -183,7 +183,7 @@ fn provide_liquidity_cw20_lp() { mint_initial_lp_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: "cosmos2contract".to_string(), amount: MINIMUM_LIQUIDITY_AMOUNT * Uint128::from(3u8), }) @@ -195,7 +195,7 @@ fn provide_liquidity_cw20_lp() { mint_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: "addr0000".to_string(), amount: Uint128::from(3_000u128), }) @@ -275,7 +275,7 @@ fn provide_liquidity_cw20_lp() { transfer_from_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom { owner: "addr0000".to_string(), recipient: MOCK_CONTRACT_ADDR.to_string(), amount: Uint128::from(100u128), @@ -288,7 +288,7 @@ fn provide_liquidity_cw20_lp() { mint_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: "staking0000".to_string(), // LP tokens sent to specified receiver amount: Uint128::from(57u128), }) diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/swap.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/swap.rs index cd762068..75f6d582 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/swap.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/swap.rs @@ -8,8 +8,8 @@ use crate::state::{ }; use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - attr, coins, from_binary, to_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, ReplyOn, SubMsg, - SubMsgResponse, SubMsgResult, Uint128, WasmMsg, + attr, coins, from_json, to_json_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, ReplyOn, + SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; use white_whale::fee::Fee; @@ -175,7 +175,7 @@ fn try_native_to_token() { id: 0, msg: CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: expected_burn_fee_amount, }) .unwrap(), @@ -271,7 +271,7 @@ fn try_native_to_token() { ) .unwrap(); - let simulation_res: SimulationResponse = from_binary( + let simulation_res: SimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -324,7 +324,7 @@ fn try_native_to_token() { ) .unwrap(); - let reverse_simulation_res: ReverseSimulationResponse = from_binary( + let reverse_simulation_res: ReverseSimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -399,7 +399,7 @@ fn try_native_to_token() { assert_eq!( &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: expected_return_amount, }) @@ -630,7 +630,7 @@ fn try_token_to_native() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { ask_asset: AssetInfo::NativeToken { denom: "uusd".to_string(), }, @@ -739,7 +739,7 @@ fn try_token_to_native() { ) .unwrap(); - let simulation_res: SimulationResponse = from_binary( + let simulation_res: SimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -793,7 +793,7 @@ fn try_token_to_native() { .unwrap(); // check reverse simulation res - let reverse_simulation_res: ReverseSimulationResponse = from_binary( + let reverse_simulation_res: ReverseSimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -883,7 +883,7 @@ fn try_token_to_native() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { ask_asset: AssetInfo::Token { contract_addr: "asset0000".to_string(), }, @@ -1037,7 +1037,7 @@ fn test_swap_to_third_party() { ) .unwrap(); - let simulation_res: SimulationResponse = from_binary( + let simulation_res: SimulationResponse = from_json( &query( deps.as_ref(), mock_env(), diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs index 3611c6fb..dc8a84d5 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/testing.rs @@ -1,6 +1,6 @@ use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - from_binary, to_binary, Addr, Decimal, Reply, ReplyOn, StdError, SubMsg, SubMsgResponse, + from_json, to_json_binary, Addr, Decimal, Reply, ReplyOn, StdError, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::MinterResponse; @@ -79,7 +79,7 @@ fn proper_initialization_cw20_lp() { vec![SubMsg { msg: WasmMsg::Instantiate { code_id: 10u64, - msg: to_binary(&TokenInstantiateMsg { + msg: to_json_binary(&TokenInstantiateMsg { name: "uusd-mAAPL-mAAPL-LP".to_string(), symbol: "uLP".to_string(), decimals: 6, @@ -759,7 +759,7 @@ fn test_update_config_successful() { instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); let config: Config = - from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); // check for original config assert_eq!(config.owner, Addr::unchecked("addr0000")); @@ -787,7 +787,7 @@ fn test_update_config_successful() { execute(deps.as_mut(), env, info, update_config_message).unwrap(); let config: Config = - from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); // check for new config assert_eq!(config.owner, Addr::unchecked("new_admin")); diff --git a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/withdrawals.rs b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/withdrawals.rs index 4ab72f02..7577bd9d 100644 --- a/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/withdrawals.rs +++ b/contracts/liquidity_hub/pool-network/stableswap_3pool/src/tests/withdrawals.rs @@ -7,7 +7,7 @@ use crate::state::{get_fees_for_asset, store_fee, COLLECTED_PROTOCOL_FEES}; use cosmwasm_std::coin; use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - attr, to_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, SubMsg, SubMsgResponse, + attr, to_json_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; @@ -111,7 +111,7 @@ fn withdraw_liquidity_cw20_lp() { // withdraw liquidity let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), + msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), amount: Uint128::from(100u128), }); @@ -168,7 +168,7 @@ fn withdraw_liquidity_cw20_lp() { msg_refund_1, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: expected_token_1_refund_amount, }) @@ -180,7 +180,7 @@ fn withdraw_liquidity_cw20_lp() { msg_refund_2, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0001".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: expected_token_2_refund_amount, }) @@ -192,7 +192,7 @@ fn withdraw_liquidity_cw20_lp() { msg_burn_liquidity, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: Uint128::from(100u128), }) .unwrap(), @@ -477,7 +477,7 @@ fn test_withdrawal_unauthorized() { // withdraw liquidity should fail let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), + msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), amount: Uint128::from(100u128), }); @@ -551,7 +551,7 @@ fn test_withdrawal_wrong_message() { // withdraw liquidity should fail let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&"invalid_message").unwrap(), + msg: to_json_binary(&"invalid_message").unwrap(), amount: Uint128::from(100u128), }); diff --git a/contracts/liquidity_hub/pool-network/terraswap_factory/src/commands.rs b/contracts/liquidity_hub/pool-network/terraswap_factory/src/commands.rs index 6d969e48..f39ede1d 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_factory/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_factory/src/commands.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - to_binary, wasm_execute, CosmosMsg, DepsMut, Env, MessageInfo, ReplyOn, Response, SubMsg, + to_json_binary, wasm_execute, CosmosMsg, DepsMut, Env, MessageInfo, ReplyOn, Response, SubMsg, WasmMsg, }; @@ -161,7 +161,7 @@ pub fn create_pair( funds: info.funds, admin: Some(env.contract.address.to_string()), label: pair_label, - msg: to_binary(&PairInstantiateMsg { + msg: to_json_binary(&PairInstantiateMsg { asset_infos, token_code_id: config.token_code_id, asset_decimals, @@ -294,7 +294,7 @@ pub fn create_trio( funds: info.funds, admin: Some(env.contract.address.to_string()), label: trio_label, - msg: to_binary(&TrioInstantiateMsg { + msg: to_json_binary(&TrioInstantiateMsg { asset_infos, token_code_id: config.token_code_id, asset_decimals, @@ -401,7 +401,7 @@ pub fn execute_migrate_pair( Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: contract, new_code_id: pair_code_id, - msg: to_binary(&PairMigrateMsg {})?, + msg: to_json_binary(&PairMigrateMsg {})?, })), ) } @@ -427,7 +427,7 @@ pub fn execute_migrate_trio( Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: contract, new_code_id: trio_code_id, - msg: to_binary(&TrioMigrateMsg {})?, + msg: to_json_binary(&TrioMigrateMsg {})?, })), ) } diff --git a/contracts/liquidity_hub/pool-network/terraswap_factory/src/contract.rs b/contracts/liquidity_hub/pool-network/terraswap_factory/src/contract.rs index a49f273b..be14e623 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_factory/src/contract.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_factory/src/contract.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, + to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, }; use cw2::{get_contract_version, set_contract_version}; use protobuf::Message; @@ -224,17 +224,17 @@ fn create_trio_reply(deps: DepsMut, msg: Reply) -> Result StdResult { match msg { - QueryMsg::Config {} => to_binary(&queries::query_config(deps)?), - QueryMsg::Pair { asset_infos } => to_binary(&queries::query_pair(deps, asset_infos)?), + QueryMsg::Config {} => to_json_binary(&queries::query_config(deps)?), + QueryMsg::Pair { asset_infos } => to_json_binary(&queries::query_pair(deps, asset_infos)?), QueryMsg::Pairs { start_after, limit } => { - to_binary(&queries::query_pairs(deps, start_after, limit)?) + to_json_binary(&queries::query_pairs(deps, start_after, limit)?) } - QueryMsg::Trio { asset_infos } => to_binary(&queries::query_trio(deps, asset_infos)?), + QueryMsg::Trio { asset_infos } => to_json_binary(&queries::query_trio(deps, asset_infos)?), QueryMsg::Trios { start_after, limit } => { - to_binary(&queries::query_trios(deps, start_after, limit)?) + to_json_binary(&queries::query_trios(deps, start_after, limit)?) } QueryMsg::NativeTokenDecimals { denom } => { - to_binary(&queries::query_native_token_decimal(deps, denom)?) + to_json_binary(&queries::query_native_token_decimal(deps, denom)?) } } } diff --git a/contracts/liquidity_hub/pool-network/terraswap_factory/src/testing.rs b/contracts/liquidity_hub/pool-network/terraswap_factory/src/testing.rs index c6f2a64d..f9734b4e 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_factory/src/testing.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_factory/src/testing.rs @@ -2,7 +2,7 @@ use cosmwasm_std::testing::{ mock_dependencies_with_balance, mock_env, mock_info, MockApi, MockStorage, MOCK_CONTRACT_ADDR, }; use cosmwasm_std::{ - attr, coin, from_binary, to_binary, Api, CanonicalAddr, Coin, CosmosMsg, Decimal, OwnedDeps, + attr, coin, from_json, to_json_binary, Api, CanonicalAddr, Coin, CosmosMsg, Decimal, OwnedDeps, Reply, ReplyOn, Response, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; @@ -45,7 +45,7 @@ fn proper_initialization() { let _res = instantiate(deps.as_mut(), mock_env(), info, msg).unwrap(); let query_res = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap(); - let config_res: ConfigResponse = from_binary(&query_res).unwrap(); + let config_res: ConfigResponse = from_json(&query_res).unwrap(); assert_eq!(123u64, config_res.token_code_id); assert_eq!(321u64, config_res.pair_code_id); assert_eq!("addr0000".to_string(), config_res.owner); @@ -107,7 +107,7 @@ fn update_config() { // it worked, let's query the state let query_res = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap(); - let config_res: ConfigResponse = from_binary(&query_res).unwrap(); + let config_res: ConfigResponse = from_json(&query_res).unwrap(); assert_eq!(123u64, config_res.token_code_id); assert_eq!(321u64, config_res.pair_code_id); assert_eq!("addr0001".to_string(), config_res.owner); @@ -130,7 +130,7 @@ fn update_config() { // it worked, let's query the state let query_res = query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap(); - let config_res: ConfigResponse = from_binary(&query_res).unwrap(); + let config_res: ConfigResponse = from_json(&query_res).unwrap(); assert_eq!(200u64, config_res.token_code_id); assert_eq!(100u64, config_res.pair_code_id); assert_eq!(300u64, config_res.trio_code_id); @@ -288,7 +288,7 @@ fn create_pair() { gas_limit: None, reply_on: ReplyOn::Success, msg: WasmMsg::Instantiate { - msg: to_binary(&expected_msg).unwrap(), + msg: to_json_binary(&expected_msg).unwrap(), code_id: 321u64, funds: [Coin { denom: "uusd".to_string(), @@ -399,7 +399,7 @@ fn create_stableswap_pair() { gas_limit: None, reply_on: ReplyOn::Success, msg: WasmMsg::Instantiate { - msg: to_binary(&expected_msg).unwrap(), + msg: to_json_binary(&expected_msg).unwrap(), code_id: 321u64, funds: vec![], label: "uusd-mAAPL pair".to_string(), @@ -522,7 +522,7 @@ fn create_pair_native_token_and_ibc_token() { gas_limit: None, reply_on: ReplyOn::Success, msg: WasmMsg::Instantiate { - msg: to_binary(&expected_msg).unwrap(), + msg: to_json_binary(&expected_msg).unwrap(), code_id: 321u64, funds: vec![], label: "uusd-ibc/2739...5EB2 pair".to_string(), @@ -652,7 +652,7 @@ fn create_ibc_tokens_pair() { gas_limit: None, reply_on: ReplyOn::Success, msg: WasmMsg::Instantiate { - msg: to_binary(&expected_msg).unwrap(), + msg: to_json_binary(&expected_msg).unwrap(), code_id: 321u64, funds: vec![], label: "ibc/4CD5...3D04-ibc/2739...5EB2 pair".to_string(), @@ -752,7 +752,7 @@ fn create_pair_ethereum_asset_and_ibc_token() { gas_limit: None, reply_on: ReplyOn::Success, msg: WasmMsg::Instantiate { - msg: to_binary(&PairInstantiateMsg { + msg: to_json_binary(&PairInstantiateMsg { asset_infos: asset_infos.clone(), token_code_id: 123u64, asset_decimals: [6u8, 6u8], @@ -1224,7 +1224,7 @@ fn reply_test() { ) .unwrap(); - let pair_res: PairInfo = from_binary(&query_res).unwrap(); + let pair_res: PairInfo = from_json(&query_res).unwrap(); assert_eq!( pair_res, PairInfo { @@ -1268,7 +1268,7 @@ fn normal_add_allow_native_token() { }, ) .unwrap(); - let res: NativeTokenDecimalsResponse = from_binary(&res).unwrap(); + let res: NativeTokenDecimalsResponse = from_json(&res).unwrap(); assert_eq!(6u8, res.decimals) } @@ -1315,7 +1315,7 @@ fn append_add_allow_native_token_with_already_exist_token() { }, ) .unwrap(); - let res: NativeTokenDecimalsResponse = from_binary(&res).unwrap(); + let res: NativeTokenDecimalsResponse = from_json(&res).unwrap(); assert_eq!(6u8, res.decimals); let msg = ExecuteMsg::AddNativeTokenDecimals { @@ -1333,7 +1333,7 @@ fn append_add_allow_native_token_with_already_exist_token() { }, ) .unwrap(); - let res: NativeTokenDecimalsResponse = from_binary(&res).unwrap(); + let res: NativeTokenDecimalsResponse = from_json(&res).unwrap(); assert_eq!(7u8, res.decimals) } @@ -1430,7 +1430,7 @@ fn normal_migrate_pair() { Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: "contract0000".to_string(), new_code_id: 123u64, - msg: to_binary(&PairMigrateMsg {}).unwrap(), + msg: to_json_binary(&PairMigrateMsg {}).unwrap(), })), ); } @@ -1452,7 +1452,7 @@ fn normal_migrate_trio() { Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: "contract0000".to_string(), new_code_id: 123u64, - msg: to_binary(&TrioMigrateMsg {}).unwrap(), + msg: to_json_binary(&TrioMigrateMsg {}).unwrap(), })), ); } @@ -1474,7 +1474,7 @@ fn normal_migrate_pair_with_none_code_id_will_config_code_id() { Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: "contract0000".to_string(), new_code_id: 321u64, - msg: to_binary(&PairMigrateMsg {}).unwrap(), + msg: to_json_binary(&PairMigrateMsg {}).unwrap(), })), ); } @@ -1496,7 +1496,7 @@ fn normal_migrate_trio_with_none_code_id_will_config_code_id() { Response::new().add_message(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: "contract0000".to_string(), new_code_id: 456u64, - msg: to_binary(&TrioMigrateMsg {}).unwrap(), + msg: to_json_binary(&TrioMigrateMsg {}).unwrap(), })), ); } @@ -1663,7 +1663,7 @@ fn update_pair_config() { .add_message(WasmMsg::Execute { contract_addr: "pair_addr".to_string(), funds: vec![], - msg: to_binary(&pool_network::pair::ExecuteMsg::UpdateConfig { + msg: to_json_binary(&pool_network::pair::ExecuteMsg::UpdateConfig { owner: Some("new_owner".to_string()), fee_collector_addr: None, pool_fees: Some(PoolFee { @@ -1748,7 +1748,7 @@ fn create_trio_cw20_lp() { gas_limit: None, reply_on: ReplyOn::Success, msg: WasmMsg::Instantiate { - msg: to_binary(&TrioInstantiateMsg { + msg: to_json_binary(&TrioInstantiateMsg { asset_infos: asset_infos.clone(), token_code_id: 123u64, asset_decimals: [6u8, 8u8, 10u8], @@ -1878,7 +1878,7 @@ fn create_trio_with_native_tokens_token_factory_lp() { gas_limit: None, reply_on: ReplyOn::Success, msg: WasmMsg::Instantiate { - msg: to_binary(&TrioInstantiateMsg { + msg: to_json_binary(&TrioInstantiateMsg { asset_infos: asset_infos.clone(), token_code_id: 123u64, asset_decimals: [6u8, 6u8, 6u8], diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs index 375b36d5..c0f98223 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/commands.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "osmosis")] use anybuf::Anybuf; #[cfg(any( feature = "token_factory", @@ -6,7 +7,7 @@ use anybuf::Anybuf; ))] use cosmwasm_std::coins; use cosmwasm_std::{ - from_binary, to_binary, Addr, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, OverflowError, + from_json, to_json_binary, Addr, CosmosMsg, Decimal, DepsMut, Env, MessageInfo, OverflowError, Response, StdError, StdResult, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; @@ -50,7 +51,7 @@ pub fn receive_cw20( let contract_addr = info.sender.clone(); let feature_toggle: FeatureToggle = CONFIG.load(deps.storage)?.feature_toggle; - match from_binary(&cw20_msg.msg) { + match from_json(&cw20_msg.msg) { Ok(Cw20HookMsg::Swap { belief_price, max_spread, @@ -172,7 +173,7 @@ pub fn provide_liquidity( if let AssetInfo::Token { contract_addr, .. } = &pool.info { messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract_addr.to_string(), - msg: to_binary(&Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom { owner: info.sender.to_string(), recipient: env.contract.address.to_string(), amount: deposits[i], @@ -363,8 +364,13 @@ pub fn swap( let ask_decimal: u8; // To calculate pool amounts properly we should subtract user deposit and the protocol fees from the pool + #[cfg(not(feature = "osmosis"))] + let contract_addr = env.contract.address; + #[cfg(feature = "osmosis")] + let contract_addr = env.contract.address.clone(); + let pools = pair_info - .query_pools(&deps.querier, deps.api, env.contract.address.clone())? + .query_pools(&deps.querier, deps.api, contract_addr)? .into_iter() .map(|mut pool| { // subtract the protocol fee from the pool @@ -482,7 +488,7 @@ pub fn swap( .append_string(1, denom) .append_string(2, swap_computation.osmosis_fee_amount.to_string())], ) - .append_string(2, env.contract.address.to_string()) + .append_string(2, &env.contract.address) .into_vec() .into(), }; @@ -657,7 +663,7 @@ fn mint_lp_token_msg( } else { Ok(vec![CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: liquidity_token, - msg: to_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?, + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?, funds: vec![], })]) } @@ -669,7 +675,7 @@ fn mint_lp_token_msg( ))] Ok(vec![CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: liquidity_token, - msg: to_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?, + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?, funds: vec![], })]) } @@ -697,7 +703,7 @@ fn burn_lp_token_msg( } else { Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: liquidity_token, - msg: to_binary(&Cw20ExecuteMsg::Burn { amount })?, + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount })?, funds: vec![], })) } @@ -708,7 +714,7 @@ fn burn_lp_token_msg( ))] Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: liquidity_token, - msg: to_binary(&Cw20ExecuteMsg::Burn { amount })?, + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount })?, funds: vec![], })) } diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/contract.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/contract.rs index 09df1aeb..dc267f91 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/contract.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/contract.rs @@ -1,7 +1,7 @@ #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - to_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, + to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult, }; use cw2::{get_contract_version, set_contract_version}; @@ -203,23 +203,24 @@ pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> StdResult { #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result { match msg { - QueryMsg::Pair {} => Ok(to_binary(&queries::query_pair_info(deps)?)?), - QueryMsg::Pool {} => Ok(to_binary(&queries::query_pool(deps)?)?), - QueryMsg::Simulation { offer_asset } => { - Ok(to_binary(&queries::query_simulation(deps, offer_asset)?)?) - } - QueryMsg::ReverseSimulation { ask_asset } => Ok(to_binary( + QueryMsg::Pair {} => Ok(to_json_binary(&queries::query_pair_info(deps)?)?), + QueryMsg::Pool {} => Ok(to_json_binary(&queries::query_pool(deps)?)?), + QueryMsg::Simulation { offer_asset } => Ok(to_json_binary(&queries::query_simulation( + deps, + offer_asset, + )?)?), + QueryMsg::ReverseSimulation { ask_asset } => Ok(to_json_binary( &queries::query_reverse_simulation(deps, ask_asset)?, )?), - QueryMsg::Config {} => Ok(to_binary(&queries::query_config(deps)?)?), - QueryMsg::ProtocolFees { asset_id, all_time } => Ok(to_binary(&queries::query_fees( + QueryMsg::Config {} => Ok(to_json_binary(&queries::query_config(deps)?)?), + QueryMsg::ProtocolFees { asset_id, all_time } => Ok(to_json_binary(&queries::query_fees( deps, asset_id, all_time, COLLECTED_PROTOCOL_FEES, Some(ALL_TIME_COLLECTED_PROTOCOL_FEES), )?)?), - QueryMsg::BurnedFees { asset_id } => Ok(to_binary(&queries::query_fees( + QueryMsg::BurnedFees { asset_id } => Ok(to_json_binary(&queries::query_fees( deps, asset_id, None, @@ -234,6 +235,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result Result { use white_whale::migrate_guards::check_contract_name; + #[cfg(not(feature = "osmosis"))] use crate::migrations; check_contract_name(deps.storage, CONTRACT_NAME.to_string())?; diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs index f5f67dcb..0a191801 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/helpers.rs @@ -8,8 +8,8 @@ use cosmwasm_schema::cw_serde; ))] use cosmwasm_std::CosmosMsg; use cosmwasm_std::{ - to_binary, Decimal, Decimal256, DepsMut, Env, ReplyOn, Response, StdError, StdResult, Storage, - SubMsg, Uint128, Uint256, WasmMsg, + to_json_binary, Decimal, Decimal256, DepsMut, Env, ReplyOn, Response, StdError, StdResult, + Storage, SubMsg, Uint128, Uint256, WasmMsg, }; use cw20::MinterResponse; use cw_storage_plus::Item; @@ -555,7 +555,7 @@ pub fn create_lp_token( msg: WasmMsg::Instantiate { admin: None, code_id: msg.token_code_id, - msg: to_binary(&TokenInstantiateMsg { + msg: to_json_binary(&TokenInstantiateMsg { name: lp_token_name.to_owned(), symbol: LP_SYMBOL.to_string(), decimals: 6, diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/migrations.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/migrations.rs index 9c1cd1db..a2e9f73d 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/migrations.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/migrations.rs @@ -19,7 +19,7 @@ use crate::helpers::instantiate_fees; use crate::state::PAIR_INFO; use crate::state::{ALL_TIME_BURNED_FEES, CONFIG}; -#[cfg(not(feature = "injective"))] +#[cfg(all(not(feature = "injective"), not(feature = "osmosis")))] /// Migrate state of the factory from PascalCase to snake_case for the following items: /// [`PairInfoRaw`], [`PairInfo`] /// as identified by commit c8d8462c6933b93245acdc8abbe303287fdc1951 which changed the structs to use diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/feature_toggle.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/feature_toggle.rs index fc86c2fd..4ffad952 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/feature_toggle.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/feature_toggle.rs @@ -1,7 +1,7 @@ use crate::contract::{execute, instantiate}; use crate::error::ContractError; use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; -use cosmwasm_std::{to_binary, Coin, Decimal, Uint128}; +use cosmwasm_std::{to_json_binary, Coin, Decimal, Uint128}; use cw20::Cw20ReceiveMsg; use white_whale::fee::Fee; use white_whale::pool_network::asset::{Asset, AssetInfo, PairType}; @@ -104,7 +104,7 @@ fn test_feature_toggle_swap_disabled() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { belief_price: None, max_spread: None, to: None, @@ -185,7 +185,7 @@ fn test_feature_toggle_withdrawals_disabled() { // withdraw liquidity should fail let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), + msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), amount: Uint128::from(100u128), }); diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/protocol_fees.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/protocol_fees.rs index ff1461c3..f3459fc7 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/protocol_fees.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/protocol_fees.rs @@ -3,7 +3,7 @@ use crate::queries::query_fees; use crate::state::{ALL_TIME_COLLECTED_PROTOCOL_FEES, COLLECTED_PROTOCOL_FEES}; use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - to_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, StdError, SubMsg, SubMsgResponse, + to_json_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, StdError, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; @@ -301,7 +301,7 @@ fn test_collect_protocol_fees_successful() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { belief_price: None, max_spread: None, to: None, @@ -368,7 +368,7 @@ fn test_collect_protocol_fees_successful() { transfer_cw20_token_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "collector".to_string(), amount: protocol_fees_for_token.first().unwrap().amount, }) @@ -551,7 +551,7 @@ fn test_collect_protocol_fees_successful_1_fee_only() { transfer_cw20_token_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "collector".to_string(), amount: protocol_fees[1].amount, }) diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/provide_liquidity.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/provide_liquidity.rs index 3b1155d5..e26f6f17 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/provide_liquidity.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/provide_liquidity.rs @@ -2,7 +2,7 @@ use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; #[cfg(feature = "token_factory")] use cosmwasm_std::{coin, BankMsg}; use cosmwasm_std::{ - to_binary, Coin, CosmosMsg, Decimal, Reply, Response, StdError, SubMsg, SubMsgResponse, + to_json_binary, Coin, CosmosMsg, Decimal, Reply, Response, StdError, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::Cw20ExecuteMsg; @@ -167,7 +167,7 @@ fn provide_liquidity_cw20_lp() { transfer_from_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom { owner: "addr0000".to_string(), recipient: MOCK_CONTRACT_ADDR.to_string(), amount: Uint128::from(2_000u128), @@ -180,7 +180,7 @@ fn provide_liquidity_cw20_lp() { mint_initial_lp_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: "cosmos2contract".to_string(), amount: MINIMUM_LIQUIDITY_AMOUNT, }) @@ -192,7 +192,7 @@ fn provide_liquidity_cw20_lp() { mint_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: "addr0000".to_string(), amount: Uint128::from(1_000u128), }) @@ -262,7 +262,7 @@ fn provide_liquidity_cw20_lp() { transfer_from_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom { owner: "addr0000".to_string(), recipient: MOCK_CONTRACT_ADDR.to_string(), amount: Uint128::from(100u128), @@ -275,7 +275,7 @@ fn provide_liquidity_cw20_lp() { mint_msg, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: "staking0000".to_string(), // LP tokens sent to specified receiver amount: Uint128::from(50u128), }) diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/swap.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/swap.rs index 1da6a72f..ec3e77e1 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/swap.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/swap.rs @@ -1,8 +1,8 @@ use anybuf::Anybuf; use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - attr, coins, from_binary, to_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, ReplyOn, SubMsg, - SubMsgResponse, SubMsgResult, Uint128, WasmMsg, + attr, coins, from_json, to_json_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, ReplyOn, + SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; @@ -180,7 +180,7 @@ fn try_native_to_token() { id: 0, msg: CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: expected_burn_fee_amount, }) .unwrap(), @@ -276,7 +276,7 @@ fn try_native_to_token() { ) .unwrap(); - let simulation_res: SimulationResponse = from_binary( + let simulation_res: SimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -323,7 +323,7 @@ fn try_native_to_token() { ) .unwrap(); - let reverse_simulation_res: ReverseSimulationResponse = from_binary( + let reverse_simulation_res: ReverseSimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -393,7 +393,7 @@ fn try_native_to_token() { assert_eq!( &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: expected_return_amount, }) @@ -623,7 +623,7 @@ fn try_token_to_native() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { belief_price: None, max_spread: Some(Decimal::percent(5u64)), to: Some("third_party".to_string()), @@ -775,7 +775,7 @@ fn try_token_to_native() { ) .unwrap(); - let simulation_res: SimulationResponse = from_binary( + let simulation_res: SimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -828,7 +828,7 @@ fn try_token_to_native() { .unwrap(); // check reverse simulation res - let reverse_simulation_res: ReverseSimulationResponse = from_binary( + let reverse_simulation_res: ReverseSimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -922,7 +922,7 @@ fn try_token_to_native() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::Swap { + msg: to_json_binary(&Cw20HookMsg::Swap { belief_price: None, max_spread: None, to: None, @@ -1063,7 +1063,7 @@ fn test_swap_to_third_party() { ) .unwrap(); - let simulation_res: SimulationResponse = from_binary( + let simulation_res: SimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -1142,7 +1142,7 @@ fn stableswap_reverse_simulation() { .unwrap(); // check reverse simulation res - let reverse_simulation_res: ReverseSimulationResponse = from_binary( + let reverse_simulation_res: ReverseSimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -1337,7 +1337,7 @@ fn stableswap_with_different_precisions() { ) .unwrap(); - let simulation_res: SimulationResponse = from_binary( + let simulation_res: SimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -1384,7 +1384,7 @@ fn stableswap_with_different_precisions() { ) .unwrap(); - let reverse_simulation_res: ReverseSimulationResponse = from_binary( + let reverse_simulation_res: ReverseSimulationResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -1436,7 +1436,7 @@ fn stableswap_with_different_precisions() { assert_eq!( &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: expected_return_amount, }) diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs index 96a7b5a9..d57eba05 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/testing.rs @@ -2,7 +2,7 @@ use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; #[cfg(feature = "token_factory")] use cosmwasm_std::CosmosMsg; use cosmwasm_std::{ - from_binary, to_binary, Addr, Decimal, Reply, ReplyOn, StdError, SubMsg, SubMsgResponse, + from_json, to_json_binary, Addr, Decimal, Reply, ReplyOn, StdError, SubMsg, SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::MinterResponse; @@ -70,7 +70,7 @@ fn proper_initialization_cw20_lp() { vec![SubMsg { msg: WasmMsg::Instantiate { code_id: 10u64, - msg: to_binary(&TokenInstantiateMsg { + msg: to_json_binary(&TokenInstantiateMsg { name: "uusd-mAAPL-LP".to_string(), symbol: "uLP".to_string(), decimals: 6, @@ -636,7 +636,7 @@ fn test_update_config_successful() { instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap(); let config: Config = - from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); // check for original config assert_eq!(config.owner, Addr::unchecked("addr0000")); @@ -687,7 +687,7 @@ fn test_update_config_successful() { execute(deps.as_mut(), env, info, update_config_message).unwrap(); let config: Config = - from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); // check for new config assert_eq!(config.owner, Addr::unchecked("new_admin")); diff --git a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/withdrawals.rs b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/withdrawals.rs index a7d0308b..b03642a7 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/withdrawals.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_pair/src/tests/withdrawals.rs @@ -1,7 +1,7 @@ use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - attr, to_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, Response, SubMsg, SubMsgResponse, - SubMsgResult, Uint128, WasmMsg, + attr, to_json_binary, BankMsg, Coin, CosmosMsg, Decimal, Reply, Response, SubMsg, + SubMsgResponse, SubMsgResult, Uint128, WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; @@ -108,7 +108,7 @@ fn withdraw_xyk_liquidity_cw20_lp() { // withdraw liquidity let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), + msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), amount: Uint128::from(100u128), }); @@ -155,7 +155,7 @@ fn withdraw_xyk_liquidity_cw20_lp() { msg_refund_1, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: expected_token_refund_amount, }) @@ -167,7 +167,7 @@ fn withdraw_xyk_liquidity_cw20_lp() { msg_burn_liquidity, &SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: Uint128::from(100u128), }) .unwrap(), @@ -269,7 +269,7 @@ fn withdraw_stableswap_liquidity() { // withdraw liquidity let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), + msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), amount: Uint128::from(100u128), }); @@ -310,7 +310,7 @@ fn withdraw_stableswap_liquidity() { }), CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: expected_token_refund_amount, }) @@ -319,7 +319,7 @@ fn withdraw_stableswap_liquidity() { }), CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "liquidity0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: Uint128::from(100u128), }) .unwrap(), @@ -388,7 +388,7 @@ fn test_withdrawal_unauthorized() { // withdraw liquidity should fail let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), + msg: to_json_binary(&Cw20HookMsg::WithdrawLiquidity {}).unwrap(), amount: Uint128::from(100u128), }); @@ -455,7 +455,7 @@ fn test_withdrawal_wrong_message() { // withdraw liquidity should fail let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), - msg: to_binary(&"invalid_message").unwrap(), + msg: to_json_binary(&"invalid_message").unwrap(), amount: Uint128::from(100u128), }); diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs index 27724aaf..0c27ff42 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/contract.rs @@ -3,7 +3,7 @@ use std::collections::HashMap; #[cfg(not(feature = "library"))] use cosmwasm_std::entry_point; use cosmwasm_std::{ - attr, from_binary, to_binary, Addr, Api, Binary, CosmosMsg, Decimal, Deps, DepsMut, Env, + attr, from_json, to_json_binary, Addr, Api, Binary, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Order, Response, StdError, StdResult, Uint128, WasmMsg, }; use cw2::{get_contract_version, set_contract_version}; @@ -125,7 +125,7 @@ pub fn receive_cw20( cw20_msg: Cw20ReceiveMsg, ) -> Result { let sender = deps.api.addr_validate(&cw20_msg.sender)?; - match from_binary(&cw20_msg.msg)? { + match from_json(&cw20_msg.msg)? { Cw20HookMsg::ExecuteSwapOperations { operations, minimum_receive, @@ -177,7 +177,7 @@ pub fn execute_swap_operations( Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: env.contract.address.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::ExecuteSwapOperation { + msg: to_json_binary(&ExecuteMsg::ExecuteSwapOperation { operation: op, to: if operation_index == operations_len { Some(to.to_string()) @@ -197,7 +197,7 @@ pub fn execute_swap_operations( messages.push(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: env.contract.address.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::AssertMinimumReceive { + msg: to_json_binary(&ExecuteMsg::AssertMinimumReceive { asset_info: target_asset_info, prev_balance: receiver_balance, minimum_receive, @@ -279,11 +279,11 @@ fn add_swap_routes( #[cfg_attr(not(feature = "library"), entry_point)] pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result { match msg { - QueryMsg::Config {} => Ok(to_binary(&query_config(deps)?)?), + QueryMsg::Config {} => Ok(to_json_binary(&query_config(deps)?)?), QueryMsg::SimulateSwapOperations { offer_amount, operations, - } => Ok(to_binary(&simulate_swap_operations( + } => Ok(to_json_binary(&simulate_swap_operations( deps, offer_amount, operations, @@ -291,18 +291,18 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result Ok(to_binary(&reverse_simulate_swap_operations( + } => Ok(to_json_binary(&reverse_simulate_swap_operations( deps, ask_amount, operations, )?)?), QueryMsg::SwapRoute { offer_asset_info, ask_asset_info, - } => Ok(to_binary(&get_swap_route( + } => Ok(to_json_binary(&get_swap_route( deps, offer_asset_info, ask_asset_info, )?)?), - QueryMsg::SwapRoutes {} => Ok(to_binary(&get_swap_routes(deps)?)?), + QueryMsg::SwapRoutes {} => Ok(to_json_binary(&get_swap_routes(deps)?)?), } } diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/operations.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/operations.rs index 804b8df0..dd96e810 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/operations.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/operations.rs @@ -1,5 +1,6 @@ use cosmwasm_std::{ - to_binary, Addr, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Response, WasmMsg, + to_json_binary, Addr, Coin, CosmosMsg, Decimal, Deps, DepsMut, Env, MessageInfo, Response, + WasmMsg, }; use crate::state::{Config, CONFIG}; @@ -81,7 +82,7 @@ pub fn asset_into_swap_msg( denom, amount: offer_asset.amount, }], - msg: to_binary(&PairExecuteMsg::Swap { + msg: to_json_binary(&PairExecuteMsg::Swap { offer_asset, belief_price: None, max_spread, @@ -91,10 +92,10 @@ pub fn asset_into_swap_msg( AssetInfo::Token { contract_addr } => Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr, funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::Send { + msg: to_json_binary(&Cw20ExecuteMsg::Send { contract: pair_contract.to_string(), amount: offer_asset.amount, - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread, to, diff --git a/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs b/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs index 8222d7eb..ab1e0986 100644 --- a/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs +++ b/contracts/liquidity_hub/pool-network/terraswap_router/src/testing/tests.rs @@ -1,6 +1,7 @@ use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - attr, coin, from_binary, to_binary, Addr, Coin, CosmosMsg, StdError, SubMsg, Uint128, WasmMsg, + attr, coin, from_json, to_json_binary, Addr, Coin, CosmosMsg, StdError, SubMsg, Uint128, + WasmMsg, }; use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg}; use white_whale::pool_network; @@ -33,7 +34,7 @@ fn proper_initialization() { // it worked, let's query the state let config: ConfigResponse = - from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), QueryMsg::Config {}).unwrap()).unwrap(); assert_eq!("terraswapfactory", config.terraswap_factory.as_str()); } @@ -111,7 +112,7 @@ fn execute_swap_operations() { SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: MOCK_CONTRACT_ADDR.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::ExecuteSwapOperation { + msg: to_json_binary(&ExecuteMsg::ExecuteSwapOperation { operation: SwapOperation::TerraSwap { offer_asset_info: AssetInfo::NativeToken { denom: "ukrw".to_string(), @@ -128,7 +129,7 @@ fn execute_swap_operations() { SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: MOCK_CONTRACT_ADDR.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::ExecuteSwapOperation { + msg: to_json_binary(&ExecuteMsg::ExecuteSwapOperation { operation: SwapOperation::TerraSwap { offer_asset_info: AssetInfo::Token { contract_addr: "asset0001".to_string(), @@ -145,7 +146,7 @@ fn execute_swap_operations() { SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: MOCK_CONTRACT_ADDR.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::ExecuteSwapOperation { + msg: to_json_binary(&ExecuteMsg::ExecuteSwapOperation { operation: SwapOperation::TerraSwap { offer_asset_info: AssetInfo::NativeToken { denom: "uluna".to_string(), @@ -162,7 +163,7 @@ fn execute_swap_operations() { SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: MOCK_CONTRACT_ADDR.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::AssertMinimumReceive { + msg: to_json_binary(&ExecuteMsg::AssertMinimumReceive { asset_info: AssetInfo::Token { contract_addr: "asset0002".to_string(), }, @@ -178,7 +179,7 @@ fn execute_swap_operations() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0000".to_string(), amount: Uint128::from(1000000u128), - msg: to_binary(&Cw20HookMsg::ExecuteSwapOperations { + msg: to_json_binary(&Cw20HookMsg::ExecuteSwapOperations { operations: vec![ SwapOperation::TerraSwap { offer_asset_info: AssetInfo::NativeToken { @@ -220,7 +221,7 @@ fn execute_swap_operations() { SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: MOCK_CONTRACT_ADDR.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::ExecuteSwapOperation { + msg: to_json_binary(&ExecuteMsg::ExecuteSwapOperation { operation: SwapOperation::TerraSwap { offer_asset_info: AssetInfo::NativeToken { denom: "ukrw".to_string(), @@ -237,7 +238,7 @@ fn execute_swap_operations() { SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: MOCK_CONTRACT_ADDR.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::ExecuteSwapOperation { + msg: to_json_binary(&ExecuteMsg::ExecuteSwapOperation { operation: SwapOperation::TerraSwap { offer_asset_info: AssetInfo::Token { contract_addr: "asset0001".to_string(), @@ -254,7 +255,7 @@ fn execute_swap_operations() { SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: MOCK_CONTRACT_ADDR.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::ExecuteSwapOperation { + msg: to_json_binary(&ExecuteMsg::ExecuteSwapOperation { operation: SwapOperation::TerraSwap { offer_asset_info: AssetInfo::NativeToken { denom: "uluna".to_string(), @@ -436,10 +437,10 @@ fn execute_swap_operation() { vec![SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset".to_string(), funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::Send { + msg: to_json_binary(&Cw20ExecuteMsg::Send { contract: "pair0000".to_string(), amount: Uint128::from(1000000u128), - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread: None, to: Some("addr0000".to_string()), @@ -544,7 +545,7 @@ fn query_buy_with_routes() { ); let res: SimulateSwapOperationsResponse = - from_binary(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); assert_eq!( res, SimulateSwapOperationsResponse { @@ -652,7 +653,7 @@ fn query_reverse_routes_with_from_native() { ); let res: SimulateSwapOperationsResponse = - from_binary(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); assert_eq!( res, @@ -690,7 +691,7 @@ fn query_reverse_routes_with_from_native() { vec![SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "pair0000".to_string(), funds: vec![coin(target_amount, "ukrw")], - msg: to_binary(&PairExecuteMsg::Swap { + msg: to_json_binary(&PairExecuteMsg::Swap { offer_asset: Asset { info: AssetInfo::NativeToken { denom: "ukrw".to_string(), @@ -789,7 +790,7 @@ fn query_reverse_routes_with_to_native() { ); let res: SimulateSwapOperationsResponse = - from_binary(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); assert_eq!( res, @@ -803,7 +804,7 @@ fn query_reverse_routes_with_to_native() { let msg = ExecuteMsg::Receive(Cw20ReceiveMsg { sender: "addr0".to_string(), amount: offer_amount, - msg: to_binary(&Cw20HookMsg::ExecuteSwapOperations { + msg: to_json_binary(&Cw20HookMsg::ExecuteSwapOperations { operations: vec![SwapOperation::TerraSwap { offer_asset_info: AssetInfo::Token { contract_addr: "asset0000".to_string(), @@ -826,7 +827,7 @@ fn query_reverse_routes_with_to_native() { vec![SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: MOCK_CONTRACT_ADDR.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::ExecuteSwapOperation { + msg: to_json_binary(&ExecuteMsg::ExecuteSwapOperation { operation: SwapOperation::TerraSwap { offer_asset_info: AssetInfo::Token { contract_addr: "asset0000".to_string(), @@ -863,10 +864,10 @@ fn query_reverse_routes_with_to_native() { vec![SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::Send { + msg: to_json_binary(&Cw20ExecuteMsg::Send { contract: "pair0000".to_string(), amount: Uint128::from(target_amount), - msg: to_binary(&pool_network::pair::Cw20HookMsg::Swap { + msg: to_json_binary(&pool_network::pair::Cw20HookMsg::Swap { belief_price: None, max_spread: None, to: None, @@ -1183,7 +1184,7 @@ fn add_swap_routes() { }; let res: Vec = - from_binary(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); assert_eq!(res, swap_route_1.swap_operations); } @@ -1569,7 +1570,7 @@ fn all_swap_routes() { let msg = QueryMsg::SwapRoutes {}; let res: Vec = - from_binary(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), mock_env(), msg).unwrap()).unwrap(); assert_eq!(res.len(), 2usize); // Verify it has the correct swap routes assert_eq!(res[0].swap_route, swap_route_1.swap_operations); diff --git a/contracts/liquidity_hub/vault-network/vault/src/contract.rs b/contracts/liquidity_hub/vault-network/vault/src/contract.rs index be453023..7f9e9682 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/contract.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/contract.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - attr, entry_point, to_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, ReplyOn, + attr, entry_point, to_json_binary, Binary, Decimal, Deps, DepsMut, Env, MessageInfo, ReplyOn, Response, StdError, StdResult, SubMsg, WasmMsg, }; use cw2::{get_contract_version, set_contract_version}; @@ -153,7 +153,7 @@ pub fn instantiate( msg: WasmMsg::Instantiate { admin: None, code_id: msg.token_id, - msg: to_binary(&white_whale::pool_network::token::InstantiateMsg { + msg: to_json_binary(&white_whale::pool_network::token::InstantiateMsg { name: lp_label.clone(), symbol: lp_symbol, decimals: 6, diff --git a/contracts/liquidity_hub/vault-network/vault/src/execute/callback/after_trade.rs b/contracts/liquidity_hub/vault-network/vault/src/execute/callback/after_trade.rs index b5a10477..3094f292 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/execute/callback/after_trade.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/execute/callback/after_trade.rs @@ -97,7 +97,8 @@ mod test { use cosmwasm_std::{ coins, testing::{mock_env, mock_info}, - to_binary, Addr, BankMsg, CosmosMsg, Decimal, ReplyOn, Response, SubMsg, Uint128, WasmMsg, + to_json_binary, Addr, BankMsg, CosmosMsg, Decimal, ReplyOn, Response, SubMsg, Uint128, + WasmMsg, }; use cw20::Cw20ExecuteMsg; @@ -311,7 +312,7 @@ mod test { id: 0, msg: CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "vault_token".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: Uint128::new(1), }) .unwrap(), diff --git a/contracts/liquidity_hub/vault-network/vault/src/execute/deposit.rs b/contracts/liquidity_hub/vault-network/vault/src/execute/deposit.rs index e2c61bb8..f0ec8dc2 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/execute/deposit.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/execute/deposit.rs @@ -5,7 +5,7 @@ ))] use cosmwasm_std::coins; use cosmwasm_std::{ - to_binary, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128, Uint256, WasmMsg, + to_json_binary, CosmosMsg, DepsMut, Env, MessageInfo, Response, Uint128, Uint256, WasmMsg, }; use cw20::{AllowanceResponse, Cw20ExecuteMsg}; @@ -81,7 +81,7 @@ pub fn deposit( messages.push( WasmMsg::Execute { contract_addr, - msg: to_binary(&Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom { owner: info.sender.clone().into_string(), recipient: env.contract.address.clone().into_string(), amount, @@ -192,7 +192,7 @@ fn mint_lp_token_msg( } else { Ok(vec![CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: liquidity_asset, - msg: to_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?, + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?, funds: vec![], })]) } @@ -204,7 +204,7 @@ fn mint_lp_token_msg( ))] Ok(vec![CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: liquidity_asset, - msg: to_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?, + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?, funds: vec![], })]) } @@ -214,7 +214,7 @@ mod test { use cosmwasm_std::{ coins, testing::{mock_dependencies, mock_env, mock_info}, - to_binary, Addr, BankMsg, CosmosMsg, Response, Uint128, WasmMsg, + to_json_binary, Addr, BankMsg, CosmosMsg, Response, Uint128, WasmMsg, }; use cw20::Cw20ExecuteMsg; use cw_multi_test::Executor; @@ -285,7 +285,7 @@ mod test { WasmMsg::Execute { contract_addr: "lp_token".to_string(), funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: env.contract.address.to_string(), amount: Uint128::new(1_000), }) @@ -294,7 +294,7 @@ mod test { WasmMsg::Execute { contract_addr: "lp_token".to_string(), funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: "creator".to_string(), amount: Uint128::new(4_000), }) @@ -361,7 +361,7 @@ mod test { WasmMsg::Execute { contract_addr: "vault_token".to_string(), funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::TransferFrom { + msg: to_json_binary(&Cw20ExecuteMsg::TransferFrom { owner: "creator".to_string(), recipient: env.contract.address.clone().into_string(), amount: Uint128::new(5_000), @@ -371,7 +371,7 @@ mod test { WasmMsg::Execute { contract_addr: "lp_token".to_string(), funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: env.contract.address.into_string(), amount: Uint128::new(1_000), }) @@ -380,7 +380,7 @@ mod test { WasmMsg::Execute { contract_addr: "lp_token".to_string(), funds: vec![], - msg: to_binary(&Cw20ExecuteMsg::Mint { + msg: to_json_binary(&Cw20ExecuteMsg::Mint { recipient: "creator".to_string(), amount: Uint128::new(4_000), }) diff --git a/contracts/liquidity_hub/vault-network/vault/src/execute/flash_loan.rs b/contracts/liquidity_hub/vault-network/vault/src/execute/flash_loan.rs index 5d5b35ae..9ea8da16 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/execute/flash_loan.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/execute/flash_loan.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - coins, to_binary, Binary, CosmosMsg, DepsMut, Env, MessageInfo, OverflowError, Response, + coins, to_json_binary, Binary, CosmosMsg, DepsMut, Env, MessageInfo, OverflowError, Response, StdError, Uint128, WasmMsg, }; use cw20::{BalanceResponse, Cw20ExecuteMsg, Cw20QueryMsg}; @@ -54,7 +54,7 @@ pub fn flash_loan( if let AssetInfo::Token { contract_addr } = config.asset_info.clone() { let loan_msg = WasmMsg::Execute { contract_addr, - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: info.sender.clone().into_string(), amount, })?, @@ -84,7 +84,7 @@ pub fn flash_loan( messages.push( WasmMsg::Execute { contract_addr: env.contract.address.into_string(), - msg: to_binary(&ExecuteMsg::Callback(CallbackMsg::AfterTrade { + msg: to_json_binary(&ExecuteMsg::Callback(CallbackMsg::AfterTrade { old_balance, loan_amount: amount, }))?, @@ -104,7 +104,7 @@ mod test { use cosmwasm_std::{ coins, testing::{mock_dependencies, mock_dependencies_with_balance, mock_env}, - to_binary, Addr, BankMsg, Response, Uint128, WasmMsg, + to_json_binary, Addr, BankMsg, Response, Uint128, WasmMsg, }; use white_whale::pool_network::asset::AssetInfo; use white_whale::vault_network::vault::Config; @@ -147,7 +147,7 @@ mod test { mock_creator(), white_whale::vault_network::vault::ExecuteMsg::FlashLoan { amount: Uint128::new(5_000), - msg: to_binary(&BankMsg::Burn { amount: vec![] }).unwrap(), + msg: to_json_binary(&BankMsg::Burn { amount: vec![] }).unwrap(), }, ); @@ -159,7 +159,7 @@ mod test { let mut deps = mock_dependencies_with_balance(&coins(10_000, "uluna")); let env = mock_env(); - let callback_msg = to_binary(&BankMsg::Burn { amount: vec![] }).unwrap(); + let callback_msg = to_json_binary(&BankMsg::Burn { amount: vec![] }).unwrap(); instantiate( deps.as_mut(), @@ -201,7 +201,7 @@ mod test { let mut deps = mock_dependencies_with_balance(&coins(10_000, "uluna")); let env = mock_env(); - let callback_msg = to_binary(&BankMsg::Burn { amount: vec![] }).unwrap(); + let callback_msg = to_json_binary(&BankMsg::Burn { amount: vec![] }).unwrap(); instantiate( deps.as_mut(), @@ -244,12 +244,14 @@ mod test { WasmMsg::Execute { contract_addr: env.contract.address.into_string(), funds: vec![], - msg: to_binary(&white_whale::vault_network::vault::ExecuteMsg::Callback( - white_whale::vault_network::vault::CallbackMsg::AfterTrade { - old_balance: Uint128::new(10_000), - loan_amount: Uint128::new(5_000) - } - )) + msg: to_json_binary( + &white_whale::vault_network::vault::ExecuteMsg::Callback( + white_whale::vault_network::vault::CallbackMsg::AfterTrade { + old_balance: Uint128::new(10_000), + loan_amount: Uint128::new(5_000) + } + ) + ) .unwrap() } ]) @@ -268,7 +270,7 @@ mod test { vec![], ); - let callback_msg = to_binary(&BankMsg::Burn { amount: vec![] }).unwrap(); + let callback_msg = to_json_binary(&BankMsg::Burn { amount: vec![] }).unwrap(); // inject config CONFIG @@ -313,7 +315,7 @@ mod test { WasmMsg::Execute { contract_addr: "vault_token".to_string(), funds: vec![], - msg: to_binary(&cw20::Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::Transfer { recipient: mock_creator().sender.into_string(), amount: Uint128::new(5_000) }) @@ -327,12 +329,14 @@ mod test { WasmMsg::Execute { contract_addr: env.contract.address.into_string(), funds: vec![], - msg: to_binary(&white_whale::vault_network::vault::ExecuteMsg::Callback( - white_whale::vault_network::vault::CallbackMsg::AfterTrade { - old_balance: Uint128::new(10_000), - loan_amount: Uint128::new(5_000) - } - )) + msg: to_json_binary( + &white_whale::vault_network::vault::ExecuteMsg::Callback( + white_whale::vault_network::vault::CallbackMsg::AfterTrade { + old_balance: Uint128::new(10_000), + loan_amount: Uint128::new(5_000) + } + ) + ) .unwrap() } ]) diff --git a/contracts/liquidity_hub/vault-network/vault/src/execute/receive/mod.rs b/contracts/liquidity_hub/vault-network/vault/src/execute/receive/mod.rs index b08de1b0..b0b0d5b0 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/execute/receive/mod.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/execute/receive/mod.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{from_binary, DepsMut, Env, MessageInfo, Response}; +use cosmwasm_std::{from_json, DepsMut, Env, MessageInfo, Response}; use white_whale::pool_network::asset::AssetInfo; use white_whale::vault_network::vault::{Cw20HookMsg, Cw20ReceiveMsg}; @@ -27,14 +27,14 @@ pub fn receive( return Err(VaultError::ExternalCallback {}); } - match from_binary(&msg.msg)? { + match from_json(&msg.msg)? { Cw20HookMsg::Withdraw {} => withdraw(deps, env, msg.sender, msg.amount), } } #[cfg(test)] mod test { - use cosmwasm_std::{to_binary, Addr, Uint128}; + use cosmwasm_std::{to_json_binary, Addr, Uint128}; #[cfg(any( feature = "token_factory", @@ -89,7 +89,7 @@ mod test { white_whale::vault_network::vault::Cw20ReceiveMsg { sender: mock_creator().sender.into_string(), amount: Uint128::new(5_000), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) + msg: to_json_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) .unwrap(), }, ); @@ -136,7 +136,7 @@ mod test { white_whale::vault_network::vault::Cw20ReceiveMsg { sender: mock_creator().sender.into_string(), amount: Uint128::new(5_000), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) + msg: to_json_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) .unwrap(), }, ); diff --git a/contracts/liquidity_hub/vault-network/vault/src/execute/receive/withdraw.rs b/contracts/liquidity_hub/vault-network/vault/src/execute/receive/withdraw.rs index fe5eacc9..82afb514 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/execute/receive/withdraw.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/execute/receive/withdraw.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - coins, to_binary, BankMsg, CosmosMsg, Decimal, DepsMut, Env, Response, Uint128, WasmMsg, + coins, to_json_binary, BankMsg, CosmosMsg, Decimal, DepsMut, Env, Response, Uint128, WasmMsg, }; use cw20::{BalanceResponse, Cw20ExecuteMsg, Cw20QueryMsg}; @@ -75,7 +75,7 @@ pub fn withdraw( .into(), AssetInfo::Token { contract_addr } => WasmMsg::Execute { contract_addr, - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: sender.into_string(), amount: withdraw_amount, })?, @@ -116,7 +116,7 @@ fn burn_lp_asset_msg( } else { Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: liquidity_asset, - msg: to_binary(&Cw20ExecuteMsg::Burn { amount })?, + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount })?, funds: vec![], })) } @@ -127,7 +127,7 @@ fn burn_lp_asset_msg( ))] Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: liquidity_asset, - msg: to_binary(&Cw20ExecuteMsg::Burn { amount })?, + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount })?, funds: vec![], })) } @@ -137,7 +137,7 @@ mod tests { use cosmwasm_std::{ coins, testing::{mock_env, mock_info}, - to_binary, Addr, BankMsg, Response, SubMsg, Uint128, WasmMsg, + to_json_binary, Addr, BankMsg, Response, SubMsg, Uint128, WasmMsg, }; use cw20::Cw20ExecuteMsg; use cw_multi_test::Executor; @@ -171,8 +171,10 @@ mod tests { white_whale::vault_network::vault::Cw20ReceiveMsg { sender: mock_creator().sender.into_string(), amount: Uint128::new(5_000), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) - .unwrap(), + msg: to_json_binary( + &white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}, + ) + .unwrap(), }, ), ); @@ -191,8 +193,10 @@ mod tests { white_whale::vault_network::vault::Cw20ReceiveMsg { sender: mock_creator().sender.into_string(), amount: Uint128::new(5_000), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) - .unwrap(), + msg: to_json_binary( + &white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}, + ) + .unwrap(), }, ), ); @@ -248,8 +252,10 @@ mod tests { white_whale::vault_network::vault::Cw20ReceiveMsg { amount: Uint128::new(2_000), sender: mock_creator().sender.into_string(), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) - .unwrap(), + msg: to_json_binary( + &white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}, + ) + .unwrap(), }, ), ); @@ -301,7 +307,7 @@ mod tests { &Cw20ExecuteMsg::Send { contract: vault_addr.to_string(), amount: Uint128::new(4_500), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) + msg: to_json_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) .unwrap(), }, &[], @@ -409,7 +415,7 @@ mod tests { &Cw20ExecuteMsg::Send { contract: vault_addr.to_string(), amount: Uint128::new(4_500), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) + msg: to_json_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) .unwrap(), }, &[], @@ -507,8 +513,10 @@ mod tests { white_whale::vault_network::vault::Cw20ReceiveMsg { amount: Uint128::new(5_000), sender: mock_creator().sender.into_string(), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) - .unwrap(), + msg: to_json_binary( + &white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}, + ) + .unwrap(), }, ), ) @@ -539,7 +547,7 @@ mod tests { reply_on: cosmwasm_std::ReplyOn::Never, msg: WasmMsg::Execute { contract_addr: "lp_token".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: Uint128::new(5000) }) .unwrap(), @@ -617,8 +625,10 @@ mod tests { white_whale::vault_network::vault::Cw20ReceiveMsg { amount: Uint128::new(5_000), sender: mock_creator().sender.into_string(), - msg: to_binary(&white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}) - .unwrap(), + msg: to_json_binary( + &white_whale::vault_network::vault::Cw20HookMsg::Withdraw {}, + ) + .unwrap(), }, ), ) @@ -639,7 +649,7 @@ mod tests { reply_on: cosmwasm_std::ReplyOn::Never, msg: WasmMsg::Execute { contract_addr: "vault_token".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { amount: Uint128::new(4_999), recipient: mock_creator().sender.into_string(), }) @@ -654,7 +664,7 @@ mod tests { reply_on: cosmwasm_std::ReplyOn::Never, msg: WasmMsg::Execute { contract_addr: "lp_token".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: Uint128::new(5000) }) .unwrap(), diff --git a/contracts/liquidity_hub/vault-network/vault/src/queries/get_config.rs b/contracts/liquidity_hub/vault-network/vault/src/queries/get_config.rs index b3f2eacc..c1f4efbe 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/queries/get_config.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/queries/get_config.rs @@ -1,16 +1,16 @@ -use cosmwasm_std::{to_binary, Binary, Deps}; +use cosmwasm_std::{to_json_binary, Binary, Deps}; use crate::error::VaultError; use crate::state::CONFIG; pub fn get_config(deps: Deps) -> Result { - Ok(to_binary(&CONFIG.load(deps.storage)?)?) + Ok(to_json_binary(&CONFIG.load(deps.storage)?)?) } #[cfg(test)] mod test { use cosmwasm_std::{ - from_binary, + from_json, testing::{mock_dependencies, mock_env}, Addr, }; @@ -45,7 +45,7 @@ mod test { CONFIG.save(&mut deps.storage, &config).unwrap(); - let res: Config = from_binary( + let res: Config = from_json( &query( deps.as_ref(), env, diff --git a/contracts/liquidity_hub/vault-network/vault/src/queries/get_payback_amount.rs b/contracts/liquidity_hub/vault-network/vault/src/queries/get_payback_amount.rs index 9e2e2c1b..f695a04d 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/queries/get_payback_amount.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/queries/get_payback_amount.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Binary, Deps, Uint128, Uint256}; +use cosmwasm_std::{to_json_binary, Binary, Deps, Uint128, Uint256}; use white_whale::vault_network::vault::PaybackAmountResponse; use crate::error::VaultError; @@ -18,7 +18,7 @@ pub fn get_payback_amount(deps: Deps, amount: Uint128) -> Result Result { if all_time { let fees = all_time_fees_storage_item.load(deps.storage)?; - return Ok(to_binary(&ProtocolFeesResponse { fees })?); + return Ok(to_json_binary(&ProtocolFeesResponse { fees })?); } let fees = fees_storage_item .ok_or_else(|| StdError::generic_err("fees_storage_item was None"))? .load(deps.storage)?; - Ok(to_binary(&ProtocolFeesResponse { fees })?) + Ok(to_json_binary(&ProtocolFeesResponse { fees })?) } #[cfg(test)] mod test { use cosmwasm_std::{ - from_binary, + from_json, testing::{mock_dependencies, mock_env}, Uint128, }; @@ -68,7 +68,7 @@ mod test { ) .unwrap(); - let res: ProtocolFeesResponse = from_binary( + let res: ProtocolFeesResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -115,7 +115,7 @@ mod test { ) .unwrap(); - let res: ProtocolFeesResponse = from_binary( + let res: ProtocolFeesResponse = from_json( &query( deps.as_ref(), mock_env(), @@ -154,8 +154,7 @@ mod test { .unwrap(); let res: ProtocolFeesResponse = - from_binary(&query(deps.as_ref(), mock_env(), QueryMsg::BurnedFees {}).unwrap()) - .unwrap(); + from_json(&query(deps.as_ref(), mock_env(), QueryMsg::BurnedFees {}).unwrap()).unwrap(); assert_eq!( res, ProtocolFeesResponse { diff --git a/contracts/liquidity_hub/vault-network/vault/src/queries/get_share.rs b/contracts/liquidity_hub/vault-network/vault/src/queries/get_share.rs index 17d2c970..504d898d 100644 --- a/contracts/liquidity_hub/vault-network/vault/src/queries/get_share.rs +++ b/contracts/liquidity_hub/vault-network/vault/src/queries/get_share.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Binary, Decimal, Deps, Env, Uint128}; +use cosmwasm_std::{to_json_binary, Binary, Decimal, Deps, Env, Uint128}; use cw20::{BalanceResponse, Cw20QueryMsg}; use white_whale::pool_network::asset::{get_total_share, AssetInfo}; @@ -40,12 +40,12 @@ pub fn get_share(deps: Deps, env: Env, amount: Uint128) -> Result QuerierResult { // MockQuerier doesn't support Custom, so we ignore it completely here - let request: QueryRequest = match from_slice(bin_request) { + let request: QueryRequest = match from_json(bin_request) { Ok(v) => v, Err(e) => { return SystemResult::Err(SystemError::InvalidRequest { @@ -101,10 +101,10 @@ impl WasmMockQuerier { match &request { QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => { if contract_addr == "lp_token" { - match from_binary(msg).unwrap() { + match from_json(msg).unwrap() { Cw20QueryMsg::TokenInfo {} => { return SystemResult::Ok(ContractResult::Ok( - to_binary(&TokenInfoResponse { + to_json_binary(&TokenInfoResponse { decimals: 6, name: "lp_token".to_string(), symbol: "uLP".to_string(), @@ -120,7 +120,7 @@ impl WasmMockQuerier { } Cw20QueryMsg::Balance { address } => { return SystemResult::Ok(ContractResult::Ok( - to_binary(&BalanceResponse { + to_json_binary(&BalanceResponse { balance: *self .token_querier .balances @@ -135,10 +135,10 @@ impl WasmMockQuerier { _ => panic!("DO NOT ENTER HERE"), } } else if contract_addr == "vault_token" { - match from_binary(msg).unwrap() { + match from_json(msg).unwrap() { Cw20QueryMsg::Balance { address } => { return SystemResult::Ok(ContractResult::Ok( - to_binary(&BalanceResponse { + to_json_binary(&BalanceResponse { balance: *self .token_querier .balances @@ -152,7 +152,7 @@ impl WasmMockQuerier { } Cw20QueryMsg::Allowance { owner, spender } => { return SystemResult::Ok(ContractResult::Ok( - to_binary(&AllowanceResponse { + to_json_binary(&AllowanceResponse { allowance: *self .token_querier .allowances diff --git a/contracts/liquidity_hub/vault-network/vault_factory/src/execute/create_vault.rs b/contracts/liquidity_hub/vault-network/vault_factory/src/execute/create_vault.rs index 9da0ac51..fd6cecad 100644 --- a/contracts/liquidity_hub/vault-network/vault_factory/src/execute/create_vault.rs +++ b/contracts/liquidity_hub/vault-network/vault_factory/src/execute/create_vault.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, DepsMut, Env, MessageInfo, ReplyOn, Response, SubMsg, WasmMsg}; +use cosmwasm_std::{to_json_binary, DepsMut, Env, MessageInfo, ReplyOn, Response, SubMsg, WasmMsg}; use white_whale::fee::VaultFee; use white_whale::pool_network::asset::AssetInfo; use white_whale::vault_network::vault::InstantiateMsg; @@ -37,7 +37,7 @@ pub fn create_vault( msg: WasmMsg::Instantiate { admin: Some(env.contract.address.clone().into_string()), code_id: config.vault_id, - msg: to_binary(&InstantiateMsg { + msg: to_json_binary(&InstantiateMsg { owner: env.contract.address.into_string(), asset_info: asset_info.clone(), token_id: config.token_id, @@ -70,7 +70,8 @@ pub fn create_vault( #[cfg(test)] mod tests { use cosmwasm_std::{ - testing::mock_info, to_binary, Addr, Decimal, ReplyOn, Response, StdError, SubMsg, WasmMsg, + testing::mock_info, to_json_binary, Addr, Decimal, ReplyOn, Response, StdError, SubMsg, + WasmMsg, }; use cw_multi_test::Executor; use white_whale::fee::{Fee, VaultFee}; @@ -114,7 +115,7 @@ mod tests { msg: WasmMsg::Instantiate { admin: Some(env.contract.address.to_string()), code_id: 5, - msg: to_binary(&white_whale::vault_network::vault::InstantiateMsg { + msg: to_json_binary(&white_whale::vault_network::vault::InstantiateMsg { owner: env.contract.address.to_string(), asset_info, token_id: 6, @@ -159,7 +160,7 @@ mod tests { msg: WasmMsg::Instantiate { admin: Some(env.contract.address.to_string()), code_id: 5, - msg: to_binary(&white_whale::vault_network::vault::InstantiateMsg { + msg: to_json_binary(&white_whale::vault_network::vault::InstantiateMsg { owner: env.contract.address.to_string(), asset_info, token_id: 6, @@ -354,7 +355,7 @@ mod tests { msg: WasmMsg::Instantiate { admin: Some(env.contract.address.to_string()), code_id: 5, - msg: to_binary(&white_whale::vault_network::vault::InstantiateMsg { + msg: to_json_binary(&white_whale::vault_network::vault::InstantiateMsg { owner: env.contract.address.to_string(), asset_info, token_id: 6, @@ -400,7 +401,7 @@ mod tests { msg: WasmMsg::Instantiate { admin: Some(env.contract.address.to_string()), code_id: 5, - msg: to_binary(&white_whale::vault_network::vault::InstantiateMsg { + msg: to_json_binary(&white_whale::vault_network::vault::InstantiateMsg { owner: env.contract.address.to_string(), asset_info, token_id: 6, diff --git a/contracts/liquidity_hub/vault-network/vault_factory/src/execute/migrate_vaults.rs b/contracts/liquidity_hub/vault-network/vault_factory/src/execute/migrate_vaults.rs index ddd62e14..bbd7770f 100644 --- a/contracts/liquidity_hub/vault-network/vault_factory/src/execute/migrate_vaults.rs +++ b/contracts/liquidity_hub/vault-network/vault_factory/src/execute/migrate_vaults.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Addr, CosmosMsg, DepsMut, Response, WasmMsg}; +use cosmwasm_std::{to_json_binary, Addr, CosmosMsg, DepsMut, Response, WasmMsg}; use white_whale::vault_network::vault::MigrateMsg; @@ -42,7 +42,7 @@ fn migrate_vault_msg(vault_addr: Addr, code_id: u64) -> StdResult { Ok(CosmosMsg::Wasm(WasmMsg::Migrate { contract_addr: vault_addr.to_string(), new_code_id: code_id, - msg: to_binary(&MigrateMsg {})?, + msg: to_json_binary(&MigrateMsg {})?, })) } diff --git a/contracts/liquidity_hub/vault-network/vault_factory/src/execute/update_config.rs b/contracts/liquidity_hub/vault-network/vault_factory/src/execute/update_config.rs index a1aac9ef..2febb1cd 100644 --- a/contracts/liquidity_hub/vault-network/vault_factory/src/execute/update_config.rs +++ b/contracts/liquidity_hub/vault-network/vault_factory/src/execute/update_config.rs @@ -46,7 +46,7 @@ pub fn update_config( #[cfg(test)] mod tests { - use cosmwasm_std::{from_binary, testing::mock_info, Addr, Response}; + use cosmwasm_std::{from_json, testing::mock_info, Addr, Response}; use white_whale::vault_network::vault_factory::{Config, ExecuteMsg, QueryMsg}; use crate::{ @@ -83,7 +83,7 @@ mod tests { // check query let config: Config = - from_binary(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(); assert_eq!(config.owner, Addr::unchecked("other_acc")); // check storage @@ -118,7 +118,7 @@ mod tests { // check query let config: Config = - from_binary(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(); assert_eq!(config.fee_collector_addr, Addr::unchecked("other_acc")); // check storage @@ -160,7 +160,7 @@ mod tests { }; let config: Config = - from_binary(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(); assert_eq!(config, desired_config); // check storage @@ -202,7 +202,7 @@ mod tests { }; let config: Config = - from_binary(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(); + from_json(&query(deps.as_ref(), env, QueryMsg::Config {}).unwrap()).unwrap(); assert_eq!(config, desired_config); // check storage diff --git a/contracts/liquidity_hub/vault-network/vault_factory/src/queries/config.rs b/contracts/liquidity_hub/vault-network/vault_factory/src/queries/config.rs index 50cbfee5..13b229f1 100644 --- a/contracts/liquidity_hub/vault-network/vault_factory/src/queries/config.rs +++ b/contracts/liquidity_hub/vault-network/vault_factory/src/queries/config.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Binary, Deps}; +use cosmwasm_std::{to_json_binary, Binary, Deps}; use crate::{err::StdResult, state::CONFIG}; @@ -6,7 +6,7 @@ use crate::{err::StdResult, state::CONFIG}; pub fn get_config(deps: Deps) -> StdResult { let config = CONFIG.load(deps.storage)?; - Ok(to_binary(&config)?) + Ok(to_json_binary(&config)?) } #[cfg(test)] diff --git a/contracts/liquidity_hub/vault-network/vault_factory/src/queries/vault.rs b/contracts/liquidity_hub/vault-network/vault_factory/src/queries/vault.rs index 38cc8e0f..f924b49c 100644 --- a/contracts/liquidity_hub/vault-network/vault_factory/src/queries/vault.rs +++ b/contracts/liquidity_hub/vault-network/vault_factory/src/queries/vault.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Binary, Deps}; +use cosmwasm_std::{to_json_binary, Binary, Deps}; use white_whale::pool_network::asset::AssetInfo; use white_whale::vault_network::vault_factory::{VaultInfo, VaultsResponse}; @@ -9,10 +9,10 @@ use crate::{asset::AssetReference, err::StdResult, state::VAULTS}; pub fn get_vault(deps: Deps, asset_info: AssetInfo) -> StdResult { let vault_option = VAULTS.may_load(deps.storage, asset_info.get_reference())?; if let Some((vault_addr, _)) = vault_option { - return Ok(to_binary(&vault_addr)?); + return Ok(to_json_binary(&vault_addr)?); } - Ok(to_binary(&vault_option)?) + Ok(to_json_binary(&vault_option)?) } pub fn get_vaults( @@ -21,7 +21,7 @@ pub fn get_vaults( limit: Option, ) -> StdResult { let vaults: Vec = read_vaults(deps.storage, deps.api, start_after, limit)?; - Ok(to_binary(&VaultsResponse { vaults })?) + Ok(to_json_binary(&VaultsResponse { vaults })?) } #[cfg(test)] diff --git a/contracts/liquidity_hub/vault-network/vault_factory/src/tests/mock_query.rs b/contracts/liquidity_hub/vault-network/vault_factory/src/tests/mock_query.rs index d0b7b167..9c31f8d2 100644 --- a/contracts/liquidity_hub/vault-network/vault_factory/src/tests/mock_query.rs +++ b/contracts/liquidity_hub/vault-network/vault_factory/src/tests/mock_query.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - from_binary, + from_json, testing::{MockApi, MockQuerier, MockStorage}, Env, OwnedDeps, }; @@ -20,7 +20,7 @@ where { let (deps, env) = mock_instantiate(vault_id, token_id); - let res = from_binary(&query(deps.as_ref(), env.clone(), query_msg).unwrap()).unwrap(); + let res = from_json(&query(deps.as_ref(), env.clone(), query_msg).unwrap()).unwrap(); (res, deps, env) } diff --git a/contracts/liquidity_hub/vault-network/vault_router/src/execute/complete_loan.rs b/contracts/liquidity_hub/vault-network/vault_router/src/execute/complete_loan.rs index 9f5586b6..33cf9ecd 100644 --- a/contracts/liquidity_hub/vault-network/vault_router/src/execute/complete_loan.rs +++ b/contracts/liquidity_hub/vault-network/vault_router/src/execute/complete_loan.rs @@ -1,5 +1,6 @@ use cosmwasm_std::{ - attr, coins, to_binary, Addr, BankMsg, CosmosMsg, DepsMut, Env, MessageInfo, Response, WasmMsg, + attr, coins, to_json_binary, Addr, BankMsg, CosmosMsg, DepsMut, Env, MessageInfo, Response, + WasmMsg, }; use white_whale::pool_network::asset::{Asset, AssetInfo}; use white_whale::vault_network::vault::PaybackAmountResponse; @@ -76,7 +77,7 @@ pub fn complete_loan( AssetInfo::Token { contract_addr } => Ok(WasmMsg::Execute { contract_addr, funds: vec![], - msg: to_binary(&cw20::Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::Transfer { recipient: vault, amount: payback_amount.payback_amount, })?, @@ -97,7 +98,7 @@ pub fn complete_loan( AssetInfo::Token { contract_addr } => Ok(WasmMsg::Execute { contract_addr, funds: vec![], - msg: to_binary(&cw20::Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&cw20::Cw20ExecuteMsg::Transfer { recipient: initiator.clone().into_string(), amount: profit_amount, })?, diff --git a/contracts/liquidity_hub/vault-network/vault_router/src/execute/flash_loan.rs b/contracts/liquidity_hub/vault-network/vault_router/src/execute/flash_loan.rs index db3f84f5..782f118e 100644 --- a/contracts/liquidity_hub/vault-network/vault_router/src/execute/flash_loan.rs +++ b/contracts/liquidity_hub/vault-network/vault_router/src/execute/flash_loan.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, CosmosMsg, DepsMut, MessageInfo, Response, WasmMsg}; +use cosmwasm_std::{to_json_binary, CosmosMsg, DepsMut, MessageInfo, Response, WasmMsg}; use white_whale::pool_network::asset::Asset; use white_whale::vault_network::vault_router::ExecuteMsg; @@ -51,9 +51,9 @@ pub fn flash_loan( messages.push( WasmMsg::Execute { contract_addr: vault.to_string(), - msg: to_binary(&white_whale::vault_network::vault::ExecuteMsg::FlashLoan { + msg: to_json_binary(&white_whale::vault_network::vault::ExecuteMsg::FlashLoan { amount: asset.amount, - msg: to_binary(&ExecuteMsg::NextLoan { + msg: to_json_binary(&ExecuteMsg::NextLoan { initiator: info.sender, source_vault: vault.to_string(), source_vault_asset_info: asset.info.clone(), @@ -76,7 +76,7 @@ pub fn flash_loan( #[cfg(test)] mod tests { use cosmwasm_std::{ - coins, from_binary, to_binary, Attribute, BankMsg, CosmosMsg, Event, Response, Uint128, + coins, from_json, to_json_binary, Attribute, BankMsg, CosmosMsg, Event, Response, Uint128, WasmMsg, }; use cw_multi_test::Executor; @@ -110,7 +110,7 @@ mod tests { let payload = vec![WasmMsg::Execute { contract_addr: dummy_contract_addr.clone().into_string(), - msg: to_binary(&crate::tests::ExecuteMsg::Send { + msg: to_json_binary(&crate::tests::ExecuteMsg::Send { to_address: router_addr.clone(), amount: coins(transfer_amount, "uluna"), }) @@ -140,7 +140,7 @@ mod tests { // verify payload was executed let payload_amount = match payload.first().unwrap() { CosmosMsg::Wasm(WasmMsg::Execute { msg, .. }) => { - let msg: crate::tests::ExecuteMsg = from_binary(msg).unwrap(); + let msg: crate::tests::ExecuteMsg = from_json(msg).unwrap(); match msg { crate::tests::ExecuteMsg::Send { amount, .. } => amount, } @@ -296,7 +296,7 @@ mod tests { let payload = vec![WasmMsg::Execute { contract_addr: dummy_contract_addr.clone().into_string(), - msg: to_binary(&crate::tests::ExecuteMsg::Send { + msg: to_json_binary(&crate::tests::ExecuteMsg::Send { to_address: router_addr.clone(), amount: coins(transfer_amount, "uluna"), }) @@ -325,7 +325,7 @@ mod tests { let payload_amount = match payload.first().unwrap() { CosmosMsg::Wasm(WasmMsg::Execute { msg, .. }) => { - let msg: crate::tests::ExecuteMsg = from_binary(msg).unwrap(); + let msg: crate::tests::ExecuteMsg = from_json(msg).unwrap(); match msg { crate::tests::ExecuteMsg::Send { amount, .. } => amount, } diff --git a/contracts/liquidity_hub/vault-network/vault_router/src/execute/next_loan.rs b/contracts/liquidity_hub/vault-network/vault_router/src/execute/next_loan.rs index ef9cf131..a24b72a5 100644 --- a/contracts/liquidity_hub/vault-network/vault_router/src/execute/next_loan.rs +++ b/contracts/liquidity_hub/vault-network/vault_router/src/execute/next_loan.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Addr, CosmosMsg, DepsMut, Env, MessageInfo, Response, WasmMsg}; +use cosmwasm_std::{to_json_binary, Addr, CosmosMsg, DepsMut, Env, MessageInfo, Response, WasmMsg}; use white_whale::pool_network::asset::{Asset, AssetInfo}; use white_whale::vault_network::vault_router::ExecuteMsg; @@ -44,9 +44,9 @@ pub fn next_loan( vec![WasmMsg::Execute { contract_addr: vault.clone(), funds: vec![], - msg: to_binary(&white_whale::vault_network::vault::ExecuteMsg::FlashLoan { + msg: to_json_binary(&white_whale::vault_network::vault::ExecuteMsg::FlashLoan { amount: asset.amount, - msg: to_binary(&ExecuteMsg::NextLoan { + msg: to_json_binary(&ExecuteMsg::NextLoan { initiator, source_vault: vault.to_string(), source_vault_asset_info: asset.info.clone(), @@ -64,7 +64,7 @@ pub fn next_loan( WasmMsg::Execute { contract_addr: env.contract.address.to_string(), funds: vec![], - msg: to_binary(&ExecuteMsg::CompleteLoan { + msg: to_json_binary(&ExecuteMsg::CompleteLoan { initiator, loaned_assets, })?, diff --git a/contracts/liquidity_hub/vault-network/vault_router/src/queries/config.rs b/contracts/liquidity_hub/vault-network/vault_router/src/queries/config.rs index 1f080f4c..7941783d 100644 --- a/contracts/liquidity_hub/vault-network/vault_router/src/queries/config.rs +++ b/contracts/liquidity_hub/vault-network/vault_router/src/queries/config.rs @@ -1,4 +1,4 @@ -use cosmwasm_std::{to_binary, Binary, Deps}; +use cosmwasm_std::{to_json_binary, Binary, Deps}; use crate::{err::StdResult, state::CONFIG}; @@ -6,7 +6,7 @@ use crate::{err::StdResult, state::CONFIG}; pub fn get_config(deps: Deps) -> StdResult { let config = CONFIG.load(deps.storage)?; - Ok(to_binary(&config)?) + Ok(to_json_binary(&config)?) } #[cfg(test)] diff --git a/contracts/liquidity_hub/vault-network/vault_router/src/tests/mock_query.rs b/contracts/liquidity_hub/vault-network/vault_router/src/tests/mock_query.rs index 0b6414d9..89349648 100644 --- a/contracts/liquidity_hub/vault-network/vault_router/src/tests/mock_query.rs +++ b/contracts/liquidity_hub/vault-network/vault_router/src/tests/mock_query.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{ - from_binary, + from_json, testing::{MockApi, MockQuerier, MockStorage}, Env, OwnedDeps, }; @@ -19,7 +19,7 @@ where { let (deps, env) = mock_instantiate(factory_addr); - let res = from_binary(&query(deps.as_ref(), env.clone(), query_msg).unwrap()).unwrap(); + let res = from_json(&query(deps.as_ref(), env.clone(), query_msg).unwrap()).unwrap(); (res, deps, env) } diff --git a/contracts/liquidity_hub/whale_lair/src/contract.rs b/contracts/liquidity_hub/whale_lair/src/contract.rs index 0470cfa9..fc4bbe12 100644 --- a/contracts/liquidity_hub/whale_lair/src/contract.rs +++ b/contracts/liquidity_hub/whale_lair/src/contract.rs @@ -1,5 +1,5 @@ use cosmwasm_std::{entry_point, Addr}; -use cosmwasm_std::{to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; +use cosmwasm_std::{to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult}; use cw2::{get_contract_version, set_contract_version}; use semver::Version; use white_whale::pool_network::asset::AssetInfo; @@ -99,21 +99,21 @@ pub fn execute( #[entry_point] pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { match msg { - QueryMsg::Config {} => to_binary(&queries::query_config(deps)?), - QueryMsg::Bonded { address } => to_binary(&queries::query_bonded(deps, address)?), + QueryMsg::Config {} => to_json_binary(&queries::query_config(deps)?), + QueryMsg::Bonded { address } => to_json_binary(&queries::query_bonded(deps, address)?), QueryMsg::Unbonding { address, denom, start_after, limit, - } => to_binary(&queries::query_unbonding( + } => to_json_binary(&queries::query_unbonding( deps, address, denom, start_after, limit, )?), - QueryMsg::Withdrawable { address, denom } => to_binary(&queries::query_withdrawable( + QueryMsg::Withdrawable { address, denom } => to_json_binary(&queries::query_withdrawable( deps, env.block.time, address, @@ -128,15 +128,15 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult { let timestamp = timestamp.unwrap_or(env.block.time); // TODO: Make better timestamp handling - to_binary(&queries::query_weight( + to_json_binary(&queries::query_weight( deps, timestamp, address, global_index, )?) } - QueryMsg::TotalBonded {} => to_binary(&queries::query_total_bonded(deps)?), - QueryMsg::GlobalIndex {} => to_binary(&queries::query_global_index(deps)?), + QueryMsg::TotalBonded {} => to_json_binary(&queries::query_total_bonded(deps)?), + QueryMsg::GlobalIndex {} => to_json_binary(&queries::query_global_index(deps)?), } } diff --git a/contracts/liquidity_hub/whale_lair/src/queries.rs b/contracts/liquidity_hub/whale_lair/src/queries.rs index e1cf9b0f..2fb39a5f 100644 --- a/contracts/liquidity_hub/whale_lair/src/queries.rs +++ b/contracts/liquidity_hub/whale_lair/src/queries.rs @@ -1,8 +1,8 @@ use std::collections::HashSet; use cosmwasm_std::{ - to_binary, Decimal, Deps, Order, QueryRequest, StdError, StdResult, Timestamp, Uint128, Uint64, - WasmQuery, + to_json_binary, Decimal, Deps, Order, QueryRequest, StdError, StdResult, Timestamp, Uint128, + Uint64, WasmQuery, }; use cw_storage_plus::Bound; @@ -64,7 +64,7 @@ pub(crate) fn query_bonded(deps: Deps, address: String) -> StdResult StdResult { + pub fn into_json_binary(self) -> StdResult { let msg = EpochChangedExecuteMsg::EpochChangedHook(self); - to_binary(&msg) + to_json_binary(&msg) } /// creates a cosmos_msg sending this struct to the named contract pub fn into_cosmos_msg>(self, contract_addr: T) -> StdResult { - let msg = self.into_binary()?; + let msg = self.into_json_binary()?; let execute = WasmMsg::Execute { contract_addr: contract_addr.into(), msg, diff --git a/packages/white-whale/src/pool_network/asset.rs b/packages/white-whale/src/pool_network/asset.rs index 634bcec9..4e48076a 100644 --- a/packages/white-whale/src/pool_network/asset.rs +++ b/packages/white-whale/src/pool_network/asset.rs @@ -3,7 +3,7 @@ use std::fmt::{Display, Formatter}; use cosmwasm_schema::cw_serde; use cosmwasm_std::{ - coins, to_binary, Addr, Api, BankMsg, CanonicalAddr, Coin, CosmosMsg, Deps, MessageInfo, + coins, to_json_binary, Addr, Api, BankMsg, CanonicalAddr, Coin, CosmosMsg, Deps, MessageInfo, QuerierWrapper, StdError, StdResult, SubMsg, Uint128, WasmMsg, }; use cw20::Cw20ExecuteMsg; @@ -50,7 +50,7 @@ impl Asset { match &self.info { AssetInfo::Token { contract_addr } => Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: contract_addr.to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: recipient.to_string(), amount, })?, @@ -74,7 +74,7 @@ impl Asset { let burn_msg = match self.info { AssetInfo::Token { contract_addr } => CosmosMsg::Wasm(WasmMsg::Execute { contract_addr, - msg: to_binary(&Cw20ExecuteMsg::Burn { + msg: to_json_binary(&Cw20ExecuteMsg::Burn { amount: self.amount, })?, funds: vec![], diff --git a/packages/white-whale/src/pool_network/mock_querier.rs b/packages/white-whale/src/pool_network/mock_querier.rs index a35dd4c8..0e8258cf 100644 --- a/packages/white-whale/src/pool_network/mock_querier.rs +++ b/packages/white-whale/src/pool_network/mock_querier.rs @@ -5,8 +5,8 @@ use std::panic; use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR}; use cosmwasm_std::{ - from_binary, from_slice, to_binary, Coin, ContractInfoResponse, ContractResult, Empty, - OwnedDeps, Querier, QuerierResult, QueryRequest, SystemError, SystemResult, Uint128, WasmQuery, + from_json, to_json_binary, Coin, ContractInfoResponse, ContractResult, Empty, OwnedDeps, + Querier, QuerierResult, QueryRequest, SystemError, SystemResult, Uint128, WasmQuery, }; use cw20::{BalanceResponse as Cw20BalanceResponse, Cw20QueryMsg, TokenInfoResponse}; @@ -125,7 +125,7 @@ pub fn native_token_decimals_to_map(native_token_decimals: &[(String, u8)]) -> H impl Querier for WasmMockQuerier { fn raw_query(&self, bin_request: &[u8]) -> QuerierResult { // MockQuerier doesn't support Custom, so we ignore it completely here - let request: QueryRequest = match from_slice(bin_request) { + let request: QueryRequest = match from_json(bin_request) { Ok(v) => v, Err(e) => { return SystemResult::Err(SystemError::InvalidRequest { @@ -141,7 +141,7 @@ impl Querier for WasmMockQuerier { impl Querier for WasmMockTrioQuerier { fn raw_query(&self, bin_request: &[u8]) -> QuerierResult { // MockQuerier doesn't support Custom, so we ignore it completely here - let request: QueryRequest = match from_slice(bin_request) { + let request: QueryRequest = match from_json(bin_request) { Ok(v) => v, Err(e) => { return SystemResult::Err(SystemError::InvalidRequest { @@ -157,41 +157,41 @@ impl Querier for WasmMockTrioQuerier { impl WasmMockQuerier { pub fn handle_query(&self, request: &QueryRequest) -> QuerierResult { match &request { - QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => { - match from_binary(msg) { - Ok(FactoryQueryMsg::Pair { asset_infos }) => { - let key = [asset_infos[0].to_string(), asset_infos[1].to_string()].join(""); - let mut sort_key: Vec = key.chars().collect(); - sort_key.sort_by(|a, b| b.cmp(a)); - match self - .pool_factory_querier - .pairs - .get(&String::from_iter(sort_key.iter())) - { - Some(v) => SystemResult::Ok(ContractResult::Ok(to_binary(v).unwrap())), - None => SystemResult::Err(SystemError::InvalidRequest { - error: "No pair info exists".to_string(), - request: msg.as_slice().into(), - }), - } + QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => match from_json(msg) { + Ok(FactoryQueryMsg::Pair { asset_infos }) => { + let key = [asset_infos[0].to_string(), asset_infos[1].to_string()].join(""); + let mut sort_key: Vec = key.chars().collect(); + sort_key.sort_by(|a, b| b.cmp(a)); + match self + .pool_factory_querier + .pairs + .get(&String::from_iter(sort_key.iter())) + { + Some(v) => SystemResult::Ok(ContractResult::Ok(to_json_binary(v).unwrap())), + None => SystemResult::Err(SystemError::InvalidRequest { + error: "No pair info exists".to_string(), + request: msg.as_slice().into(), + }), } - Ok(FactoryQueryMsg::NativeTokenDecimals { denom }) => { - match self.pool_factory_querier.native_token_decimals.get(&denom) { - Some(decimals) => SystemResult::Ok(ContractResult::Ok( - to_binary(&NativeTokenDecimalsResponse { - decimals: *decimals, - }) - .unwrap(), - )), - None => SystemResult::Err(SystemError::InvalidRequest { - error: "No decimal info exist".to_string(), - request: msg.as_slice().into(), - }), - } + } + Ok(FactoryQueryMsg::NativeTokenDecimals { denom }) => { + match self.pool_factory_querier.native_token_decimals.get(&denom) { + Some(decimals) => SystemResult::Ok(ContractResult::Ok( + to_json_binary(&NativeTokenDecimalsResponse { + decimals: *decimals, + }) + .unwrap(), + )), + None => SystemResult::Err(SystemError::InvalidRequest { + error: "No decimal info exist".to_string(), + request: msg.as_slice().into(), + }), } - _ => match from_binary(msg) { - Ok(PairQueryMsg::Pool {}) => { - SystemResult::Ok(ContractResult::from(to_binary(&PairPoolResponse { + } + _ => { + match from_json(msg) { + Ok(PairQueryMsg::Pool {}) => SystemResult::Ok(ContractResult::from( + to_json_binary(&PairPoolResponse { assets: vec![ Asset { info: AssetInfo::NativeToken { @@ -207,10 +207,10 @@ impl WasmMockQuerier { }, ], total_share: Uint128::new(2_000_000_000u128), - }))) - } + }), + )), Ok(PairQueryMsg::Pair {}) => { - SystemResult::Ok(ContractResult::from(to_binary(&PairInfo { + SystemResult::Ok(ContractResult::from(to_json_binary(&PairInfo { asset_infos: [ AssetInfo::NativeToken { denom: "uluna".to_string(), @@ -247,7 +247,7 @@ impl WasmMockQuerier { osmosis_fee_amount: Uint128::zero(), }; - SystemResult::Ok(ContractResult::from(to_binary(&data))) + SystemResult::Ok(ContractResult::from(to_json_binary(&data))) } Ok(PairQueryMsg::ReverseSimulation { ask_asset }) => { #[cfg(not(feature = "osmosis"))] @@ -269,9 +269,9 @@ impl WasmMockQuerier { osmosis_fee_amount: Uint128::zero(), }; - SystemResult::Ok(ContractResult::from(to_binary(&data))) + SystemResult::Ok(ContractResult::from(to_json_binary(&data))) } - _ => match from_binary(msg).unwrap() { + _ => match from_json(msg).unwrap() { Cw20QueryMsg::TokenInfo {} => { let balances: &HashMap = match self.token_querier.balances.get(contract_addr) { @@ -293,7 +293,7 @@ impl WasmMockQuerier { } SystemResult::Ok(ContractResult::Ok( - to_binary(&TokenInfoResponse { + to_json_binary(&TokenInfoResponse { name: "mAAPL".to_string(), symbol: "mAAPL".to_string(), decimals: 8, @@ -320,7 +320,7 @@ impl WasmMockQuerier { Some(v) => *v, None => { return SystemResult::Ok(ContractResult::Ok( - to_binary(&Cw20BalanceResponse { + to_json_binary(&Cw20BalanceResponse { balance: Uint128::zero(), }) .unwrap(), @@ -329,15 +329,15 @@ impl WasmMockQuerier { }; SystemResult::Ok(ContractResult::Ok( - to_binary(&Cw20BalanceResponse { balance }).unwrap(), + to_json_binary(&Cw20BalanceResponse { balance }).unwrap(), )) } _ => panic!("DO NOT ENTER HERE"), }, - }, + } } - } + }, QueryRequest::Wasm(WasmQuery::ContractInfo { .. }) => { let mut contract_info_response = ContractInfoResponse::default(); contract_info_response.code_id = 0u64; @@ -345,7 +345,7 @@ impl WasmMockQuerier { contract_info_response.admin = Some("creator".to_string()); SystemResult::Ok(ContractResult::Ok( - to_binary(&contract_info_response).unwrap(), + to_json_binary(&contract_info_response).unwrap(), )) } _ => self.base.handle_query(request), @@ -356,46 +356,46 @@ impl WasmMockQuerier { impl WasmMockTrioQuerier { pub fn handle_query(&self, request: &QueryRequest) -> QuerierResult { match &request { - QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => { - match from_binary(msg) { - Ok(FactoryQueryMsg::Trio { asset_infos }) => { - let key = [ - asset_infos[0].to_string(), - asset_infos[1].to_string(), - asset_infos[2].to_string(), - ] - .join(""); - let mut sort_key: Vec = key.chars().collect(); - sort_key.sort_by(|a, b| b.cmp(a)); - match self - .pool_factory_querier - .pairs - .get(&String::from_iter(sort_key.iter())) - { - Some(v) => SystemResult::Ok(ContractResult::Ok(to_binary(v).unwrap())), - None => SystemResult::Err(SystemError::InvalidRequest { - error: "No trio info exists".to_string(), - request: msg.as_slice().into(), - }), - } + QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => match from_json(msg) { + Ok(FactoryQueryMsg::Trio { asset_infos }) => { + let key = [ + asset_infos[0].to_string(), + asset_infos[1].to_string(), + asset_infos[2].to_string(), + ] + .join(""); + let mut sort_key: Vec = key.chars().collect(); + sort_key.sort_by(|a, b| b.cmp(a)); + match self + .pool_factory_querier + .pairs + .get(&String::from_iter(sort_key.iter())) + { + Some(v) => SystemResult::Ok(ContractResult::Ok(to_json_binary(v).unwrap())), + None => SystemResult::Err(SystemError::InvalidRequest { + error: "No trio info exists".to_string(), + request: msg.as_slice().into(), + }), } - Ok(FactoryQueryMsg::NativeTokenDecimals { denom }) => { - match self.pool_factory_querier.native_token_decimals.get(&denom) { - Some(decimals) => SystemResult::Ok(ContractResult::Ok( - to_binary(&NativeTokenDecimalsResponse { - decimals: *decimals, - }) - .unwrap(), - )), - None => SystemResult::Err(SystemError::InvalidRequest { - error: "No decimal info exist".to_string(), - request: msg.as_slice().into(), - }), - } + } + Ok(FactoryQueryMsg::NativeTokenDecimals { denom }) => { + match self.pool_factory_querier.native_token_decimals.get(&denom) { + Some(decimals) => SystemResult::Ok(ContractResult::Ok( + to_json_binary(&NativeTokenDecimalsResponse { + decimals: *decimals, + }) + .unwrap(), + )), + None => SystemResult::Err(SystemError::InvalidRequest { + error: "No decimal info exist".to_string(), + request: msg.as_slice().into(), + }), } - _ => match from_binary(msg) { - Ok(TrioQueryMsg::Pool {}) => { - SystemResult::Ok(ContractResult::from(to_binary(&TrioPoolResponse { + } + _ => { + match from_json(msg) { + Ok(TrioQueryMsg::Pool {}) => SystemResult::Ok(ContractResult::from( + to_json_binary(&TrioPoolResponse { assets: vec![ Asset { info: AssetInfo::NativeToken { @@ -417,10 +417,10 @@ impl WasmMockTrioQuerier { }, ], total_share: Uint128::new(3_000_000_000u128), - }))) - } + }), + )), Ok(TrioQueryMsg::Trio {}) => { - SystemResult::Ok(ContractResult::from(to_binary(&TrioInfo { + SystemResult::Ok(ContractResult::from(to_json_binary(&TrioInfo { asset_infos: [ AssetInfo::NativeToken { denom: "uluna".to_string(), @@ -459,7 +459,7 @@ impl WasmMockTrioQuerier { osmosis_fee_amount: Uint128::zero(), }; - SystemResult::Ok(ContractResult::from(to_binary(&data))) + SystemResult::Ok(ContractResult::from(to_json_binary(&data))) } Ok(TrioQueryMsg::ReverseSimulation { ask_asset, .. }) => { #[cfg(not(feature = "osmosis"))] @@ -481,9 +481,9 @@ impl WasmMockTrioQuerier { osmosis_fee_amount: Uint128::zero(), }; - SystemResult::Ok(ContractResult::from(to_binary(&data))) + SystemResult::Ok(ContractResult::from(to_json_binary(&data))) } - _ => match from_binary(msg).unwrap() { + _ => match from_json(msg).unwrap() { Cw20QueryMsg::TokenInfo {} => { let balances: &HashMap = match self.token_querier.balances.get(contract_addr) { @@ -505,7 +505,7 @@ impl WasmMockTrioQuerier { } SystemResult::Ok(ContractResult::Ok( - to_binary(&TokenInfoResponse { + to_json_binary(&TokenInfoResponse { name: "mAAPL".to_string(), symbol: "mAAPL".to_string(), decimals: 8, @@ -532,7 +532,7 @@ impl WasmMockTrioQuerier { Some(v) => *v, None => { return SystemResult::Ok(ContractResult::Ok( - to_binary(&Cw20BalanceResponse { + to_json_binary(&Cw20BalanceResponse { balance: Uint128::zero(), }) .unwrap(), @@ -541,15 +541,15 @@ impl WasmMockTrioQuerier { }; SystemResult::Ok(ContractResult::Ok( - to_binary(&Cw20BalanceResponse { balance }).unwrap(), + to_json_binary(&Cw20BalanceResponse { balance }).unwrap(), )) } _ => panic!("DO NOT ENTER HERE"), }, - }, + } } - } + }, QueryRequest::Wasm(WasmQuery::ContractInfo { .. }) => { let mut contract_info_response = ContractInfoResponse::default(); contract_info_response.code_id = 0u64; @@ -557,7 +557,7 @@ impl WasmMockTrioQuerier { contract_info_response.admin = Some("creator".to_string()); SystemResult::Ok(ContractResult::Ok( - to_binary(&contract_info_response).unwrap(), + to_json_binary(&contract_info_response).unwrap(), )) } _ => self.base.handle_query(request), @@ -647,7 +647,7 @@ mod mock_exception { fn none_factory_pair_will_err() { let deps = mock_dependencies(&[]); - let msg = to_binary(&FactoryQueryMsg::Pair { + let msg = to_json_binary(&FactoryQueryMsg::Pair { asset_infos: [ AssetInfo::NativeToken { denom: "uluna".to_string(), @@ -675,7 +675,7 @@ mod mock_exception { fn none_tokens_info_will_err() { let deps = mock_dependencies(&[]); - let msg = to_binary(&Cw20QueryMsg::TokenInfo {}).unwrap(); + let msg = to_json_binary(&Cw20QueryMsg::TokenInfo {}).unwrap(); assert_eq!( deps.querier @@ -694,7 +694,7 @@ mod mock_exception { fn none_tokens_balance_will_err() { let deps = mock_dependencies(&[]); - let msg = to_binary(&Cw20QueryMsg::Balance { + let msg = to_json_binary(&Cw20QueryMsg::Balance { address: "address0000".to_string(), }) .unwrap(); @@ -717,7 +717,7 @@ mod mock_exception { fn none_tokens_minter_will_panic() { let deps = mock_dependencies(&[]); - let msg = to_binary(&Cw20QueryMsg::Minter {}).unwrap(); + let msg = to_json_binary(&Cw20QueryMsg::Minter {}).unwrap(); deps.querier .handle_query(&QueryRequest::Wasm(WasmQuery::Smart { diff --git a/packages/white-whale/src/pool_network/pair.rs b/packages/white-whale/src/pool_network/pair.rs index 4d16a1c5..8881dfa4 100644 --- a/packages/white-whale/src/pool_network/pair.rs +++ b/packages/white-whale/src/pool_network/pair.rs @@ -122,24 +122,7 @@ impl PoolFee { self.swap_fee.is_valid()?; self.burn_fee.is_valid()?; - let total_fee = { - let base_fee = self - .protocol_fee - .share - .checked_add(self.swap_fee.share)? - .checked_add(self.burn_fee.share)?; - - #[cfg(feature = "osmosis")] - { - self.osmosis_fee.is_valid()?; - base_fee.checked_add(self.osmosis_fee.share)? - } - - #[cfg(not(feature = "osmosis"))] - { - base_fee - } - }; + let total_fee = self.aggregate()?; // Check if the total fee exceeds 100% if total_fee >= Decimal::percent(100) { diff --git a/packages/white-whale/src/pool_network/querier.rs b/packages/white-whale/src/pool_network/querier.rs index 0ace1a5c..ba5a7dc1 100644 --- a/packages/white-whale/src/pool_network/querier.rs +++ b/packages/white-whale/src/pool_network/querier.rs @@ -6,7 +6,7 @@ use crate::pool_network::pair::{ use crate::pool_network::trio::QueryMsg as TrioQueryMsg; use cosmwasm_std::{ - to_binary, Addr, AllBalanceResponse, BalanceResponse, BankQuery, Coin, QuerierWrapper, + to_json_binary, Addr, AllBalanceResponse, BalanceResponse, BankQuery, Coin, QuerierWrapper, QueryRequest, StdResult, Uint128, WasmQuery, }; @@ -41,7 +41,7 @@ pub fn query_token_balance( ) -> StdResult { let res: Cw20BalanceResponse = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: contract_addr.to_string(), - msg: to_binary(&Cw20QueryMsg::Balance { + msg: to_json_binary(&Cw20QueryMsg::Balance { address: account_addr.to_string(), })?, }))?; @@ -56,7 +56,7 @@ pub fn query_token_info( ) -> StdResult { let token_info: TokenInfoResponse = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: contract_addr.to_string(), - msg: to_binary(&Cw20QueryMsg::TokenInfo {})?, + msg: to_json_binary(&Cw20QueryMsg::TokenInfo {})?, }))?; Ok(token_info) @@ -70,7 +70,7 @@ pub fn query_native_decimals( let res: NativeTokenDecimalsResponse = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: factory_contract.to_string(), - msg: to_binary(&FactoryQueryMsg::NativeTokenDecimals { denom })?, + msg: to_json_binary(&FactoryQueryMsg::NativeTokenDecimals { denom })?, }))?; Ok(res.decimals) } @@ -82,7 +82,7 @@ pub fn query_pair_info( ) -> StdResult { querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: factory_contract.to_string(), - msg: to_binary(&FactoryQueryMsg::Pair { + msg: to_json_binary(&FactoryQueryMsg::Pair { asset_infos: asset_infos.clone(), })?, })) @@ -95,7 +95,7 @@ pub fn simulate( ) -> StdResult { querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: pair_contract.to_string(), - msg: to_binary(&PairQueryMsg::Simulation { + msg: to_json_binary(&PairQueryMsg::Simulation { offer_asset: offer_asset.clone(), })?, })) @@ -108,7 +108,7 @@ pub fn reverse_simulate( ) -> StdResult { querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: pair_contract.to_string(), - msg: to_binary(&PairQueryMsg::ReverseSimulation { + msg: to_json_binary(&PairQueryMsg::ReverseSimulation { ask_asset: ask_asset.clone(), })?, })) @@ -120,7 +120,7 @@ pub fn query_pair_info_from_pair( ) -> StdResult { let pair_info: PairInfo = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: pair_contract.to_string(), - msg: to_binary(&PairQueryMsg::Pair {})?, + msg: to_json_binary(&PairQueryMsg::Pair {})?, }))?; Ok(pair_info) @@ -132,7 +132,7 @@ pub fn query_trio_info_from_trio( ) -> StdResult { let trio_info: TrioInfo = querier.query(&QueryRequest::Wasm(WasmQuery::Smart { contract_addr: trio_contract.to_string(), - msg: to_binary(&TrioQueryMsg::Trio {})?, + msg: to_json_binary(&TrioQueryMsg::Trio {})?, }))?; Ok(trio_info) diff --git a/packages/white-whale/src/pool_network/testing.rs b/packages/white-whale/src/pool_network/testing.rs index b0936716..5d4e9154 100644 --- a/packages/white-whale/src/pool_network/testing.rs +++ b/packages/white-whale/src/pool_network/testing.rs @@ -6,8 +6,8 @@ use crate::pool_network::querier::{ use cosmwasm_std::testing::MOCK_CONTRACT_ADDR; use cosmwasm_std::{ - coin, to_binary, Addr, Api, BankMsg, Coin, CosmosMsg, MessageInfo, StdError, SubMsg, Uint128, - WasmMsg, + coin, to_json_binary, Addr, Api, BankMsg, Coin, CosmosMsg, MessageInfo, StdError, SubMsg, + Uint128, WasmMsg, }; use cw20::Cw20ExecuteMsg; @@ -195,7 +195,7 @@ fn test_asset() { .unwrap(), CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: Uint128::from(123123u128), }) @@ -210,7 +210,7 @@ fn test_asset() { .unwrap(), SubMsg::new(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: "asset0000".to_string(), - msg: to_binary(&Cw20ExecuteMsg::Transfer { + msg: to_json_binary(&Cw20ExecuteMsg::Transfer { recipient: "addr0000".to_string(), amount: Uint128::from(123123u128), }) diff --git a/packages/white-whale/src/pool_network/trio.rs b/packages/white-whale/src/pool_network/trio.rs index abf23ff0..12c86187 100644 --- a/packages/white-whale/src/pool_network/trio.rs +++ b/packages/white-whale/src/pool_network/trio.rs @@ -137,24 +137,7 @@ impl PoolFee { self.swap_fee.is_valid()?; self.burn_fee.is_valid()?; - let total_fee = { - let base_fee = self - .protocol_fee - .share - .checked_add(self.swap_fee.share)? - .checked_add(self.burn_fee.share)?; - - #[cfg(feature = "osmosis")] - { - self.osmosis_fee.is_valid()?; - base_fee.checked_add(self.osmosis_fee.share)? - } - - #[cfg(not(feature = "osmosis"))] - { - base_fee - } - }; + let total_fee = self.aggregate()?; // Check if the total fee exceeds 100% if total_fee >= Decimal::percent(100) {