Skip to content

Commit

Permalink
Merge pull request #677 from bcnmy/feature/new-user-op
Browse files Browse the repository at this point in the history
feat: new userOp structure for EPv0.7
  • Loading branch information
veljkovranic authored Sep 11, 2024
2 parents 8e63592 + f423c0f commit a0a0ad1
Show file tree
Hide file tree
Showing 51 changed files with 1,307 additions and 282 deletions.
20 changes: 17 additions & 3 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
5003, 100, 10200, 195, 196, 2810, 997, 713715, 3799, 167009, 80084, 5845,
167000, 1328, 1329
],
"supportedNetworksV07": [
84532
],
"EIP1559SupportedNetworks": [
1, 137, 42161, 10, 43114, 43113, 8453, 59140, 59144, 204, 5611, 421614,
11155111, 84532, 168587773, 80085, 81457, 42170, 169, 56400, 11155420,
Expand Down Expand Up @@ -119,6 +122,12 @@
"url": "https://rpc.ankr.com/blast_testnet_sepolia/0f2ac70eb2e86d935951e9d3874deeb44525123a1ce2a7cf609cf1f0a098d2d6",
"type": "private"
}
],
"84532": [
{
"url": "https://sepolia.base.org",
"type": "public"
}
]
},
"currency": {
Expand Down Expand Up @@ -904,6 +913,11 @@
"supportedChainIds": [84532]
}
},
"entryPointV07Data": {
"0x0000000071727De22E5E9d8BAf0edAc6f37da032": {
"supportedChainIds": [84532]
}
},
"zeroAddress": "0x0000000000000000000000000000000000000000",
"l2Networks": [42161, 42170],
"polygonZKEvmNetworks": [1101, 2442, 195, 196],
Expand Down Expand Up @@ -989,9 +1003,9 @@
},
"hardcodedGasLimits": {
"84532": {
"verificationGasLimit": 50000000,
"callGasLimit": 50000000,
"preVerificationGasLimit": 50000000
"verificationGasLimit": 2000000,
"callGasLimit": 2000000,
"preVerificationGas": 45000000
}
}
}
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ services:
condition: service_started
redis:
condition: service_healthy
restart: true
#restart: true
rabbitmq:
condition: service_healthy
restart: true
#restart: true
# centrifugo:
# condition: service_healthy
# restart: true
Expand Down
99 changes: 99 additions & 0 deletions src/common/db/dao/UserOperationV07DAO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import {
FinalUserOperationDataType,
IUserOperationV07DAO,
InitialUserOperationV07DataType,
} from "../interface";
import { IUserOperationV07, Mongo } from "../mongo";

export class UserOperationV07DAO implements IUserOperationV07DAO {
private _db: Mongo;

constructor() {
this._db = Mongo.getInstance();
}

async save(
chainId: number,
userOperationData: InitialUserOperationV07DataType,
): Promise<void> {
await this._db.getUserOperationV07(chainId).insertMany([userOperationData]);
}

async getUserOperationsDataByApiKey(
chainId: number,
bundlerApiKey: string,
startTime: number,
endTime: number,
limit: number,
offSet: number,
): Promise<Array<IUserOperationV07>> {
const data = await this._db
.getUserOperationV07(chainId)
.aggregate([
{
$match: {
$and: [
{ "metaData.dappAPIKey": bundlerApiKey },
{ creationTime: { $gte: startTime } },
{ creationTime: { $lte: endTime } },
],
},
},
])
.skip(offSet)
.limit(limit);
return data;
}

async getUserOperationDataByUserOpHash(
chainId: number,
userOpHash: string,
): Promise<IUserOperationV07 | null> {
const data = await this._db
.getUserOperationV07(chainId)
.findOne({ userOpHash });
return data;
}

async updateUserOpDataToDatabaseByTransactionIdAndUserOpHash(
chainId: number,
transactionId: string,
userOpHash: string,
userOperationData: FinalUserOperationDataType,
): Promise<void> {
await this._db.getUserOperationV07(chainId).updateOne(
{
transactionId,
userOpHash,
},
userOperationData,
);
}

async getUserOpsByTransactionId(
chainId: number,
transactionId: string,
): Promise<IUserOperationV07[]> {
const data = await this._db
.getUserOperationV07(chainId)
.find({
transactionId,
})
.sort({ _id: -1 })
.lean();
return data;
}

async getUserOperationsCountByApiKey(
chainId: number,
bundlerApiKey: string,
startTime: number,
endTime: number,
): Promise<number> {
const data = await this._db.getUserOperationV07(chainId).count({
"metaData.dappAPIKey": bundlerApiKey,
creationTime: { $gte: startTime, $lte: endTime },
});
return data;
}
}
1 change: 1 addition & 0 deletions src/common/db/dao/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./TransactionDAO";
export * from "./UserOperationDAO";
export * from "./UserOperationStateDAO";
export * from "./UserOperationV07DAO";
4 changes: 2 additions & 2 deletions src/common/db/interface/IUserOperationDAO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ export type InitialUserOperationDataType = {
dappAPIKey?: string;
entryPoint: string;
sender: string;
nonce: number;
initCode: string;
nonce: number;
callData: string;
callGasLimit: number;
verificationGasLimit: number;
preVerificationGas: number;
maxFeePerGas: number;
maxPriorityFeePerGas: number;
paymasterAndData: string;
signature: string;
userOpHash: string;
chainId: number;
status: string;
paymaster: string;
paymasterAndData: string;
creationTime: number;
metaData?: object;
};
Expand Down
75 changes: 75 additions & 0 deletions src/common/db/interface/IUserOperationV07DAO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { IUserOperationV07 } from "../mongo/interface";

export type InitialUserOperationV07DataType = {
transactionId: string;
dappAPIKey?: string;
entryPoint: string;
sender: string;
nonce: number;
callData: string;
callGasLimit: number;
verificationGasLimit: number;
preVerificationGas: number;
maxFeePerGas: number;
maxPriorityFeePerGas: number;
signature: string;
userOpHash: string;
chainId: number;
status: string;
paymaster: string;
paymasterVerificationGasLimit: number;
paymasterPostOpGasLimit: number;
factory: string;
factoryData: string;
paymasterData: string;
creationTime: number;
metaData?: object;
};

export type FinalUserOperationV07DataType = {
transactionHash?: string;
receipt: object;
status: string;
success: string;
blockNumber: number;
blockHash: string;
actualGasCost: number;
actualGasUsed: number;
reason: string;
logs: any;
};

export interface IUserOperationV07DAO {
save(
chainId: number,
initialUserOperationData: InitialUserOperationV07DataType,
): Promise<void>;
getUserOperationDataByUserOpHash(
chainId: number,
userOpHash: string,
): Promise<IUserOperationV07 | null>;
updateUserOpDataToDatabaseByTransactionIdAndUserOpHash(
chainId: number,
userOpHash: string,
transactionId: string,
initialUserOperationData: FinalUserOperationV07DataType,
): Promise<void>;
getUserOpsByTransactionId(
chainId: number,
transactionId: string,
): Promise<IUserOperationV07[]>;
getUserOperationsDataByApiKey(
chainId: number,
bundlerApiKey: string,
startTime: number,
endTime: number,
limit: number,
offSet: number,
): Promise<Array<IUserOperationV07>>;
getUserOperationsCountByApiKey(
chainId: number,
bundlerApiKey: string,
startTime: number,
endTime: number,
): Promise<number>;
}
1 change: 1 addition & 0 deletions src/common/db/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./IDBService";
export * from "./ITransactionDAO";
export * from "./IUserOperationDAO";
export * from "./IUserOperationV07DAO";
export * from "./IUserOperationStateDAO";
18 changes: 17 additions & 1 deletion src/common/db/mongo/Mongo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
UserOperationsMapType,
UserOperationsStateMap,
UserOperationsStateMapType,
UserOperationsV07Map,
UserOperationsV07MapType,
} from "./models";

const log = logger.child({
Expand Down Expand Up @@ -147,7 +149,6 @@ export class Mongo implements IDBService {
dbName: "relayer-node-service",
});
}
log.info("Connected to db");
} catch (error) {
log.error("error while connecting to mongo db");
log.error(error);
Expand Down Expand Up @@ -186,6 +187,21 @@ export class Mongo implements IDBService {
return UserOperationsMap[networkId];
}

/**
* Method returns user operation model for a given chain id
* @param networkId
* @returns user operation model for a given chain id
*/
getUserOperationV07(networkId: number): UserOperationsV07MapType[number] {
if (!this.client) {
throw new Error("Not connected to db");
}
const supportedNetworksV07: number[] = config.supportedNetworksV07 || [];
if (!supportedNetworksV07.includes(networkId))
throw new Error(`Network Id ${networkId} is not supported`);
return UserOperationsV07Map[networkId];
}

/**
* Method returns user operation state model for a given chain id
* @param networkId
Expand Down
2 changes: 1 addition & 1 deletion src/common/db/mongo/interface/IUserOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export interface IUserOperation {
creationTime: number;
metaData: object;
dappAPIKey: string;
}
}
31 changes: 31 additions & 0 deletions src/common/db/mongo/interface/IUserOperationV07.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export interface IUserOperationV07 {
transactionId: string;
transactionHash: string;
entryPoint: string;
sender: string;
nonce: number;
factory: string;
factoryData: string,
callData: string;
callGasLimit: number;
verificationGasLimit: number;
preVerificationGas: number;
maxFeePerGas: number;
maxPriorityFeePerGas: number;
signature: string;
userOpHash: string;
receipt: object;
chainId: number;
status: string;
success: string;
blockNumber: number;
blockHash: string;
paymaster: string;
actualGasCost: number;
actualGasUsed: number;
reason: string;
logs: object;
creationTime: number;
metaData: object;
dappAPIKey: string;
}
1 change: 1 addition & 0 deletions src/common/db/mongo/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./IBlockchainTransaction";
export * from "./IUserOperation";
export * from "./IUserOperationState";
export * from "./IUserOperationV07";
21 changes: 17 additions & 4 deletions src/common/db/mongo/models/user-operations/model.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import mongoose from "mongoose";
import { config } from "../../../../../config";
import { IUserOperation } from "../../interface";
import { UserOperationSchema } from "./schema";
import { IUserOperation, IUserOperationV07 } from "../../interface";
import { UserOperationSchema, UserOperationV07Schema } from "./schema";

const { supportedNetworks } = config;
const { supportedNetworks, supportedNetworksV07 } = config;

export type UserOperationsMapType = {
[networkId: number]: mongoose.Model<IUserOperation, {}, {}, {}>;
};

export type UserOperationsV07MapType = {
[networkId: number]: mongoose.Model<IUserOperationV07, {}, {}, {}>;
};

const UserOperationsMap: UserOperationsMapType = {};
const UserOperationsV07Map: UserOperationsV07MapType = {};

for (const networkId of supportedNetworks) {
const collectionName = `UserOperations_${networkId}`;
Expand All @@ -19,4 +24,12 @@ for (const networkId of supportedNetworks) {
);
}

export { UserOperationsMap };
for (const networkId of supportedNetworksV07) {
const collectionNameV07 = `UserOperationsV07_${networkId}`;
UserOperationsV07Map[networkId] = mongoose.model(
collectionNameV07,
UserOperationV07Schema,
);
}

export { UserOperationsMap, UserOperationsV07Map };
Loading

0 comments on commit a0a0ad1

Please sign in to comment.