Skip to content

feat(backend): add asset pair canonical key builder module (#372) - #472

Open
jdjioe5-cpu wants to merge 1 commit into
Kitewell-lab:mainfrom
jdjioe5-cpu:feat/issue-372-asset-pair-key-builder
Open

jdjioe5-cpu wants to merge 1 commit into
Kitewell-lab:mainfrom
jdjioe5-cpu:feat/issue-372-asset-pair-key-builder

Conversation

@jdjioe5-cpu

Copy link
Copy Markdown

Summary

Implements the canonical asset pair key builder in backend/src/assetPairKeyBuilder.js to build order-independent keys for trading asset pairs (e.g. native/CODE:ISSUER) per #372.

Changes

  • Add backend/src/assetPairKeyBuilder.js exporting buildAssetPairKey, canonicalizeAsset, parseAssetPairKey, and assetPairKeyBuilder alias
  • Support native assets ("native", "XLM", { type: "native" }) and credit assets ("CODE:ISSUER", "CODE-ISSUER", { code, issuer })
  • Guarantee deterministic, order-independent key generation via lexicographical sorting (canonA.localeCompare(canonB) <= 0)
  • Export constants in backend/src/assetPairKeyBuilderConstants.js (CANONICAL_NATIVE_ASSET, ASSET_PAIR_SEPARATOR, ASSET_PAIR_KEY_ERROR)
  • Add 9 single-behavior node:test test files in backend/src/:
    • assetPairKeyBuilder-order-independent.test.js (order independence between base and counter)
    • assetPairKeyBuilder-native-credit.test.js (native and credit pair keys)
    • assetPairKeyBuilder-two-credits.test.js (two credit assets pair sorting)
    • assetPairKeyBuilder-options-object.test.js (options object with assetA/assetB, base/counter, selling/buying)
    • assetPairKeyBuilder-object-inputs.test.js (asset objects inputs)
    • assetPairKeyBuilder-parse.test.js (decomposing key back into canonical assets)
    • assetPairKeyBuilder-invalid-inputs.test.js (missing and invalid format input rejection)
    • assetPairKeyBuilder-invalid-issuer.test.js (invalid code length and issuer public key rejection)
    • assetPairKeyBuilder-constants.test.js (constant immutability verification)
  • Add documentation in docs/features/assetPairKeyBuilder.md
  • No existing files modified

Verification

  • npm test run from backend/ passes 395/395 tests clean

Closes #372

- Implement backend/src/assetPairKeyBuilder.js to build order-independent canonical keys for trading asset pairs
- Support native (normalized to native) and credit assets (normalized to CODE:ISSUER)
- Export constants CANONICAL_NATIVE_ASSET, ASSET_PAIR_SEPARATOR, and ASSET_PAIR_KEY_ERROR
- Provide parseAssetPairKey to decompose canonical keys back into assets
- Handle both positional and options object inputs
- Add 9 single-behavior node:test test files covering order-independence, object inputs, parsing, constants, and invalid code/issuer validations
- Add documentation under docs/features/assetPairKeyBuilder.md

Closes Kitewell-lab#372
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.

New backend module: backend/src/assetPairKeyBuilder.js — Asset pair canonical key builder

1 participant