# BorrowLogic

{% hint style="info" %}
This contract tracks **borrow lifecycle events**:

* Borrowing liquidity
* Repaying debt
* Switching between stable/variable interest rate
* Rebalancing rates
* Debt tracking in isolation mode

{% endhint %}

### Events&#x20;

* **Borrow(reserve, user, onBehalfOf, amount, interestRateMode, borrowRate, referralCode)**\
  Emitted when a user **borrows an asset** from the protocol.
  * `reserve`: Asset being borrowed.
  * `user`: Address initiating the borrow.
  * `onBehalfOf`: Address that receives the debt.
  * `amount`: Amount borrowed.
  * `interestRateMode`: Type of interest rate chosen (stable or variable).
  * `borrowRate`: Rate applied at the moment of borrowing.
  * `referralCode`: Referral code for partner integrations.

***

* **IsolationModeTotalDebtUpdated(asset, totalDebt)**\
  Emitted when the **total debt** of an asset in **isolation mode** changes.
  * `asset`: Address of the reserve in isolation mode.
  * `totalDebt`: Updated total debt for this asset.

***

* **RebalanceStableBorrowRate(reserve, user)**\
  Emitted when a user’s **stable borrow rate** is rebalanced by the protocol.
  * `reserve`: Asset where the rebalance occurs.
  * `user`: Address of the borrower whose stable rate is adjusted.

***

* **Repay(reserve, user, repayer, amount, useATokens)**\
  Emitted when a **loan is repaid**.
  * `reserve`: Asset being repaid.
  * `user`: Borrower whose debt is being reduced.
  * `repayer`: Address that actually performs the repayment (can be the user or another address).
  * `amount`: Amount repaid.
  * `useATokens`: Whether aTokens were used to repay the debt directly.

***

* **SwapBorrowRateMode(reserve, user, interestRateMode)**\
  Emitted when a borrower **switches their interest rate mode**.
  * `reserve`: Asset where the swap happens.
  * `user`: Borrower changing the mode.
  * `interestRateMode`: New interest rate mode (stable or variable).

```
[
  {
    "anonymous": false,
    "inputs": [
      { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" },
      { "indexed": false, "internalType": "address", "name": "user", "type": "address" },
      { "indexed": true, "internalType": "address", "name": "onBehalfOf", "type": "address" },
      { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" },
      { "indexed": false, "internalType": "enum DataTypes.InterestRateMode", "name": "interestRateMode", "type": "uint8" },
      { "indexed": false, "internalType": "uint256", "name": "borrowRate", "type": "uint256" },
      { "indexed": true, "internalType": "uint16", "name": "referralCode", "type": "uint16" }
    ],
    "name": "Borrow",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      { "indexed": true, "internalType": "address", "name": "asset", "type": "address" },
      { "indexed": false, "internalType": "uint256", "name": "totalDebt", "type": "uint256" }
    ],
    "name": "IsolationModeTotalDebtUpdated",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" },
      { "indexed": true, "internalType": "address", "name": "user", "type": "address" }
    ],
    "name": "RebalanceStableBorrowRate",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" },
      { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
      { "indexed": true, "internalType": "address", "name": "repayer", "type": "address" },
      { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" },
      { "indexed": false, "internalType": "bool", "name": "useATokens", "type": "bool" }
    ],
    "name": "Repay",
    "type": "event"
  },
  {
    "anonymous": false,
    "inputs": [
      { "indexed": true, "internalType": "address", "name": "reserve", "type": "address" },
      { "indexed": true, "internalType": "address", "name": "user", "type": "address" },
      { "indexed": false, "internalType": "enum DataTypes.InterestRateMode", "name": "interestRateMode", "type": "uint8" }
    ],
    "name": "SwapBorrowRateMode",
    "type": "event"
  }
]

```


---

# 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://colend.gitbook.io/home/abi/borrowlogic.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.
