# Overnight smart contracts

## Portfolio manager

Portfolio manager is a smart contract that runs the algorithm that rebalances the portfolio to meet the investment strategy.&#x20;

> Hold information about the target weights `strategyWeights` for the strategies. If necessary, performs the asset reallocation process using the `balance` method.

Portfolio manager receives M2M data and compares the portfolio structure to the Investment strategy. In case the asset weight is below the minimum or above the maximum specified, It will initiate trades required to meet the target asset weights. For example, in the case of a large deposit, the portfolio manager will see the weight of cash exceed the maximum percentage and thus deploy the excess cash into the relevant lending and liquidity strategies. It will do the opposite in case of a large withdrawal.&#x20;

Portfolio manager contains three methods available only for the `EXCHANGER` role:

* `deposit` - receives assets and places them in `cashStrategy` until the limit is reached. If the limit is exceeded, then it starts balancing for distributing assets to all strategies according to target weights
* `withdraw` - withdraws assets from strategies to return to the client. If there are enough assets in `cashStrategy`, then use them, otherwise starts balancing with the withdrawal of the required amount of assets from the strategies
* `claimAndBalance` - starts collecting (claiming) rewards for strategies with the subsequent balancing of the portfolio to target values

There are also management methods available for the `ADMIN` role:

* `balance` - start balancing assets between strategies to match the given target values
* `setStrategyWeights` - setting target values for strategies
* `setCashStrategy` - assigns which strategy to use as `cashStrategy` - which is a buffer for assets, preventing permanent balancing

## Mark2Market

Mark2Market provides functionality for obtaining information about current assets managed by strategies and their value in USDC. Information about the value of each asset in USDC is provided by the strategies themselves.

> Has the following public methods:
>
> * `strategyAssets` - getting a pivot table for the value of current assets managed by strategies
> * `totalNetAssets` - total value of assets managed by all strategies at USDC equivalent
> * `totalLiquidationAssets` - the potential amount of USDC, which can be obtained with a full withdrawal of assets from all strategies

\ <br>


---

# 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.overnight.fi/advanced/overnight-smart-contracts.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.
