Skip to content

Commit

Permalink
remove bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 10, 2024
1 parent 38197fb commit 1be9ae7
Show file tree
Hide file tree
Showing 24 changed files with 59 additions and 1,568 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
30 changes: 15 additions & 15 deletions contracts/neutron_interchain_queries/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ pub fn instantiate(

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
_deps: DepsMut<NeutronQuery>,
_deps: DepsMut,
_env: Env,
_: MessageInfo,
msg: ExecuteMsg,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
match msg {
ExecuteMsg::RegisterBalancesQuery {
connection_id,
Expand Down Expand Up @@ -148,7 +148,7 @@ pub fn register_balances_query(
addr: String,
denoms: Vec<String>,
update_period: u64,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg = new_register_balances_query_msg(connection_id, addr, denoms, update_period)?;

Ok(Response::new().add_message(msg))
Expand All @@ -158,7 +158,7 @@ pub fn register_bank_total_supply_query(
connection_id: String,
denoms: Vec<String>,
update_period: u64,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg = new_register_bank_total_supply_query_msg(connection_id, denoms, update_period)?;

Ok(Response::new().add_message(msg))
Expand All @@ -167,7 +167,7 @@ pub fn register_bank_total_supply_query(
pub fn register_distribution_fee_pool_query(
connection_id: String,
update_period: u64,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg = new_register_distribution_fee_pool_query_msg(connection_id, update_period)?;

Ok(Response::new().add_message(msg))
Expand All @@ -177,7 +177,7 @@ pub fn register_gov_proposal_query(
connection_id: String,
proposals_ids: Vec<u64>,
update_period: u64,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg = new_register_gov_proposals_query_msg(connection_id, proposals_ids, update_period)?;

Ok(Response::new().add_message(msg))
Expand All @@ -187,7 +187,7 @@ pub fn register_staking_validators_query(
connection_id: String,
validators: Vec<String>,
update_period: u64,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg = new_register_staking_validators_query_msg(connection_id, validators, update_period)?;

Ok(Response::new().add_message(msg))
Expand All @@ -197,7 +197,7 @@ pub fn register_validators_signing_infos_query(
connection_id: String,
validators: Vec<String>,
update_period: u64,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg =
new_register_validators_signing_infos_query_msg(connection_id, validators, update_period)?;

Expand All @@ -209,7 +209,7 @@ pub fn register_delegations_query(
delegator: String,
validators: Vec<String>,
update_period: u64,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg = new_register_delegator_delegations_query_msg(
connection_id,
delegator,
Expand All @@ -225,7 +225,7 @@ pub fn register_unbonding_delegations_query(
delegator: String,
validators: Vec<String>,
update_period: u64,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg = new_register_delegator_unbonding_delegations_query_msg(
connection_id,
delegator,
Expand All @@ -241,7 +241,7 @@ pub fn register_transfers_query(
recipient: String,
update_period: u64,
min_height: Option<u64>,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let msg =
new_register_transfers_query_msg(connection_id, recipient, update_period, min_height)?;

Expand All @@ -253,7 +253,7 @@ pub fn register_cw20_balance_query(
update_period: u64,
cw20_contract_address: String,
account_address: String,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
// cw_storage_plus uses this prefix for maps
let mut storage_key = vec![0u8, 7u8];

Expand All @@ -275,7 +275,7 @@ pub fn update_interchain_query(
new_keys: Option<Vec<KVKey>>,
new_update_period: Option<u64>,
new_recipient: Option<String>,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
let new_filter = new_recipient.map(|recipient| {
vec![TransactionFilterItem {
field: RECIPIENT_FIELD.to_string(),
Expand All @@ -289,13 +289,13 @@ pub fn update_interchain_query(
Ok(Response::new().add_message(update_msg))
}

pub fn remove_interchain_query(query_id: u64) -> NeutronResult<Response<NeutronMsg>> {
pub fn remove_interchain_query(query_id: u64) -> NeutronResult<Response> {
let remove_msg = NeutronMsg::remove_interchain_query(query_id);
Ok(Response::new().add_message(remove_msg))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> NeutronResult<Binary> {
pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> NeutronResult<Binary> {
match msg {
//TODO: check if query.result.height is too old (for all interchain queries)
QueryMsg::Balance { query_id } => Ok(to_json_binary(&query_balance(deps, env, query_id)?)?),
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.

Loading

0 comments on commit 1be9ae7

Please sign in to comment.