Skip to content

fix(stellar): validate DEX and trustline asset references - #157

Merged
akargi merged 5 commits into
Chulilee:mainfrom
akargi:fix/dex-asset-validation
Nov 4, 2026
Merged

akargi merged 5 commits into
Chulilee:mainfrom
akargi:fix/dex-asset-validation

Conversation

@akargi

@akargi akargi commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #58.

buildDexOfferTx only rejected the case where both sides were native XLM. Malformed asset codes or issuers were left to the Stellar SDK, whose errors do not identify which side is wrong, and the source account was loaded from Horizon before any validation. This change adds explicit asset-reference validation and runs it before network I/O.

Acceptance criteria

  • Asset code format validation
  • Issuer public key validation
  • Descriptive error messages
  • Unit tests for validation edge cases

Changes

  • Added src/lib/stellar/assetValidation.ts:
    • 1-12 alphanumeric asset code check.
    • Stellar account ID (G...) issuer check via StrKey.isValidEd25519PublicKey.
    • Native XLM must not carry an issuer.
    • InvalidAssetError with side-specific messages.
  • Validated base/counter assets in buildDexOfferTx and trustline assets in buildTrustlineTx / buildRemoveTrustlineTx before horizon.loadAccount.
  • Added defense-in-depth validation in toSdkAsset.
  • Added 17 unit tests covering valid references and edge cases.

Validation

Ran from the frontend repository with the existing dependency tree:

  • npm test -- src/lib/stellar --runInBand — 3 suites, 47 tests passed.
  • npm run type-check — passed.
  • npm run lint — passed with pre-existing <img> warnings only.

Not run locally:

  • npm run build — CI runs this.
  • npm run test:e2e — requires a running app and wallet setup.

No live Testnet transaction was submitted. The tests exercise transaction construction and stop before Horizon I/O.

Compatibility and scope

  • No public function signatures changed.
  • Valid asset references behave as before.
  • Invalid references now fail fast with InvalidAssetError instead of a generic SDK/Horizon error.
  • No wallet, signing, or submission changes.

Non-goals

  • No changes to the off-chain order-routing simulator or supported trading-pair validation (Fix: API accepts orders for non-existent trading pairs #59).
  • No attempt to validate whether an issuer account is funded or has a trustline; this change validates the Stellar asset reference format only.

Reject malformed asset codes and issuers before loading the source account or constructing a DEX offer. Errors now name the offending side (base, counter, or trustline) and explain the expected Stellar format.

Refs Chulilee#58
Exercise valid native and credit assets, malformed codes, missing or invalid issuers, and verify the transaction builders reject bad references before any Horizon request.

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:51am UTC

The merge left both the new assertValidAssetRef and the old
validateAssetRef running in buildDexOfferTx. The new validator throws
first with a descriptive InvalidAssetError, so the old block was dead
code that never produced its own messages. Drop the old block, delete
the superseded module and its suite, and keep one validator wired into
horizon.toSdkAsset and the DEX offer builder.
The offer builder now fails fast through assertValidAssetRef, whose
messages name the side, the offending value, and the expected format.
Update the assertions to match so the suite pins the new contract.
@akargi
akargi merged commit 7c72a17 into Chulilee:main Nov 4, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — 2825150d 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: DEX offer builder lacks asset validation

1 participant