@account-kit/infra 4.46.0 → 4.47.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/actions/types.d.ts +1 -1
- package/dist/esm/actions/types.js.map +1 -1
- package/dist/esm/client/smartAccountClient.d.ts +3 -8
- package/dist/esm/client/smartAccountClient.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/middleware/gasManager.d.ts +8 -8
- package/dist/esm/middleware/gasManager.js +4 -4
- package/dist/esm/middleware/gasManager.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/actions/types.d.ts +1 -1
- package/dist/types/client/smartAccountClient.d.ts +3 -8
- package/dist/types/client/smartAccountClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/middleware/gasManager.d.ts +8 -8
- package/dist/types/middleware/gasManager.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/actions/types.ts +1 -1
- package/src/client/smartAccountClient.ts +3 -8
- package/src/index.ts +1 -0
- package/src/middleware/gasManager.ts +17 -15
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/actions/types.ts"],"names":[],"mappings":"AAQA,MAAM,CAAN,IAAY,iBAUX;AAVD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,oCAAe,CAAA;IACf,sCAAiB,CAAA;IACjB,wCAAmB,CAAA;IACnB;;;OAGG;IACH,gDAA2B,CAAA;AAC7B,CAAC,EAVW,iBAAiB,KAAjB,iBAAiB,QAU5B;AAED,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,2CAAqB,CAAA;AACvB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B","sourcesContent":["import type {\n UserOperationStruct,\n UserOperationRequest,\n UserOperationOverrides,\n EntryPointVersion,\n} from \"@aa-sdk/core\";\nimport type { Address, Hash, Hex } from \"viem\";\n\nexport enum SimulateAssetType {\n NATIVE = \"NATIVE\",\n ERC20 = \"ERC20\",\n ERC721 = \"ERC721\",\n ERC1155 = \"ERC1155\",\n /**\n * Special contracts that don't follow ERC 721/1155. Currently limited to\n * CryptoKitties and CryptoPunks.\n */\n SPECIAL_NFT = \"SPECIAL_NFT\",\n}\n\nexport enum SimulateChangeType {\n APPROVE = \"APPROVE\",\n TRANSFER = \"TRANSFER\",\n}\n\nexport type SimulateUserOperationAssetChangesRequest = [\n UserOperationStruct,\n entryPoint: Address,\n blockNumber?: Hash,\n];\n\nexport type SimulateUserOperationAssetChangesResponse = {\n changes: SimulateAssetChange[];\n error?: SimulateAssetChangesError;\n};\n\nexport interface SimulateAssetChangesError extends Record<string, any> {\n message: string;\n}\n\nexport interface SimulateAssetChange {\n assetType: SimulateAssetType;\n changeType: SimulateChangeType;\n from: Address;\n to: Address;\n rawAmount?: string;\n amount?: string;\n contactAddress: Address;\n tokenId?: string;\n decimals: number;\n symbol: string;\n name?: string;\n logo?: string;\n}\n\nexport type RequestGasAndPaymasterAndDataRequest = [\n {\n policyId: string | string[];\n entryPoint: Address;\n erc20Context?: {\n tokenAddress: Address;\n permit?: Hex;\n maxTokenAmount?:
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/actions/types.ts"],"names":[],"mappings":"AAQA,MAAM,CAAN,IAAY,iBAUX;AAVD,WAAY,iBAAiB;IAC3B,sCAAiB,CAAA;IACjB,oCAAe,CAAA;IACf,sCAAiB,CAAA;IACjB,wCAAmB,CAAA;IACnB;;;OAGG;IACH,gDAA2B,CAAA;AAC7B,CAAC,EAVW,iBAAiB,KAAjB,iBAAiB,QAU5B;AAED,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,yCAAmB,CAAA;IACnB,2CAAqB,CAAA;AACvB,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B","sourcesContent":["import type {\n UserOperationStruct,\n UserOperationRequest,\n UserOperationOverrides,\n EntryPointVersion,\n} from \"@aa-sdk/core\";\nimport type { Address, Hash, Hex } from \"viem\";\n\nexport enum SimulateAssetType {\n NATIVE = \"NATIVE\",\n ERC20 = \"ERC20\",\n ERC721 = \"ERC721\",\n ERC1155 = \"ERC1155\",\n /**\n * Special contracts that don't follow ERC 721/1155. Currently limited to\n * CryptoKitties and CryptoPunks.\n */\n SPECIAL_NFT = \"SPECIAL_NFT\",\n}\n\nexport enum SimulateChangeType {\n APPROVE = \"APPROVE\",\n TRANSFER = \"TRANSFER\",\n}\n\nexport type SimulateUserOperationAssetChangesRequest = [\n UserOperationStruct,\n entryPoint: Address,\n blockNumber?: Hash,\n];\n\nexport type SimulateUserOperationAssetChangesResponse = {\n changes: SimulateAssetChange[];\n error?: SimulateAssetChangesError;\n};\n\nexport interface SimulateAssetChangesError extends Record<string, any> {\n message: string;\n}\n\nexport interface SimulateAssetChange {\n assetType: SimulateAssetType;\n changeType: SimulateChangeType;\n from: Address;\n to: Address;\n rawAmount?: string;\n amount?: string;\n contactAddress: Address;\n tokenId?: string;\n decimals: number;\n symbol: string;\n name?: string;\n logo?: string;\n}\n\nexport type RequestGasAndPaymasterAndDataRequest = [\n {\n policyId: string | string[];\n entryPoint: Address;\n erc20Context?: {\n tokenAddress: Address;\n permit?: Hex;\n maxTokenAmount?: number;\n };\n dummySignature: Hex;\n userOperation: UserOperationRequest;\n overrides?: UserOperationOverrides;\n },\n];\n\nexport type RequestGasAndPaymasterAndDataResponse<\n TEntryPointVersion extends EntryPointVersion = EntryPointVersion,\n> = Pick<\n UserOperationRequest,\n | \"callGasLimit\"\n | \"preVerificationGas\"\n | \"verificationGasLimit\"\n | \"maxFeePerGas\"\n | \"maxPriorityFeePerGas\"\n> &\n (TEntryPointVersion extends \"0.6.0\"\n ? {\n paymasterAndData: UserOperationRequest<\"0.6.0\">[\"paymasterAndData\"];\n }\n : TEntryPointVersion extends \"0.7.0\"\n ? Pick<\n UserOperationRequest<\"0.7.0\">,\n | \"paymaster\"\n | \"paymasterData\"\n | \"paymasterVerificationGasLimit\"\n | \"paymasterPostOpGasLimit\"\n >\n : never);\n\nexport type RequestPaymasterTokenQuoteRequest = [\n {\n policyId: string;\n entryPoint: Address;\n erc20Context?: {\n tokenAddress: Address;\n permit?: Hex;\n maxTokenAmount?: BigInt;\n };\n dummySignature: Hex;\n userOperation: UserOperationRequest;\n overrides?: UserOperationOverrides;\n },\n];\n\nexport type RequestPaymasterTokenQuoteResponse = {\n tokensPerEth: string;\n estimatedTokenAmount: string;\n estimatedUsd: number;\n};\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Prettify, type SmartAccountClient, type SmartAccountClientActions, type SmartAccountClientConfig, type SmartAccountClientRpcSchema, type SmartContractAccount, type SmartContractAccountWithSigner, type UserOperationContext } from "@aa-sdk/core";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Chain } from "viem";
|
|
3
3
|
import { type AlchemyTransport } from "../alchemyTransport.js";
|
|
4
4
|
import { type AlchemySmartAccountClientActions } from "./decorators/smartAccount.js";
|
|
5
5
|
import type { AlchemyRpcSchema } from "./types.js";
|
|
6
|
+
import type { PolicyToken } from "../middleware/gasManager.js";
|
|
6
7
|
export declare function getSignerTypeHeader<TAccount extends SmartContractAccountWithSigner>(account: TAccount): {
|
|
7
8
|
"Alchemy-Aa-Sdk-Signer": string;
|
|
8
9
|
};
|
|
@@ -10,13 +11,7 @@ export type AlchemySmartAccountClientConfig<chain extends Chain | undefined = Ch
|
|
|
10
11
|
account?: account;
|
|
11
12
|
useSimulation?: boolean;
|
|
12
13
|
policyId?: string | string[];
|
|
13
|
-
policyToken?:
|
|
14
|
-
address: Address;
|
|
15
|
-
maxTokenAmount: bigint;
|
|
16
|
-
approvalMode?: "NONE" | "PERMIT";
|
|
17
|
-
erc20Name?: string;
|
|
18
|
-
version?: string;
|
|
19
|
-
};
|
|
14
|
+
policyToken?: PolicyToken;
|
|
20
15
|
} & Pick<SmartAccountClientConfig<AlchemyTransport, chain, account, context>, "customMiddleware" | "feeEstimator" | "gasEstimator" | "signUserOperation" | "transport" | "chain" | "opts">;
|
|
21
16
|
export type BaseAlchemyActions<chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, context extends UserOperationContext | undefined = UserOperationContext | undefined> = SmartAccountClientActions<chain, account, context> & AlchemySmartAccountClientActions<account, context>;
|
|
22
17
|
export type AlchemySmartAccountClient_Base<chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, actions extends Record<string, unknown> = Record<string, unknown>, context extends UserOperationContext | undefined = UserOperationContext | undefined> = Prettify<SmartAccountClient<AlchemyTransport, chain, account, actions & BaseAlchemyActions<chain, account, context>, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccountClient.js","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,GASzB,MAAM,cAAc,CAAC;AACtB,OAAO,
|
|
1
|
+
{"version":3,"file":"smartAccountClient.js","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,wBAAwB,EACxB,wBAAwB,GASzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAc,MAAM,MAAM,CAAC;AAClC,OAAO,EACL,OAAO,EACP,sBAAsB,GAEvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iCAAiC,EAAE,MAAM,gBAAgB,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EA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IAAI,MAAM,CAAC,OAAO,IAAI,wBAAwB,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;QAC/D,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,mBAAmB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import {\n ChainNotFoundError,\n clientHeaderTrack,\n createSmartAccountClient,\n isSmartAccountWithSigner,\n type Prettify,\n type SmartAccountClient,\n type SmartAccountClientActions,\n type SmartAccountClientConfig,\n type SmartAccountClientRpcSchema,\n type SmartContractAccount,\n type SmartContractAccountWithSigner,\n type UserOperationContext,\n} from \"@aa-sdk/core\";\nimport { type Chain } from \"viem\";\nimport {\n alchemy,\n convertHeadersToObject,\n type AlchemyTransport,\n} from \"../alchemyTransport.js\";\nimport { getDefaultUserOperationFeeOptions } from \"../defaults.js\";\nimport { alchemyFeeEstimator } from \"../middleware/feeEstimator.js\";\nimport { alchemyGasAndPaymasterAndDataMiddleware } from \"../middleware/gasManager.js\";\nimport { alchemyUserOperationSimulator } from \"../middleware/userOperationSimulator.js\";\nimport {\n alchemyActions,\n type AlchemySmartAccountClientActions,\n} from \"./decorators/smartAccount.js\";\nimport type { AlchemyRpcSchema } from \"./types.js\";\nimport { headersUpdate } from \"../alchemyTrackerHeaders.js\";\nimport type { PolicyToken } from \"../middleware/gasManager.js\";\n\nexport function getSignerTypeHeader<\n TAccount extends SmartContractAccountWithSigner,\n>(account: TAccount) {\n return { \"Alchemy-Aa-Sdk-Signer\": account.getSigner().signerType };\n}\n\n// #region AlchemySmartAccountClientConfig\nexport type AlchemySmartAccountClientConfig<\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined,\n> = {\n account?: account;\n useSimulation?: boolean;\n policyId?: string | string[];\n policyToken?: PolicyToken;\n} & Pick<\n SmartAccountClientConfig<AlchemyTransport, chain, account, context>,\n | \"customMiddleware\"\n | \"feeEstimator\"\n | \"gasEstimator\"\n | \"signUserOperation\"\n | \"transport\"\n | \"chain\"\n | \"opts\"\n>;\n// #endregion AlchemySmartAccountClientConfig\n\nexport type BaseAlchemyActions<\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined,\n> = SmartAccountClientActions<chain, account, context> &\n AlchemySmartAccountClientActions<account, context>;\n\nexport type AlchemySmartAccountClient_Base<\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n actions extends Record<string, unknown> = Record<string, unknown>,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined,\n> = Prettify<\n SmartAccountClient<\n AlchemyTransport,\n chain,\n account,\n actions & BaseAlchemyActions<chain, account, context>,\n [...SmartAccountClientRpcSchema, ...AlchemyRpcSchema],\n context\n >\n>;\n\nexport type AlchemySmartAccountClient<\n chain extends Chain | undefined = Chain | undefined,\n account extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n actions extends Record<string, unknown> = Record<string, unknown>,\n context extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined,\n> = Prettify<AlchemySmartAccountClient_Base<chain, account, actions, context>>;\n\nexport function createAlchemySmartAccountClient<\n TChain extends Chain = Chain,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined,\n>(\n params: AlchemySmartAccountClientConfig<TChain, TAccount, TContext>,\n): AlchemySmartAccountClient<TChain, TAccount, Record<string, never>, TContext>;\n\n/**\n * Creates an Alchemy smart account client using the provided configuration options, including account details, gas manager configuration, and custom middleware.\n *\n * @example\n * ```ts\n * import { createAlchemySmartAccountClient, alchemy } from \"@account-kit/infra\";\n * import { sepolia } from \"@account-kit/infra/chain\";\n *\n * const client = createAlchemySmartAccountClient({\n * chain: sepolia,\n * transport: alchemy({ apiKey: \"your-api-key\" }),\n * });\n * ```\n *\n * @param {AlchemySmartAccountClientConfig} config The configuration for creating the Alchemy smart account client\n * @returns {AlchemySmartAccountClient} An instance of `AlchemySmartAccountClient` configured based on the provided options\n */\nexport function createAlchemySmartAccountClient(\n config: AlchemySmartAccountClientConfig,\n): AlchemySmartAccountClient {\n if (!config.chain) {\n throw new ChainNotFoundError();\n }\n\n const feeOptions =\n config.opts?.feeOptions ?? getDefaultUserOperationFeeOptions(config.chain);\n\n const scaClient = createSmartAccountClient({\n account: config.account,\n transport: config.transport,\n chain: config.chain,\n type: \"AlchemySmartAccountClient\",\n opts: {\n ...config.opts,\n feeOptions,\n },\n feeEstimator: config.feeEstimator ?? alchemyFeeEstimator(config.transport),\n gasEstimator: config.gasEstimator,\n customMiddleware: async (struct, args) => {\n if (isSmartAccountWithSigner(args.account)) {\n config.transport.updateHeaders(getSignerTypeHeader(args.account));\n }\n return config.customMiddleware\n ? config.customMiddleware(struct, args)\n : struct;\n },\n ...(config.policyId\n ? alchemyGasAndPaymasterAndDataMiddleware({\n policyId: config.policyId,\n policyToken: config.policyToken,\n transport: config.transport,\n gasEstimatorOverride: config.gasEstimator,\n feeEstimatorOverride: config.feeEstimator,\n })\n : {}),\n userOperationSimulator: config.useSimulation\n ? alchemyUserOperationSimulator(config.transport)\n : undefined,\n signUserOperation: config.signUserOperation,\n addBreadCrumb(breadcrumb: string) {\n const oldConfig = config.transport.config;\n const dynamicFetchOptions = config.transport.dynamicFetchOptions;\n const newTransport = alchemy({ ...oldConfig });\n newTransport.updateHeaders(\n headersUpdate(breadcrumb)(\n convertHeadersToObject(dynamicFetchOptions?.headers),\n ),\n );\n return createAlchemySmartAccountClient({\n ...config,\n transport: newTransport,\n }) as any;\n },\n })\n .extend(alchemyActions)\n .extend((client_) => ({\n addBreadcrumb(breadcrumb: string) {\n return clientHeaderTrack(client_, breadcrumb);\n },\n }));\n\n if (config.account && isSmartAccountWithSigner(config.account)) {\n config.transport.updateHeaders(getSignerTypeHeader(config.account));\n }\n\n return scaClient;\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -20,6 +20,6 @@ export { getAlchemyPaymasterAddress } from "./gas-manager.js";
|
|
|
20
20
|
export { alchemyFeeEstimator } from "./middleware/feeEstimator.js";
|
|
21
21
|
export type * from "./middleware/gasManager.js";
|
|
22
22
|
export * from "./alchemyTrackerHeaders.js";
|
|
23
|
-
export { alchemyGasManagerMiddleware, alchemyGasAndPaymasterAndDataMiddleware, } from "./middleware/gasManager.js";
|
|
23
|
+
export { alchemyGasManagerMiddleware, alchemyGasAndPaymasterAndDataMiddleware, type PolicyToken, } from "./middleware/gasManager.js";
|
|
24
24
|
export { alchemyUserOperationSimulator } from "./middleware/userOperationSimulator.js";
|
|
25
25
|
export type * from "./schema.js";
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AAGzF,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EACL,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,eAAe,EACf,IAAI,EACJ,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,cAAc,EACd,MAAM,EACN,OAAO,EACP,QAAQ,EACR,cAAc,EACd,eAAe,EACf,OAAO,EACP,WAAW,EACX,aAAa,EACb,OAAO,EACP,KAAK,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,IAAI,EACJ,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,eAAe,EACf,eAAe,EACf,UAAU,EACV,UAAU,EACV,MAAM,EACN,YAAY,EACZ,eAAe,EACf,aAAa,EACb,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ACZ,WAAW,EACX,aAAa,EACb,WAAW,EACX,UAAU,GACX,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEvF,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AAEtF,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AAEjF,OAAO,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAEnE,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EACL,2BAA2B,EAC3B,uCAAuC,GAExC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC","sourcesContent":["export type * from \"./actions/simulateUserOperationChanges.js\";\nexport { simulateUserOperationChanges } from \"./actions/simulateUserOperationChanges.js\";\nexport type * from \"./actions/types.js\";\nexport type * from \"./alchemyTransport.js\";\nexport { alchemy, isAlchemyTransport } from \"./alchemyTransport.js\";\nexport type * from \"./chains.js\";\nexport {\n arbitrum,\n arbitrumGoerli,\n arbitrumNova,\n arbitrumSepolia,\n base,\n baseGoerli,\n baseSepolia,\n defineAlchemyChain,\n fraxtal,\n fraxtalSepolia,\n goerli,\n mainnet,\n optimism,\n optimismGoerli,\n optimismSepolia,\n polygon,\n polygonAmoy,\n polygonMumbai,\n sepolia,\n shape,\n shapeSepolia,\n worldChain,\n worldChainSepolia,\n zora,\n zoraSepolia,\n beraChainBartio,\n opbnbMainnet,\n opbnbTestnet,\n soneiumMinato,\n soneiumMainnet,\n unichainMainnet,\n unichainSepolia,\n inkMainnet,\n inkSepolia,\n mekong,\n monadTestnet,\n openlootSepolia,\n gensynTestnet,\n riseTestnet,\n storyMainnet,\n storyAeneid,\n celoAlfajores,\n celoMainnet,\n teaSepolia,\n} from \"./chains.js\";\nexport type * from \"./client/decorators/alchemyEnhancedApis.js\";\nexport { alchemyEnhancedApiActions } from \"./client/decorators/alchemyEnhancedApis.js\";\nexport type * from \"./client/decorators/smartAccount.js\";\nexport { alchemyActions } from \"./client/decorators/smartAccount.js\";\nexport { isAlchemySmartAccountClient } from \"./client/isAlchemySmartAccountClient.js\";\nexport type * from \"./client/rpcClient.js\";\nexport { createAlchemyPublicRpcClient } from \"./client/rpcClient.js\";\nexport type * from \"./client/smartAccountClient.js\";\nexport { createAlchemySmartAccountClient } from \"./client/smartAccountClient.js\";\nexport type * from \"./client/types.js\";\nexport { getDefaultUserOperationFeeOptions } from \"./defaults.js\";\nexport { getAlchemyPaymasterAddress } from \"./gas-manager.js\";\nexport { alchemyFeeEstimator } from \"./middleware/feeEstimator.js\";\nexport type * from \"./middleware/gasManager.js\";\nexport * from \"./alchemyTrackerHeaders.js\";\nexport {\n alchemyGasManagerMiddleware,\n alchemyGasAndPaymasterAndDataMiddleware,\n type PolicyToken,\n} from \"./middleware/gasManager.js\";\nexport { alchemyUserOperationSimulator } from \"./middleware/userOperationSimulator.js\";\nexport type * from \"./schema.js\";\n"]}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { Address, ClientMiddlewareConfig, ClientMiddlewareFn } from "@aa-sdk/core";
|
|
2
2
|
import type { AlchemyTransport } from "../alchemyTransport.js";
|
|
3
|
+
export type PolicyToken = {
|
|
4
|
+
address: Address;
|
|
5
|
+
maxTokenAmount: number;
|
|
6
|
+
paymasterAddress?: Address;
|
|
7
|
+
approvalMode?: "NONE" | "PERMIT";
|
|
8
|
+
erc20Name?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
};
|
|
3
11
|
/**
|
|
4
12
|
* Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring
|
|
5
13
|
* transactions. Adheres to the ERC-7677 standardized communication protocol.
|
|
@@ -28,14 +36,6 @@ interface AlchemyGasAndPaymasterAndDataMiddlewareParams {
|
|
|
28
36
|
gasEstimatorOverride?: ClientMiddlewareFn;
|
|
29
37
|
feeEstimatorOverride?: ClientMiddlewareFn;
|
|
30
38
|
}
|
|
31
|
-
export type PolicyToken = {
|
|
32
|
-
address: Address;
|
|
33
|
-
maxTokenAmount: bigint;
|
|
34
|
-
paymasterAddress?: Address;
|
|
35
|
-
approvalMode?: "NONE" | "PERMIT";
|
|
36
|
-
erc20Name?: string;
|
|
37
|
-
version?: string;
|
|
38
|
-
};
|
|
39
39
|
/**
|
|
40
40
|
* Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring
|
|
41
41
|
* transactions. Uses Alchemy's custom `alchemy_requestGasAndPaymasterAndData`
|
|
@@ -247,8 +247,8 @@ const generateSignedPermit = async (client, account, policyToken) => {
|
|
|
247
247
|
if (!nonceResponse.data) {
|
|
248
248
|
throw new Error("No nonces returned from erc20 contract call");
|
|
249
249
|
}
|
|
250
|
-
const decimals =
|
|
251
|
-
const
|
|
250
|
+
const decimals = 10 ** (decimalsResponse.data ? Number(decimalsResponse.data) : 18);
|
|
251
|
+
const maxRawAmountToken = BigInt(policyToken.maxTokenAmount * decimals);
|
|
252
252
|
const nonce = BigInt(nonceResponse.data);
|
|
253
253
|
const paymasterAddress = policyToken.paymasterAddress ??
|
|
254
254
|
getAlchemyPaymasterAddress(client.chain, account.getEntryPoint().version);
|
|
@@ -268,12 +268,12 @@ const generateSignedPermit = async (client, account, policyToken) => {
|
|
|
268
268
|
message: {
|
|
269
269
|
owner: account.address,
|
|
270
270
|
spender: paymasterAddress,
|
|
271
|
-
value:
|
|
271
|
+
value: maxRawAmountToken,
|
|
272
272
|
nonce: nonce,
|
|
273
273
|
deadline,
|
|
274
274
|
},
|
|
275
275
|
};
|
|
276
276
|
const signedPermit = await account.signTypedData(typedPermitData);
|
|
277
|
-
return encodeAbiParameters([{ type: "uint256" }, { type: "uint256" }, { type: "bytes" }], [
|
|
277
|
+
return encodeAbiParameters([{ type: "uint256" }, { type: "uint256" }, { type: "bytes" }], [maxRawAmountToken, deadline, signedPermit]);
|
|
278
278
|
};
|
|
279
279
|
//# sourceMappingURL=gasManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gasManager.js","sourceRoot":"","sources":["../../../src/middleware/gasManager.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,cAAc,EACd,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,OAAO,EACP,KAAK,EAEL,mBAAmB,EACnB,kBAAkB,EAClB,QAAQ,GACT,MAAM,MAAM,CAAC;AAGd,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD,OAAO,EACL,WAAW,EACX,WAAW,EACX,SAAS,EACT,0BAA0B,GAC3B,MAAM,mBAAmB,CAAC;AAY3B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,2BAA2B,CACzC,QAA2B,EAC3B,WAAyB;IAIzB,MAAM,YAAY,GAAG,KAAK,EACxB,IAAuC,EACrB,EAAE;QACpB,MAAM,OAAO,GAAY,EAAE,QAAQ,EAAE,CAAC;QAEtC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;QACjC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAClB,MAAM,IAAI,kBAAkB,EAAE,CAAC;QACjC,CAAC;QAED,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC9B,OAAO,CAAC,YAAY,GAAG;gBACrB,YAAY,EAAE,WAAW,CAAC,OAAO;gBACjC,cAAc,EAAE,WAAW,CAAC,cAAc;aAC3C,CAAC;YAEF,IAAI,WAAW,CAAC,YAAY,KAA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AC;IAClE,OAAO,mBAAmB,CACxB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAC7D,CAAC,cAAc,EAAE,QAAQ,EAAE,YAAY,CAAC,CACzC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {\n Address,\n ClientMiddlewareConfig,\n ClientMiddlewareFn,\n EntryPointVersion,\n Multiplier,\n SmartContractAccount,\n UserOperationFeeOptions,\n UserOperationOverrides,\n UserOperationRequest,\n} from \"@aa-sdk/core\";\nimport {\n bypassPaymasterAndData,\n ChainNotFoundError,\n clientHeaderTrack,\n deepHexlify,\n defaultGasEstimator,\n erc7677Middleware,\n filterUndefined,\n isBigNumberish,\n isMultiplier,\n noopMiddleware,\n resolveProperties,\n} from \"@aa-sdk/core\";\nimport {\n fromHex,\n isHex,\n type Hex,\n encodeAbiParameters,\n encodeFunctionData,\n parseAbi,\n} from \"viem\";\nimport type { AlchemySmartAccountClient } from \"../client/smartAccountClient.js\";\nimport type { AlchemyTransport } from \"../alchemyTransport.js\";\nimport { alchemyFeeEstimator } from \"./feeEstimator.js\";\nimport type { RequestGasAndPaymasterAndDataRequest } from \"../actions/types.js\";\nimport {\n PermitTypes,\n EIP7597Abis,\n ERC20Abis,\n getAlchemyPaymasterAddress,\n} from \"../gas-manager.js\";\nimport type { PermitMessage, PermitDomain } from \"../gas-manager.js\";\nimport type { MiddlewareClient } from \"../../../../aa-sdk/core/dist/types/middleware/actions.js\";\n\ntype Context = {\n policyId: string | string[];\n erc20Context?: {\n tokenAddress: Address;\n maxTokenAmount?: BigInt;\n permit?: Hex;\n };\n};\n/**\n * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring\n * transactions. Adheres to the ERC-7677 standardized communication protocol.\n *\n * @example\n * ```ts\n * import { sepolia, alchemyGasManagerMiddleware } from \"@account-kit/infra\";\n * import { http } from \"viem\";\n *\n * const client = createSmartAccountClient({\n * transport: http(\"rpc-url\"),\n * chain: sepolia,\n * ...alchemyGasManagerMiddleware(\"policyId\")\n * });\n * ```\n *\n * @param {string | string[]} policyId - The policyId (or list of policyIds) for Alchemy's gas manager\n * @param {PolicyToken | undefined} policyToken - The policy token configuration\n * @returns {Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"paymasterAndData\">} Partial client middleware configuration containing `dummyPaymasterAndData` and `paymasterAndData`\n */\nexport function alchemyGasManagerMiddleware(\n policyId: string | string[],\n policyToken?: PolicyToken,\n): Required<\n Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"paymasterAndData\">\n> {\n const buildContext = async (\n args: Parameters<ClientMiddlewareFn>[1],\n ): Promise<Context> => {\n const context: Context = { policyId };\n\n const { account, client } = args;\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n if (policyToken !== undefined) {\n context.erc20Context = {\n tokenAddress: policyToken.address,\n maxTokenAmount: policyToken.maxTokenAmount,\n };\n\n if (policyToken.approvalMode === \"PERMIT\") {\n context.erc20Context.permit = await generateSignedPermit(\n client as AlchemySmartAccountClient,\n account,\n policyToken,\n );\n }\n }\n\n return context;\n };\n return {\n dummyPaymasterAndData: async (uo, args) => {\n const context = await buildContext(args);\n const baseMiddleware = erc7677Middleware({ context });\n return baseMiddleware.dummyPaymasterAndData(uo, args);\n },\n\n paymasterAndData: async (uo, args) => {\n const context = await buildContext(args);\n const baseMiddleware = erc7677Middleware({ context });\n return baseMiddleware.paymasterAndData(uo, args);\n },\n };\n}\n\ninterface AlchemyGasAndPaymasterAndDataMiddlewareParams {\n policyId: string | string[];\n policyToken?: PolicyToken;\n transport: AlchemyTransport;\n gasEstimatorOverride?: ClientMiddlewareFn;\n feeEstimatorOverride?: ClientMiddlewareFn;\n}\n\nexport type PolicyToken = {\n address: Address;\n maxTokenAmount: bigint;\n paymasterAddress?: Address;\n approvalMode?: \"NONE\" | \"PERMIT\";\n erc20Name?: string;\n version?: string;\n};\n\n/**\n * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring\n * transactions. Uses Alchemy's custom `alchemy_requestGasAndPaymasterAndData`\n * method instead of conforming to the standard ERC-7677 interface. Note that\n * if you use `createAlchemySmartAccountClient`, this middleware is already\n * used by default and you do not need to manually include it.\n *\n * @example\n * ```ts twoslash\n * import { sepolia, alchemy, alchemyGasAndPaymasterAndDataMiddleware } from \"@account-kit/infra\";\n * import { createSmartAccountClient } from \"@aa-sdk/core\";\n *\n * const client = createSmartAccountClient({\n * transport: alchemy({ apiKey: \"your-api-key\" }),\n * chain: sepolia,\n * ...alchemyGasAndPaymasterAndDataMiddleware({\n * policyId: \"policyId\",\n * transport: alchemy({ apiKey: \"your-api-key\" }),\n * })\n * });\n * ```\n *\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams} params configuration params\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.policyId} params.policyId the policyId for Alchemy's gas manager\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.transport} params.transport fallback transport to use for fee estimation when not using the paymaster\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.gasEstimatorOverride} params.gasEstimatorOverride custom gas estimator middleware\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.feeEstimatorOverride} params.feeEstimatorOverride custom fee estimator middleware\n * @returns {Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"feeEstimator\" | \"gasEstimator\" | \"paymasterAndData\">} partial client middleware configuration containing `dummyPaymasterAndData`, `feeEstimator`, `gasEstimator`, and `paymasterAndData`\n */\nexport function alchemyGasAndPaymasterAndDataMiddleware(\n params: AlchemyGasAndPaymasterAndDataMiddlewareParams,\n): Pick<\n ClientMiddlewareConfig,\n \"dummyPaymasterAndData\" | \"feeEstimator\" | \"gasEstimator\" | \"paymasterAndData\"\n> {\n const {\n policyId,\n policyToken,\n transport,\n gasEstimatorOverride,\n feeEstimatorOverride,\n } = params;\n return {\n dummyPaymasterAndData: async (uo, args) => {\n if (\n // No reason to generate dummy data if we are bypassing the paymaster.\n bypassPaymasterAndData(args.overrides) ||\n // When using alchemy_requestGasAndPaymasterAndData, there is generally no reason to generate dummy\n // data. However, if the gas/feeEstimator is overriden, then this option should be enabled.\n !(gasEstimatorOverride || feeEstimatorOverride)\n ) {\n return noopMiddleware(uo, args);\n }\n\n // Fall back to the default 7677 dummyPaymasterAndData middleware.\n return alchemyGasManagerMiddleware(\n policyId,\n policyToken,\n ).dummyPaymasterAndData(uo, args);\n },\n feeEstimator: (uo, args) => {\n return feeEstimatorOverride\n ? feeEstimatorOverride(uo, args)\n : bypassPaymasterAndData(args.overrides)\n ? alchemyFeeEstimator(transport)(uo, args)\n : noopMiddleware(uo, args);\n },\n gasEstimator: (uo, args) => {\n return gasEstimatorOverride\n ? gasEstimatorOverride(uo, args)\n : bypassPaymasterAndData(args.overrides)\n ? defaultGasEstimator(args.client)(uo, args)\n : noopMiddleware(uo, args);\n },\n paymasterAndData: async (\n uo,\n { account, client: client_, feeOptions, overrides: overrides_ },\n ) => {\n const client = clientHeaderTrack(client_, \"alchemyFeeEstimator\");\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const userOp = deepHexlify(await resolveProperties(uo));\n\n const overrides: UserOperationOverrides = filterUndefined({\n maxFeePerGas: overrideField(\n \"maxFeePerGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n maxPriorityFeePerGas: overrideField(\n \"maxPriorityFeePerGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n callGasLimit: overrideField(\n \"callGasLimit\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n verificationGasLimit: overrideField(\n \"verificationGasLimit\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n preVerificationGas: overrideField(\n \"preVerificationGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n ...(account.getEntryPoint().version === \"0.7.0\"\n ? {\n paymasterVerificationGasLimit: overrideField<\"0.7.0\">(\n \"paymasterVerificationGasLimit\",\n overrides_ as UserOperationOverrides<\"0.7.0\">,\n feeOptions,\n userOp,\n ),\n paymasterPostOpGasLimit: overrideField<\"0.7.0\">(\n \"paymasterPostOpGasLimit\",\n overrides_ as UserOperationOverrides<\"0.7.0\">,\n feeOptions,\n userOp,\n ),\n }\n : {}),\n });\n\n let erc20Context: RequestGasAndPaymasterAndDataRequest[0][\"erc20Context\"] =\n undefined;\n if (policyToken !== undefined) {\n erc20Context = {\n tokenAddress: policyToken.address,\n maxTokenAmount: policyToken.maxTokenAmount,\n };\n if (policyToken.approvalMode === \"PERMIT\") {\n erc20Context.permit = await generateSignedPermit(\n client,\n account,\n policyToken,\n );\n }\n }\n\n const result = await (client as AlchemySmartAccountClient).request({\n method: \"alchemy_requestGasAndPaymasterAndData\",\n params: [\n {\n policyId,\n entryPoint: account.getEntryPoint().address,\n userOperation: userOp,\n dummySignature: await account.getDummySignature(),\n overrides,\n ...(erc20Context\n ? {\n erc20Context,\n }\n : {}),\n },\n ],\n });\n\n return {\n ...uo,\n ...result,\n };\n },\n };\n}\n\n/**\n * Utility function to override a field in the user operation request with the overrides or fee options\n *\n * @template {EntryPointVersion} TEntryPointVersion\n * @param {keyof UserOperationFeeOptions<TEntryPointVersion>} field the field to override\n * @param {UserOperationOverrides<TEntryPointVersion> | undefined} overrides the overrides object\n * @param {UserOperationFeeOptions<TEntryPointVersion> | undefined} feeOptions the fee options object from the client\n * @param {UserOperationRequest<TEntryPointVersion>} userOperation the user operation request\n * @returns {Hex | Multiplier | undefined} the overridden field value\n */\nconst overrideField = <\n TEntryPointVersion extends EntryPointVersion = EntryPointVersion,\n>(\n field: keyof UserOperationFeeOptions<TEntryPointVersion>,\n overrides: UserOperationOverrides<TEntryPointVersion> | undefined,\n feeOptions: UserOperationFeeOptions<TEntryPointVersion> | undefined,\n userOperation: UserOperationRequest<TEntryPointVersion>,\n): Hex | Multiplier | undefined => {\n let _field = field as keyof UserOperationOverrides<TEntryPointVersion>;\n\n if (overrides?.[_field] != null) {\n // one-off absolute override\n if (isBigNumberish(overrides[_field])) {\n return deepHexlify(overrides[_field]);\n }\n // one-off multiplier overrides\n else {\n return {\n multiplier: Number((overrides[_field] as Multiplier).multiplier),\n };\n }\n }\n\n // provider level fee options with multiplier\n if (isMultiplier(feeOptions?.[field])) {\n return {\n multiplier: Number((feeOptions![field] as Multiplier).multiplier),\n };\n }\n\n const userOpField =\n userOperation[field as keyof UserOperationRequest<TEntryPointVersion>];\n if (isHex(userOpField) && fromHex(userOpField as Hex, \"bigint\") > 0n) {\n return userOpField;\n }\n return undefined;\n};\n\n/**\n * Utility function to generate a signed Permit for erc20 transaction\n *\n * @param {MiddlewareClient} client - The Alchemy smart account client\n * @param {TAccount} account - The smart account instance\n * @param {PolicyToken} policyToken - The policy token configuration\n * @param {Address} policyToken.address - ERC20 contract addressya\n * @param {bigint} [policyToken.maxTokenAmount] - Optional ERC20 token limit\n * @param {Address} [policyToken.paymasterAddress] - Optional Paymaster Address\n * @param {\"NONE\" | \"PERMIT\"} [policyToken.approvalMode] - ERC20 approve mode\n * @param {string} [policyToken.erc20Name] - EIP2612 specified ERC20 contract name\n * @param {string} [policyToken.version] - EIP2612 specified ERC20 contract version\n * @returns {Promise<Hex>} Returns a Promise containing the signed EIP2612 permit\n */\nconst generateSignedPermit = async <TAccount extends SmartContractAccount>(\n client: MiddlewareClient,\n account: TAccount,\n policyToken: {\n address: Address;\n maxTokenAmount: bigint;\n paymasterAddress?: Address;\n approvalMode?: \"NONE\" | \"PERMIT\";\n erc20Name?: string;\n version?: string;\n },\n): Promise<Hex> => {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n if (!policyToken.erc20Name || !policyToken.version) {\n throw new Error(\"erc20Name or version is missing\");\n }\n\n let decimalsFuture = client.call({\n to: policyToken.address,\n data: encodeFunctionData({\n abi: parseAbi(ERC20Abis),\n functionName: \"decimals\",\n args: [],\n }),\n });\n\n let nonceFuture = client.call({\n to: policyToken.address,\n data: encodeFunctionData({\n abi: parseAbi(EIP7597Abis),\n functionName: \"nonces\",\n args: [account.address],\n }),\n });\n\n const [decimalsResponse, nonceResponse] = await Promise.all([\n decimalsFuture,\n nonceFuture,\n ]);\n if (!decimalsResponse.data) {\n throw new Error(\"No decimals returned from erc20 contract call\");\n }\n if (!nonceResponse.data) {\n throw new Error(\"No nonces returned from erc20 contract call\");\n }\n\n const decimals =\n 10n ** (decimalsResponse.data ? BigInt(decimalsResponse.data) : 18n);\n const maxAmountToken = policyToken.maxTokenAmount * decimals;\n const nonce = BigInt(nonceResponse.data);\n\n const paymasterAddress =\n policyToken.paymasterAddress ??\n getAlchemyPaymasterAddress(client.chain, account.getEntryPoint().version);\n\n if (paymasterAddress === undefined || paymasterAddress === \"0x\") {\n throw new Error(\"no paymaster contract address available\");\n }\n\n const deadline = BigInt(Math.floor(Date.now() / 1000) + 60 * 10);\n\n const typedPermitData = {\n types: PermitTypes,\n primaryType: \"Permit\" as const,\n domain: {\n name: policyToken.erc20Name ?? \"\",\n version: policyToken.version ?? \"\",\n chainId: BigInt(client.chain.id),\n verifyingContract: policyToken.address,\n } satisfies PermitDomain,\n message: {\n owner: account.address,\n spender: paymasterAddress,\n value: maxAmountToken,\n nonce: nonce,\n deadline,\n } satisfies PermitMessage,\n } as const;\n\n const signedPermit = await account.signTypedData(typedPermitData);\n return encodeAbiParameters(\n [{ type: \"uint256\" }, { type: \"uint256\" }, { type: \"bytes\" }],\n [maxAmountToken, deadline, signedPermit],\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"gasManager.js","sourceRoot":"","sources":["../../../src/middleware/gasManager.ts"],"names":[],"mappings":"AAWA,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,EACjB,WAAW,EACX,mBAAmB,EACnB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,cAAc,EACd,iBAAiB,GAClB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,O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,gBAAgB,KAAK,SAAS,IAAI,gBAAgB,KAAK,IAAI,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IAEjE,MAAM,eAAe,GAAG;QACtB,KAAK,EAAE,WAAW;QAClB,WAAW,EAAE,QAAiB;QAC9B,MAAM,EAAE;YACN,IAAI,EAAE,WAAW,CAAC,SAAS,IAAI,EAAE;YACjC,OAAO,EAAE,WAAW,CAAC,OAAO,IAAI,EAAE;YAClC,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAChC,iBAAiB,EAAE,WAAW,CAAC,OAAO;SAChB;QACxB,OAAO,EAAE;YACP,KAAK,EAAE,OAAO,CAAC,OAAO;YACtB,OAAO,EAAE,gBAAgB;YACzB,KAAK,EAAE,iBAAiB;YACxB,KAAK,EAAE,KAAK;YACZ,QAAQ;SACe;KACjB,CAAC;IAEX,MAAM,YAAY,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;IAClE,OAAO,mBAAmB,CACxB,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EAC7D,CAAC,iBAAiB,EAAE,QAAQ,EAAE,YAAY,CAAC,CAC5C,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type {\n Address,\n ClientMiddlewareConfig,\n ClientMiddlewareFn,\n EntryPointVersion,\n Multiplier,\n SmartContractAccount,\n UserOperationFeeOptions,\n UserOperationOverrides,\n UserOperationRequest,\n} from \"@aa-sdk/core\";\nimport {\n bypassPaymasterAndData,\n ChainNotFoundError,\n clientHeaderTrack,\n deepHexlify,\n defaultGasEstimator,\n erc7677Middleware,\n filterUndefined,\n isBigNumberish,\n isMultiplier,\n noopMiddleware,\n resolveProperties,\n} from \"@aa-sdk/core\";\nimport {\n fromHex,\n isHex,\n type Hex,\n encodeAbiParameters,\n encodeFunctionData,\n parseAbi,\n} from \"viem\";\nimport type { AlchemySmartAccountClient } from \"../client/smartAccountClient.js\";\nimport type { AlchemyTransport } from \"../alchemyTransport.js\";\nimport { alchemyFeeEstimator } from \"./feeEstimator.js\";\nimport type { RequestGasAndPaymasterAndDataRequest } from \"../actions/types.js\";\n\nimport {\n PermitTypes,\n EIP7597Abis,\n ERC20Abis,\n getAlchemyPaymasterAddress,\n} from \"../gas-manager.js\";\nimport type { PermitMessage, PermitDomain } from \"../gas-manager.js\";\nimport type { MiddlewareClient } from \"../../../../aa-sdk/core/dist/types/middleware/actions.js\";\n\ntype Context = {\n policyId: string | string[];\n erc20Context?: {\n tokenAddress: Address;\n maxTokenAmount?: number;\n permit?: Hex;\n };\n};\n\nexport type PolicyToken = {\n address: Address;\n maxTokenAmount: number;\n paymasterAddress?: Address;\n approvalMode?: \"NONE\" | \"PERMIT\";\n erc20Name?: string;\n version?: string;\n};\n\n/**\n * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring\n * transactions. Adheres to the ERC-7677 standardized communication protocol.\n *\n * @example\n * ```ts\n * import { sepolia, alchemyGasManagerMiddleware } from \"@account-kit/infra\";\n * import { http } from \"viem\";\n *\n * const client = createSmartAccountClient({\n * transport: http(\"rpc-url\"),\n * chain: sepolia,\n * ...alchemyGasManagerMiddleware(\"policyId\")\n * });\n * ```\n *\n * @param {string | string[]} policyId - The policyId (or list of policyIds) for Alchemy's gas manager\n * @param {PolicyToken | undefined} policyToken - The policy token configuration\n * @returns {Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"paymasterAndData\">} Partial client middleware configuration containing `dummyPaymasterAndData` and `paymasterAndData`\n */\nexport function alchemyGasManagerMiddleware(\n policyId: string | string[],\n policyToken?: PolicyToken,\n): Required<\n Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"paymasterAndData\">\n> {\n const buildContext = async (\n args: Parameters<ClientMiddlewareFn>[1],\n ): Promise<Context> => {\n const context: Context = { policyId };\n\n const { account, client } = args;\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n if (policyToken !== undefined) {\n context.erc20Context = {\n tokenAddress: policyToken.address,\n maxTokenAmount: policyToken.maxTokenAmount,\n };\n\n if (policyToken.approvalMode === \"PERMIT\") {\n context.erc20Context.permit = await generateSignedPermit(\n client as AlchemySmartAccountClient,\n account,\n policyToken,\n );\n }\n }\n\n return context;\n };\n return {\n dummyPaymasterAndData: async (uo, args) => {\n const context = await buildContext(args);\n const baseMiddleware = erc7677Middleware({ context });\n return baseMiddleware.dummyPaymasterAndData(uo, args);\n },\n\n paymasterAndData: async (uo, args) => {\n const context = await buildContext(args);\n const baseMiddleware = erc7677Middleware({ context });\n return baseMiddleware.paymasterAndData(uo, args);\n },\n };\n}\n\ninterface AlchemyGasAndPaymasterAndDataMiddlewareParams {\n policyId: string | string[];\n policyToken?: PolicyToken;\n transport: AlchemyTransport;\n gasEstimatorOverride?: ClientMiddlewareFn;\n feeEstimatorOverride?: ClientMiddlewareFn;\n}\n\n/**\n * Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring\n * transactions. Uses Alchemy's custom `alchemy_requestGasAndPaymasterAndData`\n * method instead of conforming to the standard ERC-7677 interface. Note that\n * if you use `createAlchemySmartAccountClient`, this middleware is already\n * used by default and you do not need to manually include it.\n *\n * @example\n * ```ts twoslash\n * import { sepolia, alchemy, alchemyGasAndPaymasterAndDataMiddleware } from \"@account-kit/infra\";\n * import { createSmartAccountClient } from \"@aa-sdk/core\";\n *\n * const client = createSmartAccountClient({\n * transport: alchemy({ apiKey: \"your-api-key\" }),\n * chain: sepolia,\n * ...alchemyGasAndPaymasterAndDataMiddleware({\n * policyId: \"policyId\",\n * transport: alchemy({ apiKey: \"your-api-key\" }),\n * })\n * });\n * ```\n *\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams} params configuration params\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.policyId} params.policyId the policyId for Alchemy's gas manager\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.transport} params.transport fallback transport to use for fee estimation when not using the paymaster\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.gasEstimatorOverride} params.gasEstimatorOverride custom gas estimator middleware\n * @param {AlchemyGasAndPaymasterAndDataMiddlewareParams.feeEstimatorOverride} params.feeEstimatorOverride custom fee estimator middleware\n * @returns {Pick<ClientMiddlewareConfig, \"dummyPaymasterAndData\" | \"feeEstimator\" | \"gasEstimator\" | \"paymasterAndData\">} partial client middleware configuration containing `dummyPaymasterAndData`, `feeEstimator`, `gasEstimator`, and `paymasterAndData`\n */\nexport function alchemyGasAndPaymasterAndDataMiddleware(\n params: AlchemyGasAndPaymasterAndDataMiddlewareParams,\n): Pick<\n ClientMiddlewareConfig,\n \"dummyPaymasterAndData\" | \"feeEstimator\" | \"gasEstimator\" | \"paymasterAndData\"\n> {\n const {\n policyId,\n policyToken,\n transport,\n gasEstimatorOverride,\n feeEstimatorOverride,\n } = params;\n return {\n dummyPaymasterAndData: async (uo, args) => {\n if (\n // No reason to generate dummy data if we are bypassing the paymaster.\n bypassPaymasterAndData(args.overrides) ||\n // When using alchemy_requestGasAndPaymasterAndData, there is generally no reason to generate dummy\n // data. However, if the gas/feeEstimator is overriden, then this option should be enabled.\n !(gasEstimatorOverride || feeEstimatorOverride)\n ) {\n return noopMiddleware(uo, args);\n }\n\n // Fall back to the default 7677 dummyPaymasterAndData middleware.\n return alchemyGasManagerMiddleware(\n policyId,\n policyToken,\n ).dummyPaymasterAndData(uo, args);\n },\n feeEstimator: (uo, args) => {\n return feeEstimatorOverride\n ? feeEstimatorOverride(uo, args)\n : bypassPaymasterAndData(args.overrides)\n ? alchemyFeeEstimator(transport)(uo, args)\n : noopMiddleware(uo, args);\n },\n gasEstimator: (uo, args) => {\n return gasEstimatorOverride\n ? gasEstimatorOverride(uo, args)\n : bypassPaymasterAndData(args.overrides)\n ? defaultGasEstimator(args.client)(uo, args)\n : noopMiddleware(uo, args);\n },\n paymasterAndData: async (\n uo,\n { account, client: client_, feeOptions, overrides: overrides_ },\n ) => {\n const client = clientHeaderTrack(client_, \"alchemyFeeEstimator\");\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const userOp = deepHexlify(await resolveProperties(uo));\n\n const overrides: UserOperationOverrides = filterUndefined({\n maxFeePerGas: overrideField(\n \"maxFeePerGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n maxPriorityFeePerGas: overrideField(\n \"maxPriorityFeePerGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n callGasLimit: overrideField(\n \"callGasLimit\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n verificationGasLimit: overrideField(\n \"verificationGasLimit\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n preVerificationGas: overrideField(\n \"preVerificationGas\",\n overrides_ as UserOperationOverrides,\n feeOptions,\n userOp,\n ),\n ...(account.getEntryPoint().version === \"0.7.0\"\n ? {\n paymasterVerificationGasLimit: overrideField<\"0.7.0\">(\n \"paymasterVerificationGasLimit\",\n overrides_ as UserOperationOverrides<\"0.7.0\">,\n feeOptions,\n userOp,\n ),\n paymasterPostOpGasLimit: overrideField<\"0.7.0\">(\n \"paymasterPostOpGasLimit\",\n overrides_ as UserOperationOverrides<\"0.7.0\">,\n feeOptions,\n userOp,\n ),\n }\n : {}),\n });\n\n let erc20Context: RequestGasAndPaymasterAndDataRequest[0][\"erc20Context\"] =\n undefined;\n if (policyToken !== undefined) {\n erc20Context = {\n tokenAddress: policyToken.address,\n maxTokenAmount: policyToken.maxTokenAmount,\n };\n if (policyToken.approvalMode === \"PERMIT\") {\n erc20Context.permit = await generateSignedPermit(\n client,\n account,\n policyToken,\n );\n }\n }\n\n const result = await (client as AlchemySmartAccountClient).request({\n method: \"alchemy_requestGasAndPaymasterAndData\",\n params: [\n {\n policyId,\n entryPoint: account.getEntryPoint().address,\n userOperation: userOp,\n dummySignature: await account.getDummySignature(),\n overrides,\n ...(erc20Context\n ? {\n erc20Context,\n }\n : {}),\n },\n ],\n });\n\n return {\n ...uo,\n ...result,\n };\n },\n };\n}\n\n/**\n * Utility function to override a field in the user operation request with the overrides or fee options\n *\n * @template {EntryPointVersion} TEntryPointVersion\n * @param {keyof UserOperationFeeOptions<TEntryPointVersion>} field the field to override\n * @param {UserOperationOverrides<TEntryPointVersion> | undefined} overrides the overrides object\n * @param {UserOperationFeeOptions<TEntryPointVersion> | undefined} feeOptions the fee options object from the client\n * @param {UserOperationRequest<TEntryPointVersion>} userOperation the user operation request\n * @returns {Hex | Multiplier | undefined} the overridden field value\n */\nconst overrideField = <\n TEntryPointVersion extends EntryPointVersion = EntryPointVersion,\n>(\n field: keyof UserOperationFeeOptions<TEntryPointVersion>,\n overrides: UserOperationOverrides<TEntryPointVersion> | undefined,\n feeOptions: UserOperationFeeOptions<TEntryPointVersion> | undefined,\n userOperation: UserOperationRequest<TEntryPointVersion>,\n): Hex | Multiplier | undefined => {\n let _field = field as keyof UserOperationOverrides<TEntryPointVersion>;\n\n if (overrides?.[_field] != null) {\n // one-off absolute override\n if (isBigNumberish(overrides[_field])) {\n return deepHexlify(overrides[_field]);\n }\n // one-off multiplier overrides\n else {\n return {\n multiplier: Number((overrides[_field] as Multiplier).multiplier),\n };\n }\n }\n\n // provider level fee options with multiplier\n if (isMultiplier(feeOptions?.[field])) {\n return {\n multiplier: Number((feeOptions![field] as Multiplier).multiplier),\n };\n }\n\n const userOpField =\n userOperation[field as keyof UserOperationRequest<TEntryPointVersion>];\n if (isHex(userOpField) && fromHex(userOpField as Hex, \"bigint\") > 0n) {\n return userOpField;\n }\n return undefined;\n};\n\n/**\n * Utility function to generate a signed Permit for erc20 transaction\n *\n * @param {MiddlewareClient} client - The Alchemy smart account client\n * @param {TAccount} account - The smart account instance\n * @param {PolicyToken} policyToken - The policy token configuration\n * @param {Address} policyToken.address - ERC20 contract addressya\n * @param {bigint} [policyToken.maxTokenAmount] - Optional ERC20 token limit\n * @param {Address} [policyToken.paymasterAddress] - Optional Paymaster Address\n * @param {\"NONE\" | \"PERMIT\"} [policyToken.approvalMode] - ERC20 approve mode\n * @param {string} [policyToken.erc20Name] - EIP2612 specified ERC20 contract name\n * @param {string} [policyToken.version] - EIP2612 specified ERC20 contract version\n * @returns {Promise<Hex>} Returns a Promise containing the signed EIP2612 permit\n */\nconst generateSignedPermit = async <TAccount extends SmartContractAccount>(\n client: MiddlewareClient,\n account: TAccount,\n policyToken: {\n address: Address;\n maxTokenAmount: number;\n paymasterAddress?: Address;\n approvalMode?: \"NONE\" | \"PERMIT\";\n erc20Name?: string;\n version?: string;\n },\n): Promise<Hex> => {\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n if (!policyToken.erc20Name || !policyToken.version) {\n throw new Error(\"erc20Name or version is missing\");\n }\n\n let decimalsFuture = client.call({\n to: policyToken.address,\n data: encodeFunctionData({\n abi: parseAbi(ERC20Abis),\n functionName: \"decimals\",\n args: [],\n }),\n });\n\n let nonceFuture = client.call({\n to: policyToken.address,\n data: encodeFunctionData({\n abi: parseAbi(EIP7597Abis),\n functionName: \"nonces\",\n args: [account.address],\n }),\n });\n\n const [decimalsResponse, nonceResponse] = await Promise.all([\n decimalsFuture,\n nonceFuture,\n ]);\n if (!decimalsResponse.data) {\n throw new Error(\"No decimals returned from erc20 contract call\");\n }\n if (!nonceResponse.data) {\n throw new Error(\"No nonces returned from erc20 contract call\");\n }\n\n const decimals =\n 10 ** (decimalsResponse.data ? Number(decimalsResponse.data) : 18);\n const maxRawAmountToken = BigInt(policyToken.maxTokenAmount * decimals);\n const nonce = BigInt(nonceResponse.data);\n\n const paymasterAddress =\n policyToken.paymasterAddress ??\n getAlchemyPaymasterAddress(client.chain, account.getEntryPoint().version);\n\n if (paymasterAddress === undefined || paymasterAddress === \"0x\") {\n throw new Error(\"no paymaster contract address available\");\n }\n\n const deadline = BigInt(Math.floor(Date.now() / 1000) + 60 * 10);\n\n const typedPermitData = {\n types: PermitTypes,\n primaryType: \"Permit\" as const,\n domain: {\n name: policyToken.erc20Name ?? \"\",\n version: policyToken.version ?? \"\",\n chainId: BigInt(client.chain.id),\n verifyingContract: policyToken.address,\n } satisfies PermitDomain,\n message: {\n owner: account.address,\n spender: paymasterAddress,\n value: maxRawAmountToken,\n nonce: nonce,\n deadline,\n } satisfies PermitMessage,\n } as const;\n\n const signedPermit = await account.signTypedData(typedPermitData);\n return encodeAbiParameters(\n [{ type: \"uint256\" }, { type: \"uint256\" }, { type: \"bytes\" }],\n [maxRawAmountToken, deadline, signedPermit],\n );\n};\n"]}
|
package/dist/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.47.0";
|
package/dist/esm/version.js
CHANGED
package/dist/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.47.0\";\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Prettify, type SmartAccountClient, type SmartAccountClientActions, type SmartAccountClientConfig, type SmartAccountClientRpcSchema, type SmartContractAccount, type SmartContractAccountWithSigner, type UserOperationContext } from "@aa-sdk/core";
|
|
2
|
-
import { type
|
|
2
|
+
import { type Chain } from "viem";
|
|
3
3
|
import { type AlchemyTransport } from "../alchemyTransport.js";
|
|
4
4
|
import { type AlchemySmartAccountClientActions } from "./decorators/smartAccount.js";
|
|
5
5
|
import type { AlchemyRpcSchema } from "./types.js";
|
|
6
|
+
import type { PolicyToken } from "../middleware/gasManager.js";
|
|
6
7
|
export declare function getSignerTypeHeader<TAccount extends SmartContractAccountWithSigner>(account: TAccount): {
|
|
7
8
|
"Alchemy-Aa-Sdk-Signer": string;
|
|
8
9
|
};
|
|
@@ -10,13 +11,7 @@ export type AlchemySmartAccountClientConfig<chain extends Chain | undefined = Ch
|
|
|
10
11
|
account?: account;
|
|
11
12
|
useSimulation?: boolean;
|
|
12
13
|
policyId?: string | string[];
|
|
13
|
-
policyToken?:
|
|
14
|
-
address: Address;
|
|
15
|
-
maxTokenAmount: bigint;
|
|
16
|
-
approvalMode?: "NONE" | "PERMIT";
|
|
17
|
-
erc20Name?: string;
|
|
18
|
-
version?: string;
|
|
19
|
-
};
|
|
14
|
+
policyToken?: PolicyToken;
|
|
20
15
|
} & Pick<SmartAccountClientConfig<AlchemyTransport, chain, account, context>, "customMiddleware" | "feeEstimator" | "gasEstimator" | "signUserOperation" | "transport" | "chain" | "opts">;
|
|
21
16
|
export type BaseAlchemyActions<chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, context extends UserOperationContext | undefined = UserOperationContext | undefined> = SmartAccountClientActions<chain, account, context> & AlchemySmartAccountClientActions<account, context>;
|
|
22
17
|
export type AlchemySmartAccountClient_Base<chain extends Chain | undefined = Chain | undefined, account extends SmartContractAccount | undefined = SmartContractAccount | undefined, actions extends Record<string, unknown> = Record<string, unknown>, context extends UserOperationContext | undefined = UserOperationContext | undefined> = Prettify<SmartAccountClient<AlchemyTransport, chain, account, actions & BaseAlchemyActions<chain, account, context>, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccountClient.d.ts","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,8BAA8B,EACnC,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"smartAccountClient.d.ts","sourceRoot":"","sources":["../../../src/client/smartAccountClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,QAAQ,EACb,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,8BAA8B,EACnC,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAKhC,OAAO,EAEL,KAAK,gCAAgC,EACtC,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,wBAAgB,mBAAmB,CACjC,QAAQ,SAAS,8BAA8B,EAC/C,OAAO,EAAE,QAAQ;;EAElB;AAGD,MAAM,MAAM,+BAA+B,CACzC,KAAK,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,EACnD,OAAO,SAAS,oBAAoB,GAAG,SAAS,GAC5C,oBAAoB,GACpB,SAAS,EACb,OAAO,SAAS,oBAAoB,GAAG,SAAS,GAC5C,oBAAoB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,yBAAyB,CACnC,KAAK,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,EACnD,OAAO,SAAS,oBAAoB,GAAG,SAAS,GAC5C,oBAAoB,GACpB,SAAS,EACb,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjE,OAAO,SAAS,oBAAoB,GAAG,SAAS,GAC5C,oBAAoB,GACpB,SAAS,IACX,QAAQ,CAAC,8BAA8B,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/E,wBAAgB,+BAA+B,CAC7C,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,QAAQ,SAAS,oBAAoB,GAAG,SAAS,GAC7C,oBAAoB,GACpB,SAAS,EACb,QAAQ,SAAS,oBAAoB,GAAG,SAAS,GAC7C,oBAAoB,GACpB,SAAS,EAEb,MAAM,EAAE,+BAA+B,CAAC,MAAM,EAAE,QAAQ,EAAE,QAAQ,CAAC,GAClE,yBAAyB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export { getAlchemyPaymasterAddress } from "./gas-manager.js";
|
|
|
20
20
|
export { alchemyFeeEstimator } from "./middleware/feeEstimator.js";
|
|
21
21
|
export type * from "./middleware/gasManager.js";
|
|
22
22
|
export * from "./alchemyTrackerHeaders.js";
|
|
23
|
-
export { alchemyGasManagerMiddleware, alchemyGasAndPaymasterAndDataMiddleware, } from "./middleware/gasManager.js";
|
|
23
|
+
export { alchemyGasManagerMiddleware, alchemyGasAndPaymasterAndDataMiddleware, type PolicyToken, } from "./middleware/gasManager.js";
|
|
24
24
|
export { alchemyUserOperationSimulator } from "./middleware/userOperationSimulator.js";
|
|
25
25
|
export type * from "./schema.js";
|
|
26
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,2CAA2C,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,2CAA2C,CAAC;AACzF,mBAAmB,oBAAoB,CAAC;AACxC,mBAAmB,uBAAuB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACpE,mBAAmB,aAAa,CAAC;AACjC,OAAO,EACL,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,eAAe,EACf,IAAI,EACJ,UAAU,EACV,WAAW,EACX,kBAAkB,EAClB,OAAO,EACP,cAAc,EACd,MAAM,EACN,OAAO,EACP,QAAQ,EACR,cAAc,EACd,eAAe,EACf,OAAO,EACP,WAAW,EACX,aAAa,EACb,OAAO,EACP,KAAK,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,IAAI,EACJ,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,eAAe,EACf,eAAe,EACf,UAAU,EACV,UAAU,EACV,MAAM,EACN,YAAY,EACZ,eAAe,EACf,aAAa,EACb,WAAW,EACX,YAAY,EACZ,WAAW,EACX,aAAa,EACb,WAAW,EACX,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,mBAAmB,4CAA4C,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AACvF,mBAAmB,qCAAqC,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,mBAAmB,uBAAuB,CAAC;AAC3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,mBAAmB,gCAAgC,CAAC;AACpD,OAAO,EAAE,+BA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AC;AACvF,mBAAmB,qCAAqC,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,2BAA2B,EAAE,MAAM,yCAAyC,CAAC;AACtF,mBAAmB,uBAAuB,CAAC;AAC3C,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AACrE,mBAAmB,gCAAgC,CAAC;AACpD,OAAO,EAAE,+BAA+B,EAAE,MAAM,gCAAgC,CAAC;AACjF,mBAAmB,mBAAmB,CAAC;AACvC,OAAO,EAAE,iCAAiC,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,mBAAmB,4BAA4B,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,OAAO,EACL,2BAA2B,EAC3B,uCAAuC,EACvC,KAAK,WAAW,GACjB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,6BAA6B,EAAE,MAAM,wCAAwC,CAAC;AACvF,mBAAmB,aAAa,CAAC"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import type { Address, ClientMiddlewareConfig, ClientMiddlewareFn } from "@aa-sdk/core";
|
|
2
2
|
import type { AlchemyTransport } from "../alchemyTransport.js";
|
|
3
|
+
export type PolicyToken = {
|
|
4
|
+
address: Address;
|
|
5
|
+
maxTokenAmount: number;
|
|
6
|
+
paymasterAddress?: Address;
|
|
7
|
+
approvalMode?: "NONE" | "PERMIT";
|
|
8
|
+
erc20Name?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
};
|
|
3
11
|
/**
|
|
4
12
|
* Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring
|
|
5
13
|
* transactions. Adheres to the ERC-7677 standardized communication protocol.
|
|
@@ -28,14 +36,6 @@ interface AlchemyGasAndPaymasterAndDataMiddlewareParams {
|
|
|
28
36
|
gasEstimatorOverride?: ClientMiddlewareFn;
|
|
29
37
|
feeEstimatorOverride?: ClientMiddlewareFn;
|
|
30
38
|
}
|
|
31
|
-
export type PolicyToken = {
|
|
32
|
-
address: Address;
|
|
33
|
-
maxTokenAmount: bigint;
|
|
34
|
-
paymasterAddress?: Address;
|
|
35
|
-
approvalMode?: "NONE" | "PERMIT";
|
|
36
|
-
erc20Name?: string;
|
|
37
|
-
version?: string;
|
|
38
|
-
};
|
|
39
39
|
/**
|
|
40
40
|
* Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring
|
|
41
41
|
* transactions. Uses Alchemy's custom `alchemy_requestGasAndPaymasterAndData`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gasManager.d.ts","sourceRoot":"","sources":["../../../src/middleware/gasManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,sBAAsB,EACtB,kBAAkB,EAOnB,MAAM,cAAc,CAAC;AAuBtB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"gasManager.d.ts","sourceRoot":"","sources":["../../../src/middleware/gasManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,sBAAsB,EACtB,kBAAkB,EAOnB,MAAM,cAAc,CAAC;AAuBtB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAsB/D,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,cAAc,EAAE,MAAM,CAAC;IACvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,EAC3B,WAAW,CAAC,EAAE,WAAW,GACxB,QAAQ,CACT,IAAI,CAAC,sBAAsB,EAAE,uBAAuB,GAAG,kBAAkB,CAAC,CAC3E,CAyCA;AAED,UAAU,6CAA6C;IACrD,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC5B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,SAAS,EAAE,gBAAgB,CAAC;IAC5B,oBAAoB,CAAC,EAAE,kBAAkB,CAAC;IAC1C,oBAAoB,CAAC,EAAE,kBAAkB,CAAC;CAC3C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,uCAAuC,CACrD,MAAM,EAAE,6CAA6C,GACpD,IAAI,CACL,sBAAsB,EACtB,uBAAuB,GAAG,cAAc,GAAG,cAAc,GAAG,kBAAkB,CAC/E,CA4IA"}
|
package/dist/types/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "4.
|
|
1
|
+
export declare const VERSION = "4.47.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@account-kit/infra",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.47.0",
|
|
4
4
|
"description": "adapters for @aa-sdk/core for interacting with alchemy services",
|
|
5
5
|
"author": "Alchemy",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"typescript-template": "*"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@aa-sdk/core": "^4.
|
|
47
|
-
"@account-kit/logging": "^4.
|
|
46
|
+
"@aa-sdk/core": "^4.47.0",
|
|
47
|
+
"@account-kit/logging": "^4.47.0",
|
|
48
48
|
"eventemitter3": "^5.0.1",
|
|
49
49
|
"zod": "^3.22.4"
|
|
50
50
|
},
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
64
64
|
},
|
|
65
65
|
"homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
|
|
66
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "7c729a1a6f4591d330c6ff8126441b0a23ae6a1a",
|
|
67
67
|
"optionalDependencies": {
|
|
68
68
|
"alchemy-sdk": "^3.0.0"
|
|
69
69
|
}
|
package/src/actions/types.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
type SmartContractAccountWithSigner,
|
|
13
13
|
type UserOperationContext,
|
|
14
14
|
} from "@aa-sdk/core";
|
|
15
|
-
import { type
|
|
15
|
+
import { type Chain } from "viem";
|
|
16
16
|
import {
|
|
17
17
|
alchemy,
|
|
18
18
|
convertHeadersToObject,
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from "./decorators/smartAccount.js";
|
|
29
29
|
import type { AlchemyRpcSchema } from "./types.js";
|
|
30
30
|
import { headersUpdate } from "../alchemyTrackerHeaders.js";
|
|
31
|
+
import type { PolicyToken } from "../middleware/gasManager.js";
|
|
31
32
|
|
|
32
33
|
export function getSignerTypeHeader<
|
|
33
34
|
TAccount extends SmartContractAccountWithSigner,
|
|
@@ -48,13 +49,7 @@ export type AlchemySmartAccountClientConfig<
|
|
|
48
49
|
account?: account;
|
|
49
50
|
useSimulation?: boolean;
|
|
50
51
|
policyId?: string | string[];
|
|
51
|
-
policyToken?:
|
|
52
|
-
address: Address;
|
|
53
|
-
maxTokenAmount: bigint;
|
|
54
|
-
approvalMode?: "NONE" | "PERMIT";
|
|
55
|
-
erc20Name?: string;
|
|
56
|
-
version?: string;
|
|
57
|
-
};
|
|
52
|
+
policyToken?: PolicyToken;
|
|
58
53
|
} & Pick<
|
|
59
54
|
SmartAccountClientConfig<AlchemyTransport, chain, account, context>,
|
|
60
55
|
| "customMiddleware"
|
package/src/index.ts
CHANGED
|
@@ -68,6 +68,7 @@ export * from "./alchemyTrackerHeaders.js";
|
|
|
68
68
|
export {
|
|
69
69
|
alchemyGasManagerMiddleware,
|
|
70
70
|
alchemyGasAndPaymasterAndDataMiddleware,
|
|
71
|
+
type PolicyToken,
|
|
71
72
|
} from "./middleware/gasManager.js";
|
|
72
73
|
export { alchemyUserOperationSimulator } from "./middleware/userOperationSimulator.js";
|
|
73
74
|
export type * from "./schema.js";
|
|
@@ -34,6 +34,7 @@ import type { AlchemySmartAccountClient } from "../client/smartAccountClient.js"
|
|
|
34
34
|
import type { AlchemyTransport } from "../alchemyTransport.js";
|
|
35
35
|
import { alchemyFeeEstimator } from "./feeEstimator.js";
|
|
36
36
|
import type { RequestGasAndPaymasterAndDataRequest } from "../actions/types.js";
|
|
37
|
+
|
|
37
38
|
import {
|
|
38
39
|
PermitTypes,
|
|
39
40
|
EIP7597Abis,
|
|
@@ -47,10 +48,20 @@ type Context = {
|
|
|
47
48
|
policyId: string | string[];
|
|
48
49
|
erc20Context?: {
|
|
49
50
|
tokenAddress: Address;
|
|
50
|
-
maxTokenAmount?:
|
|
51
|
+
maxTokenAmount?: number;
|
|
51
52
|
permit?: Hex;
|
|
52
53
|
};
|
|
53
54
|
};
|
|
55
|
+
|
|
56
|
+
export type PolicyToken = {
|
|
57
|
+
address: Address;
|
|
58
|
+
maxTokenAmount: number;
|
|
59
|
+
paymasterAddress?: Address;
|
|
60
|
+
approvalMode?: "NONE" | "PERMIT";
|
|
61
|
+
erc20Name?: string;
|
|
62
|
+
version?: string;
|
|
63
|
+
};
|
|
64
|
+
|
|
54
65
|
/**
|
|
55
66
|
* Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring
|
|
56
67
|
* transactions. Adheres to the ERC-7677 standardized communication protocol.
|
|
@@ -127,15 +138,6 @@ interface AlchemyGasAndPaymasterAndDataMiddlewareParams {
|
|
|
127
138
|
feeEstimatorOverride?: ClientMiddlewareFn;
|
|
128
139
|
}
|
|
129
140
|
|
|
130
|
-
export type PolicyToken = {
|
|
131
|
-
address: Address;
|
|
132
|
-
maxTokenAmount: bigint;
|
|
133
|
-
paymasterAddress?: Address;
|
|
134
|
-
approvalMode?: "NONE" | "PERMIT";
|
|
135
|
-
erc20Name?: string;
|
|
136
|
-
version?: string;
|
|
137
|
-
};
|
|
138
|
-
|
|
139
141
|
/**
|
|
140
142
|
* Paymaster middleware factory that uses Alchemy's Gas Manager for sponsoring
|
|
141
143
|
* transactions. Uses Alchemy's custom `alchemy_requestGasAndPaymasterAndData`
|
|
@@ -379,7 +381,7 @@ const generateSignedPermit = async <TAccount extends SmartContractAccount>(
|
|
|
379
381
|
account: TAccount,
|
|
380
382
|
policyToken: {
|
|
381
383
|
address: Address;
|
|
382
|
-
maxTokenAmount:
|
|
384
|
+
maxTokenAmount: number;
|
|
383
385
|
paymasterAddress?: Address;
|
|
384
386
|
approvalMode?: "NONE" | "PERMIT";
|
|
385
387
|
erc20Name?: string;
|
|
@@ -423,8 +425,8 @@ const generateSignedPermit = async <TAccount extends SmartContractAccount>(
|
|
|
423
425
|
}
|
|
424
426
|
|
|
425
427
|
const decimals =
|
|
426
|
-
|
|
427
|
-
const
|
|
428
|
+
10 ** (decimalsResponse.data ? Number(decimalsResponse.data) : 18);
|
|
429
|
+
const maxRawAmountToken = BigInt(policyToken.maxTokenAmount * decimals);
|
|
428
430
|
const nonce = BigInt(nonceResponse.data);
|
|
429
431
|
|
|
430
432
|
const paymasterAddress =
|
|
@@ -449,7 +451,7 @@ const generateSignedPermit = async <TAccount extends SmartContractAccount>(
|
|
|
449
451
|
message: {
|
|
450
452
|
owner: account.address,
|
|
451
453
|
spender: paymasterAddress,
|
|
452
|
-
value:
|
|
454
|
+
value: maxRawAmountToken,
|
|
453
455
|
nonce: nonce,
|
|
454
456
|
deadline,
|
|
455
457
|
} satisfies PermitMessage,
|
|
@@ -458,6 +460,6 @@ const generateSignedPermit = async <TAccount extends SmartContractAccount>(
|
|
|
458
460
|
const signedPermit = await account.signTypedData(typedPermitData);
|
|
459
461
|
return encodeAbiParameters(
|
|
460
462
|
[{ type: "uint256" }, { type: "uint256" }, { type: "bytes" }],
|
|
461
|
-
[
|
|
463
|
+
[maxRawAmountToken, deadline, signedPermit],
|
|
462
464
|
);
|
|
463
465
|
};
|
package/src/version.ts
CHANGED