Skip to content

Add Stellar admin wallet balance check before executing bulk payroll #15

Description

@DevSolex

Description

executeBulkPayroll in apps/backend/src/services/payment.ts iterates all APPROVED payrolls and attempts to transfer tokens without first verifying that the admin wallet has sufficient balance. If the wallet is underfunded, every payment in the batch fails with a Stellar error, incrementing retryCount for all entries unnecessarily.

Expected Outcome

A pre-flight balance check before bulk execution that aborts early and returns a descriptive error if the admin wallet cannot cover the total amount for any given token.

Acceptance Criteria

  • Before processing any payroll in executeBulkPayroll, calculate the total amount required per token
  • Fetch admin wallet balances via getAccountBalance from apps/backend/src/services/stellar.ts
  • If any token balance is insufficient, the function throws with a message like "Insufficient XLM balance: need 500, have 200"
  • The check runs before any executePayroll call — no payrolls are updated if the check fails
  • The balance check result is included in the API response from POST /api/payroll/bulk-execute
  • Unit test covers the insufficient-balance path (mock getAccountBalance)

Technical Notes

  • apps/backend/src/services/payment.tsexecuteBulkPayroll function
  • apps/backend/src/services/stellar.tsgetAccountBalance already exists
  • apps/backend/src/routes/payroll.tsPOST /bulk-execute handler

Difficulty

Intermediate

Estimated Time

4 hours

Labels

backend stellar payroll feature

Metadata

Metadata

Assignees

No one assigned

    Labels

    backendBackend / Express / Prisma relatedfeatureNew feature or requestpayrollPayroll workflowstellarStellar blockchain integration

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions