Skip to content

Commit

Permalink
Merge pull request #187 from zerodevapp/feat/session-account
Browse files Browse the repository at this point in the history
feat: session account
  • Loading branch information
SahilVasava authored Sep 17, 2024
2 parents 04a3106 + 6ab803a commit e612073
Show file tree
Hide file tree
Showing 44 changed files with 3,787 additions and 80 deletions.
Binary file modified bun.lockb
Binary file not shown.
33 changes: 22 additions & 11 deletions packages/test/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import type { EntryPointVersion } from "permissionless/types/entrypoint"
import type { EntryPointVersion } from "permissionless/types"
import type { Chain } from "viem"
import { polygonMumbai, sepolia } from "viem/chains"
import {
baseSepolia,
optimismSepolia,
polygonMumbai,
sepolia
} from "viem/chains"

export const config: {
[key in EntryPointVersion]: {
[key in Chain["name"]]: {
[key in number]: {
rpcUrl: string
chainId: number
bundlerUrl: string
Expand All @@ -13,25 +18,31 @@ export const config: {
}
} = {
"v0.6": {
polygonMumbai: {
rpcUrl: process.env.RPC_URL_MUMBAI || "",
bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV06 || "",
chainId: polygonMumbai.id,
projectId: process.env.ZERODEV_PROJECT_ID_MUMBAI || ""
},
sepolia: {
[sepolia.id]: {
rpcUrl: process.env.RPC_URL_SEPOLIA || "",
bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV07 || "",
chainId: sepolia.id,
projectId: process.env.ZERODEV_PROJECT_ID_SEPOLIA || ""
}
},
"v0.7": {
sepolia: {
[sepolia.id]: {
rpcUrl: process.env.RPC_URL_SEPOLIA || "",
bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV07 || "",
chainId: sepolia.id,
projectId: process.env.ZERODEV_PROJECT_ID_SEPOLIA || ""
},
[optimismSepolia.id]: {
rpcUrl: process.env.RPC_URL_OP_SEPOLIA || "",
bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV07 || "",
chainId: optimismSepolia.id,
projectId: process.env.ZERODEV_PROJECT_ID_OP_SEPOLIA || ""
},
[baseSepolia.id]: {
rpcUrl: process.env.RPC_URL_BASE_SEPOLIA || "",
bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV07 || "",
chainId: baseSepolia.id,
projectId: process.env.ZERODEV_PROJECT_ID_BASE_SEPOLIA || ""
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions packages/test/ecdsaKernelAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import dotenv from "dotenv"
import { ethers } from "ethers"
import { type BundlerClient, ENTRYPOINT_ADDRESS_V06 } from "permissionless"
import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts"
import type { ENTRYPOINT_ADDRESS_V06_TYPE } from "permissionless/types/entrypoint.js"
import type { ENTRYPOINT_ADDRESS_V06_TYPE } from "permissionless/types"
import {
type Address,
type Chain,
Expand Down Expand Up @@ -200,7 +200,7 @@ describe("ECDSA kernel Account", () => {
message,
signature: signature,
provider: new ethers.providers.JsonRpcProvider(
config["v0.6"].sepolia.rpcUrl
config["v0.6"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down Expand Up @@ -265,7 +265,7 @@ describe("ECDSA kernel Account", () => {
},
signature: signature,
provider: new ethers.providers.JsonRpcProvider(
config["v0.6"].sepolia.rpcUrl
config["v0.6"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand All @@ -291,7 +291,7 @@ describe("ECDSA kernel Account", () => {
message,
signature: response,
provider: new ethers.providers.JsonRpcProvider(
config["v0.6"].sepolia.rpcUrl
config["v0.6"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down
6 changes: 3 additions & 3 deletions packages/test/fallbackClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ describe("fallback client e2e", () => {
message,
signature: signature,
provider: new ethers.providers.JsonRpcProvider(
config["v0.6"].sepolia.rpcUrl
config["v0.6"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down Expand Up @@ -344,7 +344,7 @@ describe("fallback client e2e", () => {
},
signature: signature,
provider: new ethers.providers.JsonRpcProvider(
config["v0.6"].sepolia.rpcUrl
config["v0.6"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand All @@ -370,7 +370,7 @@ describe("fallback client e2e", () => {
message,
signature: response,
provider: new ethers.providers.JsonRpcProvider(
config["v0.6"].sepolia.rpcUrl
config["v0.6"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down
2 changes: 1 addition & 1 deletion packages/test/kernelV1Account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe("ECDSA kernel Account v1", () => {
message,
signature: response,
provider: new ethers.providers.JsonRpcProvider(
config["v0.6"].sepolia.rpcUrl
config["v0.6"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down
2 changes: 1 addition & 1 deletion packages/test/kernelV2Account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe("ECDSA kernel Account v2", () => {
message,
signature: response,
provider: new ethers.providers.JsonRpcProvider(
config["v0.6"].sepolia.rpcUrl
config["v0.6"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down
2 changes: 1 addition & 1 deletion packages/test/sessionKeyKernelAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe("Session Key kernel Account", async () => {
let publicClient: PublicClient
const client = await createPublicClient({
chain: sepolia,
transport: http(config["v0.6"].sepolia.rpcUrl as string)
transport: http(config["v0.6"][sepolia.id].rpcUrl as string)
})
const executeBatchSelector = toFunctionSelector(
getAbiItem({
Expand Down
16 changes: 8 additions & 8 deletions packages/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import {
type SmartAccount,
signerToSimpleSmartAccount
} from "permissionless/accounts"
import type { Middleware } from "permissionless/actions/smartAccount.js"
import type { Middleware } from "permissionless/actions/smartAccount"
import type {
ENTRYPOINT_ADDRESS_V06_TYPE,
EntryPoint
} from "permissionless/types/entrypoint.js"
} from "permissionless/types"
import {
http,
type AbiItem,
Expand Down Expand Up @@ -69,7 +69,7 @@ import { config } from "./config.js"
export const Test_ERC20Address = "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B"
export const index = 5438533232332340n
const DEFAULT_PROVIDER = "STACKUP"
const projectId = config["v0.6"].sepolia.projectId
const projectId = config["v0.6"][sepolia.id].projectId
export const kernelVersion = "0.2.4"
export const getFactoryAddress = (): Address => {
const factoryAddress = process.env.FACTORY_ADDRESS
Expand All @@ -88,7 +88,7 @@ export const getPrivateKeyAccount = (): Account => {
}

export const getTestingChain = (): Chain => {
const testChainId = config["v0.6"].sepolia.chainId
const testChainId = config["v0.6"][sepolia.id].chainId
const chainId = testChainId ?? sepolia.id
const chain = Object.values(allChains).find((c) => c.id === chainId)
if (!chain) {
Expand Down Expand Up @@ -157,7 +157,7 @@ export const getKernelV1Account = async () => {
return createKernelAccountV1(publicClient, {
signer,
index,
entrypoint: getEntryPoint()
entryPoint: getEntryPoint()
}) as unknown as KernelSmartAccount<ENTRYPOINT_ADDRESS_V06_TYPE>
}

Expand Down Expand Up @@ -462,7 +462,7 @@ export const getSessionKeyToSessionKeyKernelAccount = async (

const getBundlerRpc = (): string => {
const zeroDevProjectId = projectId
const zeroDevBundlerRpcHost = config["v0.6"].sepolia.bundlerUrl
const zeroDevBundlerRpcHost = config["v0.6"][sepolia.id].bundlerUrl
if (!zeroDevProjectId || !zeroDevBundlerRpcHost) {
throw new Error(
"ZERODEV_PROJECT_ID and ZERODEV_BUNDLER_RPC_HOST environment variables must be set"
Expand Down Expand Up @@ -514,7 +514,7 @@ export const getKernelAccountClient = async ({
}

export const getEoaWalletClient = (): WalletClient => {
const rpcUrl = config["v0.6"].sepolia.rpcUrl
const rpcUrl = config["v0.6"][sepolia.id].rpcUrl
if (!rpcUrl) {
throw new Error("RPC_URL environment variable not set")
}
Expand All @@ -531,7 +531,7 @@ export const getEntryPoint = (): ENTRYPOINT_ADDRESS_V06_TYPE => {
}

export const getPublicClient = async (): Promise<PublicClient> => {
const rpcUrl = config["v0.6"].sepolia.rpcUrl
const rpcUrl = config["v0.6"][sepolia.id].rpcUrl
if (!rpcUrl) {
throw new Error("RPC_URL environment variable not set")
}
Expand Down
11 changes: 6 additions & 5 deletions packages/test/v0.7/ecdsaKernelAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import {
bundlerActions
} from "permissionless"
import { SignTransactionNotSupportedBySmartAccount } from "permissionless/accounts"
import type { PimlicoBundlerClient } from "permissionless/clients/pimlico.js"
import type { ENTRYPOINT_ADDRESS_V07_TYPE } from "permissionless/types/entrypoint.js"
import type { PimlicoBundlerClient } from "permissionless/clients/pimlico"
import type { ENTRYPOINT_ADDRESS_V07_TYPE } from "permissionless/types"
import {
type Address,
type Chain,
Expand All @@ -43,6 +43,7 @@ import {
zeroAddress
} from "viem"
import { privateKeyToAccount } from "viem/accounts"
import { sepolia } from "viem/chains"
import { EntryPointAbi } from "../abis/EntryPoint.js"
import { GreeterAbi, GreeterBytecode } from "../abis/Greeter.js"
import { TokenActionsAbi } from "../abis/TokenActionsAbi.js"
Expand Down Expand Up @@ -195,7 +196,7 @@ describe("ECDSA kernel Account", () => {
message,
signature: signature,
provider: new ethers.providers.JsonRpcProvider(
config["v0.7"].sepolia.rpcUrl
config["v0.7"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down Expand Up @@ -260,7 +261,7 @@ describe("ECDSA kernel Account", () => {
},
signature: signature,
provider: new ethers.providers.JsonRpcProvider(
config["v0.7"].sepolia.rpcUrl
config["v0.7"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down Expand Up @@ -290,7 +291,7 @@ describe("ECDSA kernel Account", () => {
message,
signature: response,
provider: new ethers.providers.JsonRpcProvider(
config["v0.7"].sepolia.rpcUrl
config["v0.7"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down
8 changes: 4 additions & 4 deletions packages/test/v0.7/multiChainECDSAValidator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ describe("MultiChainECDSAValidator", () => {
message,
signature: signature,
provider: new ethers.providers.JsonRpcProvider(
config["v0.7"].sepolia.rpcUrl
config["v0.7"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down Expand Up @@ -341,7 +341,7 @@ describe("MultiChainECDSAValidator", () => {
},
signature: signature,
provider: new ethers.providers.JsonRpcProvider(
config["v0.7"].sepolia.rpcUrl
config["v0.7"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down Expand Up @@ -371,7 +371,7 @@ describe("MultiChainECDSAValidator", () => {
message,
signature: response,
provider: new ethers.providers.JsonRpcProvider(
config["v0.7"].sepolia.rpcUrl
config["v0.7"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down Expand Up @@ -414,7 +414,7 @@ describe("MultiChainECDSAValidator", () => {
message,
signature: response,
provider: new ethers.providers.JsonRpcProvider(
config["v0.7"].sepolia.rpcUrl
config["v0.7"][sepolia.id].rpcUrl
)
})
expect(ambireResult).toBeTrue()
Expand Down
Loading

0 comments on commit e612073

Please sign in to comment.