Skip to content

Commit d9abe67

Browse files
committed
add example oracle & marketmap query contracts
1 parent ab2fa67 commit d9abe67

16 files changed

Lines changed: 439 additions & 0 deletions

File tree

contracts/marketmap/.cargo/config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[alias]
2+
wasm = "build --release --target wasm32-unknown-unknown"
3+
wasm-debug = "build --target wasm32-unknown-unknown"
4+
unit-test = "test --lib --features backtraces"
5+
integration-test = "test --test integration"
6+
schema = "run --example schema"

contracts/marketmap/Cargo.toml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
[package]
2+
name = "marketmap"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
exclude = [
8+
# 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.
9+
"contract.wasm",
10+
"hash.txt",
11+
]
12+
13+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
14+
15+
[lib]
16+
crate-type = ["cdylib", "rlib"]
17+
18+
[profile.release]
19+
opt-level = 3
20+
debug = false
21+
rpath = false
22+
lto = true
23+
debug-assertions = false
24+
codegen-units = 1
25+
panic = 'abort'
26+
incremental = false
27+
overflow-checks = true
28+
29+
[features]
30+
# for quicker tests, cargo test --lib
31+
# for more explicit tests, cargo test --features=backtraces
32+
backtraces = ["cosmwasm-std/backtraces"]
33+
library = []
34+
35+
[dependencies]
36+
cosmwasm-std = "1.3.1"
37+
cw2 = "1.1.0"
38+
schemars = "0.8.10"
39+
serde = { version = "1.0.180", default-features = false, features = ["derive"] }
40+
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false }
41+
42+
43+
[dev-dependencies]
44+
cosmwasm-schema = { version = "1.3.1", default-features = false }

contracts/marketmap/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# MarketMap
2+
3+
The example contract shows how to interact with MarketMap module.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2022 Neutron
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
use std::env::current_dir;
16+
use std::fs::create_dir_all;
17+
18+
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
19+
use marketmap::contract::InstantiateMsg;
20+
use neutron_sdk::bindings::marketmap::query::MarketMapQuery;
21+
22+
fn main() {
23+
let mut out_dir = current_dir().unwrap();
24+
out_dir.push("schema");
25+
create_dir_all(&out_dir).unwrap();
26+
remove_schemas(&out_dir).unwrap();
27+
28+
export_schema(&schema_for!(InstantiateMsg), &out_dir);
29+
export_schema(&schema_for!(MarketMapQuery), &out_dir);
30+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "InstantiateMsg",
4+
"type": "object"
5+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"title": "MarketmapQuery",
4+
"oneOf": [
5+
{
6+
"description": "Parameters queries the parameters of the module.",
7+
"type": "object",
8+
"required": [
9+
"params"
10+
],
11+
"properties": {
12+
"params": {
13+
"type": "object"
14+
}
15+
},
16+
"additionalProperties": false
17+
},
18+
{
19+
"type": "object",
20+
"required": [
21+
"get_last_updated_request"
22+
],
23+
"properties": {
24+
"get_last_updated_request": {
25+
"type": "object"
26+
}
27+
},
28+
"additionalProperties": false
29+
},
30+
{
31+
"type": "object",
32+
"required": [
33+
"get_market_map_request"
34+
],
35+
"properties": {
36+
"get_market_map_request": {
37+
"type": "object"
38+
}
39+
},
40+
"additionalProperties": false
41+
}
42+
]
43+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
use cosmwasm_std::{
2+
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
3+
};
4+
use cw2::set_contract_version;
5+
use schemars::JsonSchema;
6+
use serde::{Deserialize, Serialize};
7+
8+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
9+
pub struct InstantiateMsg {}
10+
11+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
12+
#[serde(rename_all = "snake_case")]
13+
pub enum ExecuteMsg {}
14+
15+
use neutron_sdk::bindings::marketmap::query::MarketResponse;
16+
use neutron_sdk::bindings::{
17+
marketmap::query::{LastUpdatedResponse, MarketMapQuery, MarketMapResponse, ParamsResponse},
18+
msg::NeutronMsg,
19+
query::NeutronQuery,
20+
};
21+
22+
const CONTRACT_NAME: &str = concat!("crates.io:neutron-contracts__", env!("CARGO_PKG_NAME"));
23+
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
24+
25+
#[entry_point]
26+
pub fn instantiate(
27+
deps: DepsMut,
28+
_env: Env,
29+
_info: MessageInfo,
30+
_msg: InstantiateMsg,
31+
) -> StdResult<Response> {
32+
deps.api.debug("WASMDEBUG: instantiate");
33+
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
34+
Ok(Response::default())
35+
}
36+
37+
#[entry_point]
38+
pub fn execute(
39+
_deps: DepsMut,
40+
_env: Env,
41+
_info: MessageInfo,
42+
_msg: ExecuteMsg,
43+
) -> StdResult<Response<NeutronMsg>> {
44+
Ok(Default::default())
45+
}
46+
47+
#[entry_point]
48+
pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: MarketMapQuery) -> StdResult<Binary> {
49+
query_marketmap(deps, env, msg)
50+
}
51+
52+
fn query_marketmap(deps: Deps<NeutronQuery>, _env: Env, msg: MarketMapQuery) -> StdResult<Binary> {
53+
match msg {
54+
MarketMapQuery::Params { .. } => {
55+
let query_response: ParamsResponse = deps.querier.query(&msg.into())?;
56+
to_json_binary(&query_response)
57+
}
58+
MarketMapQuery::LastUpdated { .. } => {
59+
let query_response: LastUpdatedResponse = deps.querier.query(&msg.into())?;
60+
to_json_binary(&query_response)
61+
}
62+
MarketMapQuery::MarketMap { .. } => {
63+
let query_response: MarketMapResponse = deps.querier.query(&msg.into())?;
64+
to_json_binary(&query_response)
65+
}
66+
MarketMapQuery::Market { .. } => {
67+
let query_response: MarketResponse = deps.querier.query(&msg.into())?;
68+
to_json_binary(&query_response)
69+
}
70+
}
71+
}

contracts/marketmap/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod contract;

contracts/oracle/.cargo/config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[alias]
2+
wasm = "build --release --target wasm32-unknown-unknown"
3+
wasm-debug = "build --target wasm32-unknown-unknown"
4+
unit-test = "test --lib --features backtraces"
5+
integration-test = "test --test integration"
6+
schema = "run --example schema"

contracts/oracle/Cargo.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[package]
2+
name = "oracle"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
7+
exclude = [
8+
# 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.
9+
"contract.wasm",
10+
"hash.txt",
11+
]
12+
13+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
14+
15+
[lib]
16+
crate-type = ["cdylib", "rlib"]
17+
18+
[profile.release]
19+
opt-level = 3
20+
debug = false
21+
rpath = false
22+
lto = true
23+
debug-assertions = false
24+
codegen-units = 1
25+
panic = 'abort'
26+
incremental = false
27+
overflow-checks = true
28+
29+
[features]
30+
# for quicker tests, cargo test --lib
31+
# for more explicit tests, cargo test --features=backtraces
32+
backtraces = ["cosmwasm-std/backtraces"]
33+
library = []
34+
35+
[dependencies]
36+
cosmwasm-std = "1.3.1"
37+
cw2 = "1.1.0"
38+
schemars = "0.8.10"
39+
serde = { version = "1.0.180", default-features = false, features = ["derive"] }
40+
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false }
41+
42+
[dev-dependencies]
43+
cosmwasm-schema = { version = "1.3.1", default-features = false }

0 commit comments

Comments
 (0)