Skip to content

feat: Add support for Asset Freeze transactions #167

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

lempira
Copy link
Collaborator

@lempira lempira commented Jun 22, 2025

  • Implement AssetFreezeTransactionFields with asset_id, freeze_target, and frozen fields
  • Add AssetFreezeTransactionBuilder with derive_builder pattern support
  • Update Transaction enum to include AssetFreeze variant with proper serde serialization
  • Add FFI bindings for cross-language support (Python, TypeScript, Swift)
  • Update all transaction handling code to support the new transaction type
  • Add comprehensive test coverage including encoding/decoding, transaction IDs, fee calculation, and transaction grouping
  • Include test data generation for both freeze and unfreeze scenarios
  • Add example usage in Python and TypeScript test suites

This enables freezing and unfreezing of asset holdings for specific accounts, allowing asset managers to control transfer permissions on a per-account basis.

- Implement AssetFreezeTransactionFields with asset_id, freeze_target, and frozen fields
- Add AssetFreezeTransactionBuilder with derive_builder pattern support
- Update Transaction enum to include AssetFreeze variant with proper serde serialization
- Add FFI bindings for cross-language support (Python, TypeScript, Swift)
- Update all transaction handling code to support the new transaction type
- Add comprehensive test coverage including encoding/decoding, transaction IDs, fee calculation, and transaction grouping
- Include test data generation for both freeze and unfreeze scenarios
- Add example usage in Python and TypeScript test suites

This enables freezing and unfreezing of asset holdings for specific accounts,
allowing asset managers to control transfer permissions on a per-account basis.
@lempira lempira force-pushed the feat/add-asset-freeze-txn branch from c876e58 to 005e406 Compare June 22, 2025 01:16
@lempira lempira marked this pull request as ready for review June 22, 2025 01:18
@Copilot Copilot AI review requested due to automatic review settings June 22, 2025 01:18
Copy link

@Copilot 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 support for Asset Freeze transactions across the core library, FFI bindings, and language-specific SDKs.

  • Introduce AssetFreezeTransactionFields and AssetFreezeTransactionBuilder in Rust core
  • Extend Transaction enum, serialization, FFI, fee calculation, and ID logic to cover asset freeze/unfreeze
  • Add comprehensive tests and examples in TypeScript, Python, and Rust

Reviewed Changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/typescript/algokit_transact/tests/asset_freeze.test.ts Add TS tests for freeze/unfreeze encoding, ID, fee
packages/python/algokit_transact/tests/test_asset_freeze.py Add Python tests for asset freeze transactions
crates/algokit_transact_ffi/src/lib.rs Expose AssetFreezeTransactionFields via FFI
crates/algokit_transact/src/transactions/mod.rs Register AssetFreeze variant in the core Transaction enum
crates/algokit_transact/src/transactions/asset_freeze.rs Define the Rust AssetFreezeTransactionFields struct
crates/algokit_transact/src/tests.rs Add end-to-end Rust tests for freeze/unfreeze flows
crates/algokit_transact/src/test_utils/mod.rs Extend test utilities to generate freeze/unfreeze data
crates/algokit_transact/src/lib.rs Re-export freeze builder/fields in top-level API
Comments suppressed due to low confidence (2)

packages/python/algokit_transact/tests/test_asset_freeze.py:110

  • It could be valuable to also verify that the decoded transaction’s freeze_target matches the original address (e.g., assert decoded.asset_freeze.freeze_target.address == target_account.address).
    assert get_encoded_transaction_type(encoded) == TransactionType.ASSET_FREEZE

crates/algokit_transact/src/transactions/asset_freeze.rs:25

  • asset_id and freeze_target are required fields for this transaction. Consider adding builder validation (e.g., via #[builder(validator(...))]) to ensure asset_id > 0 and freeze_target is not a zero address.
pub struct AssetFreezeTransactionFields {

@@ -0,0 +1,128 @@
import { expect, test, describe } from "bun:test";
Copy link
Preview

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

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

[nitpick] The test suite is imported from "bun:test", which may conflict with the project's standard runner (e.g., Jest or Vitest). Consider aligning the import with the rest of the repository’s test framework for consistency.

Copilot uses AI. Check for mistakes.

));
}

let data = tx.clone().asset_freeze.unwrap();
Copy link
Preview

Copilot AI Jun 22, 2025

Choose a reason for hiding this comment

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

Cloning the entire Transaction just to extract asset_freeze can be expensive. Instead, pattern-match on tx.asset_freeze or take() the field to avoid a full struct clone.

Suggested change
let data = tx.clone().asset_freeze.unwrap();
let data = tx.asset_freeze.unwrap();

Copilot uses AI. Check for mistakes.

@lempira lempira marked this pull request as draft June 22, 2025 01:27
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.

1 participant