# yToken contract methods

**Yupana Protocol** is a decentralized lending protocol for individuals and protocols to access financial services. The protocol is permissionless, transparent, and non-custodial.

This section describes the methods of the main protocol contract. We call it `yToken`.

`yToken` - Core contract that manages all markets and implements [`FA2`](https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-12/tzip-12.md) interface for `yToken` for each collateral provided.

<details>

<summary>Deployed contracts</summary>

### *Hangzhou*

#### *Main contracts*

* **YToken** contract: [*KT1NXWFUmX8iYM55TMCTHu5rMQ9m3UWh9HXH*](https://better-call.dev/hangzhou2net/KT1NXWFUmX8iYM55TMCTHu5rMQ9m3UWh9HXH)
* [**Proxy**](/yupana-document-portal/developer-space/pricefeed-contract.md) (PriceFeed) contract: [*KT19ibMmvjuGqyB64yerYfqDFS28pxoL2RW3*](https://better-call.dev/hangzhou2net/KT19ibMmvjuGqyB64yerYfqDFS28pxoL2RW3)

#### *Market contracts*

Market 0 (fa12) `tokenId = 0n`

* **Token (fa12)** *contract:* [*KT1SWHKPhaqigm4c4dNkpN3DPt1qYqRxBZag*](https://better-call.dev/hangzhou2net/KT1SWHKPhaqigm4c4dNkpN3DPt1qYqRxBZag)
* [**InterestRate**](/yupana-document-portal/developer-space/interestrate-contract.md) contract: [*KT1FeGpeZY35UBBvnJurHaKVf4wG7CSphAPc*](https://better-call.dev/hangzhou2net/KT1FeGpeZY35UBBvnJurHaKVf4wG7CSphAPc) &#x20;

Market 1 (fa2) `tokenId = 1n`

* **Token (fa2)** *contract:* [*KT1CWNzjSe1gvMWPEFKBz6qajDpBno89nRG7*](https://better-call.dev/hangzhou2net/KT1CWNzjSe1gvMWPEFKBz6qajDpBno89nRG7)&#x20;
* [**InterestRate**](/yupana-document-portal/developer-space/interestrate-contract.md) contract: [*KT1VogQQRUHUMqbN38UJZUSNzPgrssYWXrwn*](https://better-call.dev/hangzhou2net/KT1VogQQRUHUMqbN38UJZUSNzPgrssYWXrwn)

</details>

### Glossary

**Underlying asset** is the real asset that is provided to the lending protocol.

**`yToken` token is** the single token with the specific `token id` inside of the core Yupana FA2; represents specific underlying asset locked in the protocol.

**Collateral** is the `yToken` token that can be used as the collateral to take the loan.

**Borrow** is the amount of the underlying asset borrowed by the user (*loan*).

**Cash** is the amount of the underlying asset present on the contract (*not borrowed*).

**Reserves** value is the amount of the underlying asset stored in the protocol.

**Collateral Factor** is the rate represents by which the borrow limit increases if the `yToken` is minted.

**Close Factor** is the max portion of the loan that can be liquidated per single transaction.

**Reserve Factor** is the rate that represents what part of the interest goes to the protocol reserves.

**Liquidation discount** is the rate that the liquidator will earn if liquidate the asset.

### User experience

{% hint style="success" %}
All usage examples use **JS/TS** and **Python** example calls with [Taquito](https://tezostaquito.io/) and [PyTezos](https://pytezos.org/) libraries.
{% endhint %}

#### As lending protocol

User of protocol allowed to perform actions:

* mint - add a token as a collateral. It allows you to add a token to our system.
* redeem - designed to withdraw tokens from the platform.
* borrow - for borrowing a token. Implemented the logic of freezing collateral tokens when borrowing a token.
* repay - designed to repay debt.
* liquidate - allows another user to liquidate someone's debt.
* enterMarket - allows you to designate that this token will be used as collateral.
* exitMarket - allows you to indicate that this token is no longer used as collateral.

{% hint style="warning" %}
Before any of the methods would be called, should be executed [updateInterest](/yupana-document-portal/developer-space/ytoken-contract-methods/updateinterest.md) and [PriceFeed.getPrice](/yupana-document-portal/developer-space/pricefeed-contract/getprice.md) methods in the same block.
{% endhint %}

More detailed explanation of calling and using methods is described in the linked section.

{% content-ref url="/pages/bJ9Lw2SBLy6ucSqd6Zxc" %}
[Lending methods](/yupana-document-portal/developer-space/ytoken-contract-methods/lending-methods.md)
{% endcontent-ref %}

#### As FA2 Token

Contract serves `FA2` token for each underlying asset by `token_id`. So, the contract should implement [TZIP-12](https://gitlab.com/tezos/tzip/-/blob/master/proposals/tzip-12/tzip-12.md) proposal about `FA2` token standard.

FA2 token inteface consist of this entrypoints:

* transfer - for sending tokens.
* update\_operators -for allowing other user or contract to be "`operator`" of `sender` tokens.
* balance\_of - on-chain view to get balance by `owner` and `token_id` of a requested token.
* get\_total\_supply - on-chain view to get balance of all token supply by `token_id`.

More about `FA2` contract described in corresponding section.

{% content-ref url="/pages/PsT6zPZu2UG5svjcX09x" %}
[FA2 Token entrypoints](/yupana-document-portal/developer-space/ytoken-contract-methods/fa2-token-entrypoints.md)
{% endcontent-ref %}

### Contract management

`yToken` contract is managed by `admin` address.

Admin is responsible for the initial setup of the contract, especially setting lambda functions, that contains the main codebase of the contract.

Also, admin adds new markets, adjust lending factors, pauses borrows, updates meta, etc.

`admin` abilities are explained in the related section.

{% content-ref url="/pages/1n9Ij3qwXXcHkiX6uT1s" %}
[Admin methods](/yupana-document-portal/developer-space/ytoken-contract-methods/admin-methods.md)
{% endcontent-ref %}


---

# 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://yupana-finance.gitbook.io/yupana-document-portal/developer-space/ytoken-contract-methods.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.
