Skip to content

Feat/optional total supply - #795

Open
ozgunozerk wants to merge 1 commit into
feat/contract-type-composefrom
feat/optional-total-supply
Open

Feat/optional total supply#795
ozgunozerk wants to merge 1 commit into
feat/contract-type-composefrom
feat/optional-total-supply

Conversation

@ozgunozerk

@ozgunozerk ozgunozerk commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Fixes #560

PR Checklist

  • Tests
  • Documentation

@brozorec, here is the PR that we were talking about, please take your time for reviewing it, because this is an important change. We should put our best effort into it to make it the "finalized" and "future proof" version if possible

Summary by CodeRabbit

  • New Features

    • Added opt-in total supply tracking for fungible tokens, including mint, burn, and supply queries.
    • Added composable token extensions for combining transfer policies with total supply tracking.
    • Added composition support for non-fungible token extensions.
    • Updated token examples to use the new composition and total supply capabilities.
  • Documentation

    • Clarified extension behavior, supported combinations, and total supply requirements across token and vault examples.

@ozgunozerk
ozgunozerk requested a review from brozorec July 14, 2026 12:38
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 93441713-6a88-48c3-b720-22d5592bee98

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The PR introduces Compose-based token contract composition, separates fungible total-supply tracking into an opt-in extension, adds composed allowlist/blocklist combinations, updates supply-aware integrations, and migrates token examples and documentation to the new APIs.

Changes

Token architecture

Layer / File(s) Summary
Fungible total-supply extension
packages/tokens/src/fungible/...
Adds total-supply storage, mutation helpers, override routing, validation tests, and removes total-supply bookkeeping from Base.
Fungible contract composition
packages/tokens/src/fungible/extensions/combinations/*, packages/tokens/src/fungible/extensions/{allowlist,blocklist}/*
Adds Compose, supported composed contract types, and policy marker bounds for allowlist/blocklist extensions.
Supply-aware integrations
packages/tokens/src/fungible/extensions/votes/*, packages/tokens/src/rwa/*, packages/tokens/src/vault/*
Routes votes, RWA, and vault supply behavior through total-supply overrides and helpers.
Non-fungible contract composition
packages/tokens/src/non_fungible/*
Adds non-fungible Compose resolution and updates supported contract type documentation.
Example contract migrations
examples/*, Architecture.md
Updates fungible and non-fungible examples to use composed contract types and explicit total-supply traits or helpers.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

Suggested reviewers: brozorec

Poem

I’m a rabbit composing types,
With supply-safe hops and checks.
Allowlists guard, vault shares grow,
Votes keep their totals in flow.
New examples bloom in the queue—
Compose makes the token view true!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description satisfies the checklist and issue reference, but it lacks the required change summary and context section. Add a short summary of the feature, key architectural changes, and any important implementation details or caveats.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement a Compose-based architecture and marker traits that support valid extension combinations, matching issue #560's composability goal.
Out of Scope Changes check ✅ Passed All code, tests, and docs appear tied to optional total supply and the new composition architecture, with no clear unrelated changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Title check ✅ Passed The title is concise and accurately points to the main change: optional total supply.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/optional-total-supply

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

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 76.66667% with 28 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ns/src/fungible/extensions/combinations/storage.rs 63.79% 21 Missing ⚠️
...ns/src/fungible/extensions/total_supply/storage.rs 86.27% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/tokens/src/fungible/extensions/combinations/mod.rs (1)

87-131: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce repetition in single-type Composable impls.

14 near-identical impls (bare type + 1-tuple, same Out) for 7 types. A small macro keeps the mapping in one place and removes the risk of forgetting the tuple form when a new contract type is added.

♻️ Proposed macro-based refactor
+macro_rules! impl_composable_single {
+    ($($ty:ty),* $(,)?) => {
+        $(
+            impl Composable for $ty {
+                type Out = $ty;
+            }
+            impl Composable for ($ty,) {
+                type Out = $ty;
+            }
+        )*
+    };
+}
+
-impl Composable for Base {
-    type Out = Base;
-}
-impl Composable for (Base,) {
-    type Out = Base;
-}
-impl Composable for AllowList {
-    type Out = AllowList;
-}
-impl Composable for (AllowList,) {
-    type Out = AllowList;
-}
-impl Composable for BlockList {
-    type Out = BlockList;
-}
-impl Composable for (BlockList,) {
-    type Out = BlockList;
-}
-impl Composable for TotalSupply {
-    type Out = TotalSupply;
-}
-impl Composable for (TotalSupply,) {
-    type Out = TotalSupply;
-}
-impl Composable for RWA {
-    type Out = RWA;
-}
-impl Composable for (RWA,) {
-    type Out = RWA;
-}
-impl Composable for Vault {
-    type Out = Vault;
-}
-impl Composable for (Vault,) {
-    type Out = Vault;
-}
-impl Composable for FungibleVotes {
-    type Out = FungibleVotes;
-}
-impl Composable for (FungibleVotes,) {
-    type Out = FungibleVotes;
-}
+impl_composable_single!(Base, AllowList, BlockList, TotalSupply, RWA, Vault, FungibleVotes);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/tokens/src/fungible/extensions/combinations/mod.rs` around lines 87
- 131, Replace the repeated single-type Composable implementations with a small
macro that generates both the bare-type and one-element tuple implementations
with the same Out mapping. Invoke it once for each of Base, AllowList,
BlockList, TotalSupply, RWA, Vault, and FungibleVotes, preserving the existing
resolution behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/tokens/src/fungible/extensions/combinations/mod.rs`:
- Around line 87-131: Replace the repeated single-type Composable
implementations with a small macro that generates both the bare-type and
one-element tuple implementations with the same Out mapping. Invoke it once for
each of Base, AllowList, BlockList, TotalSupply, RWA, Vault, and FungibleVotes,
preserving the existing resolution behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 56514609-a954-4a7c-90b7-957fbb8c277f

📥 Commits

Reviewing files that changed from the base of the PR and between 1e51389 and f3263ca.

📒 Files selected for processing (46)
  • Architecture.md
  • examples/fungible-allowlist/src/contract.rs
  • examples/fungible-blocklist/src/contract.rs
  • examples/fungible-capped/src/contract.rs
  • examples/fungible-governor-timelock/token/src/token.rs
  • examples/fungible-governor/token/src/token.rs
  • examples/fungible-pausable/src/contract.rs
  • examples/fungible-vault/src/contract.rs
  • examples/fungible-votes/src/contract.rs
  • examples/nft-access-control/src/contract.rs
  • examples/nft-consecutive/src/contract.rs
  • examples/nft-enumerable/src/contract.rs
  • examples/nft-royalties/src/contract.rs
  • examples/nft-sequential-minting/src/contract.rs
  • examples/rwa/token/src/contract.rs
  • packages/tokens/src/fungible/extensions/allowlist/mod.rs
  • packages/tokens/src/fungible/extensions/blocklist/mod.rs
  • packages/tokens/src/fungible/extensions/burnable/mod.rs
  • packages/tokens/src/fungible/extensions/burnable/storage.rs
  • packages/tokens/src/fungible/extensions/burnable/test.rs
  • packages/tokens/src/fungible/extensions/capped/mod.rs
  • packages/tokens/src/fungible/extensions/capped/test.rs
  • packages/tokens/src/fungible/extensions/combinations/mod.rs
  • packages/tokens/src/fungible/extensions/combinations/storage.rs
  • packages/tokens/src/fungible/extensions/combinations/test.rs
  • packages/tokens/src/fungible/extensions/mod.rs
  • packages/tokens/src/fungible/extensions/total_supply/mod.rs
  • packages/tokens/src/fungible/extensions/total_supply/storage.rs
  • packages/tokens/src/fungible/extensions/total_supply/test.rs
  • packages/tokens/src/fungible/extensions/votes/storage.rs
  • packages/tokens/src/fungible/extensions/votes/test.rs
  • packages/tokens/src/fungible/mod.rs
  • packages/tokens/src/fungible/overrides.rs
  • packages/tokens/src/fungible/storage.rs
  • packages/tokens/src/fungible/test.rs
  • packages/tokens/src/non_fungible/extensions/burnable/mod.rs
  • packages/tokens/src/non_fungible/extensions/combinations/mod.rs
  • packages/tokens/src/non_fungible/extensions/mod.rs
  • packages/tokens/src/non_fungible/mod.rs
  • packages/tokens/src/non_fungible/overrides.rs
  • packages/tokens/src/rwa/mod.rs
  • packages/tokens/src/rwa/storage.rs
  • packages/tokens/src/rwa/test.rs
  • packages/tokens/src/vault/mod.rs
  • packages/tokens/src/vault/storage.rs
  • packages/tokens/src/vault/test.rs
💤 Files with no reviewable changes (2)
  • packages/tokens/src/fungible/test.rs
  • packages/tokens/src/fungible/extensions/burnable/test.rs

Tracking the total supply is not required by SEP-41 and has a
scalability cost: every mint and burn writes a shared storage entry,
serializing otherwise independent transactions under parallel
execution. The base FungibleToken trait no longer tracks or exposes it.

The opt-in total_supply extension provides the FungibleTotalSupply
trait and a supply-aware TotalSupply contract type, storing the supply
in its own persistent entry so mints and burns only conflict with each
other, never with plain transfers. Compose resolves the curated
combinations with the allowlist/blocklist policies; the combined
contract types stay internal. RWA, Vault and FungibleVotes are
inherently supply-aware (votes serves the query from its checkpoints,
removing the previous double-tracking).

Closes #33

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@ozgunozerk
ozgunozerk changed the base branch from main to feat/contract-type-compose July 28, 2026 08:47
@ozgunozerk
ozgunozerk force-pushed the feat/optional-total-supply branch from f3263ca to 9205bff Compare July 28, 2026 08:55
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.

🏗️ [Core Feature]: Have a better architecture to enforce mutual exclusivity, without limiting composability and worsening DevX

1 participant