2021-06-21 07:04:07 -07:00
|
|
|
// contracts/State.sol
|
|
|
|
// SPDX-License-Identifier: Apache 2
|
|
|
|
|
|
|
|
pragma solidity ^0.8.0;
|
|
|
|
|
2022-08-25 13:47:02 -07:00
|
|
|
import "@openzeppelin/contracts/utils/Counters.sol";
|
|
|
|
|
2021-06-21 07:04:07 -07:00
|
|
|
contract TokenStorage {
|
|
|
|
struct State {
|
|
|
|
string name;
|
|
|
|
string symbol;
|
|
|
|
|
2021-09-01 04:13:51 -07:00
|
|
|
uint64 metaLastUpdatedSequence;
|
|
|
|
|
2021-06-21 07:04:07 -07:00
|
|
|
uint256 totalSupply;
|
|
|
|
uint8 decimals;
|
|
|
|
|
2021-09-01 04:13:51 -07:00
|
|
|
mapping(address => uint256) balances;
|
2021-06-21 07:04:07 -07:00
|
|
|
|
2021-09-01 04:13:51 -07:00
|
|
|
mapping(address => mapping(address => uint256)) allowances;
|
2021-06-21 07:04:07 -07:00
|
|
|
|
|
|
|
address owner;
|
|
|
|
|
|
|
|
bool initialized;
|
|
|
|
|
|
|
|
uint16 chainId;
|
|
|
|
bytes32 nativeContract;
|
2022-08-25 13:47:02 -07:00
|
|
|
|
|
|
|
// EIP712
|
2022-09-01 14:02:40 -07:00
|
|
|
// Cache the domain separator and salt, but also store the chain id that
|
|
|
|
// it corresponds to, in order to invalidate the cached domain separator
|
|
|
|
// if the chain id changes.
|
2022-08-25 13:47:02 -07:00
|
|
|
bytes32 cachedDomainSeparator;
|
|
|
|
uint256 cachedChainId;
|
|
|
|
address cachedThis;
|
2022-09-01 14:02:40 -07:00
|
|
|
bytes32 cachedSalt;
|
|
|
|
bytes32 cachedHashedName;
|
2022-08-25 13:47:02 -07:00
|
|
|
|
|
|
|
// ERC20Permit draft
|
|
|
|
mapping(address => Counters.Counter) nonces;
|
2021-06-21 07:04:07 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contract TokenState {
|
2022-08-25 13:47:02 -07:00
|
|
|
using Counters for Counters.Counter;
|
|
|
|
|
2021-06-21 07:04:07 -07:00
|
|
|
TokenStorage.State _state;
|
2022-08-25 13:47:02 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev See {IERC20Permit-nonces}.
|
|
|
|
*/
|
|
|
|
function nonces(address owner_) public view returns (uint256) {
|
|
|
|
return _state.nonces[owner_].current();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dev "Consume a nonce": return the current value and increment.
|
|
|
|
*/
|
|
|
|
function _useNonce(address owner_) internal returns (uint256 current) {
|
|
|
|
Counters.Counter storage nonce = _state.nonces[owner_];
|
|
|
|
current = nonce.current();
|
|
|
|
nonce.increment();
|
|
|
|
}
|
2021-06-21 07:04:07 -07:00
|
|
|
}
|