Skip to content

Commit

Permalink
Merge pull request #166 from neutron-org/feat/clean-bindings
Browse files Browse the repository at this point in the history
feat: clean bindings #ntrn-410
  • Loading branch information
pr0n00gler authored Oct 31, 2024
2 parents 38197fb + 5935e3f commit b83c182
Show file tree
Hide file tree
Showing 316 changed files with 1,146 additions and 52,076 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "2"
members = ["contracts/*", "packages/*", "proto-build"]
members = ["contracts/*", "packages/*"]

[profile.release]
opt-level = 3
Expand All @@ -15,6 +15,7 @@ overflow-checks = true

[workspace.dependencies]
cosmwasm-std = "2.1.0"
neutron-std = { git = "https://github.com/neutron-org/neutron-std", branch = "main" }
cosmwasm-schema = { version = "2.1.0", default-features = false }
cw2 = "2.0.0"
cw-storage-plus = "2.0.0"
Expand Down
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ compile:

check_contracts:
@cargo install cosmwasm-check
@cosmwasm-check --available-capabilities iterator,staking,stargate,neutron artifacts/*.wasm
@cosmwasm-check --available-capabilities iterator,staking,stargate,neutron,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0 artifacts/*.wasm

build: schema clippy test fmt doc compile check_contracts

build-proto:
@cargo run --bin proto-build
1 change: 1 addition & 0 deletions contracts/ibc_transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ serde-json-wasm = { workspace = true }
cw-storage-plus = { workspace = true, features = ["iterator"]}
cosmwasm-schema = { workspace = true }
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false }
neutron-std = { workspace = true }

[dev-dependencies]
cosmwasm-schema = { workspace = true }
97 changes: 36 additions & 61 deletions contracts/ibc_transfer/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
use cosmwasm_std::{
coin, entry_point, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply, Response,
StdError, StdResult, SubMsg,
};
use cw2::set_contract_version;
use neutron_sdk::interchain_txs::helpers::decode_message_response;
use neutron_sdk::proto_types::neutron::transfer::MsgTransferResponse;
use neutron_sdk::{
bindings::{
msg::{IbcFee, NeutronMsg},
query::NeutronQuery,
},
query::min_ibc_fee::query_min_ibc_fee,
sudo::msg::{RequestPacket, RequestPacketTimeoutHeight, TransferSudoMsg},
NeutronResult,
};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use crate::{
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg},
state::{
read_reply_payload, read_sudo_payload, save_reply_payload, save_sudo_payload,
IBC_SUDO_ID_RANGE_END, IBC_SUDO_ID_RANGE_START,
},
};
use cosmwasm_std::{
entry_point, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Reply, Response, StdError,
StdResult, SubMsg,
};
use cw2::set_contract_version;
use neutron_sdk::interchain_txs::helpers::{decode_message_response, query_denom_min_ibc_fee};
use neutron_sdk::sudo::msg::{RequestPacket, TransferSudoMsg};
use neutron_std::types::cosmos::base::v1beta1::Coin as SDKCoin;
use neutron_std::types::neutron::transfer::{MsgTransfer, MsgTransferResponse};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

// Default timeout for IbcTransfer is 10000000 blocks
const DEFAULT_TIMEOUT_HEIGHT: u64 = 10000000;
Expand All @@ -44,12 +36,7 @@ pub fn instantiate(
}

#[entry_point]
pub fn execute(
deps: DepsMut<NeutronQuery>,
env: Env,
_: MessageInfo,
msg: ExecuteMsg,
) -> NeutronResult<Response<NeutronMsg>> {
pub fn execute(deps: DepsMut, env: Env, _: MessageInfo, msg: ExecuteMsg) -> StdResult<Response> {
match msg {
// NOTE: this is an example contract that shows how to make IBC transfers!
// Please add necessary authorization or other protection mechanisms
Expand Down Expand Up @@ -100,7 +87,7 @@ pub enum SudoPayload {

// saves payload to process later to the storage and returns a SubmitTX Cosmos SubMsg with necessary reply id
fn msg_with_sudo_callback<C: Into<CosmosMsg<T>>, T>(
deps: DepsMut<NeutronQuery>,
deps: DepsMut,
msg: C,
payload: SudoPayload,
) -> StdResult<SubMsg<T>> {
Expand Down Expand Up @@ -143,46 +130,50 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> StdResult<Response> {
}

fn execute_send(
mut deps: DepsMut<NeutronQuery>,
mut deps: DepsMut,
env: Env,
channel: String,
to: String,
denom: String,
amount: u128,
timeout_height: Option<u64>,
) -> NeutronResult<Response<NeutronMsg>> {
) -> StdResult<Response> {
// contract must pay for relaying of acknowledgements
// See more info here: https://docs.neutron.org/neutron/feerefunder/overview
let fee = min_ntrn_ibc_fee(query_min_ibc_fee(deps.as_ref())?.min_fee);
let coin1 = coin(amount, denom.clone());
let msg1 = NeutronMsg::IbcTransfer {
let fee = query_denom_min_ibc_fee(deps.as_ref(), FEE_DENOM)?;
let msg1 = MsgTransfer {
source_port: "transfer".to_string(),
source_channel: channel.clone(),
sender: env.contract.address.to_string(),
receiver: to.clone(),
token: coin1,
timeout_height: RequestPacketTimeoutHeight {
revision_number: Some(2),
revision_height: timeout_height.or(Some(DEFAULT_TIMEOUT_HEIGHT)),
},
token: Some(SDKCoin {
denom: denom.clone(),
amount: amount.to_string(),
}),
timeout_height: Some(neutron_std::types::ibc::core::client::v1::Height {
revision_number: 2,
revision_height: timeout_height.unwrap_or(DEFAULT_TIMEOUT_HEIGHT),
}),
timeout_timestamp: 0,
memo: "".to_string(),
fee: fee.clone(),
fee: Some(fee.clone()),
};
let coin2 = coin(2 * amount, denom);
let msg2 = NeutronMsg::IbcTransfer {
let msg2 = MsgTransfer {
source_port: "transfer".to_string(),
source_channel: channel,
sender: env.contract.address.to_string(),
receiver: to,
token: coin2,
timeout_height: RequestPacketTimeoutHeight {
revision_number: Some(2),
revision_height: timeout_height.or(Some(DEFAULT_TIMEOUT_HEIGHT)),
},
token: Some(SDKCoin {
denom,
amount: (2 * amount).to_string(),
}),
timeout_height: Some(neutron_std::types::ibc::core::client::v1::Height {
revision_number: 2,
revision_height: timeout_height.unwrap_or(DEFAULT_TIMEOUT_HEIGHT),
}),
timeout_timestamp: 0,
memo: "".to_string(),
fee,
fee: Some(fee.clone()),
};
// prepare first transfer message with payload of Type1
let submsg1 = msg_with_sudo_callback(
Expand Down Expand Up @@ -278,19 +269,3 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response
deps.api.debug("WASMDEBUG: migrate");
Ok(Response::default())
}

fn min_ntrn_ibc_fee(fee: IbcFee) -> IbcFee {
IbcFee {
recv_fee: fee.recv_fee,
ack_fee: fee
.ack_fee
.into_iter()
.filter(|a| a.denom == FEE_DENOM)
.collect(),
timeout_fee: fee
.timeout_fee
.into_iter()
.filter(|a| a.denom == FEE_DENOM)
.collect(),
}
}
2 changes: 2 additions & 0 deletions contracts/neutron_interchain_queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ cw-storage-plus = { workspace = true }
serde-json-wasm = { workspace = true }
prost-types = { workspace = true }
cosmwasm-schema = { workspace = true }
neutron-std = { workspace = true }
prost = { workspace = true }

[dev-dependencies]
base64 = { workspace = true }
36 changes: 14 additions & 22 deletions contracts/neutron_interchain_queries/schema/execute_msg.json
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,15 @@
"update_interchain_query": {
"type": "object",
"required": [
"new_keys",
"new_update_period",
"query_id"
],
"properties": {
"new_keys": {
"type": [
"array",
"null"
],
"type": "array",
"items": {
"$ref": "#/definitions/KVKey"
"$ref": "#/definitions/KvKey"
}
},
"new_recipient": {
Expand All @@ -383,10 +382,7 @@
]
},
"new_update_period": {
"type": [
"integer",
"null"
],
"type": "integer",
"format": "uint64",
"minimum": 0.0
},
Expand Down Expand Up @@ -426,28 +422,24 @@
}
],
"definitions": {
"Binary": {
"description": "Binary is a wrapper around Vec<u8> to add base64 de/serialization with serde. It also adds some helper methods to help encode inline.\n\nThis is only needed as serde-json-{core,wasm} has a horrible encoding for Vec<u8>. See also <https://github.com/CosmWasm/cosmwasm/blob/main/docs/MESSAGE_TYPES.md>.",
"type": "string"
},
"KVKey": {
"description": "Describes a KV key for which you want to get value from the storage on remote chain",
"KvKey": {
"type": "object",
"required": [
"key",
"path"
],
"properties": {
"key": {
"description": "*key** is a key you want to read from the storage",
"allOf": [
{
"$ref": "#/definitions/Binary"
}
]
"description": "Key you want to read from the storage",
"type": "array",
"items": {
"type": "integer",
"format": "uint8",
"minimum": 0.0
}
},
"path": {
"description": "*path** is a path to the storage (storage prefix) where you want to read value by key (usually name of cosmos-packages module: 'staking', 'bank', etc.)",
"description": "Path (storage prefix) to the storage where you want to read value by key (usually name of cosmos-sdk module: 'staking', 'bank', etc.)",
"type": "string"
}
},
Expand Down
Loading

0 comments on commit b83c182

Please sign in to comment.