# NOTE, DEX, and Lending Market

When building DApps, you may wish to leverage Canto's Free Public Infrastructure, such as its native unit of account, DEX, or lending market. This page provides an overview of how these primitives are designed and how you can interact with them.

For mainnet and testnet deployment addresses, refer to the Contract Addresses page:

{% content-ref url="contract-addresses" %}
[contract-addresses](https://docs.canto.io/evm-development/contract-addresses)
{% endcontent-ref %}

## NOTE

[NOTE](https://docs.canto.io/free-public-infrastructure-fpi/note) must be borrowed from the Accountant via the Canto Lending Market. The amount of NOTE circulating at any given time (including NOTE that users have supplied back to the Canto Lending Market) is equal to the sum of all NOTE and cNOTE *not* held by the Accountant.

The NOTE smart contract may be modified and redeployed at a new address in the future. For this reason, DApps should use the `CToken.underlying()` view on the [cNOTE](https://docs.canto.io/evm-development/contract-addresses#neofinance) contract to determine the address for NOTE instead of hardcoding it.

## Canto DEX

The Canto DEX is built around three contracts: [`BaseV1Factory`](https://github.com/Canto-Network/clm/blob/7a734186ac773a8e53c55c07c5ec32d32a528b4a/src/Swap/BaseV1-core.sol#L530), [`BaseV1Pair`](https://github.com/Canto-Network/clm/blob/7a734186ac773a8e53c55c07c5ec32d32a528b4a/src/Swap/BaseV1-core.sol#L11), and [`BaseV1Router01`](https://github.com/Canto-Network/clm/blob/7a734186ac773a8e53c55c07c5ec32d32a528b4a/src/Swap/BaseV1-periphery.sol#L47). Each liquidity pool is represented by a unique `BaseV1Pair` contract generated by the `BaseV1Factory`.

For most use cases, `BaseV1Router01` offers sufficient functionality. Key methods include:

| Method                           | Description                                         |
| -------------------------------- | --------------------------------------------------- |
| `pairFor`                        | Calculates the address for a pair                   |
| `isPair`                         | Checks if an address is a valid pair                |
| `getReserves`                    | Fetches and sorts the reserves for a pair           |
| `getAmountOut`                   | Calculates amount out for a specified pair          |
| `addLiquidity`                   | Adds liquidity to a pair                            |
| `removeLiquidity`                | Removes liquidity from a pair                       |
| `swapExactTokensforTokensSimple` | Swaps one token for another directly                |
| `swapExactTokensforTokens`       | Swaps one token for another using a specified route |
| `getUnderlyingPrice`             | Gets underlying asset price as a mantissa           |

For CANTO-specific and other methods, refer to the [contract source code](https://github.com/Canto-Network/clm/blob/7a734186ac773a8e53c55c07c5ec32d32a528b4a/src/Swap/BaseV1-periphery.sol#L47).

## Canto Lending Market

The Canto Lending Market is an adaptation of [Compound v2](https://docs.compound.finance/v2/comptroller/). Its functional design is unchanged in that the primary means of interacting with the lending market is the [`CToken`](https://github.com/Canto-Network/clm/blob/main/src/CToken.sol), an ERC20 representation of a supplied asset.

Key methods on `CToken` contracts include:

| Method             | Description                                                          |
| ------------------ | -------------------------------------------------------------------- |
| `mint`             | Deposits a token and mints the corresponding CToken                  |
| `redeem`           | Redeems a specified amount of CToken tokens for the underlying token |
| `redeemUnderlying` | Redeems CToken tokens for a specified amount of the underlying token |
| `borrow`           | Borrows the underlying token                                         |
| `repayBorrow`      | Repays a borrow of the underlying token                              |

For more information on the Canto Lending Market's design, see the [Compound v2 docs](https://docs.compound.finance/v2/).


---

# 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.canto.io/evm-development/dex-and-lending-market.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.
