feat(keys): build on-chain metadata sync service for creator key contracts (#986) - #1004
Merged
Chucks1093 merged 1 commit intoSep 30, 2026
Conversation
|
@bamiebot-maker 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
Implements a background on-chain metadata synchronization service for creator key contracts, addressing #986. The service synchronizes on-chain metadata (
name,symbol,description,image_cid) into the off-chain API metadata cache, resolves IPFS CIDs to Pinata gateway URLs, triggers automatic sync on key creation and onMetadataUpdatedcontract events, and exposesGET /keys/:keyId/metadatawith an accuratestaleflag when synchronization is delayed.Key Changes
Key Metadata Storage Model:
KeyMetadatamodel inprisma/schema/key-metadata.prismastoringkeyId,keyAddress,name,symbol,description,imageCid,imageUrl,lastSyncedAt,contractUpdatedAt,txHash, andledger.IPFS / Pinata Gateway URL Resolution:
resolvePinataGatewayUrl(imageCid, gatewayBaseUrl)handling raw CIDs (Qm...,bafy...),ipfs://protocol URIs, and/ipfs/prefixes, mapping to configuredPINATA_GATEWAY_URL(https://gateway.pinata.cloud/ipfs/${cid}).Background On-Chain Metadata Synchronization Service:
syncKeyMetadata(keyIdentifier, onChainData?, eventContext?)insrc/modules/keys/key-metadata-sync.service.ts.setOnChainMetadataFetcher) and fallback to contract storage readers.Event-Driven Synchronization Triggers:
key_registeredevents viainitKeyCreationMetadataSync()on server boot to automatically initiate metadata synchronization upon key contract registration.handleMetadataUpdatedChainEventandprocessMetadataUpdatedEventsinsrc/modules/indexer/key-metadata-indexer.service.tsto trigger / schedule re-sync within 60 seconds of on-chain event receipt.Metadata API Endpoint (
GET /api/v1/keys/:keyId/metadata):src/modules/keys/keys.routes.tsreturning synced metadata.Date.now() - lastSyncedAt > METADATA_STALENESS_THRESHOLD_MS(default: 10 minutes) and includesstale: booleanin response.Configuration:
PINATA_GATEWAY_URLandMETADATA_STALENESS_THRESHOLD_MStosrc/config.schema.ts.Automated Testing:
src/modules/keys/key-metadata-sync.service.test.ts(12 tests) verifying gateway resolution, sync execution, staleness detection, event handling, and key registration listeners.src/modules/keys/key-metadata.routes.test.ts(3 tests) verifying 200 responses, stale flag detection, and 404 handling.Verification
pnpm test src/modules/keys/key-metadata-sync.service.test.ts src/modules/keys/key-metadata.routes.test.ts: 15/15 tests passing.pnpm build: TypeScript compilation succeeded with 0 errors.pnpm eslint ...: Lint checks passed with 0 errors.Closes #986