Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
add OFTUpgradeable
Browse files Browse the repository at this point in the history
  • Loading branch information
e00dan committed Jan 20, 2024
1 parent 57e031c commit eb3cce8
Show file tree
Hide file tree
Showing 19 changed files with 1,056 additions and 15 deletions.
9 changes: 9 additions & 0 deletions .vscode/settings.json
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"
}
2 changes: 1 addition & 1 deletion lib/LayerZero-v2
Submodule LayerZero-v2 updated 85 files
+1 −1 messagelib/contracts/Executor.sol
+1 −1 messagelib/contracts/ExecutorFeeLib.sol
+1 −1 messagelib/contracts/MessageLibBase.sol
+1 −1 messagelib/contracts/PriceFeed.sol
+1 −1 messagelib/contracts/ReceiveLibBaseE2.sol
+1 −1 messagelib/contracts/SendLibBase.sol
+1 −1 messagelib/contracts/SendLibBaseE2.sol
+1 −1 messagelib/contracts/Treasury.sol
+1 −1 messagelib/contracts/Worker.sol
+1 −1 messagelib/contracts/libs/SafeCall.sol
+5 −4 messagelib/contracts/uln/LzExecutor.sol
+1 −1 messagelib/contracts/uln/ReceiveUlnBase.sol
+1 −1 messagelib/contracts/uln/SendUlnBase.sol
+1 −1 messagelib/contracts/uln/UlnBase.sol
+1 −1 messagelib/contracts/uln/dvn/DVN.sol
+1 −1 messagelib/contracts/uln/dvn/DVNFeeLib.sol
+1 −1 messagelib/contracts/uln/dvn/MultiSig.sol
+0 −152 messagelib/contracts/uln/dvn/adapters/CCIP/CCIPDVNAdapter.sol
+0 −7 messagelib/contracts/uln/dvn/adapters/CCIP/CCIPDVNAdapterFeeLib.sol
+0 −162 messagelib/contracts/uln/dvn/adapters/DVNAdapterBase.sol
+0 −20 messagelib/contracts/uln/dvn/adapters/DVNAdapterFeeLibBase.sol
+0 −156 messagelib/contracts/uln/dvn/adapters/axelar/AxelarDVNAdapter.sol
+0 −7 messagelib/contracts/uln/dvn/adapters/axelar/AxelarDVNAdapterFeeLib.sol
+1 −1 messagelib/contracts/uln/libs/DVNOptions.sol
+1 −1 messagelib/contracts/uln/libs/UlnOptions.sol
+1 −1 messagelib/contracts/uln/uln301/AddressSizeConfig.sol
+1 −1 messagelib/contracts/uln/uln301/ReceiveLibBaseE1.sol
+1 −1 messagelib/contracts/uln/uln301/ReceiveUln301.sol
+1 −1 messagelib/contracts/uln/uln301/SendLibBaseE1.sol
+1 −1 messagelib/contracts/uln/uln301/SendUln301.sol
+1 −1 messagelib/contracts/uln/uln301/TreasuryFeeHandler.sol
+1 −1 messagelib/contracts/uln/uln302/ReceiveUln302.sol
+1 −1 messagelib/contracts/uln/uln302/SendUln302.sol
+2 −2 messagelib/contracts/upgradeable/WorkerUpgradeable.sol
+0 −177 messagelib/test/DVNAdapterBase.t.sol
+0 −35 messagelib/test/DVNAdapterFeeLibBase.t.sol
+15 −7 messagelib/test/LzExecutor.t.sol
+1 −1 messagelib/test/mocks/ReceiveLibMock.sol
+1 −1 messagelib/test/mocks/SendLibMock.sol
+1 −1 oapp/contracts/oapp/OApp.sol
+1 −1 oapp/contracts/oapp/OAppCore.sol
+1 −1 oapp/contracts/oapp/OAppReceiver.sol
+1 −1 oapp/contracts/oapp/OAppSender.sol
+1 −1 oapp/contracts/oapp/examples/OmniCounter.sol
+1 −1 oapp/contracts/oapp/examples/OmniCounterPreCrime.sol
+1 −1 oapp/contracts/oapp/interfaces/IOAppComposer.sol
+1 −1 oapp/contracts/oapp/interfaces/IOAppCore.sol
+1 −1 oapp/contracts/oapp/interfaces/IOAppMsgInspector.sol
+1 −1 oapp/contracts/oapp/interfaces/IOAppOptionsType3.sol
+1 −1 oapp/contracts/oapp/libs/OAppOptionsType3.sol
+1 −1 oapp/contracts/oapp/libs/OptionsBuilder.sol
+1 −1 oapp/contracts/oft/OFT.sol
+1 −1 oapp/contracts/oft/OFTAdapter.sol
+2 −2 oapp/contracts/oft/OFTCore.sol
+1 −1 oapp/contracts/oft/OFTPrecrime.sol
+1 −1 oapp/contracts/oft/interfaces/IOFT.sol
+1 −1 oapp/contracts/oft/libs/OFTComposeMsgCodec.sol
+1 −1 oapp/contracts/oft/libs/OFTMsgCodec.sol
+1 −1 oapp/contracts/precrime/OAppPreCrimeSimulator.sol
+1 −1 oapp/contracts/precrime/PreCrime.sol
+1 −1 oapp/contracts/precrime/extensions/PreCrimeE1.sol
+1 −1 oapp/contracts/precrime/interfaces/IOAppPreCrimeSimulator.sol
+1 −1 oapp/contracts/precrime/interfaces/IPreCrime.sol
+1 −1 oapp/contracts/precrime/libs/Packet.sol
+1 −1 oapp/test/OFT.t.sol
+1 −1 oapp/test/TestHelper.sol
+1 −1 oapp/test/mocks/ERC20Mock.sol
+1 −1 oapp/test/mocks/ExecutorFeeLibMock.sol
+1 −1 protocol/contracts/EndpointV2.sol
+1 −1 protocol/contracts/EndpointV2Alt.sol
+1 −1 protocol/contracts/MessageLibManager.sol
+1 −1 protocol/contracts/MessagingChannel.sol
+1 −1 protocol/contracts/MessagingComposer.sol
+1 −1 protocol/contracts/MessagingContext.sol
+11 −0 protocol/contracts/interfaces/ILayerZeroComposer.sol
+1 −1 protocol/contracts/libs/AddressCast.sol
+1 −1 protocol/contracts/libs/CalldataBytesLib.sol
+1 −1 protocol/contracts/libs/Errors.sol
+1 −1 protocol/contracts/libs/GUID.sol
+1 −1 protocol/contracts/libs/Transfer.sol
+1 −1 protocol/contracts/messagelib/BlockedMessageLib.sol
+1 −1 protocol/contracts/messagelib/SimpleMessageLib.sol
+1 −1 protocol/contracts/messagelib/libs/BitMaps.sol
+1 −1 protocol/contracts/messagelib/libs/ExecutorOptions.sol
+1 −1 protocol/contracts/messagelib/libs/PacketV1Codec.sol
82 changes: 82 additions & 0 deletions lib/oapp-upgradeable/oapp/libs/OAppOptionsType3Upgradeable.sol
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);
}
}
Loading

0 comments on commit eb3cce8

Please sign in to comment.