# Operation - Repay

### Key Steps

1. **Parse Repayment Amount**:
   * Convert the repayment amount into the correct unit using the `parseUnits` function, specifying the number of decimals that match the debt token's specifications (usually 18, like Ethereum).
2. **Execute Repayment Transaction**:
   * Use the `doRepay` function to initiate the repayment. This function requires parameters such as the public and wallet clients, protocol configuration, collateral details, and the repayment amount. It processes the transaction on the blockchain and updates the user's debt status accordingly.

### Usage

This function is typically used by users who wish to:

* **Decrease Financial Liabilities**: Repaying part of the minted amount to reduce the accruing interest and improve financial standing.
* **Improve Trove Health**: Enhancing the collateral-to-debt ratio to secure the trove against potential liquidations in volatile market conditions.

### Example

```typescript
import { parseUnits } from 'viem';
import { publicClient, walletClient, protocolConfig, collateral } from 'satoshi-sdk';

async function repayDebt() {
  // Step 1: Define the amount to repay
  const repayAmt = parseUnits('5', DEBT_TOKEN_DECIMALS);  // Repaying 5 SAT stablecoins

  // Step 2: Execute the repayment transaction
  const receipt = await satoshiClient.Postition.doRepay({
    publicClient,
    walletClient,
    protocolConfig,
    collateral,
    repayAmt,
  });

  console.log('Repayment successful:', receipt);
}

repayDebt();
```

This example function, `repayDebt`, outlines the process of repaying a specified amount of satUSD stablecoins. It demonstrates how to correctly convert the repayment amount to the proper unit and execute the transaction, ensuring the debt is correctly reduced in the user's trove.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.river.inc/satoshi-protocol-v1/sdk/position/operation-repay.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
