Skip to content

Commit

Permalink
fix proto types
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 11, 2024
1 parent 09deffe commit fc7041b
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 99 deletions.
2 changes: 1 addition & 1 deletion contracts/ibc_transfer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +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"
neutron-std = { git = "https://github.com/neutron-org/neutron-std", rev = "cc49ece967353bcae7ad29ce04f75d2cc167b028" }

[dev-dependencies]
cosmwasm-schema = { workspace = true }
8 changes: 4 additions & 4 deletions contracts/ibc_transfer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ use cosmwasm_std::{
StdError, StdResult, SubMsg,
};
use cw2::set_contract_version;
use neutron_std::types::neutron::transfer::MsgTransfer;
use neutron_std::types::neutron::transfer::{MsgTransfer, MsgTransferResponse};
use neutron_sdk::interchain_txs::helpers::decode_message_response;
use neutron_sdk::proto_types::neutron::transfer::{MsgTransferResponse};
use neutron_sdk::{
sudo::msg::{RequestPacket, RequestPacketTimeoutHeight, TransferSudoMsg},
NeutronResult,
};
use neutron_std::types::cosmos::base::v1beta1::Coin as SuperCoin; // TODO: rename
use neutron_std::types::cosmos::base::v1beta1::Coin as SuperCoin;
use neutron_std::types::neutron::feerefunder::{Fee, FeerefunderQuerier};
// 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
2 changes: 1 addition & 1 deletion contracts/neutron_interchain_queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ serde-json-wasm = { workspace = true }
prost-types = { workspace = true }
cosmwasm-schema = { workspace = true }
# TODO: use workspace everywhere?
neutron-std = "4.2.2-rc"
neutron-std = { git = "https://github.com/neutron-org/neutron-std", rev = "cc49ece967353bcae7ad29ce04f75d2cc167b028" }

[dev-dependencies]
base64 = { workspace = true }
6 changes: 3 additions & 3 deletions contracts/neutron_interchain_queries/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ pub fn register_balances_query(
denoms: Vec<String>,
update_period: u64,
) -> NeutronResult<Response> {
let msg = new_register_balances_query_msg(contract, connection_id, addr, denoms, update_period)?;
let msg: CosmosMsg = new_register_balances_query_msg(contract, connection_id, addr, denoms, update_period)?.into();

Ok(Response::new().add_message(msg))
}
Expand Down Expand Up @@ -289,7 +289,7 @@ pub fn update_interchain_query(
new_keys: Vec<KvKey>,
new_update_period: u64,
new_recipient: Option<String>,
) -> NeutronResult<dyn Into<CosmosMsg>> {
) -> NeutronResult<Response> {
let new_filter = new_recipient.map(|recipient| {
vec![TransactionFilterItem {
field: RECIPIENT_FIELD.to_string(),
Expand All @@ -303,7 +303,7 @@ pub fn update_interchain_query(
Ok(Response::new().add_message(update_msg))
}

pub fn remove_interchain_query(contract: Addr, query_id: u64) -> NeutronResult<dyn Into<CosmosMsg>> {
pub fn remove_interchain_query(contract: Addr, query_id: u64) -> NeutronResult<Response> {
let remove_msg = helpers_remove_interchain_query(contract, query_id);
Ok(Response::new().add_message(remove_msg))
}
Expand Down
1 change: 0 additions & 1 deletion contracts/neutron_interchain_queries/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::state::Transfer;
use cosmwasm_std::Uint128;
use neutron_std::types::neutron::interchainqueries::KvKey;
use neutron_sdk::bindings::types::KVKey;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 2 additions & 0 deletions contracts/neutron_interchain_txs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ cosmos-sdk-proto = { workspace = true }
neutron-sdk = { path = "../../packages/neutron-sdk", default-features = false }
prost-types = { workspace = true }
cosmwasm-schema = { workspace = true }
# TODO: fixme
neutron-std = { git = "https://github.com/neutron-org/neutron-std", rev = "cc49ece967353bcae7ad29ce04f75d2cc167b028" }
77 changes: 43 additions & 34 deletions contracts/neutron_interchain_txs/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
use cosmos_sdk_proto::cosmos::base::v1beta1::Coin;
use cosmos_sdk_proto::cosmos::staking::v1beta1::{
MsgDelegate, MsgDelegateResponse, MsgUndelegate, MsgUndelegateResponse,
};
use cosmos_sdk_proto::traits::Message;
use cosmwasm_std::{
to_json_binary, Binary, Coin as CoinSDK, CosmosMsg, CustomQuery, Deps, DepsMut, Env,
MessageInfo, Reply, Response, StdError, StdResult, SubMsg,
};
use cw2::set_contract_version;
use neutron_std::shim::Timestamp;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

use neutron_std::types::cosmos::base::v1beta1::Coin;
use neutron_std::types::cosmos::staking::v1beta1::{MsgDelegate, MsgDelegateResponse, MsgUndelegateResponse};
use neutron_std::types::neutron::feerefunder::{Fee, FeerefunderQuerier};
use crate::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use crate::storage::{
add_error_to_queue, read_errors_from_queue, read_reply_payload, read_sudo_payload,
save_reply_payload, save_sudo_payload, AcknowledgementResult, SudoPayload,
ACKNOWLEDGEMENT_RESULTS, INTERCHAIN_ACCOUNTS, SUDO_PAYLOAD_REPLY_ID,
};
use neutron_sdk::bindings::msg::{ChannelOrdering, IbcFee};
use neutron_sdk::proto_types::neutron::interchaintxs::v1::MsgSubmitTxResponse;
use neutron_sdk::{
bindings::{
msg::NeutronMsg,
types::ProtobufAny,
},
interchain_txs::helpers::{decode_message_response, get_port_id},
interchain_txs::v047::helpers::decode_acknowledgement_response,
sudo::msg::{RequestPacket, SudoMsg},
NeutronError, NeutronResult,
};
use neutron_sdk::interchain_queries::v045::register_queries::register_interchain_account;
use neutron_std::types::neutron::interchaintxs::v1::{InterchaintxsQuerier, MsgSubmitTxResponse};

// Default timeout for SubmitTX is two weeks
const DEFAULT_TIMEOUT_SECONDS: u64 = 60 * 60 * 24 * 7 * 2;
Expand All @@ -54,19 +53,19 @@ pub fn instantiate(
_env: Env,
_info: MessageInfo,
_msg: InstantiateMsg,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response> {
deps.api.debug("WASMDEBUG: instantiate");
set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?;
Ok(Response::default())
}

#[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)]
pub fn execute(
deps: DepsMut<NeutronQuery>,
deps: DepsMut,
env: Env,
_: MessageInfo,
msg: ExecuteMsg,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<Response>{
deps.api
.debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str());
match msg {
Expand Down Expand Up @@ -117,7 +116,7 @@ pub fn execute(
}

#[cfg_attr(not(feature = "library"), cosmwasm_std::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 {
QueryMsg::InterchainAccountAddress {
interchain_account_id,
Expand All @@ -136,24 +135,24 @@ pub fn query(deps: Deps<NeutronQuery>, env: Env, msg: QueryMsg) -> NeutronResult

// returns ICA address from Neutron ICA SDK module
pub fn query_interchain_address(
deps: Deps<NeutronQuery>,
deps: Deps,
env: Env,
interchain_account_id: String,
connection_id: String,
) -> NeutronResult<Binary> {
let query = NeutronQuery::InterchainAccountAddress {
owner_address: env.contract.address.to_string(),
let querier = InterchaintxsQuerier::new(&deps.querier);
let res = querier.interchain_account_address(
env.contract.address.to_string(),
interchain_account_id,
connection_id,
};
)?;

let res: QueryInterchainAccountAddressResponse = deps.querier.query(&query.into())?;
Ok(to_json_binary(&res)?)
}

// returns ICA address from the contract storage. The address was saved in sudo_open_ack method
pub fn query_interchain_address_contract(
deps: Deps<NeutronQuery>,
deps: Deps,
env: Env,
interchain_account_id: String,
) -> NeutronResult<Binary> {
Expand All @@ -166,7 +165,7 @@ pub fn query_interchain_address_contract(

// returns the result
pub fn query_acknowledgement_result(
deps: Deps<NeutronQuery>,
deps: Deps,
env: Env,
interchain_account_id: String,
sequence_id: u64,
Expand All @@ -176,14 +175,14 @@ pub fn query_acknowledgement_result(
Ok(to_json_binary(&res)?)
}

pub fn query_errors_queue(deps: Deps<NeutronQuery>) -> NeutronResult<Binary> {
pub fn query_errors_queue(deps: Deps) -> NeutronResult<Binary> {
let res = read_errors_from_queue(deps.storage)?;
Ok(to_json_binary(&res)?)
}

// 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 All @@ -192,37 +191,38 @@ fn msg_with_sudo_callback<C: Into<CosmosMsg<T>>, T>(
}

fn execute_register_ica(
deps: DepsMut<NeutronQuery>,
deps: DepsMut,
env: Env,
connection_id: String,
interchain_account_id: String,
register_fee: Vec<CoinSDK>,
register_fee: Vec<Coin>,
ordering: Option<ChannelOrdering>,
) -> NeutronResult<Response<NeutronMsg>> {
let register = NeutronMsg::register_interchain_account(
) -> NeutronResult<Response> {
let register = register_interchain_account(
env.contract.address.clone(),
connection_id,
interchain_account_id.clone(),
Some(register_fee),
register_fee,
ordering,
);
let key = get_port_id(env.contract.address.as_str(), &interchain_account_id);
let key = get_port_id(&env.contract.address.to_string(), &interchain_account_id);
// we are saving empty data here because we handle response of registering ICA in sudo_open_ack method
INTERCHAIN_ACCOUNTS.save(deps.storage, key, &None)?;
Ok(Response::new().add_message(register))
}

fn execute_delegate(
mut deps: DepsMut<NeutronQuery>,
mut deps: DepsMut,
env: Env,
interchain_account_id: String,
validator: String,
amount: u128,
denom: String,
timeout: Option<u64>,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<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 fee = min_ntrn_ibc_fee(query_min_fee(deps.as_ref())?.min_fee);
let (delegator, connection_id) = get_ica(deps.as_ref(), &env, &interchain_account_id)?;
let delegate_msg = MsgDelegate {
delegator_address: delegator,
Expand All @@ -246,7 +246,7 @@ fn execute_delegate(
value: Binary::from(buf),
};

let cosmos_msg = NeutronMsg::submit_tx(
let cosmos_msg = submit_tx(
connection_id,
interchain_account_id.clone(),
vec![any_msg],
Expand All @@ -270,14 +270,14 @@ fn execute_delegate(
}

fn execute_undelegate(
mut deps: DepsMut<NeutronQuery>,
mut deps: DepsMut,
env: Env,
interchain_account_id: String,
validator: String,
amount: u128,
denom: String,
timeout: Option<u64>,
) -> NeutronResult<Response<NeutronMsg>> {
) -> NeutronResult<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);
Expand All @@ -304,7 +304,7 @@ fn execute_undelegate(
value: Binary::from(buf),
};

let cosmos_msg = NeutronMsg::submit_tx(
let cosmos_msg = submit_tx(
connection_id,
interchain_account_id.clone(),
vec![any_msg],
Expand Down Expand Up @@ -454,7 +454,7 @@ fn sudo_response(deps: DepsMut, request: RequestPacket, data: Binary) -> StdResu
deps.api
.debug(error_msg);
add_error_to_queue(deps.storage, error_msg.to_string());
Some(prost_types::Timestamp::default())
Some(Timestamp::default())
});
deps.api
.debug(format!("Undelegation completion time: {:?}", completion_time).as_str());
Expand Down Expand Up @@ -643,3 +643,12 @@ fn min_ntrn_ibc_fee(fee: IbcFee) -> IbcFee {
.collect(),
}
}

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)
}
2 changes: 1 addition & 1 deletion contracts/neutron_interchain_txs/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use cosmwasm_std::Coin;
use neutron_std::types::cosmos::base::v1beta1::Coin;
use neutron_sdk::bindings::msg::ChannelOrdering;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion packages/neutron-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +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 = { git = "https://github.com/neutron-org/neutron-std", rev = "cc49ece967353bcae7ad29ce04f75d2cc167b028" }
neutron-std-derive = { version = "0.20.1", path = "../neutron-std-derive" }

[dev-dependencies]
Expand Down
15 changes: 11 additions & 4 deletions packages/neutron-sdk/src/bindings/msg.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
bindings::types::{KVKey, ProtobufAny},
bindings::types::ProtobufAny,
interchain_queries::types::{QueryPayload, QueryType, TransactionFilterItem},
proto_types::neutron::cron::ExecutionStage,
sudo::msg::RequestPacketTimeoutHeight,
NeutronResult,
};
Expand All @@ -27,10 +26,18 @@ pub struct IbcFee {
}

#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum ChannelOrdering {
OrderUnordered ,
OrderOrdered,
OrderUnordered,
}

impl Into<i32> for ChannelOrdering {
fn into(self) -> i32 {
match self {
ChannelOrdering::OrderUnordered => 1,
ChannelOrdering::OrderOrdered => 2
}
}
}

#[deprecated(note = "Please use neutron-std autogenerated messages instead of wasmbindings", since = "0.12.0")]
Expand Down
9 changes: 5 additions & 4 deletions packages/neutron-sdk/src/interchain_queries/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use neutron_std::types::neutron::interchainqueries::{InterchainqueriesQuerier, R

/// Checks **actual** query type is **expected** query type
pub fn check_query_type(actual: String, expected: QueryType) -> NeutronResult<()> {
if actual != expected.to_string() {
let expected_str: String = expected.into();
if actual != expected_str {
return Err(NeutronError::InvalidQueryType {
query_type: actual.into(),
});
Expand All @@ -31,7 +32,7 @@ pub fn query_kv_result<T: KVReconstruct>(
query_id: u64,
) -> NeutronResult<T> {
let registered_query_result = get_raw_interchain_query_result(deps, query_id)?;
KVReconstruct::reconstruct(registered_query_result.clone().kv_results.into())
KVReconstruct::reconstruct(registered_query_result.kv_results.as_slice())
}

/// Queries raw interchain query result (raw KV storage values or transactions) from Interchain Queries Module.
Expand All @@ -41,10 +42,10 @@ pub fn query_kv_result<T: KVReconstruct>(
pub fn get_raw_interchain_query_result(
deps: Deps,
interchain_query_id: u64,
) -> NeutronResult<&QueryResult> {
) -> NeutronResult<QueryResult> {
let querier = InterchainqueriesQuerier::new(&deps.querier);
let query_res = querier.query_result(interchain_query_id.into())?;
let res = &query_res.result.ok_or_else(|| StdError::generic_err("no result in registered query"))?;
let res = query_res.result.ok_or_else(|| StdError::generic_err("no result in registered query"))?;

Ok(res)
}
Loading

0 comments on commit fc7041b

Please sign in to comment.