Skip to content

[Stellar] Add toggle to switch from default to explicit trait implementation#728

Merged
CoveMB merged 80 commits intoOpenZeppelin:masterfrom
CoveMB:stellar-default_impl_attribute
Jan 14, 2026
Merged

[Stellar] Add toggle to switch from default to explicit trait implementation#728
CoveMB merged 80 commits intoOpenZeppelin:masterfrom
CoveMB:stellar-default_impl_attribute

Conversation

@CoveMB
Copy link
Contributor

@CoveMB CoveMB commented Nov 11, 2025

Fixes #706

Summary

Enable UI and tooling to use explicit Soroban trait implementations instead of relying solely on #[default_impl], adding regression coverage and docs for the new option.

Motivation / Context

Contract authors asked for a way to inspect and customize every generated Soroban trait function instead of depending on #[default_impl]. This work exposes that capability in the builders, UI, and MCP tools without changing the default experience.

Changes

  • Major feature: optional explicit trait implementations throughout Stellar contract builders, plus access-control and token module plumbing updates.
  • Config / tooling: UI control section, AI descriptions, schema, and MCP tool changes so the new option can be toggled and validated end-to-end.

Description

  • packages/core/stellar/src/common-options.ts:10-36 and the builder defaults now carry an explicitImplementations flag so every contract kind can opt in to non-macro trait bodies.
  • packages/core/stellar/src/contract.ts:188-192 introduces addTraitForEachFunctions, letting trait mixins add all functions programmatically when macros are disabled.
  • Access-control helpers (packages/core/stellar/src/set-access-control.ts:18-235, packages/core/stellar/src/add-pausable.ts:4-44, packages/core/stellar/src/add-upgradeable.ts:4-45) accept the flag, generate Ownable/AccessControl function bodies, and still enforce the same role/owner checks.
  • Token builders propagate the choice through every feature (packages/core/stellar/src/fungible.ts:25-210, packages/core/stellar/src/non-fungible.ts:28-305, packages/core/stellar/src/stablecoin.ts:48-101) and update generation blueprints so option sweeps include the new mode.
  • UI/tooling surfaces the toggle (packages/ui/src/stellar/TraitImplementationSection.svelte:1-33 plus imports in each controls file) while schemas/prompts describe and validate it (packages/mcp/src/stellar/schemas.ts:24-35, packages/mcp/src/stellar/tools/fungible.ts:10-40, packages/common/src/ai/descriptions/stellar.ts:12-20).
  • New compile tests, scenario docs, and MCP tool suites cover explicit builds across fungible, non-fungible, and stablecoin variants (packages/core/stellar/src/*.compile.test.ts, packages/core/stellar/src/*.test.ts / .md, packages/mcp/src/stellar/tools/*.test.ts).

Affected Functions

  • packages/core/stellar/src/contract.ts:188 — new addTraitForEachFunctions helper to bulk-attach trait methods when macros are skipped.
  • packages/core/stellar/src/set-access-control.ts:18setAccessControl accepts the explicit flag and adds per-function trait impls for Ownable/AccessControl when needed.
  • packages/core/stellar/src/set-access-control.ts:84requireAccessControl forwards the explicit flag so pausable/upgradeable traits stay consistent.
  • packages/core/stellar/src/add-pausable.ts:4 & packages/core/stellar/src/add-upgradeable.ts:4 — feature mixins now require the explicit flag and pass it through to access control.
  • packages/core/stellar/src/fungible.ts:63 & :137 — base, burnable, and mintable helpers emit explicit trait functions when requested.
  • packages/core/stellar/src/non-fungible.ts:91 & :212 — non-fungible base, burnable/enumerable/consecutive modules support explicit implementations.
  • packages/core/stellar/src/stablecoin.ts:48 — limitation helpers forward the flag so allow/blocklist operations can be emitted explicitly.

Security Impact

  • ✅ No new security concerns; explicit implementations call the same helper libraries and still rely on requireAccessControl for gating.
  • Security-sensitive modifications: not applicable.

Testing

  • Added compile regressions for each contract family with explicitImplementations enabled (packages/core/stellar/src/fungible.compile.test.ts, non-fungible.compile.test.ts, stablecoin.compile.test.ts).
  • Added scenario/API tests, markdown snapshots, and MCP tool coverage for the new option (packages/core/stellar/src/*.test.ts, .md, .snap, and packages/mcp/src/stellar/tools/*.test.ts).

Manual verification:

  1. In the UI, toggle "Explicit trait methods" for each contract type and confirm the preview drops #[default_impl] and shows explicit bodies.
  2. Run pnpm test --filter='packages/core/stellar/src/*explicit*' and the relevant MCP tool tests to ensure the new flag compiles cleanly.

Backward Compatibility

  • ✅ No breaking changes; the wizard still uses #[default_impl] unless the new toggle is enabled.
  • ✅ No migration needed; existing saved configs remain valid and ignore the new option.

Copy link
Member

@ericglau ericglau left a comment

Choose a reason for hiding this comment

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

Looking great so far!

CoveMB and others added 2 commits November 19, 2025 14:31
Co-authored-by: Eric Lau <ericglau@outlook.com>
Co-authored-by: Eric Lau <ericglau@outlook.com>
@ericglau
Copy link
Member

The comments above need to be addressed before this can be merged.

@CoveMB CoveMB requested a review from ozgunozerk December 18, 2025 03:16
Copy link
Contributor

@brozorec brozorec left a comment

Choose a reason for hiding this comment

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

LGTM 👍

I'd also suggest bumping the version to 0.5.1

Copy link
Member

@ericglau ericglau left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@CoveMB CoveMB enabled auto-merge (squash) January 14, 2026 18:01
@CoveMB CoveMB merged commit aa0f0d2 into OpenZeppelin:master Jan 14, 2026
33 of 40 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 14, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Suggestion: add UI toggle for default_impl attribute in contract generation

4 participants