feat(payouts): enforce configurable minimum payout via MIN_STELLAR_PAYOUT#525
Open
Petah1 wants to merge 1 commit into
Open
feat(payouts): enforce configurable minimum payout via MIN_STELLAR_PAYOUT#525Petah1 wants to merge 1 commit into
Petah1 wants to merge 1 commit into
Conversation
…YOUT Load the minimum payout threshold from the MIN_STELLAR_PAYOUT environment variable (default 5) through the centralized ConfigService. Validate at application startup that the configured value is a positive finite number, throwing immediately if it is not. Add a private assertMinimumPayout() guard in PayoutsService and call it at every payout entry point — requestPayout, requestPayoutWithDetails, initiateStellarPayout, processPayout, and batchProcessPayouts — before any balance query, Stellar account load, transaction build, signing, or on-chain submission. Replace the ad-hoc MIN_PAYOUT_AMOUNT env read in requestPayoutWithDetails with the centralized guard. Error message is dynamic and reflects the configured threshold: "Minimum payout amount is <N> USD equivalent."
|
@Petah1 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #368
Summary
Centralized config —
ConfigServicenow exposesminStellarPayout, loaded fromMIN_STELLAR_PAYOUT(default5). A constructor validates the value at application startup: if the env var is missing, zero, negative, or non-numeric the process fails immediately with a descriptive error rather than silently accepting a broken threshold.Single enforcement point —
PayoutsService.assertMinimumPayout(amount)is the only place the check lives. It throwsBadRequestExceptionwith a dynamic message that reflects the configured value:{ "message": "Minimum payout amount is 5 USD equivalent." }All payout entry points protected — the guard is called before any balance query, Stellar account load, transaction build, signing, or on-chain submission in:
requestPayoutavailableBalancecomputed, before fee calcrequestPayoutWithDetailsinitiateStellarPayoutprocessPayoutbatchProcessPayoutsBackward compatible — existing behaviour is unchanged; operators can lower or raise the threshold via the env var with no code changes.
Removed the previous ad-hoc
parseFloat(process.env.MIN_PAYOUT_AMOUNT ?? '10')inrequestPayoutWithDetails— all paths now use the same threshold from config.Fixed pre-existing duplicate
import { FeeService }inpayouts.service.ts.Test plan
ConfigServicestartup throws whenMIN_STELLAR_PAYOUTis"","0","-5","abc"ConfigServiceuses default5when env var is absentrequestPayoutWithDetailsrejects amount below threshold; error message contains configured valuerequestPayoutWithDetailsproceeds when amount equals or exceeds thresholdrequestPayoutWithDetailsdoes not query DB or create payout when validation failsrequestPayoutrejects when available balance is below threshold; payout not createdrequestPayoutproceeds when balance exactly equals thresholdinitiateStellarPayoutrejects below-threshold amount; no balance query or TX builtinitiateStellarPayoutproceeds when amount equals thresholdprocessPayoutrejects below-threshold payout amount; nopayout.updatecalledminStellarPayoutvalue at runtime