Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
eerkaijun committed Sep 18, 2023
1 parent d173aa2 commit c211fc8
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
22 changes: 6 additions & 16 deletions bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@
from processes import PROCESS_MGR
from config import L2Config

####################################################################################################
# CONSTANTS

# Minimum Go version required by the Stackup bundler.
GO_VERSION = "1.19"

####################################################################################################
# ARGUMENT PARSING

Expand Down Expand Up @@ -110,13 +104,6 @@ def setup_stackup_bundler(config: L2Config):
priv_key = config.bundler_key
lib.run("set private key", f"echo ERC4337_BUNDLER_PRIVATE_KEY={priv_key} >> .env")

# make sure that GOPATH is set in PATH
current_path = os.environ.get("PATH", "")
gopath = subprocess.check_output(["go", "env", "GOPATH"]).decode().strip()
# append the bin directory of GOPATH to PATH
new_path = f"{gopath}/bin:{current_path}"
os.environ["PATH"] = new_path

# start bundler as a persistent process
print("Starting bundler...")
log_file_path = "logs/stackup_bundler.log"
Expand Down Expand Up @@ -163,6 +150,10 @@ def setup_paymaster(config: L2Config):
["grep", '==VerifyingPaymaster addr=', "logs/deploy_4337_contracts.log"]
).decode().strip().split(' ')[-1]
lib.run("set paymaster", f"echo PAYMASTER_ADDRESS={paymaster_address} >> paymaster/.env")
lib.run(
"set sponsored transactions time validity",
f"echo TIME_VALIDITY={config.paymaster_validity} >> paymaster/.env"
)
# set private key for paymaster
if config.deployer_key is None:
priv_key = input("Enter private key for paymaster signer: ")
Expand All @@ -185,9 +176,6 @@ def setup_paymaster(config: L2Config):
)
print("Paymaster service is running!")

# allow background processes to continue running
PROCESS_MGR.wait_all()

####################################################################################################
# CLEANUP

Expand All @@ -209,6 +197,8 @@ def clean():
deps.check_go()
if args.command == "start":
start()
# allow background processes to continue running
PROCESS_MGR.wait_all()
elif args.command == "clean":
clean()

Expand Down
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def __init__(self):
Will be used if set, otherwise will prompt users to enter private key.
"""

self.paymaster_validity = 300
"""
Time validity (in seconds) for the sponsored transaction that is signed by paymaster.
"""

# ==============================================================================================
# Updating / Altering the Configuration

Expand Down
7 changes: 7 additions & 0 deletions deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import shutil
import sys
import subprocess

import libroll as lib
import term
Expand Down Expand Up @@ -72,6 +73,12 @@ def check_go():
f"Go version is too low. Please update to Go **version {GO_VERSION}** or higher.\n"
"Go is backwards compatible, so your old project will continue to build.")

# make sure that GOPATH is set in PATH (this is needed for 4337 bundler)
current_path = os.environ.get("PATH", "")
gopath = subprocess.check_output(["go", "env", "GOPATH"]).decode().strip()
# append the bin directory of GOPATH to PATH
new_path = f"{gopath}/bin:{current_path}"
os.environ["PATH"] = new_path

####################################################################################################

Expand Down
3 changes: 2 additions & 1 deletion paymaster/src/rpcMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ export async function sponsorTransaction(userOp: UserOperation): Promise<UserOpe
const validAfter = (await provider.getBlock('latest'))?.timestamp;
// sanity check for validAfter
if (validAfter === undefined) throw new Error('Could not get latest block timestamp');
const validUntil = validAfter + 300; // 5 minutes
// time validity of 5 minutes by default if not set
const validUntil = validAfter + parseInt(process.env.TIME_VALIDITY ?? '300');
const hash = await paymaster.getHash(userOp, validUntil, validAfter);
const signature = await signer.signMessage(ethers.getBytes(hash));

Expand Down

0 comments on commit c211fc8

Please sign in to comment.