Skip to content

fix: resolve assigned issues #599, #600, #785, #786#858

Merged
Wilfred007 merged 1 commit into
Gildado:mainfrom
JamesVictor-O:fix/resolve-assigned-issues-599-600-785-786
Jun 24, 2026
Merged

fix: resolve assigned issues #599, #600, #785, #786#858
Wilfred007 merged 1 commit into
Gildado:mainfrom
JamesVictor-O:fix/resolve-assigned-issues-599-600-785-786

Conversation

@JamesVictor-O

@JamesVictor-O JamesVictor-O commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Summary

[CONTRACT] #599 - Optimize Storage Footprint for Large Employee Maps

  • Compressed BatchStatusMap: Packs payment statuses into 2-bit-per-status format (16 statuses per u32 word), reducing storage from O(N) individual keys to a single key per batch
  • archive_batch_statuses(): Admin function to compress PaymentEntry records into a BatchStatusMap after batch processing is complete, removing individual temporary storage keys
  • get_archived_status(): Read payment status from compressed storage by batch_id and payment_index
  • reduce_batch_ttl(): Apply shorter TTL to old batch records for faster archival
  • Tiered TTL constants: ARCHIVE_TTL_THRESHOLD (5,000) and ARCHIVE_TTL_EXTEND_TO (50,000) for historical data vs active data

[CONTRACT] #600 - Implement Automatic Distribution Account Re-funding

  • set_refund_config(): Admin configures distribution account, funding source, token, threshold, and refund amount
  • check_and_refund(): Checks distribution account balance against threshold and automatically transfers refund_amount from funding source when below threshold
  • get_refund_config() / remove_refund_config(): Config management functions
  • Events: AccountRefundedEvent and RefundConfigUpdatedEvent for on-chain audit trail
  • New error codes: AutoRefundFailed(26), RefundThresholdInvalid(27), RefundConfigNotSet(28), RefundNotNeeded(29)

[BACKEND] #785 - Backend Legacy Issue - Maintenance & Stability

  • asyncHandler utility: Wraps async Express handlers to forward rejected promises to the error middleware, eliminating uncaught promise rejections across all controllers
  • HttpError class: Factory methods (badRequest, unauthorized, notFound, etc.) for standardized error throwing that integrates with the centralized error handler
  • preflightCheckWithAutoRefund(): New BalanceService method that attempts on-chain auto-refund before failing a preflight check, integrating with Issue [CONTRACT] Implement Automatic Distribution Account Re-funding #600's contract functionality
  • Retry on Stellar submissions: withRetry() wrapper (3 attempts, exponential backoff) around StellarService.submitTransaction() in the payroll worker
  • Standardized timeout errors: Response timeout now uses apiErrorResponse format instead of ad-hoc JSON

[BACKEND] #786 - Backend Legacy Issue - Maintenance & Stability

  • Graceful worker shutdown: New stopWorkers() function that cleanly closes all 4 BullMQ workers (payroll, notification, scheduler, tx-verification)
  • Server shutdown integration: Workers are now stopped before database pool closure during SIGTERM/SIGINT
  • Webhook retry interval cleanup: clearInterval() on shutdown prevents timer leaks
  • Database migrations: 050_auto_refund_audit_log.sql and 051_batch_archive_tracking.sql for off-chain tracking

Test plan

  • All 121 Soroban contract tests pass (cargo test -p bulk_payment) including 15 new tests
  • All 21 new backend unit tests pass (asyncHandler, HttpError, BalanceService)
  • No TypeScript compilation errors in modified files
  • Existing test suite not affected (no regressions)

Closes #599
Closes #600
Closes #785
Closes #786

[CONTRACT] Issue Gildado#599 - Optimize Storage Footprint for Large Employee Maps:
- Add BatchStatusMap with 2-bit-per-status packing (16 statuses per u32)
- Add archive_batch_statuses() to compress PaymentEntry keys into single map
- Add get_archived_status() for reading from compressed storage
- Add reduce_batch_ttl() for tiered TTL on old batch records
- Add ARCHIVE_TTL constants for shorter retention of historical data

[CONTRACT] Issue Gildado#600 - Implement Automatic Distribution Account Re-funding:
- Add RefundConfig storage type and set_refund_config() admin function
- Add check_and_refund() that transfers from funding source when below threshold
- Add get_refund_config() and remove_refund_config() for config management
- Emit AccountRefundedEvent and RefundConfigUpdatedEvent for audit trail
- New error codes: AutoRefundFailed(26), RefundThresholdInvalid(27),
  RefundConfigNotSet(28), RefundNotNeeded(29)

[BACKEND] Issue Gildado#785 - Backend Legacy Maintenance & Stability:
- Add asyncHandler utility for consistent async error propagation to Express
- Add HttpError class with factory methods for standardized error throwing
- Standardize timeout error response to use apiErrorResponse format
- Replace console.error with structured error messages in balance controller
- Add preflightCheckWithAutoRefund to BalanceService for on-chain integration
- Add withRetry wrapper around Stellar transaction submission in payroll worker

[BACKEND] Issue Gildado#786 - Backend Legacy Maintenance & Stability:
- Add stopWorkers() for graceful BullMQ worker shutdown
- Integrate worker shutdown into server graceful shutdown sequence
- Clear webhook retry interval on shutdown to prevent leaked timers
- Add database migrations for auto-refund audit log and batch archive tracking

All changes include comprehensive tests:
- 121 contract tests pass (including 15 new tests)
- 21 new backend unit tests pass

Closes Gildado#599
Closes Gildado#600
Closes Gildado#785
Closes Gildado#786
@drips-wave

drips-wave Bot commented Jun 24, 2026

Copy link
Copy Markdown

@JamesVictor-O Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Wilfred007 Wilfred007 merged commit ecb0629 into Gildado:main Jun 24, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants