diff --git a/contracts/marketmap/.cargo/config b/contracts/marketmap/.cargo/config new file mode 100644 index 00000000..7c115322 --- /dev/null +++ b/contracts/marketmap/.cargo/config @@ -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" diff --git a/contracts/marketmap/Cargo.toml b/contracts/marketmap/Cargo.toml new file mode 100644 index 00000000..1e7866b3 --- /dev/null +++ b/contracts/marketmap/Cargo.toml @@ -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 } diff --git a/contracts/marketmap/README.md b/contracts/marketmap/README.md new file mode 100644 index 00000000..40e607b0 --- /dev/null +++ b/contracts/marketmap/README.md @@ -0,0 +1,3 @@ +# MarketMap + +The example contract shows how to interact with MarketMap module. diff --git a/contracts/marketmap/examples/schema.rs b/contracts/marketmap/examples/schema.rs new file mode 100644 index 00000000..d83d7f18 --- /dev/null +++ b/contracts/marketmap/examples/schema.rs @@ -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); +} diff --git a/contracts/marketmap/schema/instantiate_msg.json b/contracts/marketmap/schema/instantiate_msg.json new file mode 100644 index 00000000..44588cf2 --- /dev/null +++ b/contracts/marketmap/schema/instantiate_msg.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object" +} diff --git a/contracts/marketmap/schema/marketmap_query.json b/contracts/marketmap/schema/marketmap_query.json new file mode 100644 index 00000000..2c57a0bb --- /dev/null +++ b/contracts/marketmap/schema/marketmap_query.json @@ -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 + } + ] +} diff --git a/contracts/marketmap/src/contract.rs b/contracts/marketmap/src/contract.rs new file mode 100644 index 00000000..85981505 --- /dev/null +++ b/contracts/marketmap/src/contract.rs @@ -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 { + 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> { + Ok(Default::default()) +} + +#[entry_point] +pub fn query(deps: Deps, env: Env, msg: MarketMapQuery) -> StdResult { + query_marketmap(deps, env, msg) +} + +fn query_marketmap(deps: Deps, _env: Env, msg: MarketMapQuery) -> StdResult { + 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) + } + } +} diff --git a/contracts/marketmap/src/lib.rs b/contracts/marketmap/src/lib.rs new file mode 100644 index 00000000..2943dbb5 --- /dev/null +++ b/contracts/marketmap/src/lib.rs @@ -0,0 +1 @@ +pub mod contract; diff --git a/contracts/oracle/.cargo/config b/contracts/oracle/.cargo/config new file mode 100644 index 00000000..7c115322 --- /dev/null +++ b/contracts/oracle/.cargo/config @@ -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" diff --git a/contracts/oracle/Cargo.toml b/contracts/oracle/Cargo.toml new file mode 100644 index 00000000..bd358d7e --- /dev/null +++ b/contracts/oracle/Cargo.toml @@ -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 } diff --git a/contracts/oracle/README.md b/contracts/oracle/README.md new file mode 100644 index 00000000..154f1e95 --- /dev/null +++ b/contracts/oracle/README.md @@ -0,0 +1,4 @@ +# Oracle + +The example contract shows how to interact with Oracle module + diff --git a/contracts/oracle/examples/schema.rs b/contracts/oracle/examples/schema.rs new file mode 100644 index 00000000..5217d6de --- /dev/null +++ b/contracts/oracle/examples/schema.rs @@ -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); +} diff --git a/contracts/oracle/schema/instantiate_msg.json b/contracts/oracle/schema/instantiate_msg.json new file mode 100644 index 00000000..44588cf2 --- /dev/null +++ b/contracts/oracle/schema/instantiate_msg.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "InstantiateMsg", + "type": "object" +} diff --git a/contracts/oracle/schema/oracle_query.json b/contracts/oracle/schema/oracle_query.json new file mode 100644 index 00000000..5bbc3bc3 --- /dev/null +++ b/contracts/oracle/schema/oracle_query.json @@ -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" + } + } + } + } +} diff --git a/contracts/oracle/src/contract.rs b/contracts/oracle/src/contract.rs new file mode 100644 index 00000000..fd78e974 --- /dev/null +++ b/contracts/oracle/src/contract.rs @@ -0,0 +1,68 @@ +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::{ + msg::NeutronMsg, + oracle::query::{ + GetAllCurrencyPairsResponse, GetPriceResponse, GetPricesResponse, OracleQuery, + }, + 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 { + 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> { + Ok(Default::default()) +} + +#[entry_point] +pub fn query(deps: Deps, env: Env, msg: OracleQuery) -> StdResult { + query_oracle(deps, env, msg) +} + +fn query_oracle(deps: Deps, _env: Env, msg: OracleQuery) -> StdResult { + match msg { + OracleQuery::GetPrice { .. } => { + let query_response: GetPriceResponse = deps.querier.query(&msg.into())?; + to_json_binary(&query_response) + } + OracleQuery::GetPrices { .. } => { + let query_response: GetPricesResponse = deps.querier.query(&msg.into())?; + to_json_binary(&query_response) + } + OracleQuery::GetAllCurrencyPairs { .. } => { + let query_response: GetAllCurrencyPairsResponse = deps.querier.query(&msg.into())?; + to_json_binary(&query_response) + } + } +} diff --git a/contracts/oracle/src/lib.rs b/contracts/oracle/src/lib.rs new file mode 100644 index 00000000..2943dbb5 --- /dev/null +++ b/contracts/oracle/src/lib.rs @@ -0,0 +1 @@ +pub mod contract;