fix(escrow): derive split-release payments from on-chain basis points - #79
Merged
chonilius merged 1 commit intoAug 17, 2026
Conversation
splitRelease computed each Payment.amount by independently rounding (totalAmount * percentage / 100) in JS floats while the contract received Math.round(percentage * 100) basis points — two never-reconciled computations of the same split that could drift from escrow.amount and from what was actually instructed on-chain (MergeFi#43). - Apportion percentages into basis points that sum to exactly 10,000. - Derive each Payment.amount in whole stroops from those same basis points, allocating the rounding remainder via largest-remainder so sum(payments.amount) === escrow.amount exactly. - Record the split_release result (incl. returnValue) in escrow metadata and warn when the contract's returned total diverges from the recorded total, deferring per-recipient reconciliation to the reconciliation job. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
|
@eulami is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
nice job |
3 tasks
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
EscrowService.splitReleasecomputed each recordedPayment.amountby independently rounding(totalAmount * percentage / 100)in JS floating point, while the contract was instructed withMath.round(percentage * 100)basis points. These are two never-reconciled computations of the same split, so the local ledger could drift fromescrow.amountand from what was actually sent on-chain.Changes
100.00%), and those same basis points are both sent on-chain and used to derive eachPayment.amount.totalStroops * bps / 10000) with a largest-remainder allocation, sosum(payments.amount) === escrow.amountexactly for every valid split (including uneven thirds).split_releaseresult (includingreturnValue) is recorded in escrow metadata, and a divergence between the contract's returned total and the recorded total is surfaced as a warning rather than silently discarded. Per-recipient reconciliation remains deferred until the deployed contract returns a per-recipient breakdown.Tests
split-math.util.spec.tscovers basis-point apportionment and exact stroop splitting.escrow.service.spec.tsassertssum(payments.amount) === escrow.amountvia BigInt/stroops comparison and that the basis points sent on-chain sum to 10,000.Closes #43