Skip to content
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: permit2 allowance flow for zrx swaps #7758

Merged
merged 26 commits into from
Oct 21, 2024
Merged

feat: permit2 allowance flow for zrx swaps #7758

merged 26 commits into from
Oct 21, 2024

Conversation

woodenfurniture
Copy link
Member

@woodenfurniture woodenfurniture commented Sep 17, 2024

Description

Breaks token allowance approval UI components into reusable ones in prep for permit2 UI flow.

Notable non-permit2 changes:

  • Adds default "exact" allowance state per conversation with product (previously this was only the case for LiFi trades).
  • Copy for allowance reset is now "allowance reset", not "approval reset"
  • Copy for allowance approval is not "allowance approval", not "approval"
  • Code renaming to correspond to the above
  • Combine allowance reset and allowance approval steps into a single allowance step component
  • Migrates 0x swapper to use api proxy
  • UI will persistently display all approval related TX hashes (e.g both the allowance reset and allowance approval), with better naming

Permit2 changes:

  • Fully implements Permit2 flow, which consists of an initial unlimited allowance approval (toggle will be hidden) followed by a signature
  • If the initial approval was already processed for the sell token, only a signature is required
  • USDT allowance reset never appears for Permit2 because only unlimited allowance is presented when initially approving. If a user gets into a state they need to reset their allowance, they will have to use https://app.unrekt.net/
  • A feature toggle to disable the Permit2 version of the 0x swapper has been included so we can fall back to the v1 API if we have any issues. Due to the surface area of the change, no feature toggle exists for the UI and state changes so extra care is required to ensure we roll this out without issues.

TODO:

  • Beard oil
  • ETH -> ERC20 broken
  • insufficient for fees
  • triple check zrx still works with flag off
  • triple check zrx v2 api proxy endpoints are deployed to prod

Issue (if applicable)

progresses #7648

Risk

High Risk PRs Require 2 approvals

This is a high risk change because it heavily modifies the state management of trades and completely rewrites the UI associated with allowance approvals.

What protocols, transaction types, wallets or contract interactions might be affected by this PR?

All trades, especially those with token allowance approvals. Due to the surface area of the change, no feature toggle exists for the UI and state changes so extra care is required to ensure we roll this out without issues.

Testing

General

  • trades on all chains

non 0x trades

  • without allowance approvals
  • trades with allowance approvals
  • trades with USDT allowance reset and approval
  • multi-hop trades

0x trades

  • with REACT_APP_FEATURE_ZRX_PERMIT2 feature flag enabled

    • without allowance approvals
    • trades with allowance approvals
    • trades with USDT allowance reset and approval
  • with REACT_APP_FEATURE_ZRX_PERMIT2 feature flag disabled

    • trades with initial Permit2 allowance approval + sign
    • trades with Permit2 sign only (i.e allowance previously approved)

Engineering

Operations

There is a feature flag in this PR but its used only as a fallback if we need to disable permit2 trades for any reason. The changes made in this PR still affect the app majorly regardless of whether the flag is enabled.

Screenshots (if applicable)

non-0x trades

0x trades

@woodenfurniture woodenfurniture changed the title chore: break up approval components into reusable ones feat: implement permit2 flow for 0x swapper Sep 17, 2024
@woodenfurniture woodenfurniture changed the title feat: implement permit2 flow for 0x swapper feat: break up allowance approval flow in prep for permit2 Sep 18, 2024
@woodenfurniture woodenfurniture marked this pull request as ready for review September 18, 2024 01:22
@woodenfurniture woodenfurniture requested a review from a team as a code owner September 18, 2024 01:22
@woodenfurniture woodenfurniture marked this pull request as draft September 19, 2024 22:09
@woodenfurniture woodenfurniture changed the title feat: break up allowance approval flow in prep for permit2 feat: permit2 allowance flow for zrx swaps Sep 23, 2024
@woodenfurniture woodenfurniture marked this pull request as ready for review October 10, 2024 23:43
Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First very very high-level pass to get familiar with this - untested at runtime just yet and allowance hooks still not reviewed, but looks solid from this first read!
Some comments re: generalization and naming mostly, though nothing obviously stands out as wrong here.

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First runtime pass with permit2 flag enabled

image

- USDT.ARB -> ETH.ARB (0x) quote 🚫 Same here:

image

Also tested with the flag off:

Unable to test more USDT flow re: unlimited, 0, and approval reset flows for the time being because of low fundus

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally after local origin/develop rebase and LGTM for all tested flows, minus one spotted issue re: permit2 contract approval being prompted (with the flag on) when there is enough allowance, and there shouldn't be any new allowance Tx, hence no permit2 contract approval nor actual allowance Tx/permit2 EIP712 message signed and broadcasted.

See testing in https://gist.github.com/gomesalexandre/6c0b209f940b64a09d726c53ad7f7527

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is looking solid, permit flow is solid.

I noticed one blocking regression whilst testing - on this branch we only seem able to get 0x quotes for the Ethereum chain. See screenshots below (left is this branch, right is production):

Screenshot 2024-10-18 at 16 03 36 Screenshot 2024-10-18 at 16 11 58

Nitpick: the tooltip being after a : is odd:

Screenshot 2024-10-18 at 16 09 46

Copy link
Contributor

@gomesalexandre gomesalexandre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retested locally as a last paranoia pass after last changes and confirmed we're looking good at runtime:

https://gist.github.com/gomesalexandre/ab10310c3aff40bd37c00fb15c3ed4da

One q: re price or quote logic for permit2, but otherwise looks sane to land :fridaydog:

Copy link
Contributor

@0xApotheosis 0xApotheosis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My nitpick feedback was addressed, and I'm putting the quote issues I had down to dev endpoint shenanigans.

gm

@woodenfurniture woodenfurniture merged commit 63ff1f7 into develop Oct 21, 2024
3 checks passed
@woodenfurniture woodenfurniture deleted the permit2 branch October 21, 2024 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants