Skip to content

feat(vault): add capabilities() bitmap for client feature detection#582

Open
Ajibose wants to merge 1 commit into
CalloraOrg:mainfrom
Ajibose:task/capabilities-bitmap
Open

feat(vault): add capabilities() bitmap for client feature detection#582
Ajibose wants to merge 1 commit into
CalloraOrg:mainfrom
Ajibose:task/capabilities-bitmap

Conversation

@Ajibose

@Ajibose Ajibose commented Jun 28, 2026

Copy link
Copy Markdown

Closes #504

Summary

  • Adds a capabilities() -> u64 pure-view function to CalloraVault that returns a stable bitmask of every feature the contract supports
  • Each of the 18 assigned bits maps to a specific, documented capability; bits 18–63 are reserved and always zero
  • Ships docs/CAPABILITIES.md with a full bit registry, stability guarantees, and integration examples for TypeScript and Rust clients

Changes

File What changed
contracts/vault/src/capabilities.rs New module — 18 CAP_* constants, ALL_CAPABILITIES aggregate, and capabilities() function
contracts/vault/src/lib.rs Wires pub mod capabilities, exposes CalloraVault::capabilities(), registers mod test_capabilities
contracts/vault/src/test_capabilities.rs 25 tests: each individual bit set, reserved bits zero, constant stability, idempotency, pre-init availability, no-overlap invariant
docs/CAPABILITIES.md Complete bit registry table, stability guarantee, integration checklist, TypeScript constant exports

Capability bit registry

Bit Constant Feature
0 CAP_DEPOSIT deposit()
1 CAP_WITHDRAW withdraw() / withdraw_to()
2 CAP_DEDUCT deduct()
3 CAP_BATCH_DEDUCT batch_deduct()
4 CAP_PAUSE pause() / unpause()
5 CAP_AUTHORIZED_CALLER set_authorized_caller()
6 CAP_OFFERING_METADATA metadata CRUD
7 CAP_PRICE_REGISTRY price CRUD
8 CAP_REQUEST_IDEMPOTENCY request_id dedup
9 CAP_TWO_STEP_OWNERSHIP ownership transfer
10 CAP_TWO_STEP_ADMIN admin transfer
11 CAP_SETTLEMENT settlement integration
12 CAP_REVENUE_POOL revenue pool
13 CAP_RATE_LIMIT developer rate limiting
14 CAP_ADMIN_BROADCAST broadcast()
15 CAP_DEPOSITOR_ALLOWLIST depositor allowlist
16 CAP_SLIPPAGE_GUARD max_fee_bps guard
17 CAP_UPGRADE upgrade()
18–63 (reserved) Always zero

Test plan

25 tests in test_capabilities.rs cover:

  • capabilities() returns ALL_CAPABILITIES constant
  • Each of the 18 CAP_* bits is individually set
  • Reserved bits 18–63 are always zero
  • Bit positions are pinned to their exact hex values (stability)
  • No two CAP_* constants share a bit (no-overlap invariant)
  • All 18 bits 0–17 present in ALL_CAPABILITIES (no gaps)
  • Result is idempotent across multiple calls
  • Available before vault initialization (pure view, no storage read)

Note: The upstream repository has pre-existing compilation errors in contracts/vault/src/lib.rs (duplicate broadcast and get_max_deduct function definitions) and contracts/settlement/src/lib.rs that prevent cargo test from executing. None of these errors are in the new capabilities code — verified by grep capabilities returning no hits in the compiler error output. The capability module itself is correct and self-consistent.

Exposes a pure-view `capabilities() -> u64` function on CalloraVault that
returns a stable bitmask of every feature the contract supports.  Each of the
18 assigned bits maps to a specific capability (deposit, withdraw, deduct,
batch_deduct, pause, authorized_caller, offering_metadata, price_registry,
request_idempotency, two_step_ownership, two_step_admin, settlement,
revenue_pool, rate_limit, admin_broadcast, depositor_allowlist,
slippage_guard, upgrade).  Bits 18-63 are reserved and always zero.

- contracts/vault/src/capabilities.rs: bit constants and capabilities()
- contracts/vault/src/lib.rs: expose CalloraVault::capabilities(), wire module
- contracts/vault/src/test_capabilities.rs: 25 tests covering every bit,
  stability, reserved-bits-zero, idempotency, and no-init availability
- docs/CAPABILITIES.md: full bit registry with integration examples
@drips-wave

drips-wave Bot commented Jun 28, 2026

Copy link
Copy Markdown

@Ajibose Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

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.

Add a contract version bitmap so clients can detect capability deltas

1 participant