# CreditNotes

CreditNotes are tokens that represent borrowed collateral in the fx-protocol's Long-Short Pool lending system. It acts as a debt instrument that tracks how much collateral the Short Pool has borrowed from the Long Pool.

For each short pool, one type of CreditNote is generated. For example, we currently have two short pools in the system — the wstETH short pool and the WBTC short pool. Thus, there are two types of CreditNotes in the system, named:

* fxETH (CreditNotes for wstETH Pool)
* fxBTC (CreditNotes for WBTC Short Pool)

CreditNotes are primarily held by protocol contracts, though users may also receive CreditNotes from the protocol. In such cases, several methods are provided to allow users to redeem their CreditNotes for standard asset types.

### **1. Redemption Mechanism:**

Users can redeem CreditNote tokens for underlying fxUSD collateral:

```
// Users call ShortPoolManager.redeemByCreditNote()
function redeemByCreditNote(address pool, uint256 debts, uint256 minColls) external {
    // Transfer CreditNote from user
    IERC20(creditNote).safeTransferFrom(_msgSender(), address(this), debts);
    
    // Redeem equivalent collateral
    colls = IShortPool(pool).redeemByCreditNote(rawDebts);
    
    // Apply protocol fees
    uint256 protocolFees = (colls * getRedeemFeeRatio()) / FEE_PRECISION;
    colls -= protocolFees;
    
    // Transfer net collateral to user
    _transferOut(fxUSD, colls, _msgSender());
}
```

In the end, when the short pool reaches the end of its life cycle, all CreditNotes should be burned.

For more details on how to use it in a keeper bot, see the [redeemByCreditNote](/fx-docs/developers/processing-the-rebalances-and-liquidations/keeper-bots.md#redeembycreditnote) section.


---

# 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://fxprotocol.gitbook.io/fx-docs/developers/processing-the-rebalances-and-liquidations/creditnotes.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.
