@mentaproject/core 0.5.15 → 0.6.1

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.
@@ -5937,6 +5937,64 @@ const getValidatorAddress = (entryPoint, kernelVersion, validatorContractVersion
5937
5937
  return validatorAddress ?? passKeyValidatorAddress ?? zeroAddress;
5938
5938
  };
5939
5939
 
5940
+ /**
5941
+ * RPC methods that should be routed to the bundler.
5942
+ * All other methods will be routed to the public RPC.
5943
+ */
5944
+ const BUNDLER_METHODS = new Set([
5945
+ // ERC-4337 standard methods
5946
+ "eth_sendUserOperation",
5947
+ "eth_estimateUserOperationGas",
5948
+ "eth_getUserOperationByHash",
5949
+ "eth_getUserOperationReceipt",
5950
+ "eth_supportedEntryPoints",
5951
+ // Pimlico-specific methods
5952
+ "pimlico_getUserOperationGasPrice",
5953
+ "pimlico_getUserOperationStatus",
5954
+ "pimlico_sendCompressedUserOperation",
5955
+ // pm_ paymaster methods (used by some bundlers)
5956
+ "pm_getPaymasterData",
5957
+ "pm_getPaymasterStubData",
5958
+ "pm_sponsorUserOperation",
5959
+ "pm_validateSponsorshipPolicies",
5960
+ ]);
5961
+ /**
5962
+ * Creates a transport that routes requests between a public RPC and a bundler RPC.
5963
+ *
5964
+ * Bundler-specific methods (ERC-4337) are routed to the bundler transport,
5965
+ * while all other methods (eth_getBlockByNumber, eth_call, etc.) are routed
5966
+ * to the public transport.
5967
+ *
5968
+ * @param publicTransport - Transport for standard Ethereum RPC calls
5969
+ * @param bundlerTransport - Transport for ERC-4337 bundler calls
5970
+ * @returns A unified transport that routes requests appropriately
5971
+ *
5972
+ * @example
5973
+ * import { http } from 'viem';
5974
+ * import { createRoutedTransport } from '@mentaproject/core/utils';
5975
+ *
5976
+ * const transport = createRoutedTransport(
5977
+ * http('https://eth-mainnet.g.alchemy.com/v2/...'),
5978
+ * http('https://api.pimlico.io/v2/1/rpc?apikey=...')
5979
+ * );
5980
+ */
5981
+ function createRoutedTransport(publicTransport, bundlerTransport) {
5982
+ return (params) => {
5983
+ const publicClient = publicTransport(params);
5984
+ const bundlerClient = bundlerTransport(params);
5985
+ const request = async ({ method, params: reqParams }) => {
5986
+ if (BUNDLER_METHODS.has(method)) {
5987
+ return bundlerClient.request({ method, params: reqParams });
5988
+ }
5989
+ return publicClient.request({ method, params: reqParams });
5990
+ };
5991
+ return {
5992
+ ...publicClient,
5993
+ request,
5994
+ };
5995
+ };
5996
+ }
5997
+
5940
5998
  async function createMentaAccount(client, params) {
5941
5999
  const validator = await toPasskeyValidator(client, {
5942
6000
  webAuthnKey: params.signer,
@@ -5951,9 +6009,12 @@ async function createMentaAccount(client, params) {
5951
6009
  owners: [validator],
5952
6010
  client: client,
5953
6011
  });
6012
+ // Create a routed transport that sends bundler methods to the bundler
6013
+ // and all other RPC calls to the public transport
6014
+ const routedTransport = createRoutedTransport(params.publicTransport, params.bundlerTransport);
5954
6015
  return createSmartAccountClient({
5955
6016
  account: kernel,
5956
- bundlerTransport: params.bundlerTransport,
6017
+ bundlerTransport: routedTransport,
5957
6018
  }).extend(erc7579Actions());
5958
6019
  }
5959
6020