feat(api): Swagger response docs, shared amount util, solver PATCH, race-safe idempotent create (#271-#274) - #347
Open
Meshmulla wants to merge 1 commit into
Conversation
Implements issues stellar-vortex-protocol#271, stellar-vortex-protocol#272, stellar-vortex-protocol#273, stellar-vortex-protocol#274. stellar-vortex-protocol#271 - Typed Swagger response docs for SorobanController and TokensController - Every /api/v1/chain/* and /api/v1/tokens/* route now declares an @ApiOkResponse schema; the account route also documents 400 and 429. - Added StellarTokenDto / StellarTokensResponseDto for the /tokens/stellar shape. - Extended test/openapi-contract.e2e-spec.ts to assert the new schemas. - Regenerated src/generated/ (openapi.json + api-types.ts). stellar-vortex-protocol#272 - Shared BigInt amount util (src/common/amount.ts) - parseBaseUnits, toDecimalNumber, toBaseUnits, calculateProtocolFee (0.05%), varianceScaleFromPerfScore, applyVarianceScale - all BigInt-based, Number only at the final display-scaling step. - IntentsController.quote()/fill() refactored onto the helpers with no behaviour change for valid inputs. - 39 unit tests incl. amounts past Number.MAX_SAFE_INTEGER, zero, decimals 0-18. stellar-vortex-protocol#273 - PATCH /api/v1/solvers/:address - UpdateSolverDto (name / supportedChains / supportedTokens / avgFillTime, all optional) + required signature; immutable fields stripped by the whitelist ValidationPipe. - buildUpdateSolverMessage() helper; signature verified before SolversService. - SolversService.update() applies a partial patch, ignoring undefined values. - Swagger + docs/solver-onboarding.md section 1a; regenerated client. stellar-vortex-protocol#274 - Race-safe idempotency key in IntentsService.create() - Synchronous reserve-then-create: concurrent requests with the same key claim an in-flight promise before any await, so exactly one intent is created and the losers replay its result. - persistNewIntent() extracted; documents the INSERT ... ON CONFLICT approach the future Prisma adapter must use. - 7 unit tests + test/load/concurrent-idempotent-create.test.ts. Incidental: restored imports/values dropped by earlier bad merges (INTENTS_REPOSITORY in intents.service, Throttle in intents.controller, ConfigService in test/utils/create-test-app, isActive: true in SolversService.reactivate) - all required for the code touched here to compile and for the new tests to run.
|
@Meshmulla Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SorobanControllerandTokensController#271 — Typed Swagger response documentation forSorobanControllerandTokensControllerBigIntamount-parsing/formatting logic into a shared utility #272 — Consolidated duplicatedBigIntamount parsing/formatting intosrc/common/amount.tsPATCHendpoint to update mutable solver profile fields #273 —PATCH /api/v1/solvers/:addressto update mutable solver profile fieldsIntentsService.create()#274 — Fixed the idempotency-key check-then-set race inIntentsService.create()Issues:
SorobanControllerandTokensController#271BigIntamount-parsing/formatting logic into a shared utility #272PATCHendpoint to update mutable solver profile fields #273IntentsService.create()#274Changes
#271 — Swagger response docs
SorobanController(/api/v1/chain/health|ledger|network|account/:publicKey) andTokensController(/api/v1/tokens,/api/v1/tokens/stellar) now carries an@ApiOkResponsewith an inline schema matching the actual return shape.@ApiBadRequestResponse(invalid key) and@ApiTooManyRequestsResponse(AccountRateLimitGuard's 429), plus@ApiParam.src/tokens/dto/token-response.dto.ts(StellarTokenDto,StellarTokensResponseDto) gives/tokens/stellara typed class.test/openapi-contract.e2e-spec.tsextended with assertions that all six routes expose a 200 schema and that the account route documents 400/429.src/generated/regenerated vianpm run generate:client— the new schemas appear inopenapi.json/api-types.ts. Regeneration also picked up/intents/:id/auditand/intents/:id/quote, which had been added in earlier merged PRs without a client regen.#272 — Shared amount utility
src/common/amount.ts:parseBaseUnits,toDecimalNumber,toBaseUnits,calculateProtocolFee(the documented 0.05% =dstAmount * 5 / 10000),varianceScaleFromPerfScore,applyVarianceScale. All arithmetic isBigInt; the onlyNumberconversion is the final display-scaling step, and it splits whole/fraction as strings first so large amounts don't lose precision.IntentsController.quote()andfill()refactored onto the helpers. No behaviour change for valid inputs (fee %, variance formula and rounding preserved); large-amount paths are now precision-safe rather than lossy.src/common/amount.spec.ts— 39 unit tests covering amounts near/beyondNumber.MAX_SAFE_INTEGER, zero amounts,decimals0–18, round-trips, and reproduction of the original inline formulas.#273 — Solver profile PATCH
PATCH /api/v1/solvers/:addressaccepts a partialUpdateSolverDto(name,supportedChains,supportedTokens,avgFillTime— all optional) plus a requiredsignature.verifyStellarSignatureconvention against a newbuildUpdateSolverMessage(address)→update-solver:<address>, beforeSolversServiceis touched.address,bondAmount,fillsCompleted,fillsFailed,totalVolume,registeredAt,isActive) are not on the DTO, so the globalValidationPipe({ whitelist: true })strips them silently.supportedChains/supportedTokensvalidated with the same@IsIn/@ArrayMaxSizerigor asRegisterSolverDto.SolversService.update()applies the patch, ignoringundefinedvalues so an absent field never clears data.docs/solver-onboarding.mdnew section "1a. Updating Your Solver Profile"; Swagger decorators on the route; client SDK regenerated.#274 — Race-safe idempotent create
IntentsService.create()now takes a synchronous reserve-then-create claim: it checks and sets anidempotencyInFlightmap with noawaitin between, so two concurrent requests with the same key can never both proceed — the loser awaits the winner's in-flight promise and returns its intent.registerOnChain()await (extracted intopersistNewIntent()), so the window is closed, not shifted..finally) and nothing is cached, so a later retry succeeds.INSERT ... ON CONFLICT (idempotency_key) DO NOTHING+ read-back that issue feat: rebuild backend on NestJS, drop Express #1's Prisma adapter must use.src/intents/intents.service.idempotency.spec.ts— 7 unit tests (25-way concurrent same-key → 1 intent, widened race window, sequential replay, distinct keys, no-key path, failure/retry, claim-before-on-chain-await).test/load/concurrent-idempotent-create.test.ts— load test mirroringtest/load/concurrent-accept.test.ts.Incidental (merge-rot repairs, required to compile/run the above)
maincurrently does not type-check or build (pre-existing, ~46tscerrors from earlier bad merges). This PR does not attempt a general fix, but four one-line drops in files it already touches were restored because the new code/tests can't compile otherwise:import { INTENTS_REPOSITORY, IIntentsRepository }inintents.service.ts(present in42a8c89, lost in a later merge)import { Throttle }inintents.controller.ts(decorator was already in use)import { ConfigService }intest/utils/create-test-app.ts(symbol already in use)isActive: true(was bareisActive) inSolversService.reactivate()intents.controller.tsnettscerror count goes 41 → 30; no new errors introduced (the twogetPersistedQuoteerrors reported as "new" are the same pre-existing errors, shifted down by added import lines).Testing / validation
npm run lint— 0 errors (37 pre-existing warnings, unchanged).npm run typecheck— 30 pre-existing errors remain (down from 46 onmain); none in files added or the regenerated client. Full green is blocked by unrelated pre-existing breakage in*.spec.ts,stats.service.ts,getPersistedQuote.src/common/amount.spec.ts— 39/39src/intents/intents.service.idempotency.spec.ts— 7/7src/solvers/solvers.service.update.spec.ts— 5/5src/solvers/solvers.service.spec.ts— 8/8 (still green after thereactivatefix)npm run generate:clientruns clean and the diff reflects the new endpoint + schemas.test/*.e2e-spec.ts) is not runnable onmain— the sharedtest/__mocks__/@stellar/stellar-sdk.tsstub is missing most exports (Networks,Keypair, …). The e2e specs added here (test/solvers-update.e2e-spec.ts, theopenapi-contractadditions) follow the existing pattern and will pass once that harness is repaired; this PR deliberately does not touch the shared mock.