# GNSReferrals

_Facet #2: Referral system_

## constructor

```solidity
constructor() public
```

## initializeReferrals

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

### Parameters

| Name                | Type    | Description                                                      |
| ------------------- | ------- | ---------------------------------------------------------------- |
| \_allyFeeP          | uint256 | % of total referral fee going to ally                            |
| \_startReferrerFeeP | uint256 | initial % of total referral fee earned when zero volume referred |
| \_targetVolumeUsd   | uint256 | usd opening volume to refer to reach 100% of referral fee        |

## updateAllyFeeP

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

_Updates allyFeeP_

### Parameters

| Name    | Type    | Description    |
| ------- | ------- | -------------- |
| \_value | uint256 | new ally fee % |

## updateStartReferrerFeeP

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

_Updates startReferrerFeeP_

### Parameters

| Name    | Type    | Description              |
| ------- | ------- | ------------------------ |
| \_value | uint256 | new start referrer fee % |

## updateReferralsTargetVolumeUsd

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

_Updates targetVolumeUsd_

### Parameters

| Name    | Type    | Description              |
| ------- | ------- | ------------------------ |
| \_value | uint256 | new target volume in usd |

## whitelistAllies

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

_Whitelists ally addresses_

### Parameters

| Name     | Type       | Description             |
| -------- | ---------- | ----------------------- |
| \_allies | address\[] | array of ally addresses |

## unwhitelistAllies

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

_Unwhitelists ally addresses_

### Parameters

| Name     | Type       | Description             |
| -------- | ---------- | ----------------------- |
| \_allies | address\[] | array of ally addresses |

## whitelistReferrers

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

_Whitelists referrer addresses_

### Parameters

| Name        | Type       | Description                           |
| ----------- | ---------- | ------------------------------------- |
| \_referrers | address\[] | array of referrer addresses           |
| \_allies    | address\[] | array of corresponding ally addresses |

## unwhitelistReferrers

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

_Unwhitelists referrer addresses_

### Parameters

| Name        | Type       | Description                 |
| ----------- | ---------- | --------------------------- |
| \_referrers | address\[] | array of referrer addresses |

## registerPotentialReferrer

```solidity
function registerPotentialReferrer(address _trader, address _referrer) external virtual
```

_Registers potential referrer for trader (only works if trader wasn't referred yet by someone else)_

### Parameters

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

## distributeReferralReward

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

_Distributes ally and referrer rewards_

### Parameters

| Name             | Type    | Description                            |
| ---------------- | ------- | -------------------------------------- |
| \_trader         | address | trader address                         |
| \_volumeUsd      | uint256 | trading volume in usd (1e18 precision) |
| \_referrerFeeUsd | uint256 | referrer fee in USD (1e18 precision)   |
| \_gnsPriceUsd    | uint256 | token price in usd (1e10 precision)    |

## claimAllyRewards

```solidity
function claimAllyRewards() external
```

_Claims pending GNS ally rewards of caller_

## claimReferrerRewards

```solidity
function claimReferrerRewards() external
```

_Claims pending GNS referrer rewards of caller_

## getReferrerFeeProgressP

```solidity
function getReferrerFeeProgressP(address _referrer) external view returns (uint256)
```

_Returns referrer fee % progress towards earning 100% based on his volume referred (1e10)_

### Parameters

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

## getTraderLastReferrer

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

_Returns last referrer of trader (whether referrer active or not)_

### Parameters

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

## getTraderActiveReferrer

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

_Returns active referrer of trader_

### Parameters

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

## getReferrersReferred

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

_Returns referrers referred by ally_

### Parameters

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

## getTradersReferred

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

_Returns traders referred by referrer_

### Parameters

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

## getReferralsAllyFeeP

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

_Returns ally fee % of total referral fee_

## getReferralsStartReferrerFeeP

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

_Returns start referrer fee % of total referral fee when zero volume was referred_

## getReferralsTargetVolumeUsd

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

_Returns target volume in usd to reach 100% of referral fee_

## getAllyDetails

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

_Returns ally details_

### Parameters

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

## getReferrerDetails

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

_Returns referrer details_

### Parameters

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