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

Features/sma 329 improve repo #49

Merged
merged 19 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ artifacts-filtered
account-abstraction
scw-contracts

.DS_Store
yarn-error.log
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint && git add .
yarn lint
66 changes: 66 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Contributing to Biconomy Projects 🚀

First off, thank you for considering contributing to Biconomy! We truly appreciate your effort and contributions from the community are what make Biconomy awesome. 🙌
Aboudjem marked this conversation as resolved.
Show resolved Hide resolved

Your contributions are valued and will help in driving the decentralized web forward.

> If you're passionate about our mission but can't contribute directly, there are other ways to support:
>
> - ⭐ Star our projects on GitHub
> - 🐦 [Tweet about Biconomy](https://twitter.com/biconomy/)
> - 📌 Reference Biconomy in your project's readme
> - 🗣️ Share about Biconomy at meetups or with peers

## Table of Contents

- [Contributing to Biconomy Projects 🚀](#contributing-to-biconomy-projects-)
- [Table of Contents](#table-of-contents)
- [Have a Question?](#have-a-question)
- [Ready to Contribute?](#ready-to-contribute)
- [Legal Notice 📜](#legal-notice-)
- [Reporting Bugs 🐛](#reporting-bugs-)
- [Suggesting Enhancements 💡](#suggesting-enhancements-)
- [First Time Contributing? 🌱](#first-time-contributing-)
- [Improving Documentation 📚](#improving-documentation-)
- [Commit Messages 📝](#commit-messages-)
- [Join Biconomy's Team! 🚀](#join-biconomys-team-)

## Have a Question?

Before reaching out, please ensure you've gone through our [Documentation](https://docs.biconomy.io/). If you still have questions:

1. Search for existing [Issues](https://github.com/bcnmy/scw-contracts/issues) that might answer your question.
2. Check out our [Forum](https://forum.biconomy.io/).
3. Join our [Discord](https://discord.com/invite/biconomy) or [Telegram](https://t.me/biconomy) communities.

If you still need assistance, feel free to open an [Issue](https://github.com/bcnmy/scw-contracts/issues/new) with your question.

## Ready to Contribute?

### Legal Notice 📜

By contributing, you agree that you've authored your contribution and that it can be provided under the project's license.

### Reporting Bugs 🐛

Before submitting a bug report, ensure you're using the latest version and that you've read our [documentation](https://docs.biconomy.io/). If you've identified a bug that hasn't been reported, open a new [Issue](https://github.com/bcnmy/scw-contracts/issues/new) detailing the bug.

### Suggesting Enhancements 💡

Have a feature in mind? First, ensure it aligns with Biconomy's mission and hasn't been suggested before. Then, open an [Issue](https://github.com/bcnmy/scw-contracts/issues/new) to discuss your enhancement.

### First Time Contributing? 🌱

Welcome! We're thrilled to have you. If you're unsure where to start, look for issues labeled `good first issue`.

### Improving Documentation 📚

Good documentation is key! If you spot areas for improvement or errors in our documentation, we'd love your input. If you wish to suggest changes, feel free to raise a PR on our [documentation repository](https://github.com/bcnmy/docs).

### Commit Messages 📝

Ensure your commit messages are clear and descriptive.

## Join Biconomy's Team! 🚀

Interested in joining our mission full-time? Check out our [current job openings](https://jobs.lever.co/biconomy).
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Biconomy

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
107 changes: 53 additions & 54 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,87 +1,86 @@
# biconomy-paymasters
# Biconomy Paymasters 🌐

### Playground for ERC4337 Paymasters built with :heart_eyes: by Biconomy
#### Some examples
Welcome to the `biconomy-paymasters` repository! Paymaster contracts enable seamless transaction fee handling in decentralized applications. 🛠️

1. Singleton Verifying Paymaster: Acts as a sponsorship paymaster and lets Dapps manage deposit without deploying a new one for each Dapp.
## What is Biconomy Paymasters? 🤔
Copy link
Collaborator

Choose a reason for hiding this comment

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

is -> are

would be good to talk about ERC4337 paymasters on the high level maybe with some flow diagrams.

Copy link
Collaborator

Choose a reason for hiding this comment

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


2. Token Paymaster: Extended version of Verifying Paymaster which can accept fees from user by withdrawing ERC20 tokens
Biconomy Paymasters are smart contracts that abstract away the complexity of gas fees for end-users. By utilizing these contracts, developers can offer their users gasless transactions or the ability to pay for gas in ERC20 tokens. 🚀
Copy link
Collaborator

Choose a reason for hiding this comment

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

can just limit to gas abstraction. then talk about kind of paymaster we already have or we plan to have with gas abstraction (how) aspect of each


#### Other WIP
- **Sponsorship Paymaster**: Allows transactions without end-users needing to pay for gas, enhancing UX.
- **Token Paymaster**: Provides the ability to pay for transactions with ERC20 tokens.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe highlight, that users still pay by themselves with token paymaster and token paymaster allows not having native token

Copy link
Collaborator

Choose a reason for hiding this comment

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

nvm, I see that this is explained later


Fiat Paymaster
## Features 🌟

Deposit Paymaster
- Simplified transaction fee handling.
- ERC 4337 Account Abstraction compliant.
- Multi-token support for gas payments.

Custom versions of above Verifying (allow Dapp deposit sponsorship in different tokens) and Token Paymaster (acts as deposit paymaster also)
### ERC20 Token Paymaster

![ERC20 Token Paymaster](./assets/readme/erc20-token-gas-payment-flow.png)

- ERC20 Token Paymaster helps users pay for their transactions using ERC20 tokens.
- Users initiate a transaction using an ERC20 token.
Copy link
Collaborator

Choose a reason for hiding this comment

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

refer to ERC20 paymaster design notion doc

- Paymaster validates the transaction and forwards it to the network while handling necessary fee conversions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Technically Paymaster doesn't forward the transaction. It just pays for the userOp.

- This flow ensures ease of use and convenience for users.

# How to run the project
### Sponsorship Paymaster

#### You're going to need to place a private key in a .env file in the root. ####
![Sponsorship Paymaster](./assets/readme/paymaster-off-chain-request-processing-flow.png)

#### In order to add/udpate git submodule account-abstraction: ####
.gitmodules file is already added. two submodules are being used in this project
- Sponsorship Paymaster covers transaction fees for users.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest changing txns to userOps everywhere

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe I'm missing something, but I find it a bit confusing, that we have it named 'Sponsorship Paymaster', however I can't find Sponsorship Paymaster in the repo.
I understand Verifying Paymaster is not the best name, Sponsorship Paymaster is much better , but I think need some consistency between readme and file names here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right @filmakarov, I found the references to 'Sponsorship Paymaster' in both Biconomy blog and official documentation.

I agree 'Sponsorship Paymaster' sounds like a better name to me too. Let's bring this up with the team for further discussion.

- The process starts with the user initiating a transaction.
- Paymaster takes over and sponsors the fees, so users don't have to bear the gas costs.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we describe that to sponsor a userOp, paymaster still needs signature by verifying party that reviews userOps before agreeing to pay for it

- This ensures that the transaction is confirmed on the network.

git submodule update --init (This command will initialize and fetch the submodules listed in the .gitmodules file.)
## Getting Started 🏁

git submodule update --remote (This will update the submodules to the latest commit in their respective repositories.)
To set up and use the Biconomy Paymasters, you'll need to have Node.js, Yarn, Hardhat, and Foundry installed.

you can also alternatively run forge install (or forge install <repo_url>)
### Prerequisites 📋

If you encounter any issues during the submodule update process, you can try deleting the submodules directory and then running the git submodule update --init command again.
Make sure you have Node.js and Yarn installed. You will also need to install Foundry for smart contract development with Solidity.

#### If you face below error, make sure typechain artifacts are generated in account-abstraction folder. ####
Error: Cannot find module '../typechain'
### Installation 📦

cd lib/account-abstraction
yarn
npx hardhat compile
Clone the repository and install the dependencies with `yarn`:

```bash
git clone https://github.com/bcnmy/biconomy-paymasters.git
cd biconomy-paymasters
yarn install
```

### Building the Project 🏗️

Compile your smart contracts and generate typechain artifacts:

This project demonstrates an advanced Hardhat use case, integrating other tools commonly used alongside Hardhat in the ecosystem. Foundry support is also added.
```bash
yarn build
```

Try running some of the following tasks:
### Running Tests 🧪

```shell
forge build --via-ir
After building, run your tests to ensure everything is working correctly:

npx hardhat accounts
npx hardhat compile
npx hardhat clean
npx hardhat test
npx hardhat node
npx hardhat help
REPORT_GAS=true npx hardhat test
npx hardhat coverage
npx hardhat run scripts/deploy.ts
TS_NODE_FILES=true npx ts-node scripts/deploy.ts
npx eslint '**/*.{js,ts}'
npx eslint '**/*.{js,ts}' --fix
npx prettier '**/*.{json,sol,md}' --check
npx prettier '**/*.{json,sol,md}' --write
npx solhint 'contracts/**/*.sol'
npx solhint 'contracts/**/*.sol' --fix
```bash
yarn test
```

# Etherscan verification
This will run both Hardhat and Foundry tests as specified in your `package.json` scripts.

To try out Etherscan verification, you first need to deploy a contract to an Ethereum network that's supported by Etherscan, such as Ropsten.
## Documentation 📚

In this project, copy the .env.example file to a file named .env, and then edit it to fill in the details. Enter your Etherscan API key, your Ropsten node URL (eg from Alchemy), and the private key of the account which will send the deployment transaction. With a valid .env file in place, first deploy your contract:
For more detailed information about Paymasters and how to integrate them into your project, visit the [Biconomy Paymaster Documentation](https://docs.biconomy.io/category/paymaster).

```shell
hardhat run --network polygon_mumbai scripts/deploy.ts
```
## Foundry Installation

Then, copy the deployment address and paste it in to replace `DEPLOYED_CONTRACT_ADDRESS` in this command:
For instructions on how to set up Foundryfollow the instructions provided in the [Foundry Book](https://book.getfoundry.sh/getting-started/installation.html).

```shell
npx hardhat verify --network polygon_mumbai DEPLOYED_CONTRACT_ADDRESS "Hello, Hardhat!"
```
## Contributing 🤝

# Performance optimizations
We welcome contributions from the community. Please take a look at the [guidelines for contributions](./CONTRIBUTING.md).

For faster runs of your tests and scripts, consider skipping ts-node's type checking by setting the environment variable `TS_NODE_TRANSPILE_ONLY` to `1` in hardhat's environment. For more details see [the documentation](https://hardhat.org/guides/typescript.html#performance-optimizations).
## License 📜

This project is licensed under the MIT License. See the [`LICENSE`](./LICENSE.md) file for more information.
Binary file added assets/readme/erc20-token-gas-payment-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added audits/Token Paymaster - Zellic Audit Report.pdf
Binary file not shown.