Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new userOp structure for EPv0.7 #677

Merged
merged 8 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 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 @@ -82,6 +85,9 @@
"1328": ["BUNDLER"],
"1329": ["BUNDLER"]
},
"supportedTransactionTypeV07": {
"84532": ["BUNDLER_V3"]
},
"chains": {
"providers": {
"5000": [
Expand Down Expand Up @@ -119,6 +125,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 +916,11 @@
"supportedChainIds": [84532]
}
},
"entryPointV07Data": {
"0x0000000071727De22E5E9d8BAf0edAc6f37da032": {
"supportedChainIds": [84532]
}
},
"zeroAddress": "0x0000000000000000000000000000000000000000",
"l2Networks": [42161, 42170],
"polygonZKEvmNetworks": [1101, 2442, 195, 196],
Expand Down Expand Up @@ -989,9 +1006,9 @@
},
"hardcodedGasLimits": {
"84532": {
"verificationGasLimit": 50000000,
"callGasLimit": 50000000,
"preVerificationGasLimit": 50000000
"verificationGasLimit": 2000000,
"callGasLimit": 2000000,
"preVerificationGas": 2000000
}
}
}
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 } },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you check if we have Mongo indexes on these fields?

It's also a good opportunity to setup a connection to our MongoDB and browse the data if you didn't do it so far.
@TakGN can give you instructions how to connect to the prod database.

{ 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
70 changes: 70 additions & 0 deletions src/common/db/interface/IUserOperationV07DAO.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
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;
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";
19 changes: 18 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,7 @@ export class Mongo implements IDBService {
dbName: "relayer-node-service",
});
}
log.info("Connected to db");
log.info(`Connected to db ${dbUrl}`);
} catch (error) {
veljkovranic marked this conversation as resolved.
Show resolved Hide resolved
log.error("error while connecting to mongo db");
log.error(error);
Expand Down Expand Up @@ -186,6 +188,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;
veljkovranic marked this conversation as resolved.
Show resolved Hide resolved
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