# unwind()

In historic crypto-market conditions the funding rate has consistently been positive, which is an assumption that this strategy relies on. The Managers of Vortex are constantly monitoring the funding rate and ensuring that it remains positive; if it stays negative for a prolonged amount of time then the Manager can *unwind()* the funds to prevent any further losses. This function can also be used to prevent a liquidation. The *unwind()* function is described below:

```
    /**
     * @notice  unwind the position in adverse funding rate scenarios, settle short position
     *          and pull funds from the margin account. Then converts the long position back
     *          to want.
     * @dev     only callable by the owner
     */
    function unwind() public onlyAuthorised {
        require(!isUnwind, "unwound");
        isUnwind = true;
        mcLiquidityPool.forceToSyncState();
        // swap long asset back to want
        _swap(IERC20(long).balanceOf(address(this)), long, want);
        // check if the perpetual is in settlement, if it is then settle it
        // otherwise unwind the fund as normal.
        if (!_settle()) {
            // close the short position
            _closeAllPerpPositions();
            // withdraw all cash in the margin account
            mcLiquidityPool.withdraw(
                perpetualIndex,
                address(this),
                getMargin()
            );
        }
        // reset positions
        positions.perpContracts = 0;
        positions.margin = getMargin();
        positions.unitAccumulativeFunding = getUnitAccumulativeFunding();
        emit StrategyUnwind(IERC20(want).balanceOf(address(this)));
    }
```

*unwind()* will close all long positions, then check if the MCDEX perpetual market has been settled. If it has been settled, then all funds will be withdrawn as all positions have already been closed by MCDEX. If the perpetual pool is not settled, then all short positions are closed and withdrawn from the margin account to the strategy contract.


---

# 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://akropolis.gitbook.io/akropolis/developer-documentation/vortex/risk-management/unwind.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.
