Skip to content

feat: implement fractional fee calculation and treasury routing - #91

Merged
Robotron2 merged 1 commit into
Padi-Pay:mainfrom
thegreatfeez:feat/59-fee-skimming
Jul 24, 2026
Merged

feat: implement fractional fee calculation and treasury routing#91
Robotron2 merged 1 commit into
Padi-Pay:mainfrom
thegreatfeez:feat/59-fee-skimming

Conversation

@thegreatfeez

Copy link
Copy Markdown
Contributor

Description

Implements protocol fee skimming during release_funds. When a treasury and a non-zero fee rate are configured (via set_fee_config), the release now splits the escrowed amount into amount - fee to the seller and fee to the treasury, emitting a ProtocolFeeCollected event atomically alongside FundsReleased. If no fee is configured, or the fee truncates to 0 for a given amount, the seller receives 100% of the funds and only FundsReleased fires — matching pre-existing behavior exactly.

The fee is computed with u128 for the intermediate multiplication (guarded with checked_mul) to avoid overflow, and integer division truncates the fee downward, so rounding always favors the seller.

Depends on #58 (this branch is built on top of feat/fee-storage, since fee skimming needs the DataKey::FeeRate/DataKey::Treasury storage and read_fee_rate/read_treasury helpers introduced there). This PR cannot merge before #58/PR #90 merges — the diff below currently includes that PR's commit as well; it will shrink to just this issue's changes once #90 lands and this branch is rebased onto main.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

  1. cargo test — all existing tests plus 5 new tests pass (107 total): fee-uninitialized defaults to a full payout, a configured fee correctly splits seller/treasury balances and emits both events, fee rounding truncates in the seller's favor on an odd amount, and a tiny amount whose fee truncates to 0 still pays the seller 100% with no fee event
  2. cargo fmt --all -- --check — clean
  3. cargo clippy --all-targets --all-features -- -D warnings — clean
  4. cargo build --target wasm32v1-none --release — builds successfully

Closes #59

Checklist

  • Code follows style guidelines (cargo fmt run)
  • Tests added/updated and cargo test passes
  • Documentation updated

@thegreatfeez
thegreatfeez force-pushed the feat/59-fee-skimming branch from d37a874 to 0a20531 Compare July 24, 2026 13:43
Splits release_funds into a seller payout and a protocol fee transfer
to the configured treasury, using u128 for the percentage math to
avoid overflow and truncating the fee in the seller's favor. Emits
ProtocolFeeCollected alongside FundsReleased when a fee is actually
collected; releases fall back to paying the seller 100% when no fee
is configured.
@thegreatfeez
thegreatfeez force-pushed the feat/59-fee-skimming branch from 0a20531 to 64a199e Compare July 24, 2026 14:40
@Robotron2
Robotron2 merged commit 9553a15 into Padi-Pay:main Jul 24, 2026
1 check passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Jul 24, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Protocol Fee Skimming Execution

2 participants