Skip to content

Commit

Permalink
Use array of quotePayload
Browse files Browse the repository at this point in the history
  • Loading branch information
austinborn committed Sep 12, 2023
1 parent e1e95e3 commit f6548d9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
8 changes: 4 additions & 4 deletions contracts/src/v0.8/llo-feeds/VerifierProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 15 additions & 16 deletions contracts/src/v0.8/llo-feeds/dev/FeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
);

Expand Down Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/v0.8/llo-feeds/dev/interfaces/IFeeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions contracts/src/v0.8/llo-feeds/interfaces/IVerifierProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f6548d9

Please sign in to comment.