-
Notifications
You must be signed in to change notification settings - Fork 14
feat: add changeAmount and effectiveFee to finalized melt operations #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@cashu/coco": minor | ||
| --- | ||
|
|
||
| Add changeAmount and effectiveFee to finalized melt operations for accurate settlement reporting |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,6 +26,7 @@ import { | |||||||||||
| } from '../../models/Error'; | ||||||||||||
| import type { MintAdapter } from '@core/infra'; | ||||||||||||
| import type { MeltHandlerProvider } from '../../infra/handlers'; | ||||||||||||
| import type { FinalizeResult } from '../../infra/handlers/MeltMethodHandler'; | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * MeltOperationService orchestrates melt sagas while delegating | ||||||||||||
|
|
@@ -300,7 +301,7 @@ export class MeltOperationService { | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| async finalize(operationId: string): Promise<void> { | ||||||||||||
| async finalize(operationId: string): Promise<FinalizeResult> { | ||||||||||||
| const releaseLock = await this.acquireOperationLock(operationId); | ||||||||||||
| try { | ||||||||||||
| const operation = await this.meltOperationRepository.getById(operationId); | ||||||||||||
|
|
@@ -309,13 +310,18 @@ export class MeltOperationService { | |||||||||||
| } | ||||||||||||
| if (operation.state === 'finalized') { | ||||||||||||
| this.logger?.debug('Operation already finalized', { operationId }); | ||||||||||||
| return; | ||||||||||||
| // Return settlement amounts if already finalized | ||||||||||||
| const finalizedOp = operation as FinalizedMeltOperation; | ||||||||||||
| return { | ||||||||||||
| changeAmount: finalizedOp.changeAmount, | ||||||||||||
| effectiveFee: finalizedOp.effectiveFee, | ||||||||||||
|
Comment on lines
+316
to
+317
|
||||||||||||
| changeAmount: finalizedOp.changeAmount, | |
| effectiveFee: finalizedOp.effectiveFee, | |
| // Fallbacks for backward compatibility with operations finalized before changeAmount/effectiveFee were added | |
| changeAmount: finalizedOp.changeAmount ?? 0, | |
| effectiveFee: finalizedOp.effectiveFee ?? (finalizedOp as any).fee_reserve ?? 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FinalizedMeltOperation interface now requires changeAmount and effectiveFee fields (non-optional). Existing finalized operations in storage from before this change will not have these fields. Consider either: (1) making these fields optional with
changeAmount?: number, (2) adding a data migration to populate these fields for existing operations, or (3) adding fallback values when reading from storage. Without one of these approaches, loading pre-existing finalized operations will fail or have undefined values that violate the type contract.