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.
See FeeAllocation
Addresses
Chain | Address |
---|---|
Arbitrum Sepolia | 0xF14Ec5F09Fab76E7450D1Ba768430B88Fef04ED8 |
Zircuit | 0x499D2715C2DAC02E6428f02638C60cD7ede23F24 |
Functions
constructor
create a new FeeDistributor that initially sends all rewards to caller
constructor(contract IFeeReferral _feeReferral, contract IDomFiVault _domFiVault) public
call setFeeAllocations() immediately after deploying
Parameters
Name | Type | Description |
---|---|---|
_feeReferral | contract IFeeReferral | FeeReferral, for redirecting fees before distribution |
_domFiVault | contract IDomFiVault | Vault 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
Name | Type | Description |
---|---|---|
allos | struct 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
Name | Type | Description |
---|---|---|
allo | struct IFeeDistributor.FeeAllocation | FeeAllocation 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
Can't do this automatically in _setFeeAllocation because allos may not be in a valid state.
Parameters
Name | Type | Description |
---|---|---|
alloIndex | uint256 | redistribute 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
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
Name | Type | Description |
---|---|---|
caller | address | Address 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
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
Name | Type | Description |
---|---|---|
recipient | address | Address of the fee recipient |
transferFee
Pay out accrued fees (integer part) to a DIRECT allocation
function transferFee(uint256 alloIndex) internal returns (uint256 fee)
DIRECT only, unchecked
Parameters
Name | Type | Description |
---|---|---|
alloIndex | uint256 | Index of a DIRECT allocation |
Return Values
Name | Type | Description |
---|---|---|
fee | uint256 | Actual 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)
NOTIFY only. Recipient must implement IRewardRecipient. Does not call transferRewardAmount if 0 tokens to be transfered.
Parameters
Name | Type | Description |
---|---|---|
alloIndex | uint256 | Index of a NOTIFY allocation |
Return Values
Name | Type | Description |
---|---|---|
fee | uint256 | Actual 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
Name | Type | Description |
---|---|---|
allo | struct IFeeDistributor.FeeAllocation | FeeAllo with a recipent |
getFeeAllocationIndex
find a stored fee allocation for a given recipient
function getFeeAllocationIndex(address recipient) public view returns (bool found, uint256 index)
Linear with feeAllocations.length
Parameters
Name | Type | Description |
---|---|---|
recipient | address | Search for a saved allo with this recipient |
Return Values
Name | Type | Description |
---|---|---|
found | bool | whether an allo already exists |
index | uint256 | index 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)
Linear with feeAllocations.length
Parameters
Name | Type | Description |
---|---|---|
recipient | address | Search for a saved allo with this recipient |
Return Values
Name | Type | Description |
---|---|---|
found | bool | whether an allo already exists |
index | uint256 | index 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
Not public because order of fee allocations can change between calls
Parameters
Name | Type | Description |
---|---|---|
index | uint256 | Index in feeAllocations |
allo | struct IFeeDistributor.FeeAllocation | Store this recipient, feeRatio, and distributionType at index |
requireCompleteFeeRatio
revert if the sum of feeRatio
s across all active FeeAllocations
does not equal 1.
function requireCompleteFeeRatio() internal view
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
Name | Type | Description |
---|---|---|
[0] | uint256 | uint256 feeAllocations.length |
setFeeReferral
Set FeeReferral, for redirecting part of fees on receipt
function setFeeReferral(contract IFeeReferral _feeReferral) external
Parameters
Name | Type | Description |
---|---|---|
_feeReferral | contract IFeeReferral | New 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 feeRatio
s 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
Name | Type | Description |
---|---|---|
feeRatioSum | FPUnsigned | the 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()