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 Sepolia0xb2be0cD8C17d5BBCF3fb2f37Ab8c109c598523eC
Base Sepolia0x3ED9Adb7D915E1E08f7588684E403dd7F2e54e20
Base Mainnet0x1122A0AE37673D8c57F73eebBf730268B82c7421

Functions

initialize

function initialize(struct StorageInstance _store) 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 FeeAllocation[] allos) external

Parameters

NameTypeDescription
allosstruct 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 FeeAllocation allo) external

Parameters

NameTypeDescription
allostruct 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(address recipient) external
Dev note

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

Parameters

NameTypeDescription
recipientaddressredistribute 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(struct FeeAllocationPtr allocation) internal returns (uint256 fee)
Dev note

DIRECT only, unchecked

Parameters

NameTypeDescription
allocationstruct FeeAllocationPtrIndex 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(struct FeeAllocationPtr allocation) internal returns (uint256 fee)
Dev note

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

Parameters

NameTypeDescription
allocationstruct FeeAllocationPtrIndex of a NOTIFY allocation

Return Values

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

_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(struct FeeAllocation args) internal
Dev note

Not public because order of fee allocations can change between calls

Parameters

NameTypeDescription
argsstruct 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

Events

ReferralDistributed

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

FeeDistributed

event FeeDistributed(address to, uint256 amount)

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

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()

UnknownDistributionType

error UnknownDistributionType()

Variables

props

feeAllocations