Skip to content

Commit

Permalink
change deposit amount to uint96
Browse files Browse the repository at this point in the history
  • Loading branch information
wildmolasses committed Apr 5, 2024
1 parent 2ac42a5 commit 31d4923
Show file tree
Hide file tree
Showing 5 changed files with 472 additions and 261 deletions.
32 changes: 16 additions & 16 deletions src/UniStaker.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,19 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @param delegatee The governance delegate who receives the voting weight for this deposit.
/// @param beneficiary The address that accrues staking rewards earned by this deposit.
struct Deposit {
uint256 balance;
uint96 balance;
address owner;
address delegatee;
address beneficiary;
}

/// @notice Type hash used when encoding data for `stakeOnBehalf` calls.
bytes32 public constant STAKE_TYPEHASH = keccak256(
"Stake(uint256 amount,address delegatee,address beneficiary,address depositor,uint256 nonce,uint256 deadline)"
"Stake(uint96 amount,address delegatee,address beneficiary,address depositor,uint256 nonce,uint256 deadline)"
);
/// @notice Type hash used when encoding data for `stakeMoreOnBehalf` calls.
bytes32 public constant STAKE_MORE_TYPEHASH = keccak256(
"StakeMore(uint256 depositId,uint256 amount,address depositor,uint256 nonce,uint256 deadline)"
"StakeMore(uint256 depositId,uint96 amount,address depositor,uint256 nonce,uint256 deadline)"
);
/// @notice Type hash used when encoding data for `alterDelegateeOnBehalf` calls.
bytes32 public constant ALTER_DELEGATEE_TYPEHASH = keccak256(
Expand All @@ -119,7 +119,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
);
/// @notice Type hash used when encoding data for `withdrawOnBehalf` calls.
bytes32 public constant WITHDRAW_TYPEHASH = keccak256(
"Withdraw(uint256 depositId,uint256 amount,address depositor,uint256 nonce,uint256 deadline)"
"Withdraw(uint256 depositId,uint96 amount,address depositor,uint256 nonce,uint256 deadline)"
);
/// @notice Type hash used when encoding data for `claimRewardOnBehalf` calls.
bytes32 public constant CLAIM_REWARD_TYPEHASH =
Expand Down Expand Up @@ -259,7 +259,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @return _depositId The unique identifier for this deposit.
/// @dev The delegatee may not be the zero address. The deposit will be owned by the message
/// sender, and the beneficiary will also be the message sender.
function stake(uint256 _amount, address _delegatee)
function stake(uint96 _amount, address _delegatee)
external
returns (DepositIdentifier _depositId)
{
Expand All @@ -274,7 +274,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @return _depositId Unique identifier for this deposit.
/// @dev Neither the delegatee nor the beneficiary may be the zero address. The deposit will be
/// owned by the message sender.
function stake(uint256 _amount, address _delegatee, address _beneficiary)
function stake(uint96 _amount, address _delegatee, address _beneficiary)
external
returns (DepositIdentifier _depositId)
{
Expand All @@ -296,7 +296,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @dev Neither the delegatee nor the beneficiary may be the zero address. The deposit will be
/// owned by the message sender.
function permitAndStake(
uint256 _amount,
uint96 _amount,
address _delegatee,
address _beneficiary,
uint256 _deadline,
Expand All @@ -320,7 +320,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @return _depositId Unique identifier for this deposit.
/// @dev Neither the delegatee nor the beneficiary may be the zero address.
function stakeOnBehalf(
uint256 _amount,
uint96 _amount,
address _delegatee,
address _beneficiary,
address _depositor,
Expand Down Expand Up @@ -354,7 +354,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @param _depositId Unique identifier of the deposit to which stake will be added.
/// @param _amount Quantity of stake to be added.
/// @dev The message sender must be the owner of the deposit.
function stakeMore(DepositIdentifier _depositId, uint256 _amount) external {
function stakeMore(DepositIdentifier _depositId, uint96 _amount) external {
Deposit storage deposit = deposits[_depositId];
_revertIfNotDepositOwner(deposit, msg.sender);
_stakeMore(deposit, _depositId, _amount);
Expand All @@ -374,7 +374,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @dev The message sender must be the owner of the deposit.
function permitAndStakeMore(
DepositIdentifier _depositId,
uint256 _amount,
uint96 _amount,
uint256 _deadline,
uint8 _v,
bytes32 _r,
Expand All @@ -397,7 +397,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @param _signature Signature of the user authorizing this stake.
function stakeMoreOnBehalf(
DepositIdentifier _depositId,
uint256 _amount,
uint96 _amount,
address _depositor,
uint256 _deadline,
bytes memory _signature
Expand Down Expand Up @@ -525,7 +525,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @param _amount Quantity of staked token to withdraw.
/// @dev The message sender must be the owner of the deposit. Stake is withdrawn to the message
/// sender's account.
function withdraw(DepositIdentifier _depositId, uint256 _amount) external {
function withdraw(DepositIdentifier _depositId, uint96 _amount) external {
Deposit storage deposit = deposits[_depositId];
_revertIfNotDepositOwner(deposit, msg.sender);
_withdraw(deposit, _depositId, _amount);
Expand All @@ -541,7 +541,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @dev Stake is withdrawn to the deposit owner's account.
function withdrawOnBehalf(
DepositIdentifier _depositId,
uint256 _amount,
uint96 _amount,
address _depositor,
uint256 _deadline,
bytes memory _signature
Expand Down Expand Up @@ -694,7 +694,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @notice Internal convenience methods which performs the staking operations.
/// @dev This method must only be called after proper authorization has been completed.
/// @dev See public stake methods for additional documentation.
function _stake(address _depositor, uint256 _amount, address _delegatee, address _beneficiary)
function _stake(address _depositor, uint96 _amount, address _delegatee, address _beneficiary)
internal
returns (DepositIdentifier _depositId)
{
Expand Down Expand Up @@ -725,7 +725,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @notice Internal convenience method which adds more stake to an existing deposit.
/// @dev This method must only be called after proper authorization has been completed.
/// @dev See public stakeMore methods for additional documentation.
function _stakeMore(Deposit storage deposit, DepositIdentifier _depositId, uint256 _amount)
function _stakeMore(Deposit storage deposit, DepositIdentifier _depositId, uint96 _amount)
internal
{
_checkpointGlobalReward();
Expand Down Expand Up @@ -779,7 +779,7 @@ contract UniStaker is INotifiableRewardReceiver, Multicall, EIP712, Nonces {
/// @notice Internal convenience method which withdraws the stake from an existing deposit.
/// @dev This method must only be called after proper authorization has been completed.
/// @dev See public withdraw methods for additional documentation.
function _withdraw(Deposit storage deposit, DepositIdentifier _depositId, uint256 _amount)
function _withdraw(Deposit storage deposit, DepositIdentifier _depositId, uint96 _amount)
internal
{
_checkpointGlobalReward();
Expand Down
10 changes: 5 additions & 5 deletions test/UniStaker.integration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ contract Propose is IntegrationTest {
contract Stake is IntegrationTest, PercentAssertions {
function testForkFuzz_CorrectlyStakeAndEarnRewardsAfterFullDuration(
address _depositor,
uint256 _amount,
uint96 _amount,
address _delegatee,
uint128 _swapAmount
) public {
Expand All @@ -259,7 +259,7 @@ contract Stake is IntegrationTest, PercentAssertions {

function testForkFuzz_CorrectlyStakeAndClaimRewardsAfterFullDuration(
address _depositor,
uint256 _amount,
uint96 _amount,
address _delegatee,
uint128 _swapAmount
) public {
Expand Down Expand Up @@ -287,7 +287,7 @@ contract Stake is IntegrationTest, PercentAssertions {

function testForkFuzz_CorrectlyStakeAndEarnRewardsAfterPartialDuration(
address _depositor,
uint256 _amount,
uint96 _amount,
address _delegatee,
uint128 _swapAmount,
uint256 _percentDuration
Expand All @@ -310,8 +310,8 @@ contract Stake is IntegrationTest, PercentAssertions {

function testForkFuzz_CorrectlyStakeMoreAndEarnRewardsAfterFullDuration(
address _depositor,
uint256 _initialAmount,
uint256 _additionalAmount,
uint96 _initialAmount,
uint96 _additionalAmount,
address _delegatee,
uint128 _swapAmount,
uint256 _percentDuration
Expand Down
Loading

0 comments on commit 31d4923

Please sign in to comment.