Skip to content

Add NYM swap provider#457

Open
j0ntz wants to merge 1 commit into
masterfrom
jon/nym-swap
Open

Add NYM swap provider#457
j0ntz wants to merge 1 commit into
masterfrom
jon/nym-swap

Conversation

@j0ntz

@j0ntz j0ntz commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

Asana task

Integrate NYM as a centralized swap provider (pluginId: nym).

Asana: https://app.asana.com/1/9976422036640/project/1213880789473005/task/1215306512581867

NYM provides its own swap liquidity, so every swap must have the NYM asset on one side. The plugin gates this locally before hitting the API to avoid offering NYM (and rate-limiting it) on unrelated pairs.

NYM exposes an Edge-shaped partner API, which keeps the plugin thin:

  • Native-unit amountssourceAmount/destinationAmount are already in the chain's smallest unit (matching Edge's nativeAmount), so no denomination conversion is needed in either direction.
  • Edge-style asset references{ chainNetwork, chainId?, tokenId? }. chainNetwork is the network-family name (mapped from the Edge pluginId), chainId comes from the wallet's evmChainId, and tokenId is the 0x contract address (not the Edge tokenId). Sepolia is represented as chainNetwork: 'ethereum' + chainId: 11155111.
  • Limits — the quote response returns native-unit min/max for both sides; the plugin enforces them as SwapBelowLimitError / SwapAboveLimitError.
  • Errors — NYM's JSON error bodies ({ errors: [{ error, message }] } and { error }) are parsed into SwapCurrencyError / SwapPermissionError, with rate-limit/other failures surfaced as transient errors.

Files:

  • src/swap/central/nym.ts — the provider.
  • src/mappings/nym.tsEdgeCurrencyPluginId → chainNetwork, scoped to the current testnet asset list (BTC, LTC, ZEC, DASH, Sepolia ETH/USDC, ADA, NYM).
  • src/index.ts — registers nym: makeNymPlugin.

Testnet-only for now. Base URL points at the NYM testnet API; the mapping (and base URL) should be expanded when NYM launches mainnet. The init option is { apiKey } (header x-api-key); GUI wiring is a separate follow-up.

Validated end-to-end against the live NYM testnet API: GET /currencies, and POST /quotePOST /order for both buy-NYM (e.g. USDC→NYM) and sell-NYM (e.g. NYM→Sepolia ETH, NYM→ADA) directions, plus the unsupported-pair / wrong-tokenId-format error paths.


Note

Medium Risk
New third-party swap path that sets pay-in addresses and amounts; mitigated by testnet-only endpoints and patterns shared with other CEX plugins, but still user-fund flow if misconfigured.

Overview
Adds a testnet-only centralized swap provider (nym) wired into the plugin registry and documented in the CHANGELOG.

The new plugin talks to NYM’s partner API (quote then order) with x-api-key auth. It only offers pairs where NYM is on one side, rejects unmapped chains locally, and maps Edge wallets to NYM asset refs (chainNetwork, optional chainId, 0x tokenId). Quotes use native amounts with min/max enforcement, then build deposit spendInfo (including Zcash transparent payout/refund) and swap metadata. Order tracking URLs are built from a fixed ORDER_URI prefix, not the API’s statusUrl. API errors are mapped to SwapCurrencyError / SwapPermissionError where appropriate.

src/mappings/nym.ts defines the current testnet pluginIdchainNetwork table (BTC, LTC, ZEC, DASH, ADA, Sepolia-as-ethereum, NYM sandbox).

Reviewed by Cursor Bugbot for commit e721125. Bugbot is set up for automated code reviews on this repo. Configure here.

Comment thread src/swap/central/nym.ts
Comment thread src/swap/central/nym.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5cc72ff. Configure here.

Comment thread src/swap/central/nym.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale comment

Comment thread src/swap/central/nym.ts Outdated
Integrate NYM as a centralized swap provider. NYM provides its own
liquidity, so every swap must have the NYM asset on one side; the plugin
gates this locally before calling the API.

NYM exposes an Edge-shaped partner API: native-unit amounts (no
denomination conversion) and asset references of chainNetwork + optional
EVM chainId + 0x contract-address tokenId. Sepolia is represented as
chainNetwork 'ethereum' with chainId 11155111. The plugin enforces the
min/max limits returned by the quote endpoint and parses NYM's JSON error
bodies into the appropriate swap errors. Testnet-only for now.

Validated end-to-end (quote + order) against the NYM testnet API.
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.

1 participant