> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sweepr.co/llms.txt
> Use this file to discover all available pages before exploring further.

# EVM V2 On-Chain Fees

> How Sweepr V2 uses signed fee authorizations and the V5 contract to split partner and protocol fees on-chain.

# EVM V2 On-Chain Partner Fees

V2 uses `SweeprBatchV5PartnerFees`, a Permit2-based EVM contract that atomically splits sweep output between the user, partner, and Sweepr protocol recipient.

V2 does not support cross-chain sweeps. Each V2 sweep is single-chain.

## Flow

```txt theme={"dark"}
Partner app
  -> POST /sweepr/v2/sweep/build
  <- Permit2 typed data, V5 transaction template, signed fee authorization

User wallet
  -> signs Permit2 typed data
  -> sends V5 transaction

V5 contract
  -> verifies Sweepr fee authorization
  -> pulls tokens through Permit2
  -> executes whitelisted router swaps
  -> splits output atomically

Partner app
  -> POST /sweepr/v2/sweep/status/:id/confirm
  <- Sweepr confirms actual split from matching SweepExecutedV5 event
```

## Fee Math

```txt theme={"dark"}
grossOutput = output balance after swaps
totalFee = grossOutput * totalFeeBps / 10000
partnerFee = totalFee * partnerShareBps / 10000
protocolFee = totalFee - partnerFee
userAmount = grossOutput - totalFee
```

`partnerShareBps` is the partner's share of the Sweepr platform fee. It is not charged directly against the full swap output.

The current V2 platform fee is `75` bps, or `0.75%` of gross output.

## Dynamic Partner Fees

Partner fee share is configured in Sweepr's backend per partner. The partner cannot override it in the build request.

For each V2 build, Sweepr signs a short-lived `FeeAuthorization`:

```txt theme={"dark"}
user
partnerId
partnerRecipient
protocolRecipient
outputToken
totalFeeBps
partnerShareBps
nonce
deadline
```

The V5 contract verifies:

* Signature is from the configured Sweepr fee signer.
* Signed user is `msg.sender`.
* Deadline is still valid.
* Nonce has not been used.
* Signed chain and contract match the EIP-712 domain.
* Output token matches the actual sweep output token.
* Fee is under the hard cap.
* Required recipients are non-zero.

## Confirmation And Indexing

V2 does not run a broad full-chain indexer. It indexes only submitted transaction hashes known to Sweepr.

The partner app must call confirm after the user submits the transaction:

```txt theme={"dark"}
POST /sweepr/v2/sweep/status/:id/confirm
```

If the receipt is not indexed yet, Sweepr returns `pending`. The backend indexer continues checking the submitted hash with retry backoff and fallback RPC providers.

Sweepr only marks the sweep complete when the V5 event matches the original stored fee authorization:

* event user matches the signed user
* event partner id matches the stored partner id
* event partner recipient matches the stored payout wallet
* event output token matches the signed output token
* event token count matches the built sweep

This prevents a valid V5 transaction from being used as proof for a different sweep.

## Reliability Model

The V2 indexer stores lifecycle state for every fee authorization:

```txt theme={"dark"}
status
txHash
submittedAt
confirmedAt
checkAttempts
lastCheckedAt
nextCheckAt
lastError
```

Unsubmitted authorizations can expire after their deadline. Once a transaction hash is submitted, Sweepr reconciles against the actual on-chain receipt rather than expiring it blindly.

## Rollback

V4 remains available. If Sweepr sets:

```txt theme={"dark"}
SWEEPR_EVM_BUILD_MODE=v4_fallback
```

the backend can return the V4 path without requiring partner app changes.
