> For the complete documentation index, see [llms.txt](https://developers.dforce.network/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.dforce.network/lend/lend-and-synth/controller.md).

# Controller

The Controller is the risk management portal of the dForce Lending & Synthetic Protocol, it determines how much collateral a user is required to maintain, whether (and how much) a user can be liquidated, and control the protocol risk by adjusting supply/borrow capacity and risk parameters.

## Methods

### enterMarkets()

Enter into a list of markets. In order to supply collateral or borrow in a market, it must be entered first.

```
function enterMarkets(address[] calldata iTokens)
        external
        returns (bool[] memory);
```

###

### exitMarkets()

Exit a market, exited markets will not count towards account liquidity calculations.

```
function exitMarkets(address[] calldata iTokens)
        external
        returns (bool[] memory);
```

###

### getAlliTokens()

Get all markets already added into the protocol.

```
function getAlliTokens() external view returns (address[] memory);
```

###

### hasiToken()

Return the status whether an iToken is listed in the controller.

```
function hasiToken(address _iToken) external view returns (bool);
```

###

### getEnteredMarkets()

Get all markets already entered from one account.

```
function getEnteredMarkets(address account)
        external
        view
        returns (address[] memory);
```

###

### getBorrowedAssets()

Get all assets already borrowed from one account.

```
function getBorrowedAssets(address account)
        external
        view
        returns (address[] memory);
```

### calcAccountEquity()

Account liquidity represents the USD value with the specific asset/amount-continue-redeeming or amount-continue-borrowing before it reaches liquidation. Returns Tuple of values (equity, shortfall, collaterals, borrows). A non-zero equity value indicates the account has available borrowable value, a non-zero shortfall value indicates the account is currently below the collateral requirement and is subject to liquidation. At most one of equity or shortfall shall be non-zero. Collaterals and borrows represent the current collateral and borrow value is USD with 36 integer precision which for example, 360000000000000000000000000000000000000000 indicates 360000 in USD.

```
function calcAccountEquity(address _account)
        public
        view
        override
        returns (
            uint256 equity,
            uint256 shortfall,
            uint256 collaterals,
            uint256 borrows
        )
```

### liquidateCalculateSeizeTokens()

Compute the amount of collateral iToken available to seize after repaying a specific amount of borrow asset.

```
function liquidateCalculateSeizeTokens(
        address _iTokenBorrowed,
        address _iTokenCollateral,
        uint256 _actualRepayAmount
    )
    external
    view
    override
    returns (uint256 _seizedTokenCollateral)
```

###

### Key Events

| Event                                                                | Description                                                           |
| -------------------------------------------------------------------- | --------------------------------------------------------------------- |
| <p>event MarketEntered</p><p>(address iToken, address account)</p>   | Emitted upon a successful Enter Market.                               |
| <p>event MarketExited</p><p>(address iToken, address account)</p>    | Emitted upon a successful Exit Market.                                |
| <p>event BorrowedAdded</p><p>(address iToken, address account)</p>   | Emitted upon a successful borrowing new asset(never borrowed before). |
| <p>event BorrowedRemoved</p><p>(address iToken, address account)</p> | Emitted upon a successful payoff an outstanding loan.                 |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://developers.dforce.network/lend/lend-and-synth/controller.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
