Skip to content

feat(sdk): token purchase and set price transitions #2613

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

Merged
merged 1 commit into from
May 17, 2025

Conversation

pauldelucia
Copy link
Member

@pauldelucia pauldelucia commented May 15, 2025

Issue being fixed or feature implemented

Add the token purchase and set price transitions to the sdk

What was done?

How Has This Been Tested?

Not yet

Breaking Changes

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
    • Added the ability to build and sign token purchase state transitions.
    • Introduced functionality to set or change the direct purchase price of fungible tokens, including support for optional parameters such as fee adjustments and public notes.

Copy link
Contributor

coderabbitai bot commented May 15, 2025

Walkthrough

Two new modules, purchase and set_price, have been added to the fungible tokens state transitions in the SDK. These modules introduce builder structs for constructing and signing state transitions related to direct token purchases and changing token purchase prices, each with fluent configuration methods and asynchronous signing functionality.

Changes

File(s) Change Summary
.../fungible_tokens/mod.rs Added public exports for new modules: purchase and set_price.
.../fungible_tokens/purchase.rs Introduced TokenDirectPurchaseTransitionBuilder struct with methods for configuring and signing token purchase transitions.
.../fungible_tokens/set_price.rs Introduced TokenChangeDirectPurchasePriceTransitionBuilder struct with methods for configuring and signing token price change transitions.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Builder (Purchase/SetPrice)
    participant SDK
    participant Signer

    Caller->>Builder (Purchase/SetPrice): new(...).with_...(optional).sign(...)
    Builder->>SDK: get_identity_contract_nonce(...)
    SDK-->>Builder: nonce
    Builder->>Signer: sign(transition_data)
    Signer-->>Builder: signature
    Builder-->>Caller: StateTransition (signed)
Loading

Poem

In the warren of code, two tunnels appear,
One for buying tokens, one for setting price clear.
Builders now hop, with options in tow,
Signing transitions as onward they go.
With every new module, the SDK grows bright—
A rabbit’s delight in the springtime light!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need 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)

  • @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 generate sequence diagram to generate a sequence diagram of the changes in 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: 3

🧹 Nitpick comments (4)
packages/rs-sdk/src/platform/transition/fungible_tokens/mod.rs (1)

10-11: Consider keeping pub mod declarations alphabetically ordered
For long‐lived modules, keeping the list alphabetised (burn, claim, …, transfer, unfreeze) makes merge-conflicts easier to resolve and helps readers spot missing modules quickly.

packages/rs-sdk/src/platform/transition/fungible_tokens/purchase.rs (1)

34-48: Doc-comment parameters are out of sync with the function signature
issuer_id is mentioned, but the argument is named actor_id.
total_agreed_price is accepted by the function but not documented.
Keeping the docs accurate prevents misuse by downstream developers.

packages/rs-sdk/src/platform/transition/fungible_tokens/set_price.rs (2)

35-39: Stale documentation
The doc-comment still references amount even though this builder changes price, not quantity, and mentions issuer_id instead of actor_id.
Synchronise the docs with the code to avoid developer confusion.


100-106: Group-action auto-selection left as TODO
If group information is mandatory for certain schedules, forgetting to fill this value will create runtime errors difficult to trace.
Either implement the lookup here or fail fast with a descriptive error until the feature is complete.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 7cfe69d and 782f196.

📒 Files selected for processing (3)
  • packages/rs-sdk/src/platform/transition/fungible_tokens/mod.rs (1 hunks)
  • packages/rs-sdk/src/platform/transition/fungible_tokens/purchase.rs (1 hunks)
  • packages/rs-sdk/src/platform/transition/fungible_tokens/set_price.rs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Rust packages (dash-sdk) / Unused dependencies
  • GitHub Check: Rust packages (dash-sdk) / Tests
  • GitHub Check: Rust packages (dash-sdk) / Check each feature
  • GitHub Check: Rust packages (dash-sdk) / 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 JS packages / Build JS
🔇 Additional comments (2)
packages/rs-sdk/src/platform/transition/fungible_tokens/purchase.rs (1)

49-50: TODO left for production-critical validation
Validating token_position against the contract layout is essential to prevent malformed or malicious transitions.
Please either implement the check now or create a tracked issue so it does not get forgotten.

packages/rs-sdk/src/platform/transition/fungible_tokens/set_price.rs (1)

49-50: Validation of token_position is still TODO
As with the purchase builder, the absence of this check can let invalid transitions through.

Comment on lines +110 to +114
let token_id = Identifier::from(calculate_token_id(
self.data_contract.id().as_bytes(),
self.token_position,
));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

No check that token_id actually belongs to data_contract
Although calculate_token_id(...) is called, we don’t ensure the resulting token_id is present in the contract’s token definitions. An invalid position would silently create an incoherent transition.
Consider validating:

if self.token_position >= self.data_contract.tokens().len() {
    return Err(Error::InvalidTokenPosition(self.token_position));
}
🤖 Prompt for AI Agents
In packages/rs-sdk/src/platform/transition/fungible_tokens/purchase.rs around
lines 110 to 114, the code calculates a token_id from a token_position without
verifying that the position is valid within the data_contract's tokens. To fix
this, add a check before calculating token_id to ensure self.token_position is
less than the length of self.data_contract.tokens(). If the position is invalid,
return an appropriate error such as Error::InvalidTokenPosition with the invalid
position value.

@QuantumExplorer QuantumExplorer merged commit e334672 into v2.0-dev May 17, 2025
43 of 45 checks passed
@QuantumExplorer QuantumExplorer deleted the feat/token-pricing-sdk branch May 17, 2025 14:56
@thephez thephez added this to the v2.0.0 milestone May 19, 2025
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.

4 participants