# FeeTiersUtils

\_GNSFeeTiers facet internal library

This is a library to apply fee tiers to trading fees based on a trailing point system.\_

## initializeFeeTiers

```solidity
function initializeFeeTiers(uint256[] _groupIndices, uint256[] _groupVolumeMultipliers, uint256[] _feeTiersIndices, struct IFeeTiers.FeeTier[] _feeTiers) internal
```

*Check IFeeTiersUtils interface for documentation*

## setGroupVolumeMultipliers

```solidity
function setGroupVolumeMultipliers(uint256[] _groupIndices, uint256[] _groupVolumeMultipliers) internal
```

*Check IFeeTiersUtils interface for documentation*

## setFeeTiers

```solidity
function setFeeTiers(uint256[] _feeTiersIndices, struct IFeeTiers.FeeTier[] _feeTiers) internal
```

*Check IFeeTiersUtils interface for documentation*

## setTradersFeeTiersEnrollment

```solidity
function setTradersFeeTiersEnrollment(address[] _traders, struct IFeeTiers.TraderEnrollment[] _values) internal
```

*Check IFeeTiersUtils interface for documentation*

## addTradersUnclaimedPoints

```solidity
function addTradersUnclaimedPoints(address[] _traders, enum IFeeTiers.CreditType[] _creditTypes, uint224[] _points) internal
```

*Check IFeeTiersUtils interface for documentation*

## updateTraderPoints

```solidity
function updateTraderPoints(address _trader, uint256 _volumeUsd, uint256 _groupIndex) internal
```

*Check IFeeTiersUtils interface for documentation*

## calculateFeeAmount

```solidity
function calculateFeeAmount(address _trader, uint256 _normalFeeAmountCollateral) internal view returns (uint256)
```

*Check IFeeTiersUtils interface for documentation*

## getFeeTiersCount

```solidity
function getFeeTiersCount() internal view returns (uint256)
```

*Check IFeeTiersUtils interface for documentation*

## getFeeTier

```solidity
function getFeeTier(uint256 _feeTierIndex) internal view returns (struct IFeeTiers.FeeTier)
```

*Check IFeeTiersUtils interface for documentation*

## getGroupVolumeMultiplier

```solidity
function getGroupVolumeMultiplier(uint256 _groupIndex) internal view returns (uint256)
```

*Check IFeeTiersUtils interface for documentation*

## getFeeTiersTraderInfo

```solidity
function getFeeTiersTraderInfo(address _trader) internal view returns (struct IFeeTiers.TraderInfo)
```

*Check IFeeTiersUtils interface for documentation*

## getTraderFeeTiersEnrollment

```solidity
function getTraderFeeTiersEnrollment(address _trader) internal view returns (struct IFeeTiers.TraderEnrollment)
```

*Check IFeeTiersUtils interface for documentation*

## getTraderUnclaimedPoints

```solidity
function getTraderUnclaimedPoints(address _trader) internal view returns (uint224)
```

*Check IFeeTiersUtils interface for documentation*

## getFeeTiersTraderDailyInfo

```solidity
function getFeeTiersTraderDailyInfo(address _trader, uint32 _day) internal view returns (struct IFeeTiers.TraderDailyInfo)
```

*Check IFeeTiersUtils 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 IFeeTiers.FeeTiersStorage s)
```

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

## \_checkFeeTierUpdateValid

```solidity
function _checkFeeTierUpdateValid(uint256 _index, struct IFeeTiers.FeeTier _feeTier, struct IFeeTiers.FeeTier[8] _feeTiers) internal view
```

*Checks validity of a single fee tier update (feeMultiplier: descending, pointsThreshold: ascending, no gap)*

### Parameters

| Name       | Type                                                                                                     | Description                            |
| ---------- | -------------------------------------------------------------------------------------------------------- | -------------------------------------- |
| \_index    | uint256                                                                                                  | index of the fee tier that was updated |
| \_feeTier  | [IFeeTiers.FeeTier](/developer/technical-reference/contracts/interfaces/types/ifeetiers.md#feetier)      | fee tier new value                     |
| \_feeTiers | [IFeeTiers.FeeTier\[8\]](/developer/technical-reference/contracts/interfaces/types/ifeetiers.md#feetier) | all fee tiers                          |

## \_getCurrentDay

```solidity
function _getCurrentDay() internal view returns (uint32)
```

*Get current day (index of mapping traderDailyInfo)*

## \_claimUnclaimedPoints

```solidity
function _claimUnclaimedPoints(address _trader) internal
```

*Claims unclaimed points for a trader and adds them to the daily points for the current day. In the event that it's the first points update for the trader, backdates points to yesterday so the tier discount becomes immediate.*

### Parameters

| Name     | Type    | Description    |
| -------- | ------- | -------------- |
| \_trader | address | trader address |


---

# 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/feetiersutils.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.
