Skip to content

Instantly share code, notes, and snippets.

@johanneskares
Created October 29, 2024 10:39
Show Gist options
  • Save johanneskares/3c7dbbe408834c16905231e1345dce7f to your computer and use it in GitHub Desktop.
Save johanneskares/3c7dbbe408834c16905231e1345dce7f to your computer and use it in GitHub Desktop.
Zerodev: Get AA Wallet Address from Owner Address
import { ENTRYPOINT_ADDRESS_V06, getSenderAddress } from "permissionless";
import { type Address, encodeFunctionData, createPublicClient } from "viem";
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
const publicClient = createPublicClient({
chain: mainnet,
transport: http()
})
async function getKernelAddressFromOwner(address: Address) {
const _kernel2_2 = "0x0DA6a956B9488eD4dd761E59f52FDc6c8068E6B5";
const _kernel2_3 = "0xD3F582F6B4814E989Ee8E96bc3175320B5A540ab";
const kernel2_4 = "0xd3082872F8B06073A021b4602e022d5A070d7cfC";
const ecdsaValidatorAddress = "0xd9AB5096a832b9ce79914329DAEE236f8Eea0390";
const accountLogicAddress = kernel2_4;
const accountAddress = await getSenderAddress(publicClient, {
factory: "0x5de4839a76cf55d0c90e2061ef4386d962E15ae3",
factoryData: encodeFunctionData({
abi: createAccountAbi,
functionName: "createAccount",
args: [
accountLogicAddress,
encodeFunctionData({
abi: KernelInitAbi,
functionName: "initialize",
args: [ecdsaValidatorAddress, address],
}),
0n,
],
}),
// biome-ignore lint: entryPoint error
entryPoint: ENTRYPOINT_ADDRESS_V06 as any,
});
return accountAddress;
}
const KernelInitAbi = [
{
inputs: [
{
internalType: "contract IKernelValidator",
name: "_defaultValidator",
type: "address",
},
{
internalType: "bytes",
name: "_data",
type: "bytes",
},
],
name: "initialize",
outputs: [],
stateMutability: "payable",
type: "function",
},
] as const;
const createAccountAbi = [
{
inputs: [
{
internalType: "address",
name: "_implementation",
type: "address",
},
{
internalType: "bytes",
name: "_data",
type: "bytes",
},
{
internalType: "uint256",
name: "_index",
type: "uint256",
},
],
name: "createAccount",
outputs: [
{
internalType: "address",
name: "proxy",
type: "address",
},
],
stateMutability: "payable",
type: "function",
},
] as const;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment