@account-kit/infra 4.0.0-alpha.0 → 4.0.0-alpha.10
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/cjs/actions/simulateUserOperationChanges.js.map +1 -1
- package/dist/cjs/chains.d.ts +25 -0
- package/dist/cjs/chains.js +200 -1
- package/dist/cjs/chains.js.map +1 -1
- package/dist/cjs/client/decorators/alchemyEnhancedApis.d.ts +5393 -1
- package/dist/cjs/client/decorators/alchemyEnhancedApis.js.map +1 -1
- package/dist/cjs/client/decorators/smartAccount.js.map +1 -1
- package/dist/cjs/client/internal/smartAccountClientFromRpc.d.ts +2 -2
- package/dist/cjs/client/internal/smartAccountClientFromRpc.js +3 -14
- package/dist/cjs/client/internal/smartAccountClientFromRpc.js.map +1 -1
- package/dist/cjs/client/isAlchemySmartAccountClient.d.ts +1173 -1317
- package/dist/cjs/client/isAlchemySmartAccountClient.js.map +1 -1
- package/dist/cjs/client/rpcClient.js.map +1 -1
- package/dist/cjs/client/smartAccountClient.d.ts +2 -3
- package/dist/cjs/client/smartAccountClient.js +2 -2
- package/dist/cjs/client/smartAccountClient.js.map +1 -1
- package/dist/cjs/client/types.d.ts +1 -48
- package/dist/cjs/client/types.js.map +1 -1
- package/dist/cjs/defaults.js +7 -7
- package/dist/cjs/defaults.js.map +1 -1
- package/dist/cjs/gas-manager.js +16 -16
- package/dist/cjs/gas-manager.js.map +1 -1
- package/dist/cjs/index.d.ts +2 -1
- package/dist/cjs/index.js +22 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/middleware/feeEstimator.js.map +1 -1
- package/dist/cjs/middleware/gasManager.d.ts +2 -29
- package/dist/cjs/middleware/gasManager.js +4 -141
- package/dist/cjs/middleware/gasManager.js.map +1 -1
- package/dist/cjs/middleware/userOperationSimulator.d.ts +2 -2
- package/dist/cjs/middleware/userOperationSimulator.js.map +1 -1
- package/dist/cjs/schema.js +3 -10
- package/dist/cjs/schema.js.map +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/esm/actions/simulateUserOperationChanges.js.map +1 -1
- package/dist/esm/chains.d.ts +25 -0
- package/dist/esm/chains.js +199 -0
- package/dist/esm/chains.js.map +1 -1
- package/dist/esm/client/decorators/alchemyEnhancedApis.d.ts +5393 -1
- package/dist/esm/client/decorators/alchemyEnhancedApis.js.map +1 -1
- package/dist/esm/client/decorators/smartAccount.js.map +1 -1
- package/dist/esm/client/internal/smartAccountClientFromRpc.d.ts +2 -2
- package/dist/esm/client/internal/smartAccountClientFromRpc.js +3 -14
- package/dist/esm/client/internal/smartAccountClientFromRpc.js.map +1 -1
- package/dist/esm/client/isAlchemySmartAccountClient.d.ts +1173 -1317
- package/dist/esm/client/isAlchemySmartAccountClient.js.map +1 -1
- package/dist/esm/client/rpcClient.js.map +1 -1
- package/dist/esm/client/smartAccountClient.d.ts +2 -3
- package/dist/esm/client/smartAccountClient.js +2 -3
- package/dist/esm/client/smartAccountClient.js.map +1 -1
- package/dist/esm/client/types.d.ts +1 -48
- package/dist/esm/client/types.js.map +1 -1
- package/dist/esm/defaults.js +2 -1
- package/dist/esm/defaults.js.map +1 -1
- package/dist/esm/gas-manager.js +1 -1
- package/dist/esm/gas-manager.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/middleware/feeEstimator.js.map +1 -1
- package/dist/esm/middleware/gasManager.d.ts +2 -29
- package/dist/esm/middleware/gasManager.js +5 -142
- package/dist/esm/middleware/gasManager.js.map +1 -1
- package/dist/esm/middleware/userOperationSimulator.d.ts +2 -2
- package/dist/esm/middleware/userOperationSimulator.js.map +1 -1
- package/dist/esm/schema.js +4 -11
- package/dist/esm/schema.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/simulateUserOperationChanges.d.ts +17 -0
- package/dist/types/actions/simulateUserOperationChanges.d.ts.map +1 -1
- package/dist/types/chains.d.ts +44 -0
- package/dist/types/chains.d.ts.map +1 -1
- package/dist/types/client/decorators/alchemyEnhancedApis.d.ts +5410 -1
- package/dist/types/client/decorators/alchemyEnhancedApis.d.ts.map +1 -1
- package/dist/types/client/decorators/smartAccount.d.ts +15 -0
- package/dist/types/client/decorators/smartAccount.d.ts.map +1 -1
- package/dist/types/client/internal/smartAccountClientFromRpc.d.ts +4 -4
- package/dist/types/client/internal/smartAccountClientFromRpc.d.ts.map +1 -1
- package/dist/types/client/isAlchemySmartAccountClient.d.ts +1188 -1317
- package/dist/types/client/isAlchemySmartAccountClient.d.ts.map +1 -1
- package/dist/types/client/rpcClient.d.ts +22 -0
- package/dist/types/client/rpcClient.d.ts.map +1 -1
- package/dist/types/client/smartAccountClient.d.ts +2 -3
- package/dist/types/client/smartAccountClient.d.ts.map +1 -1
- package/dist/types/client/types.d.ts +1 -48
- package/dist/types/client/types.d.ts.map +1 -1
- package/dist/types/defaults.d.ts +14 -0
- package/dist/types/defaults.d.ts.map +1 -1
- package/dist/types/gas-manager.d.ts +13 -0
- package/dist/types/gas-manager.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/middleware/feeEstimator.d.ts +19 -0
- package/dist/types/middleware/feeEstimator.d.ts.map +1 -1
- package/dist/types/middleware/gasManager.d.ts +15 -87
- package/dist/types/middleware/gasManager.d.ts.map +1 -1
- package/dist/types/middleware/userOperationSimulator.d.ts +21 -2
- package/dist/types/middleware/userOperationSimulator.d.ts.map +1 -1
- package/dist/types/schema.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/actions/simulateUserOperationChanges.ts +17 -0
- package/src/chains.ts +255 -0
- package/src/client/decorators/alchemyEnhancedApis.ts +50 -33
- package/src/client/decorators/smartAccount.ts +15 -0
- package/src/client/internal/smartAccountClientFromRpc.ts +36 -32
- package/src/client/isAlchemySmartAccountClient.ts +15 -0
- package/src/client/rpcClient.ts +22 -0
- package/src/client/smartAccountClient.ts +21 -5
- package/src/client/types.ts +1 -54
- package/src/defaults.ts +17 -3
- package/src/gas-manager.ts +17 -4
- package/src/index.ts +25 -1
- package/src/middleware/feeEstimator.ts +19 -0
- package/src/middleware/gasManager.ts +21 -424
- package/src/middleware/userOperationSimulator.ts +25 -2
- package/src/schema.ts +3 -11
- package/src/version.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"alchemyEnhancedApis.js","sourceRoot":"","sources":["../../../../src/client/decorators/alchemyEnhancedApis.ts"],"names":[],"mappings":";;;AAGA,+CAAyD;
|
|
1
|
+
{"version":3,"file":"alchemyEnhancedApis.js","sourceRoot":"","sources":["../../../../src/client/decorators/alchemyEnhancedApis.ts"],"names":[],"mappings":";;;AAGA,+CAAyD;AA8BlD,MAAM,yBAAyB,GACpC,CAAC,OAAgB,EAAE,EAAE,CACrB,CAOE,MAA+D,EAC1C,EAAE;IACvB,MAAM,UAAU,GAAG,kCAAsB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAEzD,IAAI,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QACrC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC,SACa,CAAC;QAErC,IACE,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,MAAM;YAChC,OAAO,CAAC,MAAM,CAAC,GAAG;YAClB,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,GAAG,EAC1B,CAAC;YACD,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO;QACL,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,GAAG,EAAE,UAAU,CAAC,GAAG;QACnB,QAAQ,EAAE,UAAU,CAAC,QAAQ;QAC7B,KAAK,EAAE,UAAU,CAAC,KAAK;QACvB,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,MAAM,EAAE,UAAU,CAAC,MAAM;QACzB,MAAM,EAAE,UAAU,CAAC,MAAM;KAC1B,CAAC;AACJ,CAAC,CAAC;AArCS,QAAA,yBAAyB,6BAqClC","sourcesContent":["import type { SmartContractAccount } from \"@aa-sdk/core\";\nimport type { Alchemy } from \"alchemy-sdk\";\nimport type { Chain, HttpTransport, Transport } from \"viem\";\nimport { AlchemySdkClientSchema } from \"../../schema.js\";\nimport type { AlchemySmartAccountClient } from \"../smartAccountClient.js\";\n\nexport type AlchemyEnhancedApis = {\n core: Alchemy[\"core\"];\n nft: Alchemy[\"nft\"];\n transact: Alchemy[\"transact\"];\n debug: Alchemy[\"debug\"];\n ws: Alchemy[\"ws\"];\n notify: Alchemy[\"notify\"];\n config: Alchemy[\"config\"];\n};\n\n/**\n * Given an instance of the Alchemy SDK, returns a smart account client decorator which contains actions for interacting Alchemy's enhanced APIs.\n *\n * @example\n * ```ts\n * import { Alchemy } from \"alchemy-sdk\";\n * import { alchemyEnhancedApiActions } from \"@account-kit/infra\";\n * import { alchemySCAClient } from \"./client\";\n *\n * const alchemy = new Alchemy(...);\n * const enhancedApiDecorator = alchemyEnhancedApiActions(alchemy);\n * const withEnhancedApis = alchemySCAClient.extend(enhancedApiDecorator);\n * ```\n *\n * @param {Alchemy} alchemy The Alchemy instance containing the SDK client\n * @returns {(client: AlchemySmartAccountClient) => AlchemyEnhancedApis} A client decorator for Alchemy Smart Account clients that adds the enhanced API methods\n */\nexport const alchemyEnhancedApiActions =\n (alchemy: Alchemy) =>\n <\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n >(\n client: AlchemySmartAccountClient<TTransport, TChain, TAccount>\n ): AlchemyEnhancedApis => {\n const alchemySdk = AlchemySdkClientSchema.parse(alchemy);\n\n if (client.transport.type === \"http\") {\n const { url } = client.transport as ReturnType<HttpTransport>[\"config\"] &\n ReturnType<HttpTransport>[\"value\"];\n\n if (\n client.transport.type === \"http\" &&\n alchemy.config.url &&\n alchemy.config.url !== url\n ) {\n throw new Error(\n \"Alchemy SDK client JSON-RPC URL must match AlchemyProvider JSON-RPC URL\"\n );\n }\n }\n\n return {\n core: alchemySdk.core,\n nft: alchemySdk.nft,\n transact: alchemySdk.transact,\n debug: alchemySdk.debug,\n ws: alchemySdk.ws,\n notify: alchemySdk.notify,\n config: alchemySdk.config,\n };\n };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccount.js","sourceRoot":"","sources":["../../../../src/client/decorators/smartAccount.ts"],"names":[],"mappings":";;;AAMA,mGAA6F;
|
|
1
|
+
{"version":3,"file":"smartAccount.js","sourceRoot":"","sources":["../../../../src/client/decorators/smartAccount.ts"],"names":[],"mappings":";;;AAMA,mGAA6F;AA+BtF,MAAM,cAAc,GAWiC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACvE,qBAAqB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACpC,IAAA,8DAA4B,EAAC,MAAM,EAAE,IAAI,CAAC;CAC7C,CAAC,CAAC;AAdU,QAAA,cAAc,kBAcxB","sourcesContent":["import type {\n SendUserOperationParameters,\n SmartContractAccount,\n UserOperationContext,\n} from \"@aa-sdk/core\";\nimport type { Chain, Client, Transport } from \"viem\";\nimport { simulateUserOperationChanges } from \"../../actions/simulateUserOperationChanges.js\";\nimport type { SimulateUserOperationAssetChangesResponse } from \"../../actions/types.js\";\n\nexport type AlchemySmartAccountClientActions<\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = {\n simulateUserOperation: (\n args: SendUserOperationParameters<TAccount, TContext>\n ) => Promise<SimulateUserOperationAssetChangesResponse>;\n};\n\n/**\n * Provides a set of actions for interacting with the Alchemy Smart Account client, including the ability to simulate user operations.\n *\n * @example\n * ```ts\n * import { alchemyActions } from \"@account-kit/infra\";\n * import { createPublicClient } from \"viem\";\n *\n * const client = createPublicClient(...);\n * const clientWithAlchemyActions = client.extend(alchemyActions);\n * ```\n *\n * @param {Client<TTransport, TChain, TAccount>} client The client instance used to perform actions\n * @returns {AlchemySmartAccountClientActions<TAccount, TContext>} An object containing Alchemy Smart Account client actions\n */\nexport const alchemyActions: <\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n>(\n client: Client<TTransport, TChain, TAccount>\n) => AlchemySmartAccountClientActions<TAccount, TContext> = (client) => ({\n simulateUserOperation: async (args) =>\n simulateUserOperationChanges(client, args),\n});\n"]}
|
|
@@ -2,10 +2,10 @@ import { type SmartContractAccount, type SmartContractAccountWithSigner, type Us
|
|
|
2
2
|
import type { Chain, CustomTransport, Transport } from "viem";
|
|
3
3
|
import type { AlchemySmartAccountClient, AlchemySmartAccountClientConfig } from "../smartAccountClient.js";
|
|
4
4
|
import type { ClientWithAlchemyMethods } from "../types.js";
|
|
5
|
-
export type
|
|
5
|
+
export type CreateAlchemySmartAccountClientFromRpcClientParams<TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = UserOperationContext | undefined> = Omit<AlchemySmartAccountClientConfig<Transport, Chain, TAccount, TContext>, "rpcUrl" | "chain" | "apiKey" | "jwt"> & {
|
|
6
6
|
client: ClientWithAlchemyMethods;
|
|
7
7
|
};
|
|
8
8
|
export declare function getSignerTypeHeader<TAccount extends SmartContractAccountWithSigner>(account: TAccount): {
|
|
9
9
|
"Alchemy-Aa-Sdk-Signer": string;
|
|
10
10
|
};
|
|
11
|
-
export declare function createAlchemySmartAccountClientFromRpcClient<TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = UserOperationContext | undefined>(args:
|
|
11
|
+
export declare function createAlchemySmartAccountClientFromRpcClient<TChain extends Chain | undefined = Chain | undefined, TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined, TContext extends UserOperationContext | undefined = UserOperationContext | undefined>(args: CreateAlchemySmartAccountClientFromRpcClientParams<TAccount, TContext>): AlchemySmartAccountClient<CustomTransport, TChain, TAccount, Record<string, never>, TContext>;
|
|
@@ -10,7 +10,8 @@ function getSignerTypeHeader(account) {
|
|
|
10
10
|
return { "Alchemy-Aa-Sdk-Signer": account.getSigner().signerType };
|
|
11
11
|
}
|
|
12
12
|
exports.getSignerTypeHeader = getSignerTypeHeader;
|
|
13
|
-
function createAlchemySmartAccountClientFromRpcClient(
|
|
13
|
+
function createAlchemySmartAccountClientFromRpcClient(args) {
|
|
14
|
+
const { opts, account, useSimulation, policyId, feeEstimator, gasEstimator, customMiddleware, signUserOperation, client, } = args;
|
|
14
15
|
const feeOptions = opts?.feeOptions ?? (0, core_1.getDefaultUserOperationFeeOptions)(client.chain);
|
|
15
16
|
const scaClient = (0, core_1.createSmartAccountClientFromExisting)({
|
|
16
17
|
account,
|
|
@@ -31,19 +32,7 @@ function createAlchemySmartAccountClientFromRpcClient({ opts, account, useSimula
|
|
|
31
32
|
? (0, userOperationSimulator_js_1.alchemyUserOperationSimulator)(client)
|
|
32
33
|
: undefined,
|
|
33
34
|
gasEstimator,
|
|
34
|
-
...(
|
|
35
|
-
(0, gasManager_js_1.alchemyGasManagerMiddleware)(client, {
|
|
36
|
-
...gasManagerConfig,
|
|
37
|
-
gasEstimationOptions: {
|
|
38
|
-
...gasManagerConfig.gasEstimationOptions,
|
|
39
|
-
disableGasEstimation: gasManagerConfig.gasEstimationOptions?.disableGasEstimation ??
|
|
40
|
-
false,
|
|
41
|
-
fallbackFeeDataGetter: gasManagerConfig.gasEstimationOptions?.fallbackFeeDataGetter ??
|
|
42
|
-
feeEstimator,
|
|
43
|
-
fallbackGasEstimator: gasManagerConfig.gasEstimationOptions?.fallbackGasEstimator ??
|
|
44
|
-
gasEstimator,
|
|
45
|
-
},
|
|
46
|
-
})),
|
|
35
|
+
...(policyId && (0, gasManager_js_1.alchemyGasManagerMiddleware)(policyId)),
|
|
47
36
|
signUserOperation,
|
|
48
37
|
}).extend(smartAccount_js_1.alchemyActions);
|
|
49
38
|
if (account && (0, core_1.isSmartAccountWithSigner)(account)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smartAccountClientFromRpc.js","sourceRoot":"","sources":["../../../../src/client/internal/smartAccountClientFromRpc.ts"],"names":[],"mappings":";;;AAAA,uCAOsB;AAEtB,sEAAuE;AACvE,kEAA6E;AAC7E,0FAA2F;AAC3F,mEAA+D;AAmB/D,SAAgB,mBAAmB,CAEjC,OAAiB;IACjB,OAAO,EAAE,uBAAuB,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,UAAU,EAAE,CAAC;AACrE,CAAC;AAJD,kDAIC;
|
|
1
|
+
{"version":3,"file":"smartAccountClientFromRpc.js","sourceRoot":"","sources":["../../../../src/client/internal/smartAccountClientFromRpc.ts"],"names":[],"mappings":";;;AAAA,uCAOsB;AAEtB,sEAAuE;AACvE,kEAA6E;AAC7E,0FAA2F;AAC3F,mEAA+D;AAmB/D,SAAgB,mBAAmB,CAEjC,OAAiB;IACjB,OAAO,EAAE,uBAAuB,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,UAAU,EAAE,CAAC;AACrE,CAAC;AAJD,kDAIC;AA4CD,SAAgB,4CAA4C,CAC1D,IAAwD;IAExD,MAAM,EACJ,IAAI,EACJ,OAAO,EACP,aAAa,EACb,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,MAAM,GACP,GAAG,IAAI,CAAC;IACT,MAAM,UAAU,GACd,IAAI,EAAE,UAAU,IAAI,IAAA,wCAAiC,EAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEtE,MAAM,SAAS,GAAG,IAAA,2CAAoC,EAAC;QACrD,OAAO;QACP,MAAM;QACN,IAAI,EAAE,2BAA2B;QACjC,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,UAAU;SACX;QACD,gBAAgB,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE;YACvC,IAAI,IAAA,+BAAwB,EAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC3C,MAAM,CAAC,aAAa,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;YAC1D,CAAC;YACD,OAAO,gBAAgB,CAAC,CAAC,CAAC,gBAAgB,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;QACpE,CAAC;QACD,YAAY,EAAE,YAAY,IAAI,IAAA,qCAAmB,EAAC,MAAM,CAAC;QACzD,sBAAsB,EAAE,aAAa;YACnC,CAAC,CAAC,IAAA,yDAA6B,EAAC,MAAM,CAAC;YACvC,CAAC,CAAC,SAAS;QACb,YAAY;QACZ,GAAG,CAAC,QAAQ,IAAI,IAAA,2CAA2B,EAAC,QAAQ,CAAC,CAAC;QACtD,iBAAiB;KAClB,CAAC,CAAC,MAAM,CAAC,gCAAc,CAAC,CAAC;IAE1B,IAAI,OAAO,IAAI,IAAA,+BAAwB,EAAC,OAAO,CAAC,EAAE,CAAC;QACjD,MAAM,CAAC,aAAa,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;IACrD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AA7CD,oGA6CC","sourcesContent":["import {\n createSmartAccountClientFromExisting,\n getDefaultUserOperationFeeOptions,\n isSmartAccountWithSigner,\n type SmartContractAccount,\n type SmartContractAccountWithSigner,\n type UserOperationContext,\n} from \"@aa-sdk/core\";\nimport type { Chain, CustomTransport, Transport } from \"viem\";\nimport { alchemyFeeEstimator } from \"../../middleware/feeEstimator.js\";\nimport { alchemyGasManagerMiddleware } from \"../../middleware/gasManager.js\";\nimport { alchemyUserOperationSimulator } from \"../../middleware/userOperationSimulator.js\";\nimport { alchemyActions } from \"../decorators/smartAccount.js\";\nimport type {\n AlchemySmartAccountClient,\n AlchemySmartAccountClientConfig,\n} from \"../smartAccountClient.js\";\nimport type { ClientWithAlchemyMethods } from \"../types.js\";\n\nexport type CreateAlchemySmartAccountClientFromRpcClientParams<\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n> = Omit<\n AlchemySmartAccountClientConfig<Transport, Chain, TAccount, TContext>,\n \"rpcUrl\" | \"chain\" | \"apiKey\" | \"jwt\"\n> & { client: ClientWithAlchemyMethods };\n\nexport function getSignerTypeHeader<\n TAccount extends SmartContractAccountWithSigner\n>(account: TAccount) {\n return { \"Alchemy-Aa-Sdk-Signer\": account.getSigner().signerType };\n}\n\n/**\n * Helper method meant to be used internally to create an alchemy smart account client\n * from an existing Alchemy Rpc Client\n *\n * @param {CreateAlchemySmartAccountClientFromRpcClientParams<TAccount, TContext>} args configuration for the client\n * @returns {AlchemySmartAccountClient} a smart account client configured to use Alchemy's RPC\n */\nexport function createAlchemySmartAccountClientFromRpcClient<\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined\n>(\n args: CreateAlchemySmartAccountClientFromRpcClientParams<TAccount, TContext>\n): AlchemySmartAccountClient<\n CustomTransport,\n TChain,\n TAccount,\n Record<string, never>,\n TContext\n>;\n\n/**\n * Creates an AlchemySmartAccountClient using the provided RPC client configuration, including options, account, simulation settings, gas management, fee estimation, middleware and user operation signing.\n *\n * @example\n * ```ts\n * import { createAlchemySmartAccountClientFromRpcClient, createAlchemyPublicRpcClient } from \"@account-kit/infra\";\n *\n * const client = createAlchemyPublicRpcClient(...);\n * const scaClient = createAlchemySmartAccountClientFromRpcClient({\n * client,\n * ...\n * });\n * ```\n *\n * @param {CreateAlchemySmartAccountClientFromRpcClientParams} args The configuration object containing all required parameters\n * @returns {AlchemySmartAccountClient} An instance of AlchemySmartAccountClient\n */\nexport function createAlchemySmartAccountClientFromRpcClient(\n args: CreateAlchemySmartAccountClientFromRpcClientParams\n): AlchemySmartAccountClient {\n const {\n opts,\n account,\n useSimulation,\n policyId,\n feeEstimator,\n gasEstimator,\n customMiddleware,\n signUserOperation,\n client,\n } = args;\n const feeOptions =\n opts?.feeOptions ?? getDefaultUserOperationFeeOptions(client.chain);\n\n const scaClient = createSmartAccountClientFromExisting({\n account,\n client,\n type: \"AlchemySmartAccountClient\",\n opts: {\n ...opts,\n feeOptions,\n },\n customMiddleware: async (struct, args) => {\n if (isSmartAccountWithSigner(args.account)) {\n client.updateHeaders(getSignerTypeHeader(args.account));\n }\n return customMiddleware ? customMiddleware(struct, args) : struct;\n },\n feeEstimator: feeEstimator ?? alchemyFeeEstimator(client),\n userOperationSimulator: useSimulation\n ? alchemyUserOperationSimulator(client)\n : undefined,\n gasEstimator,\n ...(policyId && alchemyGasManagerMiddleware(policyId)),\n signUserOperation,\n }).extend(alchemyActions);\n\n if (account && isSmartAccountWithSigner(account)) {\n client.updateHeaders(getSignerTypeHeader(account));\n }\n\n return scaClient;\n}\n"]}
|