Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zZoMROT committed Aug 22, 2023
0 parents commit 60d18b6
Show file tree
Hide file tree
Showing 32 changed files with 12,537 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Editor configuration, see https://editorconfig.org
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.yaml]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules/
truffle-config.js
js/
coverage/
52 changes: 52 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"extends" : [
"standard",
"plugin:promise/recommended"
],
"plugins": [
"promise"
],
"env": {
"browser" : true,
"node" : true,
"mocha" : true,
"jest" : true
},
"globals" : {
"artifacts": false,
"contract": false,
"assert": false,
"web3": false
},
"rules": {

// Strict mode
"strict": [2, "global"],

// Code style
"indent": [2, 4],
"quotes": [2, "single"],
"semi": ["error", "always"],
"space-before-function-paren": ["error", "always"],
"no-use-before-define": 0,
"no-unused-expressions": "off",
"eqeqeq": [2, "smart"],
"dot-notation": [2, {"allowKeywords": true, "allowPattern": ""}],
"no-redeclare": [2, {"builtinGlobals": true}],
"no-trailing-spaces": [2, { "skipBlankLines": true }],
"eol-last": 1,
"comma-spacing": [2, {"before": false, "after": true}],
"camelcase": [2, {"properties": "always"}],
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"comma-dangle": [1, "always-multiline"],
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-debugger": 0,
"no-undef": 2,
"object-curly-spacing": [2, "always"],
"max-len": [2, 200, 2],
"generator-star-spacing": ["error", "before"],
"promise/avoid-new": 0,
"promise/always-return": 0
}
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.sol linguist-language=Solidity
44 changes: 44 additions & 0 deletions .github/1inch_github_b.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 44 additions & 0 deletions .github/1inch_github_w.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions .github/actions/docker-image-cacher/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Docker Image Cacher

runs:
using: composite
steps:
# Cache Docker layers
- uses: actions/cache@v2
with:
path: /tmp/docker-save
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-
# Load Docker image from cache
- run: |
if [ -f /tmp/docker-save/image.tar ]; then
docker load -i /tmp/docker-save/image.tar
fi
shell: bash
# Save Docker image
- run: |
if [ ! -f /tmp/docker-save/image.tar ]; then
docker pull zzomrot/zksync-era-test-node-amd64:latest
mkdir -p /tmp/docker-save
docker save -o /tmp/docker-save/image.tar zzomrot/zksync-era-test-node-amd64:latest
fi
shell: bash
12 changes: 12 additions & 0 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Setup

runs:
using: composite
steps:
- uses: actions/setup-node@v3
with:
node-version: 18.15
cache: 'yarn'

- run: yarn
shell: bash
57 changes: 57 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: CI

on:
push:
branches: [ master ]
pull_request:

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- run: yarn lint

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/setup
- uses: ./.github/actions/docker-image-cacher

- name: Start era-test-node
run: |
docker run -d --name era-test-node -p 8011:8011 zzomrot/zksync-era-test-node-amd64:latest
sleep 10
- run: yarn test:fork
env:
ZKSYNC_PRIVATE_KEY: ${{ secrets.ZKSYNC_PRIVATE_KEY }}
ZKSYNC_WEB3_API_URL: ${{ secrets.ZKSYNC_WEB3_API_URL }}

- name: Stop era-test-node
run: docker stop era-test-node

# https://github.com/matter-labs/hardhat-zksync/issues/99
# coverage:
# runs-on: ubuntu-latest

# steps:
# - uses: actions/checkout@v3
# - uses: ./.github/actions/setup
# - uses: ./.github/actions/docker-image-cacher

# - name: Start era-test-node
# run: |
# docker run -d --name era-test-node -p 8011:8011 zzomrot/zksync-era-test-node-amd64:latest
# sleep 10

# - run: yarn coverage --network zksyncFork
# env:
# ZKSYNC_PRIVATE_KEY: ${{ secrets.ZKSYNC_PRIVATE_KEY }}

# - name: Stop era-test-node
# run: docker stop era-test-node

# - uses: codecov/codecov-action@v3
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
node_modules
coverage
hardhat-dependency-compiler
coverage.json
build
artifacts
artifacts-zk
cache
cache-zk
solcinputs
.idea
.env
27 changes: 27 additions & 0 deletions .solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
configureYulOptimizer: true,
solcOptimizerDetails: {
constantOptimizer: true,
yul: true,
yulDetails: {
optimizerSteps:
"dhfoDgvlfnTUtnIf" + // None of these can make stack problems worse
"[" +
"xa[r]EsLM" + // Turn into SSA and simplify
"CTUtTOntnfDIl" + // Perform structural simplification
"Ll" + // Simplify again
"Vl [j]" + // Reverse SSA

// should have good "compilability" property here.

"Tpel" + // Run functional expression inliner
"xa[rl]" + // Prune a bit more in SSA
"xa[r]L" + // Turn into SSA again and simplify
"gvf" + // Run full inliner
"CTUa[r]LSsTFOtfDna[r]Il" + // SSA plus simplify
"]" +
"jml[jl] VTOl jml : fDnTO",
},
},
skipFiles: ['mocks', 'interfaces'],
}
18 changes: 18 additions & 0 deletions .solhint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "solhint:recommended",
"rules": {
"not-rely-on-time": "off",
"no-global-import": "off",
"compiler-version": [
"error",
"0.8.20"
],
"private-vars-leading-underscore": "error",
"func-visibility": [
"warn",
{
"ignoreConstructors": true
}
]
}
}
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 1inch

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.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<div align="center">
<img src=".github/1inch_github_w.svg#gh-light-mode-only">
<img src=".github/1inch_github_b.svg#gh-dark-mode-only">
</div>

# Paymaster ZkSync

[![Build Status](https://github.com/1inch/paymaster-zksync/workflows/CI/badge.svg)](https://github.com/1inch/paymaster-zksync/actions)

Paymaster - this is a contract designed to pay transaction fees using any tokens through the 1inch. This allows users to pay fees not only in ETH, but also in other tokens, making an automatic exchange for the required amount of ETH in 1inch. This provides more flexible and convenient payment mechanisms for users.

## Contract Overview

- **Purpose**: The contract serves to allow users to execute token transfers or token exchanges while paying for gas fees with tokens instead of ETH.
- **Main Components**:
- `Paymaster`: Manages the fee payment for gas in tokens.
- `Bootloader`: Default management contract for Paymaster functionality in zksync.
- `AggregationRouter`: Responsible for exchange user tokens for gas fee to ETH.

## Setup & Deployment

This repository is designed for demonstration and test purposes and is optimized for use within a ZkSync mainnet fork. However, its applications are not limited to this context.

1. Before you begin, you must be connected to the correct zksync fork node. Detailed instructions can be found at [ZKSync Era Test Node](https://github.com/matter-labs/era-test-node). You need set env variable `process.env.ZKSYNC_WEB3_API_URL` with node url.
```
# Example of ZKSYNC_WEB3_API_URL in .env file
ZKSYNC_WEB3_API_URL=http://localhost:8011
```
2. **Rich Wallet:** To run the test, you'll need an address with a good amount of ETH. These addresses can be found in the logs of the era-test-node. Use it in `process.env.ZKSYNC_PRIVATE_KEY`.
```
# Example of ZKSYNC_PRIVATE_KEY in .env file
ZKSYNC_PRIVATE_KEY=7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110
```

## Testing

**Test Execution:**
```
yarn && yarn test:fork
```

**Main Operations:**
- The test will initialize contracts like `Paymaster`, `AggregationRouter` and various token contracts.
- Tokens will be bought via MuteSwitch exchange.
- A token-to-ETH swap will be simulated to cover the fee payment in the paymaster.
- A main operation of token transfer between two wallets will be conducted.
- At the end, balances of different wallets and tokens are printed and verified.

## Using Paymaster for Your Purposes

You can utilize this Paymaster for any of your needs, not just for transferring tokens from one address to another. Relying on the test, you can build your own calldata for the 1inch AggregationRouter to exchange any tokens for ETH as a transaction fee. The required number of tokens for the exchange should be calculated offchain in advance. Any surplus will be returned to the address in ETH currency.
Loading

0 comments on commit 60d18b6

Please sign in to comment.