{
  "openapi": "3.1.0",
  "info": {
    "title": "Loopscale API",
    "version": "0.1.0"
  },
  "servers": [
    {
      "url": "https://tars.loopscale.com/v1",
      "description": "Loopscale Production Server"
    }
  ],
  "paths": {
    "/markets/quote": {
      "post": {
        "tags": [
          "quotes"
        ],
        "summary": "Get quotes",
        "operationId": "route_get_quote",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RawQuoteFilter"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "List of available quotes",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/RawQuoteOffer"
                  }
                }
              }
            }
          },
          "400": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "description": "Returns a list of current lend orders available for the specified principal token, collateral, and target duration. Results are sorted by APY and support pagination."
      }
    },
    "/markets/quote/max": {
      "post": {
        "tags": [
          "quotes"
        ],
        "summary": "Get max quote",
        "operationId": "route_get_max_quote",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/MaxQuoteRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Best matching quote per collateral asset",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/MaxQuoteResponse"
                  }
                }
              }
            }
          },
          "400": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "description": "Returns the top quote for each specified collateral asset based on available liquidity. This endpoint is designed for minimizing rate slippage for a borrow with known inputs."
      }
    }
  },
  "components": {
    "schemas": {
      "AssetDataInfo": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "Spl"
            ],
            "properties": {
              "Spl": {
                "$ref": "#/components/schemas/SplData"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "StakedSol"
            ],
            "properties": {
              "StakedSol": {
                "$ref": "#/components/schemas/StakedSolData"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "Orca"
            ],
            "properties": {
              "Orca": {
                "$ref": "#/components/schemas/OrcaPositionData"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "Meteora"
            ],
            "properties": {
              "Meteora": {
                "$ref": "#/components/schemas/MeteoraDlmmPositionData"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "Raydium"
            ],
            "properties": {
              "Raydium": {
                "$ref": "#/components/schemas/RaydiumPositionData"
              }
            }
          }
        ],
        "description": "Collateral asset identification, tagged by collateral kind (SPL token,\nstaked SOL, or a CLMM LP position on Orca / Meteora / Raydium)."
      },
      "CollateralFilter": {
        "type": "object",
        "required": [
          "amount",
          "assetData"
        ],
        "properties": {
          "amount": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "assetData": {
            "$ref": "#/components/schemas/AssetDataInfo"
          },
          "priceOverride": {
            "type": [
              "number",
              "null"
            ],
            "format": "double"
          }
        }
      },
      "ErrorDetails": {
        "type": "object",
        "description": "Inner detail of the [`ErrorResponse`] envelope.",
        "required": [
          "code",
          "message"
        ],
        "properties": {
          "code": {
            "type": "integer",
            "format": "int32",
            "description": "HTTP status code, mirrored in the response status line",
            "example": 400,
            "minimum": 0
          },
          "message": {
            "type": "string",
            "description": "human-readable, client-safe message (sensitive data redacted)",
            "example": "Request could not be processed."
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "description": "Canonical error envelope for every endpoint. The `x-request-id` response\nheader carries the correlation id for the failing request.",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "$ref": "#/components/schemas/ErrorDetails",
            "description": "error detail"
          }
        }
      },
      "MaxQuoteRequest": {
        "type": "object",
        "required": [
          "collateralFilter",
          "principalMint",
          "duration",
          "durationType"
        ],
        "properties": {
          "collateralFilter": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/CollateralFilter"
            }
          },
          "duration": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "durationType": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "excludedExternalYield": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "integer",
              "format": "int32",
              "minimum": 0
            }
          },
          "principalMint": {
            "type": "string"
          },
          "strategyCredit": {
            "type": "object",
            "additionalProperties": {
              "type": "integer",
              "format": "int64",
              "minimum": 0
            },
            "propertyNames": {
              "type": "string"
            }
          }
        }
      },
      "MaxQuoteResponse": {
        "type": "object",
        "required": [
          "apy",
          "strategy",
          "collateralIdentifier",
          "ltv",
          "lqt",
          "amount"
        ],
        "properties": {
          "amount": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "apy": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "collateralIdentifier": {
            "type": "string"
          },
          "lqt": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "ltv": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "strategy": {
            "type": "string"
          }
        }
      },
      "MeteoraDlmmPositionData": {
        "type": "object",
        "required": [
          "positionAddress",
          "lbPair"
        ],
        "properties": {
          "lbPair": {
            "type": "string"
          },
          "positionAddress": {
            "type": "string"
          },
          "tokenProgram": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "OrcaPositionData": {
        "type": "object",
        "required": [
          "positionMint",
          "whirlpool"
        ],
        "properties": {
          "positionMint": {
            "type": "string"
          },
          "tokenProgram": {
            "type": [
              "string",
              "null"
            ]
          },
          "whirlpool": {
            "type": "string"
          }
        }
      },
      "RawQuoteFilter": {
        "type": "object",
        "required": [
          "collateral",
          "principal",
          "limit",
          "duration",
          "durationType",
          "offset"
        ],
        "properties": {
          "apyRange": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "integer",
              "format": "int64",
              "minimum": 0
            },
            "description": "Inclusive `[min, max]` APY bounds (basis points)."
          },
          "collateral": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "duration": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "durationType": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "excludedExternalYield": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": "integer",
              "format": "int32",
              "minimum": 0
            }
          },
          "lendingStrategyAddress": {
            "type": [
              "string",
              "null"
            ]
          },
          "limit": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "minPrincipalAmount": {
            "type": [
              "integer",
              "null"
            ],
            "format": "int64",
            "minimum": 0
          },
          "offset": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "principal": {
            "type": "string"
          }
        }
      },
      "RawQuoteOffer": {
        "type": "object",
        "required": [
          "apy",
          "ltv",
          "liquidationThreshold",
          "maxPrincipalAvailable",
          "sumPrincipalAvailable"
        ],
        "properties": {
          "apy": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "liquidationThreshold": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "ltv": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "maxPrincipalAvailable": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "sumPrincipalAvailable": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          }
        }
      },
      "RaydiumPositionData": {
        "type": "object",
        "required": [
          "mint",
          "pool"
        ],
        "properties": {
          "mint": {
            "type": "string"
          },
          "pool": {
            "type": "string"
          },
          "tokenProgram": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "SplData": {
        "type": "object",
        "required": [
          "mint"
        ],
        "properties": {
          "mint": {
            "type": "string"
          }
        }
      },
      "StakedSolData": {
        "type": "object",
        "required": [
          "stakeAccount",
          "stakePool"
        ],
        "properties": {
          "stakeAccount": {
            "type": "string"
          },
          "stakePool": {
            "type": "string"
          }
        }
      }
    }
  }
}
