@@ -301,6 +301,8 @@ abstract contract Scheduler is IScheduler, SchedulerState {
301301 : 0 ,
302302 curTime + FUTURE_TIMESTAMP_MAX_VALIDITY_PERIOD
303303 );
304+ status.balanceInWei -= pythFee;
305+ status.totalSpent += pythFee;
304306
305307 // Verify all price feeds have the same Pythnet slot.
306308 // All feeds in a subscription must be updated at the same time.
@@ -327,7 +329,7 @@ abstract contract Scheduler is IScheduler, SchedulerState {
327329
328330 _storePriceUpdates (subscriptionId, priceFeeds);
329331
330- _processFeesAndPayKeeper (status, startGas, priceIds.length , pythFee );
332+ _processFeesAndPayKeeper (status, startGas, priceIds.length );
331333
332334 emit PricesUpdated (subscriptionId, latestPublishTime);
333335 }
@@ -745,35 +747,33 @@ abstract contract Scheduler is IScheduler, SchedulerState {
745747 /**
746748 * @notice Internal function to calculate total fees, deduct from balance, and pay the keeper.
747749 * @dev This function sends funds to `msg.sender`, so be sure that this is being called by a keeper.
750+ * @dev Note that the Pyth fee is already paid in the parsePriceFeedUpdatesWithSlots call.
748751 * @param status Storage reference to the subscription's status.
749752 * @param startGas Gas remaining at the start of the parent function call.
750753 * @param numPriceIds Number of price IDs being updated.
751- * @param pythFee Fee paid to Pyth for the update.
752754 */
753755 function _processFeesAndPayKeeper (
754756 SubscriptionStatus storage status ,
755757 uint256 startGas ,
756- uint256 numPriceIds ,
757- uint256 pythFee
758+ uint256 numPriceIds
758759 ) internal {
759760 // Calculate fee components
760761 uint256 gasCost = (startGas - gasleft () + GAS_OVERHEAD) * tx .gasprice ;
761762 uint256 keeperSpecificFee = uint256 (_state.singleUpdateKeeperFeeInWei) *
762763 numPriceIds;
763764 uint256 totalKeeperFee = gasCost + keeperSpecificFee;
764- uint256 totalFee = totalKeeperFee + pythFee; // pythFee is already paid in the parsePriceFeedUpdatesWithSlots call
765765
766766 // Check balance
767- if (status.balanceInWei < totalFee ) {
767+ if (status.balanceInWei < totalKeeperFee ) {
768768 revert InsufficientBalance ();
769769 }
770770
771- // Update status and pay keeper
772- status.balanceInWei -= totalFee;
773- status.totalSpent += totalFee;
774- (bool sent , ) = msg .sender .call {value: totalKeeperFee}("" ); // Pay only the keeper portion
771+ // Pay keeper and update status if successful
772+ (bool sent , ) = msg .sender .call {value: totalKeeperFee}("" );
775773 if (! sent) {
776774 revert KeeperPaymentFailed ();
777775 }
776+ status.balanceInWei -= totalKeeperFee;
777+ status.totalSpent += totalKeeperFee;
778778 }
779779}
0 commit comments