This repository has been archived by the owner on Apr 30, 2024. It is now read-only.
generated from storyprotocol/solidity-template
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introducing Meta-Transaction Support to IPAccount with EIP712 Standar…
…d Signatures (#32)
- Loading branch information
1 parent
d2b9c4b
commit 6de2d8b
Showing
6 changed files
with
759 additions
and
13 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
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,65 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
// See https://github.com/storyprotocol/protocol-contracts/blob/main/StoryProtocol-AlphaTestingAgreement-17942166.3.pdf | ||
pragma solidity ^0.8.23; | ||
|
||
/// @title MetaTx | ||
/// @dev This library provides functions for handling meta transactions in the Story Protocol. | ||
library MetaTx { | ||
/// @dev Version of the EIP712 domain. | ||
string constant EIP712_DOMAIN_VERSION = "1"; | ||
/// @dev Hash of the EIP712 domain version. | ||
bytes32 constant EIP712_DOMAIN_VERSION_HASH = keccak256(bytes(EIP712_DOMAIN_VERSION)); | ||
/// @dev EIP712 domain type hash. | ||
bytes32 constant EIP712_DOMAIN = | ||
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"); | ||
/// @dev Execute type hash. | ||
bytes32 constant EXECUTE = keccak256("Execute(address to,uint256 value,bytes data,uint256 nonce,uint256 deadline)"); | ||
|
||
/// @dev Structure for the Execute type. | ||
struct Execute { | ||
address to; | ||
uint256 value; | ||
bytes data; | ||
uint256 nonce; | ||
uint256 deadline; | ||
} | ||
|
||
/// @dev Calculates the EIP712 domain separator for the current contract. | ||
/// @return The EIP712 domain separator. | ||
function calculateDomainSeparator() internal view returns (bytes32) { | ||
return calculateDomainSeparator(address(this)); | ||
} | ||
|
||
/// @dev Calculates the EIP712 domain separator for a given IP account. | ||
/// @param ipAccount The IP account for which to calculate the domain separator. | ||
/// @return The EIP712 domain separator. | ||
function calculateDomainSeparator(address ipAccount) internal view returns (bytes32) { | ||
return | ||
keccak256( | ||
abi.encode( | ||
EIP712_DOMAIN, | ||
keccak256("Story Protocol IP Account"), | ||
EIP712_DOMAIN_VERSION_HASH, | ||
block.chainid, | ||
ipAccount | ||
) | ||
); | ||
} | ||
|
||
/// @dev Calculates the EIP712 struct hash of an Execute. | ||
/// @param execute The Execute to hash. | ||
/// @return The EIP712 struct hash of the Execute. | ||
function getExecuteStructHash(Execute memory execute) internal pure returns (bytes32) { | ||
return | ||
keccak256( | ||
abi.encode( | ||
MetaTx.EXECUTE, | ||
execute.to, | ||
execute.value, | ||
keccak256(execute.data), | ||
execute.nonce, | ||
execute.deadline | ||
) | ||
); | ||
} | ||
} |
Oops, something went wrong.