-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: kernel batch transactions and gas estimation fixes (#39)
* feat: `ISmartAccountProvider` accepts `BaseSmartContractAccount` as generic * fix: fixed type export for `SmartAccountSinger` * feat: added signMessage method in `SmartAccountProvider` * feat: fixed lint errors * feat: exported `alchemyPaymasterAndDataMiddleware` in alchemy package * feat: fixed core package build issues * feat: fixed estimation mismatch and implemented signMessage method for `KernelSmartAccountProvider` * feat: fixed estimation mismatch and implemented signMessage method for `KernelSmartAccountProvider` * feat: added support for batch transfers * feat: added support for batch transfers * feat: added support for batch transfers * fix: lint errors fixes * fix: lint errors fixes * fix: minor code enhancements * fix: few cleanup items and nits * fix: few cleanup items and nits * fix: few cleanup items and nits * fix: few cleanup items and nits
- Loading branch information
1 parent
383fd27
commit f2a3d3d
Showing
7 changed files
with
114 additions
and
84 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
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
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,14 @@ | ||
export const MultiSendAbi = [ | ||
{ | ||
inputs: [], | ||
stateMutability: "nonpayable", | ||
type: "constructor", | ||
}, | ||
{ | ||
inputs: [{ internalType: "bytes", name: "transactions", type: "bytes" }], | ||
name: "multiSend", | ||
outputs: [], | ||
stateMutability: "payable", | ||
type: "function", | ||
}, | ||
] as const; |
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
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,46 +1,12 @@ | ||
import type { HttpTransport } from "viem"; | ||
import { | ||
type AccountMiddlewareFn, | ||
deepHexlify, | ||
resolveProperties, | ||
SmartAccountProvider, | ||
} from "@alchemy/aa-core"; | ||
import type { Hash, HttpTransport } from "viem"; | ||
import { SmartAccountProvider } from "@alchemy/aa-core"; | ||
import { KernelSmartContractAccount } from "./account"; | ||
|
||
export class KernelAccountProvider extends SmartAccountProvider<HttpTransport> { | ||
gasEstimator: AccountMiddlewareFn = async (struct) => { | ||
const request = deepHexlify(await resolveProperties(struct)); | ||
const estimates = await this.rpcClient.estimateUserOperationGas( | ||
request, | ||
this.entryPointAddress | ||
); | ||
|
||
estimates.verificationGasLimit = | ||
(BigInt(estimates.verificationGasLimit) * 130n) / 100n; | ||
|
||
return { | ||
...struct, | ||
...estimates, | ||
}; | ||
}; | ||
|
||
request: (args: { method: string; params?: any[] }) => Promise<any> = async ( | ||
args | ||
) => { | ||
const { method, params } = args; | ||
if (method === "personal_sign") { | ||
if (!this.account) { | ||
throw new Error("account not connected!"); | ||
} | ||
const [data, address] = params!; | ||
if (address !== (await this.getAddress())) { | ||
throw new Error( | ||
"cannot sign for address that is not the current account" | ||
); | ||
} | ||
// @ts-ignore | ||
return this.account.signWithEip6492(data); | ||
} else { | ||
return super.request(args); | ||
signMessage = async (msg: string | Uint8Array): Promise<Hash> => { | ||
if (!this.account) { | ||
throw new Error("account not connected!"); | ||
} | ||
return (this.account as KernelSmartContractAccount).signWithEip6492(msg); | ||
}; | ||
} |
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,7 @@ | ||
import type { UserOperationCallData } from "@alchemy/aa-core"; | ||
|
||
export interface KernelUserOperationCallData extends UserOperationCallData { | ||
delegateCall?: boolean; | ||
} | ||
|
||
export type KernelBatchUserOperationCallData = KernelUserOperationCallData[]; |
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,17 @@ | ||
import { encodePacked, toBytes } from "viem"; | ||
import type { Hex } from "viem"; | ||
import type { KernelUserOperationCallData } from "./types"; | ||
|
||
export const encodeCall = (call: KernelUserOperationCallData): Hex => { | ||
const data = toBytes(call.data); | ||
return encodePacked( | ||
["uint8", "address", "uint256", "uint256", "bytes"], | ||
[ | ||
call.delegateCall ? 1 : 0, | ||
call.target, | ||
call.value ?? BigInt(0), | ||
BigInt(data.length), | ||
call.data, | ||
] | ||
); | ||
}; |