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

Update our tokenfactory to the latest version NTRN-93 #26

Merged
merged 17 commits into from
Sep 20, 2023
Merged
420 changes: 295 additions & 125 deletions Cargo.lock

Large diffs are not rendered by default.

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");
2 changes: 1 addition & 1 deletion contracts/tokenfactory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ library = []
cosmwasm-std = "1.3.1"
serde = { version = "1.0.180", default-features = false, features = ["derive"] }
schemars = "0.8.12"
neutron-sdk = { package = "neutron-sdk", version = "0.6.1" }
neutron-sdk = { package = "neutron-sdk", git="https://github.com/neutron-org/neutron-sdk", branch="feat/tokenfactory-update" }

[dev-dependencies]
cosmwasm-schema = { version = "1.3.1", default-features = false }
24 changes: 24 additions & 0 deletions contracts/tokenfactory/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,30 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"set_before_send_hook"
],
"properties": {
"set_before_send_hook": {
"type": "object",
"required": [
"contract_addr",
"denom"
],
"properties": {
"contract_addr": {
"type": "string"
},
"denom": {
"type": "string"
}
}
}
},
"additionalProperties": false
}
],
"definitions": {
Expand Down
20 changes: 20 additions & 0 deletions contracts/tokenfactory/schema/query_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@
}
},
"additionalProperties": false
},
{
"type": "object",
"required": [
"before_send_hook"
],
"properties": {
"before_send_hook": {
"type": "object",
"required": [
"denom"
],
"properties": {
"denom": {
"type": "string"
}
}
}
},
"additionalProperties": false
}
]
}
6 changes: 6 additions & 0 deletions contracts/tokenfactory/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use cosmwasm_std::{
coins, entry_point, to_binary, BankMsg, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo,
Response, StdResult,
};
use neutron_sdk::query::token_factory::query_before_send_hook;
use neutron_sdk::{
bindings::{msg::NeutronMsg, query::NeutronQuery},
query::token_factory::{query_denom_admin, query_full_denom},
Expand Down Expand Up @@ -38,6 +39,10 @@ pub fn execute(
ExecuteMsg::BurnTokens { denom, amount } => {
NeutronMsg::submit_burn_tokens(denom, amount).into()
}
ExecuteMsg::SetBeforeSendHook {
denom,
contract_addr,
} => NeutronMsg::submit_set_before_send_hook(denom, contract_addr).into(),
ExecuteMsg::SendTokens {
recipient,
denom,
Expand All @@ -59,6 +64,7 @@ pub fn query(deps: Deps<NeutronQuery>, _env: Env, msg: QueryMsg) -> NeutronResul
subdenom,
} => to_binary(&query_full_denom(deps, creator_addr, subdenom)?)?,
QueryMsg::DenomAdmin { subdenom } => to_binary(&query_denom_admin(deps, subdenom)?)?,
QueryMsg::BeforeSendHook { denom } => to_binary(&query_before_send_hook(deps, denom)?)?,
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved
})
}

Expand Down
Loading
Loading