Skip to content

Commit b880481

Browse files
authored
Merge pull request #129 from liquity/bribe-initiative-sorted-list-getter
Add sorted list info to getters in BribeInitiative
2 parents 4b4a3a6 + 1c33ece commit b880481

File tree

7 files changed

+108
-66
lines changed

7 files changed

+108
-66
lines changed

src/BribeInitiative.sol

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,26 @@ contract BribeInitiative is IInitiative, IBribeInitiative {
5252
}
5353

5454
/// @inheritdoc IBribeInitiative
55-
function totalLQTYAllocatedByEpoch(uint256 _epoch) external view returns (uint256, uint256) {
56-
return (totalLQTYAllocationByEpoch.items[_epoch].lqty, totalLQTYAllocationByEpoch.items[_epoch].offset);
55+
function totalLQTYAllocatedByEpoch(uint256 _epoch) external view returns (uint256, uint256, uint256, uint256) {
56+
return (
57+
totalLQTYAllocationByEpoch.items[_epoch].lqty,
58+
totalLQTYAllocationByEpoch.items[_epoch].offset,
59+
totalLQTYAllocationByEpoch.items[_epoch].prev,
60+
totalLQTYAllocationByEpoch.items[_epoch].next
61+
);
5762
}
5863

5964
/// @inheritdoc IBribeInitiative
60-
function lqtyAllocatedByUserAtEpoch(address _user, uint256 _epoch) external view returns (uint256, uint256) {
65+
function lqtyAllocatedByUserAtEpoch(address _user, uint256 _epoch)
66+
external
67+
view
68+
returns (uint256, uint256, uint256, uint256)
69+
{
6170
return (
6271
lqtyAllocationByUserAtEpoch[_user].items[_epoch].lqty,
63-
lqtyAllocationByUserAtEpoch[_user].items[_epoch].offset
72+
lqtyAllocationByUserAtEpoch[_user].items[_epoch].offset,
73+
lqtyAllocationByUserAtEpoch[_user].items[_epoch].prev,
74+
lqtyAllocationByUserAtEpoch[_user].items[_epoch].next
6475
);
6576
}
6677

src/interfaces/IBribeInitiative.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,24 @@ interface IBribeInitiative {
4747
/// @param _epoch Epoch at which the LQTY was allocated
4848
/// @return totalLQTYAllocated Total LQTY allocated
4949
/// @return offset Voting power offset
50+
/// @return prev Previous epoch at which the total LQTY allocation was updated
51+
/// @return next Next epoch at which the total LQTY allocation was updated
5052
function totalLQTYAllocatedByEpoch(uint256 _epoch)
5153
external
5254
view
53-
returns (uint256 totalLQTYAllocated, uint256 offset);
55+
returns (uint256 totalLQTYAllocated, uint256 offset, uint256 prev, uint256 next);
5456
/// @notice LQTY allocated by a user to the initiative at a given epoch
5557
/// Voting power can be calculated as `lqtyAllocated * timestamp - offset`
5658
/// @param _user Address of the user
5759
/// @param _epoch Epoch at which the LQTY was allocated by the user
5860
/// @return lqtyAllocated LQTY allocated by the user
5961
/// @return offset Voting power offset
62+
/// @return prev Previous epoch at which the user updated the LQTY allocation for this initiative
63+
/// @return next Next epoch at which the user updated the LQTY allocation for this initiative
6064
function lqtyAllocatedByUserAtEpoch(address _user, uint256 _epoch)
6165
external
6266
view
63-
returns (uint256 lqtyAllocated, uint256 offset);
67+
returns (uint256 lqtyAllocated, uint256 offset, uint256 prev, uint256 next);
6468

6569
/// @notice Deposit bribe tokens for a given epoch
6670
/// @dev The caller has to approve this contract to spend the BOLD and bribe tokens.

test/BribeInitiative.t.sol

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
9393
// allocate LQTY to the bribeInitiative
9494
_allocateLQTY(user1, 10e18, 0);
9595
// total LQTY allocated for this epoch should increase
96-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
96+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
9797
assertEq(totalLQTYAllocated, 10e18);
9898
}
9999

@@ -107,7 +107,7 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
107107
// allocate LQTY to veto bribeInitiative
108108
_allocateLQTY(user1, 0, 10e18);
109109
// total LQTY allocated for this epoch should not increase
110-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
110+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
111111
assertEq(totalLQTYAllocated, 0);
112112
}
113113

@@ -122,8 +122,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
122122
_allocateLQTY(user1, 5e18, 0);
123123

124124
// total LQTY allocated for this epoch should increase
125-
(uint256 totalLQTYAllocated1,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
126-
(uint256 userLQTYAllocated1,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
125+
(uint256 totalLQTYAllocated1,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
126+
(uint256 userLQTYAllocated1,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
127127
assertEq(totalLQTYAllocated1, 5e18);
128128
assertEq(userLQTYAllocated1, 5e18);
129129

@@ -133,8 +133,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
133133
_allocateLQTY(user1, 5e18, 0);
134134

135135
// total LQTY allocated for this epoch should not change
136-
(uint256 totalLQTYAllocated2,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
137-
(uint256 userLQTYAllocated2,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
136+
(uint256 totalLQTYAllocated2,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
137+
(uint256 userLQTYAllocated2,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
138138
assertEq(totalLQTYAllocated2, 5e18);
139139
assertEq(userLQTYAllocated1, 5e18);
140140
}
@@ -147,14 +147,14 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
147147

148148
// user1 allocates in first epoch
149149
_allocateLQTY(user1, 5e18, 0);
150-
(uint256 totalLQTYAllocated1,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
151-
(uint256 userLQTYAllocated1,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
150+
(uint256 totalLQTYAllocated1,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
151+
(uint256 userLQTYAllocated1,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
152152
assertEq(totalLQTYAllocated1, 5e18);
153153
assertEq(userLQTYAllocated1, 5e18);
154154

155155
_allocateLQTY(user1, 5e18, 0);
156-
(uint256 totalLQTYAllocated2,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
157-
(uint256 userLQTYAllocated2,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
156+
(uint256 totalLQTYAllocated2,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
157+
(uint256 userLQTYAllocated2,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
158158
assertEq(totalLQTYAllocated2, 5e18);
159159
assertEq(userLQTYAllocated2, 5e18);
160160
}
@@ -166,14 +166,14 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
166166

167167
// user1 allocates in first epoch
168168
_allocateLQTY(user1, 5e18, 0);
169-
(uint256 totalLQTYAllocated1,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
170-
(uint256 userLQTYAllocated1,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
169+
(uint256 totalLQTYAllocated1,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
170+
(uint256 userLQTYAllocated1,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
171171
assertEq(totalLQTYAllocated1, 5e18);
172172
assertEq(userLQTYAllocated1, 5e18);
173173

174174
console2.log("current governance epoch: ", governance.epoch());
175175
// user's linked-list should be updated to have a value for the current epoch
176-
(uint256 allocatedAtEpoch,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
176+
(uint256 allocatedAtEpoch,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
177177
console2.log("allocatedAtEpoch: ", allocatedAtEpoch);
178178
}
179179

@@ -186,8 +186,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
186186

187187
// user1 allocates in first epoch
188188
_allocateLQTY(user1, 10e18, 0);
189-
(uint256 totalLQTYAllocated1,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
190-
(uint256 userLQTYAllocated1,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
189+
(uint256 totalLQTYAllocated1,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
190+
(uint256 userLQTYAllocated1,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
191191
assertEq(totalLQTYAllocated1, 10e18);
192192
assertEq(userLQTYAllocated1, 10e18);
193193

@@ -196,8 +196,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
196196

197197
// user allocations should be disjoint because they're in separate epochs
198198
_allocateLQTY(user2, 10e18, 0);
199-
(uint256 totalLQTYAllocated2,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
200-
(uint256 userLQTYAllocated2,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user2, governance.epoch());
199+
(uint256 totalLQTYAllocated2,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
200+
(uint256 userLQTYAllocated2,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user2, governance.epoch());
201201
assertEq(totalLQTYAllocated2, 20e18);
202202
assertEq(userLQTYAllocated2, 10e18);
203203
}
@@ -211,14 +211,14 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
211211

212212
// user1 allocates in first epoch
213213
_allocateLQTY(user1, 10e18, 0);
214-
(uint256 totalLQTYAllocated1,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
215-
(uint256 userLQTYAllocated1,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
214+
(uint256 totalLQTYAllocated1,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
215+
(uint256 userLQTYAllocated1,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
216216
assertEq(totalLQTYAllocated1, 10e18);
217217
assertEq(userLQTYAllocated1, 10e18);
218218

219219
_allocateLQTY(user2, 10e18, 0);
220-
(uint256 totalLQTYAllocated2,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
221-
(uint256 userLQTYAllocated2,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user2, governance.epoch());
220+
(uint256 totalLQTYAllocated2,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
221+
(uint256 userLQTYAllocated2,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user2, governance.epoch());
222222
assertEq(totalLQTYAllocated2, 20e18);
223223
assertEq(userLQTYAllocated2, 10e18);
224224
}
@@ -232,13 +232,13 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
232232

233233
// user1 allocates in first epoch
234234
_allocateLQTY(user1, 10e18, 0);
235-
(uint256 totalLQTYAllocated1,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
235+
(uint256 totalLQTYAllocated1,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
236236
assertEq(totalLQTYAllocated1, 10e18);
237237

238238
// warp to the end of the epoch
239239
vm.warp(block.timestamp + (EPOCH_VOTING_CUTOFF - 1));
240240

241-
(uint256 totalLQTYAllocated2,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
241+
(uint256 totalLQTYAllocated2,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
242242
assertEq(totalLQTYAllocated2, 10e18);
243243
}
244244

@@ -587,7 +587,7 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
587587

588588
// user votes on bribeInitiative
589589
_allocateLQTY(user1, 1e18, 0);
590-
(uint256 lqtyAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
590+
(uint256 lqtyAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
591591
assertEq(lqtyAllocated, 1e18, "lqty doesn't immediately get allocated");
592592
}
593593

@@ -615,8 +615,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
615615
// deposit bribe for Epoch + 2
616616
_depositBribe(1e18, 1e18, governance.epoch() + 1);
617617

618-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
619-
(uint256 userLQTYAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
618+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
619+
(uint256 userLQTYAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
620620
assertEq(totalLQTYAllocated, 5e17, "total allocation");
621621
assertEq(userLQTYAllocated, 5e17, "user allocation");
622622

@@ -635,8 +635,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
635635
// decrease user allocation for the initiative
636636
_resetAllocation(user1);
637637

638-
(userLQTYAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
639-
(totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
638+
(userLQTYAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
639+
(totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
640640
assertEq(userLQTYAllocated, 0, "total allocation");
641641
assertEq(totalLQTYAllocated, 0, "user allocation");
642642
}
@@ -667,8 +667,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
667667

668668
_allocateLQTY(user1, 1e18, 0);
669669

670-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
671-
(uint256 userLQTYAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
670+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
671+
(uint256 userLQTYAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
672672
assertEq(totalLQTYAllocated, 1e18);
673673
assertEq(userLQTYAllocated, 1e18);
674674

@@ -698,8 +698,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
698698

699699
_allocateLQTY(user1, 1e18, 0);
700700

701-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
702-
(uint256 userLQTYAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
701+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
702+
(uint256 userLQTYAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
703703
assertEq(totalLQTYAllocated, 1e18);
704704
assertEq(userLQTYAllocated, 1e18);
705705

@@ -729,8 +729,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
729729

730730
_allocateLQTY(user1, 1e18, 0);
731731

732-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
733-
(uint256 userLQTYAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
732+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
733+
(uint256 userLQTYAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
734734
assertEq(totalLQTYAllocated, 1e18);
735735
assertEq(userLQTYAllocated, 1e18);
736736

@@ -761,8 +761,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
761761

762762
_allocateLQTY(user1, 1e18, 0);
763763

764-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
765-
(uint256 userLQTYAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
764+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
765+
(uint256 userLQTYAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
766766
assertEq(totalLQTYAllocated, 1e18);
767767
assertEq(userLQTYAllocated, 1e18);
768768

@@ -790,8 +790,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
790790

791791
_tryAllocateNothing(user1);
792792

793-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
794-
(uint256 userLQTYAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
793+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
794+
(uint256 userLQTYAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
795795
assertEq(totalLQTYAllocated, 0);
796796
assertEq(userLQTYAllocated, 0);
797797

@@ -824,8 +824,8 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
824824

825825
_tryAllocateNothing(user1);
826826

827-
(uint256 totalLQTYAllocated,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
828-
(uint256 userLQTYAllocated,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
827+
(uint256 totalLQTYAllocated,,,) = bribeInitiative.totalLQTYAllocatedByEpoch(governance.epoch());
828+
(uint256 userLQTYAllocated,,,) = bribeInitiative.lqtyAllocatedByUserAtEpoch(user1, governance.epoch());
829829
assertEq(totalLQTYAllocated, 0);
830830
assertEq(userLQTYAllocated, 0);
831831

0 commit comments

Comments
 (0)