# Collateral Management

## Adding collateral

Increase the margin of a position by depositing additional collateral.&#x20;

```solidity
function depositCollateral(bytes32 loanId, uint256 depositAmount) external payable nonReentrant whenNotPaused 
```

**Arguments**

<table><thead><tr><th width="190.33333333333334">Name</th><th width="147">Type</th><th>Description</th></tr></thead><tbody><tr><td>loanId</td><td>bytes32</td><td>A unique ID representing the loan.</td></tr><tr><td>depositAmount</td><td>uint256</td><td>The amount to be deposited in collateral tokens.</td></tr></tbody></table>

## Removing collateral

Withdraw from the collateral. This reduces the margin of a position. Note that it is not possible to reduce the margin below the maintenance margin. If attempted, as much collateral as possible will be removed, leaving the position at the maintenance margin level.

```solidity
function withdrawCollateral(bytes32 loanId, address receiver, uint256 withdrawAmount) external nonpayable nonReentrant whenNotPaused 
returns(actualWithdrawAmount uint256)
```

**Arguments**

<table><thead><tr><th width="187.33333333333334">Name</th><th width="116">Type</th><th>Description</th></tr></thead><tbody><tr><td>loanId</td><td>bytes32</td><td>A unique ID representing the loan.</td></tr><tr><td>receiver</td><td>address</td><td>The account getting the withdrawal.</td></tr><tr><td>withdrawAmount</td><td>uint256</td><td>The amount to be withdrawn in collateral tokens. </td></tr></tbody></table>

**Returns**

The amount withdrawn&#x20;


---

# 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://build.sovryn.com/builder-portal/smart-contracts/lending-and-margin-trading-protocol/collateral-management.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.
