Skip to content

Commit

Permalink
Remove redundant string conversions (#763)
Browse files Browse the repository at this point in the history
  • Loading branch information
lubkoll authored Aug 9, 2024
1 parent 08ab150 commit c857b1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 55 deletions.
27 changes: 10 additions & 17 deletions smart-contracts/osmosis/contracts/cl-vault/src/helpers/msgs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::{state::POSITION, vault::swap::SwapParams, ContractError};
use cosmwasm_std::{
attr, to_json_binary, Addr, Attribute, BankMsg, Coin, CosmosMsg, Deps, Env, Uint128, WasmMsg,
};
Expand All @@ -10,11 +11,6 @@ use osmosis_std::types::{
},
};

use crate::{state::POSITION, vault::swap::SwapParams, ContractError};

// Bank

/// Generate a bank message and attributes for refunding tokens to a recipient.
pub fn refund_bank_msg(
receiver: Addr,
refund0: Option<Coin>,
Expand Down Expand Up @@ -55,26 +51,25 @@ pub fn swap_msg(
params: SwapParams,
dex_router: Option<Addr>,
) -> Result<CosmosMsg, ContractError> {
let pool_route = SwapAmountInRoute {
pool_id: params.pool_id,
token_out_denom: params.token_out_denom.to_string(),
};

if let Some(dex_router) = dex_router {
cw_dex_execute_swap_operations_msg(
dex_router,
params.forced_swap_route,
params.token_in_denom.to_string(),
params.token_in_denom,
params.token_in_amount,
params.token_out_denom.to_string(),
params.token_out_denom,
params.token_out_min_amount,
)
} else {
let pool_route = SwapAmountInRoute {
pool_id: params.pool_id,
token_out_denom: params.token_out_denom,
};
Ok(osmosis_swap_exact_amount_in_msg(
sender,
pool_route,
params.token_in_amount,
&params.token_in_denom.to_string(),
params.token_in_denom,
params.token_out_min_amount,
))
}
Expand All @@ -84,14 +79,14 @@ fn osmosis_swap_exact_amount_in_msg(
sender: Addr,
pool_route: SwapAmountInRoute,
token_in_amount: Uint128,
token_in_denom: &String,
token_in_denom: String,
token_out_min_amount: Uint128,
) -> CosmosMsg {
osmosis_std::types::osmosis::poolmanager::v1beta1::MsgSwapExactAmountIn {
sender: sender.to_string(),
routes: vec![pool_route],
token_in: Some(OsmoCoin {
denom: token_in_denom.to_string(),
denom: token_in_denom,
amount: token_in_amount.to_string(),
}),
token_out_min_amount: token_out_min_amount.to_string(),
Expand Down Expand Up @@ -124,8 +119,6 @@ fn cw_dex_execute_swap_operations_msg(
Ok(swap_msg)
}

/// Collect Incentives
pub fn collect_incentives_msg(deps: Deps, env: Env) -> Result<MsgCollectIncentives, ContractError> {
let position = POSITION.load(deps.storage)?;
Ok(MsgCollectIncentives {
Expand Down
38 changes: 0 additions & 38 deletions smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,42 +231,4 @@ mod tests {
panic!("Unexpected message type: {:?}", result);
}
}

// TODO: Move this test logic into any invoker of swap_msg tests as now its their concern to
// validate the token_in_denom based on the context we swap (either non vault funds or during a rerange / anydeposit)
// #[test]
// fn test_bad_denom_swap() {
// let mut deps = mock_dependencies_with_balance(&[Coin {
// denom: "token0".to_string(),
// amount: Uint128::new(1000),
// }]);
// let deps_mut = deps.as_mut();

// let env = mock_env();

// let token_in_amount = Uint128::new(100);
// let token_in_denom = "token3".to_string();
// let token_out_min_amount = Uint128::new(100);
// let token_out_denom = "token1".to_string();

// let swap_params = SwapParams {
// token_in_amount,
// token_out_min_amount,
// token_in_denom,
// token_out_denom,
// recommended_swap_route: None,
// force_swap_route: false,
// };

// POOL_CONFIG
// .save(deps_mut.storage, &mock_pool_config())
// .unwrap();

// let err = super::swap_msg(&deps_mut, &env, swap_params).unwrap_err();

// assert_eq!(
// err.to_string(),
// "Bad token out requested for swap, must be one of: \"token0\", \"token1\"".to_string()
// );
// }
}

0 comments on commit c857b1b

Please sign in to comment.