> For the complete documentation index, see [llms.txt](https://docs.vela.exchange/vela-knowledge-base/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vela.exchange/vela-knowledge-base/developers/contract-functions/liquidate-vault.md).

# Liquidate Vault

### Initialize

This function is used to initialize the contract and set up the necessary interfaces.

```solidity
liquidateVault.initialize();
```

### Register Liquidate Position

This function allows an address to register a position for liquidation.

```solidity
liquidateVault.registerLiquidatePosition(
    uint256 _posId
);
```

### Liquidate Position

This function allows an address to liquidate a position if it meets certain conditions.

```solidity
liquidateVault.liquidatePosition(
    uint256 _posId
);
```

### Validate Liquidation With Posid

This function is used to check if a position is eligible for liquidation.

**Example Input:**

```solidity
liquidateVault.validateLiquidationWithPosid(
    uint256 _posId
);
```

**Example Output:**

```
// Returns a boolean indicating whether the position is liquidatable, and three integers representing pnl, fundingFee, and borrowFee respectively.
```

### Validate Liquidation With Posid And Price

This function is used to check if a position is eligible for liquidation, given a specific price.

**Example Input:**

```solidity
liquidateVault.validateLiquidationWithPosidAndPrice(
    uint256 _posId,
    uint256 _price
);
```

**Example Output:**

```
// Returns a boolean indicating whether the position is liquidatable, and three integers representing pnl, fundingFee, and borrowFee respectively.
```

### Validate Liquidation

This function calculates the profit and loss (PnL), funding fee, and borrow fee for a position and checks if the position is eligible for liquidation.

**Example Input:**

```solidity
liquidateVault.validateLiquidation(
    uint256 _tokenId,
    bool _isLong,
    uint256 _size,
    uint256 _averagePrice,
    uint256 _lastPrice,
    uint256 _lastIncreasedTime,
    uint256 _accruedBorrowFee,
    int256 _fundingIndex,
    uint256 _collateral
);
```

**Example Output:**

```
// Returns a boolean indicating whether the position is liquidatable, and three integers representing pnl, fundingFee, and borrowFee respectively.
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.vela.exchange/vela-knowledge-base/developers/contract-functions/liquidate-vault.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
