@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":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA0DA;;GAEG;AACH,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,gDAAyB,CAAA;IACzB,4CAAqB,CAAA;IACrB,wCAAiB,CAAA;IACjB,8CAAuB,CAAA;IACvB,wCAAiB,CAAA;IACjB,8CAAuB,CAAA;AACzB,CAAC,EAPW,mBAAmB,mCAAnB,mBAAmB,QAO9B","sourcesContent":["import type {\n TransactionParams,\n TransactionType,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * A complete user operation to be submitted to a bundler.\n * Defined in EIP-4337.\n */\nexport type UserOperation = {\n /** The data to pass to the sender during the main execution call. */\n callData: string;\n\n /** The amount of gas to allocate the main execution call. */\n callGasLimit: string;\n\n /**\n * The initCode of the account.\n * Needed if and only if the account is not yet on-chain and needs to be created.\n */\n initCode: string;\n\n /**\n * Maximum fee per gas.\n * Similar to EIP-1559 max_fee_per_gas.\n */\n maxFeePerGas: string;\n\n /**\n * Maximum priority fee per gas.\n * Similar to EIP-1559 max_priority_fee_per_gas.\n */\n maxPriorityFeePerGas: string;\n\n /** Anti-replay parameter. */\n nonce: string;\n\n /**\n * Address of paymaster sponsoring the transaction, followed by extra data to send to the paymaster.\n * Empty for self-sponsored transactions.\n */\n paymasterAndData: string;\n\n /** The amount of gas to pay to compensate the bundler for pre-verification execution, calldata and any gas overhead that cannot be tracked on-chain. */\n preVerificationGas: string;\n\n /** The account making the operation. */\n sender: string;\n\n /** Data passed into the account along with the nonce during the verification step. */\n signature: string;\n\n /** The amount of gas to allocate for the verification step. */\n verificationGasLimit: string;\n};\n\n/**\n * The possible statuses of a single user operation.\n */\nexport enum UserOperationStatus {\n Unapproved = 'unapproved',\n Approved = 'approved',\n Signed = 'signed',\n Submitted = 'submitted',\n Failed = 'failed',\n Confirmed = 'confirmed',\n}\n\n/** Information concerning an error while creating a user operation. */\nexport type UserOperationError = {\n /**\n * A descriptive error name.\n */\n name: string;\n\n /**\n * A descriptive error message providing details about the encountered error.\n */\n message: string;\n\n /**\n * The stack trace associated with the error, if available.\n */\n stack: string | null;\n\n /**\n * An optional error code associated with the error.\n */\n code: string | null;\n\n /**\n * Additional information related to the error.\n */\n rpc: string | null;\n};\n\n/**\n * Metadata concerning a single user operation, stored in the client state.\n */\nexport type UserOperationMetadata = {\n /** Confirmed total cost of the gas for the user operation. */\n actualGasCost: string | null;\n\n /** Confirmed total amount of gas used by the user operation. */\n actualGasUsed: string | null;\n\n /** Base fee of the transaction block as a hex value. */\n baseFeePerGas: string | null;\n\n /** URL of the bundler that the operation was submitted to. */\n bundlerUrl: string | null;\n\n /** Hexadecimal chain ID of the target network. */\n chainId: string;\n\n /** An error that occurred while creating the operation. */\n error: UserOperationError | null;\n\n /** Hash of the user operation, generated by the bundler. */\n hash: string | null;\n\n /** A unique ID used to identify a user operation in the client. */\n id: string;\n\n /** The origin of the user operation, such as the hostname of a dApp. */\n origin: string;\n\n /** Current status of the user operation. */\n status: UserOperationStatus;\n\n /** Metadata specific to swap transactions. */\n swapsMetadata: SwapsMetadata | null;\n\n /** Timestamp of when the user operation was created. */\n time: number;\n\n /** Hash of the transaction that submitted the user operation to the entrypoint. */\n transactionHash: string | null;\n\n /** The initial transaction parameters that the user operation was created from. */\n transactionParams: Required<TransactionParams> | null;\n\n /** The type of transaction that the user operation will create. */\n transactionType: TransactionType | null;\n\n /** The origin of the gas fee values. */\n userFeeLevel: UserFeeLevel | null;\n\n /** Resulting user operation object to be submitted to the bundler. */\n userOperation: UserOperation;\n};\n\n/**\n * The data provided to the smart contract account when preparing a user operation.\n */\nexport type PrepareUserOperationRequest = {\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n\n /** The data to include in the resulting transaction. */\n data?: string;\n\n /** Address of the account requesting the user operation. */\n from: string;\n\n /** The destination address of the resulting transaction. */\n to?: string;\n\n /** The value to send in the resulting transaction. */\n value?: string;\n};\n\n/**\n * The data provided to the smart contract account when updating a user operation.\n */\nexport type UpdateUserOperationRequest = {\n /** The user operation to update including the dummy signature and dummy paymasterAndData values. */\n userOperation: UserOperation;\n\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n};\n\n/**\n * The data provided to the smart contract account when signing a user operation.\n */\nexport type SignUserOperationRequest = {\n /** The user operation to sign including the dummy signature and final paymasterAndData values. */\n userOperation: UserOperation;\n\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n};\n\n/**\n * The data returned by the smart contract account when preparing a user operation.\n */\nexport type PrepareUserOperationResponse = {\n /** The URL of the bundler to submit the user operation to. */\n bundler: string;\n\n /** The data to pass to the sender during the main execution call. */\n callData: string;\n\n /**\n * A dummy paymasterAndData value required to estimate gas using the bundler.\n * Only required if the smart contract account is not providing gas values.\n */\n dummyPaymasterAndData?: string;\n\n /**\n * A dummy signature value required to estimate gas using the bundler.\n * Only required if the smart contract account is not providing gas values.\n */\n dummySignature?: string;\n\n /**\n * The estimated gas limits for the user operation.\n * Gas is automatically estimated using the bundler if not provided.\n */\n gas?: {\n /** The amount of gas to allocate to the main execution call. */\n callGasLimit: string;\n\n /** The amount of gas to pay to compensate the bundler for pre-verification execution, calldata and any gas overhead that cannot be tracked on-chain. */\n preVerificationGas: string;\n\n /** The amount of gas to allocate for the verification step. */\n verificationGasLimit: string;\n };\n\n /**\n * The initCode to include in the user operation.\n * Required only if the smart contract is not yet deployed.\n */\n initCode?: string;\n\n /**\n * The nonce to include in the user operation, specific to the smart contract account.\n */\n nonce: string;\n\n /**\n * The address of the smart contract account creating the user operation.\n */\n sender: string;\n};\n\n/**\n * The data returned by the smart contract account when updating a user operation.\n */\nexport type UpdateUserOperationResponse = {\n /**\n * The final paymasterAndData to include in the user operation.\n * Not required if a paymaster is not sponsoring the transaction.\n */\n paymasterAndData?: string;\n\n /**\n * The final gas limits for the user operation suggested by the smart contract account.\n * The simulated gas limits may be different after the bundler estimates gas with the use\n * of the paymaster.\n */\n callGasLimit?: string;\n preVerificationGas?: string;\n verificationGasLimit?: string;\n};\n\n/**\n * The data returned by the smart contract account when signing a user operation.\n */\nexport type SignUserOperationResponse = {\n /** The final signature of the user operation. */\n signature: string;\n};\n\n/**\n * An abstraction to provide smart contract and paymaster specific data when creating a user operation.\n * This will typically communicate with an account snap installed in the client.\n */\nexport type SmartContractAccount = {\n /**\n * Retrieve the initial values required to create a user operation.\n *\n * @param request - The data needed by the smart contract account to provide the initial user operation values.\n * @returns The initial values required to create a user operation.\n */\n prepareUserOperation: (\n request: PrepareUserOperationRequest,\n ) => Promise<PrepareUserOperationResponse>;\n\n /**\n * Retrieve additional data required to create a user operation, such as the paymasterAndData value.\n * If gas values were not provided in the prepare response, this will be called after estimating gas using the bundler.\n *\n * @param request - The data needed by the smart contract account to provide the additional user operation values.\n * @returns The additional values required to create a user operation.\n */\n updateUserOperation: (\n request: UpdateUserOperationRequest,\n ) => Promise<UpdateUserOperationResponse>;\n\n /**\n * Sign the final user operation.\n *\n * @param request - The data needed by the smart contract account to generate the signature.\n * @returns The final values required to sign a user operation.\n */\n signUserOperation: (\n request: SignUserOperationRequest,\n ) => Promise<SignUserOperationResponse>;\n};\n\n/**\n * Response from the `eth_getUserOperationReceipt` bundler method.\n * Includes the status of a completed user operation and the receipt of the transaction that submitted it.\n */\nexport type UserOperationReceipt = {\n /** Confirmed total cost of the gas for the user operation. */\n actualGasCost: Hex | number;\n\n /** Confirmed total amount of gas used by the user operation. */\n actualGasUsed: Hex | number;\n\n /** True if the user operation was successfully confirmed on chain. */\n success: boolean;\n\n /** Receipt for the associated transaction. */\n receipt: {\n /** Hash of the block the transaction was added to. */\n blockHash: string;\n\n /** Hash of the confirmed transaction. */\n transactionHash: string;\n };\n};\n\n/** Information specific to user operations created from swap transactions. */\nexport type SwapsMetadata = {\n /** ID of the associated approval transaction. */\n approvalTxId: string | null;\n\n /** Address of the destination token. */\n destinationTokenAddress: string | null;\n\n /** Number of decimals of the destination token. */\n destinationTokenDecimals: number | null;\n\n /** Symbol of the destination token. */\n destinationTokenSymbol: string | null;\n\n /** Amount of the destination token. */\n destinationTokenAmount: string | null;\n\n /** Estimated base fee of the swap. */\n estimatedBaseFee: string | null;\n\n /** Address of the source token. */\n sourceTokenAddress: string | null;\n\n /** Amount of the source token. */\n sourceTokenAmount: string | null;\n\n /** Number of decimals of the source token. */\n sourceTokenDecimals: number | null;\n\n /** Symbol of the source token. */\n sourceTokenSymbol: string | null;\n\n /** Recipient of the swap and send transaction. */\n swapAndSendRecipient: string | null;\n\n /** Untyped raw metadata values. */\n swapMetaData: Record<string, never> | null;\n\n /** Value of the token being swapped. */\n swapTokenValue: string | null;\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { TransactionParams, TransactionType, UserFeeLevel } from
|
|
2
|
-
import type { Hex } from
|
|
1
|
+
import type { TransactionParams, TransactionType, UserFeeLevel } from "@metamask/transaction-controller";
|
|
2
|
+
import type { Hex } from "@metamask/utils";
|
|
3
3
|
/**
|
|
4
4
|
* A complete user operation to be submitted to a bundler.
|
|
5
5
|
* Defined in EIP-4337.
|
|
@@ -291,4 +291,4 @@ export type SwapsMetadata = {
|
|
|
291
291
|
/** Value of the token being swapped. */
|
|
292
292
|
swapTokenValue: string | null;
|
|
293
293
|
};
|
|
294
|
-
//# sourceMappingURL=types.d.
|
|
294
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,YAAY,EACb,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;;GAGG;AACH,MA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AAI,CAAC;IAEpC,mCAAmC;IACnC,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAC;IAE3C,wCAAwC;IACxC,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import type { TransactionParams, TransactionType, UserFeeLevel } from "@metamask/transaction-controller";
|
|
2
|
+
import type { Hex } from "@metamask/utils";
|
|
3
|
+
/**
|
|
4
|
+
* A complete user operation to be submitted to a bundler.
|
|
5
|
+
* Defined in EIP-4337.
|
|
6
|
+
*/
|
|
7
|
+
export type UserOperation = {
|
|
8
|
+
/** The data to pass to the sender during the main execution call. */
|
|
9
|
+
callData: string;
|
|
10
|
+
/** The amount of gas to allocate the main execution call. */
|
|
11
|
+
callGasLimit: string;
|
|
12
|
+
/**
|
|
13
|
+
* The initCode of the account.
|
|
14
|
+
* Needed if and only if the account is not yet on-chain and needs to be created.
|
|
15
|
+
*/
|
|
16
|
+
initCode: string;
|
|
17
|
+
/**
|
|
18
|
+
* Maximum fee per gas.
|
|
19
|
+
* Similar to EIP-1559 max_fee_per_gas.
|
|
20
|
+
*/
|
|
21
|
+
maxFeePerGas: string;
|
|
22
|
+
/**
|
|
23
|
+
* Maximum priority fee per gas.
|
|
24
|
+
* Similar to EIP-1559 max_priority_fee_per_gas.
|
|
25
|
+
*/
|
|
26
|
+
maxPriorityFeePerGas: string;
|
|
27
|
+
/** Anti-replay parameter. */
|
|
28
|
+
nonce: string;
|
|
29
|
+
/**
|
|
30
|
+
* Address of paymaster sponsoring the transaction, followed by extra data to send to the paymaster.
|
|
31
|
+
* Empty for self-sponsored transactions.
|
|
32
|
+
*/
|
|
33
|
+
paymasterAndData: string;
|
|
34
|
+
/** The amount of gas to pay to compensate the bundler for pre-verification execution, calldata and any gas overhead that cannot be tracked on-chain. */
|
|
35
|
+
preVerificationGas: string;
|
|
36
|
+
/** The account making the operation. */
|
|
37
|
+
sender: string;
|
|
38
|
+
/** Data passed into the account along with the nonce during the verification step. */
|
|
39
|
+
signature: string;
|
|
40
|
+
/** The amount of gas to allocate for the verification step. */
|
|
41
|
+
verificationGasLimit: string;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* The possible statuses of a single user operation.
|
|
45
|
+
*/
|
|
46
|
+
export declare enum UserOperationStatus {
|
|
47
|
+
Unapproved = "unapproved",
|
|
48
|
+
Approved = "approved",
|
|
49
|
+
Signed = "signed",
|
|
50
|
+
Submitted = "submitted",
|
|
51
|
+
Failed = "failed",
|
|
52
|
+
Confirmed = "confirmed"
|
|
53
|
+
}
|
|
54
|
+
/** Information concerning an error while creating a user operation. */
|
|
55
|
+
export type UserOperationError = {
|
|
56
|
+
/**
|
|
57
|
+
* A descriptive error name.
|
|
58
|
+
*/
|
|
59
|
+
name: string;
|
|
60
|
+
/**
|
|
61
|
+
* A descriptive error message providing details about the encountered error.
|
|
62
|
+
*/
|
|
63
|
+
message: string;
|
|
64
|
+
/**
|
|
65
|
+
* The stack trace associated with the error, if available.
|
|
66
|
+
*/
|
|
67
|
+
stack: string | null;
|
|
68
|
+
/**
|
|
69
|
+
* An optional error code associated with the error.
|
|
70
|
+
*/
|
|
71
|
+
code: string | null;
|
|
72
|
+
/**
|
|
73
|
+
* Additional information related to the error.
|
|
74
|
+
*/
|
|
75
|
+
rpc: string | null;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Metadata concerning a single user operation, stored in the client state.
|
|
79
|
+
*/
|
|
80
|
+
export type UserOperationMetadata = {
|
|
81
|
+
/** Confirmed total cost of the gas for the user operation. */
|
|
82
|
+
actualGasCost: string | null;
|
|
83
|
+
/** Confirmed total amount of gas used by the user operation. */
|
|
84
|
+
actualGasUsed: string | null;
|
|
85
|
+
/** Base fee of the transaction block as a hex value. */
|
|
86
|
+
baseFeePerGas: string | null;
|
|
87
|
+
/** URL of the bundler that the operation was submitted to. */
|
|
88
|
+
bundlerUrl: string | null;
|
|
89
|
+
/** Hexadecimal chain ID of the target network. */
|
|
90
|
+
chainId: string;
|
|
91
|
+
/** An error that occurred while creating the operation. */
|
|
92
|
+
error: UserOperationError | null;
|
|
93
|
+
/** Hash of the user operation, generated by the bundler. */
|
|
94
|
+
hash: string | null;
|
|
95
|
+
/** A unique ID used to identify a user operation in the client. */
|
|
96
|
+
id: string;
|
|
97
|
+
/** The origin of the user operation, such as the hostname of a dApp. */
|
|
98
|
+
origin: string;
|
|
99
|
+
/** Current status of the user operation. */
|
|
100
|
+
status: UserOperationStatus;
|
|
101
|
+
/** Metadata specific to swap transactions. */
|
|
102
|
+
swapsMetadata: SwapsMetadata | null;
|
|
103
|
+
/** Timestamp of when the user operation was created. */
|
|
104
|
+
time: number;
|
|
105
|
+
/** Hash of the transaction that submitted the user operation to the entrypoint. */
|
|
106
|
+
transactionHash: string | null;
|
|
107
|
+
/** The initial transaction parameters that the user operation was created from. */
|
|
108
|
+
transactionParams: Required<TransactionParams> | null;
|
|
109
|
+
/** The type of transaction that the user operation will create. */
|
|
110
|
+
transactionType: TransactionType | null;
|
|
111
|
+
/** The origin of the gas fee values. */
|
|
112
|
+
userFeeLevel: UserFeeLevel | null;
|
|
113
|
+
/** Resulting user operation object to be submitted to the bundler. */
|
|
114
|
+
userOperation: UserOperation;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* The data provided to the smart contract account when preparing a user operation.
|
|
118
|
+
*/
|
|
119
|
+
export type PrepareUserOperationRequest = {
|
|
120
|
+
/** The hexadecimal chain ID of the target network. */
|
|
121
|
+
chainId: string;
|
|
122
|
+
/** The data to include in the resulting transaction. */
|
|
123
|
+
data?: string;
|
|
124
|
+
/** Address of the account requesting the user operation. */
|
|
125
|
+
from: string;
|
|
126
|
+
/** The destination address of the resulting transaction. */
|
|
127
|
+
to?: string;
|
|
128
|
+
/** The value to send in the resulting transaction. */
|
|
129
|
+
value?: string;
|
|
130
|
+
};
|
|
131
|
+
/**
|
|
132
|
+
* The data provided to the smart contract account when updating a user operation.
|
|
133
|
+
*/
|
|
134
|
+
export type UpdateUserOperationRequest = {
|
|
135
|
+
/** The user operation to update including the dummy signature and dummy paymasterAndData values. */
|
|
136
|
+
userOperation: UserOperation;
|
|
137
|
+
/** The hexadecimal chain ID of the target network. */
|
|
138
|
+
chainId: string;
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* The data provided to the smart contract account when signing a user operation.
|
|
142
|
+
*/
|
|
143
|
+
export type SignUserOperationRequest = {
|
|
144
|
+
/** The user operation to sign including the dummy signature and final paymasterAndData values. */
|
|
145
|
+
userOperation: UserOperation;
|
|
146
|
+
/** The hexadecimal chain ID of the target network. */
|
|
147
|
+
chainId: string;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* The data returned by the smart contract account when preparing a user operation.
|
|
151
|
+
*/
|
|
152
|
+
export type PrepareUserOperationResponse = {
|
|
153
|
+
/** The URL of the bundler to submit the user operation to. */
|
|
154
|
+
bundler: string;
|
|
155
|
+
/** The data to pass to the sender during the main execution call. */
|
|
156
|
+
callData: string;
|
|
157
|
+
/**
|
|
158
|
+
* A dummy paymasterAndData value required to estimate gas using the bundler.
|
|
159
|
+
* Only required if the smart contract account is not providing gas values.
|
|
160
|
+
*/
|
|
161
|
+
dummyPaymasterAndData?: string;
|
|
162
|
+
/**
|
|
163
|
+
* A dummy signature value required to estimate gas using the bundler.
|
|
164
|
+
* Only required if the smart contract account is not providing gas values.
|
|
165
|
+
*/
|
|
166
|
+
dummySignature?: string;
|
|
167
|
+
/**
|
|
168
|
+
* The estimated gas limits for the user operation.
|
|
169
|
+
* Gas is automatically estimated using the bundler if not provided.
|
|
170
|
+
*/
|
|
171
|
+
gas?: {
|
|
172
|
+
/** The amount of gas to allocate to the main execution call. */
|
|
173
|
+
callGasLimit: string;
|
|
174
|
+
/** The amount of gas to pay to compensate the bundler for pre-verification execution, calldata and any gas overhead that cannot be tracked on-chain. */
|
|
175
|
+
preVerificationGas: string;
|
|
176
|
+
/** The amount of gas to allocate for the verification step. */
|
|
177
|
+
verificationGasLimit: string;
|
|
178
|
+
};
|
|
179
|
+
/**
|
|
180
|
+
* The initCode to include in the user operation.
|
|
181
|
+
* Required only if the smart contract is not yet deployed.
|
|
182
|
+
*/
|
|
183
|
+
initCode?: string;
|
|
184
|
+
/**
|
|
185
|
+
* The nonce to include in the user operation, specific to the smart contract account.
|
|
186
|
+
*/
|
|
187
|
+
nonce: string;
|
|
188
|
+
/**
|
|
189
|
+
* The address of the smart contract account creating the user operation.
|
|
190
|
+
*/
|
|
191
|
+
sender: string;
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* The data returned by the smart contract account when updating a user operation.
|
|
195
|
+
*/
|
|
196
|
+
export type UpdateUserOperationResponse = {
|
|
197
|
+
/**
|
|
198
|
+
* The final paymasterAndData to include in the user operation.
|
|
199
|
+
* Not required if a paymaster is not sponsoring the transaction.
|
|
200
|
+
*/
|
|
201
|
+
paymasterAndData?: string;
|
|
202
|
+
/**
|
|
203
|
+
* The final gas limits for the user operation suggested by the smart contract account.
|
|
204
|
+
* The simulated gas limits may be different after the bundler estimates gas with the use
|
|
205
|
+
* of the paymaster.
|
|
206
|
+
*/
|
|
207
|
+
callGasLimit?: string;
|
|
208
|
+
preVerificationGas?: string;
|
|
209
|
+
verificationGasLimit?: string;
|
|
210
|
+
};
|
|
211
|
+
/**
|
|
212
|
+
* The data returned by the smart contract account when signing a user operation.
|
|
213
|
+
*/
|
|
214
|
+
export type SignUserOperationResponse = {
|
|
215
|
+
/** The final signature of the user operation. */
|
|
216
|
+
signature: string;
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* An abstraction to provide smart contract and paymaster specific data when creating a user operation.
|
|
220
|
+
* This will typically communicate with an account snap installed in the client.
|
|
221
|
+
*/
|
|
222
|
+
export type SmartContractAccount = {
|
|
223
|
+
/**
|
|
224
|
+
* Retrieve the initial values required to create a user operation.
|
|
225
|
+
*
|
|
226
|
+
* @param request - The data needed by the smart contract account to provide the initial user operation values.
|
|
227
|
+
* @returns The initial values required to create a user operation.
|
|
228
|
+
*/
|
|
229
|
+
prepareUserOperation: (request: PrepareUserOperationRequest) => Promise<PrepareUserOperationResponse>;
|
|
230
|
+
/**
|
|
231
|
+
* Retrieve additional data required to create a user operation, such as the paymasterAndData value.
|
|
232
|
+
* If gas values were not provided in the prepare response, this will be called after estimating gas using the bundler.
|
|
233
|
+
*
|
|
234
|
+
* @param request - The data needed by the smart contract account to provide the additional user operation values.
|
|
235
|
+
* @returns The additional values required to create a user operation.
|
|
236
|
+
*/
|
|
237
|
+
updateUserOperation: (request: UpdateUserOperationRequest) => Promise<UpdateUserOperationResponse>;
|
|
238
|
+
/**
|
|
239
|
+
* Sign the final user operation.
|
|
240
|
+
*
|
|
241
|
+
* @param request - The data needed by the smart contract account to generate the signature.
|
|
242
|
+
* @returns The final values required to sign a user operation.
|
|
243
|
+
*/
|
|
244
|
+
signUserOperation: (request: SignUserOperationRequest) => Promise<SignUserOperationResponse>;
|
|
245
|
+
};
|
|
246
|
+
/**
|
|
247
|
+
* Response from the `eth_getUserOperationReceipt` bundler method.
|
|
248
|
+
* Includes the status of a completed user operation and the receipt of the transaction that submitted it.
|
|
249
|
+
*/
|
|
250
|
+
export type UserOperationReceipt = {
|
|
251
|
+
/** Confirmed total cost of the gas for the user operation. */
|
|
252
|
+
actualGasCost: Hex | number;
|
|
253
|
+
/** Confirmed total amount of gas used by the user operation. */
|
|
254
|
+
actualGasUsed: Hex | number;
|
|
255
|
+
/** True if the user operation was successfully confirmed on chain. */
|
|
256
|
+
success: boolean;
|
|
257
|
+
/** Receipt for the associated transaction. */
|
|
258
|
+
receipt: {
|
|
259
|
+
/** Hash of the block the transaction was added to. */
|
|
260
|
+
blockHash: string;
|
|
261
|
+
/** Hash of the confirmed transaction. */
|
|
262
|
+
transactionHash: string;
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
/** Information specific to user operations created from swap transactions. */
|
|
266
|
+
export type SwapsMetadata = {
|
|
267
|
+
/** ID of the associated approval transaction. */
|
|
268
|
+
approvalTxId: string | null;
|
|
269
|
+
/** Address of the destination token. */
|
|
270
|
+
destinationTokenAddress: string | null;
|
|
271
|
+
/** Number of decimals of the destination token. */
|
|
272
|
+
destinationTokenDecimals: number | null;
|
|
273
|
+
/** Symbol of the destination token. */
|
|
274
|
+
destinationTokenSymbol: string | null;
|
|
275
|
+
/** Amount of the destination token. */
|
|
276
|
+
destinationTokenAmount: string | null;
|
|
277
|
+
/** Estimated base fee of the swap. */
|
|
278
|
+
estimatedBaseFee: string | null;
|
|
279
|
+
/** Address of the source token. */
|
|
280
|
+
sourceTokenAddress: string | null;
|
|
281
|
+
/** Amount of the source token. */
|
|
282
|
+
sourceTokenAmount: string | null;
|
|
283
|
+
/** Number of decimals of the source token. */
|
|
284
|
+
sourceTokenDecimals: number | null;
|
|
285
|
+
/** Symbol of the source token. */
|
|
286
|
+
sourceTokenSymbol: string | null;
|
|
287
|
+
/** Recipient of the swap and send transaction. */
|
|
288
|
+
swapAndSendRecipient: string | null;
|
|
289
|
+
/** Untyped raw metadata values. */
|
|
290
|
+
swapMetaData: Record<string, never> | null;
|
|
291
|
+
/** Value of the token being swapped. */
|
|
292
|
+
swapTokenValue: string | null;
|
|
293
|
+
};
|
|
294
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,YAAY,EACb,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,qEAAqE;IACrE,QAAQ,EAAE,MAAM,CAAC;IAEjB,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IAErB;;;OAGG;IACH,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AM,GAAG,IAAI,CAAC;CAC/B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA0DA;;GAEG;AACH,MAAM,CAAN,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,gDAAyB,CAAA;IACzB,4CAAqB,CAAA;IACrB,wCAAiB,CAAA;IACjB,8CAAuB,CAAA;IACvB,wCAAiB,CAAA;IACjB,8CAAuB,CAAA;AACzB,CAAC,EAPW,mBAAmB,KAAnB,mBAAmB,QAO9B","sourcesContent":["import type {\n TransactionParams,\n TransactionType,\n UserFeeLevel,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * A complete user operation to be submitted to a bundler.\n * Defined in EIP-4337.\n */\nexport type UserOperation = {\n /** The data to pass to the sender during the main execution call. */\n callData: string;\n\n /** The amount of gas to allocate the main execution call. */\n callGasLimit: string;\n\n /**\n * The initCode of the account.\n * Needed if and only if the account is not yet on-chain and needs to be created.\n */\n initCode: string;\n\n /**\n * Maximum fee per gas.\n * Similar to EIP-1559 max_fee_per_gas.\n */\n maxFeePerGas: string;\n\n /**\n * Maximum priority fee per gas.\n * Similar to EIP-1559 max_priority_fee_per_gas.\n */\n maxPriorityFeePerGas: string;\n\n /** Anti-replay parameter. */\n nonce: string;\n\n /**\n * Address of paymaster sponsoring the transaction, followed by extra data to send to the paymaster.\n * Empty for self-sponsored transactions.\n */\n paymasterAndData: string;\n\n /** The amount of gas to pay to compensate the bundler for pre-verification execution, calldata and any gas overhead that cannot be tracked on-chain. */\n preVerificationGas: string;\n\n /** The account making the operation. */\n sender: string;\n\n /** Data passed into the account along with the nonce during the verification step. */\n signature: string;\n\n /** The amount of gas to allocate for the verification step. */\n verificationGasLimit: string;\n};\n\n/**\n * The possible statuses of a single user operation.\n */\nexport enum UserOperationStatus {\n Unapproved = 'unapproved',\n Approved = 'approved',\n Signed = 'signed',\n Submitted = 'submitted',\n Failed = 'failed',\n Confirmed = 'confirmed',\n}\n\n/** Information concerning an error while creating a user operation. */\nexport type UserOperationError = {\n /**\n * A descriptive error name.\n */\n name: string;\n\n /**\n * A descriptive error message providing details about the encountered error.\n */\n message: string;\n\n /**\n * The stack trace associated with the error, if available.\n */\n stack: string | null;\n\n /**\n * An optional error code associated with the error.\n */\n code: string | null;\n\n /**\n * Additional information related to the error.\n */\n rpc: string | null;\n};\n\n/**\n * Metadata concerning a single user operation, stored in the client state.\n */\nexport type UserOperationMetadata = {\n /** Confirmed total cost of the gas for the user operation. */\n actualGasCost: string | null;\n\n /** Confirmed total amount of gas used by the user operation. */\n actualGasUsed: string | null;\n\n /** Base fee of the transaction block as a hex value. */\n baseFeePerGas: string | null;\n\n /** URL of the bundler that the operation was submitted to. */\n bundlerUrl: string | null;\n\n /** Hexadecimal chain ID of the target network. */\n chainId: string;\n\n /** An error that occurred while creating the operation. */\n error: UserOperationError | null;\n\n /** Hash of the user operation, generated by the bundler. */\n hash: string | null;\n\n /** A unique ID used to identify a user operation in the client. */\n id: string;\n\n /** The origin of the user operation, such as the hostname of a dApp. */\n origin: string;\n\n /** Current status of the user operation. */\n status: UserOperationStatus;\n\n /** Metadata specific to swap transactions. */\n swapsMetadata: SwapsMetadata | null;\n\n /** Timestamp of when the user operation was created. */\n time: number;\n\n /** Hash of the transaction that submitted the user operation to the entrypoint. */\n transactionHash: string | null;\n\n /** The initial transaction parameters that the user operation was created from. */\n transactionParams: Required<TransactionParams> | null;\n\n /** The type of transaction that the user operation will create. */\n transactionType: TransactionType | null;\n\n /** The origin of the gas fee values. */\n userFeeLevel: UserFeeLevel | null;\n\n /** Resulting user operation object to be submitted to the bundler. */\n userOperation: UserOperation;\n};\n\n/**\n * The data provided to the smart contract account when preparing a user operation.\n */\nexport type PrepareUserOperationRequest = {\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n\n /** The data to include in the resulting transaction. */\n data?: string;\n\n /** Address of the account requesting the user operation. */\n from: string;\n\n /** The destination address of the resulting transaction. */\n to?: string;\n\n /** The value to send in the resulting transaction. */\n value?: string;\n};\n\n/**\n * The data provided to the smart contract account when updating a user operation.\n */\nexport type UpdateUserOperationRequest = {\n /** The user operation to update including the dummy signature and dummy paymasterAndData values. */\n userOperation: UserOperation;\n\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n};\n\n/**\n * The data provided to the smart contract account when signing a user operation.\n */\nexport type SignUserOperationRequest = {\n /** The user operation to sign including the dummy signature and final paymasterAndData values. */\n userOperation: UserOperation;\n\n /** The hexadecimal chain ID of the target network. */\n chainId: string;\n};\n\n/**\n * The data returned by the smart contract account when preparing a user operation.\n */\nexport type PrepareUserOperationResponse = {\n /** The URL of the bundler to submit the user operation to. */\n bundler: string;\n\n /** The data to pass to the sender during the main execution call. */\n callData: string;\n\n /**\n * A dummy paymasterAndData value required to estimate gas using the bundler.\n * Only required if the smart contract account is not providing gas values.\n */\n dummyPaymasterAndData?: string;\n\n /**\n * A dummy signature value required to estimate gas using the bundler.\n * Only required if the smart contract account is not providing gas values.\n */\n dummySignature?: string;\n\n /**\n * The estimated gas limits for the user operation.\n * Gas is automatically estimated using the bundler if not provided.\n */\n gas?: {\n /** The amount of gas to allocate to the main execution call. */\n callGasLimit: string;\n\n /** The amount of gas to pay to compensate the bundler for pre-verification execution, calldata and any gas overhead that cannot be tracked on-chain. */\n preVerificationGas: string;\n\n /** The amount of gas to allocate for the verification step. */\n verificationGasLimit: string;\n };\n\n /**\n * The initCode to include in the user operation.\n * Required only if the smart contract is not yet deployed.\n */\n initCode?: string;\n\n /**\n * The nonce to include in the user operation, specific to the smart contract account.\n */\n nonce: string;\n\n /**\n * The address of the smart contract account creating the user operation.\n */\n sender: string;\n};\n\n/**\n * The data returned by the smart contract account when updating a user operation.\n */\nexport type UpdateUserOperationResponse = {\n /**\n * The final paymasterAndData to include in the user operation.\n * Not required if a paymaster is not sponsoring the transaction.\n */\n paymasterAndData?: string;\n\n /**\n * The final gas limits for the user operation suggested by the smart contract account.\n * The simulated gas limits may be different after the bundler estimates gas with the use\n * of the paymaster.\n */\n callGasLimit?: string;\n preVerificationGas?: string;\n verificationGasLimit?: string;\n};\n\n/**\n * The data returned by the smart contract account when signing a user operation.\n */\nexport type SignUserOperationResponse = {\n /** The final signature of the user operation. */\n signature: string;\n};\n\n/**\n * An abstraction to provide smart contract and paymaster specific data when creating a user operation.\n * This will typically communicate with an account snap installed in the client.\n */\nexport type SmartContractAccount = {\n /**\n * Retrieve the initial values required to create a user operation.\n *\n * @param request - The data needed by the smart contract account to provide the initial user operation values.\n * @returns The initial values required to create a user operation.\n */\n prepareUserOperation: (\n request: PrepareUserOperationRequest,\n ) => Promise<PrepareUserOperationResponse>;\n\n /**\n * Retrieve additional data required to create a user operation, such as the paymasterAndData value.\n * If gas values were not provided in the prepare response, this will be called after estimating gas using the bundler.\n *\n * @param request - The data needed by the smart contract account to provide the additional user operation values.\n * @returns The additional values required to create a user operation.\n */\n updateUserOperation: (\n request: UpdateUserOperationRequest,\n ) => Promise<UpdateUserOperationResponse>;\n\n /**\n * Sign the final user operation.\n *\n * @param request - The data needed by the smart contract account to generate the signature.\n * @returns The final values required to sign a user operation.\n */\n signUserOperation: (\n request: SignUserOperationRequest,\n ) => Promise<SignUserOperationResponse>;\n};\n\n/**\n * Response from the `eth_getUserOperationReceipt` bundler method.\n * Includes the status of a completed user operation and the receipt of the transaction that submitted it.\n */\nexport type UserOperationReceipt = {\n /** Confirmed total cost of the gas for the user operation. */\n actualGasCost: Hex | number;\n\n /** Confirmed total amount of gas used by the user operation. */\n actualGasUsed: Hex | number;\n\n /** True if the user operation was successfully confirmed on chain. */\n success: boolean;\n\n /** Receipt for the associated transaction. */\n receipt: {\n /** Hash of the block the transaction was added to. */\n blockHash: string;\n\n /** Hash of the confirmed transaction. */\n transactionHash: string;\n };\n};\n\n/** Information specific to user operations created from swap transactions. */\nexport type SwapsMetadata = {\n /** ID of the associated approval transaction. */\n approvalTxId: string | null;\n\n /** Address of the destination token. */\n destinationTokenAddress: string | null;\n\n /** Number of decimals of the destination token. */\n destinationTokenDecimals: number | null;\n\n /** Symbol of the destination token. */\n destinationTokenSymbol: string | null;\n\n /** Amount of the destination token. */\n destinationTokenAmount: string | null;\n\n /** Estimated base fee of the swap. */\n estimatedBaseFee: string | null;\n\n /** Address of the source token. */\n sourceTokenAddress: string | null;\n\n /** Amount of the source token. */\n sourceTokenAmount: string | null;\n\n /** Number of decimals of the source token. */\n sourceTokenDecimals: number | null;\n\n /** Symbol of the source token. */\n sourceTokenSymbol: string | null;\n\n /** Recipient of the swap and send transaction. */\n swapAndSendRecipient: string | null;\n\n /** Untyped raw metadata values. */\n swapMetaData: Record<string, never> | null;\n\n /** Value of the token being swapped. */\n swapTokenValue: string | null;\n};\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.toEip155ChainId = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Converts a chain ID string to a compliant CAIP-2 chain ID reference for EIP-155 chains.
|
|
6
|
+
*
|
|
7
|
+
* @param chainId - Chain ID string
|
|
8
|
+
* @returns An CAIP-2 chain ID reference for EIP-155 chains.
|
|
9
|
+
*/
|
|
10
|
+
function toEip155ChainId(chainId) {
|
|
11
|
+
const chainIdNumber = Number(chainId);
|
|
12
|
+
// If for some reason the chainId isn't convertible to a decimal integer representation, we fallback
|
|
13
|
+
// to the initial `chainId`.
|
|
14
|
+
return Number.isInteger(chainIdNumber) ? chainIdNumber.toString() : chainId;
|
|
15
|
+
}
|
|
16
|
+
exports.toEip155ChainId = toEip155ChainId;
|
|
17
|
+
//# sourceMappingURL=chain-id.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-id.cjs","sourceRoot":"","sources":["../../src/utils/chain-id.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,OAAe;IAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEtC,oGAAoG;IACpG,4BAA4B;IAC5B,OAAO,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AAC9E,CAAC;AAND,0CAMC","sourcesContent":["/**\n * Converts a chain ID string to a compliant CAIP-2 chain ID reference for EIP-155 chains.\n *\n * @param chainId - Chain ID string\n * @returns An CAIP-2 chain ID reference for EIP-155 chains.\n */\nexport function toEip155ChainId(chainId: string): string {\n const chainIdNumber = Number(chainId);\n\n // If for some reason the chainId isn't convertible to a decimal integer representation, we fallback\n // to the initial `chainId`.\n return Number.isInteger(chainIdNumber) ? chainIdNumber.toString() : chainId;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-id.d.cts","sourceRoot":"","sources":["../../src/utils/chain-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMvD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a chain ID string to a compliant CAIP-2 chain ID reference for EIP-155 chains.
|
|
3
|
+
*
|
|
4
|
+
* @param chainId - Chain ID string
|
|
5
|
+
* @returns An CAIP-2 chain ID reference for EIP-155 chains.
|
|
6
|
+
*/
|
|
7
|
+
export declare function toEip155ChainId(chainId: string): string;
|
|
8
|
+
//# sourceMappingURL=chain-id.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-id.d.mts","sourceRoot":"","sources":["../../src/utils/chain-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAMvD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain-id.mjs","sourceRoot":"","sources":["../../src/utils/chain-id.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,MAAM,aAAa,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IAEtC,oGAAoG;IACpG,4BAA4B;IAC5B,OAAO,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;AAC9E,CAAC","sourcesContent":["/**\n * Converts a chain ID string to a compliant CAIP-2 chain ID reference for EIP-155 chains.\n *\n * @param chainId - Chain ID string\n * @returns An CAIP-2 chain ID reference for EIP-155 chains.\n */\nexport function toEip155ChainId(chainId: string): string {\n const chainIdNumber = Number(chainId);\n\n // If for some reason the chainId isn't convertible to a decimal integer representation, we fallback\n // to the initial `chainId`.\n return Number.isInteger(chainIdNumber) ? chainIdNumber.toString() : chainId;\n}\n"]}
|
|
@@ -0,0 +1,194 @@
|
|
|
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.updateGasFees = void 0;
|
|
7
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
8
|
+
const eth_query_1 = __importDefault(require("@metamask/eth-query"));
|
|
9
|
+
const gas_fee_controller_1 = require("@metamask/gas-fee-controller");
|
|
10
|
+
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
11
|
+
const utils_1 = require("@metamask/utils");
|
|
12
|
+
const constants_js_1 = require("../constants.cjs");
|
|
13
|
+
const logger_js_1 = require("../logger.cjs");
|
|
14
|
+
const log = (0, logger_js_1.createModuleLogger)(logger_js_1.projectLogger, 'gas-fees');
|
|
15
|
+
/**
|
|
16
|
+
* Populates the gas fee properties for a user operation.
|
|
17
|
+
*
|
|
18
|
+
* @param request - The request to update the gas fees.
|
|
19
|
+
* @param request.getGasFeeEstimates - A callback to get gas fee estimates.
|
|
20
|
+
* @param request.metadata - The metadata for the user operation.
|
|
21
|
+
* @param request.originalRequest - The original request to add the user operation.
|
|
22
|
+
* @param request.provider - A provider to query the network.
|
|
23
|
+
* @param request.transaction - The transaction that created the user operation.
|
|
24
|
+
*/
|
|
25
|
+
async function updateGasFees(request) {
|
|
26
|
+
const { metadata, originalRequest, transaction } = request;
|
|
27
|
+
const { userOperation } = metadata;
|
|
28
|
+
let suggestedGasFees;
|
|
29
|
+
const getGasFeeEstimates = async () => {
|
|
30
|
+
if (!suggestedGasFees) {
|
|
31
|
+
suggestedGasFees = await getSuggestedGasFees(request);
|
|
32
|
+
}
|
|
33
|
+
return suggestedGasFees;
|
|
34
|
+
};
|
|
35
|
+
userOperation.maxFeePerGas = await getMaxFeePerGas(originalRequest, getGasFeeEstimates, transaction);
|
|
36
|
+
userOperation.maxPriorityFeePerGas = await getMaxPriorityFeePerGas(originalRequest, getGasFeeEstimates, userOperation, transaction);
|
|
37
|
+
metadata.userFeeLevel = getUserFeeLevel(metadata, originalRequest, suggestedGasFees, transaction);
|
|
38
|
+
}
|
|
39
|
+
exports.updateGasFees = updateGasFees;
|
|
40
|
+
/**
|
|
41
|
+
* Gets the maxFeePerGas for a user operation.
|
|
42
|
+
*
|
|
43
|
+
* @param originalRequest - The original request to add the user operation.
|
|
44
|
+
* @param getGetFasEstimates - A callback to get gas fee estimates.
|
|
45
|
+
* @param transaction - The transaction that created the user operation.
|
|
46
|
+
* @returns The maxFeePerGas for the user operation.
|
|
47
|
+
*/
|
|
48
|
+
async function getMaxFeePerGas(originalRequest, getGetFasEstimates, transaction) {
|
|
49
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;
|
|
50
|
+
const { gasPrice } = transaction ?? {};
|
|
51
|
+
if (!isGasFeeEmpty(maxFeePerGas)) {
|
|
52
|
+
log('Using maxFeePerGas from request', maxFeePerGas);
|
|
53
|
+
return maxFeePerGas;
|
|
54
|
+
}
|
|
55
|
+
if (isGasFeeEmpty(maxPriorityFeePerGas) && gasPrice) {
|
|
56
|
+
log('Setting maxFeePerGas to transaction gasPrice', gasPrice);
|
|
57
|
+
return gasPrice;
|
|
58
|
+
}
|
|
59
|
+
const { maxFeePerGas: suggestedMaxFeePerGas } = await getGetFasEstimates();
|
|
60
|
+
if (!suggestedMaxFeePerGas) {
|
|
61
|
+
throw new Error('Failed to get gas fee estimate for maxFeePerGas');
|
|
62
|
+
}
|
|
63
|
+
log('Using maxFeePerGas from estimate', suggestedMaxFeePerGas);
|
|
64
|
+
return suggestedMaxFeePerGas;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Gets the maxPriorityFeePerGas for a user operation.
|
|
68
|
+
*
|
|
69
|
+
* @param originalRequest - The original request to add the user operation.
|
|
70
|
+
* @param getGetFasEstimates - A callback to get gas fee estimates.
|
|
71
|
+
* @param userOperation - The user operation being updated.
|
|
72
|
+
* @param transaction - The transaction that created the user operation.
|
|
73
|
+
* @returns The maxPriorityFeePerGas for the user operation.
|
|
74
|
+
*/
|
|
75
|
+
async function getMaxPriorityFeePerGas(originalRequest, getGetFasEstimates, userOperation, transaction) {
|
|
76
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;
|
|
77
|
+
const { gasPrice } = transaction ?? {};
|
|
78
|
+
const { maxFeePerGas: updatedMaxFeePerGas } = userOperation;
|
|
79
|
+
if (!isGasFeeEmpty(maxPriorityFeePerGas)) {
|
|
80
|
+
log('Using maxPriorityFeePerGas from request', maxPriorityFeePerGas);
|
|
81
|
+
return maxPriorityFeePerGas;
|
|
82
|
+
}
|
|
83
|
+
if (isGasFeeEmpty(maxFeePerGas) && gasPrice) {
|
|
84
|
+
log('Setting maxPriorityFeePerGas to transaction gasPrice', gasPrice);
|
|
85
|
+
return gasPrice;
|
|
86
|
+
}
|
|
87
|
+
const { maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas } = await getGetFasEstimates();
|
|
88
|
+
if (suggestedMaxPriorityFeePerGas) {
|
|
89
|
+
log('Using maxPriorityFeePerGas from estimate', suggestedMaxPriorityFeePerGas);
|
|
90
|
+
return suggestedMaxPriorityFeePerGas;
|
|
91
|
+
}
|
|
92
|
+
log('Setting maxPriorityFeePerGas to maxFeePerGas', updatedMaxFeePerGas);
|
|
93
|
+
return updatedMaxFeePerGas;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Gets the userFeeLevel for a user operation.
|
|
97
|
+
*
|
|
98
|
+
* @param metadata - The metadata for the user operation.
|
|
99
|
+
* @param originalRequest - The original request to add the user operation.
|
|
100
|
+
* @param suggestedGasFees - The suggested gas fees, if any.
|
|
101
|
+
* @param transaction - The transaction that created the user operation.
|
|
102
|
+
* @returns The userFeeLevel for the user operation.
|
|
103
|
+
*/
|
|
104
|
+
function getUserFeeLevel(metadata, originalRequest, suggestedGasFees, transaction) {
|
|
105
|
+
const { origin } = metadata;
|
|
106
|
+
const { maxFeePerGas, maxPriorityFeePerGas } = originalRequest;
|
|
107
|
+
const { maxFeePerGas: suggestedMaxFeePerGas, maxPriorityFeePerGas: suggestedMaxPriorityFeePerGas, } = suggestedGasFees || {};
|
|
108
|
+
if (isGasFeeEmpty(maxFeePerGas) &&
|
|
109
|
+
isGasFeeEmpty(maxPriorityFeePerGas) &&
|
|
110
|
+
transaction?.gasPrice) {
|
|
111
|
+
return origin === controller_utils_1.ORIGIN_METAMASK
|
|
112
|
+
? transaction_controller_1.UserFeeLevel.CUSTOM
|
|
113
|
+
: transaction_controller_1.UserFeeLevel.DAPP_SUGGESTED;
|
|
114
|
+
}
|
|
115
|
+
if (isGasFeeEmpty(maxFeePerGas) &&
|
|
116
|
+
isGasFeeEmpty(maxPriorityFeePerGas) &&
|
|
117
|
+
suggestedMaxFeePerGas &&
|
|
118
|
+
suggestedMaxPriorityFeePerGas) {
|
|
119
|
+
return transaction_controller_1.UserFeeLevel.MEDIUM;
|
|
120
|
+
}
|
|
121
|
+
if (origin === controller_utils_1.ORIGIN_METAMASK) {
|
|
122
|
+
return transaction_controller_1.UserFeeLevel.CUSTOM;
|
|
123
|
+
}
|
|
124
|
+
return transaction_controller_1.UserFeeLevel.DAPP_SUGGESTED;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets suggested gas fees.
|
|
128
|
+
*
|
|
129
|
+
* @param request - The request to update the gas fees.
|
|
130
|
+
* @param request.getGasFeeEstimates - A callback to get gas fee estimates.
|
|
131
|
+
* @param request.provider - A provider to query the network.
|
|
132
|
+
* @returns The suggested gas fees.
|
|
133
|
+
*/
|
|
134
|
+
async function getSuggestedGasFees(request) {
|
|
135
|
+
const { getGasFeeEstimates, provider } = request;
|
|
136
|
+
try {
|
|
137
|
+
const { gasFeeEstimates, gasEstimateType } = await getGasFeeEstimates();
|
|
138
|
+
if (gasEstimateType === gas_fee_controller_1.GAS_ESTIMATE_TYPES.FEE_MARKET) {
|
|
139
|
+
/* istanbul ignore next */
|
|
140
|
+
const { medium: { suggestedMaxPriorityFeePerGas, suggestedMaxFeePerGas } = {}, } = gasFeeEstimates;
|
|
141
|
+
if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {
|
|
142
|
+
const values = {
|
|
143
|
+
maxFeePerGas: gweiDecimalToWeiHex(suggestedMaxFeePerGas),
|
|
144
|
+
maxPriorityFeePerGas: gweiDecimalToWeiHex(suggestedMaxPriorityFeePerGas),
|
|
145
|
+
};
|
|
146
|
+
log('Using medium values from fee market estimate', values);
|
|
147
|
+
return values;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (gasEstimateType === gas_fee_controller_1.GAS_ESTIMATE_TYPES.LEGACY) {
|
|
151
|
+
const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.medium);
|
|
152
|
+
log('Using medium value from legacy estimate', maxFeePerGas);
|
|
153
|
+
return {
|
|
154
|
+
maxFeePerGas,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
if (gasEstimateType === gas_fee_controller_1.GAS_ESTIMATE_TYPES.ETH_GASPRICE) {
|
|
158
|
+
const maxFeePerGas = gweiDecimalToWeiHex(gasFeeEstimates.gasPrice);
|
|
159
|
+
log('Using gasPrice from estimate', maxFeePerGas);
|
|
160
|
+
return {
|
|
161
|
+
maxFeePerGas,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
log('Failed to get estimate', error);
|
|
167
|
+
}
|
|
168
|
+
const gasPriceDecimal = (await (0, controller_utils_1.query)(new eth_query_1.default(provider), 'gasPrice'));
|
|
169
|
+
if (!gasPriceDecimal) {
|
|
170
|
+
return {};
|
|
171
|
+
}
|
|
172
|
+
const maxFeePerGas = (0, utils_1.add0x)(gasPriceDecimal.toString(16));
|
|
173
|
+
log('Using gasPrice from network as fallback', maxFeePerGas);
|
|
174
|
+
return { maxFeePerGas };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Converts a GWEI decimal string to a WEI hexadecimal string.
|
|
178
|
+
*
|
|
179
|
+
* @param value - The GWEI decimal string to convert.
|
|
180
|
+
* @returns The WEI hexadecimal string.
|
|
181
|
+
*/
|
|
182
|
+
function gweiDecimalToWeiHex(value) {
|
|
183
|
+
return (0, controller_utils_1.toHex)((0, controller_utils_1.gweiDecToWEIBN)(value));
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Checks if a gas fee property is empty.
|
|
187
|
+
*
|
|
188
|
+
* @param value - The gas fee value to check.
|
|
189
|
+
* @returns Whether the gas fee property is empty.
|
|
190
|
+
*/
|
|
191
|
+
function isGasFeeEmpty(value) {
|
|
192
|
+
return !value || value === constants_js_1.EMPTY_BYTES;
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=gas-fees.cjs.map
|