Skip to content

Commit

Permalink
deposit paymaster fund before spinning up server
Browse files Browse the repository at this point in the history
  • Loading branch information
eerkaijun committed Jan 14, 2024
1 parent b9ba11b commit a1208ce
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
7 changes: 7 additions & 0 deletions account_abstraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,15 @@ def start_paymaster(config: Config):
"SIMPLE_ACCOUNT_FACTORY_ADDRESS": simple_account_factory_address,
"PAYMASTER_ADDRESS": paymaster_address,
"TIME_VALIDITY": str(config.paymaster_validity),
"INITIAL_DEPOSIT": config.paymaster_initial_deposit,
"PRIVATE_KEY": config.paymaster_key}

lib.run(
"deposit initial funds for paymaster",
command=deps.cmd_with_node("pnpm run deposit"),
cwd="paymaster",
env=env)

# start paymaster signer service
log_file_path = f"{config.logs_dir}/paymaster_signer.log"
log_file = open(log_file_path, "w")
Expand Down
5 changes: 5 additions & 0 deletions config/account_abstraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ class AccountAbstractionConfig:
def __init__(self):
super().__init__()

self.paymaster_initial_deposit = "3"
"""
Initial deposit amount (in Ether) for the paymaster contract.
"""

self.paymaster_validity = 300
"""
Time validity (in seconds) for the sponsored transaction that is signed by paymaster.
Expand Down
1 change: 1 addition & 0 deletions paymaster/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"deposit": "npx ts-node script/deposit.ts",
"start": "tsc && node dist/src/server.js",
"test": "npx ts-node test/tests.ts"
},
Expand Down
26 changes: 26 additions & 0 deletions paymaster/script/deposit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ethers } from 'ethers';
import dotenv from 'dotenv';
import { paymasterAbi } from '../src/abis';
dotenv.config();

async function main() {
const depositAmount = process.env.INITIAL_DEPOSIT as string;
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL as string);
const signer = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);

// Paymaster first needs to have funds in Entrypoint contract
const paymasterAddress = process.env.PAYMASTER_ADDRESS as string;
const paymaster = new ethers.Contract(
paymasterAddress,
paymasterAbi,
signer
);

// Deposit
await (await paymaster.deposit({ value: ethers.parseEther(depositAmount)})).wait();
await (await paymaster.addStake(3000, { value: ethers.parseEther(depositAmount)})).wait();

console.log("Deposit funds successful!");
}

main();
6 changes: 2 additions & 4 deletions paymaster/test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@ async function main() {
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL as string);
const signer = new ethers.Wallet(process.env.PRIVATE_KEY as string, provider);

// Paymaster first needs to have funds in Entrypoint contract
// Initialize paymaster contract
const paymasterAddress = process.env.PAYMASTER_ADDRESS as string;
const paymaster = new ethers.Contract(
paymasterAddress,
paymasterAbi,
signer
provider
);
await (await paymaster.deposit({ value: ethers.parseEther('3')})).wait();
await (await paymaster.addStake(3000, { value: ethers.parseEther('3')})).wait();

// Generate initcode
const simpleAccountFactoryAddress = process.env.SIMPLE_ACCOUNT_FACTORY_ADDRESS as string;
Expand Down

0 comments on commit a1208ce

Please sign in to comment.