@metamask/transaction-pay-controller 18.2.0 → 19.0.1
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 +21 -2
- package/dist/TransactionPayController.cjs +5 -3
- package/dist/TransactionPayController.cjs.map +1 -1
- package/dist/TransactionPayController.d.cts.map +1 -1
- package/dist/TransactionPayController.d.mts.map +1 -1
- package/dist/TransactionPayController.mjs +5 -3
- package/dist/TransactionPayController.mjs.map +1 -1
- package/dist/strategy/relay/constants.cjs +3 -1
- package/dist/strategy/relay/constants.cjs.map +1 -1
- package/dist/strategy/relay/constants.d.cts +2 -0
- package/dist/strategy/relay/constants.d.cts.map +1 -1
- package/dist/strategy/relay/constants.d.mts +2 -0
- package/dist/strategy/relay/constants.d.mts.map +1 -1
- package/dist/strategy/relay/constants.mjs +2 -0
- package/dist/strategy/relay/constants.mjs.map +1 -1
- package/dist/strategy/relay/hyperliquid-withdraw.cjs +194 -0
- package/dist/strategy/relay/hyperliquid-withdraw.cjs.map +1 -0
- package/dist/strategy/relay/hyperliquid-withdraw.d.cts +18 -0
- package/dist/strategy/relay/hyperliquid-withdraw.d.cts.map +1 -0
- package/dist/strategy/relay/hyperliquid-withdraw.d.mts +18 -0
- package/dist/strategy/relay/hyperliquid-withdraw.d.mts.map +1 -0
- package/dist/strategy/relay/hyperliquid-withdraw.mjs +190 -0
- package/dist/strategy/relay/hyperliquid-withdraw.mjs.map +1 -0
- package/dist/strategy/relay/relay-submit.cjs +8 -1
- package/dist/strategy/relay/relay-submit.cjs.map +1 -1
- package/dist/strategy/relay/relay-submit.d.cts.map +1 -1
- package/dist/strategy/relay/relay-submit.d.mts.map +1 -1
- package/dist/strategy/relay/relay-submit.mjs +8 -1
- package/dist/strategy/relay/relay-submit.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +2 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +2 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/feature-flags.cjs +161 -29
- package/dist/utils/feature-flags.cjs.map +1 -1
- package/dist/utils/feature-flags.d.cts +19 -4
- package/dist/utils/feature-flags.d.cts.map +1 -1
- package/dist/utils/feature-flags.d.mts +19 -4
- package/dist/utils/feature-flags.d.mts.map +1 -1
- package/dist/utils/feature-flags.mjs +159 -28
- package/dist/utils/feature-flags.mjs.map +1 -1
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [
|
|
10
|
+
## [19.0.1]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Bump `@metamask/bridge-controller` from `^69.2.3` to `^70.0.0` ([#8340](https://github.com/MetaMask/core/pull/8340))
|
|
15
|
+
- Bump `@metamask/bridge-status-controller` from `^70.0.3` to `^70.0.4` ([#8340](https://github.com/MetaMask/core/pull/8340))
|
|
16
|
+
- Add route-based `confirmations_pay` strategy resolution ([#8282](https://github.com/MetaMask/core/pull/8282))
|
|
17
|
+
|
|
18
|
+
## [19.0.0]
|
|
11
19
|
|
|
12
20
|
### Added
|
|
13
21
|
|
|
22
|
+
- **BREAKING:** Add `KeyringControllerSignTypedMessageAction` to `AllowedActions` for HyperLiquid EIP-712 signing ([#8314](https://github.com/MetaMask/core/pull/8314))
|
|
23
|
+
- Clients must now provide `KeyringController:signTypedMessage` permission when constructing the controller messenger
|
|
24
|
+
- Add HyperLiquid withdrawal submission via Relay ([#8314](https://github.com/MetaMask/core/pull/8314))
|
|
14
25
|
- Add HyperLiquid source quote support for Relay strategy ([#8285](https://github.com/MetaMask/core/pull/8285))
|
|
26
|
+
- Bump `@metamask/assets-controller` from `^3.2.0` to `^3.2.1` ([#8325](https://github.com/MetaMask/core/pull/8325))
|
|
27
|
+
- Bump `@metamask/assets-controllers` from `^102.0.0` to `^103.0.0` ([#8325](https://github.com/MetaMask/core/pull/8325))
|
|
28
|
+
- Bump `@metamask/bridge-controller` from `^69.2.2` to `^69.2.3` ([#8325](https://github.com/MetaMask/core/pull/8325))
|
|
29
|
+
- Bump `@metamask/bridge-status-controller` from `^70.0.2` to `^70.0.3` ([#8325](https://github.com/MetaMask/core/pull/8325))
|
|
30
|
+
|
|
31
|
+
## [18.2.0]
|
|
15
32
|
|
|
16
33
|
### Changed
|
|
17
34
|
|
|
@@ -584,7 +601,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
584
601
|
|
|
585
602
|
- Initial release ([#6820](https://github.com/MetaMask/core/pull/6820))
|
|
586
603
|
|
|
587
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@
|
|
604
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@19.0.1...HEAD
|
|
605
|
+
[19.0.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@19.0.0...@metamask/transaction-pay-controller@19.0.1
|
|
606
|
+
[19.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@18.2.0...@metamask/transaction-pay-controller@19.0.0
|
|
588
607
|
[18.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@18.1.0...@metamask/transaction-pay-controller@18.2.0
|
|
589
608
|
[18.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@18.0.0...@metamask/transaction-pay-controller@18.1.0
|
|
590
609
|
[18.0.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-pay-controller@17.1.0...@metamask/transaction-pay-controller@18.0.0
|
|
@@ -200,8 +200,10 @@ _TransactionPayController_getDelegationTransaction = new WeakMap(), _Transaction
|
|
|
200
200
|
const strategyCandidates = __classPrivateFieldGet(this, _TransactionPayController_getStrategies, "f")?.call(this, transaction) ??
|
|
201
201
|
(__classPrivateFieldGet(this, _TransactionPayController_getStrategy, "f") ? [__classPrivateFieldGet(this, _TransactionPayController_getStrategy, "f").call(this, transaction)] : []);
|
|
202
202
|
const validStrategies = strategyCandidates.filter((strategy) => (0, constants_1.isTransactionPayStrategy)(strategy));
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
203
|
+
if (validStrategies.length) {
|
|
204
|
+
return validStrategies;
|
|
205
|
+
}
|
|
206
|
+
const paymentToken = this.state.transactionData[transaction.id]?.paymentToken;
|
|
207
|
+
return (0, feature_flags_1.getStrategyOrder)(this.messenger, paymentToken?.chainId, paymentToken?.address, transaction.type);
|
|
206
208
|
};
|
|
207
209
|
//# sourceMappingURL=TransactionPayController.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayController.cjs","sourceRoot":"","sources":["../src/TransactionPayController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+DAA2D;AAG3D,mCAA8B;AAE9B,2EAAkE;AAClE,6EAAoE;AACpE,+CAIqB;AACrB,iEAA0D;AAW1D,6DAAyD;AACzD,+CAA8C;AAC9C,+DAA6D;AAC7D,yDAA6D;AAE7D,MAAM,yBAAyB,GAAG;IAChC,0BAA0B;IAC1B,aAAa;IACb,sBAAsB;IACtB,mBAAmB;IACnB,oBAAoB;CACZ,CAAC;AAEX,MAAM,aAAa,GAAiD;IAClE,eAAe,EAAE;QACf,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,eAAe,GAAG,GAAkC,EAAE,CAAC,CAAC;IAC5D,eAAe,EAAE,EAAE;CACpB,CAAC,CAAC;AAEH,MAAa,wBAAyB,SAAQ,gCAI7C;IAWC,YAAY,EACV,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,SAAS,EACT,KAAK,GAC2B;QAChC,KAAK,CAAC;YACJ,IAAI,EAAE,2BAAe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,gGAA2B,CAAC,IAAI,CAAC,IAAI,CAAC;YACzD,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,eAAe,EAAE,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,aAAa,CAAC;YAC1D,aAAa;YACb,qBAAqB,EAAE,uBAAA,IAAI,4FAAuB,CAAC,IAAI,CAAC,IAAI,CAAC;SAC9D,CAAC,CAAC,KAAK,CAAC,aAAI,CAAC,CAAC;IACjB,CAAC;AACH,CAAC,qHAGC,WAA4B;IAE5B,MAAM,kBAAkB,GACtB,uBAAA,IAAI,+CAAe,EAAE,KAArB,IAAI,EAAkB,WAAW,CAAC;QAClC,CAAC,uBAAA,IAAI,6CAAa,CAAC,CAAC,CAAC,CAAC,uBAAA,IAAI,6CAAa,MAAjB,IAAI,EAAc,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE9D,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAC/C,CAAC,QAAQ,EAAsC,EAAE,CAC/C,IAAA,oCAAwB,EAAC,QAAQ,CAAC,CACrC,CAAC;IAEF,OAAO,eAAe,CAAC,MAAM;QAC3B,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,IAAA,gCAAgB,EAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Draft } from 'immer';\nimport { noop } from 'lodash';\n\nimport { updateFiatPayment } from './actions/update-fiat-payment';\nimport { updatePaymentToken } from './actions/update-payment-token';\nimport {\n CONTROLLER_NAME,\n isTransactionPayStrategy,\n TransactionPayStrategy,\n} from './constants';\nimport { QuoteRefresher } from './helpers/QuoteRefresher';\nimport type {\n GetDelegationTransactionCallback,\n TransactionConfigCallback,\n TransactionData,\n TransactionPayControllerMessenger,\n TransactionPayControllerOptions,\n TransactionPayControllerState,\n UpdateFiatPaymentRequest,\n UpdatePaymentTokenRequest,\n} from './types';\nimport { getStrategyOrder } from './utils/feature-flags';\nimport { updateQuotes } from './utils/quotes';\nimport { updateSourceAmounts } from './utils/source-amounts';\nimport { pollTransactionChanges } from './utils/transaction';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getDelegationTransaction',\n 'getStrategy',\n 'setTransactionConfig',\n 'updateFiatPayment',\n 'updatePaymentToken',\n] as const;\n\nconst stateMetadata: StateMetadata<TransactionPayControllerState> = {\n transactionData: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = (): TransactionPayControllerState => ({\n transactionData: {},\n});\n\nexport class TransactionPayController extends BaseController<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState,\n TransactionPayControllerMessenger\n> {\n readonly #getDelegationTransaction: GetDelegationTransactionCallback;\n\n readonly #getStrategy?: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy;\n\n readonly #getStrategies?: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy[];\n\n constructor({\n getDelegationTransaction,\n getStrategy,\n getStrategies,\n messenger,\n state,\n }: TransactionPayControllerOptions) {\n super({\n name: CONTROLLER_NAME,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#getDelegationTransaction = getDelegationTransaction;\n this.#getStrategy = getStrategy;\n this.#getStrategies = getStrategies;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n pollTransactionChanges(\n messenger,\n this.#updateTransactionData.bind(this),\n this.#removeTransactionData.bind(this),\n );\n\n // eslint-disable-next-line no-new\n new QuoteRefresher({\n getStrategies: this.#getStrategiesWithFallback.bind(this),\n messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Sets the transaction configuration.\n *\n * The callback receives the current configuration properties and can mutate\n * them in place. Updated values are written back to the transaction data.\n *\n * @param transactionId - The ID of the transaction to configure.\n * @param callback - A callback that receives a mutable {@link TransactionConfig} object.\n */\n setTransactionConfig(\n transactionId: string,\n callback: TransactionConfigCallback,\n ): void {\n this.#updateTransactionData(transactionId, (transactionData) => {\n const config = {\n isMaxAmount: transactionData.isMaxAmount,\n isPostQuote: transactionData.isPostQuote,\n isHyperliquidSource: transactionData.isHyperliquidSource,\n refundTo: transactionData.refundTo,\n };\n\n callback(config);\n\n transactionData.isMaxAmount = config.isMaxAmount;\n transactionData.isPostQuote = config.isPostQuote;\n transactionData.isHyperliquidSource = config.isHyperliquidSource;\n transactionData.refundTo = config.refundTo;\n });\n }\n\n /**\n * Updates the payment token for a transaction.\n *\n * Resolves token metadata and balances, then stores the new payment token\n * in the transaction data. This triggers recalculation of source amounts\n * and quote retrieval.\n *\n * @param request - The payment token update request containing the\n * transaction ID, token address, and chain ID.\n */\n updatePaymentToken(request: UpdatePaymentTokenRequest): void {\n updatePaymentToken(request, {\n messenger: this.messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Updates the fiat payment state for a transaction.\n *\n * The request callback receives the current fiat payment state and can\n * mutate it to update properties such as the selected payment method or\n * fiat amount.\n *\n * @param request - The fiat payment update request containing the\n * transaction ID and a callback to mutate fiat payment state.\n */\n updateFiatPayment(request: UpdateFiatPaymentRequest): void {\n updateFiatPayment(request, {\n messenger: this.messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Gets the delegation transaction for a given transaction.\n *\n * Converts the provided transaction into a redeem delegation by delegating\n * to the configured callback. Returns the delegation transaction data\n * including the encoded call data, target address, value, and an optional\n * authorization list.\n *\n * @param args - The arguments forwarded to the {@link GetDelegationTransactionCallback},\n * containing the transaction metadata.\n * @returns A promise resolving to the delegation transaction data.\n */\n getDelegationTransaction(\n ...args: Parameters<GetDelegationTransactionCallback>\n ): ReturnType<GetDelegationTransactionCallback> {\n return this.#getDelegationTransaction(...args);\n }\n\n /**\n * Gets the preferred strategy for a transaction.\n *\n * Returns the first strategy from the ordered list of strategies applicable\n * to the given transaction. Falls back to the default strategy order derived\n * from feature flags when no custom strategy callback is configured.\n *\n * @param transaction - The transaction metadata to determine the strategy for.\n * @returns The preferred {@link TransactionPayStrategy} for the transaction.\n */\n getStrategy(transaction: TransactionMeta): TransactionPayStrategy {\n return this.#getStrategiesWithFallback(transaction)[0];\n }\n\n #removeTransactionData(transactionId: string): void {\n this.update((state) => {\n delete state.transactionData[transactionId];\n });\n }\n\n #updateTransactionData(\n transactionId: string,\n fn: (transactionData: Draft<TransactionData>) => void,\n ): void {\n let shouldUpdateQuotes = false;\n\n this.update((state) => {\n const { transactionData } = state;\n let current = transactionData[transactionId];\n const originalPaymentToken = current?.paymentToken;\n const originalTokens = current?.tokens;\n const originalIsMaxAmount = current?.isMaxAmount;\n const originalIsPostQuote = current?.isPostQuote;\n\n if (!current) {\n transactionData[transactionId] = {\n fiatPayment: {},\n isLoading: false,\n tokens: [],\n };\n\n current = transactionData[transactionId];\n }\n\n fn(current);\n\n const isPaymentTokenUpdated =\n current.paymentToken?.address?.toLowerCase() !==\n originalPaymentToken?.address?.toLowerCase() ||\n current.paymentToken?.chainId !== originalPaymentToken?.chainId;\n\n const isTokensUpdated = current.tokens !== originalTokens;\n const isIsMaxUpdated = current.isMaxAmount !== originalIsMaxAmount;\n const isPostQuoteUpdated = current.isPostQuote !== originalIsPostQuote;\n\n if (\n isPaymentTokenUpdated ||\n isIsMaxUpdated ||\n isTokensUpdated ||\n isPostQuoteUpdated\n ) {\n updateSourceAmounts(transactionId, current as never, this.messenger);\n\n shouldUpdateQuotes = true;\n }\n });\n\n if (shouldUpdateQuotes) {\n updateQuotes({\n getStrategies: this.#getStrategiesWithFallback.bind(this),\n messenger: this.messenger,\n transactionData: this.state.transactionData[transactionId],\n transactionId,\n updateTransactionData: this.#updateTransactionData.bind(this),\n }).catch(noop);\n }\n }\n\n #getStrategiesWithFallback(\n transaction: TransactionMeta,\n ): TransactionPayStrategy[] {\n const strategyCandidates: unknown[] =\n this.#getStrategies?.(transaction) ??\n (this.#getStrategy ? [this.#getStrategy(transaction)] : []);\n\n const validStrategies = strategyCandidates.filter(\n (strategy): strategy is TransactionPayStrategy =>\n isTransactionPayStrategy(strategy),\n );\n\n return validStrategies.length\n ? validStrategies\n : getStrategyOrder(this.messenger);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TransactionPayController.cjs","sourceRoot":"","sources":["../src/TransactionPayController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,+DAA2D;AAG3D,mCAA8B;AAE9B,2EAAkE;AAClE,6EAAoE;AACpE,+CAIqB;AACrB,iEAA0D;AAW1D,6DAAyD;AACzD,+CAA8C;AAC9C,+DAA6D;AAC7D,yDAA6D;AAE7D,MAAM,yBAAyB,GAAG;IAChC,0BAA0B;IAC1B,aAAa;IACb,sBAAsB;IACtB,mBAAmB;IACnB,oBAAoB;CACZ,CAAC;AAEX,MAAM,aAAa,GAAiD;IAClE,eAAe,EAAE;QACf,sBAAsB,EAAE,KAAK;QAC7B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF,MAAM,eAAe,GAAG,GAAkC,EAAE,CAAC,CAAC;IAC5D,eAAe,EAAE,EAAE;CACpB,CAAC,CAAC;AAEH,MAAa,wBAAyB,SAAQ,gCAI7C;IAWC,YAAY,EACV,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,SAAS,EACT,KAAK,GAC2B;QAChC,KAAK,CAAC;YACJ,IAAI,EAAE,2BAAe;YACrB,QAAQ,EAAE,aAAa;YACvB,SAAS;YACT,KAAK,EAAE,EAAE,GAAG,eAAe,EAAE,EAAE,GAAG,KAAK,EAAE;SAC1C,CAAC,CAAC;;QAtBI,qEAA4D;QAE5D,wDAEmB;QAEnB,0DAEqB;QAgB5B,uBAAA,IAAI,sDAA6B,wBAAwB,MAAA,CAAC;QAC1D,uBAAA,IAAI,yCAAg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AAK,CAAC,aAAI,CAAC,CAAC;IACjB,CAAC;AACH,CAAC,qHAGC,WAA4B;IAE5B,MAAM,kBAAkB,GACtB,uBAAA,IAAI,+CAAe,EAAE,KAArB,IAAI,EAAkB,WAAW,CAAC;QAClC,CAAC,uBAAA,IAAI,6CAAa,CAAC,CAAC,CAAC,CAAC,uBAAA,IAAI,6CAAa,MAAjB,IAAI,EAAc,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE9D,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAC/C,CAAC,QAAQ,EAAsC,EAAE,CAC/C,IAAA,oCAAwB,EAAC,QAAQ,CAAC,CACrC,CAAC;IAEF,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;QAC3B,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,MAAM,YAAY,GAChB,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC;IAE3D,OAAO,IAAA,gCAAgB,EACrB,IAAI,CAAC,SAAS,EACd,YAAY,EAAE,OAAO,EACrB,YAAY,EAAE,OAAO,EACrB,WAAW,CAAC,IAAI,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Draft } from 'immer';\nimport { noop } from 'lodash';\n\nimport { updateFiatPayment } from './actions/update-fiat-payment';\nimport { updatePaymentToken } from './actions/update-payment-token';\nimport {\n CONTROLLER_NAME,\n isTransactionPayStrategy,\n TransactionPayStrategy,\n} from './constants';\nimport { QuoteRefresher } from './helpers/QuoteRefresher';\nimport type {\n GetDelegationTransactionCallback,\n TransactionConfigCallback,\n TransactionData,\n TransactionPayControllerMessenger,\n TransactionPayControllerOptions,\n TransactionPayControllerState,\n UpdateFiatPaymentRequest,\n UpdatePaymentTokenRequest,\n} from './types';\nimport { getStrategyOrder } from './utils/feature-flags';\nimport { updateQuotes } from './utils/quotes';\nimport { updateSourceAmounts } from './utils/source-amounts';\nimport { pollTransactionChanges } from './utils/transaction';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getDelegationTransaction',\n 'getStrategy',\n 'setTransactionConfig',\n 'updateFiatPayment',\n 'updatePaymentToken',\n] as const;\n\nconst stateMetadata: StateMetadata<TransactionPayControllerState> = {\n transactionData: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = (): TransactionPayControllerState => ({\n transactionData: {},\n});\n\nexport class TransactionPayController extends BaseController<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState,\n TransactionPayControllerMessenger\n> {\n readonly #getDelegationTransaction: GetDelegationTransactionCallback;\n\n readonly #getStrategy?: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy;\n\n readonly #getStrategies?: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy[];\n\n constructor({\n getDelegationTransaction,\n getStrategy,\n getStrategies,\n messenger,\n state,\n }: TransactionPayControllerOptions) {\n super({\n name: CONTROLLER_NAME,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#getDelegationTransaction = getDelegationTransaction;\n this.#getStrategy = getStrategy;\n this.#getStrategies = getStrategies;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n pollTransactionChanges(\n messenger,\n this.#updateTransactionData.bind(this),\n this.#removeTransactionData.bind(this),\n );\n\n // eslint-disable-next-line no-new\n new QuoteRefresher({\n getStrategies: this.#getStrategiesWithFallback.bind(this),\n messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Sets the transaction configuration.\n *\n * The callback receives the current configuration properties and can mutate\n * them in place. Updated values are written back to the transaction data.\n *\n * @param transactionId - The ID of the transaction to configure.\n * @param callback - A callback that receives a mutable {@link TransactionConfig} object.\n */\n setTransactionConfig(\n transactionId: string,\n callback: TransactionConfigCallback,\n ): void {\n this.#updateTransactionData(transactionId, (transactionData) => {\n const config = {\n isMaxAmount: transactionData.isMaxAmount,\n isPostQuote: transactionData.isPostQuote,\n isHyperliquidSource: transactionData.isHyperliquidSource,\n refundTo: transactionData.refundTo,\n };\n\n callback(config);\n\n transactionData.isMaxAmount = config.isMaxAmount;\n transactionData.isPostQuote = config.isPostQuote;\n transactionData.isHyperliquidSource = config.isHyperliquidSource;\n transactionData.refundTo = config.refundTo;\n });\n }\n\n /**\n * Updates the payment token for a transaction.\n *\n * Resolves token metadata and balances, then stores the new payment token\n * in the transaction data. This triggers recalculation of source amounts\n * and quote retrieval.\n *\n * @param request - The payment token update request containing the\n * transaction ID, token address, and chain ID.\n */\n updatePaymentToken(request: UpdatePaymentTokenRequest): void {\n updatePaymentToken(request, {\n messenger: this.messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Updates the fiat payment state for a transaction.\n *\n * The request callback receives the current fiat payment state and can\n * mutate it to update properties such as the selected payment method or\n * fiat amount.\n *\n * @param request - The fiat payment update request containing the\n * transaction ID and a callback to mutate fiat payment state.\n */\n updateFiatPayment(request: UpdateFiatPaymentRequest): void {\n updateFiatPayment(request, {\n messenger: this.messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Gets the delegation transaction for a given transaction.\n *\n * Converts the provided transaction into a redeem delegation by delegating\n * to the configured callback. Returns the delegation transaction data\n * including the encoded call data, target address, value, and an optional\n * authorization list.\n *\n * @param args - The arguments forwarded to the {@link GetDelegationTransactionCallback},\n * containing the transaction metadata.\n * @returns A promise resolving to the delegation transaction data.\n */\n getDelegationTransaction(\n ...args: Parameters<GetDelegationTransactionCallback>\n ): ReturnType<GetDelegationTransactionCallback> {\n return this.#getDelegationTransaction(...args);\n }\n\n /**\n * Gets the preferred strategy for a transaction.\n *\n * Returns the first strategy from the ordered list of strategies applicable\n * to the given transaction. Falls back to the default strategy order derived\n * from feature flags when no custom strategy callback is configured.\n *\n * @param transaction - The transaction metadata to determine the strategy for.\n * @returns The preferred {@link TransactionPayStrategy} for the transaction.\n */\n getStrategy(transaction: TransactionMeta): TransactionPayStrategy {\n return this.#getStrategiesWithFallback(transaction)[0];\n }\n\n #removeTransactionData(transactionId: string): void {\n this.update((state) => {\n delete state.transactionData[transactionId];\n });\n }\n\n #updateTransactionData(\n transactionId: string,\n fn: (transactionData: Draft<TransactionData>) => void,\n ): void {\n let shouldUpdateQuotes = false;\n\n this.update((state) => {\n const { transactionData } = state;\n let current = transactionData[transactionId];\n const originalPaymentToken = current?.paymentToken;\n const originalTokens = current?.tokens;\n const originalIsMaxAmount = current?.isMaxAmount;\n const originalIsPostQuote = current?.isPostQuote;\n\n if (!current) {\n transactionData[transactionId] = {\n fiatPayment: {},\n isLoading: false,\n tokens: [],\n };\n\n current = transactionData[transactionId];\n }\n\n fn(current);\n\n const isPaymentTokenUpdated =\n current.paymentToken?.address?.toLowerCase() !==\n originalPaymentToken?.address?.toLowerCase() ||\n current.paymentToken?.chainId !== originalPaymentToken?.chainId;\n\n const isTokensUpdated = current.tokens !== originalTokens;\n const isIsMaxUpdated = current.isMaxAmount !== originalIsMaxAmount;\n const isPostQuoteUpdated = current.isPostQuote !== originalIsPostQuote;\n\n if (\n isPaymentTokenUpdated ||\n isIsMaxUpdated ||\n isTokensUpdated ||\n isPostQuoteUpdated\n ) {\n updateSourceAmounts(transactionId, current as never, this.messenger);\n\n shouldUpdateQuotes = true;\n }\n });\n\n if (shouldUpdateQuotes) {\n updateQuotes({\n getStrategies: this.#getStrategiesWithFallback.bind(this),\n messenger: this.messenger,\n transactionData: this.state.transactionData[transactionId],\n transactionId,\n updateTransactionData: this.#updateTransactionData.bind(this),\n }).catch(noop);\n }\n }\n\n #getStrategiesWithFallback(\n transaction: TransactionMeta,\n ): TransactionPayStrategy[] {\n const strategyCandidates: unknown[] =\n this.#getStrategies?.(transaction) ??\n (this.#getStrategy ? [this.#getStrategy(transaction)] : []);\n\n const validStrategies = strategyCandidates.filter(\n (strategy): strategy is TransactionPayStrategy =>\n isTransactionPayStrategy(strategy),\n );\n\n if (validStrategies.length) {\n return validStrategies;\n }\n\n const paymentToken =\n this.state.transactionData[transaction.id]?.paymentToken;\n\n return getStrategyOrder(\n this.messenger,\n paymentToken?.chainId,\n paymentToken?.address,\n transaction.type,\n );\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayController.d.cts","sourceRoot":"","sources":["../src/TransactionPayController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAMxE,OAAO,EACL,eAAe,EAEf,sBAAsB,EACvB,wBAAoB;AAErB,OAAO,KAAK,EACV,gCAAgC,EAChC,yBAAyB,EAEzB,iCAAiC,EACjC,+BAA+B,EAC/B,6BAA6B,EAC7B,wBAAwB,EACxB,yBAAyB,EAC1B,oBAAgB;AA2BjB,qBAAa,wBAAyB,SAAQ,cAAc,CAC1D,OAAO,eAAe,EACtB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAWa,EACV,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,+BAA+B;IA+BlC;;;;;;;;OAQG;IACH,oBAAoB,CAClB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,yBAAyB,GAClC,IAAI;IAkBP;;;;;;;;;OASG;IACH,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI;IAO5D;;;;;;;;;OASG;IACH,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAO1D;;;;;;;;;;;OAWG;IACH,wBAAwB,CACtB,GAAG,IAAI,EAAE,UAAU,CAAC,gCAAgC,CAAC,GACpD,UAAU,CAAC,gCAAgC,CAAC;IAI/C;;;;;;;;;OASG;IACH,WAAW,CAAC,WAAW,EAAE,eAAe,GAAG,sBAAsB;
|
|
1
|
+
{"version":3,"file":"TransactionPayController.d.cts","sourceRoot":"","sources":["../src/TransactionPayController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAMxE,OAAO,EACL,eAAe,EAEf,sBAAsB,EACvB,wBAAoB;AAErB,OAAO,KAAK,EACV,gCAAgC,EAChC,yBAAyB,EAEzB,iCAAiC,EACjC,+BAA+B,EAC/B,6BAA6B,EAC7B,wBAAwB,EACxB,yBAAyB,EAC1B,oBAAgB;AA2BjB,qBAAa,wBAAyB,SAAQ,cAAc,CAC1D,OAAO,eAAe,EACtB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAWa,EACV,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,+BAA+B;IA+BlC;;;;;;;;OAQG;IACH,oBAAoB,CAClB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,yBAAyB,GAClC,IAAI;IAkBP;;;;;;;;;OASG;IACH,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI;IAO5D;;;;;;;;;OASG;IACH,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAO1D;;;;;;;;;;;OAWG;IACH,wBAAwB,CACtB,GAAG,IAAI,EAAE,UAAU,CAAC,gCAAgC,CAAC,GACpD,UAAU,CAAC,gCAAgC,CAAC;IAI/C;;;;;;;;;OASG;IACH,WAAW,CAAC,WAAW,EAAE,eAAe,GAAG,sBAAsB;CA8FlE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayController.d.mts","sourceRoot":"","sources":["../src/TransactionPayController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAMxE,OAAO,EACL,eAAe,EAEf,sBAAsB,EACvB,wBAAoB;AAErB,OAAO,KAAK,EACV,gCAAgC,EAChC,yBAAyB,EAEzB,iCAAiC,EACjC,+BAA+B,EAC/B,6BAA6B,EAC7B,wBAAwB,EACxB,yBAAyB,EAC1B,oBAAgB;AA2BjB,qBAAa,wBAAyB,SAAQ,cAAc,CAC1D,OAAO,eAAe,EACtB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAWa,EACV,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,+BAA+B;IA+BlC;;;;;;;;OAQG;IACH,oBAAoB,CAClB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,yBAAyB,GAClC,IAAI;IAkBP;;;;;;;;;OASG;IACH,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI;IAO5D;;;;;;;;;OASG;IACH,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAO1D;;;;;;;;;;;OAWG;IACH,wBAAwB,CACtB,GAAG,IAAI,EAAE,UAAU,CAAC,gCAAgC,CAAC,GACpD,UAAU,CAAC,gCAAgC,CAAC;IAI/C;;;;;;;;;OASG;IACH,WAAW,CAAC,WAAW,EAAE,eAAe,GAAG,sBAAsB;
|
|
1
|
+
{"version":3,"file":"TransactionPayController.d.mts","sourceRoot":"","sources":["../src/TransactionPayController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EAAE,eAAe,EAAE,yCAAyC;AAMxE,OAAO,EACL,eAAe,EAEf,sBAAsB,EACvB,wBAAoB;AAErB,OAAO,KAAK,EACV,gCAAgC,EAChC,yBAAyB,EAEzB,iCAAiC,EACjC,+BAA+B,EAC/B,6BAA6B,EAC7B,wBAAwB,EACxB,yBAAyB,EAC1B,oBAAgB;AA2BjB,qBAAa,wBAAyB,SAAQ,cAAc,CAC1D,OAAO,eAAe,EACtB,6BAA6B,EAC7B,iCAAiC,CAClC;;gBAWa,EACV,wBAAwB,EACxB,WAAW,EACX,aAAa,EACb,SAAS,EACT,KAAK,GACN,EAAE,+BAA+B;IA+BlC;;;;;;;;OAQG;IACH,oBAAoB,CAClB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,yBAAyB,GAClC,IAAI;IAkBP;;;;;;;;;OASG;IACH,kBAAkB,CAAC,OAAO,EAAE,yBAAyB,GAAG,IAAI;IAO5D;;;;;;;;;OASG;IACH,iBAAiB,CAAC,OAAO,EAAE,wBAAwB,GAAG,IAAI;IAO1D;;;;;;;;;;;OAWG;IACH,wBAAwB,CACtB,GAAG,IAAI,EAAE,UAAU,CAAC,gCAAgC,CAAC,GACpD,UAAU,CAAC,gCAAgC,CAAC;IAI/C;;;;;;;;;OASG;IACH,WAAW,CAAC,WAAW,EAAE,eAAe,GAAG,sBAAsB;CA8FlE"}
|
|
@@ -197,8 +197,10 @@ _TransactionPayController_getDelegationTransaction = new WeakMap(), _Transaction
|
|
|
197
197
|
const strategyCandidates = __classPrivateFieldGet(this, _TransactionPayController_getStrategies, "f")?.call(this, transaction) ??
|
|
198
198
|
(__classPrivateFieldGet(this, _TransactionPayController_getStrategy, "f") ? [__classPrivateFieldGet(this, _TransactionPayController_getStrategy, "f").call(this, transaction)] : []);
|
|
199
199
|
const validStrategies = strategyCandidates.filter((strategy) => isTransactionPayStrategy(strategy));
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
200
|
+
if (validStrategies.length) {
|
|
201
|
+
return validStrategies;
|
|
202
|
+
}
|
|
203
|
+
const paymentToken = this.state.transactionData[transaction.id]?.paymentToken;
|
|
204
|
+
return getStrategyOrder(this.messenger, paymentToken?.chainId, paymentToken?.address, transaction.type);
|
|
203
205
|
};
|
|
204
206
|
//# sourceMappingURL=TransactionPayController.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionPayController.mjs","sourceRoot":"","sources":["../src/TransactionPayController.ts"],"names":[],"mappings":";;;;;;;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EAAE,KAArB,IAAI,EAAkB,WAAW,CAAC;QAClC,CAAC,uBAAA,IAAI,6CAAa,CAAC,CAAC,CAAC,CAAC,uBAAA,IAAI,6CAAa,MAAjB,IAAI,EAAc,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE9D,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAC/C,CAAC,QAAQ,EAAsC,EAAE,CAC/C,wBAAwB,CAAC,QAAQ,CAAC,CACrC,CAAC;IAEF,OAAO,eAAe,CAAC,MAAM;QAC3B,CAAC,CAAC,eAAe;QACjB,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AACvC,CAAC","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Draft } from 'immer';\nimport { noop } from 'lodash';\n\nimport { updateFiatPayment } from './actions/update-fiat-payment';\nimport { updatePaymentToken } from './actions/update-payment-token';\nimport {\n CONTROLLER_NAME,\n isTransactionPayStrategy,\n TransactionPayStrategy,\n} from './constants';\nimport { QuoteRefresher } from './helpers/QuoteRefresher';\nimport type {\n GetDelegationTransactionCallback,\n TransactionConfigCallback,\n TransactionData,\n TransactionPayControllerMessenger,\n TransactionPayControllerOptions,\n TransactionPayControllerState,\n UpdateFiatPaymentRequest,\n UpdatePaymentTokenRequest,\n} from './types';\nimport { getStrategyOrder } from './utils/feature-flags';\nimport { updateQuotes } from './utils/quotes';\nimport { updateSourceAmounts } from './utils/source-amounts';\nimport { pollTransactionChanges } from './utils/transaction';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getDelegationTransaction',\n 'getStrategy',\n 'setTransactionConfig',\n 'updateFiatPayment',\n 'updatePaymentToken',\n] as const;\n\nconst stateMetadata: StateMetadata<TransactionPayControllerState> = {\n transactionData: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = (): TransactionPayControllerState => ({\n transactionData: {},\n});\n\nexport class TransactionPayController extends BaseController<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState,\n TransactionPayControllerMessenger\n> {\n readonly #getDelegationTransaction: GetDelegationTransactionCallback;\n\n readonly #getStrategy?: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy;\n\n readonly #getStrategies?: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy[];\n\n constructor({\n getDelegationTransaction,\n getStrategy,\n getStrategies,\n messenger,\n state,\n }: TransactionPayControllerOptions) {\n super({\n name: CONTROLLER_NAME,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#getDelegationTransaction = getDelegationTransaction;\n this.#getStrategy = getStrategy;\n this.#getStrategies = getStrategies;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n pollTransactionChanges(\n messenger,\n this.#updateTransactionData.bind(this),\n this.#removeTransactionData.bind(this),\n );\n\n // eslint-disable-next-line no-new\n new QuoteRefresher({\n getStrategies: this.#getStrategiesWithFallback.bind(this),\n messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Sets the transaction configuration.\n *\n * The callback receives the current configuration properties and can mutate\n * them in place. Updated values are written back to the transaction data.\n *\n * @param transactionId - The ID of the transaction to configure.\n * @param callback - A callback that receives a mutable {@link TransactionConfig} object.\n */\n setTransactionConfig(\n transactionId: string,\n callback: TransactionConfigCallback,\n ): void {\n this.#updateTransactionData(transactionId, (transactionData) => {\n const config = {\n isMaxAmount: transactionData.isMaxAmount,\n isPostQuote: transactionData.isPostQuote,\n isHyperliquidSource: transactionData.isHyperliquidSource,\n refundTo: transactionData.refundTo,\n };\n\n callback(config);\n\n transactionData.isMaxAmount = config.isMaxAmount;\n transactionData.isPostQuote = config.isPostQuote;\n transactionData.isHyperliquidSource = config.isHyperliquidSource;\n transactionData.refundTo = config.refundTo;\n });\n }\n\n /**\n * Updates the payment token for a transaction.\n *\n * Resolves token metadata and balances, then stores the new payment token\n * in the transaction data. This triggers recalculation of source amounts\n * and quote retrieval.\n *\n * @param request - The payment token update request containing the\n * transaction ID, token address, and chain ID.\n */\n updatePaymentToken(request: UpdatePaymentTokenRequest): void {\n updatePaymentToken(request, {\n messenger: this.messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Updates the fiat payment state for a transaction.\n *\n * The request callback receives the current fiat payment state and can\n * mutate it to update properties such as the selected payment method or\n * fiat amount.\n *\n * @param request - The fiat payment update request containing the\n * transaction ID and a callback to mutate fiat payment state.\n */\n updateFiatPayment(request: UpdateFiatPaymentRequest): void {\n updateFiatPayment(request, {\n messenger: this.messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Gets the delegation transaction for a given transaction.\n *\n * Converts the provided transaction into a redeem delegation by delegating\n * to the configured callback. Returns the delegation transaction data\n * including the encoded call data, target address, value, and an optional\n * authorization list.\n *\n * @param args - The arguments forwarded to the {@link GetDelegationTransactionCallback},\n * containing the transaction metadata.\n * @returns A promise resolving to the delegation transaction data.\n */\n getDelegationTransaction(\n ...args: Parameters<GetDelegationTransactionCallback>\n ): ReturnType<GetDelegationTransactionCallback> {\n return this.#getDelegationTransaction(...args);\n }\n\n /**\n * Gets the preferred strategy for a transaction.\n *\n * Returns the first strategy from the ordered list of strategies applicable\n * to the given transaction. Falls back to the default strategy order derived\n * from feature flags when no custom strategy callback is configured.\n *\n * @param transaction - The transaction metadata to determine the strategy for.\n * @returns The preferred {@link TransactionPayStrategy} for the transaction.\n */\n getStrategy(transaction: TransactionMeta): TransactionPayStrategy {\n return this.#getStrategiesWithFallback(transaction)[0];\n }\n\n #removeTransactionData(transactionId: string): void {\n this.update((state) => {\n delete state.transactionData[transactionId];\n });\n }\n\n #updateTransactionData(\n transactionId: string,\n fn: (transactionData: Draft<TransactionData>) => void,\n ): void {\n let shouldUpdateQuotes = false;\n\n this.update((state) => {\n const { transactionData } = state;\n let current = transactionData[transactionId];\n const originalPaymentToken = current?.paymentToken;\n const originalTokens = current?.tokens;\n const originalIsMaxAmount = current?.isMaxAmount;\n const originalIsPostQuote = current?.isPostQuote;\n\n if (!current) {\n transactionData[transactionId] = {\n fiatPayment: {},\n isLoading: false,\n tokens: [],\n };\n\n current = transactionData[transactionId];\n }\n\n fn(current);\n\n const isPaymentTokenUpdated =\n current.paymentToken?.address?.toLowerCase() !==\n originalPaymentToken?.address?.toLowerCase() ||\n current.paymentToken?.chainId !== originalPaymentToken?.chainId;\n\n const isTokensUpdated = current.tokens !== originalTokens;\n const isIsMaxUpdated = current.isMaxAmount !== originalIsMaxAmount;\n const isPostQuoteUpdated = current.isPostQuote !== originalIsPostQuote;\n\n if (\n isPaymentTokenUpdated ||\n isIsMaxUpdated ||\n isTokensUpdated ||\n isPostQuoteUpdated\n ) {\n updateSourceAmounts(transactionId, current as never, this.messenger);\n\n shouldUpdateQuotes = true;\n }\n });\n\n if (shouldUpdateQuotes) {\n updateQuotes({\n getStrategies: this.#getStrategiesWithFallback.bind(this),\n messenger: this.messenger,\n transactionData: this.state.transactionData[transactionId],\n transactionId,\n updateTransactionData: this.#updateTransactionData.bind(this),\n }).catch(noop);\n }\n }\n\n #getStrategiesWithFallback(\n transaction: TransactionMeta,\n ): TransactionPayStrategy[] {\n const strategyCandidates: unknown[] =\n this.#getStrategies?.(transaction) ??\n (this.#getStrategy ? [this.#getStrategy(transaction)] : []);\n\n const validStrategies = strategyCandidates.filter(\n (strategy): strategy is TransactionPayStrategy =>\n isTransactionPayStrategy(strategy),\n );\n\n return validStrategies.length\n ? validStrategies\n : getStrategyOrder(this.messenger);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"TransactionPayController.mjs","sourceRoot":"","sources":["../src/TransactionPayController.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EAAE,cAAc,EAAE,kCAAkC;;;AAK3D,OAAO,EAAE,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AAa,CAAC,CAAC,CAAC,CAAC,uBAAA,IAAI,6CAAa,MAAjB,IAAI,EAAc,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IAE9D,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAC/C,CAAC,QAAQ,EAAsC,EAAE,CAC/C,wBAAwB,CAAC,QAAQ,CAAC,CACrC,CAAC;IAEF,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;QAC3B,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,MAAM,YAAY,GAChB,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC;IAE3D,OAAO,gBAAgB,CACrB,IAAI,CAAC,SAAS,EACd,YAAY,EAAE,OAAO,EACrB,YAAY,EAAE,OAAO,EACrB,WAAW,CAAC,IAAI,CACjB,CAAC;AACJ,CAAC","sourcesContent":["import type { StateMetadata } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Draft } from 'immer';\nimport { noop } from 'lodash';\n\nimport { updateFiatPayment } from './actions/update-fiat-payment';\nimport { updatePaymentToken } from './actions/update-payment-token';\nimport {\n CONTROLLER_NAME,\n isTransactionPayStrategy,\n TransactionPayStrategy,\n} from './constants';\nimport { QuoteRefresher } from './helpers/QuoteRefresher';\nimport type {\n GetDelegationTransactionCallback,\n TransactionConfigCallback,\n TransactionData,\n TransactionPayControllerMessenger,\n TransactionPayControllerOptions,\n TransactionPayControllerState,\n UpdateFiatPaymentRequest,\n UpdatePaymentTokenRequest,\n} from './types';\nimport { getStrategyOrder } from './utils/feature-flags';\nimport { updateQuotes } from './utils/quotes';\nimport { updateSourceAmounts } from './utils/source-amounts';\nimport { pollTransactionChanges } from './utils/transaction';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'getDelegationTransaction',\n 'getStrategy',\n 'setTransactionConfig',\n 'updateFiatPayment',\n 'updatePaymentToken',\n] as const;\n\nconst stateMetadata: StateMetadata<TransactionPayControllerState> = {\n transactionData: {\n includeInDebugSnapshot: false,\n includeInStateLogs: true,\n persist: false,\n usedInUi: true,\n },\n};\n\nconst getDefaultState = (): TransactionPayControllerState => ({\n transactionData: {},\n});\n\nexport class TransactionPayController extends BaseController<\n typeof CONTROLLER_NAME,\n TransactionPayControllerState,\n TransactionPayControllerMessenger\n> {\n readonly #getDelegationTransaction: GetDelegationTransactionCallback;\n\n readonly #getStrategy?: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy;\n\n readonly #getStrategies?: (\n transaction: TransactionMeta,\n ) => TransactionPayStrategy[];\n\n constructor({\n getDelegationTransaction,\n getStrategy,\n getStrategies,\n messenger,\n state,\n }: TransactionPayControllerOptions) {\n super({\n name: CONTROLLER_NAME,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#getDelegationTransaction = getDelegationTransaction;\n this.#getStrategy = getStrategy;\n this.#getStrategies = getStrategies;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n\n pollTransactionChanges(\n messenger,\n this.#updateTransactionData.bind(this),\n this.#removeTransactionData.bind(this),\n );\n\n // eslint-disable-next-line no-new\n new QuoteRefresher({\n getStrategies: this.#getStrategiesWithFallback.bind(this),\n messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Sets the transaction configuration.\n *\n * The callback receives the current configuration properties and can mutate\n * them in place. Updated values are written back to the transaction data.\n *\n * @param transactionId - The ID of the transaction to configure.\n * @param callback - A callback that receives a mutable {@link TransactionConfig} object.\n */\n setTransactionConfig(\n transactionId: string,\n callback: TransactionConfigCallback,\n ): void {\n this.#updateTransactionData(transactionId, (transactionData) => {\n const config = {\n isMaxAmount: transactionData.isMaxAmount,\n isPostQuote: transactionData.isPostQuote,\n isHyperliquidSource: transactionData.isHyperliquidSource,\n refundTo: transactionData.refundTo,\n };\n\n callback(config);\n\n transactionData.isMaxAmount = config.isMaxAmount;\n transactionData.isPostQuote = config.isPostQuote;\n transactionData.isHyperliquidSource = config.isHyperliquidSource;\n transactionData.refundTo = config.refundTo;\n });\n }\n\n /**\n * Updates the payment token for a transaction.\n *\n * Resolves token metadata and balances, then stores the new payment token\n * in the transaction data. This triggers recalculation of source amounts\n * and quote retrieval.\n *\n * @param request - The payment token update request containing the\n * transaction ID, token address, and chain ID.\n */\n updatePaymentToken(request: UpdatePaymentTokenRequest): void {\n updatePaymentToken(request, {\n messenger: this.messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Updates the fiat payment state for a transaction.\n *\n * The request callback receives the current fiat payment state and can\n * mutate it to update properties such as the selected payment method or\n * fiat amount.\n *\n * @param request - The fiat payment update request containing the\n * transaction ID and a callback to mutate fiat payment state.\n */\n updateFiatPayment(request: UpdateFiatPaymentRequest): void {\n updateFiatPayment(request, {\n messenger: this.messenger,\n updateTransactionData: this.#updateTransactionData.bind(this),\n });\n }\n\n /**\n * Gets the delegation transaction for a given transaction.\n *\n * Converts the provided transaction into a redeem delegation by delegating\n * to the configured callback. Returns the delegation transaction data\n * including the encoded call data, target address, value, and an optional\n * authorization list.\n *\n * @param args - The arguments forwarded to the {@link GetDelegationTransactionCallback},\n * containing the transaction metadata.\n * @returns A promise resolving to the delegation transaction data.\n */\n getDelegationTransaction(\n ...args: Parameters<GetDelegationTransactionCallback>\n ): ReturnType<GetDelegationTransactionCallback> {\n return this.#getDelegationTransaction(...args);\n }\n\n /**\n * Gets the preferred strategy for a transaction.\n *\n * Returns the first strategy from the ordered list of strategies applicable\n * to the given transaction. Falls back to the default strategy order derived\n * from feature flags when no custom strategy callback is configured.\n *\n * @param transaction - The transaction metadata to determine the strategy for.\n * @returns The preferred {@link TransactionPayStrategy} for the transaction.\n */\n getStrategy(transaction: TransactionMeta): TransactionPayStrategy {\n return this.#getStrategiesWithFallback(transaction)[0];\n }\n\n #removeTransactionData(transactionId: string): void {\n this.update((state) => {\n delete state.transactionData[transactionId];\n });\n }\n\n #updateTransactionData(\n transactionId: string,\n fn: (transactionData: Draft<TransactionData>) => void,\n ): void {\n let shouldUpdateQuotes = false;\n\n this.update((state) => {\n const { transactionData } = state;\n let current = transactionData[transactionId];\n const originalPaymentToken = current?.paymentToken;\n const originalTokens = current?.tokens;\n const originalIsMaxAmount = current?.isMaxAmount;\n const originalIsPostQuote = current?.isPostQuote;\n\n if (!current) {\n transactionData[transactionId] = {\n fiatPayment: {},\n isLoading: false,\n tokens: [],\n };\n\n current = transactionData[transactionId];\n }\n\n fn(current);\n\n const isPaymentTokenUpdated =\n current.paymentToken?.address?.toLowerCase() !==\n originalPaymentToken?.address?.toLowerCase() ||\n current.paymentToken?.chainId !== originalPaymentToken?.chainId;\n\n const isTokensUpdated = current.tokens !== originalTokens;\n const isIsMaxUpdated = current.isMaxAmount !== originalIsMaxAmount;\n const isPostQuoteUpdated = current.isPostQuote !== originalIsPostQuote;\n\n if (\n isPaymentTokenUpdated ||\n isIsMaxUpdated ||\n isTokensUpdated ||\n isPostQuoteUpdated\n ) {\n updateSourceAmounts(transactionId, current as never, this.messenger);\n\n shouldUpdateQuotes = true;\n }\n });\n\n if (shouldUpdateQuotes) {\n updateQuotes({\n getStrategies: this.#getStrategiesWithFallback.bind(this),\n messenger: this.messenger,\n transactionData: this.state.transactionData[transactionId],\n transactionId,\n updateTransactionData: this.#updateTransactionData.bind(this),\n }).catch(noop);\n }\n }\n\n #getStrategiesWithFallback(\n transaction: TransactionMeta,\n ): TransactionPayStrategy[] {\n const strategyCandidates: unknown[] =\n this.#getStrategies?.(transaction) ??\n (this.#getStrategy ? [this.#getStrategy(transaction)] : []);\n\n const validStrategies = strategyCandidates.filter(\n (strategy): strategy is TransactionPayStrategy =>\n isTransactionPayStrategy(strategy),\n );\n\n if (validStrategies.length) {\n return validStrategies;\n }\n\n const paymentToken =\n this.state.transactionData[transaction.id]?.paymentToken;\n\n return getStrategyOrder(\n this.messenger,\n paymentToken?.chainId,\n paymentToken?.address,\n transaction.type,\n );\n }\n}\n"]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RELAY_DEPOSIT_TYPES = exports.RELAY_PENDING_STATUSES = exports.RELAY_FAILURE_STATUSES = exports.TOKEN_TRANSFER_FOUR_BYTE = exports.RELAY_POLLING_INTERVAL = exports.RELAY_STATUS_URL = exports.RELAY_QUOTE_URL = exports.RELAY_EXECUTE_URL = exports.RELAY_URL_BASE = void 0;
|
|
3
|
+
exports.RELAY_DEPOSIT_TYPES = exports.RELAY_PENDING_STATUSES = exports.RELAY_FAILURE_STATUSES = exports.TOKEN_TRANSFER_FOUR_BYTE = exports.RELAY_POLLING_INTERVAL = exports.HYPERLIQUID_EXCHANGE_URL = exports.RELAY_STATUS_URL = exports.RELAY_QUOTE_URL = exports.RELAY_EXECUTE_URL = exports.RELAY_AUTHORIZE_URL = exports.RELAY_URL_BASE = void 0;
|
|
4
4
|
const transaction_controller_1 = require("@metamask/transaction-controller");
|
|
5
5
|
exports.RELAY_URL_BASE = 'https://api.relay.link';
|
|
6
|
+
exports.RELAY_AUTHORIZE_URL = `${exports.RELAY_URL_BASE}/authorize`;
|
|
6
7
|
exports.RELAY_EXECUTE_URL = `${exports.RELAY_URL_BASE}/execute`;
|
|
7
8
|
exports.RELAY_QUOTE_URL = `${exports.RELAY_URL_BASE}/quote`;
|
|
8
9
|
exports.RELAY_STATUS_URL = `${exports.RELAY_URL_BASE}/intents/status/v3`;
|
|
10
|
+
exports.HYPERLIQUID_EXCHANGE_URL = 'https://api.hyperliquid.xyz/exchange';
|
|
9
11
|
exports.RELAY_POLLING_INTERVAL = 1000; // 1 Second
|
|
10
12
|
exports.TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';
|
|
11
13
|
exports.RELAY_FAILURE_STATUSES = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":";;;AAAA,6EAAmE;AAItD,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAC1C,QAAA,iBAAiB,GAAG,GAAG,sBAAc,UAAU,CAAC;AAChD,QAAA,eAAe,GAAG,GAAG,sBAAc,QAAQ,CAAC;AAC5C,QAAA,gBAAgB,GAAG,GAAG,sBAAc,oBAAoB,CAAC;AACzD,QAAA,sBAAsB,GAAG,IAAI,CAAC,CAAC,WAAW;AAC1C,QAAA,wBAAwB,GAAG,YAAY,CAAC;AAExC,QAAA,sBAAsB,GAAkB;IACnD,SAAS;IACT,QAAQ;IACR,UAAU;CACX,CAAC;AAEW,QAAA,sBAAsB,GAAkB;IACnD,SAAS;IACT,YAAY;IACZ,SAAS;IACT,WAAW;IACX,SAAS;CACV,CAAC;AAEW,QAAA,mBAAmB,GAAoC;IAClE,CAAC,wCAAe,CAAC,cAAc,CAAC,EAAE,wCAAe,CAAC,mBAAmB;IACrE,CAAC,wCAAe,CAAC,YAAY,CAAC,EAAE,wCAAe,CAAC,iBAAiB;CAClE,CAAC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\n\nimport type { RelayStatus } from './types';\n\nexport const RELAY_URL_BASE = 'https://api.relay.link';\nexport const RELAY_EXECUTE_URL = `${RELAY_URL_BASE}/execute`;\nexport const RELAY_QUOTE_URL = `${RELAY_URL_BASE}/quote`;\nexport const RELAY_STATUS_URL = `${RELAY_URL_BASE}/intents/status/v3`;\nexport const RELAY_POLLING_INTERVAL = 1000; // 1 Second\nexport const TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';\n\nexport const RELAY_FAILURE_STATUSES: RelayStatus[] = [\n 'failure',\n 'refund',\n 'refunded',\n];\n\nexport const RELAY_PENDING_STATUSES: RelayStatus[] = [\n 'delayed',\n 'depositing',\n 'pending',\n 'submitted',\n 'waiting',\n];\n\nexport const RELAY_DEPOSIT_TYPES: Record<string, TransactionType> = {\n [TransactionType.predictDeposit]: TransactionType.predictRelayDeposit,\n [TransactionType.perpsDeposit]: TransactionType.perpsRelayDeposit,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":";;;AAAA,6EAAmE;AAItD,QAAA,cAAc,GAAG,wBAAwB,CAAC;AAC1C,QAAA,mBAAmB,GAAG,GAAG,sBAAc,YAAY,CAAC;AACpD,QAAA,iBAAiB,GAAG,GAAG,sBAAc,UAAU,CAAC;AAChD,QAAA,eAAe,GAAG,GAAG,sBAAc,QAAQ,CAAC;AAC5C,QAAA,gBAAgB,GAAG,GAAG,sBAAc,oBAAoB,CAAC;AACzD,QAAA,wBAAwB,GAAG,sCAAsC,CAAC;AAClE,QAAA,sBAAsB,GAAG,IAAI,CAAC,CAAC,WAAW;AAC1C,QAAA,wBAAwB,GAAG,YAAY,CAAC;AAExC,QAAA,sBAAsB,GAAkB;IACnD,SAAS;IACT,QAAQ;IACR,UAAU;CACX,CAAC;AAEW,QAAA,sBAAsB,GAAkB;IACnD,SAAS;IACT,YAAY;IACZ,SAAS;IACT,WAAW;IACX,SAAS;CACV,CAAC;AAEW,QAAA,mBAAmB,GAAoC;IAClE,CAAC,wCAAe,CAAC,cAAc,CAAC,EAAE,wCAAe,CAAC,mBAAmB;IACrE,CAAC,wCAAe,CAAC,YAAY,CAAC,EAAE,wCAAe,CAAC,iBAAiB;CAClE,CAAC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\n\nimport type { RelayStatus } from './types';\n\nexport const RELAY_URL_BASE = 'https://api.relay.link';\nexport const RELAY_AUTHORIZE_URL = `${RELAY_URL_BASE}/authorize`;\nexport const RELAY_EXECUTE_URL = `${RELAY_URL_BASE}/execute`;\nexport const RELAY_QUOTE_URL = `${RELAY_URL_BASE}/quote`;\nexport const RELAY_STATUS_URL = `${RELAY_URL_BASE}/intents/status/v3`;\nexport const HYPERLIQUID_EXCHANGE_URL = 'https://api.hyperliquid.xyz/exchange';\nexport const RELAY_POLLING_INTERVAL = 1000; // 1 Second\nexport const TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';\n\nexport const RELAY_FAILURE_STATUSES: RelayStatus[] = [\n 'failure',\n 'refund',\n 'refunded',\n];\n\nexport const RELAY_PENDING_STATUSES: RelayStatus[] = [\n 'delayed',\n 'depositing',\n 'pending',\n 'submitted',\n 'waiting',\n];\n\nexport const RELAY_DEPOSIT_TYPES: Record<string, TransactionType> = {\n [TransactionType.predictDeposit]: TransactionType.predictRelayDeposit,\n [TransactionType.perpsDeposit]: TransactionType.perpsRelayDeposit,\n};\n"]}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { TransactionType } from "@metamask/transaction-controller";
|
|
2
2
|
import type { RelayStatus } from "./types.cjs";
|
|
3
3
|
export declare const RELAY_URL_BASE = "https://api.relay.link";
|
|
4
|
+
export declare const RELAY_AUTHORIZE_URL = "https://api.relay.link/authorize";
|
|
4
5
|
export declare const RELAY_EXECUTE_URL = "https://api.relay.link/execute";
|
|
5
6
|
export declare const RELAY_QUOTE_URL = "https://api.relay.link/quote";
|
|
6
7
|
export declare const RELAY_STATUS_URL = "https://api.relay.link/intents/status/v3";
|
|
8
|
+
export declare const HYPERLIQUID_EXCHANGE_URL = "https://api.hyperliquid.xyz/exchange";
|
|
7
9
|
export declare const RELAY_POLLING_INTERVAL = 1000;
|
|
8
10
|
export declare const TOKEN_TRANSFER_FOUR_BYTE = "0xa9059cbb";
|
|
9
11
|
export declare const RELAY_FAILURE_STATUSES: RelayStatus[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAgB;AAE3C,eAAO,MAAM,cAAc,2BAA2B,CAAC;AACvD,eAAO,MAAM,iBAAiB,mCAA8B,CAAC;AAC7D,eAAO,MAAM,eAAe,iCAA4B,CAAC;AACzD,eAAO,MAAM,gBAAgB,6CAAwC,CAAC;AACtE,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,wBAAwB,eAAe,CAAC;AAErD,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAI/C,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAM/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAG/D,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAgB;AAE3C,eAAO,MAAM,cAAc,2BAA2B,CAAC;AACvD,eAAO,MAAM,mBAAmB,qCAAgC,CAAC;AACjE,eAAO,MAAM,iBAAiB,mCAA8B,CAAC;AAC7D,eAAO,MAAM,eAAe,iCAA4B,CAAC;AACzD,eAAO,MAAM,gBAAgB,6CAAwC,CAAC;AACtE,eAAO,MAAM,wBAAwB,yCAAyC,CAAC;AAC/E,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,wBAAwB,eAAe,CAAC;AAErD,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAI/C,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAM/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAG/D,CAAC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { TransactionType } from "@metamask/transaction-controller";
|
|
2
2
|
import type { RelayStatus } from "./types.mjs";
|
|
3
3
|
export declare const RELAY_URL_BASE = "https://api.relay.link";
|
|
4
|
+
export declare const RELAY_AUTHORIZE_URL = "https://api.relay.link/authorize";
|
|
4
5
|
export declare const RELAY_EXECUTE_URL = "https://api.relay.link/execute";
|
|
5
6
|
export declare const RELAY_QUOTE_URL = "https://api.relay.link/quote";
|
|
6
7
|
export declare const RELAY_STATUS_URL = "https://api.relay.link/intents/status/v3";
|
|
8
|
+
export declare const HYPERLIQUID_EXCHANGE_URL = "https://api.hyperliquid.xyz/exchange";
|
|
7
9
|
export declare const RELAY_POLLING_INTERVAL = 1000;
|
|
8
10
|
export declare const TOKEN_TRANSFER_FOUR_BYTE = "0xa9059cbb";
|
|
9
11
|
export declare const RELAY_FAILURE_STATUSES: RelayStatus[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAgB;AAE3C,eAAO,MAAM,cAAc,2BAA2B,CAAC;AACvD,eAAO,MAAM,iBAAiB,mCAA8B,CAAC;AAC7D,eAAO,MAAM,eAAe,iCAA4B,CAAC;AACzD,eAAO,MAAM,gBAAgB,6CAAwC,CAAC;AACtE,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,wBAAwB,eAAe,CAAC;AAErD,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAI/C,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAM/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAG/D,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAEnE,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAgB;AAE3C,eAAO,MAAM,cAAc,2BAA2B,CAAC;AACvD,eAAO,MAAM,mBAAmB,qCAAgC,CAAC;AACjE,eAAO,MAAM,iBAAiB,mCAA8B,CAAC;AAC7D,eAAO,MAAM,eAAe,iCAA4B,CAAC;AACzD,eAAO,MAAM,gBAAgB,6CAAwC,CAAC;AACtE,eAAO,MAAM,wBAAwB,yCAAyC,CAAC;AAC/E,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAC3C,eAAO,MAAM,wBAAwB,eAAe,CAAC;AAErD,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAI/C,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,WAAW,EAM/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAG/D,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { TransactionType } from "@metamask/transaction-controller";
|
|
2
2
|
export const RELAY_URL_BASE = 'https://api.relay.link';
|
|
3
|
+
export const RELAY_AUTHORIZE_URL = `${RELAY_URL_BASE}/authorize`;
|
|
3
4
|
export const RELAY_EXECUTE_URL = `${RELAY_URL_BASE}/execute`;
|
|
4
5
|
export const RELAY_QUOTE_URL = `${RELAY_URL_BASE}/quote`;
|
|
5
6
|
export const RELAY_STATUS_URL = `${RELAY_URL_BASE}/intents/status/v3`;
|
|
7
|
+
export const HYPERLIQUID_EXCHANGE_URL = 'https://api.hyperliquid.xyz/exchange';
|
|
6
8
|
export const RELAY_POLLING_INTERVAL = 1000; // 1 Second
|
|
7
9
|
export const TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';
|
|
8
10
|
export const RELAY_FAILURE_STATUSES = [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAInE,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AACvD,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,cAAc,UAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,cAAc,QAAQ,CAAC;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,cAAc,oBAAoB,CAAC;AACtE,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,CAAC,WAAW;AACvD,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,SAAS;IACT,QAAQ;IACR,UAAU;CACX,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,SAAS;IACT,YAAY;IACZ,SAAS;IACT,WAAW;IACX,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAoC;IAClE,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,eAAe,CAAC,mBAAmB;IACrE,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,iBAAiB;CAClE,CAAC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\n\nimport type { RelayStatus } from './types';\n\nexport const RELAY_URL_BASE = 'https://api.relay.link';\nexport const RELAY_EXECUTE_URL = `${RELAY_URL_BASE}/execute`;\nexport const RELAY_QUOTE_URL = `${RELAY_URL_BASE}/quote`;\nexport const RELAY_STATUS_URL = `${RELAY_URL_BASE}/intents/status/v3`;\nexport const RELAY_POLLING_INTERVAL = 1000; // 1 Second\nexport const TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';\n\nexport const RELAY_FAILURE_STATUSES: RelayStatus[] = [\n 'failure',\n 'refund',\n 'refunded',\n];\n\nexport const RELAY_PENDING_STATUSES: RelayStatus[] = [\n 'delayed',\n 'depositing',\n 'pending',\n 'submitted',\n 'waiting',\n];\n\nexport const RELAY_DEPOSIT_TYPES: Record<string, TransactionType> = {\n [TransactionType.predictDeposit]: TransactionType.predictRelayDeposit,\n [TransactionType.perpsDeposit]: TransactionType.perpsRelayDeposit,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../../../src/strategy/relay/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,yCAAyC;AAInE,MAAM,CAAC,MAAM,cAAc,GAAG,wBAAwB,CAAC;AACvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,cAAc,YAAY,CAAC;AACjE,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,cAAc,UAAU,CAAC;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,cAAc,QAAQ,CAAC;AACzD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,cAAc,oBAAoB,CAAC;AACtE,MAAM,CAAC,MAAM,wBAAwB,GAAG,sCAAsC,CAAC;AAC/E,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC,CAAC,WAAW;AACvD,MAAM,CAAC,MAAM,wBAAwB,GAAG,YAAY,CAAC;AAErD,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,SAAS;IACT,QAAQ;IACR,UAAU;CACX,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAkB;IACnD,SAAS;IACT,YAAY;IACZ,SAAS;IACT,WAAW;IACX,SAAS;CACV,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAoC;IAClE,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE,eAAe,CAAC,mBAAmB;IACrE,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,eAAe,CAAC,iBAAiB;CAClE,CAAC","sourcesContent":["import { TransactionType } from '@metamask/transaction-controller';\n\nimport type { RelayStatus } from './types';\n\nexport const RELAY_URL_BASE = 'https://api.relay.link';\nexport const RELAY_AUTHORIZE_URL = `${RELAY_URL_BASE}/authorize`;\nexport const RELAY_EXECUTE_URL = `${RELAY_URL_BASE}/execute`;\nexport const RELAY_QUOTE_URL = `${RELAY_URL_BASE}/quote`;\nexport const RELAY_STATUS_URL = `${RELAY_URL_BASE}/intents/status/v3`;\nexport const HYPERLIQUID_EXCHANGE_URL = 'https://api.hyperliquid.xyz/exchange';\nexport const RELAY_POLLING_INTERVAL = 1000; // 1 Second\nexport const TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';\n\nexport const RELAY_FAILURE_STATUSES: RelayStatus[] = [\n 'failure',\n 'refund',\n 'refunded',\n];\n\nexport const RELAY_PENDING_STATUSES: RelayStatus[] = [\n 'delayed',\n 'depositing',\n 'pending',\n 'submitted',\n 'waiting',\n];\n\nexport const RELAY_DEPOSIT_TYPES: Record<string, TransactionType> = {\n [TransactionType.predictDeposit]: TransactionType.predictRelayDeposit,\n [TransactionType.perpsDeposit]: TransactionType.perpsRelayDeposit,\n};\n"]}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.submitHyperliquidWithdraw = void 0;
|
|
4
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
5
|
+
const keyring_controller_1 = require("@metamask/keyring-controller");
|
|
6
|
+
const utils_1 = require("@metamask/utils");
|
|
7
|
+
const constants_1 = require("./constants.cjs");
|
|
8
|
+
const constants_2 = require("../../constants.cjs");
|
|
9
|
+
const logger_1 = require("../../logger.cjs");
|
|
10
|
+
const log = (0, utils_1.createModuleLogger)(logger_1.projectLogger, 'hyperliquid-withdraw');
|
|
11
|
+
const DOMAIN_FIELD_MAP = {
|
|
12
|
+
name: { name: 'name', type: 'string' },
|
|
13
|
+
version: { name: 'version', type: 'string' },
|
|
14
|
+
chainId: { name: 'chainId', type: 'uint256' },
|
|
15
|
+
verifyingContract: { name: 'verifyingContract', type: 'address' },
|
|
16
|
+
salt: { name: 'salt', type: 'bytes32' },
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Submit a HyperLiquid 2-step withdrawal via Relay.
|
|
20
|
+
*
|
|
21
|
+
* Step 1 (authorize): Sign an EIP-712 nonce-mapping message, POST to Relay /authorize.
|
|
22
|
+
* Step 2 (deposit): Sign an EIP-712 HyperliquidSignTransaction, POST to HyperLiquid exchange.
|
|
23
|
+
*
|
|
24
|
+
* Both signatures are silent (no user confirmation). Both steps share the same nonce
|
|
25
|
+
* from the Relay quote response.
|
|
26
|
+
*
|
|
27
|
+
* @param quote - Relay quote containing the 2-step flow.
|
|
28
|
+
* @param from - User's account address.
|
|
29
|
+
* @param messenger - Controller messenger (for KeyringController:signTypedMessage).
|
|
30
|
+
*/
|
|
31
|
+
async function submitHyperliquidWithdraw(quote, from, messenger) {
|
|
32
|
+
const { steps } = quote.original;
|
|
33
|
+
log('Starting HyperLiquid withdrawal', {
|
|
34
|
+
stepCount: steps.length,
|
|
35
|
+
stepIds: steps.map((step) => step.id),
|
|
36
|
+
});
|
|
37
|
+
const authorizeStep = steps.find((step) => step.kind === 'signature' && step.id === 'authorize');
|
|
38
|
+
const depositStep = steps.find((step) => step.id === 'deposit');
|
|
39
|
+
if (!authorizeStep || !depositStep) {
|
|
40
|
+
throw new Error(`Expected authorize and deposit steps for HyperLiquid withdrawal, got: ${steps.map((step) => `${step.id}(${step.kind})`).join(', ')}`);
|
|
41
|
+
}
|
|
42
|
+
// Step 1: Authorize (nonce-mapping signature -> POST to Relay /authorize)
|
|
43
|
+
await executeAuthorizeStep(authorizeStep, from, messenger);
|
|
44
|
+
// Step 2: Deposit (HyperLiquid sendAsset -> POST to HyperLiquid exchange)
|
|
45
|
+
await executeDepositStep(depositStep, from, messenger);
|
|
46
|
+
log('HyperLiquid withdrawal submitted successfully');
|
|
47
|
+
}
|
|
48
|
+
exports.submitHyperliquidWithdraw = submitHyperliquidWithdraw;
|
|
49
|
+
/**
|
|
50
|
+
* Derive the EIP712Domain type array from a domain object.
|
|
51
|
+
* eth-sig-util defaults to EIP712Domain: [] when absent, breaking
|
|
52
|
+
* the domain separator hash. This ensures it matches ethers.js behavior.
|
|
53
|
+
*
|
|
54
|
+
* @param domain - The EIP-712 domain object.
|
|
55
|
+
* @returns The EIP712Domain type array in canonical order.
|
|
56
|
+
*/
|
|
57
|
+
function deriveEIP712DomainType(domain) {
|
|
58
|
+
return Object.keys(DOMAIN_FIELD_MAP)
|
|
59
|
+
.filter((key) => key in domain)
|
|
60
|
+
.map((key) => DOMAIN_FIELD_MAP[key]);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Execute the authorize step: sign EIP-712 nonce-mapping and POST to Relay.
|
|
64
|
+
*
|
|
65
|
+
* @param step - The authorize signature step from the Relay quote.
|
|
66
|
+
* @param from - User's account address.
|
|
67
|
+
* @param messenger - Controller messenger for signing.
|
|
68
|
+
*/
|
|
69
|
+
async function executeAuthorizeStep(step, from, messenger) {
|
|
70
|
+
if (step.items.length !== 1) {
|
|
71
|
+
throw new Error(`Expected exactly 1 authorize item, got ${step.items.length}`);
|
|
72
|
+
}
|
|
73
|
+
const item = step.items[0];
|
|
74
|
+
if (!item) {
|
|
75
|
+
throw new Error('Authorize step has no items');
|
|
76
|
+
}
|
|
77
|
+
const { sign, post } = item.data;
|
|
78
|
+
const typedData = {
|
|
79
|
+
domain: sign.domain,
|
|
80
|
+
types: {
|
|
81
|
+
...sign.types,
|
|
82
|
+
EIP712Domain: deriveEIP712DomainType(sign.domain),
|
|
83
|
+
},
|
|
84
|
+
primaryType: sign.primaryType,
|
|
85
|
+
message: sign.value,
|
|
86
|
+
};
|
|
87
|
+
log('Signing authorize (nonce-mapping)', { domain: sign.domain });
|
|
88
|
+
const signature = await messenger.call('KeyringController:signTypedMessage', {
|
|
89
|
+
from,
|
|
90
|
+
data: JSON.stringify(typedData),
|
|
91
|
+
}, keyring_controller_1.SignTypedDataVersion.V4);
|
|
92
|
+
log('Posting authorize signature to Relay');
|
|
93
|
+
const authorizeUrl = `${constants_1.RELAY_AUTHORIZE_URL}?signature=${signature}`;
|
|
94
|
+
try {
|
|
95
|
+
const response = await (0, controller_utils_1.successfulFetch)(authorizeUrl, {
|
|
96
|
+
method: post.method,
|
|
97
|
+
headers: { 'Content-Type': 'application/json' },
|
|
98
|
+
body: JSON.stringify(post.body),
|
|
99
|
+
});
|
|
100
|
+
const result = await response.json();
|
|
101
|
+
log('Authorize response', result);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
throw new Error(`HyperLiquid authorize failed: ${error.message}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Execute the deposit step: sign HyperLiquid sendAsset and POST to HL exchange.
|
|
109
|
+
*
|
|
110
|
+
* The signature data must be constructed from the step's eip712Types and action
|
|
111
|
+
* parameters, following the Relay HyperLiquid integration spec.
|
|
112
|
+
*
|
|
113
|
+
* @param step - The deposit step from the Relay quote.
|
|
114
|
+
* @param from - User's account address.
|
|
115
|
+
* @param messenger - Controller messenger for signing.
|
|
116
|
+
*/
|
|
117
|
+
async function executeDepositStep(step, from, messenger) {
|
|
118
|
+
const items = step.items;
|
|
119
|
+
if (items.length !== 1) {
|
|
120
|
+
throw new Error(`Expected exactly 1 deposit item, got ${items.length}`);
|
|
121
|
+
}
|
|
122
|
+
const item = items[0];
|
|
123
|
+
if (!item) {
|
|
124
|
+
throw new Error('Deposit step has no items');
|
|
125
|
+
}
|
|
126
|
+
const { data } = item;
|
|
127
|
+
const action = data.action;
|
|
128
|
+
const nonce = data.nonce;
|
|
129
|
+
const eip712Types = data.eip712Types;
|
|
130
|
+
const eip712PrimaryType = data.eip712PrimaryType;
|
|
131
|
+
// HyperLiquid's EIP-712 signing spec requires Arbitrum's chain ID in the
|
|
132
|
+
// domain and message. This does not affect which chain the withdrawal
|
|
133
|
+
// targets — the destination chain is determined by the Relay quote.
|
|
134
|
+
const chainId = Number(constants_2.CHAIN_ID_ARBITRUM);
|
|
135
|
+
const domain = {
|
|
136
|
+
name: 'HyperliquidSignTransaction',
|
|
137
|
+
version: '1',
|
|
138
|
+
chainId,
|
|
139
|
+
verifyingContract: '0x0000000000000000000000000000000000000000',
|
|
140
|
+
};
|
|
141
|
+
const signatureData = {
|
|
142
|
+
domain,
|
|
143
|
+
types: {
|
|
144
|
+
...eip712Types,
|
|
145
|
+
EIP712Domain: deriveEIP712DomainType(domain),
|
|
146
|
+
},
|
|
147
|
+
primaryType: eip712PrimaryType,
|
|
148
|
+
message: {
|
|
149
|
+
...action.parameters,
|
|
150
|
+
type: action.type,
|
|
151
|
+
signatureChainId: `0x${chainId.toString(16)}`,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
log('Signing HyperLiquid deposit (sendAsset)', {
|
|
155
|
+
nonce,
|
|
156
|
+
action: action.type,
|
|
157
|
+
});
|
|
158
|
+
const signature = await messenger.call('KeyringController:signTypedMessage', {
|
|
159
|
+
from,
|
|
160
|
+
data: JSON.stringify(signatureData),
|
|
161
|
+
}, keyring_controller_1.SignTypedDataVersion.V4);
|
|
162
|
+
// eslint-disable-next-line id-length
|
|
163
|
+
const r = signature.slice(0, 66);
|
|
164
|
+
// eslint-disable-next-line id-length
|
|
165
|
+
const s = `0x${signature.slice(66, 130)}`;
|
|
166
|
+
// eslint-disable-next-line id-length
|
|
167
|
+
const v = parseInt(signature.slice(130, 132), 16);
|
|
168
|
+
log('Posting deposit to HyperLiquid exchange');
|
|
169
|
+
let result;
|
|
170
|
+
try {
|
|
171
|
+
const response = await (0, controller_utils_1.successfulFetch)(constants_1.HYPERLIQUID_EXCHANGE_URL, {
|
|
172
|
+
method: 'POST',
|
|
173
|
+
headers: { 'Content-Type': 'application/json' },
|
|
174
|
+
body: JSON.stringify({
|
|
175
|
+
action: {
|
|
176
|
+
...action.parameters,
|
|
177
|
+
type: action.type,
|
|
178
|
+
signatureChainId: `0x${chainId.toString(16)}`,
|
|
179
|
+
},
|
|
180
|
+
nonce,
|
|
181
|
+
signature: { r, s, v },
|
|
182
|
+
}),
|
|
183
|
+
});
|
|
184
|
+
result = await response.json();
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
throw new Error(`HyperLiquid deposit failed: ${error.message}`);
|
|
188
|
+
}
|
|
189
|
+
if (result?.status !== 'ok') {
|
|
190
|
+
throw new Error(`HyperLiquid deposit failed: ${JSON.stringify(result)}`);
|
|
191
|
+
}
|
|
192
|
+
log('HyperLiquid deposit response', result);
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=hyperliquid-withdraw.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperliquid-withdraw.cjs","sourceRoot":"","sources":["../../../src/strategy/relay/hyperliquid-withdraw.ts"],"names":[],"mappings":";;;AAAA,iEAA6D;AAC7D,qEAAoE;AAEpE,2CAAqD;AAErD,+CAA4E;AAE5E,mDAAoD;AACpD,6CAA6C;AAM7C,MAAM,GAAG,GAAG,IAAA,0BAAkB,EAAC,sBAAa,EAAE,sBAAsB,CAAC,CAAC;AAItE,MAAM,gBAAgB,GAAsC;IAC1D,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;IACtC,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC5C,OAAO,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE;IAC7C,iBAAiB,EAAE,EAAE,IAAI,EAAE,mBAAmB,EAAE,IAAI,EAAE,SAAS,EAAE;IACjE,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;CACxC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,yBAAyB,CAC7C,KAAsC,EACtC,IAAS,EACT,SAA4C;IAE5C,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC;IAEjC,GAAG,CAAC,iCAAiC,EAAE;QACrC,SAAS,EAAE,KAAK,CAAC,MAAM;QACvB,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE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AQ,CAAC,EAAE,CAAC,EAAE;iBAC9C;gBACD,KAAK;gBACL,SAAS,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE;aACvB,CAAC;SACH,CAAC,CAAC;QAEH,MAAM,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,+BAAgC,KAAe,CAAC,OAAO,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,IAAK,MAA8B,EAAE,MAAM,KAAK,IAAI,EAAE,CAAC;QACrD,MAAM,IAAI,KAAK,CAAC,+BAA+B,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IAC3E,CAAC;IAED,GAAG,CAAC,8BAA8B,EAAE,MAAM,CAAC,CAAC;AAC9C,CAAC","sourcesContent":["import { successfulFetch } from '@metamask/controller-utils';\nimport { SignTypedDataVersion } from '@metamask/keyring-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\n\nimport { RELAY_AUTHORIZE_URL, HYPERLIQUID_EXCHANGE_URL } from './constants';\nimport type { RelayQuote, RelaySignatureStep } from './types';\nimport { CHAIN_ID_ARBITRUM } from '../../constants';\nimport { projectLogger } from '../../logger';\nimport type {\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types';\n\nconst log = createModuleLogger(projectLogger, 'hyperliquid-withdraw');\n\ntype EIP712DomainField = { name: string; type: string };\n\nconst DOMAIN_FIELD_MAP: Record<string, EIP712DomainField> = {\n name: { name: 'name', type: 'string' },\n version: { name: 'version', type: 'string' },\n chainId: { name: 'chainId', type: 'uint256' },\n verifyingContract: { name: 'verifyingContract', type: 'address' },\n salt: { name: 'salt', type: 'bytes32' },\n};\n\n/**\n * Submit a HyperLiquid 2-step withdrawal via Relay.\n *\n * Step 1 (authorize): Sign an EIP-712 nonce-mapping message, POST to Relay /authorize.\n * Step 2 (deposit): Sign an EIP-712 HyperliquidSignTransaction, POST to HyperLiquid exchange.\n *\n * Both signatures are silent (no user confirmation). Both steps share the same nonce\n * from the Relay quote response.\n *\n * @param quote - Relay quote containing the 2-step flow.\n * @param from - User's account address.\n * @param messenger - Controller messenger (for KeyringController:signTypedMessage).\n */\nexport async function submitHyperliquidWithdraw(\n quote: TransactionPayQuote<RelayQuote>,\n from: Hex,\n messenger: TransactionPayControllerMessenger,\n): Promise<void> {\n const { steps } = quote.original;\n\n log('Starting HyperLiquid withdrawal', {\n stepCount: steps.length,\n stepIds: steps.map((step) => step.id),\n });\n\n const authorizeStep = steps.find(\n (step) => step.kind === 'signature' && step.id === 'authorize',\n ) as RelaySignatureStep | undefined;\n\n const depositStep = steps.find((step) => step.id === 'deposit');\n\n if (!authorizeStep || !depositStep) {\n throw new Error(\n `Expected authorize and deposit steps for HyperLiquid withdrawal, got: ${steps.map((step) => `${step.id}(${step.kind})`).join(', ')}`,\n );\n }\n\n // Step 1: Authorize (nonce-mapping signature -> POST to Relay /authorize)\n await executeAuthorizeStep(authorizeStep, from, messenger);\n\n // Step 2: Deposit (HyperLiquid sendAsset -> POST to HyperLiquid exchange)\n await executeDepositStep(depositStep, from, messenger);\n\n log('HyperLiquid withdrawal submitted successfully');\n}\n\n/**\n * Derive the EIP712Domain type array from a domain object.\n * eth-sig-util defaults to EIP712Domain: [] when absent, breaking\n * the domain separator hash. This ensures it matches ethers.js behavior.\n *\n * @param domain - The EIP-712 domain object.\n * @returns The EIP712Domain type array in canonical order.\n */\nfunction deriveEIP712DomainType(\n domain: Record<string, unknown>,\n): EIP712DomainField[] {\n return Object.keys(DOMAIN_FIELD_MAP)\n .filter((key) => key in domain)\n .map((key) => DOMAIN_FIELD_MAP[key]);\n}\n\n/**\n * Execute the authorize step: sign EIP-712 nonce-mapping and POST to Relay.\n *\n * @param step - The authorize signature step from the Relay quote.\n * @param from - User's account address.\n * @param messenger - Controller messenger for signing.\n */\nasync function executeAuthorizeStep(\n step: RelaySignatureStep,\n from: Hex,\n messenger: TransactionPayControllerMessenger,\n): Promise<void> {\n if (step.items.length !== 1) {\n throw new Error(\n `Expected exactly 1 authorize item, got ${step.items.length}`,\n );\n }\n\n const item = step.items[0];\n if (!item) {\n throw new Error('Authorize step has no items');\n }\n\n const { sign, post } = item.data;\n\n const typedData = {\n domain: sign.domain,\n types: {\n ...sign.types,\n EIP712Domain: deriveEIP712DomainType(sign.domain),\n },\n primaryType: sign.primaryType,\n message: sign.value,\n };\n\n log('Signing authorize (nonce-mapping)', { domain: sign.domain });\n\n const signature = await messenger.call(\n 'KeyringController:signTypedMessage',\n {\n from,\n data: JSON.stringify(typedData),\n },\n SignTypedDataVersion.V4,\n );\n\n log('Posting authorize signature to Relay');\n\n const authorizeUrl = `${RELAY_AUTHORIZE_URL}?signature=${signature}`;\n\n try {\n const response = await successfulFetch(authorizeUrl, {\n method: post.method,\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify(post.body),\n });\n\n const result = await response.json();\n\n log('Authorize response', result);\n } catch (error) {\n throw new Error(\n `HyperLiquid authorize failed: ${(error as Error).message}`,\n );\n }\n}\n\n/**\n * Execute the deposit step: sign HyperLiquid sendAsset and POST to HL exchange.\n *\n * The signature data must be constructed from the step's eip712Types and action\n * parameters, following the Relay HyperLiquid integration spec.\n *\n * @param step - The deposit step from the Relay quote.\n * @param from - User's account address.\n * @param messenger - Controller messenger for signing.\n */\nasync function executeDepositStep(\n step: RelaySignatureStep | { id: string; kind: string; items: unknown[] },\n from: Hex,\n messenger: TransactionPayControllerMessenger,\n): Promise<void> {\n const items = step.items as { data: Record<string, unknown> }[];\n\n if (items.length !== 1) {\n throw new Error(`Expected exactly 1 deposit item, got ${items.length}`);\n }\n\n const item = items[0];\n if (!item) {\n throw new Error('Deposit step has no items');\n }\n\n const { data } = item;\n\n const action = data.action as {\n type: string;\n parameters: Record<string, unknown>;\n };\n const nonce = data.nonce as number;\n const eip712Types = data.eip712Types as Record<string, unknown>;\n const eip712PrimaryType = data.eip712PrimaryType as string;\n\n // HyperLiquid's EIP-712 signing spec requires Arbitrum's chain ID in the\n // domain and message. This does not affect which chain the withdrawal\n // targets — the destination chain is determined by the Relay quote.\n const chainId = Number(CHAIN_ID_ARBITRUM);\n\n const domain = {\n name: 'HyperliquidSignTransaction',\n version: '1',\n chainId,\n verifyingContract: '0x0000000000000000000000000000000000000000',\n };\n\n const signatureData = {\n domain,\n types: {\n ...eip712Types,\n EIP712Domain: deriveEIP712DomainType(domain),\n },\n primaryType: eip712PrimaryType,\n message: {\n ...action.parameters,\n type: action.type,\n signatureChainId: `0x${chainId.toString(16)}`,\n },\n };\n\n log('Signing HyperLiquid deposit (sendAsset)', {\n nonce,\n action: action.type,\n });\n\n const signature = await messenger.call(\n 'KeyringController:signTypedMessage',\n {\n from,\n data: JSON.stringify(signatureData),\n },\n SignTypedDataVersion.V4,\n );\n\n // eslint-disable-next-line id-length\n const r = signature.slice(0, 66);\n // eslint-disable-next-line id-length\n const s = `0x${signature.slice(66, 130)}`;\n // eslint-disable-next-line id-length\n const v = parseInt(signature.slice(130, 132), 16);\n\n log('Posting deposit to HyperLiquid exchange');\n\n let result: unknown;\n\n try {\n const response = await successfulFetch(HYPERLIQUID_EXCHANGE_URL, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n action: {\n ...action.parameters,\n type: action.type,\n signatureChainId: `0x${chainId.toString(16)}`,\n },\n nonce,\n signature: { r, s, v },\n }),\n });\n\n result = await response.json();\n } catch (error) {\n throw new Error(`HyperLiquid deposit failed: ${(error as Error).message}`);\n }\n\n if ((result as { status?: string })?.status !== 'ok') {\n throw new Error(`HyperLiquid deposit failed: ${JSON.stringify(result)}`);\n }\n\n log('HyperLiquid deposit response', result);\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
import type { RelayQuote } from "./types.cjs";
|
|
3
|
+
import type { TransactionPayControllerMessenger, TransactionPayQuote } from "../../types.cjs";
|
|
4
|
+
/**
|
|
5
|
+
* Submit a HyperLiquid 2-step withdrawal via Relay.
|
|
6
|
+
*
|
|
7
|
+
* Step 1 (authorize): Sign an EIP-712 nonce-mapping message, POST to Relay /authorize.
|
|
8
|
+
* Step 2 (deposit): Sign an EIP-712 HyperliquidSignTransaction, POST to HyperLiquid exchange.
|
|
9
|
+
*
|
|
10
|
+
* Both signatures are silent (no user confirmation). Both steps share the same nonce
|
|
11
|
+
* from the Relay quote response.
|
|
12
|
+
*
|
|
13
|
+
* @param quote - Relay quote containing the 2-step flow.
|
|
14
|
+
* @param from - User's account address.
|
|
15
|
+
* @param messenger - Controller messenger (for KeyringController:signTypedMessage).
|
|
16
|
+
*/
|
|
17
|
+
export declare function submitHyperliquidWithdraw(quote: TransactionPayQuote<RelayQuote>, from: Hex, messenger: TransactionPayControllerMessenger): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=hyperliquid-withdraw.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperliquid-withdraw.d.cts","sourceRoot":"","sources":["../../../src/strategy/relay/hyperliquid-withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,UAAU,EAAsB,oBAAgB;AAG9D,OAAO,KAAK,EACV,iCAAiC,EACjC,mBAAmB,EACpB,wBAAoB;AAcrB;;;;;;;;;;;;GAYG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,EACtC,IAAI,EAAE,GAAG,EACT,SAAS,EAAE,iCAAiC,GAC3C,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Hex } from "@metamask/utils";
|
|
2
|
+
import type { RelayQuote } from "./types.mjs";
|
|
3
|
+
import type { TransactionPayControllerMessenger, TransactionPayQuote } from "../../types.mjs";
|
|
4
|
+
/**
|
|
5
|
+
* Submit a HyperLiquid 2-step withdrawal via Relay.
|
|
6
|
+
*
|
|
7
|
+
* Step 1 (authorize): Sign an EIP-712 nonce-mapping message, POST to Relay /authorize.
|
|
8
|
+
* Step 2 (deposit): Sign an EIP-712 HyperliquidSignTransaction, POST to HyperLiquid exchange.
|
|
9
|
+
*
|
|
10
|
+
* Both signatures are silent (no user confirmation). Both steps share the same nonce
|
|
11
|
+
* from the Relay quote response.
|
|
12
|
+
*
|
|
13
|
+
* @param quote - Relay quote containing the 2-step flow.
|
|
14
|
+
* @param from - User's account address.
|
|
15
|
+
* @param messenger - Controller messenger (for KeyringController:signTypedMessage).
|
|
16
|
+
*/
|
|
17
|
+
export declare function submitHyperliquidWithdraw(quote: TransactionPayQuote<RelayQuote>, from: Hex, messenger: TransactionPayControllerMessenger): Promise<void>;
|
|
18
|
+
//# sourceMappingURL=hyperliquid-withdraw.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hyperliquid-withdraw.d.mts","sourceRoot":"","sources":["../../../src/strategy/relay/hyperliquid-withdraw.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,OAAO,KAAK,EAAE,UAAU,EAAsB,oBAAgB;AAG9D,OAAO,KAAK,EACV,iCAAiC,EACjC,mBAAmB,EACpB,wBAAoB;AAcrB;;;;;;;;;;;;GAYG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,EACtC,IAAI,EAAE,GAAG,EACT,SAAS,EAAE,iCAAiC,GAC3C,OAAO,CAAC,IAAI,CAAC,CA2Bf"}
|