feat: add atomic-key-sewap - #1010
Merged
Merged
Conversation
|
@ONEONUORA Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
5 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.
close #957
close #960
close #958
close #961
Description
This PR implements the on-chain Key Rating mechanism for creator keys in
creator-keys.Key holders can submit a score (1–5 stars) for a creator. The contract maintains a running average score for each creator, enforces holder balance requirements, and supports re-ratings without double-counting unique raters.
Key Changes
1. Data Structures & Storage Keys
KeyRatingAggregatestruct containing:total_score: u64: Sum of all individual scores.count: u32: Number of unique raters.average_score_scaled: u32: Running average scaled by 100 (e.g.450represents4.50stars).RatingErrorenum:NotRegistered,InvalidScore,NotAHolder.FeatureKey:FeatureKey::KeyRatingAggregate(creator)FeatureKey::HolderKeyRating(creator, rater)2. Contract Entrypoints & Logic
rate_key(env, creator, rater, score):require_auth()).1..=5).holder_balance > 0).total_scoreandcountincrementally; updating an existing rating replaces the previous score instead of incrementingcount.KeyRatedEvent.get_key_rating(env, creator): Read-only view getter for aggregate key ratings.3. Event Emission
KEY_RATED_EVENT_NAME(symbol_short!("key_rated")).KeyRatedEventstruct andkey_rated_topicshelper.4. Tests
test_issues_972_971_968_969.rscovering:RatingError::NotAHolder).RatingError::InvalidScore).get_key_ratinggetter consistency.Verification
Ran cargo unit tests:
cargo test -p creator-keys --lib test_key_rating_flow_and_rejections