TieredDiscount

The TieredDiscount contract provides fee discounts based on a user's token balance.

Source: contracts/periphery/TieredDiscount.sol

Overview

TieredDiscount implements IFeeManager to provide progressive fee discounts:

  • Users holding more tokens receive larger discounts

  • Discounts are applied during swap execution

  • Configurable thresholds and discount rates

State Variables

DENOMINATOR

uint256 public constant DENOMINATOR = 10000;

Constant used for basis point calculations (10000 = 100%).

token

address public token;

The ERC20 token whose balance determines discount eligibility.

thresholds

Balance thresholds for each discount tier (ascending order).

discounts

Discount amounts in basis points for each tier.

Constructor

Parameter
Description

_token

Token to check balance of

_thresholds

Balance thresholds (must be ascending)

_discounts

Discount bps for each threshold

Example:

Functions

computeFee

Computes the discounted fee based on the caller's token balance.

Parameters:

Name
Type
Description

fee

uint24

Base fee in hundredths of a bip

Returns:

Type
Description

uint24

Discounted fee

Logic:

Example Calculation:


computeFeeFor

Computes the fee for an arbitrary address. Useful for simulating fees before swapping.

Parameters:

Name
Type
Description

fee

uint24

Base fee in hundredths of a bip

recipient

address

Address to check balance for

Returns:

Type
Description

uint24

Discounted fee


updateInfo

Updates the token, thresholds, and discounts configuration.

Access Control: Owner only

Parameters:

Name
Type
Description

_token

address

Token to check balance of

_thresholds

uint256[]

New thresholds (ascending order, positive values)

_discounts

uint16[]

New discounts in bps (ascending order, <= 10000)

Requirements:

  • Arrays must not be empty

  • Arrays must have the same length

  • Thresholds must be positive and strictly increasing

  • Discounts must be strictly increasing and <= 10000 (100%)

Example:

Discount Tiers

Default Configuration

Tier
Balance Threshold
Discount

1

≥ 1,000 tokens

1% (100 bps)

2

≥ 10,000 tokens

2% (200 bps)

3

≥ 100,000 tokens

3% (300 bps)

4

≥ 1,000,000 tokens

4% (400 bps)

Tier Selection Logic

The function iterates through thresholds in ascending order and selects the highest applicable discount.

Usage Examples

Checking Effective Discount

Simulating Discounted Fee

Manual Calculation

Integration

Pool Creation

With OverridableFeeManager

Security Considerations

tx.origin Usage

The contract uses tx.origin to determine the swapper's balance:

Implications:

  • Discounts apply to the original transaction sender

  • Contracts calling on behalf of users may not receive expected discounts

  • Flash loan attacks cannot easily exploit discounts

Token Balance Manipulation

Risk: Users could temporarily acquire tokens to get discounts.

Mitigations:

  • Require minimum holding period

  • Use time-weighted average balance

  • Integrate with staking for eligibility

Owner Privileges

The owner can:

  • Change token, thresholds, and discounts at any time via updateInfo()

Recommendations:

  • Use multisig for ownership

  • Add timelock for configuration changes

  • Consider immutable deployments

Last updated