-
Notifications
You must be signed in to change notification settings - Fork 192
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
feat: split trade rates and quotes final wire-up #8079
Conversation
packages/swapper/src/swappers/ZrxSwapper/getZrxTradeQuote/getZrxTradeQuote.ts
Outdated
Show resolved
Hide resolved
src/components/MultiHopTrade/components/MultiHopTradeConfirm/MultiHopTradeConfirm.tsx
Show resolved
Hide resolved
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.
✅ Fetching rate without being connected
https://jam.dev/c/8a85ecab-202d-48a2-b2c5-7f0b920e68ae
✅ Swap using thorchain
https://jam.dev/c/e016404c-3e9d-4551-9732-cef9f243ee36
✅ Swap using Li.Fi
✅ Swap using 0x
https://jam.dev/c/79388f55-0302-429d-8275-cd103e87843b
✅ Swap using chainflip
https://jam.dev/c/0f2ef4f0-5a19-444c-a896-53f239799eb0
To external address
https://jam.dev/c/187036cc-2792-4a32-82c6-ef21278ab970
✅ Portals
Gas weren't there before quote, then appeared, seems as promised
https://jam.dev/c/f63681c4-1ecd-4b94-b1fc-40bc0b6f0be5
Cowsap swap ✅ but gas fees ❌
Gas fees didn't even worked at quote time for some reason, is this expected @gomesalexandre ?
Everything else looks fine, I would be able to stamp after a response for the cow gas fees
Totally expected ser @NeOMakinG! There's no Tx fees for CoW, since there is no Tx but a message signing! |
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.
One thought on this whilst testing: in cases where we don't have a gas estimate on rate fetch (e.g. for Portals), in this branch we unfairly list that swapper above other swappers that do have a gas estimate.
In the example below LiFi is actually a much better rate overall (very low gas vs what Portals will end up being), but it ranks below Portals.
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.
Next thought:
We should probably show the difference in the rate, maybe as a percentage here. This popped up every time for me when using Portals (maybe because we go from not knowing gas to knowing gas? This itself feels like a bug/undesirable behavior), and every time I had to try work out if the rate got better or worse, but I didn't know because I had no reference point.
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.
Tested:
✅ Cross-account trades
✅ 0x trades (with Permit2)
✅ CoW trades
✅ Portals trades
✅ LiFi trades
✅ Rate changing modal (though see comment above, I think this is way too noisy)
❌ I was able to get into a strange state, though I'm not sure exactly how I did it. It was consistent once I got into the state though, and was able to Jam it:
Urgh, very nice catch @0xApotheosis and quite a bad one indeed, I was also able to consistently repro with ZRX (which is the odd one with the weird time of final quote fetching). Read more to dig in a proper rabbit hole. There were a few things wrong with this one, mostly stemming from incorrect cross-account checks: The naive solutionFirst of all, we were doing undefined checks instead of empty checks in However, fixing that still made us unable to sign permit2: We were never upserting a final quote, as we were early bailing from the Getting to a root cause fix... almost (but actually fixing a prod bug in the process!)The reason why we weren't is we were checking for equal addresses, which, when using the same address as your wallet address but as a custom one, and dealing with checksum addresses (e.g copied over from MM) would fail equality checks, and result in the trade being wrongly detected as cross-account when it is in fact not. Fixed in f8e2b7d The actual root cause fixNow, this obviously exposes another issue: we were able to get rates for cross-account trades, which shouldn't be possible (assuming you did provide a receive address or have a wallet connected). You'll notice that the previous emptiness check has been reverted, which is expected. The whole reason why we ended up in such weird state in the first place was because we were able to continue with cross-account trades when we shouldn't have been able to. By fixing this, we fix the root cause that warranted the emptiness checks in the first place. Keeping the emptiness early return vs. undefined early return means that we were not anymore setting empty quote data, which in turns meant that in web/src/state/slices/tradeQuoteSlice/selectors.ts Lines 86 to 101 in a78a164
The web/src/state/slices/tradeQuoteSlice/selectors.ts Lines 643 to 658 in a78a164
This has all been fixed by bringing back While at that, also fixed a bug with native EVM assets signing being borked for ZRX, since we correctly got final quote at pre-permit2 signing time when permit2 was required, but were never getting it for native assets (where permit2 is not required, meaning it should be fetched at pre-Tx signing time as usual) See full regression test here including cross-account, and ensuring we do guard against cross-account detection: https://jam.dev/c/0afbf6dd-11f3-4d76-81e4-e28ccef8c802 And fix in 358c8a7 |
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.
Re-tested with a focus on manual receive address and 0x trade permutations.
✅ Using a manual receive address that is different from the send receive address correctly does not show 0x or Portals (fine with a manual receive address with the same address - an edge case, but expected behaviour)
✅ A trade where a manual receive address is specified is correctly received by the specified address
✅ 0x permit2 trades work as expected
✅ 0x non-permit2 trades work as expected
Phew, well done ser - monster PR.
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.
Smoke test quote/rate of all swappers (not E2E)
First test with portal: https://jam.dev/c/c2f08b08-cc14-4111-ad75-c2c8beb0bc49
I can click on the Sign Transaction
button while the rate
is not fetch yet, nitpick but could we had some loaders and skeletons everywhere while the rate is fetching?
https://jam.dev/c/3b60e0f8-5dd1-42c9-9e75-31c8b3c17288
Sometime it feels super weird but the rate expire, it should be the first time we fetch it? We shouldn't see the modal? Ex with Li.Fi: https://jam.dev/c/fa642e26-a462-49a0-aa84-fb05f3df1588 , not a blocker but it doesn't seems the best UX tbh
Manual receive address (not the same address)
https://jam.dev/c/9cec6b35-ecd7-4203-8962-a6f930a2e943
After a few minutes, using an external address, I couldn't sign a trade from BTC to ETH (https://jam.dev/c/d93e1e1f-86ac-41ed-b0aa-e631e0a7b00b)
Retrying after refresh did work
Manual receive address (same address)
https://jam.dev/c/ea3b0972-ae47-48a4-afaf-daf14ef222b3
Looks good so far, I didn't test at runtime for most of them except one or 2 with 0x, as I already tested the most in the first testing session, but very good PR
Description
TODO:
check with product how the new quote should look likeuseGetTradequotes
upgive it a better home, maybe, vs. it being a hook?After obtaining the quote, the next step is to sign the Permit2 EIP-712 message. Smart contract wallets and multi-sig wallets need to sign this message securely to authorize the swap.
(https://0x.org/docs/0x-swap-api/guides/smart-contract-wallet-integration#4-fetch-a-firm-quote)
Both states are inherently bad, and we will have to work around that
Issue (if applicable)
closes #7941
Risk
🚨 THIS 😱 RIGHT⚠️ HERE 😤 IS 💅 LITERALLY 🙈 THE 💃 MOST 🎲 HIGHEST ⬆️ RISKIEST 💣 RISKY 🔥 RISK 🎯 THAT 😈 EVER 💅 RISKED 💀 IN 🌪️ THE 🦹 HISTORY 📚 OF 💫 RISKS 🎲 BESTIE 💅 NO 🙅♀️ CAP 🧢 FR 💯 FR 💯
Testing
Engineering
Operations
Screenshots (if applicable)