This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
19 changed files
with
1,056 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"solidity.packageDefaultDependenciesContractsDirectory": "src", | ||
"solidity.packageDefaultDependenciesDirectory": "lib", | ||
"solidity.compileUsingRemoteVersion": "v0.8.23", | ||
"[solidity]": { | ||
"editor.defaultFormatter": "JuanBlanco.solidity" | ||
}, | ||
"solidity.formatter": "forge" | ||
} |
Submodule LayerZero-v2
updated
85 files
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
82 changes: 82 additions & 0 deletions
82
lib/oapp-upgradeable/oapp/libs/OAppOptionsType3Upgradeable.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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol"; | ||
import { IOAppOptionsType3, EnforcedOptionParam } from "@layerzerolabs/lz-evm-oapp-v2/contracts/oapp/interfaces/IOAppOptionsType3.sol"; | ||
|
||
/** | ||
* @title OAppOptionsType3Upgradeable | ||
* @dev Abstract contract implementing the OAppOptionsType3 interface with type 3 options. | ||
*/ | ||
abstract contract OAppOptionsType3Upgradeable is IOAppOptionsType3, OwnableUpgradeable { | ||
uint16 internal constant OPTION_TYPE_3 = 3; | ||
|
||
// @dev The "msgType" should be defined in the child contract. | ||
mapping(uint32 eid => mapping(uint16 msgType => bytes enforcedOption)) public enforcedOptions; | ||
|
||
/** | ||
* @dev Sets the enforced options for specific endpoint and message type combinations. | ||
* @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options. | ||
* | ||
* @dev Only the owner/admin of the OApp can call this function. | ||
* @dev Provides a way for the OApp to enforce things like paying for PreCrime, AND/OR minimum dst lzReceive gas amounts etc. | ||
* @dev These enforced options can vary as the potential options/execution on the remote may differ as per the msgType. | ||
* eg. Amount of lzReceive() gas necessary to deliver a lzCompose() message adds overhead you dont want to pay | ||
* if you are only making a standard LayerZero message ie. lzReceive() WITHOUT sendCompose(). | ||
*/ | ||
function setEnforcedOptions(EnforcedOptionParam[] calldata _enforcedOptions) public virtual onlyOwner { | ||
for (uint256 i = 0; i < _enforcedOptions.length; i++) { | ||
// @dev Enforced options are only available for optionType 3, as type 1 and 2 dont support combining. | ||
_assertOptionsType3(_enforcedOptions[i].options); | ||
enforcedOptions[_enforcedOptions[i].eid][_enforcedOptions[i].msgType] = _enforcedOptions[i].options; | ||
} | ||
|
||
emit EnforcedOptionSet(_enforcedOptions); | ||
} | ||
|
||
/** | ||
* @notice Combines options for a given endpoint and message type. | ||
* @param _eid The endpoint ID. | ||
* @param _msgType The OAPP message type. | ||
* @param _extraOptions Additional options passed by the caller. | ||
* @return options The combination of caller specified options AND enforced options. | ||
* | ||
* @dev If there is an enforced lzReceive option: | ||
* - {gasLimit: 200k, msg.value: 1 ether} AND a caller supplies a lzReceive option: {gasLimit: 100k, msg.value: 0.5 ether} | ||
* - The resulting options will be {gasLimit: 300k, msg.value: 1.5 ether} when the message is executed on the remote lzReceive() function. | ||
* @dev This presence of duplicated options is handled off-chain in the verifier/executor. | ||
*/ | ||
function combineOptions( | ||
uint32 _eid, | ||
uint16 _msgType, | ||
bytes calldata _extraOptions | ||
) public view virtual returns (bytes memory) { | ||
bytes memory enforced = enforcedOptions[_eid][_msgType]; | ||
|
||
// No enforced options, pass whatever the caller supplied, even if it's empty or legacy type 1/2 options. | ||
if (enforced.length == 0) return _extraOptions; | ||
|
||
// No caller options, return enforced | ||
if (_extraOptions.length == 0) return enforced; | ||
|
||
// @dev If caller provided _extraOptions, must be type 3 as its the ONLY type that can be combined. | ||
if (_extraOptions.length >= 2) { | ||
_assertOptionsType3(_extraOptions); | ||
// @dev Remove the first 2 bytes containing the type from the _extraOptions and combine with enforced. | ||
return bytes.concat(enforced, _extraOptions[2:]); | ||
} | ||
|
||
// No valid set of options was found. | ||
revert InvalidOptions(_extraOptions); | ||
} | ||
|
||
/** | ||
* @dev Internal function to assert that options are of type 3. | ||
* @param _options The options to be checked. | ||
*/ | ||
function _assertOptionsType3(bytes calldata _options) internal pure virtual { | ||
uint16 optionsType = uint16(bytes2(_options[0:2])); | ||
if (optionsType != OPTION_TYPE_3) revert InvalidOptions(_options); | ||
} | ||
} |
Oops, something went wrong.