-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: override functions to extract params from LSP7 calldata
- Loading branch information
Showing
3 changed files
with
55 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: MIT OR Apache-2.0 | ||
pragma solidity >=0.8.0; | ||
|
||
/// @dev Adjusted version of the TokenMessage library from Hyperlane | ||
/// to extract parameters from the calldata of an LSP7 transfer | ||
/// according to the `transfer(address,address,uint256,bool,bytes)` signature. | ||
library TokenMessageForLSP7 { | ||
function format(bytes32 _recipient, uint256 _amount, bytes memory _metadata) internal view returns (bytes memory) { | ||
return abi.encodePacked( | ||
msg.sender, // TODO: which sender should be specified here? Should we add an extra parameter? | ||
_recipient, | ||
_amount, | ||
true, // force param set to `true` by default | ||
_metadata | ||
); | ||
} | ||
|
||
function recipient(bytes calldata message) internal pure returns (bytes32) { | ||
return bytes32(message[32:64]); | ||
} | ||
|
||
function amount(bytes calldata message) internal pure returns (uint256) { | ||
return uint256(bytes32(message[64:96])); | ||
} | ||
} |