Skip to content

Commit

Permalink
fix a bug in fee calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Mar 12, 2023
1 parent 8ddc073 commit 33ebe1f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ library LibProposing {
isProposal: true,
tNow: uint64(block.timestamp),
tLast: state.lastProposedAt,
tAvg: state.avgBlockTime
tAvg: state.avgBlockTime,
tCap: config.blockTimeCap
});
fee = LibUtils.getSlotsAdjustedFee({
state: state,
Expand Down
17 changes: 8 additions & 9 deletions packages/protocol/contracts/L1/libs/LibUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,19 @@ library LibUtils {
bool isProposal,
uint64 tNow,
uint64 tLast,
uint64 tAvg
uint64 tAvg,
uint64 tCap
) internal view returns (uint256 newFeeBase, uint256 tRelBp) {
if (tAvg == 0) {
newFeeBase = state.feeBase;
// tRelBp = 0;
} else {
uint256 _tAvg = tAvg > config.proofTimeCap
? config.proofTimeCap
: tAvg;
uint256 tGrace = (config.feeGracePeriodPctg * _tAvg) / 100;
uint256 tMax = (config.feeMaxPeriodPctg * _tAvg) / 100;
uint256 a = tLast + tGrace;
uint256 b = tNow > a ? tNow - a : 0;
tRelBp = (b.min(tMax) * 10000) / tMax; // [0 - 10000]
uint256 _tAvg = tAvg > tCap ? tCap : tAvg;
uint256 grace = (config.feeGracePeriodPctg * _tAvg) / 100;
uint256 max = (config.feeMaxPeriodPctg * _tAvg) / 100;
uint256 a = tLast + tAvg + grace;
a = tNow > a ? tNow - a : 0;
tRelBp = (a.min(max) * 10000) / max; // [0 - 10000]
uint256 alpha = 10000 +
((config.rewardMultiplierPctg - 100) * tRelBp) /
100;
Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ library LibVerifying {
isProposal: false,
tNow: provenAt,
tLast: proposedAt,
tAvg: state.avgProofTime
tAvg: state.avgProofTime,
tCap: config.proofTimeCap
});
reward = LibUtils.getSlotsAdjustedFee({
state: state,
Expand Down

0 comments on commit 33ebe1f

Please sign in to comment.