# Technical Notes
## Operator Functions
There are several functions for the operator to periodically call:
### 1. set_reference_price()
Every hour, the contract operator computes the average NEAR price in USD from one or more exchange markets and send the information to the smart contract. That price determines the ratio of collateralization and the exchange rate for the conversion window.
### 2. compute_rewards()
In the middle of each epoch, the contract operator calls this function to compute staking rewards from all the collateral. The rewards are added to the collateral pool, increasing the stNEAR amount and then collateralization for all users.
### 3. collect_interest()
In the middle of each epoch, after calling compute_rewards(), the contract operator calls this function to compute interest on collateral. Interest is sent to the contract treasury.
## Use Cases
Alice can have an account where she can deposit collateral stNEAR.
Some minimun NEAR deposit may be required to open the account (to back-up account storage) if that storage is not provided by the operator.
Once Alice deposits the collateral, a "credit limit" is computed according to the current NEAR price and the collateralization ratio. e.g. if Alice deposited stNEAR 100, and the NEAR price is USD 2.5, then the collateral value is USD 250. If the collateralization ratio is 200% it means Alice will have a "line of credit" to borrow USDNEAR 125 backed by her USD 250 valued collateral.
Alice account now reads:
- Tokens
-- USDNEAR: 0
-- stNEAR: 100 Available (USD 250) + 0 Locked (USD 0)
- Line of Credit
-- Limit: USDNEAR 125 [Take Loan]
- Outstanding Loans:
-- owed: USDNEAR 0
-- Locked Collateral: stNEAR 0
If Alice chooses to borrow USDNEAR 100, USDNEAR 100 are minted into Alice's account, and USD 200 value of collateral is locked and trasnferred to the collateral pool. The global amount of minted USDNEAR will be increased by 100 and the value of the collateral pool will be incresed by stNEAR valued USD 200, keeping the global overcollateralization constant.
Alice account now reads:
- Tokens
-- USDNEAR: 100
-- stNEAR: 20 Available (USD 50) + 80 Locked (USD 200)
- Line of Credit
-- Limit: USDNEAR 50
- Outstanding Loans:
-- owed: USDNEAR 100 [Repay]
-- Locked stNEAR (Collateral): 80 (USD 200) [Add Collateral]
-- Collateralization Ratio: 200%
Let's assume Alice trasnfers USDNEAR 100 to Bob
Bob account now reads:
- Tokens
-- USDNEAR: 100
and Alice account reads:
- Tokens
-- USDNEAR: 0
-- stNEAR: 20 Available (USD 50) + 80 Locked (USD 200)
- Line of Credit
-- Limit: USDNEAR 50
- Outstanding Loans:
-- owed: USDNEAR 100 [Repay]
-- Locked stNEAR (Collateral): 80 (USD 200) [Add Collateral]
-- Collateralization Ratio: 200%
## Liquidation Event
Let's assume the NEAR price is now USD 1.50. With this new price Alice's account reads:
- Tokens
-- USDNEAR: 0
-- stNEAR: 20 Available (USD 30) + 80 Locked (USD 120)
- Line of Credit
-- Limit: USDNEAR 50
- Outstanding Loans:
-- owed: USDNEAR 100 [Repay]
-- Locked stNEAR (Collateral): 80 (USD 120)
-- Collateralization Ratio: 120% **OPEN FOR LIQUIDATION** [Add Collateral]
At this point Alice's debt is open for liquidation because it's collateral is less than 150%