Skip to content

feat(stream_contract): implement permissionless third-party top-up (#… - #1602

Open
emarkees wants to merge 5 commits into
LabsCrypt:mainfrom
emarkees:feat/permissionless-top-up-1463
Open

emarkees wants to merge 5 commits into
LabsCrypt:mainfrom
emarkees:feat/permissionless-top-up-1463

Conversation

@emarkees

Copy link
Copy Markdown
Contributor

feat(stream_contract): implement permissionless third-party top-up & automated balance refuel (#1463)

Closes #1463

Description

Addresses #1463 by implementing permissionless third-party top-up functionality (top_up_from) on StreamContract.

Previously, top_up_stream strictly enforced sender.require_auth(), preventing external sponsors, automated treasury refuel keepers (e.g. Gelato), DAO multisigs, or team leads from extending a payment stream's runway without administrative transfer.

Summary of Changes

1. Permissionless Top-Up Entrypoint

  • Added top_up_from(env: Env, funder: Address, stream_id: u64, amount: i128) -> Result<(), StreamError> in contracts/stream_contract/src/lib.rs:
    • Enforces funder.require_auth() instead of requiring the stream creator's authorization.
    • Enforces circuit breaker check (require_not_protocol_paused).
    • Validates positive amount and active stream status.
    • Rejects StepTranches vesting schedules with TopUpUnsupported.
    • Deducts protocol fees if configured and credits net amount to stream.deposited_amount.
    • Recalculates projected stream end time.
    • Persists stream state before transferring fees (CEI pattern).

2. Event Emission

  • Added StreamRefueledEvent in contracts/stream_contract/src/events.rs:
    • Published to topic ("stream_refueled", stream_id).
    • Carries stream_id, funder, amount, new_deposited_amount, and new_end_time.
    • Distinguishes third-party contributions from creator top-ups for downstream indexers and UIs.

3. Cancellation Refund Invariant

  • Maintained donation equity: third-party top-ups are non-refundable gifts to the stream. Upon stream cancellation, unvested tokens are refunded to the original stream.sender.

4. Storage & Schema Alignment

  • Updated STREAM_FIELD_COUNT = 17 in storage.rs to reflect all fields (cliff_time, arbiter, dispute_status, is_allowance_based).
  • Updated legacy migration shape tests and resolved cross-contract re-entrancy in fee observation test.
  • Resolved all unused variables, unused imports, and unused Result warnings.

Testing & Quality Gates

  • cargo test: 235 passed, 0 failed
  • cargo clippy --all-targets -- -D warnings: Clean (0 warnings)
  • cargo fmt --all -- --check: Clean
  • cargo build --target wasm32-unknown-unknown --release: Clean

Closes #1463

emarkees and others added 5 commits September 30, 2026 12:30
…absCrypt#1463)

- Add `top_up_from` entrypoint to allow any authorized funder to extend active stream runway
- Emit `StreamRefueledEvent` distinguishing third-party funder contributions from creator top-ups
- Enforce donation equity where unvested funds refund to original sender upon stream cancellation
- Deduct protocol fees if configured and project updated stream end time
- Reject unsupported schedules (e.g., StepTranches) with TopUpUnsupported
- Update STREAM_FIELD_COUNT and schema shape checks to 17 fields to account for recent Stream fields
- Add comprehensive test suite covering auth, accounting, multi-funder extensions, and refund equity

This branch has not been deployed

No deployments
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.

[Smart Contracts] Implement Permissionless Third-Party Top-Up & Automated Balance Refuel

1 participant