Skip to main content

FeeDistributor

FeeDistributor

Fee distributor for Domination Finance perpetual exchange

Receives fees from DomFiPerp and splits them between users, LPers, governance, RewardDistributors, etc. Highly configurable after deployment.

Dev note

Addresses

ChainAddress
Arbitrum Sepolia0xF14Ec5F09Fab76E7450D1Ba768430B88Fef04ED8

Functions

constructor

create a new FeeDistributor that initially sends all rewards to caller

constructor(contract IFeeReferral _feeReferral, contract IDomFiVault _domFiVault) public
Dev note

call setFeeAllocations() immediately after deploying

Parameters

NameTypeDescription
_feeReferralcontract IFeeReferralFeeReferral, for redirecting fees before distribution
_domFiVaultcontract IDomFiVaultVault to deposit referral fees

setOwner

function setOwner(address _owner) external

setFeeAllocations

create/update/delete FeeAllocations. Unmentioned FeeAllocations are unchanged. Must leave allos in a valid state (active feeRatios must sum to 1)

function setFeeAllocations(struct IFeeDistributor.FeeAllocation[] allos) external

Parameters

NameTypeDescription
allosstruct IFeeDistributor.FeeAllocation[]FeeAllocations to update or create

setFeeAllocation

create/update/delete a single FeeAllocation. Unmentioned allos are unchanged. Must leave allos in a valid state (active feeRatios must sum to 1)

function setFeeAllocation(struct IFeeDistributor.FeeAllocation allo) external

Parameters

NameTypeDescription
allostruct IFeeDistributor.FeeAllocationFeeAllocation to update or create

reallocateFees

Move a disabled FeeAllocation's accrued fees to the other allos. Useful to rescue funds from a NOTIFY type allo that reverts when transferRewardAmount is called.

function reallocateFees(uint256 alloIndex) external
Dev note

Can't do this automatically in _setFeeAllocation because allos may not be in a valid state.

Parameters

NameTypeDescription
alloIndexuint256redistribute funds from feeAllocations[alloIndex]

receiveFee

Notify FeeDistributor that caller has sent it some fees. Check FeeReferral to see who referred the caller, and send that referrer their share of fees. Then, proportionally increase pending fees of each active FeeAllocation.

function receiveFee(address caller) external
Dev note

Normally, a function like this would pull tokens straight from msg.sender. This push-and-notify model allows the exchange to collect fees without having to call approve() each time, and (in the case of deposits and increases) to transfer tokens straight from the user to FeeDistributor without an intermediary transfer to the exchange. EOAs and integrators calling receiveFee() should do so within the context of a single smart contract transaction - otherwise, anybody can call receiveFee() with a high gas payment to "take credit" for a previous transfer.

Parameters

NameTypeDescription
calleraddressAddress responsible for recent increase in collateral balance. For instance, a trader who has just paid a fee.

distributeFees

Distribute accrued fees to all active FeeAllocations

function distributeFees() external

distributeFee

Distribute any accrued fee to a single fee recipient.

function distributeFee(address recipient) external
Dev note

If a NOTIFY call reverts, distributeFees() will revert until an admin disables that allocation. In the meantime, this function may be used to continue fee distribution to other recipients.

Parameters

NameTypeDescription
recipientaddressAddress of the fee recipient

transferFee

Pay out accrued fees (integer part) to a DIRECT allocation

function transferFee(uint256 alloIndex) internal returns (uint256 fee)
Dev note

DIRECT only, unchecked

Parameters

NameTypeDescription
alloIndexuint256Index of a DIRECT allocation

Return Values

NameTypeDescription
feeuint256Actual collateral transfered. Can't send <1 wei.

transferNotifyFee

Pay out accrued fees (integer part) to a NOTIFY allocation

function transferNotifyFee(uint256 alloIndex) internal returns (uint256 fee)
Dev note

NOTIFY only. Recipient must implement IRewardRecipient. Does not call transferRewardAmount if 0 tokens to be transfered.

Parameters

NameTypeDescription
alloIndexuint256Index of a NOTIFY allocation

Return Values

NameTypeDescription
feeuint256Actual collateral transfered. Can't send <1 wei.

_setFeeAllocation

Update or add a stored FeeAllocation based on its recipient

function _setFeeAllocation(struct IFeeDistributor.FeeAllocation allo) internal

Parameters

NameTypeDescription
allostruct IFeeDistributor.FeeAllocationFeeAllo with a recipent

getFeeAllocationIndex

find a stored fee allocation for a given recipient

function getFeeAllocationIndex(address recipient) public view returns (bool found, uint256 index)
Dev note

Linear with feeAllocations.length

Parameters

NameTypeDescription
recipientaddressSearch for a saved allo with this recipient

Return Values

NameTypeDescription
foundboolwhether an allo already exists
indexuint256index of the allo if found, otherwise feeAllocations.length

_getFeeAllocationIndex

find a stored fee allocation for a given recipient

function _getFeeAllocationIndex(address recipient) internal view returns (bool found, uint256 index)
Dev note

Linear with feeAllocations.length

Parameters

NameTypeDescription
recipientaddressSearch for a saved allo with this recipient

Return Values

NameTypeDescription
foundboolwhether an allo already exists
indexuint256index of the allo if found, otherwise feeAllocations.length

_setFeeAllocation

Set fields (except accrued fee) for allo at the given index. If updating to DELETED, disburse then delete. If updating to FORCE_DELETED, delete.

function _setFeeAllocation(uint256 index, struct IFeeDistributor.FeeAllocation allo) internal
Dev note

Not public because order of fee allocations can change between calls

Parameters

NameTypeDescription
indexuint256Index in feeAllocations
allostruct IFeeDistributor.FeeAllocationStore this recipient, feeRatio, and distributionType at index

requireCompleteFeeRatio

revert if the sum of feeRatios across all active FeeAllocations does not equal 1.

function requireCompleteFeeRatio() internal view
Dev note

Each recipient gets feeRatio * fee; if the portions don't actually sum to fee there will be problems. Instead of saving weights and recomputing each time a fee is received, the owner is responsible for managing them and we check only when they're set.

feeAllocationsLength

Length of the public feeAllocations array; convenience function

function feeAllocationsLength() external view returns (uint256)

Return Values

NameTypeDescription
[0]uint256uint256 feeAllocations.length

setFeeReferral

Set FeeReferral, for redirecting part of fees on receipt

function setFeeReferral(contract IFeeReferral _feeReferral) external

Parameters

NameTypeDescription
_feeReferralcontract IFeeReferralNew IFeeReferral instance

Events

ReferralDistributed

event ReferralDistributed(address recipient, address source, uint256 amount)

FeeDistributed

event FeeDistributed(address to, uint256 amount)

UpdateOwner

event UpdateOwner(address owner)

FeeReferralSet

event FeeReferralSet(contract IFeeReferral _feeReferral)

Modifiers

onlyOwner

modifier onlyOwner()

Errors

InvalidFeeRatioSum

The feeRatios of active allocations must sum to 1 in order to split up incoming fees, but after an update the sum was something different.

error InvalidFeeRatioSum(FPUnsigned feeRatioSum)

Parameters

NameTypeDescription
feeRatioSumFPUnsignedthe offending fee ratio sum

OwnerOnly

error OwnerOnly()

AllocationNotDisabled

Can only reallocate the feed of a disabled allocation

error AllocationNotDisabled()

Undistributable

When deleting an allocation with accumulated fees, we try to distribute those fees. But a DISABLED allocation has no transfer function. Before attempting to delete this allo, call reallocateFees or use FORCE_DELETE.

error Undistributable()

AllocationNotFound

error AllocationNotFound()

Variables

feeReferral

domFiVault

feeAllocations

totalPendingFees

owner

collateral