@alchemy/aa-core
Version:
viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts
46 lines • 1.67 kB
JavaScript
import {} from "viem";
import { EntryPointNotFoundError } from "../errors/entrypoint.js";
import EntryPoint_v6 from "./0.6.js";
import EntryPoint_v7 from "./0.7.js";
export const defaultEntryPointVersion = "0.6.0";
export const entryPointRegistry = {
"0.6.0": EntryPoint_v6,
"0.7.0": EntryPoint_v7,
};
export const isEntryPointVersion = (value) => {
return Object.keys(entryPointRegistry).includes(value);
};
export function getEntryPoint(chain, options) {
const { version = defaultEntryPointVersion, addressOverride } = options ?? {
version: defaultEntryPointVersion,
};
const entryPoint = entryPointRegistry[version ?? defaultEntryPointVersion];
const address = addressOverride ??
entryPoint.address[chain.id] ??
entryPoint.address.default;
if (!address) {
throw new EntryPointNotFoundError(chain, version);
}
if (entryPoint.version === "0.6.0") {
return {
version: entryPoint.version,
address,
chain,
abi: entryPoint.abi,
getUserOperationHash: (r) => entryPoint.getUserOperationHash(r, address, chain.id),
packUserOperation: entryPoint.packUserOperation,
};
}
else if (entryPoint.version === "0.7.0") {
return {
version: entryPoint.version,
address,
chain,
abi: entryPoint.abi,
getUserOperationHash: (r) => entryPoint.getUserOperationHash(r, address, chain.id),
packUserOperation: entryPoint.packUserOperation,
};
}
throw new EntryPointNotFoundError(chain, version);
}
//# sourceMappingURL=index.js.map