From b65d3aab86b618193e067a5b5487a4fc7d7bc9f9 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Wed, 7 May 2025 15:56:19 +0200 Subject: [PATCH] Add returnedCollateral when the sale is ignored --- codex/sales/states/ignored.nim | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/codex/sales/states/ignored.nim b/codex/sales/states/ignored.nim index 7f2ae5b1..4543fb34 100644 --- a/codex/sales/states/ignored.nim +++ b/codex/sales/states/ignored.nim @@ -22,10 +22,25 @@ method run*( state: SaleIgnored, machine: Machine ): Future[?State] {.async: (raises: []).} = let agent = SalesAgent(machine) + let data = agent.data + let market = agent.context.market + + without request =? data.request: + raiseAssert "no sale request" try: + # The returnedCollateral is needed because a reservation could + # be created and the collateral assigned to that reservation. + # The returnedCollateral will be used in the cleanup function + # and be passed to the deleteReservation function. + let slot = Slot(request: request, slotIndex: data.slotIndex) + let currentCollateral = await market.currentCollateral(slot.id) + let returnedCollateral = currentCollateral.some + if onCleanUp =? agent.onCleanUp: - await onCleanUp(reprocessSlot = state.reprocessSlot) + await onCleanUp( + reprocessSlot = state.reprocessSlot, returnedCollateral = returnedCollateral + ) except CancelledError as e: trace "SaleIgnored.run was cancelled", error = e.msgDetail except CatchableError as e: