From 300e8a1bf54674457b40bfe297f457c6884827f3 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Sat, 13 Apr 2024 16:00:12 +0100 Subject: [PATCH] fixed bank --- contracts/cosmwasm/order/src/lib.rs | 21 ++++++++------------- contracts/cosmwasm/outpost/src/assets.rs | 4 ++-- contracts/cosmwasm/outpost/src/error.rs | 4 ++-- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/contracts/cosmwasm/order/src/lib.rs b/contracts/cosmwasm/order/src/lib.rs index d5142e71..44aa5b6e 100644 --- a/contracts/cosmwasm/order/src/lib.rs +++ b/contracts/cosmwasm/order/src/lib.rs @@ -517,13 +517,15 @@ impl OrderContract<'_> { let mut order: OrderItem = self.orders.load(storage, order_amount.u128())?; order.fill(transfer_coin.amount, optimal_price)?; + // hey, need some other data structure for this + let solver_order = solver_orders + .iter_mut() + .find(|x| x.order.order_id == order.order_id) + .expect("solver order"); + + solver_order.order = order.clone(); + let (event, remaining) = if order.given.amount.is_zero() { - // hey, need some other data structure for this - TOOD - let (_idx, solver_order) = solver_orders - .iter() - .find_position(|x| x.order.order_id == order.order_id) - .expect("solver order"); api.debug(&format!("mantis::order::filled::full {:?}", order.order_id)); @@ -533,13 +535,6 @@ impl OrderContract<'_> { false, ) } else { - let solver_order = solver_orders - .iter_mut() - .find(|x| x.order.order_id == order.order_id) - .expect("solver order"); - - solver_order.order = order.clone(); - self.orders.save(storage, order.order_id.u128(), &order)?; ( mantis_order_filled_partially( diff --git a/contracts/cosmwasm/outpost/src/assets.rs b/contracts/cosmwasm/outpost/src/assets.rs index b990a9f6..d3c1790b 100644 --- a/contracts/cosmwasm/outpost/src/assets.rs +++ b/contracts/cosmwasm/outpost/src/assets.rs @@ -30,7 +30,7 @@ pub(crate) fn force_asset(_: auth::Admin, deps: DepsMut, msg: AssetItem) -> Resu pub(crate) fn get_asset_by_id(deps: Deps, asset_id: AssetId) -> Result { ASSETS .may_load(deps.storage, asset_id)? - .ok_or(ContractError::AssetNotFound) + .ok_or(ContractError::AssetIdNotFound) } /// Fetches information about given asset by its local reference. @@ -40,7 +40,7 @@ pub(crate) fn get_local_asset_by_reference( ) -> Result { LOCAL_ASSETS .may_load(deps.storage, reference)? - .ok_or(ContractError::AssetNotFound) + .ok_or(ContractError::AssetIdNotFound) } /// Removes an existing asset from the registry; errors out if asset doesn’t diff --git a/contracts/cosmwasm/outpost/src/error.rs b/contracts/cosmwasm/outpost/src/error.rs index c36bd193..5a4898cd 100644 --- a/contracts/cosmwasm/outpost/src/error.rs +++ b/contracts/cosmwasm/outpost/src/error.rs @@ -25,8 +25,8 @@ pub enum ContractError { FailedIBCTransfer(String), #[error("Could not serialize to JSON")] FailedToSerialize, - #[error("Asset not been found in the registry.")] - AssetNotFound, + #[error("Asset not been found in the registry {0}.")] + AssetIdNotFound(AssetId), #[error("Exchange not been found in the registry.")] ExchangeNotFound, #[error("The contract must be initialized first.")]