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

Fix/update sdk #11

Merged
merged 2 commits into from
Dec 7, 2024
Merged
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
2 changes: 1 addition & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"javascript": {
"formatter": {
"semicolons": "asNeeded",
"trailingComma": "none"
"trailingCommas": "none"
}
}
}
Binary file modified bun.lockb
Binary file not shown.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zerodev/orchestra",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"main": "dist/index.js",
"type": "module",
Expand All @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 4 additions & 15 deletions src/action/deployContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
54 changes: 26 additions & 28 deletions src/clients/createKernelClient.ts
Original file line number Diff line number Diff line change
@@ -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<KernelAccountClient> => {
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
Expand Down
38 changes: 38 additions & 0 deletions test/deployContract.test.ts
Original file line number Diff line number Diff line change
@@ -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);
Loading