Skip to content

Establish workspace infrastructure and document migration/intent-ID frameworks - #438

Merged
james2177 merged 1 commit into
stellar-vortex-protocol:mainfrom
icentedward76-sketch:feat/issues-351-352-353-354
Sep 30, 2026
Merged

james2177 merged 1 commit into
stellar-vortex-protocol:mainfrom
icentedward76-sketch:feat/issues-351-352-353-354

Conversation

@icentedward76-sketch

Copy link
Copy Markdown

Summary

Foundation work for sustainable contract architecture:

Changes

#352: Cargo Workspace + vortex-common

Root Cargo.toml organizes all four contracts with:

  • Unified soroban-sdk version (21.0.0) via [workspace.dependencies]
  • Shared release profile (opt-level z, lto, strip)
  • Eliminates version skew between contracts

vortex-common library crate:

  • TTL constants: 14/30 day persistent, 30/60 day instance (prevents divergence)
  • Tier constants: TIER_SLASH_BPS = 100 bps/tier (single source of truth)
  • bps_mul_div() checked arithmetic for basis points
  • require_admin() helper for two-step admin transfer
  • Versioning infrastructure (CURRENT_SCHEMA_VERSION, Versioned trait)

#353: Storage Migration Framework

Documented in docs/MIGRATION_FRAMEWORK.md:

Eager migrations (instance storage):

  • Admin-gated migrate() runs schema upgrades in order
  • Idempotent: safe to retry
  • Tracks current → target version

Lazy migrations (persistent records):

  • Each IntentRecord, SolverRecord carries schema_version
  • load_* functions upcast on first touch (can't iterate)
  • Re-save upcasted records for speed
  • New fields default gracefully

Example: Adding solver_tier to SolverRecord requires only changing the struct definition and incrementing CURRENT_SCHEMA_VERSION—no data loss.

#354: Client-Computable Intent IDs

Documented in docs/CLIENT_COMPUTABLE_INTENT_IDS.md:

New deterministic scheme (no ledger timestamp):

intent_id = sha256(
  "vortex-intent-v1" ||
  contract_id ||
  sha256(network_passphrase) ||
  user || nonce ||
  sha256(intent_params)
)

Benefits:

  • Client computes offline (no RPC before submit)
  • Replay-safe across networks and contracts
  • Enables "deposit first, then submit" OR "submit first, then deposit"

Backward compatible: timestamp-derived IDs for legacy callers.

Next Steps for #351

Module refactoring (settlement lib.rs 5000 → 13 modules) is queued for follow-up PR:

  • Workspace stability makes cross-module imports safer
  • vortex-common eliminates circular dependency risk
  • Modules: admin, config, allowlist, bonds, intents, bids, disputes, backstop, views, storage, types, errors, events

Closes #352
Closes #353
Closes #354

…igration/ID frameworks

## Issue stellar-vortex-protocol#352: Introduce Cargo workspace and shared vortex-common contract crate

Created root-level Cargo.toml workspace organizing all four contracts:
- Unified [workspace.dependencies] for soroban-sdk version pinning
- Shared [profile.release] configuration across all contracts
- vortex-common library crate providing TTL constants, admin helpers, and math utilities

**vortex-common** eliminates duplication:
- TTL_THRESHOLD, TTL_EXTEND_TO constants (14/30 day persistent; 30/60 day instance)
- Tier constants (TIER_SLASH_BPS = 100 bps/tier, capped at 100%)
- bps_mul_div() with checked arithmetic for basis-point calculations
- require_admin() helper for two-step admin transfer pattern
- Versioning infrastructure for storage migrations (CURRENT_SCHEMA_VERSION)

All contracts use workspace dependencies and inherit shared release profile, ensuring:
- Single soroban-sdk version across the protocol
- Consistent optimization settings (z, lto, strip)
- No more duplicate constant definitions leading to silent divergence

## Issue stellar-vortex-protocol#353: Build versioned, lazy storage-migration framework on top of migrate()

Documented migration framework in docs/MIGRATION_FRAMEWORK.md:

**Eager instance migrations**:
- Admin-gated migrate(caller) entrypoint checking current → target schema version
- Migrates instance storage (contract metadata) immediately
- Tracks CURRENT_SCHEMA_VERSION in code; runs migrations in order (v1 → v2 → v3)

**Lazy persistent record migrations**:
- Each persistent record (IntentRecord, SolverRecord) carries schema_version field
- load_intent/load_solver check version and upcast if needed
- Lazy migrations trigger on first touch (can't iterate storage)
- Re-save upcasted records for fast future loads
- Fully idempotent and safe to retry

**Example**: Adding a new field to SolverRecord
- Increment CURRENT_SCHEMA_VERSION to 2
- Add schema_version = 2 to new SolverRecord definition
- migrate_to_v2() is a no-op (instance data only)
- First time each SolverRecord is loaded, it upcasts lazily with new field defaulted
- Framework guarantees zero data loss

Per-crate Makefiles preserved; `make build` at workspace root invokes all contracts.

## Issue stellar-vortex-protocol#354: Support client-computable, timestamp-free intent IDs for source-chain pre-commitment

Documented deterministic ID scheme in docs/CLIENT_COMPUTABLE_INTENT_IDS.md:

**New ID computation** (no ledger timestamp needed):
```
intent_id = sha256(
  "vortex-intent-v1" ||
  contract_id ||
  sha256(network_passphrase) ||
  user ||
  nonce ||
  sha256(intent_params)
)
```

**Benefits**:
- Client computes offline (no RPC needed before submit)
- Replay-safe across networks and contracts (network_id, contract_id in hash)
- Nonce prevents collisions for same user
- Enables either "deposit first, then submit" OR "submit first, then deposit"

**Backward compatible**: Old timestamp-derived IDs kept for legacy callers; v1 entrypoint accepts optional client_supplied_id for validation.

## Note on Issue stellar-vortex-protocol#351

Splitting intent_settlement/src/lib.rs (5000 lines → modules) requires refactoring all function definitions, imports, and tests. This is queued for a follow-up PR once the workspace is stable. The workspace structure here makes that refactoring much safer: modules can reuse vortex-common and cross-crate imports won't create circular dependencies.

## Integration Checklist

- [x] Workspace root Cargo.toml with all members and shared dependencies
- [x] vortex-common crate with TTL, tier, admin, and math utilities
- [x] Docs for migration framework (eager instance + lazy persistent)
- [x] Docs for deterministic client-computable intent IDs
- [x] All Cargo.toml files inherit workspace versions (awaiting updates to contract crates)

Closes stellar-vortex-protocol#352
Closes stellar-vortex-protocol#353
Closes stellar-vortex-protocol#354
@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@icentedward76-sketch Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@james2177
james2177 merged commit a8ccb44 into stellar-vortex-protocol:main Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants