Skip to content

Commit

Permalink
remove bindings; remove bindings for ibc-transfer contract
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 9, 2024
1 parent 38197fb commit d963527
Show file tree
Hide file tree
Showing 33 changed files with 1,957 additions and 3,816 deletions.
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 = "4.2.2-rc"

[dev-dependencies]
cosmwasm-schema = { workspace = true }
72 changes: 38 additions & 34 deletions contracts/ibc_transfer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ use cosmwasm_std::{
StdError, StdResult, SubMsg,
};
use cw2::set_contract_version;
use neutron_std::types::neutron::transfer::MsgTransfer;
use neutron_sdk::interchain_txs::helpers::decode_message_response;
use neutron_sdk::proto_types::neutron::transfer::MsgTransferResponse;
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 neutron_std::types::cosmos::base::v1beta1::Coin as SuperCoin; // TODO: rename
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use neutron_sdk::proto_types::neutron::feerefunder::{Fee, FeerefunderQuerier};
use crate::{
msg::{ExecuteMsg, InstantiateMsg, MigrateMsg},
state::{
Expand Down Expand Up @@ -45,11 +42,11 @@ pub fn instantiate(

#[entry_point]
pub fn execute(
deps: DepsMut<NeutronQuery>,
deps: DepsMut,
env: Env,
_: MessageInfo,
msg: ExecuteMsg,
) -> NeutronResult<Response<NeutronMsg>> {
) -> 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 +97,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 +140,44 @@ 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 = min_ntrn_ibc_fee(query_min_fee(deps.as_ref())?);
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(SuperCoin{ 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_else(|| 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(SuperCoin{ 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_else(|| 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 @@ -279,17 +274,26 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response
Ok(Response::default())
}

fn min_ntrn_ibc_fee(fee: IbcFee) -> IbcFee {
IbcFee {
recv_fee: fee.recv_fee,
fn query_min_fee(deps: Deps) -> StdResult<Fee> {
let querier = FeerefunderQuerier::new(&deps.querier);
let params = querier.params()?;
let params_inner = params.params.ok_or_else(|| StdError::generic_err("no params found for feerefunder"))?;
let min_fee = params_inner.min_fee.ok_or_else(|| StdError::generic_err("no minimum fee param for feerefunder"))?;

Ok(min_fee)
}

fn min_ntrn_ibc_fee(fee: Fee) -> neutron_std::types::neutron::feerefunder::Fee {
neutron_std::types::neutron::feerefunder::Fee {
recv_fee: fee.recv_fee.iter().map(|r| SuperCoin{ denom: r.denom.to_string(), amount: r.amount.clone() } ).collect(),
ack_fee: fee
.ack_fee
.into_iter()
.iter().map(|r| SuperCoin{ denom: r.denom.to_string(), amount: r.amount.clone() } )
.filter(|a| a.denom == FEE_DENOM)
.collect(),
timeout_fee: fee
.timeout_fee
.into_iter()
.iter().map(|r| SuperCoin{ denom: r.denom.to_string(), amount: r.amount.clone() } )
.filter(|a| a.denom == FEE_DENOM)
.collect(),
}
Expand Down
2 changes: 0 additions & 2 deletions contracts/neutron_interchain_txs/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,10 @@ use neutron_sdk::proto_types::neutron::interchaintxs::v1::MsgSubmitTxResponse;
use neutron_sdk::{
bindings::{
msg::NeutronMsg,
query::{NeutronQuery, QueryInterchainAccountAddressResponse},
types::ProtobufAny,
},
interchain_txs::helpers::{decode_message_response, get_port_id},
interchain_txs::v047::helpers::decode_acknowledgement_response,
query::min_ibc_fee::query_min_ibc_fee,
sudo::msg::{RequestPacket, SudoMsg},
NeutronError, NeutronResult,
};
Expand Down
1 change: 1 addition & 0 deletions packages/neutron-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ prost-types = { workspace = true }
tendermint-proto = { workspace = true }
speedate = { workspace = true }
chrono = { version = "0.4.22", default-features = false }
neutron-std = { version = "4.2.2-rc" }
neutron-std-derive = { version = "0.20.1", path = "../neutron-std-derive" }

[dev-dependencies]
Expand Down
13 changes: 1 addition & 12 deletions packages/neutron-sdk/src/bin/neutron-sdk-schema.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,3 @@
use std::env::current_dir;
use std::fs::create_dir_all;

use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use neutron_sdk::bindings::{msg::NeutronMsg, query::NeutronQuery};

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!(NeutronMsg), &out_dir);
export_schema(&schema_for!(NeutronQuery), &out_dir);
// TODO: remove this file
}
3 changes: 0 additions & 3 deletions packages/neutron-sdk/src/bindings/dex/mod.rs

This file was deleted.

102 changes: 0 additions & 102 deletions packages/neutron-sdk/src/bindings/dex/msg.rs

This file was deleted.

Loading

0 comments on commit d963527

Please sign in to comment.