{
  "openapi": "3.1.0",
  "info": {
    "title": "ChainIQ | Bulk Crypto Cost Basis CSV",
    "version": "1.1.0",
    "description": "Choose FIFO, LIFO, HIFO or Optimized HIFO for 1–200,000 supplied USD spot fills. The response identifies downloadable CSV parts. Payments use native USDC on Base.",
    "x-guidance": "Start with the public bulk upload client. Prepare the authorized trade JSON and wait for a ready request. Submit that exact request to the Google merchant to obtain an order-specific price. Approve the amount before signing."
  },
  "servers": [{"url": "https://bulk---chainiq-fifo-hpdt6vofhq-ue.a.run.app"}],
  "externalDocs": {"description": "Prepare the upload, authorize payment and collect the CSV", "url": "https://kcbsolutions.org/x402#agents"},
  "paths": {
    "/api/v1/calculate-tax": {
      "post": {
        "operationId": "purchasePreparedFifoWorkpaper",
        "summary": "Buy a crypto cost basis workpaper for the selected method",
        "description": "Send the exact ready CSV or 2025 PDF order. The signed payment binds its product and amount. A PDF includes the source FIFO workpaper as an attachment.",
        "tags": ["crypto cost basis", "tax lots"],
        "externalDocs": {"url": "https://kcbsolutions.org/x402/bulk_upload.py"},
        "x-payment-info": {"protocols": [{"x402": {}}], "price": {"mode": "dynamic", "currency": "USD", "min": "0.05", "max": "50.00"}},
        "parameters": [
          {"name": "chainiq-payment-id", "in": "header", "schema": {"type": "string"}, "description": "The buyer client's payment ID for this order."},
          {"name": "Payment-Signature", "in": "header", "schema": {"type": "string"}, "description": "Include only for the authorized paid retry."}
        ],
        "requestBody": {"required": true, "content": {"application/json": {"schema": {"oneOf":[{"$ref":"#/components/schemas/ReadyOrder"},{"$ref":"#/components/schemas/StatementOrder"}]}}}},
        "responses": {
          "200": {"description": "Paid download manifest with byte lengths and SHA-256 digests for the CSV and its parts.", "content": {"application/json": {"schema": {"type": "object"}}}},
          "202": {"description": "Settlement is pending. Resume with the original order and buyer client."},
          "402": {"description": "Ready order requires its exact Base USDC payment.", "headers": {"Payment-Required": {"schema": {"type": "string"}}}},
          "404": {"description": "Prepared workpaper or upload is unavailable."},
          "410": {"description": "The unpaid upload's 24-hour staging period expired."},
          "422": {"description": "The submitted document does not identify a valid prepared bulk order."}
        }
      }
    },
    "/api/v1/bulk/uploads/{upload}/statement": {
      "post": {
        "operationId":"prepareFifoStatement2025", "summary":"Check and prepare a 2025 FIFO PDF at no charge",
        "parameters":[{"name":"upload","in":"path","required":true,"schema":{"$ref":"#/components/schemas/Digest"}},{"name":"chainiq-result-key","in":"header","required":true,"schema":{"$ref":"#/components/schemas/Digest"}}],
        "description":"Use an authorized ready FIFO upload. Supply a stable inventory label. For corrections, use the prior paid statement order digest, payer and payment ID and retain the same private result key. An optional csvPurchase identifies a paid CSV from the same active upload for the 5 USDC premium alone.",
        "requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","additionalProperties":false,"required":["generation","inventory"],"properties":{"generation":{"enum":["original","corrected"]},"inventory":{"type":"string","pattern":"^[A-Za-z0-9._-]{1,48}$"},"replaces":{"type":"object","required":["orderSHA256","payer","paymentID"]},"csvPurchase":{"type":"object","required":["payer","paymentID"]}}}}}},
        "responses":{"200":{"description":"Check checkoutAvailable. A ready response includes the product-specific request and amount. A needs_review response gives the reason and available affected row and field."},"202":{"description":"The underlying workpaper is processing."},"403":{"description":"Private key or paid predecessor proof failed."},"422":{"description":"The input, year, precision, volume or correction is ineligible. No payment is requested."}}
      }
    }
  },
  "components": {
    "schemas": {
      "Digest": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
      "StatementOrder": {"type":"object","required":["schema","method","engine","fills","bookSHA256","upload","resultKeySHA256","inventory","year","generation","replaces","priceSchedule","csvOrder","csvSHA256","pdfSHA256","allocations"],"properties":{"schema":{"const":"chainiq.statement-2025-order.v1"},"method":{"const":"FIFO"},"year":{"const":2025},"generation":{"enum":["original","corrected"]},"priceSchedule":{"enum":["fifo-statement-2025-v1","fifo-statement-2025-paid-csv-v1"]},"allocations":{"type":"integer","minimum":1,"maximum":1000}},"description":"Return the exact object from free statement preparation verbatim."},
      "ReadyOrder": {
        "type": "object", "additionalProperties": false,
        "description": "Use the exact object returned by the upload status. Keep the result key private.",
        "required": ["schema", "bookSHA256", "resultKeySHA256", "engine", "method", "fills", "upload"],
        "oneOf": [{"properties":{"method":{"const":"FIFO"},"schema":{"const":"chainiq.bulk-fifo-order.v1"}}},{"properties":{"method":{"enum":["LIFO","HIFO","OPTIMIZED_HIFO"]},"schema":{"const":"chainiq.bulk-method-order.v1"}}}],
        "properties": {
          "schema": {"type": "string", "enum": ["chainiq.bulk-fifo-order.v1", "chainiq.bulk-method-order.v1"]},
          "bookSHA256": {"$ref": "#/components/schemas/Digest"},
          "resultKeySHA256": {"$ref": "#/components/schemas/Digest"},
          "engine": {"$ref": "#/components/schemas/Digest"},
          "method": {"type": "string", "enum": ["FIFO", "LIFO", "HIFO", "OPTIMIZED_HIFO"]},
          "fills": {"type": "integer", "minimum": 1, "maximum": 200000},
          "upload": {"$ref": "#/components/schemas/Digest"}
        }
      }
    }
  }
}
