Delegation Fees + unit tests
Closed this issue · 0 comments
cmalfesi commented
Delegation Fee
- Keep track of delegation fee variation in order to be able to determine the fee to use when a epoch reward is being claimed
struct DFeeData {
uint256 fromEpoch;
uint256 fee;
bool applied;
}
DFeeData[] public delegationFees;
event CommitNewFees(uint256 deadline, uint256 feeRate);
event NewFees(uint256 fromEpoch, uint256 feeRate);
Determine Epoch Fee
- Iterate
delegationFees
backwards, take first wherefromEpoch
is lower or equal to the given epoch
Commit new fee
- Only 1 pending fee at any given time
- If at the moment of committing a new fee there is a delegation fee pending to be applied:
- The pending fee still not able to applied, due to deadline not reached, the new fee will replace the pending one as the new pending
- The pending fee can be applied then mark as
applied
and add the new one as pending. Emit NewFees event
- Emit CommitedNewFee event
Apply Fee
- Only mark a fee as applied if current epoch is greater or equal to
fromEpoch
- Mark a fee as applied when a new one is committed an the pending one can be applied
- Mark a fee as applied when claiming reward for an epoch which needs to use the pending fee