Skip to content

[Smart Contracts] Support Non-Linear & Milestone Step-Vesting Streaming Schedules #1440

Description

@blurbeast

Overview & Background

Currently, FlowFi only supports strict linear streaming, where tokens unlock continuously per second (rate_per_second). However, institutional grants, venture capital token distributions, and executive compensation packages frequently require milestone step-vesting (e.g. 25% unlock at 6 months, 25% at 12 months, followed by linear unlock for remaining tokens, or custom scheduled tranches).


Detailed Problem Statement

  1. Incompatibility with Milestone Grants:
    • DAOs and protocols funding milestone-based development cannot model tranche releases within a single stream.
  2. Manual Fragmented Workarounds:
    • Senders currently have to create separate individual streams for each milestone tranche, resulting in multiplied gas costs and fragmented tracking.
  3. Lack of Dynamic Schedule Verification:
    • Recipient claimable calculations cannot evaluate discrete time-step unlock functions.

Technical Specification & Architecture

1. Milestone Vesting Step Model (types.rs)

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct VestingStep {
    pub unlock_time: u64,
    pub unlock_amount: i128,
}

#[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum VestingSchedule {
    Linear,
    StepTranches(Vec<VestingStep>),
    HybridCliffLinear { cliff_time: u64, cliff_unlock_amount: i128 },
}

2. Creation Entrypoint

pub fn create_step_vesting_stream(
    env: Env,
    sender: Address,
    recipient: Address,
    token_address: Address,
    steps: Vec<VestingStep>,
) -> Result<u64, StreamError>

3. Claimable Calculation Engine

  • At any timestamp $T$, total claimable amount equals the sum of step.unlock_amount for all steps where step.unlock_time <= T, minus stream.withdrawn_amount.
  • Cancellation rules: Senders can only refund steps where step.unlock_time > cancellation_time.

Target Files

  • contracts/stream_contract/src/types.rs
  • contracts/stream_contract/src/lib.rs
  • contracts/stream_contract/src/test.rs

Acceptance Criteria

  • Senders can deploy streams with up to 12 scheduled unlock steps.
  • Recipient can claim exactly the cumulative unlocked step amounts at designated timestamps.
  • Step times must be strictly monotonically increasing and total step amounts must equal deposited amount.
  • Cancellation properly settles unlocked steps to recipient and returns unearned future steps to sender.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions