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: clean bindings #ntrn-410 #166

Merged
merged 35 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1be9ae7
remove bindings
NeverHappened Oct 10, 2024
9cc816c
remake interchain queries
NeverHappened Oct 10, 2024
f6a46d8
fix register_queries in v047
NeverHappened Oct 10, 2024
302b8b6
fix interchain_queries contracts
NeverHappened Oct 10, 2024
09deffe
remove proto_types
NeverHappened Oct 11, 2024
fc7041b
fix proto types
NeverHappened Oct 11, 2024
7bacf6a
comment tests
NeverHappened Oct 11, 2024
9791793
fix compilation for interchain_txs contract
NeverHappened Oct 11, 2024
6da2278
fix compile and warning errors
NeverHappened Oct 11, 2024
f01ca63
fix compile and warning errors
NeverHappened Oct 11, 2024
a097d93
fix clippy errors
NeverHappened Oct 11, 2024
236d124
extract interchain helpers out
NeverHappened Oct 15, 2024
716ae7c
use workspace for neutron-std
NeverHappened Oct 15, 2024
a329bd9
add submit_tx helper
NeverHappened Oct 15, 2024
bdaa2d4
cleanup return func
NeverHappened Oct 15, 2024
4841d02
fix height type
NeverHappened Oct 15, 2024
2f88f4e
remove more bindings
NeverHappened Oct 15, 2024
6c4b026
remove channelOrdering
NeverHappened Oct 15, 2024
82e4e33
move hex to helpers out of bindings
NeverHappened Oct 15, 2024
25bdfbd
kv_key_from_string
NeverHappened Oct 15, 2024
abebb3e
fix interchainqueries tests
NeverHappened Oct 16, 2024
ba8de0c
fix tests in packages
NeverHappened Oct 16, 2024
599d9ad
cargo fmt
NeverHappened Oct 16, 2024
741b978
fix make schema
NeverHappened Oct 16, 2024
08b4e76
fix build
NeverHappened Oct 16, 2024
b3095f3
fix Height deps
NeverHappened Oct 17, 2024
a50c739
fix tests
NeverHappened Oct 18, 2024
b5fa043
fmt
NeverHappened Oct 18, 2024
c0fdaa1
move sudo msg Height to proper location
NeverHappened Oct 18, 2024
bc49eae
remove neutrond_version
NeverHappened Oct 28, 2024
94567bb
remove unnecessary trim from mock_querier
NeverHappened Oct 28, 2024
7d44584
remove duplicated submit_tx; move hex functions to helpers; add and c…
NeverHappened Oct 28, 2024
67f20b6
refactor query min ibc fee helper. improve comments
NeverHappened Oct 28, 2024
4353f65
remove unnecessary TODO's
NeverHappened Oct 29, 2024
5935e3f
set std branch to main
NeverHappened Oct 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
sotnikov-s marked this conversation as resolved.
Show resolved Hide resolved

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
Loading