{
  "openapi": "3.1.0",
  "info": {
    "title": "QIELend API",
    "version": "0.1.0",
    "description": "Public API for QIELend (Compound V2 fork) on QIE Blockchain mainnet (chain id 1990). Read endpoints return market and account data read directly from the chain. Transaction endpoints return UNSIGNED transactions (to, data, value) for a wallet to sign; this service never signs, holds keys or broadcasts. Amount parameters are human decimal strings (QIE 18 dp, QUSDC 6 dp). Rates are raw protocol figures."
  },
  "servers": [
    {
      "url": "https://api.qielend.qie.digital",
      "description": "Production"
    },
    {
      "url": "http://localhost:8080",
      "description": "Local"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "summary": "Service health: last block, snapshot age, oracle feed age",
        "tags": [
          "Meta"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/protocol": {
      "get": {
        "summary": "Protocol parameters and contract addresses (close factor, liquidation incentive, pause flags)",
        "tags": [
          "Read"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/markets": {
      "get": {
        "summary": "All markets: totals, utilization, per-block rates, collateral factor, oracle price, borrow cap, available liquidity",
        "tags": [
          "Read"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/markets/{id}": {
      "get": {
        "summary": "One market",
        "tags": [
          "Read"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "qToken address, underlying address, or symbol (QIE, WQIE, QUSDC, qWQIE, qQUSDC)",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/accounts/{address}": {
      "get": {
        "summary": "Account position: supplied, borrowed, health factor, borrow limit, max borrowable QUSDC, max withdrawable QIE, wallet balances and allowances",
        "tags": [
          "Read"
        ],
        "parameters": [
          {
            "name": "address",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/quote": {
      "get": {
        "summary": "Quote: supply X QIE as collateral -> max QUSDC borrowable, health factor and liquidation price per scenario",
        "tags": [
          "Read"
        ],
        "parameters": [
          {
            "name": "supplyQie",
            "in": "query",
            "required": true,
            "description": "QIE to supply (decimal)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "borrowQusdc",
            "in": "query",
            "required": false,
            "description": "Optional QUSDC borrow to evaluate",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "address",
            "in": "query",
            "required": false,
            "description": "Optional: include this account's existing position",
            "schema": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/tx/supply": {
      "get": {
        "summary": "Supply QIE: [wrap QIE->WQIE] -> [approve WQIE] -> qWQIE.mint",
        "tags": [
          "Transactions"
        ],
        "parameters": [
          {
            "name": "address",
            "in": "query",
            "required": true,
            "description": "User wallet address (0x...)",
            "schema": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            }
          },
          {
            "name": "amount",
            "in": "query",
            "required": true,
            "description": "QIE amount (decimal)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "wrap",
            "in": "query",
            "required": false,
            "description": "Wrap native QIE first (default true). false = spend existing WQIE",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "approval",
            "in": "query",
            "required": false,
            "description": "exact (default) approves only the amount needed; max approves uint256 max",
            "schema": {
              "type": "string",
              "enum": [
                "exact",
                "max"
              ],
              "default": "exact"
            }
          },
          {
            "name": "simulate",
            "in": "query",
            "required": false,
            "description": "Dry-run steps that can run now with eth_call + eth_estimateGas from `address` (default true)",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Unsigned transaction steps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TxPlan"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "422": {
            "description": "Rejected by a protocol check (limit, liquidity, no debt...)"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/tx/enable-collateral": {
      "get": {
        "summary": "Enable supplied QIE as collateral: Comptroller.enterMarkets([qWQIE]). Returns no steps if already enabled",
        "tags": [
          "Transactions"
        ],
        "parameters": [
          {
            "name": "address",
            "in": "query",
            "required": true,
            "description": "User wallet address (0x...)",
            "schema": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            }
          },
          {
            "name": "simulate",
            "in": "query",
            "required": false,
            "description": "Dry-run steps that can run now with eth_call + eth_estimateGas from `address` (default true)",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Unsigned transaction steps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TxPlan"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "422": {
            "description": "Rejected by a protocol check (limit, liquidity, no debt...)"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/tx/borrow": {
      "get": {
        "summary": "Borrow QUSDC: qQUSDC.borrow (adds enterMarkets first if QIE is supplied but not enabled)",
        "tags": [
          "Transactions"
        ],
        "parameters": [
          {
            "name": "address",
            "in": "query",
            "required": true,
            "description": "User wallet address (0x...)",
            "schema": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            }
          },
          {
            "name": "amount",
            "in": "query",
            "required": true,
            "description": "QUSDC amount (decimal)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "simulate",
            "in": "query",
            "required": false,
            "description": "Dry-run steps that can run now with eth_call + eth_estimateGas from `address` (default true)",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Unsigned transaction steps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TxPlan"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "422": {
            "description": "Rejected by a protocol check (limit, liquidity, no debt...)"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/tx/repay": {
      "get": {
        "summary": "Repay QUSDC: [approve QUSDC] -> qQUSDC.repayBorrow. amount=max repays the full debt (uint256 max)",
        "tags": [
          "Transactions"
        ],
        "parameters": [
          {
            "name": "address",
            "in": "query",
            "required": true,
            "description": "User wallet address (0x...)",
            "schema": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            }
          },
          {
            "name": "amount",
            "in": "query",
            "required": true,
            "description": "QUSDC amount (decimal) or max",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "approval",
            "in": "query",
            "required": false,
            "description": "exact (default) approves only the amount needed; max approves uint256 max",
            "schema": {
              "type": "string",
              "enum": [
                "exact",
                "max"
              ],
              "default": "exact"
            }
          },
          {
            "name": "simulate",
            "in": "query",
            "required": false,
            "description": "Dry-run steps that can run now with eth_call + eth_estimateGas from `address` (default true)",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Unsigned transaction steps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TxPlan"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "422": {
            "description": "Rejected by a protocol check (limit, liquidity, no debt...)"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/tx/withdraw": {
      "get": {
        "summary": "Withdraw QIE: qWQIE.redeemUnderlying (or redeem all for max) -> [WQIE.withdraw to unwrap]",
        "tags": [
          "Transactions"
        ],
        "parameters": [
          {
            "name": "address",
            "in": "query",
            "required": true,
            "description": "User wallet address (0x...)",
            "schema": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            }
          },
          {
            "name": "amount",
            "in": "query",
            "required": true,
            "description": "QIE amount (decimal) or max (only when no debt)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "unwrap",
            "in": "query",
            "required": false,
            "description": "Unwrap WQIE to native QIE (default true)",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "simulate",
            "in": "query",
            "required": false,
            "description": "Dry-run steps that can run now with eth_call + eth_estimateGas from `address` (default true)",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Unsigned transaction steps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TxPlan"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "422": {
            "description": "Rejected by a protocol check (limit, liquidity, no debt...)"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/tx/supply-and-borrow": {
      "get": {
        "summary": "Full flow in one plan: wrap -> approve -> mint -> enterMarkets -> borrow",
        "tags": [
          "Transactions"
        ],
        "parameters": [
          {
            "name": "address",
            "in": "query",
            "required": true,
            "description": "User wallet address (0x...)",
            "schema": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            }
          },
          {
            "name": "supplyQie",
            "in": "query",
            "required": true,
            "description": "QIE to supply",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "borrowQusdc",
            "in": "query",
            "required": true,
            "description": "QUSDC to borrow",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "approval",
            "in": "query",
            "required": false,
            "description": "exact (default) approves only the amount needed; max approves uint256 max",
            "schema": {
              "type": "string",
              "enum": [
                "exact",
                "max"
              ],
              "default": "exact"
            }
          },
          {
            "name": "simulate",
            "in": "query",
            "required": false,
            "description": "Dry-run steps that can run now with eth_call + eth_estimateGas from `address` (default true)",
            "schema": {
              "type": "boolean",
              "default": true
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Unsigned transaction steps",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TxPlan"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "422": {
            "description": "Rejected by a protocol check (limit, liquidity, no debt...)"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/openapi.json": {
      "get": {
        "summary": "This document",
        "tags": [
          "Meta"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    },
    "/docs": {
      "get": {
        "summary": "HTML docs",
        "tags": [
          "Meta"
        ],
        "parameters": [],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "400": {
            "description": "Bad parameters"
          },
          "404": {
            "description": "Not found"
          },
          "429": {
            "description": "Rate limited"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "TxPlan": {
        "type": "object",
        "properties": {
          "action": {
            "type": "string"
          },
          "chainId": {
            "type": "integer",
            "const": 1990
          },
          "from": {
            "type": "string"
          },
          "ready": {
            "type": "boolean",
            "description": "true when there are no blockers and no dry-run failures"
          },
          "blockers": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "ordering": {
            "type": "string"
          },
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "index": {
                  "type": "integer"
                },
                "id": {
                  "type": "string",
                  "enum": [
                    "wrap",
                    "approve",
                    "supply",
                    "enableCollateral",
                    "borrow",
                    "repay",
                    "withdraw",
                    "unwrap"
                  ]
                },
                "action": {
                  "type": "string"
                },
                "description": {
                  "type": "string"
                },
                "dependsOn": {
                  "type": "array",
                  "items": {
                    "type": "string"
                  }
                },
                "tx": {
                  "type": "object",
                  "properties": {
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": "string"
                    },
                    "data": {
                      "type": "string"
                    },
                    "value": {
                      "type": "string",
                      "description": "hex wei"
                    },
                    "chainId": {
                      "type": "integer"
                    }
                  }
                },
                "valueQIE": {
                  "type": "string"
                },
                "simulation": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok",
                        "failed",
                        "pending",
                        "skipped"
                      ]
                    },
                    "gasEstimate": {
                      "type": "integer"
                    },
                    "gasLimit": {
                      "type": "string"
                    },
                    "returnCode": {
                      "type": "integer"
                    },
                    "error": {
                      "type": "string"
                    },
                    "reason": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
