diff --git a/biome.json b/biome.json index 9d6847c..17d4834 100644 --- a/biome.json +++ b/biome.json @@ -40,7 +40,7 @@ "javascript": { "formatter": { "semicolons": "asNeeded", - "trailingComma": "none" + "trailingCommas": "none" } } } diff --git a/bun.lockb b/bun.lockb index a98633c..5c3614c 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index 630ec82..40a44d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@zerodev/orchestra", - "version": "0.1.0", + "version": "0.1.1", "description": "", "main": "dist/index.js", "type": "module", @@ -12,7 +12,7 @@ "dev": "ts-node src/index.ts", "format": "biome format ./src --write", "lint": "biome check ./src", - "lint:fix": "bun run lint --apply", + "lint:fix": "bun run lint --write", "start": "node dist/index.js" }, "bin": { @@ -43,8 +43,8 @@ ], "license": "MIT", "dependencies": { - "@zerodev/sdk": "^5.3.3", - "@zerodev/ecdsa-validator": "^5.3.1", + "@zerodev/ecdsa-validator": "^5.4.0", + "@zerodev/sdk": "^5.4.3", "chalk": "4.1.2", "cli-table3": "^0.6.3", "commander": "^11.1.0", diff --git a/src/action/deployContracts.ts b/src/action/deployContracts.ts index 558bf4f..86c6545 100644 --- a/src/action/deployContracts.ts +++ b/src/action/deployContracts.ts @@ -78,30 +78,19 @@ export const deployToChain = async ( `Contract will be deployed at ${result.data?.toLowerCase()} does not match expected address ${expectedAddress.toLowerCase()}` ) } - const opHash = await kernelAccountClient.sendUserOperation({ - account: kernelAccountClient.account, - userOperation: { - callData: await kernelAccountClient.account.encodeCallData({ + callData: await kernelAccountClient.account.encodeCalls([ + { to: DEPLOYER_CONTRACT_ADDRESS, value: 0n, data: ensureHex(salt + bytecode.slice(2)) - }), - callGasLimit - } + } + ]) }) const bundlerClient = kernelAccountClient.extend( bundlerActions(ENTRYPOINT_ADDRESS_V07) ) - const userOpResult = await bundlerClient.waitForUserOperationReceipt({ - hash: opHash - }) - if (!userOpResult.success) { - throw new Error( - `User operation failed with reason: ${userOpResult.reason}, User Op Hash: ${opHash}` - ) - } return [getAddress(result.data as Address), opHash] } diff --git a/src/clients/createKernelClient.ts b/src/clients/createKernelClient.ts index 45780ca..340c4ec 100644 --- a/src/clients/createKernelClient.ts +++ b/src/clients/createKernelClient.ts @@ -1,61 +1,59 @@ import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator" import { + type KernelAccountClient, createKernelAccount, createKernelAccountClient, createZeroDevPaymasterClient } from "@zerodev/sdk" -import { KERNEL_V3_1 } from "@zerodev/sdk/constants" -import { ENTRYPOINT_ADDRESS_V07 } from "permissionless/utils" +import { KERNEL_V3_1, getEntryPoint } from "@zerodev/sdk/constants" import type { Hex } from "viem" import { http, createPublicClient } from "viem" import { privateKeyToAccount } from "viem/accounts" import type { Chain } from "../constant.js" import { getZeroDevBundlerRPC, getZeroDevPaymasterRPC } from "./index.js" -export const createKernelClient = async (privateKey: Hex, chain: Chain) => { - const entryPoint = ENTRYPOINT_ADDRESS_V07 +export const createKernelClient = async ( + privateKey: Hex, + chain: Chain +): Promise => { const rpcUrl = getZeroDevBundlerRPC(chain.projectId, "PIMLICO") const paymasterRpcUrl = getZeroDevPaymasterRPC(chain.projectId, "PIMLICO") - + const entryPoint = getEntryPoint("0.7") const publicClient = createPublicClient({ - transport: http(rpcUrl) + transport: http(rpcUrl), + chain: chain.viemChainObject }) const signer = privateKeyToAccount(privateKey) - const ecdsaValidatorPlugin = await signerToEcdsaValidator(publicClient, { - entryPoint, + const ecdsaValidator = await signerToEcdsaValidator(publicClient, { signer, + entryPoint, kernelVersion: KERNEL_V3_1 }) - const kernelAccount = await createKernelAccount(publicClient, { - entryPoint, + // Construct a Kernel account + const account = await createKernelAccount(publicClient, { plugins: { - sudo: ecdsaValidatorPlugin + sudo: ecdsaValidator }, + entryPoint, kernelVersion: KERNEL_V3_1 }) + const zerodevPaymaster = createZeroDevPaymasterClient({ + chain: chain.viemChainObject, + transport: http(paymasterRpcUrl) + }) + // Construct a Kernel account client const kernelClient = createKernelAccountClient({ - account: kernelAccount, + account, chain: chain.viemChainObject, - bundlerTransport: http(rpcUrl, { - timeout: 60000 // 1 min - }), - middleware: { - sponsorUserOperation: async ({ userOperation }) => { - const zeroDevPaymasterClient = createZeroDevPaymasterClient({ - chain: chain.viemChainObject, - transport: http(paymasterRpcUrl), - entryPoint - }) - return zeroDevPaymasterClient.sponsorUserOperation({ - userOperation, - entryPoint - }) + bundlerTransport: http(rpcUrl), + paymaster: { + getPaymasterData(userOperation) { + return zerodevPaymaster.sponsorUserOperation({ userOperation }) } - }, - entryPoint + } }) return kernelClient diff --git a/test/deployContract.test.ts b/test/deployContract.test.ts new file mode 100644 index 0000000..6a202c1 --- /dev/null +++ b/test/deployContract.test.ts @@ -0,0 +1,38 @@ +import { expect, test } from "bun:test"; +import { deployToChain,deployContracts } from "../src/action/deployContracts"; +import { processAndValidateChains } from "../src/utils"; +import {generatePrivateKey,} from "viem/accounts"; +import { concat } from 'viem' + + +const PRIVATE_KEY = generatePrivateKey(); // this is copied from viem.sh docs, so don't use this in production and no it's not even ours + +test("deployContract", async () => { + await deployToChain( + PRIVATE_KEY, + processAndValidateChains("sepolia", { + testnetAll : false, + mainnetAll : false, + allNetworks : false + })[0], + concat(['0x00', generatePrivateKey()]), + generatePrivateKey(), + undefined, + undefined + ); +}, 30000); + +test("deployContractTestnet", async () => { + await deployContracts( + PRIVATE_KEY, + concat(['0x00', generatePrivateKey()]), + processAndValidateChains(undefined, { + testnetAll : true, + mainnetAll : false, + allNetworks : false + }), + generatePrivateKey(), + undefined, + undefined + ); +}, 30000); \ No newline at end of file