Skip to content
This repository has been archived by the owner on Dec 29, 2023. It is now read-only.

Commit

Permalink
Event enhancement (#57)
Browse files Browse the repository at this point in the history
* event enhancement

* typo fix & process_spot_orders to process_orders for accurate meaning

* fix: replace attributes event_type to event

---------

Co-authored-by: politeWall <[email protected]>
  • Loading branch information
jelysn and politeWall authored Dec 3, 2023
1 parent d1fe29c commit f50b3cc
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/action/execute/cancel_margin_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ pub fn cancel_margin_order(
amount: vec![order.collateral.clone()],
};

let resp = Response::new().add_attribute("order_id", order.order_id.to_string());
let resp = Response::new().add_event(
Event::new("cancel_margin_order")
.add_attribute("margin_order_id", order.order_id.to_string()),
);

MARGIN_ORDER.save(deps.storage, &orders)?;

Expand Down
2 changes: 1 addition & 1 deletion src/action/execute/cancel_spot_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub fn cancel_spot_order(

let resp = Response::new()
.add_message(CosmosMsg::Bank(refund_msg))
.add_attribute("canceled_spot_order_id", order_id.to_string());
.add_event(Event::new("cancel_spot_order").add_attribute("order_id", order_id.to_string()));

SPOT_ORDER.save(deps.storage, &orders_list)?;

Expand Down
10 changes: 8 additions & 2 deletions src/action/execute/create_margin_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ fn create_margin_open_order(

MARGIN_ORDER.save(deps.storage, &orders)?;

let resp = Response::new().add_attribute("margin_order_id", order_id.to_string());
let resp = Response::new().add_event(
Event::new("create_margin_open_order")
.add_attribute("margin_order_id", order_id.to_string()),
);

if order_type != MarketOpen {
return Ok(resp);
Expand Down Expand Up @@ -223,7 +226,10 @@ fn create_margin_close_order(

MARGIN_ORDER.save(deps.storage, &orders)?;

let resp = Response::new().add_attribute("margin_order_id", order_id.to_string());
let resp = Response::new().add_event(
Event::new("create_margin_close_order")
.add_attribute("margin_order_id", order_id.to_string()),
);

if order_type != MarketClose {
return Ok(resp);
Expand Down
5 changes: 4 additions & 1 deletion src/action/execute/create_spot_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ fn create_resp(
in_route: Vec<SwapAmountInRoute>,
) -> StdResult<Response<ElysMsg>> {
let resp = Response::new()
.add_attribute("order_id", new_order.order_id.to_string())
.add_event(
Event::new("create_spot_order")
.add_attribute("order_id", new_order.order_id.to_string()),
)
.add_message(bank_msg); // information message

if new_order.order_type != SpotOrderType::MarketBuy {
Expand Down
5 changes: 3 additions & 2 deletions src/action/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{states::*, types::*, ContractError};
use cosmwasm_std::Event;
use cosmwasm_std::{BankMsg, CosmosMsg, DepsMut, Env, MessageInfo, Response};
use elys_bindings::*;

Expand Down Expand Up @@ -71,6 +72,6 @@ pub mod reply {
pub mod sudo {
use super::*;

mod process_spot_orders;
pub use process_spot_orders::process_spot_orders;
mod process_orders;
pub use process_orders::process_orders;
}
2 changes: 1 addition & 1 deletion src/action/query/get_margin_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ pub fn get_margin_position(
if let Some(_) = &resp.mtp {
Ok(resp)
} else {
Err(StdError::not_found("margin trading prosition").into())
Err(StdError::not_found("margin trading position").into())
}
}
8 changes: 5 additions & 3 deletions src/action/reply/close_margin_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ pub fn reply_to_close_margin_order(

MARGIN_ORDER.save(deps.storage, &orders)?;

let resp: Response<ElysMsg> = Response::new()
.add_attribute("processed_margin_order_id", order_id.to_string())
.add_attribute("margin_trading_position_closed_id", res.id.to_string());
let resp: Response<ElysMsg> = Response::new().add_event(
Event::new("reply_to_close_margin_order")
.add_attribute("margin_order_id", order_id.to_string())
.add_attribute("margin_trading_position_closed_id", res.id.to_string()),
);

Ok(resp)
}
6 changes: 4 additions & 2 deletions src/action/reply/create_margin_order_market_close.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ pub fn reply_to_create_margin_market_close(

order.status = Status::Processed;

let resp =
Response::new().add_attribute("margin_trading_position_id", margin_resp.id.to_string());
let resp = Response::new().add_event(
Event::new("reply_to_create_margin_market_close")
.add_attribute("margin_trading_position_id", margin_resp.id.to_string()),
);

Ok(resp)
}
6 changes: 4 additions & 2 deletions src/action/reply/create_margin_order_market_open.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ pub fn reply_to_create_margin_market_open(
order.status = Status::Processed;
order.position_id = Some(margin_resp.id);

let resp =
Response::new().add_attribute("margin_trading_position_id", margin_resp.id.to_string());
let resp = Response::new().add_event(
Event::new("reply_to_create_margin_market_open")
.add_attribute("margin_trading_position_id", margin_resp.id.to_string()),
);

Ok(resp)
}
8 changes: 5 additions & 3 deletions src/action/reply/open_margin_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ pub fn reply_to_open_margin_position(

MARGIN_ORDER.save(deps.storage, &orders)?;

let resp: Response<ElysMsg> = Response::new()
.add_attribute("processed_margin_order_id", order_id.to_string())
.add_attribute("margin_trading_position_opened_id", res.id.to_string());
let resp: Response<ElysMsg> = Response::new().add_event(
Event::new("reply_to_open_margin_position")
.add_attribute("margin_order_id", order_id.to_string())
.add_attribute("margin_trading_position_opened_id", res.id.to_string()),
);

Ok(resp)
}
5 changes: 3 additions & 2 deletions src/action/reply/spot_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ pub fn reply_to_spot_order(

SPOT_ORDER.save(deps.storage, &orders)?;

let resp: Response<ElysMsg> =
Response::new().add_attribute("processed_order_id", order_id.to_string());
let resp: Response<ElysMsg> = Response::new().add_event(
Event::new("reply_to_spot_order").add_attribute("order_id", order_id.to_string()),
);

Ok(resp)
}
5 changes: 3 additions & 2 deletions src/action/reply/spot_order_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ pub fn reply_to_spot_order_market(

SPOT_ORDER.save(deps.storage, &orders)?;

let resp: Response<ElysMsg> =
Response::new().add_attribute("processed_order_id", order_id.to_string());
let resp: Response<ElysMsg> = Response::new().add_event(
Event::new("reply_to_spot_order_market").add_attribute("order_id", order_id.to_string()),
);

Ok(resp)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::ops::Div;

use super::*;

pub fn process_spot_orders(
pub fn process_orders(
deps: DepsMut<ElysQuery>,
env: Env,
) -> Result<Response<ElysMsg>, ContractError> {
Expand Down
2 changes: 1 addition & 1 deletion src/entry_point/sudo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ pub fn sudo(
msg: SudoMsg,
) -> Result<Response<ElysMsg>, ContractError> {
match msg {
SudoMsg::ClockEndBlock {} => process_spot_orders(deps, env),
SudoMsg::ClockEndBlock {} => process_orders(deps, env),
}
}

0 comments on commit f50b3cc

Please sign in to comment.