Skip to content

fix(proxy): require balance covering endpoint price before proxying - #1474

Open
lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:fix/1224-require-balance-covering-endpoint-price
Open

lienhoatienphung-svg wants to merge 1 commit into
CalloraOrg:mainfrom
lienhoatienphung-svg:fix/1224-require-balance-covering-endpoint-price

Conversation

@lienhoatienphung-svg

Copy link
Copy Markdown

Closes #1224

Summary

Resolves the matched endpoint's priceUsdc before the pre-proxy balance check in handleProxy (src/routes/proxyRoutes.ts), rejects requests with 402 Payment Required (INSUFFICIENT_BALANCE in the standard error envelope) without contacting the upstream service when currentBalance < endpointPriceUsdc, and allows free endpoints (priceUsdc === 0) to proceed even when the caller's balance is zero.

Acceptance Criteria Mapping

  • A user with balance 1 calling a 5-price endpoint receives 402 and the upstream is not called: Verified in src/routes/gatewayRoutes.test.ts and src/__tests__/proxy.integration.test.ts.
  • A user with balance 5 calling a 5-price endpoint succeeds and has 5 deducted: Verified in src/routes/gatewayRoutes.test.ts and src/__tests__/proxy.integration.test.ts.
  • A user with balance 0 calling a 0-price endpoint succeeds: Free endpoints skip the positive-balance requirement and proxy normally.
  • Error response matches the standard error envelope: Throws new PaymentRequiredError('Payment Required: insufficient balance', 'INSUFFICIENT_BALANCE').

Validation

  • npx jest src/routes/gatewayRoutes.test.ts --no-cache and npx jest src/__tests__/proxy.integration.test.ts -t "1224" --no-cache (all pass).

Payout Wallet (Base Mainnet USDC / EVM): 0x3806cd592a508d1992Ed007C2F53de251C2E7452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Require balance covering endpoint price before proxying

1 participant