{
  "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/creditbook/collateral/orca/claim_fees": {
      "post": {
        "tags": [
          "creditbook"
        ],
        "operationId": "query_claim_orca_fee",
        "parameters": [
          {
            "name": "Idempotent-Key",
            "in": "header",
            "description": "Optional idempotency key; a retried write with the same key replays the original response",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TxnClaimFeeParams"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Serialized transaction message and signatures",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VersionedTransactionReturn"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency-Key reused with a different request body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "summary": "Claim Orca fees",
        "description": "Claim accrued fees for an Orca CLMM collateral position on a loan."
      }
    },
    "/markets/creditbook/collateral/orca/update_liquidity": {
      "post": {
        "tags": [
          "creditbook"
        ],
        "operationId": "query_manage_orca_liquidity",
        "parameters": [
          {
            "name": "Idempotent-Key",
            "in": "header",
            "description": "Optional idempotency key; a retried write with the same key replays the original response",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TxnManageOrcaLiquidityParams"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Serialized transaction message and signatures",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VersionedTransactionReturn"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency-Key reused with a different request body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "summary": "Update Orca liquidity",
        "description": "Increase or decrease liquidity on an Orca CLMM collateral position while keeping the loan collateralized."
      }
    },
    "/markets/creditbook/collateral/orca/transfer_position": {
      "post": {
        "tags": [
          "creditbook"
        ],
        "operationId": "query_transfer_orca_position",
        "parameters": [
          {
            "name": "Idempotent-Key",
            "in": "header",
            "description": "Optional idempotency key; a retried write with the same key replays the original response",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TxnTransferOrcaPositionParams"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Serialized transaction message and signatures",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VersionedTransactionReturn"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency-Key reused with a different request body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "summary": "Transfer Orca position",
        "description": "Reposition an Orca CLMM collateral position to a new tick range on an existing loan."
      }
    },
    "/markets/creditbook/collateral/raydium/update_liquidity": {
      "post": {
        "tags": [
          "creditbook"
        ],
        "operationId": "query_manage_raydium_liquidity",
        "parameters": [
          {
            "name": "Idempotent-Key",
            "in": "header",
            "description": "Optional idempotency key; a retried write with the same key replays the original response",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TxnManageRaydiumLiquidityParams"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Serialized transaction message and signatures",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VersionedTransactionReturn"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency-Key reused with a different request body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "summary": "Update Raydium liquidity",
        "description": "Increase or decrease liquidity on a Raydium CLMM collateral position while keeping the loan collateralized."
      }
    },
    "/markets/creditbook/collateral/raydium/transfer_position": {
      "post": {
        "tags": [
          "creditbook"
        ],
        "operationId": "query_transfer_raydium_position",
        "parameters": [
          {
            "name": "Idempotent-Key",
            "in": "header",
            "description": "Optional idempotency key; a retried write with the same key replays the original response",
            "required": false,
            "schema": {
              "type": [
                "string",
                "null"
              ]
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TxnTransferRaydiumPositionParams"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "description": "Serialized transaction message and signatures",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/VersionedTransactionReturn"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "409": {
            "description": "Idempotency-Key reused with a different request body",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "500": {
            "description": "Internal server error",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "summary": "Transfer Raydium position",
        "description": "Reposition a Raydium CLMM collateral position to a new tick range on an existing loan."
      }
    }
  },
  "components": {
    "schemas": {
      "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"
          }
        }
      },
      "LiquidityParamsSchema": {
        "type": "object",
        "description": "CLMM liquidity-management params (slippage bound), used by Orca/Raydium\n`manage_liquidity`.",
        "required": [
          "slippageToleranceBps"
        ],
        "properties": {
          "slippageToleranceBps": {
            "type": "integer",
            "format": "int32",
            "description": "Slippage tolerance, in basis points.",
            "minimum": 0
          }
        }
      },
      "ManageLiquidityParamsSchema": {
        "type": "object",
        "description": "Params for managing Orca CLMM collateral liquidity (`manage_orca_liquidity`).",
        "required": [
          "collateralIndex",
          "liquidityAmount",
          "transferParams",
          "assetIndexGuidance"
        ],
        "properties": {
          "assetIndexGuidance": {
            "type": "array",
            "items": {
              "type": "integer",
              "format": "int32",
              "minimum": 0
            }
          },
          "collateralIndex": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "liquidityAmount": {
            "type": "integer",
            "minimum": 0
          },
          "transferParams": {
            "$ref": "#/components/schemas/TransferTypeParamsSchema"
          }
        }
      },
      "ManageRaydiumLiquidityParamsSchema": {
        "type": "object",
        "description": "Params for managing Raydium CLMM collateral liquidity (`manage_raydium_liquidity`).",
        "required": [
          "collateralIndex",
          "liquidityAmount",
          "manageParams",
          "assetIndexGuidance"
        ],
        "properties": {
          "assetIndexGuidance": {
            "type": "array",
            "items": {
              "type": "integer",
              "format": "int32",
              "minimum": 0
            }
          },
          "collateralIndex": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "liquidityAmount": {
            "type": "integer",
            "minimum": 0
          },
          "manageParams": {
            "$ref": "#/components/schemas/TokenAmountsParamsSchema"
          }
        }
      },
      "TokenAmountsParamsSchema": {
        "type": "object",
        "description": "Explicit token-amount params for a CLMM position (Raydium / token-amount mode).",
        "required": [
          "tokenAAmount",
          "tokenBAmount"
        ],
        "properties": {
          "tokenAAmount": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "tokenBAmount": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          }
        }
      },
      "TransferPositionParamsSchema": {
        "type": "object",
        "description": "Params for transferring an Orca/Raydium CLMM position as collateral\n(`transfer_*_position`).",
        "required": [
          "liquidityAmount",
          "collateralIndex",
          "transferParams",
          "tickLowerIndex",
          "tickUpperIndex",
          "assetIndexGuidance"
        ],
        "properties": {
          "assetIndexGuidance": {
            "type": "array",
            "items": {
              "type": "integer",
              "format": "int32",
              "minimum": 0
            }
          },
          "collateralIndex": {
            "type": "integer",
            "format": "int32",
            "minimum": 0
          },
          "liquidityAmount": {
            "type": "integer",
            "minimum": 0
          },
          "tickLowerIndex": {
            "type": "integer",
            "format": "int32"
          },
          "tickUpperIndex": {
            "type": "integer",
            "format": "int32"
          },
          "transferParams": {
            "$ref": "#/components/schemas/TransferTypeParamsSchema"
          }
        }
      },
      "TransferTypeParamsSchema": {
        "oneOf": [
          {
            "type": "object",
            "required": [
              "Liquidity"
            ],
            "properties": {
              "Liquidity": {
                "$ref": "#/components/schemas/LiquidityParamsSchema"
              }
            }
          },
          {
            "type": "object",
            "required": [
              "TokenAmounts"
            ],
            "properties": {
              "TokenAmounts": {
                "$ref": "#/components/schemas/TokenAmountsParamsSchema"
              }
            }
          }
        ],
        "description": "How a CLMM transfer/manage sizes the position: by liquidity or by explicit\ntoken amounts (externally-tagged: `{ \"Liquidity\": … }` / `{ \"TokenAmounts\": … }`)."
      },
      "TxnClaimFeeParams": {
        "type": "object",
        "required": [
          "loan",
          "positionMint"
        ],
        "properties": {
          "loan": {
            "type": "string"
          },
          "positionMint": {
            "type": "string"
          }
        }
      },
      "TxnManageOrcaLiquidityParams": {
        "type": "object",
        "required": [
          "loan",
          "positionMint",
          "increase",
          "manageParams"
        ],
        "properties": {
          "increase": {
            "type": "boolean"
          },
          "loan": {
            "type": "string"
          },
          "manageParams": {
            "$ref": "#/components/schemas/ManageLiquidityParamsSchema"
          },
          "positionMint": {
            "type": "string"
          }
        }
      },
      "TxnManageRaydiumLiquidityParams": {
        "type": "object",
        "required": [
          "loan",
          "positionMint",
          "increase",
          "manageParams",
          "amount",
          "slippageDecimals"
        ],
        "properties": {
          "amount": {
            "type": "integer",
            "format": "int64",
            "minimum": 0
          },
          "increase": {
            "type": "boolean"
          },
          "isTokenA": {
            "type": "boolean"
          },
          "loan": {
            "type": "string"
          },
          "manageParams": {
            "$ref": "#/components/schemas/ManageRaydiumLiquidityParamsSchema"
          },
          "positionMint": {
            "type": "string"
          },
          "slippageDecimals": {
            "type": "number",
            "format": "double"
          }
        }
      },
      "TxnTransferOrcaPositionParams": {
        "type": "object",
        "required": [
          "loan",
          "positionMint",
          "transferParams"
        ],
        "properties": {
          "loan": {
            "type": "string"
          },
          "positionMint": {
            "type": "string"
          },
          "transferParams": {
            "$ref": "#/components/schemas/TransferPositionParamsSchema"
          }
        }
      },
      "TxnTransferRaydiumPositionParams": {
        "type": "object",
        "required": [
          "loan",
          "positionMint",
          "slippageDecimals",
          "transferParams"
        ],
        "properties": {
          "loan": {
            "type": "string"
          },
          "positionMint": {
            "type": "string"
          },
          "slippageDecimals": {
            "type": "number",
            "format": "double"
          },
          "transferParams": {
            "$ref": "#/components/schemas/TransferPositionParamsSchema"
          }
        }
      },
      "VersionedTransactionReturn": {
        "type": "object",
        "description": "versioned txn return",
        "required": [
          "message",
          "signatures"
        ],
        "properties": {
          "message": {
            "type": "string",
            "description": "serialized message"
          },
          "signatures": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/VersionedTransactionSignature"
            },
            "description": "serialized signatures"
          }
        }
      },
      "VersionedTransactionSignature": {
        "type": "object",
        "description": "versioned txn return",
        "required": [
          "publicKey",
          "signature"
        ],
        "properties": {
          "publicKey": {
            "type": "string",
            "description": "serialized message"
          },
          "signature": {
            "type": "string",
            "description": "serialized signatures"
          }
        }
      }
    }
  }
}
