diff --git a/cw-dex-astroport/src/pool.rs b/cw-dex-astroport/src/pool.rs index 96bd68e..37c2443 100644 --- a/cw-dex-astroport/src/pool.rs +++ b/cw-dex-astroport/src/pool.rs @@ -36,7 +36,7 @@ pub struct AstroportPool { /// The type of pool represented: Constant product (*Xyk*) or *Stableswap* pub pair_type: PairType, /// The address of the Astroport liquidity manager contract - pub liquidity_manager: Addr, + pub liquidity_manager: Option, } impl AstroportPool { @@ -44,7 +44,7 @@ impl AstroportPool { /// /// Arguments: /// - `pair_addr`: The address of the pair contract associated with the pool - pub fn new(deps: Deps, pair_addr: Addr, liquidity_manager: Addr) -> StdResult { + pub fn new(deps: Deps, pair_addr: Addr, liquidity_manager: Option) -> StdResult { let pair_info = deps .querier .query_wasm_smart::( @@ -84,7 +84,7 @@ impl AstroportPool { pub fn get_pool_for_lp_token( deps: Deps, lp_token: &AssetInfo, - astroport_liquidity_manager: Addr, + astroport_liquidity_manager: Option, ) -> Result { match lp_token { AssetInfo::Cw20(address) => { @@ -131,7 +131,7 @@ impl Pool for AstroportPool { _deps: Deps, env: &Env, assets: AssetList, - min_out: Uint128, + _min_out: Uint128, ) -> Result { let (funds, cw20s) = separate_natives_and_cw20s(&assets); @@ -142,7 +142,7 @@ impl Pool for AstroportPool { Ok(CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: asset.address, msg: to_json_binary(&Cw20ExecuteMsg::IncreaseAllowance { - spender: self.liquidity_manager.to_string(), + spender: self.pair_addr.to_string(), amount: asset.amount, expires: Some(Expiration::AtHeight(env.block.height + 1)), })?, @@ -161,16 +161,12 @@ impl Pool for AstroportPool { // Create the provide liquidity message let provide_liquidity_msg = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: self.liquidity_manager.to_string(), - msg: to_json_binary(&liquidity_manager::ExecuteMsg::ProvideLiquidity { - pair_addr: self.pair_addr.to_string(), - min_lp_to_receive: Some(min_out), - pair_msg: astroport::pair::ExecuteMsg::ProvideLiquidity { - assets: assets_vec.into_elementwise(), - slippage_tolerance: Some(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?), - auto_stake: Some(false), - receiver: None, - }, + contract_addr: self.pair_addr.to_string(), + msg: to_json_binary(&astroport::pair::ExecuteMsg::ProvideLiquidity { + assets: assets_vec.into_elementwise(), + slippage_tolerance: Some(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?), + auto_stake: Some(false), + receiver: None, })?, funds, }); @@ -205,7 +201,13 @@ impl Pool for AstroportPool { let withdraw_liquidity = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: token_addr.to_string(), msg: to_json_binary(&Cw20ExecuteMsg::Send { - contract: self.liquidity_manager.to_string(), + contract: self + .liquidity_manager + .clone() + .ok_or(CwDexError::Std(StdError::generic_err( + "Custom pair type is not supported", + )))? + .to_string(), amount: asset.amount, msg: to_json_binary(&liquidity_manager::Cw20HookMsg::WithdrawLiquidity { pair_msg: astroport::pair::Cw20HookMsg::WithdrawLiquidity { @@ -239,11 +241,11 @@ impl Pool for AstroportPool { let withdraw_liquidity = CosmosMsg::Wasm(WasmMsg::Execute { contract_addr: self.pair_addr.to_string(), msg: to_json_binary(&astroport_v5::pair::ExecuteMsg::WithdrawLiquidity { - assets: vec![asset_to_astroport_v5_asset(asset.clone())], + assets: vec![asset_to_astroport_v5_asset(&asset.clone())], min_assets_to_receive: Some( min_out .to_vec() - .into_iter() + .iter() .map(asset_to_astroport_v5_asset) .collect(), ), @@ -326,15 +328,10 @@ impl Pool for AstroportPool { assets: AssetList, ) -> Result { let amount: Uint128 = deps.querier.query_wasm_smart( - self.liquidity_manager.to_string(), - &liquidity_manager::QueryMsg::SimulateProvide { - pair_addr: self.pair_addr.to_string(), - pair_msg: astroport::pair::ExecuteMsg::ProvideLiquidity { - assets: assets.into(), - slippage_tolerance: Some(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?), - auto_stake: Some(false), - receiver: None, - }, + self.pair_addr.to_string(), + &astroport_v5::pair::QueryMsg::SimulateProvide { + assets: assets.iter().map(asset_to_astroport_v5_asset).collect(), + slippage_tolerance: Some(Decimal::from_str(MAX_ALLOWED_SLIPPAGE)?), }, )?; @@ -352,10 +349,9 @@ impl Pool for AstroportPool { lp_token: &Asset, ) -> Result { let assets: Vec = deps.querier.query_wasm_smart( - self.liquidity_manager.to_string(), - &liquidity_manager::QueryMsg::SimulateWithdraw { - pair_addr: self.pair_addr.to_string(), - lp_tokens: lp_token.amount, + self.pair_addr.to_string(), + &astroport_v5::pair::QueryMsg::SimulateWithdraw { + lp_amount: lp_token.amount, }, )?; @@ -396,11 +392,11 @@ pub fn astroport_v5_assetinfo_to_assetinfo(asset: astroport_v5::asset::AssetInfo } } -pub fn asset_to_astroport_v5_asset(asset: Asset) -> astroport_v5::asset::Asset { - match asset.info { +pub fn asset_to_astroport_v5_asset(asset: &Asset) -> astroport_v5::asset::Asset { + match &asset.info { AssetInfoBase::Native(denom) => astroport_v5::asset::Asset::native(denom, asset.amount), AssetInfo::Cw20(contract_addr) => { - astroport_v5::asset::Asset::cw20(contract_addr, asset.amount) + astroport_v5::asset::Asset::cw20(contract_addr.clone(), asset.amount) } } } diff --git a/test-contracts/astroport-test-contract/src/contract.rs b/test-contracts/astroport-test-contract/src/contract.rs index 9a1acb8..ab51ea9 100644 --- a/test-contracts/astroport-test-contract/src/contract.rs +++ b/test-contracts/astroport-test-contract/src/contract.rs @@ -21,8 +21,7 @@ pub fn instantiate( msg: InstantiateMsg, ) -> Result { let pair_addr = deps.api.addr_validate(&msg.pair_addr)?; - let liquidity_manager = deps.api.addr_validate(&msg.liquidity_manager_addr)?; - let pool = AstroportPool::new(deps.as_ref(), pair_addr, liquidity_manager)?; + let pool = AstroportPool::new(deps.as_ref(), pair_addr, None)?; POOL.save(deps.storage, &pool)?; STAKING.save( diff --git a/test-contracts/package/src/msg.rs b/test-contracts/package/src/msg.rs index 60481f6..3501df9 100644 --- a/test-contracts/package/src/msg.rs +++ b/test-contracts/package/src/msg.rs @@ -16,7 +16,6 @@ pub struct AstroportContractInstantiateMsg { pub lp_token: String, pub incentives_addr: String, pub astro_token: AssetInfo, - pub liquidity_manager_addr: String, } #[cw_serde] diff --git a/test-helpers/src/astroport.rs b/test-helpers/src/astroport.rs index 0ce5374..70b8716 100644 --- a/test-helpers/src/astroport.rs +++ b/test-helpers/src/astroport.rs @@ -275,7 +275,6 @@ pub fn setup_pool_and_test_contract<'a>( astroport_contracts.astro_token.address.clone(), )), lp_token_addr.clone(), - astroport_contracts.liquidity_manager.address.clone(), &accs[0], )?; @@ -297,7 +296,6 @@ pub fn instantiate_test_astroport_contract<'a, R: Runner<'a>>( incentives_addr: String, astro_token: AssetInfo, lp_token: String, - liquidity_manager_addr: String, signer: &SigningAccount, ) -> RunnerResult { let init_msg = AstroportContractInstantiateMsg { @@ -305,7 +303,6 @@ pub fn instantiate_test_astroport_contract<'a, R: Runner<'a>>( lp_token, incentives_addr, astro_token, - liquidity_manager_addr, }; let wasm = Wasm::new(runner);