UNPKG

startale-aa-sdk

Version:

SDK for startale account integration with support for account abstraction, ERC-7579, ERC-4337.

56 lines 2.48 kB
import { http } from "viem"; import { createBundlerClient } from "viem/account-abstraction"; import { scsSponsoredPaymasterContext } from "./createSCSPaymasterClient.js"; import { scsBundlerActions } from "./decorators/bundler/index.js"; import { getGasFeeValues } from "./decorators/bundler/getGasFeeValues.js"; import { erc7579Actions } from "./decorators/erc7579/index.js"; import { smartAccountActions } from "./decorators/smartAccount/index.js"; /** * Creates SCS Bundler Client with a given Transport configured for a Chain. * * @param parameters - Configuration for the SCS Bundler Client * @returns SCS Bundler Client * * @example * import { createSCSBundlerClient, http } from 'startale-aa-sdk' * import { mainnet } from 'viem/chains' * * const bundlerClient = createSCSBundlerClient({ chain: mainnet }); */ export const createSCSBundlerClient = (parameters) => { const { mock = false, transport, bundlerUrl, apiKey, paymaster, paymasterContext, userOperation, chain } = parameters; if (!apiKey && !bundlerUrl && !transport && !chain) { throw new Error("Cannot set determine a bundler url, please provide a chain."); } const defaultedTransport = transport ? transport : bundlerUrl ? http(bundlerUrl) : http( // @ts-ignore: Type saftey provided by the if statement above `https://bundler.biconomy.io/api/v3/${chain?.id}/${apiKey ?? "nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f14"}`); const defaultedPaymasterContext = paymaster ? (paymasterContext ?? scsSponsoredPaymasterContext) : undefined; const defaultedUserOperation = userOperation ?? { estimateFeesPerGas: async () => { return (await getGasFeeValues(bundler_)).fast; } }; const bundler_ = createBundlerClient({ ...parameters, transport: defaultedTransport, paymasterContext: defaultedPaymasterContext, userOperation: defaultedUserOperation }) .extend((client) => ({ ...client, mock })) .extend(scsBundlerActions()) .extend(erc7579Actions()) .extend(smartAccountActions()); return bundler_; }; // Aliases for backwards compatibility export const createSmartAccountClient = createSCSBundlerClient; export const createStartaleAccountClient = createSmartAccountClient; export const createStartaleSessionClient = createSmartAccountClient; //# sourceMappingURL=createSCSBundlerClient.js.map