Repository navigation
Conversation
…nd token escrow - Replace the period-based pull model with per-second streams. Accrual is V = rate_per_second * (now - start_time), clamped to [0, deposit], using ledger timestamp seconds. Reason: SC-070 requires linear per-second accrual. Consequence: pull_payment, period_length, and amount_per_period are removed. - Move funds through the Soroban token interface. create_stream escrows the deposit from the sender; withdraw and cancel_stream transfer tokens out. Reason: the balance invariant (contract balance equals the sum of unwithdrawn active stream balances) needs a real token balance to check. Consequence: create_stream takes a token address and the sender must hold the deposit. - Settle cancellation in one call: the accrued, unwithdrawn amount goes to the recipient and the unvested remainder goes back to the sender. Reason: the previous code computed a refund but neither paid the accrued amount nor left it pullable, so those tokens were stranded. Consequence: a cancelled stream holds zero balance and cannot be withdrawn from. - Support multiple streams keyed by u32 id, with get_stream, stream_count, vested, and claimable views. Reason: the invariant is defined over the sum of several streams. Consequence: streams are kept in instance storage, so storage grows with the number of streams. - Use checked arithmetic for the deposit, vesting, and transfer amounts. An overflow aborts the call. Vesting uses exact integer multiplication with no rounding; the rounding direction is documented in vested_at. - Replace the inline tests with src/test.rs, wired in with `mod test`. The tests cover vesting, cancellation, the balance invariant across a multi-stream scenario, and the failure paths. Reason: the previous src/test.rs was never compiled and targeted an API that lib.rs did not provide. Consequence: src/test.rs is the single test module; tests use the stellar asset contract from soroban-sdk testutils, with no new dependencies.
|
@dhikbass is attempting to deploy a commit to the Ayomide Adeniran's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@dhikbass 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! 🚀 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The payment streaming contract did not meet SC-070. Its
lib.rsused a period-based pull model (wholeperiod_lengthledgers, floor division) with no token transfers and no balance. Itstest.rswas not declared as a module and called an API thatlib.rsdid not provide, so it was never compiled.This PR rewrites the contract's accrual, cancellation, and escrow logic so the three acceptance criteria hold:
V = rate_per_second * (now - start_time), clamped to[0, deposit].create_streamescrows the deposit, andwithdrawandcancel_streamtransfer tokens out.cancel_streampays the accrued, unwithdrawn amount to the recipient and refunds the unvested remainder to the sender, in one call.deposit - withdrawnover Active streams after every operation. A test helper checks this in a multi-stream scenario.vested_at.src/test.rsis wired in with#[cfg(test)] mod test;and replaces the inline tests.No dependencies, lockfiles, or other contracts were changed.
soroban-sdkstays at 28.0.0.What breaks if this is wrong
create_streamnow takes a token address and a rate, and returns au32stream id.pull_paymentis removed, andcancel_streamtakes a stream id and returns the refund. Any caller of the old signatures will fail to compile or call. A repo search found no Rust callers outside the contract. The references are in docs and the contracts workspace manifest.rate_per_second * (stop_time - start_time)of the token. The transfer happens insidecreate_stream, so a short balance reverts the whole call.create_streamdepends on the sender's authorization covering the token sub-invocation. This is standard for Soroban but has not been exercised against a real network.Criteria status
V = rate * (now - start)lib.rspull_payment/claimable).vested_at,withdraw,claimableinlib.rs.test_vesting_is_linear_per_second,test_withdraw_pays_accrued_amount,test_full_withdrawal_exhausts_stream.cancel_streamcomputed a refund but never paid the accrued amount, so it was stranded. Old test checked only the refund.cancel_streamtransfers accrued to recipient and unvested to sender.test_cancel_mid_stream_vests_accrued_and_refunds_unvested,test_cancel_after_partial_withdrawal_pays_remaining_accrued,test_cancel_before_start_refunds_everything,test_cancel_after_full_vesting_refunds_nothing.assert_invariantintest.rssumsdeposit - withdrawnover Active streams and compares it with the token balance. It is test-only and loops overstream_count(), so it is not an on-chain sum.test_invariant_holds_across_multi_stream_scenario, which calls the check after each step.Failure paths, all in
test.rs: withdraw before start (test_withdraw_before_start_fails), non-recipient withdraw (test_non_recipient_cannot_withdraw), non-sender cancel (test_non_sender_cannot_cancel), withdraw after cancel (test_withdraw_after_cancel_fails), double cancel with no second payout (test_double_cancel_fails_and_pays_nothing_twice), deposit overflow (test_overflow_in_deposit_is_rejected), and non-positive rate (test_non_positive_rate_is_rejected).Verification
Verified by reading only. Nothing was compiled or run. Each signature was checked against its call sites, and the imports were checked against the
soroban-sdk28.0.0 API as used in this crate.APIs the reviewer should confirm at compile time:
Env::register_stellar_asset_contract_v2andStellarAssetContract::address()(testutils),soroban_sdk::token::{TokenClient, StellarAssetClient}, the generatedtry_*client methods, and theTokenClient::transferandmintargument forms (references).Commands that should run, not yet run:
Closes #1867