# Lending methods

This section is about main protocol methods of Yupana.

### Types

Most of all lending methods receive `yAssetParams` type as an input

```pascaligo
type yAssetParams       is [@layout:comb] record [
  tokenId                 : nat; // yToken token Id
  amount                  : nat;
]
```

Exception in input parameters type have [liquidate](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/liquidate) and [enterMarket](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/entermarket)/[exitMarket](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/exitmarket).

### Entrypoints

All contract calls represented in this block are used for operating user collateral inside the Yupana protocol.

At the beginning of lending journey, the user should inform the contract about what tokens would be used by the user as collateral.&#x20;

#### enterMarket

Using for indicating usage of underlying token as collateral from yToken `tokenId`.

{% content-ref url="lending-methods/entermarket" %}
[entermarket](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/entermarket)
{% endcontent-ref %}

Next calls required of 2 pre-call operations included in block.

{% hint style="info" %}
The `yToken` contract expects that underlying token info of `tokenId` is updated by calling [PriceFeed.getPrice](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/pricefeed-contract/getprice) and [updateInterest](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/updateinterest) in the same block for next contract methods
{% endhint %}

#### exitMarket

Indicates contract that user is no longer want to use as collateral token, underlying under `tokenId`.

{% content-ref url="lending-methods/exitmarket" %}
[exitmarket](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/exitmarket)
{% endcontent-ref %}

#### mint

User could add an underlying token to Yupana system and receive `amount` of related yToken `token` by `tokenId`.

{% content-ref url="lending-methods/mint" %}
[mint](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/mint)
{% endcontent-ref %}

#### redeem

If user want to claim `amount` of underlying token back from Yupana, then he should call redeem with `tokenId`  of related yToken `token`.

{% content-ref url="lending-methods/redeem" %}
[redeem](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/redeem)
{% endcontent-ref %}

#### borrow

User could **borrow** some tokens from protocol. To do it, call borrow with `tokenId` of yToken `token`, related to borrow token market and `amount` of token you want to **borrow**.

{% content-ref url="lending-methods/borrow" %}
[borrow](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/borrow)
{% endcontent-ref %}

#### repay

When user come back with tokens to return debt, he should call, **repay** entrypoint with `amount` of token to return and `tokenId` of related to market yToken `token`.

{% content-ref url="lending-methods/repay" %}
[repay](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/repay)
{% endcontent-ref %}

#### liquidate

The liquidation process occurs when another user repays part of the outstanding amount of the borrower and thus purchases his collateral at a discount. To do this, user call **liquidate** method. For more info about liquidations work go to [liquidation](https://yupana-finance.gitbook.io/yupana-document-portal/liquidation "mention") page. Params of call and usage described in related section.

{% content-ref url="lending-methods/liquidate" %}
[liquidate](https://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods/liquidate)
{% endcontent-ref %}

### General errors

* `yToken/use-lambda-not-set` - lambda of called entrypoint is not set yet.
* `cant-unpack-use-lambda` - lambda bytes of function is broken.
