# ReferralsUtils

*GNSReferrals facet internal library*

## initializeReferrals

```solidity
function initializeReferrals(uint256 _allyFeeP, uint256 _startReferrerFeeP, uint256 _targetVolumeUsd) internal
```

*Check IReferralsUtils interface for documentation*

## updateAllyFeeP

```solidity
function updateAllyFeeP(uint256 _value) internal
```

*Check IReferralsUtils interface for documentation*

## updateStartReferrerFeeP

```solidity
function updateStartReferrerFeeP(uint256 _value) internal
```

*Check IReferralsUtils interface for documentation*

## updateReferralsTargetVolumeUsd

```solidity
function updateReferralsTargetVolumeUsd(uint256 _value) internal
```

*Check IReferralsUtils interface for documentation*

## whitelistAllies

```solidity
function whitelistAllies(address[] _allies) internal
```

*Check IReferralsUtils interface for documentation*

## unwhitelistAllies

```solidity
function unwhitelistAllies(address[] _allies) internal
```

*Check IReferralsUtils interface for documentation*

## whitelistReferrers

```solidity
function whitelistReferrers(address[] _referrers, address[] _allies) internal
```

*Check IReferralsUtils interface for documentation*

## unwhitelistReferrers

```solidity
function unwhitelistReferrers(address[] _referrers) internal
```

*Check IReferralsUtils interface for documentation*

## registerPotentialReferrer

```solidity
function registerPotentialReferrer(address _trader, address _referrer) internal
```

*Check IReferralsUtils interface for documentation*

## distributeReferralReward

```solidity
function distributeReferralReward(address _trader, uint256 _volumeUsd, uint256 _referrerFeeUsd, uint256 _gnsPriceUsd) internal
```

*Check IReferralsUtils interface for documentation*

## claimAllyRewards

```solidity
function claimAllyRewards() internal
```

*Check IReferralsUtils interface for documentation*

## claimReferrerRewards

```solidity
function claimReferrerRewards() internal
```

*Check IReferralsUtils interface for documentation*

## getReferrerFeeProgressP

```solidity
function getReferrerFeeProgressP(address _referrer) internal view returns (uint256 progressP)
```

*Check IReferralsUtils interface for documentation*

## getTraderLastReferrer

```solidity
function getTraderLastReferrer(address _trader) internal view returns (address)
```

*Check IReferralsUtils interface for documentation*

## getTraderActiveReferrer

```solidity
function getTraderActiveReferrer(address _trader) internal view returns (address)
```

*Check IReferralsUtils interface for documentation*

## getReferrersReferred

```solidity
function getReferrersReferred(address _ally) internal view returns (address[])
```

*Check IReferralsUtils interface for documentation*

## getTradersReferred

```solidity
function getTradersReferred(address _referrer) internal view returns (address[])
```

*Check IReferralsUtils interface for documentation*

## getReferralsAllyFeeP

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

*Check IReferralsUtils interface for documentation*

## getReferralsStartReferrerFeeP

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

*Check IReferralsUtils interface for documentation*

## getReferralsTargetVolumeUsd

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

*Check IReferralsUtils interface for documentation*

## getAllyDetails

```solidity
function getAllyDetails(address _ally) internal view returns (struct IReferrals.AllyDetails)
```

*Check IReferralsUtils interface for documentation*

## getReferrerDetails

```solidity
function getReferrerDetails(address _referrer) internal view returns (struct IReferrals.ReferrerDetails)
```

*Check IReferralsUtils 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 IReferrals.ReferralsStorage s)
```

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

## \_whitelistAlly

```solidity
function _whitelistAlly(address _ally) internal
```

*Whitelists new ally*

### Parameters

| Name   | Type    | Description     |
| ------ | ------- | --------------- |
| \_ally | address | address of ally |

## \_unwhitelistAlly

```solidity
function _unwhitelistAlly(address _ally) internal
```

*Unwhitelists ally*

### Parameters

| Name   | Type    | Description     |
| ------ | ------- | --------------- |
| \_ally | address | address of ally |

## \_whitelistReferrer

```solidity
function _whitelistReferrer(address _referrer, address _ally) internal
```

*Whitelists new referrer*

### Parameters

| Name       | Type    | Description         |
| ---------- | ------- | ------------------- |
| \_referrer | address | address of referrer |
| \_ally     | address | address of ally     |

## \_unwhitelistReferrer

```solidity
function _unwhitelistReferrer(address _referrer) internal
```

*Unwhitelists referrer*

### Parameters

| Name       | Type    | Description         |
| ---------- | ------- | ------------------- |
| \_referrer | address | address of referrer |


---

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