@metamask/transaction-pay-controller 23.16.0 → 23.17.0
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 +19 -1
- package/dist/strategy/fiat/chomp.cjs +58 -0
- package/dist/strategy/fiat/chomp.cjs.map +1 -0
- package/dist/strategy/fiat/chomp.d.cts +9 -0
- package/dist/strategy/fiat/chomp.d.cts.map +1 -0
- package/dist/strategy/fiat/chomp.d.mts +9 -0
- package/dist/strategy/fiat/chomp.d.mts.map +1 -0
- package/dist/strategy/fiat/chomp.mjs +54 -0
- package/dist/strategy/fiat/chomp.mjs.map +1 -0
- package/dist/strategy/fiat/fiat-direct-musd.cjs +50 -3
- package/dist/strategy/fiat/fiat-direct-musd.cjs.map +1 -1
- package/dist/strategy/fiat/fiat-direct-musd.d.cts +7 -2
- package/dist/strategy/fiat/fiat-direct-musd.d.cts.map +1 -1
- package/dist/strategy/fiat/fiat-direct-musd.d.mts +7 -2
- package/dist/strategy/fiat/fiat-direct-musd.d.mts.map +1 -1
- package/dist/strategy/fiat/fiat-direct-musd.mjs +50 -3
- package/dist/strategy/fiat/fiat-direct-musd.mjs.map +1 -1
- package/dist/strategy/fiat/fiat-submit.cjs +29 -3
- package/dist/strategy/fiat/fiat-submit.cjs.map +1 -1
- package/dist/strategy/fiat/fiat-submit.d.cts.map +1 -1
- package/dist/strategy/fiat/fiat-submit.d.mts.map +1 -1
- package/dist/strategy/fiat/fiat-submit.mjs +29 -3
- package/dist/strategy/fiat/fiat-submit.mjs.map +1 -1
- package/dist/strategy/fiat/utils.cjs +9 -4
- package/dist/strategy/fiat/utils.cjs.map +1 -1
- package/dist/strategy/fiat/utils.d.cts +20 -2
- package/dist/strategy/fiat/utils.d.cts.map +1 -1
- package/dist/strategy/fiat/utils.d.mts +20 -2
- package/dist/strategy/fiat/utils.d.mts.map +1 -1
- package/dist/strategy/fiat/utils.mjs +9 -4
- package/dist/strategy/fiat/utils.mjs.map +1 -1
- package/dist/tests/messenger-mock.d.cts +9 -1
- package/dist/tests/messenger-mock.d.cts.map +1 -1
- package/dist/tests/messenger-mock.d.mts +9 -1
- package/dist/tests/messenger-mock.d.mts.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -2
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/transaction.cjs +11 -8
- package/dist/utils/transaction.cjs.map +1 -1
- package/dist/utils/transaction.d.cts +16 -4
- package/dist/utils/transaction.d.cts.map +1 -1
- package/dist/utils/transaction.d.mts +16 -4
- package/dist/utils/transaction.d.mts.map +1 -1
- package/dist/utils/transaction.mjs +11 -8
- package/dist/utils/transaction.mjs.map +1 -1
- package/package.json +2 -2
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA2OA;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAwB;IAChE,aAAa;IACb,iBAAiB;IACjB,eAAe;CAChB,CAAC","sourcesContent":["import type {\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerStateChangeEvent,\n} from '@metamask/assets-controller';\nimport type {\n CurrencyRateControllerGetStateAction,\n CurrencyRateStateChange,\n TokenBalancesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type { TokenRatesControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { TokenRatesControllerStateChangeEvent } from '@metamask/assets-controllers';\nimport type {\n TokensControllerGetStateAction,\n TokensControllerStateChangeEvent,\n} from '@metamask/assets-controllers';\nimport type { AccountTrackerControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { ControllerStateChangeEvent } from '@metamask/base-controller';\nimport type { ControllerGetStateAction } from '@metamask/base-controller';\nimport type { BridgeControllerFetchQuotesAction } from '@metamask/bridge-controller';\nimport type { BridgeStatusControllerStateChangeEvent } from '@metamask/bridge-status-controller';\nimport type {\n BridgeStatusControllerGetStateAction,\n BridgeStatusControllerSubmitTxAction,\n} from '@metamask/bridge-status-controller';\nimport type { GetGasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerSignTypedMessageAction,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { NetworkControllerFindNetworkClientIdByChainIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkConfigurationByChainIdAction } from '@metamask/network-controller';\nimport type { Quote as RampsQuote } from '@metamask/ramps-controller';\nimport type {\n RampsControllerGetOrderAction,\n RampsControllerGetQuotesAction,\n} from '@metamask/ramps-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type {\n AuthorizationList,\n TransactionControllerAddTransactionBatchAction,\n TransactionControllerEstimateGasAction,\n TransactionControllerEstimateGasBatchAction,\n TransactionControllerUnapprovedTransactionAddedEvent,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransaction,\n BatchTransactionParams,\n TransactionControllerAddTransactionAction,\n TransactionControllerGetGasFeeTokensAction,\n TransactionControllerGetStateAction,\n TransactionControllerStateChangeEvent,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport type {\n CONTROLLER_NAME,\n PaymentOverride,\n TransactionPayStrategy,\n} from './constants';\nimport type { TransactionPayControllerMethodActions } from './TransactionPayController-method-action-types';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | AssetsControllerGetStateForTransactionPayAction\n | BridgeControllerFetchQuotesAction\n | BridgeStatusControllerGetStateAction\n | BridgeStatusControllerSubmitTxAction\n | CurrencyRateControllerGetStateAction\n | GetGasFeeState\n | KeyringControllerGetStateAction\n | KeyringControllerSignTypedMessageAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetNetworkConfigurationByChainIdAction\n | RampsControllerGetOrderAction\n | RampsControllerGetQuotesAction\n | RemoteFeatureFlagControllerGetStateAction\n | TokenBalancesControllerGetStateAction\n | TokenRatesControllerGetStateAction\n | TokensControllerGetStateAction\n | TransactionControllerAddTransactionAction\n | TransactionControllerAddTransactionBatchAction\n | TransactionControllerEstimateGasAction\n | TransactionControllerEstimateGasBatchAction\n | TransactionControllerGetGasFeeTokensAction\n | TransactionControllerGetStateAction\n | TransactionControllerUpdateTransactionAction;\n\nexport type AllowedEvents =\n | AssetsControllerStateChangeEvent\n | BridgeStatusControllerStateChangeEvent\n | CurrencyRateStateChange\n | TokenRatesControllerStateChangeEvent\n | TokensControllerStateChangeEvent\n | TransactionControllerStateChangeEvent\n | TransactionControllerUnapprovedTransactionAddedEvent;\n\nexport type TransactionPayControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n>;\n\n/** Configurable properties of a transaction. */\nexport type TransactionConfig = {\n /**\n * Optional address to override the default account used by the transaction.\n * When `isPostQuote` is true, used as the recipient of the MM Pay transfer.\n * When `isPostQuote` is false, it provides the funds and pays for gas.\n */\n accountOverride?: Hex;\n\n /**\n * Whether the source of funds is HyperLiquid (HyperCore).\n * When true, the Relay strategy uses the HyperLiquid 2-step withdrawal\n * flow: (1) authorize nonce-mapping, (2) sendAsset to Relay solver.\n */\n isHyperliquidSource?: boolean;\n\n /** Whether the source of funds is a Polymarket deposit wallet. */\n isPolymarketDepositWallet?: boolean;\n\n /** Whether the user has selected the maximum amount. */\n isMaxAmount?: boolean;\n\n /**\n * Whether this is a post-quote transaction.\n * When true, the paymentToken represents the destination token,\n * and the quote source is derived from the transaction's output token.\n */\n isPostQuote?: boolean;\n\n /** Overrides the payment source for the transaction. */\n paymentOverride?: PaymentOverride;\n\n /** When true, a quote is always fetched even when the source and target tokens are identical. */\n isQuoteRequired?: boolean;\n\n /**\n * Optional address to receive refunds if the quote provider transaction fails.\n * When set, overrides the default refund recipient (EOA) in the quote\n * request. Use this for post-quote flows where the user's funds originate\n * from a smart contract account (e.g. Predict Safe proxy) so that refunds\n * go back to that account rather than the EOA.\n */\n refundTo?: Hex;\n};\n\n/** Callback to update transaction config. */\nexport type TransactionConfigCallback = (config: TransactionConfig) => void;\n\n/** Request passed to {@link GetPaymentOverrideDataCallback}. */\nexport type GetPaymentOverrideDataRequest = {\n /** Amount of the source token in human-readable format. */\n amount: string;\n\n /** Metadata of the original transaction. */\n transaction: TransactionMeta;\n\n /** Pay-controller state for the transaction. */\n transactionData: TransactionData;\n};\n\n/** Response returned by {@link GetPaymentOverrideDataCallback}. */\nexport type GetPaymentOverrideDataResponse = {\n /** Batch transaction params to prepend to the submit batch. */\n calls: BatchTransactionParams[];\n\n /** Optional recipient address for the funding token transfer. */\n recipient?: Hex;\n\n /** Optional EIP-7702 authorization list from delegation. */\n authorizationList?: AuthorizationList;\n};\n\n/**\n * Callback invoked during submit when `paymentOverride` is defined.\n * Returns batch transaction params to prepend to the submit batch.\n */\nexport type GetPaymentOverrideDataCallback = (\n request: GetPaymentOverrideDataRequest,\n) => Promise<GetPaymentOverrideDataResponse>;\n\nexport type GetAmountDataRequest = {\n /** Raw token amount (atomic units) to encode into calldata. */\n amount: string;\n\n /** Metadata of the transaction whose nested calls need updating. */\n transaction: TransactionMeta;\n};\n\nexport type GetAmountDataResponse = {\n /** Per-nested-call data updates; empty when no update is needed. */\n updates: { nestedTransactionIndex: number; data: Hex }[];\n};\n\n/**\n * Optional callback that re-encodes nested transaction calldata for a given\n * token amount. Used by transaction types with non-standard nested data\n * (e.g. vault approve + deposit) that cannot be derived from the amount alone\n * without client-side context (vault config, RPC providers, etc.).\n */\nexport type GetAmountDataCallback = (\n request: GetAmountDataRequest,\n) => Promise<GetAmountDataResponse>;\n\n/** Callback to update fiat payment state. */\nexport type TransactionFiatPaymentCallback = (\n fiatPayment: TransactionFiatPayment,\n) => void;\n\nexport type TransactionPayControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n >;\n\nexport type TransactionPayControllerActions =\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerMethodActions;\n\nexport type TransactionPayControllerEvents =\n TransactionPayControllerStateChangeEvent;\n\nexport type TransactionPayControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n TransactionPayControllerActions | AllowedActions,\n TransactionPayControllerEvents | AllowedEvents\n>;\n\n/**\n * Keyring types that support EIP-7702 authorization signing.\n * Hardware wallets, snap keyrings, and custody keyrings are excluded.\n */\nexport const KEYRING_TYPES_SUPPORTING_7702: `${KeyringTypes}`[] = [\n 'HD Key Tree',\n 'Simple Key Pair',\n 'Money Keyring',\n];\n\n/** Options for the TransactionPayController. */\nexport type TransactionPayControllerOptions = {\n /** Optional callback to re-encode nested transaction calldata for a given amount. */\n getAmountData?: GetAmountDataCallback;\n\n /** Callback to convert a transaction into a redeem delegation. */\n getDelegationTransaction: GetDelegationTransactionCallback;\n\n /** Optional fiat execution configuration. */\n fiatOptions?: TransactionPayFiatOptions;\n\n /**\n * Optional callback invoked during quote execution when `paymentOverride` is defined.\n * Returns additional transactions to be submitted alongside the quote batch.\n */\n getPaymentOverrideData?: GetPaymentOverrideDataCallback;\n\n /** Callback to select the PayStrategy for a transaction. */\n getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;\n\n /** Callback to select ordered PayStrategies for a transaction. */\n getStrategies?: (transaction: TransactionMeta) => TransactionPayStrategy[];\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Callbacks for the Polymarket relayer; required only for the Polymarket deposit-wallet flow. */\n polymarket?: PolymarketCallbacks;\n\n /** Initial state of the controller. */\n state?: Partial<TransactionPayControllerState>;\n};\n\n/** State of the TransactionPayController. */\nexport type TransactionPayControllerState = {\n /** State relating to each transaction, keyed by transaction ID. */\n transactionData: Record<string, TransactionData>;\n};\n\n/** Optional fiat execution configuration. */\nexport type TransactionPayFiatOptions = {\n /** Test funding source used to bypass fiat on-ramp execution during local QA. */\n testFundingSource?: Hex;\n\n /** Optional human amount to transfer from the test funding source. */\n testAmountOverride?: string;\n};\n\n/** State relating to a single transaction. */\nexport type TransactionData = {\n /**\n * Optional address to override the default account used by the transaction.\n * When `isPostQuote` is true, used as the recipient of the MM Pay transfer.\n * When `isPostQuote` is false, it provides the funds and pays for gas.\n */\n accountOverride?: Hex;\n\n /** Fiat payment method state. */\n fiatPayment?: TransactionFiatPayment;\n\n /** Whether quotes are currently being retrieved. */\n isLoading: boolean;\n\n /** Whether the user has selected the maximum amount. */\n isMaxAmount?: boolean;\n\n /**\n * Whether this is a post-quote transaction.\n * When true, the paymentToken represents the destination token,\n * and the quote source is derived from the transaction's output token.\n * Used when funds need to be moved after a transaction completes\n * (e.g., bridging output to a different token/chain).\n */\n isPostQuote?: boolean;\n\n /** Whether the source of funds is HyperLiquid (HyperCore). */\n isHyperliquidSource?: boolean;\n\n /** Whether the source of funds is a Polymarket deposit wallet. */\n isPolymarketDepositWallet?: boolean;\n\n /** Overrides the payment source for the transaction. */\n paymentOverride?: PaymentOverride;\n\n /** When true, a quote is always fetched even when the source and target tokens are identical. */\n isQuoteRequired?: boolean;\n\n /**\n * Optional address to receive refunds if the quote provider transaction fails.\n * When set, overrides the default refund recipient (EOA) in the quote\n * request.\n */\n refundTo?: Hex;\n\n /**\n * Token selected for the transaction.\n * - For standard flows (isPostQuote=false): This is the SOURCE/payment token\n * - For post-quote flows (isPostQuote=true): This is the DESTINATION token\n */\n paymentToken?: TransactionPaymentToken;\n\n /** Quotes retrieved for the transaction. */\n quotes?: TransactionPayQuote<Json>[];\n\n /** Timestamp of when quotes were last updated. */\n quotesLastUpdated?: number;\n\n /** Amounts of payment token required for each required token. */\n sourceAmounts?: TransactionPaySourceAmount[];\n\n /** Tokens required by the transaction. */\n tokens: TransactionPayRequiredToken[];\n\n /** Calculated totals for the transaction. */\n totals?: TransactionPayTotals;\n};\n\n/** Fiat payment state stored per transaction. */\nexport type TransactionFiatPayment = {\n /** Entered fiat amount for the selected payment method. */\n amountFiat?: string;\n\n /** CAIP-19 asset id derived from the transaction type for the fiat on-ramp. */\n caipAssetId?: string;\n\n /** Order identifier in normalized format (/providers/{provider}/orders/{id}). */\n orderId?: string;\n\n /** The ramps quote received from the ramps provider. */\n rampsQuote?: RampsQuote;\n\n /** Selected fiat payment method ID. */\n selectedPaymentMethodId?: string;\n};\n\n/** A token required by a transaction. */\nexport type TransactionPayRequiredToken = {\n /** Address of the required token. */\n address: Hex;\n\n /** Whether to allow quotes that return less than the minimum amount requested. */\n allowUnderMinimum: boolean;\n\n /** Amount required in the selected currency. */\n amountFiat: string;\n\n /** Amount required in a human-readable format factoring token decimals. */\n amountHuman: string;\n\n /** Amount required in atomic format without factoring token decimals. */\n amountRaw: string;\n\n /** Amount required in USD. */\n amountUsd: string;\n\n /** Balance of the required token in the selected currency. */\n balanceFiat: string;\n\n /** Balance of the required token in a human-readable format factoring token decimals. */\n balanceHuman: string;\n\n /** Balance of the required token in atomic format without factoring token decimals. */\n balanceRaw: string;\n\n /** Balance of the required token in USD. */\n balanceUsd: string;\n\n /** Chain ID of the required token. */\n chainId: Hex;\n\n /** Decimals of the required token. */\n decimals: number;\n\n /** Whether to skip transfer of this token if balance is already sufficient. */\n skipIfBalance: boolean;\n\n /** Symbol of the required token. */\n symbol: string;\n};\n\n/** Amount of payment token required by a required token. */\nexport type TransactionPaySourceAmount = {\n /** Amount of payment token required in the selected currency. */\n sourceAmountHuman: string;\n\n /** Amount of payment token required in atomic format without factoring token decimals. */\n sourceAmountRaw: string;\n\n /** Balance of the source token in atomic format (for post-quote flows). */\n sourceBalanceRaw?: string;\n\n /** Chain ID of the source token (for post-quote flows). */\n sourceChainId?: Hex;\n\n /** Address of the source token (for post-quote flows). */\n sourceTokenAddress?: Hex;\n\n /** Address of the target token. */\n targetTokenAddress: Hex;\n};\n\n/** Source token used to pay for required tokens. */\nexport type TransactionPaymentToken = {\n /** Address of the payment token. */\n address: Hex;\n\n /** Balance of the payment token in the selected currency. */\n balanceFiat: string;\n\n /** Balance of the payment token in a human-readable format factoring token decimals. */\n balanceHuman: string;\n\n /** Balance of the payment token in atomic format without factoring token decimals. */\n balanceRaw: string;\n\n /** Balance of the payment token in USD. */\n balanceUsd: string;\n\n /** Chain ID of the payment token. */\n chainId: Hex;\n\n /** Decimals of the payment token. */\n decimals: number;\n\n /** Symbol of the payment token. */\n symbol: string;\n};\n\n/** Callback to update state for a single transaction. */\nexport type UpdateTransactionDataCallback = (\n /** ID of the transaction to update. */\n transactionId: string,\n /** Function that receives a draft of the transaction data to update. */\n fn: (data: Draft<TransactionData>) => void,\n) => void;\n\n/** Conversion rates from the native currency to other currencies. */\nexport type FiatRates = {\n /** Conversion rate for the native currency to the selected fiat currency. */\n fiatRate: string;\n\n /** Conversion rate for the native currency to USD. */\n usdRate: string;\n};\n\n/** Request for a quote to retrieve a required token. */\nexport type QuoteRequest = {\n /** Address of the user's account. */\n from: Hex;\n\n /** Whether the transaction is a maximum amount transaction. */\n isMaxAmount?: boolean;\n\n /** Whether this is a post-quote flow. */\n isPostQuote?: boolean;\n\n /** Whether the source of funds is HyperLiquid (HyperCore). */\n isHyperliquidSource?: boolean;\n\n /** Whether the source of funds is a Polymarket deposit wallet. */\n isPolymarketDepositWallet?: boolean;\n\n /** Whether this quote is the direct mUSD-to-Money-Account fiat flow. */\n isDirectMusdMoneyAccount?: boolean;\n\n /** Overrides the payment source for the transaction. */\n paymentOverride?: PaymentOverride;\n\n /** Optional recipient address for Relay requests. When set, overrides the default `from` address. */\n recipient?: Hex;\n\n /**\n * Optional address to receive refunds if the quote provider transaction fails.\n * When set, overrides the default refund recipient (EOA) in the quote\n * request.\n */\n refundTo?: Hex;\n\n /** Whether to skip processTransactions in relay-quotes. Defaults to `isPostQuote`. */\n skipProcessTransactions?: boolean;\n\n /** Balance of the source token in atomic format without factoring token decimals. */\n sourceBalanceRaw: string;\n\n /** Chain ID of the source token. */\n sourceChainId: Hex;\n\n /** Address of the source token. */\n sourceTokenAddress: Hex;\n\n /** Amount of the required token in atomic format without factoring token decimals. */\n sourceTokenAmount: string;\n\n /** Minimum amount required of the target token in atomic format without factoring token decimals. */\n targetAmountMinimum: string;\n\n /** Chain ID of the target token. */\n targetChainId: Hex;\n\n /** Address of the target token. */\n targetTokenAddress: Hex;\n\n /**\n * One-time HyperLiquid activation fee (USD) reserved from the source amount\n * for an unactivated HyperCore account. The source amount sent to the\n * provider is reduced by this amount so HyperLiquid retains enough balance\n * for the fee, and the amount is surfaced as part of the provider fee.\n */\n hyperliquidActivationFeeUsd?: string;\n};\n\n/** Fees associated with a transaction pay quote. */\nexport type TransactionPayFees = {\n /** Whether a gas fee token is used to pay source network fees. */\n isSourceGasFeeToken?: boolean;\n\n /** Whether a gas fee token is used to pay target network fees. */\n isTargetGasFeeToken?: boolean;\n\n /** Fee charged by MetaMask. */\n metaMask: FiatValue;\n\n /** Fee charged by the quote provider. */\n provider: FiatValue;\n\n /** Fee charged by fiat on-ramp provider (breakdown of the provider total). */\n providerFiat?: FiatValue;\n\n /** Network fee for transactions on the source network. */\n sourceNetwork: {\n estimate: Amount;\n max: Amount;\n };\n\n /** Network fee for transactions on the target network. */\n targetNetwork: FiatValue;\n};\n\n/** Quote returned to retrieve a required token using the payment token. */\nexport type TransactionPayQuote<OriginalQuote> = {\n /** Additional amount provided by the quote beyond the minimum requested. */\n dust: FiatValue;\n\n /** Duration estimated for the transaction to complete in seconds. */\n estimatedDuration: number;\n\n /** Fees associated with the transaction pay quote. */\n fees: TransactionPayFees;\n\n /** Raw quote data returned by the provider. */\n original: OriginalQuote;\n\n /** Associated quote request. */\n request: QuoteRequest;\n\n /** Amount of source token required. */\n sourceAmount: Amount;\n\n /** Name of the strategy used to retrieve the quote. */\n strategy: TransactionPayStrategy;\n\n /** Amount of target token provided. */\n targetAmount: FiatValue;\n};\n\n/** Request to get quotes for a transaction. */\nexport type PayStrategyGetQuotesRequest = {\n /** Whether the account supports EIP-7702 authorization signing. */\n accountSupports7702: boolean;\n\n /** Selected fiat payment method ID, if applicable. */\n fiatPaymentMethod?: string;\n\n /**\n * Resolved wallet address for the transaction.\n * This is `accountOverride ?? txParams.from`, pre-computed by the quote\n * orchestrator so that individual strategies do not need to re-derive it.\n */\n from: Hex;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quote requests for required tokens. */\n requests: QuoteRequest[];\n\n /**\n * Signal that aborts when a newer quote request supersedes this one.\n * Strategies that perform their own network IO should forward this to\n * their fetch calls so cancelled requests release network resources.\n */\n signal?: AbortSignal;\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to submit quotes for a transaction. */\nexport type PayStrategyExecuteRequest<OriginalRequest> = {\n /** Whether the account supports EIP-7702 authorization signing. */\n accountSupports7702: boolean;\n\n /** Callback to determine if the transaction is a smart transaction. */\n isSmartTransaction: (chainId: Hex) => boolean;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes to be submitted. */\n quotes: TransactionPayQuote<OriginalRequest>[];\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to get batch transactions for quotes. */\nexport type PayStrategyGetBatchRequest<OriginalQuote> = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes for required tokens. */\n quotes: TransactionPayQuote<OriginalQuote>[];\n\n /** Signal that aborts when a newer quote request supersedes this one. */\n signal?: AbortSignal;\n};\n\n/** Request to check whether retrieved quotes can be executed by a strategy. */\nexport type PayStrategyCheckQuoteSupportRequest<OriginalQuote> = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes returned by the strategy. */\n quotes: TransactionPayQuote<OriginalQuote>[];\n\n /** Signal that aborts when a newer quote request supersedes this one. */\n signal?: AbortSignal;\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to get refresh interval for a specific strategy. */\nexport type PayStrategyGetRefreshIntervalRequest = {\n /** Chain ID of the source or payment token. */\n chainId: Hex;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n};\n\n/** Strategy used to obtain required tokens for a transaction. */\nexport type PayStrategy<OriginalQuote> = {\n /**\n * Check if the strategy supports the given request.\n * Defaults to true if not implemented.\n */\n supports?: (\n request: PayStrategyGetQuotesRequest,\n ) => boolean | Promise<boolean>;\n\n /** Retrieve quotes for required tokens. */\n getQuotes: (\n request: PayStrategyGetQuotesRequest,\n ) => Promise<TransactionPayQuote<OriginalQuote>[]>;\n\n /**\n * Check if the returned quotes are supported after provider quote\n * construction and gas planning.\n *\n * Use this for limitations that are only knowable once quote metadata is\n * available, such as whether execution will require an EIP-7702\n * authorization list.\n */\n checkQuoteSupport?: (\n request: PayStrategyCheckQuoteSupportRequest<OriginalQuote>,\n ) => boolean | Promise<boolean>;\n\n /** Retrieve batch transactions for quotes, if supported by the strategy. */\n getBatchTransactions?: (\n request: PayStrategyGetBatchRequest<OriginalQuote>,\n ) => Promise<BatchTransaction[]>;\n\n /**\n * Retrieve refresh interval for the strategy, if applicable.\n * Defaults to 30 seconds.\n */\n getRefreshInterval?: (\n request: PayStrategyGetRefreshIntervalRequest,\n ) => Promise<number | undefined>;\n\n /** Execute or submit the quotes to obtain required tokens. */\n execute: (request: PayStrategyExecuteRequest<OriginalQuote>) => Promise<{\n transactionHash?: Hex;\n }>;\n};\n\n/** Single fiat value in alternate currencies. */\nexport type FiatValue = {\n /** Value in the selected fiat currency. */\n fiat: string;\n\n /** Value in USD. */\n usd: string;\n};\n\n/** Calculated totals for a target transaction and all quotes. */\nexport type TransactionPayTotals = {\n /** Total estimated duration for the target transaction and all quotes. */\n estimatedDuration: number;\n\n /** Total fees for the target transaction and all quotes. */\n fees: TransactionPayFees;\n\n /** Total amount of source token required. */\n sourceAmount: Amount;\n\n /** Total amount of target token provided. */\n targetAmount: FiatValue;\n\n /** Overall total cost for the target transaction and all quotes. */\n total: FiatValue;\n};\n\n/** Request to update the payment token for a transaction. */\nexport type UpdatePaymentTokenRequest = {\n /** ID of the transaction to update. */\n transactionId: string;\n\n /** Address of the new payment token. */\n tokenAddress: Hex;\n\n /** Chain ID of the new payment token. */\n chainId: Hex;\n};\n\n/** Request to update fiat payment state for a transaction. */\nexport type UpdateFiatPaymentRequest = {\n /** ID of the transaction to update. */\n transactionId: string;\n\n /** Callback to mutate fiat payment state. */\n callback: TransactionFiatPaymentCallback;\n};\n\n/** Callback to convert a transaction to a redeem delegation. */\nexport type GetDelegationTransactionCallback = ({\n transaction,\n}: {\n transaction: TransactionMeta;\n}) => Promise<{\n authorizationList?: AuthorizationList;\n data: Hex;\n to: Hex;\n value: Hex;\n}>;\n\n/** Client-supplied callbacks for the Polymarket relayer protocol. */\nexport type PolymarketCallbacks = {\n /** Derive the deposit-wallet address (CREATE2) for the given EOA. */\n getDepositWalletAddress: (params: { eoa: Hex }) => Promise<Hex>;\n\n /** Sign and broadcast a deposit-wallet batch, returning the source hash. */\n submitDepositWalletBatch: (params: {\n eoa: Hex;\n depositWallet: Hex;\n calls: { target: Hex; data: Hex; value: string }[];\n }) => Promise<{ sourceHash: Hex }>;\n};\n\n/** Single amount in alternate formats. */\nexport type Amount = FiatValue & {\n /** Amount in human-readable format factoring token decimals. */\n human: string;\n\n /** Amount in atomic format without factoring token decimals. */\n raw: string;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AA6OA;;;GAGG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAwB;IAChE,aAAa;IACb,iBAAiB;IACjB,eAAe;CAChB,CAAC","sourcesContent":["import type {\n AssetsControllerGetStateForTransactionPayAction,\n AssetsControllerStateChangeEvent,\n} from '@metamask/assets-controller';\nimport type {\n CurrencyRateControllerGetStateAction,\n CurrencyRateStateChange,\n TokenBalancesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type { TokenRatesControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { TokenRatesControllerStateChangeEvent } from '@metamask/assets-controllers';\nimport type {\n TokensControllerGetStateAction,\n TokensControllerStateChangeEvent,\n} from '@metamask/assets-controllers';\nimport type { AccountTrackerControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { ControllerStateChangeEvent } from '@metamask/base-controller';\nimport type { ControllerGetStateAction } from '@metamask/base-controller';\nimport type { BridgeControllerFetchQuotesAction } from '@metamask/bridge-controller';\nimport type { BridgeStatusControllerStateChangeEvent } from '@metamask/bridge-status-controller';\nimport type {\n BridgeStatusControllerGetStateAction,\n BridgeStatusControllerSubmitTxAction,\n} from '@metamask/bridge-status-controller';\nimport type { GetGasFeeState } from '@metamask/gas-fee-controller';\nimport type {\n KeyringControllerGetStateAction,\n KeyringControllerSignTypedMessageAction,\n KeyringControllerUnlockEvent,\n KeyringTypes,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { NetworkControllerFindNetworkClientIdByChainIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkConfigurationByChainIdAction } from '@metamask/network-controller';\nimport type { Quote as RampsQuote } from '@metamask/ramps-controller';\nimport type {\n RampsControllerGetOrderAction,\n RampsControllerGetQuotesAction,\n} from '@metamask/ramps-controller';\nimport type { RemoteFeatureFlagControllerGetStateAction } from '@metamask/remote-feature-flag-controller';\nimport type {\n AuthorizationList,\n TransactionControllerAddTransactionBatchAction,\n TransactionControllerEstimateGasAction,\n TransactionControllerEstimateGasBatchAction,\n TransactionControllerUnapprovedTransactionAddedEvent,\n} from '@metamask/transaction-controller';\nimport type {\n BatchTransaction,\n BatchTransactionParams,\n TransactionControllerAddTransactionAction,\n TransactionControllerGetGasFeeTokensAction,\n TransactionControllerGetStateAction,\n TransactionControllerStateChangeEvent,\n TransactionControllerUpdateTransactionAction,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\nimport type { Draft } from 'immer';\n\nimport type {\n CONTROLLER_NAME,\n PaymentOverride,\n TransactionPayStrategy,\n} from './constants';\nimport type { TransactionPayControllerMethodActions } from './TransactionPayController-method-action-types';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | AssetsControllerGetStateForTransactionPayAction\n | BridgeControllerFetchQuotesAction\n | BridgeStatusControllerGetStateAction\n | BridgeStatusControllerSubmitTxAction\n | CurrencyRateControllerGetStateAction\n | GetGasFeeState\n | KeyringControllerGetStateAction\n | KeyringControllerSignTypedMessageAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetNetworkConfigurationByChainIdAction\n | RampsControllerGetOrderAction\n | RampsControllerGetQuotesAction\n | RemoteFeatureFlagControllerGetStateAction\n | TokenBalancesControllerGetStateAction\n | TokenRatesControllerGetStateAction\n | TokensControllerGetStateAction\n | TransactionControllerAddTransactionAction\n | TransactionControllerAddTransactionBatchAction\n | TransactionControllerEstimateGasAction\n | TransactionControllerEstimateGasBatchAction\n | TransactionControllerGetGasFeeTokensAction\n | TransactionControllerGetStateAction\n | TransactionControllerUpdateTransactionAction;\n\nexport type AllowedEvents =\n | AssetsControllerStateChangeEvent\n | BridgeStatusControllerStateChangeEvent\n | CurrencyRateStateChange\n | KeyringControllerUnlockEvent\n | TokenRatesControllerStateChangeEvent\n | TokensControllerStateChangeEvent\n | TransactionControllerStateChangeEvent\n | TransactionControllerUnapprovedTransactionAddedEvent;\n\nexport type TransactionPayControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n>;\n\n/** Configurable properties of a transaction. */\nexport type TransactionConfig = {\n /**\n * Optional address to override the default account used by the transaction.\n * When `isPostQuote` is true, used as the recipient of the MM Pay transfer.\n * When `isPostQuote` is false, it provides the funds and pays for gas.\n */\n accountOverride?: Hex;\n\n /**\n * Whether the source of funds is HyperLiquid (HyperCore).\n * When true, the Relay strategy uses the HyperLiquid 2-step withdrawal\n * flow: (1) authorize nonce-mapping, (2) sendAsset to Relay solver.\n */\n isHyperliquidSource?: boolean;\n\n /** Whether the source of funds is a Polymarket deposit wallet. */\n isPolymarketDepositWallet?: boolean;\n\n /** Whether the user has selected the maximum amount. */\n isMaxAmount?: boolean;\n\n /**\n * Whether this is a post-quote transaction.\n * When true, the paymentToken represents the destination token,\n * and the quote source is derived from the transaction's output token.\n */\n isPostQuote?: boolean;\n\n /** Overrides the payment source for the transaction. */\n paymentOverride?: PaymentOverride;\n\n /** When true, a quote is always fetched even when the source and target tokens are identical. */\n isQuoteRequired?: boolean;\n\n /**\n * Optional address to receive refunds if the quote provider transaction fails.\n * When set, overrides the default refund recipient (EOA) in the quote\n * request. Use this for post-quote flows where the user's funds originate\n * from a smart contract account (e.g. Predict Safe proxy) so that refunds\n * go back to that account rather than the EOA.\n */\n refundTo?: Hex;\n};\n\n/** Callback to update transaction config. */\nexport type TransactionConfigCallback = (config: TransactionConfig) => void;\n\n/** Request passed to {@link GetPaymentOverrideDataCallback}. */\nexport type GetPaymentOverrideDataRequest = {\n /** Amount of the source token in human-readable format. */\n amount: string;\n\n /** Metadata of the original transaction. */\n transaction: TransactionMeta;\n\n /** Pay-controller state for the transaction. */\n transactionData: TransactionData;\n};\n\n/** Response returned by {@link GetPaymentOverrideDataCallback}. */\nexport type GetPaymentOverrideDataResponse = {\n /** Batch transaction params to prepend to the submit batch. */\n calls: BatchTransactionParams[];\n\n /** Optional recipient address for the funding token transfer. */\n recipient?: Hex;\n\n /** Optional EIP-7702 authorization list from delegation. */\n authorizationList?: AuthorizationList;\n};\n\n/**\n * Callback invoked during submit when `paymentOverride` is defined.\n * Returns batch transaction params to prepend to the submit batch.\n */\nexport type GetPaymentOverrideDataCallback = (\n request: GetPaymentOverrideDataRequest,\n) => Promise<GetPaymentOverrideDataResponse>;\n\nexport type GetAmountDataRequest = {\n /** Raw token amount (atomic units) to encode into calldata. */\n amount: string;\n\n /** Metadata of the transaction whose nested calls need updating. */\n transaction: TransactionMeta;\n};\n\nexport type GetAmountDataResponse = {\n /** Per-nested-call data updates; empty when no update is needed. */\n updates: { nestedTransactionIndex: number; data: Hex }[];\n};\n\n/**\n * Optional callback that re-encodes nested transaction calldata for a given\n * token amount. Used by transaction types with non-standard nested data\n * (e.g. vault approve + deposit) that cannot be derived from the amount alone\n * without client-side context (vault config, RPC providers, etc.).\n */\nexport type GetAmountDataCallback = (\n request: GetAmountDataRequest,\n) => Promise<GetAmountDataResponse>;\n\n/** Callback to update fiat payment state. */\nexport type TransactionFiatPaymentCallback = (\n fiatPayment: TransactionFiatPayment,\n) => void;\n\nexport type TransactionPayControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n >;\n\nexport type TransactionPayControllerActions =\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerMethodActions;\n\nexport type TransactionPayControllerEvents =\n TransactionPayControllerStateChangeEvent;\n\nexport type TransactionPayControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n TransactionPayControllerActions | AllowedActions,\n TransactionPayControllerEvents | AllowedEvents\n>;\n\n/**\n * Keyring types that support EIP-7702 authorization signing.\n * Hardware wallets, snap keyrings, and custody keyrings are excluded.\n */\nexport const KEYRING_TYPES_SUPPORTING_7702: `${KeyringTypes}`[] = [\n 'HD Key Tree',\n 'Simple Key Pair',\n 'Money Keyring',\n];\n\n/** Options for the TransactionPayController. */\nexport type TransactionPayControllerOptions = {\n /** Optional callback to re-encode nested transaction calldata for a given amount. */\n getAmountData?: GetAmountDataCallback;\n\n /** Callback to convert a transaction into a redeem delegation. */\n getDelegationTransaction: GetDelegationTransactionCallback;\n\n /** Optional fiat execution configuration. */\n fiatOptions?: TransactionPayFiatOptions;\n\n /**\n * Optional callback invoked during quote execution when `paymentOverride` is defined.\n * Returns additional transactions to be submitted alongside the quote batch.\n */\n getPaymentOverrideData?: GetPaymentOverrideDataCallback;\n\n /** Callback to select the PayStrategy for a transaction. */\n getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;\n\n /** Callback to select ordered PayStrategies for a transaction. */\n getStrategies?: (transaction: TransactionMeta) => TransactionPayStrategy[];\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Callbacks for the Polymarket relayer; required only for the Polymarket deposit-wallet flow. */\n polymarket?: PolymarketCallbacks;\n\n /** Initial state of the controller. */\n state?: Partial<TransactionPayControllerState>;\n};\n\n/** State of the TransactionPayController. */\nexport type TransactionPayControllerState = {\n /** State relating to each transaction, keyed by transaction ID. */\n transactionData: Record<string, TransactionData>;\n};\n\n/** Optional fiat execution configuration. */\nexport type TransactionPayFiatOptions = {\n /** Test funding source used to bypass fiat on-ramp execution during local QA. */\n testFundingSource?: Hex;\n\n /** Optional human amount to transfer from the test funding source. */\n testAmountOverride?: string;\n};\n\n/** State relating to a single transaction. */\nexport type TransactionData = {\n /**\n * Optional address to override the default account used by the transaction.\n * When `isPostQuote` is true, used as the recipient of the MM Pay transfer.\n * When `isPostQuote` is false, it provides the funds and pays for gas.\n */\n accountOverride?: Hex;\n\n /** Fiat payment method state. */\n fiatPayment?: TransactionFiatPayment;\n\n /** Whether quotes are currently being retrieved. */\n isLoading: boolean;\n\n /** Whether the user has selected the maximum amount. */\n isMaxAmount?: boolean;\n\n /**\n * Whether this is a post-quote transaction.\n * When true, the paymentToken represents the destination token,\n * and the quote source is derived from the transaction's output token.\n * Used when funds need to be moved after a transaction completes\n * (e.g., bridging output to a different token/chain).\n */\n isPostQuote?: boolean;\n\n /** Whether the source of funds is HyperLiquid (HyperCore). */\n isHyperliquidSource?: boolean;\n\n /** Whether the source of funds is a Polymarket deposit wallet. */\n isPolymarketDepositWallet?: boolean;\n\n /** Overrides the payment source for the transaction. */\n paymentOverride?: PaymentOverride;\n\n /** When true, a quote is always fetched even when the source and target tokens are identical. */\n isQuoteRequired?: boolean;\n\n /**\n * Optional address to receive refunds if the quote provider transaction fails.\n * When set, overrides the default refund recipient (EOA) in the quote\n * request.\n */\n refundTo?: Hex;\n\n /**\n * Token selected for the transaction.\n * - For standard flows (isPostQuote=false): This is the SOURCE/payment token\n * - For post-quote flows (isPostQuote=true): This is the DESTINATION token\n */\n paymentToken?: TransactionPaymentToken;\n\n /** Quotes retrieved for the transaction. */\n quotes?: TransactionPayQuote<Json>[];\n\n /** Timestamp of when quotes were last updated. */\n quotesLastUpdated?: number;\n\n /** Amounts of payment token required for each required token. */\n sourceAmounts?: TransactionPaySourceAmount[];\n\n /** Tokens required by the transaction. */\n tokens: TransactionPayRequiredToken[];\n\n /** Calculated totals for the transaction. */\n totals?: TransactionPayTotals;\n};\n\n/** Fiat payment state stored per transaction. */\nexport type TransactionFiatPayment = {\n /** Entered fiat amount for the selected payment method. */\n amountFiat?: string;\n\n /** CAIP-19 asset id derived from the transaction type for the fiat on-ramp. */\n caipAssetId?: string;\n\n /** Order identifier in normalized format (/providers/{provider}/orders/{id}). */\n orderId?: string;\n\n /** The ramps quote received from the ramps provider. */\n rampsQuote?: RampsQuote;\n\n /** Selected fiat payment method ID. */\n selectedPaymentMethodId?: string;\n};\n\n/** A token required by a transaction. */\nexport type TransactionPayRequiredToken = {\n /** Address of the required token. */\n address: Hex;\n\n /** Whether to allow quotes that return less than the minimum amount requested. */\n allowUnderMinimum: boolean;\n\n /** Amount required in the selected currency. */\n amountFiat: string;\n\n /** Amount required in a human-readable format factoring token decimals. */\n amountHuman: string;\n\n /** Amount required in atomic format without factoring token decimals. */\n amountRaw: string;\n\n /** Amount required in USD. */\n amountUsd: string;\n\n /** Balance of the required token in the selected currency. */\n balanceFiat: string;\n\n /** Balance of the required token in a human-readable format factoring token decimals. */\n balanceHuman: string;\n\n /** Balance of the required token in atomic format without factoring token decimals. */\n balanceRaw: string;\n\n /** Balance of the required token in USD. */\n balanceUsd: string;\n\n /** Chain ID of the required token. */\n chainId: Hex;\n\n /** Decimals of the required token. */\n decimals: number;\n\n /** Whether to skip transfer of this token if balance is already sufficient. */\n skipIfBalance: boolean;\n\n /** Symbol of the required token. */\n symbol: string;\n};\n\n/** Amount of payment token required by a required token. */\nexport type TransactionPaySourceAmount = {\n /** Amount of payment token required in the selected currency. */\n sourceAmountHuman: string;\n\n /** Amount of payment token required in atomic format without factoring token decimals. */\n sourceAmountRaw: string;\n\n /** Balance of the source token in atomic format (for post-quote flows). */\n sourceBalanceRaw?: string;\n\n /** Chain ID of the source token (for post-quote flows). */\n sourceChainId?: Hex;\n\n /** Address of the source token (for post-quote flows). */\n sourceTokenAddress?: Hex;\n\n /** Address of the target token. */\n targetTokenAddress: Hex;\n};\n\n/** Source token used to pay for required tokens. */\nexport type TransactionPaymentToken = {\n /** Address of the payment token. */\n address: Hex;\n\n /** Balance of the payment token in the selected currency. */\n balanceFiat: string;\n\n /** Balance of the payment token in a human-readable format factoring token decimals. */\n balanceHuman: string;\n\n /** Balance of the payment token in atomic format without factoring token decimals. */\n balanceRaw: string;\n\n /** Balance of the payment token in USD. */\n balanceUsd: string;\n\n /** Chain ID of the payment token. */\n chainId: Hex;\n\n /** Decimals of the payment token. */\n decimals: number;\n\n /** Symbol of the payment token. */\n symbol: string;\n};\n\n/** Callback to update state for a single transaction. */\nexport type UpdateTransactionDataCallback = (\n /** ID of the transaction to update. */\n transactionId: string,\n /** Function that receives a draft of the transaction data to update. */\n fn: (data: Draft<TransactionData>) => void,\n) => void;\n\n/** Conversion rates from the native currency to other currencies. */\nexport type FiatRates = {\n /** Conversion rate for the native currency to the selected fiat currency. */\n fiatRate: string;\n\n /** Conversion rate for the native currency to USD. */\n usdRate: string;\n};\n\n/** Request for a quote to retrieve a required token. */\nexport type QuoteRequest = {\n /** Address of the user's account. */\n from: Hex;\n\n /** Whether the transaction is a maximum amount transaction. */\n isMaxAmount?: boolean;\n\n /** Whether this is a post-quote flow. */\n isPostQuote?: boolean;\n\n /** Whether the source of funds is HyperLiquid (HyperCore). */\n isHyperliquidSource?: boolean;\n\n /** Whether the source of funds is a Polymarket deposit wallet. */\n isPolymarketDepositWallet?: boolean;\n\n /** Whether this quote is the direct mUSD-to-Money-Account fiat flow. */\n isDirectMusdMoneyAccount?: boolean;\n\n /** Overrides the payment source for the transaction. */\n paymentOverride?: PaymentOverride;\n\n /** Optional recipient address for Relay requests. When set, overrides the default `from` address. */\n recipient?: Hex;\n\n /**\n * Optional address to receive refunds if the quote provider transaction fails.\n * When set, overrides the default refund recipient (EOA) in the quote\n * request.\n */\n refundTo?: Hex;\n\n /** Whether to skip processTransactions in relay-quotes. Defaults to `isPostQuote`. */\n skipProcessTransactions?: boolean;\n\n /** Balance of the source token in atomic format without factoring token decimals. */\n sourceBalanceRaw: string;\n\n /** Chain ID of the source token. */\n sourceChainId: Hex;\n\n /** Address of the source token. */\n sourceTokenAddress: Hex;\n\n /** Amount of the required token in atomic format without factoring token decimals. */\n sourceTokenAmount: string;\n\n /** Minimum amount required of the target token in atomic format without factoring token decimals. */\n targetAmountMinimum: string;\n\n /** Chain ID of the target token. */\n targetChainId: Hex;\n\n /** Address of the target token. */\n targetTokenAddress: Hex;\n\n /**\n * One-time HyperLiquid activation fee (USD) reserved from the source amount\n * for an unactivated HyperCore account. The source amount sent to the\n * provider is reduced by this amount so HyperLiquid retains enough balance\n * for the fee, and the amount is surfaced as part of the provider fee.\n */\n hyperliquidActivationFeeUsd?: string;\n};\n\n/** Fees associated with a transaction pay quote. */\nexport type TransactionPayFees = {\n /** Whether a gas fee token is used to pay source network fees. */\n isSourceGasFeeToken?: boolean;\n\n /** Whether a gas fee token is used to pay target network fees. */\n isTargetGasFeeToken?: boolean;\n\n /** Fee charged by MetaMask. */\n metaMask: FiatValue;\n\n /** Fee charged by the quote provider. */\n provider: FiatValue;\n\n /** Fee charged by fiat on-ramp provider (breakdown of the provider total). */\n providerFiat?: FiatValue;\n\n /** Network fee for transactions on the source network. */\n sourceNetwork: {\n estimate: Amount;\n max: Amount;\n };\n\n /** Network fee for transactions on the target network. */\n targetNetwork: FiatValue;\n};\n\n/** Quote returned to retrieve a required token using the payment token. */\nexport type TransactionPayQuote<OriginalQuote> = {\n /** Additional amount provided by the quote beyond the minimum requested. */\n dust: FiatValue;\n\n /** Duration estimated for the transaction to complete in seconds. */\n estimatedDuration: number;\n\n /** Fees associated with the transaction pay quote. */\n fees: TransactionPayFees;\n\n /** Raw quote data returned by the provider. */\n original: OriginalQuote;\n\n /** Associated quote request. */\n request: QuoteRequest;\n\n /** Amount of source token required. */\n sourceAmount: Amount;\n\n /** Name of the strategy used to retrieve the quote. */\n strategy: TransactionPayStrategy;\n\n /** Amount of target token provided. */\n targetAmount: FiatValue;\n};\n\n/** Request to get quotes for a transaction. */\nexport type PayStrategyGetQuotesRequest = {\n /** Whether the account supports EIP-7702 authorization signing. */\n accountSupports7702: boolean;\n\n /** Selected fiat payment method ID, if applicable. */\n fiatPaymentMethod?: string;\n\n /**\n * Resolved wallet address for the transaction.\n * This is `accountOverride ?? txParams.from`, pre-computed by the quote\n * orchestrator so that individual strategies do not need to re-derive it.\n */\n from: Hex;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quote requests for required tokens. */\n requests: QuoteRequest[];\n\n /**\n * Signal that aborts when a newer quote request supersedes this one.\n * Strategies that perform their own network IO should forward this to\n * their fetch calls so cancelled requests release network resources.\n */\n signal?: AbortSignal;\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to submit quotes for a transaction. */\nexport type PayStrategyExecuteRequest<OriginalRequest> = {\n /** Whether the account supports EIP-7702 authorization signing. */\n accountSupports7702: boolean;\n\n /** Callback to determine if the transaction is a smart transaction. */\n isSmartTransaction: (chainId: Hex) => boolean;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes to be submitted. */\n quotes: TransactionPayQuote<OriginalRequest>[];\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to get batch transactions for quotes. */\nexport type PayStrategyGetBatchRequest<OriginalQuote> = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes for required tokens. */\n quotes: TransactionPayQuote<OriginalQuote>[];\n\n /** Signal that aborts when a newer quote request supersedes this one. */\n signal?: AbortSignal;\n};\n\n/** Request to check whether retrieved quotes can be executed by a strategy. */\nexport type PayStrategyCheckQuoteSupportRequest<OriginalQuote> = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quotes returned by the strategy. */\n quotes: TransactionPayQuote<OriginalQuote>[];\n\n /** Signal that aborts when a newer quote request supersedes this one. */\n signal?: AbortSignal;\n\n /** Metadata of the original target transaction. */\n transaction: TransactionMeta;\n};\n\n/** Request to get refresh interval for a specific strategy. */\nexport type PayStrategyGetRefreshIntervalRequest = {\n /** Chain ID of the source or payment token. */\n chainId: Hex;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n};\n\n/** Strategy used to obtain required tokens for a transaction. */\nexport type PayStrategy<OriginalQuote> = {\n /**\n * Check if the strategy supports the given request.\n * Defaults to true if not implemented.\n */\n supports?: (\n request: PayStrategyGetQuotesRequest,\n ) => boolean | Promise<boolean>;\n\n /** Retrieve quotes for required tokens. */\n getQuotes: (\n request: PayStrategyGetQuotesRequest,\n ) => Promise<TransactionPayQuote<OriginalQuote>[]>;\n\n /**\n * Check if the returned quotes are supported after provider quote\n * construction and gas planning.\n *\n * Use this for limitations that are only knowable once quote metadata is\n * available, such as whether execution will require an EIP-7702\n * authorization list.\n */\n checkQuoteSupport?: (\n request: PayStrategyCheckQuoteSupportRequest<OriginalQuote>,\n ) => boolean | Promise<boolean>;\n\n /** Retrieve batch transactions for quotes, if supported by the strategy. */\n getBatchTransactions?: (\n request: PayStrategyGetBatchRequest<OriginalQuote>,\n ) => Promise<BatchTransaction[]>;\n\n /**\n * Retrieve refresh interval for the strategy, if applicable.\n * Defaults to 30 seconds.\n */\n getRefreshInterval?: (\n request: PayStrategyGetRefreshIntervalRequest,\n ) => Promise<number | undefined>;\n\n /** Execute or submit the quotes to obtain required tokens. */\n execute: (request: PayStrategyExecuteRequest<OriginalQuote>) => Promise<{\n transactionHash?: Hex;\n }>;\n};\n\n/** Single fiat value in alternate currencies. */\nexport type FiatValue = {\n /** Value in the selected fiat currency. */\n fiat: string;\n\n /** Value in USD. */\n usd: string;\n};\n\n/** Calculated totals for a target transaction and all quotes. */\nexport type TransactionPayTotals = {\n /** Total estimated duration for the target transaction and all quotes. */\n estimatedDuration: number;\n\n /** Total fees for the target transaction and all quotes. */\n fees: TransactionPayFees;\n\n /** Total amount of source token required. */\n sourceAmount: Amount;\n\n /** Total amount of target token provided. */\n targetAmount: FiatValue;\n\n /** Overall total cost for the target transaction and all quotes. */\n total: FiatValue;\n};\n\n/** Request to update the payment token for a transaction. */\nexport type UpdatePaymentTokenRequest = {\n /** ID of the transaction to update. */\n transactionId: string;\n\n /** Address of the new payment token. */\n tokenAddress: Hex;\n\n /** Chain ID of the new payment token. */\n chainId: Hex;\n};\n\n/** Request to update fiat payment state for a transaction. */\nexport type UpdateFiatPaymentRequest = {\n /** ID of the transaction to update. */\n transactionId: string;\n\n /** Callback to mutate fiat payment state. */\n callback: TransactionFiatPaymentCallback;\n};\n\n/** Callback to convert a transaction to a redeem delegation. */\nexport type GetDelegationTransactionCallback = ({\n transaction,\n}: {\n transaction: TransactionMeta;\n}) => Promise<{\n authorizationList?: AuthorizationList;\n data: Hex;\n to: Hex;\n value: Hex;\n}>;\n\n/** Client-supplied callbacks for the Polymarket relayer protocol. */\nexport type PolymarketCallbacks = {\n /** Derive the deposit-wallet address (CREATE2) for the given EOA. */\n getDepositWalletAddress: (params: { eoa: Hex }) => Promise<Hex>;\n\n /** Sign and broadcast a deposit-wallet batch, returning the source hash. */\n submitDepositWalletBatch: (params: {\n eoa: Hex;\n depositWallet: Hex;\n calls: { target: Hex; data: Hex; value: string }[];\n }) => Promise<{ sourceHash: Hex }>;\n};\n\n/** Single amount in alternate formats. */\nexport type Amount = FiatValue & {\n /** Amount in human-readable format factoring token decimals. */\n human: string;\n\n /** Amount in atomic format without factoring token decimals. */\n raw: string;\n};\n"]}
|
|
@@ -215,7 +215,7 @@ const ERC20_TRANSFER_EVENT_TOPIC = erc20Interface.getEventTopic('Transfer');
|
|
|
215
215
|
* For native tokens the amount is resolved via `debug_traceTransaction`
|
|
216
216
|
* (internal-call aware), falling back to the top-level `tx.value`.
|
|
217
217
|
* For ERC-20 tokens the amount is decoded from `Transfer` event logs
|
|
218
|
-
* in the transaction receipt.
|
|
218
|
+
* in the transaction receipt, and the receipt `blockNumber` is also returned.
|
|
219
219
|
*
|
|
220
220
|
* @param options - The options.
|
|
221
221
|
* @param options.messenger - Controller messenger for network access.
|
|
@@ -223,13 +223,13 @@ const ERC20_TRANSFER_EVENT_TOPIC = erc20Interface.getEventTopic('Transfer');
|
|
|
223
223
|
* @param options.chainId - Chain ID where the transaction was executed.
|
|
224
224
|
* @param options.tokenAddress - Address of the transferred token.
|
|
225
225
|
* @param options.walletAddress - Recipient wallet address to filter transfers to.
|
|
226
|
-
* @returns The raw
|
|
227
|
-
* or `undefined` if the amount cannot be determined.
|
|
226
|
+
* @returns The raw transferred amount and, for ERC-20, the receipt block number.
|
|
228
227
|
*/
|
|
229
228
|
async function getTransferredAmountFromTxHash({ messenger, txHash, chainId, tokenAddress, walletAddress, }) {
|
|
230
229
|
const isNative = tokenAddress.toLowerCase() === (0, token_1.getNativeToken)(chainId).toLowerCase();
|
|
231
230
|
if (isNative) {
|
|
232
|
-
|
|
231
|
+
const amountRaw = await getNativeTransferAmount(messenger, chainId, txHash, walletAddress);
|
|
232
|
+
return { amountRaw, blockNumber: undefined };
|
|
233
233
|
}
|
|
234
234
|
return await getErc20TransferAmount(messenger, chainId, txHash, tokenAddress, walletAddress);
|
|
235
235
|
}
|
|
@@ -280,14 +280,16 @@ async function getNativeTransferAmount(messenger, chainId, txHash, walletAddress
|
|
|
280
280
|
}
|
|
281
281
|
/**
|
|
282
282
|
* Resolves the ERC-20 token amount received by a wallet from a transaction
|
|
283
|
-
* by decoding `Transfer` event logs from the transaction receipt.
|
|
283
|
+
* by decoding `Transfer` event logs from the transaction receipt. Also
|
|
284
|
+
* returns the receipt `blockNumber` so callers can reuse it without a
|
|
285
|
+
* second network request.
|
|
284
286
|
*
|
|
285
287
|
* @param messenger - Controller messenger.
|
|
286
288
|
* @param chainId - Chain ID where the transaction was executed.
|
|
287
289
|
* @param txHash - Transaction hash.
|
|
288
290
|
* @param tokenAddress - ERC-20 token contract address.
|
|
289
291
|
* @param walletAddress - Recipient wallet address.
|
|
290
|
-
* @returns Raw amount
|
|
292
|
+
* @returns Raw amount (or `undefined`) and the receipt block number (or `undefined`).
|
|
291
293
|
*/
|
|
292
294
|
async function getErc20TransferAmount(messenger, chainId, txHash, tokenAddress, walletAddress) {
|
|
293
295
|
const receipt = await (0, provider_1.rpcRequest)({
|
|
@@ -297,8 +299,9 @@ async function getErc20TransferAmount(messenger, chainId, txHash, tokenAddress,
|
|
|
297
299
|
params: [txHash],
|
|
298
300
|
});
|
|
299
301
|
if (!receipt) {
|
|
300
|
-
return undefined;
|
|
302
|
+
return { amountRaw: undefined, blockNumber: undefined };
|
|
301
303
|
}
|
|
304
|
+
const { blockNumber } = receipt;
|
|
302
305
|
let total = new bignumber_js_1.BigNumber(0);
|
|
303
306
|
for (const txLog of receipt.logs) {
|
|
304
307
|
if (txLog.address.toLowerCase() !== tokenAddress.toLowerCase()) {
|
|
@@ -319,7 +322,7 @@ async function getErc20TransferAmount(messenger, chainId, txHash, tokenAddress,
|
|
|
319
322
|
continue;
|
|
320
323
|
}
|
|
321
324
|
}
|
|
322
|
-
return positiveOrUndefined(total.toFixed(0));
|
|
325
|
+
return { amountRaw: positiveOrUndefined(total.toFixed(0)), blockNumber };
|
|
323
326
|
}
|
|
324
327
|
/**
|
|
325
328
|
* Recursively walks a `callTracer` result and sums native value
|
|
@@ -1 +1 @@
|
|
|
1
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AG,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAChD,CAAC;QAAC,MAAM,CAAC;YACP,SAAS;QACX,CAAC;IACH,CAAC;IAED,OAAO,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAQD;;;;;;;GAOG;AACH,SAAS,uBAAuB,CAC9B,KAAgB,EAChB,aAAkB;IAElB,IAAI,KAAK,GAAG,IAAI,wBAAS,CAAC,CAAC,CAAC,CAAC;IAE7B,IACE,KAAK,CAAC,EAAE,EAAE,WAAW,EAAE,KAAK,aAAa,CAAC,WAAW,EAAE;QACvD,KAAK,CAAC,KAAK;QACX,KAAK,CAAC,KAAK,KAAK,KAAK,EACrB,CAAC;QACD,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,wBAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAc;IACzC,OAAO,IAAI,wBAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport type { Patch } from 'immer';\nimport { cloneDeep } from 'lodash';\n\nimport { projectLogger } from '../logger';\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayControllerState,\n UpdateTransactionDataCallback,\n} from '../types';\nimport { getAssetsUnifyStateFeature } from './feature-flags';\nimport { rpcRequest } from './provider';\nimport { parseRequiredTokens } from './required-tokens';\nimport { getNativeToken } from './token';\n\nconst log = createModuleLogger(projectLogger, 'transaction');\n\nexport const FINALIZED_STATUSES = [\n TransactionStatus.confirmed,\n TransactionStatus.dropped,\n TransactionStatus.failed,\n];\n\n/**\n * Retrieve transaction metadata by ID.\n *\n * @param transactionId - ID of the transaction to retrieve.\n * @param messenger - Controller messenger.\n * @returns The transaction metadata or undefined if not found.\n */\nexport function getTransaction(\n transactionId: string,\n messenger: TransactionPayControllerMessenger,\n): TransactionMeta | undefined {\n const transactionControllerState = messenger.call(\n 'TransactionController:getState',\n );\n\n return transactionControllerState.transactions.find(\n (tx) => tx.id === transactionId,\n );\n}\n\n/**\n * Subscribe to transaction changes and update the transaction data accordingly.\n *\n * @param messenger - Controller messenger.\n * @param updateTransactionData - Callback to update transaction data.\n * @param removeTransactionData - Callback to remove transaction data.\n */\nexport function subscribeTransactionChanges(\n messenger: TransactionPayControllerMessenger,\n updateTransactionData: UpdateTransactionDataCallback,\n removeTransactionData: (transactionId: string) => void,\n): void {\n messenger.subscribe(\n 'TransactionController:stateChange',\n (\n transactions: TransactionMeta[],\n previousTransactions: TransactionMeta[] | undefined,\n ) => {\n const newTransactions = transactions.filter(\n (tx) => !previousTransactions?.find((prevTx) => prevTx.id === tx.id),\n );\n\n const updatedTransactions = transactions.filter((tx) => {\n const previousTransaction = previousTransactions?.find(\n (prevTx) => prevTx.id === tx.id,\n );\n\n return (\n previousTransaction &&\n previousTransaction?.txParams.data !== tx.txParams.data\n );\n });\n\n const finalizedTransactions = transactions.filter((tx) => {\n const previousTransaction = previousTransactions?.find(\n (prevTx) => prevTx.id === tx.id,\n );\n\n return (\n previousTransaction &&\n !FINALIZED_STATUSES.includes(previousTransaction.status) &&\n FINALIZED_STATUSES.includes(tx.status)\n );\n });\n\n const deletedTransactions = (previousTransactions ?? []).filter(\n (prevTx) => !transactions.find((tx) => tx.id === prevTx.id),\n );\n\n [...finalizedTransactions, ...deletedTransactions].forEach((tx) =>\n onTransactionFinalized(tx, removeTransactionData),\n );\n\n [...newTransactions, ...updatedTransactions].forEach((tx) =>\n onTransactionChange(tx, messenger, updateTransactionData),\n );\n },\n (state) => state.transactions,\n );\n}\n\n/**\n * Subscribe to asset state changes and re-parse required tokens for\n * in-flight transactions whose tokens have not yet resolved.\n *\n * @param messenger - Controller messenger.\n * @param getControllerState - Callback returning the current controller state.\n * @param updateTransactionData - Callback to update transaction data.\n */\nexport function subscribeAssetChanges(\n messenger: TransactionPayControllerMessenger,\n getControllerState: () => TransactionPayControllerState,\n updateTransactionData: UpdateTransactionDataCallback,\n): void {\n const buildHandler =\n (source: string) =>\n (_state: unknown, patches: Patch[] | undefined): void => {\n const { transactionData } = getControllerState();\n\n for (const [transactionId, data] of Object.entries(transactionData)) {\n if (data.tokens.length > 0) {\n continue;\n }\n\n const transaction = getTransaction(transactionId, messenger);\n\n if (!transaction || FINALIZED_STATUSES.includes(transaction.status)) {\n continue;\n }\n\n log('Asset data changed', { transactionId, source, patches });\n\n onTransactionChange(transaction, messenger, updateTransactionData);\n }\n };\n\n if (getAssetsUnifyStateFeature(messenger)) {\n messenger.subscribe(\n 'AssetsController:stateChange',\n buildHandler('AssetsController'),\n );\n return;\n }\n\n messenger.subscribe(\n 'TokensController:stateChange',\n buildHandler('TokensController'),\n );\n messenger.subscribe(\n 'TokenRatesController:stateChange',\n buildHandler('TokenRatesController'),\n );\n messenger.subscribe(\n 'CurrencyRateController:stateChange',\n buildHandler('CurrencyRateController'),\n );\n}\n\n/**\n * Wait for a transaction to be confirmed or fail.\n *\n * @param transactionId - ID of the transaction to wait for.\n * @param messenger - Controller messenger.\n * @returns A promise that resolves when the transaction is confirmed or rejects if it fails.\n */\nexport function waitForTransactionConfirmed(\n transactionId: string,\n messenger: TransactionPayControllerMessenger,\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const isConfirmed = (tx?: TransactionMeta, fn?: () => void): boolean => {\n log('Checking transaction status', tx?.status, tx?.type);\n\n if (tx?.status === TransactionStatus.confirmed) {\n fn?.();\n resolve();\n return true;\n }\n\n if (\n [TransactionStatus.dropped, TransactionStatus.failed].includes(\n tx?.status as TransactionStatus,\n )\n ) {\n fn?.();\n reject(\n new Error(`Transaction failed - ${tx?.type} - ${tx?.error?.message}`),\n );\n return true;\n }\n\n return false;\n };\n\n const initialState = messenger.call('TransactionController:getState');\n\n const initialTx = initialState.transactions.find(\n (singleTransaction) => singleTransaction.id === transactionId,\n );\n\n if (isConfirmed(initialTx)) {\n return;\n }\n\n const handler = (tx?: TransactionMeta): void => {\n const unsubscribe = (): void =>\n messenger.unsubscribe('TransactionController:stateChange', handler);\n\n isConfirmed(tx, unsubscribe);\n };\n\n messenger.subscribe('TransactionController:stateChange', handler, (state) =>\n state.transactions.find((tx) => tx.id === transactionId),\n );\n });\n}\n\n/**\n * Update a transaction by applying a function to its draft.\n *\n * @param request - Request object.\n * @param request.transactionId - ID of the transaction to update.\n * @param request.messenger - Controller messenger.\n * @param request.note - Note describing the update.\n * @param fn - Function that applies updates to the transaction draft.\n */\nexport function updateTransaction(\n {\n transactionId,\n messenger,\n note,\n }: {\n transactionId: string;\n messenger: TransactionPayControllerMessenger;\n note: string;\n },\n fn: (draft: TransactionMeta) => void,\n): void {\n const transaction = getTransaction(transactionId, messenger as never);\n\n if (!transaction) {\n throw new Error(`Transaction not found: ${transactionId}`);\n }\n\n const newTransaction = cloneDeep(transaction);\n\n fn(newTransaction);\n\n messenger.call(\n 'TransactionController:updateTransaction',\n newTransaction,\n note,\n );\n}\n\n/**\n * Collect all new transactions until `end` is called.\n *\n * @param chainId - The chain ID to filter transactions by.\n * @param from - The address to filter transactions by.\n * @param messenger - The controller messenger.\n * @param onTransaction - Callback called with each matching transaction ID.\n * @returns An object with an `end` method to stop collecting transactions.\n */\nexport function collectTransactionIds(\n chainId: Hex,\n from: Hex,\n messenger: TransactionPayControllerMessenger,\n onTransaction: (transactionId: string) => void,\n): { end: () => void } {\n const listener = (tx: TransactionMeta): void => {\n if (\n tx.chainId !== chainId ||\n tx.txParams.from.toLowerCase() !== from.toLowerCase()\n ) {\n return;\n }\n\n onTransaction(tx.id);\n };\n\n messenger.subscribe(\n 'TransactionController:unapprovedTransactionAdded',\n listener,\n );\n\n const end = (): void => {\n messenger.unsubscribe(\n 'TransactionController:unapprovedTransactionAdded',\n listener,\n );\n };\n\n return { end };\n}\n\n/**\n * Check whether a transaction is a Predict withdrawal.\n *\n * Returns `true` when the transaction's own type is `predictWithdraw`, or\n * when any of its nested transactions has that type.\n *\n * @param transaction - Transaction metadata.\n * @returns `true` when the transaction is a Predict withdrawal.\n */\nexport function isPredictWithdrawTransaction(\n transaction: TransactionMeta,\n): boolean {\n return (\n transaction.type === TransactionType.predictWithdraw ||\n (transaction.nestedTransactions?.some(\n (nt) => nt.type === TransactionType.predictWithdraw,\n ) ??\n false)\n );\n}\n\n/**\n * Handle a transaction change by updating its associated data.\n *\n * @param transaction - Transaction metadata.\n * @param messenger - Controller messenger.\n * @param updateTransactionData - Callback to update transaction data.\n */\nfunction onTransactionChange(\n transaction: TransactionMeta,\n messenger: TransactionPayControllerMessenger,\n updateTransactionData: UpdateTransactionDataCallback,\n): void {\n const tokens = parseRequiredTokens(transaction, messenger);\n\n log('Transaction changed', { transaction, tokens });\n\n updateTransactionData(transaction.id, (data) => {\n data.tokens = tokens;\n });\n}\n\n/**\n * Handle a finalized transaction by removing its associated data.\n *\n * @param transaction - Transaction metadata.\n * @param removeTransactionData - Callback to remove transaction data.\n */\nfunction onTransactionFinalized(\n transaction: TransactionMeta,\n removeTransactionData: (transactionId: string) => void,\n): void {\n log('Transaction finalized', { transaction });\n removeTransactionData(transaction.id);\n}\n\nconst erc20Interface = new Interface(abiERC20);\n\nconst ERC20_TRANSFER_EVENT_TOPIC = erc20Interface.getEventTopic('Transfer');\n\n/**\n * Reads the transferred token amount from a completed on-chain transaction.\n *\n * For native tokens the amount is resolved via `debug_traceTransaction`\n * (internal-call aware), falling back to the top-level `tx.value`.\n * For ERC-20 tokens the amount is decoded from `Transfer` event logs\n * in the transaction receipt.\n *\n * @param options - The options.\n * @param options.messenger - Controller messenger for network access.\n * @param options.txHash - Transaction hash of the completed on-chain transaction.\n * @param options.chainId - Chain ID where the transaction was executed.\n * @param options.tokenAddress - Address of the transferred token.\n * @param options.walletAddress - Recipient wallet address to filter transfers to.\n * @returns The raw (atomic) transferred amount as a decimal string,\n * or `undefined` if the amount cannot be determined.\n */\nexport async function getTransferredAmountFromTxHash({\n messenger,\n txHash,\n chainId,\n tokenAddress,\n walletAddress,\n}: {\n messenger: TransactionPayControllerMessenger;\n txHash: string;\n chainId: Hex;\n tokenAddress: Hex;\n walletAddress: Hex;\n}): Promise<string | undefined> {\n const isNative =\n tokenAddress.toLowerCase() === getNativeToken(chainId).toLowerCase();\n\n if (isNative) {\n return await getNativeTransferAmount(\n messenger,\n chainId,\n txHash,\n walletAddress,\n );\n }\n\n return await getErc20TransferAmount(\n messenger,\n chainId,\n txHash,\n tokenAddress,\n walletAddress,\n );\n}\n\n/**\n * Resolves the native token amount received by a wallet from a transaction.\n *\n * 1. Attempts `debug_traceTransaction` with `callTracer` to walk internal\n * calls and sum all native value transfers targeting `walletAddress`.\n * 2. Falls back to the top-level `tx.value` when the wallet is the direct\n * recipient and the trace RPC is unavailable or errors.\n *\n * @param messenger - Controller messenger.\n * @param chainId - Chain ID where the transaction was executed.\n * @param txHash - Transaction hash.\n * @param walletAddress - Recipient wallet address.\n * @returns Raw amount as a decimal string, or `undefined`.\n */\nasync function getNativeTransferAmount(\n messenger: TransactionPayControllerMessenger,\n chainId: Hex,\n txHash: string,\n walletAddress: Hex,\n): Promise<string | undefined> {\n try {\n const trace = await rpcRequest<CallTrace>({\n messenger,\n chainId,\n method: 'debug_traceTransaction',\n params: [txHash, { tracer: 'callTracer' }],\n });\n\n const amount = sumNativeValueFromTrace(trace, walletAddress);\n if (amount.gt(0)) {\n return amount.toFixed(0);\n }\n } catch {\n // debug_traceTransaction not supported — fall through to tx.value\n }\n\n const tx = await rpcRequest<{ to?: string; value: string } | null>({\n messenger,\n chainId,\n method: 'eth_getTransactionByHash',\n params: [txHash],\n });\n\n if (!tx) {\n return undefined;\n }\n\n if (tx.to?.toLowerCase() !== walletAddress.toLowerCase()) {\n return undefined;\n }\n\n return positiveOrUndefined(new BigNumber(tx.value).toFixed(0));\n}\n\n/**\n * Resolves the ERC-20 token amount received by a wallet from a transaction\n * by decoding `Transfer` event logs from the transaction receipt.\n *\n * @param messenger - Controller messenger.\n * @param chainId - Chain ID where the transaction was executed.\n * @param txHash - Transaction hash.\n * @param tokenAddress - ERC-20 token contract address.\n * @param walletAddress - Recipient wallet address.\n * @returns Raw amount as a decimal string, or `undefined`.\n */\nasync function getErc20TransferAmount(\n messenger: TransactionPayControllerMessenger,\n chainId: Hex,\n txHash: string,\n tokenAddress: Hex,\n walletAddress: Hex,\n): Promise<string | undefined> {\n const receipt = await rpcRequest<{\n logs: { address: string; topics: string[]; data: string }[];\n } | null>({\n messenger,\n chainId,\n method: 'eth_getTransactionReceipt',\n params: [txHash],\n });\n\n if (!receipt) {\n return undefined;\n }\n\n let total = new BigNumber(0);\n\n for (const txLog of receipt.logs) {\n if (txLog.address.toLowerCase() !== tokenAddress.toLowerCase()) {\n continue;\n }\n\n if (!txLog.topics[0] || txLog.topics[0] !== ERC20_TRANSFER_EVENT_TOPIC) {\n continue;\n }\n\n try {\n const parsed = erc20Interface.parseLog(txLog);\n const to = (parsed.args[1] as string).toLowerCase();\n\n if (to !== walletAddress.toLowerCase()) {\n continue;\n }\n\n total = total.plus(parsed.args[2].toString());\n } catch {\n continue;\n }\n }\n\n return positiveOrUndefined(total.toFixed(0));\n}\n\ntype CallTrace = {\n to?: string;\n value?: string;\n calls?: CallTrace[];\n};\n\n/**\n * Recursively walks a `callTracer` result and sums native value\n * transferred to a specific address.\n *\n * @param trace - Call trace node.\n * @param walletAddress - Target address to accumulate value for.\n * @returns Accumulated native value as BigNumber.\n */\nfunction sumNativeValueFromTrace(\n trace: CallTrace,\n walletAddress: Hex,\n): BigNumber {\n let total = new BigNumber(0);\n\n if (\n trace.to?.toLowerCase() === walletAddress.toLowerCase() &&\n trace.value &&\n trace.value !== '0x0'\n ) {\n total = total.plus(new BigNumber(trace.value));\n }\n\n if (trace.calls) {\n for (const child of trace.calls) {\n total = total.plus(sumNativeValueFromTrace(child, walletAddress));\n }\n }\n\n return total;\n}\n\nfunction positiveOrUndefined(amount: string): string | undefined {\n return new BigNumber(amount).gt(0) ? amount : undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"transaction.cjs","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":";;;AAAA,4CAA+C;AAC/C,mEAAuD;AACvD,6EAG0C;AAG1C,2CAAqD;AACrD,+CAAyC;AAEzC,mCAAmC;AAEnC,0CAA0C;AAM1C,uDAA6D;AAC7D,6CAAwC;AACxC,2DAAwD;AACxD,uCAAyC;AAEzC,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,aAAa,CAAC,CAAC;AAEhD,QAAA,kBAAkB,GAAG;IAChC,0CAAiB,CAAC,SAAS;IAC3B,0CAAiB,CAAC,OAAO;IACzB,0CAAiB,CAAC,MAAM;CACzB,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,aAAqB,EACrB,SAA4C;IAE5C,MAAM,0BAA0B,GAAG,SAAS,CAAC,IAAI,CAC/C,gCAAgC,CACjC,CAAC;IAEF,OAAO,0BAA0B,CAAC,YAAY,CAAC,IAAI,CACjD,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EA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CAAC,KAAK;QACX,KAAK,CAAC,KAAK,KAAK,KAAK,EACrB,CAAC;QACD,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,wBAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IACjD,CAAC;IAED,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;YAChC,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAc;IACzC,OAAO,IAAI,wBAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AAC1D,CAAC","sourcesContent":["import { Interface } from '@ethersproject/abi';\nimport { abiERC20 } from '@metamask/metamask-eth-abis';\nimport {\n TransactionStatus,\n TransactionType,\n} from '@metamask/transaction-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport type { Patch } from 'immer';\nimport { cloneDeep } from 'lodash';\n\nimport { projectLogger } from '../logger';\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayControllerState,\n UpdateTransactionDataCallback,\n} from '../types';\nimport { getAssetsUnifyStateFeature } from './feature-flags';\nimport { rpcRequest } from './provider';\nimport { parseRequiredTokens } from './required-tokens';\nimport { getNativeToken } from './token';\n\nconst log = createModuleLogger(projectLogger, 'transaction');\n\nexport const FINALIZED_STATUSES = [\n TransactionStatus.confirmed,\n TransactionStatus.dropped,\n TransactionStatus.failed,\n];\n\n/**\n * Retrieve transaction metadata by ID.\n *\n * @param transactionId - ID of the transaction to retrieve.\n * @param messenger - Controller messenger.\n * @returns The transaction metadata or undefined if not found.\n */\nexport function getTransaction(\n transactionId: string,\n messenger: TransactionPayControllerMessenger,\n): TransactionMeta | undefined {\n const transactionControllerState = messenger.call(\n 'TransactionController:getState',\n );\n\n return transactionControllerState.transactions.find(\n (tx) => tx.id === transactionId,\n );\n}\n\n/**\n * Subscribe to transaction changes and update the transaction data accordingly.\n *\n * @param messenger - Controller messenger.\n * @param updateTransactionData - Callback to update transaction data.\n * @param removeTransactionData - Callback to remove transaction data.\n */\nexport function subscribeTransactionChanges(\n messenger: TransactionPayControllerMessenger,\n updateTransactionData: UpdateTransactionDataCallback,\n removeTransactionData: (transactionId: string) => void,\n): void {\n messenger.subscribe(\n 'TransactionController:stateChange',\n (\n transactions: TransactionMeta[],\n previousTransactions: TransactionMeta[] | undefined,\n ) => {\n const newTransactions = transactions.filter(\n (tx) => !previousTransactions?.find((prevTx) => prevTx.id === tx.id),\n );\n\n const updatedTransactions = transactions.filter((tx) => {\n const previousTransaction = previousTransactions?.find(\n (prevTx) => prevTx.id === tx.id,\n );\n\n return (\n previousTransaction &&\n previousTransaction?.txParams.data !== tx.txParams.data\n );\n });\n\n const finalizedTransactions = transactions.filter((tx) => {\n const previousTransaction = previousTransactions?.find(\n (prevTx) => prevTx.id === tx.id,\n );\n\n return (\n previousTransaction &&\n !FINALIZED_STATUSES.includes(previousTransaction.status) &&\n FINALIZED_STATUSES.includes(tx.status)\n );\n });\n\n const deletedTransactions = (previousTransactions ?? []).filter(\n (prevTx) => !transactions.find((tx) => tx.id === prevTx.id),\n );\n\n [...finalizedTransactions, ...deletedTransactions].forEach((tx) =>\n onTransactionFinalized(tx, removeTransactionData),\n );\n\n [...newTransactions, ...updatedTransactions].forEach((tx) =>\n onTransactionChange(tx, messenger, updateTransactionData),\n );\n },\n (state) => state.transactions,\n );\n}\n\n/**\n * Subscribe to asset state changes and re-parse required tokens for\n * in-flight transactions whose tokens have not yet resolved.\n *\n * @param messenger - Controller messenger.\n * @param getControllerState - Callback returning the current controller state.\n * @param updateTransactionData - Callback to update transaction data.\n */\nexport function subscribeAssetChanges(\n messenger: TransactionPayControllerMessenger,\n getControllerState: () => TransactionPayControllerState,\n updateTransactionData: UpdateTransactionDataCallback,\n): void {\n const buildHandler =\n (source: string) =>\n (_state: unknown, patches: Patch[] | undefined): void => {\n const { transactionData } = getControllerState();\n\n for (const [transactionId, data] of Object.entries(transactionData)) {\n if (data.tokens.length > 0) {\n continue;\n }\n\n const transaction = getTransaction(transactionId, messenger);\n\n if (!transaction || FINALIZED_STATUSES.includes(transaction.status)) {\n continue;\n }\n\n log('Asset data changed', { transactionId, source, patches });\n\n onTransactionChange(transaction, messenger, updateTransactionData);\n }\n };\n\n if (getAssetsUnifyStateFeature(messenger)) {\n messenger.subscribe(\n 'AssetsController:stateChange',\n buildHandler('AssetsController'),\n );\n return;\n }\n\n messenger.subscribe(\n 'TokensController:stateChange',\n buildHandler('TokensController'),\n );\n messenger.subscribe(\n 'TokenRatesController:stateChange',\n buildHandler('TokenRatesController'),\n );\n messenger.subscribe(\n 'CurrencyRateController:stateChange',\n buildHandler('CurrencyRateController'),\n );\n}\n\n/**\n * Wait for a transaction to be confirmed or fail.\n *\n * @param transactionId - ID of the transaction to wait for.\n * @param messenger - Controller messenger.\n * @returns A promise that resolves when the transaction is confirmed or rejects if it fails.\n */\nexport function waitForTransactionConfirmed(\n transactionId: string,\n messenger: TransactionPayControllerMessenger,\n): Promise<void> {\n return new Promise<void>((resolve, reject) => {\n const isConfirmed = (tx?: TransactionMeta, fn?: () => void): boolean => {\n log('Checking transaction status', tx?.status, tx?.type);\n\n if (tx?.status === TransactionStatus.confirmed) {\n fn?.();\n resolve();\n return true;\n }\n\n if (\n [TransactionStatus.dropped, TransactionStatus.failed].includes(\n tx?.status as TransactionStatus,\n )\n ) {\n fn?.();\n reject(\n new Error(`Transaction failed - ${tx?.type} - ${tx?.error?.message}`),\n );\n return true;\n }\n\n return false;\n };\n\n const initialState = messenger.call('TransactionController:getState');\n\n const initialTx = initialState.transactions.find(\n (singleTransaction) => singleTransaction.id === transactionId,\n );\n\n if (isConfirmed(initialTx)) {\n return;\n }\n\n const handler = (tx?: TransactionMeta): void => {\n const unsubscribe = (): void =>\n messenger.unsubscribe('TransactionController:stateChange', handler);\n\n isConfirmed(tx, unsubscribe);\n };\n\n messenger.subscribe('TransactionController:stateChange', handler, (state) =>\n state.transactions.find((tx) => tx.id === transactionId),\n );\n });\n}\n\n/**\n * Update a transaction by applying a function to its draft.\n *\n * @param request - Request object.\n * @param request.transactionId - ID of the transaction to update.\n * @param request.messenger - Controller messenger.\n * @param request.note - Note describing the update.\n * @param fn - Function that applies updates to the transaction draft.\n */\nexport function updateTransaction(\n {\n transactionId,\n messenger,\n note,\n }: {\n transactionId: string;\n messenger: TransactionPayControllerMessenger;\n note: string;\n },\n fn: (draft: TransactionMeta) => void,\n): void {\n const transaction = getTransaction(transactionId, messenger as never);\n\n if (!transaction) {\n throw new Error(`Transaction not found: ${transactionId}`);\n }\n\n const newTransaction = cloneDeep(transaction);\n\n fn(newTransaction);\n\n messenger.call(\n 'TransactionController:updateTransaction',\n newTransaction,\n note,\n );\n}\n\n/**\n * Collect all new transactions until `end` is called.\n *\n * @param chainId - The chain ID to filter transactions by.\n * @param from - The address to filter transactions by.\n * @param messenger - The controller messenger.\n * @param onTransaction - Callback called with each matching transaction ID.\n * @returns An object with an `end` method to stop collecting transactions.\n */\nexport function collectTransactionIds(\n chainId: Hex,\n from: Hex,\n messenger: TransactionPayControllerMessenger,\n onTransaction: (transactionId: string) => void,\n): { end: () => void } {\n const listener = (tx: TransactionMeta): void => {\n if (\n tx.chainId !== chainId ||\n tx.txParams.from.toLowerCase() !== from.toLowerCase()\n ) {\n return;\n }\n\n onTransaction(tx.id);\n };\n\n messenger.subscribe(\n 'TransactionController:unapprovedTransactionAdded',\n listener,\n );\n\n const end = (): void => {\n messenger.unsubscribe(\n 'TransactionController:unapprovedTransactionAdded',\n listener,\n );\n };\n\n return { end };\n}\n\n/**\n * Check whether a transaction is a Predict withdrawal.\n *\n * Returns `true` when the transaction's own type is `predictWithdraw`, or\n * when any of its nested transactions has that type.\n *\n * @param transaction - Transaction metadata.\n * @returns `true` when the transaction is a Predict withdrawal.\n */\nexport function isPredictWithdrawTransaction(\n transaction: TransactionMeta,\n): boolean {\n return (\n transaction.type === TransactionType.predictWithdraw ||\n (transaction.nestedTransactions?.some(\n (nt) => nt.type === TransactionType.predictWithdraw,\n ) ??\n false)\n );\n}\n\n/**\n * Handle a transaction change by updating its associated data.\n *\n * @param transaction - Transaction metadata.\n * @param messenger - Controller messenger.\n * @param updateTransactionData - Callback to update transaction data.\n */\nfunction onTransactionChange(\n transaction: TransactionMeta,\n messenger: TransactionPayControllerMessenger,\n updateTransactionData: UpdateTransactionDataCallback,\n): void {\n const tokens = parseRequiredTokens(transaction, messenger);\n\n log('Transaction changed', { transaction, tokens });\n\n updateTransactionData(transaction.id, (data) => {\n data.tokens = tokens;\n });\n}\n\n/**\n * Handle a finalized transaction by removing its associated data.\n *\n * @param transaction - Transaction metadata.\n * @param removeTransactionData - Callback to remove transaction data.\n */\nfunction onTransactionFinalized(\n transaction: TransactionMeta,\n removeTransactionData: (transactionId: string) => void,\n): void {\n log('Transaction finalized', { transaction });\n removeTransactionData(transaction.id);\n}\n\nconst erc20Interface = new Interface(abiERC20);\n\nconst ERC20_TRANSFER_EVENT_TOPIC = erc20Interface.getEventTopic('Transfer');\n\n/**\n * Result from {@link getTransferredAmountFromTxHash}.\n */\nexport type TransferredAmountResult = {\n /** Raw (atomic) transferred amount as a decimal string, or `undefined`. */\n amountRaw: string | undefined;\n /**\n * Block number of the on-chain transaction as a 0x-prefixed hex string.\n * Populated only for ERC-20 tokens (sourced from the receipt); `undefined`\n * for native token transactions.\n */\n blockNumber: Hex | undefined;\n};\n\n/**\n * Reads the transferred token amount from a completed on-chain transaction.\n *\n * For native tokens the amount is resolved via `debug_traceTransaction`\n * (internal-call aware), falling back to the top-level `tx.value`.\n * For ERC-20 tokens the amount is decoded from `Transfer` event logs\n * in the transaction receipt, and the receipt `blockNumber` is also returned.\n *\n * @param options - The options.\n * @param options.messenger - Controller messenger for network access.\n * @param options.txHash - Transaction hash of the completed on-chain transaction.\n * @param options.chainId - Chain ID where the transaction was executed.\n * @param options.tokenAddress - Address of the transferred token.\n * @param options.walletAddress - Recipient wallet address to filter transfers to.\n * @returns The raw transferred amount and, for ERC-20, the receipt block number.\n */\nexport async function getTransferredAmountFromTxHash({\n messenger,\n txHash,\n chainId,\n tokenAddress,\n walletAddress,\n}: {\n messenger: TransactionPayControllerMessenger;\n txHash: string;\n chainId: Hex;\n tokenAddress: Hex;\n walletAddress: Hex;\n}): Promise<TransferredAmountResult> {\n const isNative =\n tokenAddress.toLowerCase() === getNativeToken(chainId).toLowerCase();\n\n if (isNative) {\n const amountRaw = await getNativeTransferAmount(\n messenger,\n chainId,\n txHash,\n walletAddress,\n );\n\n return { amountRaw, blockNumber: undefined };\n }\n\n return await getErc20TransferAmount(\n messenger,\n chainId,\n txHash,\n tokenAddress,\n walletAddress,\n );\n}\n\n/**\n * Resolves the native token amount received by a wallet from a transaction.\n *\n * 1. Attempts `debug_traceTransaction` with `callTracer` to walk internal\n * calls and sum all native value transfers targeting `walletAddress`.\n * 2. Falls back to the top-level `tx.value` when the wallet is the direct\n * recipient and the trace RPC is unavailable or errors.\n *\n * @param messenger - Controller messenger.\n * @param chainId - Chain ID where the transaction was executed.\n * @param txHash - Transaction hash.\n * @param walletAddress - Recipient wallet address.\n * @returns Raw amount as a decimal string, or `undefined`.\n */\nasync function getNativeTransferAmount(\n messenger: TransactionPayControllerMessenger,\n chainId: Hex,\n txHash: string,\n walletAddress: Hex,\n): Promise<string | undefined> {\n try {\n const trace = await rpcRequest<CallTrace>({\n messenger,\n chainId,\n method: 'debug_traceTransaction',\n params: [txHash, { tracer: 'callTracer' }],\n });\n\n const amount = sumNativeValueFromTrace(trace, walletAddress);\n if (amount.gt(0)) {\n return amount.toFixed(0);\n }\n } catch {\n // debug_traceTransaction not supported — fall through to tx.value\n }\n\n const tx = await rpcRequest<{ to?: string; value: string } | null>({\n messenger,\n chainId,\n method: 'eth_getTransactionByHash',\n params: [txHash],\n });\n\n if (!tx) {\n return undefined;\n }\n\n if (tx.to?.toLowerCase() !== walletAddress.toLowerCase()) {\n return undefined;\n }\n\n return positiveOrUndefined(new BigNumber(tx.value).toFixed(0));\n}\n\n/**\n * Resolves the ERC-20 token amount received by a wallet from a transaction\n * by decoding `Transfer` event logs from the transaction receipt. Also\n * returns the receipt `blockNumber` so callers can reuse it without a\n * second network request.\n *\n * @param messenger - Controller messenger.\n * @param chainId - Chain ID where the transaction was executed.\n * @param txHash - Transaction hash.\n * @param tokenAddress - ERC-20 token contract address.\n * @param walletAddress - Recipient wallet address.\n * @returns Raw amount (or `undefined`) and the receipt block number (or `undefined`).\n */\nasync function getErc20TransferAmount(\n messenger: TransactionPayControllerMessenger,\n chainId: Hex,\n txHash: string,\n tokenAddress: Hex,\n walletAddress: Hex,\n): Promise<TransferredAmountResult> {\n const receipt = await rpcRequest<{\n blockNumber: Hex;\n logs: { address: string; topics: string[]; data: string }[];\n } | null>({\n messenger,\n chainId,\n method: 'eth_getTransactionReceipt',\n params: [txHash],\n });\n\n if (!receipt) {\n return { amountRaw: undefined, blockNumber: undefined };\n }\n\n const { blockNumber } = receipt;\n let total = new BigNumber(0);\n\n for (const txLog of receipt.logs) {\n if (txLog.address.toLowerCase() !== tokenAddress.toLowerCase()) {\n continue;\n }\n\n if (!txLog.topics[0] || txLog.topics[0] !== ERC20_TRANSFER_EVENT_TOPIC) {\n continue;\n }\n\n try {\n const parsed = erc20Interface.parseLog(txLog);\n const to = (parsed.args[1] as string).toLowerCase();\n\n if (to !== walletAddress.toLowerCase()) {\n continue;\n }\n\n total = total.plus(parsed.args[2].toString());\n } catch {\n continue;\n }\n }\n\n return { amountRaw: positiveOrUndefined(total.toFixed(0)), blockNumber };\n}\n\ntype CallTrace = {\n to?: string;\n value?: string;\n calls?: CallTrace[];\n};\n\n/**\n * Recursively walks a `callTracer` result and sums native value\n * transferred to a specific address.\n *\n * @param trace - Call trace node.\n * @param walletAddress - Target address to accumulate value for.\n * @returns Accumulated native value as BigNumber.\n */\nfunction sumNativeValueFromTrace(\n trace: CallTrace,\n walletAddress: Hex,\n): BigNumber {\n let total = new BigNumber(0);\n\n if (\n trace.to?.toLowerCase() === walletAddress.toLowerCase() &&\n trace.value &&\n trace.value !== '0x0'\n ) {\n total = total.plus(new BigNumber(trace.value));\n }\n\n if (trace.calls) {\n for (const child of trace.calls) {\n total = total.plus(sumNativeValueFromTrace(child, walletAddress));\n }\n }\n\n return total;\n}\n\nfunction positiveOrUndefined(amount: string): string | undefined {\n return new BigNumber(amount).gt(0) ? amount : undefined;\n}\n"]}
|
|
@@ -72,13 +72,26 @@ export declare function collectTransactionIds(chainId: Hex, from: Hex, messenger
|
|
|
72
72
|
* @returns `true` when the transaction is a Predict withdrawal.
|
|
73
73
|
*/
|
|
74
74
|
export declare function isPredictWithdrawTransaction(transaction: TransactionMeta): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Result from {@link getTransferredAmountFromTxHash}.
|
|
77
|
+
*/
|
|
78
|
+
export type TransferredAmountResult = {
|
|
79
|
+
/** Raw (atomic) transferred amount as a decimal string, or `undefined`. */
|
|
80
|
+
amountRaw: string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Block number of the on-chain transaction as a 0x-prefixed hex string.
|
|
83
|
+
* Populated only for ERC-20 tokens (sourced from the receipt); `undefined`
|
|
84
|
+
* for native token transactions.
|
|
85
|
+
*/
|
|
86
|
+
blockNumber: Hex | undefined;
|
|
87
|
+
};
|
|
75
88
|
/**
|
|
76
89
|
* Reads the transferred token amount from a completed on-chain transaction.
|
|
77
90
|
*
|
|
78
91
|
* For native tokens the amount is resolved via `debug_traceTransaction`
|
|
79
92
|
* (internal-call aware), falling back to the top-level `tx.value`.
|
|
80
93
|
* For ERC-20 tokens the amount is decoded from `Transfer` event logs
|
|
81
|
-
* in the transaction receipt.
|
|
94
|
+
* in the transaction receipt, and the receipt `blockNumber` is also returned.
|
|
82
95
|
*
|
|
83
96
|
* @param options - The options.
|
|
84
97
|
* @param options.messenger - Controller messenger for network access.
|
|
@@ -86,8 +99,7 @@ export declare function isPredictWithdrawTransaction(transaction: TransactionMet
|
|
|
86
99
|
* @param options.chainId - Chain ID where the transaction was executed.
|
|
87
100
|
* @param options.tokenAddress - Address of the transferred token.
|
|
88
101
|
* @param options.walletAddress - Recipient wallet address to filter transfers to.
|
|
89
|
-
* @returns The raw
|
|
90
|
-
* or `undefined` if the amount cannot be determined.
|
|
102
|
+
* @returns The raw transferred amount and, for ERC-20, the receipt block number.
|
|
91
103
|
*/
|
|
92
104
|
export declare function getTransferredAmountFromTxHash({ messenger, txHash, chainId, tokenAddress, walletAddress, }: {
|
|
93
105
|
messenger: TransactionPayControllerMessenger;
|
|
@@ -95,5 +107,5 @@ export declare function getTransferredAmountFromTxHash({ messenger, txHash, chai
|
|
|
95
107
|
chainId: Hex;
|
|
96
108
|
tokenAddress: Hex;
|
|
97
109
|
walletAddress: Hex;
|
|
98
|
-
}): Promise<
|
|
110
|
+
}): Promise<TransferredAmountResult>;
|
|
99
111
|
//# sourceMappingURL=transaction.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.cts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EAElB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAO3C,OAAO,KAAK,EACV,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC9B,qBAAiB;AAQlB,eAAO,MAAM,kBAAkB,qBAI9B,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,iC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AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,eAAe,GAC3B,OAAO,CAQT;AAyCD;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,2EAA2E;IAC3E,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;;OAIG;IACH,WAAW,EAAE,GAAG,GAAG,SAAS,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,8BAA8B,CAAC,EACnD,SAAS,EACT,MAAM,EACN,OAAO,EACP,YAAY,EACZ,aAAa,GACd,EAAE;IACD,SAAS,EAAE,iCAAiC,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,GAAG,CAAC;IACb,YAAY,EAAE,GAAG,CAAC;IAClB,aAAa,EAAE,GAAG,CAAC;CACpB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAsBnC"}
|
|
@@ -72,13 +72,26 @@ export declare function collectTransactionIds(chainId: Hex, from: Hex, messenger
|
|
|
72
72
|
* @returns `true` when the transaction is a Predict withdrawal.
|
|
73
73
|
*/
|
|
74
74
|
export declare function isPredictWithdrawTransaction(transaction: TransactionMeta): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Result from {@link getTransferredAmountFromTxHash}.
|
|
77
|
+
*/
|
|
78
|
+
export type TransferredAmountResult = {
|
|
79
|
+
/** Raw (atomic) transferred amount as a decimal string, or `undefined`. */
|
|
80
|
+
amountRaw: string | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Block number of the on-chain transaction as a 0x-prefixed hex string.
|
|
83
|
+
* Populated only for ERC-20 tokens (sourced from the receipt); `undefined`
|
|
84
|
+
* for native token transactions.
|
|
85
|
+
*/
|
|
86
|
+
blockNumber: Hex | undefined;
|
|
87
|
+
};
|
|
75
88
|
/**
|
|
76
89
|
* Reads the transferred token amount from a completed on-chain transaction.
|
|
77
90
|
*
|
|
78
91
|
* For native tokens the amount is resolved via `debug_traceTransaction`
|
|
79
92
|
* (internal-call aware), falling back to the top-level `tx.value`.
|
|
80
93
|
* For ERC-20 tokens the amount is decoded from `Transfer` event logs
|
|
81
|
-
* in the transaction receipt.
|
|
94
|
+
* in the transaction receipt, and the receipt `blockNumber` is also returned.
|
|
82
95
|
*
|
|
83
96
|
* @param options - The options.
|
|
84
97
|
* @param options.messenger - Controller messenger for network access.
|
|
@@ -86,8 +99,7 @@ export declare function isPredictWithdrawTransaction(transaction: TransactionMet
|
|
|
86
99
|
* @param options.chainId - Chain ID where the transaction was executed.
|
|
87
100
|
* @param options.tokenAddress - Address of the transferred token.
|
|
88
101
|
* @param options.walletAddress - Recipient wallet address to filter transfers to.
|
|
89
|
-
* @returns The raw
|
|
90
|
-
* or `undefined` if the amount cannot be determined.
|
|
102
|
+
* @returns The raw transferred amount and, for ERC-20, the receipt block number.
|
|
91
103
|
*/
|
|
92
104
|
export declare function getTransferredAmountFromTxHash({ messenger, txHash, chainId, tokenAddress, walletAddress, }: {
|
|
93
105
|
messenger: TransactionPayControllerMessenger;
|
|
@@ -95,5 +107,5 @@ export declare function getTransferredAmountFromTxHash({ messenger, txHash, chai
|
|
|
95
107
|
chainId: Hex;
|
|
96
108
|
tokenAddress: Hex;
|
|
97
109
|
walletAddress: Hex;
|
|
98
|
-
}): Promise<
|
|
110
|
+
}): Promise<TransferredAmountResult>;
|
|
99
111
|
//# sourceMappingURL=transaction.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transaction.d.mts","sourceRoot":"","sources":["../../src/utils/transaction.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EAElB,yCAAyC;AAC1C,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAO3C,OAAO,KAAK,EACV,iCAAiC,EACjC,6BAA6B,EAC7B,6BAA6B,EAC9B,qBAAiB;AAQlB,eAAO,MAAM,kBAAkB,qBAI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AAC,aAAa,EAAE,MAAM,KAAK,IAAI,GAC7C;IAAE,GAAG,EAAE,MAAM,IAAI,CAAA;CAAE,CAyBrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,WAAW,EAAE,eAAe,GAC3B,OAAO,CAQT;AAyCD;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,2EAA2E;IAC3E,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B;;;;OAIG;IACH,WAAW,EAAE,GAAG,GAAG,SAAS,CAAC;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,8BAA8B,CAAC,EACnD,SAAS,EACT,MAAM,EACN,OAAO,EACP,YAAY,EACZ,aAAa,GACd,EAAE;IACD,SAAS,EAAE,iCAAiC,CAAC;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,GAAG,CAAC;IACb,YAAY,EAAE,GAAG,CAAC;IAClB,aAAa,EAAE,GAAG,CAAC;CACpB,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAsBnC"}
|
|
@@ -206,7 +206,7 @@ const ERC20_TRANSFER_EVENT_TOPIC = erc20Interface.getEventTopic('Transfer');
|
|
|
206
206
|
* For native tokens the amount is resolved via `debug_traceTransaction`
|
|
207
207
|
* (internal-call aware), falling back to the top-level `tx.value`.
|
|
208
208
|
* For ERC-20 tokens the amount is decoded from `Transfer` event logs
|
|
209
|
-
* in the transaction receipt.
|
|
209
|
+
* in the transaction receipt, and the receipt `blockNumber` is also returned.
|
|
210
210
|
*
|
|
211
211
|
* @param options - The options.
|
|
212
212
|
* @param options.messenger - Controller messenger for network access.
|
|
@@ -214,13 +214,13 @@ const ERC20_TRANSFER_EVENT_TOPIC = erc20Interface.getEventTopic('Transfer');
|
|
|
214
214
|
* @param options.chainId - Chain ID where the transaction was executed.
|
|
215
215
|
* @param options.tokenAddress - Address of the transferred token.
|
|
216
216
|
* @param options.walletAddress - Recipient wallet address to filter transfers to.
|
|
217
|
-
* @returns The raw
|
|
218
|
-
* or `undefined` if the amount cannot be determined.
|
|
217
|
+
* @returns The raw transferred amount and, for ERC-20, the receipt block number.
|
|
219
218
|
*/
|
|
220
219
|
export async function getTransferredAmountFromTxHash({ messenger, txHash, chainId, tokenAddress, walletAddress, }) {
|
|
221
220
|
const isNative = tokenAddress.toLowerCase() === getNativeToken(chainId).toLowerCase();
|
|
222
221
|
if (isNative) {
|
|
223
|
-
|
|
222
|
+
const amountRaw = await getNativeTransferAmount(messenger, chainId, txHash, walletAddress);
|
|
223
|
+
return { amountRaw, blockNumber: undefined };
|
|
224
224
|
}
|
|
225
225
|
return await getErc20TransferAmount(messenger, chainId, txHash, tokenAddress, walletAddress);
|
|
226
226
|
}
|
|
@@ -270,14 +270,16 @@ async function getNativeTransferAmount(messenger, chainId, txHash, walletAddress
|
|
|
270
270
|
}
|
|
271
271
|
/**
|
|
272
272
|
* Resolves the ERC-20 token amount received by a wallet from a transaction
|
|
273
|
-
* by decoding `Transfer` event logs from the transaction receipt.
|
|
273
|
+
* by decoding `Transfer` event logs from the transaction receipt. Also
|
|
274
|
+
* returns the receipt `blockNumber` so callers can reuse it without a
|
|
275
|
+
* second network request.
|
|
274
276
|
*
|
|
275
277
|
* @param messenger - Controller messenger.
|
|
276
278
|
* @param chainId - Chain ID where the transaction was executed.
|
|
277
279
|
* @param txHash - Transaction hash.
|
|
278
280
|
* @param tokenAddress - ERC-20 token contract address.
|
|
279
281
|
* @param walletAddress - Recipient wallet address.
|
|
280
|
-
* @returns Raw amount
|
|
282
|
+
* @returns Raw amount (or `undefined`) and the receipt block number (or `undefined`).
|
|
281
283
|
*/
|
|
282
284
|
async function getErc20TransferAmount(messenger, chainId, txHash, tokenAddress, walletAddress) {
|
|
283
285
|
const receipt = await rpcRequest({
|
|
@@ -287,8 +289,9 @@ async function getErc20TransferAmount(messenger, chainId, txHash, tokenAddress,
|
|
|
287
289
|
params: [txHash],
|
|
288
290
|
});
|
|
289
291
|
if (!receipt) {
|
|
290
|
-
return undefined;
|
|
292
|
+
return { amountRaw: undefined, blockNumber: undefined };
|
|
291
293
|
}
|
|
294
|
+
const { blockNumber } = receipt;
|
|
292
295
|
let total = new BigNumber(0);
|
|
293
296
|
for (const txLog of receipt.logs) {
|
|
294
297
|
if (txLog.address.toLowerCase() !== tokenAddress.toLowerCase()) {
|
|
@@ -309,7 +312,7 @@ async function getErc20TransferAmount(messenger, chainId, txHash, tokenAddress,
|
|
|
309
312
|
continue;
|
|
310
313
|
}
|
|
311
314
|
}
|
|
312
|
-
return positiveOrUndefined(total.toFixed(0));
|
|
315
|
+
return { amountRaw: positiveOrUndefined(total.toFixed(0)), blockNumber };
|
|
313
316
|
}
|
|
314
317
|
/**
|
|
315
318
|
* Recursively walks a `callTracer` result and sums native value
|