Skip to content

feat(streams): implement linear vesting schedules, withdrawals, and funding entrypoints (#202) - #325

Open
Dimank92 wants to merge 3 commits into
Zenith-options:mainfrom
Dimank92:feat/issue-202-streams-vesting-entrypoints
Open

Dimank92 wants to merge 3 commits into
Zenith-options:mainfrom
Dimank92:feat/issue-202-streams-vesting-entrypoints

Conversation

@Dimank92

Copy link
Copy Markdown

Summary

Resolves #202 by reconstructing the streams contract from a non-compiling shell into a fully functional Soroban smart contract implementing linear token streaming, stepped milestones, and cliff vesting.

Changes

  1. Schedule Architecture:
    • Resolved Soroban contracttype macro enum limitations by converting Schedule variants from named fields to tuple variants: Linear, LinearWithCliff(u64), and Stepped(Vec<(u64, i128)>).
    • Implemented validate_schedule ensuring strictly increasing milestone checkpoints up to MAX_CHECKPOINTS (64) bounded within [start, end] and terminating at total.
  2. Stream Lifecycle & Entrypoints:
    • create_stream & create_stream_stepped: upfront token deposit pull with TransferShortfall balance delta verification, preventing underfunded or fee-on-transfer shortfalls.
    • withdraw: allows recipients to withdraw accrued vested tokens computed via deterministic time-based curve.
    • cancel: funder or governance cancellation with exact pro-rata split (accrued balance paid to recipient, remainder refunded to funder).
    • transfer: recipient reassigns stream ownership and unwithdrawn accruals to a new recipient.
    • funding ops: top_up, extend_duration, increase_rate, and set_funding_delegate rebase the schedule via monotonic checkpoints so vested tokens never decrease.
    • schema_version, migrate, migrate_batch: fully integrated schema migration guards.
  3. Spec-Conforming Events v2:
    • Implemented typed InitializedEvent, StreamCreatedEvent, WithdrawnEvent, StreamCanceledEvent, and StreamTransferredEvent conforming to events.json.
  4. Testing:
    • 37/37 tests pass (cargo test -p zenith-streams), including unit tests, adversarial token tests, and proptests (prop_withdrawn_never_exceeds_deposit, prop_withdrawable_never_decreases, prop_vested_is_monotonic_across_funding_calls).
    • Clean Clippy check with zero warnings (cargo clippy -p zenith-streams --tests --no-deps -- -D warnings).

Payout Wallet: 0xC345C07229307d4f1c7935aD2cAe48e390215808 (Polygon / Base / Arbitrum / Stellar)

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.

Implement the streams Contract's Linear Vesting and Withdrawal Entrypoints

1 participant