Skip to content

fix: validate trading pairs on order submission and DEX offer assets - #156

Merged
akargi merged 6 commits into
Chulilee:mainfrom
akargi:feature/validate-pairs-and-dex-assets
Nov 4, 2026
Merged

akargi merged 6 commits into
Chulilee:mainfrom
akargi:feature/validate-pairs-and-dex-assets

Conversation

@akargi

@akargi akargi commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Two validation gaps let malformed input reach deeper layers where it failed late and unclear:

Trading pair validation (API)

  • Adds src/lib/trading-pairs.ts with the SUPPORTED_TRADING_PAIRS registry and isSupportedTradingPair helper.
  • POST /api/v1/orders now rejects unknown pairs with 400 and returns the offending pair plus the list of valid markets in details.valid.
  • Price/quantity checks now require finite numbers, so NaN/Infinity can no longer reach the matching engine.
  • OpenAPI docs for the endpoint document the supported pairs and the enriched 400 response.

DEX asset validation (Stellar)

  • Adds src/lib/stellar/asset-validation.ts: asset code shape (1-12 alphanumeric after normalization) and issuer public key format (G + 55 base32 characters), with descriptive messages.
  • buildDexOfferTx validates base and counter assets before touching Horizon, so invalid references fail fast with Base asset invalid: ... / Counter asset invalid: ... instead of opaque SDK submission errors. buildCancelOfferTx inherits the check via delegation.

Testing

  • src/__tests__/api.test.ts: covers unsupported pair rejection (status, message, details.valid) and acceptance of another registry pair.
  • src/lib/stellar/__tests__/asset-validation.test.ts: edge cases for key length/prefix/base32 charset, code length/charset, native XLM, missing issuer, lowercase normalization.
  • src/lib/stellar/__tests__/dex.test.ts: happy-path offer builds (mocked Horizon), both-native guard, and per-side validation failures including the no-network-call-before-validation guarantee.

npm run type-check and npm run lint pass.

Closes #59
Closes #58

POST /orders accepted any pair string, so orders for markets that do
not exist were created and rested on the book with no possible
counterparty. Validate the pair against the supported registry and
return 400 with the valid alternatives, and require finite price and
quantity values so NaN can no longer reach the matching engine.

Closes Chulilee#59
buildDexOfferTx only checked that base and counter were not both
native XLM. Malformed asset codes or issuer keys reached the SDK and
surfaced as opaque submission failures. Validate the code shape
(1-12 alphanumeric) and the issuer public key (G... base32) up front
and throw descriptive errors naming the offending side.

Closes Chulilee#58
@vercel

vercel Bot commented Nov 4, 2026

Copy link
Copy Markdown

@akargi is attempting to deploy a commit to the Akargi Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
inter-changabletrade-fricks Ready Ready Preview Nov 4, 2026 8:31am UTC

@akargi
akargi merged commit c8941c5 into Chulilee:main Nov 4, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — e18bf07e Deployed Nov 4, 2026 by vercel[bot]
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.

Fix: API accepts orders for non-existent trading pairs Fix: DEX offer builder lacks asset validation

1 participant