Skip to content

Add NYM Swap (nymswap) reporting plugin#226

Open
j0ntz wants to merge 1 commit into
masterfrom
jon/nymswap-reports
Open

Add NYM Swap (nymswap) reporting plugin#226
j0ntz wants to merge 1 commit into
masterfrom
jon/nymswap-reports

Conversation

@j0ntz

@j0ntz j0ntz commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Description

Add a new reports-server partner plugin nymswap so NYM swaps surface in the reports
pipeline. Asana: https://app.asana.com/0/1215088146871429/1216728226940270

The reporting contract is confirmed against NYM's live "Edge Partner" API (OpenAPI at
https://nym-swap-api.nymtech.cc/api/docs/) and a live query run under the GUI's existing
NYM swap key (NYM_SWAP_INIT.apiKey), which had real order history to read.

What it does:

  • src/partners/nym.ts - queryNym walks GET /api/partner/v1/reports/transactions
    (auth x-api-key, params startDate/endDate/limit<=500/cursor, envelope
    { transactions, nextCursor }), following nextCursor until null with a 5-day lookback,
    retry/snooze on throttling, and a conservative progress save (advance latestIsoDate only
    after the full cursor walk completes). processNymTx maps each EdgeTransactionRecord
    into StandardTx.
  • Native-unit string amounts are converted to major units via NYM's own
    GET /api/partner/v1/currencies decimals (keyed by currency code + tokenId), with a
    built-in fallback map for the current asset set if that fetch fails.
  • Report timestamp keys off createdDate because NYM leaves completedDate null on most
    completed orders (observed 7 of 8 in the live sample).
  • Status enum mapped pending/processing/infoNeeded/expired/refunded/completed to Edge
    StandardTx statuses.
  • Registered nymswap in src/queryEngine.ts and src/demo/partners.ts. The pluginId
    is nymswap, matching the NYM swap plugin in edge-exchange-plugins.
  • test/nym.test.ts - unit tests for processNymTx using real captured EdgeTransactionRecord
    payloads (amount decimal conversion, unknown-status degradation, null-txid tolerance,
    unknown-asset skip, non-numeric amount clamp).

Credentials are human/ops only for production (partner dashboard + production CouchDB
reports_apps partnerIds.nymswap.apiKeys); no production credential is fetched or set by
this code. The live verification used the GUI's existing swap key at the operator's request.

Open questions raised with the NYM team (see the Asana task):

  • completedDate is null on completed orders - should reporting rely on createdDate for
    the settlement time, or will completedDate be populated?
  • sourceNetwork/destinationNetwork casing is inconsistent (ethereum vs BTC/NYM) and
    does not map 1:1 to Edge plugin ids; chain plugin fields are left undefined for now.
  • Confirm the production reporting key is the same key/scheme as the swap key, or a distinct
    reporting credential.

Testing:

  • Live query against GET /api/partner/v1/reports/transactions under the GUI key returned
    21 real records (8 completed, 13 expired); the response matched the OpenAPI TransactionReport
    schema exactly and drove the cleaner design.
  • Repo typecheck (tsc / build.types) clean of the new code; eslint clean on changed files.
  • test/nym.test.ts passes (5/5).
  • Note: the repo's existing mocha suite has 31 pre-existing failures (apiAnalytics + util
    date-math) unrelated to this change.

Note

Medium Risk
New external API integration affects reported swap amounts and timestamps (createdDate vs settlement); mis-scaled decimals are guarded by skipping unknown assets, but ops must configure the API key in CouchDB.

Overview
Adds NYM Swap (nymswap) to the reports pipeline so Edge can ingest partner swap history from NYM’s Partner API.

A new plugin in src/partners/nym.ts pages GET /api/partner/v1/reports/transactions with x-api-key, a 5-day lookback, cursor pagination, and retries; latestIsoDate advances only after the full cursor walk finishes so partial runs do not skip data. Native amount strings are scaled to major units using live /currencies decimals (with a static fallback), records map to StandardTx (status mapping, createdDate for timestamps because completedDate is often null), and bad rows are skipped instead of failing the whole page.

nymswap is wired into queryEngine and the demo partner list; CHANGELOG and test/nym.test.ts cover processNymTx conversion and edge cases.

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

Comment thread src/partners/nym.ts Outdated
@j0ntz
j0ntz force-pushed the jon/nymswap-reports branch from b6b27fd to caf38d4 Compare July 23, 2026 00:57
Comment thread src/partners/nym.ts Outdated
Comment thread src/partners/nym.ts
@j0ntz
j0ntz force-pushed the jon/nymswap-reports branch from caf38d4 to 0be7ad3 Compare July 23, 2026 01:01

@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 using default effort 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 0be7ad3. Configure here.

Comment thread src/partners/nym.ts
@j0ntz
j0ntz force-pushed the jon/nymswap-reports branch 2 times, most recently from fbc8882 to 971a2d7 Compare July 24, 2026 22:12
Query NYM's partner reporting API for completed swap orders and map them
into StandardTx, modeled on the clean shape of swapuz. Register nymswap in
queryEngine and the demo partners config. Add a transform unit test.

The reporting endpoint, auth scheme, and order field names are the
documented assumption to confirm with NYM; credentials are human/ops set.
@j0ntz
j0ntz force-pushed the jon/nymswap-reports branch from 971a2d7 to 834e37a Compare July 24, 2026 23:09
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