diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/helpers/msgs.rs b/smart-contracts/osmosis/contracts/cl-vault/src/helpers/msgs.rs index 578014ece..6b691a12a 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/helpers/msgs.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/helpers/msgs.rs @@ -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, }; @@ -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, @@ -55,26 +51,25 @@ pub fn swap_msg( params: SwapParams, dex_router: Option, ) -> Result { - 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, - ¶ms.token_in_denom.to_string(), + params.token_in_denom, params.token_out_min_amount, )) } @@ -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(), @@ -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 { let position = POSITION.load(deps.storage)?; Ok(MsgCollectIncentives { diff --git a/smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs b/smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs index b494f9ea3..3f5bdfeec 100644 --- a/smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs +++ b/smart-contracts/osmosis/contracts/cl-vault/src/vault/swap.rs @@ -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() - // ); - // } }