Skip to content

Commit

Permalink
fix: incorrect initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
k1rill-fedoseev committed Sep 14, 2023
1 parent 4461aa1 commit 0d287bb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/zkbob/utils/ZkBobAccounting.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ contract ZkBobAccounting is IZkBobAccounting, Ownable {
slot0 = Slot0({
maxWeeklyAvgTvl: _maxWeeklyAvgTvl,
maxWeeklyTxCount: _maxWeeklyTxCount,
tailSlot: 0,
tailSlot: curSlot,
headSlot: curSlot,
cumTvl: _cumTvl,
txCount: _txCount
});
slot1 = Slot1({tvl: _tvl});
snapshots[0] = Snapshot({nextSlot: curSlot, txCount: _txCount, cumTvl: _cumTvl});
}

/**
Expand Down Expand Up @@ -309,7 +308,7 @@ contract ZkBobAccounting is IZkBobAccounting, Ownable {
// however, in order to keep constant gas usage, "if" is being used
// this can lead to a longer sliding window (> 1 week) in some cases,
// but eventually it will converge back to the 1 week target
if (s0.txCount > 0 && curSlot - s0.tailSlot > WEEK_SLOTS) {
if (s0.headSlot > s0.tailSlot && curSlot - s0.tailSlot > WEEK_SLOTS) {
// if tail is more than 1 week behind, we move tail pointer to the next snapshot
Snapshot memory sn = snapshots[s0.tailSlot];
delete snapshots[s0.tailSlot];
Expand Down
14 changes: 14 additions & 0 deletions test/zkbob/utils/ZkBobAccounting.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ contract ZkBobAccountingTest is Test {
_checkStats({_maxWeeklyAvgTvl: 200, _maxWeeklyTxCount: 504, _txCount: 1207});
}

function testNoWeeklyActivity() public {
pool.recordOperation(IZkBobAccounting.TxType.Common, user1, int256(100 gwei));
pool.recordOperation(IZkBobAccounting.TxType.Common, user1, 0);

vm.warp(block.timestamp + 10 days);

for (uint256 i = 0; i < 10; i++) {
pool.recordOperation(IZkBobAccounting.TxType.Common, user1, 0);
vm.warp(block.timestamp + 1 days);
}

_checkStats({_maxWeeklyAvgTvl: 100, _maxWeeklyTxCount: 7, _txCount: 12});
}

function testDepositCap() public {
pool.setLimits(0, 1000 gwei, 500 gwei, 500 gwei, 300 gwei, 100 gwei, 0, 0);

Expand Down

0 comments on commit 0d287bb

Please sign in to comment.