-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #174 from bcnmy/m_sdk_modularity_pm
M sdk modularity pm
- Loading branch information
Showing
102 changed files
with
9,104 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
191 changes: 191 additions & 0 deletions
191
packages/common/src/Types/@account-abstraction/contracts/core/BaseAccount.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; | ||
}; | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/common/src/Types/@account-abstraction/contracts/core/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
9 changes: 9 additions & 0 deletions
9
packages/common/src/Types/@account-abstraction/contracts/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.