Skip to content

Commit

Permalink
fix compilation for interchain_txs contract
Browse files Browse the repository at this point in the history
  • Loading branch information
NeverHappened committed Oct 11, 2024
1 parent 7bacf6a commit 9791793
Show file tree
Hide file tree
Showing 12 changed files with 356 additions and 150 deletions.
53 changes: 37 additions & 16 deletions contracts/ibc_transfer/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ use cosmwasm_std::{
StdError, StdResult, SubMsg,
};
use cw2::set_contract_version;
use neutron_std::types::neutron::transfer::{MsgTransfer, MsgTransferResponse};
use neutron_sdk::interchain_txs::helpers::decode_message_response;
use neutron_sdk::{
sudo::msg::{RequestPacket, RequestPacketTimeoutHeight, TransferSudoMsg},
NeutronResult,
};
use neutron_std::types::neutron::transfer::{MsgTransfer, MsgTransferResponse};
// 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 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 schemars::JsonSchema;
use serde::{Deserialize, Serialize};

// Default timeout for IbcTransfer is 10000000 blocks
const DEFAULT_TIMEOUT_HEIGHT: u64 = 10000000;
Expand All @@ -41,12 +42,7 @@ pub fn instantiate(
}

#[entry_point]
pub fn execute(
deps: DepsMut,
env: Env,
_: MessageInfo,
msg: ExecuteMsg,
) -> StdResult<Response> {
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 @@ -156,7 +152,10 @@ fn execute_send(
source_channel: channel.clone(),
sender: env.contract.address.to_string(),
receiver: to.clone(),
token: Some(SuperCoin{ denom: denom.clone(), amount: amount.to_string() }),
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),
Expand All @@ -170,7 +169,10 @@ fn execute_send(
source_channel: channel,
sender: env.contract.address.to_string(),
receiver: to,
token: Some(SuperCoin{ denom, amount: (2 * amount).to_string() }),
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),
Expand Down Expand Up @@ -277,23 +279,42 @@ pub fn migrate(deps: DepsMut, _env: Env, _msg: MigrateMsg) -> StdResult<Response
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"))?;
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(),
recv_fee: fee
.recv_fee
.iter()
.map(|r| SuperCoin {
denom: r.denom.to_string(),
amount: r.amount.clone(),
})
.collect(),
ack_fee: fee
.ack_fee
.iter().map(|r| SuperCoin{ denom: r.denom.to_string(), amount: r.amount.clone() } )
.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
.iter().map(|r| SuperCoin{ denom: r.denom.to_string(), amount: r.amount.clone() } )
.iter()
.map(|r| SuperCoin {
denom: r.denom.to_string(),
amount: r.amount.clone(),
})
.filter(|a| a.denom == FEE_DENOM)
.collect(),
}
Expand Down
140 changes: 109 additions & 31 deletions contracts/neutron_interchain_queries/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
use cosmos_sdk_proto::cosmos::bank::v1beta1::MsgSend;
use cosmos_sdk_proto::cosmos::tx::v1beta1::{TxBody, TxRaw};
use cosmos_sdk_proto::traits::Message;
use cosmwasm_std::{entry_point, to_json_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdError, StdResult, Uint128};
use cosmwasm_std::{
entry_point, to_json_binary, Addr, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo,
Response, StdError, StdResult, Uint128,
};
use cw2::set_contract_version;
use neutron_sdk::interchain_queries::v047::register_queries::new_register_validators_signing_infos_query_msg;
use neutron_std::types::neutron::interchainqueries::{InterchainqueriesQuerier, RegisteredQuery, QueryResult, KvKey};
use neutron_std::types::neutron::interchainqueries::{
InterchainqueriesQuerier, KvKey, QueryResult, RegisteredQuery,
};
// TODO: fix name
use neutron_sdk::interchain_queries::v045::register_queries::{update_interchain_query as helpers_update_interchain_query, remove_interchain_query as helpers_remove_interchain_query};
use neutron_sdk::interchain_queries::v045::register_queries::{
remove_interchain_query as helpers_remove_interchain_query,
update_interchain_query as helpers_update_interchain_query,
};

use crate::msg::{
Cw20BalanceResponse, ExecuteMsg, GetRecipientTxsResponse, InstantiateMsg, MigrateMsg, QueryMsg,
Expand Down Expand Up @@ -72,37 +80,71 @@ pub fn execute(
addr,
denoms,
update_period,
} => register_balances_query(env.contract.address, connection_id, addr, denoms, update_period),
} => register_balances_query(
env.contract.address,
connection_id,
addr,
denoms,
update_period,
),
ExecuteMsg::RegisterBankTotalSupplyQuery {
connection_id,
denoms,
update_period,
} => register_bank_total_supply_query(env.contract.address, connection_id, denoms, update_period),
} => register_bank_total_supply_query(
env.contract.address,
connection_id,
denoms,
update_period,
),
ExecuteMsg::RegisterDistributionFeePoolQuery {
connection_id,
update_period,
} => register_distribution_fee_pool_query(env.contract.address, connection_id, update_period),
} => {
register_distribution_fee_pool_query(env.contract.address, connection_id, update_period)
}
ExecuteMsg::RegisterGovernmentProposalsQuery {
connection_id,
proposals_ids,
update_period,
} => register_gov_proposal_query(env.contract.address, connection_id, proposals_ids, update_period),
} => register_gov_proposal_query(
env.contract.address,
connection_id,
proposals_ids,
update_period,
),
ExecuteMsg::RegisterStakingValidatorsQuery {
connection_id,
validators,
update_period,
} => register_staking_validators_query(env.contract.address, connection_id, validators, update_period),
} => register_staking_validators_query(
env.contract.address,
connection_id,
validators,
update_period,
),
ExecuteMsg::RegisterValidatorsSigningInfosQuery {
connection_id,
validators,
update_period,
} => register_validators_signing_infos_query(env.contract.address, connection_id, validators, update_period),
} => register_validators_signing_infos_query(
env.contract.address,
connection_id,
validators,
update_period,
),
ExecuteMsg::RegisterDelegatorDelegationsQuery {
connection_id,
delegator,
validators,
update_period,
} => register_delegations_query(env.contract.address, connection_id, delegator, validators, update_period),
} => register_delegations_query(
env.contract.address,
connection_id,
delegator,
validators,
update_period,
),
ExecuteMsg::RegisterDelegatorUnbondingDelegationsQuery {
connection_id,
delegator,
Expand All @@ -120,7 +162,13 @@ pub fn execute(
recipient,
update_period,
min_height,
} => register_transfers_query(env.contract.address, connection_id, recipient, update_period, min_height),
} => register_transfers_query(
env.contract.address,
connection_id,
recipient,
update_period,
min_height,
),
ExecuteMsg::RegisterCw20BalanceQuery {
connection_id,
update_period,
Expand All @@ -138,8 +186,16 @@ pub fn execute(
new_keys,
new_update_period,
new_recipient,
} => update_interchain_query(env.contract.address, query_id, new_keys, new_update_period, new_recipient),
ExecuteMsg::RemoveInterchainQuery { query_id } => remove_interchain_query(env.contract.address, query_id),
} => update_interchain_query(
env.contract.address,
query_id,
new_keys,
new_update_period,
new_recipient,
),
ExecuteMsg::RemoveInterchainQuery { query_id } => {
remove_interchain_query(env.contract.address, query_id)
}
}
}

Expand All @@ -150,7 +206,9 @@ pub fn register_balances_query(
denoms: Vec<String>,
update_period: u64,
) -> NeutronResult<Response> {
let msg: CosmosMsg = new_register_balances_query_msg(contract, connection_id, addr, denoms, update_period)?.into();
let msg: CosmosMsg =
new_register_balances_query_msg(contract, connection_id, addr, denoms, update_period)?
.into();

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

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

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

Ok(Response::new().add_message(msg))
}
Expand All @@ -204,8 +273,12 @@ pub fn register_validators_signing_infos_query(
validators: Vec<String>,
update_period: u64,
) -> NeutronResult<Response> {
let msg =
new_register_validators_signing_infos_query_msg(contract, connection_id, validators, update_period)?;
let msg = new_register_validators_signing_infos_query_msg(
contract,
connection_id,
validators,
update_period,
)?;

Ok(Response::new().add_message(msg))
}
Expand Down Expand Up @@ -253,8 +326,13 @@ pub fn register_transfers_query(
update_period: u64,
min_height: Option<u64>,
) -> NeutronResult<Response> {
let msg =
new_register_transfers_query_msg(contract, connection_id, recipient, update_period, min_height)?;
let msg = new_register_transfers_query_msg(
contract,
connection_id,
recipient,
update_period,
min_height,
)?;

Ok(Response::new().add_message(msg))
}
Expand Down Expand Up @@ -298,13 +376,18 @@ pub fn update_interchain_query(
}]
});

let update_msg =
helpers_update_interchain_query(contract, query_id, new_keys, new_update_period, new_filter)?;
let update_msg = helpers_update_interchain_query(
contract,
query_id,
new_keys,
new_update_period,
new_filter,
)?;
Ok(Response::new().add_message(update_msg))
}

pub fn remove_interchain_query(contract: Addr, query_id: u64) -> NeutronResult<Response> {
let remove_msg = helpers_remove_interchain_query(contract, query_id);
let remove_msg = helpers_remove_interchain_query(contract, query_id)?;
Ok(Response::new().add_message(remove_msg))
}

Expand Down Expand Up @@ -400,8 +483,7 @@ pub fn sudo_tx_query_result(
let body: TxBody = TxBody::decode(tx.body_bytes.as_slice())?;

// Get the registered query by ID and retrieve the raw query string
let registered_query: RegisteredQuery =
get_registered_query(deps.as_ref(), query_id)?;
let registered_query: RegisteredQuery = get_registered_query(deps.as_ref(), query_id)?;
let transactions_filter = registered_query.transactions_filter;

#[allow(clippy::match_single_binding)]
Expand Down Expand Up @@ -507,11 +589,7 @@ fn check_deposits_size(deposits: &Vec<Transfer>) -> StdResult<()> {

/// sudo_kv_query_result is the contract's callback for KV query results. Note that only the query
/// id is provided, so you need to read the query result from the state.
pub fn sudo_kv_query_result(
deps: DepsMut,
_env: Env,
query_id: u64,
) -> NeutronResult<Response> {
pub fn sudo_kv_query_result(deps: DepsMut, _env: Env, query_id: u64) -> NeutronResult<Response> {
deps.api.debug(
format!(
"WASMDEBUG: sudo_kv_query_result received; query_id: {:?}",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cosmwasm_schema::{export_schema, remove_schemas, schema_for};
use neutron_interchain_txs::msg::{ExecuteMsg, InstantiateMsg, MigrateMsg, QueryMsg};
use neutron_sdk::bindings::query::QueryInterchainAccountAddressResponse;
use neutron_sdk::sudo::msg::SudoMsg;
use std::env::current_dir;
use std::fs::create_dir_all;
Expand All @@ -16,8 +15,4 @@ fn main() {
export_schema(&schema_for!(SudoMsg), &out_dir);
export_schema(&schema_for!(QueryMsg), &out_dir);
export_schema(&schema_for!(ExecuteMsg), &out_dir);
export_schema(
&schema_for!(QueryInterchainAccountAddressResponse),
&out_dir,
);
}
Loading

0 comments on commit 9791793

Please sign in to comment.