livepeer / livepeer/subgraph

Fee calculation uses faceValue instead of amountToTransfer

Open
#229 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
5
Forks
7
Avg merge
4h 1m
Merged PRs (30d)
6

Description

## 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)

```solidity
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`:
```solidity
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in ticketBroker.ts and trace the WinningTicketRedeemed handler's fee calculations alongside the WinningTicketTransfer flow in MixinTicketBrokerCore.sol:137-155. Verify the indexed fee values for an underfunded sender against amountToTransfer, then run the subgraph's relevant indexing or test checks; done means the fee fields no longer use the larger faceValue base in that case.

Written by the indexing model from the issue text.

Assessment

Tech stack
solidity, typescript
Domain
blockchain, data-engineering
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
64/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.