Skip to content

Feat 28 clawback#143

Merged
Tinna23 merged 3 commits intoStellarCommons:mainfrom
JoeX17:feat-28-clawback
Feb 26, 2026
Merged

Feat 28 clawback#143
Tinna23 merged 3 commits intoStellarCommons:mainfrom
JoeX17:feat-28-clawback

Conversation

@JoeX17
Copy link
Contributor

@JoeX17 JoeX17 commented Feb 26, 2026

feat(core): add clawback and clawback_claimable_balance operation explainers

Closes #87

Summary

Implements first-class explainers for both clawback and clawback_claimable_balance operations. These are regulated-asset operations that users often encounter without context. Both explainers include a fixed contextual note explaining what clawback means so users understand why funds were recovered.

All 303 tests pass (142 lib + 146 bin + 15 doc-tests).


Changes

src/explain/operation/clawback.rs (new file)

Core deliverable for Issue #28:

  • ClawbackExplanation struct with summary, issuer, from, asset_code, asset_issuer, amount
  • ClawbackClaimableBalanceExplanation struct with summary, issuer, balance_id
  • explain_clawback() — produces: "The asset issuer reclaimed 100 USDC from GHOLDER. Clawback is a feature of regulated assets that allows issuers to recover funds under specific conditions."
  • explain_clawback_claimable_balance() — produces: "The asset issuer clawed back claimable balance 00000000...ef12. Clawback is a feature..."
  • Balance IDs are shortened to XXXXXXXX...XXXX in summaries for readability; full ID preserved in the balance_id field
  • Graceful "Unknown issuer" fallback when source_account is absent
  • 15 unit tests covering both variants, context note presence, field preservation, fractional amounts, non-USDC assets, unknown issuer fallback, and ID truncation behaviour

src/models/operation.rs

  • Added ClawbackOperation struct: id, source_account, from, asset_code, asset_issuer, amount
  • Added ClawbackClaimableBalanceOperation struct: id, source_account, balance_id
  • Added Clawback(ClawbackOperation) and ClawbackClaimableBalance(ClawbackClaimableBalanceOperation) variants to Operation enum
  • Added id() match arms for both new variants
  • Added "clawback" and "clawback_claimable_balance" arms to From<HorizonOperation>

src/services/horizon.rs

  • Added balance_id: Option<String> to HorizonOperation so the clawback_claimable_balance mapping can read the balance ID off the Horizon response

src/explain/operation/mod.rs

  • Added pub mod clawback;

Test Results

test result: ok. 142 passed; 0 failed; 0 ignored   (lib)
test result: ok. 146 passed; 0 failed; 0 ignored   (bin)
test result: ok.  15 passed; 0 failed; 0 ignored   (doc-tests)
─────────────────────────────────────────────────
Total: 303 passed, 0 failed

Clawback tests (15 new tests all passing)

explain::operation::clawback::tests::test_clawback_summary_contains_amount_and_asset           ok
explain::operation::clawback::tests::test_clawback_summary_contains_recipient                  ok
explain::operation::clawback::tests::test_clawback_summary_contains_context_note               ok
explain::operation::clawback::tests::test_clawback_summary_format                              ok
explain::operation::clawback::tests::test_clawback_fields_preserved                            ok
explain::operation::clawback::tests::test_clawback_unknown_issuer_fallback                     ok
explain::operation::clawback::tests::test_clawback_fractional_amount                           ok
explain::operation::clawback::tests::test_clawback_non_usdc_asset                              ok
explain::operation::clawback::tests::test_clawback_claimable_balance_summary_contains_context  ok
explain::operation::clawback::tests::test_clawback_claimable_balance_summary_starts_correctly  ok
explain::operation::clawback::tests::test_clawback_claimable_balance_id_shortened              ok
explain::operation::clawback::tests::test_clawback_claimable_balance_full_id_in_field          ok
explain::operation::clawback::tests::test_clawback_claimable_balance_issuer_field              ok
explain::operation::clawback::tests::test_clawback_claimable_balance_unknown_issuer_fallback   ok
explain::operation::clawback::tests::test_short_balance_id_not_truncated                       ok

Acceptance Criteria

Criterion Status
Clawback operations include contextual note about regulated assets
clawback_claimable_balance variant is handled
Tests pass

@Tinna23 Tinna23 merged commit 9b8e1fc into StellarCommons:main Feb 26, 2026
1 check failed
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.

Issue #28 Add clawback and clawback_claimable_balance operation explainers

2 participants