-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add example oracle & marketmap query contracts
- Loading branch information
1 parent
ab2fa67
commit 7a3e7c9
Showing
16 changed files
with
439 additions
and
0 deletions.
There are no files selected for viewing
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,6 @@ | ||
[alias] | ||
wasm = "build --release --target wasm32-unknown-unknown" | ||
wasm-debug = "build --target wasm32-unknown-unknown" | ||
unit-test = "test --lib --features backtraces" | ||
integration-test = "test --test integration" | ||
schema = "run --example schema" |
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,44 @@ | ||
[package] | ||
name = "marketmap" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
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"] | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
debug = false | ||
rpath = false | ||
lto = true | ||
debug-assertions = false | ||
codegen-units = 1 | ||
panic = 'abort' | ||
incremental = false | ||
overflow-checks = true | ||
|
||
[features] | ||
# for quicker tests, cargo test --lib | ||
# for more explicit tests, cargo test --features=backtraces | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
library = [] | ||
|
||
[dependencies] | ||
cosmwasm-std = "1.3.1" | ||
cw2 = "1.1.0" | ||
schemars = "0.8.10" | ||
serde = { version = "1.0.180", default-features = false, features = ["derive"] } | ||
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false } | ||
|
||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { version = "1.3.1", default-features = false } |
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,3 @@ | ||
# MarketMap | ||
|
||
The example contract shows how interact with MarketMap module. |
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,30 @@ | ||
// Copyright 2022 Neutron | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::env::current_dir; | ||
use std::fs::create_dir_all; | ||
|
||
use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; | ||
use marketmap::contract::InstantiateMsg; | ||
use neutron_sdk::bindings::marketmap::query::MarketMapQuery; | ||
|
||
fn main() { | ||
let mut out_dir = current_dir().unwrap(); | ||
out_dir.push("schema"); | ||
create_dir_all(&out_dir).unwrap(); | ||
remove_schemas(&out_dir).unwrap(); | ||
|
||
export_schema(&schema_for!(InstantiateMsg), &out_dir); | ||
export_schema(&schema_for!(MarketMapQuery), &out_dir); | ||
} |
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,5 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "InstantiateMsg", | ||
"type": "object" | ||
} |
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,43 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "MarketmapQuery", | ||
"oneOf": [ | ||
{ | ||
"description": "Parameters queries the parameters of the module.", | ||
"type": "object", | ||
"required": [ | ||
"params" | ||
], | ||
"properties": { | ||
"params": { | ||
"type": "object" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"get_last_updated_request" | ||
], | ||
"properties": { | ||
"get_last_updated_request": { | ||
"type": "object" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"get_market_map_request" | ||
], | ||
"properties": { | ||
"get_market_map_request": { | ||
"type": "object" | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
] | ||
} |
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,71 @@ | ||
use cosmwasm_std::{ | ||
entry_point, to_json_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult, | ||
}; | ||
use cw2::set_contract_version; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
pub struct InstantiateMsg {} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum ExecuteMsg {} | ||
|
||
use neutron_sdk::bindings::marketmap::query::MarketResponse; | ||
use neutron_sdk::bindings::{ | ||
marketmap::query::{LastUpdatedResponse, MarketMapQuery, MarketMapResponse, ParamsResponse}, | ||
msg::NeutronMsg, | ||
query::NeutronQuery, | ||
}; | ||
|
||
const CONTRACT_NAME: &str = concat!("crates.io:neutron-contracts__", env!("CARGO_PKG_NAME")); | ||
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
|
||
#[entry_point] | ||
pub fn instantiate( | ||
deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
_msg: InstantiateMsg, | ||
) -> StdResult<Response> { | ||
deps.api.debug("WASMDEBUG: instantiate"); | ||
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; | ||
Ok(Response::default()) | ||
} | ||
|
||
#[entry_point] | ||
pub fn execute( | ||
_deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
_msg: ExecuteMsg, | ||
) -> StdResult<Response<NeutronMsg>> { | ||
Ok(Default::default()) | ||
} | ||
|
||
#[entry_point] | ||
pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: MarketMapQuery) -> StdResult<Binary> { | ||
query_marketmap(deps, env, msg) | ||
} | ||
|
||
fn query_marketmap(deps: Deps<NeutronQuery>, _env: Env, msg: MarketMapQuery) -> StdResult<Binary> { | ||
match msg { | ||
MarketMapQuery::Params { .. } => { | ||
let query_response: ParamsResponse = deps.querier.query(&msg.into())?; | ||
to_json_binary(&query_response) | ||
} | ||
MarketMapQuery::LastUpdated { .. } => { | ||
let query_response: LastUpdatedResponse = deps.querier.query(&msg.into())?; | ||
to_json_binary(&query_response) | ||
} | ||
MarketMapQuery::MarketMap { .. } => { | ||
let query_response: MarketMapResponse = deps.querier.query(&msg.into())?; | ||
to_json_binary(&query_response) | ||
} | ||
MarketMapQuery::Market { .. } => { | ||
let query_response: MarketResponse = deps.querier.query(&msg.into())?; | ||
to_json_binary(&query_response) | ||
} | ||
} | ||
} |
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 @@ | ||
pub mod contract; |
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,6 @@ | ||
[alias] | ||
wasm = "build --release --target wasm32-unknown-unknown" | ||
wasm-debug = "build --target wasm32-unknown-unknown" | ||
unit-test = "test --lib --features backtraces" | ||
integration-test = "test --test integration" | ||
schema = "run --example schema" |
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,43 @@ | ||
[package] | ||
name = "oracle" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
|
||
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"] | ||
|
||
[profile.release] | ||
opt-level = 3 | ||
debug = false | ||
rpath = false | ||
lto = true | ||
debug-assertions = false | ||
codegen-units = 1 | ||
panic = 'abort' | ||
incremental = false | ||
overflow-checks = true | ||
|
||
[features] | ||
# for quicker tests, cargo test --lib | ||
# for more explicit tests, cargo test --features=backtraces | ||
backtraces = ["cosmwasm-std/backtraces"] | ||
library = [] | ||
|
||
[dependencies] | ||
cosmwasm-std = "1.3.1" | ||
cw2 = "1.1.0" | ||
schemars = "0.8.10" | ||
serde = { version = "1.0.180", default-features = false, features = ["derive"] } | ||
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false } | ||
|
||
[dev-dependencies] | ||
cosmwasm-schema = { version = "1.3.1", default-features = false } |
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,4 @@ | ||
# Oracle | ||
|
||
The example contract shows how to interact with Oracle module | ||
|
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,30 @@ | ||
// Copyright 2022 Neutron | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use std::env::current_dir; | ||
use std::fs::create_dir_all; | ||
|
||
use cosmwasm_schema::{export_schema, remove_schemas, schema_for}; | ||
use neutron_sdk::bindings::oracle::query::OracleQuery; | ||
use oracle::contract::InstantiateMsg; | ||
|
||
fn main() { | ||
let mut out_dir = current_dir().unwrap(); | ||
out_dir.push("schema"); | ||
create_dir_all(&out_dir).unwrap(); | ||
remove_schemas(&out_dir).unwrap(); | ||
|
||
export_schema(&schema_for!(InstantiateMsg), &out_dir); | ||
export_schema(&schema_for!(OracleQuery), &out_dir); | ||
} |
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,5 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "InstantiateMsg", | ||
"type": "object" | ||
} |
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,79 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "OracleQuery", | ||
"oneOf": [ | ||
{ | ||
"description": "Parameters queries the parameters of the module.", | ||
"type": "object", | ||
"required": [ | ||
"get_all_currency_pairs" | ||
], | ||
"properties": { | ||
"get_all_currency_pairs": { | ||
"type": "object" | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"get_price_request" | ||
], | ||
"properties": { | ||
"get_price_request": { | ||
"type": "object", | ||
"required": [ | ||
"currency_pair" | ||
], | ||
"properties": { | ||
"currency_pair": { | ||
"$ref": "#/definitions/CurrencyPair" | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
}, | ||
{ | ||
"type": "object", | ||
"required": [ | ||
"get_prices_request" | ||
], | ||
"properties": { | ||
"get_prices_request": { | ||
"type": "object", | ||
"required": [ | ||
"currency_pair_ids" | ||
], | ||
"properties": { | ||
"currency_pair_ids": { | ||
"type": "array", | ||
"items": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
], | ||
"definitions": { | ||
"CurrencyPair": { | ||
"type": "object", | ||
"required": [ | ||
"base", | ||
"quote" | ||
], | ||
"properties": { | ||
"base": { | ||
"type": "string" | ||
}, | ||
"quote": { | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.