generated from defi-wonderland/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 6
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
excaliborr
committed
Jul 25, 2024
1 parent
56f49a3
commit 3bb8d4b
Showing
7 changed files
with
130 additions
and
17 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
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,61 @@ | ||
pragma solidity 0.8.25; | ||
|
||
import {ShortString, ShortStrings} from '@openzeppelin/contracts/utils/ShortStrings.sol'; | ||
import {IOpUSDCBridgeAdapter} from 'interfaces/IOpUSDCBridgeAdapter.sol'; | ||
|
||
contract SigUtils { | ||
using ShortStrings for *; | ||
|
||
bytes32 private constant _TYPE_HASH = | ||
keccak256('EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)'); | ||
bytes32 public constant BRIDGE_MESSAGE_TYPEHASH = | ||
keccak256('BridgeMessage(address to,uint256 amount,uint256 deadline,uint256 nonce,uint32 minGasLimit)'); | ||
|
||
bytes32 internal immutable _DOMAIN_SEPARATOR; | ||
|
||
bytes32 private immutable _HASHED_NAME; | ||
bytes32 private immutable _HASHED_VERSION; | ||
|
||
ShortString private immutable _NAME; | ||
ShortString private immutable _VERSION; | ||
string private _nameFallback; | ||
string private _versionFallback; | ||
|
||
constructor(address _adapter) { | ||
string memory _name = 'OpUSDCBridgeAdapter'; | ||
string memory _version = '1.0.0'; | ||
_NAME = _name.toShortStringWithFallback(_nameFallback); | ||
_VERSION = _version.toShortStringWithFallback(_versionFallback); | ||
|
||
_HASHED_NAME = keccak256(bytes(_name)); | ||
_HASHED_VERSION = keccak256(bytes(_version)); | ||
|
||
_DOMAIN_SEPARATOR = keccak256(abi.encode(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION, block.chainid, _adapter)); | ||
} | ||
|
||
/** | ||
* @notice Hashes the bridge message struct | ||
* @param _message The bridge message struct to hash | ||
* @return _hash The hash of the bridge message struct | ||
*/ | ||
function getBridgeMessageHash(IOpUSDCBridgeAdapter.BridgeMessage memory _message) public view returns (bytes32 _hash) { | ||
Check warning on line 41 in test/utils/SigUtils.sol GitHub Actions / Lint Commit Messages
Check warning on line 41 in test/utils/SigUtils.sol GitHub Actions / Lint Commit Messages
|
||
_hash = keccak256( | ||
abi.encode( | ||
BRIDGE_MESSAGE_TYPEHASH, _message.to, _message.amount, _message.deadline, _message.nonce, _message.minGasLimit | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* @notice Hashes the bridge message struct and returns the EIP712 hash | ||
* @param _message The bridge message struct to hash | ||
* @return _hash The hash of the bridge message struct | ||
*/ | ||
function getTypedBridgeMessageHash(IOpUSDCBridgeAdapter.BridgeMessage memory _message) | ||
public | ||
view | ||
returns (bytes32 _hash) | ||
{ | ||
_hash = keccak256(abi.encodePacked('\x19\x01', _DOMAIN_SEPARATOR, getBridgeMessageHash(_message))); | ||
} | ||
} |