feat: Make share_decimals configurable per vault#152
Conversation
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)
There was a problem hiding this comment.
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: u32toBatchVaultParams(and thereforeCreateVaultParamsvia the type alias). - Plumbs
share_decimalsthrough factory entrypoints intoSingleRwaVaultInitParamsinstead of hardcoding6u32. - Sets the minimal
create_single_rwa_vaulthelper to defaultshare_decimalsto7u32(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_decimalsis now an external input but_create_single_rwa_vaultdoesn’t validate it.single_rwa_vault::__constructorrejects 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 withError::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. |
There was a problem hiding this comment.
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").
| /// 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. |
| /// **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 |
There was a problem hiding this comment.
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).
Description
Closes #66
The current implementation of vault creation hardcodes
share_decimalsto 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
share_decimalsfield toCreateVaultParamsandBatchVaultParamsstructs.share_decimalsthrough toInitParamsinstead of using the hardcoded value.7u32(following the SEP-41 convention).Key Files
params.rs— Updated parameter structs to includeshare_decimals.factory.rs— Updated logic to handle parameterized share precision.lib.rs— Default value implementation for simplified vault creation.Implementation Details
share_decimalsis now a configurable field per vault withinCreateVaultParamsandBatchVaultParams.create_single_rwa_vaulthelper now defaults to7u32to align with Stellar's SEP-41 standard.share_decimalsvalue.Definition of Done
vault_factory.single_rwa_vault.