Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ cw-storage-plus = "1.1.0"
cw-utils = "1.0.1"
mars-owner = { version = "2.0.0", features = ["emergency-owner"] }
neutron-sdk = "0.6.1"
osmosis-std = "0.16.1"
osmosis-std = "0.16.2"
prost = { version = "0.11.9", default-features = false }
pyth-sdk-cw = "1.2.0"
schemars = "0.8.12"
Expand Down
8 changes: 7 additions & 1 deletion contracts/oracle/osmosis/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::DowntimeDetector;
/// 48 hours in seconds
const TWO_DAYS_IN_SECONDS: u64 = 172800u64;

/// Assert the Osmosis pool indicated by `pool_id` is of Balancer XYK or StableSwap and assets are OSMO and `denom`
/// Assert the Osmosis pool indicated by `pool_id` is of Balancer XYK, StableSwap or ConcentratedLiquidity and assets are OSMO and `denom`
pub fn assert_osmosis_pool_assets(
pool: &Pool,
denom: &str,
Expand All @@ -23,6 +23,7 @@ pub fn assert_osmosis_pool_assets(
assert_equal_asset_weights(balancer_pool)?;
}
Pool::StableSwap(_) => {}
Pool::ConcentratedLiquidity(_) => {}
};

Ok(())
Expand All @@ -39,6 +40,11 @@ pub fn assert_osmosis_xyk_lp_pool(pool: &Pool) -> ContractResult<()> {
reason: format!("StableSwap pool not supported. Pool id {}", stable_swap_pool.id),
});
}
Pool::ConcentratedLiquidity(cl_pool) => {
return Err(ContractError::InvalidPriceSource {
reason: format!("ConcentratedLiquidity pool not supported. Pool id {}", cl_pool.id),
});
}
};

Ok(())
Expand Down
8 changes: 8 additions & 0 deletions contracts/oracle/osmosis/src/price_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,14 @@ impl OsmosisPriceSourceChecked {
reason: format!("StableSwap pool not supported. Pool id {}", pool.id),
})
}
Pool::ConcentratedLiquidity(pool) => {
return Err(ContractError::InvalidPrice {
reason: format!(
"ConcentratedLiquidity pool not supported. Pool id {}",
pool.id
),
})
}
};

let coin0 = Pool::unwrap_coin(&pool.pool_assets[0].token)?;
Expand Down
29 changes: 28 additions & 1 deletion contracts/oracle/osmosis/tests/tests/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use cosmwasm_std::{
};
use mars_oracle_base::ContractError;
use mars_oracle_osmosis::{contract::entry, msg::ExecuteMsg, OsmosisPriceSourceUnchecked};
use mars_osmosis::{BalancerPool, StableSwapPool};
use mars_osmosis::{BalancerPool, ConcentratedLiquidityPool, StableSwapPool};
use mars_red_bank_types::oracle::msg::{InstantiateMsg, QueryMsg};
use mars_testing::{mock_info, MarsMockQuerier};
use osmosis_std::types::osmosis::{gamm::v1beta1::PoolAsset, poolmanager::v1beta1::PoolResponse};
Expand Down Expand Up @@ -96,6 +96,10 @@ pub fn setup_test_with_pools() -> OwnedDeps<MockStorage, MockApi, MarsMockQuerie
deps.querier
.set_query_pool_response(6666, prepare_query_stable_swap_pool_response(6666, &assets));

// Set ConcentratedLiquidity pool
deps.querier
.set_query_pool_response(7777, prepare_query_cl_pool_response(7777, "ujuno", "uosmo"));

deps
}

Expand Down Expand Up @@ -207,6 +211,29 @@ pub fn prepare_query_stable_swap_pool_response(pool_id: u64, assets: &[Coin]) ->
}
}

pub fn prepare_query_cl_pool_response(pool_id: u64, token0: &str, token1: &str) -> PoolResponse {
let pool = ConcentratedLiquidityPool {
address: "osmo126pr9qp44aft4juw7x4ev4s2qdtnwe38jzwunec9pxt5cpzaaphqyagqpu".to_string(),
incentives_address: "osmo1h2mhtj3wmsdt3uacev9pgpg38hkcxhsmyyn9ums0ya6eddrsafjsxs9j03"
.to_string(),
spread_rewards_address: "osmo16j5sssw32xuk8a0kjj8n54g25ye6kr339nz5axf8lzyeajk0k22stsm36c"
.to_string(),
id: pool_id,
current_tick_liquidity: "3820025893854099618.699762490947860933".to_string(),
token0: token0.to_string(),
token1: token1.to_string(),
current_sqrt_price: "656651.537483144215151633465586753226461989".to_string(),
current_tick: 102311912,
tick_spacing: 100,
exponent_at_price_one: -6,
spread_factor: "0.002000000000000000".to_string(),
last_liquidity_update: None,
};
PoolResponse {
pool: Some(pool.to_any()),
}
}

pub fn set_pyth_price_source(deps: DepsMut, denom: &str, price_id: PriceIdentifier) {
set_price_source(
deps,
Expand Down
11 changes: 10 additions & 1 deletion contracts/oracle/osmosis/tests/tests/test_set_price_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,14 +1036,23 @@ fn setting_price_source_xyk_lp() {
);

// attempting to use StableSwap pool
let err = set_price_source_xyk_lp("atom_mars_lp", 5555).unwrap_err();
let err = set_price_source_xyk_lp("atom_uosmo_lp", 5555).unwrap_err();
assert_eq!(
err,
ContractError::InvalidPriceSource {
reason: "StableSwap pool not supported. Pool id 5555".to_string()
}
);

// attempting to use ConcentratedLiquid pool
let err = set_price_source_xyk_lp("ujuno_uosmo_lp", 7777).unwrap_err();
assert_eq!(
err,
ContractError::InvalidPriceSource {
reason: "ConcentratedLiquidity pool not supported. Pool id 7777".to_string()
}
);

// properly set xyk lp price source
let res = set_price_source_xyk_lp("uosmo_umars_lp", 89).unwrap();
assert_eq!(res.messages.len(), 0);
Expand Down
45 changes: 44 additions & 1 deletion packages/chains/osmosis/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use osmosis_std::{
types::{
cosmos::base::v1beta1::Coin,
osmosis::{
concentratedliquidity::v1beta1::Pool as ConcentratedLiquidityPool,
downtimedetector::v1beta1::DowntimedetectorQuerier,
gamm::{
poolmodels::stableswap::v1beta1::Pool as StableSwapPool,
Expand All @@ -30,13 +31,15 @@ pub trait CommonPoolData {
pub enum Pool {
Balancer(BalancerPool),
StableSwap(StableSwapPool),
ConcentratedLiquidity(ConcentratedLiquidityPool),
}

impl CommonPoolData for Pool {
fn get_pool_id(&self) -> u64 {
match self {
Pool::Balancer(pool) => pool.id,
Pool::StableSwap(pool) => pool.id,
Pool::ConcentratedLiquidity(pool) => pool.id,
}
}

Expand All @@ -51,6 +54,9 @@ impl CommonPoolData for Pool {
Pool::StableSwap(pool) => {
pool.pool_liquidity.iter().map(|pl| pl.denom.clone()).collect()
}
Pool::ConcentratedLiquidity(pool) => {
vec![pool.token0.clone(), pool.token1.clone()]
}
}
}
}
Expand All @@ -62,13 +68,18 @@ impl TryFrom<osmosis_std::shim::Any> for Pool {
if let Ok(pool) = BalancerPool::decode(value.value.as_slice()) {
return Ok(Pool::Balancer(pool));
}

if let Ok(pool) = StableSwapPool::decode(value.value.as_slice()) {
return Ok(Pool::StableSwap(pool));
}

if let Ok(pool) = ConcentratedLiquidityPool::decode(value.value.as_slice()) {
return Ok(Pool::ConcentratedLiquidity(pool));
}

Err(StdError::parse_err(
"Pool",
"Unsupported pool: must be either `Balancer` or `StableSwap`.",
"Unsupported pool: must be either `Balancer`, `StableSwap` or `ConcentratedLiquidity`.",
))
}
}
Expand Down Expand Up @@ -279,4 +290,36 @@ mod tests {
assert_eq!(stable_swap_pool.id, pool.get_pool_id());
assert_eq!(vec!["denom_1".to_string(), "denom_2".to_string()], pool.get_pool_denoms())
}

#[test]
fn common_data_for_concentrated_liquidity_pool() {
let concentrated_liquidity_pool = ConcentratedLiquidityPool {
address: "pool_address".to_string(),
incentives_address: "incentives_address".to_string(),
spread_rewards_address: "spread_rewards_address".to_string(),
id: 1066,
current_tick_liquidity: "3820025893854099618.699762490947860933".to_string(),
token0: "uosmo".to_string(),
token1: "ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7"
.to_string(),
current_sqrt_price: "656651.537483144215151633465586753226461989".to_string(),
current_tick: 102311912,
tick_spacing: 100,
exponent_at_price_one: -6,
spread_factor: "0.002000000000000000".to_string(),
last_liquidity_update: None,
};

let any_pool = concentrated_liquidity_pool.to_any();
let pool: Pool = any_pool.try_into().unwrap();

assert_eq!(concentrated_liquidity_pool.id, pool.get_pool_id());
assert_eq!(
vec![
"uosmo".to_string(),
"ibc/0CD3A0285E1341859B5E86B6AB7682F023D03E97607CCC1DC95706411D866DF7".to_string()
],
pool.get_pool_denoms()
);
}
}
7 changes: 5 additions & 2 deletions packages/chains/osmosis/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub mod helpers;

pub use osmosis_std::types::osmosis::gamm::{
poolmodels::stableswap::v1beta1::Pool as StableSwapPool, v1beta1::Pool as BalancerPool,
pub use osmosis_std::types::osmosis::{
concentratedliquidity::v1beta1::Pool as ConcentratedLiquidityPool,
gamm::{
poolmodels::stableswap::v1beta1::Pool as StableSwapPool, v1beta1::Pool as BalancerPool,
},
};