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 fee allocation
Addresses
Chain | Address |
---|---|
Arbitrum Sepolia | 0xb2be0cD8C17d5BBCF3fb2f37Ab8c109c598523eC |
Base Sepolia | 0x3ED9Adb7D915E1E08f7588684E403dd7F2e54e20 |
Base Mainnet | 0x1122A0AE37673D8c57F73eebBf730268B82c7421 |
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
Name | Type | Description |
---|---|---|
allos | struct 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
Name | Type | Description |
---|---|---|
allo | struct 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(address recipient) external
Can't do this automatically in _setFeeAllocation because allos may not be in a valid state.
Parameters
Name | Type | Description |
---|---|---|
recipient | address | 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(struct FeeAllocationPtr allocation) internal returns (uint256 fee)
DIRECT only, unchecked
Parameters
Name | Type | Description |
---|---|---|
allocation | struct FeeAllocationPtr | 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(struct FeeAllocationPtr allocation) internal returns (uint256 fee)
NOTIFY only. Recipient must implement IRewardRecipient. Does not call transferRewardAmount if 0 tokens to be transfered.
Parameters
Name | Type | Description |
---|---|---|
allocation | struct FeeAllocationPtr | Index of a NOTIFY allocation |
Return Values
Name | Type | Description |
---|---|---|
fee | uint256 | Actual 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
Not public because order of fee allocations can change between calls
Parameters
Name | Type | Description |
---|---|---|
args | struct 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 |
Events
ReferralDistributed
event ReferralDistributed(address recipient, address source, uint256 amount)
FeeDistributed
event FeeDistributed(address to, uint256 amount)
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 |
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()