From f6548d9e59ed3ca9a5c5072e5bd3a2c30bc5f255 Mon Sep 17 00:00:00 2001 From: Austin Born Date: Tue, 12 Sep 2023 08:34:12 -0700 Subject: [PATCH] Use array of quotePayload --- .../src/v0.8/llo-feeds/VerifierProxy.sol | 8 ++--- .../src/v0.8/llo-feeds/dev/FeeManager.sol | 31 +++++++++---------- .../llo-feeds/dev/interfaces/IFeeManager.sol | 4 +-- .../dev/interfaces/IVerifierFeeManager.sol | 10 +++--- .../llo-feeds/interfaces/IVerifierProxy.sol | 10 +++--- 5 files changed, 33 insertions(+), 30 deletions(-) diff --git a/contracts/src/v0.8/llo-feeds/VerifierProxy.sol b/contracts/src/v0.8/llo-feeds/VerifierProxy.sol index 4df6691b6ac..fc902484057 100644 --- a/contracts/src/v0.8/llo-feeds/VerifierProxy.sol +++ b/contracts/src/v0.8/llo-feeds/VerifierProxy.sol @@ -121,24 +121,24 @@ contract VerifierProxy is IVerifierProxy, ConfirmedOwner, TypeAndVersionInterfac } /// @inheritdoc IVerifierProxy - function verify(bytes calldata payload) external payable checkAccess returns (bytes memory) { + function verify(bytes calldata payload, bytes calldata quotePayload) external payable checkAccess returns (bytes memory) { IVerifierFeeManager feeManager = s_feeManager; // Bill the verifier if (address(feeManager) != address(0)) { - feeManager.processFee{value: msg.value}(payload, msg.sender); + feeManager.processFee{value: msg.value}(payload, quotePayload, msg.sender); } return _verify(payload); } /// @inheritdoc IVerifierProxy - function verifyBulk(bytes[] calldata payloads) external payable checkAccess returns (bytes[] memory verifiedReports) { + function verifyBulk(bytes[] calldata payloads, bytes[] calldata quotePayloads) external payable checkAccess returns (bytes[] memory verifiedReports) { IVerifierFeeManager feeManager = s_feeManager; // Bill the verifier if (address(feeManager) != address(0)) { - feeManager.processFeeBulk{value: msg.value}(payloads, msg.sender); + feeManager.processFeeBulk{value: msg.value}(payloads, quotePayloads, msg.sender); } //verify the reports diff --git a/contracts/src/v0.8/llo-feeds/dev/FeeManager.sol b/contracts/src/v0.8/llo-feeds/dev/FeeManager.sol index c770ad02109..beeb512485c 100644 --- a/contracts/src/v0.8/llo-feeds/dev/FeeManager.sol +++ b/contracts/src/v0.8/llo-feeds/dev/FeeManager.sol @@ -169,8 +169,8 @@ contract FeeManager is IFeeManager, ConfirmedOwner, TypeAndVersionInterface { } /// @inheritdoc IVerifierFeeManager - function processFee(bytes calldata payload, address subscriber) external payable override onlyProxy { - (Common.Asset memory fee, Common.Asset memory reward, uint256 appliedDiscount) = _processFee(payload, subscriber); + function processFee(bytes calldata payload, bytes calldata quotePayload, address subscriber) external payable override onlyProxy { + (Common.Asset memory fee, Common.Asset memory reward, uint256 appliedDiscount) = _processFee(payload, quotePayload, subscriber); if (fee.amount == 0) { _tryReturnChange(subscriber, msg.value); @@ -188,17 +188,22 @@ contract FeeManager is IFeeManager, ConfirmedOwner, TypeAndVersionInterface { } /// @inheritdoc IVerifierFeeManager - function processFeeBulk(bytes[] calldata payloads, address subscriber) external payable override onlyProxy { + function processFeeBulk(bytes[] calldata payloads, bytes[] calldata quotePayloads, address subscriber) external payable override onlyProxy { FeeAndReward[] memory feesAndRewards = new IFeeManager.FeeAndReward[](payloads.length); //keep track of the number of fees to prevent over initialising the FeePayment array within _convertToLinkAndNativeFees uint256 numberOfLinkFees; uint256 numberOfNativeFees; + bool separateQuotePayloads = quotePayloads.length > 1; + uint256 feesAndRewardsIndex; for (uint256 i; i < payloads.length; ++i) { + bytes calldata quotePayload = separateQuotePayloads ? quotePayloads[i] : quotePayloads[0]; + (Common.Asset memory fee, Common.Asset memory reward, uint256 appliedDiscount) = _processFee( payloads[i], + quotePayload, subscriber ); @@ -232,7 +237,7 @@ contract FeeManager is IFeeManager, ConfirmedOwner, TypeAndVersionInterface { function getFeeAndReward( address subscriber, bytes memory report, - Quote memory quote + address quoteAddress ) public view returns (Common.Asset memory, Common.Asset memory, uint256) { Common.Asset memory fee; Common.Asset memory reward; @@ -251,7 +256,7 @@ contract FeeManager is IFeeManager, ConfirmedOwner, TypeAndVersionInterface { } //verify the quote payload is a supported token - if (quote.quoteAddress != i_nativeAddress && quote.quoteAddress != i_linkAddress) { + if (quoteAddress != i_nativeAddress && quoteAddress != i_linkAddress) { revert InvalidQuote(); } @@ -270,14 +275,14 @@ contract FeeManager is IFeeManager, ConfirmedOwner, TypeAndVersionInterface { } //get the discount being applied - uint256 discount = s_subscriberDiscounts[subscriber][feedId][quote.quoteAddress]; + uint256 discount = s_subscriberDiscounts[subscriber][feedId][quoteAddress]; //the reward is always set in LINK reward.assetAddress = i_linkAddress; reward.amount = Math.ceilDiv(linkQuantity * (PERCENTAGE_SCALAR - discount), PERCENTAGE_SCALAR); //calculate either the LINK fee or native fee if it's within the report - if (quote.quoteAddress == i_linkAddress) { + if (quoteAddress == i_linkAddress) { fee.assetAddress = i_linkAddress; fee.amount = reward.amount; } else { @@ -358,6 +363,7 @@ contract FeeManager is IFeeManager, ConfirmedOwner, TypeAndVersionInterface { function _processFee( bytes calldata payload, + bytes calldata quotePayload, address subscriber ) internal view returns (Common.Asset memory, Common.Asset memory, uint256) { if (subscriber == address(this)) revert InvalidAddress(); @@ -369,17 +375,10 @@ contract FeeManager is IFeeManager, ConfirmedOwner, TypeAndVersionInterface { bytes32 feedId = bytes32(report); //v1 doesn't need a quote payload, so skip the decoding - Quote memory quote; + address quote; if (_getReportVersion(feedId) != REPORT_V1) { - //all reports greater than v1 should have a quote payload - (, , , , , bytes memory quoteBytes) = abi.decode( - payload, - // reportContext, report, rs, ss, raw, quote - (bytes32[3], bytes, bytes32[], bytes32[], bytes32, bytes) - ); - //decode the quote from the bytes - (quote) = abi.decode(quoteBytes, (Quote)); + (quote) = abi.decode(quotePayload, (address)); } //decode the fee, it will always be native or LINK diff --git a/contracts/src/v0.8/llo-feeds/dev/interfaces/IFeeManager.sol b/contracts/src/v0.8/llo-feeds/dev/interfaces/IFeeManager.sol index 49fd7f95587..dc5bffd159d 100644 --- a/contracts/src/v0.8/llo-feeds/dev/interfaces/IFeeManager.sol +++ b/contracts/src/v0.8/llo-feeds/dev/interfaces/IFeeManager.sol @@ -10,13 +10,13 @@ interface IFeeManager is IERC165, IVerifierFeeManager { * @notice Calculate the applied fee and the reward from a report. If the sender is a subscriber, they will receive a discount. * @param subscriber address trying to verify * @param report report to calculate the fee for - * @param quote any metadata required to fetch the fee + * @param quoteAddress address of the quote payment token * @return (fee, reward, totalDiscount) fee and the reward data with the discount applied */ function getFeeAndReward( address subscriber, bytes memory report, - Quote memory quote + address quoteAddress ) external returns (Common.Asset memory, Common.Asset memory, uint256); /** diff --git a/contracts/src/v0.8/llo-feeds/dev/interfaces/IVerifierFeeManager.sol b/contracts/src/v0.8/llo-feeds/dev/interfaces/IVerifierFeeManager.sol index c9b1a821746..99ff1e6fe12 100644 --- a/contracts/src/v0.8/llo-feeds/dev/interfaces/IVerifierFeeManager.sol +++ b/contracts/src/v0.8/llo-feeds/dev/interfaces/IVerifierFeeManager.sol @@ -7,17 +7,19 @@ import {Common} from "../../../libraries/Common.sol"; interface IVerifierFeeManager is IERC165 { /** * @notice Handles fees for a report from the subscriber and manages rewards - * @param payload report and quote to process the fee for + * @param payload report to process the fee for + * @param quotePayload quote payload * @param subscriber address of the fee will be applied */ - function processFee(bytes calldata payload, address subscriber) external payable; + function processFee(bytes calldata payload, bytes calldata quotePayload, address subscriber) external payable; /** * @notice Processes the fees for each report in the payload, billing the subscriber and paying the reward manager - * @param payloads reports and quotes to process + * @param payloads reports to process + * @param quotePayloads quote payloads for each payload or 1 for all * @param subscriber address of the user to process fee for */ - function processFeeBulk(bytes[] calldata payloads, address subscriber) external payable; + function processFeeBulk(bytes[] calldata payloads, bytes[] calldata quotePayloads, address subscriber) external payable; /** * @notice Sets the fee recipients according to the fee manager diff --git a/contracts/src/v0.8/llo-feeds/interfaces/IVerifierProxy.sol b/contracts/src/v0.8/llo-feeds/interfaces/IVerifierProxy.sol index 82ac492f5c3..75475f2672d 100644 --- a/contracts/src/v0.8/llo-feeds/interfaces/IVerifierProxy.sol +++ b/contracts/src/v0.8/llo-feeds/interfaces/IVerifierProxy.sol @@ -10,19 +10,21 @@ interface IVerifierProxy { * @notice Verifies that the data encoded has been signed * correctly by routing to the correct verifier, and bills the user if applicable. * @param payload The encoded data to be verified, including the signed - * report and any metadata for billing. + * report. + * @param quotePayload quote metadata for billing * @return verifierResponse The encoded report from the verifier. */ - function verify(bytes calldata payload) external payable returns (bytes memory verifierResponse); + function verify(bytes calldata payload, bytes calldata quotePayload) external payable returns (bytes memory verifierResponse); /** * @notice Bulk verifies that the data encoded has been signed * correctly by routing to the correct verifier, and bills the user if applicable. * @param payloads The encoded payloads to be verified, including the signed - * report and any metadata for billing. + * report. + * @param quotePayloads quote metadata for billing * @return verifiedReports The encoded reports from the verifier. */ - function verifyBulk(bytes[] calldata payloads) external payable returns (bytes[] memory verifiedReports); + function verifyBulk(bytes[] calldata payloads, bytes[] calldata quotePayloads) external payable returns (bytes[] memory verifiedReports); /** * @notice Sets the verifier address initially, allowing `setVerifier` to be set by this Verifier in the future