Skip to content

feat(icrc1): add ICRC-123 Rosetta support for freeze/unfreeze operations#9556

Closed
bogwar wants to merge 2 commits intoicrc-123-2-index-ngfrom
icrc-123-3-rosetta
Closed

feat(icrc1): add ICRC-123 Rosetta support for freeze/unfreeze operations#9556
bogwar wants to merge 2 commits intoicrc-123-2-index-ngfrom
icrc-123-3-rosetta

Conversation

@bogwar
Copy link
Copy Markdown
Contributor

@bogwar bogwar commented Mar 23, 2026

Summary

  • Add FreezeAccount, UnfreezeAccount, FreezePrincipal, and UnfreezePrincipal variants to IcrcOperation in the Rosetta data API
  • Implement block-to-operation conversion, storage operations, and balance tracking (these ops don't affect balances)
  • Update construction API to handle new operation types in request/response mapping

Stacked on #9533.

Test plan

  • Unit tests pass (ic-icrc-rosetta-unit-tests)
  • Integration tests pass (icrc_rosetta_integration_tests)
  • System tests pass (icrc_rosetta_system_tests, icrc_multitoken_rosetta_system_tests)
  • ICP rosetta integration tests pass

🤖 Generated with Claude Code

- Add 4 IcrcOperation variants: FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal
- Add TryFrom parsing for 4 new block types from generic blocks
- Add From<IcrcOperation> serialization to BTreeMap for storage
- Add OperationType variants and metadata structs for freeze operations
- Add IcrcOperationBuilder fields and conversion logic for freeze ops
- Update storage_operations balance tracking (no balance impact)
- Update construction_api and data_api match arms
- Add proptest strategy functions for freeze operations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive ICRC-123 Rosetta support for freeze/unfreeze operations, building on the foundation established in PR #9533. The implementation includes full block-to-operation conversion, storage operations, metadata handling, and balance tracking for four new operation types: FreezeAccount, UnfreezeAccount, FreezePrincipal, and UnfreezePrincipal. All freeze operations are correctly treated as non-balance-affecting, and the code includes extensive test coverage with property-based testing.

Changes:

  • Added four new operation variants to IcrcOperation enum with full CBOR encoding/decoding support
  • Implemented bidirectional conversion between Rosetta operations and ICRC-1 operations for freeze operations
  • Added FreezeAccountMetadata and FreezePrincipalMetadata types for serialization
  • Updated balance tracking logic to handle freeze operations as no-ops
  • Added comprehensive test coverage including property-based tests
  • Updated all exhaustive match arms across the codebase

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
rs/rosetta-api/icrc1/src/common/types.rs Added OperationType variants and metadata types for freeze operations
rs/rosetta-api/icrc1/src/common/storage/types.rs Added IcrcOperation variants, CBOR encoding/decoding, test infrastructure
rs/rosetta-api/icrc1/src/common/utils/utils.rs Implemented builder pattern and bidirectional Rosetta-ICRC1 conversion
rs/rosetta-api/icrc1/src/common/storage/storage_operations/mod.rs Updated balance tracking and block storage for freeze operations
rs/rosetta-api/icrc1/src/construction_api/utils.rs Updated match arms to handle freeze operations as unsupported
rs/rosetta-api/icrc1/src/construction_api/services.rs Updated error message for freeze operations
rs/rosetta-api/icrc1/src/data_api/services.rs Updated test match arms for freeze operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

| crate::common::storage::types::IcrcOperation::UnfreezeAccount { .. }
| crate::common::storage::types::IcrcOperation::FreezePrincipal { .. }
| crate::common::storage::types::IcrcOperation::UnfreezePrincipal { .. } => {
bail!("ICRC-124 operations not supported")
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Error message refers only to "ICRC-124 operations" but the match arm also includes ICRC-123 freeze/unfreeze operations (FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal). The error message should be updated to reflect both ICRC-123 and ICRC-124 operations, or more generally "Management and freeze operations not supported".

Suggested change
bail!("ICRC-124 operations not supported")
bail!("Management and freeze operations not supported")

Copilot uses AI. Check for mistakes.
| crate::common::storage::types::IcrcOperation::UnfreezeAccount { .. }
| crate::common::storage::types::IcrcOperation::FreezePrincipal { .. }
| crate::common::storage::types::IcrcOperation::UnfreezePrincipal { .. } => {
bail!("ICRC-124 operations not supported")
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Error message refers only to "ICRC-124 operations" but the match arm also includes ICRC-123 freeze/unfreeze operations (FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal). The error message should be updated to reflect both ICRC-123 and ICRC-124 operations, or more generally "Management and freeze operations not supported".

Suggested change
bail!("ICRC-124 operations not supported")
bail!("Management and freeze operations not supported")

Copilot uses AI. Check for mistakes.
| ic_icrc1::Operation::FreezePrincipal { .. }
| ic_icrc1::Operation::UnfreezePrincipal { .. } => {
panic!("Management operations not implemented")
panic!("ICRC-124 operations not implemented")
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

Error message refers only to "ICRC-124 operations" but the match arm also includes ICRC-123 freeze/unfreeze operations (FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal). The error message should be updated to reflect both ICRC-123 and ICRC-124 operations, or more generally "Management and freeze operations not implemented".

Suggested change
panic!("ICRC-124 operations not implemented")
panic!("Management and freeze operations not implemented")

Copilot uses AI. Check for mistakes.
}

pub fn build(self) -> anyhow::Result<crate::common::storage::types::IcrcOperation> {
Ok(match self.icrc_operation.context("Icrc Operation type must be one of Mint, Burn, Transfer, Approve, FeeCollector, Pause, Unpause, or Deactivate")? {
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The context message for the build function lists the allowed operation types but is outdated. It should also include the new freeze operation types (FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal) that are now handled.

Suggested change
Ok(match self.icrc_operation.context("Icrc Operation type must be one of Mint, Burn, Transfer, Approve, FeeCollector, Pause, Unpause, or Deactivate")? {
Ok(match self.icrc_operation.context("Icrc Operation type must be one of Mint, Burn, Transfer, Approve, FeeCollector, FreezeAccount, UnfreezeAccount, FreezePrincipal, UnfreezePrincipal, Pause, Unpause, or Deactivate")? {

Copilot uses AI. Check for mistakes.
…ations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bogwar
Copy link
Copy Markdown
Contributor Author

bogwar commented Apr 22, 2026

Superseded by new implementation in #9981, #9980, #9979, #9978, #9976

@bogwar bogwar closed this Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants