From b7b525039caceec972c404b0b0ee711032d841e7 Mon Sep 17 00:00:00 2001 From: Obie Kaku Date: Mon, 1 Apr 2024 10:28:13 -0500 Subject: [PATCH] updated the simulate_pool_swap token in format --- packages/osmosis-helpers/src/osmosis_lp.rs | 2 +- packages/osmosis-helpers/src/osmosis_swap.rs | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/osmosis-helpers/src/osmosis_lp.rs b/packages/osmosis-helpers/src/osmosis_lp.rs index a552788..3375ff9 100644 --- a/packages/osmosis-helpers/src/osmosis_lp.rs +++ b/packages/osmosis-helpers/src/osmosis_lp.rs @@ -178,7 +178,7 @@ pub fn join_osmosis_cl_pool_single_side( querier, user_addr, &pool_id, - coin( + &coin( offer_asset.amount.checked_div(2u128.into())?.u128(), offer_asset.denom.clone(), ), diff --git a/packages/osmosis-helpers/src/osmosis_swap.rs b/packages/osmosis-helpers/src/osmosis_swap.rs index af655b1..349d3a5 100644 --- a/packages/osmosis-helpers/src/osmosis_swap.rs +++ b/packages/osmosis-helpers/src/osmosis_swap.rs @@ -440,12 +440,12 @@ pub fn generate_swap( pub fn simulate_pool_swap( querier: &QuerierWrapper, pool_id: &u64, - offer_asset: &str, + offer_token: &CWCoin, token_out_denom: &str, ) -> Result { let simulation = EstimateSwapExactAmountInRequest { pool_id: pool_id.clone(), - token_in: offer_asset.to_string(), + token_in: format!("{}{}", offer_token.amount, offer_token.denom), routes: vec![SwapAmountInRoute { pool_id: *pool_id, token_out_denom: token_out_denom.to_string(), @@ -460,19 +460,17 @@ pub fn pool_swap_with_sim( querier: &QuerierWrapper, user_addr: &Addr, pool_id: &u64, - offer_asset: cosmwasm_std::Coin, + offer_asset: &CWCoin, token_out_denom: &str, token_out_min_amount: Uint128, ) -> Result<(Vec, Uint128), OsmosisHelperError> { - let offer_coin = Coin { - denom: offer_asset.denom.to_string(), - amount: offer_asset.amount.to_string(), - }; - Ok(( vec![CosmosProtoMsg::OsmosisSwapExactAmountIn( MsgSwapExactAmountIn { - token_in: Some(offer_coin.clone()), + token_in: Some(Coin { + denom: offer_asset.denom.to_string(), + amount: offer_asset.amount.to_string(), + }), sender: user_addr.to_string(), token_out_min_amount: token_out_min_amount.to_string(), routes: vec![SwapAmountInRoute { @@ -482,7 +480,7 @@ pub fn pool_swap_with_sim( }, )], Uint128::from_str( - simulate_pool_swap(querier, pool_id, &offer_coin.denom, token_out_denom)? + simulate_pool_swap(querier, pool_id, offer_asset, token_out_denom)? .token_out_amount .as_str(), )?,