Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCL pools migration #65

Closed
wants to merge 17 commits into from
Closed
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
238 changes: 183 additions & 55 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cosmwasm-schema = { version = "1.4.1", default-features = false }
astroport = { path = "packages/astroport", default-features = false }
astroport-periphery = { path = "packages/astroport_periphery" }
vesting-base = { path = "packages/vesting-base" }
vesting-base-lp = {path = "packages/vesting-base-lp"}
# setting cw-multi-test to 0.17.0 enables cosmwasm_1_1, we don't want that
cw-multi-test = "0.16.5"
itertools = "0.11.0"
Expand Down
30 changes: 19 additions & 11 deletions contracts/astroport/oracle/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use astroport::oracle::{Config, ExecuteMsg, InstantiateMsg, QueryMsg};
use astroport::pair::TWAP_PRECISION;
use astroport::querier::query_pair_info;
use cosmwasm_std::{
entry_point, to_binary, Binary, Decimal256, Deps, DepsMut, Env, MessageInfo, Response, Uint128,
Uint256, Uint64,
entry_point, to_json_binary, Binary, Decimal256, Deps, DepsMut, Env, MessageInfo, Response,
Uint128, Uint256, Uint64,
};
use cw2::set_contract_version;
use std::ops::Div;
Expand Down Expand Up @@ -42,10 +42,16 @@ pub fn instantiate(
Ok(Response::default())
}

/// ## Description
/// Exposes all the execute functions available in the contract.
/// ## Params
/// * **deps** is an object of type [`DepsMut`].
///
/// ## Variants
/// * **ExecuteMsg::Update {}** Updates the local TWAP values for the assets in the Astroport pool.
/// * **env** is an object of type [`Env`].
///
/// * **info** is an object of type [`MessageInfo`].
///
/// * **msg** is an object of type [`ExecuteMsg`].
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
Expand Down Expand Up @@ -174,19 +180,21 @@ pub fn update(deps: DepsMut, env: Env) -> Result<Response, ContractError> {
}

/// Exposes all the queries available in the contract.
/// ## Params
/// * **deps** is an object of type [`Deps`].
///
/// * **_env** is an object of type [`Env`].
///
/// ## Queries
/// * **QueryMsg::Consult { token, amount }** Validates assets and calculates a new average
/// amount with updated precision
/// * **msg** is an object of type [`QueryMsg`].
#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> Result<Binary, ContractError> {
match msg {
QueryMsg::Consult { token, amount } => Ok(to_binary(&consult(deps, token, amount)?)?),
QueryMsg::Consult { token, amount } => Ok(to_json_binary(&consult(deps, token, amount)?)?),
QueryMsg::TWAPAtHeight { token, height } => {
Ok(to_binary(&twap_at_height(deps, token, height)?)?)
Ok(to_json_binary(&twap_at_height(deps, token, height)?)?)
}
QueryMsg::Config {} => Ok(to_binary(&query_config(deps)?)?),
QueryMsg::LastUpdateTimestamp {} => Ok(to_binary(&query_last_update_ts(deps)?)?),
QueryMsg::Config {} => Ok(to_json_binary(&query_config(deps)?)?),
QueryMsg::LastUpdateTimestamp {} => Ok(to_json_binary(&query_last_update_ts(deps)?)?),
}
}

Expand Down
26 changes: 13 additions & 13 deletions contracts/astroport/oracle/src/mock_querier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use astroport::pair::QueryMsg::{self, CumulativePrices};
use astroport::pair::{CumulativePricesResponse, SimulationResponse};
use cosmwasm_std::testing::{MockApi, MockQuerier, MockStorage, MOCK_CONTRACT_ADDR};
use cosmwasm_std::{
from_binary, from_slice, to_binary, Addr, Coin, Empty, OwnedDeps, Querier, QuerierResult,
QueryRequest, SystemError, SystemResult, Uint128, WasmQuery,
from_json, to_json_binary, Addr, Coin, Empty, OwnedDeps, Querier, QuerierResult, QueryRequest,
SystemError, SystemResult, Uint128, WasmQuery,
};
use cw20::{BalanceResponse, Cw20QueryMsg, TokenInfoResponse};
use std::collections::HashMap;
Expand Down Expand Up @@ -82,7 +82,7 @@ pub(crate) fn balances_to_map(
impl Querier for WasmMockQuerier {
fn raw_query(&self, bin_request: &[u8]) -> QuerierResult {
// MockQuerier doesn't support Custom, so we ignore it completely here
let request: QueryRequest<Empty> = match from_slice(bin_request) {
let request: QueryRequest<Empty> = match from_json(bin_request) {
Ok(v) => v,
Err(e) => {
return SystemResult::Err(SystemError::InvalidRequest {
Expand All @@ -100,9 +100,9 @@ impl WasmMockQuerier {
match &request {
QueryRequest::Wasm(WasmQuery::Smart { contract_addr, msg }) => {
if contract_addr == "factory" {
match from_binary(msg).unwrap() {
match from_json(msg).unwrap() {
Pair { asset_infos } => SystemResult::Ok(
to_binary(&PairInfo {
to_json_binary(&PairInfo {
asset_infos,
contract_addr: Addr::unchecked("pair"),
liquidity_token: Addr::unchecked("lp_token"),
Expand All @@ -113,9 +113,9 @@ impl WasmMockQuerier {
_ => panic!("DO NOT ENTER HERE"),
}
} else if contract_addr == "astro-token" || contract_addr == "usdc-token" {
match from_binary(msg).unwrap() {
match from_json(msg).unwrap() {
Cw20QueryMsg::TokenInfo {} => SystemResult::Ok(
to_binary(&TokenInfoResponse {
to_json_binary(&TokenInfoResponse {
name: contract_addr.to_string(),
symbol: contract_addr.to_string(),
decimals: 6u8,
Expand All @@ -126,21 +126,21 @@ impl WasmMockQuerier {
_ => panic!("DO NOT ENTER HERE"),
}
} else if contract_addr == "pair" {
match from_binary(msg).unwrap() {
match from_json(msg).unwrap() {
CumulativePrices { .. } => {
let balance = match self.token_querier.pairs.get(contract_addr) {
Some(v) => v,
None => {
return SystemResult::Err(SystemError::Unknown {});
}
};
SystemResult::Ok(to_binary(&balance).into())
SystemResult::Ok(to_json_binary(&balance).into())
}
QueryMsg::Simulation {
offer_asset,
ask_asset_info: _,
} => SystemResult::Ok(
to_binary(&SimulationResponse {
to_json_binary(&SimulationResponse {
return_amount: offer_asset.amount,
spread_amount: Uint128::zero(),
commission_amount: Uint128::zero(),
Expand All @@ -150,7 +150,7 @@ impl WasmMockQuerier {
_ => panic!("DO NOT ENTER HERE"),
}
} else {
match from_binary(msg).unwrap() {
match from_json(msg).unwrap() {
Cw20QueryMsg::TokenInfo {} => {
let balances: &HashMap<String, Uint128> =
match self.token_querier.balances.get(contract_addr) {
Expand All @@ -167,7 +167,7 @@ impl WasmMockQuerier {
}

SystemResult::Ok(
to_binary(&TokenInfoResponse {
to_json_binary(&TokenInfoResponse {
name: "mAPPL".to_string(),
symbol: "mAPPL".to_string(),
decimals: 6,
Expand All @@ -193,7 +193,7 @@ impl WasmMockQuerier {
};

SystemResult::Ok(
to_binary(&BalanceResponse { balance: *balance }).into(),
to_json_binary(&BalanceResponse { balance: *balance }).into(),
)
}
_ => panic!("DO NOT ENTER HERE"),
Expand Down
14 changes: 7 additions & 7 deletions contracts/astroport/oracle/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use astroport::asset::{Asset, AssetInfo, PairInfo};
use astroport::oracle::{Config, ExecuteMsg, InstantiateMsg, QueryMsg};
use cosmwasm_std::testing::{mock_env, mock_info, MOCK_CONTRACT_ADDR};
use cosmwasm_std::{
from_binary, Addr, Decimal256, DepsMut, Env, MessageInfo, Uint128, Uint256, Uint64,
from_json, Addr, Decimal256, DepsMut, Env, MessageInfo, Uint128, Uint256, Uint64,
};
use std::ops::{Add, Mul};

Expand Down Expand Up @@ -205,7 +205,7 @@ fn cfg_and_last_update_ts() {

// make sure config query works as expected
let cfg: Config =
from_binary(&query(deps.as_ref(), env.clone(), QueryMsg::Config {}).unwrap()).unwrap();
from_json(query(deps.as_ref(), env.clone(), QueryMsg::Config {}).unwrap()).unwrap();
assert_eq!(
cfg,
Config {
Expand Down Expand Up @@ -249,7 +249,7 @@ fn cfg_and_last_update_ts() {
)
.unwrap();
let last_update_ts: u64 =
from_binary(&query(deps.as_ref(), env.clone(), QueryMsg::LastUpdateTimestamp {}).unwrap())
from_json(query(deps.as_ref(), env.clone(), QueryMsg::LastUpdateTimestamp {}).unwrap())
.unwrap();
assert_eq!(last_update_ts, first_update_ts);
env.block.time = env.block.time.plus_seconds(100);
Expand All @@ -261,7 +261,7 @@ fn cfg_and_last_update_ts() {
)
.unwrap();
let last_update_ts: u64 =
from_binary(&query(deps.as_ref(), env.clone(), QueryMsg::LastUpdateTimestamp {}).unwrap())
from_json(query(deps.as_ref(), env.clone(), QueryMsg::LastUpdateTimestamp {}).unwrap())
.unwrap();
assert_eq!(last_update_ts, first_update_ts.add(100));

Expand All @@ -274,12 +274,12 @@ fn cfg_and_last_update_ts() {
)
.unwrap();
let cfg: Config =
from_binary(&query(deps.as_ref(), env.clone(), QueryMsg::Config {}).unwrap()).unwrap();
from_json(query(deps.as_ref(), env.clone(), QueryMsg::Config {}).unwrap()).unwrap();
assert_eq!(cfg.period, 500u64);

// make sure premature update doesn't work
let last_update_ts: u64 =
from_binary(&query(deps.as_ref(), env.clone(), QueryMsg::LastUpdateTimestamp {}).unwrap())
from_json(query(deps.as_ref(), env.clone(), QueryMsg::LastUpdateTimestamp {}).unwrap())
.unwrap();
assert_eq!(last_update_ts, first_update_ts.add(100));
env.block.time = env.block.time.plus_seconds(100);
Expand All @@ -295,7 +295,7 @@ fn cfg_and_last_update_ts() {
env.block.time = env.block.time.plus_seconds(500);
execute(deps.as_mut(), env.clone(), info, ExecuteMsg::Update {}).unwrap();
let last_update_ts: u64 =
from_binary(&query(deps.as_ref(), env, QueryMsg::LastUpdateTimestamp {}).unwrap()).unwrap();
from_json(query(deps.as_ref(), env, QueryMsg::LastUpdateTimestamp {}).unwrap()).unwrap();
assert_eq!(last_update_ts, first_update_ts.add(700));
}

Expand Down
Loading
Loading