Giter Club home page Giter Club logo

paymaster-examples's Introduction

Paymaster Examples Repository ๐Ÿ“

Welcome to the world of Paymasters!! ๐ŸŽ‰ ๐ŸŒ ๐ŸŽ‰

โš ๏ธ Work in Progress: Please note that none of the contracts in this repository have been fully audited or extensively tested. These contracts are examples and, therefore, are not designed for production use.

This repository houses a variety of example Paymaster Contracts demonstrating different use cases. Plus, a user-friendly, configurable frontend to interact with these examples, developed using React and Next.js.

Repository structure ๐Ÿ—๏ธ

The repository is divided into two main sections:

  • /contracts: This directory contains the smart contracts, where each sub-directory represents a unique Paymaster use case.

  • /frontend: This directory hosts the frontend developed using React and Next.js. The frontend allows you to interact with the various Paymaster contracts provided.

Commands ๐Ÿ’ป

Here are some useful commands to get started:

  • yarn compile:contracts: Compiles the contracts.
  • yarn deploy:contracts: This command deploys contracts. Scripts for deployment can be found in the /contracts/deploy directory.
  • yarn test:contracts: Runs contract tests. Please ensure to check the test requirements in /contracts directory.
  • yarn serve:ui: Serves up frontend on localhost:3000
  • yarn format: Runs prettier formatter.

Have a request? ๐Ÿ™‹โ€โ™€๏ธ

Do you want to see a specific type of Paymaster contract included in this repository? Head over to the zkync-developers/discussions and tell us about it! We highly value your feedback and are always open to new ideas for showcasing different use-cases and techniques.

Contributing ๐Ÿ™‹โ€โ™‚๏ธ

We welcome all contributors! If you're interested in contributing to this project, please review the CONTRIBUTING guide but for a quick summary:

  1. Fork the repository
  2. Create a new branch for your changes
  3. Implement your changes and commit them
  4. Push your changes to your fork
  5. Submit a pull request to the main repository

Your contribution will be reviewed and, if it's beneficial to the project, merged into the main branch. Thank you for your interest in our project!

Official links ๐Ÿ”—

paymaster-examples's People

Contributors

albionahoti avatar dutterbutter avatar hoshiyari420 avatar idea404 avatar martinkong1990 avatar mexicanace avatar phureewat29 avatar uf4no avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

paymaster-examples's Issues

Add an `ERC20gatedPaymaster` contract

Paymaster Description

Objective: Implement an ERC20GatedPaymaster that covers gas fees for users based on their possession of a specific ERC20 token.

Functionality:

  • Before agreeing to pay the gas fee, the ERC20GatedPaymaster will verify if the user holds a certain ERC20 token in their account.
  • The user must have a balance greater than 0 of the specified ERC20 token to be eligible.
  • If eligible, the paymaster will cover the corresponding gas fees for the user's transaction.

Rationale

  1. Extended Utility for Tokens: This paymaster concept augments the utility of governance tokens and other ERC20 tokens. Token holders can engage in platform activities without the concern of gas fees.
  2. Innovative Use Cases: Projects can incentivize their communities to hold onto their tokens by offering gas-free transactions.
  3. Ease of Adoption: With the proliferation of ERC20 tokens in various projects, a ready-to-use ERC20GatedPaymaster can easily be adopted and integrated, making it a valuable tool for numerous projects.

Additional Information

  • Extending Considerations: While the primary check is for a non-zero balance, the contract can potentially be extended to require minimum token thresholds for different tiers of gas fee coverage.

Task deliverable

  • Adds ERC20GatedPaymaster contract
  • Add to the UI integration
  • Add unit tests
  • Updates readmes

Add a SignatureBasedPaymaster contract

Paymaster Description

Objective: Implement aSignatureBasedPaymaster contract that covers gas fees for users based on valid signature provided by the signer of the paymaster contract.

Rationale

  1. Enhanced user flexibility : Current gated examples Allowlist,ERC20Fixed,ERC721Gated require owner of the paymaster to perform a certain type of on-chain transactions such as setBatchAllowance() in Allowlist, Transferring ERC20 token to user, Transferring ERC721 token to user etc. However, SignatureBasedPaymaster eliminates the necessity for pre-transaction and post-transaction requirements, thus making it more flexible.

  2. Efficient short term use : New users onboarding without on-chain transactions from owner providing a one-time speedy and hassle-free process.

  3. Secure personalised paymasters : A personalised paymaster that takes care of gas fees of all the user's related addresses with simple off-chain signatures. An application can be build over this use-case; thus expanding mainstream paymaster services.

Additional Information

Functionality:

  • This paymaster contract shall validate based on the signature provided through innerInputs whether or not the user's transaction shall be allowed to proceed or not.
  • The signer shall have authority to ensure signature is only valid upto particular timestamp.
  • The signature shall be EIP712 compliance which is signed on values like (user address, last timestamp, nonces).
  • Users are required to provide certain inputs such as signature and last timestamp as innerInputs in paymaster params.
  • The paymaster will then check signature based on transaction.from, block.timestamp and nonces to ensure only valid users are allowed to use paymaster.

Security Considerations:

  • Paymaster should use nonce for every user in validating signatures which increments on every successful transactions.
  • Paymaster should check expiry timestamp of signatures.
  • Paymaster should validate signatures based on transaction.from to ensure correct user has sent transaction.
  • Paymaster should revert if recovered signer does not match or signature expires.
  • Owner can update the paymaster signer.
  • Owner should be able to cancel any user's nonce.
  • EIP712 compliance signatures support.
  • Use of battle-tested standard libraries for ECDSA signature verification (Openzeppelin)

Are you willing to write the paymaster contract?

Yes. Completed below deliverable tasks at PR-22:

  • Add SignatureBasedPaymaster contract
  • Add unit testing, deploy scripts
  • Update readme.
  • Update UI (needs more discussion)

Sample deployment on mainnet

Add a `wETHApprovalBasedPaymaster` contract

Paymaster Description

Objective:

To create a paymaster that facilitates the payment of transaction fees in wETH (wrapped Eth) using the ApprovalBased flow.

Functionality:

  1. Paymaster Role: The paymaster should sponsor transactions for users, enabling them to pay transaction fees in wETH.
  2. Approval-Based Flow: Implement the ApprovalBased paymaster flow, which requires users to set a certain allowance for the paymaster to operate. The paymaster should ensure that the provided allowance is sufficient for the transaction fees.

Rationale:

Creating a paymaster that pays fees in wETH, we can enhance user experience, security, and flexibility, promoting broader adoption of zkSync's advanced features.

Task Deliverables:

  • Paymaster implementation: Develop and test the paymaster that pays fees in wETH using the ApprovalBased flow.
  • Documentation: Provide detailed documentation on how the paymaster works, how to integrate it, and any prerequisites required.
  • Test Cases: Implement test cases to ensure the paymaster functions as expected and handles edge cases.
  • Update readme: Update the readme to reflect new example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.