Socket
Socket
Sign inDemoInstall

@alchemy/aa-core

Package Overview
Dependencies
16
Maintainers
2
Versions
81
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.2.0

dist/cjs/account/schema.d.ts

14

./dist/cjs/index.js

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = exports.resolveProperties = exports.getUserOperationHash = exports.getChain = exports.defineReadOnly = exports.deepHexlify = exports.bigIntPercent = exports.bigIntMax = exports.asyncPipe = exports.noOpMiddleware = exports.SmartAccountProvider = exports.convertCoinTypeToChainId = exports.convertCoinTypeToChain = exports.convertChainIdToCoinType = exports.erc4337ClientActions = exports.createPublicErc4337FromClient = exports.createPublicErc4337Client = exports.WalletClientSigner = exports.wrapSignatureWith6492 = exports.verifyEIP6492Signature = exports.LocalAccountSigner = exports.SimpleSmartContractAccount = exports.BaseSmartContractAccount = exports.SimpleAccountFactoryAbi = exports.SimpleAccountAbi = exports.EntryPointAbi = exports.chains = void 0;
exports.Logger = exports.resolveProperties = exports.getUserOperationHash = exports.getDefaultSimpleAccountFactoryAddress = exports.getDefaultEntryPointAddress = exports.getChain = exports.defineReadOnly = exports.deepHexlify = exports.bigIntPercent = exports.bigIntMax = exports.asyncPipe = exports.ChainSchema = exports.createSmartAccountProviderConfigSchema = exports.SmartAccountProviderOptsSchema = exports.noOpMiddleware = exports.SmartAccountProvider = exports.convertCoinTypeToChainId = exports.convertCoinTypeToChain = exports.convertChainIdToCoinType = exports.createPublicErc4337ClientSchema = exports.erc4337ClientActions = exports.createPublicErc4337FromClient = exports.createPublicErc4337Client = exports.WalletClientSigner = exports.wrapSignatureWith6492 = exports.verifyEIP6492Signature = exports.SignerSchema = exports.LocalAccountSigner = exports.SimpleSmartContractAccount = exports.createBaseSmartAccountParamsSchema = exports.BaseSmartContractAccount = exports.SimpleAccountFactoryAbi = exports.SimpleAccountAbi = exports.EntryPointAbi = exports.chains = void 0;
exports.chains = __importStar(require("viem/chains"));

@@ -37,2 +37,4 @@ var EntryPointAbi_js_1 = require("./abis/EntryPointAbi.js");

Object.defineProperty(exports, "BaseSmartContractAccount", { enumerable: true, get: function () { return base_js_1.BaseSmartContractAccount; } });
var schema_js_1 = require("./account/schema.js");
Object.defineProperty(exports, "createBaseSmartAccountParamsSchema", { enumerable: true, get: function () { return schema_js_1.createBaseSmartAccountParamsSchema; } });
var simple_js_1 = require("./account/simple.js");

@@ -42,2 +44,4 @@ Object.defineProperty(exports, "SimpleSmartContractAccount", { enumerable: true, get: function () { return simple_js_1.SimpleSmartContractAccount; } });

Object.defineProperty(exports, "LocalAccountSigner", { enumerable: true, get: function () { return local_account_js_1.LocalAccountSigner; } });
var schema_js_2 = require("./signer/schema.js");
Object.defineProperty(exports, "SignerSchema", { enumerable: true, get: function () { return schema_js_2.SignerSchema; } });
var utils_js_1 = require("./signer/utils.js");

@@ -52,2 +56,4 @@ Object.defineProperty(exports, "verifyEIP6492Signature", { enumerable: true, get: function () { return utils_js_1.verifyEIP6492Signature; } });

Object.defineProperty(exports, "erc4337ClientActions", { enumerable: true, get: function () { return create_client_js_1.erc4337ClientActions; } });
var schema_js_3 = require("./client/schema.js");
Object.defineProperty(exports, "createPublicErc4337ClientSchema", { enumerable: true, get: function () { return schema_js_3.createPublicErc4337ClientSchema; } });
var utils_js_2 = require("./ens/utils.js");

@@ -60,3 +66,7 @@ Object.defineProperty(exports, "convertChainIdToCoinType", { enumerable: true, get: function () { return utils_js_2.convertChainIdToCoinType; } });

Object.defineProperty(exports, "noOpMiddleware", { enumerable: true, get: function () { return base_js_2.noOpMiddleware; } });
var schema_js_4 = require("./provider/schema.js");
Object.defineProperty(exports, "SmartAccountProviderOptsSchema", { enumerable: true, get: function () { return schema_js_4.SmartAccountProviderOptsSchema; } });
Object.defineProperty(exports, "createSmartAccountProviderConfigSchema", { enumerable: true, get: function () { return schema_js_4.createSmartAccountProviderConfigSchema; } });
var index_js_1 = require("./utils/index.js");
Object.defineProperty(exports, "ChainSchema", { enumerable: true, get: function () { return index_js_1.ChainSchema; } });
Object.defineProperty(exports, "asyncPipe", { enumerable: true, get: function () { return index_js_1.asyncPipe; } });

@@ -68,2 +78,4 @@ Object.defineProperty(exports, "bigIntMax", { enumerable: true, get: function () { return index_js_1.bigIntMax; } });

Object.defineProperty(exports, "getChain", { enumerable: true, get: function () { return index_js_1.getChain; } });
Object.defineProperty(exports, "getDefaultEntryPointAddress", { enumerable: true, get: function () { return index_js_1.getDefaultEntryPointAddress; } });
Object.defineProperty(exports, "getDefaultSimpleAccountFactoryAddress", { enumerable: true, get: function () { return index_js_1.getDefaultSimpleAccountFactoryAddress; } });
Object.defineProperty(exports, "getUserOperationHash", { enumerable: true, get: function () { return index_js_1.getUserOperationHash; } });

@@ -70,0 +82,0 @@ Object.defineProperty(exports, "resolveProperties", { enumerable: true, get: function () { return index_js_1.resolveProperties; } });

17

dist/cjs/account/base.d.ts

@@ -7,3 +7,3 @@ import type { Address } from "abitype";

import type { BatchUserOperationCallData } from "../types.js";
import type { ISmartContractAccount, SignTypedDataParams } from "./types.js";
import type { BaseSmartAccountParams, ISmartContractAccount, SignTypedDataParams } from "./types.js";
export declare enum DeploymentState {

@@ -14,10 +14,2 @@ UNDEFINED = "0x0",

}
export interface BaseSmartAccountParams<TTransport extends SupportedTransports = Transport> {
rpcClient: string | PublicErc4337Client<TTransport>;
entryPointAddress: Address;
factoryAddress: Address;
owner?: SmartAccountSigner | undefined;
chain: Chain;
accountAddress?: Address;
}
export declare abstract class BaseSmartContractAccount<TTransport extends SupportedTransports = Transport> implements ISmartContractAccount {

@@ -27,2 +19,3 @@ protected factoryAddress: Address;

protected accountAddress?: Address;
protected accountInitCode?: Hex;
protected owner: SmartAccountSigner | undefined;

@@ -32,3 +25,3 @@ protected entryPoint: GetContractReturnType<typeof EntryPointAbi, PublicClient, Chain>;

protected rpcProvider: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;
constructor(params: BaseSmartAccountParams<TTransport>);
constructor(params_: BaseSmartAccountParams<TTransport>);
abstract getDummySignature(): Hash;

@@ -41,3 +34,2 @@ abstract encodeExecute(target: string, value: bigint, data: string): Promise<Hash>;

signTypedDataWith6492(params: SignTypedDataParams): Promise<`0x${string}`>;
private create6492Signature;
encodeBatchExecute(_txs: BatchUserOperationCallData): Promise<`0x${string}`>;

@@ -49,2 +41,3 @@ getNonce(): Promise<bigint>;

getFactoryAddress(): Address;
getEntryPointAddress(): Address;
isAccountDeployed(): Promise<boolean>;

@@ -56,2 +49,4 @@ getDeploymentState(): Promise<DeploymentState>;

]>;
private _getAccountInitCode;
private create6492Signature;
}

@@ -9,2 +9,4 @@ "use strict";

const utils_js_1 = require("../signer/utils.js");
const defaults_js_1 = require("../utils/defaults.js");
const schema_js_1 = require("./schema.js");
var DeploymentState;

@@ -17,3 +19,3 @@ (function (DeploymentState) {

class BaseSmartContractAccount {
constructor(params) {
constructor(params_) {
Object.defineProperty(this, "factoryAddress", {

@@ -37,2 +39,8 @@ enumerable: true,

});
Object.defineProperty(this, "accountInitCode", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "owner", {

@@ -62,3 +70,5 @@ enumerable: true,

});
this.entryPointAddress = params.entryPointAddress;
const params = (0, schema_js_1.createBaseSmartAccountParamsSchema)().parse(params_);
this.entryPointAddress =
params.entryPointAddress ?? (0, defaults_js_1.getDefaultEntryPointAddress)(params.chain);
const rpcUrl = typeof params.rpcClient === "string"

@@ -82,3 +92,3 @@ ? params.rpcClient

...fetchOptions?.headers,
"Alchemy-Aa-Sdk-Signer": params.owner?.signerType,
"Alchemy-Aa-Sdk-Signer": params.owner?.signerType || "unknown",
"Alchemy-Aa-Sdk-Factory-Address": params.factoryAddress,

@@ -92,4 +102,5 @@ },

this.owner = params.owner;
this.accountInitCode = params.initCode;
this.entryPoint = (0, viem_1.getContract)({
address: params.entryPointAddress,
address: this.entryPointAddress,
abi: EntryPointAbi_js_1.EntryPointAbi,

@@ -116,15 +127,2 @@ publicClient: this.rpcProvider,

}
async create6492Signature(isDeployed, signature) {
if (isDeployed) {
return signature;
}
const [factoryAddress, factoryCalldata] = await this.parseFactoryAddressFromAccountInitCode();
logger_js_1.Logger.debug(`[BaseSmartContractAccount](create6492Signature)\
factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`);
return (0, utils_js_1.wrapSignatureWith6492)({
factoryAddress,
factoryCalldata,
signature,
});
}
async encodeBatchExecute(_txs) {

@@ -154,7 +152,7 @@ throw new Error("encodeBatchExecute not supported");

}
return this.getAccountInitCode();
return this._getAccountInitCode();
}
async getAddress() {
if (!this.accountAddress) {
const initCode = await this.getAccountInitCode();
const initCode = await this._getAccountInitCode();
logger_js_1.Logger.debug("[BaseSmartContractAccount](getAddress) initCode: ", initCode);

@@ -181,2 +179,5 @@ try {

}
getEntryPointAddress() {
return this.entryPointAddress;
}
async isAccountDeployed() {

@@ -197,3 +198,3 @@ return (await this.getDeploymentState()) === DeploymentState.DEPLOYED;

async parseFactoryAddressFromAccountInitCode() {
const initCode = await this.getAccountInitCode();
const initCode = await this._getAccountInitCode();
const factoryAddress = `0x${initCode.substring(2, 42)}`;

@@ -203,4 +204,20 @@ const factoryCalldata = `0x${initCode.substring(42)}`;

}
async _getAccountInitCode() {
return this.accountInitCode ?? this.getAccountInitCode();
}
async create6492Signature(isDeployed, signature) {
if (isDeployed) {
return signature;
}
const [factoryAddress, factoryCalldata] = await this.parseFactoryAddressFromAccountInitCode();
logger_js_1.Logger.debug(`[BaseSmartContractAccount](create6492Signature)\
factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`);
return (0, utils_js_1.wrapSignatureWith6492)({
factoryAddress,
factoryCalldata,
signature,
});
}
}
exports.BaseSmartContractAccount = BaseSmartContractAccount;
//# sourceMappingURL=base.js.map
import { type FallbackTransport, type Hex, type Transport } from "viem";
import type { SmartAccountSigner } from "../signer/types.js";
import type { BatchUserOperationCallData } from "../types.js";
import { BaseSmartContractAccount, type BaseSmartAccountParams } from "./base.js";
import type { SmartAccountSigner } from "../signer/types.js";
export interface SimpleSmartAccountParams<TTransport extends Transport | FallbackTransport = Transport> extends BaseSmartAccountParams<TTransport> {
owner: SmartAccountSigner;
index?: bigint;
}
import { BaseSmartContractAccount } from "./base.js";
import type { SimpleSmartAccountParams } from "./types.js";
export declare class SimpleSmartContractAccount<TTransport extends Transport | FallbackTransport = Transport> extends BaseSmartContractAccount<TTransport> {

@@ -10,0 +7,0 @@ protected owner: SmartAccountSigner;

@@ -8,4 +8,6 @@ "use strict";

const base_js_1 = require("./base.js");
const schema_js_1 = require("./schema.js");
class SimpleSmartContractAccount extends base_js_1.BaseSmartContractAccount {
constructor(params) {
(0, schema_js_1.SimpleSmartAccountParamsSchema)().parse(params);
super(params);

@@ -12,0 +14,0 @@ Object.defineProperty(this, "owner", {

import type { Address } from "abitype";
import type { Hash, Hex } from "viem";
import type { Hash, Hex, Transport } from "viem";
import type { SignTypedDataParameters } from "viem/accounts";
import type { z } from "zod";
import type { SupportedTransports } from "../client/types";
import type { SmartAccountSigner } from "../signer/types";
import type { BatchUserOperationCallData } from "../types";
import type { SmartAccountSigner } from "../signer/types";
import type { SimpleSmartAccountParamsSchema, createBaseSmartAccountParamsSchema } from "./schema";
export type SignTypedDataParams = Omit<SignTypedDataParameters, "privateKey">;
export type BaseSmartAccountParams<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof createBaseSmartAccountParamsSchema<TTransport>>>;
export type SimpleSmartAccountParams<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof SimpleSmartAccountParamsSchema<TTransport>>>;
export interface ISmartContractAccount {

@@ -20,2 +25,3 @@ getInitCode(): Promise<Hex>;

getFactoryAddress(): Address;
getEntryPointAddress(): Address;
}

@@ -8,7 +8,8 @@ export type { Abi } from "abitype";

export { BaseSmartContractAccount } from "./account/base.js";
export type { BaseSmartAccountParams } from "./account/base.js";
export { createBaseSmartAccountParamsSchema } from "./account/schema.js";
export { SimpleSmartContractAccount } from "./account/simple.js";
export type { SimpleSmartAccountParams } from "./account/simple.js";
export type * from "./account/types.js";
export type { BaseSmartAccountParams } from "./account/types.js";
export { LocalAccountSigner } from "./signer/local-account.js";
export { SignerSchema } from "./signer/schema.js";
export type { SmartAccountSigner } from "./signer/types.js";

@@ -18,11 +19,12 @@ export { verifyEIP6492Signature, wrapSignatureWith6492, } from "./signer/utils.js";

export { createPublicErc4337Client, createPublicErc4337FromClient, erc4337ClientActions, } from "./client/create-client.js";
export { createPublicErc4337ClientSchema } from "./client/schema.js";
export type * from "./client/types.js";
export { convertChainIdToCoinType, convertCoinTypeToChain, convertCoinTypeToChainId, } from "./ens/utils.js";
export { SmartAccountProvider, noOpMiddleware } from "./provider/base.js";
export type { SmartAccountProviderConfig, SmartAccountProviderOpts, } from "./provider/base.js";
export { SmartAccountProviderOptsSchema, createSmartAccountProviderConfigSchema, } from "./provider/schema.js";
export type * from "./provider/types.js";
export type * from "./types.js";
export type * from "./utils/index.js";
export { asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getChain, getUserOperationHash, resolveProperties, } from "./utils/index.js";
export { ChainSchema, asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getChain, getDefaultEntryPointAddress, getDefaultSimpleAccountFactoryAddress, getUserOperationHash, resolveProperties, } from "./utils/index.js";
export { Logger } from "./logger.js";
export type { LogLevel } from "./logger.js";

@@ -26,3 +26,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = exports.resolveProperties = exports.getUserOperationHash = exports.getChain = exports.defineReadOnly = exports.deepHexlify = exports.bigIntPercent = exports.bigIntMax = exports.asyncPipe = exports.noOpMiddleware = exports.SmartAccountProvider = exports.convertCoinTypeToChainId = exports.convertCoinTypeToChain = exports.convertChainIdToCoinType = exports.erc4337ClientActions = exports.createPublicErc4337FromClient = exports.createPublicErc4337Client = exports.WalletClientSigner = exports.wrapSignatureWith6492 = exports.verifyEIP6492Signature = exports.LocalAccountSigner = exports.SimpleSmartContractAccount = exports.BaseSmartContractAccount = exports.SimpleAccountFactoryAbi = exports.SimpleAccountAbi = exports.EntryPointAbi = exports.chains = void 0;
exports.Logger = exports.resolveProperties = exports.getUserOperationHash = exports.getDefaultSimpleAccountFactoryAddress = exports.getDefaultEntryPointAddress = exports.getChain = exports.defineReadOnly = exports.deepHexlify = exports.bigIntPercent = exports.bigIntMax = exports.asyncPipe = exports.ChainSchema = exports.createSmartAccountProviderConfigSchema = exports.SmartAccountProviderOptsSchema = exports.noOpMiddleware = exports.SmartAccountProvider = exports.convertCoinTypeToChainId = exports.convertCoinTypeToChain = exports.convertChainIdToCoinType = exports.createPublicErc4337ClientSchema = exports.erc4337ClientActions = exports.createPublicErc4337FromClient = exports.createPublicErc4337Client = exports.WalletClientSigner = exports.wrapSignatureWith6492 = exports.verifyEIP6492Signature = exports.SignerSchema = exports.LocalAccountSigner = exports.SimpleSmartContractAccount = exports.createBaseSmartAccountParamsSchema = exports.BaseSmartContractAccount = exports.SimpleAccountFactoryAbi = exports.SimpleAccountAbi = exports.EntryPointAbi = exports.chains = void 0;
exports.chains = __importStar(require("viem/chains"));

@@ -37,2 +37,4 @@ var EntryPointAbi_js_1 = require("./abis/EntryPointAbi.js");

Object.defineProperty(exports, "BaseSmartContractAccount", { enumerable: true, get: function () { return base_js_1.BaseSmartContractAccount; } });
var schema_js_1 = require("./account/schema.js");
Object.defineProperty(exports, "createBaseSmartAccountParamsSchema", { enumerable: true, get: function () { return schema_js_1.createBaseSmartAccountParamsSchema; } });
var simple_js_1 = require("./account/simple.js");

@@ -42,2 +44,4 @@ Object.defineProperty(exports, "SimpleSmartContractAccount", { enumerable: true, get: function () { return simple_js_1.SimpleSmartContractAccount; } });

Object.defineProperty(exports, "LocalAccountSigner", { enumerable: true, get: function () { return local_account_js_1.LocalAccountSigner; } });
var schema_js_2 = require("./signer/schema.js");
Object.defineProperty(exports, "SignerSchema", { enumerable: true, get: function () { return schema_js_2.SignerSchema; } });
var utils_js_1 = require("./signer/utils.js");

@@ -52,2 +56,4 @@ Object.defineProperty(exports, "verifyEIP6492Signature", { enumerable: true, get: function () { return utils_js_1.verifyEIP6492Signature; } });

Object.defineProperty(exports, "erc4337ClientActions", { enumerable: true, get: function () { return create_client_js_1.erc4337ClientActions; } });
var schema_js_3 = require("./client/schema.js");
Object.defineProperty(exports, "createPublicErc4337ClientSchema", { enumerable: true, get: function () { return schema_js_3.createPublicErc4337ClientSchema; } });
var utils_js_2 = require("./ens/utils.js");

@@ -60,3 +66,7 @@ Object.defineProperty(exports, "convertChainIdToCoinType", { enumerable: true, get: function () { return utils_js_2.convertChainIdToCoinType; } });

Object.defineProperty(exports, "noOpMiddleware", { enumerable: true, get: function () { return base_js_2.noOpMiddleware; } });
var schema_js_4 = require("./provider/schema.js");
Object.defineProperty(exports, "SmartAccountProviderOptsSchema", { enumerable: true, get: function () { return schema_js_4.SmartAccountProviderOptsSchema; } });
Object.defineProperty(exports, "createSmartAccountProviderConfigSchema", { enumerable: true, get: function () { return schema_js_4.createSmartAccountProviderConfigSchema; } });
var index_js_1 = require("./utils/index.js");
Object.defineProperty(exports, "ChainSchema", { enumerable: true, get: function () { return index_js_1.ChainSchema; } });
Object.defineProperty(exports, "asyncPipe", { enumerable: true, get: function () { return index_js_1.asyncPipe; } });

@@ -68,2 +78,4 @@ Object.defineProperty(exports, "bigIntMax", { enumerable: true, get: function () { return index_js_1.bigIntMax; } });

Object.defineProperty(exports, "getChain", { enumerable: true, get: function () { return index_js_1.getChain; } });
Object.defineProperty(exports, "getDefaultEntryPointAddress", { enumerable: true, get: function () { return index_js_1.getDefaultEntryPointAddress; } });
Object.defineProperty(exports, "getDefaultSimpleAccountFactoryAddress", { enumerable: true, get: function () { return index_js_1.getDefaultSimpleAccountFactoryAddress; } });
Object.defineProperty(exports, "getUserOperationHash", { enumerable: true, get: function () { return index_js_1.getUserOperationHash; } });

@@ -70,0 +82,0 @@ Object.defineProperty(exports, "resolveProperties", { enumerable: true, get: function () { return index_js_1.resolveProperties; } });

@@ -6,16 +6,4 @@ import { default as EventEmitter } from "eventemitter3";

import { type BatchUserOperationCallData, type UserOperationCallData, type UserOperationOverrides, type UserOperationReceipt, type UserOperationRequest, type UserOperationResponse, type UserOperationStruct } from "../types.js";
import type { AccountMiddlewareFn, FeeDataMiddleware, GasEstimatorMiddleware, ISmartAccountProvider, PaymasterAndDataMiddleware, ProviderEvents, SendUserOperationResult } from "./types.js";
import type { AccountMiddlewareFn, FeeDataMiddleware, GasEstimatorMiddleware, ISmartAccountProvider, PaymasterAndDataMiddleware, ProviderEvents, SendUserOperationResult, SmartAccountProviderConfig } from "./types.js";
export declare const noOpMiddleware: AccountMiddlewareFn;
export interface SmartAccountProviderOpts {
txMaxRetries?: number;
txRetryIntervalMs?: number;
txRetryMulitplier?: number;
minPriorityFeePerBid?: bigint;
}
export type SmartAccountProviderConfig<TTransport extends SupportedTransports = Transport> = {
rpcProvider: string | PublicErc4337Client<TTransport>;
chain: Chain;
entryPointAddress: Address;
opts?: SmartAccountProviderOpts;
};
export declare class SmartAccountProvider<TTransport extends SupportedTransports = Transport> extends EventEmitter<ProviderEvents> implements ISmartAccountProvider<TTransport> {

@@ -25,8 +13,8 @@ private txMaxRetries;

private txRetryMulitplier;
private minPriorityFeePerBid;
readonly account?: ISmartContractAccount;
protected entryPointAddress: Address;
protected entryPointAddress?: Address;
protected chain: Chain;
minPriorityFeePerBid: bigint;
rpcClient: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;
constructor({ rpcProvider, entryPointAddress, chain, opts, }: SmartAccountProviderConfig<TTransport>);
constructor(config: SmartAccountProviderConfig<TTransport>);
request: (args: {

@@ -74,4 +62,5 @@ method: string;

};
getEntryPointAddress: () => Address;
extend: <R>(fn: (self: this) => R) => this & R;
private overrideMiddlewareFunction;
}

@@ -11,4 +11,4 @@ "use strict";

const create_client_js_1 = require("../client/create-client.js");
const types_js_1 = require("../types.js");
const index_js_1 = require("../utils/index.js");
const schema_js_1 = require("./schema.js");
const noOpMiddleware = async (struct) => struct;

@@ -21,3 +21,5 @@ exports.noOpMiddleware = noOpMiddleware;

class SmartAccountProvider extends eventemitter3_1.default {
constructor({ rpcProvider, entryPointAddress, chain, opts, }) {
constructor(config) {
(0, schema_js_1.createSmartAccountProviderConfigSchema)().parse(config);
const { rpcProvider, entryPointAddress, chain, opts } = config;
super();

@@ -42,3 +44,3 @@ Object.defineProperty(this, "txMaxRetries", {

});
Object.defineProperty(this, "account", {
Object.defineProperty(this, "minPriorityFeePerBid", {
enumerable: true,

@@ -49,3 +51,3 @@ configurable: true,

});
Object.defineProperty(this, "entryPointAddress", {
Object.defineProperty(this, "account", {
enumerable: true,

@@ -56,3 +58,3 @@ configurable: true,

});
Object.defineProperty(this, "chain", {
Object.defineProperty(this, "entryPointAddress", {
enumerable: true,

@@ -63,3 +65,3 @@ configurable: true,

});
Object.defineProperty(this, "minPriorityFeePerBid", {
Object.defineProperty(this, "chain", {
enumerable: true,

@@ -345,8 +347,8 @@ configurable: true,

const request = (0, index_js_1.deepHexlify)(uoStruct);
if (!(0, types_js_1.isValidRequest)(request)) {
if (!(0, index_js_1.isValidRequest)(request)) {
throw new Error(`Request is missing parameters. All properties on UserOperationStruct must be set. uo: ${JSON.stringify(request, null, 2)}`);
}
request.signature = (await this.account.signMessage((0, index_js_1.getUserOperationHash)(request, this.entryPointAddress, BigInt(this.chain.id))));
request.signature = (await this.account.signMessage((0, index_js_1.getUserOperationHash)(request, this.getEntryPointAddress(), BigInt(this.chain.id))));
return {
hash: await this.rpcClient.sendUserOperation(request, this.entryPointAddress),
hash: await this.rpcClient.sendUserOperation(request, this.getEntryPointAddress()),
request,

@@ -380,3 +382,3 @@ };

const request = (0, index_js_1.deepHexlify)(await (0, index_js_1.resolveProperties)(struct));
const estimates = await this.rpcClient.estimateUserOperationGas(request, this.entryPointAddress);
const estimates = await this.rpcClient.estimateUserOperationGas(request, this.getEntryPointAddress());
struct.callGasLimit = estimates.callGasLimit;

@@ -465,2 +467,6 @@ struct.verificationGasLimit = estimates.verificationGasLimit;

const account = fn(this.rpcClient);
if (this.entryPointAddress &&
account.getEntryPointAddress() !== this.entryPointAddress) {
throw new Error(`Account entryPoint address: ${account.getEntryPointAddress()} does not match the current provider's entryPoint address: ${this.entryPointAddress}`);
}
(0, index_js_1.defineReadOnly)(this, "account", account);

@@ -479,3 +485,3 @@ if (this.rpcClient.transport.type === "http") {

...fetchOptions?.headers,
"Alchemy-Aa-Sdk-Signer": signer?.signerType,
"Alchemy-Aa-Sdk-Signer": signer?.signerType || "unknown",
"Alchemy-Aa-Sdk-Factory-Address": factoryAddress,

@@ -516,2 +522,12 @@ },

});
Object.defineProperty(this, "getEntryPointAddress", {
enumerable: true,
configurable: true,
writable: true,
value: () => {
return (this.entryPointAddress ??
this.account?.getEntryPointAddress() ??
(0, index_js_1.getDefaultEntryPointAddress)(this.chain));
}
});
Object.defineProperty(this, "extend", {

@@ -542,3 +558,2 @@ enumerable: true,

});
this.entryPointAddress = entryPointAddress;
this.chain = chain;

@@ -548,2 +563,3 @@ this.txMaxRetries = opts?.txMaxRetries ?? 5;

this.txRetryMulitplier = opts?.txRetryMulitplier ?? 1.5;
this.entryPointAddress = entryPointAddress;
this.minPriorityFeePerBid =

@@ -550,0 +566,0 @@ opts?.minPriorityFeePerBid ??

import type { Address } from "abitype";
import type { Hash, Hex, HttpTransport, RpcTransactionRequest, Transport } from "viem";
import type { SignTypedDataParameters } from "viem/accounts";
import type { z } from "zod";
import type { ISmartContractAccount, SignTypedDataParams } from "../account/types.js";

@@ -8,2 +9,3 @@ import type { PublicErc4337Client, SupportedTransports } from "../client/types.js";

import type { Deferrable } from "../utils";
import type { SmartAccountProviderOptsSchema, createSmartAccountProviderConfigSchema } from "./schema.js";
type WithRequired<T, K extends keyof T> = Required<Pick<T, K>>;

@@ -34,2 +36,4 @@ type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K>;

export type FeeDataMiddleware = AccountMiddlewareOverrideFn<"maxFeePerGas" | "maxPriorityFeePerGas">;
export type SmartAccountProviderOpts = z.infer<typeof SmartAccountProviderOptsSchema>;
export type SmartAccountProviderConfig<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof createSmartAccountProviderConfigSchema<TTransport>>>;
export interface ISmartAccountProvider<TTransport extends SupportedTransports = Transport> {

@@ -36,0 +40,0 @@ readonly rpcClient: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;

@@ -93,2 +93,1 @@ import type { Address, Hash } from "viem";

}
export declare function isValidRequest(request: UserOperationStruct): request is UserOperationRequest;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isValidRequest = void 0;
function isValidRequest(request) {
return (!!request.callGasLimit &&
!!request.maxFeePerGas &&
request.maxPriorityFeePerGas != null &&
!!request.preVerificationGas &&
!!request.verificationGasLimit);
}
exports.isValidRequest = isValidRequest;
//# sourceMappingURL=types.js.map

@@ -14,1 +14,4 @@ import type { Address, Hash } from "viem";

export * from "./bigint.js";
export * from "./defaults.js";
export * from "./schema.js";
export * from "./userop.js";

@@ -125,2 +125,5 @@ "use strict";

__exportStar(require("./bigint.js"), exports);
__exportStar(require("./defaults.js"), exports);
__exportStar(require("./schema.js"), exports);
__exportStar(require("./userop.js"), exports);
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

export declare const VERSION = "0.1.1";
export declare const VERSION = "0.2.0";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERSION = void 0;
exports.VERSION = "0.1.1";
exports.VERSION = "0.2.0";
//# sourceMappingURL=version.js.map

@@ -7,3 +7,3 @@ import type { Address } from "abitype";

import type { BatchUserOperationCallData } from "../types.js";
import type { ISmartContractAccount, SignTypedDataParams } from "./types.js";
import type { BaseSmartAccountParams, ISmartContractAccount, SignTypedDataParams } from "./types.js";
export declare enum DeploymentState {

@@ -14,10 +14,2 @@ UNDEFINED = "0x0",

}
export interface BaseSmartAccountParams<TTransport extends SupportedTransports = Transport> {
rpcClient: string | PublicErc4337Client<TTransport>;
entryPointAddress: Address;
factoryAddress: Address;
owner?: SmartAccountSigner | undefined;
chain: Chain;
accountAddress?: Address;
}
export declare abstract class BaseSmartContractAccount<TTransport extends SupportedTransports = Transport> implements ISmartContractAccount {

@@ -27,2 +19,3 @@ protected factoryAddress: Address;

protected accountAddress?: Address;
protected accountInitCode?: Hex;
protected owner: SmartAccountSigner | undefined;

@@ -32,3 +25,3 @@ protected entryPoint: GetContractReturnType<typeof EntryPointAbi, PublicClient, Chain>;

protected rpcProvider: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;
constructor(params: BaseSmartAccountParams<TTransport>);
constructor(params_: BaseSmartAccountParams<TTransport>);
abstract getDummySignature(): Hash;

@@ -41,3 +34,2 @@ abstract encodeExecute(target: string, value: bigint, data: string): Promise<Hash>;

signTypedDataWith6492(params: SignTypedDataParams): Promise<`0x${string}`>;
private create6492Signature;
encodeBatchExecute(_txs: BatchUserOperationCallData): Promise<`0x${string}`>;

@@ -49,2 +41,3 @@ getNonce(): Promise<bigint>;

getFactoryAddress(): Address;
getEntryPointAddress(): Address;
isAccountDeployed(): Promise<boolean>;

@@ -56,2 +49,4 @@ getDeploymentState(): Promise<DeploymentState>;

]>;
private _getAccountInitCode;
private create6492Signature;
}

@@ -6,2 +6,4 @@ import { getContract, } from "viem";

import { wrapSignatureWith6492 } from "../signer/utils.js";
import { getDefaultEntryPointAddress } from "../utils/defaults.js";
import { createBaseSmartAccountParamsSchema } from "./schema.js";
export var DeploymentState;

@@ -14,3 +16,3 @@ (function (DeploymentState) {

export class BaseSmartContractAccount {
constructor(params) {
constructor(params_) {
Object.defineProperty(this, "factoryAddress", {

@@ -34,2 +36,8 @@ enumerable: true,

});
Object.defineProperty(this, "accountInitCode", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "owner", {

@@ -59,3 +67,5 @@ enumerable: true,

});
this.entryPointAddress = params.entryPointAddress;
const params = createBaseSmartAccountParamsSchema().parse(params_);
this.entryPointAddress =
params.entryPointAddress ?? getDefaultEntryPointAddress(params.chain);
const rpcUrl = typeof params.rpcClient === "string"

@@ -79,3 +89,3 @@ ? params.rpcClient

...fetchOptions?.headers,
"Alchemy-Aa-Sdk-Signer": params.owner?.signerType,
"Alchemy-Aa-Sdk-Signer": params.owner?.signerType || "unknown",
"Alchemy-Aa-Sdk-Factory-Address": params.factoryAddress,

@@ -89,4 +99,5 @@ },

this.owner = params.owner;
this.accountInitCode = params.initCode;
this.entryPoint = getContract({
address: params.entryPointAddress,
address: this.entryPointAddress,
abi: EntryPointAbi,

@@ -113,15 +124,2 @@ publicClient: this.rpcProvider,

}
async create6492Signature(isDeployed, signature) {
if (isDeployed) {
return signature;
}
const [factoryAddress, factoryCalldata] = await this.parseFactoryAddressFromAccountInitCode();
Logger.debug(`[BaseSmartContractAccount](create6492Signature)\
factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`);
return wrapSignatureWith6492({
factoryAddress,
factoryCalldata,
signature,
});
}
async encodeBatchExecute(_txs) {

@@ -151,7 +149,7 @@ throw new Error("encodeBatchExecute not supported");

}
return this.getAccountInitCode();
return this._getAccountInitCode();
}
async getAddress() {
if (!this.accountAddress) {
const initCode = await this.getAccountInitCode();
const initCode = await this._getAccountInitCode();
Logger.debug("[BaseSmartContractAccount](getAddress) initCode: ", initCode);

@@ -178,2 +176,5 @@ try {

}
getEntryPointAddress() {
return this.entryPointAddress;
}
async isAccountDeployed() {

@@ -194,3 +195,3 @@ return (await this.getDeploymentState()) === DeploymentState.DEPLOYED;

async parseFactoryAddressFromAccountInitCode() {
const initCode = await this.getAccountInitCode();
const initCode = await this._getAccountInitCode();
const factoryAddress = `0x${initCode.substring(2, 42)}`;

@@ -200,3 +201,19 @@ const factoryCalldata = `0x${initCode.substring(42)}`;

}
async _getAccountInitCode() {
return this.accountInitCode ?? this.getAccountInitCode();
}
async create6492Signature(isDeployed, signature) {
if (isDeployed) {
return signature;
}
const [factoryAddress, factoryCalldata] = await this.parseFactoryAddressFromAccountInitCode();
Logger.debug(`[BaseSmartContractAccount](create6492Signature)\
factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`);
return wrapSignatureWith6492({
factoryAddress,
factoryCalldata,
signature,
});
}
}
//# sourceMappingURL=base.js.map
import { type FallbackTransport, type Hex, type Transport } from "viem";
import type { SmartAccountSigner } from "../signer/types.js";
import type { BatchUserOperationCallData } from "../types.js";
import { BaseSmartContractAccount, type BaseSmartAccountParams } from "./base.js";
import type { SmartAccountSigner } from "../signer/types.js";
export interface SimpleSmartAccountParams<TTransport extends Transport | FallbackTransport = Transport> extends BaseSmartAccountParams<TTransport> {
owner: SmartAccountSigner;
index?: bigint;
}
import { BaseSmartContractAccount } from "./base.js";
import type { SimpleSmartAccountParams } from "./types.js";
export declare class SimpleSmartContractAccount<TTransport extends Transport | FallbackTransport = Transport> extends BaseSmartContractAccount<TTransport> {

@@ -10,0 +7,0 @@ protected owner: SmartAccountSigner;

import { concatHex, encodeFunctionData, hexToBytes, } from "viem";
import { SimpleAccountAbi } from "../abis/SimpleAccountAbi.js";
import { SimpleAccountFactoryAbi } from "../abis/SimpleAccountFactoryAbi.js";
import { BaseSmartContractAccount, } from "./base.js";
import { BaseSmartContractAccount } from "./base.js";
import { SimpleSmartAccountParamsSchema } from "./schema.js";
export class SimpleSmartContractAccount extends BaseSmartContractAccount {
constructor(params) {
SimpleSmartAccountParamsSchema().parse(params);
super(params);

@@ -8,0 +10,0 @@ Object.defineProperty(this, "owner", {

import type { Address } from "abitype";
import type { Hash, Hex } from "viem";
import type { Hash, Hex, Transport } from "viem";
import type { SignTypedDataParameters } from "viem/accounts";
import type { z } from "zod";
import type { SupportedTransports } from "../client/types";
import type { SmartAccountSigner } from "../signer/types";
import type { BatchUserOperationCallData } from "../types";
import type { SmartAccountSigner } from "../signer/types";
import type { SimpleSmartAccountParamsSchema, createBaseSmartAccountParamsSchema } from "./schema";
export type SignTypedDataParams = Omit<SignTypedDataParameters, "privateKey">;
export type BaseSmartAccountParams<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof createBaseSmartAccountParamsSchema<TTransport>>>;
export type SimpleSmartAccountParams<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof SimpleSmartAccountParamsSchema<TTransport>>>;
export interface ISmartContractAccount {

@@ -20,2 +25,3 @@ getInitCode(): Promise<Hex>;

getFactoryAddress(): Address;
getEntryPointAddress(): Address;
}

@@ -8,7 +8,8 @@ export type { Abi } from "abitype";

export { BaseSmartContractAccount } from "./account/base.js";
export type { BaseSmartAccountParams } from "./account/base.js";
export { createBaseSmartAccountParamsSchema } from "./account/schema.js";
export { SimpleSmartContractAccount } from "./account/simple.js";
export type { SimpleSmartAccountParams } from "./account/simple.js";
export type * from "./account/types.js";
export type { BaseSmartAccountParams } from "./account/types.js";
export { LocalAccountSigner } from "./signer/local-account.js";
export { SignerSchema } from "./signer/schema.js";
export type { SmartAccountSigner } from "./signer/types.js";

@@ -18,11 +19,12 @@ export { verifyEIP6492Signature, wrapSignatureWith6492, } from "./signer/utils.js";

export { createPublicErc4337Client, createPublicErc4337FromClient, erc4337ClientActions, } from "./client/create-client.js";
export { createPublicErc4337ClientSchema } from "./client/schema.js";
export type * from "./client/types.js";
export { convertChainIdToCoinType, convertCoinTypeToChain, convertCoinTypeToChainId, } from "./ens/utils.js";
export { SmartAccountProvider, noOpMiddleware } from "./provider/base.js";
export type { SmartAccountProviderConfig, SmartAccountProviderOpts, } from "./provider/base.js";
export { SmartAccountProviderOptsSchema, createSmartAccountProviderConfigSchema, } from "./provider/schema.js";
export type * from "./provider/types.js";
export type * from "./types.js";
export type * from "./utils/index.js";
export { asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getChain, getUserOperationHash, resolveProperties, } from "./utils/index.js";
export { ChainSchema, asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getChain, getDefaultEntryPointAddress, getDefaultSimpleAccountFactoryAddress, getUserOperationHash, resolveProperties, } from "./utils/index.js";
export { Logger } from "./logger.js";
export type { LogLevel } from "./logger.js";

@@ -7,11 +7,15 @@ import * as chains_1 from "viem/chains";

export { BaseSmartContractAccount } from "./account/base.js";
export { createBaseSmartAccountParamsSchema } from "./account/schema.js";
export { SimpleSmartContractAccount } from "./account/simple.js";
export { LocalAccountSigner } from "./signer/local-account.js";
export { SignerSchema } from "./signer/schema.js";
export { verifyEIP6492Signature, wrapSignatureWith6492, } from "./signer/utils.js";
export { WalletClientSigner } from "./signer/wallet-client.js";
export { createPublicErc4337Client, createPublicErc4337FromClient, erc4337ClientActions, } from "./client/create-client.js";
export { createPublicErc4337ClientSchema } from "./client/schema.js";
export { convertChainIdToCoinType, convertCoinTypeToChain, convertCoinTypeToChainId, } from "./ens/utils.js";
export { SmartAccountProvider, noOpMiddleware } from "./provider/base.js";
export { asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getChain, getUserOperationHash, resolveProperties, } from "./utils/index.js";
export { SmartAccountProviderOptsSchema, createSmartAccountProviderConfigSchema, } from "./provider/schema.js";
export { ChainSchema, asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getChain, getDefaultEntryPointAddress, getDefaultSimpleAccountFactoryAddress, getUserOperationHash, resolveProperties, } from "./utils/index.js";
export { Logger } from "./logger.js";
//# sourceMappingURL=index.js.map

@@ -6,16 +6,4 @@ import { default as EventEmitter } from "eventemitter3";

import { type BatchUserOperationCallData, type UserOperationCallData, type UserOperationOverrides, type UserOperationReceipt, type UserOperationRequest, type UserOperationResponse, type UserOperationStruct } from "../types.js";
import type { AccountMiddlewareFn, FeeDataMiddleware, GasEstimatorMiddleware, ISmartAccountProvider, PaymasterAndDataMiddleware, ProviderEvents, SendUserOperationResult } from "./types.js";
import type { AccountMiddlewareFn, FeeDataMiddleware, GasEstimatorMiddleware, ISmartAccountProvider, PaymasterAndDataMiddleware, ProviderEvents, SendUserOperationResult, SmartAccountProviderConfig } from "./types.js";
export declare const noOpMiddleware: AccountMiddlewareFn;
export interface SmartAccountProviderOpts {
txMaxRetries?: number;
txRetryIntervalMs?: number;
txRetryMulitplier?: number;
minPriorityFeePerBid?: bigint;
}
export type SmartAccountProviderConfig<TTransport extends SupportedTransports = Transport> = {
rpcProvider: string | PublicErc4337Client<TTransport>;
chain: Chain;
entryPointAddress: Address;
opts?: SmartAccountProviderOpts;
};
export declare class SmartAccountProvider<TTransport extends SupportedTransports = Transport> extends EventEmitter<ProviderEvents> implements ISmartAccountProvider<TTransport> {

@@ -25,8 +13,8 @@ private txMaxRetries;

private txRetryMulitplier;
private minPriorityFeePerBid;
readonly account?: ISmartContractAccount;
protected entryPointAddress: Address;
protected entryPointAddress?: Address;
protected chain: Chain;
minPriorityFeePerBid: bigint;
rpcClient: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;
constructor({ rpcProvider, entryPointAddress, chain, opts, }: SmartAccountProviderConfig<TTransport>);
constructor(config: SmartAccountProviderConfig<TTransport>);
request: (args: {

@@ -74,4 +62,5 @@ method: string;

};
getEntryPointAddress: () => Address;
extend: <R>(fn: (self: this) => R) => this & R;
private overrideMiddlewareFunction;
}

@@ -5,4 +5,5 @@ import { default as EventEmitter } from "eventemitter3";

import { createPublicErc4337Client } from "../client/create-client.js";
import { isValidRequest, } from "../types.js";
import { asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getUserOperationHash, resolveProperties, } from "../utils/index.js";
import {} from "../types.js";
import { asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getDefaultEntryPointAddress, getUserOperationHash, isValidRequest, resolveProperties, } from "../utils/index.js";
import { createSmartAccountProviderConfigSchema } from "./schema.js";
export const noOpMiddleware = async (struct) => struct;

@@ -14,3 +15,5 @@ const minPriorityFeePerBidDefaults = new Map([

export class SmartAccountProvider extends EventEmitter {
constructor({ rpcProvider, entryPointAddress, chain, opts, }) {
constructor(config) {
createSmartAccountProviderConfigSchema().parse(config);
const { rpcProvider, entryPointAddress, chain, opts } = config;
super();

@@ -35,3 +38,3 @@ Object.defineProperty(this, "txMaxRetries", {

});
Object.defineProperty(this, "account", {
Object.defineProperty(this, "minPriorityFeePerBid", {
enumerable: true,

@@ -42,3 +45,3 @@ configurable: true,

});
Object.defineProperty(this, "entryPointAddress", {
Object.defineProperty(this, "account", {
enumerable: true,

@@ -49,3 +52,3 @@ configurable: true,

});
Object.defineProperty(this, "chain", {
Object.defineProperty(this, "entryPointAddress", {
enumerable: true,

@@ -56,3 +59,3 @@ configurable: true,

});
Object.defineProperty(this, "minPriorityFeePerBid", {
Object.defineProperty(this, "chain", {
enumerable: true,

@@ -341,5 +344,5 @@ configurable: true,

}
request.signature = (await this.account.signMessage(getUserOperationHash(request, this.entryPointAddress, BigInt(this.chain.id))));
request.signature = (await this.account.signMessage(getUserOperationHash(request, this.getEntryPointAddress(), BigInt(this.chain.id))));
return {
hash: await this.rpcClient.sendUserOperation(request, this.entryPointAddress),
hash: await this.rpcClient.sendUserOperation(request, this.getEntryPointAddress()),
request,

@@ -373,3 +376,3 @@ };

const request = deepHexlify(await resolveProperties(struct));
const estimates = await this.rpcClient.estimateUserOperationGas(request, this.entryPointAddress);
const estimates = await this.rpcClient.estimateUserOperationGas(request, this.getEntryPointAddress());
struct.callGasLimit = estimates.callGasLimit;

@@ -458,2 +461,6 @@ struct.verificationGasLimit = estimates.verificationGasLimit;

const account = fn(this.rpcClient);
if (this.entryPointAddress &&
account.getEntryPointAddress() !== this.entryPointAddress) {
throw new Error(`Account entryPoint address: ${account.getEntryPointAddress()} does not match the current provider's entryPoint address: ${this.entryPointAddress}`);
}
defineReadOnly(this, "account", account);

@@ -472,3 +479,3 @@ if (this.rpcClient.transport.type === "http") {

...fetchOptions?.headers,
"Alchemy-Aa-Sdk-Signer": signer?.signerType,
"Alchemy-Aa-Sdk-Signer": signer?.signerType || "unknown",
"Alchemy-Aa-Sdk-Factory-Address": factoryAddress,

@@ -509,2 +516,12 @@ },

});
Object.defineProperty(this, "getEntryPointAddress", {
enumerable: true,
configurable: true,
writable: true,
value: () => {
return (this.entryPointAddress ??
this.account?.getEntryPointAddress() ??
getDefaultEntryPointAddress(this.chain));
}
});
Object.defineProperty(this, "extend", {

@@ -535,3 +552,2 @@ enumerable: true,

});
this.entryPointAddress = entryPointAddress;
this.chain = chain;

@@ -541,2 +557,3 @@ this.txMaxRetries = opts?.txMaxRetries ?? 5;

this.txRetryMulitplier = opts?.txRetryMulitplier ?? 1.5;
this.entryPointAddress = entryPointAddress;
this.minPriorityFeePerBid =

@@ -543,0 +560,0 @@ opts?.minPriorityFeePerBid ??

import type { Address } from "abitype";
import type { Hash, Hex, HttpTransport, RpcTransactionRequest, Transport } from "viem";
import type { SignTypedDataParameters } from "viem/accounts";
import type { z } from "zod";
import type { ISmartContractAccount, SignTypedDataParams } from "../account/types.js";

@@ -8,2 +9,3 @@ import type { PublicErc4337Client, SupportedTransports } from "../client/types.js";

import type { Deferrable } from "../utils";
import type { SmartAccountProviderOptsSchema, createSmartAccountProviderConfigSchema } from "./schema.js";
type WithRequired<T, K extends keyof T> = Required<Pick<T, K>>;

@@ -34,2 +36,4 @@ type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K>;

export type FeeDataMiddleware = AccountMiddlewareOverrideFn<"maxFeePerGas" | "maxPriorityFeePerGas">;
export type SmartAccountProviderOpts = z.infer<typeof SmartAccountProviderOptsSchema>;
export type SmartAccountProviderConfig<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof createSmartAccountProviderConfigSchema<TTransport>>>;
export interface ISmartAccountProvider<TTransport extends SupportedTransports = Transport> {

@@ -36,0 +40,0 @@ readonly rpcClient: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;

@@ -93,2 +93,1 @@ import type { Address, Hash } from "viem";

}
export declare function isValidRequest(request: UserOperationStruct): request is UserOperationRequest;

@@ -1,8 +0,2 @@

export function isValidRequest(request) {
return (!!request.callGasLimit &&
!!request.maxFeePerGas &&
request.maxPriorityFeePerGas != null &&
!!request.preVerificationGas &&
!!request.verificationGasLimit);
}
export {};
//# sourceMappingURL=types.js.map

@@ -14,1 +14,4 @@ import type { Address, Hash } from "viem";

export * from "./bigint.js";
export * from "./defaults.js";
export * from "./schema.js";
export * from "./userop.js";

@@ -90,2 +90,5 @@ import { encodeAbiParameters, hexToBigInt, keccak256, toHex } from "viem";

export * from "./bigint.js";
export * from "./defaults.js";
export * from "./schema.js";
export * from "./userop.js";
//# sourceMappingURL=index.js.map

@@ -1,1 +0,1 @@

export declare const VERSION = "0.1.1";
export declare const VERSION = "0.2.0";

@@ -1,2 +0,2 @@

export const VERSION = "0.1.1";
export const VERSION = "0.2.0";
//# sourceMappingURL=version.js.map

@@ -7,3 +7,3 @@ import type { Address } from "abitype";

import type { BatchUserOperationCallData } from "../types.js";
import type { ISmartContractAccount, SignTypedDataParams } from "./types.js";
import type { BaseSmartAccountParams, ISmartContractAccount, SignTypedDataParams } from "./types.js";
export declare enum DeploymentState {

@@ -14,10 +14,2 @@ UNDEFINED = "0x0",

}
export interface BaseSmartAccountParams<TTransport extends SupportedTransports = Transport> {
rpcClient: string | PublicErc4337Client<TTransport>;
entryPointAddress: Address;
factoryAddress: Address;
owner?: SmartAccountSigner | undefined;
chain: Chain;
accountAddress?: Address;
}
export declare abstract class BaseSmartContractAccount<TTransport extends SupportedTransports = Transport> implements ISmartContractAccount {

@@ -27,2 +19,3 @@ protected factoryAddress: Address;

protected accountAddress?: Address;
protected accountInitCode?: Hex;
protected owner: SmartAccountSigner | undefined;

@@ -32,3 +25,3 @@ protected entryPoint: GetContractReturnType<typeof EntryPointAbi, PublicClient, Chain>;

protected rpcProvider: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;
constructor(params: BaseSmartAccountParams<TTransport>);
constructor(params_: BaseSmartAccountParams<TTransport>);
/**

@@ -58,3 +51,3 @@ * This method should return a signature that will not `revert` during validation.

* this should return the init code that will be used to create an account if one does not exist.
* Usually this is the concatenation of the account's factory address and the abi encoded function data of the account factory's `createAccount` method.
* This is the concatenation of the account's factory address and the abi encoded function data of the account factory's `createAccount` method.
*/

@@ -84,3 +77,2 @@ protected abstract getAccountInitCode(): Promise<Hash>;

signTypedDataWith6492(params: SignTypedDataParams): Promise<`0x${string}`>;
private create6492Signature;
/**

@@ -100,2 +92,3 @@ * Not all contracts support batch execution.

getFactoryAddress(): Address;
getEntryPointAddress(): Address;
isAccountDeployed(): Promise<boolean>;

@@ -113,3 +106,5 @@ getDeploymentState(): Promise<DeploymentState>;

]>;
private _getAccountInitCode;
private create6492Signature;
}
//# sourceMappingURL=base.d.ts.map
import { type FallbackTransport, type Hex, type Transport } from "viem";
import type { SmartAccountSigner } from "../signer/types.js";
import type { BatchUserOperationCallData } from "../types.js";
import { BaseSmartContractAccount, type BaseSmartAccountParams } from "./base.js";
import type { SmartAccountSigner } from "../signer/types.js";
export interface SimpleSmartAccountParams<TTransport extends Transport | FallbackTransport = Transport> extends BaseSmartAccountParams<TTransport> {
owner: SmartAccountSigner;
index?: bigint;
}
import { BaseSmartContractAccount } from "./base.js";
import type { SimpleSmartAccountParams } from "./types.js";
export declare class SimpleSmartContractAccount<TTransport extends Transport | FallbackTransport = Transport> extends BaseSmartContractAccount<TTransport> {

@@ -10,0 +7,0 @@ protected owner: SmartAccountSigner;

import type { Address } from "abitype";
import type { Hash, Hex } from "viem";
import type { Hash, Hex, Transport } from "viem";
import type { SignTypedDataParameters } from "viem/accounts";
import type { z } from "zod";
import type { SupportedTransports } from "../client/types";
import type { SmartAccountSigner } from "../signer/types";
import type { BatchUserOperationCallData } from "../types";
import type { SmartAccountSigner } from "../signer/types";
import type { SimpleSmartAccountParamsSchema, createBaseSmartAccountParamsSchema } from "./schema";
export type SignTypedDataParams = Omit<SignTypedDataParameters, "privateKey">;
export type BaseSmartAccountParams<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof createBaseSmartAccountParamsSchema<TTransport>>>;
export type SimpleSmartAccountParams<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof SimpleSmartAccountParamsSchema<TTransport>>>;
export interface ISmartContractAccount {

@@ -79,3 +84,7 @@ /**

getFactoryAddress(): Address;
/**
* @returns the address of the entry point contract for the smart contract account
*/
getEntryPointAddress(): Address;
}
//# sourceMappingURL=types.d.ts.map

@@ -8,7 +8,8 @@ export type { Abi } from "abitype";

export { BaseSmartContractAccount } from "./account/base.js";
export type { BaseSmartAccountParams } from "./account/base.js";
export { createBaseSmartAccountParamsSchema } from "./account/schema.js";
export { SimpleSmartContractAccount } from "./account/simple.js";
export type { SimpleSmartAccountParams } from "./account/simple.js";
export type * from "./account/types.js";
export type { BaseSmartAccountParams } from "./account/types.js";
export { LocalAccountSigner } from "./signer/local-account.js";
export { SignerSchema } from "./signer/schema.js";
export type { SmartAccountSigner } from "./signer/types.js";

@@ -18,12 +19,13 @@ export { verifyEIP6492Signature, wrapSignatureWith6492, } from "./signer/utils.js";

export { createPublicErc4337Client, createPublicErc4337FromClient, erc4337ClientActions, } from "./client/create-client.js";
export { createPublicErc4337ClientSchema } from "./client/schema.js";
export type * from "./client/types.js";
export { convertChainIdToCoinType, convertCoinTypeToChain, convertCoinTypeToChainId, } from "./ens/utils.js";
export { SmartAccountProvider, noOpMiddleware } from "./provider/base.js";
export type { SmartAccountProviderConfig, SmartAccountProviderOpts, } from "./provider/base.js";
export { SmartAccountProviderOptsSchema, createSmartAccountProviderConfigSchema, } from "./provider/schema.js";
export type * from "./provider/types.js";
export type * from "./types.js";
export type * from "./utils/index.js";
export { asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getChain, getUserOperationHash, resolveProperties, } from "./utils/index.js";
export { ChainSchema, asyncPipe, bigIntMax, bigIntPercent, deepHexlify, defineReadOnly, getChain, getDefaultEntryPointAddress, getDefaultSimpleAccountFactoryAddress, getUserOperationHash, resolveProperties, } from "./utils/index.js";
export { Logger } from "./logger.js";
export type { LogLevel } from "./logger.js";
//# sourceMappingURL=index.d.ts.map

@@ -6,28 +6,4 @@ import { default as EventEmitter } from "eventemitter3";

import { type BatchUserOperationCallData, type UserOperationCallData, type UserOperationOverrides, type UserOperationReceipt, type UserOperationRequest, type UserOperationResponse, type UserOperationStruct } from "../types.js";
import type { AccountMiddlewareFn, FeeDataMiddleware, GasEstimatorMiddleware, ISmartAccountProvider, PaymasterAndDataMiddleware, ProviderEvents, SendUserOperationResult } from "./types.js";
import type { AccountMiddlewareFn, FeeDataMiddleware, GasEstimatorMiddleware, ISmartAccountProvider, PaymasterAndDataMiddleware, ProviderEvents, SendUserOperationResult, SmartAccountProviderConfig } from "./types.js";
export declare const noOpMiddleware: AccountMiddlewareFn;
export interface SmartAccountProviderOpts {
/**
* The maximum number of times to try fetching a transaction receipt before giving up (default: 5)
*/
txMaxRetries?: number;
/**
* The interval in milliseconds to wait between retries while waiting for tx receipts (default: 2_000n)
*/
txRetryIntervalMs?: number;
/**
* The mulitplier on interval length to wait between retries while waiting for tx receipts (default: 1.5)
*/
txRetryMulitplier?: number;
/**
* used when computing the fees for a user operation (default: 100_000_000n)
*/
minPriorityFeePerBid?: bigint;
}
export type SmartAccountProviderConfig<TTransport extends SupportedTransports = Transport> = {
rpcProvider: string | PublicErc4337Client<TTransport>;
chain: Chain;
entryPointAddress: Address;
opts?: SmartAccountProviderOpts;
};
export declare class SmartAccountProvider<TTransport extends SupportedTransports = Transport> extends EventEmitter<ProviderEvents> implements ISmartAccountProvider<TTransport> {

@@ -37,8 +13,8 @@ private txMaxRetries;

private txRetryMulitplier;
private minPriorityFeePerBid;
readonly account?: ISmartContractAccount;
protected entryPointAddress: Address;
protected entryPointAddress?: Address;
protected chain: Chain;
minPriorityFeePerBid: bigint;
rpcClient: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;
constructor({ rpcProvider, entryPointAddress, chain, opts, }: SmartAccountProviderConfig<TTransport>);
constructor(config: SmartAccountProviderConfig<TTransport>);
request: (args: {

@@ -86,2 +62,3 @@ method: string;

};
getEntryPointAddress: () => Address;
extend: <R>(fn: (self: this) => R) => this & R;

@@ -88,0 +65,0 @@ private overrideMiddlewareFunction;

import type { Address } from "abitype";
import type { Hash, Hex, HttpTransport, RpcTransactionRequest, Transport } from "viem";
import type { SignTypedDataParameters } from "viem/accounts";
import type { z } from "zod";
import type { ISmartContractAccount, SignTypedDataParams } from "../account/types.js";

@@ -8,2 +9,3 @@ import type { PublicErc4337Client, SupportedTransports } from "../client/types.js";

import type { Deferrable } from "../utils";
import type { SmartAccountProviderOptsSchema, createSmartAccountProviderConfigSchema } from "./schema.js";
type WithRequired<T, K extends keyof T> = Required<Pick<T, K>>;

@@ -34,2 +36,4 @@ type WithOptional<T, K extends keyof T> = Pick<Partial<T>, K>;

export type FeeDataMiddleware = AccountMiddlewareOverrideFn<"maxFeePerGas" | "maxPriorityFeePerGas">;
export type SmartAccountProviderOpts = z.infer<typeof SmartAccountProviderOptsSchema>;
export type SmartAccountProviderConfig<TTransport extends SupportedTransports = Transport> = z.infer<ReturnType<typeof createSmartAccountProviderConfigSchema<TTransport>>>;
export interface ISmartAccountProvider<TTransport extends SupportedTransports = Transport> {

@@ -36,0 +40,0 @@ readonly rpcClient: PublicErc4337Client<TTransport> | PublicErc4337Client<HttpTransport>;

@@ -93,9 +93,2 @@ import type { Address, Hash } from "viem";

}
/**
* Utility method for asserting a {@link UserOperationStruct} is a {@link UserOperationRequest}
*
* @param request a {@link UserOperationStruct} to validate
* @returns a type guard that asserts the {@link UserOperationStruct} is a {@link UserOperationRequest}
*/
export declare function isValidRequest(request: UserOperationStruct): request is UserOperationRequest;
//# sourceMappingURL=types.d.ts.map

@@ -47,2 +47,5 @@ import type { Address, Hash } from "viem";

export * from "./bigint.js";
export * from "./defaults.js";
export * from "./schema.js";
export * from "./userop.js";
//# sourceMappingURL=index.d.ts.map

@@ -1,2 +0,2 @@

export declare const VERSION = "0.1.1";
export declare const VERSION = "0.2.0";
//# sourceMappingURL=version.d.ts.map
{
"name": "@alchemy/aa-core",
"license": "MIT",
"version": "0.1.1",
"version": "0.2.0",
"description": "viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts",

@@ -55,3 +55,4 @@ "author": "Alchemy",

"eventemitter3": "^5.0.1",
"viem": "^1.16.2"
"viem": "^1.16.2",
"zod": "^3.22.4"
},

@@ -66,3 +67,3 @@ "repository": {

"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
"gitHead": "d080df586c7b46c952b4219bf549c1e481bdada6"
"gitHead": "e9de0ca797605b04dc0a5db0764f1efed4a94610"
}

@@ -22,3 +22,9 @@ import type { Address } from "abitype";

import type { BatchUserOperationCallData } from "../types.js";
import type { ISmartContractAccount, SignTypedDataParams } from "./types.js";
import { getDefaultEntryPointAddress } from "../utils/defaults.js";
import { createBaseSmartAccountParamsSchema } from "./schema.js";
import type {
BaseSmartAccountParams,
ISmartContractAccount,
SignTypedDataParams,
} from "./types.js";

@@ -31,13 +37,2 @@ export enum DeploymentState {

export interface BaseSmartAccountParams<
TTransport extends SupportedTransports = Transport
> {
rpcClient: string | PublicErc4337Client<TTransport>;
entryPointAddress: Address;
factoryAddress: Address;
owner?: SmartAccountSigner | undefined;
chain: Chain;
accountAddress?: Address;
}
export abstract class BaseSmartContractAccount<

@@ -50,2 +45,3 @@ TTransport extends SupportedTransports = Transport

protected accountAddress?: Address;
protected accountInitCode?: Hex;
protected owner: SmartAccountSigner | undefined;

@@ -62,5 +58,9 @@ protected entryPoint: GetContractReturnType<

constructor(params: BaseSmartAccountParams<TTransport>) {
this.entryPointAddress = params.entryPointAddress;
constructor(params_: BaseSmartAccountParams<TTransport>) {
const params =
createBaseSmartAccountParamsSchema<TTransport>().parse(params_);
this.entryPointAddress =
params.entryPointAddress ?? getDefaultEntryPointAddress(params.chain);
const rpcUrl =

@@ -94,3 +94,3 @@ typeof params.rpcClient === "string"

...fetchOptions?.headers,
"Alchemy-Aa-Sdk-Signer": params.owner?.signerType,
"Alchemy-Aa-Sdk-Signer": params.owner?.signerType || "unknown",
"Alchemy-Aa-Sdk-Factory-Address": params.factoryAddress,

@@ -105,5 +105,6 @@ },

this.owner = params.owner;
this.accountInitCode = params.initCode;
this.entryPoint = getContract({
address: params.entryPointAddress,
address: this.entryPointAddress,
abi: EntryPointAbi,

@@ -149,3 +150,3 @@ // Need to cast this as PublicClient or else it breaks ABI typing.

* this should return the init code that will be used to create an account if one does not exist.
* Usually this is the concatenation of the account's factory address and the abi encoded function data of the account factory's `createAccount` method.
* This is the concatenation of the account's factory address and the abi encoded function data of the account factory's `createAccount` method.
*/

@@ -201,25 +202,2 @@ protected abstract getAccountInitCode(): Promise<Hash>;

private async create6492Signature(
isDeployed: boolean,
signature: Hash
): Promise<Hash> {
if (isDeployed) {
return signature;
}
const [factoryAddress, factoryCalldata] =
await this.parseFactoryAddressFromAccountInitCode();
Logger.debug(
`[BaseSmartContractAccount](create6492Signature)\
factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`
);
return wrapSignatureWith6492({
factoryAddress,
factoryCalldata,
signature,
});
}
/**

@@ -240,2 +218,3 @@ * Not all contracts support batch execution.

// Extra implementations
async getNonce(): Promise<bigint> {

@@ -264,3 +243,3 @@ if (!(await this.isAccountDeployed())) {

return this.getAccountInitCode();
return this._getAccountInitCode();
}

@@ -270,3 +249,3 @@

if (!this.accountAddress) {
const initCode = await this.getAccountInitCode();
const initCode = await this._getAccountInitCode();
Logger.debug(

@@ -303,3 +282,6 @@ "[BaseSmartContractAccount](getAddress) initCode: ",

// Extra implementations
getEntryPointAddress(): Address {
return this.entryPointAddress;
}
async isAccountDeployed(): Promise<boolean> {

@@ -329,3 +311,3 @@ return (await this.getDeploymentState()) === DeploymentState.DEPLOYED;

> {
const initCode = await this.getAccountInitCode();
const initCode = await this._getAccountInitCode();
const factoryAddress = `0x${initCode.substring(2, 42)}` as Address;

@@ -335,2 +317,29 @@ const factoryCalldata = `0x${initCode.substring(42)}` as Hex;

}
private async _getAccountInitCode(): Promise<Hash> {
return this.accountInitCode ?? this.getAccountInitCode();
}
private async create6492Signature(
isDeployed: boolean,
signature: Hash
): Promise<Hash> {
if (isDeployed) {
return signature;
}
const [factoryAddress, factoryCalldata] =
await this.parseFactoryAddressFromAccountInitCode();
Logger.debug(
`[BaseSmartContractAccount](create6492Signature)\
factoryAddress: ${factoryAddress}, factoryCalldata: ${factoryCalldata}`
);
return wrapSignatureWith6492({
factoryAddress,
factoryCalldata,
signature,
});
}
}

@@ -12,16 +12,8 @@ import type { Address } from "abitype";

import { SimpleAccountFactoryAbi } from "../abis/SimpleAccountFactoryAbi.js";
import type { SmartAccountSigner } from "../signer/types.js";
import type { BatchUserOperationCallData } from "../types.js";
import {
BaseSmartContractAccount,
type BaseSmartAccountParams,
} from "./base.js";
import type { SmartAccountSigner } from "../signer/types.js";
import { BaseSmartContractAccount } from "./base.js";
import { SimpleSmartAccountParamsSchema } from "./schema.js";
import type { SimpleSmartAccountParams } from "./types.js";
export interface SimpleSmartAccountParams<
TTransport extends Transport | FallbackTransport = Transport
> extends BaseSmartAccountParams<TTransport> {
owner: SmartAccountSigner;
index?: bigint;
}
export class SimpleSmartContractAccount<

@@ -34,2 +26,4 @@ TTransport extends Transport | FallbackTransport = Transport

constructor(params: SimpleSmartAccountParams<TTransport>) {
SimpleSmartAccountParamsSchema<TTransport>().parse(params);
super(params);

@@ -36,0 +30,0 @@ this.owner = params.owner;

import type { Address } from "abitype";
import type { Hash, Hex } from "viem";
import type { Hash, Hex, Transport } from "viem";
import type { SignTypedDataParameters } from "viem/accounts";
import type { z } from "zod";
import type { SupportedTransports } from "../client/types";
import type { SmartAccountSigner } from "../signer/types";
import type { BatchUserOperationCallData } from "../types";
import type { SmartAccountSigner } from "../signer/types";
import type {
SimpleSmartAccountParamsSchema,
createBaseSmartAccountParamsSchema,
} from "./schema";
export type SignTypedDataParams = Omit<SignTypedDataParameters, "privateKey">;
export type BaseSmartAccountParams<
TTransport extends SupportedTransports = Transport
> = z.infer<ReturnType<typeof createBaseSmartAccountParamsSchema<TTransport>>>;
export type SimpleSmartAccountParams<
TTransport extends SupportedTransports = Transport
> = z.infer<ReturnType<typeof SimpleSmartAccountParamsSchema<TTransport>>>;
export interface ISmartContractAccount {

@@ -92,2 +106,7 @@ /**

getFactoryAddress(): Address;
/**
* @returns the address of the entry point contract for the smart contract account
*/
getEntryPointAddress(): Address;
}

@@ -10,7 +10,9 @@ export type { Abi } from "abitype";

export { BaseSmartContractAccount } from "./account/base.js";
export type { BaseSmartAccountParams } from "./account/base.js";
export { createBaseSmartAccountParamsSchema } from "./account/schema.js";
export { SimpleSmartContractAccount } from "./account/simple.js";
export type { SimpleSmartAccountParams } from "./account/simple.js";
export type * from "./account/types.js";
export type { BaseSmartAccountParams } from "./account/types.js";
export { LocalAccountSigner } from "./signer/local-account.js";
export { SignerSchema } from "./signer/schema.js";
export type { SmartAccountSigner } from "./signer/types.js";

@@ -28,2 +30,3 @@ export {

} from "./client/create-client.js";
export { createPublicErc4337ClientSchema } from "./client/schema.js";
export type * from "./client/types.js";

@@ -38,6 +41,6 @@

export { SmartAccountProvider, noOpMiddleware } from "./provider/base.js";
export type {
SmartAccountProviderConfig,
SmartAccountProviderOpts,
} from "./provider/base.js";
export {
SmartAccountProviderOptsSchema,
createSmartAccountProviderConfigSchema,
} from "./provider/schema.js";
export type * from "./provider/types.js";

@@ -48,2 +51,3 @@

export {
ChainSchema,
asyncPipe,

@@ -55,2 +59,4 @@ bigIntMax,

getChain,
getDefaultEntryPointAddress,
getDefaultSimpleAccountFactoryAddress,
getUserOperationHash,

@@ -57,0 +63,0 @@ resolveProperties,

@@ -24,3 +24,2 @@ import { default as EventEmitter } from "eventemitter3";

import {
isValidRequest,
type BatchUserOperationCallData,

@@ -40,6 +39,9 @@ type UserOperationCallData,

defineReadOnly,
getDefaultEntryPointAddress,
getUserOperationHash,
isValidRequest,
resolveProperties,
type Deferrable,
} from "../utils/index.js";
import { createSmartAccountProviderConfigSchema } from "./schema.js";
import type {

@@ -54,2 +56,3 @@ AccountMiddlewareFn,

SendUserOperationResult,
SmartAccountProviderConfig,
} from "./types.js";

@@ -61,24 +64,2 @@

export interface SmartAccountProviderOpts {
/**
* The maximum number of times to try fetching a transaction receipt before giving up (default: 5)
*/
txMaxRetries?: number;
/**
* The interval in milliseconds to wait between retries while waiting for tx receipts (default: 2_000n)
*/
txRetryIntervalMs?: number;
/**
* The mulitplier on interval length to wait between retries while waiting for tx receipts (default: 1.5)
*/
txRetryMulitplier?: number;
/**
* used when computing the fees for a user operation (default: 100_000_000n)
*/
minPriorityFeePerBid?: bigint;
}
const minPriorityFeePerBidDefaults = new Map<number, bigint>([

@@ -89,11 +70,2 @@ [arbitrum.id, 10_000_000n],

export type SmartAccountProviderConfig<
TTransport extends SupportedTransports = Transport
> = {
rpcProvider: string | PublicErc4337Client<TTransport>;
chain: Chain;
entryPointAddress: Address;
opts?: SmartAccountProviderOpts;
};
export class SmartAccountProvider<

@@ -108,7 +80,10 @@ TTransport extends SupportedTransports = Transport

private txRetryMulitplier: number;
private minPriorityFeePerBid: bigint;
readonly account?: ISmartContractAccount;
protected entryPointAddress: Address;
protected entryPointAddress?: Address;
protected chain: Chain;
minPriorityFeePerBid: bigint;
rpcClient:

@@ -118,11 +93,9 @@ | PublicErc4337Client<TTransport>

constructor({
rpcProvider,
entryPointAddress,
chain,
opts,
}: SmartAccountProviderConfig<TTransport>) {
constructor(config: SmartAccountProviderConfig<TTransport>) {
createSmartAccountProviderConfigSchema<TTransport>().parse(config);
const { rpcProvider, entryPointAddress, chain, opts } = config;
super();
this.entryPointAddress = entryPointAddress;
this.chain = chain;

@@ -133,2 +106,3 @@

this.txRetryMulitplier = opts?.txRetryMulitplier ?? 1.5;
this.entryPointAddress = entryPointAddress;

@@ -452,3 +426,3 @@ this.minPriorityFeePerBid =

request,
this.entryPointAddress as `0x${string}`,
this.getEntryPointAddress(),
BigInt(this.chain.id)

@@ -461,3 +435,3 @@ )

request,
this.entryPointAddress
this.getEntryPointAddress()
),

@@ -487,3 +461,3 @@ request,

request,
this.entryPointAddress
this.getEntryPointAddress()
);

@@ -576,2 +550,15 @@

const account = fn(this.rpcClient);
// sanity check. Note that this check is only performed if and only if the optional entryPointAddress is given upon initialization.
if (
this.entryPointAddress &&
account.getEntryPointAddress() !== this.entryPointAddress
) {
throw new Error(
`Account entryPoint address: ${account.getEntryPointAddress()} does not match the current provider's entryPoint address: ${
this.entryPointAddress
}`
);
}
defineReadOnly(this, "account", account);

@@ -594,3 +581,3 @@

...fetchOptions?.headers,
"Alchemy-Aa-Sdk-Signer": signer?.signerType,
"Alchemy-Aa-Sdk-Signer": signer?.signerType || "unknown",
"Alchemy-Aa-Sdk-Factory-Address": factoryAddress,

@@ -630,2 +617,13 @@ },

/*
* Note that the connected account's entryPointAddress always takes the precedence
*/
getEntryPointAddress = (): Address => {
return (
this.entryPointAddress ??
this.account?.getEntryPointAddress() ??
getDefaultEntryPointAddress(this.chain)
);
};
extend = <R>(fn: (self: this) => R): this & R => {

@@ -632,0 +630,0 @@ const extended = fn(this) as any;

@@ -10,2 +10,3 @@ import type { Address } from "abitype";

import type { SignTypedDataParameters } from "viem/accounts";
import type { z } from "zod";
import type {

@@ -28,2 +29,6 @@ ISmartContractAccount,

import type { Deferrable } from "../utils";
import type {
SmartAccountProviderOptsSchema,
createSmartAccountProviderConfigSchema,
} from "./schema.js";

@@ -81,2 +86,12 @@ type WithRequired<T, K extends keyof T> = Required<Pick<T, K>>;

export type SmartAccountProviderOpts = z.infer<
typeof SmartAccountProviderOptsSchema
>;
export type SmartAccountProviderConfig<
TTransport extends SupportedTransports = Transport
> = z.infer<
ReturnType<typeof createSmartAccountProviderConfigSchema<TTransport>>
>;
// TODO: this also will need to implement EventEmitteer

@@ -83,0 +98,0 @@ export interface ISmartAccountProvider<

@@ -181,20 +181,1 @@ import type { Address, Hash } from "viem";

}
/**
* Utility method for asserting a {@link UserOperationStruct} is a {@link UserOperationRequest}
*
* @param request a {@link UserOperationStruct} to validate
* @returns a type guard that asserts the {@link UserOperationStruct} is a {@link UserOperationRequest}
*/
export function isValidRequest(
request: UserOperationStruct
): request is UserOperationRequest {
// These are the only ones marked as optional in the interface above
return (
!!request.callGasLimit &&
!!request.maxFeePerGas &&
request.maxPriorityFeePerGas != null &&
!!request.preVerificationGas &&
!!request.verificationGasLimit
);
}

@@ -160,1 +160,4 @@ import type { Address, Hash, Hex } from "viem";

export * from "./bigint.js";
export * from "./defaults.js";
export * from "./schema.js";
export * from "./userop.js";
// This file is autogenerated by inject-version.ts. Any changes will be
// overwritten on commit!
export const VERSION = "0.1.1";
export const VERSION = "0.2.0";

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc