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(permit): initial flow #3067

Merged
merged 119 commits into from
Sep 21, 2023
Merged

feat(permit): initial flow #3067

merged 119 commits into from
Sep 21, 2023

Conversation

alfetopito
Copy link
Collaborator

@alfetopito alfetopito commented Aug 21, 2023

Summary

Initial implementation of the full flow for permittable tokens

PR will merge onto https://github.com/cowprotocol/cowswap/tree/hack/permit feature branch, safe to merge.

What is included

  • Check token is permittable
    • For COW like tokens
    • On Goerli and Mainnet
  • Cache the result permanently in localStorage
  • Add pre-hook data to quote requests
    • If selected sell token is permittable, generates pre-hook and adds it to quote's request appData
    • This (and the permittable check) uses a fake PK to sign the request so users don't have to sign a msg just for quoting
  • Request permit signature
    • When placing an order with a permittable token for the first time, the permit signature will be requested
    • Right now this signature is stored indefinitely in the browser
  • Add pre-hook data to order
    • Once permit request is signed, the order will contain the pre-hook in its appData

TODOs

  • More testing
  • Continue refactoring
  • Clear debug statements
  • Test with different EOAs (hardware wallets)
  • Address comments

What is NOT included

  • Check token is permittable for DAI and USDC
  • Check token is permittable on Gnosis Chain
  • Detect when permit is expired/invalid
  • Update the permit when expired/invalid
  • Offer permit only when there's not enough allowance
  • Additional UI changes being worked on by Michel

To Test

  1. Connect on goerli with an EOA
  2. Pick COW as the sell token (or UNI, also works)
  3. Make sure to reset your allowance using for example revoke.cash
  4. Pick a buy token
  5. Check the quote requests in the console
  1. Place the order
  • There should be 1 signature requesting the allowance
  1. Sign the permit signature
  • There should be 1 signature for placing the order
  1. Sign the request
  • Order should be placed
  • Order should be matched like usual
  1. Once matched, check the approval for picked sell token on revoke.cash or similar
  • Approval should be set to infinite

shoom3301 and others added 30 commits July 12, 2023 20:01
… hack/permit

# Conflicts:
#	src/legacy/utils/trade.ts
alfetopito and others added 9 commits September 15, 2023 16:15
* feat: add permit tag token selector

* feat: add permit tag token selector

* feat: optimize

* Permit styles [Modal/Stepper/IconSpinner] (#3097)

* feat: updates

* feat: updates

* feat: updates

* feat: updates

* feat: updates

* feat: fix box shadow var

* feat: optimize

* feat: optimize IconSpinner (#3099)

* feat: optimize IconSpinner

* feat: optimize

* feat: add ENUM

* feat: add ENUM (#3110)

* feat: updates

* feat: updates

* feat: updates

* feat: updates

* feat: updates

* feat: fix box shadow var

* feat: optimize

* feat: optimize IconSpinner (#3099)

* feat: optimize IconSpinner

* feat: optimize

* feat: add ENUM

* feat: add ENUM

* feat: add ENUM

* feat: add ENUM usage

* feat: add ENUM usage

* feat: add ENUM usage

* fix: restore yarn.lock to version matching parent branch

* fix: reverted package.json changes as well

* chore: restore once again yarn.lock

* feat: add ENUM usage

* feat: add ENUM usage

---------

Co-authored-by: Alfetopito <[email protected]>

* feat: updates

---------

Co-authored-by: Alfetopito <[email protected]>
…#3103)

* fix: trim eth-flow contract abi json file

* fix(eth-flow): additionally check eth-flow order id in smart-contract

* chore: remove unused ABI

* chore: rename checkEthFlowOrderExists
* fix: handle individual token price query failure

* chore: processQueue will no longer throw

* chore: remove resetAtom as it's no longer used
* chore: update the quote if appData changes

* chore: refactor useEnoughBalanceAndAllowance to return balance/alloance results separately

* chore: propage hasEnoughAllowance to swapFlow

* refactor: rename addHooksToAppData to updateHooksOnAppData and remove hooks when unset

* chore: only add hooks to order when needed, and remove when not needed

* chore: show approval status now includes permittable tokens

* chore: hasEnoughAllowance can be undefined

* Revert "refactor: make PERMIT_GAS_LIMIT_MIN a single const rather than an obj with repeated values"

This reverts commit fbddd09.

* chore: reduce gas limit min for Goerli to 36k down from 55k

* refactor: move default to constant

* fix: rework request caching to prevent caching failed promises

* chore: calculate gasLimit again using the account address

* chore: hardcode gas limit to 80k
* chore: add feature flags hook useIsPermitEnabled

* feat: do not query/return any result when permit is not enabled
* feat: use estimated gasLimit for quotes if higher than default

* chore: add 10% to quote gas limit estimation for additional wiggle room

* chore: estimate gas for real accounts also, but without extra 10%

* chore: use a new empty private key for estimating the permits
@alfetopito alfetopito merged commit d62b7f4 into develop Sep 21, 2023
@alfetopito alfetopito deleted the hack/permit-3 branch September 21, 2023 13:31
@github-actions github-actions bot locked and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants