-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: incentives testing contract with bindings and queries
- Loading branch information
1 parent
e864c22
commit 0e81237
Showing
10 changed files
with
315 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,53 @@ | ||
[package] | ||
name = "neutron_incentives" | ||
version = "0.1.0" | ||
authors = ["ratik <[email protected]>"] | ||
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 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"] } | ||
serde-json-wasm = { version = "0.5.1" } | ||
cw-storage-plus = { version = "1.1.0", features = ["iterator"]} | ||
cosmos-sdk-proto = { version = "0.16.0", default-features = false } | ||
neutron-sdk = { package = "neutron-sdk",git = "https://github.com/neutron-org/neutron-sdk.git", rev = "3c1861118cdc3899bb3a6d81e7eb00163eb28b84" } | ||
|
||
base64 = "0.21.2" | ||
protobuf = { version = "3.2.0", features = ["with-bytes"] } | ||
prost = "0.11" | ||
prost-types = "0.11" | ||
bech32 = "0.9.0" | ||
thiserror = { version = "1.0" } | ||
|
||
|
||
[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,9 @@ | ||
CURRENT_DIR = $(shell pwd) | ||
CURRENT_DIR_RELATIVE = $(notdir $(shell pwd)) | ||
|
||
clippy: | ||
rustup component add clippy || true | ||
cargo clippy --all-targets --all-features --workspace -- -D warnings | ||
|
||
test: clippy | ||
cargo unit-test |
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 @@ | ||
# Neutron Incentives Contract | ||
|
||
The contract is for integration testing wasm bindings for Incentives 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 cosmwasm_schema::{export_schema, remove_schemas, schema_for}; | ||
use neutron_incentives::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; | ||
use std::env::current_dir; | ||
use std::fs::create_dir_all; | ||
|
||
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!(MigrateMsg), &out_dir); | ||
export_schema(&schema_for!(QueryMsg), &out_dir); | ||
export_schema(&schema_for!(ExecuteMsg), &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,116 @@ | ||
// 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. | ||
|
||
#[cfg(not(feature = "library"))] | ||
use cosmwasm_std::entry_point; | ||
use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError, StdResult}; | ||
use cw2::set_contract_version; | ||
|
||
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg}; | ||
use neutron_sdk::bindings::msg::NeutronMsg; | ||
use neutron_sdk::bindings::query::NeutronQuery; | ||
use neutron_sdk::NeutronResult; | ||
|
||
const CONTRACT_NAME: &str = concat!("crates.io:neutron-contracts__", env!("CARGO_PKG_NAME")); | ||
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION"); | ||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn instantiate( | ||
deps: DepsMut, | ||
_env: Env, | ||
_info: MessageInfo, | ||
_msg: InstantiateMsg, | ||
) -> NeutronResult<Response<NeutronMsg>> { | ||
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, | ||
_: MessageInfo, | ||
msg: ExecuteMsg, | ||
) -> StdResult<Response<NeutronMsg>> { | ||
deps.api | ||
.debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str()); | ||
match msg { | ||
ExecuteMsg::AddToGauge { gauge_id, rewards } => execute_add_to_gauge(deps, env, gauge_id, rewards), | ||
ExecuteMsg::Stake { coins } => execute_stake(deps, env, coins), | ||
ExecuteMsg::Unstake { unstakes } => execute_unstake(deps, env, unstakes), | ||
} | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> NeutronResult<Binary> { | ||
match msg { | ||
QueryMsg::ModuleState {} => query_module_state(deps, env), | ||
QueryMsg::GaugeByID { id } => query_gauge_by_id(deps, env, id), | ||
QueryMsg::Gauges { status, denom } => query_gauges(deps, env, status, denom), | ||
QueryMsg::StakeByID { stake_id } => query_stake_by_id(deps, env, stake_id), | ||
QueryMsg::Stakes { owner } => query_stakes(deps, env), | ||
} | ||
} | ||
|
||
fn query_module_state(deps: Deps<NeutronQuery>, env: Env) -> NeutronResult<Binary> { | ||
todo!() | ||
} | ||
|
||
fn query_gauge_by_id(deps: Deps<NeutronQuery>, env: Env, gauge_id: u64) -> NeutronResult<Binary> { | ||
todo!() | ||
} | ||
|
||
fn query_gauges(deps: Deps<NeutronQuery>, env: Env, status: String, denom: String) -> NeutronResult<Binary> { | ||
todo!() | ||
} | ||
|
||
fn query_stake_by_id(deps: Deps<NeutronQuery>, env: Env, stake_id: u64) -> NeutronResult<Binary> { | ||
todo!() | ||
} | ||
|
||
pub fn query_stakes(_deps: Deps<NeutronQuery>, _env: Env) -> NeutronResult<Binary> { | ||
// let query = NeutronQuery::InterchainAccountAddress { | ||
// owner_address: env.contract.address.to_string(), | ||
// interchain_account_id, | ||
// connection_id, | ||
// }; | ||
|
||
// Ok(to_binary(&res)?) | ||
todo!() | ||
} | ||
|
||
#[cfg_attr(not(feature = "library"), entry_point)] | ||
pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> { | ||
deps.api.debug("WASMDEBUG: migrate"); | ||
Ok(Response::default()) | ||
} | ||
|
||
fn execute_add_to_gauge(_deps: DepsMut, _env: Env, gauge_id: u64, rewards: Vec<Coin>) -> StdResult<Response<NeutronMsg>> { | ||
todo!() | ||
} | ||
fn execute_add_to_stake(_deps: DepsMut, _env: Env) -> StdResult<Response<NeutronMsg>> { | ||
todo!() | ||
} | ||
|
||
#[entry_point] | ||
pub fn reply(deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response> { | ||
deps.api | ||
.debug(format!("WASMDEBUG: reply msg: {:?}", msg).as_str()); | ||
match msg.id { | ||
_ => Err(StdError::generic_err(format!( | ||
"unsupported reply message id {}", | ||
msg.id | ||
))), | ||
} | ||
} |
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,19 @@ | ||
// 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. | ||
|
||
#![warn(clippy::unwrap_used, clippy::expect_used)] | ||
|
||
pub mod contract; | ||
pub mod msg; | ||
mod storage; |
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,37 @@ | ||
use cosmwasm_std::Coin; | ||
use neutron_sdk::bindings::msg::UnstakeDescriptor; | ||
use schemars::JsonSchema; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub struct InstantiateMsg {} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum ExecuteMsg { | ||
AddToGauge { | ||
gauge_id: u64, | ||
rewards: Vec<Coin>, | ||
}, | ||
Stake { | ||
coins: Vec<Coin>, | ||
}, | ||
Unstake { | ||
unstakes: Vec<UnstakeDescriptor> | ||
}, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub enum QueryMsg { | ||
ModuleState {}, | ||
GaugeByID { id: u64 }, | ||
Gauges { status: String, denom: String }, | ||
StakeByID { stake_id: u64 }, | ||
Stakes { owner: String }, | ||
} | ||
|
||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)] | ||
#[serde(rename_all = "snake_case")] | ||
pub struct MigrateMsg {} |
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 @@ | ||
|