permissionless 0.2.49 → 0.2.50

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # permissionless
2
2
 
3
+ ## 0.2.50
4
+
5
+ ### Patch Changes
6
+
7
+ - ba0e2bd161d5ee4bbd975a28f9f36ff520aca8f7: Added estimateErc20PaymasterCost
8
+
3
9
  ## 0.2.49
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -71,7 +71,7 @@ const account = toSimpleSmartAccount<entryPointVersion>({
71
71
  // Create the required clients.
72
72
  const bundlerClient = createSmartAccountClient({
73
73
  account,
74
- paymaster:
74
+ paymaster,
75
75
  chain: sepolia,
76
76
  bundlerTransport: http(
77
77
  `https://api.pimlico.io/v2/sepolia/rpc?apikey=${pimlicoApiKey}`,
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.estimateErc20PaymasterCost = void 0;
4
+ const viem_1 = require("viem");
5
+ const utils_1 = require("viem/utils");
6
+ const getRequiredPrefund_js_1 = require("../../utils/getRequiredPrefund.js");
7
+ const getTokenQuotes_js_1 = require("./getTokenQuotes.js");
8
+ const estimateErc20PaymasterCost = async (client, args) => {
9
+ const chain = args.chain ?? client.chain;
10
+ if (!chain) {
11
+ throw new viem_1.ChainNotFoundError();
12
+ }
13
+ const { entryPoint, userOperation, token } = args;
14
+ const quotes = await (0, utils_1.getAction)(client, getTokenQuotes_js_1.getTokenQuotes, "getTokenQuotes")({
15
+ tokens: [token],
16
+ entryPointAddress: entryPoint.address,
17
+ chain
18
+ });
19
+ const postOpGas = quotes[0].postOpGas;
20
+ const exchangeRate = quotes[0].exchangeRate;
21
+ const exchangeRateNativeToUsd = quotes[0].exchangeRateNativeToUsd;
22
+ const userOperationMaxCost = (0, getRequiredPrefund_js_1.getRequiredPrefund)({
23
+ userOperation,
24
+ entryPointVersion: entryPoint.version
25
+ });
26
+ const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
27
+ const costInToken = (maxCostInWei * exchangeRate) / BigInt(1e18);
28
+ const costInUsd = (maxCostInWei * exchangeRateNativeToUsd) / 10n ** 18n;
29
+ return {
30
+ costInToken,
31
+ costInUsd
32
+ };
33
+ };
34
+ exports.estimateErc20PaymasterCost = estimateErc20PaymasterCost;
35
+ //# sourceMappingURL=estimateErc20PaymasterCost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateErc20PaymasterCost.js","sourceRoot":"","sources":["../../../actions/pimlico/estimateErc20PaymasterCost.ts"],"names":[],"mappings":";;;AAAA,+BAQa;AAEb,sCAAsC;AAEtC,6EAAsE;AACtE,2DAAoD;AA8B7C,MAAM,0BAA0B,GAAG,KAAK,EAK3C,MAKC,EACD,IAIC,EAC4C,EAAE;IAC/C,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,MAAM,CAAC,KAAK,CAAA;IAExC,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,MAAM,IAAI,yBAAkB,EAAE,CAAA;IAClC,CAAC;IAED,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,KAAK,EAAE,GAAG,IAAI,CAAA;IAEjD,MAAM,MAAM,GAAG,MAAM,IAAA,iBAAS,EAC1B,MAAM,EACN,kCAAc,EACd,gBAAgB,CACnB,CAAC;QACE,MAAM,EAAE,CAAC,KAAK,CAAC;QACf,iBAAiB,EAAE,UAAU,CAAC,OAAO;QACrC,KAAK;KACR,CAAC,CAAA;IAEF,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;IACrC,MAAM,YAAY,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,YAAY,CAAA;IAC3C,MAAM,uBAAuB,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC,uBAAuB,CAAA;IAEjE,MAAM,oBAAoB,GAAG,IAAA,0CAAkB,EAAC;QAC5C,aAAa;QACb,iBAAiB,EAAE,UAAU,CAAC,OAAO;KACxC,CAAC,CAAA;IAGF,MAAM,YAAY,GACd,oBAAoB,GAAG,SAAS,GAAG,aAAa,CAAC,YAAY,CAAA;IAGjE,MAAM,WAAW,GAAG,CAAC,YAAY,GAAG,YAAY,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IAGhE,MAAM,SAAS,GAAG,CAAC,YAAY,GAAG,uBAAuB,CAAC,GAAG,GAAG,IAAI,GAAG,CAAA;IAEvE,OAAO;QACH,WAAW;QACX,SAAS;KACZ,CAAA;AACL,CAAC,CAAA;AA1DY,QAAA,0BAA0B,8BA0DtC"}
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pimlicoActions = void 0;
4
4
  const pimlico_js_1 = require("../../actions/pimlico.js");
5
+ const estimateErc20PaymasterCost_js_1 = require("../../actions/pimlico/estimateErc20PaymasterCost.js");
5
6
  const getUserOperationGasPrice_js_1 = require("../../actions/pimlico/getUserOperationGasPrice.js");
6
7
  const getUserOperationStatus_js_1 = require("../../actions/pimlico/getUserOperationStatus.js");
7
8
  const sponsorUserOperation_js_1 = require("../../actions/pimlico/sponsorUserOperation.js");
@@ -24,6 +25,11 @@ const pimlicoActions = ({ entryPoint }) => (client) => ({
24
25
  ...args,
25
26
  chain: args.chain,
26
27
  entryPointAddress: entryPoint.address
28
+ }),
29
+ estimateErc20PaymasterCost: async (args) => (0, estimateErc20PaymasterCost_js_1.estimateErc20PaymasterCost)(client, {
30
+ ...args,
31
+ entryPoint,
32
+ chain: args.chain
27
33
  })
28
34
  });
29
35
  exports.pimlicoActions = pimlicoActions;
@@ -1 +1 @@
1
- {"version":3,"file":"pimlico.js","sourceRoot":"","sources":["../../../clients/decorators/pimlico.ts"],"names":[],"mappings":";;;AAEA,yDASiC;AACjC,mGAG0D;AAC1D,+FAIwD;AACxD,2FAIsD;AAuG/C,MAAM,cAAc,GACvB,CAA8C,EAC1C,UAA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,EAAC,MAAM,CAAC;IACtE,sBAAsB,EAAE,KAAK,EACzB,IAAsC,EACxC,EAAE,CAAC,IAAA,kDAAsB,EAAC,MAAM,EAAE,IAAI,CAAC;IACzC,2BAA2B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACxC,IAAA,wCAA2B,EAAC,MAAM,EAAE;QAChC,GAAG,IAAI;QACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;KACxC,CAAC;IACN,oBAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACjC,IAAA,8CAAoB,EAAC,MAAM,EAAE;QACzB,GAAG,IAAI;QACP,UAAU;KACb,CAAC;IACN,2BAA2B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACxC,IAAA,wCAA2B,EAAC,MAAM,EAAE;QAChC,GAAG,IAAI;QACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;KACxC,CAAC;IACN,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAC3B,IAAA,2BAAc,EAAC,MAAM,EAAE;QACnB,GAAG,IAAI;QACP,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,iBAAiB,EAAE,UAAU,CAAC,OAAO;KACxC,CAAC;IACN,0BAA0B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACvC,IAAA,0DAA0B,EAAC,MAAM,EAAE;QAC/B,GAAG,IAAI;QACP,UAAU;QACV,KAAK,EAAE,IAAI,CAAC,KAAK;KACpB,CAAC;CACT,CAAC,CAAA;AA3CO,QAAA,cAAc,kBA2CrB"}
@@ -0,0 +1,43 @@
1
+ import { ChainNotFoundError } from "viem";
2
+ import { getAction } from "viem/utils";
3
+ import { getRequiredPrefund } from "../../utils/getRequiredPrefund.js";
4
+ import { getTokenQuotes } from "./getTokenQuotes.js";
5
+ /**
6
+ * Returns all related fields to calculate the potential cost of a userOperation in ERC-20 tokens.
7
+ *
8
+ * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/EstimateErc20PaymasterCost
9
+ *
10
+ * @param client that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
11
+ * @returns quotes, see {@link EstimateErc20PaymasterCostReturnType}
12
+ *
13
+ */
14
+ export const estimateErc20PaymasterCost = async (client, args) => {
15
+ const chain = args.chain ?? client.chain;
16
+ if (!chain) {
17
+ throw new ChainNotFoundError();
18
+ }
19
+ const { entryPoint, userOperation, token } = args;
20
+ const quotes = await getAction(client, getTokenQuotes, "getTokenQuotes")({
21
+ tokens: [token],
22
+ entryPointAddress: entryPoint.address,
23
+ chain
24
+ });
25
+ const postOpGas = quotes[0].postOpGas;
26
+ const exchangeRate = quotes[0].exchangeRate;
27
+ const exchangeRateNativeToUsd = quotes[0].exchangeRateNativeToUsd;
28
+ const userOperationMaxCost = getRequiredPrefund({
29
+ userOperation,
30
+ entryPointVersion: entryPoint.version
31
+ });
32
+ // represents the userOperation's max cost in denomination of wei
33
+ const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
34
+ // represents the userOperation's max cost in token denomination (wei)
35
+ const costInToken = (maxCostInWei * exchangeRate) / BigInt(1e18);
36
+ // represents the userOperation's max cost in usd (with 6 decimals of precision)
37
+ const costInUsd = (maxCostInWei * exchangeRateNativeToUsd) / 10n ** 18n;
38
+ return {
39
+ costInToken,
40
+ costInUsd
41
+ };
42
+ };
43
+ //# sourceMappingURL=estimateErc20PaymasterCost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateErc20PaymasterCost.js","sourceRoot":"","sources":["../../../actions/pimlico/estimateErc20PaymasterCost.ts"],"names":[],"mappings":"AAAA,OAAO,EAIH,kBAAkB,EAIrB,MAAM,MAAM,CAAA;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAqBpD;;;;;;;;GAQG;AACH,MAAM,CAA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../../actions/pimlico.js";
2
+ import { estimateErc20PaymasterCost } from "../../actions/pimlico/estimateErc20PaymasterCost.js";
2
3
  import { getUserOperationGasPrice } from "../../actions/pimlico/getUserOperationGasPrice.js";
3
4
  import { getUserOperationStatus } from "../../actions/pimlico/getUserOperationStatus.js";
4
5
  import { sponsorUserOperation } from "../../actions/pimlico/sponsorUserOperation.js";
@@ -21,6 +22,11 @@ export const pimlicoActions = ({ entryPoint }) => (client) => ({
21
22
  ...args,
22
23
  chain: args.chain,
23
24
  entryPointAddress: entryPoint.address
25
+ }),
26
+ estimateErc20PaymasterCost: async (args) => estimateErc20PaymasterCost(client, {
27
+ ...args,
28
+ entryPoint,
29
+ chain: args.chain
24
30
  })
25
31
  });
26
32
  //# sourceMappingURL=pimlico.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pimlico.js","sourceRoot":"","sources":["../../../clients/decorators/pimlico.ts"],"names":[],"mappings":"AAEA,OAAO,EAMH,cAAc,EACd,2BAA2B,EAC3B,2BAA2B,EAC9B,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAEH,wBAAwB,EAC3B,MAAM,mDAAmD,CAAA;AAC1D,OAAO,EAGH,sBAAsB,EACzB,MAAM,iDAAiD,CAAA;AACxD,OAAO,EAGH,oBAAoB,EACvB,MAAM,+CAA+C,CAAA;AAuGtD,MAAM,CAAC,MAAM,cAAc,GACvB,CAA8C,EAC1C,UAAU,EAGb,EAAE,EAAE,CACL,CAII,MAAkC,EACO,EAAE,CAAC,CAAC;IAC7C,wBAAwB,EAAE,KAAK,IAAI,EAAE,CAAC,wBAAwB,CAAC,MAAM,CAAC;IACtE,sBAAsB,EAAE,KAAK,EACzB,IAAsC,EACxC,EAAE,CAAC,sBAAsB,CAAC,MAAM,EAAE,IAAI,CAAC;IACzC,2BAA2B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACxC,2BAA2B,CAAC,MAAM,EAAE;QAChC,GAAG,IAAI;QACP,iBAAiB,EAAE,UAAU,CAAC,O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AChC,GAAG,IAAI;QACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;KACxC,CAAC;IACN,oBAAoB,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACjC,oBAAoB,CAAC,MAAM,EAAE;QACzB,GAAG,IAAI;QACP,UAAU;KACb,CAAC;IACN,2BAA2B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACxC,2BAA2B,CAAC,MAAM,EAAE;QAChC,GAAG,IAAI;QACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;KACxC,CAAC;IACN,cAAc,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CAC3B,cAAc,CAAC,MAAM,EAAE;QACnB,GAAG,IAAI;QACP,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,iBAAiB,EAAE,UAAU,CAAC,OAAO;KACxC,CAAC;IACN,0BAA0B,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE,CACvC,0BAA0B,CAAC,MAAM,EAAE;QAC/B,GAAG,IAAI;QACP,UAAU;QACV,KAAK,EAAE,IAAI,CAAC,KAAK;KACpB,CAAC;CACT,CAAC,CAAA"}
@@ -0,0 +1,30 @@
1
+ import { type Account, type Address, type Chain, type Client, type GetChainParameter, type Transport } from "viem";
2
+ import type { EntryPointVersion, UserOperation } from "viem/account-abstraction";
3
+ import type { PimlicoRpcSchema } from "../../types/pimlico.js";
4
+ /**
5
+ * @costInToken represents the max amount of token that will be charged for this user operation in token decimals
6
+ * @costInUsd represents the max amount of USD value of the token in 10^6 decimals
7
+ */
8
+ export type EstimateErc20PaymasterCostReturnType = {
9
+ costInToken: bigint;
10
+ costInUsd: bigint;
11
+ };
12
+ export type EstimateErc20PaymasterCostParameters<entryPointVersion extends EntryPointVersion, TChain extends Chain | undefined, TChainOverride extends Chain | undefined = Chain | undefined> = {
13
+ entryPoint: {
14
+ version: entryPointVersion;
15
+ address: Address;
16
+ };
17
+ userOperation: UserOperation<entryPointVersion>;
18
+ token: Address;
19
+ } & GetChainParameter<TChain, TChainOverride>;
20
+ /**
21
+ * Returns all related fields to calculate the potential cost of a userOperation in ERC-20 tokens.
22
+ *
23
+ * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/EstimateErc20PaymasterCost
24
+ *
25
+ * @param client that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
26
+ * @returns quotes, see {@link EstimateErc20PaymasterCostReturnType}
27
+ *
28
+ */
29
+ export declare const estimateErc20PaymasterCost: <entryPointVersion extends EntryPointVersion, TChain extends Chain | undefined, TChainOverride extends Chain | undefined = Chain | undefined>(client: Client<Transport, TChain, Account | undefined, PimlicoRpcSchema<entryPointVersion>>, args: EstimateErc20PaymasterCostParameters<entryPointVersion, TChain, TChainOverride>) => Promise<EstimateErc20PaymasterCostReturnType>;
30
+ //# sourceMappingURL=estimateErc20PaymasterCost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"estimateErc20PaymasterCost.d.ts","sourceRoot":"","sources":["../../../actions/pimlico/estimateErc20PaymasterCost.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,KAAK,EAEV,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACjB,MAAM,MAAM,CAAA;AACb,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAEhF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AAI9D;;;GAGG;AACH,MAAM,MAAM,oCAAoC,GAAG;IAC/C,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CACpB,CAAA;AAED,MAAM,MAAM,oCAAoC,CAC5C,iBAAiB,SAAS,iBAAiB,EAC3C,MAAM,SAAS,KAAK,GAAG,SAAS,EAChC,cAAc,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,IAC5D;IACA,UAAU,EAAE;QAAE,OAAO,EAAE,iBAAiB,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAA;IAC5D,aAAa,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAA;IAC/C,KAAK,EAAE,OAAO,CAAA;CACjB,GAAG,iBAAiB,CAAC,MAAM,EAAE,cAAc,CAAC,CAAA;AAE7C;;;;;;;;GAQG;AACH,eAAO,MAAM,0BAA0B,GACnC,iBAAiB,SAAS,iBAAiB,EAC3C,MAAM,SAAS,KAAK,GAAG,SAAS,EAChC,cAAc,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,EAE5D,QAAQ,MAAM,CACV,SAAS,EACT,MAAM,EACN,OAAO,GAAG,SAAS,EACnB,gBAAgB,CAAC,iBAAiB,CAAC,CACtC,EACD,MAAM,oCAAoC,CACtC,iBAAiB,EACjB,MAAM,EACN,cAAc,CACjB,KACF,OAAO,CAAC,oCAAoC,CA0C9C,CAAA"}
@@ -1,6 +1,7 @@
1
1
  import type { Address, Chain, Client, Hash, Prettify, Transport } from "viem";
2
2
  import type { EntryPointVersion } from "viem/account-abstraction";
3
3
  import { type GetTokenQuotesParameters, type GetTokenQuotesReturnType, type SendCompressedUserOperationParameters, type ValidateSponsorshipPolicies, type ValidateSponsorshipPoliciesParameters } from "../../actions/pimlico.js";
4
+ import { type EstimateErc20PaymasterCostParameters, type EstimateErc20PaymasterCostReturnType } from "../../actions/pimlico/estimateErc20PaymasterCost.js";
4
5
  import { type GetUserOperationGasPriceReturnType } from "../../actions/pimlico/getUserOperationGasPrice.js";
5
6
  import { type GetUserOperationStatusParameters, type GetUserOperationStatusReturnType } from "../../actions/pimlico/getUserOperationStatus.js";
6
7
  import { type PimlicoSponsorUserOperationParameters, type SponsorUserOperationReturnType } from "../../actions/pimlico/sponsorUserOperation.js";
@@ -74,6 +75,7 @@ export type PimlicoActions<TChain extends Chain | undefined, entryPointVersion e
74
75
  sponsorUserOperation: (args: Omit<PimlicoSponsorUserOperationParameters<entryPointVersion>, "entryPoint">) => Promise<Prettify<SponsorUserOperationReturnType<entryPointVersion>>>;
75
76
  validateSponsorshipPolicies: (args: Prettify<Omit<ValidateSponsorshipPoliciesParameters, "entryPointAddress">>) => Promise<Prettify<ValidateSponsorshipPolicies>[]>;
76
77
  getTokenQuotes: <TChainOverride extends Chain | undefined = Chain | undefined>(args: Prettify<Omit<GetTokenQuotesParameters<TChain, TChainOverride>, "entryPointAddress">>) => Promise<Prettify<GetTokenQuotesReturnType>>;
78
+ estimateErc20PaymasterCost: <TChainOverride extends Chain | undefined = Chain | undefined>(args: Omit<EstimateErc20PaymasterCostParameters<entryPointVersion, TChain, TChainOverride>, "entryPoint">) => Promise<Prettify<EstimateErc20PaymasterCostReturnType>>;
77
79
  };
78
80
  export declare const pimlicoActions: <entryPointVersion extends EntryPointVersion>({ entryPoint }: {
79
81
  entryPoint: {
@@ -1 +1 @@
1
- {"version":3,"file":"pimlico.d.ts","sourceRoot":"","sources":["../../../clients/decorators/pimlico.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAC7E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAA;AACjE,OAAO,EACH,KAAK,wBAAwB,EAC7B,KAAK,wBAAwB,EAC7B,KAAK,qCAAqC,EAC1C,KAAK,2BAA2B,EAChC,KAAK,qCAAqC,EAI7C,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACH,KAAK,kCAAkC,EAE1C,MAAM,mDAAmD,CAAA;AAC1D,OAAO,EACH,KAAK,gCAAgC,EACrC,KAAK,gCAAgC,EAExC,MAAM,iDAAiD,CAAA;AACxD,OAAO,EACH,KAAK,qCAAqC,EAC1C,KAAK,8BAA8B,EAEtC,MAAM,+CAA+C,CAAA;AAEtD,MAAM,MAAM,cAAc,CACtB,MAAM,SAAS,KAAK,GAAG,SAAS,EAChC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MAAM,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,EAEpD,QAAQ,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,KACnC,cAAc,CAAC,MAAM,EAAE,iBAAiB,CAgCzC,CAAA"}
@@ -0,0 +1,102 @@
1
+ import {
2
+ type Account,
3
+ type Address,
4
+ type Chain,
5
+ ChainNotFoundError,
6
+ type Client,
7
+ type GetChainParameter,
8
+ type Transport
9
+ } from "viem"
10
+ import type { EntryPointVersion, UserOperation } from "viem/account-abstraction"
11
+ import { getAction } from "viem/utils"
12
+ import type { PimlicoRpcSchema } from "../../types/pimlico.js"
13
+ import { getRequiredPrefund } from "../../utils/getRequiredPrefund.js"
14
+ import { getTokenQuotes } from "./getTokenQuotes.js"
15
+
16
+ /**
17
+ * @costInToken represents the max amount of token that will be charged for this user operation in token decimals
18
+ * @costInUsd represents the max amount of USD value of the token in 10^6 decimals
19
+ */
20
+ export type EstimateErc20PaymasterCostReturnType = {
21
+ costInToken: bigint
22
+ costInUsd: bigint
23
+ }
24
+
25
+ export type EstimateErc20PaymasterCostParameters<
26
+ entryPointVersion extends EntryPointVersion,
27
+ TChain extends Chain | undefined,
28
+ TChainOverride extends Chain | undefined = Chain | undefined
29
+ > = {
30
+ entryPoint: { version: entryPointVersion; address: Address }
31
+ userOperation: UserOperation<entryPointVersion>
32
+ token: Address
33
+ } & GetChainParameter<TChain, TChainOverride>
34
+
35
+ /**
36
+ * Returns all related fields to calculate the potential cost of a userOperation in ERC-20 tokens.
37
+ *
38
+ * - Docs: https://docs.pimlico.io/permissionless/reference/pimlico-bundler-actions/EstimateErc20PaymasterCost
39
+ *
40
+ * @param client that you created using viem's createClient whose transport url is pointing to the Pimlico's bundler.
41
+ * @returns quotes, see {@link EstimateErc20PaymasterCostReturnType}
42
+ *
43
+ */
44
+ export const estimateErc20PaymasterCost = async <
45
+ entryPointVersion extends EntryPointVersion,
46
+ TChain extends Chain | undefined,
47
+ TChainOverride extends Chain | undefined = Chain | undefined
48
+ >(
49
+ client: Client<
50
+ Transport,
51
+ TChain,
52
+ Account | undefined,
53
+ PimlicoRpcSchema<entryPointVersion>
54
+ >,
55
+ args: EstimateErc20PaymasterCostParameters<
56
+ entryPointVersion,
57
+ TChain,
58
+ TChainOverride
59
+ >
60
+ ): Promise<EstimateErc20PaymasterCostReturnType> => {
61
+ const chain = args.chain ?? client.chain
62
+
63
+ if (!chain) {
64
+ throw new ChainNotFoundError()
65
+ }
66
+
67
+ const { entryPoint, userOperation, token } = args
68
+
69
+ const quotes = await getAction(
70
+ client,
71
+ getTokenQuotes,
72
+ "getTokenQuotes"
73
+ )({
74
+ tokens: [token],
75
+ entryPointAddress: entryPoint.address,
76
+ chain
77
+ })
78
+
79
+ const postOpGas = quotes[0].postOpGas
80
+ const exchangeRate = quotes[0].exchangeRate
81
+ const exchangeRateNativeToUsd = quotes[0].exchangeRateNativeToUsd
82
+
83
+ const userOperationMaxCost = getRequiredPrefund({
84
+ userOperation,
85
+ entryPointVersion: entryPoint.version
86
+ })
87
+
88
+ // represents the userOperation's max cost in denomination of wei
89
+ const maxCostInWei =
90
+ userOperationMaxCost + postOpGas * userOperation.maxFeePerGas
91
+
92
+ // represents the userOperation's max cost in token denomination (wei)
93
+ const costInToken = (maxCostInWei * exchangeRate) / BigInt(1e18)
94
+
95
+ // represents the userOperation's max cost in usd (with 6 decimals of precision)
96
+ const costInUsd = (maxCostInWei * exchangeRateNativeToUsd) / 10n ** 18n
97
+
98
+ return {
99
+ costInToken,
100
+ costInUsd
101
+ }
102
+ }
@@ -10,6 +10,11 @@ import {
10
10
  sendCompressedUserOperation,
11
11
  validateSponsorshipPolicies
12
12
  } from "../../actions/pimlico.js"
13
+ import {
14
+ type EstimateErc20PaymasterCostParameters,
15
+ type EstimateErc20PaymasterCostReturnType,
16
+ estimateErc20PaymasterCost
17
+ } from "../../actions/pimlico/estimateErc20PaymasterCost.js"
13
18
  import {
14
19
  type GetUserOperationGasPriceReturnType,
15
20
  getUserOperationGasPrice
@@ -124,6 +129,18 @@ export type PimlicoActions<
124
129
  >
125
130
  >
126
131
  ) => Promise<Prettify<GetTokenQuotesReturnType>>
132
+ estimateErc20PaymasterCost: <
133
+ TChainOverride extends Chain | undefined = Chain | undefined
134
+ >(
135
+ args: Omit<
136
+ EstimateErc20PaymasterCostParameters<
137
+ entryPointVersion,
138
+ TChain,
139
+ TChainOverride
140
+ >,
141
+ "entryPoint"
142
+ >
143
+ ) => Promise<Prettify<EstimateErc20PaymasterCostReturnType>>
127
144
  }
128
145
 
129
146
  export const pimlicoActions =
@@ -162,5 +179,11 @@ export const pimlicoActions =
162
179
  ...args,
163
180
  chain: args.chain,
164
181
  entryPointAddress: entryPoint.address
182
+ }),
183
+ estimateErc20PaymasterCost: async (args) =>
184
+ estimateErc20PaymasterCost(client, {
185
+ ...args,
186
+ entryPoint,
187
+ chain: args.chain
165
188
  })
166
189
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "permissionless",
3
- "version": "0.2.49",
3
+ "version": "0.2.50",
4
4
  "author": "Pimlico",
5
5
  "homepage": "https://docs.pimlico.io/permissionless",
6
6
  "repository": "github:pimlicolabs/permissionless.js",