-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cda1529
commit 13d64bb
Showing
6 changed files
with
902 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import "./xpNFT.sol"; | ||
|
||
contract ZetaXP_V2 is ZetaXP { | ||
bytes32 private constant SETLEVEL_TYPEHASH = | ||
keccak256("SetLevel(uint256 tokenId,uint256 signatureExpiration,uint256 sigTimestamp,uint256 level)"); | ||
|
||
struct SetLevelData { | ||
uint256 tokenId; | ||
bytes signature; | ||
uint256 signatureExpiration; | ||
uint256 sigTimestamp; | ||
uint256 level; | ||
} | ||
|
||
mapping(uint256 => uint256) public levelByTokenId; | ||
event LevelSet(address indexed sender, uint256 indexed tokenId, uint256 level); | ||
|
||
function version() public pure override returns (string memory) { | ||
return "2.0.0"; | ||
} | ||
|
||
function _verifySetLevelSignature(SetLevelData memory data) private view { | ||
bytes32 structHash = keccak256( | ||
abi.encode(SETLEVEL_TYPEHASH, data.tokenId, data.signatureExpiration, data.sigTimestamp, data.level) | ||
); | ||
bytes32 constructedHash = _hashTypedDataV4(structHash); | ||
|
||
if (!SignatureChecker.isValidSignatureNow(signerAddress, constructedHash, data.signature)) { | ||
revert InvalidSigner(); | ||
} | ||
|
||
if (block.timestamp > data.signatureExpiration) revert SignatureExpired(); | ||
if (data.sigTimestamp <= lastUpdateTimestampByTokenId[data.tokenId]) revert OutdatedSignature(); | ||
} | ||
|
||
function setLevel(SetLevelData memory data) external { | ||
_verifySetLevelSignature(data); | ||
|
||
levelByTokenId[data.tokenId] = data.level; | ||
lastUpdateTimestampByTokenId[data.tokenId] = data.sigTimestamp; | ||
emit LevelSet(msg.sender, data.tokenId, data.level); | ||
} | ||
|
||
function getLevel(uint256 tokenId) external view returns (uint256) { | ||
return levelByTokenId[tokenId]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.