-
Notifications
You must be signed in to change notification settings - Fork 168
fix(contracts): claimable() returns 0 after cancel and auto-settle (#591) #655
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
adesuwa-tech
wants to merge
2
commits into
ritik4ever:main
Choose a base branch
from
adesuwa-tech:fix/591-claimable-after-cancel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
min_enduses wall-clocknow, not the effective (paused) vesting cutoff — corrupts the persisted schedule and can makeclawback()return a negative amount for paused-then-canceled streams.vestedcorrectly freezes atpause_started_atwhen the stream is paused (pervested_amount), sorecipient_payout/sender_refundare computed correctly. Butmin_endis derived from the rawnow, not that same effective time. Example: stream 0–1000/total 1000, paused at t=300, canceled at t=800 →vested=300(correct), but persistedend_time=800,total_amount=300. That’s an internally inconsistent linear schedule (300 vested over 800, not over 300).This isn’t just cosmetic:
clawback()(unchanged) doesn’t checkstream.canceledand recomputesvested_amountdirectly on the persisted stream. With the inconsistent fields above,vested_amountrecomputes to112(not300), sounclaimed_vested = 112 - claimed_amount(300) = -188, andclawbackcan return a negativeactual_clawbackto the caller (no transfer occurs, but the reported clawback amount is wrong).claimable()/get_claimable_batch()are unaffected since they short-circuit oncanceledbefore touchingvested_amount, so there's no direct fund-safety issue — but the stored schedule andclawback()'s return value are incorrect for this reachable pause→cancel ordering (nothing prevents cancel while paused).🐛 Suggested fix — bound by the effective (paused-aware) time
let now = env.ledger().timestamp(); let vested = vested_amount(&stream, now); let recipient_payout = vested.saturating_sub(stream.claimed_amount); let sender_refund = stream.total_amount.saturating_sub(vested); stream.canceled = true; - let min_end = if now > stream.start_time { now } else { stream.start_time }; + // Keep the persisted schedule consistent with the same instant used + // to freeze `vested` above (pause_started_at when paused). + let effective_now = if stream.paused { + stream.pause_started_at.unwrap_or(now) + } else { + now + }; + let min_end = if effective_now > stream.start_time { effective_now } else { stream.start_time }; if min_end < stream.end_time { stream.end_time = min_end; } stream.total_amount = vested;📝 Committable suggestion
🤖 Prompt for AI Agents