-
Notifications
You must be signed in to change notification settings - Fork 9
🎨 Refactor the Price Buckets #488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🎨 Refactor the Price Buckets #488
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the bucket creation process and updates related documentation and tests. The changes remove unnecessary error handling by eliminating unwraps and adjust the bucket initialization to compute parameters internally.
- Updated documentation for ProvideAssetPrice to remove the obsolete usd_decimals parameter.
- Refactored bucket creation across modules to return BucketOf directly.
- Modified tests and instantiator functions to align with the new bucket API.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| polimec-common/common/src/lib.rs | Removed outdated usd_decimals doc comment to match updated API. |
| pallets/funding/src/types.rs | Updated Bucket::new usage to compute delta_amount and delta_price. |
| pallets/funding/src/tests/*.rs | Removed unwrap calls to adapt to the new bucket creation API. |
| pallets/funding/src/instantiator/calculations.rs | Adjusted bucket creation to remove error handling. |
| pallets/funding/src/functions/misc.rs | Changed create_bucket_from_metadata to return BucketOf directly. |
Comments suppressed due to low confidence (2)
polimec-common/common/src/lib.rs:387
- The documentation line for 'usd_decimals' has been removed to align with the updated function signature. Ensure all related documentation and code examples are updated accordingly.
/// * `usd_decimals`: The number of decimal places for the USD (or pricing) currency.
pallets/funding/src/functions/misc.rs:26
- [nitpick] The function 'create_bucket_from_metadata' now returns BucketOf directly, removing error handling. Confirm that this change is safe because the fixed point conversion used internally can never fail, otherwise consider reintroducing error management.
pub fn create_bucket_from_metadata(metadata: &ProjectMetadataOf<T>) -> BucketOf<T> {
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the price bucket logic in the pallets/funding module by simplifying the bucket creation functions and cleaning up redundant error handling. Key changes include:
- Eliminating the Result return type from create_bucket_from_metadata and removing unnecessary unwrap calls.
- Simplifying the Bucket::new constructor to internally compute a 10% delta_price and delta_amount.
- Minor documentation cleanup in polimec-common.
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| polimec-common/common/src/lib.rs | Removed an unused parameter from trait documentation. |
| pallets/funding/src/types.rs | Updated Bucket::new constructor to encapsulate 10% calculation logic. |
| pallets/funding/src/functions/misc.rs | Updated create_bucket_from_metadata to return BucketOf directly. |
| Various tests files in pallets/funding/src/tests/ and instantiator | Removed unwrap calls in bucket creation to match the new API. |
| pallets/funding/src/functions/1_application.rs and benchmarking.rs | Updated bucket creation call sites by removing .unwrap(). |
| pub fn new(amount_left: Balance, initial_price: Price) -> Self { | ||
| let ten_percent = Percent::from_percent(10); | ||
| let delta_amount = ten_percent * amount_left; | ||
| let ten_percent_fixed = Price::checked_from_rational(1, 10).expect("10% is a valid fixed point number"); |
Copilot
AI
May 16, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a comment explaining why the conversion using checked_from_rational with an expect call is guaranteed to succeed, to clarify that 10% is always representable.
9c7636a to
67b6aa1
Compare
625c74f to
a158df9
Compare
67b6aa1 to
a998aff
Compare
a158df9 to
d4d5667
Compare
a998aff to
0d7c547
Compare
0d7c547 to
992689e
Compare
d4d5667 to
2cb9446
Compare
992689e to
aa8e672
Compare
2dc95a6 to
0b832b8
Compare
aa8e672 to
7fcb836
Compare
7fcb836 to
33fe2fd
Compare
0b832b8 to
32ac644
Compare
33fe2fd to
4783aa9
Compare
32ac644 to
a6f07a5
Compare
4783aa9 to
33fe2fd
Compare
a6f07a5 to
32ac644
Compare
33fe2fd to
6daa42f
Compare
32ac644 to
003774e
Compare

This pull request simplifies the
create_bucket_from_metadatafunction and its usage across thepallets/fundingmodule by removing unnecessary error handling and making theBucket::newconstructor more concise. Additionally, it includes minor cleanup in related files.Simplification of
create_bucket_from_metadata:pallets/funding/src/functions/misc.rs: Removed theResultreturn type and unnecessary error handling in thecreate_bucket_from_metadatafunction. The function now directly returns aBucketOf<T>object.pallets/funding/src/types.rs: Simplified theBucket::newconstructor by removing redundant parameters and calculations, and moved the 10% calculation logic into the constructor.Updates to function calls:
create_bucket_from_metadataacross the module to remove.unwrap()since the function no longer returns aResult. This change affects:pallets/funding/src/benchmarking.rspallets/funding/src/functions/1_application.rspallets/funding/src/instantiator/calculations.rs[1] [2] [3]pallets/funding/src/tests/1_application.rspallets/funding/src/tests/3_auction.rspallets/funding/src/tests/misc.rs[1] [2]Code cleanup:
pallets/funding/src/types.rs: AddedPercentto the imports to support the updatedBucket::newimplementation.polimec-common/common/src/lib.rs: Removed an unused parameter (usd_decimals) from the documentation of theProvideAssetPricetrait.