Skip to content

Conversation

@QuantumExplorer
Copy link
Member

@QuantumExplorer QuantumExplorer commented Apr 21, 2025

Issue being fixed or feature implemented

We added token config presets to make selecting a token configuration easier.

How Has This Been Tested?

Not consensus code. Only presets.

Breaking Changes

None

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

Summary by CodeRabbit

  • New Features

    • Introduced customizable token configuration presets, allowing flexible permission and rule sets based on feature levels.
    • Added a method to create uniform history-keeping rules for tokens with a single setting.
  • Refactor

    • Centralized and modularized default token configuration logic, replacing hardcoded defaults with a preset-based system.
    • Optimized internal handling of authorized action takers to use value copying instead of cloning for efficiency.

@QuantumExplorer QuantumExplorer added this to the v2.0.0 milestone Apr 21, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 21, 2025

Walkthrough

This update introduces a new preset-based system for constructing default token configurations in the codebase. It adds an enum to categorize feature sets, a struct to encapsulate preset features and authorized action takers, and several methods to generate change control and distribution rules according to these presets. The logic for creating default token configurations is centralized and modularized, replacing previous hardcoded defaults. Additionally, a utility method is added to uniformly set history-keeping rules, and the AuthorizedActionTakers enum is updated to be Copy as well as Clone. Minor refactors replace cloning with copying for AuthorizedActionTakers in several places.

Changes

File(s) Change Summary
.../token_configuration/v0/mod.rs Refactored token configuration defaults by introducing TokenConfigurationPresetFeatures enum and TokenConfigurationPreset struct, with methods to generate change control and distribution rules based on presets; replaced previous hardcoded defaults with this modular system.
.../token_keeps_history_rules/v0/mod.rs Added method to create TokenKeepsHistoryRulesV0 instances with all fields set to a specified boolean value.
.../change_control_rules/authorized_action_takers.rs Updated AuthorizedActionTakers enum to derive Copy in addition to Clone.
.../token_configuration/methods/authorized_action_takers_for_configuration_item/v0/mod.rs Replaced cloning of AuthorizedActionTakers with copying via dereferencing in method returning authorized action takers for configuration items.
.../state_transitions/batch/action_validation/token/token_base_transition_action/state_v0/mod.rs Replaced cloning of AuthorizedActionTakers with copying via dereferencing in validation error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant TokenConfigurationPreset
    participant TokenConfigurationV0

    Caller->>TokenConfigurationPreset: create with features and action_taker
    Caller->>TokenConfigurationPreset: token_configuration_v0(params)
    TokenConfigurationPreset->>TokenConfigurationPreset: generate change control rules
    TokenConfigurationPreset->>TokenConfigurationPreset: generate distribution rules
    TokenConfigurationPreset->>TokenConfigurationV0: construct TokenConfigurationV0 with rules and params
    TokenConfigurationV0-->>Caller: return configured instance
Loading

Possibly related PRs

Suggested reviewers

  • shumkov

Poem

In the warren of code, a new preset appears,
With features and rules for all token frontiers.
History kept tidy, permissions precise,
Modular rabbits make config so nice!
Copy and clone, the enum now hops—
This bunny’s refactor just never stops! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 62aded7 and c1a628b.

📒 Files selected for processing (2)
  • packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/authorized_action_takers_for_configuration_item/v0/mod.rs (1 hunks)
  • packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_base_transition_action/state_v0/mod.rs (4 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.
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: Rust packages (dash-sdk) / Detect immutable structure changes
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (drive) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive-abci) / Unused dependencies
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Formatting
  • 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 Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (12)
packages/rs-drive-abci/src/execution/validation/state_transition/state_transitions/batch/action_validation/token/token_base_transition_action/state_v0/mod.rs (4)

114-114: Efficient optimization: using Copy instead of Clone

Good change! Replacing clone() with dereferencing (*) is more efficient since AuthorizedActionTakers now implements the Copy trait. This avoids unnecessary heap allocations.


133-133: Consistent use of Copy trait

Correctly replaced clone() with dereferencing (*) for AuthorizedActionTakers here as well, maintaining consistency throughout the codebase.


149-150: Appropriate use of Copy semantics

Good change - using Copy semantics for AuthorizedActionTakers makes the code more efficient in error reporting scenarios.


169-170: Improved memory efficiency

Well done implementing the final instance of dereferencing instead of cloning for AuthorizedActionTakers in this method. This completes the pattern consistently.

packages/rs-dpp/src/data_contract/associated_token/token_configuration/methods/authorized_action_takers_for_configuration_item/v0/mod.rs (8)

21-24: Effective optimization using Copy trait

Good change replacing clone() with dereferencing for AuthorizedActionTakers. This is more memory efficient and cleaner code.


25-29: Consistent optimization for control and admin groups

Well implemented change across both control group and admin group cases, maintaining the same optimization pattern.


30-38: Memory optimization for MaxSupply related actions

Good application of the Copy trait for MaxSupply configuration items and their related control/admin groups. The consistent pattern improves code readability.


39-51: Distribution rules optimization

Effective update for PerpetualDistribution configuration items and their related control/admin groups. Using dereferencing instead of cloning maintains the optimization pattern correctly.


52-74: Token destination and minting rules optimization

All token destination and minting rules are consistently updated to use Copy semantics through dereferencing, which is more efficient than cloning.


76-86: Manual operations rules optimization

Good job updating manual minting and burning rules to use dereferencing instead of cloning, consistent with the pattern applied throughout.


87-94: Freeze/unfreeze operations optimization

Effectively updated freeze and unfreeze operations to leverage Copy semantics through dereferencing, maintaining code optimization consistency.


95-106: Special operations optimization

Well implemented optimization for destroy frozen funds and emergency actions, completing the consistent application of the Copy trait usage throughout all token configuration operations.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

🧹 Nitpick comments (3)
packages/rs-dpp/src/data_contract/associated_token/token_keeps_history_rules/v0/mod.rs (1)

38-49: default_for_keeping_all_history – consider const fn + clearer naming

The helper is useful, but:

  1. The word default is misleading because the caller supplies the value. Something like uniform(keeps_all_history: bool) (or new_all(…)) expresses intent better.
  2. Marking it const fn allows compile‑time evaluation in most call‑sites:
-impl TokenKeepsHistoryRulesV0 {
-    pub fn default_for_keeping_all_history(keeps_all_history: bool) -> TokenKeepsHistoryRulesV0 {
+impl TokenKeepsHistoryRulesV0 {
+    pub const fn uniform(keeps_all_history: bool) -> Self {

No behaviour changes, but readability and usability improve.

packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs (2)

329-364: token_configuration_v0 hard‑codes allow_transfer_to_frozen_balance = true

Free transfers into frozen accounts can be a security/UX decision that callers may want to opt out of.
Adding a boolean parameter (mirroring with_direct_pricing) or exposing a .with_allow_transfer_to_frozen_balance(bool) builder would make the preset system more flexible.


369-383: Magic numbers & decimals in default_most_restrictive

base_supply is hard‑coded to 100_000 and decimals to 8. These magic numbers may surprise library users expecting a “blank” preset.

Propose exposing them as constants or parameters:

pub fn default_most_restrictive(
    base_supply: TokenAmount,
    decimals: u8,
) -> Self {}

Keeps the convenience while avoiding silent assumptions.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 83a660f and 62aded7.

📒 Files selected for processing (3)
  • packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs (3 hunks)
  • packages/rs-dpp/src/data_contract/associated_token/token_keeps_history_rules/v0/mod.rs (1 hunks)
  • packages/rs-dpp/src/data_contract/change_control_rules/authorized_action_takers.rs (1 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.
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive-abci) / Formatting
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • 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 JS packages / Build JS
🔇 Additional comments (3)
packages/rs-dpp/src/data_contract/change_control_rules/authorized_action_takers.rs (1)

11-13: Copy derive could fail to compile and/or change semantics

Adding Copy requires that every payload type in every variant (Identifier, GroupContractPosition) also implements Copy.
Please double‑check that these types already derive/implement Copy; otherwise the crate will fail to compile.
Even if compilation succeeds, turning a formerly Clone‑only enum into Copy means the compiler will silently duplicate values instead of moving them, which can mask logic bugs when mutability is later introduced.

If any inner type is not trivially copyable or you want to enforce move semantics, drop the Copy derive:

-#[derive(Serialize, Deserialize, Decode, Encode, Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Default)]
+#[derive(Serialize, Deserialize, Decode, Encode, Debug, Clone, PartialEq, Eq, PartialOrd, Default)]

Would you run cargo check --workspace to ensure the new derive compiles across all dependent crates?

packages/rs-dpp/src/data_contract/associated_token/token_configuration/v0/mod.rs (2)

178-196: Visibility of TokenConfigurationPreset{Features,} is pub but inner fields are private

TokenConfigurationPresetFeatures is pub and the struct TokenConfigurationPreset itself is pub, yet its fields are private.
Because consumers cannot construct the struct manually, you should either:

  • Expose a constructor (builder/static new()), or
  • Make the fields pub(crate) / pub to avoid frustration.

Right now the only entry‑point is the preset methods implemented further below; confirm this matches the intended API surface.


296-327: with_direct_pricing gate only affects change rules – typo or missing logic?

When with_direct_pricing == false you still set:

minting_allow_choosing_destination: true,

and leave perpetual_distribution & pre_programmed_distribution untouched.
Is it intentional that the token can not be directly priced yet the destination for newly minted tokens can still be chosen freely?

If direct pricing is disabled, consider also setting minting_allow_choosing_destination to false or document why the two concepts are orthogonal.

@QuantumExplorer QuantumExplorer merged commit 69832bc into v2.0-dev Apr 21, 2025
65 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/TokenConfigPresets branch April 21, 2025 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants