Skip to content

feat: Make share_decimals configurable per vault#152

Open
trinnode wants to merge 1 commit into
StellarYield:mainfrom
trinnode:fix/issue-66-share-decimals-configuration
Open

feat: Make share_decimals configurable per vault#152
trinnode wants to merge 1 commit into
StellarYield:mainfrom
trinnode:fix/issue-66-share-decimals-configuration

Conversation

@trinnode
Copy link
Copy Markdown
Contributor

@trinnode trinnode commented Mar 26, 2026

Description

Closes #66

The current implementation of vault creation hardcodes share_decimals to 6. This is restrictive for vaults handling various asset types (e.g., BTC, ETH, or SEP-41 compliant tokens) that require different precision levels for shares. Developers and protocols need the flexibility to define share decimals at the point of initialization to ensure compatibility with diverse asset standards.

Requirements

  • Add share_decimals field to CreateVaultParams and BatchVaultParams structs.
  • Update the initialization logic to pass share_decimals through to InitParams instead of using the hardcoded value.
  • Set the simple creation function to default to 7u32 (following the SEP-41 convention).
  • Provide documentation within the code regarding the relationship between underlying asset decimals and share decimals.

Key Files

  • params.rs — Updated parameter structs to include share_decimals.
  • factory.rs — Updated logic to handle parameterized share precision.
  • lib.rs — Default value implementation for simplified vault creation.

Implementation Details

  • Configurability: share_decimals is now a configurable field per vault within CreateVaultParams and BatchVaultParams.
  • Standard Defaults: The create_single_rwa_vault helper now defaults to 7u32 to align with Stellar's SEP-41 standard.
  • Precision Support: Full parameterized functions now respect the caller-specified share_decimals value.
  • Documentation: Added guidance for common decimal values: 6 (USDC), 7 (SEP-41), 8 (BTC), and 18 (ETH).
  • Backward Compatibility: All existing factory functionality remains intact with no breaking changes to the core state.

Definition of Done

  • Vaults can be initialized with custom share decimal precision.
  • Default SEP-41 compliance (7 decimals) is applied to standard RWA vaults.
  • Inline documentation clarifies decimal selection for different asset classes.
  • Testing:
    • All 19 tests pass in vault_factory.
    • All 188 tests pass in single_rwa_vault.
    • Verified no regressions in existing deployment workflows.

Closes StellarYield#66 - Hardcoded share_decimals: 6 in Factory Ignores Asset's Actual Decimals

- Add share_decimals field to CreateVaultParams and BatchVaultParams
- Pass share_decimals through to InitParams instead of hardcoding 6
- Simple creation function defaults to 7u32 (SEP-41 convention)
- Document relationship between asset decimals and share decimals
- Common values: 6 (USDC), 7 (SEP-41), 8 (BTC), 18 (ETH)
Copilot AI review requested due to automatic review settings March 26, 2026 20:24
Copy link
Copy Markdown

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 addresses #66 by making share_decimals configurable per vault in the vault_factory contract, removing the previous hardcoded value and documenting expected conventions.

Changes:

  • Adds share_decimals: u32 to BatchVaultParams (and therefore CreateVaultParams via the type alias).
  • Plumbs share_decimals through factory entrypoints into SingleRwaVaultInitParams instead of hardcoding 6u32.
  • Sets the minimal create_single_rwa_vault helper to default share_decimals to 7u32 (SEP-41 convention) and updates tests/params construction accordingly.

Reviewed changes

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

File Description
soroban-contracts/contracts/vault_factory/src/types.rs Adds share_decimals to vault creation params and expands documentation on share-decimal conventions.
soroban-contracts/contracts/vault_factory/src/lib.rs Routes caller-provided share_decimals into vault init params; defaults the simple create path to 7.
soroban-contracts/contracts/vault_factory/src/tests.rs Updates batch param construction in tests to include share_decimals.
soroban-contracts/contracts/vault_factory/src/test.rs Updates (commented) test param structs to include share_decimals.
Comments suppressed due to low confidence (1)

soroban-contracts/contracts/vault_factory/src/lib.rs:541

  • share_decimals is now an external input but _create_single_rwa_vault doesn’t validate it. single_rwa_vault::__constructor rejects values > 18, so invalid values here will fail later during deployment with a less clear error and extra cost. Add a factory-side validation (e.g., reject > 18 with Error::InvalidInitParams) to fail fast and keep error semantics consistent.
        share_decimals: u32,
        rwa_name: String,
        rwa_symbol: String,
        rwa_document_uri: String,
        rwa_category: String,

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pub name: String,
pub symbol: String,
/// Number of decimal places for the vault's share token.
/// Default: 7u32 (SEP-41 convention). Set to 6u32 for USDC-aligned assets.
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The docstring says share_decimals has a "Default: 7u32" but BatchVaultParams/CreateVaultParams require the caller to always provide this field (there is no on-chain default applied when deserializing the struct). Please reword this to avoid implying an automatic default (e.g., "recommended" or "factory simple create uses 7u32").

Suggested change
/// Default: 7u32 (SEP-41 convention). Set to 6u32 for USDC-aligned assets.
/// Recommended: 7u32 (SEP-41 convention, used by the factory's simple
/// creation flows). Set to 6u32 for USDC-aligned assets, or another value
/// as appropriate for the asset.

Copilot uses AI. Check for mistakes.
Comment on lines +146 to +150
/// **Note:** `share_decimals` is required in `CreateVaultParams`. Common values:
/// - `6u32` for USDC/USDT-aligned assets
/// - `7u32` for SEP-41 convention (default recommendation)
/// - `8u32` for BTC-pegged tokens
/// - `18u32` for ETH/ERC-20 compatibility
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The PR description states "no breaking changes", but adding a required share_decimals field to CreateVaultParams/BatchVaultParams changes the XDR shape of arguments for create_single_rwa_vault_full / create_single_rwa_vault_batch / batch_create_vaults. Existing off-chain callers will need to update their generated bindings / param construction. Please either (a) update the PR description/release notes to reflect the breaking API change, or (b) preserve backward compatibility by keeping the old entrypoints/types and adding new ones that include share_decimals (or making the field optional with an explicit default).

Copilot uses AI. Check for mistakes.
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.

Hardcoded share_decimals: 6 in Factory Ignores Asset's Actual Decimals

2 participants