feat(rewards): accrue protocol fee rewards with view, event, and boundary tests - #443
Merged
mikewheeleer merged 1 commit intoJul 30, 2026
Conversation
…dary tests Adds a minimal rewards-accrual model: every fee-bearing compute_route_fee call adds its fee to a protocol-wide RewardsAccrued counter (saturating, owed to FeeRecipient once distributed), exposed via get_rewards_accrued and a rwd_accr event carrying (fee, running_total). Zero-fee routes are not a state change and neither write nor emit. Closes StableRoute-Org#419 Closes StableRoute-Org#420 Closes StableRoute-Org#421
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.
Summary
The router had no rewards concept — closest existing state is the fee collected per route (
compute_route_fee) that's ultimately owed toFeeRecipient. Issues #419-#421 each describe a slice of a rewards model (a view, an event, boundary tests) that presuppose the underlying accrual exists, so this is the minimal accrual this repo's fee model naturally supports, built in one PR since #419's view and #420's event are two sides of the same state:DataKey::RewardsAccrued— protocol-wide lifetime sum of fees collected,saturating_add, same pattern asTotalRoutesAllTime/PairVolumeget_rewards_accrued()— read-only view (Add a read-only view exposing the current rewards state #419)rwd_accrevent carrying(fee, running_total), emitted only whenfee > 0— a zero-fee route is not a rewards-state change, so it neither writes nor emits (Emit a dedicated event when rewards state changes #420, 'no duplicate emissions')compute_route_fee's existing effects section, right after theTotalRoutesAllTimewriteTests (#421)
Default-zero, accumulation across multiple routes, zero-fee route is a no-op (no write, no event), event payload carries the correct
(fee, running_total), and the over-limit boundary: seeding the counter neari128::MAXand confirming a further accrual saturates instead of panicking.Test output
Same pre-existing
main-at-HEAD build breakage as prior PRs in this batch (103 unrelated errors, reproducible viagit stash). Confirmed this change adds zero additional errors.Closes #419
Closes #420
Closes #421