-
Notifications
You must be signed in to change notification settings - Fork 32
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
d61063e
commit 29ba989
Showing
1 changed file
with
13 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
packages/contracts-communication/contracts/libs/Options.sol
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 |
---|---|---|
@@ -1,20 +1,33 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/// @title OptionsLib | ||
/// @notice A library for encoding and decoding Interchain options related to interchain messages. | ||
library OptionsLib { | ||
/// @dev Struct to hold V1 of options data. | ||
/// @param version The version of the options. | ||
/// @param gasLimit The gas limit for the transaction. | ||
/// @param gasAirdrop The amount of gas to airdrop. | ||
struct Options { | ||
uint8 version; | ||
uint256 gasLimit; | ||
// uint256 msgValue; | ||
uint256 gasAirdrop; | ||
} | ||
|
||
/// @notice Encodes options into a bytes format. | ||
/// @param options The Options to encode. | ||
/// @return The encoded options as bytes. | ||
function encodeOptions(Options memory options) internal pure returns (bytes memory) { | ||
return abi.encode(options.version, options.gasLimit, options.gasAirdrop); | ||
} | ||
|
||
/// @notice Decodes options from a bytes format back into an Options struct. | ||
/// @param data The options data in bytes format. | ||
/// @return The decoded options as an Options struct. | ||
function decodeOptions(bytes memory data) internal pure returns (Options memory) { | ||
(uint8 version, uint256 gasLimit, uint256 gasAirdrop) = abi.decode(data, (uint8, uint256, uint256)); | ||
return Options(version, gasLimit, gasAirdrop); | ||
} | ||
} | ||
|