-
Notifications
You must be signed in to change notification settings - Fork 44
feat(dpp): add marketplace rules to token configuration #2635
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
Conversation
WalkthroughA new marketplace rules subsystem for token configurations was introduced. This includes new modules, traits, data structures, and logic for handling marketplace trade modes and their change control rules. Existing token configuration methods were updated to support, validate, and authorize changes to these marketplace-related fields, with new enum variants and accessor traits added throughout. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant TokenConfig
participant MarketplaceRules
User->>TokenConfig: Propose configuration change (e.g., MarketplaceTradeMode)
TokenConfig->>MarketplaceRules: Access trade_mode_change_rules()
TokenConfig->>MarketplaceRules: Validate or apply change
MarketplaceRules-->>TokenConfig: Result (allowed/denied or updated)
TokenConfig-->>User: Respond with outcome
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (20)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
QuantumExplorer
left a comment
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.
Self reviewed
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.
Actionable comments posted: 1
🔭 Outside diff range comments (1)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs (1)
214-238:⚠️ Potential issueUpdate Display implementation to include marketplace_rules field.
The Display implementation is missing the newly added
marketplace_rulesfield, creating an inconsistency with the struct definition.Apply this diff to include the marketplace_rules field:
write!( f, - "TokenConfigurationV0 {{\n conventions: {:?},\n conventions_change_rules: {:?},\n base_supply: {},\n max_supply: {:?},\n keeps_history: {},\n start_as_paused: {},\n allow_transfer_to_frozen_balance: {},\n max_supply_change_rules: {:?},\n distribution_rules: {},\n manual_minting_rules: {:?},\n manual_burning_rules: {:?},\n freeze_rules: {:?},\n unfreeze_rules: {:?},\n destroy_frozen_funds_rules: {:?},\n emergency_action_rules: {:?},\n main_control_group: {:?},\n main_control_group_can_be_modified: {:?}\n}}", + "TokenConfigurationV0 {{\n conventions: {:?},\n conventions_change_rules: {:?},\n base_supply: {},\n max_supply: {:?},\n keeps_history: {},\n start_as_paused: {},\n allow_transfer_to_frozen_balance: {},\n max_supply_change_rules: {:?},\n distribution_rules: {},\n marketplace_rules: {},\n manual_minting_rules: {:?},\n manual_burning_rules: {:?},\n freeze_rules: {:?},\n unfreeze_rules: {:?},\n destroy_frozen_funds_rules: {:?},\n emergency_action_rules: {:?},\n main_control_group: {:?},\n main_control_group_can_be_modified: {:?}\n}}", self.conventions, self.conventions_change_rules, self.base_supply, self.max_supply, self.keeps_history, self.start_as_paused, self.allow_transfer_to_frozen_balance, self.max_supply_change_rules, self.distribution_rules, + self.marketplace_rules, self.manual_minting_rules, self.manual_burning_rules, self.freeze_rules, self.unfreeze_rules, self.destroy_frozen_funds_rules, self.emergency_action_rules, self.main_control_group, self.main_control_group_can_be_modified )
🧹 Nitpick comments (1)
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/v0/mod.rs (1)
14-17: Consider future extensibility for trade modes.The
TokenTradeModeenum currently only hasNotTradeablevariant. While this is appropriate for the initial implementation, consider documenting the design intention for future trade modes (e.g.,Tradeable,RestrictedTradeable, etc.) to help guide future development.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
packages/rs-dpp/src/data_contract/associated_token/mod.rs(1 hunks)packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/apply_token_configuration_item/v0/mod.rs(2 hunks)packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/authorized_action_takers_for_configuration_item/v0/mod.rs(2 hunks)packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/can_apply_token_configuration_item/v0/mod.rs(2 hunks)packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/validate_token_configuration_update/v0/mod.rs(2 hunks)packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs(5 hunks)packages/rs-dpp/src/data_contract/associated_token/token_configuration_item.rs(4 hunks)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/mod.rs(1 hunks)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/v0/mod.rs(1 hunks)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/mod.rs(1 hunks)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/v0/accessors.rs(1 hunks)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/v0/mod.rs(1 hunks)packages/rs-drive-abci/src/execution/platform_events/initialization/create_genesis_state/test/tokens.rs(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: QuantumExplorer
PR: dashpay/platform#2257
File: packages/rs-drive-abci/src/mimic/test_quorum.rs:159-164
Timestamp: 2024-11-20T16:16:01.830Z
Learning: QuantumExplorer prefers not to receive auto-generated messages asking to post on social media.
🧬 Code Graph Analysis (3)
packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/apply_token_configuration_item/v0/mod.rs (3)
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/mod.rs (1)
trade_mode(11-15)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/v0/mod.rs (1)
trade_mode(7-7)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/v0/accessors.rs (1)
trade_mode(11-13)
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/v0/mod.rs (2)
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/mod.rs (5)
trade_mode(11-15)trade_mode_change_rules(17-21)trade_mode_change_rules_mut(23-27)set_trade_mode(32-36)set_trade_mode_change_rules(38-42)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/v0/accessors.rs (5)
trade_mode(11-13)trade_mode_change_rules(15-17)trade_mode_change_rules_mut(19-21)set_trade_mode(26-28)set_trade_mode_change_rules(30-32)
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/mod.rs (2)
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/v0/mod.rs (5)
trade_mode(7-7)trade_mode_change_rules(10-10)trade_mode_change_rules_mut(13-13)set_trade_mode(19-19)set_trade_mode_change_rules(22-22)packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/v0/accessors.rs (5)
trade_mode(11-13)trade_mode_change_rules(15-17)trade_mode_change_rules_mut(19-21)set_trade_mode(26-28)set_trade_mode_change_rules(30-32)
⏰ Context from checks skipped due to timeout of 90000ms (20)
- GitHub Check: Rust packages (drive-abci) / Check each feature
- GitHub Check: Rust packages (drive-abci) / Tests
- GitHub Check: Rust packages (drive-abci) / Unused dependencies
- GitHub Check: Rust packages (drive-abci) / Formatting
- GitHub Check: Rust packages (dpp) / Check each feature
- GitHub Check: Rust packages (dpp) / Tests
- GitHub Check: Rust packages (drive) / Formatting
- GitHub Check: Rust packages (drive) / Linting
- GitHub Check: Rust packages (drive) / Tests
- GitHub Check: Rust packages (dpp) / Unused dependencies
- GitHub Check: Rust packages (dpp) / Linting
- GitHub Check: Rust packages (wasm-dpp) / Linting
- GitHub Check: Rust packages (wasm-dpp) / Tests
- GitHub Check: Rust packages (wasm-dpp) / Unused dependencies
- GitHub Check: Rust packages (wasm-dpp) / Formatting
- GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
- GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
- GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
- GitHub Check: Build JS packages / Build JS
- GitHub Check: Rust crates security audit
🔇 Additional comments (27)
packages/rs-dpp/src/data_contract/associated_token/mod.rs (1)
8-8: LGTM! Clean module addition.The addition of the
token_marketplace_rulesmodule follows the established pattern and correctly exposes the new marketplace functionality.packages/rs-drive-abci/src/execution/platform_events/initialization/create_genesis_state/test/tokens.rs (2)
12-12: LGTM! Proper import addition.The import for
TokenMarketplaceRulesV0is correctly added to support the new marketplace rules functionality in the test configuration.
265-269: LGTM! Consistent field initialization.The
marketplace_rulesfield is properly initialized with appropriate defaults:
- Default trade mode (likely non-tradeable based on the context)
- Default change control rules wrapped in
ChangeControlRulesV0This follows the same initialization pattern as other rule fields in the token configuration.
packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/apply_token_configuration_item/v0/mod.rs (2)
6-8: LGTM! Appropriate accessor imports.The imports for
TokenMarketplaceRulesV0GettersandTokenMarketplaceRulesV0Settersare correctly added to support the new marketplace rules functionality.
141-153: LGTM! Comprehensive marketplace rules handling.The three new match cases properly handle marketplace-related configuration changes:
MarketplaceTradeMode- Sets the trade mode using the setter methodMarketplaceTradeModeControlGroup- Updates the authorized action takers for trade mode changesMarketplaceTradeModeAdminGroup- Updates the admin action takers for trade mode changesThe implementation follows the established pattern used by other configuration items and correctly delegates to the appropriate accessor methods.
packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/authorized_action_takers_for_configuration_item/v0/mod.rs (2)
4-4: LGTM! Required accessor import.The import for
TokenMarketplaceRulesV0Gettersis correctly added to access marketplace rules for authorization checks.
109-120: LGTM! Correct authorization logic for marketplace rules.The three new match cases properly determine authorized action takers for marketplace configuration changes:
MarketplaceTradeMode- Returns the authorized action takers for trade mode changesMarketplaceTradeModeControlGroup&MarketplaceTradeModeAdminGroup- Both return admin action takers since these are control group modificationsThe implementation correctly delegates to
marketplace_rules.trade_mode_change_rules()and follows the established authorization pattern used throughout the codebase.packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/can_apply_token_configuration_item/v0/mod.rs (2)
4-4: LGTM: Clean import addition.The import for
TokenMarketplaceRulesV0Gettersis properly added and follows the existing import structure.
294-319: Excellent implementation following established patterns.The three new marketplace-related match arms consistently follow the same delegation pattern as existing configuration items:
- Permission checks are properly delegated to the marketplace rules' change control system
- All required parameters are correctly passed through
- The structure mirrors other similar variants (e.g., conventions, max_supply variants)
This consistency ensures maintainability and correctness of the authorization system.
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/v0/mod.rs (1)
1-24: Excellent trait design with clear separation of concerns.The trait definitions demonstrate good Rust practices:
- Clean separation between read (
TokenMarketplaceRulesV0Getters) and write operations (TokenMarketplaceRulesV0Setters)- Comprehensive documentation for all methods
- Consistent naming conventions
- Proper handling of mutable vs immutable access patterns
The inclusion of
trade_mode_change_rules_mut()alongside the immutable getter provides flexible access to the change control rules.packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/v0/accessors.rs (1)
1-34: Clean and straightforward trait implementations.The implementations are well-executed:
- Simple, direct field access for getters with appropriate reference types
- Clean setter implementations with direct assignment
- No unnecessary complexity or potential error sources
- Consistent with the trait definitions and follows expected patterns
The code is easy to understand and maintain.
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/mod.rs (1)
1-27: Excellent implementation following established versioning patterns.The
TokenMarketplaceRulesenum demonstrates good architectural practices:
- Versioning: Proper use of
#[serde(tag = "$format_version")]for future extensibility- Derives: Appropriate trait derivations for serialization, debugging, and comparison
- Display: Clean delegation to the inner
V0variant implementation- Module structure: Well-organized with separate
accessorsandv0submodulesThe implementation is consistent with other versioned enums in the codebase and sets up a solid foundation for future marketplace rule enhancements.
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/accessors/mod.rs (1)
1-43: LGTM! Clean accessor implementation following established patterns.The accessor implementation correctly follows the delegation pattern used throughout the codebase, where the enum wrapper delegates method calls to the inner versioned implementation. The code is well-structured with clear separation of getters and setters, and the pattern matching is exhaustive for the current V0 variant.
packages/rs-dpp/src/data_contract/associated_token/token_marketplace_rules/v0/mod.rs (2)
27-35: Excellent security-first default configuration.The
default_change_control_rulesfunction correctly initializes a very restrictive configuration where no one can make changes by default. This follows the principle of least privilege and ensures that marketplace rules can only be modified when explicitly configured with appropriate authorization.
37-48: Well-formatted Display implementation.The Display implementation provides clear, readable output with proper formatting and includes all relevant fields. The multi-line format makes it easy to read the marketplace rules configuration.
packages/rs-dpp/src/data_contract/associated_token/token_configuration_item.rs (4)
3-3: Correct import addition for marketplace functionality.The import of
TokenTradeModeis properly added to support the new marketplace-related enum variants.
63-66: Well-structured marketplace enum variants.The three new marketplace-related variants follow the established naming convention and pattern:
MarketplaceTradeModefor the trade mode valueMarketplaceTradeModeControlGroupfor control group authorizationMarketplaceTradeModeAdminGroupfor admin group authorizationThis maintains consistency with other configuration items in the enum.
99-102: Correct index assignment and reordering.The index assignment correctly assigns sequential indices (28, 29, 30) to the new marketplace variants and appropriately shifts
MainControlGroupto index 31. This maintains the sequential ordering while accommodating the new variants.
226-234: Consistent Display implementation for marketplace variants.The Display implementation for the new marketplace variants follows the same format and style as existing variants, using appropriate formatting for the contained data types.
packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/validate_token_configuration_update/v0/mod.rs (3)
5-5: Correct import addition for marketplace rules validation.The import of
TokenMarketplaceRulesV0Gettersis properly added to support validation of the new marketplace rules fields.
163-195: Proper validation logic for direct purchase pricing rules.The validation block correctly follows the established pattern for checking field changes and validating permissions using the
can_change_tomethod. The error message and field identification are appropriate.
199-226: Correct validation implementation for marketplace rules.The validation logic properly checks for changes to both the trade mode and its change rules, then validates permissions using the
can_change_tomethod. The error message correctly identifies the marketplace-related fields being validated.packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs (5)
10-13: LGTM! Clean import statements for marketplace rules.The imports follow the established patterns and properly bring in the necessary marketplace rules types.
77-79: LGTM! Well-documented and properly positioned field.The new
marketplace_rulesfield is appropriately placed, follows the same pattern as other rule fields, and includes clear documentation explaining its purpose.
181-192: LGTM! Sensible default implementation for marketplace rules.The default function correctly initializes marketplace rules with:
NotTradeablemode (safe default)- Restrictive change control rules (
NoOnecan make changes)- Consistent pattern with other default rule functions
This provides a secure default configuration that prevents trading until explicitly enabled.
438-443: LGTM! Consistent preset implementation.The
default_marketplace_rules_v0()method properly follows the preset pattern by usingdefault_basic_change_control_rules_v0()for consistency with other preset configurations while maintaining the safeNotTradeabledefault.
468-468: LGTM! Proper integration of marketplace rules.The marketplace rules are correctly integrated into the token configuration creation process using the preset's default marketplace rules method.
Issue being fixed or feature implemented
Added marketplace rules to the token configuration, allowing for the management of trade modes and associated control rules. This is to better future proof the system so people can register tokens now that can later have a marketplace.
What was done?
TokenMarketplaceRulesandTokenMarketplaceRulesV0structures.TokenConfigurationChangeItemto include new items for marketplace trade mode and control groups.TokenConfigurationV0to handle the new marketplace rules.How Has This Been Tested?
New unit tests were added to ensure the functionality of marketplace rules and their integration with existing token configuration logic.
Breaking Changes
None
Checklist
For repository code-owners and collaborators only
Summary by CodeRabbit
New Features
Bug Fixes