feat: implement fractional fee calculation and treasury routing - #91
Merged
Merged
Conversation
thegreatfeez
force-pushed
the
feat/59-fee-skimming
branch
from
July 24, 2026 13:43
d37a874 to
0a20531
Compare
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
force-pushed
the
feat/59-fee-skimming
branch
from
July 24, 2026 14:40
0a20531 to
64a199e
Compare
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Implements protocol fee skimming during
release_funds. When a treasury and a non-zero fee rate are configured (viaset_fee_config), the release now splits the escrowed amount intoamount - feeto the seller andfeeto the treasury, emitting aProtocolFeeCollectedevent atomically alongsideFundsReleased. If no fee is configured, or the fee truncates to 0 for a given amount, the seller receives 100% of the funds and onlyFundsReleasedfires — matching pre-existing behavior exactly.The fee is computed with
u128for the intermediate multiplication (guarded withchecked_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 theDataKey::FeeRate/DataKey::Treasurystorage andread_fee_rate/read_treasuryhelpers 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 ontomain.Type of Change
Testing
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 eventcargo fmt --all -- --check— cleancargo clippy --all-targets --all-features -- -D warnings— cleancargo build --target wasm32v1-none --release— builds successfullyCloses #59
Checklist
cargo fmtrun)cargo testpasses