Skip to content

Commit

Permalink
fix: property and added a utility view function for epoch calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
GalloDaSballo committed Oct 19, 2024
1 parent 3e5bcc6 commit 7c055d4
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 6 deletions.
15 changes: 15 additions & 0 deletions src/BribeInitiative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {DoubleLinkedList} from "./utils/DoubleLinkedList.sol";


import {EncodingDecodingLib} from "src/utils/EncodingDecodingLib.sol";
import {console} from "forge-std/console.sol";


contract BribeInitiative is IInitiative, IBribeInitiative {
Expand Down Expand Up @@ -182,6 +183,20 @@ contract BribeInitiative is IInitiative, IBribeInitiative {
return _decodeLQTYAllocation(lqtyAllocationByUserAtEpoch[_user].items[_epoch].value);
}

/// @inheritdoc IBribeInitiative
function getMostRecentUserEpoch(address _user) external view returns (uint16) {
uint16 mostRecentUserEpoch = lqtyAllocationByUserAtEpoch[_user].getHead();

return mostRecentUserEpoch;
}

/// @inheritdoc IBribeInitiative
function getMostRecentTotalEpoch() external view returns (uint16) {
uint16 mostRecentTotalEpoch = totalLQTYAllocationByEpoch.getHead();

return mostRecentTotalEpoch;
}

function onAfterAllocateLQTY(
uint16 _currentEpoch,
address _user,
Expand Down
6 changes: 6 additions & 0 deletions src/interfaces/IBribeInitiative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,10 @@ interface IBribeInitiative {
function claimBribes(ClaimData[] calldata _claimData)
external
returns (uint256 boldAmount, uint256 bribeTokenAmount);

/// @notice Given a user address return the last recorded epoch for their allocation
function getMostRecentUserEpoch(address _user) external view returns (uint16);

/// @notice Return the last recorded epoch for the system
function getMostRecentTotalEpoch() external view returns (uint16);
}
20 changes: 20 additions & 0 deletions test/recon/CryticToFoundry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,24 @@ contract CryticToFoundry is Test, TargetFunctions, FoundryAsserts {
initiative_claimBribes(0,3,0,0);
property_BI11();
}


// forge test --match-test test_property_BI04_1 -vv
function test_property_BI04_1() public {


governance_depositLQTY(2);

vm.roll(block.number + 1);
vm.warp(block.timestamp + 654326);
governance_allocateLQTY_clamped_single_initiative(0,1,0);


vm.roll(block.number + 1);
vm.warp(block.timestamp + 559510);
property_resetting_never_reverts();

property_BI04();

}
}
14 changes: 8 additions & 6 deletions test/recon/properties/BribeInitiativeProperties.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,16 @@ function property_BI04() public {
function _getLastLQTYAllocationKnown(IBribeInitiative initiative, uint16 targetEpoch) internal returns (uint88) {
uint16 currenEpoch;
uint88 found;
while(currenEpoch <= targetEpoch) {
(uint88 totalLQTYAllocatedAtEpoch, uint32 ts) = initiative.totalLQTYAllocatedByEpoch(currenEpoch++);
if(ts != 0) {
found = totalLQTYAllocatedAtEpoch;
}

uint16 mostRecentTotalEpoch = initiative.getMostRecentTotalEpoch();

if(targetEpoch < mostRecentTotalEpoch) {
(uint88 totalLQTYAllocatedAtEpoch, uint32 ts) = initiative.totalLQTYAllocatedByEpoch(targetEpoch);
return totalLQTYAllocatedAtEpoch;
}

return found;
(uint88 totalLQTYAllocatedAtEpoch, uint32 ts) = initiative.totalLQTYAllocatedByEpoch(mostRecentTotalEpoch);
return totalLQTYAllocatedAtEpoch;
}

function property_BI05() public {
Expand Down

0 comments on commit 7c055d4

Please sign in to comment.