Comments (2)
Would be interesting to create token extensions for solmate π
Since there's not an existing ERC721 contract in this repo I thought I'd drop a reference ERC721Permit extension
here instead:
// SPDX-License-Identifier: WTFPL
pragma solidity >=0.8.0;
import "solmate/tokens/ERC721.sol";
abstract contract ERC721Permit is ERC721 {
// ----------------------------------------------------------
// Mutables
// ----------------------------------------------------------
mapping(uint256 => uint256) public nonces;
// ----------------------------------------------------------
// Immutables
// ----------------------------------------------------------
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
constructor(
string memory _name,
string memory _symbol
) ERC721(_name, _symbol) {
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
// ----------------------------------------------------------
// Actions
// ----------------------------------------------------------
function permit(
address spender,
uint256 id,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(spender != address(0), "INVALID_SPENDER");
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the tokens's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256("Permit(address spender,uint256 id,uint256 nonce,uint256 deadline)"),
spender,
id,
nonces[id]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == _ownerOf[id], "INVALID_SIGNER");
getApproved[id] = spender;
emit Approval(recoveredAddress, spender, id);
}
}
// ----------------------------------------------------------
// Viewables
// ----------------------------------------------------------
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
}
from solady.
closed as token extensions seem out of scope of solady utilities πΊ
from solady.
Related Issues (20)
- π¨ Unexplained revert of SSTORE2.write in Foundry invariant testing HOT 1
- β¨ Adding ability to pack extra-data with balance in `ERC20` HOT 3
- β¨ LibPRNG gaussianWad HOT 1
- β»οΈ Rename all `rawOp` functions to `_op`? HOT 1
- β¨ Signed variants of wad math
- Add `toHexStringChecksumed` as an alias for `toHexStringChecksummed` HOT 4
- . HOT 1
- β¨ RingBufferLib HOT 3
- β‘οΈERC721: Combine _mint() and set _setExtraData() into single SSTORE HOT 9
- β¨ ERC1967Factory should salt by default HOT 4
- `match` used in assembly is a reserved keyword. HOT 5
- β¨ LibClone ERC1967I HOT 1
- β οΈ Potential Error in _hashTypedData Assembly Code Leading to Incorrect EIP-712 Digest Calculation HOT 1
- β¨ SafeTransferLib Permit2 operations
- π·ββοΈ Slither unable to generate IR for LibSort HOT 5
- β‘ Avoiding balance cold storage reset for tokens HOT 2
- Feature: URL Encoding safe Base64 HOT 3
- β»οΈ Convert modifiers to internal functions.
- Error in verifying git while installing HOT 2
- β»οΈ More generalized DeploylessPredeployQueryer
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solady.