Skip to content

Commit

Permalink
updated to new hook
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Mar 30, 2024
1 parent 19b73e7 commit 32680e2
Show file tree
Hide file tree
Showing 17 changed files with 175 additions and 185 deletions.
70 changes: 30 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ num = { version = "^0.4.1", default-features = false }
enumn = { version = "0.1.13" }
prost-build = { version = "^0.12.2" }
bech32 = { version = "^0.11.0", default-features = false }
cosmwasm-std = { version = "^1.5.0", features = [
cosmwasm-std = { version = "^1.5.3", features = [
"iterator",
], default-features = false }

Expand All @@ -79,7 +79,7 @@ cw20 = { version = "^1.1.2", default-features = false }
cw-controllers = { version = "^1.1.1", default-features = false }
sylvia = { version = "^0.9.1", default-features = false }
schemars = { version = "^0.8.16", default-features = false }
cosmwasm-schema = { version = "^1.5.0", default-features = false }
cosmwasm-schema = { version = "^1.5.3", default-features = false }
serde = { version = "^1.0.197", default-features = false }
cw-storage-plus = { version = "^1.2.0", features = [
"iterator",
Expand Down Expand Up @@ -128,7 +128,7 @@ thiserror = { version = "^1.0.50", default-features = false, package = "thiserro
# xcm = { version = "^5.0.0", default-features = false, package = "staging-xcm" }
cw-utils = { version = "^1.0.3", default-features = false }
cw2 = { version = "^1.1.2", default-features = false }
ibc-apps-more = { git = "https://github.com/ComposableFi/ibc-apps-more-rs.git", branch = "main", default-features = false }
ibc-apps-more = { git = "https://github.com/ComposableFi/ibc-apps-more-rs.git", rev = "bf01a0ba3ff4af816974d27456efc9751f188dac", default-features = false }
ibc-app-transfer-types = { git = "https://github.com/dzmitry-lahoda-forks/ibc-rs.git", branch = "dz/14", default-features = false, features = [
"serde",
] }
Expand Down
4 changes: 2 additions & 2 deletions contracts/cosmwasm/executor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use cosmwasm_std::{
SubMsgResult, WasmMsg, WasmQuery,
};
use cvm_route::{asset::AssetReference, exchange::ExchangeItem};
use cvm_runtime::executor::*;
use cvm_runtime::{executor::*, shared::CvmAddress};
use cvm_runtime::{
apply_bindings,
exchange::*,
Expand Down Expand Up @@ -457,7 +457,7 @@ pub fn interpret_transfer(
deps: &mut DepsMut,
env: &Env,
tip: &Addr,
to: Destination<shared::XcAddr>,
to: Destination<CvmAddress>,
assets: Funds<Amount>,
) -> Result {
let Config {
Expand Down
1 change: 0 additions & 1 deletion contracts/cosmwasm/order/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ impl OrderContract<'_> {
let order: OrderItem = self.orders.load(ctx.deps.storage, order_id.u128())?;
validation::validate_solver(ctx.deps.as_ref(), &ctx.info.sender, &order)?;
self.orders.remove(ctx.deps.storage, order_id.u128());
validation::validate_program(ctx.deps.as_ref(), &cvm_program, &order)?;
let cvm = wasm_execute(
self.cvm_address.load(ctx.deps.storage)?,
&cvm_program,
Expand Down
10 changes: 0 additions & 10 deletions contracts/cosmwasm/order/src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,6 @@ pub fn validate_solver(
Ok(())
}

/// Validate program is sane
pub(crate) fn validate_program(
as_ref: cosmwasm_std::Deps<'_>,
cvm_program: &cvm_runtime::Program<
Vec<cvm_runtime::Instruction<Vec<u8>, cvm_runtime::shared::XcAddr, cvm_runtime::Funds>>,
>,
order: &OrderItem,
) -> StdResult<()> {
Ok(())
}

/// Validate solver can solver amount he claimed
pub(crate) fn validate_solvers(
Expand Down
3 changes: 2 additions & 1 deletion contracts/cosmwasm/outpost/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use cosmwasm_std::{Deps, Env, MessageInfo};
use cvm::NetworkId;
use cvm_route::transport::*;
use ibc_apps_more::types::hook::derive_intermediate_sender;

/// Authorisation token indicating call is authorised according to policy
/// `T`.
Expand Down Expand Up @@ -99,7 +100,7 @@ impl Auth<policy::WasmHook> {
.ok_or(ContractError::ICS20NotFound)?
.source;
let hash_of_channel_and_sender =
ibc_apps_more::hook::derive_intermediate_sender(&channel, &sender, &prefix)?;
derive_intermediate_sender(&channel, &sender, &prefix)?;
deps.api.debug(&format!(
"cvm::outpost:auth:: {0} {1}",
&hash_of_channel_and_sender, &info.sender
Expand Down
3 changes: 2 additions & 1 deletion contracts/cosmwasm/outpost/src/contract/sudo.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{error::ContractError, state};
use cosmwasm_std::{entry_point, wasm_execute, Coin, DepsMut, Env, Event, Response};
use ibc_apps_more::hook::{IBCLifecycleComplete, SudoMsg};

use ibc_apps_more::types::hook::{IBCLifecycleComplete, SudoMsg};
use ibc_core_host_types::identifiers::ChannelId;

#[cfg_attr(not(feature = "library"), entry_point)]
Expand Down
6 changes: 3 additions & 3 deletions contracts/cosmwasm/outpost/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub enum ContractError {
#[error("Route not found.")]
RouteNotFound,
#[error("{0}")]
Bech32(bech32::Error),
Bech32(bech32::EncodeError),
#[error("{0}")]
Serde(#[from] serde_json_wasm::ser::Error),
#[error("Assets non transferrable")]
Expand Down Expand Up @@ -94,8 +94,8 @@ impl From<cvm_runtime::proto::DecodeError> for ContractError {
}
}

impl From<bech32::Error> for ContractError {
fn from(value: bech32::Error) -> Self {
impl From<bech32::EncodeError> for ContractError {
fn from(value: bech32::EncodeError) -> Self {
Self::Bech32(value)
}
}
Expand Down
5 changes: 3 additions & 2 deletions crates/cvm-runtime/src/outpost/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use cvm_route::{
asset::{AssetItem, AssetReference},
exchange::ExchangeItem,
};
use ibc_apps_more::types::hook::{Callback, HookMemo, LazyHookMemo};
pub use query::*;

use crate::{
Expand Down Expand Up @@ -92,9 +93,9 @@ impl ExecutePacketICS20Msg {

pub fn into_wasm_hook(self, contract: ibc_primitives::Signer) -> Result<ExecuteMsg, StdError> {
let ics20 = self.into_packet()?;
let memo: ibc_apps_more::memo::Memo = serde_json_wasm::from_str(&ics20.memo.to_string())
let memo: LazyHookMemo = serde_json_wasm::from_str(&ics20.memo.to_string())
.map_err(|x| StdError::generic_err(format!("{:?}", x)))?;
let wasm: ibc_apps_more::hook::Callback = memo
let wasm: Callback<serde_cw_value::Value> = memo.base
.wasm
.ok_or(StdError::generic_err(format!("no wasm in memo")))?;
ensure!(
Expand Down
3 changes: 2 additions & 1 deletion crates/cvm-runtime/src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::panic;

use crate::{prelude::*, AssetId};
use cosmwasm_std::{from_json, to_json_binary, Api, Binary, CanonicalAddr, StdError, StdResult};
use cvm::NetworkId;
use cvm::{NetworkId, XcAddr};
use serde::{de::DeserializeOwned, Serialize};

pub use cvm::shared::*;
Expand All @@ -12,6 +12,7 @@ pub type CvmFunds = Vec<(AssetId, Displayed<u128>)>;
/// like `CvmFunds`, but allow relative(percentages) amounts. Similar to assets filters in XCM
pub type CvmBalanceFilter = crate::asset::Amount;
pub type CvmFundsFilter = crate::Funds<CvmBalanceFilter>;
pub type CvmAddress = XcAddr;
pub type CvmInstruction = crate::Instruction<Vec<u8>, XcAddr, CvmFundsFilter>;
pub type CvmPacket = crate::Packet<CvmProgram>;
pub type CvmProgram = crate::Program<Vec<CvmInstruction>>;
Expand Down
13 changes: 7 additions & 6 deletions crates/cvm-runtime/src/transport/ibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ use cosmwasm_std::{Api, BlockInfo, CosmosMsg, Deps, IbcEndpoint, StdResult};
use cvm_route::transport::RelativeTimeout;
use ibc_core_host_types::identifiers::{ChannelId, ConnectionId, PortId};

use ibc_apps_more::{
hook::{Callback, SendMemo},
memo::Memo,
};
use ibc_apps_more::types::hook::Callback;
//, HookMemo};
// use ibc_apps_more::types::memo::Memo;

/// This message should be send as part of wasm termination memo.
/// So that can match it to sender hash and know what channel and origin was used to send message.
Expand Down Expand Up @@ -72,12 +71,14 @@ pub fn to_cosmwasm_message<T>(
block: BlockInfo,
to_outpost: Addr,
) -> StdResult<CosmosMsg<T>> {
use ibc_apps_more::types::{hook::LazyHookMemo, memo::Memo};

let msg = outpost::ExecuteMsg::MessageHook(XcMessageData {
from_network_id: route.from_network,
packet,
});
let memo = SendMemo {
inner: Memo {
let memo = LazyHookMemo {
base: Memo {
wasm: Some(Callback::new_cosmwasm(
to_outpost.clone(),
serde_cw_value::to_value(msg).expect("can always serde"),
Expand Down
Loading

0 comments on commit 32680e2

Please sign in to comment.