Skip to content

Commit

Permalink
feat: Added getUpgradeKernelCall util
Browse files Browse the repository at this point in the history
  • Loading branch information
SahilVasava committed Dec 24, 2024
1 parent 9776f74 commit ce9c082
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 22 deletions.
6 changes: 6 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @zerodev/sdk

## 5.4.8

### Patch Changes

- Added getUpgradeKernelCall util

## 5.4.7

### Patch Changes
Expand Down
29 changes: 29 additions & 0 deletions packages/core/accounts/kernel/utils/common/getUpgradeKernelCall.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import type { Hex } from "viem"
import { encodeFunctionData } from "viem"
import type { SmartAccount } from "viem/account-abstraction"
import { KernelVersionToAddressesMap } from "../../../../constants.js"
import type { KERNEL_VERSION_TYPE } from "../../../../types/kernel.js"
import { validateKernelVersionWithEntryPoint } from "../../../../utils.js"
import { KernelV3AccountAbi } from "../../abi/kernel_v_3_0_0/KernelAccountAbi.js"

export function getUpgradeKernelCall(
account: SmartAccount,
kernelVersion: KERNEL_VERSION_TYPE
): { to: string; data: Hex; value: bigint } {
validateKernelVersionWithEntryPoint(
account.entryPoint.version,
kernelVersion
)
const implementation =
KernelVersionToAddressesMap[kernelVersion].accountImplementationAddress

return {
to: account.address,
data: encodeFunctionData({
abi: KernelV3AccountAbi,
functionName: "upgradeTo",
args: [implementation]
}),
value: 0n
}
}
25 changes: 4 additions & 21 deletions packages/core/actions/account-client/upgradeKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ import {
type SmartAccount,
sendUserOperation
} from "viem/account-abstraction"
import { encodeFunctionData, getAction, parseAccount } from "viem/utils"
import { KernelV3AccountAbi } from "../../accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js"
import { KernelVersionToAddressesMap } from "../../constants.js"
import { getAction, parseAccount } from "viem/utils"
import { getUpgradeKernelCall } from "../../accounts/kernel/utils/common/getUpgradeKernelCall.js"
import { AccountNotFoundError } from "../../errors/index.js"
import type { KERNEL_VERSION_TYPE } from "../../types/kernel.js"
import { validateKernelVersionWithEntryPoint } from "../../utils.js"

export type UpgradeKernelParameters<
account extends SmartAccount | undefined,
Expand Down Expand Up @@ -37,30 +35,15 @@ export async function upgradeKernel<
})

const account = parseAccount(account_) as SmartAccount
validateKernelVersionWithEntryPoint(
account.entryPoint.version,
kernelVersion
)
const implementation =
KernelVersionToAddressesMap[kernelVersion].accountImplementationAddress
const call = getUpgradeKernelCall(account, kernelVersion)

return await getAction(
client,
sendUserOperation,
"sendUserOperation"
)({
...args,
calls: [
{
to: account.address,
data: encodeFunctionData({
abi: KernelV3AccountAbi,
functionName: "upgradeTo",
args: [implementation]
}),
value: 0n
}
],
calls: [call],
account
} as SendUserOperationParameters)
}
1 change: 1 addition & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,4 @@ export { getUserOperationGasPrice } from "./actions/account-client/getUserOperat
export { isPluginInitialized } from "./accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.js"
export * from "./errors/index.js"
export * from "./utils/index.js"
export { getUpgradeKernelCall } from "./accounts/kernel/utils/common/getUpgradeKernelCall.js"
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/sdk",
"version": "5.4.7",
"version": "5.4.8",
"author": "ZeroDev",
"main": "./_cjs/index.js",
"module": "./_esm/index.js",
Expand Down

0 comments on commit ce9c082

Please sign in to comment.