> ## Documentation Index
> Fetch the complete documentation index at: https://docs.compasslabs.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Repay to Market

> Repay borrowed tokens to a market in order to reduce or eliminate debt.

A Morpho Market is a primitive lending pool that pairs one collateral asset with one
loan asset. Each market is isolated (meaning risks are contained within each
individual market), immutable (cannot be changed after deployment), and will persist
as long as the blockchain it is deployed on is live.
                    <Info>
                    **Required Allowances**

                        In order to make this transaction, token allowances need to be set for the following contracts.

                     - `MorphoMarket`
                    </Info>
                



## OpenAPI

````yaml /v1/combined_spec.json post /v1/morpho/repay
openapi: 3.1.0
info:
  title: Compass API
  description: Compass Labs DeFi API
  version: 0.0.1
servers:
  - url: https://api.compasslabs.ai
    description: Production server
security:
  - ApiKeyAuth: []
paths:
  /v1/morpho/repay:
    post:
      tags:
        - Morpho
      summary: Repay to Market
      description: >-
        Repay borrowed tokens to a market in order to reduce or eliminate debt.


        A Morpho Market is a primitive lending pool that pairs one collateral
        asset with one

        loan asset. Each market is isolated (meaning risks are contained within
        each

        individual market), immutable (cannot be changed after deployment), and
        will persist

        as long as the blockchain it is deployed on is live.
                            <Info>
                            **Required Allowances**

                                In order to make this transaction, token allowances need to be set for the following contracts.

                             - `MorphoMarket`
                            </Info>
                        
      operationId: v1_morpho_repay
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MorphoRepayRequest'
        required: true
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TransactionResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      x-codeSamples:
        - lang: python
          label: Python (SDK)
          source: |-
            from compass_api_sdk import CompassAPI, models


            with CompassAPI(
                api_key_auth="<YOUR_API_KEY_HERE>",
            ) as compass_api:

                res = compass_api.morpho.morpho_repay(amount=0.000005, unique_market_key="0x3b3769cfca57be2eaed03fcc5299c25691b77781a1e124e7a8d520eb9a7eabb5", chain=models.MorphoRepayRequestChain.BASE, sender="0xbc267D24E58b429347026346c0C103b8Fa95D93d", estimate_gas=True)

                # Handle response
                print(res)
        - lang: typescript
          label: Typescript (SDK)
          source: |-
            import { CompassApiSDK } from "@compass-labs/api-sdk";

            const compassApiSDK = new CompassApiSDK({
              apiKeyAuth: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await compassApiSDK.morpho.morphoRepay({
                amount: 0.000005,
                uniqueMarketKey: "0x3b3769cfca57be2eaed03fcc5299c25691b77781a1e124e7a8d520eb9a7eabb5",
                chain: "base",
                sender: "0xbc267D24E58b429347026346c0C103b8Fa95D93d",
              });

              console.log(result);
            }

            run();
components:
  schemas:
    MorphoRepayRequest:
      properties:
        action_type:
          type: string
          const: MORPHO_REPAY
          title: Action Type
          default: MORPHO_REPAY
        amount:
          anyOf:
            - type: number
            - type: string
              pattern: ^(?!^[-+.]*$)[+-]?0*\d*\.?\d*$
            - type: string
              const: ALL
          title: Amount
          description: >-
            Amount of the token to repay to the market. If set to 'ALL', all
            debt plus interest will be paid back if the user has a sufficient
            token balance in their wallet.
          examples:
            - 1.5
            - ALL
          default: 0.000005
        unique_market_key:
          type: string
          pattern: ^0x.*
          title: Unique Market Key
          description: >-
            The key that uniquely identifies the market. This can be found using
            the 'Get Markets' endpoint.
          examples:
            - '0xe7399fdebc318d76dfec7356caafcf8cd4b91287e139a3ec423f09aeeb656fc4'
          default: '0x3b3769cfca57be2eaed03fcc5299c25691b77781a1e124e7a8d520eb9a7eabb5'
        on_behalf_of:
          anyOf:
            - type: string
            - type: 'null'
          title: On Behalf Of
          description: >-
            The address on behalf of whom the repayment is made. Defaults to
            sender.
        callback_data:
          anyOf:
            - type: string
              format: binary
            - type: 'null'
          title: Callback Data
          description: >-
            An optional field for callback byte data that will be triggered upon
            successful repaying of debt.
        chain:
          type: string
          enum:
            - arbitrum
            - base
            - ethereum
          title: Chain
          default: base
          examples:
            - base
        sender:
          type: string
          title: Sender
          description: The address of the transaction sender.
          examples:
            - '0x29F20a192328eF1aD35e1564aBFf4Be9C5ce5f7B'
          default: '0xbc267D24E58b429347026346c0C103b8Fa95D93d'
        estimate_gas:
          type: boolean
          title: Estimate Gas
          description: >-
            Determines whether to estimate gas costs for transactions, also
            verifying that the transaction can be successfully executed.
          default: true
      type: object
      required:
        - amount
        - unique_market_key
        - chain
        - sender
      title: MorphoRepayRequest
      default:
        chain: base
        sender: '0xbc267D24E58b429347026346c0C103b8Fa95D93d'
        amount: 0.000005
        unique_market_key: '0x3b3769cfca57be2eaed03fcc5299c25691b77781a1e124e7a8d520eb9a7eabb5'
      required_allowances:
        - MorphoMarket
    TransactionResponse:
      properties:
        transaction:
          anyOf:
            - $ref: '#/components/schemas/UnsignedTransaction'
            - $ref: '#/components/schemas/UserOperationResponse'
          title: Transaction
          description: >-
            The unsigned transaction data. User must sign and broadcast to
            network.
      type: object
      required:
        - transaction
      title: TransactionResponse
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    UnsignedTransaction:
      properties:
        chainId:
          type: string
          title: Chainid
          description: The chain id of the transaction
        data:
          type: string
          title: Data
          description: The data of the transaction
        from:
          type: string
          title: From
          description: The sender of the transaction
        gas:
          anyOf:
            - type: string
            - type: 'null'
          title: Gas
          description: The gas of the transaction
        to:
          type: string
          title: To
          description: The recipient of the transaction
        value:
          type: string
          title: Value
          description: The value of the transaction
        nonce:
          type: string
          title: Nonce
          description: The nonce of the address
        maxFeePerGas:
          type: string
          title: Maxfeepergas
          description: The max fee per gas of the transaction
        maxPriorityFeePerGas:
          type: string
          title: Maxpriorityfeepergas
          description: The max priority fee per gas of the transaction
      type: object
      required:
        - chainId
        - data
        - from
        - gas
        - to
        - value
        - nonce
        - maxFeePerGas
        - maxPriorityFeePerGas
      title: UnsignedTransaction
      example:
        chainId: '0x2105'
        data: >-
          0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d
        from: '0x4A83b4413CF41C3244027e1590E35a0F48403F0c'
        gas: '0x7a120'
        maxFeePerGas: '0x59682f00'
        maxPriorityFeePerGas: '0x3b9aca00'
        nonce: '0x5'
        to: '0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67'
        value: '0x0'
    UserOperationResponse:
      properties:
        to:
          type: string
          title: To
          description: The target contract address for the operation
        data:
          type: string
          title: Data
          description: The calldata for the operation
        value:
          type: string
          title: Value
          description: The ETH value to send with the operation
      type: object
      required:
        - to
        - data
        - value
      title: UserOperationResponse
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your Compass API Key. Get your key
        [here](https://www.compasslabs.ai/dashboard).

````