Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into testing
Browse files Browse the repository at this point in the history
  • Loading branch information
danielattilasimon committed Nov 22, 2024
2 parents 19c5621 + 1926488 commit 25fb79c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 42 deletions.
7 changes: 4 additions & 3 deletions src/BribeInitiative.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,19 @@ contract BribeInitiative is IInitiative, IBribeInitiative {
lqtyAllocationByUserAtEpoch[_user].getItem(_prevLQTYAllocationEpoch);

require(
lqtyAllocation.value != 0 && _prevLQTYAllocationEpoch <= _epoch
&& (lqtyAllocation.next > _epoch || lqtyAllocation.next == 0),
_prevLQTYAllocationEpoch <= _epoch && (lqtyAllocation.next > _epoch || lqtyAllocation.next == 0),
"BribeInitiative: invalid-prev-lqty-allocation-epoch"
);
DoubleLinkedList.Item memory totalLQTYAllocation =
totalLQTYAllocationByEpoch.getItem(_prevTotalLQTYAllocationEpoch);
require(
totalLQTYAllocation.value != 0 && _prevTotalLQTYAllocationEpoch <= _epoch
_prevTotalLQTYAllocationEpoch <= _epoch
&& (totalLQTYAllocation.next > _epoch || totalLQTYAllocation.next == 0),
"BribeInitiative: invalid-prev-total-lqty-allocation-epoch"
);

(uint88 totalLQTY, uint120 totalAverageTimestamp) = _decodeLQTYAllocation(totalLQTYAllocation.value);
require(totalLQTY > 0, "BribeInitiative: total-lqty-allocation-zero");

// NOTE: SCALING!!! | The timestamp will work until type(uint32).max | After which the math will eventually overflow
uint120 scaledEpochEnd = (
Expand All @@ -113,6 +113,7 @@ contract BribeInitiative is IInitiative, IBribeInitiative {
uint240 totalVotes = governance.lqtyToVotes(totalLQTY, scaledEpochEnd, totalAverageTimestamp);
if (totalVotes != 0) {
(uint88 lqty, uint120 averageTimestamp) = _decodeLQTYAllocation(lqtyAllocation.value);
require(lqty > 0, "BribeInitiative: lqty-allocation-zero");

/// @audit Governance Invariant
assert(averageTimestamp <= scaledEpochEnd);
Expand Down
29 changes: 0 additions & 29 deletions src/ForwardBribe.sol

This file was deleted.

23 changes: 16 additions & 7 deletions src/UserProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@ pragma solidity ^0.8.24;

import {IERC20} from "openzeppelin/contracts/interfaces/IERC20.sol";
import {IERC20Permit} from "openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import {SafeERC20} from "openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

import {IUserProxy} from "./interfaces/IUserProxy.sol";
import {ILQTYStaking} from "./interfaces/ILQTYStaking.sol";
import {PermitParams} from "./utils/Types.sol";

contract UserProxy is IUserProxy {
using SafeERC20 for IERC20;

/// @inheritdoc IUserProxy
IERC20 public immutable lqty;
/// @inheritdoc IUserProxy
Expand All @@ -36,7 +33,7 @@ contract UserProxy is IUserProxy {

/// @inheritdoc IUserProxy
function stake(uint256 _amount, address _lqtyFrom) public onlyStakingV2 {
lqty.safeTransferFrom(_lqtyFrom, address(this), _amount);
lqty.transferFrom(_lqtyFrom, address(this), _amount);
stakingV1.stake(_amount);
emit Stake(_amount, _lqtyFrom);
}
Expand Down Expand Up @@ -65,19 +62,31 @@ contract UserProxy is IUserProxy {
onlyStakingV2
returns (uint256 lusdAmount, uint256 ethAmount)
{
uint256 initialLQTYAmount = lqty.balanceOf(address(this));
uint256 initialLUSDAmount = lusd.balanceOf(address(this));
uint256 initialETHAmount = address(this).balance;

stakingV1.unstake(_amount);

uint256 lqtyAmount = lqty.balanceOf(address(this));
if (lqtyAmount > 0) lqty.safeTransfer(_recipient, lqtyAmount);
if (lqtyAmount > 0) lqty.transfer(_recipient, lqtyAmount);
lusdAmount = lusd.balanceOf(address(this));
if (lusdAmount > 0) lusd.safeTransfer(_recipient, lusdAmount);
if (lusdAmount > 0) lusd.transfer(_recipient, lusdAmount);
ethAmount = address(this).balance;
if (ethAmount > 0) {
(bool success,) = payable(_recipient).call{value: ethAmount}("");
require(success, "UserProxy: eth-fail");
}

emit Unstake(_amount, _recipient, lusdAmount, ethAmount);
emit Unstake(
_recipient,
lqtyAmount - initialLQTYAmount,
lqtyAmount,
lusdAmount - initialLUSDAmount,
lusdAmount,
ethAmount - initialETHAmount,
ethAmount
);
}

/// @inheritdoc IUserProxy
Expand Down
10 changes: 9 additions & 1 deletion src/interfaces/IUserProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ import {PermitParams} from "../utils/Types.sol";

interface IUserProxy {
event Stake(uint256 amount, address lqtyFrom);
event Unstake(uint256 lqtyUnstaked, address indexed lqtyRecipient, uint256 lusdAmount, uint256 ethAmount);
event Unstake(
address indexed lqtyRecipient,
uint256 lqtyReceived,
uint256 lqtySent,
uint256 lusdAmountReceived,
uint256 lusdAmountSent,
uint256 ethAmountReceived,
uint256 ethAmountSent
);

/// @notice Address of the LQTY token
/// @return lqty Address of the LQTY token
Expand Down
4 changes: 2 additions & 2 deletions test/BribeInitiative.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
// user2 should receive no bribes if they try to claim
claimEpoch = governance.epoch() - 1; // claim for epoch 3
prevAllocationEpoch = governance.epoch() - 1; // epoch 3
(boldAmount, bribeTokenAmount) = _claimBribe(user2, claimEpoch, prevAllocationEpoch, prevAllocationEpoch);
(boldAmount, bribeTokenAmount) = _claimBribe(user2, claimEpoch, prevAllocationEpoch, prevAllocationEpoch, true);
assertEq(boldAmount, 0, "vetoer receives bold bribe amount");
assertEq(bribeTokenAmount, 0, "vetoer receives bribe amount");
}
Expand Down Expand Up @@ -845,7 +845,7 @@ contract BribeInitiativeTest is Test, MockStakingV1Deployer {
epochs[0].epoch = governance.epoch() - 1;
epochs[0].prevLQTYAllocationEpoch = governance.epoch() - 2;
epochs[0].prevTotalLQTYAllocationEpoch = governance.epoch() - 2;
vm.expectRevert("BribeInitiative: invalid-prev-total-lqty-allocation-epoch");
vm.expectRevert("BribeInitiative: total-lqty-allocation-zero");
(uint256 boldAmount, uint256 bribeTokenAmount) = bribeInitiative.claimBribes(epochs);
vm.stopPrank();

Expand Down
2 changes: 2 additions & 0 deletions test/BribeInitiativeAllocate.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ contract BribeInitiativeAllocateTest is Test {
claimData[0].epoch = 2;
claimData[0].prevLQTYAllocationEpoch = 2;
claimData[0].prevTotalLQTYAllocationEpoch = 2;
vm.expectRevert("BribeInitiative: total-lqty-allocation-zero");
(uint256 boldAmount, uint256 bribeTokenAmount) = bribeInitiative.claimBribes(claimData);
assertEq(boldAmount, 0, "boldAmount nonzero");
assertEq(bribeTokenAmount, 0, "bribeTokenAmount nonzero");
Expand Down Expand Up @@ -702,6 +703,7 @@ contract BribeInitiativeAllocateTest is Test {
claimData[0].epoch = 1;
claimData[0].prevLQTYAllocationEpoch = 1;
claimData[0].prevTotalLQTYAllocationEpoch = 1;
vm.expectRevert("BribeInitiative: lqty-allocation-zero");
(uint256 boldAmount, uint256 bribeTokenAmount) = bribeInitiative.claimBribes(claimData);
assertEq(boldAmount, 0);
assertEq(bribeTokenAmount, 0);
Expand Down

0 comments on commit 25fb79c

Please sign in to comment.