Skip to main content

DistributionManager

Git Source

Inherits: IDistributionManager, GACManaged, CustomReentrancyGuard

Author: Struct Finance

State Variables

totalAllocationPoints

Uses SafeERC20 to interact with ERC20 tokens safely.

Total allocation points for token distribution.

uint256 public totalAllocationPoints;

totalAllocationFee

Total allocation points for fee distribution.

uint256 public totalAllocationFee;

rewardsPerSecond

Rewards being distributed per second based on token distribution.

uint256 public rewardsPerSecond;

lastUpdateTime

The last distribution timestamp.

uint256 public lastUpdateTime;

queuedNative

Native tokens accrued and queuing for distribution.

uint256 public queuedNative;

isInitialized

Indicates if the contract has been initialized.

bool public isInitialized;

recipients

Array of addresses and their token and fee allocation.

RecipientData[] public recipients;

structToken

The STRUCT token contract.

IERC20Metadata public structToken;

nativeToken

The WAVAX token contract.

IERC20Metadata public nativeToken;

router

Joe router contract.

IJoeRouter public router;

Functions

constructor

Contract constructor that initializes the contract and its variables.

constructor(
IERC20Metadata _nativeToken,
uint256 _rewardsPerSecond,
IGAC _globalAccessControl,
RecipientData[] memory _recipientData
);

Parameters

NameTypeDescription
_nativeTokenIERC20MetadataThe token contract that rewards are distributed in.
_rewardsPerSeconduint256The rate at which rewards are distributed per second.
_globalAccessControlIGACThe global access control contract.
_recipientDataRecipientData[]An array of initial recipients that rewards are distributed to

initialize

Initialize for initial recipients Initializer for STRUCT token.

Allows the contract to get the struct token address after the contract has been deployed.

Can only be called once.

Initialize the contract for the STRUCT token.

function initialize(IERC20Metadata _structToken) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_structTokenIERC20MetadataThe address of the STRUCT token contract.

distributeRewards

Distributes rewards from protocol fees and token distribution to recipients.

Loops through the array of recipient data to calculate the recipient's token and fee allocation.

Method then calls notifyRewardAmount in recipient contracts to transfer the allocated Struct and native tokens.

function distributeRewards() public nonReentrant;

queueFees

Loop through recipient array and distribute rewards Account for token distribution Account for fee distribution Inform recipient contract how much STRUCT it received Inform recipient contract how much native token it received all native fees distributed - reset to zero <=============== RESTRICTED METHODS ===============>

Queue the fees until reward is distributed

function queueFees(uint256 _amount) external onlyRole(PRODUCT);

Parameters

NameTypeDescription
_amountuint256The amount of fees to queue, in native tokens

addDistributionRecipient

Fees queued for next distribution, in native tokens;

Allows owner to add a new recipient into the RecipientData array

Only callable by the Governance role.

function addDistributionRecipient(address _destination, uint256 _allocationPoints, uint256 _allocationFee)
external
onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_destinationaddressThe address of the new recipient
_allocationPointsuint256The number of allocation points the new recipient will receive
_allocationFeeuint256The amount of fees the new recipient will receive

removeDistributionRecipient

Update total token allocation Update total fee allocation Push data into RecipientData array

Allows owner to remove a recipient from the RecipientData array

function removeDistributionRecipient(uint256 index) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
indexuint256The index of the recipient to be removed

editDistributionRecipient

Update total token allocation Update total fee allocation shift distributions indexes across

Allows owner to edit details of a recipient in the RecipientData array

Only callable by the Governance role.

function editDistributionRecipient(
uint256 _index,
address _destination,
uint256 _allocationPoints,
uint256 _allocationFee
) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_indexuint256The index of the recipient to edit.
_destinationaddressThe address of the new recipient
_allocationPointsuint256The number of allocation points the new recipient will receive
_allocationFeeuint256The amount of fees the new recipient will receive

setRewardsPerSecond

Update destination Update total token allocation Update total fee allocation Update allocations

Allows the owner to set the rewards per second.

Only callable by the Governance role.

function setRewardsPerSecond(uint256 _newRewardsPerSecond) external onlyRole(GOVERNANCE);

Parameters

NameTypeDescription
_newRewardsPerSeconduint256The new rewards per second.

getRecipients

<=============== VIEWS ===============>

Returns an array of all recipients.

function getRecipients() public view returns (RecipientData[] memory);

Returns

NameTypeDescription
<none>RecipientData[]An array of all recipients.

_validateRecipientConfig

<=============== PRIVATE ===============>

validates that the recipient:

  • destination is not a zero address
  • either allocationPoints and allocationFee is a non-zero value
function _validateRecipientConfig(address _destination, uint256 _allocationPoints, uint256 _allocationFee)
public
pure;

Parameters

NameTypeDescription
_destinationaddress- the recipient destination address
_allocationPointsuint256- the recipient Struct token allocation
_allocationFeeuint256- the recipient native token allocation

Events

DistributionRewards

<=============== EVENTS ===============>

Event emitted when rewards are distributed.

event DistributionRewards(uint256 _distributionAmount);

QueueFees

Event emitted when fees are queued.

event QueueFees(uint256 _queuedNative);

AddRecipient

Event emitted when a recipient is added.

event AddRecipient(uint256 _index, address indexed _destination, uint256 _allocationPoints, uint256 _allocationFee);

EditRecipient

Event emitted when a recipient is edited.

event EditRecipient(uint256 _index, address indexed _destination, uint256 _allocationPoints, uint256 _allocationFee);

RewardAdded

Event emitted when rewards are added.

event RewardAdded(uint256 _allocatedTotal, uint256 periodFinish, uint256 _excess);

RewardsPerSecondUpdate

Event emitted when rewards per second is updated.

event RewardsPerSecondUpdate(uint256 _rewardsPerSecond);