{
  "openapi": "3.1.0",
  "info": {
    "title": "0tx.io/draft",
    "version": "0.1.0",
    "description": "Deploy and upgrade Solana programs on devnet without holding SOL. Reserve a program ID (free or x402 V2 mainnet USDC depending on live config at /draft/v1/info), build with that declare_id!, PUT the compiled .so binary, and poll until deployed. 0tx pays devnet rent from a recycled SOL pool and reclaims it when the lease expires. Full instructions: https://0tx.io/draft/llms.txt",
    "contact": {
      "name": "@0sumTX on X",
      "url": "https://x.com/0sumTX"
    }
  },
  "servers": [
    {
      "url": "https://0tx.io/draft"
    }
  ],
  "paths": {
    "/v1/info": {
      "get": {
        "summary": "Live pricing, limits and devnet rent pool status",
        "responses": {
          "200": {
            "description": "Public config and pool availability",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Info"
                }
              }
            }
          }
        }
      }
    },
    "/v1/programs": {
      "post": {
        "summary": "Reserve a devnet program ID and lease secret",
        "parameters": [
          {
            "name": "PAYMENT-SIGNATURE",
            "in": "header",
            "required": false,
            "schema": { "type": "string" },
            "description": "Base64 x402 V2 payment payload (required when /v1/info reports free=false; omit on first call to get a 402 challenge)."
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "max_bytes": {
                    "type": "integer",
                    "minimum": 1,
                    "description": "Upper bound on uploaded .so size in bytes (defaults to limits.max_bytes)."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Lease reserved; includes lease_secret (store it for PUT/extend/DELETE)",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ReservedLease" }
              }
            }
          },
          "400": { "description": "invalid_json, invalid_body, invalid_max_bytes", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "402": { "description": "x402 V2 payment challenge (when price_usdc > 0)" },
          "403": { "description": "banned", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "409": { "description": "in_progress", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "429": { "description": "payer_limit, ip_limit, ip_daily_limit, or rate limit", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "502": { "description": "payment_pending", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "503": { "description": "paused, out_of_stock, capacity_reached, payments_unavailable", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/v1/programs/{id}": {
      "get": {
        "summary": "Poll lease status and deploy progress (no auth required, returns no secrets)",
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Lease status", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Lease" } } } },
          "404": { "description": "not_found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "put": {
        "summary": "Upload a compiled Solana SBF .so binary to deploy or upgrade in place",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/octet-stream": {
              "schema": { "type": "string", "format": "binary" }
            }
          }
        },
        "responses": {
          "202": { "description": "Upload accepted; deploy running in background", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Lease" } } } },
          "400": { "description": "empty_body, invalid_binary", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "401": { "description": "unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "403": { "description": "upload_limit", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "not_found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "409": { "description": "deploy_in_progress, lease_expired, lease_closed, in_progress", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "413": { "description": "too_large", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "503": { "description": "paused", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      },
      "delete": {
        "summary": "Close a lease early and return its devnet rent to the pool",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Closed on chain; rent recovered", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ClosedLease" } } } },
          "202": { "description": "Marked closing; cron will finish reclaiming rent", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Lease" } } } },
          "401": { "description": "unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "not_found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "409": { "description": "deploy_in_progress, in_progress", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    },
    "/v1/programs/{id}/extend": {
      "post": {
        "summary": "Extend an active lease by lease_days (up to max_extend_days from now)",
        "security": [{ "bearerAuth": [] }],
        "parameters": [
          { "name": "id", "in": "path", "required": true, "schema": { "type": "string" } },
          { "name": "PAYMENT-SIGNATURE", "in": "header", "required": false, "schema": { "type": "string" } }
        ],
        "responses": {
          "200": { "description": "Lease extended", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ExtendedLease" } } } },
          "401": { "description": "unauthorized", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "402": { "description": "x402 V2 payment challenge (when extend_price_usdc > 0)" },
          "403": { "description": "banned", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "404": { "description": "not_found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "409": { "description": "lease_expired, lease_closed, max_lease_reached, in_progress", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "502": { "description": "payment_pending", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
          "503": { "description": "paused, payments_unavailable", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "The lease_secret returned by POST /v1/programs"
      }
    },
    "schemas": {
      "Info": {
        "type": "object",
        "properties": {
          "paused": { "type": "boolean" },
          "network": { "type": "string", "enum": ["solana-devnet"] },
          "free": { "type": "boolean" },
          "price_usdc": { "type": "string" },
          "extend_price_usdc": { "type": "string" },
          "limits": { "type": "object" },
          "pool": { "type": "object" },
          "pay_to": { "type": ["string", "null"] }
        }
      },
      "Lease": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "program_id": { "type": "string" },
          "network": { "type": "string", "enum": ["solana-devnet"] },
          "explorer": { "type": "string" },
          "status": { "type": "string", "enum": ["reserved", "ready", "deploying", "deployed", "failed", "closing", "closed"] },
          "max_bytes": { "type": "integer" },
          "binary_bytes": { "type": ["integer", "null"] },
          "binary_sha256": { "type": ["string", "null"] },
          "bytes_written": { "type": "integer" },
          "uploads": { "type": "integer" },
          "max_uploads": { "type": "integer" },
          "last_deploy_tx": { "type": ["string", "null"] },
          "last_deploy_kind": { "type": ["string", "null"], "enum": ["deploy", "upgrade", "none", null] },
          "last_deploy_explorer": { "type": ["string", "null"] },
          "error": { "type": ["string", "null"] },
          "retryable": { "type": ["boolean", "null"] },
          "expires_at": { "type": "string", "format": "date-time" },
          "closed_at": { "type": ["string", "null"], "format": "date-time" },
          "upload_url": { "type": "string" },
          "status_url": { "type": "string" },
          "extend_url": { "type": "string" },
          "close_url": { "type": "string" }
        }
      },
      "ReservedLease": {
        "allOf": [
          { "$ref": "#/components/schemas/Lease" },
          {
            "type": "object",
            "properties": {
              "lease_secret": { "type": "string" },
              "payment_tx": { "type": ["string", "null"] }
            }
          }
        ]
      },
      "ExtendedLease": {
        "allOf": [
          { "$ref": "#/components/schemas/Lease" },
          { "type": "object", "properties": { "payment_tx": { "type": ["string", "null"] } } }
        ]
      },
      "ClosedLease": {
        "allOf": [
          { "$ref": "#/components/schemas/Lease" },
          { "type": "object", "properties": { "recovered_sol": { "type": "string" } } }
        ]
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "message": { "type": "string" },
          "docs": { "type": "string" }
        }
      }
    }
  }
}
