Skip to content

Fee calculation uses faceValue instead of amountToTransfer #229

Description

@rickstaa

Problem

In ticketBroker.ts, the WinningTicketRedeemed handler uses event.params.faceValue for fee distribution math. However, the contract's updateTranscoderWithFees receives amountToTransfer, which can be less than faceValue when the sender's deposit is insufficient.

Contract flow (MixinTicketBrokerCore.sol:137-155)

if (_ticket.faceValue > sender.deposit) {
    amountToTransfer = sender.deposit.add(
        claimFromReserve(_ticket.sender, _ticket.recipient, _ticket.faceValue.sub(sender.deposit))
    );
    sender.deposit = 0;
} else {
    amountToTransfer = _ticket.faceValue;
}

winningTicketTransfer(_ticket.recipient, amountToTransfer, _ticket.auxData);

winningTicketTransfer → updateTranscoderWithFees(_recipient, _amount, ...) uses amountToTransfer.

But the WinningTicketRedeemed event emits faceValue, not amountToTransfer:

emit WinningTicketRedeemed(_ticket.sender, _ticket.recipient, _ticket.faceValue, ...);

Impact

When a sender is underfunded (deposit < faceValue), the subgraph overcounts:

  • delegatorsFees and transcoderCommissionFees are computed on a higher base
  • cumulativeFeeFactor update is slightly inflated
  • pendingFeeCommission / lifetimeFeeCommission are slightly inflated

In the normal case (deposit >= faceValue), the values are equal and there is no issue.

Possible fix

The WinningTicketTransfer event emits amountToTransfer — could use that instead of or in addition to WinningTicketRedeemed.faceValue for the fee math.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions