feat(stream_contract): add overflow-safe calculate_claimable helper f…#152
Conversation
|
@ogazboiz You can comment on the PR: Hi 👋 Would you prefer: Upgrading dependencies with breaking changes? Relaxing the audit level? Or allowing audit warnings without failing CI? Happy to follow your preferred approach |
ogazboiz
left a comment
There was a problem hiding this comment.
Thanks for resubmitting this as a cleaner PR! The calculate_claimable helper and overflow-safe arithmetic are the right approach. However, this PR is currently conflicting with main.
Please run:
git fetch origin
git rebase origin/main
git push --force-with-lease
Once rebased and conflict-free, this will be ready to merge quickly. Looking forward to it! ✅
ogazboiz
left a comment
There was a problem hiding this comment.
hey! thanks for looking into the CI failures.
for the npm audit issue, let's just allow audit warnings without failing the CI for now — no need to introduce breaking changes for dev dependencies at this stage.
also, i noticed the PR currently has merge conflicts with main. could you run git fetch origin && git rebase origin/main to resolve them? once that's forced pushed and the CI passes, this will be ready to merge!
5c3e78a to
d5baffd
Compare
|
Hi 👋 I’ve updated the security workflow to allow The audit still runs and reports vulnerabilities in the logs, but it no longer blocks the pipeline due to moderate-level issues from dev dependencies. There are no changes to application logic or dependency versions — this only adjusts CI behavior. Please let me know if you’d prefer tightening the audit level (e.g., critical only) instead. |
Closes #79
This PR introduces a helper function
calculate_claimable(stream, now)to compute the withdrawable amount based on elapsed time.Summary of Changes
Added
calculate_claimable(&Stream, now)helper.Implements precise streaming formula:
claimable = (now - last_update_time) * rate_per_second
Uses
saturating_subto prevent negative elapsed time.Uses
checked_multo prevent integer overflow.Caps the result to the remaining stream balance to prevent over-withdrawal.
Updated
withdraw()to use the new helper function.Mathematical Safety
All calculations use integer-only arithmetic (no floating point).
Overflow is handled safely via
checked_mul.Final claimable amount is bounded by:
deposited_amount - withdrawn_amount
This guarantees:
Rounding Behavior
amount / duration) ensures deterministic floor rounding.env.ledger().timestamp().Scope
top_up_stream,cancel_stream, or events.withdraw().This implementation satisfies all acceptance criteria for Issue #79.