Skip to content

Commit

Permalink
feat(liq. manager): add PCL support
Browse files Browse the repository at this point in the history
  • Loading branch information
epanchee authored May 27, 2024
1 parent 9928471 commit 5e7d5cd
Show file tree
Hide file tree
Showing 10 changed files with 264 additions and 36 deletions.
42 changes: 22 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion contracts/periphery/liquidity_manager/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astroport-liquidity-manager"
version = "1.1.0"
version = "1.2.0"
edition = "2021"
description = "Astroport Liquidity Manager contract"
license = "GPL-3.0-only"
Expand All @@ -19,10 +19,13 @@ cosmwasm-schema.workspace = true
cw-storage-plus.workspace = true
cw20 = "1.1"
thiserror.workspace = true
itertools.workspace = true
astroport = { path = "../../../packages/astroport", version = "4" }
cw20-base = { version = "1.1", features = ["library"] }
astroport-pair = { path = "../../pair", features = ["library"], version = "1.5" }
astroport-pair-stable = { path = "../../pair_stable", features = ["library"], version = "3" }
astroport-pair-concentrated = { path = "../../pair_concentrated", features = ["library"], version = "3" }
astroport-pcl-common = { path = "../../../packages/astroport_pcl_common", version = "2" }
astroport-factory = { path = "../../factory", features = ["library"], version = "1" }

[dev-dependencies]
Expand Down
59 changes: 56 additions & 3 deletions contracts/periphery/liquidity_manager/src/query.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{to_json_binary, Binary, Deps, Env, StdError, StdResult, Uint128};
Expand All @@ -8,9 +10,13 @@ use astroport::liquidity_manager::QueryMsg;
use astroport::pair::{ExecuteMsg as PairExecuteMsg, QueryMsg as PairQueryMsg};
use astroport::querier::query_supply;
use astroport_pair::contract::get_share_in_assets;
use astroport_pcl_common::state::Precisions;

use crate::error::ContractError;
use crate::utils::{convert_config, stableswap_provide_simulation, xyk_provide_simulation};
use crate::utils::{
convert_pcl_config, convert_stable_config, pcl_provide_simulation,
stableswap_provide_simulation, xyk_provide_simulation,
};

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> StdResult<Binary> {
Expand Down Expand Up @@ -102,7 +108,7 @@ fn simulate_provide(
.querier
.query_wasm_raw(pair_addr, b"config")?
.ok_or_else(|| StdError::generic_err("pair stable config not found"))?;
let pair_config = convert_config(deps.querier, pair_config_data)?;
let pair_config = convert_stable_config(deps.querier, pair_config_data)?;
to_json_binary(
&stableswap_provide_simulation(
deps.querier,
Expand All @@ -114,7 +120,54 @@ fn simulate_provide(
.map_err(|err| StdError::generic_err(format!("{err}")))?,
)
}
PairType::Custom(..) => unimplemented!("not implemented yet"),
PairType::Custom(typ) if typ == "concentrated" => {
let balances = pair_info.query_pools(&deps.querier, &pair_addr)?;
let pcl_config_raw = deps
.querier
.query_wasm_raw(&pair_addr, b"config")?
.ok_or_else(|| StdError::generic_err("PCL config not found"))?;
let pcl_config = convert_pcl_config(pcl_config_raw)?;
let precisions = balances
.iter()
.map(|asset| {
let prec = Precisions::PRECISIONS
.query(&deps.querier, pair_addr.clone(), asset.info.to_string())?
.or_else(|| {
asset
.info
.decimals(&deps.querier, &pcl_config.factory_addr)
.ok()
})
.ok_or_else(|| {
StdError::generic_err(format!(
"Asset {} precision not found",
&asset.info
))
})?;
Ok((asset.info.to_string(), prec))
})
.collect::<StdResult<HashMap<_, _>>>()?;
let dec_balances = balances
.into_iter()
.map(|asset| {
asset
.to_decimal_asset(*precisions.get(&asset.info.to_string()).unwrap())
.map_err(Into::into)
})
.collect::<StdResult<Vec<_>>>()?;
let total_share = query_supply(&deps.querier, &pair_info.liquidity_token)?;
pcl_provide_simulation(
env,
dec_balances,
assets,
total_share,
pcl_config,
precisions,
)
.map_err(|err| StdError::generic_err(err.to_string()))
.and_then(|res| to_json_binary(&res))
}
PairType::Custom(_) => unimplemented!("not implemented yet"),
}
}
_ => Err(StdError::generic_err("Invalid simulate message")),
Expand Down
Loading

0 comments on commit 5e7d5cd

Please sign in to comment.