@metamask-previews/user-operation-controller 41.2.9-preview-4f4c98e → 41.2.9-preview-eb263b0ee
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 +0 -4
- package/dist/BlockTrackerPollingController.cjs +68 -0
- package/dist/BlockTrackerPollingController.cjs.map +1 -0
- package/dist/{BlockTrackerPollingController.d.ts → BlockTrackerPollingController.d.cts} +11 -11
- package/dist/BlockTrackerPollingController.d.cts.map +1 -0
- package/dist/BlockTrackerPollingController.d.mts +41 -0
- package/dist/BlockTrackerPollingController.d.mts.map +1 -0
- package/dist/{BlockTrackerPollingController.js → BlockTrackerPollingController.mjs} +16 -17
- package/dist/BlockTrackerPollingController.mjs.map +1 -0
- package/dist/UserOperationController-method-action-types.cjs +7 -0
- package/dist/UserOperationController-method-action-types.cjs.map +1 -0
- package/dist/{UserOperationController-method-action-types.d.ts → UserOperationController-method-action-types.d.cts} +2 -2
- package/dist/UserOperationController-method-action-types.d.cts.map +1 -0
- package/dist/UserOperationController-method-action-types.d.mts +57 -0
- package/dist/UserOperationController-method-action-types.d.mts.map +1 -0
- package/dist/{UserOperationController-method-action-types.js → UserOperationController-method-action-types.mjs} +1 -1
- package/dist/UserOperationController-method-action-types.mjs.map +1 -0
- package/dist/UserOperationController.cjs +495 -0
- package/dist/UserOperationController.cjs.map +1 -0
- package/dist/{UserOperationController.d.ts → UserOperationController.d.cts} +15 -13
- package/dist/UserOperationController.d.cts.map +1 -0
- package/dist/UserOperationController.d.mts +136 -0
- package/dist/UserOperationController.d.mts.map +1 -0
- package/dist/{UserOperationController.js → UserOperationController.mjs} +20 -19
- package/dist/UserOperationController.mjs.map +1 -0
- package/dist/constants.cjs +7 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +4 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/{constants.js → constants.mjs} +1 -1
- package/dist/constants.mjs.map +1 -0
- package/dist/helpers/Bundler.cjs +91 -0
- package/dist/helpers/Bundler.cjs.map +1 -0
- package/dist/helpers/{Bundler.d.ts → Bundler.d.cts} +2 -2
- package/dist/helpers/Bundler.d.cts.map +1 -0
- package/dist/helpers/Bundler.d.mts +46 -0
- package/dist/helpers/Bundler.d.mts.map +1 -0
- package/dist/helpers/{Bundler.js → Bundler.mjs} +2 -2
- package/dist/helpers/Bundler.mjs.map +1 -0
- package/dist/helpers/PendingUserOperationTracker.cjs +127 -0
- package/dist/helpers/PendingUserOperationTracker.cjs.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.d.ts → PendingUserOperationTracker.d.cts} +12 -10
- package/dist/helpers/PendingUserOperationTracker.d.cts.map +1 -0
- package/dist/helpers/PendingUserOperationTracker.d.mts +51 -0
- package/dist/helpers/PendingUserOperationTracker.d.mts.map +1 -0
- package/dist/helpers/{PendingUserOperationTracker.js → PendingUserOperationTracker.mjs} +16 -9
- package/dist/helpers/PendingUserOperationTracker.mjs.map +1 -0
- package/dist/helpers/SnapSmartContractAccount.cjs +64 -0
- package/dist/helpers/SnapSmartContractAccount.cjs.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.d.ts → SnapSmartContractAccount.d.cts} +3 -3
- package/dist/helpers/SnapSmartContractAccount.d.cts.map +1 -0
- package/dist/helpers/SnapSmartContractAccount.d.mts +10 -0
- package/dist/helpers/SnapSmartContractAccount.d.mts.map +1 -0
- package/dist/helpers/{SnapSmartContractAccount.js → SnapSmartContractAccount.mjs} +3 -3
- package/dist/helpers/SnapSmartContractAccount.mjs.map +1 -0
- package/dist/index.cjs +19 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.cjs +8 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +5 -0
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/{logger.js → logger.mjs} +2 -2
- package/dist/logger.mjs.map +1 -0
- package/dist/types.cjs +16 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types.d.ts → types.d.cts} +3 -3
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +294 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/{types.js → types.mjs} +1 -1
- package/dist/types.mjs.map +1 -0
- package/dist/utils/chain-id.cjs +17 -0
- package/dist/utils/chain-id.cjs.map +1 -0
- package/dist/utils/{chain-id.d.ts → chain-id.d.cts} +1 -1
- package/dist/utils/chain-id.d.cts.map +1 -0
- package/dist/utils/chain-id.d.mts +8 -0
- package/dist/utils/chain-id.d.mts.map +1 -0
- package/dist/utils/{chain-id.js → chain-id.mjs} +1 -1
- package/dist/utils/chain-id.mjs.map +1 -0
- package/dist/utils/gas-fees.cjs +194 -0
- package/dist/utils/gas-fees.cjs.map +1 -0
- package/dist/utils/{gas-fees.d.ts → gas-fees.d.cts} +6 -6
- package/dist/utils/gas-fees.d.cts.map +1 -0
- package/dist/utils/gas-fees.d.mts +24 -0
- package/dist/utils/gas-fees.d.mts.map +1 -0
- package/dist/utils/{gas-fees.js → gas-fees.mjs} +15 -8
- package/dist/utils/gas-fees.mjs.map +1 -0
- package/dist/utils/gas.cjs +72 -0
- package/dist/utils/gas.cjs.map +1 -0
- package/dist/utils/{gas.d.ts → gas.d.cts} +2 -2
- package/dist/utils/gas.d.cts.map +1 -0
- package/dist/utils/gas.d.mts +10 -0
- package/dist/utils/gas.d.mts.map +1 -0
- package/dist/utils/{gas.js → gas.mjs} +14 -7
- package/dist/utils/gas.mjs.map +1 -0
- package/dist/utils/transaction.cjs +117 -0
- package/dist/utils/transaction.cjs.map +1 -0
- package/dist/utils/{transaction.d.ts → transaction.d.cts} +3 -3
- package/dist/utils/transaction.d.cts.map +1 -0
- package/dist/utils/transaction.d.mts +10 -0
- package/dist/utils/transaction.d.mts.map +1 -0
- package/dist/utils/{transaction.js → transaction.mjs} +13 -6
- package/dist/utils/transaction.mjs.map +1 -0
- package/dist/utils/validation.cjs +162 -0
- package/dist/utils/validation.cjs.map +1 -0
- package/dist/utils/{validation.d.ts → validation.d.cts} +3 -3
- package/dist/utils/validation.d.cts.map +1 -0
- package/dist/utils/validation.d.mts +33 -0
- package/dist/utils/validation.d.mts.map +1 -0
- package/dist/utils/{validation.js → validation.mjs} +5 -5
- package/dist/utils/validation.mjs.map +1 -0
- package/package.json +17 -13
- package/dist/BlockTrackerPollingController.d.ts.map +0 -1
- package/dist/BlockTrackerPollingController.js.map +0 -1
- package/dist/UserOperationController-method-action-types.d.ts.map +0 -1
- package/dist/UserOperationController-method-action-types.js.map +0 -1
- package/dist/UserOperationController.d.ts.map +0 -1
- package/dist/UserOperationController.js.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/helpers/Bundler.d.ts.map +0 -1
- package/dist/helpers/Bundler.js.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.d.ts.map +0 -1
- package/dist/helpers/PendingUserOperationTracker.js.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.d.ts.map +0 -1
- package/dist/helpers/SnapSmartContractAccount.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -3
- package/dist/index.js.map +0 -1
- package/dist/logger.d.ts +0 -4
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js.map +0 -1
- package/dist/utils/chain-id.d.ts.map +0 -1
- package/dist/utils/chain-id.js.map +0 -1
- package/dist/utils/gas-fees.d.ts.map +0 -1
- package/dist/utils/gas-fees.js.map +0 -1
- package/dist/utils/gas.d.ts.map +0 -1
- package/dist/utils/gas.js.map +0 -1
- package/dist/utils/transaction.d.ts.map +0 -1
- package/dist/utils/transaction.js.map +0 -1
- package/dist/utils/validation.d.ts.map +0 -1
- package/dist/utils/validation.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas-fees.cjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,iEAKoC;AACpC,oEAA2C;AAC3C,qEAAkE;AAIlE,6EAAgE;AAEhE,2CAAwC;AAExC,mDAA8C;AAC9C,6CAAiE;AAIjE,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,UAAU,CAAC,CAAC;AAe1D;;;;;;;;;GASG;AACI,KAAK,UAAU,aAAa,CAAC,OAA6B;IAC/D,MAAM,EAAE,QAAQ,EAAE,eAAe,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAC3D,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IACnC,IAAI,gBAA8C,CAAC;IAEnD,MAAM,kBAAkB,GAAG,KAAK,IAAI,EAAE;QACpC,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,gBAAgB,GAAG,MAAM,mBAAmB,CAAC,OAAO,CAAC,CAAC;QACxD,CAAC;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC,CAAC;IAEF,aAAa,CAAC,YAAY,GAAG,MAAM,eAAe,CAChD,eAAe,EACf,kBAAkB,EAClB,WAAW,CACZ,CAAC;IAEF,aAAa,CAAC,oBAAoB,GAAG,MAAM,uBAAuB,CAChE,eAAe,EACf,kBAAkB,EAClB,aAAa,EACb,WAAW,CACZ,CAAC;IAEF,QAAQ,CAAC,YAAY,GAAG,eAAe,CACrC,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,WAAW,CACZ,CAAC;AACJ,CAAC;AAhCD,sCAgCC;AAED;;;;;;;GAOG;AACH,KAAK,UAAU,eAAe,CAC5B,eAAwC,EACxC,kBAAmD,EACnD,WAA+B;IAE/B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IAAI,mBAAQ,CAAC,QAAQ,CAAC,EAAE,UAAU,CAAC,CAE3D,CAAC;IAEd,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,aAAK,EAAC,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;IAEzD,GAAG,CAAC,yCAAyC,EAAE,YAAY,CAAC,CAAC;IAE7D,OAAO,EAAE,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,IAAA,wBAAK,EAAC,IAAA,iCAAc,EAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,0BAAW,CAAC;AACzC,CAAC","sourcesContent":["import {\n gweiDecToWEIBN,\n ORIGIN_METAMASK,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type { Provider } from '@metamask/network-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport { UserFeeLevel } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type { UserOperation, UserOperationMetadata } from '../types.js';\nimport type { AddUserOperationRequest } from '../UserOperationController.js';\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport type UpdateGasFeesRequest = {\n getGasFeeEstimates: () => Promise<GasFeeState>;\n metadata: UserOperationMetadata;\n originalRequest: AddUserOperationRequest;\n provider: Provider;\n transaction?: TransactionParams;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Populates the gas fee properties for a user operation.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.metadata - The metadata for the user operation.\n * @param request.originalRequest - The original request to add the user operation.\n * @param request.provider - A provider to query the network.\n * @param request.transaction - The transaction that created the user operation.\n */\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { metadata, originalRequest, transaction } = request;\n const { userOperation } = metadata;\n let suggestedGasFees: SuggestedGasFees | undefined;\n\n const getGasFeeEstimates = async () => {\n if (!suggestedGasFees) {\n suggestedGasFees = await getSuggestedGasFees(request);\n }\n\n return suggestedGasFees;\n };\n\n userOperation.maxFeePerGas = await getMaxFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n transaction,\n );\n\n userOperation.maxPriorityFeePerGas = await getMaxPriorityFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n userOperation,\n transaction,\n );\n\n metadata.userFeeLevel = getUserFeeLevel(\n metadata,\n originalRequest,\n suggestedGasFees,\n transaction,\n );\n}\n\n/**\n * Gets the maxFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxFeePerGas for the user operation.\n */\nasync function getMaxFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n\n if (!isGasFeeEmpty(maxFeePerGas)) {\n log('Using maxFeePerGas from request', maxFeePerGas);\n return maxFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxPriorityFeePerGas) && gasPrice) {\n log('Setting maxFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxFeePerGas: suggestedMaxFeePerGas } = await getGetFasEstimates();\n\n if (!suggestedMaxFeePerGas) {\n throw new Error('Failed to get gas fee estimate for maxFeePerGas');\n }\n\n log('Using maxFeePerGas from estimate', suggestedMaxFeePerGas);\n\n return suggestedMaxFeePerGas;\n}\n\n/**\n * Gets the maxPriorityFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param userOperation - The user operation being updated.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxPriorityFeePerGas for the user operation.\n */\nasync function getMaxPriorityFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n userOperation: UserOperation,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n const { maxFeePerGas: updatedMaxFeePerGas } = userOperation;\n\n if (!isGasFeeEmpty(maxPriorityFeePerGas)) {\n log('Using maxPriorityFeePerGas from request', maxPriorityFeePerGas);\n return maxPriorityFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxFeePerGas) && gasPrice) {\n log('Setting maxPriorityFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas } =\n await getGetFasEstimates();\n\n if (suggestedMaxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from estimate',\n suggestedMaxPriorityFeePerGas,\n );\n return suggestedMaxPriorityFeePerGas;\n }\n\n log('Setting maxPriorityFeePerGas to maxFeePerGas', updatedMaxFeePerGas);\n\n return updatedMaxFeePerGas;\n}\n\n/**\n * Gets the userFeeLevel for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param suggestedGasFees - The suggested gas fees, if any.\n * @param transaction - The transaction that created the user operation.\n * @returns The userFeeLevel for the user operation.\n */\nfunction getUserFeeLevel(\n metadata: UserOperationMetadata,\n originalRequest: AddUserOperationRequest,\n suggestedGasFees?: SuggestedGasFees,\n transaction?: TransactionParams,\n): UserFeeLevel {\n const { origin } = metadata;\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n\n const {\n maxFeePerGas: suggestedMaxFeePerGas,\n maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas,\n } = suggestedGasFees || {};\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n transaction?.gasPrice\n ) {\n return origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n suggestedMaxFeePerGas &&\n suggestedMaxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (origin === ORIGIN_METAMASK) {\n return UserFeeLevel.CUSTOM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Gets suggested gas fees.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.provider - A provider to query the network.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<{ maxFeePerGas?: Hex; maxPriorityFeePerGas?: Hex }> {\n const { getGasFeeEstimates, provider } = request;\n\n try {\n const { gasFeeEstimates, gasEstimateType } = await getGasFeeEstimates();\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n /* istanbul ignore next */\n const {\n medium: { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = {},\n } = gasFeeEstimates;\n\n if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {\n const values = {\n maxFeePerGas: gweiDecimalToWeiHex(suggestedMaxFeePerGas),\n maxPriorityFeePerGas: gweiDecimalToWeiHex(\n suggestedMaxPriorityFeePerGas,\n ),\n };\n\n log('Using medium values from fee market estimate', values);\n\n return values;\n }\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.medium);\n\n log('Using medium value from legacy estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.gasPrice);\n\n log('Using gasPrice from estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n } catch (error) {\n log('Failed to get estimate', error);\n }\n\n const gasPriceDecimal = (await query(new EthQuery(provider), 'gasPrice')) as\n | number\n | undefined;\n\n if (!gasPriceDecimal) {\n return {};\n }\n\n const maxFeePerGas = add0x(gasPriceDecimal.toString(16));\n\n log('Using gasPrice from network as fallback', maxFeePerGas);\n\n return { maxFeePerGas };\n}\n\n/**\n * Converts a GWEI decimal string to a WEI hexadecimal string.\n *\n * @param value - The GWEI decimal string to convert.\n * @returns The WEI hexadecimal string.\n */\nfunction gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Checks if a gas fee property is empty.\n *\n * @param value - The gas fee value to check.\n * @returns Whether the gas fee property is empty.\n */\nfunction isGasFeeEmpty(value?: string): boolean {\n return !value || value === EMPTY_BYTES;\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { GasFeeState } from
|
|
2
|
-
import type { Provider } from
|
|
3
|
-
import type { TransactionParams } from
|
|
4
|
-
import type { UserOperationMetadata } from
|
|
5
|
-
import type { AddUserOperationRequest } from
|
|
1
|
+
import type { GasFeeState } from "@metamask/gas-fee-controller";
|
|
2
|
+
import type { Provider } from "@metamask/network-controller";
|
|
3
|
+
import type { TransactionParams } from "@metamask/transaction-controller";
|
|
4
|
+
import type { UserOperationMetadata } from "../types.cjs";
|
|
5
|
+
import type { AddUserOperationRequest } from "../UserOperationController.cjs";
|
|
6
6
|
export type UpdateGasFeesRequest = {
|
|
7
7
|
getGasFeeEstimates: () => Promise<GasFeeState>;
|
|
8
8
|
metadata: UserOperationMetadata;
|
|
@@ -21,4 +21,4 @@ export type UpdateGasFeesRequest = {
|
|
|
21
21
|
* @param request.transaction - The transaction that created the user operation.
|
|
22
22
|
*/
|
|
23
23
|
export declare function updateGasFees(request: UpdateGasFeesRequest): Promise<void>;
|
|
24
|
-
//# sourceMappingURL=gas-fees.d.
|
|
24
|
+
//# sourceMappingURL=gas-fees.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas-fees.d.cts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAoB;AACxE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAsC;AAI7E,MAAM,MAAM,oBAAoB,GAAG;IACjC,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,QAAQ,EAAE,qBAAqB,CAAC;IAChC,eAAe,EAAE,uBAAuB,CAAC;IACzC,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAOF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,iBAgChE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { GasFeeState } from "@metamask/gas-fee-controller";
|
|
2
|
+
import type { Provider } from "@metamask/network-controller";
|
|
3
|
+
import type { TransactionParams } from "@metamask/transaction-controller";
|
|
4
|
+
import type { UserOperationMetadata } from "../types.mjs";
|
|
5
|
+
import type { AddUserOperationRequest } from "../UserOperationController.mjs";
|
|
6
|
+
export type UpdateGasFeesRequest = {
|
|
7
|
+
getGasFeeEstimates: () => Promise<GasFeeState>;
|
|
8
|
+
metadata: UserOperationMetadata;
|
|
9
|
+
originalRequest: AddUserOperationRequest;
|
|
10
|
+
provider: Provider;
|
|
11
|
+
transaction?: TransactionParams;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Populates the gas fee properties for a user operation.
|
|
15
|
+
*
|
|
16
|
+
* @param request - The request to update the gas fees.
|
|
17
|
+
* @param request.getGasFeeEstimates - A callback to get gas fee estimates.
|
|
18
|
+
* @param request.metadata - The metadata for the user operation.
|
|
19
|
+
* @param request.originalRequest - The original request to add the user operation.
|
|
20
|
+
* @param request.provider - A provider to query the network.
|
|
21
|
+
* @param request.transaction - The transaction that created the user operation.
|
|
22
|
+
*/
|
|
23
|
+
export declare function updateGasFees(request: UpdateGasFeesRequest): Promise<void>;
|
|
24
|
+
//# sourceMappingURL=gas-fees.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas-fees.d.mts","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,qCAAqC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,qCAAqC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,yCAAyC;AAO1E,OAAO,KAAK,EAAiB,qBAAqB,EAAE,qBAAoB;AACxE,OAAO,KAAK,EAAE,uBAAuB,EAAE,uCAAsC;AAI7E,MAAM,MAAM,oBAAoB,GAAG;IACjC,kBAAkB,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IAC/C,QAAQ,EAAE,qBAAqB,CAAC;IAChC,eAAe,EAAE,uBAAuB,CAAC;IACzC,QAAQ,EAAE,QAAQ,CAAC;IACnB,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC,CAAC;AAOF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAC,OAAO,EAAE,oBAAoB,iBAgChE"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
1
|
+
function $importDefault(module) {
|
|
2
|
+
if (module?.__esModule) {
|
|
3
|
+
return module.default;
|
|
4
|
+
}
|
|
5
|
+
return module;
|
|
6
|
+
}
|
|
7
|
+
import { gweiDecToWEIBN, ORIGIN_METAMASK, query, toHex } from "@metamask/controller-utils";
|
|
8
|
+
import $EthQuery from "@metamask/eth-query";
|
|
9
|
+
const EthQuery = $importDefault($EthQuery);
|
|
10
|
+
import { GAS_ESTIMATE_TYPES } from "@metamask/gas-fee-controller";
|
|
11
|
+
import { UserFeeLevel } from "@metamask/transaction-controller";
|
|
12
|
+
import { add0x } from "@metamask/utils";
|
|
13
|
+
import { EMPTY_BYTES } from "../constants.mjs";
|
|
14
|
+
import { createModuleLogger, projectLogger } from "../logger.mjs";
|
|
8
15
|
const log = createModuleLogger(projectLogger, 'gas-fees');
|
|
9
16
|
/**
|
|
10
17
|
* Populates the gas fee properties for a user operation.
|
|
@@ -184,4 +191,4 @@ function gweiDecimalToWeiHex(value) {
|
|
|
184
191
|
function isGasFeeEmpty(value) {
|
|
185
192
|
return !value || value === EMPTY_BYTES;
|
|
186
193
|
}
|
|
187
|
-
//# sourceMappingURL=gas-fees.
|
|
194
|
+
//# sourceMappingURL=gas-fees.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas-fees.mjs","sourceRoot":"","sources":["../../src/utils/gas-fees.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,cAAc,EACd,eAAe,EACf,KAAK,EACL,KAAK,EACN,mCAAmC;AACpC,OAAO,SAAQ,4BAA4B;;AAC3C,OAAO,EAAE,kBAAkB,EAAE,qCAAqC;AAIlE,OAAO,EAAE,YAAY,EAAE,yCAAyC;AAEhE,OAAO,EAAE,KAAK,EAAE,wBAAwB;AAExC,OAAO,EAAE,WAA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AE,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,KAAa;IACxC,OAAO,KAAK,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,KAAc;IACnC,OAAO,CAAC,KAAK,IAAI,KAAK,KAAK,WAAW,CAAC;AACzC,CAAC","sourcesContent":["import {\n gweiDecToWEIBN,\n ORIGIN_METAMASK,\n query,\n toHex,\n} from '@metamask/controller-utils';\nimport EthQuery from '@metamask/eth-query';\nimport { GAS_ESTIMATE_TYPES } from '@metamask/gas-fee-controller';\nimport type { GasFeeState } from '@metamask/gas-fee-controller';\nimport type { Provider } from '@metamask/network-controller';\nimport type { TransactionParams } from '@metamask/transaction-controller';\nimport { UserFeeLevel } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x } from '@metamask/utils';\n\nimport { EMPTY_BYTES } from '../constants.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type { UserOperation, UserOperationMetadata } from '../types.js';\nimport type { AddUserOperationRequest } from '../UserOperationController.js';\n\nconst log = createModuleLogger(projectLogger, 'gas-fees');\n\nexport type UpdateGasFeesRequest = {\n getGasFeeEstimates: () => Promise<GasFeeState>;\n metadata: UserOperationMetadata;\n originalRequest: AddUserOperationRequest;\n provider: Provider;\n transaction?: TransactionParams;\n};\n\ntype SuggestedGasFees = {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n};\n\n/**\n * Populates the gas fee properties for a user operation.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.metadata - The metadata for the user operation.\n * @param request.originalRequest - The original request to add the user operation.\n * @param request.provider - A provider to query the network.\n * @param request.transaction - The transaction that created the user operation.\n */\nexport async function updateGasFees(request: UpdateGasFeesRequest) {\n const { metadata, originalRequest, transaction } = request;\n const { userOperation } = metadata;\n let suggestedGasFees: SuggestedGasFees | undefined;\n\n const getGasFeeEstimates = async () => {\n if (!suggestedGasFees) {\n suggestedGasFees = await getSuggestedGasFees(request);\n }\n\n return suggestedGasFees;\n };\n\n userOperation.maxFeePerGas = await getMaxFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n transaction,\n );\n\n userOperation.maxPriorityFeePerGas = await getMaxPriorityFeePerGas(\n originalRequest,\n getGasFeeEstimates,\n userOperation,\n transaction,\n );\n\n metadata.userFeeLevel = getUserFeeLevel(\n metadata,\n originalRequest,\n suggestedGasFees,\n transaction,\n );\n}\n\n/**\n * Gets the maxFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxFeePerGas for the user operation.\n */\nasync function getMaxFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n\n if (!isGasFeeEmpty(maxFeePerGas)) {\n log('Using maxFeePerGas from request', maxFeePerGas);\n return maxFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxPriorityFeePerGas) && gasPrice) {\n log('Setting maxFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxFeePerGas: suggestedMaxFeePerGas } = await getGetFasEstimates();\n\n if (!suggestedMaxFeePerGas) {\n throw new Error('Failed to get gas fee estimate for maxFeePerGas');\n }\n\n log('Using maxFeePerGas from estimate', suggestedMaxFeePerGas);\n\n return suggestedMaxFeePerGas;\n}\n\n/**\n * Gets the maxPriorityFeePerGas for a user operation.\n *\n * @param originalRequest - The original request to add the user operation.\n * @param getGetFasEstimates - A callback to get gas fee estimates.\n * @param userOperation - The user operation being updated.\n * @param transaction - The transaction that created the user operation.\n * @returns The maxPriorityFeePerGas for the user operation.\n */\nasync function getMaxPriorityFeePerGas(\n originalRequest: AddUserOperationRequest,\n getGetFasEstimates: () => Promise<SuggestedGasFees>,\n userOperation: UserOperation,\n transaction?: TransactionParams,\n) {\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n const { gasPrice } = transaction ?? {};\n const { maxFeePerGas: updatedMaxFeePerGas } = userOperation;\n\n if (!isGasFeeEmpty(maxPriorityFeePerGas)) {\n log('Using maxPriorityFeePerGas from request', maxPriorityFeePerGas);\n return maxPriorityFeePerGas as string;\n }\n\n if (isGasFeeEmpty(maxFeePerGas) && gasPrice) {\n log('Setting maxPriorityFeePerGas to transaction gasPrice', gasPrice);\n return gasPrice;\n }\n\n const { maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas } =\n await getGetFasEstimates();\n\n if (suggestedMaxPriorityFeePerGas) {\n log(\n 'Using maxPriorityFeePerGas from estimate',\n suggestedMaxPriorityFeePerGas,\n );\n return suggestedMaxPriorityFeePerGas;\n }\n\n log('Setting maxPriorityFeePerGas to maxFeePerGas', updatedMaxFeePerGas);\n\n return updatedMaxFeePerGas;\n}\n\n/**\n * Gets the userFeeLevel for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param originalRequest - The original request to add the user operation.\n * @param suggestedGasFees - The suggested gas fees, if any.\n * @param transaction - The transaction that created the user operation.\n * @returns The userFeeLevel for the user operation.\n */\nfunction getUserFeeLevel(\n metadata: UserOperationMetadata,\n originalRequest: AddUserOperationRequest,\n suggestedGasFees?: SuggestedGasFees,\n transaction?: TransactionParams,\n): UserFeeLevel {\n const { origin } = metadata;\n const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;\n\n const {\n maxFeePerGas: suggestedMaxFeePerGas,\n maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas,\n } = suggestedGasFees || {};\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n transaction?.gasPrice\n ) {\n return origin === ORIGIN_METAMASK\n ? UserFeeLevel.CUSTOM\n : UserFeeLevel.DAPP_SUGGESTED;\n }\n\n if (\n isGasFeeEmpty(maxFeePerGas) &&\n isGasFeeEmpty(maxPriorityFeePerGas) &&\n suggestedMaxFeePerGas &&\n suggestedMaxPriorityFeePerGas\n ) {\n return UserFeeLevel.MEDIUM;\n }\n\n if (origin === ORIGIN_METAMASK) {\n return UserFeeLevel.CUSTOM;\n }\n\n return UserFeeLevel.DAPP_SUGGESTED;\n}\n\n/**\n * Gets suggested gas fees.\n *\n * @param request - The request to update the gas fees.\n * @param request.getGasFeeEstimates - A callback to get gas fee estimates.\n * @param request.provider - A provider to query the network.\n * @returns The suggested gas fees.\n */\nasync function getSuggestedGasFees(\n request: UpdateGasFeesRequest,\n): Promise<{ maxFeePerGas?: Hex; maxPriorityFeePerGas?: Hex }> {\n const { getGasFeeEstimates, provider } = request;\n\n try {\n const { gasFeeEstimates, gasEstimateType } = await getGasFeeEstimates();\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET) {\n /* istanbul ignore next */\n const {\n medium: { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = {},\n } = gasFeeEstimates;\n\n if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {\n const values = {\n maxFeePerGas: gweiDecimalToWeiHex(suggestedMaxFeePerGas),\n maxPriorityFeePerGas: gweiDecimalToWeiHex(\n suggestedMaxPriorityFeePerGas,\n ),\n };\n\n log('Using medium values from fee market estimate', values);\n\n return values;\n }\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.medium);\n\n log('Using medium value from legacy estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n\n if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {\n const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.gasPrice);\n\n log('Using gasPrice from estimate', maxFeePerGas);\n\n return {\n maxFeePerGas,\n };\n }\n } catch (error) {\n log('Failed to get estimate', error);\n }\n\n const gasPriceDecimal = (await query(new EthQuery(provider), 'gasPrice')) as\n | number\n | undefined;\n\n if (!gasPriceDecimal) {\n return {};\n }\n\n const maxFeePerGas = add0x(gasPriceDecimal.toString(16));\n\n log('Using gasPrice from network as fallback', maxFeePerGas);\n\n return { maxFeePerGas };\n}\n\n/**\n * Converts a GWEI decimal string to a WEI hexadecimal string.\n *\n * @param value - The GWEI decimal string to convert.\n * @returns The WEI hexadecimal string.\n */\nfunction gweiDecimalToWeiHex(value: string) {\n return toHex(gweiDecToWEIBN(value));\n}\n\n/**\n * Checks if a gas fee property is empty.\n *\n * @param value - The gas fee value to check.\n * @returns Whether the gas fee property is empty.\n */\nfunction isGasFeeEmpty(value?: string): boolean {\n return !value || value === EMPTY_BYTES;\n}\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updateGas = void 0;
|
|
7
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
8
|
+
const utils_1 = require("@metamask/utils");
|
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
10
|
+
const constants_js_1 = require("../constants.cjs");
|
|
11
|
+
const Bundler_js_1 = require("../helpers/Bundler.cjs");
|
|
12
|
+
const logger_js_1 = require("../logger.cjs");
|
|
13
|
+
const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'gas');
|
|
14
|
+
/**
|
|
15
|
+
* A multiplier to apply to all gas estimate values returned from the bundler.
|
|
16
|
+
*/
|
|
17
|
+
const GAS_ESTIMATE_MULTIPLIER = 1.5;
|
|
18
|
+
/**
|
|
19
|
+
* Populates the gas properties for a user operation.
|
|
20
|
+
*
|
|
21
|
+
* @param metadata - The metadata for the user operation.
|
|
22
|
+
* @param prepareResponse - The prepare response from the smart contract account.
|
|
23
|
+
* @param entrypoint - Address of the entrypoint contract.
|
|
24
|
+
*/
|
|
25
|
+
async function updateGas(metadata, prepareResponse, entrypoint) {
|
|
26
|
+
const { userOperation } = metadata;
|
|
27
|
+
if (prepareResponse.gas) {
|
|
28
|
+
userOperation.callGasLimit = prepareResponse.gas.callGasLimit;
|
|
29
|
+
userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;
|
|
30
|
+
userOperation.verificationGasLimit =
|
|
31
|
+
prepareResponse.gas.verificationGasLimit;
|
|
32
|
+
log('Using gas values from smart contract account', {
|
|
33
|
+
callGasLimit: userOperation.callGasLimit,
|
|
34
|
+
preVerificationGas: userOperation.preVerificationGas,
|
|
35
|
+
verificationGasLimit: userOperation.verificationGasLimit,
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const payload = {
|
|
40
|
+
...userOperation,
|
|
41
|
+
maxFeePerGas: constants_js_1.VALUE_ZERO,
|
|
42
|
+
maxPriorityFeePerGas: constants_js_1.VALUE_ZERO,
|
|
43
|
+
callGasLimit: constants_js_1.VALUE_ZERO,
|
|
44
|
+
preVerificationGas: constants_js_1.VALUE_ZERO,
|
|
45
|
+
verificationGasLimit: '0xF4240',
|
|
46
|
+
};
|
|
47
|
+
const bundler = new Bundler_js_1.Bundler(metadata.bundlerUrl);
|
|
48
|
+
const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);
|
|
49
|
+
userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);
|
|
50
|
+
userOperation.preVerificationGas = normalizeGasEstimate(estimate.preVerificationGas);
|
|
51
|
+
userOperation.verificationGasLimit = normalizeGasEstimate((estimate.verificationGasLimit ?? estimate.verificationGas));
|
|
52
|
+
log('Using buffered gas values from bundler estimate', {
|
|
53
|
+
callGasLimit: userOperation.callGasLimit,
|
|
54
|
+
preVerificationGas: userOperation.preVerificationGas,
|
|
55
|
+
verificationGasLimit: userOperation.verificationGasLimit,
|
|
56
|
+
multiplier: GAS_ESTIMATE_MULTIPLIER,
|
|
57
|
+
estimate,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.updateGas = updateGas;
|
|
61
|
+
/**
|
|
62
|
+
* Normalizes a gas estimate value from the bundler.
|
|
63
|
+
*
|
|
64
|
+
* @param rawValue - The raw value to normalize.
|
|
65
|
+
* @returns The normalized value as a hexadecimal string.
|
|
66
|
+
*/
|
|
67
|
+
function normalizeGasEstimate(rawValue) {
|
|
68
|
+
const value = typeof rawValue === 'string' ? (0, controller_utils_1.hexToBN)(rawValue) : new bn_js_1.default(rawValue);
|
|
69
|
+
const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);
|
|
70
|
+
return (0, utils_1.add0x)(bufferedValue.toString(16));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=gas.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.cjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;;;;AAAA,iEAAqD;AACrD,2CAAwC;AACxC,kDAAuB;AAEvB,mDAA6C;AAC7C,uDAAgD;AAChD,6CAAiE;AAMjE,MAAM,GAAG,GAAG,IAAA,8BAAkB,EAAC,yBAAa,EAAE,KAAK,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC;;;;;;GAMG;AACI,KAAK,UAAU,SAAS,CAC7B,QAA+B,EAC/B,eAA6C,EAC7C,UAAkB;IAElB,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IAEnC,IAAI,eAAe,CAAC,GAAG,EAAE,CAAC;QACxB,aAAa,CAAC,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;QAC9D,aAAa,CAAC,kBAAkB,GAAG,eAAe,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAC1E,aAAa,CAAC,oBAAoB;YACh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,CAAC,CAAC,CAAC,CAAC,IAAI,eAAE,CAAC,QAAQ,CAAC,CAAC;IAEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,IAAA,aAAK,EAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { hexToBN } from '@metamask/controller-utils';\nimport { add0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { VALUE_ZERO } from '../constants.js';\nimport { Bundler } from '../helpers/Bundler.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types.js';\n\nconst log = createModuleLogger(projectLogger, 'gas');\n\n/**\n * A multiplier to apply to all gas estimate values returned from the bundler.\n */\nconst GAS_ESTIMATE_MULTIPLIER = 1.5;\n\n/**\n * Populates the gas properties for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param prepareResponse - The prepare response from the smart contract account.\n * @param entrypoint - Address of the entrypoint contract.\n */\nexport async function updateGas(\n metadata: UserOperationMetadata,\n prepareResponse: PrepareUserOperationResponse,\n entrypoint: string,\n) {\n const { userOperation } = metadata;\n\n if (prepareResponse.gas) {\n userOperation.callGasLimit = prepareResponse.gas.callGasLimit;\n userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;\n userOperation.verificationGasLimit =\n prepareResponse.gas.verificationGasLimit;\n\n log('Using gas values from smart contract account', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n });\n\n return;\n }\n\n const payload = {\n ...userOperation,\n maxFeePerGas: VALUE_ZERO,\n maxPriorityFeePerGas: VALUE_ZERO,\n callGasLimit: VALUE_ZERO,\n preVerificationGas: VALUE_ZERO,\n verificationGasLimit: '0xF4240',\n };\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);\n\n userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);\n userOperation.preVerificationGas = normalizeGasEstimate(\n estimate.preVerificationGas,\n );\n userOperation.verificationGasLimit = normalizeGasEstimate(\n (estimate.verificationGasLimit ?? estimate.verificationGas) as\n | string\n | number,\n );\n\n log('Using buffered gas values from bundler estimate', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n multiplier: GAS_ESTIMATE_MULTIPLIER,\n estimate,\n });\n}\n\n/**\n * Normalizes a gas estimate value from the bundler.\n *\n * @param rawValue - The raw value to normalize.\n * @returns The normalized value as a hexadecimal string.\n */\nfunction normalizeGasEstimate(rawValue: string | number): string {\n const value =\n typeof rawValue === 'string' ? hexToBN(rawValue) : new BN(rawValue);\n\n const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);\n\n return add0x(bufferedValue.toString(16));\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PrepareUserOperationResponse, UserOperationMetadata } from
|
|
1
|
+
import type { PrepareUserOperationResponse, UserOperationMetadata } from "../types.cjs";
|
|
2
2
|
/**
|
|
3
3
|
* Populates the gas properties for a user operation.
|
|
4
4
|
*
|
|
@@ -7,4 +7,4 @@ import type { PrepareUserOperationResponse, UserOperationMetadata } from '../typ
|
|
|
7
7
|
* @param entrypoint - Address of the entrypoint contract.
|
|
8
8
|
*/
|
|
9
9
|
export declare function updateGas(metadata: UserOperationMetadata, prepareResponse: PrepareUserOperationResponse, entrypoint: string): Promise<void>;
|
|
10
|
-
//# sourceMappingURL=gas.d.
|
|
10
|
+
//# sourceMappingURL=gas.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.d.cts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAoB;AASrB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PrepareUserOperationResponse, UserOperationMetadata } from "../types.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Populates the gas properties for a user operation.
|
|
4
|
+
*
|
|
5
|
+
* @param metadata - The metadata for the user operation.
|
|
6
|
+
* @param prepareResponse - The prepare response from the smart contract account.
|
|
7
|
+
* @param entrypoint - Address of the entrypoint contract.
|
|
8
|
+
*/
|
|
9
|
+
export declare function updateGas(metadata: UserOperationMetadata, prepareResponse: PrepareUserOperationResponse, entrypoint: string): Promise<void>;
|
|
10
|
+
//# sourceMappingURL=gas.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.d.mts","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,4BAA4B,EAC5B,qBAAqB,EACtB,qBAAoB;AASrB;;;;;;GAMG;AACH,wBAAsB,SAAS,CAC7B,QAAQ,EAAE,qBAAqB,EAC/B,eAAe,EAAE,4BAA4B,EAC7C,UAAU,EAAE,MAAM,iBAgDnB"}
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
function $importDefault(module) {
|
|
2
|
+
if (module?.__esModule) {
|
|
3
|
+
return module.default;
|
|
4
|
+
}
|
|
5
|
+
return module;
|
|
6
|
+
}
|
|
7
|
+
import { hexToBN } from "@metamask/controller-utils";
|
|
8
|
+
import { add0x } from "@metamask/utils";
|
|
9
|
+
import $BN from "bn.js";
|
|
10
|
+
const BN = $importDefault($BN);
|
|
11
|
+
import { VALUE_ZERO } from "../constants.mjs";
|
|
12
|
+
import { Bundler } from "../helpers/Bundler.mjs";
|
|
13
|
+
import { createModuleLogger, projectLogger } from "../logger.mjs";
|
|
7
14
|
const log = createModuleLogger(projectLogger, 'gas');
|
|
8
15
|
/**
|
|
9
16
|
* A multiplier to apply to all gas estimate values returned from the bundler.
|
|
@@ -62,4 +69,4 @@ function normalizeGasEstimate(rawValue) {
|
|
|
62
69
|
const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);
|
|
63
70
|
return add0x(bufferedValue.toString(16));
|
|
64
71
|
}
|
|
65
|
-
//# sourceMappingURL=gas.
|
|
72
|
+
//# sourceMappingURL=gas.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gas.mjs","sourceRoot":"","sources":["../../src/utils/gas.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,mCAAmC;AACrD,OAAO,EAAE,KAAK,EAAE,wBAAwB;AACxC,OAAO,GAAE,cAAc;;AAEvB,OAAO,EAAE,UAAU,EAAE,yBAAwB;AAC7C,OAAO,EAAE,OAAO,EAAE,+BAA8B;AAChD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,sBAAqB;AAMjE,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,uBAAuB,GAAG,GAAG,CAAC;AAEpC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,QAA+B,EAC/B,eAA6C,EAC7C,UAAkB;IAElB,MAAM,EAAE,aAAa,EAAE,GAAG,QAAQ,CAAC;IAEnC,IAAI,eAAe,CAAC,GAAG,EAAE,CAAC;QACxB,aAAa,CAAC,YAAY,GAAG,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;QAC9D,aAAa,CAAC,kBAAkB,GAAG,eAAe,CAAC,GAAG,CAAC,kBAAkB,CAAC;QAC1E,aAAa,CAAC,oBAAoB;YAChC,eAAe,CAAC,GAAG,CAAC,oBAAoB,C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AEtE,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IAE1D,OAAO,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import { hexToBN } from '@metamask/controller-utils';\nimport { add0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { VALUE_ZERO } from '../constants.js';\nimport { Bundler } from '../helpers/Bundler.js';\nimport { createModuleLogger, projectLogger } from '../logger.js';\nimport type {\n PrepareUserOperationResponse,\n UserOperationMetadata,\n} from '../types.js';\n\nconst log = createModuleLogger(projectLogger, 'gas');\n\n/**\n * A multiplier to apply to all gas estimate values returned from the bundler.\n */\nconst GAS_ESTIMATE_MULTIPLIER = 1.5;\n\n/**\n * Populates the gas properties for a user operation.\n *\n * @param metadata - The metadata for the user operation.\n * @param prepareResponse - The prepare response from the smart contract account.\n * @param entrypoint - Address of the entrypoint contract.\n */\nexport async function updateGas(\n metadata: UserOperationMetadata,\n prepareResponse: PrepareUserOperationResponse,\n entrypoint: string,\n) {\n const { userOperation } = metadata;\n\n if (prepareResponse.gas) {\n userOperation.callGasLimit = prepareResponse.gas.callGasLimit;\n userOperation.preVerificationGas = prepareResponse.gas.preVerificationGas;\n userOperation.verificationGasLimit =\n prepareResponse.gas.verificationGasLimit;\n\n log('Using gas values from smart contract account', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n });\n\n return;\n }\n\n const payload = {\n ...userOperation,\n maxFeePerGas: VALUE_ZERO,\n maxPriorityFeePerGas: VALUE_ZERO,\n callGasLimit: VALUE_ZERO,\n preVerificationGas: VALUE_ZERO,\n verificationGasLimit: '0xF4240',\n };\n\n const bundler = new Bundler(metadata.bundlerUrl as string);\n const estimate = await bundler.estimateUserOperationGas(payload, entrypoint);\n\n userOperation.callGasLimit = normalizeGasEstimate(estimate.callGasLimit);\n userOperation.preVerificationGas = normalizeGasEstimate(\n estimate.preVerificationGas,\n );\n userOperation.verificationGasLimit = normalizeGasEstimate(\n (estimate.verificationGasLimit ?? estimate.verificationGas) as\n | string\n | number,\n );\n\n log('Using buffered gas values from bundler estimate', {\n callGasLimit: userOperation.callGasLimit,\n preVerificationGas: userOperation.preVerificationGas,\n verificationGasLimit: userOperation.verificationGasLimit,\n multiplier: GAS_ESTIMATE_MULTIPLIER,\n estimate,\n });\n}\n\n/**\n * Normalizes a gas estimate value from the bundler.\n *\n * @param rawValue - The raw value to normalize.\n * @returns The normalized value as a hexadecimal string.\n */\nfunction normalizeGasEstimate(rawValue: string | number): string {\n const value =\n typeof rawValue === 'string' ? hexToBN(rawValue) : new BN(rawValue);\n\n const bufferedValue = value.muln(GAS_ESTIMATE_MULTIPLIER);\n\n return add0x(bufferedValue.toString(16));\n}\n"]}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getTransactionMetadata = void 0;
|
|
7
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
8
|
+
const utils_1 = require("@metamask/utils");
|
|
9
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
10
|
+
const constants_js_1 = require("../constants.cjs");
|
|
11
|
+
const types_js_1 = require("../types.cjs");
|
|
12
|
+
/**
|
|
13
|
+
* Converts a user operation metadata object into a transaction metadata object.
|
|
14
|
+
*
|
|
15
|
+
* @param metadata - The user operation metadata object to convert.
|
|
16
|
+
* @returns The equivalent transaction metadata object.
|
|
17
|
+
*/
|
|
18
|
+
function getTransactionMetadata(metadata) {
|
|
19
|
+
const { actualGasCost, actualGasUsed, baseFeePerGas, chainId, error: rawError, origin, transactionHash, id, swapsMetadata, time, transactionParams, transactionType, userFeeLevel: rawUserFeeLevel, userOperation, } = metadata;
|
|
20
|
+
if (!transactionParams) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
// effectiveGasPrice = actualGasCost / actualGasUsed
|
|
24
|
+
const effectiveGasPrice = actualGasCost && actualGasUsed
|
|
25
|
+
? (0, utils_1.add0x)(new bn_js_1.default((0, utils_1.remove0x)(actualGasCost), 16)
|
|
26
|
+
.div(new bn_js_1.default((0, utils_1.remove0x)(actualGasUsed), 16))
|
|
27
|
+
.toString(16))
|
|
28
|
+
: undefined;
|
|
29
|
+
const error = (rawError
|
|
30
|
+
? {
|
|
31
|
+
name: rawError.name,
|
|
32
|
+
message: rawError.message,
|
|
33
|
+
stack: rawError.stack,
|
|
34
|
+
code: rawError.code,
|
|
35
|
+
rpc: rawError.rpc,
|
|
36
|
+
}
|
|
37
|
+
: undefined);
|
|
38
|
+
const status = {
|
|
39
|
+
[types_js_1.UserOperationStatus.Unapproved]: transaction_controller_1.TransactionStatus.unapproved,
|
|
40
|
+
[types_js_1.UserOperationStatus.Approved]: transaction_controller_1.TransactionStatus.approved,
|
|
41
|
+
[types_js_1.UserOperationStatus.Signed]: transaction_controller_1.TransactionStatus.signed,
|
|
42
|
+
[types_js_1.UserOperationStatus.Submitted]: transaction_controller_1.TransactionStatus.submitted,
|
|
43
|
+
[types_js_1.UserOperationStatus.Confirmed]: transaction_controller_1.TransactionStatus.confirmed,
|
|
44
|
+
[types_js_1.UserOperationStatus.Failed]: transaction_controller_1.TransactionStatus.failed,
|
|
45
|
+
}[metadata.status];
|
|
46
|
+
const gas = addHex(userOperation.preVerificationGas, userOperation.verificationGasLimit, userOperation.callGasLimit);
|
|
47
|
+
const hasPaymaster = userOperation.paymasterAndData !== constants_js_1.EMPTY_BYTES;
|
|
48
|
+
const maxFeePerGas = hasPaymaster ? constants_js_1.VALUE_ZERO : userOperation.maxFeePerGas;
|
|
49
|
+
const maxPriorityFeePerGas = hasPaymaster
|
|
50
|
+
? constants_js_1.VALUE_ZERO
|
|
51
|
+
: userOperation.maxPriorityFeePerGas;
|
|
52
|
+
const nonce = userOperation.nonce === constants_js_1.EMPTY_BYTES ? undefined : userOperation.nonce;
|
|
53
|
+
const txParams = {
|
|
54
|
+
...transactionParams,
|
|
55
|
+
from: userOperation.sender,
|
|
56
|
+
gas,
|
|
57
|
+
nonce,
|
|
58
|
+
maxFeePerGas,
|
|
59
|
+
maxPriorityFeePerGas,
|
|
60
|
+
};
|
|
61
|
+
// User operations only support EIP-1559 gas fee properties.
|
|
62
|
+
delete txParams.gasPrice;
|
|
63
|
+
const swaps = {
|
|
64
|
+
approvalTxId: swapsMetadata?.approvalTxId ?? undefined,
|
|
65
|
+
destinationTokenAddress: swapsMetadata?.destinationTokenAddress ?? undefined,
|
|
66
|
+
destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,
|
|
67
|
+
destinationTokenDecimals: swapsMetadata?.destinationTokenDecimals ?? undefined,
|
|
68
|
+
destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,
|
|
69
|
+
estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,
|
|
70
|
+
sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,
|
|
71
|
+
sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,
|
|
72
|
+
sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,
|
|
73
|
+
sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,
|
|
74
|
+
swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,
|
|
75
|
+
swapMetaData: swapsMetadata?.swapMetaData ?? undefined,
|
|
76
|
+
swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,
|
|
77
|
+
};
|
|
78
|
+
const userFeeLevel = hasPaymaster ? transaction_controller_1.UserFeeLevel.CUSTOM : rawUserFeeLevel;
|
|
79
|
+
return {
|
|
80
|
+
baseFeePerGas: baseFeePerGas ?? undefined,
|
|
81
|
+
chainId: chainId,
|
|
82
|
+
error,
|
|
83
|
+
hash: transactionHash ?? undefined,
|
|
84
|
+
id,
|
|
85
|
+
isUserOperation: true,
|
|
86
|
+
networkClientId: 'user-operation',
|
|
87
|
+
origin,
|
|
88
|
+
status,
|
|
89
|
+
time,
|
|
90
|
+
txParams,
|
|
91
|
+
txReceipt: {
|
|
92
|
+
effectiveGasPrice: effectiveGasPrice ?? undefined,
|
|
93
|
+
gasUsed: actualGasUsed ?? undefined,
|
|
94
|
+
},
|
|
95
|
+
type: transactionType ?? undefined,
|
|
96
|
+
userFeeLevel: userFeeLevel,
|
|
97
|
+
...swaps,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
exports.getTransactionMetadata = getTransactionMetadata;
|
|
101
|
+
/**
|
|
102
|
+
* Adds the given hexadecimal values together.
|
|
103
|
+
*
|
|
104
|
+
* @param values - The hexadecimal values to add together.
|
|
105
|
+
* @returns The sum of the given hexadecimal values.
|
|
106
|
+
*/
|
|
107
|
+
function addHex(...values) {
|
|
108
|
+
const total = new bn_js_1.default(0);
|
|
109
|
+
for (const value of values) {
|
|
110
|
+
if (!value) {
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
total.iadd(new bn_js_1.default((0, utils_1.remove0x)(value), 16));
|
|
114
|
+
}
|
|
115
|
+
return (0, utils_1.add0x)(total.toString(16));
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=transaction.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;;;;AAKA,6EAG0C;AAE1C,2CAAkD;AAClD,kDAAuB;AAEvB,mDAA0D;AAC1D,2CAAkD;AAGlD;;;;;GAKG;AACH,SAAgB,sBAAsB,CACpC,QAA+B;IAE/B,MAAM,EACJ,aAAa,EACb,aAAa,EACb,aAAa,EACb,OAAO,EACP,KAAK,EAAE,QAAQ,E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actionError,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationMetadata } from '../types.js';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n *\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n *\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TransactionMeta } from
|
|
2
|
-
import type { UserOperationMetadata } from
|
|
1
|
+
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
2
|
+
import type { UserOperationMetadata } from "../types.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Converts a user operation metadata object into a transaction metadata object.
|
|
5
5
|
*
|
|
@@ -7,4 +7,4 @@ import type { UserOperationMetadata } from '../types.js';
|
|
|
7
7
|
* @returns The equivalent transaction metadata object.
|
|
8
8
|
*/
|
|
9
9
|
export declare function getTransactionMetadata(metadata: UserOperationMetadata): TransactionMeta | undefined;
|
|
10
|
-
//# sourceMappingURL=transaction.d.
|
|
10
|
+
//# sourceMappingURL=transaction.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAoB;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TransactionMeta } from "@metamask/transaction-controller";
|
|
2
|
+
import type { UserOperationMetadata } from "../types.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Converts a user operation metadata object into a transaction metadata object.
|
|
5
|
+
*
|
|
6
|
+
* @param metadata - The user operation metadata object to convert.
|
|
7
|
+
* @returns The equivalent transaction metadata object.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getTransactionMetadata(metadata: UserOperationMetadata): TransactionMeta | undefined;
|
|
10
|
+
//# sourceMappingURL=transaction.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAEhB,yCAAyC;AAW1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,qBAAoB;AAEzD;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,qBAAqB,GAC9B,eAAe,GAAG,SAAS,CA0H7B"}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
function $importDefault(module) {
|
|
2
|
+
if (module?.__esModule) {
|
|
3
|
+
return module.default;
|
|
4
|
+
}
|
|
5
|
+
return module;
|
|
6
|
+
}
|
|
7
|
+
import { TransactionStatus, UserFeeLevel } from "@metamask/transaction-controller";
|
|
8
|
+
import { add0x, remove0x } from "@metamask/utils";
|
|
9
|
+
import $BN from "bn.js";
|
|
10
|
+
const BN = $importDefault($BN);
|
|
11
|
+
import { EMPTY_BYTES, VALUE_ZERO } from "../constants.mjs";
|
|
12
|
+
import { UserOperationStatus } from "../types.mjs";
|
|
6
13
|
/**
|
|
7
14
|
* Converts a user operation metadata object into a transaction metadata object.
|
|
8
15
|
*
|
|
@@ -107,4 +114,4 @@ function addHex(...values) {
|
|
|
107
114
|
}
|
|
108
115
|
return add0x(total.toString(16));
|
|
109
116
|
}
|
|
110
|
-
//# sourceMappingURL=transaction.
|
|
117
|
+
//# sourceMappingURL=transaction.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transaction.mjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;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AM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,SAAS;QACX,CAAC;QAED,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACnC,CAAC","sourcesContent":["import type {\n TransactionError,\n TransactionMeta,\n TransactionParams,\n} from '@metamask/transaction-controller';\nimport {\n TransactionStatus,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { add0x, remove0x } from '@metamask/utils';\nimport BN from 'bn.js';\n\nimport { EMPTY_BYTES, VALUE_ZERO } from '../constants.js';\nimport { UserOperationStatus } from '../types.js';\nimport type { UserOperationMetadata } from '../types.js';\n\n/**\n * Converts a user operation metadata object into a transaction metadata object.\n *\n * @param metadata - The user operation metadata object to convert.\n * @returns The equivalent transaction metadata object.\n */\nexport function getTransactionMetadata(\n metadata: UserOperationMetadata,\n): TransactionMeta | undefined {\n const {\n actualGasCost,\n actualGasUsed,\n baseFeePerGas,\n chainId,\n error: rawError,\n origin,\n transactionHash,\n id,\n swapsMetadata,\n time,\n transactionParams,\n transactionType,\n userFeeLevel: rawUserFeeLevel,\n userOperation,\n } = metadata;\n\n if (!transactionParams) {\n return undefined;\n }\n\n // effectiveGasPrice = actualGasCost / actualGasUsed\n const effectiveGasPrice =\n actualGasCost && actualGasUsed\n ? add0x(\n new BN(remove0x(actualGasCost), 16)\n .div(new BN(remove0x(actualGasUsed), 16))\n .toString(16),\n )\n : undefined;\n\n const error = (\n rawError\n ? {\n name: rawError.name,\n message: rawError.message,\n stack: rawError.stack,\n code: rawError.code,\n rpc: rawError.rpc,\n }\n : undefined\n ) as TransactionError;\n\n const status: TransactionStatus = {\n [UserOperationStatus.Unapproved]: TransactionStatus.unapproved,\n [UserOperationStatus.Approved]: TransactionStatus.approved,\n [UserOperationStatus.Signed]: TransactionStatus.signed,\n [UserOperationStatus.Submitted]: TransactionStatus.submitted,\n [UserOperationStatus.Confirmed]: TransactionStatus.confirmed,\n [UserOperationStatus.Failed]: TransactionStatus.failed,\n }[metadata.status];\n\n const gas = addHex(\n userOperation.preVerificationGas,\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n );\n\n const hasPaymaster = userOperation.paymasterAndData !== EMPTY_BYTES;\n\n const maxFeePerGas = hasPaymaster ? VALUE_ZERO : userOperation.maxFeePerGas;\n\n const maxPriorityFeePerGas = hasPaymaster\n ? VALUE_ZERO\n : userOperation.maxPriorityFeePerGas;\n\n const nonce =\n userOperation.nonce === EMPTY_BYTES ? undefined : userOperation.nonce;\n\n const txParams = {\n ...transactionParams,\n from: userOperation.sender,\n gas,\n nonce,\n maxFeePerGas,\n maxPriorityFeePerGas,\n } as TransactionParams;\n\n // User operations only support EIP-1559 gas fee properties.\n delete txParams.gasPrice;\n\n const swaps = {\n approvalTxId: swapsMetadata?.approvalTxId ?? undefined,\n destinationTokenAddress:\n swapsMetadata?.destinationTokenAddress ?? undefined,\n destinationTokenAmount: swapsMetadata?.destinationTokenAmount ?? undefined,\n destinationTokenDecimals:\n swapsMetadata?.destinationTokenDecimals ?? undefined,\n destinationTokenSymbol: swapsMetadata?.destinationTokenSymbol ?? undefined,\n estimatedBaseFee: swapsMetadata?.estimatedBaseFee ?? undefined,\n sourceTokenAddress: swapsMetadata?.sourceTokenAddress ?? undefined,\n sourceTokenAmount: swapsMetadata?.sourceTokenAmount ?? undefined,\n sourceTokenDecimals: swapsMetadata?.sourceTokenDecimals ?? undefined,\n sourceTokenSymbol: swapsMetadata?.sourceTokenSymbol ?? undefined,\n swapAndSendRecipient: swapsMetadata?.swapAndSendRecipient ?? undefined,\n swapMetaData: swapsMetadata?.swapMetaData ?? undefined,\n swapTokenValue: swapsMetadata?.swapTokenValue ?? undefined,\n };\n\n const userFeeLevel = hasPaymaster ? UserFeeLevel.CUSTOM : rawUserFeeLevel;\n\n return {\n baseFeePerGas: (baseFeePerGas as Hex) ?? undefined,\n chainId: chainId as Hex,\n error,\n hash: transactionHash ?? undefined,\n id,\n isUserOperation: true,\n networkClientId: 'user-operation',\n origin,\n status,\n time,\n txParams,\n txReceipt: {\n effectiveGasPrice: effectiveGasPrice ?? undefined,\n gasUsed: actualGasUsed ?? undefined,\n },\n type: transactionType ?? undefined,\n userFeeLevel: userFeeLevel as string,\n ...swaps,\n };\n}\n\n/**\n * Adds the given hexadecimal values together.\n *\n * @param values - The hexadecimal values to add together.\n * @returns The sum of the given hexadecimal values.\n */\nfunction addHex(...values: (string | undefined)[]) {\n const total = new BN(0);\n\n for (const value of values) {\n if (!value) {\n continue;\n }\n\n total.iadd(new BN(remove0x(value), 16));\n }\n\n return add0x(total.toString(16));\n}\n"]}
|