-
Notifications
You must be signed in to change notification settings - Fork 36
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 #201 from zerodevapp/feat/pluginMigrations
feat: added pluginMigrations feature and test
- Loading branch information
Showing
13 changed files
with
300 additions
and
13 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,5 +1,11 @@ | ||
# @zerodev/sdk | ||
|
||
## 5.4.10 | ||
|
||
### Patch Changes | ||
|
||
- feat: add pluginMigrations feature | ||
|
||
## 5.4.9 | ||
|
||
### Patch Changes | ||
|
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
19 changes: 19 additions & 0 deletions
19
packages/core/accounts/kernel/utils/plugins/ep0_7/getPluginInstallCallData.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,19 @@ | ||
import { type Address, encodeFunctionData } from "viem" | ||
import type { PluginMigrationData } from "../../../../../types/kernel.js" | ||
import { KernelModuleInstallAbi } from "../../../abi/kernel_v_3_0_0/KernelModuleAbi.js" | ||
import type { CallArgs } from "../../types.js" | ||
|
||
export const getPluginInstallCallData = ( | ||
accountAddress: Address, | ||
plugin: PluginMigrationData | ||
): CallArgs => { | ||
const data = encodeFunctionData({ | ||
abi: KernelModuleInstallAbi, | ||
functionName: "installModule", | ||
args: [plugin.type, plugin.address, plugin.data] | ||
}) | ||
return { | ||
to: accountAddress, | ||
data | ||
} | ||
} |
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,62 @@ | ||
import type { Address, Client, Hex } from "viem" | ||
import { readContract } from "viem/actions" | ||
import { getAction } from "viem/utils" | ||
import { KernelModuleIsModuleInstalledAbi } from "../../accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js" | ||
import type { PLUGIN_TYPE } from "../../constants.js" | ||
|
||
export type IsPluginInstalledParams = { | ||
address: Address | ||
plugin: { | ||
type: (typeof PLUGIN_TYPE)[keyof typeof PLUGIN_TYPE] | ||
address: Address | ||
data?: Hex | ||
} | ||
} | ||
|
||
/** | ||
* Returns whether a plugin is installed on the account. | ||
* | ||
* @param client - Client to use | ||
* @param args - {@link IsPluginInstalledParams} address and plugin details | ||
* @returns boolean indicating if plugin is installed | ||
* | ||
* @example | ||
* import { createPublicClient } from "viem" | ||
* import { isPluginInstalled } from "@zerodev/sdk" | ||
* | ||
* const client = createPublicClient({ | ||
* chain: mainnet, | ||
* transport: http() | ||
* }) | ||
* | ||
* const isInstalled = await isPluginInstalled(client, { | ||
* address: accountAddress, | ||
* plugin: { | ||
* type: PLUGIN_TYPE.VALIDATOR, | ||
* address: validatorAddress, | ||
* data: "0x" | ||
* } | ||
* }) | ||
*/ | ||
export const isPluginInstalled = async ( | ||
client: Client, | ||
args: IsPluginInstalledParams | ||
): Promise<boolean> => { | ||
const { address, plugin } = args | ||
const { type, address: pluginAddress, data = "0x" } = plugin | ||
|
||
try { | ||
return await getAction( | ||
client, | ||
readContract, | ||
"readContract" | ||
)({ | ||
address, | ||
abi: KernelModuleIsModuleInstalledAbi, | ||
functionName: "isModuleInstalled", | ||
args: [BigInt(type), pluginAddress, data] | ||
}) | ||
} catch (error) { | ||
return false | ||
} | ||
} |
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
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
Oops, something went wrong.