{
  "openapi": "3.1.0",
  "info": {
    "title": "DobProtocol Agent API",
    "description": "Programmatic access to the DobProtocol RWA tokenization ecosystem. Enables AI agents and automated workflows to discover pools, trade RWA tokens, manage distributions, and receive real-time webhook events.",
    "version": "1.0.0",
    "contact": {
      "name": "DobProtocol",
      "url": "https://docs.dobprotocol.com/agent-api",
      "email": "security@dobprotocol.com"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://home.dobprotocol.com/api/agent",
      "description": "Production"
    }
  ],
  "security": [
    {
      "apiKey": []
    }
  ],
  "paths": {
    "/auth/keys": {
      "post": {
        "operationId": "createApiKey",
        "summary": "Create API key",
        "description": "Generate a scoped API key for agent access. Requires a JWT bearer token from wallet authentication.",
        "tags": ["Auth"],
        "security": [
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["label", "scopes"],
                "properties": {
                  "label": {
                    "type": "string",
                    "description": "Human-readable label for the key",
                    "example": "my-trading-bot"
                  },
                  "scopes": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": ["read", "trade"]
                    },
                    "description": "Permission scopes: read (pools, portfolio, webhooks) and/or trade (marketplace ops)",
                    "example": ["read", "trade"]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "API key created (shown once)",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ApiKeyResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/pools": {
      "get": {
        "operationId": "listPools",
        "summary": "List pools",
        "description": "Search and filter tokenized asset distribution pools with pagination.",
        "tags": ["Pools"],
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Pool name or ticker search"
          },
          {
            "name": "network_id",
            "in": "query",
            "schema": { "type": "integer" },
            "description": "Filter by network (e.g. 10 = Stellar Mainnet)"
          },
          {
            "name": "access_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["rtj", "p", "qr", "stk"]
            },
            "description": "Filter by access type: rtj (request/airdrop), p (buy), qr (QR code), stk (staking)"
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["created_desc", "created_asc", "apr_desc", "apr_asc", "members_desc", "members_asc"]
            }
          },
          {
            "$ref": "#/components/parameters/page"
          },
          {
            "$ref": "#/components/parameters/limit"
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated pool list",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/Pool" }
                        },
                        "meta": { "$ref": "#/components/schemas/PaginationMeta" }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": { "$ref": "#/components/responses/Unauthorized" }
        }
      }
    },
    "/pools/featured": {
      "get": {
        "operationId": "getFeaturedPools",
        "summary": "Get featured pools",
        "description": "Curated list of featured RWA token pools.",
        "tags": ["Pools"],
        "parameters": [
          {
            "name": "network_id",
            "in": "query",
            "schema": { "type": "integer" }
          }
        ],
        "responses": {
          "200": {
            "description": "Featured pools",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": {
                            "allOf": [
                              { "$ref": "#/components/schemas/Pool" },
                              {
                                "type": "object",
                                "properties": {
                                  "featured_reason": { "type": "string" }
                                }
                              }
                            ]
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pools/crowdfunding": {
      "get": {
        "operationId": "getCrowdfundingPools",
        "summary": "Active crowdfunding pools",
        "description": "List pools with active crowdfunding campaigns.",
        "tags": ["Pools"],
        "parameters": [
          {
            "name": "network_id",
            "in": "query",
            "schema": { "type": "integer" }
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["deadline_asc", "deadline_desc", "progress_desc"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Crowdfunding pools",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/CrowdfundingPool" }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pools/{address}": {
      "get": {
        "operationId": "getPool",
        "summary": "Pool details",
        "description": "Get detailed information about a specific pool including distribution config and verification status.",
        "tags": ["Pools"],
        "parameters": [
          {
            "name": "address",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "network_id",
            "in": "query",
            "schema": { "type": "integer" },
            "description": "Required if address exists on multiple networks"
          }
        ],
        "responses": {
          "200": {
            "description": "Pool detail",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/PoolDetail" }
                      }
                    }
                  ]
                }
              }
            }
          },
          "404": { "$ref": "#/components/responses/NotFound" }
        }
      }
    },
    "/pools/{address}/members": {
      "get": {
        "operationId": "getPoolMembers",
        "summary": "Pool members",
        "description": "List members and their share allocations for a pool.",
        "tags": ["Pools"],
        "parameters": [
          {
            "name": "address",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "network_id",
            "in": "query",
            "schema": { "type": "integer" }
          },
          { "$ref": "#/components/parameters/page" },
          { "$ref": "#/components/parameters/limit" }
        ],
        "responses": {
          "200": {
            "description": "Pool members",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/PoolMember" }
                        },
                        "meta": { "$ref": "#/components/schemas/PaginationMeta" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pools/{address}/distributions": {
      "get": {
        "operationId": "getPoolDistributions",
        "summary": "Distribution history",
        "description": "Query distribution rounds for a pool with status filtering.",
        "tags": ["Pools"],
        "parameters": [
          {
            "name": "address",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "network_id",
            "in": "query",
            "schema": { "type": "integer" }
          },
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["completed", "pending", "expired"]
            }
          },
          { "$ref": "#/components/parameters/page" },
          { "$ref": "#/components/parameters/limit" }
        ],
        "responses": {
          "200": {
            "description": "Distributions",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/Distribution" }
                        },
                        "meta": { "$ref": "#/components/schemas/PaginationMeta" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/pools/{address}/events": {
      "get": {
        "operationId": "getPoolEvents",
        "summary": "Pool events",
        "description": "Retrieve on-chain event log for a pool.",
        "tags": ["Pools"],
        "parameters": [
          {
            "name": "address",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "network_id",
            "in": "query",
            "schema": { "type": "integer" }
          },
          {
            "name": "event_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["init", "distribute", "claim", "transfer_shares", "withdraw", "lock", "set_admin"]
            }
          },
          { "$ref": "#/components/parameters/page" },
          { "$ref": "#/components/parameters/limit" }
        ],
        "responses": {
          "200": {
            "description": "Pool events",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/PoolEvent" }
                        },
                        "meta": { "$ref": "#/components/schemas/PaginationMeta" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/listings": {
      "get": {
        "operationId": "listMarketplaceListings",
        "summary": "All active listings",
        "description": "Browse all active RWA token listings on the marketplace.",
        "tags": ["Marketplace"],
        "parameters": [
          {
            "name": "network_id",
            "in": "query",
            "required": true,
            "schema": { "type": "integer" }
          },
          {
            "name": "payment_token",
            "in": "query",
            "schema": { "type": "string" },
            "description": "Filter by payment token symbol"
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["created_desc", "created_asc", "price_asc", "price_desc"],
              "default": "created_desc"
            }
          },
          { "$ref": "#/components/parameters/page" },
          { "$ref": "#/components/parameters/limit" }
        ],
        "responses": {
          "200": {
            "description": "Active listings",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/Listing" }
                        },
                        "meta": { "$ref": "#/components/schemas/PaginationMeta" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/listings/{poolAddress}": {
      "get": {
        "operationId": "getPoolListings",
        "summary": "Pool listings",
        "description": "Get active marketplace listings for a specific pool.",
        "tags": ["Marketplace"],
        "parameters": [
          {
            "name": "poolAddress",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "network_id",
            "in": "query",
            "required": true,
            "schema": { "type": "integer" }
          },
          {
            "name": "sort",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": ["price_asc", "price_desc", "created_desc"],
              "default": "price_asc"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Pool listings",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/Listing" }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/stats/{poolAddress}": {
      "get": {
        "operationId": "getMarketplaceStats",
        "summary": "Marketplace stats for pool",
        "description": "Get trading volume, floor price, and listing statistics for a pool.",
        "tags": ["Marketplace"],
        "parameters": [
          {
            "name": "poolAddress",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          },
          {
            "name": "network_id",
            "in": "query",
            "required": true,
            "schema": { "type": "integer" }
          }
        ],
        "responses": {
          "200": {
            "description": "Marketplace stats",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/MarketplaceStats" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/prepare-buy": {
      "post": {
        "operationId": "prepareBuy",
        "summary": "Prepare buy transaction",
        "description": "Generate an unsigned XDR transaction to buy shares from a listing. XDR expires after 10 minutes.",
        "tags": ["Marketplace"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["listing_id", "network_id"],
                "properties": {
                  "listing_id": {
                    "type": "string",
                    "description": "The sale_address of the listing"
                  },
                  "amount": {
                    "type": "integer",
                    "description": "Number of shares to buy (optional, defaults to all)"
                  },
                  "network_id": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Unsigned XDR transaction",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/PreparedTransaction" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/submit-buy": {
      "post": {
        "operationId": "submitBuy",
        "summary": "Submit signed buy transaction",
        "description": "Submit a signed XDR transaction to complete a share purchase.",
        "tags": ["Marketplace"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SignedXdrRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transaction submitted",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/TransactionResult" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/prepare-list": {
      "post": {
        "operationId": "prepareList",
        "summary": "Prepare list-shares transaction",
        "description": "Generate an unsigned XDR to list shares for sale on the marketplace.",
        "tags": ["Marketplace"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["pool_address", "shares_amount", "price_per_share", "payment_token", "network_id"],
                "properties": {
                  "pool_address": { "type": "string" },
                  "shares_amount": { "type": "integer" },
                  "price_per_share": { "type": "string", "description": "Decimal format" },
                  "payment_token": { "type": "string", "description": "Token symbol" },
                  "network_id": { "type": "integer" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Unsigned XDR transaction",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/PreparedTransaction" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/submit-list": {
      "post": {
        "operationId": "submitList",
        "summary": "Submit signed list transaction",
        "description": "Submit a signed XDR to finalize a share listing.",
        "tags": ["Marketplace"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SignedXdrRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Listing created",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/TransactionResult" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/prepare-cancel": {
      "post": {
        "operationId": "prepareCancel",
        "summary": "Prepare cancel-listing transaction",
        "description": "Generate an unsigned XDR to cancel an active listing and return shares.",
        "tags": ["Marketplace"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["listing_id", "network_id"],
                "properties": {
                  "listing_id": { "type": "string", "description": "The sale_address of the listing" },
                  "network_id": { "type": "integer" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Unsigned XDR transaction",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/PreparedTransaction" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/marketplace/submit-cancel": {
      "post": {
        "operationId": "submitCancel",
        "summary": "Submit signed cancel transaction",
        "description": "Submit a signed XDR to finalize a listing cancellation.",
        "tags": ["Marketplace"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/SignedXdrRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Listing cancelled",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/TransactionResult" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/webhooks": {
      "get": {
        "operationId": "listWebhooks",
        "summary": "List webhooks",
        "description": "List all registered webhooks for your API key.",
        "tags": ["Webhooks"],
        "responses": {
          "200": {
            "description": "Webhook list",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "array",
                          "items": { "$ref": "#/components/schemas/Webhook" }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "createWebhook",
        "summary": "Register webhook",
        "description": "Register a new webhook endpoint to receive real-time event notifications. Max 5 per API key.",
        "tags": ["Webhooks"],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["url", "events", "secret"],
                "properties": {
                  "url": {
                    "type": "string",
                    "format": "uri",
                    "description": "HTTPS URL to receive webhook POST requests"
                  },
                  "events": {
                    "type": "array",
                    "items": { "$ref": "#/components/schemas/WebhookEventType" },
                    "description": "Event types to subscribe to"
                  },
                  "secret": {
                    "type": "string",
                    "minLength": 16,
                    "description": "Shared secret for HMAC-SHA256 signature verification"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Webhook created",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/Webhook" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/{id}": {
      "put": {
        "operationId": "updateWebhook",
        "summary": "Update webhook",
        "description": "Update webhook URL, events, secret, or active status.",
        "tags": ["Webhooks"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "url": { "type": "string", "format": "uri" },
                  "events": {
                    "type": "array",
                    "items": { "$ref": "#/components/schemas/WebhookEventType" }
                  },
                  "secret": { "type": "string", "minLength": 16 },
                  "is_active": { "type": "boolean" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Webhook updated",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": { "$ref": "#/components/schemas/Webhook" }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteWebhook",
        "summary": "Delete webhook",
        "description": "Permanently remove a webhook registration.",
        "tags": ["Webhooks"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook deleted",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "id": { "type": "string" },
                            "deleted": { "type": "boolean" }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/webhooks/{id}/test": {
      "post": {
        "operationId": "testWebhook",
        "summary": "Test webhook",
        "description": "Send a test event to a webhook endpoint to verify connectivity.",
        "tags": ["Webhooks"],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string" }
          }
        ],
        "responses": {
          "200": {
            "description": "Test result",
            "content": {
              "application/json": {
                "schema": {
                  "allOf": [
                    { "$ref": "#/components/schemas/SuccessResponse" },
                    {
                      "type": "object",
                      "properties": {
                        "data": {
                          "type": "object",
                          "properties": {
                            "delivery_status": { "type": "string", "enum": ["success", "failed"] },
                            "response_code": { "type": "integer" },
                            "response_time_ms": { "type": "integer" }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Agent API key (prefix: dob_ak_). Scopes: read, trade."
      },
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "JWT from wallet signature authentication. Used only for /auth/keys."
      }
    },
    "parameters": {
      "page": {
        "name": "page",
        "in": "query",
        "schema": { "type": "integer", "default": 1, "minimum": 1 }
      },
      "limit": {
        "name": "limit",
        "in": "query",
        "schema": { "type": "integer", "default": 20, "minimum": 1, "maximum": 100 }
      }
    },
    "schemas": {
      "SuccessResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "const": true }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean", "const": false },
          "error": {
            "type": "object",
            "properties": {
              "code": { "type": "string" },
              "message": { "type": "string" }
            }
          }
        }
      },
      "PaginationMeta": {
        "type": "object",
        "properties": {
          "page": { "type": "integer" },
          "limit": { "type": "integer" },
          "total": { "type": "integer" }
        }
      },
      "Pool": {
        "type": "object",
        "properties": {
          "address": { "type": "string" },
          "name": { "type": "string" },
          "ticker": { "type": "string" },
          "network_id": { "type": "integer" },
          "estimated_apr": { "type": "number" },
          "member_count": { "type": "integer" },
          "max_participants": { "type": "integer" },
          "token_to_distribute": { "type": "string" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "PoolDetail": {
        "allOf": [
          { "$ref": "#/components/schemas/Pool" },
          {
            "type": "object",
            "properties": {
              "creator_address": { "type": "string" },
              "allow_entry": { "type": "boolean" },
              "distribution_config": {
                "type": "object",
                "properties": {
                  "min_interval_seconds": { "type": "integer" },
                  "claim_delay_seconds": { "type": "integer" },
                  "round_expiry_seconds": { "type": "integer" }
                }
              },
              "next_distribution": { "type": "string", "format": "date-time", "nullable": true }
            }
          }
        ]
      },
      "CrowdfundingPool": {
        "allOf": [
          { "$ref": "#/components/schemas/Pool" },
          {
            "type": "object",
            "properties": {
              "target_amount": { "type": "string" },
              "raised_amount": { "type": "string" },
              "progress_percent": { "type": "number" },
              "contributor_count": { "type": "integer" },
              "deadline": { "type": "string", "format": "date-time" },
              "payment_token": { "type": "string" },
              "is_active": { "type": "boolean" }
            }
          }
        ]
      },
      "PoolMember": {
        "type": "object",
        "properties": {
          "user_address": { "type": "string" },
          "shares": { "type": "integer" },
          "participation_percent": { "type": "number" },
          "joined_at": { "type": "string", "format": "date-time" }
        }
      },
      "Distribution": {
        "type": "object",
        "properties": {
          "round_id": { "type": "integer" },
          "token": { "type": "string" },
          "total_amount": { "type": "string" },
          "amount_per_share": { "type": "string" },
          "total_claimed": { "type": "string" },
          "claim_count": { "type": "integer" },
          "claimable_from": { "type": "string", "format": "date-time" },
          "expires_at": { "type": "string", "format": "date-time" }
        }
      },
      "PoolEvent": {
        "type": "object",
        "properties": {
          "event_type": {
            "type": "string",
            "enum": ["init", "distribute", "claim", "transfer_shares", "withdraw", "lock", "set_admin"]
          },
          "transaction_hash": { "type": "string" },
          "from_address": { "type": "string" },
          "to_address": { "type": "string", "nullable": true },
          "amount": { "type": "string", "nullable": true },
          "token": { "type": "string", "nullable": true },
          "date": { "type": "string", "format": "date-time" },
          "description": { "type": "string" }
        }
      },
      "Listing": {
        "type": "object",
        "properties": {
          "sale_address": { "type": "string" },
          "pool_address": { "type": "string" },
          "pool_name": { "type": "string" },
          "pool_ticker": { "type": "string" },
          "network_id": { "type": "integer" },
          "seller_address": { "type": "string" },
          "shares_amount": { "type": "integer" },
          "price_per_share": { "type": "string" },
          "total_price": { "type": "string" },
          "payment_token": { "type": "string" },
          "payment_token_address": { "type": "string" },
          "is_active": { "type": "boolean" },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "MarketplaceStats": {
        "type": "object",
        "properties": {
          "pool_address": { "type": "string" },
          "pool_name": { "type": "string" },
          "network_id": { "type": "integer" },
          "floor_price": { "type": "string" },
          "highest_price": { "type": "string" },
          "payment_token": { "type": "string" },
          "active_listings": { "type": "integer" },
          "total_shares_listed": { "type": "integer" },
          "volume_24h": { "type": "string" },
          "volume_7d": { "type": "string" },
          "volume_30d": { "type": "string" },
          "total_volume": { "type": "string" },
          "total_sales": { "type": "integer" }
        }
      },
      "PreparedTransaction": {
        "type": "object",
        "properties": {
          "xdr": { "type": "string", "description": "Unsigned XDR transaction envelope" },
          "transaction_details": { "type": "object" },
          "expires_at": { "type": "string", "format": "date-time" }
        }
      },
      "SignedXdrRequest": {
        "type": "object",
        "required": ["signed_xdr", "network_id"],
        "properties": {
          "signed_xdr": { "type": "string", "description": "Signed XDR transaction envelope" },
          "network_id": { "type": "integer" }
        }
      },
      "TransactionResult": {
        "type": "object",
        "properties": {
          "transaction_hash": { "type": "string" },
          "stellar_explorer_url": { "type": "string", "format": "uri" }
        }
      },
      "ApiKeyResponse": {
        "type": "object",
        "properties": {
          "key": { "type": "string", "description": "API key (shown once, prefix: dob_ak_)" },
          "label": { "type": "string" },
          "scopes": {
            "type": "array",
            "items": { "type": "string" }
          },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "Webhook": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "url": { "type": "string", "format": "uri" },
          "events": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/WebhookEventType" }
          },
          "is_active": { "type": "boolean" },
          "failure_count": { "type": "integer" },
          "last_triggered_at": { "type": "string", "format": "date-time", "nullable": true },
          "created_at": { "type": "string", "format": "date-time" }
        }
      },
      "WebhookEventType": {
        "type": "string",
        "enum": [
          "distribution_created",
          "claim_available",
          "shares_transferred",
          "pool_created",
          "marketplace_listing_created",
          "marketplace_sale_completed",
          "crowdfunding_finalized",
          "crowdfunding_failed"
        ]
      }
    },
    "responses": {
      "Unauthorized": {
        "description": "Invalid or missing API key",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorResponse" },
            "example": {
              "success": false,
              "error": {
                "code": "INVALID_API_KEY",
                "message": "The provided API key is not valid or has been revoked."
              }
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found",
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorResponse" },
            "example": {
              "success": false,
              "error": {
                "code": "NOT_FOUND",
                "message": "The requested resource was not found."
              }
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded (60 req/min)",
        "headers": {
          "X-RateLimit-Limit": { "schema": { "type": "integer" } },
          "X-RateLimit-Remaining": { "schema": { "type": "integer" } },
          "X-RateLimit-Reset": { "schema": { "type": "integer" } }
        },
        "content": {
          "application/json": {
            "schema": { "$ref": "#/components/schemas/ErrorResponse" },
            "example": {
              "success": false,
              "error": {
                "code": "RATE_LIMITED",
                "message": "Rate limit exceeded. Try again later."
              }
            }
          }
        }
      }
    }
  },
  "tags": [
    { "name": "Auth", "description": "API key management" },
    { "name": "Pools", "description": "RWA token pool discovery and details" },
    { "name": "Marketplace", "description": "Buy, sell, and browse RWA token listings" },
    { "name": "Webhooks", "description": "Real-time event notifications" }
  ],
  "externalDocs": {
    "description": "Full documentation",
    "url": "https://docs.dobprotocol.com/agent-api"
  }
}
