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

zkSync updates part 2 #7348

Merged

Conversation

mds1
Copy link
Contributor

@mds1 mds1 commented Sep 10, 2020

Second round of zkSync changes is ready for review. There are a lot of code paths and I've only tested against Rinkeby, so there are almost guaranteed to be some bugs and issues so please report any issues you find while testing this PR.

Changes in this PR are explained below.

Background

There are two zkSync accounts to consider:

  1. gitcoinSyncWallet — A zkSync wallet generated by having the user sign a Gitcoin-specific message. This gives us the private key used to create this deterministic wallet. Since we have the private key, we can send transfers without prompting the user
  2. nominalSyncWallet — The default zkSync wallet generated through the zkSync SDK, using the user's web3 account. We do not have the private key, so the user receives a signature prompt on each transfer

User Flows

Upon clicking "Checkout with zkSync", the flow looks like this:

  1. Does user have sufficient balance in nominalSyncWallet to cover all deposits? If yes, we call this Flow A which only requires signatures and is extremely cheap and fast. If no, we call this Flow B, which requires an L1 transaction so is costly and slow.

  2. Flow A:

    1. Prompt user to sign in to gitcoinSyncWallet (user sees prompt 1)
    2. Prompt user to sign in to nominalSyncWallet (user sees prompt 2)
    3. If user has never used zkSync (e.g. maybe someone sent them funds and they never used it), they see a signature prompt to register their zkSync account (user prompt 3)
    4. Prompt user to transfer funds from nominalSyncWallet to gitcoinSyncWallet (user sees prompts 3 or 4–n, where n = number of different currencies selected in cart)
  3. Flow B:

    1. "Advanced settings" toggle lets users choose to deposit additional funds on top of their donation
    2. Prompt user to sign in to gitcoinSyncWallet (user sees prompt 1)
    3. Prompt user to approve ERC20 tokens (user sees prompts 2–n, where n depends on number of different currencies selected in cart and pre-existing allowances)
    4. Prompt user to deposit funds into zkSync (user sees prompt n+1)
  4. Flows A and B now converge

  5. We sign each donation transfer with the gitcoinSyncWallet (no user prompts)

  6. We dispatch each donation transfer from the gitcoinSyncWallet (no user prompts)

  7. If there are any excess funds left in gitcoinSyncWallet, we transfer them to nominalSyncWallet. (Sometimes there will be dust leftover in gitcoinSyncWallet based on amount packing and fees, but there's not much we can do about this).

Notes

The main remaining tasks for zkSync that are not included in this PR are:

  • Transaction validator must be updated to support Flow A
  • Make gas estimates smarter — for now it's temporarily hardcoded at 1M
  • Make suggestion to user whether to use zkSync vs. L1 depending on balances and estimated gas costs. Our suggestion here cannot be perfect and will be wrong sometimes. This is because we'll only have imperfect gas estimates, but we may be able to tweak this as the round goes on and we get some real data

Also, apologies for the monster that cart.js has become 😅

cc @thelostone-mc @octavioamu @owocki @apbendi

@thelostone-mc thelostone-mc merged commit 5037fb5 into gitcoinco:round-7-integration Sep 10, 2020
thelostone-mc added a commit that referenced this pull request Sep 14, 2020
* Add zkSync Checkout (#7314)

* Integrate minimal working ETH-only zkSync checkout

* Refactor L1 checkout a bit to enable more code re-use with zkSync

* Adds full working checkout flow using localstorage, supports ERC20 + ETH

* Improve checkout UX by adding modal whehn using zkSync

* Warn user before closing or reloading if they started zkSync checkout

* Switch to deterministic from ephemeral wallet, fix allowance bug

Allowance bug info: If user already had sufficient allowance, tokens were not transferred

* Pull out logic into functions to facilitate re-sending on interrupted deposits

* zkSync checkout now POSTs to database and shows success message on completion

* Handle zkSync checkout interruptions

* Fix ESLint errors, add some try/catch blocks

* Fix bug in tx validator that prevented testing on rinkeby

Also some prep and cleanup for tx validator update

* Update tx validator to handle zkSync transfers

* Tweak: Show metamask popup on zkSync checkout prompts

* Only allow zkSync modal to be closed with a button to prevent accidental closures when checking out

* zkSync checkout can now be resumed if interrupted

Adds endpoint to look for dropped and replaced transactions to help with this

* Various UI/UX updates based on Figma mockups

- Update tx processing section of zkSync checkout modal
- Update grant detauls page to show Etherscan and zkScan links
- Add note about supported L2 account types on new grant page

* Update address of batch deposit contract

* Reduce gas by only using batch deposit contract when necessary, regular zkSync contract otherwise

* Now throws error if user tries to use zkSync checkout with unsupported token

* add list view for grants and migrate to vue (#7336)

* add list view for grants and migrate to vue

* hide idle grants by default

* Add contributions on grants

* add my grants

* Minor fix

* Implement follow in vuejs

* remove duplicated ids

Co-authored-by: Aditya Anand M C <aditya.anandmc@gmail.com>

* fixes #7223

* zkSync updates part 2 (#7348)

* Checks and validates cart amounts to ensure they are packable

* Add support for additional deposits. After donations are complete, all leftover balances are sent to user's web3 address

* Update appearance of zkSync modal to match new designs

* Add additional checkout flow to support users who already have a zkSync balance

* Update detail.js

Co-authored-by: Aditya Anand M C <aditya.anandmc@gmail.com>

* updated dates, just in case we got it wrong with db migration

* round up fixes

* fix for the anonymous user issue

* fix up clr info on cards

* show contribution button only if user has logged in

* update icon

* hide browse grants button

* rounding issue

* reload page on switch type/category

* fix grants without round

* fix favorite

* fix component initialization

* eslint fix

* fix grant activity

* sloppy fix

* a few fixes

* add pagination

* readd stuff

* switch btwn rinkeby+mainnet &show sybil info

* Fix my grants and add team members (#7354)

* Grants Round 7 Trust Bonus Improvements (#7353)

* Show SMS on trust bonus page w/ conditional verify button or status

* Add placeholder for twitter verification & handle SMS verification via cart link

* Conditionally show Trust Bonus banner in cart

* Include link in cart trust bonus button + bonus screen touchups

* Increase the size of the BrightID QR Code

* Fix linting indentation error

* fix for loading sidecart

* debounce search

* remove already loaded scripts

* move filter "my grants"

* zkSync updates part 3 (#7356)

* Update tx validator to support zkSync transfers when user already has funds on L2

* Add loading screen to zkSync modal

* Improve gas estimates, recommend checkout approach to user, limit zkSync to 100 contributions

* Change zkSync fees to be additive, show which tokens in cart don't support zkSync

* Fix so all zksync gas limit estimtes are strings

* Bug fixes to cart and tx validator

* Update cart copy and add zkSync details to GRANTS.md

* Update GRANTS.md

* adds grant funding info; per lefteris feedback

* adds grant funding info; per lefteris feedback

* fix for sms verification

* ads trust tab coming soon stuff

* stopgap for #7131 (comment)

* new grants header

* zkSync bug fixes (#7368)

* Fix zkScan URLs

* Ensure default network is mainnet

* Impove how tokens are fetched, close zksync modal on 'insufficient balance' errors

* Bug fix: prevents users from checking out when donation amounts + fees exceed their L1 wallet balance

* matic banner

* round 7 integration; adds brightid events to calenndar

* udpates img

* styles for banners and grid fixes

* Additional cart improvements (#7374)

* Add gas estimation for approval txs

* Fixes for Argent and BN, CSS tweak for mobile

* helper script to re-add team members that were removed by #7319

* updates grant scripts

* adds learn more link

* adds brightID info to sybilscore

* iexact

Co-authored-by: Matt <matt@mattsolomon.dev>
Co-authored-by: Miguel Angel Gordián <miguel@gordian.dev>
Co-authored-by: owocki <ksowocki@gmail.com>
Co-authored-by: octavioamu <octavioamuchastegui@gmail.com>
Co-authored-by: Ben DiFrancesco <ben@scopelift.co>
zoek1 pushed a commit to zoek1/web-1 that referenced this pull request Sep 14, 2020
* Checks and validates cart amounts to ensure they are packable

* Add support for additional deposits. After donations are complete, all leftover balances are sent to user's web3 address

* Update appearance of zkSync modal to match new designs

* Add additional checkout flow to support users who already have a zkSync balance

* Update detail.js

Co-authored-by: Aditya Anand M C <aditya.anandmc@gmail.com>
zoek1 pushed a commit to zoek1/web-1 that referenced this pull request Sep 14, 2020
* Checks and validates cart amounts to ensure they are packable

* Add support for additional deposits. After donations are complete, all leftover balances are sent to user's web3 address

* Update appearance of zkSync modal to match new designs

* Add additional checkout flow to support users who already have a zkSync balance

* Update detail.js

Co-authored-by: Aditya Anand M C <aditya.anandmc@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants