Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1225,3 +1225,173 @@ model BridgeRetry {
@@index([messageId])
@@map("bridge_retries")
}

// ─── Issue #462: Webhook Subscription Manager ───────────────────────────────────

model WebhookSubscription {
id String @id @default(uuid())
tenantId String @map("tenant_id")
eventTypes String[] @map("event_types")
filterExpr String? @map("filter_expr")
targetUrl String @map("target_url")
description String?
status SubscriptionStatus @default(active)
version Int @default(1) @map("version")
lastDelivered DateTime? @map("last_delivered")
deliveryCount Int @default(0) @map("delivery_count")
successCount Int @default(0) @map("success_count")
failCount Int @default(0) @map("fail_count")
avgLatency Float? @map("avg_latency")
pausedAt DateTime? @map("paused_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")

deliveries WebhookSubscriptionDelivery[]

@@index([tenantId])
@@index([status])
@@index([tenantId, status])
@@map("webhook_subscriptions")
}

model WebhookSubscriptionDelivery {
id String @id @default(uuid())
subscriptionId String @map("subscription_id")
eventType String @map("event_type")
payload Json
status DeliveryStatus @default(pending)
statusCode Int? @map("status_code")
latencyMs Int? @map("latency_ms")
errorMessage String? @map("error_message")
attemptCount Int @default(0) @map("attempt_count")
createdAt DateTime @default(now()) @map("created_at")
completedAt DateTime? @map("completed_at")

subscription WebhookSubscription @relation(fields: [subscriptionId], references: [id], onDelete: Cascade)

@@index([subscriptionId])
@@index([status])
@@index([createdAt])
@@map("webhook_subscription_deliveries")
}

// ─── Issue #463: Revenue Sharing Pool ───────────────────────────────────────────

model RevenuePool {
id String @id @default(uuid())
tenantId String @map("tenant_id")
name String
chain String @default("soroban")
contractId String @map("contract_id")
status PoolStatus @default(active)
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
deletedAt DateTime? @map("deleted_at")

recipients RevenueRecipient[]
distributions RevenueDistribution[]

@@index([tenantId])
@@map("revenue_pools")
}

model RevenueRecipient {
id String @id @default(uuid())
poolId String @map("pool_id")
wallet String
ratioBps Int @map("ratio_bps")
accumulated String @default("0") @map("accumulated")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

pool RevenuePool @relation(fields: [poolId], references: [id], onDelete: Cascade)

@@unique([poolId, wallet])
@@map("revenue_recipients")
}

model RevenueDistribution {
id String @id @default(uuid())
poolId String @map("pool_id")
txHash String @map("tx_hash")
amount String @map("amount")
status DistributionStatus @default(pending)
createdAt DateTime @default(now()) @map("created_at")

pool RevenuePool @relation(fields: [poolId], references: [id], onDelete: Cascade)

@@index([poolId])
@@map("revenue_distributions")
}

// ─── Issue #464: EVM Paymaster / ERC-4337 ───────────────────────────────────────

model PaymasterBudget {
id String @id @default(uuid())
tenantId String @map("tenant_id")
chainId Int @map("chain_id")
token String
balance String @default("0")
totalDeposited String @default("0") @map("total_deposited")
totalUsed String @default("0") @map("total_used")
maxGasPerTx String? @map("max_gas_per_tx")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")

@@unique([tenantId, chainId, token])
@@map("paymaster_budgets")
}

model UserOperation {
id String @id @default(uuid())
userOpHash String @unique @map("user_op_hash")
sender String
nonce String
paymaster String
mode String @default("verifying")
actualGasCost String? @map("actual_gas_cost")
status UserOpStatus @default(pending)
txHash String? @map("tx_hash")
errorMsg String? @map("error_msg")
createdAt DateTime @default(now()) @map("created_at")
completedAt DateTime? @map("completed_at")

@@index([sender])
@@index([status])
@@index([createdAt])
@@map("user_operations")
}

// ─── New Enums ──────────────────────────────────────────────────────────────────

enum SubscriptionStatus {
active
paused
disabled
}

enum DeliveryStatus {
pending
delivered
failed
retrying
}

enum PoolStatus {
active
paused
archived
}

enum DistributionStatus {
pending
completed
failed
}

enum UserOpStatus {
pending
completed
failed
}
Loading
Loading