Skip to content

Commit

Permalink
Merge pull request #174 from bcnmy/m_sdk_modularity_pm
Browse files Browse the repository at this point in the history
M sdk modularity pm
  • Loading branch information
livingrockrises authored May 24, 2023
2 parents b9298e4 + d2f5f1a commit a95e897
Show file tree
Hide file tree
Showing 102 changed files with 9,104 additions and 114 deletions.
96 changes: 49 additions & 47 deletions packages/bundler/src/Bundler.ts
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
import { IBundler } from "./interfaces/IBundler";
import { IBundler } from './interfaces/IBundler'
import { UserOperation, ChainId } from '@biconomy/core-types'
import { Bundlerconfig, UserOpResponse, UserOpGasFieldsResponse } from "./types/Types"
import { Bundlerconfig, UserOpResponse, UserOpGasFieldsResponse } from './types/Types'
import { resolveProperties } from 'ethers/lib/utils'
import { deepHexlify, getTimestampInSeconds } from '@biconomy/common'
import { HttpMethod, sendRequest } from './utils/httpRequests'

/**
* This class implements IBundler interface.
* Implementation sends UserOperation to a bundler URL as per ERC4337 standard.
* This class implements IBundler interface.
* Implementation sends UserOperation to a bundler URL as per ERC4337 standard.
* Checkout the proposal for more details on Bundlers.
*/
export class Bundler implements IBundler {
constructor(readonly bundlerConfig: Bundlerconfig) {}

constructor(readonly bundlerConfig: Bundlerconfig) {}
/**
*
* @param chainId
* @description This function will fetch gasPrices from bundler
* @returns Promise<UserOpGasPricesResponse>
*/
async getUserOpGasFields(
userOp: Partial<UserOperation>,
chainId: ChainId
): Promise<UserOpGasFieldsResponse> {
const response: any = await sendRequest({
url: `${this.bundlerConfig.bundlerUrl}`,
method: HttpMethod.Post,
body: {
method: 'eth_getUserOpGasFields',
params: [userOp, this.bundlerConfig.entryPointAddress, chainId],
id: getTimestampInSeconds(),
jsonrpc: '2.0'
}
})
return response
}
/**
*
* @param userOp
* @description This function will send signed userOp to bundler to get mined on chain
* @returns Promise<UserOpResponse>
*/
async sendUserOp(userOp: UserOperation, chainId: ChainId): Promise<UserOpResponse> {
const hexifiedUserOp = deepHexlify(await resolveProperties(userOp))
const params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress, chainId]

/**
*
* @param chainId
* @description This function will fetch gasPrices from bundler
* @returns Promise<UserOpGasPricesResponse>
*/
async getUserOpGasFields(userOp: Partial<UserOperation>, chainId: ChainId): Promise<UserOpGasFieldsResponse> {
const response: any = await sendRequest({
url: `${this.bundlerConfig.bundlerUrl}`,
method: HttpMethod.Post,
body: {
method: 'eth_getUserOpGasFields',
params: [userOp, this.bundlerConfig.entryPointAddress, chainId],
id: getTimestampInSeconds(),
jsonrpc: '2.0'
}
})
return response
}
/**
*
* @param userOp
* @description This function will send signed userOp to bundler to get mined on chain
* @returns Promise<UserOpResponse>
*/
async sendUserOp(userOp: UserOperation, chainId: ChainId): Promise<UserOpResponse> {
const hexifiedUserOp = deepHexlify(await resolveProperties(userOp))
let params = [hexifiedUserOp, this.bundlerConfig.entryPointAddress, chainId]

const response: UserOpResponse = await sendRequest({
url: `${this.bundlerConfig.bundlerUrl}`,
method: HttpMethod.Post,
body: {
method: 'eth_sendUserOperation',
params: params,
id: getTimestampInSeconds(),
jsonrpc: '2.0'
}
})
return response
}
}
const response: UserOpResponse = await sendRequest({
url: `${this.bundlerConfig.bundlerUrl}`,
method: HttpMethod.Post,
body: {
method: 'eth_sendUserOperation',
params: params,
id: getTimestampInSeconds(),
jsonrpc: '2.0'
}
})
return response
}
}
2 changes: 1 addition & 1 deletion packages/bundler/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './interfaces/IBundler'
export * from './Bundler'
export * from './types/Types'
export * from './types/Types'
13 changes: 8 additions & 5 deletions packages/bundler/src/interfaces/IBundler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { UserOpResponse, UserOpGasFieldsResponse } from "../types/Types"
import { ChainId, UserOperation } from '@biconomy/core-types'
import { UserOpResponse, UserOpGasFieldsResponse } from '../types/Types'
import { ChainId, UserOperation } from '@biconomy/core-types'

export interface IBundler {
getUserOpGasFields(userOp: Partial<UserOperation>, chainId: ChainId): Promise<UserOpGasFieldsResponse>
sendUserOp(userOp: UserOperation, chainId: ChainId): Promise<UserOpResponse>
}
getUserOpGasFields(
userOp: Partial<UserOperation>,
chainId: ChainId
): Promise<UserOpGasFieldsResponse>
sendUserOp(userOp: UserOperation, chainId: ChainId): Promise<UserOpResponse>
}
28 changes: 14 additions & 14 deletions packages/bundler/src/types/Types.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
export type Bundlerconfig = {
bundlerUrl: string,
entryPointAddress: string
bundlerUrl: string
entryPointAddress: string
}

export type UserOpResponse = {
data: {
transactionId: string,
connectionUrl: string
}
data: {
transactionId: string
connectionUrl: string
}
}

export type UserOpGasFieldsResponse = {
result: {
preVerificationGas: string,
verificationGasLimit: string,
callGasLimit: string,
maxPriorityFeePerGas: string,
maxFeePerGas: string,
gasPrice: string
}
result: {
preVerificationGas: string
verificationGasLimit: string
callGasLimit: string
maxPriorityFeePerGas: string
maxFeePerGas: string
gasPrice: string
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import type {
BaseContract,
BigNumber,
BigNumberish,
BytesLike,
CallOverrides,
ContractTransaction,
Overrides,
PopulatedTransaction,
Signer,
utils,
} from "ethers";
import type { FunctionFragment, Result } from "@ethersproject/abi";
import type { Listener, Provider } from "@ethersproject/providers";
import type {
TypedEventFilter,
TypedEvent,
TypedListener,
OnEvent,
PromiseOrValue,
} from "../../../common";

export type UserOperationStruct = {
sender: PromiseOrValue<string>;
nonce: PromiseOrValue<BigNumberish>;
initCode: PromiseOrValue<BytesLike>;
callData: PromiseOrValue<BytesLike>;
callGasLimit: PromiseOrValue<BigNumberish>;
verificationGasLimit: PromiseOrValue<BigNumberish>;
preVerificationGas: PromiseOrValue<BigNumberish>;
maxFeePerGas: PromiseOrValue<BigNumberish>;
maxPriorityFeePerGas: PromiseOrValue<BigNumberish>;
paymasterAndData: PromiseOrValue<BytesLike>;
signature: PromiseOrValue<BytesLike>;
};

export type UserOperationStructOutput = [
string,
BigNumber,
string,
string,
BigNumber,
BigNumber,
BigNumber,
BigNumber,
BigNumber,
string,
string
] & {
sender: string;
nonce: BigNumber;
initCode: string;
callData: string;
callGasLimit: BigNumber;
verificationGasLimit: BigNumber;
preVerificationGas: BigNumber;
maxFeePerGas: BigNumber;
maxPriorityFeePerGas: BigNumber;
paymasterAndData: string;
signature: string;
};

export interface BaseAccountInterface extends utils.Interface {
functions: {
"entryPoint()": FunctionFragment;
"getNonce()": FunctionFragment;
"validateUserOp((address,uint256,bytes,bytes,uint256,uint256,uint256,uint256,uint256,bytes,bytes),bytes32,uint256)": FunctionFragment;
};

getFunction(
nameOrSignatureOrTopic: "entryPoint" | "getNonce" | "validateUserOp"
): FunctionFragment;

encodeFunctionData(
functionFragment: "entryPoint",
values?: undefined
): string;
encodeFunctionData(functionFragment: "getNonce", values?: undefined): string;
encodeFunctionData(
functionFragment: "validateUserOp",
values: [
UserOperationStruct,
PromiseOrValue<BytesLike>,
PromiseOrValue<BigNumberish>
]
): string;

decodeFunctionResult(functionFragment: "entryPoint", data: BytesLike): Result;
decodeFunctionResult(functionFragment: "getNonce", data: BytesLike): Result;
decodeFunctionResult(
functionFragment: "validateUserOp",
data: BytesLike
): Result;

events: {};
}

export interface BaseAccount extends BaseContract {
connect(signerOrProvider: Signer | Provider | string): this;
attach(addressOrName: string): this;
deployed(): Promise<this>;

interface: BaseAccountInterface;

queryFilter<TEvent extends TypedEvent>(
event: TypedEventFilter<TEvent>,
fromBlockOrBlockhash?: string | number | undefined,
toBlock?: string | number | undefined
): Promise<Array<TEvent>>;

listeners<TEvent extends TypedEvent>(
eventFilter?: TypedEventFilter<TEvent>
): Array<TypedListener<TEvent>>;
listeners(eventName?: string): Array<Listener>;
removeAllListeners<TEvent extends TypedEvent>(
eventFilter: TypedEventFilter<TEvent>
): this;
removeAllListeners(eventName?: string): this;
off: OnEvent<this>;
on: OnEvent<this>;
once: OnEvent<this>;
removeListener: OnEvent<this>;

functions: {
entryPoint(overrides?: CallOverrides): Promise<[string]>;

getNonce(overrides?: CallOverrides): Promise<[BigNumber]>;

validateUserOp(
userOp: UserOperationStruct,
userOpHash: PromiseOrValue<BytesLike>,
missingAccountFunds: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;
};

entryPoint(overrides?: CallOverrides): Promise<string>;

getNonce(overrides?: CallOverrides): Promise<BigNumber>;

validateUserOp(
userOp: UserOperationStruct,
userOpHash: PromiseOrValue<BytesLike>,
missingAccountFunds: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<ContractTransaction>;

callStatic: {
entryPoint(overrides?: CallOverrides): Promise<string>;

getNonce(overrides?: CallOverrides): Promise<BigNumber>;

validateUserOp(
userOp: UserOperationStruct,
userOpHash: PromiseOrValue<BytesLike>,
missingAccountFunds: PromiseOrValue<BigNumberish>,
overrides?: CallOverrides
): Promise<BigNumber>;
};

filters: {};

estimateGas: {
entryPoint(overrides?: CallOverrides): Promise<BigNumber>;

getNonce(overrides?: CallOverrides): Promise<BigNumber>;

validateUserOp(
userOp: UserOperationStruct,
userOpHash: PromiseOrValue<BytesLike>,
missingAccountFunds: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<BigNumber>;
};

populateTransaction: {
entryPoint(overrides?: CallOverrides): Promise<PopulatedTransaction>;

getNonce(overrides?: CallOverrides): Promise<PopulatedTransaction>;

validateUserOp(
userOp: UserOperationStruct,
userOpHash: PromiseOrValue<BytesLike>,
missingAccountFunds: PromiseOrValue<BigNumberish>,
overrides?: Overrides & { from?: PromiseOrValue<string> }
): Promise<PopulatedTransaction>;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
export type { BaseAccount } from "./BaseAccount";
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* Autogenerated file. Do not edit manually. */
/* tslint:disable */
/* eslint-disable */
import type * as core from "./core";
export type { core };
import type * as interfaces from "./interfaces";
export type { interfaces };
import type * as samples from "./samples";
export type { samples };
Loading

0 comments on commit a95e897

Please sign in to comment.