From 8154300f401f9828e8fc57346e1ef31890593c77 Mon Sep 17 00:00:00 2001 From: Piotr Babel Date: Tue, 25 Jul 2023 11:57:43 +0200 Subject: [PATCH] Migrate to PoolManager for Pool and SpotPrice. Read StableSwap pool. --- Cargo.lock | 9 +- Cargo.toml | 2 +- contracts/oracle/osmosis/src/helpers.rs | 51 +++++- contracts/oracle/osmosis/src/price_source.rs | 13 +- contracts/oracle/osmosis/tests/helpers.rs | 75 ++++++-- .../oracle/osmosis/tests/test_query_price.rs | 10 +- .../osmosis/tests/test_set_price_source.rs | 9 + .../osmosis/tests/helpers.rs | 14 +- contracts/swapper/osmosis/src/route.rs | 7 +- packages/chains/osmosis/Cargo.toml | 1 + packages/chains/osmosis/src/helpers.rs | 164 ++++++++++++++---- packages/chains/osmosis/src/lib.rs | 4 + packages/testing/src/mars_mock_querier.rs | 5 +- packages/testing/src/osmosis_querier.rs | 9 +- 14 files changed, 283 insertions(+), 90 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8212e3e39..4e09fde35 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1859,6 +1859,7 @@ version = "1.2.0" dependencies = [ "cosmwasm-std", "osmosis-std", + "prost 0.11.9", "serde", ] @@ -2256,9 +2257,9 @@ dependencies = [ [[package]] name = "osmosis-test-tube" -version = "16.0.1" +version = "16.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "527375c01396e7e4de4ccc18a0141aeb6b342dc089d30c57282025f3a8753e72" +checksum = "4929047d1dcec5d7d02fd0a00ecdfca78918d3a33bffc193bf57b3eeb4d407ab" dependencies = [ "base64 0.13.1", "bindgen", @@ -3016,9 +3017,9 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e168eaaf71e8f9bd6037feb05190485708e019f4fd87d161b3c0a0d37daf85e5" +checksum = "8725e1dfadb3a50f7e5ce0b1a540466f6ed3fe7a0fca2ac2b8b831d31316bd00" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index da170bbbf..2c4861dcd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ neutron-sdk = "0.6.0" # dev-dependencies cw-multi-test = "0.16.5" cw-it = "0.1.0" -osmosis-test-tube = "16.0.0" +osmosis-test-tube = "=16.1.1" test-case = "3.0.0" proptest = "1.1.0" diff --git a/contracts/oracle/osmosis/src/helpers.rs b/contracts/oracle/osmosis/src/helpers.rs index 342c9e2ce..4ffc2a1ec 100644 --- a/contracts/oracle/osmosis/src/helpers.rs +++ b/contracts/oracle/osmosis/src/helpers.rs @@ -1,28 +1,63 @@ use mars_oracle_base::{ContractError, ContractResult}; -use mars_osmosis::helpers::{has_denom, Pool}; +use mars_osmosis::{ + helpers::{CommonPoolData, Pool}, + BalancerPool, +}; use crate::DowntimeDetector; /// 48 hours in seconds const TWO_DAYS_IN_SECONDS: u64 = 172800u64; -/// Assert the Osmosis pool indicated by `pool_id` is of XYK type and assets are OSMO and `denom` +/// Assert the Osmosis pool indicated by `pool_id` is of Balancer XYK or StableSwap and assets are OSMO and `denom` pub fn assert_osmosis_pool_assets( pool: &Pool, denom: &str, base_denom: &str, ) -> ContractResult<()> { - assert_osmosis_xyk_pool(pool)?; + match pool { + Pool::Balancer(balancer_pool) => { + assert_osmosis_xyk_pool(balancer_pool)?; + } + Pool::StableSwap(_) => {} + }; + + assert_osmosis_pool_contains_two_assets(pool, denom, base_denom)?; + + Ok(()) +} + +/// Assert the Osmosis pool indicated by `pool_id` is Balancer XYK type +pub fn assert_osmosis_xyk_lp_pool(pool: &Pool) -> ContractResult<()> { + match pool { + Pool::Balancer(balancer_pool) => assert_osmosis_xyk_pool(balancer_pool)?, + Pool::StableSwap(stable_swap_pool) => { + return Err(ContractError::InvalidPriceSource { + reason: format!("StableSwap pool not supported. Pool id {}", stable_swap_pool.id), + }); + } + }; + + Ok(()) +} + +fn assert_osmosis_pool_contains_two_assets( + pool: &Pool, + denom: &str, + base_denom: &str, +) -> ContractResult<()> { + let pool_id = pool.get_pool_id(); + let pool_denoms = pool.get_pool_denoms(); - if !has_denom(base_denom, &pool.pool_assets) { + if !pool_denoms.contains(&base_denom.to_string()) { return Err(ContractError::InvalidPriceSource { - reason: format!("pool {} does not contain the base denom {}", pool.id, base_denom), + reason: format!("pool {} does not contain the base denom {}", pool_id, base_denom), }); } - if !has_denom(denom, &pool.pool_assets) { + if !pool_denoms.contains(&denom.to_string()) { return Err(ContractError::InvalidPriceSource { - reason: format!("pool {} does not contain {}", pool.id, denom), + reason: format!("pool {} does not contain {}", pool_id, denom), }); } @@ -30,7 +65,7 @@ pub fn assert_osmosis_pool_assets( } /// Assert the Osmosis pool indicated by `pool_id` is of XYK type -pub fn assert_osmosis_xyk_pool(pool: &Pool) -> ContractResult<()> { +pub fn assert_osmosis_xyk_pool(pool: &BalancerPool) -> ContractResult<()> { if pool.pool_assets.len() != 2 { return Err(ContractError::InvalidPriceSource { reason: format!( diff --git a/contracts/oracle/osmosis/src/price_source.rs b/contracts/oracle/osmosis/src/price_source.rs index f1c1ed599..22f0eba1a 100644 --- a/contracts/oracle/osmosis/src/price_source.rs +++ b/contracts/oracle/osmosis/src/price_source.rs @@ -3,7 +3,8 @@ use std::{cmp::min, fmt}; use cosmwasm_std::{Addr, Decimal, Decimal256, Deps, Empty, Env, Isqrt, Uint128, Uint256}; use cw_storage_plus::Map; use mars_oracle_base::{ - ContractError::InvalidPrice, ContractResult, PriceSourceChecked, PriceSourceUnchecked, + ContractError::{self, InvalidPrice}, + ContractResult, PriceSourceChecked, PriceSourceUnchecked, }; use mars_osmosis::helpers::{ query_arithmetic_twap_price, query_geometric_twap_price, query_pool, query_spot_price, @@ -369,7 +370,7 @@ impl PriceSourceUnchecked for OsmosisPriceSour pool_id, } => { let pool = query_pool(&deps.querier, *pool_id)?; - helpers::assert_osmosis_xyk_pool(&pool)?; + helpers::assert_osmosis_xyk_lp_pool(&pool)?; Ok(OsmosisPriceSourceChecked::XykLiquidityToken { pool_id: *pool_id, }) @@ -593,6 +594,14 @@ impl OsmosisPriceSourceChecked { ) -> ContractResult { // XYK pool asserted during price source creation let pool = query_pool(&deps.querier, pool_id)?; + let pool = match pool { + Pool::Balancer(pool) => pool, + Pool::StableSwap(pool) => { + return Err(ContractError::InvalidPrice { + reason: format!("StableSwap pool not supported. Pool id {}", pool.id), + }) + } + }; let coin0 = Pool::unwrap_coin(&pool.pool_assets[0].token)?; let coin1 = Pool::unwrap_coin(&pool.pool_assets[1].token)?; diff --git a/contracts/oracle/osmosis/tests/helpers.rs b/contracts/oracle/osmosis/tests/helpers.rs index 80b683e54..82bb4ea76 100644 --- a/contracts/oracle/osmosis/tests/helpers.rs +++ b/contracts/oracle/osmosis/tests/helpers.rs @@ -9,10 +9,10 @@ use cosmwasm_std::{ }; use mars_oracle_base::ContractError; use mars_oracle_osmosis::{contract::entry, msg::ExecuteMsg, OsmosisPriceSourceUnchecked}; -use mars_osmosis::helpers::{Pool, QueryPoolResponse}; +use mars_osmosis::{BalancerPool, StableSwapPool}; use mars_red_bank_types::oracle::msg::{InstantiateMsg, QueryMsg}; use mars_testing::{mock_info, MarsMockQuerier}; -use osmosis_std::types::osmosis::gamm::v1beta1::PoolAsset; +use osmosis_std::types::osmosis::{gamm::v1beta1::PoolAsset, poolmanager::v1beta1::PoolResponse}; use pyth_sdk_cw::PriceIdentifier; pub fn setup_test_with_pools() -> OwnedDeps { @@ -22,25 +22,40 @@ pub fn setup_test_with_pools() -> OwnedDeps OwnedDeps OwnedDeps OwnedDeps OwnedDeps { deps } -pub fn prepare_query_pool_response( +pub fn prepare_query_balancer_pool_response( pool_id: u64, assets: &[Coin], weights: &[u64], shares: &Coin, -) -> QueryPoolResponse { - let pool = Pool { +) -> PoolResponse { + let pool = BalancerPool { address: "address".to_string(), - id: pool_id.to_string(), + id: pool_id, pool_params: None, future_pool_governor: "future_pool_governor".to_string(), total_shares: Some(osmosis_std::types::cosmos::base::v1beta1::Coin { @@ -131,8 +151,8 @@ pub fn prepare_query_pool_response( pool_assets: prepare_pool_assets(assets, weights), total_weight: "".to_string(), }; - QueryPoolResponse { - pool, + PoolResponse { + pool: Some(pool.to_any()), } } @@ -155,6 +175,33 @@ fn prepare_pool_assets(coins: &[Coin], weights: &[u64]) -> Vec { .collect() } +pub fn prepare_query_stable_swap_pool_response(pool_id: u64, assets: &[Coin]) -> PoolResponse { + let pool_liquidity: Vec<_> = assets + .iter() + .map(|coin| osmosis_std::types::cosmos::base::v1beta1::Coin { + denom: coin.denom.clone(), + amount: coin.amount.to_string(), + }) + .collect(); + + let pool = StableSwapPool { + address: "osmo15v4mn84s9flhzpstkf9ql2mu0rnxh42pm8zhq47kh2fzs5zlwjsqaterkr".to_string(), + id: pool_id, + pool_params: None, + future_pool_governor: "".to_string(), + total_shares: Some(osmosis_std::types::cosmos::base::v1beta1::Coin { + denom: format!("gamm/pool/{pool_id}"), + amount: 4497913440357232330148u128.to_string(), + }), + pool_liquidity, + scaling_factors: vec![100000u64, 113890u64], + scaling_factor_controller: "osmo1k8c2m5cn322akk5wy8lpt87dd2f4yh9afcd7af".to_string(), + }; + PoolResponse { + pool: Some(pool.to_any()), + } +} + pub fn set_pyth_price_source(deps: DepsMut, denom: &str, price_id: PriceIdentifier) { set_price_source( deps, diff --git a/contracts/oracle/osmosis/tests/test_query_price.rs b/contracts/oracle/osmosis/tests/test_query_price.rs index 0b330b91d..dc5a1c611 100644 --- a/contracts/oracle/osmosis/tests/test_query_price.rs +++ b/contracts/oracle/osmosis/tests/test_query_price.rs @@ -18,7 +18,7 @@ use osmosis_std::types::osmosis::{ }; use pyth_sdk_cw::{Price, PriceFeed, PriceFeedResponse, PriceIdentifier}; -use crate::helpers::prepare_query_pool_response; +use crate::helpers::prepare_query_balancer_pool_response; mod helpers; @@ -804,7 +804,7 @@ fn querying_xyk_lp_price() { let assets = vec![coin(1, "uatom"), coin(1, "uosmo")]; deps.querier.set_query_pool_response( 10001, - prepare_query_pool_response( + prepare_query_balancer_pool_response( 10001, &assets, &[5000u64, 5000u64], @@ -815,7 +815,7 @@ fn querying_xyk_lp_price() { let assets = vec![coin(1, "umars"), coin(1, "uosmo")]; deps.querier.set_query_pool_response( 10002, - prepare_query_pool_response( + prepare_query_balancer_pool_response( 10002, &assets, &[5000u64, 5000u64], @@ -826,7 +826,7 @@ fn querying_xyk_lp_price() { let assets = vec![coin(10000, "uatom"), coin(885000, "umars")]; deps.querier.set_query_pool_response( 10003, - prepare_query_pool_response( + prepare_query_balancer_pool_response( 10003, &assets, &[5000u64, 5000u64], @@ -889,7 +889,7 @@ fn querying_xyk_lp_price() { let assets = vec![coin(6389, "uatom"), coin(1385000, "umars")]; deps.querier.set_query_pool_response( 10003, - prepare_query_pool_response( + prepare_query_balancer_pool_response( 10003, &assets, &[5000u64, 5000u64], diff --git a/contracts/oracle/osmosis/tests/test_set_price_source.rs b/contracts/oracle/osmosis/tests/test_set_price_source.rs index f7f23c349..d56fa5c91 100644 --- a/contracts/oracle/osmosis/tests/test_set_price_source.rs +++ b/contracts/oracle/osmosis/tests/test_set_price_source.rs @@ -926,6 +926,15 @@ fn setting_price_source_xyk_lp() { } ); + // attempting to use StableSwap pool + let err = set_price_source_xyk_lp("atom_mars_lp", 5555).unwrap_err(); + assert_eq!( + err, + ContractError::InvalidPriceSource { + reason: "StableSwap pool not supported. Pool id 5555".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); diff --git a/contracts/rewards-collector/osmosis/tests/helpers.rs b/contracts/rewards-collector/osmosis/tests/helpers.rs index a7872d802..6760a31b3 100644 --- a/contracts/rewards-collector/osmosis/tests/helpers.rs +++ b/contracts/rewards-collector/osmosis/tests/helpers.rs @@ -5,11 +5,11 @@ use cosmwasm_std::{ testing::{mock_env, MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR}, Coin, Decimal, Deps, OwnedDeps, }; -use mars_osmosis::helpers::{Pool, QueryPoolResponse}; +use mars_osmosis::BalancerPool; use mars_red_bank_types::rewards_collector::{Config, InstantiateMsg, QueryMsg}; use mars_rewards_collector_osmosis::entry; use mars_testing::{mock_info, MarsMockQuerier}; -use osmosis_std::types::osmosis::gamm::v1beta1::PoolAsset; +use osmosis_std::types::osmosis::{gamm::v1beta1::PoolAsset, poolmanager::v1beta1::PoolResponse}; pub fn mock_instantiate_msg() -> InstantiateMsg { InstantiateMsg { @@ -93,10 +93,10 @@ fn prepare_query_pool_response( assets: &[Coin], weights: &[u64], shares: &Coin, -) -> QueryPoolResponse { - let pool = Pool { +) -> PoolResponse { + let pool = BalancerPool { address: "address".to_string(), - id: pool_id.to_string(), + id: pool_id, pool_params: None, future_pool_governor: "future_pool_governor".to_string(), total_shares: Some(osmosis_std::types::cosmos::base::v1beta1::Coin { @@ -106,8 +106,8 @@ fn prepare_query_pool_response( pool_assets: prepare_pool_assets(assets, weights), total_weight: "".to_string(), }; - QueryPoolResponse { - pool, + PoolResponse { + pool: Some(pool.to_any()), } } diff --git a/contracts/swapper/osmosis/src/route.rs b/contracts/swapper/osmosis/src/route.rs index 81486db4a..698eba5b5 100644 --- a/contracts/swapper/osmosis/src/route.rs +++ b/contracts/swapper/osmosis/src/route.rs @@ -2,7 +2,7 @@ use std::fmt; use cosmwasm_schema::cw_serde; use cosmwasm_std::{BlockInfo, CosmosMsg, Decimal, Empty, Env, Fraction, QuerierWrapper, Uint128}; -use mars_osmosis::helpers::{has_denom, query_arithmetic_twap_price, query_pool}; +use mars_osmosis::helpers::{query_arithmetic_twap_price, query_pool, CommonPoolData}; use mars_red_bank_types::swapper::EstimateExactInSwapResponse; use mars_swapper_base::{ContractError, ContractResult, Route}; use osmosis_std::types::osmosis::gamm::v1beta1::MsgSwapExactAmountIn; @@ -52,8 +52,9 @@ impl Route for OsmosisRoute { let mut seen_denoms = hashset(&[denom_in]); for (i, step) in steps.iter().enumerate() { let pool = query_pool(querier, step.pool_id)?; + let pool_denoms = pool.get_pool_denoms(); - if !has_denom(prev_denom_out, &pool.pool_assets) { + if !pool_denoms.contains(&prev_denom_out.to_string()) { return Err(ContractError::InvalidRoute { reason: format!( "step {}: pool {} does not contain input denom {}", @@ -64,7 +65,7 @@ impl Route for OsmosisRoute { }); } - if !has_denom(&step.token_out_denom, &pool.pool_assets) { + if !pool_denoms.contains(&step.token_out_denom) { return Err(ContractError::InvalidRoute { reason: format!( "step {}: pool {} does not contain output denom {}", diff --git a/packages/chains/osmosis/Cargo.toml b/packages/chains/osmosis/Cargo.toml index d2af81999..7f44f9934 100755 --- a/packages/chains/osmosis/Cargo.toml +++ b/packages/chains/osmosis/Cargo.toml @@ -21,3 +21,4 @@ backtraces = ["cosmwasm-std/backtraces"] cosmwasm-std = { workspace = true } osmosis-std = { workspace = true } serde = { workspace = true } +prost = { workspace = true } diff --git a/packages/chains/osmosis/src/helpers.rs b/packages/chains/osmosis/src/helpers.rs index 1503569fd..6cb9e204d 100644 --- a/packages/chains/osmosis/src/helpers.rs +++ b/packages/chains/osmosis/src/helpers.rs @@ -3,9 +3,6 @@ use std::str::FromStr; use cosmwasm_std::{ coin, Decimal, Empty, QuerierWrapper, QueryRequest, StdError, StdResult, Uint128, }; -/// FIXME: migrate to Spot queries from PoolManager once whitelisted in https://github.com/osmosis-labs/osmosis/blob/main/wasmbinding/stargate_whitelist.go#L127 -#[allow(deprecated)] -use osmosis_std::types::osmosis::gamm::v1beta1::QueryPoolRequest as PoolRequest; use osmosis_std::{ shim::{Duration, Timestamp}, types::{ @@ -13,26 +10,67 @@ use osmosis_std::{ osmosis::{ downtimedetector::v1beta1::DowntimedetectorQuerier, gamm::{ - v1beta1::{PoolAsset, PoolParams}, - v2::GammQuerier, + poolmodels::stableswap::v1beta1::Pool as StableSwapPool, + v1beta1::Pool as BalancerPool, }, + poolmanager::v1beta1::{PoolRequest, PoolResponse, PoolmanagerQuerier}, twap::v1beta1::TwapQuerier, }, }, }; -use serde::{Deserialize, Serialize}; - -// NOTE: Use custom Pool (`id` type as String) due to problem with json (de)serialization discrepancy between go and rust side. -// https://github.com/osmosis-labs/osmosis-rust/issues/42 -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] -pub struct Pool { - pub id: String, - pub address: String, - pub pool_params: Option, - pub future_pool_governor: String, - pub pool_assets: Vec, - pub total_shares: Option, - pub total_weight: String, +use prost::Message; + +// Get denoms from different type of the pool +pub trait CommonPoolData { + fn get_pool_id(&self) -> u64; + fn get_pool_denoms(&self) -> Vec; +} + +#[derive(Debug, PartialEq)] +pub enum Pool { + Balancer(BalancerPool), + StableSwap(StableSwapPool), +} + +impl CommonPoolData for Pool { + fn get_pool_id(&self) -> u64 { + match self { + Pool::Balancer(pool) => pool.id, + Pool::StableSwap(pool) => pool.id, + } + } + + fn get_pool_denoms(&self) -> Vec { + match self { + Pool::Balancer(pool) => pool + .pool_assets + .iter() + .flat_map(|asset| &asset.token) + .map(|token| token.denom.clone()) + .collect(), + Pool::StableSwap(pool) => { + pool.pool_liquidity.iter().map(|pl| pl.denom.clone()).collect() + } + } + } +} + +impl TryFrom for Pool { + type Error = StdError; + + fn try_from(value: osmosis_std::shim::Any) -> Result { + 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)); + } + + Err(StdError::parse_err( + "Pool", + "Unsupported pool: must be either `Balancer` or `StableSwap`.", + )) + } } impl Pool { @@ -48,39 +86,24 @@ impl Pool { } } -#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)] -pub struct QueryPoolResponse { - pub pool: Pool, -} - /// Query an Osmosis pool's coin depths and the supply of of liquidity token -/// -/// FIXME: migrate to Spot queries from PoolManager once whitelisted in https://github.com/osmosis-labs/osmosis/blob/main/wasmbinding/stargate_whitelist.go#L127 -#[allow(deprecated)] pub fn query_pool(querier: &QuerierWrapper, pool_id: u64) -> StdResult { let req: QueryRequest = PoolRequest { pool_id, } .into(); - let res: QueryPoolResponse = querier.query(&req)?; - Ok(res.pool) -} - -pub fn has_denom(denom: &str, pool_assets: &[PoolAsset]) -> bool { - pool_assets.iter().flat_map(|asset| &asset.token).any(|coin| coin.denom == denom) + let res: PoolResponse = querier.query(&req)?; + res.pool.ok_or_else(|| StdError::not_found("pool"))?.try_into() // convert `Any` to `Pool` } /// Query the spot price of a coin, denominated in OSMO -/// -/// FIXME: migrate to Spot queries from PoolManager once whitelisted in https://github.com/osmosis-labs/osmosis/blob/main/wasmbinding/stargate_whitelist.go#L127 -#[allow(deprecated)] pub fn query_spot_price( querier: &QuerierWrapper, pool_id: u64, base_denom: &str, quote_denom: &str, ) -> StdResult { - let spot_price_res = GammQuerier::new(querier).spot_price( + let spot_price_res = PoolmanagerQuerier::new(querier).spot_price( pool_id, base_denom.to_string(), quote_denom.to_string(), @@ -154,12 +177,14 @@ pub fn recovered_since_downtime_of_length( #[cfg(test)] mod tests { + use osmosis_std::types::osmosis::gamm::v1beta1::PoolAsset; + use super::*; #[test] fn unwrapping_coin() { - let pool = Pool { - id: "1111".to_string(), + let pool = BalancerPool { + id: 1111, address: "".to_string(), pool_params: None, future_pool_governor: "".to_string(), @@ -191,4 +216,67 @@ mod tests { let res = Pool::unwrap_coin(&pool.pool_assets[1].token).unwrap(); assert_eq!(res, coin(430, "denom_2")); } + + #[test] + fn common_data_for_balancer_pool() { + let balancer_pool = BalancerPool { + id: 1111, + address: "".to_string(), + pool_params: None, + future_pool_governor: "".to_string(), + pool_assets: vec![ + PoolAsset { + token: Some(Coin { + denom: "denom_1".to_string(), + amount: "123".to_string(), + }), + weight: "500".to_string(), + }, + PoolAsset { + token: Some(Coin { + denom: "denom_2".to_string(), + amount: "430".to_string(), + }), + weight: "500".to_string(), + }, + ], + total_shares: None, + total_weight: "".to_string(), + }; + + let any_pool = balancer_pool.to_any(); + let pool: Pool = any_pool.try_into().unwrap(); + + assert_eq!(balancer_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_stable_swap_pool() { + let stable_swap_pool = StableSwapPool { + address: "".to_string(), + id: 4444, + pool_params: None, + future_pool_governor: "".to_string(), + total_shares: None, + pool_liquidity: vec![ + Coin { + denom: "denom_1".to_string(), + amount: "123".to_string(), + }, + Coin { + denom: "denom_2".to_string(), + amount: "430".to_string(), + }, + ], + scaling_factors: vec![], + scaling_factor_controller: "".to_string(), + }; + + let any_pool = stable_swap_pool.to_any(); + let pool: Pool = any_pool.try_into().unwrap(); + + 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()) + } } diff --git a/packages/chains/osmosis/src/lib.rs b/packages/chains/osmosis/src/lib.rs index 1630fabcd..cfa498093 100644 --- a/packages/chains/osmosis/src/lib.rs +++ b/packages/chains/osmosis/src/lib.rs @@ -1 +1,5 @@ pub mod helpers; + +pub use osmosis_std::types::osmosis::gamm::{ + poolmodels::stableswap::v1beta1::Pool as StableSwapPool, v1beta1::Pool as BalancerPool, +}; diff --git a/packages/testing/src/mars_mock_querier.rs b/packages/testing/src/mars_mock_querier.rs index ea89017ea..a45dd6108 100644 --- a/packages/testing/src/mars_mock_querier.rs +++ b/packages/testing/src/mars_mock_querier.rs @@ -9,12 +9,11 @@ use mars_oracle_osmosis::{ stride::{Price, RedemptionRateResponse}, DowntimeDetector, }; -use mars_osmosis::helpers::QueryPoolResponse; use mars_params::types::asset::AssetParams; use mars_red_bank_types::{address_provider, incentives, oracle, red_bank}; use osmosis_std::types::osmosis::{ downtimedetector::v1beta1::RecoveredSinceDowntimeOfLengthResponse, - poolmanager::v1beta1::SpotPriceResponse, + poolmanager::v1beta1::{PoolResponse, SpotPriceResponse}, twap::v1beta1::{ArithmeticTwapToNowResponse, GeometricTwapToNowResponse}, }; use pyth_sdk_cw::{PriceFeedResponse, PriceIdentifier}; @@ -97,7 +96,7 @@ impl MarsMockQuerier { ); } - pub fn set_query_pool_response(&mut self, pool_id: u64, pool_response: QueryPoolResponse) { + pub fn set_query_pool_response(&mut self, pool_id: u64, pool_response: PoolResponse) { self.osmosis_querier.pools.insert(pool_id, pool_response); } diff --git a/packages/testing/src/osmosis_querier.rs b/packages/testing/src/osmosis_querier.rs index 539ba769a..9773e8772 100644 --- a/packages/testing/src/osmosis_querier.rs +++ b/packages/testing/src/osmosis_querier.rs @@ -1,12 +1,11 @@ use std::collections::HashMap; use cosmwasm_std::{to_binary, Binary, ContractResult, QuerierResult, SystemError}; -use mars_osmosis::helpers::QueryPoolResponse; use osmosis_std::types::osmosis::{ downtimedetector::v1beta1::{ RecoveredSinceDowntimeOfLengthRequest, RecoveredSinceDowntimeOfLengthResponse, }, - poolmanager::v1beta1::{PoolRequest, SpotPriceRequest, SpotPriceResponse}, + poolmanager::v1beta1::{PoolRequest, PoolResponse, SpotPriceRequest, SpotPriceResponse}, twap::v1beta1::{ ArithmeticTwapToNowRequest, ArithmeticTwapToNowResponse, GeometricTwapToNowRequest, GeometricTwapToNowResponse, @@ -23,7 +22,7 @@ pub struct PriceKey { #[derive(Clone, Default)] pub struct OsmosisQuerier { - pub pools: HashMap, + pub pools: HashMap, pub spot_prices: HashMap, pub arithmetic_twap_prices: HashMap, @@ -34,7 +33,7 @@ pub struct OsmosisQuerier { impl OsmosisQuerier { pub fn handle_stargate_query(&self, path: &str, data: &Binary) -> Result { - if path == "/osmosis.gamm.v1beta1.Query/Pool" { + if path == "/osmosis.poolmanager.v1beta1.Query/Pool" { let parse_osmosis_query: Result = Message::decode(data.as_slice()); if let Ok(osmosis_query) = parse_osmosis_query { @@ -42,7 +41,7 @@ impl OsmosisQuerier { } } - if path == "/osmosis.gamm.v2.Query/SpotPrice" { + if path == "/osmosis.poolmanager.v1beta1.Query/SpotPrice" { let parse_osmosis_query: Result = Message::decode(data.as_slice()); if let Ok(osmosis_query) = parse_osmosis_query {