Skip to content

Commit

Permalink
Merge pull request #202 from crescent-network/feat/event-order-completed
Browse files Browse the repository at this point in the history
feat: emit EventOrderCompleted when order is completed and deleted
  • Loading branch information
kingcre authored Sep 11, 2023
2 parents 4f573c5 + 513a446 commit c9e805d
Show file tree
Hide file tree
Showing 3 changed files with 222 additions and 65 deletions.
4 changes: 4 additions & 0 deletions proto/crescent/exchange/v1beta1/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ message EventOrderSourceOrdersFilled {
cosmos.base.v1beta1.DecCoin received = 7 [(gogoproto.nullable) = false];
}

message EventOrderCompleted {
uint64 order_id = 1;
}

message EventOrderExpired {
uint64 order_id = 1;
}
Expand Down
5 changes: 5 additions & 0 deletions x/exchange/keeper/matching.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func (k Keeper) finalizeMatching(ctx sdk.Context, market types.Market, orders []
executableQty := order.ExecutableQuantity()
if order.IsBuy && executableQty.TruncateDec().IsZero() ||
!order.IsBuy && executableQty.MulTruncate(order.Price).TruncateDec().IsZero() {
if err := ctx.EventManager().EmitTypedEvent(&types.EventOrderCompleted{
OrderId: order.Id,
}); err != nil {
return err
}
if err := k.cancelOrder(ctx, market, order); err != nil {
return err
}
Expand Down
278 changes: 213 additions & 65 deletions x/exchange/types/event.pb.go

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

0 comments on commit c9e805d

Please sign in to comment.