Skip to content

Commit

Permalink
chore: add the config query back
Browse files Browse the repository at this point in the history
  • Loading branch information
kerber0x committed Feb 28, 2024
1 parent 847794c commit 679a59b
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 3 deletions.
13 changes: 13 additions & 0 deletions osmosis-cw-pool/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub(crate) fn swap_exact_amount_in(
token_out_denom: String,
minimum_receive: Uint128,
) -> Result<Response, ContractError> {
ensure_is_active(&deps)?;

let config = CONFIG.load(deps.storage)?;
let sender = deps.api.addr_validate(sender.as_str())?;

Expand Down Expand Up @@ -68,6 +70,8 @@ pub(crate) fn swap_exact_amount_out(
token_in_max_amount: Uint128,
token_in_denom: String,
) -> Result<Response, ContractError> {
ensure_is_active(&deps)?;

let config = CONFIG.load(deps.storage)?;
let sender = deps.api.addr_validate(sender.as_str())?;

Expand Down Expand Up @@ -180,3 +184,12 @@ fn get_paired_asset_info(

Ok(asset_info)
}

/// Asserts that the pool is active.
fn ensure_is_active(deps: &DepsMut) -> Result<(), ContractError> {
let is_active = IS_ACTIVE.load(deps.storage)?;
if !is_active {
return Err(ContractError::InactivePool);
}
Ok(())
}
1 change: 1 addition & 0 deletions osmosis-cw-pool/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
token_out,
token_in_denom,
)?)?),
QueryMsg::GetConfig {} => Ok(to_json_binary(&queries::get_config(deps)?)?),
}
}

Expand Down
3 changes: 3 additions & 0 deletions osmosis-cw-pool/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ pub enum ContractError {

#[error("Can't swap zero amount")]
ZeroAmount,

#[error("The pool is currently inactive")]
InactivePool,
}

impl From<semver::Error> for ContractError {
Expand Down
4 changes: 4 additions & 0 deletions osmosis-cw-pool/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ pub enum QueryMsg {
token_in_denom: String,
swap_fee: Decimal,
},

/// Returns the config of the contract
#[returns(Config)]
GetConfig {},
}

#[cw_serde]
Expand Down
9 changes: 7 additions & 2 deletions osmosis-cw-pool/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use white_whale_std::pool_network::pair::{
};

use crate::msg::{
CalcInAmtGivenOutResponse, CalcOutAmtGivenInResponse, GetSwapFeeResponse, IsActiveResponse,
SpotPriceResponse, TotalPoolLiquidityResponse,
CalcInAmtGivenOutResponse, CalcOutAmtGivenInResponse, Config, GetSwapFeeResponse,
IsActiveResponse, SpotPriceResponse, TotalPoolLiquidityResponse,
};
use crate::state::{CONFIG, IS_ACTIVE};

Expand Down Expand Up @@ -68,6 +68,11 @@ pub(crate) fn get_total_pool_liquidity(deps: Deps) -> StdResult<TotalPoolLiquidi
})
}

/// Queries the config of the contract
pub(crate) fn get_config(deps: Deps) -> StdResult<Config> {
CONFIG.load(deps.storage)
}

/// Queries the spot price
pub(crate) fn spot_price(
deps: Deps,
Expand Down
14 changes: 13 additions & 1 deletion osmosis-cw-pool/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use white_whale_std::pool_network::asset::{Asset, AssetInfo};
use white_whale_std::pool_network::pair::{PoolFee, PoolResponse};

use osmosis_cw_pool::msg::{
CalcInAmtGivenOutResponse, CalcOutAmtGivenInResponse, GetSwapFeeResponse,
CalcInAmtGivenOutResponse, CalcOutAmtGivenInResponse, Config, GetSwapFeeResponse,
IsActiveResponse, QueryMsg, SpotPriceResponse, TotalPoolLiquidityResponse,
};

Expand Down Expand Up @@ -607,5 +607,17 @@ fn check_queries() {
let res = result.unwrap();
assert_eq!(res, IsActiveResponse { is_active: false });
},
)
.query_osmosis_pool_interface(
QueryMsg::GetConfig {},
|result: Result<Config, RunnerError>| {
let res = result.unwrap();
assert_eq!(
res,
Config {
white_whale_pool: ww_pool.clone()
}
);
},
);
}
Binary file modified osmosis-cw-pool/tests/test_artifacts/osmosis_cw_pool.wasm
Binary file not shown.

0 comments on commit 679a59b

Please sign in to comment.