Repository navigation
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
🛑 Files requiring codeowner reviewTo merge this PR, you'll need to get approvals from the following owners. @MetaMask/confirmations (6 files)
ℹ️ Files co-owned by
|
| transaction, | ||
| }); | ||
| } catch (error) { | ||
| const transactionHash = await waitForChompDeposit(chompOptions); |
There was a problem hiding this comment.
I don't think we want to delay here nor directly couple ourselves to CHOMP execution before throwing.
Rather we had planned just to treat this as a success if the first leg was successful and it was CHOMP compatible, likely based on a feature flag, since CHOMP may get to it immediately or in future based on a retry mechanism for example.
The recovery flow exists just to handle a race condition where CHOMP has already acted at the same time.
This is already in the confirmations backlog, I believe with @OGPoyraz 👍
There was a problem hiding this comment.
Thanks @matthewwalsh0, agreed we shouldn't delay or couple to CHOMP execution here. Treating a successful, CHOMP-compatible first leg as success is the better direction.
I'm not sure this recovery path is urgently needed for the membershipSubscription flow as it's not even released in production yet:
- Crypto deposit:
membershipSubscriptionlocks the pay amount to X, so it never reaches the second leg. The second leg only applies to "max" mode. - Fiat deposit: Most users will wait for the order to land in the app, so the regular second leg will cover it. This is an edge case. Plus we just delivered a resumable transactions for fiat, meaning that this fiat transactions will continue where it's left off if user re-opens app.
I'll keep this in the confirmations backlog and revisit once we have meaningful Confirmation analytics fyi @tuna1207
There was a problem hiding this comment.
Agree, removed the CHOMP wait. This PR now only adds secondLeg and to. Thanks @matthewwalsh0 @OGPoyraz
…t updates getAmountData updates can now include a `to`. The second leg applies it to both the submitted calls and the stored parent calls, so a premium teller deposit is not sent to the base teller. Co-authored-by: Cursor <cursoragent@cursor.com>
…eadline Measure the CHOMP deposit wait with performance.now() so that a wall-clock change cannot extend the 60 second wait. Also drop an unreachable return after the polling loop, which left a line uncovered and failed the 100% coverage threshold. Co-authored-by: Cursor <cursoragent@cursor.com>
…leg-chomp Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # packages/transaction-pay-controller/CHANGELOG.md
…leg call resolution fails Co-authored-by: Cursor <cursoragent@cursor.com>
tanguyenvn
left a comment
There was a problem hiding this comment.
This PR adds the secondLeg flag and lets getAmountData change the to of a call. Both changes work and have tests. But SUB-1162 also asks Core for a bounded CHOMP wait (up to 2 minutes) when the deposit build fails. The final diff has no wait, and a getAmountData throw (the mobile 'defer to CHOMP' path) fails the second leg before any CHOMP check runs. Separately, outside this diff: findRecentChompVaultDeposit in chomp.ts matches any outgoing mUSD transfer from the Money account with amount >= the settled amount, and does not check the recipient. So an unrelated transfer can show as a CHOMP success. Please check if a recipient or vault check is needed.
|
|
||
| ### Added | ||
|
|
||
| - Add the optional `secondLeg` flag to `GetAmountDataRequest`, set only when encoding calls for the settled amount in the non-atomic second leg ([#11787](https://github.com/MetaMask/core/pull/11787)). |
There was a problem hiding this comment.
[Must fix] The bounded CHOMP wait from SUB-1162 is not in this PR.
What happens:
- A later commit removed the CHOMP wait.
withChompRecoverynow does one scan before submit and one scan after a submit failure.- CHOMP deposits about 1 minute after the funds land, so a single scan usually misses it.
- The user sees a failure, but the ticket expects success with the CHOMP transaction.
Suggestion: Did the team drop the 2-minute wait on purpose? If not, add a bounded poll (for example, up to 2 minutes) for the CHOMP deposit, and add tests for success and timeout.
| 'TransactionPayController:getAmountData', | ||
| { | ||
| amount: sourceAmountRaw, | ||
| secondLeg: true, |
There was a problem hiding this comment.
[Must fix] A getAmountData throw (defer to CHOMP) fails the second leg with no CHOMP check.
What happens:
- Mobile throws from its
getAmountDatahandler when Sentinel errors or times out. resolveSecondLegCallsruns beforewithChompRecoveryand outside thetry.- The error goes up at once: no CHOMP scan, no wait, and no
Second leg:prefix. - Acceptance criterion 3 fails. The deposit shows failure even when CHOMP deposits later.
Suggestion: Move call resolution inside the recovery path, or catch the throw and run the bounded CHOMP wait. Is a throw the agreed defer signal, or should the response have an explicit defer field?
| const nested = nestedTransactions[nestedTransactionIndex]; | ||
| if (nested) { | ||
| nested.data = data; | ||
| nested.to = to ?? nested.to; |
There was a problem hiding this comment.
[Should fix] The new to is used with no check.
What happens:
- A handler returns any
toinupdates. - Core writes it to the parent transaction and submits the batch to that address.
- A wrong
tocan send the user's funds to the wrong contract. tois on the sharedGetAmountDataResponsetype, but max-quote and fiat ignore it with no warning.
Suggestion: Accept to only when secondLeg is true, and check it (for example, a valid address, or an allow list of known tellers). Document on the type that only the second leg honours to.
| ); | ||
| }); | ||
|
|
||
| it('passes the settled amount to getAmountData as a second-leg request', async () => { |
There was a problem hiding this comment.
[Should fix] No tests for the defer and timeout paths.
What happens:
- The tests cover the
secondLegflag and thetoretarget. - No test makes
getAmountDatareject (Sentinel error or timeout). - SUB-1162 asks for unit tests for defer, timeout, and no second leg.
Suggestion: Add tests where getAmountData rejects. Assert the expected result: CHOMP success inside the wait, and failure after the wait ends.
| for (const { nestedTransactionIndex, data } of updates) { | ||
| if (tx.nestedTransactions?.[nestedTransactionIndex]) { | ||
| tx.nestedTransactions[nestedTransactionIndex].data = data; | ||
| for (const { nestedTransactionIndex, data, to } of updates) { |
There was a problem hiding this comment.
[Nit] The update loop is now in two places.
What happens:
- The loop at line 189 and this loop do the same
dataandtoupdate. - A future change to one loop can miss the other.
Suggestion: Extract a helper, for example applyAmountUpdates(nestedTransactions, updates), and call it in both places.
Explanation
Money Account premium deposits need Sentinel to sign the exact amount that landed on the account. Only the non-atomic second leg knows that settled amount, and a premium deposit goes to a different teller contract than the default vault.
This PR adds two optional fields to
TransactionPayController:getAmountData:GetAmountDataRequest.secondLeg: set totrueonly when the second leg calls with the settled amount. Callers at quote time and the fiat calldata re-encoding callers don't set it.GetAmountDataResponse.updates[].to: an optional new target for a nested call. The second leg applies it to both the submitted batch and the parent transaction'snestedTransactions. Updates withouttokeep the existing target.Both fields are optional, so existing
getAmountDatahandlers don't change.References
Checklist
Made with Cursor
Note
Medium Risk
Changes non-atomic pay second-leg submission and calldata encoding paths where wrong
toor amount could mis-route funds; fields are optional so existinggetAmountDatahandlers stay compatible.Reviewed by Cursor Bugbot for commit 61378d1. Bugbot is set up for automated code reviews on this repo. Configure here.