@metamask/transaction-pay-controller 13.0.0 → 14.0.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 +12 -1
- package/dist/constants.cjs +19 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +3 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +3 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +18 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/strategy/bridge/bridge-quotes.cjs +2 -1
- package/dist/strategy/bridge/bridge-quotes.cjs.map +1 -1
- package/dist/strategy/bridge/bridge-quotes.mjs +2 -1
- package/dist/strategy/bridge/bridge-quotes.mjs.map +1 -1
- package/dist/strategy/relay/constants.cjs +1 -2
- package/dist/strategy/relay/constants.cjs.map +1 -1
- package/dist/strategy/relay/constants.d.cts +0 -1
- package/dist/strategy/relay/constants.d.cts.map +1 -1
- package/dist/strategy/relay/constants.d.mts +0 -1
- package/dist/strategy/relay/constants.d.mts.map +1 -1
- package/dist/strategy/relay/constants.mjs +0 -1
- package/dist/strategy/relay/constants.mjs.map +1 -1
- package/dist/strategy/relay/relay-quotes.cjs +31 -8
- package/dist/strategy/relay/relay-quotes.cjs.map +1 -1
- package/dist/strategy/relay/relay-quotes.d.cts.map +1 -1
- package/dist/strategy/relay/relay-quotes.d.mts.map +1 -1
- package/dist/strategy/relay/relay-quotes.mjs +31 -8
- package/dist/strategy/relay/relay-quotes.mjs.map +1 -1
- package/dist/strategy/relay/types.cjs.map +1 -1
- package/dist/strategy/relay/types.d.cts +11 -0
- package/dist/strategy/relay/types.d.cts.map +1 -1
- package/dist/strategy/relay/types.d.mts +11 -0
- package/dist/strategy/relay/types.d.mts.map +1 -1
- package/dist/strategy/relay/types.mjs.map +1 -1
- package/dist/strategy/test/TestStrategy.cjs +0 -2
- package/dist/strategy/test/TestStrategy.cjs.map +1 -1
- package/dist/strategy/test/TestStrategy.d.cts.map +1 -1
- package/dist/strategy/test/TestStrategy.d.mts.map +1 -1
- package/dist/strategy/test/TestStrategy.mjs +0 -2
- package/dist/strategy/test/TestStrategy.mjs.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/token.cjs +1 -5
- package/dist/utils/token.cjs.map +1 -1
- package/dist/utils/token.d.cts.map +1 -1
- package/dist/utils/token.d.mts.map +1 -1
- package/dist/utils/token.mjs +1 -5
- package/dist/utils/token.mjs.map +1 -1
- package/dist/utils/totals.cjs +1 -1
- package/dist/utils/totals.cjs.map +1 -1
- package/dist/utils/totals.mjs +1 -1
- package/dist/utils/totals.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestStrategy.d.cts","sourceRoot":"","sources":["../../../src/strategy/test/TestStrategy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,WAAW,EACX,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,EACpB,wBAAoB;AAIrB,qBAAa,YAAa,YAAW,WAAW,CAAC,IAAI,CAAC;;IAC9C,SAAS,CACb,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"TestStrategy.d.cts","sourceRoot":"","sources":["../../../src/strategy/test/TestStrategy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,WAAW,EACX,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,EACpB,wBAAoB;AAIrB,qBAAa,YAAa,YAAW,WAAW,CAAC,IAAI,CAAC;;IAC9C,SAAS,CACb,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;IAiDjC,OAAO,CACX,OAAO,EAAE,yBAAyB,CAAC,IAAI,CAAC,GACvC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC;CAa5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestStrategy.d.mts","sourceRoot":"","sources":["../../../src/strategy/test/TestStrategy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,WAAW,EACX,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,EACpB,wBAAoB;AAIrB,qBAAa,YAAa,YAAW,WAAW,CAAC,IAAI,CAAC;;IAC9C,SAAS,CACb,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"TestStrategy.d.mts","sourceRoot":"","sources":["../../../src/strategy/test/TestStrategy.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,WAAW,EACX,yBAAyB,EACzB,2BAA2B,EAC3B,mBAAmB,EACpB,wBAAoB;AAIrB,qBAAa,YAAa,YAAW,WAAW,CAAC,IAAI,CAAC;;IAC9C,SAAS,CACb,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,CAAC;IAiDjC,OAAO,CACX,OAAO,EAAE,yBAAyB,CAAC,IAAI,CAAC,GACvC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC,CAAC;CAa5C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TestStrategy.mjs","sourceRoot":"","sources":["../../../src/strategy/test/TestStrategy.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,kBAAkB,EAAE,wBAAwB;AAErD,OAAO,EAAE,sBAAsB,EAAE,wBAAc;AAC/C,OAAO,EAAE,aAAa,EAAE,yBAAqB;AAQ7C,MAAM,GAAG,GAAG,kBAAkB,CAAC,aAAa,EAAE,eAAe,CAA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YAAY,EAAE;oBACZ,KAAK,EAAE,MAAM;oBACb,IAAI,EAAE,MAAM;oBACZ,GAAG,EAAE,QAAQ;oBACb,GAAG,EAAE,MAAM;iBACZ;gBACD,YAAY,EAAE;oBACZ,IAAI,EAAE,MAAM;oBACZ,GAAG,EAAE,MAAM;iBACZ;gBACD,QAAQ,EAAE,sBAAsB,CAAC,IAAI;aACtC;SACF,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CACX,OAAwC;QAExC,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE3B,GAAG,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QAEzB,MAAM,uBAAA,IAAI,sDAAS,MAAb,IAAI,EAAU,IAAI,CAAC,CAAC;QAE1B,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,CAAC;IACxC,CAAC;CAKF;gGAHU,EAAU;IACjB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAC3D,CAAC","sourcesContent":["import { createModuleLogger } from '@metamask/utils';\n\nimport { TransactionPayStrategy } from '../..';\nimport { projectLogger } from '../../logger';\nimport type {\n PayStrategy,\n PayStrategyExecuteRequest,\n PayStrategyGetQuotesRequest,\n TransactionPayQuote,\n} from '../../types';\n\nconst log = createModuleLogger(projectLogger, 'test-strategy');\n\nexport class TestStrategy implements PayStrategy<void> {\n async getQuotes(\n request: PayStrategyGetQuotesRequest,\n ): Promise<TransactionPayQuote<void>[]> {\n const { requests } = request;\n\n log('Getting quotes', requests);\n\n await this.#timeout(5000);\n\n return [\n {\n dust: { fiat: '0.12', usd: '0.34' },\n estimatedDuration: 5,\n fees: {\n provider: { fiat: '1.23', usd: '1.23' },\n sourceNetwork: {\n estimate: {\n human: '2.34',\n fiat: '2.34',\n usd: '2.34',\n raw: '234000',\n },\n max: {\n human: '2.35',\n fiat: '2.35',\n usd: '2.35',\n raw: '235000',\n },\n },\n targetNetwork: {\n fiat: '3.45',\n usd: '3.45',\n },\n },\n original: undefined,\n request: requests[0],\n sourceAmount: {\n human: '4.56',\n fiat: '4.56',\n raw: '456000',\n usd: '4.56',\n },\n targetAmount: {\n fiat: '5.67',\n usd: '5.67',\n },\n strategy: TransactionPayStrategy.Test,\n },\n ];\n }\n\n async execute(\n request: PayStrategyExecuteRequest<void>,\n ): ReturnType<PayStrategy<void>['execute']> {\n const { quotes } = request;\n\n log('Executing', quotes);\n\n await this.#timeout(5000);\n\n return { transactionHash: undefined };\n }\n\n #timeout(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CurrencyRateControllerActions,\n TokenBalancesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type { TokenRatesControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { TokensControllerGetStateAction } 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 { BridgeControllerActions } from '@metamask/bridge-controller';\nimport type { BridgeStatusControllerStateChangeEvent } from '@metamask/bridge-status-controller';\nimport type { BridgeStatusControllerActions } from '@metamask/bridge-status-controller';\nimport type { GasFeeControllerActions } from '@metamask/gas-fee-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { NetworkControllerFindNetworkClientIdByChainIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-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 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 { CONTROLLER_NAME, TransactionPayStrategy } from './constants';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | BridgeControllerActions\n | BridgeStatusControllerActions\n | CurrencyRateControllerActions\n | GasFeeControllerActions\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\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 | BridgeStatusControllerStateChangeEvent\n | TransactionControllerStateChangeEvent\n | TransactionControllerUnapprovedTransactionAddedEvent;\n\nexport type TransactionPayControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n>;\n\nexport type TransactionPayControllerGetDelegationTransactionAction = {\n type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`;\n handler: GetDelegationTransactionCallback;\n};\n\n/** Action to get the pay strategy type used for a transaction. */\nexport type TransactionPayControllerGetStrategyAction = {\n type: `${typeof CONTROLLER_NAME}:getStrategy`;\n handler: (transaction: TransactionMeta) => TransactionPayStrategy;\n};\n\n/** Action to update the payment token for a transaction. */\nexport type TransactionPayControllerUpdatePaymentTokenAction = {\n type: `${typeof CONTROLLER_NAME}:updatePaymentToken`;\n handler: (request: UpdatePaymentTokenRequest) => void;\n};\n\n/** Action to update transaction configuration using a callback. */\nexport type TransactionPayControllerSetTransactionConfigAction = {\n type: `${typeof CONTROLLER_NAME}:setTransactionConfig`;\n handler: (transactionId: string, callback: TransactionConfigCallback) => void;\n};\n\n/** Configurable properties of a transaction. */\nexport type TransactionConfig = {\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\n/** Callback to update transaction config. */\nexport type TransactionConfigCallback = (config: TransactionConfig) => void;\n\nexport type TransactionPayControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n >;\n\nexport type TransactionPayControllerActions =\n | TransactionPayControllerGetDelegationTransactionAction\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerGetStrategyAction\n | TransactionPayControllerSetTransactionConfigAction\n | TransactionPayControllerUpdatePaymentTokenAction;\n\nexport type TransactionPayControllerEvents =\n TransactionPayControllerStateChangeEvent;\n\nexport type TransactionPayControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n TransactionPayControllerActions | AllowedActions,\n TransactionPayControllerEvents | AllowedEvents\n>;\n\n/** Options for the TransactionPayController. */\nexport type TransactionPayControllerOptions = {\n /** Callback to convert a transaction into a redeem delegation. */\n getDelegationTransaction: GetDelegationTransactionCallback;\n\n /** Callback to select the PayStrategy for a transaction. */\n getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\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/** State relating to a single transaction. */\nexport type TransactionData = {\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 /**\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/** 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 /** 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/** 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 the quote provider. */\n provider: 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 * Gas cost of the original user transaction on its native network.\n * Always calculated from the transaction's own gas params via\n * `calculateTransactionGasCost`, independent of any bridge quote fees.\n * Only populated on totals, not on individual quotes.\n */\n transactionGas?: 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: Amount;\n};\n\n/** Request to get quotes for a transaction. */\nexport type PayStrategyGetQuotesRequest = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quote requests for required tokens. */\n requests: QuoteRequest[];\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 /** 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\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 /** Retrieve quotes for required tokens. */\n getQuotes: (\n request: PayStrategyGetQuotesRequest,\n ) => Promise<TransactionPayQuote<OriginalQuote>[]>;\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: Amount;\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/** 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/** 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.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CurrencyRateControllerActions,\n TokenBalancesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type { TokenRatesControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { TokensControllerGetStateAction } 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 { BridgeControllerActions } from '@metamask/bridge-controller';\nimport type { BridgeStatusControllerStateChangeEvent } from '@metamask/bridge-status-controller';\nimport type { BridgeStatusControllerActions } from '@metamask/bridge-status-controller';\nimport type { GasFeeControllerActions } from '@metamask/gas-fee-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { NetworkControllerFindNetworkClientIdByChainIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-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 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 { CONTROLLER_NAME, TransactionPayStrategy } from './constants';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | BridgeControllerActions\n | BridgeStatusControllerActions\n | CurrencyRateControllerActions\n | GasFeeControllerActions\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\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 | BridgeStatusControllerStateChangeEvent\n | TransactionControllerStateChangeEvent\n | TransactionControllerUnapprovedTransactionAddedEvent;\n\nexport type TransactionPayControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n>;\n\nexport type TransactionPayControllerGetDelegationTransactionAction = {\n type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`;\n handler: GetDelegationTransactionCallback;\n};\n\n/** Action to get the pay strategy type used for a transaction. */\nexport type TransactionPayControllerGetStrategyAction = {\n type: `${typeof CONTROLLER_NAME}:getStrategy`;\n handler: (transaction: TransactionMeta) => TransactionPayStrategy;\n};\n\n/** Action to update the payment token for a transaction. */\nexport type TransactionPayControllerUpdatePaymentTokenAction = {\n type: `${typeof CONTROLLER_NAME}:updatePaymentToken`;\n handler: (request: UpdatePaymentTokenRequest) => void;\n};\n\n/** Action to update transaction configuration using a callback. */\nexport type TransactionPayControllerSetTransactionConfigAction = {\n type: `${typeof CONTROLLER_NAME}:setTransactionConfig`;\n handler: (transactionId: string, callback: TransactionConfigCallback) => void;\n};\n\n/** Configurable properties of a transaction. */\nexport type TransactionConfig = {\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\n/** Callback to update transaction config. */\nexport type TransactionConfigCallback = (config: TransactionConfig) => void;\n\nexport type TransactionPayControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n >;\n\nexport type TransactionPayControllerActions =\n | TransactionPayControllerGetDelegationTransactionAction\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerGetStrategyAction\n | TransactionPayControllerSetTransactionConfigAction\n | TransactionPayControllerUpdatePaymentTokenAction;\n\nexport type TransactionPayControllerEvents =\n TransactionPayControllerStateChangeEvent;\n\nexport type TransactionPayControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n TransactionPayControllerActions | AllowedActions,\n TransactionPayControllerEvents | AllowedEvents\n>;\n\n/** Options for the TransactionPayController. */\nexport type TransactionPayControllerOptions = {\n /** Callback to convert a transaction into a redeem delegation. */\n getDelegationTransaction: GetDelegationTransactionCallback;\n\n /** Callback to select the PayStrategy for a transaction. */\n getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\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/** State relating to a single transaction. */\nexport type TransactionData = {\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 /**\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/** 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 /** 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/** 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 the quote provider. */\n provider: 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 * Gas cost of the original user transaction on its native network.\n * Always calculated from the transaction's own gas params via\n * `calculateTransactionGasCost`, independent of any bridge quote fees.\n * Only populated on totals, not on individual quotes.\n */\n transactionGas?: 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 /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quote requests for required tokens. */\n requests: QuoteRequest[];\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 /** 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\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 /** Retrieve quotes for required tokens. */\n getQuotes: (\n request: PayStrategyGetQuotesRequest,\n ) => Promise<TransactionPayQuote<OriginalQuote>[]>;\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/** 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/** 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"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -244,7 +244,7 @@ export type TransactionPayQuote<OriginalQuote> = {
|
|
|
244
244
|
/** Name of the strategy used to retrieve the quote. */
|
|
245
245
|
strategy: TransactionPayStrategy;
|
|
246
246
|
/** Amount of target token provided. */
|
|
247
|
-
targetAmount:
|
|
247
|
+
targetAmount: FiatValue;
|
|
248
248
|
};
|
|
249
249
|
/** Request to get quotes for a transaction. */
|
|
250
250
|
export type PayStrategyGetQuotesRequest = {
|
|
@@ -312,7 +312,7 @@ export type TransactionPayTotals = {
|
|
|
312
312
|
/** Total amount of source token required. */
|
|
313
313
|
sourceAmount: Amount;
|
|
314
314
|
/** Total amount of target token provided. */
|
|
315
|
-
targetAmount:
|
|
315
|
+
targetAmount: FiatValue;
|
|
316
316
|
/** Overall total cost for the target transaction and all quotes. */
|
|
317
317
|
total: FiatValue;
|
|
318
318
|
};
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,6BAA6B,EAC7B,qCAAqC,EACtC,qCAAqC;AACtC,OAAO,KAAK,EAAE,kCAAkC,EAAE,qCAAqC;AACvF,OAAO,KAAK,EAAE,8BAA8B,EA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M,yBAAyB,GAAG;IACtC,uCAAuC;IACvC,aAAa,EAAE,MAAM,CAAC;IAEtB,wCAAwC;IACxC,YAAY,EAAE,GAAG,CAAC;IAElB,yCAAyC;IACzC,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,gEAAgE;AAChE,MAAM,MAAM,gCAAgC,GAAG,CAAC,EAC9C,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,eAAe,CAAC;CAC9B,KAAK,OAAO,CAAC;IACZ,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,IAAI,EAAE,GAAG,CAAC;IACV,EAAE,EAAE,GAAG,CAAC;IACR,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC,CAAC;AAEH,0CAA0C;AAC1C,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG;IAC/B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IAEd,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -244,7 +244,7 @@ export type TransactionPayQuote<OriginalQuote> = {
|
|
|
244
244
|
/** Name of the strategy used to retrieve the quote. */
|
|
245
245
|
strategy: TransactionPayStrategy;
|
|
246
246
|
/** Amount of target token provided. */
|
|
247
|
-
targetAmount:
|
|
247
|
+
targetAmount: FiatValue;
|
|
248
248
|
};
|
|
249
249
|
/** Request to get quotes for a transaction. */
|
|
250
250
|
export type PayStrategyGetQuotesRequest = {
|
|
@@ -312,7 +312,7 @@ export type TransactionPayTotals = {
|
|
|
312
312
|
/** Total amount of source token required. */
|
|
313
313
|
sourceAmount: Amount;
|
|
314
314
|
/** Total amount of target token provided. */
|
|
315
|
-
targetAmount:
|
|
315
|
+
targetAmount: FiatValue;
|
|
316
316
|
/** Overall total cost for the target transaction and all quotes. */
|
|
317
317
|
total: FiatValue;
|
|
318
318
|
};
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.m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AAC;IAEzB,6CAA6C;IAC7C,YAAY,EAAE,MAAM,CAAC;IAErB,6CAA6C;IAC7C,YAAY,EAAE,SAAS,CAAC;IAExB,oEAAoE;IACpE,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,6DAA6D;AAC7D,MAAM,MAAM,yBAAyB,GAAG;IACtC,uCAAuC;IACvC,aAAa,EAAE,MAAM,CAAC;IAEtB,wCAAwC;IACxC,YAAY,EAAE,GAAG,CAAC;IAElB,yCAAyC;IACzC,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,gEAAgE;AAChE,MAAM,MAAM,gCAAgC,GAAG,CAAC,EAC9C,WAAW,GACZ,EAAE;IACD,WAAW,EAAE,eAAe,CAAC;CAC9B,KAAK,OAAO,CAAC;IACZ,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,IAAI,EAAE,GAAG,CAAC;IACV,EAAE,EAAE,GAAG,CAAC;IACR,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC,CAAC;AAEH,0CAA0C;AAC1C,MAAM,MAAM,MAAM,GAAG,SAAS,GAAG;IAC/B,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IAEd,gEAAgE;IAChE,GAAG,EAAE,MAAM,CAAC;CACb,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CurrencyRateControllerActions,\n TokenBalancesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type { TokenRatesControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { TokensControllerGetStateAction } 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 { BridgeControllerActions } from '@metamask/bridge-controller';\nimport type { BridgeStatusControllerStateChangeEvent } from '@metamask/bridge-status-controller';\nimport type { BridgeStatusControllerActions } from '@metamask/bridge-status-controller';\nimport type { GasFeeControllerActions } from '@metamask/gas-fee-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { NetworkControllerFindNetworkClientIdByChainIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-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 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 { CONTROLLER_NAME, TransactionPayStrategy } from './constants';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | BridgeControllerActions\n | BridgeStatusControllerActions\n | CurrencyRateControllerActions\n | GasFeeControllerActions\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\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 | BridgeStatusControllerStateChangeEvent\n | TransactionControllerStateChangeEvent\n | TransactionControllerUnapprovedTransactionAddedEvent;\n\nexport type TransactionPayControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n>;\n\nexport type TransactionPayControllerGetDelegationTransactionAction = {\n type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`;\n handler: GetDelegationTransactionCallback;\n};\n\n/** Action to get the pay strategy type used for a transaction. */\nexport type TransactionPayControllerGetStrategyAction = {\n type: `${typeof CONTROLLER_NAME}:getStrategy`;\n handler: (transaction: TransactionMeta) => TransactionPayStrategy;\n};\n\n/** Action to update the payment token for a transaction. */\nexport type TransactionPayControllerUpdatePaymentTokenAction = {\n type: `${typeof CONTROLLER_NAME}:updatePaymentToken`;\n handler: (request: UpdatePaymentTokenRequest) => void;\n};\n\n/** Action to update transaction configuration using a callback. */\nexport type TransactionPayControllerSetTransactionConfigAction = {\n type: `${typeof CONTROLLER_NAME}:setTransactionConfig`;\n handler: (transactionId: string, callback: TransactionConfigCallback) => void;\n};\n\n/** Configurable properties of a transaction. */\nexport type TransactionConfig = {\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\n/** Callback to update transaction config. */\nexport type TransactionConfigCallback = (config: TransactionConfig) => void;\n\nexport type TransactionPayControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n >;\n\nexport type TransactionPayControllerActions =\n | TransactionPayControllerGetDelegationTransactionAction\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerGetStrategyAction\n | TransactionPayControllerSetTransactionConfigAction\n | TransactionPayControllerUpdatePaymentTokenAction;\n\nexport type TransactionPayControllerEvents =\n TransactionPayControllerStateChangeEvent;\n\nexport type TransactionPayControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n TransactionPayControllerActions | AllowedActions,\n TransactionPayControllerEvents | AllowedEvents\n>;\n\n/** Options for the TransactionPayController. */\nexport type TransactionPayControllerOptions = {\n /** Callback to convert a transaction into a redeem delegation. */\n getDelegationTransaction: GetDelegationTransactionCallback;\n\n /** Callback to select the PayStrategy for a transaction. */\n getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\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/** State relating to a single transaction. */\nexport type TransactionData = {\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 /**\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/** 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 /** 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/** 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 the quote provider. */\n provider: 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 * Gas cost of the original user transaction on its native network.\n * Always calculated from the transaction's own gas params via\n * `calculateTransactionGasCost`, independent of any bridge quote fees.\n * Only populated on totals, not on individual quotes.\n */\n transactionGas?: 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: Amount;\n};\n\n/** Request to get quotes for a transaction. */\nexport type PayStrategyGetQuotesRequest = {\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quote requests for required tokens. */\n requests: QuoteRequest[];\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 /** 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\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 /** Retrieve quotes for required tokens. */\n getQuotes: (\n request: PayStrategyGetQuotesRequest,\n ) => Promise<TransactionPayQuote<OriginalQuote>[]>;\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: Amount;\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/** 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/** 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":"","sourcesContent":["import type {\n CurrencyRateControllerActions,\n TokenBalancesControllerGetStateAction,\n} from '@metamask/assets-controllers';\nimport type { TokenRatesControllerGetStateAction } from '@metamask/assets-controllers';\nimport type { TokensControllerGetStateAction } 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 { BridgeControllerActions } from '@metamask/bridge-controller';\nimport type { BridgeStatusControllerStateChangeEvent } from '@metamask/bridge-status-controller';\nimport type { BridgeStatusControllerActions } from '@metamask/bridge-status-controller';\nimport type { GasFeeControllerActions } from '@metamask/gas-fee-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { NetworkControllerFindNetworkClientIdByChainIdAction } from '@metamask/network-controller';\nimport type { NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-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 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 { CONTROLLER_NAME, TransactionPayStrategy } from './constants';\n\nexport type AllowedActions =\n | AccountTrackerControllerGetStateAction\n | BridgeControllerActions\n | BridgeStatusControllerActions\n | CurrencyRateControllerActions\n | GasFeeControllerActions\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction\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 | BridgeStatusControllerStateChangeEvent\n | TransactionControllerStateChangeEvent\n | TransactionControllerUnapprovedTransactionAddedEvent;\n\nexport type TransactionPayControllerGetStateAction = ControllerGetStateAction<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n>;\n\nexport type TransactionPayControllerGetDelegationTransactionAction = {\n type: `${typeof CONTROLLER_NAME}:getDelegationTransaction`;\n handler: GetDelegationTransactionCallback;\n};\n\n/** Action to get the pay strategy type used for a transaction. */\nexport type TransactionPayControllerGetStrategyAction = {\n type: `${typeof CONTROLLER_NAME}:getStrategy`;\n handler: (transaction: TransactionMeta) => TransactionPayStrategy;\n};\n\n/** Action to update the payment token for a transaction. */\nexport type TransactionPayControllerUpdatePaymentTokenAction = {\n type: `${typeof CONTROLLER_NAME}:updatePaymentToken`;\n handler: (request: UpdatePaymentTokenRequest) => void;\n};\n\n/** Action to update transaction configuration using a callback. */\nexport type TransactionPayControllerSetTransactionConfigAction = {\n type: `${typeof CONTROLLER_NAME}:setTransactionConfig`;\n handler: (transactionId: string, callback: TransactionConfigCallback) => void;\n};\n\n/** Configurable properties of a transaction. */\nexport type TransactionConfig = {\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\n/** Callback to update transaction config. */\nexport type TransactionConfigCallback = (config: TransactionConfig) => void;\n\nexport type TransactionPayControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState\n >;\n\nexport type TransactionPayControllerActions =\n | TransactionPayControllerGetDelegationTransactionAction\n | TransactionPayControllerGetStateAction\n | TransactionPayControllerGetStrategyAction\n | TransactionPayControllerSetTransactionConfigAction\n | TransactionPayControllerUpdatePaymentTokenAction;\n\nexport type TransactionPayControllerEvents =\n TransactionPayControllerStateChangeEvent;\n\nexport type TransactionPayControllerMessenger = Messenger<\n typeof CONTROLLER_NAME,\n TransactionPayControllerActions | AllowedActions,\n TransactionPayControllerEvents | AllowedEvents\n>;\n\n/** Options for the TransactionPayController. */\nexport type TransactionPayControllerOptions = {\n /** Callback to convert a transaction into a redeem delegation. */\n getDelegationTransaction: GetDelegationTransactionCallback;\n\n /** Callback to select the PayStrategy for a transaction. */\n getStrategy?: (transaction: TransactionMeta) => TransactionPayStrategy;\n\n /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\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/** State relating to a single transaction. */\nexport type TransactionData = {\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 /**\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/** 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 /** 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/** 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 the quote provider. */\n provider: 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 * Gas cost of the original user transaction on its native network.\n * Always calculated from the transaction's own gas params via\n * `calculateTransactionGasCost`, independent of any bridge quote fees.\n * Only populated on totals, not on individual quotes.\n */\n transactionGas?: 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 /** Controller messenger. */\n messenger: TransactionPayControllerMessenger;\n\n /** Quote requests for required tokens. */\n requests: QuoteRequest[];\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 /** 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\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 /** Retrieve quotes for required tokens. */\n getQuotes: (\n request: PayStrategyGetQuotesRequest,\n ) => Promise<TransactionPayQuote<OriginalQuote>[]>;\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/** 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/** 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"]}
|
package/dist/utils/token.cjs
CHANGED
|
@@ -5,10 +5,6 @@ const controller_utils_1 = require("@metamask/controller-utils");
|
|
|
5
5
|
const bignumber_js_1 = require("bignumber.js");
|
|
6
6
|
const lodash_1 = require("lodash");
|
|
7
7
|
const constants_1 = require("../constants.cjs");
|
|
8
|
-
const STABLECOINS = {
|
|
9
|
-
[constants_1.CHAIN_ID_ARBITRUM]: [constants_1.ARBITRUM_USDC_ADDRESS.toLowerCase()],
|
|
10
|
-
[constants_1.CHAIN_ID_POLYGON]: [constants_1.POLYGON_USDCE_ADDRESS.toLowerCase()],
|
|
11
|
-
};
|
|
12
8
|
/**
|
|
13
9
|
* Check if two tokens are the same (same address and chain).
|
|
14
10
|
*
|
|
@@ -137,7 +133,7 @@ function getTokenFiatRate(messenger, tokenAddress, chainId) {
|
|
|
137
133
|
if (nativeToFiatRate === null || nativeToUsdRate === null) {
|
|
138
134
|
return undefined;
|
|
139
135
|
}
|
|
140
|
-
const isStablecoin = STABLECOINS[chainId]?.includes(tokenAddress.toLowerCase());
|
|
136
|
+
const isStablecoin = constants_1.STABLECOINS[chainId]?.includes(tokenAddress.toLowerCase());
|
|
141
137
|
const usdRate = isStablecoin
|
|
142
138
|
? '1'
|
|
143
139
|
: new bignumber_js_1.BigNumber(tokenToNativeRate ?? 1)
|
package/dist/utils/token.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.cjs","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":";;;AAAA,iEAAkE;AAElE,+CAAyC;AACzC,mCAA8B;AAE9B,gDAMsB;AAGtB,MAAM,WAAW,GAAuB;IACtC,CAAC,6BAAiB,CAAC,EAAE,CAAC,iCAAqB,CAAC,WAAW,EAAS,CAAC;IACjE,CAAC,4BAAgB,CAAC,EAAE,CAAC,iCAAqB,CAAC,WAAW,EAAS,CAAC;CACjE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CACzB,MAAsC,EACtC,MAAsC;IAEtC,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE;QAC7D,MAAM,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,CAClC,CAAC;AACJ,CAAC;AARD,kCAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,SAA4C,EAC5C,OAAY,EACZ,OAAY,EACZ,YAAiB;IAEjB,MAAM,2BAA2B,GAAG,SAAS,CAAC,IAAI,CAChD,kCAAkC,CACnC,CAAC;IAEF,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAS,CAAC;IACvD,MAAM,sBAAsB,GAAG,IAAA,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eAAe,CAChB,CAAC;QAEF,OAAO,oBAAoB,CAAC,aAAa,CAAC,MAAM,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { toChecksumHexAddress } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { uniq } from 'lodash';\n\nimport {\n ARBITRUM_USDC_ADDRESS,\n CHAIN_ID_ARBITRUM,\n CHAIN_ID_POLYGON,\n NATIVE_TOKEN_ADDRESS,\n POLYGON_USDCE_ADDRESS,\n} from '../constants';\nimport type { FiatRates, TransactionPayControllerMessenger } from '../types';\n\nconst STABLECOINS: Record<Hex, Hex[]> = {\n [CHAIN_ID_ARBITRUM]: [ARBITRUM_USDC_ADDRESS.toLowerCase() as Hex],\n [CHAIN_ID_POLYGON]: [POLYGON_USDCE_ADDRESS.toLowerCase() as Hex],\n};\n\n/**\n * Check if two tokens are the same (same address and chain).\n *\n * @param token1 - First token identifier.\n * @param token1.address - Token address.\n * @param token1.chainId - Token chain ID.\n * @param token2 - Second token identifier.\n * @param token2.address - Token address.\n * @param token2.chainId - Token chain ID.\n * @returns True if tokens are the same, false otherwise.\n */\nexport function isSameToken(\n token1: { address: Hex; chainId: Hex },\n token2: { address: Hex; chainId: Hex },\n): boolean {\n return (\n token1.address.toLowerCase() === token2.address.toLowerCase() &&\n token1.chainId === token2.chainId\n );\n}\n\n/**\n * Get the token balance for a specific account and token.\n *\n * @param messenger - Controller messenger.\n * @param account - Address of the account.\n * @param chainId - Id of the chain.\n * @param tokenAddress - Address of the token contract.\n * @returns Raw token balance as a decimal string.\n */\nexport function getTokenBalance(\n messenger: TransactionPayControllerMessenger,\n account: Hex,\n chainId: Hex,\n tokenAddress: Hex,\n): string {\n const tokenBalanceControllerState = messenger.call(\n 'TokenBalancesController:getState',\n );\n\n const normalizedAccount = account.toLowerCase() as Hex;\n const normalizedTokenAddress = toChecksumHexAddress(tokenAddress) as Hex;\n const isNative = normalizedTokenAddress === getNativeToken(chainId);\n\n const balanceHex =\n tokenBalanceControllerState.tokenBalances?.[normalizedAccount]?.[chainId]?.[\n normalizedTokenAddress\n ];\n\n if (!isNative && balanceHex === undefined) {\n return '0';\n }\n\n if (!isNative && balanceHex) {\n return new BigNumber(balanceHex, 16).toString(10);\n }\n\n const accountTrackerControllerState = messenger.call(\n 'AccountTrackerController:getState',\n );\n\n const chainAccounts =\n accountTrackerControllerState.accountsByChainId?.[chainId];\n\n const checksumAccount = toChecksumHexAddress(normalizedAccount) as Hex;\n const nativeBalanceHex = chainAccounts?.[checksumAccount]?.balance as Hex;\n\n return new BigNumber(nativeBalanceHex ?? '0x0', 16).toString(10);\n}\n\n/**\n * Get the token balance for a specific account and token.\n *\n * @param messenger - Controller messenger.\n * @param account - Address of the account.\n * @returns The token balance as a BigNumber.\n */\nexport function getAllTokenBalances(\n messenger: TransactionPayControllerMessenger,\n account: Hex,\n): {\n balance: string;\n chainId: Hex;\n tokenAddress: Hex;\n}[] {\n const tokenBalanceControllerState = messenger.call(\n 'TokenBalancesController:getState',\n );\n\n const accountTrackerControllerState = messenger.call(\n 'AccountTrackerController:getState',\n );\n\n const nativeChainIds = Object.keys(\n accountTrackerControllerState.accountsByChainId,\n ) as Hex[];\n\n const normalizedAccount = account.toLowerCase() as Hex;\n\n const balancesByTokenByChain =\n tokenBalanceControllerState.tokenBalances?.[normalizedAccount];\n\n const tokenChainIds = Object.keys(balancesByTokenByChain) as Hex[];\n const chainIds = uniq([...tokenChainIds, ...nativeChainIds]);\n\n return chainIds.flatMap((chainId) => {\n const tokenAddresses = [\n ...(Object.keys(balancesByTokenByChain[chainId] ?? {}) as Hex[]),\n getNativeToken(chainId),\n ];\n\n return tokenAddresses.map((tokenAddress) => ({\n chainId,\n tokenAddress,\n balance: getTokenBalance(messenger, account, chainId, tokenAddress),\n }));\n });\n}\n\n/**\n * Get the token decimals for a specific token.\n *\n * @param messenger - Controller messenger.\n * @param tokenAddress - Address of the token contract.\n * @param chainId - Id of the chain.\n * @returns The token decimals or undefined if the token is not found.\n */\nexport function getTokenInfo(\n messenger: TransactionPayControllerMessenger,\n tokenAddress: Hex,\n chainId: Hex,\n): { decimals: number; symbol: string } | undefined {\n const controllerState = messenger.call('TokensController:getState');\n const normalizedTokenAddress = tokenAddress.toLowerCase() as Hex;\n\n const isNative =\n normalizedTokenAddress === getNativeToken(chainId).toLowerCase();\n\n const token = Object.values(controllerState.allTokens?.[chainId] ?? {})\n .flat()\n .find(\n (singleToken) =>\n singleToken.address.toLowerCase() === normalizedTokenAddress,\n );\n\n if (!token && !isNative) {\n return undefined;\n }\n\n if (token && !isNative) {\n return { decimals: Number(token.decimals), symbol: token.symbol };\n }\n\n const ticker = getTicker(chainId, messenger);\n\n if (!ticker) {\n return undefined;\n }\n\n return { decimals: 18, symbol: ticker };\n}\n\n/**\n * Calculate fiat rates for a specific token.\n *\n * @param messenger - Controller messenger.\n * @param tokenAddress - Address of the token contract.\n * @param chainId - Id of the chain.\n * @returns An object containing the USD and fiat rates, or undefined if rates are not available.\n */\nexport function getTokenFiatRate(\n messenger: TransactionPayControllerMessenger,\n tokenAddress: Hex,\n chainId: Hex,\n): FiatRates | undefined {\n const ticker = getTicker(chainId, messenger);\n\n if (!ticker) {\n return undefined;\n }\n\n const rateControllerState = messenger.call('TokenRatesController:getState');\n\n const currencyRateControllerState = messenger.call(\n 'CurrencyRateController:getState',\n );\n\n const normalizedTokenAddress = toChecksumHexAddress(tokenAddress) as Hex;\n const isNative = normalizedTokenAddress === getNativeToken(chainId);\n\n const tokenToNativeRate =\n rateControllerState.marketData?.[chainId]?.[normalizedTokenAddress]?.price;\n\n if (tokenToNativeRate === undefined && !isNative) {\n return undefined;\n }\n\n const {\n conversionRate: nativeToFiatRate,\n usdConversionRate: nativeToUsdRate,\n } = currencyRateControllerState.currencyRates?.[ticker] ?? {\n conversionRate: null,\n usdConversionRate: null,\n };\n\n if (nativeToFiatRate === null || nativeToUsdRate === null) {\n return undefined;\n }\n const isStablecoin = STABLECOINS[chainId]?.includes(\n tokenAddress.toLowerCase() as Hex,\n );\n\n const usdRate = isStablecoin\n ? '1'\n : new BigNumber(tokenToNativeRate ?? 1)\n .multipliedBy(nativeToUsdRate)\n .toString(10);\n\n const fiatRate = new BigNumber(tokenToNativeRate ?? 1)\n .multipliedBy(nativeToFiatRate)\n .toString(10);\n\n return { usdRate, fiatRate };\n}\n\n/**\n * Get the native token address for a given chain ID.\n *\n * @param chainId - Chain ID.\n * @returns - Native token address for the given chain ID.\n */\nexport function getNativeToken(chainId: Hex): Hex {\n switch (chainId) {\n case '0x89':\n return '0x0000000000000000000000000000000000001010';\n default:\n return NATIVE_TOKEN_ADDRESS;\n }\n}\n\n/**\n * Get the ticker for a given chain ID.\n *\n * @param chainId - Chain ID.\n * @param messenger - Messenger instance.\n * @returns Ticker symbol for the given chain ID or undefined if not found.\n */\nfunction getTicker(\n chainId: Hex,\n messenger: TransactionPayControllerMessenger,\n): string | undefined {\n try {\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n\n const networkConfiguration = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n return networkConfiguration.configuration.ticker;\n } catch {\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"token.cjs","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":";;;AAAA,iEAAkE;AAElE,+CAAyC;AACzC,mCAA8B;AAE9B,gDAAiE;AAGjE;;;;;;;;;;GAUG;AACH,SAAgB,WAAW,CACzB,MAAsC,EACtC,MAAsC;IAEtC,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE;QAC7D,MAAM,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,CAClC,CAAC;AACJ,CAAC;AARD,kCAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,eAAe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;;;;;GAMG;AACH,SAAS,SAAS,CAChB,OAAY,EACZ,SAA4C;IAE5C,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,SAAS,CAAC,IAAI,CACpC,gDAAgD,EAChD,OAAO,CACR,CAAC;QAEF,MAAM,oBAAoB,GAAG,SAAS,CAAC,IAAI,CACzC,wCAAwC,EACxC,eAAe,CAChB,CAAC;QAEF,OAAO,oBAAoB,CAAC,aAAa,CAAC,MAAM,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { toChecksumHexAddress } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { uniq } from 'lodash';\n\nimport { NATIVE_TOKEN_ADDRESS, STABLECOINS } from '../constants';\nimport type { FiatRates, TransactionPayControllerMessenger } from '../types';\n\n/**\n * Check if two tokens are the same (same address and chain).\n *\n * @param token1 - First token identifier.\n * @param token1.address - Token address.\n * @param token1.chainId - Token chain ID.\n * @param token2 - Second token identifier.\n * @param token2.address - Token address.\n * @param token2.chainId - Token chain ID.\n * @returns True if tokens are the same, false otherwise.\n */\nexport function isSameToken(\n token1: { address: Hex; chainId: Hex },\n token2: { address: Hex; chainId: Hex },\n): boolean {\n return (\n token1.address.toLowerCase() === token2.address.toLowerCase() &&\n token1.chainId === token2.chainId\n );\n}\n\n/**\n * Get the token balance for a specific account and token.\n *\n * @param messenger - Controller messenger.\n * @param account - Address of the account.\n * @param chainId - Id of the chain.\n * @param tokenAddress - Address of the token contract.\n * @returns Raw token balance as a decimal string.\n */\nexport function getTokenBalance(\n messenger: TransactionPayControllerMessenger,\n account: Hex,\n chainId: Hex,\n tokenAddress: Hex,\n): string {\n const tokenBalanceControllerState = messenger.call(\n 'TokenBalancesController:getState',\n );\n\n const normalizedAccount = account.toLowerCase() as Hex;\n const normalizedTokenAddress = toChecksumHexAddress(tokenAddress) as Hex;\n const isNative = normalizedTokenAddress === getNativeToken(chainId);\n\n const balanceHex =\n tokenBalanceControllerState.tokenBalances?.[normalizedAccount]?.[chainId]?.[\n normalizedTokenAddress\n ];\n\n if (!isNative && balanceHex === undefined) {\n return '0';\n }\n\n if (!isNative && balanceHex) {\n return new BigNumber(balanceHex, 16).toString(10);\n }\n\n const accountTrackerControllerState = messenger.call(\n 'AccountTrackerController:getState',\n );\n\n const chainAccounts =\n accountTrackerControllerState.accountsByChainId?.[chainId];\n\n const checksumAccount = toChecksumHexAddress(normalizedAccount) as Hex;\n const nativeBalanceHex = chainAccounts?.[checksumAccount]?.balance as Hex;\n\n return new BigNumber(nativeBalanceHex ?? '0x0', 16).toString(10);\n}\n\n/**\n * Get the token balance for a specific account and token.\n *\n * @param messenger - Controller messenger.\n * @param account - Address of the account.\n * @returns The token balance as a BigNumber.\n */\nexport function getAllTokenBalances(\n messenger: TransactionPayControllerMessenger,\n account: Hex,\n): {\n balance: string;\n chainId: Hex;\n tokenAddress: Hex;\n}[] {\n const tokenBalanceControllerState = messenger.call(\n 'TokenBalancesController:getState',\n );\n\n const accountTrackerControllerState = messenger.call(\n 'AccountTrackerController:getState',\n );\n\n const nativeChainIds = Object.keys(\n accountTrackerControllerState.accountsByChainId,\n ) as Hex[];\n\n const normalizedAccount = account.toLowerCase() as Hex;\n\n const balancesByTokenByChain =\n tokenBalanceControllerState.tokenBalances?.[normalizedAccount];\n\n const tokenChainIds = Object.keys(balancesByTokenByChain) as Hex[];\n const chainIds = uniq([...tokenChainIds, ...nativeChainIds]);\n\n return chainIds.flatMap((chainId) => {\n const tokenAddresses = [\n ...(Object.keys(balancesByTokenByChain[chainId] ?? {}) as Hex[]),\n getNativeToken(chainId),\n ];\n\n return tokenAddresses.map((tokenAddress) => ({\n chainId,\n tokenAddress,\n balance: getTokenBalance(messenger, account, chainId, tokenAddress),\n }));\n });\n}\n\n/**\n * Get the token decimals for a specific token.\n *\n * @param messenger - Controller messenger.\n * @param tokenAddress - Address of the token contract.\n * @param chainId - Id of the chain.\n * @returns The token decimals or undefined if the token is not found.\n */\nexport function getTokenInfo(\n messenger: TransactionPayControllerMessenger,\n tokenAddress: Hex,\n chainId: Hex,\n): { decimals: number; symbol: string } | undefined {\n const controllerState = messenger.call('TokensController:getState');\n const normalizedTokenAddress = tokenAddress.toLowerCase() as Hex;\n\n const isNative =\n normalizedTokenAddress === getNativeToken(chainId).toLowerCase();\n\n const token = Object.values(controllerState.allTokens?.[chainId] ?? {})\n .flat()\n .find(\n (singleToken) =>\n singleToken.address.toLowerCase() === normalizedTokenAddress,\n );\n\n if (!token && !isNative) {\n return undefined;\n }\n\n if (token && !isNative) {\n return { decimals: Number(token.decimals), symbol: token.symbol };\n }\n\n const ticker = getTicker(chainId, messenger);\n\n if (!ticker) {\n return undefined;\n }\n\n return { decimals: 18, symbol: ticker };\n}\n\n/**\n * Calculate fiat rates for a specific token.\n *\n * @param messenger - Controller messenger.\n * @param tokenAddress - Address of the token contract.\n * @param chainId - Id of the chain.\n * @returns An object containing the USD and fiat rates, or undefined if rates are not available.\n */\nexport function getTokenFiatRate(\n messenger: TransactionPayControllerMessenger,\n tokenAddress: Hex,\n chainId: Hex,\n): FiatRates | undefined {\n const ticker = getTicker(chainId, messenger);\n\n if (!ticker) {\n return undefined;\n }\n\n const rateControllerState = messenger.call('TokenRatesController:getState');\n\n const currencyRateControllerState = messenger.call(\n 'CurrencyRateController:getState',\n );\n\n const normalizedTokenAddress = toChecksumHexAddress(tokenAddress) as Hex;\n const isNative = normalizedTokenAddress === getNativeToken(chainId);\n\n const tokenToNativeRate =\n rateControllerState.marketData?.[chainId]?.[normalizedTokenAddress]?.price;\n\n if (tokenToNativeRate === undefined && !isNative) {\n return undefined;\n }\n\n const {\n conversionRate: nativeToFiatRate,\n usdConversionRate: nativeToUsdRate,\n } = currencyRateControllerState.currencyRates?.[ticker] ?? {\n conversionRate: null,\n usdConversionRate: null,\n };\n\n if (nativeToFiatRate === null || nativeToUsdRate === null) {\n return undefined;\n }\n const isStablecoin = STABLECOINS[chainId]?.includes(\n tokenAddress.toLowerCase() as Hex,\n );\n\n const usdRate = isStablecoin\n ? '1'\n : new BigNumber(tokenToNativeRate ?? 1)\n .multipliedBy(nativeToUsdRate)\n .toString(10);\n\n const fiatRate = new BigNumber(tokenToNativeRate ?? 1)\n .multipliedBy(nativeToFiatRate)\n .toString(10);\n\n return { usdRate, fiatRate };\n}\n\n/**\n * Get the native token address for a given chain ID.\n *\n * @param chainId - Chain ID.\n * @returns - Native token address for the given chain ID.\n */\nexport function getNativeToken(chainId: Hex): Hex {\n switch (chainId) {\n case '0x89':\n return '0x0000000000000000000000000000000000001010';\n default:\n return NATIVE_TOKEN_ADDRESS;\n }\n}\n\n/**\n * Get the ticker for a given chain ID.\n *\n * @param chainId - Chain ID.\n * @param messenger - Messenger instance.\n * @returns Ticker symbol for the given chain ID or undefined if not found.\n */\nfunction getTicker(\n chainId: Hex,\n messenger: TransactionPayControllerMessenger,\n): string | undefined {\n try {\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n\n const networkConfiguration = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n return networkConfiguration.configuration.ticker;\n } catch {\n return undefined;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.cts","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"token.d.cts","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAK3C,OAAO,KAAK,EAAE,SAAS,EAAE,iCAAiC,EAAE,qBAAiB;AAE7E;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,EACtC,MAAM,EAAE;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,GACrC,OAAO,CAKT;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,iCAAiC,EAC5C,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,GAAG,EACZ,YAAY,EAAE,GAAG,GAChB,MAAM,CAiCR;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,iCAAiC,EAC5C,OAAO,EAAE,GAAG,GACX;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC;IACb,YAAY,EAAE,GAAG,CAAC;CACnB,EAAE,CAiCF;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,iCAAiC,EAC5C,YAAY,EAAE,GAAG,EACjB,OAAO,EAAE,GAAG,GACX;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA6BlD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,iCAAiC,EAC5C,YAAY,EAAE,GAAG,EACjB,OAAO,EAAE,GAAG,GACX,SAAS,GAAG,SAAS,CAiDvB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,CAOhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.d.mts","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"token.d.mts","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAK3C,OAAO,KAAK,EAAE,SAAS,EAAE,iCAAiC,EAAE,qBAAiB;AAE7E;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,EACtC,MAAM,EAAE;IAAE,OAAO,EAAE,GAAG,CAAC;IAAC,OAAO,EAAE,GAAG,CAAA;CAAE,GACrC,OAAO,CAKT;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,iCAAiC,EAC5C,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE,GAAG,EACZ,YAAY,EAAE,GAAG,GAChB,MAAM,CAiCR;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,SAAS,EAAE,iCAAiC,EAC5C,OAAO,EAAE,GAAG,GACX;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,GAAG,CAAC;IACb,YAAY,EAAE,GAAG,CAAC;CACnB,EAAE,CAiCF;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,iCAAiC,EAC5C,YAAY,EAAE,GAAG,EACjB,OAAO,EAAE,GAAG,GACX;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CA6BlD;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,iCAAiC,EAC5C,YAAY,EAAE,GAAG,EACjB,OAAO,EAAE,GAAG,GACX,SAAS,GAAG,SAAS,CAiDvB;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,GAAG,CAOhD"}
|
package/dist/utils/token.mjs
CHANGED
|
@@ -2,11 +2,7 @@ import { toChecksumHexAddress } from "@metamask/controller-utils";
|
|
|
2
2
|
import { BigNumber } from "bignumber.js";
|
|
3
3
|
import $lodash from "lodash";
|
|
4
4
|
const { uniq } = $lodash;
|
|
5
|
-
import {
|
|
6
|
-
const STABLECOINS = {
|
|
7
|
-
[CHAIN_ID_ARBITRUM]: [ARBITRUM_USDC_ADDRESS.toLowerCase()],
|
|
8
|
-
[CHAIN_ID_POLYGON]: [POLYGON_USDCE_ADDRESS.toLowerCase()],
|
|
9
|
-
};
|
|
5
|
+
import { NATIVE_TOKEN_ADDRESS, STABLECOINS } from "../constants.mjs";
|
|
10
6
|
/**
|
|
11
7
|
* Check if two tokens are the same (same address and chain).
|
|
12
8
|
*
|
package/dist/utils/token.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token.mjs","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mCAAmC;AAElE,OAAO,EAAE,SAAS,EAAE,qBAAqB;;;AAGzC,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,qBAAqB,EACtB,yBAAqB;AAGtB,MAAM,WAAW,GAAuB;IACtC,CAAC,iBAAiB,CAAC,EAAE,CAAC,qBAAqB,CAAC,WAAW,EAAS,CAAC;IACjE,CAAC,gBAAgB,CAAC,EAAE,CAAC,qBAAqB,CAAC,WAAW,EAAS,CAAC;CACjE,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CACzB,MAAsC,EACtC,MAAsC;IAEtC,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE;QAC7D,MAAM,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,CAClC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,SAA4C,EAC5C,OAAY,EACZ,OAAY,EACZ,YAAiB;IAEjB,MAAM,2BAA2B,GAAG,SAAS,CAAC,IAAI,CAChD,kCAAkC,CACnC,CAAC;IAEF,MAAM,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAS,CAAC;IACvD,MAAM,sBAA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IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { toChecksumHexAddress } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { uniq } from 'lodash';\n\nimport {\n ARBITRUM_USDC_ADDRESS,\n CHAIN_ID_ARBITRUM,\n CHAIN_ID_POLYGON,\n NATIVE_TOKEN_ADDRESS,\n POLYGON_USDCE_ADDRESS,\n} from '../constants';\nimport type { FiatRates, TransactionPayControllerMessenger } from '../types';\n\nconst STABLECOINS: Record<Hex, Hex[]> = {\n [CHAIN_ID_ARBITRUM]: [ARBITRUM_USDC_ADDRESS.toLowerCase() as Hex],\n [CHAIN_ID_POLYGON]: [POLYGON_USDCE_ADDRESS.toLowerCase() as Hex],\n};\n\n/**\n * Check if two tokens are the same (same address and chain).\n *\n * @param token1 - First token identifier.\n * @param token1.address - Token address.\n * @param token1.chainId - Token chain ID.\n * @param token2 - Second token identifier.\n * @param token2.address - Token address.\n * @param token2.chainId - Token chain ID.\n * @returns True if tokens are the same, false otherwise.\n */\nexport function isSameToken(\n token1: { address: Hex; chainId: Hex },\n token2: { address: Hex; chainId: Hex },\n): boolean {\n return (\n token1.address.toLowerCase() === token2.address.toLowerCase() &&\n token1.chainId === token2.chainId\n );\n}\n\n/**\n * Get the token balance for a specific account and token.\n *\n * @param messenger - Controller messenger.\n * @param account - Address of the account.\n * @param chainId - Id of the chain.\n * @param tokenAddress - Address of the token contract.\n * @returns Raw token balance as a decimal string.\n */\nexport function getTokenBalance(\n messenger: TransactionPayControllerMessenger,\n account: Hex,\n chainId: Hex,\n tokenAddress: Hex,\n): string {\n const tokenBalanceControllerState = messenger.call(\n 'TokenBalancesController:getState',\n );\n\n const normalizedAccount = account.toLowerCase() as Hex;\n const normalizedTokenAddress = toChecksumHexAddress(tokenAddress) as Hex;\n const isNative = normalizedTokenAddress === getNativeToken(chainId);\n\n const balanceHex =\n tokenBalanceControllerState.tokenBalances?.[normalizedAccount]?.[chainId]?.[\n normalizedTokenAddress\n ];\n\n if (!isNative && balanceHex === undefined) {\n return '0';\n }\n\n if (!isNative && balanceHex) {\n return new BigNumber(balanceHex, 16).toString(10);\n }\n\n const accountTrackerControllerState = messenger.call(\n 'AccountTrackerController:getState',\n );\n\n const chainAccounts =\n accountTrackerControllerState.accountsByChainId?.[chainId];\n\n const checksumAccount = toChecksumHexAddress(normalizedAccount) as Hex;\n const nativeBalanceHex = chainAccounts?.[checksumAccount]?.balance as Hex;\n\n return new BigNumber(nativeBalanceHex ?? '0x0', 16).toString(10);\n}\n\n/**\n * Get the token balance for a specific account and token.\n *\n * @param messenger - Controller messenger.\n * @param account - Address of the account.\n * @returns The token balance as a BigNumber.\n */\nexport function getAllTokenBalances(\n messenger: TransactionPayControllerMessenger,\n account: Hex,\n): {\n balance: string;\n chainId: Hex;\n tokenAddress: Hex;\n}[] {\n const tokenBalanceControllerState = messenger.call(\n 'TokenBalancesController:getState',\n );\n\n const accountTrackerControllerState = messenger.call(\n 'AccountTrackerController:getState',\n );\n\n const nativeChainIds = Object.keys(\n accountTrackerControllerState.accountsByChainId,\n ) as Hex[];\n\n const normalizedAccount = account.toLowerCase() as Hex;\n\n const balancesByTokenByChain =\n tokenBalanceControllerState.tokenBalances?.[normalizedAccount];\n\n const tokenChainIds = Object.keys(balancesByTokenByChain) as Hex[];\n const chainIds = uniq([...tokenChainIds, ...nativeChainIds]);\n\n return chainIds.flatMap((chainId) => {\n const tokenAddresses = [\n ...(Object.keys(balancesByTokenByChain[chainId] ?? {}) as Hex[]),\n getNativeToken(chainId),\n ];\n\n return tokenAddresses.map((tokenAddress) => ({\n chainId,\n tokenAddress,\n balance: getTokenBalance(messenger, account, chainId, tokenAddress),\n }));\n });\n}\n\n/**\n * Get the token decimals for a specific token.\n *\n * @param messenger - Controller messenger.\n * @param tokenAddress - Address of the token contract.\n * @param chainId - Id of the chain.\n * @returns The token decimals or undefined if the token is not found.\n */\nexport function getTokenInfo(\n messenger: TransactionPayControllerMessenger,\n tokenAddress: Hex,\n chainId: Hex,\n): { decimals: number; symbol: string } | undefined {\n const controllerState = messenger.call('TokensController:getState');\n const normalizedTokenAddress = tokenAddress.toLowerCase() as Hex;\n\n const isNative =\n normalizedTokenAddress === getNativeToken(chainId).toLowerCase();\n\n const token = Object.values(controllerState.allTokens?.[chainId] ?? {})\n .flat()\n .find(\n (singleToken) =>\n singleToken.address.toLowerCase() === normalizedTokenAddress,\n );\n\n if (!token && !isNative) {\n return undefined;\n }\n\n if (token && !isNative) {\n return { decimals: Number(token.decimals), symbol: token.symbol };\n }\n\n const ticker = getTicker(chainId, messenger);\n\n if (!ticker) {\n return undefined;\n }\n\n return { decimals: 18, symbol: ticker };\n}\n\n/**\n * Calculate fiat rates for a specific token.\n *\n * @param messenger - Controller messenger.\n * @param tokenAddress - Address of the token contract.\n * @param chainId - Id of the chain.\n * @returns An object containing the USD and fiat rates, or undefined if rates are not available.\n */\nexport function getTokenFiatRate(\n messenger: TransactionPayControllerMessenger,\n tokenAddress: Hex,\n chainId: Hex,\n): FiatRates | undefined {\n const ticker = getTicker(chainId, messenger);\n\n if (!ticker) {\n return undefined;\n }\n\n const rateControllerState = messenger.call('TokenRatesController:getState');\n\n const currencyRateControllerState = messenger.call(\n 'CurrencyRateController:getState',\n );\n\n const normalizedTokenAddress = toChecksumHexAddress(tokenAddress) as Hex;\n const isNative = normalizedTokenAddress === getNativeToken(chainId);\n\n const tokenToNativeRate =\n rateControllerState.marketData?.[chainId]?.[normalizedTokenAddress]?.price;\n\n if (tokenToNativeRate === undefined && !isNative) {\n return undefined;\n }\n\n const {\n conversionRate: nativeToFiatRate,\n usdConversionRate: nativeToUsdRate,\n } = currencyRateControllerState.currencyRates?.[ticker] ?? {\n conversionRate: null,\n usdConversionRate: null,\n };\n\n if (nativeToFiatRate === null || nativeToUsdRate === null) {\n return undefined;\n }\n const isStablecoin = STABLECOINS[chainId]?.includes(\n tokenAddress.toLowerCase() as Hex,\n );\n\n const usdRate = isStablecoin\n ? '1'\n : new BigNumber(tokenToNativeRate ?? 1)\n .multipliedBy(nativeToUsdRate)\n .toString(10);\n\n const fiatRate = new BigNumber(tokenToNativeRate ?? 1)\n .multipliedBy(nativeToFiatRate)\n .toString(10);\n\n return { usdRate, fiatRate };\n}\n\n/**\n * Get the native token address for a given chain ID.\n *\n * @param chainId - Chain ID.\n * @returns - Native token address for the given chain ID.\n */\nexport function getNativeToken(chainId: Hex): Hex {\n switch (chainId) {\n case '0x89':\n return '0x0000000000000000000000000000000000001010';\n default:\n return NATIVE_TOKEN_ADDRESS;\n }\n}\n\n/**\n * Get the ticker for a given chain ID.\n *\n * @param chainId - Chain ID.\n * @param messenger - Messenger instance.\n * @returns Ticker symbol for the given chain ID or undefined if not found.\n */\nfunction getTicker(\n chainId: Hex,\n messenger: TransactionPayControllerMessenger,\n): string | undefined {\n try {\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n\n const networkConfiguration = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n return networkConfiguration.configuration.ticker;\n } catch {\n return undefined;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"token.mjs","sourceRoot":"","sources":["../../src/utils/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mCAAmC;AAElE,OAAO,EAAE,SAAS,EAAE,qBAAqB;;;AAGzC,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,yBAAqB;AAGjE;;;;;;;;;;GAUG;AACH,MAAM,UAAU,WAAW,CACzB,MAAsC,EACtC,MAAsC;IAEtC,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE;QAC7D,MAAM,CAAC,OAAO,KAAK,MAAM,CAAC,OAAO,CAClC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,e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M,eAAe,GAAG,SAAS,CAAC,IAAI,CACpC,gDAAgD,EAChD,OAAO,CACR,CAAC;QAEF,MAAM,oBAAoB,GAAG,SAAS,CAAC,IAAI,CACzC,wCAAwC,EACxC,eAAe,CAChB,CAAC;QAEF,OAAO,oBAAoB,CAAC,aAAa,CAAC,MAAM,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC","sourcesContent":["import { toChecksumHexAddress } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\nimport { uniq } from 'lodash';\n\nimport { NATIVE_TOKEN_ADDRESS, STABLECOINS } from '../constants';\nimport type { FiatRates, TransactionPayControllerMessenger } from '../types';\n\n/**\n * Check if two tokens are the same (same address and chain).\n *\n * @param token1 - First token identifier.\n * @param token1.address - Token address.\n * @param token1.chainId - Token chain ID.\n * @param token2 - Second token identifier.\n * @param token2.address - Token address.\n * @param token2.chainId - Token chain ID.\n * @returns True if tokens are the same, false otherwise.\n */\nexport function isSameToken(\n token1: { address: Hex; chainId: Hex },\n token2: { address: Hex; chainId: Hex },\n): boolean {\n return (\n token1.address.toLowerCase() === token2.address.toLowerCase() &&\n token1.chainId === token2.chainId\n );\n}\n\n/**\n * Get the token balance for a specific account and token.\n *\n * @param messenger - Controller messenger.\n * @param account - Address of the account.\n * @param chainId - Id of the chain.\n * @param tokenAddress - Address of the token contract.\n * @returns Raw token balance as a decimal string.\n */\nexport function getTokenBalance(\n messenger: TransactionPayControllerMessenger,\n account: Hex,\n chainId: Hex,\n tokenAddress: Hex,\n): string {\n const tokenBalanceControllerState = messenger.call(\n 'TokenBalancesController:getState',\n );\n\n const normalizedAccount = account.toLowerCase() as Hex;\n const normalizedTokenAddress = toChecksumHexAddress(tokenAddress) as Hex;\n const isNative = normalizedTokenAddress === getNativeToken(chainId);\n\n const balanceHex =\n tokenBalanceControllerState.tokenBalances?.[normalizedAccount]?.[chainId]?.[\n normalizedTokenAddress\n ];\n\n if (!isNative && balanceHex === undefined) {\n return '0';\n }\n\n if (!isNative && balanceHex) {\n return new BigNumber(balanceHex, 16).toString(10);\n }\n\n const accountTrackerControllerState = messenger.call(\n 'AccountTrackerController:getState',\n );\n\n const chainAccounts =\n accountTrackerControllerState.accountsByChainId?.[chainId];\n\n const checksumAccount = toChecksumHexAddress(normalizedAccount) as Hex;\n const nativeBalanceHex = chainAccounts?.[checksumAccount]?.balance as Hex;\n\n return new BigNumber(nativeBalanceHex ?? '0x0', 16).toString(10);\n}\n\n/**\n * Get the token balance for a specific account and token.\n *\n * @param messenger - Controller messenger.\n * @param account - Address of the account.\n * @returns The token balance as a BigNumber.\n */\nexport function getAllTokenBalances(\n messenger: TransactionPayControllerMessenger,\n account: Hex,\n): {\n balance: string;\n chainId: Hex;\n tokenAddress: Hex;\n}[] {\n const tokenBalanceControllerState = messenger.call(\n 'TokenBalancesController:getState',\n );\n\n const accountTrackerControllerState = messenger.call(\n 'AccountTrackerController:getState',\n );\n\n const nativeChainIds = Object.keys(\n accountTrackerControllerState.accountsByChainId,\n ) as Hex[];\n\n const normalizedAccount = account.toLowerCase() as Hex;\n\n const balancesByTokenByChain =\n tokenBalanceControllerState.tokenBalances?.[normalizedAccount];\n\n const tokenChainIds = Object.keys(balancesByTokenByChain) as Hex[];\n const chainIds = uniq([...tokenChainIds, ...nativeChainIds]);\n\n return chainIds.flatMap((chainId) => {\n const tokenAddresses = [\n ...(Object.keys(balancesByTokenByChain[chainId] ?? {}) as Hex[]),\n getNativeToken(chainId),\n ];\n\n return tokenAddresses.map((tokenAddress) => ({\n chainId,\n tokenAddress,\n balance: getTokenBalance(messenger, account, chainId, tokenAddress),\n }));\n });\n}\n\n/**\n * Get the token decimals for a specific token.\n *\n * @param messenger - Controller messenger.\n * @param tokenAddress - Address of the token contract.\n * @param chainId - Id of the chain.\n * @returns The token decimals or undefined if the token is not found.\n */\nexport function getTokenInfo(\n messenger: TransactionPayControllerMessenger,\n tokenAddress: Hex,\n chainId: Hex,\n): { decimals: number; symbol: string } | undefined {\n const controllerState = messenger.call('TokensController:getState');\n const normalizedTokenAddress = tokenAddress.toLowerCase() as Hex;\n\n const isNative =\n normalizedTokenAddress === getNativeToken(chainId).toLowerCase();\n\n const token = Object.values(controllerState.allTokens?.[chainId] ?? {})\n .flat()\n .find(\n (singleToken) =>\n singleToken.address.toLowerCase() === normalizedTokenAddress,\n );\n\n if (!token && !isNative) {\n return undefined;\n }\n\n if (token && !isNative) {\n return { decimals: Number(token.decimals), symbol: token.symbol };\n }\n\n const ticker = getTicker(chainId, messenger);\n\n if (!ticker) {\n return undefined;\n }\n\n return { decimals: 18, symbol: ticker };\n}\n\n/**\n * Calculate fiat rates for a specific token.\n *\n * @param messenger - Controller messenger.\n * @param tokenAddress - Address of the token contract.\n * @param chainId - Id of the chain.\n * @returns An object containing the USD and fiat rates, or undefined if rates are not available.\n */\nexport function getTokenFiatRate(\n messenger: TransactionPayControllerMessenger,\n tokenAddress: Hex,\n chainId: Hex,\n): FiatRates | undefined {\n const ticker = getTicker(chainId, messenger);\n\n if (!ticker) {\n return undefined;\n }\n\n const rateControllerState = messenger.call('TokenRatesController:getState');\n\n const currencyRateControllerState = messenger.call(\n 'CurrencyRateController:getState',\n );\n\n const normalizedTokenAddress = toChecksumHexAddress(tokenAddress) as Hex;\n const isNative = normalizedTokenAddress === getNativeToken(chainId);\n\n const tokenToNativeRate =\n rateControllerState.marketData?.[chainId]?.[normalizedTokenAddress]?.price;\n\n if (tokenToNativeRate === undefined && !isNative) {\n return undefined;\n }\n\n const {\n conversionRate: nativeToFiatRate,\n usdConversionRate: nativeToUsdRate,\n } = currencyRateControllerState.currencyRates?.[ticker] ?? {\n conversionRate: null,\n usdConversionRate: null,\n };\n\n if (nativeToFiatRate === null || nativeToUsdRate === null) {\n return undefined;\n }\n const isStablecoin = STABLECOINS[chainId]?.includes(\n tokenAddress.toLowerCase() as Hex,\n );\n\n const usdRate = isStablecoin\n ? '1'\n : new BigNumber(tokenToNativeRate ?? 1)\n .multipliedBy(nativeToUsdRate)\n .toString(10);\n\n const fiatRate = new BigNumber(tokenToNativeRate ?? 1)\n .multipliedBy(nativeToFiatRate)\n .toString(10);\n\n return { usdRate, fiatRate };\n}\n\n/**\n * Get the native token address for a given chain ID.\n *\n * @param chainId - Chain ID.\n * @returns - Native token address for the given chain ID.\n */\nexport function getNativeToken(chainId: Hex): Hex {\n switch (chainId) {\n case '0x89':\n return '0x0000000000000000000000000000000000001010';\n default:\n return NATIVE_TOKEN_ADDRESS;\n }\n}\n\n/**\n * Get the ticker for a given chain ID.\n *\n * @param chainId - Chain ID.\n * @param messenger - Messenger instance.\n * @returns Ticker symbol for the given chain ID or undefined if not found.\n */\nfunction getTicker(\n chainId: Hex,\n messenger: TransactionPayControllerMessenger,\n): string | undefined {\n try {\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n\n const networkConfiguration = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n\n return networkConfiguration.configuration.ticker;\n } catch {\n return undefined;\n }\n}\n"]}
|
package/dist/utils/totals.cjs
CHANGED
|
@@ -26,7 +26,7 @@ function calculateTotals({ isMaxAmount, quotes, messenger, tokens, transaction,
|
|
|
26
26
|
}
|
|
27
27
|
: transactionNetworkFee;
|
|
28
28
|
const sourceAmount = sumAmounts(quotes.map((quote) => quote.sourceAmount));
|
|
29
|
-
const targetAmount =
|
|
29
|
+
const targetAmount = sumFiat(quotes.map((quote) => quote.targetAmount));
|
|
30
30
|
const quoteTokens = tokens.filter((singleToken) => !singleToken.skipIfBalance);
|
|
31
31
|
const amountFiat = sumProperty(quoteTokens, (token) => token.amountFiat);
|
|
32
32
|
const amountUsd = sumProperty(quoteTokens, (token) => token.amountUsd);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"totals.cjs","sourceRoot":"","sources":["../../src/utils/totals.ts"],"names":[],"mappings":";;;AACA,+CAAyC;AAE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EhD,OAAO,IAAI;SACR,GAAG,CAAC,WAAW,CAAC;SAChB,MAAM,CAAY,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,IAAI,wBAAS,CAAC,CAAC,CAAC,CAAC;SACxE,QAAQ,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport { BigNumber } from 'bignumber.js';\n\nimport { calculateTransactionGasCost } from './gas';\nimport type {\n Amount,\n FiatValue,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n TransactionPayRequiredToken,\n TransactionPayTotals,\n} from '../types';\n\n/**\n * Calculate totals for a list of quotes and tokens.\n *\n * @param request - Request parameters.\n * @param request.isMaxAmount - Whether the transaction is a maximum amount transaction.\n * @param request.quotes - List of bridge quotes.\n * @param request.messenger - Controller messenger.\n * @param request.tokens - List of required tokens.\n * @param request.transaction - Transaction metadata.\n * @returns The calculated totals in USD and fiat currency.\n */\nexport function calculateTotals({\n isMaxAmount,\n quotes,\n messenger,\n tokens,\n transaction,\n}: {\n isMaxAmount?: boolean;\n quotes: TransactionPayQuote<unknown>[];\n messenger: TransactionPayControllerMessenger;\n tokens: TransactionPayRequiredToken[];\n transaction: TransactionMeta;\n}): TransactionPayTotals {\n const providerFee = sumFiat(quotes.map((quote) => quote.fees.provider));\n\n const sourceNetworkFeeMax = sumAmounts(\n quotes.map((quote) => quote.fees.sourceNetwork.max),\n );\n\n const sourceNetworkFeeEstimate = sumAmounts(\n quotes.map((quote) => quote.fees.sourceNetwork.estimate),\n );\n\n const transactionNetworkFee = calculateTransactionGasCost(\n transaction,\n messenger,\n );\n\n const targetNetworkFee = quotes?.length\n ? {\n ...sumFiat(quotes.map((quote) => quote.fees.targetNetwork)),\n isGasFeeToken: false,\n }\n : transactionNetworkFee;\n\n const sourceAmount = sumAmounts(quotes.map((quote) => quote.sourceAmount));\n const targetAmount = sumFiat(quotes.map((quote) => quote.targetAmount));\n\n const quoteTokens = tokens.filter(\n (singleToken) => !singleToken.skipIfBalance,\n );\n\n const amountFiat = sumProperty(quoteTokens, (token) => token.amountFiat);\n const amountUsd = sumProperty(quoteTokens, (token) => token.amountUsd);\n const hasQuotes = quotes.length > 0;\n\n const totalFiat = new BigNumber(providerFee.fiat)\n .plus(sourceNetworkFeeEstimate.fiat)\n .plus(targetNetworkFee.fiat)\n .plus(isMaxAmount && hasQuotes ? targetAmount.fiat : amountFiat)\n .toString(10);\n\n const totalUsd = new BigNumber(providerFee.usd)\n .plus(sourceNetworkFeeEstimate.usd)\n .plus(targetNetworkFee.usd)\n .plus(isMaxAmount && hasQuotes ? targetAmount.usd : amountUsd)\n .toString(10);\n\n const estimatedDuration = Number(\n sumProperty(quotes, (quote) => quote.estimatedDuration),\n );\n\n const isSourceGasFeeToken = quotes.some(\n (quote) => quote.fees.isSourceGasFeeToken,\n );\n\n const isTargetGasFeeToken =\n Boolean(targetNetworkFee.isGasFeeToken) ||\n quotes.some((quote) => quote.fees.isTargetGasFeeToken);\n\n return {\n estimatedDuration,\n fees: {\n isSourceGasFeeToken,\n isTargetGasFeeToken,\n provider: providerFee,\n sourceNetwork: {\n estimate: sourceNetworkFeeEstimate,\n max: sourceNetworkFeeMax,\n },\n targetNetwork: targetNetworkFee,\n transactionGas: {\n fiat: transactionNetworkFee.fiat,\n usd: transactionNetworkFee.usd,\n },\n },\n sourceAmount,\n targetAmount,\n total: {\n fiat: totalFiat,\n usd: totalUsd,\n },\n };\n}\n\n/**\n * Sum a list of amounts.\n *\n * @param data - List of amounts.\n * @returns Total amount.\n */\nfunction sumAmounts(data: Amount[]): Amount {\n const fiatValue = sumFiat(data);\n const human = sumProperty(data, (item) => item.human);\n const raw = sumProperty(data, (item) => item.raw);\n\n return {\n ...fiatValue,\n human,\n raw,\n };\n}\n\n/**\n * Sum a list of fiat value.\n *\n * @param data - List of fiat values.\n * @returns Total fiat value.\n */\nfunction sumFiat(data: FiatValue[]): FiatValue {\n const fiat = sumProperty(data, (item) => item.fiat);\n const usd = sumProperty(data, (item) => item.usd);\n return { fiat, usd };\n}\n\n/**\n * Sum a specific property from a list of items.\n *\n * @param data - List of items.\n * @param getProperty - Function to extract the property to sum from each item.\n * @returns The summed value as a string.\n */\nfunction sumProperty<DataType>(\n data: DataType[],\n getProperty: (item: DataType) => BigNumber.Value,\n): string {\n return data\n .map(getProperty)\n .reduce<BigNumber>((total, value) => total.plus(value), new BigNumber(0))\n .toString(10);\n}\n"]}
|