Skip to content

Commit

Permalink
feat: [email protected] (refactored PackedUserOp)
Browse files Browse the repository at this point in the history
  • Loading branch information
pegahcarter committed Mar 15, 2024
1 parent 53a029e commit d90be9e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
10 changes: 4 additions & 6 deletions paymaster/src/rpcMethods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@ import { whitelistAll, whitelistedAddresses } from './config';
import dotenv from 'dotenv';
dotenv.config();

export interface UserOperation {
export interface PackedUserOperation {
sender: string
nonce: BigNumberish
initCode: BytesLike
callData: BytesLike
callGasLimit: BigNumberish
verificationGasLimit: BigNumberish
accountGasLimits: BytesLike
preVerificationGas: BigNumberish
maxFeePerGas: BigNumberish
maxPriorityFeePerGas: BigNumberish
gasFees: BytesLike
paymasterAndData: BytesLike
signature: BytesLike
}

export async function sponsorTransaction(userOp: UserOperation): Promise<UserOperation> {
export async function sponsorTransaction(userOp: PackedUserOperation): Promise<PackedUserOperation> {
const paymasterAddress = process.env.PAYMASTER_ADDRESS as string;
const provider = new ethers.JsonRpcProvider(process.env.RPC_URL as string);
const signer = new ethers.Wallet(process.env.PRIVATE_KEY as string);
Expand Down
4 changes: 2 additions & 2 deletions paymaster/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import express, { Express, Request, Response } from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import { sponsorTransaction, UserOperation } from './rpcMethods';
import { sponsorTransaction, PackedUserOperation } from './rpcMethods';

type JsonRpcRequestBody = {
id: number;
method: string;
params: UserOperation;
params: PackedUserOperation;
};

const app: Express = express();
Expand Down
16 changes: 10 additions & 6 deletions paymaster/test/tests.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers';
import dotenv from 'dotenv';
import axios from 'axios';
import { UserOperation } from '../src/rpcMethods';
import { PackedUserOperation } from '../src/rpcMethods';
import { simpleAccountAbi, simpleAccountFactoryAbi, paymasterAbi, entrypointAbi } from '../src/abis';
dotenv.config();

Expand Down Expand Up @@ -42,16 +42,20 @@ async function main() {
const callData = simpleAccount.interface.encodeFunctionData("execute", [to, value, data]);

// Construct UserOp
let userOp: UserOperation = {
let userOp: PackedUserOperation = {
sender: simpleAccountAddress,
nonce: Number(await paymaster.senderNonce(simpleAccountAddress)),
initCode: initCode,
callData: callData,
callGasLimit: ethers.toBeHex(3_000_000), // hardcode it for now at a high value,
verificationGasLimit: ethers.toBeHex(3_000_000), // hardcode it for now at a high value,
accountGasLimits: ethers.concat([
ethers.toBeHex(3_000_000), // callGasLimit: hardcode it for now at a high value,
ethers.toBeHex(3_000_000) // verificationGasLimit: hardcode it for now at a high value,
]),
preVerificationGas: ethers.toBeHex(2_000_000), // hardcode it for now at a high value,
maxFeePerGas: ethers.toBeHex(2e9),
maxPriorityFeePerGas: ethers.toBeHex(1e9),
gasFees: ethers.concat([
ethers.toBeHex(2e9), // maxFeePerGas
ethers.toBeHex(1e9) // maxPriorityFeePerGas
]),
paymasterAndData: ethers.concat([
paymasterAddress,
'0x' + '00'.repeat(64),
Expand Down

0 comments on commit d90be9e

Please sign in to comment.