Skip to content

feat: change token version enum to string in the rpc request#145

Merged
raul-oliveira merged 2 commits intomasterfrom
feat/change-token-version-to-string
Mar 9, 2026
Merged

feat: change token version enum to string in the rpc request#145
raul-oliveira merged 2 commits intomasterfrom
feat/change-token-version-to-string

Conversation

@raul-oliveira
Copy link
Copy Markdown
Contributor

@raul-oliveira raul-oliveira commented Mar 9, 2026

Motivation

To improve developer experience integrating with rpc-lib it was decided to change from interger enums to string describing the token type

Acceptance Criteria

  • create token and createNanoContractCreateTokenTransaction request should accept deposit and fee as available token types

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged
  • Make sure either the unit tests and/or the QA tests are capable of testing the new features
  • Make sure you do not include new dependencies in the project unless strictly necessary and do not include dev-dependencies as production ones. More dependencies increase the possibility of one of them being hijacked and affecting us.

Summary by CodeRabbit

  • Refactor

    • Token version input changed to string identifiers ("deposit", "fee") and now defaults to "deposit" when omitted.
    • Validation added to reject invalid token-version inputs.
  • New Features

    • Token-creation flow now supports a deposit path: deposit is calculated, displayed in confirmation, and passed through creation.
    • Create-token parameters may include an optional deposit value.
  • Tests

    • Coverage expanded to assert defaulting, explicit versions, and invalid inputs.

@raul-oliveira raul-oliveira force-pushed the feat/change-token-version-to-string branch from a36c5ed to c8a510c Compare March 9, 2026 18:54
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: de76517c-8810-4cb7-ab3a-29187674c446

📥 Commits

Reviewing files that changed from the base of the PR and between c8a510c and 2f839ec.

📒 Files selected for processing (3)
  • packages/hathor-rpc-handler/__tests__/rpcMethods/createToken.test.ts
  • packages/hathor-rpc-handler/src/rpcMethods/createToken.ts
  • packages/hathor-rpc-handler/src/types/prompt.ts

📝 Walkthrough

Walkthrough

Introduces a string-based TokenVersionString enum and Zod schema for RPC inputs, defaults version to DEPOSIT, updates schemas/types to use the string representation, extends createToken flow to compute/send deposit for DEPOSIT tokens, and updates tests to the new representation and behaviors.

Changes

Cohort / File(s) Summary
Token Version Schema
packages/hathor-rpc-handler/src/schemas/tokenVersionSchema.ts, packages/hathor-rpc-handler/src/schemas/index.ts
Add TokenVersionString enum and tokenVersionStringSchema that defaults to DEPOSIT and maps to internal TokenVersion. Exported from schemas index.
Schema Definitions
packages/hathor-rpc-handler/src/schemas/createTokenSchema.ts
Replace z.nativeEnum(TokenVersion) usage with tokenVersionStringSchema for createToken base and RPC schemas.
Type Definitions
packages/hathor-rpc-handler/src/types/rpcRequest.ts, packages/hathor-rpc-handler/src/types/index.ts, packages/hathor-rpc-handler/src/types/prompt.ts
Change CreateTokenRpcRequest.params.version to TokenVersionString; export TokenVersionString; add optional deposit?: bigint to CreateTokenParams.
RPC Logic
packages/hathor-rpc-handler/src/rpcMethods/createToken.ts
Add DEPOSIT branch: compute deposit via tokensUtils.getDepositAmount, include deposit in confirmation prompt, propagate deposit into token creation flow.
Tests
packages/hathor-rpc-handler/__tests__/rpcMethods/createToken.test.ts, packages/hathor-rpc-handler/__tests__/rpcMethods/createNanoContractCreateTokenTx.test.ts
Update imports/expectations to use TokenVersionString; add tests for defaulting to DEPOSIT, explicit DEPOSIT/FEE paths, and invalid version inputs; adjust assertions to include tokenVersion/deposit.
Exports
packages/hathor-rpc-handler/src/types/index.ts, packages/hathor-rpc-handler/src/schemas/index.ts
Expose TokenVersionString and tokenVersionStringSchema through public type/schema exports.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant RPC as RPC Method (createToken)
  participant Utils as tokensUtils
  participant Prompt
  participant Wallet

  Client->>RPC: send createToken(params with version string or omitted)
  RPC->>Utils: if version == DEPOSIT -> getDepositAmount(amount)
  Utils-->>RPC: depositAmount
  RPC->>Prompt: show confirmation (fee, deposit if DEPOSIT)
  Prompt-->>Client: user confirms
  Client->>RPC: confirmation response
  RPC->>Wallet: createNewToken(..., tokenVersion: internal enum, deposit?)
  Wallet-->>RPC: tx created / error
  RPC-->>Client: response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • pedroferreira1
  • andreabadesso

Poem

🐰 I bounced through lines of schema and string,
DEPOSIT now hops in as defaulting king,
Deposits computed, prompts set to cheer,
Tests updated — the rabbit claps a ear! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately describes the main change: converting token version representation from enum to string in RPC requests, which is the primary objective of this changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/change-token-version-to-string

Comment @coderabbitai help to get the list of available commands and usage tips.

@raul-oliveira raul-oliveira moved this from Todo to In Progress (Done) in Hathor Network Mar 9, 2026
andreabadesso
andreabadesso previously approved these changes Mar 9, 2026
@github-project-automation github-project-automation bot moved this from In Progress (Done) to In Review (WIP) in Hathor Network Mar 9, 2026
@raul-oliveira raul-oliveira merged commit 75fde58 into master Mar 9, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this from In Review (WIP) to Waiting to be deployed in Hathor Network Mar 9, 2026
@raul-oliveira raul-oliveira moved this from Waiting to be deployed to Done in Hathor Network Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants