# Creator Royalty Service

Automates revenue sharing for Lilith creators by orchestrating royalty
schedules, sale-based distributions, scheduled payouts, and compliance logging.

## Pipeline

1. **Compliance auditor** – validates schedule definitions and payout
   distributions.
2. **Schedule registry** – persists royalty schedules and version revisions.
3. **Share calculator** – computes dynamic payout allocations per sale.
4. **Scheduled payout calculator** – aggregates outstanding royalties for
   periodic runs.
5. **Payment executor** – dispatches on-chain transactions for recipients.
6. **Royalty ledger** – records distributions and emits audit events.
7. **Payout scheduler** – determines next payout execution window.
8. **Notification + analytics** – informs stakeholders and publishes telemetry.

## Usage

```ts
import { createCreatorRoyaltyService } from './service';

const service = createCreatorRoyaltyService({
  scheduleRegistry,
  shareCalculator,
  scheduledPayoutCalculator,
  paymentExecutor,
  complianceAuditor,
  royaltyLedger,
  payoutScheduler,
  notificationService,
  analyticsReporter,
});

const { schedule } = await service.createSchedule({
  metadata: {
    assetId: 'sacred-art-108',
    assetType: 'sacred_art',
    title: 'Lilith Moon Bloom',
    createdBy: '0xLilith',
  },
  recipients: [
    { address: '0xCreator', percentage: 70, role: 'creator' },
    { address: '0xCollaborator', percentage: 20, role: 'collaborator' },
    { address: '0xPlatform', percentage: 10, role: 'platform' },
  ],
  allocationStrategy: 'fixed_split',
  minPayoutThreshold: '100000000000000000',
  chainId: 137,
  payoutFrequency: 'weekly',
});
```

## Tests

```bash
npx jest --config apps/lilith/svc-creator-royalty/jest.config.cjs --runInBand
```
