From fc7041b0af341058c3cfd7dafda6ae6b077a9aa4 Mon Sep 17 00:00:00 2001 From: nhpd Date: Fri, 11 Oct 2024 18:03:02 +0400 Subject: [PATCH] fix proto types --- contracts/ibc_transfer/Cargo.toml | 2 +- contracts/ibc_transfer/src/contract.rs | 8 +- .../neutron_interchain_queries/Cargo.toml | 2 +- .../src/contract.rs | 6 +- .../neutron_interchain_queries/src/msg.rs | 1 - contracts/neutron_interchain_txs/Cargo.toml | 2 + .../neutron_interchain_txs/src/contract.rs | 77 +++++++++++-------- contracts/neutron_interchain_txs/src/msg.rs | 2 +- packages/neutron-sdk/Cargo.toml | 2 +- packages/neutron-sdk/src/bindings/msg.rs | 15 +++- .../src/interchain_queries/queries.rs | 9 ++- .../src/interchain_queries/types.rs | 4 +- .../src/interchain_queries/v045/helpers.rs | 6 +- .../v045/register_queries.rs | 64 +++++++++------ .../src/interchain_queries/v045/types.rs | 3 +- .../v047/register_queries.rs | 14 ++-- .../src/interchain_queries/v047/types.rs | 3 +- packages/neutron-sdk/src/lib.rs | 6 +- 18 files changed, 127 insertions(+), 99 deletions(-) diff --git a/contracts/ibc_transfer/Cargo.toml b/contracts/ibc_transfer/Cargo.toml index c253a0d7..d75daf42 100644 --- a/contracts/ibc_transfer/Cargo.toml +++ b/contracts/ibc_transfer/Cargo.toml @@ -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 } diff --git a/contracts/ibc_transfer/src/contract.rs b/contracts/ibc_transfer/src/contract.rs index 187c06c6..e470711a 100644 --- a/contracts/ibc_transfer/src/contract.rs +++ b/contracts/ibc_transfer/src/contract.rs @@ -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::{ diff --git a/contracts/neutron_interchain_queries/Cargo.toml b/contracts/neutron_interchain_queries/Cargo.toml index 5fed4a16..25d9fd5b 100644 --- a/contracts/neutron_interchain_queries/Cargo.toml +++ b/contracts/neutron_interchain_queries/Cargo.toml @@ -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 } diff --git a/contracts/neutron_interchain_queries/src/contract.rs b/contracts/neutron_interchain_queries/src/contract.rs index 6ed83501..98513f23 100644 --- a/contracts/neutron_interchain_queries/src/contract.rs +++ b/contracts/neutron_interchain_queries/src/contract.rs @@ -150,7 +150,7 @@ pub fn register_balances_query( denoms: Vec, update_period: u64, ) -> NeutronResult { - 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)) } @@ -289,7 +289,7 @@ pub fn update_interchain_query( new_keys: Vec, new_update_period: u64, new_recipient: Option, -) -> NeutronResult> { +) -> NeutronResult { let new_filter = new_recipient.map(|recipient| { vec![TransactionFilterItem { field: RECIPIENT_FIELD.to_string(), @@ -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> { +pub fn remove_interchain_query(contract: Addr, query_id: u64) -> NeutronResult { let remove_msg = helpers_remove_interchain_query(contract, query_id); Ok(Response::new().add_message(remove_msg)) } diff --git a/contracts/neutron_interchain_queries/src/msg.rs b/contracts/neutron_interchain_queries/src/msg.rs index 86eb7041..e3e910bf 100644 --- a/contracts/neutron_interchain_queries/src/msg.rs +++ b/contracts/neutron_interchain_queries/src/msg.rs @@ -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}; diff --git a/contracts/neutron_interchain_txs/Cargo.toml b/contracts/neutron_interchain_txs/Cargo.toml index 9c320018..54c4358f 100644 --- a/contracts/neutron_interchain_txs/Cargo.toml +++ b/contracts/neutron_interchain_txs/Cargo.toml @@ -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" } diff --git a/contracts/neutron_interchain_txs/src/contract.rs b/contracts/neutron_interchain_txs/src/contract.rs index cddab948..12a850fe 100644 --- a/contracts/neutron_interchain_txs/src/contract.rs +++ b/contracts/neutron_interchain_txs/src/contract.rs @@ -1,16 +1,15 @@ -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, @@ -18,10 +17,8 @@ use crate::storage::{ 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}, @@ -29,6 +26,8 @@ use neutron_sdk::{ 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; @@ -54,7 +53,7 @@ pub fn instantiate( _env: Env, _info: MessageInfo, _msg: InstantiateMsg, -) -> NeutronResult> { +) -> NeutronResult { deps.api.debug("WASMDEBUG: instantiate"); set_contract_version(deps.storage, CONTRACT_NAME, CONTRACT_VERSION)?; Ok(Response::default()) @@ -62,11 +61,11 @@ pub fn instantiate( #[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)] pub fn execute( - deps: DepsMut, + deps: DepsMut, env: Env, _: MessageInfo, msg: ExecuteMsg, -) -> NeutronResult> { +) -> NeutronResult{ deps.api .debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str()); match msg { @@ -117,7 +116,7 @@ pub fn execute( } #[cfg_attr(not(feature = "library"), cosmwasm_std::entry_point)] -pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> NeutronResult { +pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> NeutronResult { match msg { QueryMsg::InterchainAccountAddress { interchain_account_id, @@ -136,24 +135,24 @@ pub fn query(deps: Deps, env: Env, msg: QueryMsg) -> NeutronResult // returns ICA address from Neutron ICA SDK module pub fn query_interchain_address( - deps: Deps, + deps: Deps, env: Env, interchain_account_id: String, connection_id: String, ) -> NeutronResult { - 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, + deps: Deps, env: Env, interchain_account_id: String, ) -> NeutronResult { @@ -166,7 +165,7 @@ pub fn query_interchain_address_contract( // returns the result pub fn query_acknowledgement_result( - deps: Deps, + deps: Deps, env: Env, interchain_account_id: String, sequence_id: u64, @@ -176,14 +175,14 @@ pub fn query_acknowledgement_result( Ok(to_json_binary(&res)?) } -pub fn query_errors_queue(deps: Deps) -> NeutronResult { +pub fn query_errors_queue(deps: Deps) -> NeutronResult { 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>, T>( - deps: DepsMut, + deps: DepsMut, msg: C, payload: SudoPayload, ) -> StdResult> { @@ -192,37 +191,38 @@ fn msg_with_sudo_callback>, T>( } fn execute_register_ica( - deps: DepsMut, + deps: DepsMut, env: Env, connection_id: String, interchain_account_id: String, - register_fee: Vec, + register_fee: Vec, ordering: Option, -) -> NeutronResult> { - let register = NeutronMsg::register_interchain_account( +) -> NeutronResult { + 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, + mut deps: DepsMut, env: Env, interchain_account_id: String, validator: String, amount: u128, denom: String, timeout: Option, -) -> NeutronResult> { +) -> NeutronResult { // 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, @@ -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], @@ -270,14 +270,14 @@ fn execute_delegate( } fn execute_undelegate( - mut deps: DepsMut, + mut deps: DepsMut, env: Env, interchain_account_id: String, validator: String, amount: u128, denom: String, timeout: Option, -) -> NeutronResult> { +) -> NeutronResult { // 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); @@ -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], @@ -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()); @@ -643,3 +643,12 @@ fn min_ntrn_ibc_fee(fee: IbcFee) -> IbcFee { .collect(), } } + +fn query_min_fee(deps: Deps) -> StdResult { + 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) +} \ No newline at end of file diff --git a/contracts/neutron_interchain_txs/src/msg.rs b/contracts/neutron_interchain_txs/src/msg.rs index d4f44823..d27ca561 100644 --- a/contracts/neutron_interchain_txs/src/msg.rs +++ b/contracts/neutron_interchain_txs/src/msg.rs @@ -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}; diff --git a/packages/neutron-sdk/Cargo.toml b/packages/neutron-sdk/Cargo.toml index 5d710d23..62ff3095 100644 --- a/packages/neutron-sdk/Cargo.toml +++ b/packages/neutron-sdk/Cargo.toml @@ -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] diff --git a/packages/neutron-sdk/src/bindings/msg.rs b/packages/neutron-sdk/src/bindings/msg.rs index a8292044..ddec2207 100644 --- a/packages/neutron-sdk/src/bindings/msg.rs +++ b/packages/neutron-sdk/src/bindings/msg.rs @@ -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, }; @@ -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 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")] diff --git a/packages/neutron-sdk/src/interchain_queries/queries.rs b/packages/neutron-sdk/src/interchain_queries/queries.rs index 12843210..fdde90e7 100644 --- a/packages/neutron-sdk/src/interchain_queries/queries.rs +++ b/packages/neutron-sdk/src/interchain_queries/queries.rs @@ -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(), }); @@ -31,7 +32,7 @@ pub fn query_kv_result( query_id: u64, ) -> NeutronResult { 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. @@ -41,10 +42,10 @@ pub fn query_kv_result( pub fn get_raw_interchain_query_result( deps: Deps, interchain_query_id: u64, -) -> NeutronResult<&QueryResult> { +) -> NeutronResult { 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) } diff --git a/packages/neutron-sdk/src/interchain_queries/types.rs b/packages/neutron-sdk/src/interchain_queries/types.rs index 5e854d82..ddc53a78 100644 --- a/packages/neutron-sdk/src/interchain_queries/types.rs +++ b/packages/neutron-sdk/src/interchain_queries/types.rs @@ -1,9 +1,9 @@ use crate::{ - bindings::types::{StorageValue}, + // bindings::types::{StorageValue}, errors::error::NeutronResult, }; use cosmwasm_std::{from_json, StdError, Uint128}; -use neutron_std::types::neutron::interchainqueries::KvKey; +use neutron_std::types::neutron::interchainqueries::{KvKey, StorageValue}; use schemars::{JsonSchema, _serde_json::Value}; use serde::{Deserialize, Deserializer, Serialize, Serializer}; diff --git a/packages/neutron-sdk/src/interchain_queries/v045/helpers.rs b/packages/neutron-sdk/src/interchain_queries/v045/helpers.rs index e4c8cc92..e9b33560 100644 --- a/packages/neutron-sdk/src/interchain_queries/v045/helpers.rs +++ b/packages/neutron-sdk/src/interchain_queries/v045/helpers.rs @@ -324,7 +324,7 @@ pub fn get_update_time(commission: &Option) -> Option } /// Returns denom for total supply from StorageValue key -pub fn get_total_supply_denom(denom: &Binary) -> Option { +pub fn get_total_supply_denom(denom: &Vec) -> Option { if denom.len() < 2 { return None; } @@ -337,6 +337,6 @@ pub fn get_total_supply_denom(denom: &Binary) -> Option { } /// Returns total supply amount from StorageValue key -pub fn get_total_supply_amount(amount: &Binary) -> Option { - from_utf8(amount).ok().map(|a| Uint128::from_str(a).ok())? +pub fn get_total_supply_amount(amount: &Vec) -> Option { + from_utf8(amount.as_slice()).ok().map(|a| Uint128::from_str(a).ok())? } diff --git a/packages/neutron-sdk/src/interchain_queries/v045/register_queries.rs b/packages/neutron-sdk/src/interchain_queries/v045/register_queries.rs index 2a184e6a..33ebdcfc 100644 --- a/packages/neutron-sdk/src/interchain_queries/v045/register_queries.rs +++ b/packages/neutron-sdk/src/interchain_queries/v045/register_queries.rs @@ -13,9 +13,12 @@ use crate::{ create_validator_signing_info_key, create_wasm_contract_store_key, }, }; -use cosmwasm_std::{Addr, Binary, CosmosMsg, StdError}; +use cosmwasm_std::{Addr, CosmosMsg, StdError}; use neutron_std::types::neutron::interchainqueries::{KvKey, MsgRegisterInterchainQuery, MsgRemoveInterchainQueryRequest, MsgUpdateInterchainQueryRequest}; +use neutron_std::types::neutron::interchaintxs::v1::MsgRegisterInterchainAccount; use serde_json_wasm::to_string; +use crate::bindings::msg::ChannelOrdering; +use neutron_std::types::cosmos::base::v1beta1::Coin; /// Creates a message to register an Interchain Query to get balance of account on remote chain for list of denoms /// @@ -29,7 +32,7 @@ pub fn new_register_balances_query_msg( addr: String, denoms: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let kv_keys = create_balances_query_keys(addr, denoms)?; register_interchain_query(contract, QueryPayload::KV(kv_keys), connection_id, update_period) } @@ -47,7 +50,7 @@ pub fn new_register_balance_query_msg( addr: String, denom: String, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { new_register_balances_query_msg(contract, connection_id, addr, vec![denom], update_period) } @@ -61,7 +64,7 @@ pub fn new_register_bank_total_supply_query_msg( connection_id: String, denoms: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let mut kv_keys: Vec = Vec::with_capacity(denoms.len()); for denom in denoms { @@ -86,7 +89,7 @@ pub fn new_register_distribution_fee_pool_query_msg( contract: Addr, connection_id: String, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let kv_key = KvKey { path: DISTRIBUTION_STORE_KEY.to_string(), key: create_fee_pool_key()?, @@ -110,7 +113,7 @@ pub fn new_register_gov_proposals_query_msg( connection_id: String, proposals_ids: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let kv_keys = create_gov_proposal_keys(proposals_ids)?; register_interchain_query(contract, QueryPayload::KV(kv_keys), connection_id, update_period) @@ -126,7 +129,7 @@ pub fn update_gov_proposals_query_msg( query_id: u64, proposals_ids: Vec, new_update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let kv_keys = create_gov_proposal_keys(proposals_ids)?; update_interchain_query(contract, query_id, kv_keys, new_update_period, None) @@ -144,7 +147,7 @@ pub fn new_register_gov_proposals_voters_votes_query_msg( proposals_ids: Vec, voters: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let kv_keys = create_gov_proposals_voters_votes_keys(proposals_ids, voters)?; register_interchain_query(contract, QueryPayload::KV(kv_keys), connection_id, update_period) @@ -162,7 +165,7 @@ pub fn update_gov_proposals_votes_query_msg( proposals_ids: Vec, voters: Vec, new_update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let kv_keys = create_gov_proposals_voters_votes_keys(proposals_ids, voters)?; update_interchain_query(contract, query_id, kv_keys, new_update_period, None) @@ -178,7 +181,7 @@ pub fn new_register_staking_validators_query_msg( connection_id: String, validators: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let mut kv_keys: Vec = Vec::with_capacity(validators.len()); for validator in validators { @@ -205,7 +208,7 @@ pub fn new_register_validators_signing_infos_query_msg( connection_id: String, validators: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let mut kv_keys: Vec = Vec::with_capacity(validators.len()); for validator in validators { @@ -234,7 +237,7 @@ pub fn new_register_delegator_delegations_query_msg( delegator: String, validators: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let delegator_addr = decode_and_convert(&delegator)?; // Allocate memory for such KV keys as: @@ -280,7 +283,7 @@ pub fn new_register_delegator_unbonding_delegations_query_msg( delegator: String, validators: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let delegator_addr = decode_and_convert(&delegator)?; // Allocate memory, one KV key per validator @@ -318,7 +321,7 @@ pub fn new_register_wasm_contract_store_query_msg( contract_address: String, key: impl AsRef<[u8]>, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let converted_addr_bytes = decode_and_convert(contract_address.as_str())?; let wasm_key = create_wasm_contract_store_key(converted_addr_bytes, key.as_ref())?; @@ -347,7 +350,7 @@ pub fn new_register_transfers_query_msg( recipient: String, update_period: u64, min_height: Option, -) -> NeutronResult> { +) -> NeutronResult>> { let mut query_data = vec![TransactionFilterItem { field: RECIPIENT_FIELD.to_string(), op: TransactionFilterOp::Eq, @@ -377,11 +380,11 @@ pub fn new_register_transfers_query_msg( /// maximum allowed number of filters is 32. /// * **connection_id** is an IBC connection identifier between Neutron and remote chain; /// * **update_period** is used to say how often (in neutron blocks) the query must be updated. -fn register_interchain_query(contract: Addr, query: QueryPayload, connection_id: String, update_period: u64) -> NeutronResult> { - Ok(match query { +fn register_interchain_query(contract: Addr, query: QueryPayload, connection_id: String, update_period: u64) -> NeutronResult>> { + Ok(Box::new(match query { QueryPayload::KV(keys) => MsgRegisterInterchainQuery{ sender: contract.to_string(), - query_type: QueryType::KV.to_string(), + query_type: QueryType::KV.into(), keys, transactions_filter: String::new(), connection_id, @@ -396,7 +399,7 @@ fn register_interchain_query(contract: Addr, query: QueryPayload, connection_id: connection_id, update_period, }, - }) + })) } /// Basic helper to define a update interchain query message: @@ -409,8 +412,8 @@ pub fn update_interchain_query( new_keys: Vec, new_update_period: u64, new_transactions_filter: Option>, -) -> NeutronResult> { - Ok(MsgUpdateInterchainQueryRequest { +) -> NeutronResult>> { + Ok(Box::new(MsgUpdateInterchainQueryRequest { sender: contract.to_string(), query_id, new_keys, @@ -422,14 +425,25 @@ pub fn update_interchain_query( // TODO: check if passing empty string is correct None => "".to_string(), }, - }) + })) } /// Basic helper to define a remove interchain query message: /// * **query_id** is ID of the query we want to remove. -pub fn remove_interchain_query(contract: Addr, query_id: u64)-> NeutronResult> { - Ok(MsgRemoveInterchainQueryRequest { +pub fn remove_interchain_query(contract: Addr, query_id: u64) -> NeutronResult>> { + Ok(Box::new(MsgRemoveInterchainQueryRequest { sender: contract.to_string(), query_id, - }) + })) +} + +// TODO: comment +pub fn register_interchain_account(contract: Addr, connection_id: String, interchain_account_id: String, register_fee: Vec, ordering: Option) -> NeutronResult>> { + Ok(Box::new(MsgRegisterInterchainAccount{ + from_address: contract.to_string(), + connection_id, + interchain_account_id, + register_fee, + ordering: ordering.unwrap_or_else(|| ChannelOrdering::OrderOrdered).into(), + })) } diff --git a/packages/neutron-sdk/src/interchain_queries/v045/types.rs b/packages/neutron-sdk/src/interchain_queries/v045/types.rs index 68e29be8..0588598c 100644 --- a/packages/neutron-sdk/src/interchain_queries/v045/types.rs +++ b/packages/neutron-sdk/src/interchain_queries/v045/types.rs @@ -2,7 +2,6 @@ use crate::interchain_queries::helpers::uint256_to_u128; use crate::interchain_queries::types::KVReconstruct; use crate::interchain_queries::v045::helpers::deconstruct_account_denom_balance_key; use crate::{ - bindings::types::StorageValue, errors::error::{NeutronError, NeutronResult}, }; use cosmos_sdk_proto::cosmos::gov::v1beta1::Vote; @@ -18,7 +17,7 @@ use cosmwasm_std::{from_json, Addr, Coin, Decimal, Decimal256, Timestamp, Uint12 use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::{ops::Div, str::FromStr}; - +use neutron_std::types::neutron::interchainqueries::StorageValue; use super::helpers::{ get_max_change_rate, get_max_rate, get_rate, get_total_supply_amount, get_total_supply_denom, get_update_time, diff --git a/packages/neutron-sdk/src/interchain_queries/v047/register_queries.rs b/packages/neutron-sdk/src/interchain_queries/v047/register_queries.rs index 24f58bc2..6889d560 100644 --- a/packages/neutron-sdk/src/interchain_queries/v047/register_queries.rs +++ b/packages/neutron-sdk/src/interchain_queries/v047/register_queries.rs @@ -2,15 +2,13 @@ // to make it available from v047 package (kinda proxy) since they work with Cosmos SDK 0.47 as usual pub use crate::interchain_queries::v045::register_queries::*; -use crate::bindings::msg::NeutronMsg; -use crate::bindings::types::KVKey; use crate::interchain_queries::helpers::decode_and_convert; -use crate::interchain_queries::types::{QueryPayload, QueryType}; +use crate::interchain_queries::types::QueryType; use crate::interchain_queries::v045::helpers::{create_delegation_key, create_validator_key}; use crate::interchain_queries::v045::types::STAKING_STORE_KEY; use crate::interchain_queries::v047::types::STAKING_PARAMS_KEY; use crate::NeutronResult; -use cosmwasm_std::{Addr, Binary, CosmosMsg}; +use cosmwasm_std::{Addr, CosmosMsg}; use neutron_std::types::neutron::interchainqueries::{MsgRegisterInterchainQuery, KvKey}; /// Creates a message to register an Interchain Query to get delegations of particular delegator on remote chain. @@ -25,7 +23,7 @@ pub fn new_register_delegator_delegations_query_msg( delegator: String, validators: Vec, update_period: u64, -) -> NeutronResult> { +) -> NeutronResult>> { let delegator_addr = decode_and_convert(&delegator)?; // Allocate memory for such KV keys as: @@ -56,12 +54,12 @@ pub fn new_register_delegator_delegations_query_msg( }) } - Ok(MsgRegisterInterchainQuery{ - query_type: QueryType::KV.to_string(), + Ok(Box::new(MsgRegisterInterchainQuery{ + query_type: QueryType::KV.into(), keys, transactions_filter: "".to_string(), connection_id, update_period, sender: contract.to_string(), - }) + })) } diff --git a/packages/neutron-sdk/src/interchain_queries/v047/types.rs b/packages/neutron-sdk/src/interchain_queries/v047/types.rs index 38e3a00a..9cfa4f4d 100644 --- a/packages/neutron-sdk/src/interchain_queries/v047/types.rs +++ b/packages/neutron-sdk/src/interchain_queries/v047/types.rs @@ -7,7 +7,7 @@ pub use crate::interchain_queries::v045::types::*; // compatible with Cosmos SDK 0.47 use crate::interchain_queries::types::KVReconstruct; -use crate::{bindings::types::StorageValue, errors::error::NeutronResult, NeutronError}; +use crate::{errors::error::NeutronResult, NeutronError}; use crate::interchain_queries::helpers::uint256_to_u128; use crate::interchain_queries::v047::helpers::deconstruct_account_denom_balance_key; @@ -19,6 +19,7 @@ use cosmwasm_std::{Addr, Coin, Decimal256, Uint128, Uint256}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use std::str::FromStr; +use neutron_std::types::neutron::interchainqueries::StorageValue; /// Key for Staking Params in the **staking** module's storage /// diff --git a/packages/neutron-sdk/src/lib.rs b/packages/neutron-sdk/src/lib.rs index b419643d..aae2f460 100644 --- a/packages/neutron-sdk/src/lib.rs +++ b/packages/neutron-sdk/src/lib.rs @@ -3,6 +3,8 @@ // #![forbid(unsafe_code)] #![warn(trivial_casts, trivial_numeric_casts, unused_import_braces)] +// TODO: can we get it from other place? or move NEUTRON_COMMIT to other place +// TODO: do we need NEUTROND_VERSION? /// The version (commit hash) of the Cosmos SDK used when generating this library. pub const NEUTROND_VERSION: &str = include_str!("proto_types/NEUTRON_COMMIT"); @@ -10,14 +12,10 @@ pub mod bindings; mod errors; pub mod interchain_queries; pub mod interchain_txs; -#[allow(deprecated, clippy::module_inception)] -pub mod proto_types; mod serde; -pub mod shim; pub mod sudo; pub use errors::error::{NeutronError, NeutronResult}; -pub use shim::{cosmwasm_to_proto_coins, try_proto_to_cosmwasm_coins}; // This is a signal, such that any contract that imports these helpers will only run on the // neutron blockchain