This document captures the arithmetic guarantees for platform-fee calculation in
contracts/predictify-hybrid/src/fees.rs.
- All fee percentage math uses checked arithmetic.
- Any overflow in fee multiplication, addition, subtraction, or division returns
Error::FeeArithmeticOverflow. - Basis-point calculations round down using integer division.
- Fee breakdowns must reconcile exactly:
platform_fee + user_payout_amount == total_staked
Platform fees are computed with checked multiply-then-divide logic:
floor(total_staked * fee_bps / 10_000)
Because all supported fee inputs are non-negative, integer division is equivalent to floor rounding. This intentionally favors reconciliation over accidental over-collection.
The following operations must never wrap:
FeeCalculator::calculate_platform_feeFeeCalculator::calculate_user_payout_after_feesFeeCalculator::calculate_fee_breakdown- dynamic fee multiplier math
FeeManager::collect_feesthrough its fee calculation path- fee vault and creation-fee total accumulation in
FeeTracker
If an intermediate value exceeds i128, the operation fails with
Error::FeeArithmeticOverflow and no fee state is updated.
Regression tests cover:
- zero pool rejection
- 1-bps floor rounding
- overflow-adjacent
i128::MAXstake pools - fee breakdown reconciliation after floor rounding
- no mutation when
collect_feesencounters overflow - fee vault accumulation overflow rejection