-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from InjectiveLabs/feat/stargate-tester-contract
Feat/stargate tester contract
- Loading branch information
Showing
42 changed files
with
2,807 additions
and
122 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[package] | ||
authors = [ "Jose Luis Bernal Castillo <[email protected]>" ] | ||
edition = "2018" | ||
name = "injective-cosmwasm-stargate-example" | ||
version = "0.0.1" | ||
|
||
exclude = [ | ||
# Those files are rust-optimizer artifacts. You might want to commit them for convenience but they should not be part of the source code publication. | ||
"contract.wasm", | ||
"hash.txt", | ||
] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
crate-type = [ "cdylib", "rlib" ] | ||
|
||
[features] | ||
# use library feature to disable all instantiate/execute/query exports | ||
integration = [ ] | ||
library = [ ] | ||
|
||
[dependencies] | ||
base64 = { workspace = true } | ||
cosmos-sdk-proto = { workspace = true } | ||
cosmwasm-schema = { workspace = true } | ||
cosmwasm-std = { workspace = true } | ||
cw-storage-plus = { workspace = true } | ||
cw2 = { workspace = true } | ||
injective-cosmwasm = { path = "../../packages/injective-cosmwasm" } | ||
injective-math = { path = "../../packages/injective-math" } | ||
injective-std = { path = "../../packages/injective-std" } | ||
prost = { workspace = true } | ||
schemars = { workspace = true } | ||
serde = { workspace = true } | ||
serde_json = { workspace = true } | ||
thiserror = { workspace = true } | ||
|
||
[dev-dependencies] | ||
injective-std = { workspace = true } | ||
injective-test-tube = { workspace = true } | ||
injective-testing = { workspace = true } |
70 changes: 70 additions & 0 deletions
70
contracts/injective-cosmwasm-stargate-example/src/contract.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
use crate::{ | ||
error::ContractError, | ||
handle::{handle_test_market_spot_order, handle_test_transient_derivative_order, handle_test_transient_spot_order}, | ||
msg::{ExecuteMsg, InstantiateMsg, QueryMsg}, | ||
query::{handle_query_bank_params, handle_query_spot_market, handle_query_stargate_raw}, | ||
reply::{handle_create_derivative_order_reply_stargate, handle_create_order_reply_stargate}, | ||
}; | ||
|
||
use cosmwasm_std::{entry_point, Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdResult}; | ||
use cw2::set_contract_version; | ||
use injective_cosmwasm::{InjectiveMsgWrapper, InjectiveQueryWrapper}; | ||
|
||
const CONTRACT_NAME: &str = "crates.io:injective:dummy-stargate-contract"; | ||
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
pub const CREATE_SPOT_ORDER_REPLY_ID: u64 = 0u64; | ||
pub const CREATE_DERIVATIVE_ORDER_REPLY_ID: u64 = 1u64; | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn instantiate(deps: DepsMut, _env: Env, _info: MessageInfo, _msg: InstantiateMsg) -> Result<Response, ContractError> { | ||
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; | ||
Ok(Response::default()) | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn execute( | ||
deps: DepsMut<InjectiveQueryWrapper>, | ||
env: Env, | ||
info: MessageInfo, | ||
msg: ExecuteMsg, | ||
) -> Result<Response<InjectiveMsgWrapper>, ContractError> { | ||
match msg { | ||
ExecuteMsg::TestTraderTransientSpotOrders { | ||
market_id, | ||
subaccount_id, | ||
price, | ||
quantity, | ||
} => handle_test_transient_spot_order(deps, env, &info, market_id, subaccount_id, price, quantity), | ||
ExecuteMsg::TestMarketOrderStargate { | ||
market_id, | ||
subaccount_id, | ||
price, | ||
quantity, | ||
} => handle_test_market_spot_order(deps, env.contract.address.as_ref(), market_id, subaccount_id, price, quantity), | ||
ExecuteMsg::TestTraderTransientDerivativeOrders { | ||
market_id, | ||
subaccount_id, | ||
price, | ||
quantity, | ||
margin, | ||
} => handle_test_transient_derivative_order(deps, env, &info, market_id, subaccount_id, price, quantity, margin), | ||
} | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn query(deps: Deps<InjectiveQueryWrapper>, _env: Env, msg: QueryMsg) -> StdResult<Binary> { | ||
match msg { | ||
QueryMsg::QueryStargateRaw { path, query_request } => handle_query_stargate_raw(&deps.querier, path, query_request), | ||
QueryMsg::QueryBankParams {} => handle_query_bank_params(deps), | ||
QueryMsg::QuerySpotMarket { market_id } => handle_query_spot_market(deps, &market_id), | ||
} | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn reply(deps: DepsMut<InjectiveQueryWrapper>, _env: Env, msg: Reply) -> Result<Response, ContractError> { | ||
match msg.id { | ||
CREATE_SPOT_ORDER_REPLY_ID => handle_create_order_reply_stargate(deps, &msg), | ||
CREATE_DERIVATIVE_ORDER_REPLY_ID => handle_create_derivative_order_reply_stargate(deps, &msg), | ||
_ => Err(ContractError::UnrecognizedReply(msg.id)), | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
contracts/injective-cosmwasm-stargate-example/src/encode_helper.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
use base64::engine::general_purpose::STANDARD as BASE64_STANDARD; | ||
use base64::Engine; | ||
use prost::Message; | ||
|
||
pub fn encode_proto_message<T: Message>(msg: T) -> String { | ||
let mut buf = vec![]; | ||
T::encode(&msg, &mut buf).unwrap(); | ||
BASE64_STANDARD.encode(&buf) | ||
} |
14 changes: 14 additions & 0 deletions
14
contracts/injective-cosmwasm-stargate-example/src/error.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use cosmwasm_std::StdError; | ||
use thiserror::Error; | ||
|
||
#[derive(Error, Debug)] | ||
pub enum ContractError { | ||
#[error("{0}")] | ||
Std(#[from] StdError), | ||
#[error("Unrecognized reply id: {0}")] | ||
UnrecognizedReply(u64), | ||
#[error("Invalid reply from sub-message {id}, {err}")] | ||
ReplyParseFailure { id: u64, err: String }, | ||
#[error("Failure response from submsg: {0}")] | ||
SubMsgFailure(String), | ||
} |
Oops, something went wrong.