Make ERC20Votes independent from ERC20Permit (#3816)
Co-authored-by: Francisco <frangio.1@gmail.com>
This commit is contained in:
@ -68,6 +68,13 @@ library Checkpoints {
|
||||
return pos == 0 ? 0 : _unsafeAccess(self._checkpoints, pos - 1)._value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Returns checkpoint at given position.
|
||||
*/
|
||||
function getAtPosition(History storage self, uint32 pos) internal view returns (Checkpoint memory) {
|
||||
return self._checkpoints[pos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Pushes a value onto a History so that it is stored as the checkpoint for the current block.
|
||||
*
|
||||
|
||||
31
contracts/utils/Nonces.sol
Normal file
31
contracts/utils/Nonces.sol
Normal file
@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.0;
|
||||
|
||||
import "./Counters.sol";
|
||||
|
||||
/**
|
||||
* @dev Provides tracking nonces for addresses. Nonces will only increment.
|
||||
*/
|
||||
abstract contract Nonces {
|
||||
using Counters for Counters.Counter;
|
||||
|
||||
mapping(address => Counters.Counter) private _nonces;
|
||||
|
||||
/**
|
||||
* @dev Returns an address nonce.
|
||||
*/
|
||||
function nonces(address owner) public view virtual returns (uint256) {
|
||||
return _nonces[owner].current();
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Consumes a nonce.
|
||||
*
|
||||
* Returns the current value and increments nonce.
|
||||
*/
|
||||
function _useNonce(address owner) internal virtual returns (uint256 current) {
|
||||
Counters.Counter storage nonce = _nonces[owner];
|
||||
current = nonce.current();
|
||||
nonce.increment();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user