New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@alchemy/aa-alchemy

Package Overview
Dependencies
Maintainers
2
Versions
110
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alchemy/aa-alchemy - npm Package Compare versions

Comparing version 0.1.0-alpha.32 to 0.1.0

3

./dist/cjs/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlchemyProvider = exports.SupportedChains = exports.alchemyPaymasterAndDataMiddleware = exports.withAlchemyGasManager = exports.withAlchemyGasFeeEstimator = void 0;
exports.AlchemyProvider = exports.SupportedChains = exports.withAlchemyGasManager = exports.withAlchemyGasFeeEstimator = void 0;
var gas_fees_js_1 = require("./middleware/gas-fees.js");

@@ -8,3 +8,2 @@ Object.defineProperty(exports, "withAlchemyGasFeeEstimator", { enumerable: true, get: function () { return gas_fees_js_1.withAlchemyGasFeeEstimator; } });

Object.defineProperty(exports, "withAlchemyGasManager", { enumerable: true, get: function () { return gas_manager_js_1.withAlchemyGasManager; } });
Object.defineProperty(exports, "alchemyPaymasterAndDataMiddleware", { enumerable: true, get: function () { return gas_manager_js_1.alchemyPaymasterAndDataMiddleware; } });
var chains_js_1 = require("./chains.js");

@@ -11,0 +10,0 @@ Object.defineProperty(exports, "SupportedChains", { enumerable: true, get: function () { return chains_js_1.SupportedChains; } });

export { withAlchemyGasFeeEstimator } from "./middleware/gas-fees.js";
export { withAlchemyGasManager, alchemyPaymasterAndDataMiddleware, } from "./middleware/gas-manager.js";
export { withAlchemyGasManager } from "./middleware/gas-manager.js";
export { SupportedChains } from "./chains.js";
export { AlchemyProvider } from "./provider.js";
export type { AlchemyProviderConfig, ConnectionConfig } from "./provider.js";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlchemyProvider = exports.SupportedChains = exports.alchemyPaymasterAndDataMiddleware = exports.withAlchemyGasManager = exports.withAlchemyGasFeeEstimator = void 0;
exports.AlchemyProvider = exports.SupportedChains = exports.withAlchemyGasManager = exports.withAlchemyGasFeeEstimator = void 0;
var gas_fees_js_1 = require("./middleware/gas-fees.js");

@@ -8,3 +8,2 @@ Object.defineProperty(exports, "withAlchemyGasFeeEstimator", { enumerable: true, get: function () { return gas_fees_js_1.withAlchemyGasFeeEstimator; } });

Object.defineProperty(exports, "withAlchemyGasManager", { enumerable: true, get: function () { return gas_manager_js_1.withAlchemyGasManager; } });
Object.defineProperty(exports, "alchemyPaymasterAndDataMiddleware", { enumerable: true, get: function () { return gas_manager_js_1.alchemyPaymasterAndDataMiddleware; } });
var chains_js_1 = require("./chains.js");

@@ -11,0 +10,0 @@ Object.defineProperty(exports, "SupportedChains", { enumerable: true, get: function () { return chains_js_1.SupportedChains; } });

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

}
const priorityFeePerGas = BigInt(await provider.alchemyClient.request({
const priorityFeePerGas = BigInt(await provider.rpcClient.request({
method: "rundler_maxPriorityFeePerGas",

@@ -14,0 +14,0 @@ params: [],

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

import { type ConnectedSmartAccountProvider } from "@alchemy/aa-core";
import type { Address, Transport } from "viem";
import type { Address } from "viem";
import type { AlchemyProvider } from "../provider.js";
export interface AlchemyGasManagerConfig {

@@ -7,3 +7,2 @@ policyId: string;

}
export declare const withAlchemyGasManager: <T extends Transport, Provider extends ConnectedSmartAccountProvider<T>>(provider: Provider, config: AlchemyGasManagerConfig) => Provider;
export declare const alchemyPaymasterAndDataMiddleware: <T extends Transport, Provider extends ConnectedSmartAccountProvider<T>>(provider: Provider, config: AlchemyGasManagerConfig) => Parameters<ConnectedSmartAccountProvider["withPaymasterMiddleware"]>["0"];
export declare const withAlchemyGasManager: (provider: AlchemyProvider, config: AlchemyGasManagerConfig, estimateGas?: boolean) => AlchemyProvider;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.alchemyPaymasterAndDataMiddleware = exports.withAlchemyGasManager = void 0;
exports.withAlchemyGasManager = void 0;
const aa_core_1 = require("@alchemy/aa-core");
const withAlchemyGasManager = (provider, config) => {
return (provider
.withGasEstimator(async () => ({
callGasLimit: 0n,
preVerificationGas: 0n,
verificationGasLimit: 0n,
}))
.withFeeDataGetter(async () => ({
maxFeePerGas: 0n,
maxPriorityFeePerGas: 0n,
}))
.withPaymasterMiddleware({
paymasterDataMiddleware: async (struct) => {
const userOperation = (0, aa_core_1.deepHexlify)(await (0, aa_core_1.resolveProperties)(struct));
let feeOverride = undefined;
if (BigInt(userOperation.maxFeePerGas) > 0n) {
feeOverride = {
maxFeePerGas: userOperation.maxFeePerGas,
maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas,
};
}
const result = await provider.rpcClient.request({
method: "alchemy_requestGasAndPaymasterAndData",
params: [
{
policyId: config.policyId,
entryPoint: config.entryPoint,
userOperation: userOperation,
dummySignature: provider.account.getDummySignature(),
feeOverride: feeOverride,
},
],
});
return result;
},
}));
const withAlchemyGasManager = (provider, config, estimateGas = true) => {
return estimateGas
? provider
.withGasEstimator(async () => ({
callGasLimit: 0n,
preVerificationGas: 0n,
verificationGasLimit: 0n,
}))
.withFeeDataGetter(async (struct) => ({
maxFeePerGas: (await struct.maxFeePerGas) ?? 0n,
maxPriorityFeePerGas: (await struct.maxPriorityFeePerGas) ?? 0n,
}))
.withPaymasterMiddleware(withAlchemyGasAndPaymasterAndDataMiddleware(provider, config))
: provider.withPaymasterMiddleware(withAlchemyPaymasterAndDataMiddleware(provider, config));
};
exports.withAlchemyGasManager = withAlchemyGasManager;
const alchemyPaymasterAndDataMiddleware = (provider, config) => ({
const withAlchemyPaymasterAndDataMiddleware = (provider, config) => ({
dummyPaymasterDataMiddleware: async (_struct) => {

@@ -73,3 +51,27 @@ switch (provider.rpcClient.chain.id) {

});
exports.alchemyPaymasterAndDataMiddleware = alchemyPaymasterAndDataMiddleware;
const withAlchemyGasAndPaymasterAndDataMiddleware = (provider, config) => ({
paymasterDataMiddleware: async (struct) => {
const userOperation = (0, aa_core_1.deepHexlify)(await (0, aa_core_1.resolveProperties)(struct));
let feeOverride = undefined;
if (userOperation.maxFeePerGas && BigInt(userOperation.maxFeePerGas) > 0n) {
feeOverride = {
maxFeePerGas: userOperation.maxFeePerGas,
maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas,
};
}
const result = await provider.rpcClient.request({
method: "alchemy_requestGasAndPaymasterAndData",
params: [
{
policyId: config.policyId,
entryPoint: config.entryPoint,
userOperation: userOperation,
dummySignature: userOperation.signature,
feeOverride: feeOverride,
},
],
});
return result;
},
});
//# sourceMappingURL=gas-manager.js.map

@@ -1,4 +0,3 @@

import { BaseSmartContractAccount, SmartAccountProvider, type AccountMiddlewareFn, type SmartAccountProviderOpts } from "@alchemy/aa-core";
import { type Address, type Chain, type HttpTransport } from "viem";
import type { ClientWithAlchemyMethods } from "./middleware/client.js";
import { SmartAccountProvider, type AccountMiddlewareFn, type SmartAccountProviderConfig } from "@alchemy/aa-core";
import { type HttpTransport } from "viem";
import { type AlchemyGasManagerConfig } from "./middleware/gas-manager.js";

@@ -23,6 +22,2 @@ export type ConnectionConfig = {

export type AlchemyProviderConfig = {
chain: Chain | number;
entryPointAddress: Address;
account?: BaseSmartContractAccount;
opts?: SmartAccountProviderOpts;
feeOpts?: {

@@ -33,10 +28,9 @@ baseFeeBufferPercent?: bigint;

};
} & ConnectionConfig;
} & Omit<SmartAccountProviderConfig, "rpcProvider"> & ConnectionConfig;
export declare class AlchemyProvider extends SmartAccountProvider<HttpTransport> {
alchemyClient: ClientWithAlchemyMethods;
private pvgBuffer;
private feeOptsSet;
constructor({ chain, entryPointAddress, account, opts, feeOpts, ...connectionConfig }: AlchemyProviderConfig);
constructor({ chain, entryPointAddress, opts, feeOpts, ...connectionConfig }: AlchemyProviderConfig);
gasEstimator: AccountMiddlewareFn;
withAlchemyGasManager(config: AlchemyGasManagerConfig): this;
withAlchemyGasManager(config: AlchemyGasManagerConfig): AlchemyProvider;
}

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

class AlchemyProvider extends aa_core_1.SmartAccountProvider {
constructor({ chain, entryPointAddress, account, opts, feeOpts, ...connectionConfig }) {
constructor({ chain, entryPointAddress, opts, feeOpts, ...connectionConfig }) {
const _chain = typeof chain === "number" ? chains_js_1.SupportedChains.get(chain) : chain;

@@ -30,9 +30,3 @@ if (!_chain || !_chain.rpcUrls["alchemy"]) {

});
super(client, entryPointAddress, _chain, account, opts);
Object.defineProperty(this, "alchemyClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
super({ rpcProvider: client, entryPointAddress, chain: _chain, opts });
Object.defineProperty(this, "pvgBuffer", {

@@ -65,3 +59,2 @@ enumerable: true,

});
this.alchemyClient = this.rpcClient;
(0, gas_fees_js_1.withAlchemyGasFeeEstimator)(this, feeOpts?.baseFeeBufferPercent ?? 50n, feeOpts?.maxPriorityFeeBufferPercent ?? 5n);

@@ -88,8 +81,3 @@ if (feeOpts?.preVerificationGasBufferPercent) {

}
if (this.feeOptsSet) {
return this.withPaymasterMiddleware((0, gas_manager_js_1.alchemyPaymasterAndDataMiddleware)(this, config));
}
else {
return (0, gas_manager_js_1.withAlchemyGasManager)(this, config);
}
return (0, gas_manager_js_1.withAlchemyGasManager)(this, config, !this.feeOptsSet);
}

@@ -96,0 +84,0 @@ }

export { withAlchemyGasFeeEstimator } from "./middleware/gas-fees.js";
export { withAlchemyGasManager, alchemyPaymasterAndDataMiddleware, } from "./middleware/gas-manager.js";
export { withAlchemyGasManager } from "./middleware/gas-manager.js";
export { SupportedChains } from "./chains.js";
export { AlchemyProvider } from "./provider.js";
export type { AlchemyProviderConfig, ConnectionConfig } from "./provider.js";
export { withAlchemyGasFeeEstimator } from "./middleware/gas-fees.js";
export { withAlchemyGasManager, alchemyPaymasterAndDataMiddleware, } from "./middleware/gas-manager.js";
export { withAlchemyGasManager } from "./middleware/gas-manager.js";
export { SupportedChains } from "./chains.js";
export { AlchemyProvider } from "./provider.js";
//# sourceMappingURL=index.js.map

@@ -8,3 +8,3 @@ export const withAlchemyGasFeeEstimator = (provider, baseFeeBufferPercent, maxPriorityFeeBufferPercent) => {

}
const priorityFeePerGas = BigInt(await provider.alchemyClient.request({
const priorityFeePerGas = BigInt(await provider.rpcClient.request({
method: "rundler_maxPriorityFeePerGas",

@@ -11,0 +11,0 @@ params: [],

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

import { type ConnectedSmartAccountProvider } from "@alchemy/aa-core";
import type { Address, Transport } from "viem";
import type { Address } from "viem";
import type { AlchemyProvider } from "../provider.js";
export interface AlchemyGasManagerConfig {

@@ -7,3 +7,2 @@ policyId: string;

}
export declare const withAlchemyGasManager: <T extends Transport, Provider extends ConnectedSmartAccountProvider<T>>(provider: Provider, config: AlchemyGasManagerConfig) => Provider;
export declare const alchemyPaymasterAndDataMiddleware: <T extends Transport, Provider extends ConnectedSmartAccountProvider<T>>(provider: Provider, config: AlchemyGasManagerConfig) => Parameters<ConnectedSmartAccountProvider["withPaymasterMiddleware"]>["0"];
export declare const withAlchemyGasManager: (provider: AlchemyProvider, config: AlchemyGasManagerConfig, estimateGas?: boolean) => AlchemyProvider;
import { deepHexlify, resolveProperties, } from "@alchemy/aa-core";
export const withAlchemyGasManager = (provider, config) => {
return (provider
.withGasEstimator(async () => ({
callGasLimit: 0n,
preVerificationGas: 0n,
verificationGasLimit: 0n,
}))
.withFeeDataGetter(async () => ({
maxFeePerGas: 0n,
maxPriorityFeePerGas: 0n,
}))
.withPaymasterMiddleware({
paymasterDataMiddleware: async (struct) => {
const userOperation = deepHexlify(await resolveProperties(struct));
let feeOverride = undefined;
if (BigInt(userOperation.maxFeePerGas) > 0n) {
feeOverride = {
maxFeePerGas: userOperation.maxFeePerGas,
maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas,
};
}
const result = await provider.rpcClient.request({
method: "alchemy_requestGasAndPaymasterAndData",
params: [
{
policyId: config.policyId,
entryPoint: config.entryPoint,
userOperation: userOperation,
dummySignature: provider.account.getDummySignature(),
feeOverride: feeOverride,
},
],
});
return result;
},
}));
export const withAlchemyGasManager = (provider, config, estimateGas = true) => {
return estimateGas
? provider
.withGasEstimator(async () => ({
callGasLimit: 0n,
preVerificationGas: 0n,
verificationGasLimit: 0n,
}))
.withFeeDataGetter(async (struct) => ({
maxFeePerGas: (await struct.maxFeePerGas) ?? 0n,
maxPriorityFeePerGas: (await struct.maxPriorityFeePerGas) ?? 0n,
}))
.withPaymasterMiddleware(withAlchemyGasAndPaymasterAndDataMiddleware(provider, config))
: provider.withPaymasterMiddleware(withAlchemyPaymasterAndDataMiddleware(provider, config));
};
export const alchemyPaymasterAndDataMiddleware = (provider, config) => ({
const withAlchemyPaymasterAndDataMiddleware = (provider, config) => ({
dummyPaymasterDataMiddleware: async (_struct) => {

@@ -69,2 +47,27 @@ switch (provider.rpcClient.chain.id) {

});
const withAlchemyGasAndPaymasterAndDataMiddleware = (provider, config) => ({
paymasterDataMiddleware: async (struct) => {
const userOperation = deepHexlify(await resolveProperties(struct));
let feeOverride = undefined;
if (userOperation.maxFeePerGas && BigInt(userOperation.maxFeePerGas) > 0n) {
feeOverride = {
maxFeePerGas: userOperation.maxFeePerGas,
maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas,
};
}
const result = await provider.rpcClient.request({
method: "alchemy_requestGasAndPaymasterAndData",
params: [
{
policyId: config.policyId,
entryPoint: config.entryPoint,
userOperation: userOperation,
dummySignature: userOperation.signature,
feeOverride: feeOverride,
},
],
});
return result;
},
});
//# sourceMappingURL=gas-manager.js.map

@@ -1,4 +0,3 @@

import { BaseSmartContractAccount, SmartAccountProvider, type AccountMiddlewareFn, type SmartAccountProviderOpts } from "@alchemy/aa-core";
import { type Address, type Chain, type HttpTransport } from "viem";
import type { ClientWithAlchemyMethods } from "./middleware/client.js";
import { SmartAccountProvider, type AccountMiddlewareFn, type SmartAccountProviderConfig } from "@alchemy/aa-core";
import { type HttpTransport } from "viem";
import { type AlchemyGasManagerConfig } from "./middleware/gas-manager.js";

@@ -23,6 +22,2 @@ export type ConnectionConfig = {

export type AlchemyProviderConfig = {
chain: Chain | number;
entryPointAddress: Address;
account?: BaseSmartContractAccount;
opts?: SmartAccountProviderOpts;
feeOpts?: {

@@ -33,10 +28,9 @@ baseFeeBufferPercent?: bigint;

};
} & ConnectionConfig;
} & Omit<SmartAccountProviderConfig, "rpcProvider"> & ConnectionConfig;
export declare class AlchemyProvider extends SmartAccountProvider<HttpTransport> {
alchemyClient: ClientWithAlchemyMethods;
private pvgBuffer;
private feeOptsSet;
constructor({ chain, entryPointAddress, account, opts, feeOpts, ...connectionConfig }: AlchemyProviderConfig);
constructor({ chain, entryPointAddress, opts, feeOpts, ...connectionConfig }: AlchemyProviderConfig);
gasEstimator: AccountMiddlewareFn;
withAlchemyGasManager(config: AlchemyGasManagerConfig): this;
withAlchemyGasManager(config: AlchemyGasManagerConfig): AlchemyProvider;
}

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

import { BaseSmartContractAccount, SmartAccountProvider, createPublicErc4337Client, deepHexlify, resolveProperties, } from "@alchemy/aa-core";
import { SmartAccountProvider, createPublicErc4337Client, deepHexlify, resolveProperties, } from "@alchemy/aa-core";
import {} from "viem";

@@ -6,5 +6,5 @@ import { arbitrum, arbitrumGoerli, optimism, optimismGoerli, } from "viem/chains";

import { withAlchemyGasFeeEstimator } from "./middleware/gas-fees.js";
import { alchemyPaymasterAndDataMiddleware, withAlchemyGasManager, } from "./middleware/gas-manager.js";
import { withAlchemyGasManager, } from "./middleware/gas-manager.js";
export class AlchemyProvider extends SmartAccountProvider {
constructor({ chain, entryPointAddress, account, opts, feeOpts, ...connectionConfig }) {
constructor({ chain, entryPointAddress, opts, feeOpts, ...connectionConfig }) {
const _chain = typeof chain === "number" ? SupportedChains.get(chain) : chain;

@@ -28,9 +28,3 @@ if (!_chain || !_chain.rpcUrls["alchemy"]) {

});
super(client, entryPointAddress, _chain, account, opts);
Object.defineProperty(this, "alchemyClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
super({ rpcProvider: client, entryPointAddress, chain: _chain, opts });
Object.defineProperty(this, "pvgBuffer", {

@@ -63,3 +57,2 @@ enumerable: true,

});
this.alchemyClient = this.rpcClient;
withAlchemyGasFeeEstimator(this, feeOpts?.baseFeeBufferPercent ?? 50n, feeOpts?.maxPriorityFeeBufferPercent ?? 5n);

@@ -86,10 +79,5 @@ if (feeOpts?.preVerificationGasBufferPercent) {

}
if (this.feeOptsSet) {
return this.withPaymasterMiddleware(alchemyPaymasterAndDataMiddleware(this, config));
}
else {
return withAlchemyGasManager(this, config);
}
return withAlchemyGasManager(this, config, !this.feeOptsSet);
}
}
//# sourceMappingURL=provider.js.map
export { withAlchemyGasFeeEstimator } from "./middleware/gas-fees.js";
export { withAlchemyGasManager, alchemyPaymasterAndDataMiddleware, } from "./middleware/gas-manager.js";
export { withAlchemyGasManager } from "./middleware/gas-manager.js";
export { SupportedChains } from "./chains.js";

@@ -4,0 +4,0 @@ export { AlchemyProvider } from "./provider.js";

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

import { type ConnectedSmartAccountProvider } from "@alchemy/aa-core";
import type { Address, Transport } from "viem";
import type { Address } from "viem";
import type { AlchemyProvider } from "../provider.js";
export interface AlchemyGasManagerConfig {

@@ -8,19 +8,16 @@ policyId: string;

/**
* This uses the alchemy RPC method: `alchemy_requestGasAndPaymasterAndData` to get all of the gas estimates + paymaster data
* in one RPC call. It will no-op the gas estimator and fee data getter middleware and set a custom middleware that makes the RPC call
* This middleware wraps the Alchemy Gas Manager APIs to provide more flexible UserOperation gas sponsorship.
*
* @param provider - the smart account provider to override to use the alchemy paymaster
* @param config - the alchemy paymaster configuration
* @returns the provider augmented to use the alchemy paymaster
*/
export declare const withAlchemyGasManager: <T extends Transport, Provider extends ConnectedSmartAccountProvider<T>>(provider: Provider, config: AlchemyGasManagerConfig) => Provider;
/**
* This is the middleware for calling the alchemy paymaster API which does not estimate gas. It's recommend to use
* this middleware if you want more customization over the gas and fee estimation middleware, including setting
* non-default buffer values for the fee/gas estimation.
* If `estimateGas` is true, it will use `alchemy_requestGasAndPaymasterAndData` to get all of the gas estimates + paymaster data
* in one RPC call.
*
* @param config {@link AlchemyPaymasterConfig}
* @returns middleware overrides for paymaster middlewares
* Otherwise, it will use `alchemy_requestPaymasterAndData` to get only paymaster data, allowing you
* to customize the gas and fee estimation middleware.
*
* @param provider - the smart account provider to override to use the alchemy gas manager
* @param config - the alchemy gas manager configuration
* @param estimateGas - if true, this will use `alchemy_requestGasAndPaymasterAndData` else will use `alchemy_requestPaymasterAndData`
* @returns the provider augmented to use the alchemy gas manager
*/
export declare const alchemyPaymasterAndDataMiddleware: <T extends Transport, Provider extends ConnectedSmartAccountProvider<T>>(provider: Provider, config: AlchemyGasManagerConfig) => Parameters<ConnectedSmartAccountProvider["withPaymasterMiddleware"]>["0"];
export declare const withAlchemyGasManager: (provider: AlchemyProvider, config: AlchemyGasManagerConfig, estimateGas?: boolean) => AlchemyProvider;
//# sourceMappingURL=gas-manager.d.ts.map

@@ -1,4 +0,3 @@

import { BaseSmartContractAccount, SmartAccountProvider, type AccountMiddlewareFn, type SmartAccountProviderOpts } from "@alchemy/aa-core";
import { type Address, type Chain, type HttpTransport } from "viem";
import type { ClientWithAlchemyMethods } from "./middleware/client.js";
import { SmartAccountProvider, type AccountMiddlewareFn, type SmartAccountProviderConfig } from "@alchemy/aa-core";
import { type HttpTransport } from "viem";
import { type AlchemyGasManagerConfig } from "./middleware/gas-manager.js";

@@ -23,6 +22,2 @@ export type ConnectionConfig = {

export type AlchemyProviderConfig = {
chain: Chain | number;
entryPointAddress: Address;
account?: BaseSmartContractAccount;
opts?: SmartAccountProviderOpts;
feeOpts?: {

@@ -50,11 +45,16 @@ /** this adds a percent buffer on top of the base fee estimated (default 50%)

};
} & ConnectionConfig;
} & Omit<SmartAccountProviderConfig, "rpcProvider"> & ConnectionConfig;
export declare class AlchemyProvider extends SmartAccountProvider<HttpTransport> {
alchemyClient: ClientWithAlchemyMethods;
private pvgBuffer;
private feeOptsSet;
constructor({ chain, entryPointAddress, account, opts, feeOpts, ...connectionConfig }: AlchemyProviderConfig);
constructor({ chain, entryPointAddress, opts, feeOpts, ...connectionConfig }: AlchemyProviderConfig);
gasEstimator: AccountMiddlewareFn;
withAlchemyGasManager(config: AlchemyGasManagerConfig): this;
/**
* This methods adds the Alchemy Gas Manager middleware to the provider.
*
* @param config - the Alchemy Gas Manager configuration
* @returns {AlchemyProvider} - a new AlchemyProvider with the Gas Manager middleware
*/
withAlchemyGasManager(config: AlchemyGasManagerConfig): AlchemyProvider;
}
//# sourceMappingURL=provider.d.ts.map
{
"name": "@alchemy/aa-alchemy",
"version": "0.1.0-alpha.32",
"version": "0.1.0",
"description": "adapters for @alchemy/aa-core for interacting with alchemy services",

@@ -42,3 +42,3 @@ "author": "Alchemy",

"devDependencies": {
"@alchemy/aa-core": "^0.1.0-alpha.32",
"@alchemy/aa-core": "^0.1.0",
"typescript": "^5.0.4",

@@ -49,3 +49,3 @@ "typescript-template": "*",

"dependencies": {
"viem": "^1.10.9"
"viem": "^1.16.2"
},

@@ -67,3 +67,3 @@ "peerDependencies": {

"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
"gitHead": "224b58219bc2ab66f1e71e39a7272a304dc8c510"
"gitHead": "282f897bc4dcb9c1c91c272d991766fb7963417a"
}
export { withAlchemyGasFeeEstimator } from "./middleware/gas-fees.js";
export { withAlchemyGasManager } from "./middleware/gas-manager.js";
export {
withAlchemyGasManager,
alchemyPaymasterAndDataMiddleware,
} from "./middleware/gas-manager.js";
export { SupportedChains } from "./chains.js";
export { SupportedChains } from "./chains.js";
export { AlchemyProvider } from "./provider.js";
export type { AlchemyProviderConfig, ConnectionConfig } from "./provider.js";
import type { AlchemyProvider } from "../provider.js";
import type { ClientWithAlchemyMethods } from "./client.js";

@@ -15,3 +16,4 @@ export const withAlchemyGasFeeEstimator = (

const priorityFeePerGas = BigInt(
await provider.alchemyClient.request({
// it's a fair assumption that if someone is using this Alchemy Middleware, then they are using Alchemy RPC
await (provider.rpcClient as ClientWithAlchemyMethods).request({
method: "rundler_maxPriorityFeePerGas",

@@ -18,0 +20,0 @@ params: [],

import {
deepHexlify,
resolveProperties,
type ConnectedSmartAccountProvider,
type UserOperationRequest,
} from "@alchemy/aa-core";
import type { Address, Transport } from "viem";
import type { Address } from "viem";
import type { AlchemyProvider } from "../provider.js";
import type { ClientWithAlchemyMethods } from "./client.js";

@@ -16,82 +16,53 @@

/**
* This uses the alchemy RPC method: `alchemy_requestGasAndPaymasterAndData` to get all of the gas estimates + paymaster data
* in one RPC call. It will no-op the gas estimator and fee data getter middleware and set a custom middleware that makes the RPC call
* This middleware wraps the Alchemy Gas Manager APIs to provide more flexible UserOperation gas sponsorship.
*
* @param provider - the smart account provider to override to use the alchemy paymaster
* @param config - the alchemy paymaster configuration
* @returns the provider augmented to use the alchemy paymaster
* If `estimateGas` is true, it will use `alchemy_requestGasAndPaymasterAndData` to get all of the gas estimates + paymaster data
* in one RPC call.
*
* Otherwise, it will use `alchemy_requestPaymasterAndData` to get only paymaster data, allowing you
* to customize the gas and fee estimation middleware.
*
* @param provider - the smart account provider to override to use the alchemy gas manager
* @param config - the alchemy gas manager configuration
* @param estimateGas - if true, this will use `alchemy_requestGasAndPaymasterAndData` else will use `alchemy_requestPaymasterAndData`
* @returns the provider augmented to use the alchemy gas manager
*/
export const withAlchemyGasManager = <
T extends Transport,
Provider extends ConnectedSmartAccountProvider<T>
>(
provider: Provider,
config: AlchemyGasManagerConfig
): Provider => {
return (
provider
// no-op gas estimator
.withGasEstimator(async () => ({
callGasLimit: 0n,
preVerificationGas: 0n,
verificationGasLimit: 0n,
}))
// no-op fee because the alchemy api will do it
// can set this after the fact to do fee overrides.
.withFeeDataGetter(async () => ({
maxFeePerGas: 0n,
maxPriorityFeePerGas: 0n,
}))
.withPaymasterMiddleware({
paymasterDataMiddleware: async (struct) => {
const userOperation: UserOperationRequest = deepHexlify(
await resolveProperties(struct)
);
let feeOverride = undefined;
if (BigInt(userOperation.maxFeePerGas) > 0n) {
feeOverride = {
maxFeePerGas: userOperation.maxFeePerGas,
maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas,
};
}
const result = await (
provider.rpcClient as ClientWithAlchemyMethods
).request({
method: "alchemy_requestGasAndPaymasterAndData",
params: [
{
policyId: config.policyId,
entryPoint: config.entryPoint,
userOperation: userOperation,
dummySignature: provider.account.getDummySignature(),
feeOverride: feeOverride,
},
],
});
return result;
},
})
);
export const withAlchemyGasManager = (
provider: AlchemyProvider,
config: AlchemyGasManagerConfig,
estimateGas: boolean = true
): AlchemyProvider => {
return estimateGas
? provider
// no-op gas estimator
.withGasEstimator(async () => ({
callGasLimit: 0n,
preVerificationGas: 0n,
verificationGasLimit: 0n,
}))
// no-op fee because the alchemy api will do it
.withFeeDataGetter(async (struct) => ({
maxFeePerGas: (await struct.maxFeePerGas) ?? 0n,
maxPriorityFeePerGas: (await struct.maxPriorityFeePerGas) ?? 0n,
}))
.withPaymasterMiddleware(
withAlchemyGasAndPaymasterAndDataMiddleware(provider, config)
)
: provider.withPaymasterMiddleware(
withAlchemyPaymasterAndDataMiddleware(provider, config)
);
};
/**
* This is the middleware for calling the alchemy paymaster API which does not estimate gas. It's recommend to use
* This uses the alchemy RPC method: `alchemy_requestPaymasterAndData`, which does not estimate gas. It's recommend to use
* this middleware if you want more customization over the gas and fee estimation middleware, including setting
* non-default buffer values for the fee/gas estimation.
*
* @param config {@link AlchemyPaymasterConfig}
* @param config - the alchemy gas manager configuration
* @returns middleware overrides for paymaster middlewares
*/
export const alchemyPaymasterAndDataMiddleware = <
T extends Transport,
Provider extends ConnectedSmartAccountProvider<T>
>(
provider: Provider,
const withAlchemyPaymasterAndDataMiddleware = (
provider: AlchemyProvider,
config: AlchemyGasManagerConfig
): Parameters<
ConnectedSmartAccountProvider["withPaymasterMiddleware"]
>["0"] => ({
): Parameters<AlchemyProvider["withPaymasterMiddleware"]>["0"] => ({
dummyPaymasterDataMiddleware: async (_struct) => {

@@ -130,1 +101,44 @@ switch (provider.rpcClient.chain.id) {

});
/**
* This uses the alchemy RPC method: `alchemy_requestGasAndPaymasterAndData` to get all of the gas estimates + paymaster data
* in one RPC call. It will no-op the gas estimator and fee data getter middleware and set a custom middleware that makes the RPC call.
*
* @param config - the alchemy gas manager configuration
* @returns middleware overrides for paymaster middlewares
*/
const withAlchemyGasAndPaymasterAndDataMiddleware = (
provider: AlchemyProvider,
config: AlchemyGasManagerConfig
): Parameters<AlchemyProvider["withPaymasterMiddleware"]>["0"] => ({
paymasterDataMiddleware: async (struct) => {
const userOperation: UserOperationRequest = deepHexlify(
await resolveProperties(struct)
);
let feeOverride = undefined;
if (userOperation.maxFeePerGas && BigInt(userOperation.maxFeePerGas) > 0n) {
feeOverride = {
maxFeePerGas: userOperation.maxFeePerGas,
maxPriorityFeePerGas: userOperation.maxPriorityFeePerGas,
};
}
const result = await (
provider.rpcClient as ClientWithAlchemyMethods
).request({
method: "alchemy_requestGasAndPaymasterAndData",
params: [
{
policyId: config.policyId,
entryPoint: config.entryPoint,
userOperation: userOperation,
dummySignature: userOperation.signature,
feeOverride: feeOverride,
},
],
});
return result;
},
});
import {
BaseSmartContractAccount,
SmartAccountProvider,

@@ -8,5 +7,5 @@ createPublicErc4337Client,

type AccountMiddlewareFn,
type SmartAccountProviderOpts,
type SmartAccountProviderConfig,
} from "@alchemy/aa-core";
import { type Address, type Chain, type HttpTransport } from "viem";
import { type HttpTransport } from "viem";
import {

@@ -19,6 +18,4 @@ arbitrum,

import { SupportedChains } from "./chains.js";
import type { ClientWithAlchemyMethods } from "./middleware/client.js";
import { withAlchemyGasFeeEstimator } from "./middleware/gas-fees.js";
import {
alchemyPaymasterAndDataMiddleware,
withAlchemyGasManager,

@@ -35,6 +32,2 @@ type AlchemyGasManagerConfig,

export type AlchemyProviderConfig = {
chain: Chain | number;
entryPointAddress: Address;
account?: BaseSmartContractAccount;
opts?: SmartAccountProviderOpts;
feeOpts?: {

@@ -62,6 +55,6 @@ /** this adds a percent buffer on top of the base fee estimated (default 50%)

};
} & ConnectionConfig;
} & Omit<SmartAccountProviderConfig, "rpcProvider"> &
ConnectionConfig;
export class AlchemyProvider extends SmartAccountProvider<HttpTransport> {
alchemyClient: ClientWithAlchemyMethods;
private pvgBuffer: bigint;

@@ -73,3 +66,2 @@ private feeOptsSet: boolean;

entryPointAddress,
account,
opts,

@@ -102,5 +94,4 @@ feeOpts,

super(client, entryPointAddress, _chain, account, opts);
super({ rpcProvider: client, entryPointAddress, chain: _chain, opts });
this.alchemyClient = this.rpcClient as ClientWithAlchemyMethods;
withAlchemyGasFeeEstimator(

@@ -130,3 +121,3 @@ this,

gasEstimator: AccountMiddlewareFn = async (struct) => {
override gasEstimator: AccountMiddlewareFn = async (struct) => {
const request = deepHexlify(await resolveProperties(struct));

@@ -146,3 +137,9 @@ const estimates = await this.rpcClient.estimateUserOperationGas(

withAlchemyGasManager(config: AlchemyGasManagerConfig) {
/**
* This methods adds the Alchemy Gas Manager middleware to the provider.
*
* @param config - the Alchemy Gas Manager configuration
* @returns {AlchemyProvider} - a new AlchemyProvider with the Gas Manager middleware
*/
withAlchemyGasManager(config: AlchemyGasManagerConfig): AlchemyProvider {
if (!this.isConnected()) {

@@ -154,10 +151,4 @@ throw new Error(

if (this.feeOptsSet) {
return this.withPaymasterMiddleware(
alchemyPaymasterAndDataMiddleware(this, config)
);
} else {
return withAlchemyGasManager(this, config);
}
return withAlchemyGasManager(this, config, !this.feeOptsSet);
}
}

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc