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 secretswap cosmwasm v1 #354

Open
wants to merge 1 commit 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 @@ -41,7 +41,7 @@ members = [

# Mock contracts
# "contracts/mock/mock_band", //TODO: migrate to v1
# "contracts/mock/mock_secretswap_pair", //TODO: migrate to v1
"contracts/mock/mock_secretswap_pair",
"contracts/mock/mock_sienna_pair",
# "contracts/mock/mock_adapter", //TODO: migrate to v1
"contracts/mock/mock_stkd_derivative",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,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 = [
"dex",
"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,20 +1,17 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cosmwasm_schema::cw_serde;
use shade_protocol::{
c_std::{
to_binary,
Addr,
Api,
Binary,
Deps,
DepsMut,
Env,
Querier,
Response,
StdError,
StdResult,
Storage,
Uint128,
shd_entry_point,
},
contract_interfaces::{
dex::{
Expand All @@ -29,38 +26,22 @@ use shade_protocol::{
Token,
},
},
oracles::band::{InstantiateMsg, ReferenceData},
oracles::band::InstantiateMsg,
},
utils::asset::Contract,
};

use shade_protocol::storage::{singleton, singleton_read, ReadonlySingleton, Singleton};
use crate::storage::{POOL, PAIR_INFO};

pub static PAIR_INFO: &[u8] = b"pair_info";
pub static POOL: &[u8] = b"pool";

pub fn pair_info_r(storage: &dyn Storage) -> ReadonlySingleton<PairResponse> {
singleton_read(storage, PAIR_INFO)
}

pub fn pair_info_w(storage: &mut dyn Storage) -> Singleton<PairResponse> {
singleton(storage, PAIR_INFO)
}

pub fn pool_r(storage: &dyn Storage) -> ReadonlySingleton<PoolResponse> {
singleton_read(storage, POOL)
}

pub fn pool_w(storage: &mut dyn Storage) -> Singleton<PoolResponse> {
singleton(storage, POOL)
}

pub fn init(_deps: DepsMut, _env: Env, _msg: InstantiateMsg) -> StdResult<Response> {
pub fn instantiate(
_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 {
MockPool {
token_a: Contract,
Expand All @@ -70,7 +51,8 @@ pub enum ExecuteMsg {
},
}

pub fn handle(deps: DepsMut, _env: Env, msg: ExecuteMsg) -> StdResult<Response> {
#[shd_entry_point]
pub fn execute(deps: DepsMut, _env: Env, msg: ExecuteMsg) -> StdResult<Response> {
return match msg {
ExecuteMsg::MockPool {
token_a,
Expand All @@ -94,7 +76,7 @@ pub fn handle(deps: DepsMut, _env: Env, msg: ExecuteMsg) -> StdResult<Response>
},
},
];
pool_w(deps.storage).save(&PoolResponse {
POOL.save(deps.storage, &PoolResponse {
assets: vec![
Asset {
amount: amount_a,
Expand All @@ -108,7 +90,7 @@ pub fn handle(deps: DepsMut, _env: Env, msg: ExecuteMsg) -> StdResult<Response>
total_share: Uint128::zero(),
})?;

pair_info_w(deps.storage).save(&PairResponse {
PAIR_INFO.save(deps.storage, &PairResponse {
asset_infos,
contract_addr: Addr::unchecked("".to_string()),
liquidity_token: Addr::unchecked("".to_string()),
Expand All @@ -125,12 +107,13 @@ pub fn handle(deps: DepsMut, _env: Env, msg: ExecuteMsg) -> StdResult<Response>
};
}

#[shd_entry_point]
pub fn query(deps: Deps, msg: PairQuery) -> StdResult<Binary> {
match msg {
PairQuery::Pool {} => to_binary(&pool_r(deps.storage).load()?),
PairQuery::Pair {} => to_binary(&pair_info_r(deps.storage).load()?),
PairQuery::Pool {} => to_binary(&POOL.load(deps.storage)?),
PairQuery::Pair {} => to_binary(&PAIR_INFO.load(deps.storage)?),
PairQuery::Simulation { offer_asset } => {
let pool = pool_r(deps.storage).load()?;
let pool = POOL.load(deps.storage)?;

if pool.assets[0].info == offer_asset.info {
/*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod contract;
pub mod storage;

#[cfg(target_arch = "wasm32")]
mod wasm {
Expand Down
8 changes: 8 additions & 0 deletions contracts/mock/mock_secretswap_pair/src/storage.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use shade_protocol::secret_storage_plus::Item;
use shade_protocol::contract_interfaces::dex::secretswap::{
PairResponse,
PoolResponse,
};

pub const PAIR_INFO: Item<PairResponse> = Item::new("pair_info");
pub const POOL: Item<PoolResponse> = Item::new("pool");