Skip to content

feat(sdk): token claim state transition#2522

Merged
shumkov merged 4 commits into
v2.0-devfrom
feat/sdk/claim-transition
Apr 1, 2025
Merged

feat(sdk): token claim state transition#2522
shumkov merged 4 commits into
v2.0-devfrom
feat/sdk/claim-transition

Conversation

@shumkov
Copy link
Copy Markdown
Collaborator

@shumkov shumkov commented Apr 1, 2025

Issue being fixed or feature implemented

We would like to broadcast the token claim transition using SDK.

What was done?

  • Introduced a state transition builder
  • Fixed some bugs in proof verification

How Has This Been Tested?

With DET against local network

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

  • Bug Fixes

    • Enhanced error messaging for token claims to provide clearer feedback.
    • Adjusted token distribution handling to ensure recipient identities are represented more accurately.
    • Updated token transition verification to flexibly manage various token actions.
  • New Features

    • Introduced a builder for token claim transitions, enabling more configurable and secure claim processing.
    • Added a new module for managing token claim transitions within the SDK.
  • Chores

    • Refined the token history contract schema to restrict valid values and improve clarity.
    • Updated dependency versions for improved functionality and performance.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 1, 2025

Walkthrough

The pull request makes changes across several packages. In the tokens consensus module, the error message for an invalid token claim has been rewritten and the parameter order adjusted. In a token transition, recipient resolution was modified from a contract owner identity to a general identity representation. Additionally, documentation was refined in a token transition action, and state transition verification was enhanced by dynamically setting ignored fields. A new token claim transition builder and accompanying module were introduced in the SDK, while the token history contract JSON schema was updated to enforce specific enumerated values.

Changes

File(s) Change Summary
packages/rs-dpp/src/errors/consensus/state/token/invalid_token_claim_wrong_claimant.rs Rewrites error message for InvalidTokenClaimWrongClaimant with updated parameter order (claimant_id, token_id, expected_claimant_id).
packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs Alters recipient resolution: now resolves TokenDistributionRecipient::Identity to TokenDistributionResolvedRecipient::Identity instead of ContractOwnerIdentity.
packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs Updates documentation comment for build_historical_document from "Historical document id" to "Historical document".
packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs Introduces dynamic setting of ignore_fields based on token transition type (e.g., "destroyedAmount" for DestroyFrozenFunds and "amount" for Claim) for comparing documents.
packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs Adds new TokenClaimTransitionBuilder with methods (new, with_public_note, with_user_fee_increase, with_settings, and async sign) to construct and sign token claim transitions.
packages/rs-sdk/src/platform/transition/fungible_tokens/mod.rs Adds new claim module, integrating token claim functionality into fungible tokens.
packages/token-history-contract/schema/v1/token-history-contract-documents.json Updates JSON schema: changes distributionType from a minimum constraint to an enum [0, 1], and refines action property enumeration with updated description.
.pnp.cjs Adds multiple new npm packages to RAW_RUNTIME_STATE and updates dockerode version from 3.3.5 to 4.0.5.
packages/dashmate/package.json Updates dockerode dependency version from ^3.3.5 to ^4.0.5.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Builder as TokenClaimTransitionBuilder
    participant NonceSvc as IdentityNonceRetriever
    participant TransitionCreator as BatchTransitionCreator

    User->>Builder: Initialize builder with parameters
    User->>Builder: Configure via with_public_note/with_user_fee_increase/with_settings
    User->>Builder: Call sign()
    Builder->>NonceSvc: Retrieve identity contract nonce
    Builder->>TransitionCreator: Compute token ID and create BatchTransition
    TransitionCreator-->>Builder: Return StateTransition
    Builder-->>User: Return signed StateTransition
Loading
sequenceDiagram
    participant Verifier as verify_state_transition_was_executed_with_proof_v0
    participant Transition as TokenTransition
    participant Document as Document

    Verifier->>Transition: Check token transition type
    alt DestroyFrozenFunds
        Transition-->>Verifier: Set ignore_fields = ["destroyedAmount"]
    else Claim
        Transition-->>Verifier: Set ignore_fields = ["amount"]
    else Other
        Transition-->>Verifier: Set ignore_fields = None
    end
    Verifier->>Document: Compare with is_equal_ignoring_time_based_fields(ignore_fields)
    Document-->>Verifier: Return comparison result
Loading

Suggested reviewers

  • QuantumExplorer
  • pauldelucia

Poem

I'm a little rabbit, hopping through the code,
Fresh changes bloom along the winding road.
Errors fixed and paths now clear,
Transitions signed with a hop of cheer.
In this garden of code, I nibble bugs away!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 plan to trigger planning for file edits and PR creation.
  • @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.

@shumkov shumkov self-assigned this Apr 1, 2025
@shumkov shumkov moved this to In Progress in Platform team Apr 1, 2025
pauldelucia
pauldelucia previously approved these changes Apr 1, 2025
@shumkov shumkov marked this pull request as ready for review April 1, 2025 10:16
@shumkov shumkov requested a review from QuantumExplorer as a code owner April 1, 2025 10:16
Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (3)
packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs (1)

142-142: Fixed documentation comment for build_historical_document method.

The comment is now more accurate, correctly reflecting that the method builds a complete historical document rather than just an ID.

packages/rs-dpp/src/errors/consensus/state/token/invalid_token_claim_wrong_claimant.rs (1)

13-16: Fix the minor spelling issue in the error message.

The updated error message incorrectly spells "claimant" as "claimaint".

Apply the following diff to correct the spelling:

- "Token claim error: Identity '{}' is not a valid claimant for this distribution type of token '{}'. The valid claimaint is '{}'."
+ "Token claim error: Identity '{}' is not a valid claimant for this distribution type of token '{}'. The valid claimant is '{}'."
packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs (1)

40-57: Address the TODO comment for validating token position.

Currently, the constructor includes a TODO indicating that token position validation is needed. Implementing this validation can help detect invalid positions at an early stage.

If you need help implementing the validation logic, I can provide a reference or open a new issue to track this task.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between d25e226 and 500381c.

📒 Files selected for processing (7)
  • packages/rs-dpp/src/errors/consensus/state/token/invalid_token_claim_wrong_claimant.rs (1 hunks)
  • packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs (1 hunks)
  • packages/rs-drive/src/state_transition_action/batch/batched_transition/token_transition/mod.rs (1 hunks)
  • packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs (1 hunks)
  • packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs (1 hunks)
  • packages/rs-sdk/src/platform/transition/fungible_tokens/mod.rs (1 hunks)
  • packages/token-history-contract/schema/v1/token-history-contract-documents.json (3 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs (2)
packages/rs-dpp/src/errors/consensus/state/token/invalid_token_claim_wrong_claimant.rs (3)
  • new (27-37)
  • token_id (40-42)
  • from (57-59)
packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs (4)
  • token_id (182-182)
  • token_id (285-287)
  • identity_contract_nonce (188-188)
  • identity_contract_nonce (293-295)
⏰ Context from checks skipped due to timeout of 90000ms (19)
  • GitHub Check: Rust packages (dpp) / Formatting
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Linting
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (drive-abci) / Tests
  • GitHub Check: Rust packages (drive-abci) / Check each feature
  • GitHub Check: Rust packages (drive-abci) / Linting
  • GitHub Check: Rust packages (drive) / Tests
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build Docker images (Drive, drive, drive-abci) / Build Drive image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (8)
packages/rs-sdk/src/platform/transition/fungible_tokens/mod.rs (1)

4-4: LGTM: New claim module added correctly.

The addition of the claim module follows the alphabetical ordering pattern of the other modules in this file, and aligns with the PR objective of enabling token claim transition functionality in the SDK.

packages/rs-dpp/src/state_transition/state_transitions/document/batch_transition/batched_transition/token_transition.rs (1)

425-425: Updated recipient resolution to use Identity type instead of ContractOwnerIdentity.

This change properly alters how token distribution recipients of type Identity are resolved in the claim transition, switching from a specific contract owner context to a more generalized identity representation.

packages/rs-drive/src/verify/state_transition/verify_state_transition_was_executed_with_proof/v0/mod.rs (1)

359-372: Improved verification with dynamic field exclusion based on token transition type.

The modification correctly handles different token transition types by dynamically determining which fields to ignore during document verification. Now both TokenTransition::DestroyFrozenFunds and TokenTransition::Claim have specific fields ignored that are populated by the drive system.

packages/token-history-contract/schema/v1/token-history-contract-documents.json (2)

596-599: Enumerating distributionType ensures clarity and correctness.

The introduction of an enum helps strongly validate the distribution type in claims, preventing invalid values.


680-680: Documentation update looks good.

Changing the description to "The action we are performing (0: Pause, 1: Resume)" provides clarity on the possible values.

packages/rs-sdk/src/platform/transition/fungible_tokens/claim.rs (3)

16-25: Builder pattern for token claim transitions is well-structured.

The builder struct neatly encapsulates the parameters required for a token claim transition, promoting code clarity and maintainability.


59-99: Chained configuration methods are concise and intuitive.

The with_public_note, with_user_fee_increase, and with_settings methods effectively follow the builder pattern, allowing for flexible incremental configuration of the transition.


101-152: The sign method ensures robust error handling and clarity.

Invoking sdk.get_identity_contract_nonce within this async method is appropriate, and returning a Result fosters safe usage. This design aligns well with the rest of the SDK's error handling conventions.

Copy link
Copy Markdown
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: 0

🧹 Nitpick comments (2)
packages/dashmate/package.json (1)

74-74: Update dockerode dependency to ^4.0.5

The dependency update to dockerode from version ^3.3.5 to ^4.0.5 is a major version bump. Please ensure that all usages of dockerode in the codebase align with the new API and that any potential breaking changes are addressed. It would be useful to review the dockerode changelog and verify that integration tests cover all relevant functionality for this dependency.

.pnp.cjs (1)

13456-13463: Long package version update review.
There is an update involving the long package where a new entry for version 5.3.1 is specified alongside an earlier version (5.2.0). Please check if both versions are required by different dependencies or if deduplication is possible.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 500381c and ac23b23.

⛔ Files ignored due to path filters (11)
  • .yarn/cache/@grpc-grpc-js-npm-1.13.2-2010829daa-80b7bebc1d.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/@grpc-proto-loader-npm-0.7.13-be5b6af1c1-7e2d842c20.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/@js-sdsl-ordered-map-npm-4.4.2-158f6c6b74-ac64e3f061.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/docker-modem-npm-5.0.6-ba160bac18-4977797814.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/dockerode-npm-4.0.5-291e46ef8d-a300e5fdcf.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/long-npm-5.3.1-c44e0933f0-7713e10b4f.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/nan-npm-2.22.2-bb092bb459-bee49de633.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/ssh2-npm-1.16.0-bee6b5f04c-0951c22d9c.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/tar-fs-npm-2.1.2-4231292dd1-623f7e8e58.zip is excluded by !**/.yarn/**, !**/*.zip
  • .yarn/cache/uuid-npm-10.0.0-4872b46ff8-35aa606148.zip is excluded by !**/.yarn/**, !**/*.zip
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • .pnp.cjs (11 hunks)
  • packages/dashmate/package.json (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (13)
  • GitHub Check: Rust packages (drive) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Linting
  • GitHub Check: Rust packages (wasm-dpp) / Unused dependencies
  • GitHub Check: Rust packages (wasm-dpp) / Tests
  • GitHub Check: Rust packages (token-history-contract) / Unused dependencies
  • GitHub Check: Rust packages (token-history-contract) / Linting
  • GitHub Check: Rust packages (dpp) / Tests
  • GitHub Check: Rust packages (dpp) / Linting
  • GitHub Check: Rust packages (dpp) / Unused dependencies
  • GitHub Check: Rust packages (dpp) / Check each feature
  • GitHub Check: Build Docker images (Dashmate helper, dashmate-helper, dashmate-helper) / Build Dashmate helper image
  • GitHub Check: Build Docker images (DAPI, dapi, dapi) / Build DAPI image
  • GitHub Check: Build JS packages / Build JS
🔇 Additional comments (10)
.pnp.cjs (10)

3159-3168: @grpc/grpc-js entry added correctly.
This new entry for @grpc/grpc-js (version 1.13.2) is set up with the appropriate package location and dependencies (including @grpc/proto-loader and @js-sdsl/ordered-map). The structure looks consistent with Yarn Plug'n'Play metadata.


3200-3211: Updated @grpc/proto-loader dependency block.
A new block for @grpc/proto-loader (version 0.7.13) is introduced with its package location and a complete dependency list. Notably, the version for yargs used here is 17.7.2 (instead of an earlier version), so please ensure that this upgrade is compatible with the consumers of this package.


3470-3478: @js-sdsl/ordered-map entry added.
The new entry for @js-sdsl/ordered-map with version 4.4.2 is added with the correct package location, dependency specification, and linkType set to HARD. This matches the project’s dependency configuration style.


8509-8512: Dockerode version update detected.
The dependency for dockerode has been updated to version 4.0.5 in this block. This aligns with the corresponding update in other configuration files (for example, in packages/dashmate/package.json). Verify that all consumers of dockerode are compatible with the new version.


9070-9081: New docker-modem entry introduced.
A new block for docker-modem version 5.0.6 is added with its package location and an updated dependency list – notably, it now depends on ssh2 version 1.16.0. The structure is proper; however, please double-check the dependency tree to ensure no conflicts arise with other packages.


9093-9107: New dockerode package block with expanded dependencies.
This block for dockerode (version 4.0.5) now clearly lists all required dependencies such as @balena/dockerignore, the gRPC packages, docker-modem, protobufjs, tar-fs, and uuid. The configuration is comprehensive and appears correct. Consider verifying that multiple entries for dockerode (if present) are intentional.


14392-14400: New nan package entry added.
The configuration now includes a new entry for nan at version 2.22.2, complete with its package location and dependency on node-gyp version 10.0.1. This aligns with the updated requirements, and the format is correct.


17727-17738: ssh2 dependency updated with nan update.
The block for ssh2 now references nan at version 2.22.2 (updating what was previously 2.17.0), and it correctly lists its other dependencies (including asn1, bcrypt-pbkdf, and a URL-based dependency for cpu-features). Please confirm that the dependency URL for cpu-features is intentional and supported.


18168-18179: Updated tar-fs entry with complete dependency list.
The tar-fs block is updated to version 2.1.2 and now clearly includes its dependencies – such as tar-stream version 2.2.0, chownr, mkdirp-classic, and pump. The structured format adheres to Yarn Plug'n'Play specifications.


19483-19489: New uuid entry for version 10.0.0 added.
A new block for uuid (version 10.0.0) is added with its package location and dependency details, while an existing entry for version 3.4.0 remains in the configuration. Please verify if both versions are necessary or if consolidation is possible to avoid potential version conflicts.

@shumkov shumkov merged commit d17b1eb into v2.0-dev Apr 1, 2025
139 of 141 checks passed
@shumkov shumkov deleted the feat/sdk/claim-transition branch April 1, 2025 12:26
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Platform team Apr 1, 2025
@thephez thephez added the rs-sdk label Apr 8, 2025
@thephez thephez added this to the v2.0.0 milestone Apr 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants