Skip to content

Commit

Permalink
Merge pull request #13 from LayerZero-Labs/improve
Browse files Browse the repository at this point in the history
chore: worker fee lib revert if not configured
  • Loading branch information
cowboyisaac authored Jan 23, 2024
2 parents 0990059 + ddeda7a commit 6356f0a
Showing 12 changed files with 37 additions and 8 deletions.
4 changes: 4 additions & 0 deletions messagelib/contracts/ExecutorFeeLib.sol
Original file line number Diff line number Diff line change
@@ -32,6 +32,8 @@ contract ExecutorFeeLib is Ownable, IExecutorFeeLib {
IExecutor.DstConfig calldata _dstConfig,
bytes calldata _options
) external returns (uint256 fee) {
if (_dstConfig.baseGas == 0) revert Executor_EidNotSupported(_params.dstEid);

(uint256 totalDstAmount, uint256 totalGas) = _decodeExecutorOptions(
_isV1Eid(_params.dstEid),
_dstConfig.baseGas,
@@ -68,6 +70,8 @@ contract ExecutorFeeLib is Ownable, IExecutorFeeLib {
IExecutor.DstConfig calldata _dstConfig,
bytes calldata _options
) external view returns (uint256 fee) {
if (_dstConfig.baseGas == 0) revert Executor_EidNotSupported(_params.dstEid);

(uint256 totalDstAmount, uint256 totalGas) = _decodeExecutorOptions(
_isV1Eid(_params.dstEid),
_dstConfig.baseGas,
1 change: 1 addition & 0 deletions messagelib/contracts/interfaces/IExecutorFeeLib.sol
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ interface IExecutorFeeLib {
error Executor_UnsupportedOptionType(uint8 optionType);
error Executor_InvalidExecutorOptions(uint256 cursor);
error Executor_ZeroLzReceiveGasProvided();
error Executor_EidNotSupported(uint32 eid);

function getFeeOnSend(
FeeParams calldata _params,
4 changes: 4 additions & 0 deletions messagelib/contracts/uln/dvn/DVNFeeLib.sol
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ contract DVNFeeLib is Ownable, IDVNFeeLib {
IDVN.DstConfig calldata _dstConfig,
bytes calldata _options
) external payable returns (uint256) {
if (_dstConfig.gas == 0) revert DVN_EidNotSupported(_params.dstEid);

_decodeDVNOptions(_options); // todo: validate options

uint256 callDataSize = _getCallDataSize(_params.quorum);
@@ -76,6 +78,8 @@ contract DVNFeeLib is Ownable, IDVNFeeLib {
IDVN.DstConfig calldata _dstConfig,
bytes calldata _options
) external view returns (uint256) {
if (_dstConfig.gas == 0) revert DVN_EidNotSupported(_params.dstEid);

_decodeDVNOptions(_options); // validate options

uint256 callDataSize = _getCallDataSize(_params.quorum);
Original file line number Diff line number Diff line change
@@ -38,7 +38,8 @@ contract CCIPDVNAdapterFeeLib is OwnableUpgradeable, Proxied, ICCIPDVNAdapterFee
bytes calldata _options,
IRouterClient _router
) external payable returns (uint256 ccipFee, uint256 totalFee) {
if (_options.length > 0) revert CCIPDVN_OptionsUnsupported();
if (_dstConfig.gas == 0) revert CCIPDVNAdapter_EidNotSupported(_params.dstEid);
if (_options.length > 0) revert CCIPDVNAdapter_OptionsUnsupported();

ccipFee = _router.getFee(_dstConfig.chainSelector, _message);
totalFee = _applyPremium(_dstConfig.multiplierBps, _params.defaultMultiplierBps, ccipFee);
@@ -51,7 +52,8 @@ contract CCIPDVNAdapterFeeLib is OwnableUpgradeable, Proxied, ICCIPDVNAdapterFee
bytes calldata _options,
IRouterClient _router
) external view returns (uint256 totalFee) {
if (_options.length > 0) revert CCIPDVN_OptionsUnsupported();
if (_dstConfig.gas == 0) revert CCIPDVNAdapter_EidNotSupported(_params.dstEid);
if (_options.length > 0) revert CCIPDVNAdapter_OptionsUnsupported();

totalFee = _router.getFee(_dstConfig.chainSelector, _message);
totalFee = _applyPremium(_dstConfig.multiplierBps, _params.defaultMultiplierBps, totalFee);
Original file line number Diff line number Diff line change
@@ -72,6 +72,7 @@ contract AxelarDVNAdapterFeeLib is OwnableUpgradeable, Proxied, IAxelarDVNAdapte
bytes calldata _options,
address _sendLib
) external payable returns (uint256 totalFee) {
if (_dstConfig.nativeGasFee == 0) revert AxelarDVNAdapter_EidNotSupported(_param.dstEid);
if (_options.length > 0) revert AxelarDVNAdapter_OptionsUnsupported();

uint256 axelarFee = _getAxelarFee(_dstConfig.nativeGasFee);
@@ -102,6 +103,7 @@ contract AxelarDVNAdapterFeeLib is OwnableUpgradeable, Proxied, IAxelarDVNAdapte
IAxelarDVNAdapter.DstConfig calldata _dstConfig,
bytes calldata _options
) external view returns (uint256 totalFee) {
if (_dstConfig.nativeGasFee == 0) revert AxelarDVNAdapter_EidNotSupported(_param.dstEid);
if (_options.length > 0) revert AxelarDVNAdapter_OptionsUnsupported();

uint256 axelarFee = _getAxelarFee(_dstConfig.nativeGasFee);
1 change: 1 addition & 0 deletions messagelib/contracts/uln/interfaces/IDVNFeeLib.sol
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ interface IDVNFeeLib {
}

error DVN_UnsupportedOptionType(uint8 optionType);
error DVN_EidNotSupported(uint32 eid);

function getFeeOnSend(
FeeParams calldata _params,
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@ interface IAxelarDVNAdapterFeeLib {

error AxelarDVNAdapter_OptionsUnsupported();
error AxelarDVNAdapter_InsufficientBalance(uint256 actual, uint256 requested);
error AxelarDVNAdapter_EidNotSupported(uint32 eid);

function getFeeOnSend(
Param calldata _params,
Original file line number Diff line number Diff line change
@@ -25,7 +25,8 @@ interface ICCIPDVNAdapterFeeLib {

event DstConfigSet(DstConfigParam[] params);

error CCIPDVN_OptionsUnsupported();
error CCIPDVNAdapter_OptionsUnsupported();
error CCIPDVNAdapter_EidNotSupported(uint32 eid);

function getFeeOnSend(
Param calldata _params,
2 changes: 1 addition & 1 deletion messagelib/test/DVNFeeLib.t.sol
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ contract DVNFeeLibTest is Test {
uint256 gasFee = 100;
uint128 priceRatio = 1e10;
uint128 nativePriceUSD = 2000e10;
uint64 gas = 0;
uint64 gas = 1;
uint16 multiplierBps = 10000;
uint128 floorMarginUSD = 3e10;
uint64 quorum = 3;
2 changes: 1 addition & 1 deletion messagelib/test/ExecutorFeeLib.t.sol
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ contract ExecutorFeeLibTest is Test {
uint256 gasFee = 100;
uint128 priceRatio = 1e10;
uint128 nativePriceUSD = 2000e10;
uint64 baseGas = 0;
uint64 baseGas = 1;
uint16 multiplierBps = 10000;
uint128 floorMarginUSD = 3e10;
uint128 nativeDropCap = 222000;
5 changes: 5 additions & 0 deletions messagelib/test/util/Setup.sol
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import { EndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/Endpoint
import { EndpointV1 } from "../mocks/EndpointV1.sol";

import { NonceContractMock as NonceContract } from "../../contracts/uln/uln301/mocks/NonceContractMock.sol";
import { IDVN } from "../../contracts/uln/interfaces/IDVN.sol";
import { DVN } from "../../contracts/uln/dvn/DVN.sol";
import { DVNFeeLib } from "../../contracts/uln/dvn/DVNFeeLib.sol";
import { Executor } from "../../contracts/Executor.sol";
@@ -261,6 +262,10 @@ library Setup {
address[] memory admins = new address[](1);
admins[0] = address(this);
DVN dvn = new DVN(eid, libs, priceFeed, signers, 1, admins);

IDVN.DstConfigParam[] memory dstConfigParams = new IDVN.DstConfigParam[](1);
dstConfigParams[0] = IDVN.DstConfigParam({ dstEid: eid, gas: 5000, multiplierBps: 0, floorMarginUSD: 0 });
dvn.setDstConfig(dstConfigParams);
DVNFeeLib dvnFeeLib = new DVNFeeLib(1e18);
dvn.setWorkerFeeLib(address(dvnFeeLib));

14 changes: 11 additions & 3 deletions oapp/test/TestHelper.sol
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import { DoubleEndedQueue } from "@openzeppelin/contracts/utils/structs/DoubleEn
import { UlnConfig, SetDefaultUlnConfigParam } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/UlnBase.sol";
import { SetDefaultExecutorConfigParam, ExecutorConfig } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/SendLibBase.sol";
import { ReceiveUln302 } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/uln302/ReceiveUln302.sol";
import { IDVN } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/interfaces/IDVN.sol";
import { DVN, ExecuteParam } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/dvn/DVN.sol";
import { DVNFeeLib } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/dvn/DVNFeeLib.sol";
import { IExecutor } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/interfaces/IExecutor.sol";
@@ -30,8 +31,6 @@ import { SendUln302Mock as SendUln302 } from "./mocks/SendUln302Mock.sol";
import { SimpleMessageLibMock } from "./mocks/SimpleMessageLibMock.sol";
import "./mocks/ExecutorFeeLibMock.sol";

import "forge-std/console.sol";

contract TestHelper is Test, OptionsHelper {
using OptionsBuilder for bytes;

@@ -132,9 +131,9 @@ contract TestHelper is Test, OptionsHelper {
dvn.setWorkerFeeLib(address(dvnLib));
}

//todo: setDstGas
uint32 endpointNum = _endpointNum;
IExecutor.DstConfigParam[] memory dstConfigParams = new IExecutor.DstConfigParam[](endpointNum);
IDVN.DstConfigParam[] memory dvnConfigParams = new IDVN.DstConfigParam[](endpointNum);
for (uint8 j = 0; j < endpointNum; j++) {
if (i == j) continue;
uint32 dstEid = j + 1;
@@ -187,6 +186,14 @@ contract TestHelper is Test, OptionsHelper {
nativeCap: executorValueCap
});

// dvn config
dvnConfigParams[j] = IDVN.DstConfigParam({
dstEid: dstEid,
gas: 5000,
multiplierBps: 10000,
floorMarginUSD: 1e10
});

uint128 denominator = priceFeed.getPriceRatioDenominator();
ILayerZeroPriceFeed.UpdatePrice[] memory prices = new ILayerZeroPriceFeed.UpdatePrice[](1);
prices[0] = ILayerZeroPriceFeed.UpdatePrice(
@@ -196,6 +203,7 @@ contract TestHelper is Test, OptionsHelper {
priceFeed.setPrice(prices);
}
executor.setDstConfig(dstConfigParams);
dvn.setDstConfig(dvnConfigParams);
} else if (_libraryType == LibraryType.SimpleMessageLib) {
SimpleMessageLibMock messageLib = new SimpleMessageLibMock(payable(this), address(endpointList[i]));
endpointList[i].registerLibrary(address(messageLib));

0 comments on commit 6356f0a

Please sign in to comment.