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

NTRN-260 slinky bindings (market map & oracle) #47

Merged
merged 22 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 20 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
185 changes: 115 additions & 70 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions contracts/before-send-hook/examples/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use before_send_hook_test::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use before_send_hook_test::msg::{InstantiateMsg, MigrateMsg, QueryMsg};
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use std::{env::current_dir, fs::create_dir_all};

Expand All @@ -23,7 +23,6 @@ fn main() {
remove_schemas(&out_dir).unwrap();

export_schema(&schema_for!(InstantiateMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(MigrateMsg), &out_dir);
}
2 changes: 1 addition & 1 deletion contracts/before-send-hook/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct InstantiateMsg {}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {}

Expand Down
6 changes: 6 additions & 0 deletions contracts/marketmap/.cargo/config
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"
43 changes: 43 additions & 0 deletions contracts/marketmap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
[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 = { git = "https://github.com/neutron-org/neutron-sdk.git", branch = "feat/slinky-bindings" }

[dev-dependencies]
cosmwasm-schema = { version = "1.3.1", default-features = false }
3 changes: 3 additions & 0 deletions contracts/marketmap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# MarketMap

This contract is used for tests in the main neutron repository.
30 changes: 30 additions & 0 deletions contracts/marketmap/examples/schema.rs
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);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"type": "string",
"enum": []
"title": "InstantiateMsg",
"type": "object"
}
43 changes: 43 additions & 0 deletions contracts/marketmap/schema/marketmap_query.json
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
}
]
}
71 changes: 71 additions & 0 deletions contracts/marketmap/src/contract.rs
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)
}
}
}
1 change: 1 addition & 0 deletions contracts/marketmap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod contract;
6 changes: 6 additions & 0 deletions contracts/oracle/.cargo/config
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"
43 changes: 43 additions & 0 deletions contracts/oracle/Cargo.toml
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 = { git = "https://github.com/neutron-org/neutron-sdk.git", branch = "feat/slinky-bindings" }

[dev-dependencies]
cosmwasm-schema = { version = "1.3.1", default-features = false }
3 changes: 3 additions & 0 deletions contracts/oracle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Oracle

This contract is used for tests in the main neutron repository.
30 changes: 30 additions & 0 deletions contracts/oracle/examples/schema.rs
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);
}
5 changes: 5 additions & 0 deletions contracts/oracle/schema/instantiate_msg.json
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"
}
Loading
Loading