# OtcUtils

*OTC facet internal library*

## initializeOtc

```solidity
function initializeOtc(struct IOtc.OtcConfig _config) internal
```

*Check IOtcUtils interface for documentation*

## updateOtcConfig

```solidity
function updateOtcConfig(struct IOtc.OtcConfig _config) internal
```

*Check IOtcUtils interface for documentation*

## addOtcCollateralBalance

```solidity
function addOtcCollateralBalance(uint8 _collateralIndex, uint256 _collateralAmount) internal
```

*Check IOtcUtils interface for documentation*

## sellGnsForCollateral

```solidity
function sellGnsForCollateral(uint8 _collateralIndex, uint256 _collateralAmount) internal
```

*Check IOtcUtils interface for documentation*

## getOtcConfig

```solidity
function getOtcConfig() internal view returns (struct IOtc.OtcConfig)
```

*Check IOtcUtils interface for documentation*

## getOtcBalance

```solidity
function getOtcBalance(uint8 _collateralIndex) internal view returns (uint256)
```

*Check IOtcUtils interface for documentation*

## getOtcRate

```solidity
function getOtcRate(uint8 _collateralIndex) internal view returns (uint256)
```

*Check IOtcUtils interface for documentation*

## \_getSlot

```solidity
function _getSlot() internal pure returns (uint256)
```

*Returns storage slot to use when fetching storage relevant to library*

## \_getStorage

```solidity
function _getStorage() internal pure returns (struct IOtc.OtcStorage s)
```

*Returns storage pointer for storage struct in diamond contract, at defined slot*

## \_getMultiCollatDiamond

```solidity
function _getMultiCollatDiamond() internal view returns (contract IGNSMultiCollatDiamond)
```

*Returns current address as multi-collateral diamond interface to call other facets functions.*

## \_calculateGnsAmount

```solidity
function _calculateGnsAmount(uint8 _collateralIndex, uint256 _collateralAmount, uint256 _gnsPriceCollateral) internal view returns (uint256)
```

*Calculate GNS amount for given collateral amount*

### Parameters

| Name                 | Type    | Description                                 |
| -------------------- | ------- | ------------------------------------------- |
| \_collateralIndex    | uint8   | index of the collateral                     |
| \_collateralAmount   | uint256 | amount of collateral (collateral precision) |
| \_gnsPriceCollateral | uint256 | price of GNS in collateral (1e10)           |

## \_calculateGnsDistribution

```solidity
function _calculateGnsDistribution(uint256 _gnsAmount) internal view returns (uint256 treasuryAmountGns, uint256 stakingAmountGns, uint256 burnAmountGns)
```

*Calculate GNS distribution for treasury, GNS staking and burn*

### Parameters

| Name        | Type    | Description                               |
| ----------- | ------- | ----------------------------------------- |
| \_gnsAmount | uint256 | amount of GNS tokens to distribute (1e18) |

## \_distributeTreasuryGns

```solidity
function _distributeTreasuryGns(uint256 _gnsAmount) internal
```

*Distributes treasury rewards in GNS tokens*

### Parameters

| Name        | Type    | Description                               |
| ----------- | ------- | ----------------------------------------- |
| \_gnsAmount | uint256 | amount of GNS tokens to distribute (1e18) |

## \_distributeStakingGns

```solidity
function _distributeStakingGns(uint256 _gnsAmount) internal
```

*Distributes staking rewards in GNS tokens*

### Parameters

| Name        | Type    | Description                               |
| ----------- | ------- | ----------------------------------------- |
| \_gnsAmount | uint256 | amount of GNS tokens to distribute (1e18) |

## \_burnGns

```solidity
function _burnGns(uint256 _gnsAmount) internal
```

*Burns GNS tokens*

### Parameters

| Name        | Type    | Description                         |
| ----------- | ------- | ----------------------------------- |
| \_gnsAmount | uint256 | amount of GNS tokens to burn (1e18) |


---

# 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.gains.trade/developer/technical-reference/contracts/libraries/otcutils.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.
