Skip to content

Feat/interactuar 1stiteration#64

Merged
armandocodecr merged 43 commits intodevelopfrom
feat/interactuar-1stiteration
Mar 12, 2026
Merged

Feat/interactuar 1stiteration#64
armandocodecr merged 43 commits intodevelopfrom
feat/interactuar-1stiteration

Conversation

@armandocodecr
Copy link
Copy Markdown
Contributor

@armandocodecr armandocodecr commented Mar 12, 2026

Summary by CodeRabbit

  • New Features

    • Added a deployer contract enabling orchestrated deployment of three contracts in a single transaction with deterministic address generation.
    • Introduced token-sale contract with hard cap enforcement, per-investor limits, and admin controls.
  • Improvements

    • Enhanced error handling with explicit validation and checked arithmetic across participation token and vault contracts.
    • Improved vault contract with initialization state tracking and TTL maintenance.
    • Updated participation token with better balance and allowance management.
  • Documentation

    • Added comprehensive security audit reports for token-sale and vault contracts.
    • Added deployment and security documentation for vault contract.

JuanWimmin and others added 30 commits March 10, 2026 17:03
- Rename vault.rs to contract.rs (Soroban convention)
- Extract VaultOverview and ClaimPreview structs to new types.rs module
- Update lib.rs to declare types module and re-export from contract
- Update test.rs imports to reference contract module
- No logic changes — purely structural refactor

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rename sale.rs to contract.rs (Soroban convention)
- Replace string-based storage keys with typed DataKey enum in storage_types.rs
- Introduce ContractError enum in error.rs replacing .unwrap() calls
- Define and emit BuyEvent in events.rs on successful buy()
- Add set_token() function with admin authorization for deployment flow
- Constructor now accepts admin parameter (compatible with tokenDeploymentService)
- Update lib.rs to declare all new modules with public re-exports
- Update test.rs imports and constructor call signature
- All 59 tests passing

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Participation Token:
- Replace fragile string-based storage keys with typed DataKey enum
- Replace unwrap() calls with proper error handling (ContractError)
- Add amount > 0 validation on buy()
- Emit buy event for observability
- Add tests for zero and negative amount rejection

Vault Contract:
- Replace all arithmetic with checked_add/checked_mul/checked_sub/checked_div
- Replace expect() calls with typed ContractError::NotInitialized
- Add ArithmeticOverflow error variant
- Extract calculate_usdc_amount() and get_required() helpers

Token Factory:
- Use checked_add in receive_balance to prevent overflow
- Use checked_sub in spend_balance and spend_allowance to prevent underflow

All 61 tests pass (escrow: 26, participation-token: 3, token-factory: 9, vault: 23).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Storage & TTL:
- Add TTL constants (7-day bump) and extend_ttl on every buy() call
- Prevents storage expiration on testnet/mainnet

Input validation:
- Move USDC address from buy() parameter to constructor storage
- Eliminates attack vector where caller could pass a malicious token contract
- Constructor now takes: escrow_contract, participation_token, usdc_address

External contract interactions:
- Extract mint_participation_tokens() helper with documentation
- Documents why invoke_contract is used (mint is not part of TokenInterface)

Events & observability:
- Add events.rs module with typed BuyEvent struct
- Structured event data (payer, beneficiary, amount) for indexers

Tests:
- Add test_buy_payer_different_from_beneficiary (payer != beneficiary scenario)
- Update all tests for new constructor signature (3 params → no usdc in buy)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…it report (#5)

- Migrate BuyEvent to #[contractevent] macro (removes deprecated API warning)
- Add 5 edge case tests for participation-token
- Add 10 edge case tests for vault-contract
- Add 9 edge case tests for token-factory
- Add formal security audit report (security-audit-report-v1.0.0.md)
- Scout audit: 0 critical, 0 medium, 0 minor on participation-token

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Validate all constructor parameters before storing:
- ROI percentage must be in range 0..=10000
- Token and USDC addresses must differ
- Add ContractError variants: InvalidRoiPercentage, TokenAndUsdcMustDiffer
- Add 5 tests covering valid and invalid constructor inputs

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… purchases

- Add hard cap and max per investor parameters to ParticipationTokenContract constructor.
- Implement validation for hard cap and per-investor cap in the buy function.
- Introduce new ContractError variants for HardCapExceeded and InvestorCapExceeded.
- Update storage types to include hard cap, max per investor, and total minted.
- Enhance tests to cover scenarios for hard cap and per-investor cap limits.

All tests passing.
…cked_add (#25, #26)

#25: Replace all .expect() calls with typed ContractError variants:
- claim(): use .ok_or() for Enabled, RoiPercentage, TokenAddress, UsdcAddress
- get_admin, get_roi_percentage, get_token_address, get_usdc_address: change return to Result
- get_vault_usdc_balance: use .ok_or() for UsdcAddress
- preview_claim, get_vault_overview: change return to Result, use .ok_or()
- Add error variants: ArithmeticOverflow, EnabledNotFound, RoiPercentageNotFound,
  TokenAddressNotFound, UsdcAddressNotFound

#26: Use checked_add for total_redeemed + token_balance in claim(),
propagating ArithmeticOverflow on overflow.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…factory, participation token, and vault contract
- Update hard cap validation logic to ensure it only checks against the hard cap if it is greater than zero.
- This change prevents unnecessary checks when the hard cap is not set, improving contract robustness.
- Introduce new error variants for TokenAndUsdcCannotBeSame and InvalidAddressConfiguration to enforce address validation.
- Update constructor to panic if token and USDC addresses are the same or if admin address matches token or USDC.
- Add comprehensive tests to validate constructor behavior for various address configurations.
- Enhance documentation with trust assumptions and deployment checklist for better clarity.
-27 test succesfully passed (23 alredy exists + 4 new )
- Implement a flag to prevent re-invocation of the constructor, enhancing contract security.
- Introduce a new error variant `AlreadyInitialized` to handle attempts to initialize an already initialized contract.
- Update documentation and tests to reflect the new initialization behavior and error handling.
- Ensure all tests pass successfully.
- Add validation to the constructor to reject negative ROI percentages, introducing a new error variant `InvalidRoiPercentage`.
- Update existing error handling to return appropriate errors for missing storage values, including `EnabledFlagNotFound`, `RoiPercentageNotFound`, `TokenAddressNotFound`, and `UsdcAddressNotFound`.
- Modify relevant functions to return `Result` types instead of panicking, improving error management.
- Implement new tests to validate the behavior of the constructor with negative ROI and ensure zero ROI is accepted.
- All tests passing successfully.
Add tests for security scenarios identified in audit finding F-14:
- test_claim_overflow_in_formula: verify checked_mul panics on i128 overflow
- test_constructor_rejects_negative_roi: verify negative ROI is rejected
- test_double_claim_same_beneficiary: verify second claim fails after burn
- test_non_admin_cannot_change_availability: verify auth fails without admin

TTL tests omitted — depends on #22 (not yet implemented)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
feat: investment caps, constructor validation, and error handling (#3, #7, #18, #30, #31, #32)
Villarley and others added 13 commits March 11, 2026 16:22
Integrate vault constructor validation from CoKeFish PR #24:
- Keep our implementation (ROI_MAX=1000 per audit F-02, admin validation, re-init protection)
- Add test_constructor_rejects_excessive_roi and test_constructor_accepts_max_roi
- Update InvalidRoiPercentage message to 'between 0 and 1000'
- Fix should_panic expectations in ROI boundary tests

Made-with: Cursor
…D validation + add security tests

Made-with: Cursor
… extend_ttl and EnabledFlagNotFound

Made-with: Cursor
…ep feat/interactuar-1stiteration structure

- participation-token: keep contract.rs (escrow, admin, hard_cap), add AmountMustBePositive, #[contractevent], security tests
- vault-contract: keep extend_ttl, types module, full errors; add NotInitialized; merge security tests
- Remove sale.rs (use contract.rs)

Made-with: Cursor
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 12, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
backoffice-tokenization Ready Ready Preview, Comment Mar 12, 2026 7:04pm

Request Review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 07ffe16f-9b0e-4d54-beeb-9b59d52064f4

📥 Commits

Reviewing files that changed from the base of the PR and between 2189e68 and 40dffdb.

⛔ Files ignored due to path filters (1)
  • apps/smart-contracts/Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (37)
  • apps/smart-contracts/Cargo.toml
  • apps/smart-contracts/contracts/deployer/Cargo.toml
  • apps/smart-contracts/contracts/deployer/DEPLOY_ALL.md
  • apps/smart-contracts/contracts/deployer/src/deployer.rs
  • apps/smart-contracts/contracts/deployer/src/lib.rs
  • apps/smart-contracts/contracts/deployer/src/storage_types.rs
  • apps/smart-contracts/contracts/deployer/src/test.rs
  • apps/smart-contracts/contracts/participation-token/Cargo.toml
  • apps/smart-contracts/contracts/participation-token/src/allowance.rs
  • apps/smart-contracts/contracts/participation-token/src/balance.rs
  • apps/smart-contracts/contracts/participation-token/src/contract.rs
  • apps/smart-contracts/contracts/participation-token/src/lib.rs
  • apps/smart-contracts/contracts/participation-token/src/metadata.rs
  • apps/smart-contracts/contracts/participation-token/src/sale.rs
  • apps/smart-contracts/contracts/participation-token/src/storage_types.rs
  • apps/smart-contracts/contracts/participation-token/src/test.rs
  • apps/smart-contracts/contracts/token-factory/Cargo.toml
  • apps/smart-contracts/contracts/token-factory/src/lib.rs
  • apps/smart-contracts/contracts/token-factory/src/test.rs
  • apps/smart-contracts/contracts/token-sale/Cargo.toml
  • apps/smart-contracts/contracts/token-sale/security-audit-report-v1.0.0.md
  • apps/smart-contracts/contracts/token-sale/src/contract.rs
  • apps/smart-contracts/contracts/token-sale/src/error.rs
  • apps/smart-contracts/contracts/token-sale/src/events.rs
  • apps/smart-contracts/contracts/token-sale/src/lib.rs
  • apps/smart-contracts/contracts/token-sale/src/storage_types.rs
  • apps/smart-contracts/contracts/token-sale/src/test.rs
  • apps/smart-contracts/contracts/vault-contract/Cargo.toml
  • apps/smart-contracts/contracts/vault-contract/src/contract.rs
  • apps/smart-contracts/contracts/vault-contract/src/error.rs
  • apps/smart-contracts/contracts/vault-contract/src/events.rs
  • apps/smart-contracts/contracts/vault-contract/src/lib.rs
  • apps/smart-contracts/contracts/vault-contract/src/storage_types.rs
  • apps/smart-contracts/contracts/vault-contract/src/test.rs
  • apps/smart-contracts/contracts/vault-contract/src/types.rs
  • docs/VAULT_SECURITY.md
  • docs/audits/smart-contracts/vault-contract/SECURITY_AUDIT_VAULT_CONTRACT-V1.0.0.md

📝 Walkthrough

Walkthrough

This PR introduces a comprehensive restructuring of the Soroban smart contracts: bumps dependency versions (soroban-sdk/token-sdk to 25.1.0), adds a new deployer contract orchestrating three-contract deployment, refactors participation-token and vault contracts with Result-based error handling and safety checks, introduces a new token-sale contract, removes the token-factory crate, and adds extensive security audit documentation.

Changes

Cohort / File(s) Summary
Workspace & Dependency Management
apps/smart-contracts/Cargo.toml, apps/smart-contracts/contracts/participation-token/Cargo.toml, apps/smart-contracts/contracts/vault-contract/Cargo.toml
Soroban SDK version bumped from 23.1.1 to 25.1.0 across workspace; added soroban-token-sdk; updated Rust version constraints and build profiles for participation-token and vault-contract.
Deployer Contract (New)
apps/smart-contracts/contracts/deployer/*
New contract for orchestrating deterministic deployment of three related contracts in sequence; includes DeployerContract with deploy_all, individual deploy methods, constructor initialization, WASM hash management, and comprehensive test suite; includes DEPLOY_ALL.md documentation of backend workflow.
Participation Token Refactor
apps/smart-contracts/contracts/participation-token/src/lib.rs, src/contract.rs, src/allowance.rs, src/balance.rs, src/storage_types.rs, src/test.rs
Module reorganization shifting from sale-based contract to token-centric Token/TokenClient exports; replaced direct arithmetic with checked operations (checked_add/sub); removed sale.rs module; expanded test suite with token operations, mint authority validation, metadata immutability, and admin transfer scenarios.
Token Sale Contract (New)
apps/smart-contracts/contracts/token-sale/*
New contract for token purchase orchestration with parametric caps; includes TokenSaleContract with buy/set_token/set_admin methods, ContractError enum, BuyEvent/CapsUpdatedEvent structures, storage type definitions, and extensive test coverage; includes security audit report.
Vault Contract Refactor
apps/smart-contracts/contracts/vault-contract/src/contract.rs, src/error.rs, src/events.rs, src/storage_types.rs, src/types.rs, src/lib.rs, src/test.rs
Shifted from direct storage returns to Result-based error handling; added 10 new error variants (TokenAndUsdcCannotBeSame, AlreadyInitialized, ArithmeticOverflow, etc.); extracted VaultOverview/ClaimPreview to types.rs; introduced TTL extension logic, calculated USDC amount with overflow checks, initialization validation; updated event publishing to use #[contractevent] macros; reorganized module exports.
Token Factory Deprecation
apps/smart-contracts/contracts/token-factory/Cargo.toml, src/lib.rs, src/test.rs
Removed entire token-factory crate: Cargo.toml deleted, lib.rs cleared of module declarations and exports, comprehensive test suite (350+ lines) removed.
Security Documentation
docs/VAULT_SECURITY.md, docs/audits/smart-contracts/vault-contract/SECURITY_AUDIT_VAULT_CONTRACT-V1.0.0.md, apps/smart-contracts/contracts/token-sale/security-audit-report-v1.0.0.md
Added vault security assumptions and deployment checklist; comprehensive security audit reports for vault-contract (F-01 to F-17 findings, Scout analysis, claim flow diagram) and token-sale contract; detailed mitigation recommendations and testing notes.

Sequence Diagram

sequenceDiagram
    participant User as User/Admin
    participant Deployer as Deployer Contract
    participant TokenSale as Token Sale Contract
    participant PartToken as Participation Token Contract
    participant Vault as Vault Contract
    
    User->>Deployer: deploy_all(params)
    activate Deployer
    
    Note over Deployer: Phase 1: Deploy Token Sale
    Deployer->>TokenSale: deploy(salt, escrow, admin)
    activate TokenSale
    TokenSale-->>Deployer: token_sale_address
    deactivate TokenSale
    
    Note over Deployer: Phase 2: Deploy Participation Token
    Deployer->>PartToken: deploy(salt, name, symbol, mint_authority=token_sale)
    activate PartToken
    PartToken-->>Deployer: participation_token_address
    deactivate PartToken
    
    Note over Deployer: Phase 3: Wire Token Sale to Participation Token
    Deployer->>TokenSale: set_token(participation_token_address)
    activate TokenSale
    TokenSale-->>Deployer: ok
    deactivate TokenSale
    
    Note over Deployer: Phase 4: Transfer Admin Authority
    Deployer->>TokenSale: set_admin(final_admin)
    activate TokenSale
    TokenSale-->>Deployer: ok
    deactivate TokenSale
    
    Note over Deployer: Phase 5: Deploy Vault
    Deployer->>Vault: deploy(salt, admin, token=participation_token, usdc=usdc)
    activate Vault
    Vault-->>Deployer: vault_address
    deactivate Vault
    
    Deployer-->>User: DeployedContracts {token_sale, participation_token, vault}
    deactivate Deployer
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related issues

  • Issue #8 — Vault-contract security audit findings and mitigations are directly addressed by the contract refactoring (Result-based error handling, arithmetic overflow checks, initialization validation).
  • Issue #7 — Module reorganization (vault.rs → contract.rs, moving types to types.rs, updating lib.rs exports) implements the exact refactoring requested.

Possibly related PRs

  • PR #19 — Overlapping refactors across participation-token and vault-contract: moving business logic to contract.rs, adding storage_types/error/types modules, reorganizing exports and test updates.
  • PR #20 — Same smart-contract modules being hardened with security patterns: typed DataKey/error enums, #[contractevent] events, checked arithmetic, TTL management, and comprehensive test coverage.
  • PR #48 — Touches vault-contract's error enum, storage_types constants, and safer arithmetic/Result-based claim logic with overlapping constructor validation and type definitions.

Suggested reviewers

  • zkCaleb-dev
  • JoelVR17

Poem

🐰 Three contracts hop in grand ballet,
Deployer weaves their winding way,
Sale mints tokens with ROI glow,
While vault and safety steal the show—
Arithmetic checked, errors clear,
Trust blooms when code is ever sincere! 🌟

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/interactuar-1stiteration
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Tip

CodeRabbit can generate a title for your PR based on the changes.

Add @coderabbitai placeholder anywhere in the title of your PR and CodeRabbit will replace it with a title based on the changes in the PR. You can change the placeholder by changing the reviews.auto_title_placeholder setting.

@armandocodecr armandocodecr merged commit a7533bb into develop Mar 12, 2026
2 of 6 checks passed
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.

6 participants