Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: permissionless upgrade 0.1.x #97

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 43 additions & 8 deletions build-all.sh
Original file line number Diff line number Diff line change
@@ -1,35 +1,70 @@
#!/bin/bash

# Define ANSI color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

# Define the list of directories containing package.json files that should be built.
# Assuming that all packages are directly under the 'packages' and 'plugins' directories.

DIRECTORIES=("packages/*" "plugins/*")

# Arrays to keep track of build statuses
SUCCEEDED=()
FAILED=()

# Loop through each directory and run 'bun run build'.
for DIR in ${DIRECTORIES[@]}; do
# Check if the directory contains a package.json file.
if [ -f "$DIR/package.json" ]; then
# Use jq to check if a build script exists in the package.json
if jq -e '.scripts.build' "$DIR/package.json" > /dev/null; then
echo "Building $DIR"
(cd $DIR && bun run build)
echo "🔨 Attempting to build $DIR"
if (cd $DIR && bun run build); then
printf "${GREEN}✅ Build succeeded for $DIR${NC}\n\n"
SUCCEEDED+=("$DIR")
else
printf "${RED}❌ Build failed for $DIR${NC}\n\n"
FAILED+=("$DIR")
fi
else
echo "No build script found in $DIR, skipping..."
echo "No build script found in $DIR, skipping...\n"
fi
else
# If the directory does not contain a package.json file, loop through its subdirectories.
for SUBDIR in $DIR/*; do
if [ -f "$SUBDIR/package.json" ]; then
# Use jq to check if a build script exists in the package.json
if jq -e '.scripts.build' "$SUBDIR/package.json" > /dev/null; then
echo "Building $SUBDIR"
(cd $SUBDIR && bun run build)
echo "🔨 Attempting to build $SUBDIR"
if (cd $SUBDIR && bun run build); then
printf "${GREEN}✅ Build succeeded for $SUBDIR${NC}\n\n"
SUCCEEDED+=("$SUBDIR")
else
printf "${RED}❌ Build failed for $SUBDIR${NC}\n\n"
FAILED+=("$SUBDIR")
fi
else
echo "No build script found in $SUBDIR, skipping..."
echo "No build script found in $SUBDIR, skipping...\n"
fi
fi
done
fi
done

echo "Build process completed."
echo "🏁 Build process completed.\n"

# Print summary
if [ ${#SUCCEEDED[@]} -ne 0 ]; then
printf "${GREEN}✅ Build succeeded for:${NC}\n"
for item in "${SUCCEEDED[@]}"; do
printf "${GREEN}- $item${NC}\n"
done
fi

if [ ${#FAILED[@]} -ne 0 ]; then
printf "\n${RED}❌ Build failed for:${NC}\n"
for item in "${FAILED[@]}"; do
printf "${RED}- $item${NC}\n"
done
fi
Binary file modified bun.lockb
Binary file not shown.
78 changes: 39 additions & 39 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
{
"workspaces": [
"packages/*",
"templates/*",
"plugins/*"
],
"private": true,
"author": "ZeroDev",
"type": "module",
"sideEffects": false,
"devDependencies": {
"@ambire/signature-validator": "^1.3.1",
"@biomejs/biome": "^1.0.0",
"@changesets/changelog-git": "^0.1.14",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@size-limit/esbuild-why": "^9.0.0",
"@size-limit/preset-small-lib": "^9.0.0",
"ethers": "5",
"rimraf": "^5.0.1",
"simple-git-hooks": "^2.9.0",
"size-limit": "^9.0.0",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
},
"description": "",
"keywords": [],
"license": "MIT",
"scripts": {
"build": "sh build-all.sh",
"format": "biome format . --write",
"lint": "biome check .",
"lint:fix": "bun run lint --apply",
"changeset": "changeset",
"changeset:release": "bun run build && changeset publish",
"changeset:version": "changeset version && bun install --lockfile-only"
},
"simple-git-hooks": {
"pre-commit": "bun run format && bun run lint:fix"
}
"workspaces": [
"packages/*",
"templates/*",
"plugins/*"
],
"private": true,
"author": "ZeroDev",
"type": "module",
"sideEffects": false,
"devDependencies": {
"@ambire/signature-validator": "^1.3.1",
"@biomejs/biome": "^1.0.0",
"@changesets/changelog-git": "^0.1.14",
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.26.2",
"@size-limit/esbuild-why": "^9.0.0",
"@size-limit/preset-small-lib": "^9.0.0",
"ethers": "5",
"rimraf": "^5.0.1",
"simple-git-hooks": "^2.9.0",
"size-limit": "^9.0.0",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
},
"description": "",
"keywords": [],
"license": "MIT",
"scripts": {
"build": "sh build-all.sh",
"format": "biome format . --write",
"lint": "biome check .",
"lint:fix": "bun run lint --apply",
"changeset": "changeset",
"changeset:release": "bun run build && changeset publish",
"changeset:version": "changeset version && bun install --lockfile-only"
},
"simple-git-hooks": {
"pre-commit": "bun run format && bun run lint:fix"
}
}
89 changes: 68 additions & 21 deletions packages/core/accounts/kernel/createKernelAccount.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
import { getAccountNonce, getAction, getSenderAddress } from "permissionless"
import {
getAccountNonce,
getAction,
getSenderAddress,
isSmartAccountDeployed
} from "permissionless"
import {
SignTransactionNotSupportedBySmartAccount,
type SmartAccount
} from "permissionless/accounts"
import type {
ENTRYPOINT_ADDRESS_V06_TYPE,
EntryPoint
} from "permissionless/types"
import {
type Address,
type Chain,
Expand Down Expand Up @@ -43,14 +52,26 @@ import {
import { KernelExecuteAbi, KernelInitAbi } from "./abi/KernelAccountAbi.js"

export type KernelSmartAccount<
entryPoint extends EntryPoint,
transport extends Transport = Transport,
chain extends Chain | undefined = Chain | undefined
> = SmartAccount<"kernelSmartAccount", transport, chain> & {
kernelPluginManager: KernelPluginManager
> = SmartAccount<entryPoint, "kernelSmartAccount", transport, chain> & {
kernelPluginManager: KernelPluginManager<entryPoint>
generateInitCode: () => Promise<Hex>
encodeCallData: (args: KernelEncodeCallDataArgs) => Promise<Hex>
}

export type CreateKernelAccountParameters<entryPoint extends EntryPoint> = {
plugins:
| KernelPluginManagerParams<entryPoint>
| KernelPluginManager<entryPoint>
entryPoint: entryPoint
index?: bigint
factoryAddress?: Address
accountLogicAddress?: Address
deployedAccountAddress?: Address
}

/**
* The account creation ABI for a kernel smart account (from the KernelFactory)
*/
Expand Down Expand Up @@ -186,24 +207,25 @@ const getAccountInitCode = async ({
* @param initCodeProvider
*/
const getAccountAddress = async <
entryPoint extends EntryPoint,
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined
>({
client,
entryPoint,
entryPoint: entryPointAddress,
initCodeProvider
}: {
client: Client<TTransport, TChain, undefined>
initCodeProvider: () => Promise<Hex>
entryPoint: Address
entryPoint: entryPoint
}): Promise<Address> => {
// Find the init code for this account
const initCode = await initCodeProvider()

// Get the sender address based on the init code
return getSenderAddress(client, {
initCode,
entryPoint
entryPoint: entryPointAddress as ENTRYPOINT_ADDRESS_V06_TYPE
})
}

Expand All @@ -227,27 +249,21 @@ const parseFactoryAddressAndCallDataFromAccountInitCode = (
* @param deployedAccountAddress
*/
export async function createKernelAccount<
entryPoint extends EntryPoint,
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined
>(
client: Client<TTransport, TChain, undefined>,
{
plugins,
entryPoint = KERNEL_ADDRESSES.ENTRYPOINT_V0_6,
entryPoint: entryPointAddress,
index = 0n,
factoryAddress = KERNEL_ADDRESSES.FACTORY_ADDRESS,
accountLogicAddress = KERNEL_ADDRESSES.ACCOUNT_LOGIC,
deployedAccountAddress
}: {
plugins: KernelPluginManagerParams | KernelPluginManager
entryPoint?: Address
index?: bigint
factoryAddress?: Address
accountLogicAddress?: Address
deployedAccountAddress?: Address
}
): Promise<KernelSmartAccount<TTransport, TChain>> {
const kernelPluginManager = isKernelPluginManager(plugins)
}: CreateKernelAccountParameters<entryPoint>
): Promise<KernelSmartAccount<entryPoint, TTransport, TChain>> {
const kernelPluginManager = isKernelPluginManager<entryPoint>(plugins)
? plugins
: await toKernelPluginManager(client, {
sudo: plugins.sudo,
Expand All @@ -271,14 +287,19 @@ export async function createKernelAccount<
// Fetch account address and chain id
const accountAddress =
deployedAccountAddress ??
(await getAccountAddress<TTransport, TChain>({
(await getAccountAddress<entryPoint, TTransport, TChain>({
client,
entryPoint,
entryPoint: entryPointAddress,
initCodeProvider: generateInitCode
}))

if (!accountAddress) throw new Error("Account address not found")

let smartAccountDeployed = await isSmartAccountDeployed(
client,
accountAddress
)

const signHashedMessage = async (messageHash: Hex): Promise<Hex> => {
let kernelImplAddr: Address | undefined
try {
Expand Down Expand Up @@ -440,17 +461,43 @@ export async function createKernelAccount<
...account,
client: client,
publicKey: accountAddress,
entryPoint: entryPoint,
entryPoint: entryPointAddress,
source: "kernelSmartAccount",
kernelPluginManager,
generateInitCode,

async getFactory() {
if (smartAccountDeployed) return undefined

smartAccountDeployed = await isSmartAccountDeployed(
client,
accountAddress
)

if (smartAccountDeployed) return undefined

return factoryAddress
},

async getFactoryData() {
if (smartAccountDeployed) return undefined

smartAccountDeployed = await isSmartAccountDeployed(
client,
accountAddress
)

if (smartAccountDeployed) return undefined

return generateInitCode()
},

// Get the nonce of the smart account
async getNonce() {
const key = await kernelPluginManager.getNonceKey()
return getAccountNonce(client, {
sender: accountAddress,
entryPoint: entryPoint,
entryPoint: entryPointAddress,
key
})
},
Expand Down
10 changes: 6 additions & 4 deletions packages/core/accounts/utils/toKernelPluginManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getAction } from "permissionless"
import type { EntryPoint } from "permissionless/types/entrypoint"
import {
type Address,
type Chain,
Expand All @@ -22,14 +23,15 @@ import {
} from "../../types/kernel.js"
import { getKernelVersion } from "../../utils.js"

export function isKernelPluginManager(
export function isKernelPluginManager<entryPoint extends EntryPoint>(
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
plugin: any
): plugin is KernelPluginManager {
): plugin is KernelPluginManager<entryPoint> {
return plugin.getPluginEnableSignature !== undefined
}

export async function toKernelPluginManager<
entryPoint extends EntryPoint,
TTransport extends Transport = Transport,
TChain extends Chain | undefined = Chain | undefined
>(
Expand All @@ -47,8 +49,8 @@ export async function toKernelPluginManager<
},
validAfter = 0,
validUntil = 0
}: KernelPluginManagerParams
): Promise<KernelPluginManager> {
}: KernelPluginManagerParams<entryPoint>
): Promise<KernelPluginManager<entryPoint>> {
const chainId = await getChainId(client)
const getValidatorSignature = async (
accountAddress: Address,
Expand Down
Loading
Loading