Skip to content

Commit

Permalink
N05 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
wildmolasses authored Jul 1, 2024
1 parent 526d4ca commit 1bd4d23
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions src/VotesPartialDelegationUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,17 @@ abstract contract VotesPartialDelegationUpgradeable is
{
using Checkpoints for Checkpoints.Trace208;

/// @notice Invalid signature is provided.
error InvalidSignature();

/// @notice Address zero is provided as admin.
error InvalidAddressZero();

/// @notice The number of delegatees exceeds the limit.
error PartialDelegationLimitExceeded(uint256 length, uint256 max);

/// @notice The provided delegatee list is not sorted or contains duplicates.
error DuplicateOrUnsortedDelegatees(address delegatee);

/// @notice The provided numerator is zero.
error InvalidNumeratorZero();
/// @custom:storage-location erc7201:storage.VotesPartialDelegation
struct VotesPartialDelegationStorage {
mapping(address account => PartialDelegation[]) _delegatees;
mapping(address delegatee => Checkpoints.Trace208) _delegateCheckpoints;
Checkpoints.Trace208 _totalCheckpoints;
}

/// @notice The sum of the numerators exceeds the denominator.
error NumeratorSumExceedsDenominator(uint256 numerator, uint96 denominator);
enum Op {
ADD,
SUBTRACT
}

/// @notice Typehash for legacy delegation.
/// @custom:legacy
Expand All @@ -72,29 +66,10 @@ abstract contract VotesPartialDelegationUpgradeable is
uint256 public constant MAX_PARTIAL_DELEGATIONS = 100;
/// @notice Denominator of a partial delegation fraction.
uint96 public constant DENOMINATOR = 10_000;

enum Op {
ADD,
SUBTRACT
}

/// @custom:storage-location erc7201:storage.VotesPartialDelegation
struct VotesPartialDelegationStorage {
mapping(address account => PartialDelegation[]) _delegatees;
mapping(address delegatee => Checkpoints.Trace208) _delegateCheckpoints;
Checkpoints.Trace208 _totalCheckpoints;
}

// keccak256(abi.encode(uint256(keccak256("storage.VotesPartialDelegation")) - 1)) &~bytes32(uint256(0xff))
bytes32 private constant VotesPartialDelegationStorageLocation =
0x60b289dca0c170df62b40d5e0313a4c0e665948cd979375ddb3db607c1b89f00;

function _getVotesPartialDelegationStorage() private pure returns (VotesPartialDelegationStorage storage $) {
assembly {
$.slot := VotesPartialDelegationStorageLocation
}
}

/**
* @dev The clock was incorrectly modified.
*/
Expand All @@ -105,10 +80,34 @@ abstract contract VotesPartialDelegationUpgradeable is
*/
error ERC5805FutureLookup(uint256 timepoint, uint48 clock);

/// @notice Invalid signature is provided.
error InvalidSignature();

/// @notice Address zero is provided as admin.
error InvalidAddressZero();

/// @notice The number of delegatees exceeds the limit.
error PartialDelegationLimitExceeded(uint256 length, uint256 max);

/// @notice The provided delegatee list is not sorted or contains duplicates.
error DuplicateOrUnsortedDelegatees(address delegatee);

/// @notice The provided numerator is zero.
error InvalidNumeratorZero();

/// @notice The sum of the numerators exceeds the denominator.
error NumeratorSumExceedsDenominator(uint256 numerator, uint96 denominator);

function __VotesPartialDelegation_init() internal onlyInitializing {}

function __VotesPartialDelegation_init_unchained() internal onlyInitializing {}

function _getVotesPartialDelegationStorage() private pure returns (VotesPartialDelegationStorage storage $) {
assembly {
$.slot := VotesPartialDelegationStorageLocation
}
}

/**
* @dev Clock used for flagging checkpoints. Can be overridden to implement timestamp based
* checkpoints (and voting), in which case {CLOCK_MODE} should be overridden as well to match.
Expand Down

0 comments on commit 1bd4d23

Please sign in to comment.