feat: optional governed protocol fee module - #421
Open
ghg001 wants to merge 18 commits into
Open
Conversation
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.
Overview
This PR adds an optional protocol-level fee module to Tributary, off by default and backward compatible. A governed fee rate and recipient are applied once at the top level of
pay/distribute/pay_many, with the remaining amount split exactly among recipients. The accounting invariant is updated toamount_in == fee + sum(recipient_amounts), with zero-rate behavior identical to today and an on-chain cap preventing abusive governance rates.Related Issue
Closes the optional protocol fee module bounty.
Changes
⚖️ Governed Protocol Fee Module
[DECISION] Product direction recorded: protocol-level optional fee only; per-split fee configs are deferred. Nested splits do not re-apply the fee; escrow
deposit/distributeapply the fee at distribution time; eachpay_manyleg applies the configured fee once.[ADD]
contracts/splitter/src/lib.rsFeeConfig { rate_bps, recipient }state.set_fee_configwithMAX_FEE_BPS = 1000(10%) enforced on-chain.[MODIFY]
contracts/splitter/src/lib.rsamounts()/pay()/distribute()to skimfee = amount_in * rate_bps / 10000before recipient splitting.FeeTakenevent leg for transparency.[MODIFY]
contracts/splitter/src/test.rspay_manyand escrow composition tests.[MODIFY]
contracts/splitter-proofs/src/model.rsandcontracts/splitter-proofs/src/proofs.rsamount_in == fee + sum(recipient_amounts).[MODIFY]
sdk/src/index.tspreview_payoutresults.[MODIFY]
app/src/lib/tributary.tsandapp/src/lib/fees.tsVerification Results
amount_in == fee + sum(recipient_amounts)holds exactlyMAX_FEE_BPS = 1000(10%) enforced inset_fee_configpreview_payoutand events expose the fee transparentlypreview_payoutreturns fee/fee_recipient;FeeTakenemitted for pay/distributeCloses #354