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

feat: incentives bindings #ntrn-151 #32

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
483 changes: 357 additions & 126 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 7 additions & 13 deletions artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
3a4c512a4ca6a26f80e8d351b101103248d6ddb51caf8eb1c96db3613feedf5f client_updater-aarch64.wasm
c0190cf28da64b4058da71a9083c187d45f84ee7b9db11a0830025ecb0a687dc client_updater.wasm
ee36fe3b2c7b73bdaf00f92019adbbb7e0459cabf00b797336df16ca3cfd908d echo-aarch64.wasm
4ee0b1e8a1c39e7a440f236778e76935f29506f354b6a59712d267181da77678 echo.wasm
d72e2f3bd0e3cc7e38fe716144220e699023fd8013e52360dac2d3a01b2edad6 ibc_transfer-aarch64.wasm
ce5e308994094fbf5b339fd4ae761d9ff38db7dfa7fe17c10c86f942ec050509 ibc_transfer-x86_64.wasm
cf4b2b555032cffa472b98122dee6d6c8f53d07be31c2565d651b4941584f4f1 ibc_transfer.wasm
72274baaf57f04f86ae5af938ac30d824953a28b1f9e8956910ed50f85335641 msg_receiver-aarch64.wasm
af52c56fb25355afa04d86c7d9e867f9db9295a455fb8a89f9cfdbd6374dd1ff msg_receiver.wasm
15a5c15af41227b8861e92a89830d9c76fba368c2be252709bd9868ce5f9a171 neutron_interchain_queries-aarch64.wasm
5e10902809cdff421e1fa33aa390f085f7f378fd767c929fb30db581c6a6a4ef neutron_interchain_queries-x86_64.wasm
05e49fb2d0295c9a9e27a0077da856126f8285c2e949cb1f927f08fa8a867c8e neutron_interchain_queries.wasm
955075ca5b473e1a987d5384cd4e3d6aa730f412edc3049b6527239549319fec neutron_interchain_txs-aarch64.wasm
696362a84c5f8ef42eec10ea9ece3e77251b6de971e05aaa338ae1a1bb21f157 neutron_interchain_txs.wasm
08e912518f6f87119833a863b7562f52d043d80d78e0539c3f3cd50b1cfd4ac5 neutron_price_feed_mock-aarch64.wasm
867c5235f0dc7fa15b1e175173ffeab24776cfe2c79ff0a62962ef17b10669c8 neutron_interchain_txs-x86_64.wasm
e80d5b9b68d9a1a7d00fd8f13cf52157c8fb50989b6e28e3ea5c69211b384b06 neutron_interchain_txs.wasm
344ec19c522cc5e6135a77a181345f02a0f65ef19ad919d5236dc16f53d33e76 neutron_price_feed_mock.wasm
6e1a337b1f905cd6b4b5414beb64f67a16de525ad9618ebc5d917246dac4c131 neutron_validators_test-aarch64.wasm
2dac4d3a4bf9239291205a2d4840aac3664a24faecd143d66ad9ef690beffbd7 neutron_validators_test-x86_64.wasm
4678704ef3ffd9f1240b719991dc629623929fa75499fd6ed9f76eda4c8a556a neutron_validators_test.wasm
c68ec42808159b006580e6868a7e8de0abfaa52a9a6ebaf90c25ffbf711aee33 reflect-aarch64.wasm
68ab8e8f880300ec82912a1b686e0e0535ad06f8d5c3050bf2f815eb5fe8d4d3 reflect-x86_64.wasm
c24970beb5a08bfc73dc422e63207342343802a329f28d527b4accaaf66209f8 reflect.wasm
d18b852f6c0c57b51e577825f454e82f233b26f86d441d264654c7a58f42f5dc stargate_querier-aarch64.wasm
d2ee71886a22631993bbe9f5add6878601897e2f11a31eb7a83296c6eb57eafa stargate_querier.wasm
9bc16491e14afe7f8b0aded8aaa01bbfa0d7b05394e14b0b10ac5e361bc4fa07 tokenfactory-aarch64.wasm
d4f2b08d01566df34a150e7a48b7b143efaa2787de2a1245d7c1cb9276662fb7 stargate_querier.wasm
a9ee139212dca756adbde1e86723154b1fd79dc96cbc7e4885a851d8c978e946 tokenfactory.wasm
6 changes: 3 additions & 3 deletions artifacts/checksums_intermediate.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
b388b89207c69e9e243f5acf64b761e1cf1116adcc2d79e4eb59bf8cb6c9b99a target/wasm32-unknown-unknown/release/ibc_transfer.wasm
d89ba235e130977d1f79ac4d7f9252f6f6bed3002dfc1d08227ba138acec70b1 target/wasm32-unknown-unknown/release/client_updater.wasm
a67c60c5853497b890d67dd2bfed1caf0984a03af01ec67c877e63688970814e target/wasm32-unknown-unknown/release/echo.wasm
b388b89207c69e9e243f5acf64b761e1cf1116adcc2d79e4eb59bf8cb6c9b99a target/wasm32-unknown-unknown/release/ibc_transfer.wasm
f1ec0aa2f9c84a8b0d63d877fb6dcaf2d25c30023740f3ef53072496124c7dce target/wasm32-unknown-unknown/release/msg_receiver.wasm
b09e4f513e19e78b5ea08e10d26dc4d61056a4c6f534e783039f32494c39021b target/wasm32-unknown-unknown/release/neutron_interchain_queries.wasm
78b1e6a83b5adc768345716f9eac1bbcc1c4676046d18efaa27d8a8d6c470cb7 target/wasm32-unknown-unknown/release/neutron_interchain_txs.wasm
87924a496ac48e2581587f17a234e409f266b5deacc063a506bdeb43766e621e target/wasm32-unknown-unknown/release/neutron_interchain_txs.wasm
e947d71ddeb4f6e61d756b48981bedae6973e0b25a9d873c3bba5e9878079d8b target/wasm32-unknown-unknown/release/neutron_price_feed_mock.wasm
8893279611c69a5ca55628f0476e943ca60b8900cb0ae17fefc2f38c4e472215 target/wasm32-unknown-unknown/release/neutron_validators_test.wasm
b260fdda36208b9017f0f142821fa3bb47f3d3dea86901d687cf3d3da00946e0 target/wasm32-unknown-unknown/release/reflect.wasm
46d5d18cf293f37cca582c669de1364635e9c69eaed629f9d5dfe4b6db1b352e target/wasm32-unknown-unknown/release/stargate_querier.wasm
8b02c1c4e8536bb8a5be00b45993dd45ac9f9f996df2b66f0ca72e71d9598e69 target/wasm32-unknown-unknown/release/stargate_querier.wasm
fc80abbf059bafa21b25162af22ddb963a1ea1c6ab4dd671855adb3e1f8a8a84 target/wasm32-unknown-unknown/release/tokenfactory.wasm
Binary file modified artifacts/neutron_interchain_txs.wasm
Binary file not shown.
6 changes: 6 additions & 0 deletions contracts/before-send-hook/.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"
42 changes: 42 additions & 0 deletions contracts/before-send-hook/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[package]
name = "before-send-hook-test"
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"
serde = { version = "1.0.180", default-features = false, features = ["derive"] }
schemars = "0.8.12"
cw-storage-plus = "1.1.0"

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

This contract used for testing bank before hooks (set by tokenfactory)
29 changes: 29 additions & 0 deletions contracts/before-send-hook/examples/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 before_send_hook_test::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use std::{env::current_dir, 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!(ExecuteMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(MigrateMsg), &out_dir);
}
6 changes: 6 additions & 0 deletions contracts/before-send-hook/schema/execute_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "ExecuteMsg",
"type": "string",
"enum": []
}
5 changes: 5 additions & 0 deletions contracts/before-send-hook/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"
}
5 changes: 5 additions & 0 deletions contracts/before-send-hook/schema/migrate_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": "MigrateMsg",
"type": "object"
}
30 changes: 30 additions & 0 deletions contracts/before-send-hook/schema/query_msg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "QueryMsg",
"oneOf": [
{
"type": "object",
"required": [
"sudo_result_block_before"
],
"properties": {
"sudo_result_block_before": {
"type": "object"
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"sudo_result_track_before"
],
"properties": {
"sudo_result_track_before": {
"type": "object"
}
},
"additionalProperties": false
}
]
}
71 changes: 71 additions & 0 deletions contracts/before-send-hook/src/contract.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg, SudoMsg, SudoResResponse};
use crate::state::{SUDO_RES_BLOCK, SUDO_RES_TRACK};
use cosmwasm_std::{
entry_point, to_binary, Binary, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
};

#[entry_point]
pub fn instantiate(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: InstantiateMsg,
) -> StdResult<Response> {
SUDO_RES_TRACK.save(deps.storage, &false)?;
SUDO_RES_BLOCK.save(deps.storage, &false)?;

Ok(Response::new())
}

#[entry_point]
pub fn execute(
_deps: DepsMut,
_env: Env,
_info: MessageInfo,
_msg: ExecuteMsg,
) -> StdResult<Response> {
Ok(Response::new())
}

#[entry_point]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::SudoResultBlockBefore {} => to_binary(&query_sudo_result_block_before(deps)?),
QueryMsg::SudoResultTrackBefore {} => to_binary(&query_sudo_result_track_before(deps)?),
}
}

#[entry_point]
pub fn sudo(deps: DepsMut, _env: Env, msg: SudoMsg) -> StdResult<Response> {
match msg {
SudoMsg::TrackBeforeSend { .. } => sudo_result_track_before(deps),
SudoMsg::BlockBeforeSend { .. } => sudo_result_block_before(deps),
}
}

#[entry_point]
pub fn migrate(_deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response> {
Ok(Response::new())
}

fn query_sudo_result_block_before(deps: Deps) -> StdResult<SudoResResponse> {
let res = SUDO_RES_BLOCK.load(deps.storage)?;
let resp = SudoResResponse::Block { received: res };
Ok(resp)
}

fn query_sudo_result_track_before(deps: Deps) -> StdResult<SudoResResponse> {
let res = SUDO_RES_TRACK.load(deps.storage)?;
let resp = SudoResResponse::Track { received: res };
Ok(resp)
}

fn sudo_result_track_before(deps: DepsMut) -> StdResult<Response> {
SUDO_RES_TRACK.save(deps.storage, &true)?;
Ok(Response::new())
}

fn sudo_result_block_before(deps: DepsMut) -> StdResult<Response> {
SUDO_RES_BLOCK.save(deps.storage, &true)?;
Ok(Response::new())
}
19 changes: 19 additions & 0 deletions contracts/before-send-hook/src/lib.rs
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 state;
59 changes: 59 additions & 0 deletions contracts/before-send-hook/src/msg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
use cosmwasm_std::Coin;
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, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ExecuteMsg {}

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

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum SudoMsg {
TrackBeforeSend {
from: String,
to: String,
amount: Coin,
},
BlockBeforeSend {
from: String,
to: String,
amount: Coin,
},
}

/// Information about if the contract is currently paused.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum SudoResResponse {
Block { received: bool },
Track { received: bool },
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct TrackBeforeSendMsg {
from: String,
to: String,
amount: Coin,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub struct BlockBeforeSendMsg {
from: String,
to: String,
amount: Coin,
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct MigrateMsg {}
5 changes: 5 additions & 0 deletions contracts/before-send-hook/src/state.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use cw_storage_plus::Item;

/// contains number of transfers to addresses observed by the contract.
pub const SUDO_RES_BLOCK: Item<bool> = Item::new("sudo_res_block");
pub const SUDO_RES_TRACK: Item<bool> = Item::new("sudo_res_track");
6 changes: 6 additions & 0 deletions contracts/neutron_incentives/.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"
53 changes: 53 additions & 0 deletions contracts/neutron_incentives/Cargo.toml
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 = "b5207f78a2cdc9ed5a191e9026d8ccadc729550d" }

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 }
Loading
Loading