feat(keys,creator): add TWAP, graduated curve config, trade simulation and deprecation endpoints - #1007
Merged
Chucks1093 merged 1 commit intoOct 1, 2026
Conversation
…n and deprecation endpoints Closes accesslayerorg#866 Closes accesslayerorg#869 Closes accesslayerorg#870 Closes accesslayerorg#872 Consolidates the four endpoints onto one branch rebased on latest main, so they land together instead of conflicting in keys.routes.ts, creator.routes.ts and the prisma schema. accesslayerorg#866 - GET /api/v1/keys/:keyId/twap?window=1h|24h|7d Served from a new key-twap-window.service.ts so it does not clobber the GET /:keyId/price/twap service added by accesslayerorg#978 (1h/4h/24h). Returns twapPrice, spotPrice, windowLedgers and snapshotCount, with twapPrice null below two snapshots. 60s Redis TTL, invalidated from the trade indexer and on every price-snapshot write including the first. accesslayerorg#869 - POST /api/v1/creator/:keyId/curve, GET /api/v1/keys/:keyId/curve-config Creator-only milestone config, max 5 milestones, strictly ascending positive thresholds, integer exponents 1..5. accesslayerorg#870 - GET /api/v1/keys/:keyId/simulate?quantity=N&side=buy|sell Closed-form integral preview with batch quantities, batch and quantity ceilings, and rejection when a sell exceeds circulating supply. accesslayerorg#872 - POST /api/v1/creator/:keyId/deprecate Creator-only buyback wind-down with solvency check, status transition, trading pause and queued holder notifications. Schema: adds GRADUATED_CURVE_CONFIGURED and KEY_DEPRECATED activity types, and curveMilestones, baseExponent and status on CreatorProfile. The migration lives in prisma/schema/migrations, which is the directory package.json points Prisma at, rather than prisma/migrations. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Oct 1, 2026
5 tasks
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.
Closes #866
Closes #869
Closes #870
Closes #872
Consolidates the four creator-key endpoints onto a single branch rebased on latest
main. Opened as one PR deliberately: all four touchsrc/modules/keys/keys.routes.ts, and #869/#872 both touchsrc/modules/creator/creator.routes.tsplusprisma/schema/{activity,creator}.prisma, so as separate PRs they conflict with each other on merge. This supersedes #889, #890, #891 and #892.#866 — TWAP endpoint
GET /api/v1/keys/:keyId/twap?window=1h|24h|7dReturns
twapPrice,spotPrice,windowLedgers,snapshotCount;twapPriceisnullwhen fewer than two snapshots fall in the window. 60s Redis TTL, invalidated from the trade indexer and on every price-snapshot write.Note on overlap with #978:
mainalready hasGET /:keyId/price/twap(windows1h|4h|24h, returnstwap/deltaPct/stale) from #978 (which resolved issue 963). That is a different endpoint contract from the one #866 specifies. Rather than overwrite it, #866's implementation lives in a newsrc/modules/keys/key-twap-window.service.tsand the existingkey-twap.service.tsis untouched. If you'd rather have one endpoint than two, say so and I'll collapse them.#869 — Graduated curve configuration
POST /api/v1/creator/:keyId/curve(creator-only) andGET /api/v1/keys/:keyId/curve-config(public).Max 5 milestones,
supplyThresholdpositive and strictly ascending,exponentan integer in 1..5.#870 — Trade simulation
GET /api/v1/keys/:keyId/simulate?quantity=N&side=buy|sellClosed-form integral evaluation (O(1), no discrete step loop), comma-separated batch quantities, batch ceiling of 20 and per-entry ceiling of 1,000,000, and a 422 when a sell exceeds circulating supply. 15s Redis TTL.
#872 — Key deprecation and buyback
POST /api/v1/creator/:keyId/deprecate(creator-only)Requires
buybackPricePerKeyto be a positive integer, verifies the creator's XLM balance coverscirculatingSupply * buybackPricePerKey(400INSUFFICIENT_BALANCEotherwise), setsstatus = 'Deprecated'andtradingPaused = true, recordsKEY_DEPRECATED, and queues holder notifications.Review feedback carried over from #890
prisma/schema/migrations/20260930000000_add_graduated_curve_and_key_status/, notprisma/migrations/.package.jsonpoints Prisma at./prisma/schema, so the previous location would not have been picked up byprisma migrate deploy.1e400(parsed asInfinity) is refused rather than reaching the gateway.Still open from the #889/#890 reviews
curveGateway.configureGraduatedCurveand the TWAPget_twappath still log rather than submitting to Soroban, so both are effectively DB-backed. Wiring them to a real contract client is a larger change than these four endpoints; happy to do it here or in a follow-up, your call.Schema
ActivityType: addsGRADUATED_CURVE_CONFIGURED,KEY_DEPRECATED.CreatorProfile: addscurveMilestones(Json?),baseExponent(Int, default 1),status(String, default"Active").Verification