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

Mock band fixes #351

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ members = [
# "contracts/snip20_staking", //TODO: migrate to v1

# Mock contracts
# "contracts/mock/mock_band", //TODO: migrate to v1
"contracts/mock/mock_band",
# "contracts/mock/mock_secretswap_pair", //TODO: migrate to v1
"contracts/mock/mock_sienna_pair",
# "contracts/mock/mock_adapter", //TODO: migrate to v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ backtraces = ["shade-protocol/backtraces"]
debug-print = ["shade-protocol/debug-print"]

[dependencies]
bincode = "1.3.1"
shade-protocol = { version = "0.1.0", path = "../../../packages/shade_protocol", features = [
"band",
"storage_plus",
] }
schemars = "0.7"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
cosmwasm-schema = "1.1.5"
Original file line number Diff line number Diff line change
@@ -1,61 +1,49 @@
use cosmwasm_schema::cw_serde;
use shade_protocol::c_std::{
to_binary,
Api,
Binary,
Env,
DepsMut,
Response,
Querier,
StdError,
StdResult,
Storage,
Deps,
shd_entry_point,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use shade_protocol::contract_interfaces::oracles::band::{InstantiateMsg, ReferenceData};
use shade_protocol::c_std::Uint128;

use shade_protocol::storage::{bucket, bucket_read, Bucket, ReadonlyBucket};
use crate::storage::PRICE;

pub static PRICE: &[u8] = b"prices";

pub fn price_r(storage: &dyn Storage) -> ReadonlyBucket<Uint128> {
bucket_read(storage, PRICE)
}

pub fn price_w(storage: &mut dyn Storage) -> Bucket<Uint128> {
bucket(storage, PRICE)
}

pub fn init(
#[shd_entry_point]
pub fn instantiate(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add #[shd_entry_point] to this, execute & query

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

_deps: DepsMut,
_env: Env,
_msg: InstantiateMsg,
) -> StdResult<Response> {
Ok(Response::default())
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
#[cw_serde]
pub enum ExecuteMsg {
MockPrice { symbol: String, price: Uint128 },
}

pub fn handle(
#[shd_entry_point]
pub fn execute(
deps: DepsMut,
_env: Env,
msg: ExecuteMsg,
) -> StdResult<Response> {
return match msg {
ExecuteMsg::MockPrice { symbol, price } => {
price_w(deps.storage).save(symbol.as_bytes(), &price)?;
PRICE.save(deps.storage, symbol, &price)?;
Ok(Response::default())
}
};
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
#[serde(rename_all = "snake_case")]
#[cw_serde]
pub enum QueryMsg {
GetReferenceData {
base_symbol: String,
Expand All @@ -66,6 +54,8 @@ pub enum QueryMsg {
quote_symbols: Vec<String>,
},
}

#[shd_entry_point]
pub fn query(
deps: Deps,
msg: QueryMsg,
Expand All @@ -75,7 +65,7 @@ pub fn query(
base_symbol,
quote_symbol: _,
} => {
if let Some(price) = price_r(deps.storage).may_load(base_symbol.as_bytes())? {
if let Some(price) = PRICE.may_load(deps.storage, base_symbol)? {
return to_binary(&ReferenceData {
rate: price,
last_updated_base: 0,
Expand All @@ -91,7 +81,7 @@ pub fn query(
let mut results = Vec::new();

for sym in base_symbols {
if let Some(price) = price_r(deps.storage).may_load(sym.as_bytes())? {
if let Some(price) = PRICE.may_load(deps.storage, sym)? {
results.push(ReferenceData {
rate: price,
last_updated_base: 0,
Expand All @@ -100,7 +90,6 @@ pub fn query(
} else {
return Err(StdError::GenericErr {
msg: "Missing Price Feed".to_string(),
backtrace: None,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod contract;
pub mod storage;
3 changes: 3 additions & 0 deletions contracts/mock/mock_band/src/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
use shade_protocol::secret_storage_plus::Map;
use shade_protocol::c_std::Uint128;
pub const PRICE: Map<String, Uint128> = Map::new("price");