Skip to content

feat(creator): add key deprecation and buyback endpoint with holder notifications - #892

Closed
TS-mfon wants to merge 1 commit into
accesslayerorg:mainfrom
TS-mfon:fix/issue-872-deprecate-endpoint
Closed

TS-mfon wants to merge 1 commit into
accesslayerorg:mainfrom
TS-mfon:fix/issue-872-deprecate-endpoint

Conversation

@TS-mfon

@TS-mfon TS-mfon commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the creator key deprecation endpoint, enabling key creators to initiate an orderly buyback wind-down with solvency verification, on-chain deprecation contract execution, trading pause, and asynchronous notification dispatch to all key holders.

Closes #872


Implementation Details

  • Endpoint: POST /api/v1/creator/:keyId/deprecate
  • Authentication & Validation:
    • Enforces caller is the creator of the key (requireKeyCreator('keyId')).
    • Enforces buybackPricePerKey is a positive integer > 0 (returns 422 for 0, negative, or non-integer).
    • Checks creator's XLM wallet balance to verify solvency for the full buyback obligation (circulatingSupply * buybackPricePerKey). Returns 400 INSUFFICIENT_BALANCE if underfunded.
  • Contract Dispatch & Lifecycle:
    • Dispatches deprecate_key contract call via deprecateGateway.deprecateKey.
    • Updates CreatorProfile.status = 'Deprecated' and sets tradingPaused = true.
    • Records KEY_DEPRECATED entry in Activity table.
  • Holder Notification Dispatch:
    • Queries all current holders with non-zero balance (balance > 0).
    • Uses getRedisClient() to enqueue structured notification events to queue:notifications.
  • Database Migration:
    • Added migration SQL in prisma/migrations/20260924_add_key_deprecation/migration.sql for status column and KEY_DEPRECATED enum.

Testing

  • Unit test suite added in src/modules/creator/__tests__/creator-deprecate.test.ts verifying:
    • 401 on unauthenticated calls.
    • 403 when caller is not the creator of the key.
    • 422 when buyback price is 0, negative, or non-integer.
    • 400 when creator has insufficient XLM balance.
    • 200 on valid requests: executes contract call, updates status to Deprecated, sets tradingPaused, creates activity record, and enqueues notifications to Redis for each holder.
  • All 6 unit tests pass; TypeScript build passes cleanly.

…otifications

Closes accesslayerorg#872

- Add POST /api/v1/creator/:keyId/deprecate with creator authentication
- Validate buybackPricePerKey is a positive integer > 0
- Verify creator XLM balance covers circulatingSupply * buybackPricePerKey
- Submit deprecate_key contract call via deprecateGateway
- Update CreatorProfile.status to Deprecated and set tradingPaused to true
- Log KEY_DEPRECATED activity record
- Enqueue holder notifications to Redis queue:notifications via getRedisClient
- Add database migration for status column and KEY_DEPRECATED enum
Copilot AI lite review requested due to automatic review settings September 24, 2026 16:59

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@TS-mfon

TS-mfon commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #1007, which carries all four issues (#866, #869, #870, #872) on one branch rebased on latest main.

Splitting these four across separate PRs meant they collided with each other: all four touch src/modules/keys/keys.routes.ts, and #869/#872 both touch src/modules/creator/creator.routes.ts and the prisma schema, so whichever merged first would break the rest. #1007 also addresses the Copilot findings raised here — the migration moved to prisma/schema/migrations and non-finite milestone values are now rejected.

Closing this one in favour of #1007.

@TS-mfon TS-mfon closed this Oct 1, 2026
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.

Add a key deprecation endpoint for creators to initiate a buyback wind-down of their key

2 participants