@metamask-previews/transaction-pay-controller 30.3.1-preview-35f016caa → 30.3.2-preview-c1f9a0f
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 +16 -1
- package/dist/strategy/across/AcrossStrategy.d.ts.map +1 -1
- package/dist/strategy/across/AcrossStrategy.js +3 -3
- package/dist/strategy/across/AcrossStrategy.js.map +1 -1
- package/dist/strategy/across/across-actions.js +2 -2
- package/dist/strategy/across/across-actions.js.map +1 -1
- package/dist/strategy/across/across-quotes.js +1 -1
- package/dist/strategy/across/across-quotes.js.map +1 -1
- package/dist/strategy/across/across-submit.d.ts.map +1 -1
- package/dist/strategy/across/across-submit.js +4 -2
- package/dist/strategy/across/across-submit.js.map +1 -1
- package/dist/strategy/across/perps.d.ts +4 -23
- package/dist/strategy/across/perps.d.ts.map +1 -1
- package/dist/strategy/across/perps.js +5 -42
- package/dist/strategy/across/perps.js.map +1 -1
- package/dist/strategy/relay/relay-quotes.d.ts.map +1 -1
- package/dist/strategy/relay/relay-quotes.js +42 -84
- package/dist/strategy/relay/relay-quotes.js.map +1 -1
- package/dist/strategy/server/perps.d.ts +4 -24
- package/dist/strategy/server/perps.d.ts.map +1 -1
- package/dist/strategy/server/perps.js +7 -66
- package/dist/strategy/server/perps.js.map +1 -1
- package/dist/strategy/server/server-quotes.d.ts.map +1 -1
- package/dist/strategy/server/server-quotes.js +39 -70
- package/dist/strategy/server/server-quotes.js.map +1 -1
- package/dist/utils/perps.d.ts +56 -0
- package/dist/utils/perps.d.ts.map +1 -0
- package/dist/utils/perps.js +112 -0
- package/dist/utils/perps.js.map +1 -0
- package/dist/utils/post-quote-payment-override.d.ts +42 -0
- package/dist/utils/post-quote-payment-override.d.ts.map +1 -0
- package/dist/utils/post-quote-payment-override.js +55 -0
- package/dist/utils/post-quote-payment-override.js.map +1 -0
- package/dist/utils/quote-recipient.d.ts +22 -0
- package/dist/utils/quote-recipient.d.ts.map +1 -0
- package/dist/utils/quote-recipient.js +41 -0
- package/dist/utils/quote-recipient.js.map +1 -0
- package/dist/utils/second-leg.d.ts +1 -21
- package/dist/utils/second-leg.d.ts.map +1 -1
- package/dist/utils/second-leg.js +0 -36
- package/dist/utils/second-leg.js.map +1 -1
- package/dist/utils/source-amounts.d.ts.map +1 -1
- package/dist/utils/source-amounts.js +8 -8
- package/dist/utils/source-amounts.js.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relay-quotes.js","sourceRoot":"","sources":["../../../src/strategy/relay/relay-quotes.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAMnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,aAAa,EACb,eAAe,GAChB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAShD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,yBAAyB,EACzB,WAAW,EACX,cAAc,EACd,kBAAkB,EAClB,cAAc,EACd,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EACL,mCAAmC,EACnC,iCAAiC,EAC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AI,EAAE,UAAU,CAAC;IAC7C,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,aAAa,EAAE,SAAS,IAAI,GAAG,CAAC,CAAC;IACjE,MAAM,eAAe,GAAG,IAAI,SAAS,CAAC,aAAa,EAAE,eAAe,IAAI,GAAG,CAAC,CAAC;IAE7E,IAAI,CAAC,aAAa,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACzC,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,sBAAsB,GAAG,YAAY,CACzC,SAAS,EACT,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,EACrC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAC/B,CAAC;IAEF,OAAO,sBAAsB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9D,CAAC;AAED,SAAS,YAAY,CACnB,SAA4C,EAC5C,OAAe,EACf,YAAoB;IAEpB,OAAO,OAAO,CACZ,cAAc,CAAC,SAAS,CAAC,CAAC,OAAc,CAAC,EAAE,QAAQ,CACjD,YAAY,CAAC,WAAW,EAAS,CAClC,CACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable require-atomic-updates */\n\nimport { Interface } from '@ethersproject/abi';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n AuthorizationList,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport {\n ARBITRUM_USDC_ADDRESS,\n CHAIN_ID_ARBITRUM,\n CHAIN_ID_HYPERCORE,\n CHAIN_ID_POLYGON,\n HYPERCORE_USDC_ADDRESS,\n HYPERCORE_USDC_DECIMALS,\n NATIVE_TOKEN_ADDRESS,\n PERPS_DEPOSIT_TYPES,\n USDC_DECIMALS,\n PaymentOverride,\n} from '../../constants.js';\nimport { TransactionPayStrategy } from '../../index.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n Amount,\n FiatRates,\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types.js';\nimport { getFiatValueFromUsd } from '../../utils/amounts.js';\nimport {\n getRelayOriginGasOverhead,\n getSlippage,\n getStablecoins,\n isAtomicMaxEnabled,\n isEIP7702Chain,\n isRelayExecuteEnabled,\n} from '../../utils/feature-flags.js';\nimport {\n GasPaymentMode,\n resolveGasPayment,\n resolveGasStationCost,\n} from '../../utils/gas-payment.js';\nimport { calculateGasCost } from '../../utils/gas.js';\nimport {\n getPolymarketDepositWalletOverrides,\n getPredictWithdrawFeeTokenAccount,\n getPredictWithdrawSafeAddress,\n} from '../../utils/polymarket/withdraw.js';\nimport { reservePostQuoteGas } from '../../utils/post-quote.js';\nimport { estimateSourceGas } from '../../utils/quote-gas.js';\nimport type { QuoteGasTransaction } from '../../utils/quote-gas.js';\nimport { resolveNonAtomicRecipient } from '../../utils/second-leg.js';\nimport {\n getNativeToken,\n getTokenFiatRate,\n normalizeTokenAddress,\n TokenAddressTarget,\n} from '../../utils/token.js';\nimport { getQuotePricing } from '../../utils/trade-type.js';\nimport { TOKEN_TRANSFER_FOUR_BYTE } from './constants.js';\nimport { hasRelayDepositStep } from './deposit-step.js';\nimport { applyHyperliquidActivationFee } from './hyperliquid-activation.js';\nimport { fetchRelayQuote } from './relay-api.js';\nimport {\n getRelayMaxQuote,\n isSubsidizedAtomicMaxQuote,\n throwAtomicPromotionFailed,\n} from './relay-max.js';\nimport { validateRelayQuotes } from './relay-validation.js';\nimport type {\n RelayQuote,\n RelayQuoteMetamask,\n RelayQuoteRequest,\n RelayTransactionStep,\n} from './types.js';\n\nconst log = createModuleLogger(projectLogger, 'relay-strategy');\n\nconst ZERO_AMOUNT = { fiat: '0', human: '0', raw: '0', usd: '0' };\n\ntype RelayQuoteRequestDraft = Omit<RelayQuoteRequest, 'amount' | 'tradeType'> &\n Partial<Pick<RelayQuoteRequest, 'amount'>>;\n\n/**\n * Fetches Relay quotes.\n *\n * @param request - Request object.\n * @returns Array of quotes.\n */\nexport async function getRelayQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>[]> {\n const { requests } = request;\n\n log('Fetching quotes', requests);\n\n try {\n const normalizedRequests = await Promise.all(\n requests\n .filter((singleRequest) => {\n const hasTargetMinimum = singleRequest.targetAmountMinimum !== '0';\n const isPostQuote = Boolean(singleRequest.isPostQuote);\n const isExactInputRequest =\n Boolean(singleRequest.isMaxAmount) &&\n new BigNumber(singleRequest.sourceTokenAmount).gt(0);\n\n return hasTargetMinimum || isPostQuote || isExactInputRequest;\n })\n .map((singleRequest) =>\n normalizeRequest(singleRequest, request.transaction),\n )\n .map((normalizedRequest) =>\n applyHyperliquidActivationFee(\n normalizedRequest,\n request.messenger,\n request.transaction,\n request.signal,\n ),\n ),\n );\n\n log('Normalized requests', normalizedRequests);\n\n const quotes = await Promise.all(\n normalizedRequests.map((singleRequest) =>\n getQuoteWithMaxAmountHandling(singleRequest, request),\n ),\n );\n\n const atomicMaxQuotes = quotes.filter(isSubsidizedAtomicMaxQuote);\n const otherQuotes = quotes.filter(\n (quote) => !isSubsidizedAtomicMaxQuote(quote),\n );\n\n if (otherQuotes.length > 0) {\n await validateRelayQuotes({\n messenger: request.messenger,\n quotes: otherQuotes,\n signal: request.signal,\n transaction: request.transaction,\n });\n }\n\n if (atomicMaxQuotes.length > 0) {\n try {\n await validateRelayQuotes({\n messenger: request.messenger,\n quotes: atomicMaxQuotes,\n signal: request.signal,\n transaction: request.transaction,\n });\n } catch (error) {\n throwAtomicPromotionFailed(error);\n }\n }\n\n return quotes;\n } catch (error) {\n log('Error fetching quotes', { error });\n throw error;\n }\n}\n\nasync function getQuoteWithMaxAmountHandling(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>> {\n const { isMaxAmount } = request;\n\n if (!isMaxAmount) {\n return getQuoteWithPostQuoteGasHandling(request, fullRequest);\n }\n\n return getRelayMaxQuote(request, fullRequest, getSingleQuote);\n}\n\n/**\n * For post-quote flows, fetch an initial quote to compute gas cost in source\n * token, then re-quote with the source amount reduced by the gas cost.\n * This ensures Relay reserves enough for the gas fee token payment.\n *\n * For non-post-quote flows, just returns a single quote.\n *\n * @param request - Quote request.\n * @param fullRequest - Full request context.\n * @returns The final quote (phase 2 for post-quote, or phase 1 for normal).\n */\nasync function getQuoteWithPostQuoteGasHandling(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>> {\n const phase1Quote = await getSingleQuote(request, fullRequest);\n\n if (!request.isPostQuote) {\n return phase1Quote;\n }\n\n if (phase1Quote.original.metamask?.isExecute) {\n return phase1Quote;\n }\n\n return await reservePostQuoteGas({\n quote: phase1Quote,\n requote: (adjustedRequest) => getSingleQuote(adjustedRequest, fullRequest),\n });\n}\n\n/**\n * Fetches a single Relay quote.\n *\n * @param request - Quote request.\n * @param fullRequest - Full quotes request.\n * @returns Single quote.\n */\nasync function getSingleQuote(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>> {\n const {\n accountSupports7702: supports7702,\n messenger,\n signal,\n transaction,\n } = fullRequest;\n\n const {\n from,\n sourceChainId,\n sourceTokenAddress,\n sourceTokenAmount,\n targetAmountMinimum,\n targetChainId,\n targetTokenAddress,\n } = request;\n\n const slippageDecimal = getSlippage(\n messenger,\n sourceChainId,\n sourceTokenAddress,\n );\n\n const slippageTolerance = new BigNumber(slippageDecimal * 100 * 100).toFixed(\n 0,\n );\n\n try {\n const useExecute =\n supports7702 &&\n isRelayExecuteEnabled(messenger) &&\n isEIP7702Chain(messenger, sourceChainId);\n\n const nonAtomicRecipient = await resolveNonAtomicRecipient(\n transaction,\n request,\n messenger,\n );\n\n const effectiveRequest = nonAtomicRecipient\n ? { ...request, recipient: nonAtomicRecipient }\n : request;\n\n const body: RelayQuoteRequestDraft = {\n destinationChainId: Number(targetChainId),\n destinationCurrency: targetTokenAddress,\n originChainId: Number(sourceChainId),\n originCurrency: sourceTokenAddress,\n ...(useExecute\n ? {\n originGasOverhead: getRelayOriginGasOverhead(messenger),\n metamask: { executeVersion: 2 },\n }\n : {}),\n recipient: effectiveRequest.recipient ?? from,\n slippageTolerance,\n user: from,\n };\n\n if (effectiveRequest.isPolymarketDepositWallet) {\n const overrides = await getPolymarketDepositWalletOverrides(\n from,\n messenger,\n );\n const { depositWallet } = overrides;\n\n body.originCurrency = overrides.sourceTokenAddress;\n body.user = depositWallet;\n body.refundTo = depositWallet;\n body.useDepositAddress = true;\n body.strict = true;\n }\n\n const isAtomic = effectiveRequest.atomic !== false;\n\n const processedTransactions = await processTransactions(\n transaction,\n effectiveRequest,\n body,\n messenger,\n );\n\n if (\n !processedTransactions &&\n isAtomic &&\n effectiveRequest.isPostQuote &&\n effectiveRequest.paymentOverride === PaymentOverride.MoneyAccount\n ) {\n await processMoneyAccountPostQuote(\n transaction,\n effectiveRequest,\n body,\n messenger,\n );\n } else if (!processedTransactions && effectiveRequest.refundTo) {\n // For post-quote flows, honour the caller-specified refund address so that\n // failed Relay transactions refund to the correct account (e.g. the Predict\n // Safe proxy) rather than defaulting to the EOA.\n body.refundTo = effectiveRequest.refundTo;\n }\n\n const pricing = getQuotePricing({\n hasCalls: Boolean(body.txs?.length),\n sourceTokenAmount,\n targetAmountMinimum,\n transaction,\n });\n\n const finalBody: RelayQuoteRequest = {\n ...body,\n // A step that bundled its own calls has already pinned the amount those\n // calls consume, so it wins over the derived amount.\n amount: body.amount ?? pricing.amount,\n tradeType: pricing.tradeType,\n };\n\n log('Request body', finalBody);\n\n const quote = await fetchRelayQuote(messenger, finalBody, signal);\n\n log('Fetched relay quote', quote);\n\n return await normalizeQuote(quote, effectiveRequest, fullRequest);\n } catch (error) {\n log('Error fetching relay quote', error);\n throw error;\n }\n}\n\nfunction normalizeAuthorizationList(\n authorizationList: AuthorizationList | undefined,\n): RelayQuoteRequest['authorizationList'] {\n return authorizationList?.map((a) => ({\n ...a,\n chainId: Number(a.chainId),\n nonce: Number(a.nonce),\n r: a.r as Hex,\n s: a.s as Hex,\n yParity: Number(a.yParity),\n }));\n}\n\n/**\n * Add tranasction data to request body if needed.\n *\n * @param transaction - Transaction metadata.\n * @param request - Quote request.\n * @param requestBody - Request body to populate.\n * @param messenger - Controller messenger.\n * @returns `true` when the transaction was embedded in the quote; `false` when\n * skipped so the caller can route to an alternate handler.\n */\nasync function processTransactions(\n transaction: TransactionMeta,\n request: QuoteRequest,\n requestBody: RelayQuoteRequestDraft,\n messenger: TransactionPayControllerMessenger,\n): Promise<boolean> {\n // Skip when skipProcessTransactions (defaulting to isPostQuote) is set — the\n // original transaction is submitted separately, not embedded in the quote.\n // Skip Polymarket deposit wallet flows — the source is already a bridged\n // token transfer, not a contract call to embed. Skip non-atomic flows — the\n // second leg is submitted after Relay settlement.\n if (\n (request.skipProcessTransactions ?? request.isPostQuote) === true ||\n request.isPolymarketDepositWallet === true ||\n request.atomic === false\n ) {\n return false;\n }\n\n const { nestedTransactions, txParams } = transaction;\n const { isMaxAmount, targetChainId } = request;\n const data = txParams?.data as Hex | undefined;\n\n const singleData =\n nestedTransactions?.length === 1 ? nestedTransactions[0].data : data;\n\n const isHypercore = targetChainId === CHAIN_ID_HYPERCORE;\n\n const isTokenTransfer =\n !isHypercore && Boolean(singleData?.startsWith(TOKEN_TRANSFER_FOUR_BYTE));\n\n if (isTokenTransfer) {\n requestBody.recipient = getTransferRecipient(singleData as Hex);\n\n log('Updating recipient as token transfer', requestBody.recipient);\n }\n\n const hasNoData = singleData === undefined || singleData === '0x';\n const skipDelegation = hasNoData || isTokenTransfer || isHypercore;\n\n if (skipDelegation) {\n log('Skipping delegation as token transfer or Hypercore deposit');\n return true;\n }\n\n // Eligible atomic max requests carry a destination amount, so the calls\n // below use EXACT_OUTPUT rather than the usual max EXACT_INPUT quote.\n if (\n isMaxAmount &&\n (request.isPostQuote === true ||\n !isAtomicMaxEnabled(messenger, transaction))\n ) {\n throw new Error('Max amount quotes do not support included transactions');\n }\n\n const delegation = await messenger.call(\n 'TransactionPayController:getDelegationTransaction',\n { transaction },\n );\n\n requestBody.authorizationList = normalizeAuthorizationList(\n delegation.authorizationList,\n );\n\n const tokenTransferData = nestedTransactions?.find((nestedTx) =>\n nestedTx.data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE),\n )?.data;\n\n // If the transactions include a token transfer, change the recipient\n // so any extra dust is also sent to the same address, rather than back to the user.\n if (tokenTransferData) {\n requestBody.recipient = getTransferRecipient(tokenTransferData);\n requestBody.refundTo = request.from;\n }\n\n requestBody.txs = [\n {\n to: request.targetTokenAddress,\n data: buildTokenTransferData(\n transaction.txParams.from as Hex,\n request.targetAmountMinimum,\n ),\n value: '0x0',\n },\n {\n to: delegation.to,\n data: delegation.data,\n value: delegation.value,\n },\n ];\n\n return true;\n}\n\nasync function processMoneyAccountPostQuote(\n transaction: TransactionMeta,\n request: QuoteRequest,\n requestBody: RelayQuoteRequestDraft,\n messenger: TransactionPayControllerMessenger,\n): Promise<void> {\n const { transactionData: transactionDataList } = messenger.call(\n 'TransactionPayController:getState',\n );\n\n const transactionData = transactionDataList[transaction.id];\n const amountHuman = transactionData?.tokens?.[0]?.amountHuman ?? '0';\n\n const {\n calls: overrideCalls,\n recipient,\n authorizationList,\n } = await messenger.call('TransactionPayController:getPaymentOverrideData', {\n amount: amountHuman,\n transaction,\n transactionData,\n });\n\n if (!overrideCalls.length) {\n log('No payment override calls for money account post-quote');\n return;\n }\n\n const fundingRecipient = recipient ?? request.from;\n const rawAmount = transactionData?.tokens?.[0]?.amountRaw ?? '0';\n\n requestBody.authorizationList = normalizeAuthorizationList(authorizationList);\n requestBody.amount = rawAmount;\n requestBody.txs = [\n {\n to: request.targetTokenAddress,\n data: buildTokenTransferData(fundingRecipient, rawAmount),\n value: '0x0',\n },\n ...overrideCalls.map((call) => ({\n to: call.to as Hex,\n data: call.data as Hex,\n value: (call.value as Hex) ?? '0x0',\n })),\n ];\n\n log('Added money account deposit calls to quote body', {\n callCount: overrideCalls.length,\n });\n}\n\n/**\n * Normalizes requests for Relay.\n *\n * @param request - Quote request to normalize.\n * @param transaction - Parent transaction metadata, used to gate\n * Hyperliquid-specific rewrites on transaction type.\n * @returns Normalized request.\n */\nfunction normalizeRequest(\n request: QuoteRequest,\n transaction: TransactionMeta,\n): QuoteRequest {\n const newRequest = {\n ...request,\n };\n\n const isPerpsDeposit =\n transaction.type !== undefined &&\n PERPS_DEPOSIT_TYPES.includes(transaction.type);\n\n const isHyperliquidDeposit =\n isPerpsDeposit &&\n !request.isPostQuote &&\n request.targetChainId === CHAIN_ID_ARBITRUM &&\n request.targetTokenAddress.toLowerCase() ===\n ARBITRUM_USDC_ADDRESS.toLowerCase();\n\n newRequest.sourceTokenAddress = normalizeTokenAddress(\n newRequest.sourceTokenAddress,\n newRequest.sourceChainId,\n TokenAddressTarget.Relay,\n );\n newRequest.targetTokenAddress = normalizeTokenAddress(\n newRequest.targetTokenAddress,\n newRequest.targetChainId,\n TokenAddressTarget.Relay,\n );\n\n if (isHyperliquidDeposit) {\n newRequest.targetChainId = CHAIN_ID_HYPERCORE;\n newRequest.targetTokenAddress = HYPERCORE_USDC_ADDRESS;\n newRequest.targetAmountMinimum = new BigNumber(request.targetAmountMinimum)\n .shiftedBy(HYPERCORE_USDC_DECIMALS - USDC_DECIMALS)\n .toString(10);\n\n log('Converting Arbitrum Hyperliquid deposit to direct deposit', {\n originalRequest: request,\n normalizedRequest: newRequest,\n });\n }\n\n // HyperLiquid withdrawal: source is HyperCore Perps USDC, not Arbitrum.\n if (request.isHyperliquidSource) {\n newRequest.sourceChainId = CHAIN_ID_HYPERCORE;\n newRequest.sourceTokenAddress = HYPERCORE_USDC_ADDRESS;\n\n if (newRequest.sourceTokenAmount) {\n newRequest.sourceTokenAmount = new BigNumber(newRequest.sourceTokenAmount)\n .shiftedBy(HYPERCORE_USDC_DECIMALS - USDC_DECIMALS)\n .toString(10);\n }\n }\n\n return newRequest;\n}\n\n/**\n * Normalizes a Relay quote into a TransactionPayQuote.\n *\n * @param quote - Relay quote.\n * @param request - Original quote request.\n * @param fullRequest - Full quotes request.\n * @returns Normalized quote.\n */\nasync function normalizeQuote(\n quote: RelayQuote,\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>> {\n const { messenger } = fullRequest;\n const { details } = quote;\n const { currencyIn, currencyOut } = details;\n\n const { usdToFiatRate } = getFiatRates(messenger, request);\n\n const dust = getFiatValueFromUsd(\n calculateDustUsd(quote, request),\n usdToFiatRate,\n );\n\n const subsidizedFeeUsd = getSubsidizedFeeAmountUsd(messenger, quote);\n\n const appFeeUsd = new BigNumber(quote.fees?.app?.amountUsd ?? '0');\n const metaMaskFee = getFiatValueFromUsd(appFeeUsd, usdToFiatRate);\n\n // Subtract app fee from provider fee since totalImpact.usd already includes\n // it. The relay provider fee is forced to zero when the quote is subsidized,\n // but any reserved HyperLiquid activation fee is withheld from the source\n // send regardless, so it must always be surfaced in the provider fee.\n const activationFeeUsd = new BigNumber(\n request.hyperliquidActivationFeeUsd ?? '0',\n );\n const providerFeeUsd = subsidizedFeeUsd.gt(0)\n ? activationFeeUsd\n : calculateProviderFee(quote).minus(appFeeUsd).plus(activationFeeUsd);\n const provider = getFiatValueFromUsd(providerFeeUsd, usdToFiatRate);\n\n const {\n gasLimits,\n is7702,\n isGasFeeToken: isSourceGasFeeToken,\n ...sourceNetwork\n } = await calculateSourceNetworkCost(\n quote,\n messenger,\n request,\n fullRequest.transaction,\n fullRequest.accountSupports7702,\n );\n\n const targetNetwork = {\n usd: '0',\n fiat: '0',\n };\n\n const sourceAmount: Amount = {\n human: currencyIn.amountFormatted,\n raw: currencyIn.amount,\n ...getFiatValueFromUsd(new BigNumber(currencyIn.amountUsd), usdToFiatRate),\n };\n\n const isTargetStablecoin = isStablecoin(\n messenger,\n request.targetChainId,\n request.targetTokenAddress,\n );\n\n const targetAmountUsd = isTargetStablecoin\n ? new BigNumber(currencyOut.amountFormatted)\n : new BigNumber(currencyOut.amountUsd);\n\n const targetAmount = getFiatValueFromUsd(targetAmountUsd, usdToFiatRate);\n\n const metamask: RelayQuoteMetamask = {\n ...quote.metamask,\n gasLimits: is7702 ? [gasLimits[0]] : gasLimits,\n is7702,\n };\n\n return {\n dust,\n estimatedDuration: details.timeEstimate,\n fees: {\n isSourceGasFeeToken,\n metaMask: metaMaskFee,\n provider,\n sourceNetwork,\n targetNetwork,\n },\n isInputBased: quote.request.tradeType === 'EXACT_INPUT',\n original: {\n ...quote,\n metamask,\n },\n request,\n sourceAmount,\n targetAmount,\n strategy: TransactionPayStrategy.Relay,\n };\n}\n\n/**\n * Calculate dust USD value.\n *\n * @param quote - Relay quote.\n * @param request - Quote request.\n * @returns Dust value in USD and fiat.\n */\nfunction calculateDustUsd(quote: RelayQuote, request: QuoteRequest): BigNumber {\n const { currencyOut } = quote.details;\n const { amountUsd, amountFormatted, minimumAmount } = currencyOut;\n const { decimals: targetDecimals } = currencyOut.currency;\n\n const targetUsdRate = new BigNumber(amountUsd).dividedBy(amountFormatted);\n\n const dustRaw = BigNumber.maximum(\n new BigNumber(minimumAmount).minus(request.targetAmountMinimum),\n 0,\n );\n\n return dustRaw.shiftedBy(-targetDecimals).multipliedBy(targetUsdRate);\n}\n\n/**\n * Calculates USD to fiat rate.\n *\n * @param messenger - Controller messenger.\n * @param request - Quote request.\n * @returns USD to fiat rate.\n */\nfunction getFiatRates(\n messenger: TransactionPayControllerMessenger,\n request: QuoteRequest,\n): {\n sourceFiatRate: FiatRates;\n usdToFiatRate: BigNumber;\n} {\n // For HyperLiquid source, the normalized chain/token (HyperCore + Perps USDC)\n // won't have a fiat rate entry. Use Arbitrum USDC instead since Perps USDC\n // is pegged 1:1.\n const sourceChainId = request.isHyperliquidSource\n ? CHAIN_ID_ARBITRUM\n : request.sourceChainId;\n const sourceTokenAddress = request.isHyperliquidSource\n ? ARBITRUM_USDC_ADDRESS\n : request.sourceTokenAddress;\n\n const finalSourceTokenAddress =\n sourceChainId === CHAIN_ID_POLYGON &&\n sourceTokenAddress === NATIVE_TOKEN_ADDRESS\n ? getNativeToken(sourceChainId)\n : sourceTokenAddress;\n\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n finalSourceTokenAddress,\n sourceChainId,\n );\n\n if (!sourceFiatRate) {\n throw new Error('Source token fiat rate not found');\n }\n\n const usdToFiatRate = new BigNumber(sourceFiatRate.fiatRate).dividedBy(\n sourceFiatRate.usdRate,\n );\n\n return { sourceFiatRate, usdToFiatRate };\n}\n\n/**\n * Calculates source network cost from a Relay quote.\n *\n * For post-quote flows (e.g. predictWithdraw), the cost also includes the\n * original transaction's gas (the user's Polygon USDC.e transfer) in addition\n * to the Relay deposit transaction gas, by appending the original\n * transaction's params so that gas estimation and gas-fee-token logic handle\n * both transactions together.\n *\n * Network fees are zeroed whenever the user does not pay origin gas, either\n * because a relayer covers it or because MetaMask sponsors it.\n *\n * @param quote - Relay quote.\n * @param messenger - Controller messenger.\n * @param request - Quote request.\n * @param transaction - Original transaction metadata.\n * @param accountSupports7702 - Whether the source account supports EIP-7702.\n * @returns Total source network cost in USD and fiat.\n */\nasync function calculateSourceNetworkCost(\n quote: RelayQuote,\n messenger: TransactionPayControllerMessenger,\n request: QuoteRequest,\n transaction: TransactionMeta,\n accountSupports7702: boolean | undefined,\n): Promise<\n TransactionPayQuote<RelayQuote>['fees']['sourceNetwork'] & {\n gasLimits: number[];\n isGasFeeToken?: boolean;\n is7702: boolean;\n }\n> {\n const { from, sourceChainId, sourceTokenAddress } = request;\n\n // None of these flows bill origin gas to the user: the execute flow has a\n // relayer redeem a signed delegation, a HyperLiquid withdrawal's \"deposit\"\n // step is an off-chain HL sendAsset signature rather than an on-chain\n // transaction, and a Polymarket deposit-wallet withdraw is submitted by the\n // Polymarket relayer.\n const isExecuteFlow = Boolean(quote.metamask?.isExecute);\n const isHyperliquidWithdrawal = Boolean(request.isHyperliquidSource);\n const isPolymarketDepositWallet = Boolean(request.isPolymarketDepositWallet);\n\n const gasPayment = resolveGasPayment({\n isDelegated:\n isExecuteFlow || isHyperliquidWithdrawal || isPolymarketDepositWallet,\n sourceTokenAddress,\n sponsorship: {\n accountSupports7702,\n request,\n transaction,\n },\n });\n\n if (gasPayment.mode === GasPaymentMode.Delegation) {\n log('Zeroing network fees as the user does not pay origin gas', {\n isExecuteFlow,\n isHyperliquidWithdrawal,\n isPolymarketDepositWallet,\n });\n\n return {\n estimate: ZERO_AMOUNT,\n max: ZERO_AMOUNT,\n gasLimits: [],\n is7702: false,\n };\n }\n\n if (gasPayment.mode === GasPaymentMode.Sponsored) {\n log('Zeroing source network fees for sponsored same-chain Relay route');\n\n // Gas limit is zero as sponsored transactions go through the EIP-7702\n // gas station hook and do not require user-paid gas.\n return {\n estimate: ZERO_AMOUNT,\n max: ZERO_AMOUNT,\n gasLimits: [0],\n is7702: true,\n };\n }\n\n const txSteps = quote.steps.filter(\n (step): step is RelayTransactionStep => step.kind === 'transaction',\n );\n const relayParams = txSteps\n .flatMap((step) => step.items)\n .map((item) => item.data);\n\n const { chainId, data, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n relayParams[0];\n\n // `fromOverride = Safe proxy` is only valid for deposit-style Relay routes\n // where the deposit contract reads the user's source-token balance directly.\n // Same-chain destinations route through DEX swap aggregators that frequently\n // reject contract callers (anti-MEV `msg.sender == tx.origin` checks,\n // ERC777-style callback interfaces, native wrap/unwrap requiring caller\n // native balance). Simulating those from the Safe proxy reverts and breaks\n // gas estimation. For swap-only routes, fall back to the relay params'\n // EOA `from` so simulation succeeds.\n const fromOverride = getPredictWithdrawSafeAddress(\n request,\n transaction,\n hasRelayDepositStep(quote.steps),\n );\n\n const { gasLimits, is7702, totalGasEstimate, totalGasLimit } =\n await estimateSourceGas({\n fromOverride,\n messenger,\n request,\n transaction,\n transactions: relayParams.map(toQuoteGasTransaction),\n });\n\n log('Gas limit', {\n is7702,\n totalGasEstimate,\n totalGasLimit,\n gasLimits,\n });\n\n const estimate = calculateGasCost({\n chainId,\n gas: totalGasEstimate,\n maxFeePerGas,\n maxPriorityFeePerGas,\n messenger,\n });\n\n const max = calculateGasCost({\n chainId,\n gas: totalGasLimit,\n maxFeePerGas,\n maxPriorityFeePerGas,\n messenger,\n isMax: true,\n });\n\n const result = { estimate, max, gasLimits, is7702 };\n\n // Gas-fee-token lookup must use the Safe proxy for ALL Predict withdraws,\n // not only deposit-style routes. The user's source token (pUSD) lives in\n // the Safe; the EOA is empty until the Safe.execTransaction sub-call runs\n // mid-batch. Querying the EOA for gas-fee-token availability would always\n // return nothing and force users to hold POL.\n // (`useFromOverride` only governs the gas-estimation `from` address, where\n // swap-style routes need EOA because DEX routers reject contract callers.)\n const proxyFeeTokenAccount = getPredictWithdrawFeeTokenAccount(\n request,\n transaction,\n );\n\n const gasStationCost = await resolveGasStationCost({\n accountSupports7702,\n feeTokenAccount: proxyFeeTokenAccount,\n firstStepData: {\n data,\n to,\n value,\n },\n messenger,\n nativeGasCostRaw: max.raw,\n request: {\n from,\n sourceChainId,\n sourceTokenAddress,\n },\n totalGasEstimate,\n totalItemCount: proxyFeeTokenAccount\n ? relayParams.length + 1\n : Math.max(relayParams.length, gasLimits.length),\n });\n\n if (!gasStationCost.amount) {\n return result;\n }\n\n log('Using gas fee token for source network', {\n gasFeeTokenCost: gasStationCost.amount,\n proxyFeeTokenAccount,\n });\n\n return {\n isGasFeeToken: true,\n estimate: gasStationCost.amount,\n max: gasStationCost.amount,\n gasLimits,\n is7702,\n };\n}\n\nfunction toQuoteGasTransaction(\n singleParams: RelayTransactionStep['items'][0]['data'],\n): QuoteGasTransaction {\n return {\n chainId: toHex(singleParams.chainId),\n data: singleParams.data,\n from: singleParams.from,\n gas: singleParams.gas,\n to: singleParams.to,\n value: singleParams.value ?? '0',\n };\n}\n\n/**\n * Calculate the provider fee for a Relay quote.\n *\n * @param quote - Relay quote.\n * @returns - Provider fee in USD.\n */\nfunction calculateProviderFee(quote: RelayQuote): BigNumber {\n return new BigNumber(quote.details.totalImpact.usd).abs();\n}\n\n/**\n * Build token transfer data.\n *\n * @param recipient - Recipient address.\n * @param amountRaw - Amount in raw format.\n * @returns Token transfer data.\n */\nfunction buildTokenTransferData(recipient: Hex, amountRaw: string): Hex {\n return new Interface([\n 'function transfer(address to, uint256 amount)',\n ]).encodeFunctionData('transfer', [recipient, amountRaw]) as Hex;\n}\n\n/**\n * Get transfer recipient from token transfer data.\n *\n * @param data - Token transfer data.\n * @returns Transfer recipient.\n */\nfunction getTransferRecipient(data: Hex): Hex {\n return new Interface(['function transfer(address to, uint256 amount)'])\n .decodeFunctionData('transfer', data)\n .to.toLowerCase();\n}\nfunction getSubsidizedFeeAmountUsd(\n messenger: TransactionPayControllerMessenger,\n quote: RelayQuote,\n): BigNumber {\n const subsidizedFee = quote.fees?.subsidized;\n const amountUsd = new BigNumber(subsidizedFee?.amountUsd ?? '0');\n const amountFormatted = new BigNumber(subsidizedFee?.amountFormatted ?? '0');\n\n if (!subsidizedFee || amountUsd.isZero()) {\n return new BigNumber(0);\n }\n\n const isSubsidizedStablecoin = isStablecoin(\n messenger,\n toHex(subsidizedFee.currency.chainId),\n subsidizedFee.currency.address,\n );\n\n return isSubsidizedStablecoin ? amountFormatted : amountUsd;\n}\n\nfunction isStablecoin(\n messenger: TransactionPayControllerMessenger,\n chainId: string,\n tokenAddress: string,\n): boolean {\n return Boolean(\n getStablecoins(messenger)[chainId as Hex]?.includes(\n tokenAddress.toLowerCase() as Hex,\n ),\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"relay-quotes.js","sourceRoot":"","sources":["../../../src/strategy/relay/relay-quotes.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAMnD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AS,CAAC,aAAa,EAAE,eAAe,IAAI,GAAG,CAAC,CAAC;IAE7E,IAAI,CAAC,aAAa,IAAI,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC;QACzC,OAAO,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IAED,MAAM,sBAAsB,GAAG,YAAY,CACzC,SAAS,EACT,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,EACrC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAC/B,CAAC;IAEF,OAAO,sBAAsB,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9D,CAAC;AAED,SAAS,YAAY,CACnB,SAA4C,EAC5C,OAAe,EACf,YAAoB;IAEpB,OAAO,OAAO,CACZ,cAAc,CAAC,SAAS,CAAC,CAAC,OAAc,CAAC,EAAE,QAAQ,CACjD,YAAY,CAAC,WAAW,EAAS,CAClC,CACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint-disable require-atomic-updates */\n\nimport { Interface } from '@ethersproject/abi';\nimport { toHex } from '@metamask/controller-utils';\nimport type {\n AuthorizationList,\n TransactionMeta,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createModuleLogger } from '@metamask/utils';\nimport { BigNumber } from 'bignumber.js';\n\nimport {\n ARBITRUM_USDC_ADDRESS,\n CHAIN_ID_ARBITRUM,\n CHAIN_ID_HYPERCORE,\n CHAIN_ID_POLYGON,\n HYPERCORE_USDC_ADDRESS,\n NATIVE_TOKEN_ADDRESS,\n} from '../../constants.js';\nimport { TransactionPayStrategy } from '../../index.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n Amount,\n FiatRates,\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayControllerMessenger,\n TransactionPayQuote,\n} from '../../types.js';\nimport { getFiatValueFromUsd } from '../../utils/amounts.js';\nimport {\n getRelayOriginGasOverhead,\n getSlippage,\n getStablecoins,\n isAtomicMaxEnabled,\n isEIP7702Chain,\n isRelayExecuteEnabled,\n} from '../../utils/feature-flags.js';\nimport {\n GasPaymentMode,\n resolveGasPayment,\n resolveGasStationCost,\n} from '../../utils/gas-payment.js';\nimport { calculateGasCost } from '../../utils/gas.js';\nimport {\n normalizePerpsDepositRequest,\n normalizePerpsWithdrawRequest,\n} from '../../utils/perps.js';\nimport {\n getPolymarketDepositWalletOverrides,\n getPredictWithdrawFeeTokenAccount,\n getPredictWithdrawSafeAddress,\n} from '../../utils/polymarket/withdraw.js';\nimport { processPostQuotePaymentOverride } from '../../utils/post-quote-payment-override.js';\nimport { reservePostQuoteGas } from '../../utils/post-quote.js';\nimport { estimateSourceGas } from '../../utils/quote-gas.js';\nimport type { QuoteGasTransaction } from '../../utils/quote-gas.js';\nimport { resolveQuoteRecipient } from '../../utils/quote-recipient.js';\nimport {\n getNativeToken,\n getTokenFiatRate,\n normalizeTokenAddress,\n TokenAddressTarget,\n} from '../../utils/token.js';\nimport { getQuotePricing } from '../../utils/trade-type.js';\nimport { TOKEN_TRANSFER_FOUR_BYTE } from './constants.js';\nimport { hasRelayDepositStep } from './deposit-step.js';\nimport { applyHyperliquidActivationFee } from './hyperliquid-activation.js';\nimport { fetchRelayQuote } from './relay-api.js';\nimport {\n getRelayMaxQuote,\n isSubsidizedAtomicMaxQuote,\n throwAtomicPromotionFailed,\n} from './relay-max.js';\nimport { validateRelayQuotes } from './relay-validation.js';\nimport type {\n RelayQuote,\n RelayQuoteMetamask,\n RelayQuoteRequest,\n RelayTransactionStep,\n} from './types.js';\n\nconst log = createModuleLogger(projectLogger, 'relay-strategy');\n\nconst ZERO_AMOUNT = { fiat: '0', human: '0', raw: '0', usd: '0' };\n\ntype RelayQuoteRequestDraft = Omit<RelayQuoteRequest, 'amount' | 'tradeType'> &\n Partial<Pick<RelayQuoteRequest, 'amount'>>;\n\n/**\n * Fetches Relay quotes.\n *\n * @param request - Request object.\n * @returns Array of quotes.\n */\nexport async function getRelayQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>[]> {\n const { requests } = request;\n\n log('Fetching quotes', requests);\n\n try {\n const normalizedRequests = await Promise.all(\n requests\n .filter((singleRequest) => {\n const hasTargetMinimum = singleRequest.targetAmountMinimum !== '0';\n const isPostQuote = Boolean(singleRequest.isPostQuote);\n const isExactInputRequest =\n Boolean(singleRequest.isMaxAmount) &&\n new BigNumber(singleRequest.sourceTokenAmount).gt(0);\n\n return hasTargetMinimum || isPostQuote || isExactInputRequest;\n })\n .map((singleRequest) =>\n normalizeRequest(singleRequest, request.transaction),\n )\n .map((normalizedRequest) =>\n applyHyperliquidActivationFee(\n normalizedRequest,\n request.messenger,\n request.transaction,\n request.signal,\n ),\n ),\n );\n\n log('Normalized requests', normalizedRequests);\n\n const quotes = await Promise.all(\n normalizedRequests.map((singleRequest) =>\n getQuoteWithMaxAmountHandling(singleRequest, request),\n ),\n );\n\n const atomicMaxQuotes = quotes.filter(isSubsidizedAtomicMaxQuote);\n const otherQuotes = quotes.filter(\n (quote) => !isSubsidizedAtomicMaxQuote(quote),\n );\n\n if (otherQuotes.length > 0) {\n await validateRelayQuotes({\n messenger: request.messenger,\n quotes: otherQuotes,\n signal: request.signal,\n transaction: request.transaction,\n });\n }\n\n if (atomicMaxQuotes.length > 0) {\n try {\n await validateRelayQuotes({\n messenger: request.messenger,\n quotes: atomicMaxQuotes,\n signal: request.signal,\n transaction: request.transaction,\n });\n } catch (error) {\n throwAtomicPromotionFailed(error);\n }\n }\n\n return quotes;\n } catch (error) {\n log('Error fetching quotes', { error });\n throw error;\n }\n}\n\nasync function getQuoteWithMaxAmountHandling(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>> {\n const { isMaxAmount } = request;\n\n if (!isMaxAmount) {\n return getQuoteWithPostQuoteGasHandling(request, fullRequest);\n }\n\n return getRelayMaxQuote(request, fullRequest, getSingleQuote);\n}\n\n/**\n * For post-quote flows, fetch an initial quote to compute gas cost in source\n * token, then re-quote with the source amount reduced by the gas cost.\n * This ensures Relay reserves enough for the gas fee token payment.\n *\n * For non-post-quote flows, just returns a single quote.\n *\n * @param request - Quote request.\n * @param fullRequest - Full request context.\n * @returns The final quote (phase 2 for post-quote, or phase 1 for normal).\n */\nasync function getQuoteWithPostQuoteGasHandling(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>> {\n const phase1Quote = await getSingleQuote(request, fullRequest);\n\n if (!request.isPostQuote) {\n return phase1Quote;\n }\n\n if (phase1Quote.original.metamask?.isExecute) {\n return phase1Quote;\n }\n\n return await reservePostQuoteGas({\n quote: phase1Quote,\n requote: (adjustedRequest) => getSingleQuote(adjustedRequest, fullRequest),\n });\n}\n\n/**\n * Fetches a single Relay quote.\n *\n * @param request - Quote request.\n * @param fullRequest - Full quotes request.\n * @returns Single quote.\n */\nasync function getSingleQuote(\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>> {\n const {\n accountSupports7702: supports7702,\n messenger,\n signal,\n transaction,\n } = fullRequest;\n\n const {\n from,\n sourceChainId,\n sourceTokenAddress,\n sourceTokenAmount,\n targetAmountMinimum,\n targetChainId,\n targetTokenAddress,\n } = request;\n\n const slippageDecimal = getSlippage(\n messenger,\n sourceChainId,\n sourceTokenAddress,\n );\n\n const slippageTolerance = new BigNumber(slippageDecimal * 100 * 100).toFixed(\n 0,\n );\n\n try {\n const useExecute =\n supports7702 &&\n isRelayExecuteEnabled(messenger) &&\n isEIP7702Chain(messenger, sourceChainId);\n\n const recipient = await resolveQuoteRecipient({\n messenger,\n request,\n transaction,\n });\n const body: RelayQuoteRequestDraft = {\n destinationChainId: Number(targetChainId),\n destinationCurrency: targetTokenAddress,\n originChainId: Number(sourceChainId),\n originCurrency: sourceTokenAddress,\n ...(useExecute\n ? {\n originGasOverhead: getRelayOriginGasOverhead(messenger),\n metamask: { executeVersion: 2 },\n }\n : {}),\n recipient,\n slippageTolerance,\n user: from,\n };\n\n if (request.isPolymarketDepositWallet) {\n const overrides = await getPolymarketDepositWalletOverrides(\n from,\n messenger,\n );\n const { depositWallet } = overrides;\n\n body.originCurrency = overrides.sourceTokenAddress;\n body.user = depositWallet;\n body.refundTo = depositWallet;\n body.useDepositAddress = true;\n body.strict = true;\n }\n\n const processedTransactions = await processTransactions(\n transaction,\n request,\n body,\n messenger,\n );\n\n if (!processedTransactions) {\n const override = await processPostQuotePaymentOverride({\n messenger,\n request,\n transaction,\n });\n\n if (override) {\n body.amount = override.amount;\n body.authorizationList = normalizeAuthorizationList(\n override.authorizationList,\n );\n body.txs = [\n {\n data: buildTokenTransferData(override.recipient, override.amount),\n to: targetTokenAddress,\n value: '0x0',\n },\n ...override.calls,\n ];\n } else if (request.refundTo) {\n body.refundTo = request.refundTo;\n }\n }\n\n const pricing = getQuotePricing({\n hasCalls: Boolean(body.txs?.length),\n sourceTokenAmount,\n targetAmountMinimum,\n transaction,\n });\n\n const finalBody: RelayQuoteRequest = {\n ...body,\n // A step that bundled its own calls has already pinned the amount those\n // calls consume, so it wins over the derived amount.\n amount: body.amount ?? pricing.amount,\n tradeType: pricing.tradeType,\n };\n\n log('Request body', finalBody);\n\n const quote = await fetchRelayQuote(messenger, finalBody, signal);\n\n log('Fetched relay quote', quote);\n\n return await normalizeQuote(\n quote,\n { ...request, recipient: body.recipient },\n fullRequest,\n );\n } catch (error) {\n log('Error fetching relay quote', error);\n throw error;\n }\n}\n\nfunction normalizeAuthorizationList(\n authorizationList: AuthorizationList | undefined,\n): RelayQuoteRequest['authorizationList'] {\n return authorizationList?.map((a) => ({\n ...a,\n chainId: Number(a.chainId),\n nonce: Number(a.nonce),\n r: a.r as Hex,\n s: a.s as Hex,\n yParity: Number(a.yParity),\n }));\n}\n\n/**\n * Add tranasction data to request body if needed.\n *\n * @param transaction - Transaction metadata.\n * @param request - Quote request.\n * @param requestBody - Request body to populate.\n * @param messenger - Controller messenger.\n * @returns `true` when the transaction was embedded in the quote; `false` when\n * skipped so the caller can route to an alternate handler.\n */\nasync function processTransactions(\n transaction: TransactionMeta,\n request: QuoteRequest,\n requestBody: RelayQuoteRequestDraft,\n messenger: TransactionPayControllerMessenger,\n): Promise<boolean> {\n // Skip when skipProcessTransactions (defaulting to isPostQuote) is set — the\n // original transaction is submitted separately, not embedded in the quote.\n // Skip Polymarket deposit wallet flows — the source is already a bridged\n // token transfer, not a contract call to embed. Skip non-atomic flows — the\n // second leg is submitted after Relay settlement.\n if (\n (request.skipProcessTransactions ?? request.isPostQuote) === true ||\n request.isPolymarketDepositWallet === true ||\n request.atomic === false\n ) {\n return false;\n }\n\n const { nestedTransactions, txParams } = transaction;\n const { isMaxAmount, targetChainId } = request;\n const data = txParams?.data as Hex | undefined;\n\n const singleData =\n nestedTransactions?.length === 1 ? nestedTransactions[0].data : data;\n\n const isHypercore = targetChainId === CHAIN_ID_HYPERCORE;\n\n const isTokenTransfer =\n !isHypercore && Boolean(singleData?.startsWith(TOKEN_TRANSFER_FOUR_BYTE));\n\n if (isTokenTransfer) {\n requestBody.recipient = getTransferRecipient(singleData as Hex);\n\n log('Updating recipient as token transfer', requestBody.recipient);\n }\n\n const hasNoData = singleData === undefined || singleData === '0x';\n const skipDelegation = hasNoData || isTokenTransfer || isHypercore;\n\n if (skipDelegation) {\n log('Skipping delegation as token transfer or Hypercore deposit');\n return true;\n }\n\n // Eligible atomic max requests carry a destination amount, so the calls\n // below use EXACT_OUTPUT rather than the usual max EXACT_INPUT quote.\n if (\n isMaxAmount &&\n (request.isPostQuote === true ||\n !isAtomicMaxEnabled(messenger, transaction))\n ) {\n throw new Error('Max amount quotes do not support included transactions');\n }\n\n const delegation = await messenger.call(\n 'TransactionPayController:getDelegationTransaction',\n { transaction },\n );\n\n requestBody.authorizationList = normalizeAuthorizationList(\n delegation.authorizationList,\n );\n\n const tokenTransferData = nestedTransactions?.find((nestedTx) =>\n nestedTx.data?.startsWith(TOKEN_TRANSFER_FOUR_BYTE),\n )?.data;\n\n // If the transactions include a token transfer, change the recipient\n // so any extra dust is also sent to the same address, rather than back to the user.\n if (tokenTransferData) {\n requestBody.recipient = getTransferRecipient(tokenTransferData);\n requestBody.refundTo = request.from;\n }\n\n requestBody.txs = [\n {\n to: request.targetTokenAddress,\n data: buildTokenTransferData(\n transaction.txParams.from as Hex,\n request.targetAmountMinimum,\n ),\n value: '0x0',\n },\n {\n to: delegation.to,\n data: delegation.data,\n value: delegation.value,\n },\n ];\n\n return true;\n}\n\n/**\n * Normalizes requests for Relay.\n *\n * @param request - Quote request to normalize.\n * @param transaction - Parent transaction metadata, inspected to detect\n * Hyperliquid perps deposits.\n * @returns Normalized request.\n */\nfunction normalizeRequest(\n request: QuoteRequest,\n transaction: TransactionMeta,\n): QuoteRequest {\n const newRequest = {\n ...request,\n sourceTokenAddress: normalizeTokenAddress(\n request.sourceTokenAddress,\n request.sourceChainId,\n TokenAddressTarget.Relay,\n ),\n targetTokenAddress: normalizeTokenAddress(\n request.targetTokenAddress,\n request.targetChainId,\n TokenAddressTarget.Relay,\n ),\n };\n\n const depositRequest = normalizePerpsDepositRequest(\n newRequest,\n transaction,\n HYPERCORE_USDC_ADDRESS,\n );\n\n if (depositRequest !== newRequest) {\n log('Converting Arbitrum Hyperliquid deposit to direct deposit', {\n originalRequest: request,\n normalizedRequest: depositRequest,\n });\n }\n\n return normalizePerpsWithdrawRequest(depositRequest, HYPERCORE_USDC_ADDRESS);\n}\n\n/**\n * Normalizes a Relay quote into a TransactionPayQuote.\n *\n * @param quote - Relay quote.\n * @param request - Original quote request.\n * @param fullRequest - Full quotes request.\n * @returns Normalized quote.\n */\nasync function normalizeQuote(\n quote: RelayQuote,\n request: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<RelayQuote>> {\n const { messenger } = fullRequest;\n const { details } = quote;\n const { currencyIn, currencyOut } = details;\n\n const { usdToFiatRate } = getFiatRates(messenger, request);\n\n const dust = getFiatValueFromUsd(\n calculateDustUsd(quote, request),\n usdToFiatRate,\n );\n\n const subsidizedFeeUsd = getSubsidizedFeeAmountUsd(messenger, quote);\n\n const appFeeUsd = new BigNumber(quote.fees?.app?.amountUsd ?? '0');\n const metaMaskFee = getFiatValueFromUsd(appFeeUsd, usdToFiatRate);\n\n // Subtract app fee from provider fee since totalImpact.usd already includes\n // it. The relay provider fee is forced to zero when the quote is subsidized,\n // but any reserved HyperLiquid activation fee is withheld from the source\n // send regardless, so it must always be surfaced in the provider fee.\n const activationFeeUsd = new BigNumber(\n request.hyperliquidActivationFeeUsd ?? '0',\n );\n const providerFeeUsd = subsidizedFeeUsd.gt(0)\n ? activationFeeUsd\n : calculateProviderFee(quote).minus(appFeeUsd).plus(activationFeeUsd);\n const provider = getFiatValueFromUsd(providerFeeUsd, usdToFiatRate);\n\n const {\n gasLimits,\n is7702,\n isGasFeeToken: isSourceGasFeeToken,\n ...sourceNetwork\n } = await calculateSourceNetworkCost(\n quote,\n messenger,\n request,\n fullRequest.transaction,\n fullRequest.accountSupports7702,\n );\n\n const targetNetwork = {\n usd: '0',\n fiat: '0',\n };\n\n const sourceAmount: Amount = {\n human: currencyIn.amountFormatted,\n raw: currencyIn.amount,\n ...getFiatValueFromUsd(new BigNumber(currencyIn.amountUsd), usdToFiatRate),\n };\n\n const isTargetStablecoin = isStablecoin(\n messenger,\n request.targetChainId,\n request.targetTokenAddress,\n );\n\n const targetAmountUsd = isTargetStablecoin\n ? new BigNumber(currencyOut.amountFormatted)\n : new BigNumber(currencyOut.amountUsd);\n\n const targetAmount = getFiatValueFromUsd(targetAmountUsd, usdToFiatRate);\n\n const metamask: RelayQuoteMetamask = {\n ...quote.metamask,\n gasLimits: is7702 ? [gasLimits[0]] : gasLimits,\n is7702,\n };\n\n return {\n dust,\n estimatedDuration: details.timeEstimate,\n fees: {\n isSourceGasFeeToken,\n metaMask: metaMaskFee,\n provider,\n sourceNetwork,\n targetNetwork,\n },\n isInputBased: quote.request.tradeType === 'EXACT_INPUT',\n original: {\n ...quote,\n metamask,\n },\n request,\n sourceAmount,\n targetAmount,\n strategy: TransactionPayStrategy.Relay,\n };\n}\n\n/**\n * Calculate dust USD value.\n *\n * @param quote - Relay quote.\n * @param request - Quote request.\n * @returns Dust value in USD and fiat.\n */\nfunction calculateDustUsd(quote: RelayQuote, request: QuoteRequest): BigNumber {\n const { currencyOut } = quote.details;\n const { amountUsd, amountFormatted, minimumAmount } = currencyOut;\n const { decimals: targetDecimals } = currencyOut.currency;\n\n const targetUsdRate = new BigNumber(amountUsd).dividedBy(amountFormatted);\n\n const dustRaw = BigNumber.maximum(\n new BigNumber(minimumAmount).minus(request.targetAmountMinimum),\n 0,\n );\n\n return dustRaw.shiftedBy(-targetDecimals).multipliedBy(targetUsdRate);\n}\n\n/**\n * Calculates USD to fiat rate.\n *\n * @param messenger - Controller messenger.\n * @param request - Quote request.\n * @returns USD to fiat rate.\n */\nfunction getFiatRates(\n messenger: TransactionPayControllerMessenger,\n request: QuoteRequest,\n): {\n sourceFiatRate: FiatRates;\n usdToFiatRate: BigNumber;\n} {\n // For HyperLiquid source, the normalized chain/token (HyperCore + Perps USDC)\n // won't have a fiat rate entry. Use Arbitrum USDC instead since Perps USDC\n // is pegged 1:1.\n const sourceChainId = request.isHyperliquidSource\n ? CHAIN_ID_ARBITRUM\n : request.sourceChainId;\n const sourceTokenAddress = request.isHyperliquidSource\n ? ARBITRUM_USDC_ADDRESS\n : request.sourceTokenAddress;\n\n const finalSourceTokenAddress =\n sourceChainId === CHAIN_ID_POLYGON &&\n sourceTokenAddress === NATIVE_TOKEN_ADDRESS\n ? getNativeToken(sourceChainId)\n : sourceTokenAddress;\n\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n finalSourceTokenAddress,\n sourceChainId,\n );\n\n if (!sourceFiatRate) {\n throw new Error('Source token fiat rate not found');\n }\n\n const usdToFiatRate = new BigNumber(sourceFiatRate.fiatRate).dividedBy(\n sourceFiatRate.usdRate,\n );\n\n return { sourceFiatRate, usdToFiatRate };\n}\n\n/**\n * Calculates source network cost from a Relay quote.\n *\n * For post-quote flows (e.g. predictWithdraw), the cost also includes the\n * original transaction's gas (the user's Polygon USDC.e transfer) in addition\n * to the Relay deposit transaction gas, by appending the original\n * transaction's params so that gas estimation and gas-fee-token logic handle\n * both transactions together.\n *\n * Network fees are zeroed whenever the user does not pay origin gas, either\n * because a relayer covers it or because MetaMask sponsors it.\n *\n * @param quote - Relay quote.\n * @param messenger - Controller messenger.\n * @param request - Quote request.\n * @param transaction - Original transaction metadata.\n * @param accountSupports7702 - Whether the source account supports EIP-7702.\n * @returns Total source network cost in USD and fiat.\n */\nasync function calculateSourceNetworkCost(\n quote: RelayQuote,\n messenger: TransactionPayControllerMessenger,\n request: QuoteRequest,\n transaction: TransactionMeta,\n accountSupports7702: boolean | undefined,\n): Promise<\n TransactionPayQuote<RelayQuote>['fees']['sourceNetwork'] & {\n gasLimits: number[];\n isGasFeeToken?: boolean;\n is7702: boolean;\n }\n> {\n const { from, sourceChainId, sourceTokenAddress } = request;\n\n // None of these flows bill origin gas to the user: the execute flow has a\n // relayer redeem a signed delegation, a HyperLiquid withdrawal's \"deposit\"\n // step is an off-chain HL sendAsset signature rather than an on-chain\n // transaction, and a Polymarket deposit-wallet withdraw is submitted by the\n // Polymarket relayer.\n const isExecuteFlow = Boolean(quote.metamask?.isExecute);\n const isHyperliquidWithdrawal = Boolean(request.isHyperliquidSource);\n const isPolymarketDepositWallet = Boolean(request.isPolymarketDepositWallet);\n\n const gasPayment = resolveGasPayment({\n isDelegated:\n isExecuteFlow || isHyperliquidWithdrawal || isPolymarketDepositWallet,\n sourceTokenAddress,\n sponsorship: {\n accountSupports7702,\n request,\n transaction,\n },\n });\n\n if (gasPayment.mode === GasPaymentMode.Delegation) {\n log('Zeroing network fees as the user does not pay origin gas', {\n isExecuteFlow,\n isHyperliquidWithdrawal,\n isPolymarketDepositWallet,\n });\n\n return {\n estimate: ZERO_AMOUNT,\n max: ZERO_AMOUNT,\n gasLimits: [],\n is7702: false,\n };\n }\n\n if (gasPayment.mode === GasPaymentMode.Sponsored) {\n log('Zeroing source network fees for sponsored same-chain Relay route');\n\n // Gas limit is zero as sponsored transactions go through the EIP-7702\n // gas station hook and do not require user-paid gas.\n return {\n estimate: ZERO_AMOUNT,\n max: ZERO_AMOUNT,\n gasLimits: [0],\n is7702: true,\n };\n }\n\n const txSteps = quote.steps.filter(\n (step): step is RelayTransactionStep => step.kind === 'transaction',\n );\n const relayParams = txSteps\n .flatMap((step) => step.items)\n .map((item) => item.data);\n\n const { chainId, data, maxFeePerGas, maxPriorityFeePerGas, to, value } =\n relayParams[0];\n\n // `fromOverride = Safe proxy` is only valid for deposit-style Relay routes\n // where the deposit contract reads the user's source-token balance directly.\n // Same-chain destinations route through DEX swap aggregators that frequently\n // reject contract callers (anti-MEV `msg.sender == tx.origin` checks,\n // ERC777-style callback interfaces, native wrap/unwrap requiring caller\n // native balance). Simulating those from the Safe proxy reverts and breaks\n // gas estimation. For swap-only routes, fall back to the relay params'\n // EOA `from` so simulation succeeds.\n const fromOverride = getPredictWithdrawSafeAddress(\n request,\n transaction,\n hasRelayDepositStep(quote.steps),\n );\n\n const { gasLimits, is7702, totalGasEstimate, totalGasLimit } =\n await estimateSourceGas({\n fromOverride,\n messenger,\n request,\n transaction,\n transactions: relayParams.map(toQuoteGasTransaction),\n });\n\n log('Gas limit', {\n is7702,\n totalGasEstimate,\n totalGasLimit,\n gasLimits,\n });\n\n const estimate = calculateGasCost({\n chainId,\n gas: totalGasEstimate,\n maxFeePerGas,\n maxPriorityFeePerGas,\n messenger,\n });\n\n const max = calculateGasCost({\n chainId,\n gas: totalGasLimit,\n maxFeePerGas,\n maxPriorityFeePerGas,\n messenger,\n isMax: true,\n });\n\n const result = { estimate, max, gasLimits, is7702 };\n\n // Gas-fee-token lookup must use the Safe proxy for ALL Predict withdraws,\n // not only deposit-style routes. The user's source token (pUSD) lives in\n // the Safe; the EOA is empty until the Safe.execTransaction sub-call runs\n // mid-batch. Querying the EOA for gas-fee-token availability would always\n // return nothing and force users to hold POL.\n // (`useFromOverride` only governs the gas-estimation `from` address, where\n // swap-style routes need EOA because DEX routers reject contract callers.)\n const proxyFeeTokenAccount = getPredictWithdrawFeeTokenAccount(\n request,\n transaction,\n );\n\n const gasStationCost = await resolveGasStationCost({\n accountSupports7702,\n feeTokenAccount: proxyFeeTokenAccount,\n firstStepData: {\n data,\n to,\n value,\n },\n messenger,\n nativeGasCostRaw: max.raw,\n request: {\n from,\n sourceChainId,\n sourceTokenAddress,\n },\n totalGasEstimate,\n totalItemCount: proxyFeeTokenAccount\n ? relayParams.length + 1\n : Math.max(relayParams.length, gasLimits.length),\n });\n\n if (!gasStationCost.amount) {\n return result;\n }\n\n log('Using gas fee token for source network', {\n gasFeeTokenCost: gasStationCost.amount,\n proxyFeeTokenAccount,\n });\n\n return {\n isGasFeeToken: true,\n estimate: gasStationCost.amount,\n max: gasStationCost.amount,\n gasLimits,\n is7702,\n };\n}\n\nfunction toQuoteGasTransaction(\n singleParams: RelayTransactionStep['items'][0]['data'],\n): QuoteGasTransaction {\n return {\n chainId: toHex(singleParams.chainId),\n data: singleParams.data,\n from: singleParams.from,\n gas: singleParams.gas,\n to: singleParams.to,\n value: singleParams.value ?? '0',\n };\n}\n\n/**\n * Calculate the provider fee for a Relay quote.\n *\n * @param quote - Relay quote.\n * @returns - Provider fee in USD.\n */\nfunction calculateProviderFee(quote: RelayQuote): BigNumber {\n return new BigNumber(quote.details.totalImpact.usd).abs();\n}\n\n/**\n * Build token transfer data.\n *\n * @param recipient - Recipient address.\n * @param amountRaw - Amount in raw format.\n * @returns Token transfer data.\n */\nfunction buildTokenTransferData(recipient: Hex, amountRaw: string): Hex {\n return new Interface([\n 'function transfer(address to, uint256 amount)',\n ]).encodeFunctionData('transfer', [recipient, amountRaw]) as Hex;\n}\n\n/**\n * Get transfer recipient from token transfer data.\n *\n * @param data - Token transfer data.\n * @returns Transfer recipient.\n */\nfunction getTransferRecipient(data: Hex): Hex {\n return new Interface(['function transfer(address to, uint256 amount)'])\n .decodeFunctionData('transfer', data)\n .to.toLowerCase();\n}\nfunction getSubsidizedFeeAmountUsd(\n messenger: TransactionPayControllerMessenger,\n quote: RelayQuote,\n): BigNumber {\n const subsidizedFee = quote.fees?.subsidized;\n const amountUsd = new BigNumber(subsidizedFee?.amountUsd ?? '0');\n const amountFormatted = new BigNumber(subsidizedFee?.amountFormatted ?? '0');\n\n if (!subsidizedFee || amountUsd.isZero()) {\n return new BigNumber(0);\n }\n\n const isSubsidizedStablecoin = isStablecoin(\n messenger,\n toHex(subsidizedFee.currency.chainId),\n subsidizedFee.currency.address,\n );\n\n return isSubsidizedStablecoin ? amountFormatted : amountUsd;\n}\n\nfunction isStablecoin(\n messenger: TransactionPayControllerMessenger,\n chainId: string,\n tokenAddress: string,\n): boolean {\n return Boolean(\n getStablecoins(messenger)[chainId as Hex]?.includes(\n tokenAddress.toLowerCase() as Hex,\n ),\n );\n}\n"]}
|
|
@@ -9,32 +9,12 @@ import type { QuoteRequest } from '../../types.js';
|
|
|
9
9
|
*/
|
|
10
10
|
export declare const SERVER_HYPERCORE_USDC_PERPS_ADDRESS: Hex;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* caller funnelling a bridge deposit through Pay is supported.
|
|
12
|
+
* Translate a Hyperliquid perps deposit or withdraw quote request into the
|
|
13
|
+
* HyperCore shape with a provider-agnostic sentinel address. Backend providers
|
|
14
|
+
* detect the sentinel and rewrite it to their respective on-chain addresses.
|
|
16
15
|
*
|
|
17
16
|
* @param request - Quote request from the transaction-pay controller.
|
|
18
|
-
* @param transaction - Parent transaction whose
|
|
19
|
-
* @returns Whether the request matches a Hyperliquid bridge deposit.
|
|
20
|
-
*/
|
|
21
|
-
export declare function isServerPerpsDepositRequest(request: Pick<QuoteRequest, 'isPostQuote' | 'targetChainId' | 'targetTokenAddress'>, transaction: Pick<TransactionMeta, 'txParams' | 'nestedTransactions'>): boolean;
|
|
22
|
-
/**
|
|
23
|
-
* Translate a Hyperliquid perps-deposit quote request into the HyperCore
|
|
24
|
-
* direct-deposit shape with a provider-agnostic sentinel destination. Backend
|
|
25
|
-
* providers detect the sentinel and rewrite it to their respective on-chain
|
|
26
|
-
* destinations.
|
|
27
|
-
*
|
|
28
|
-
* Transaction pay starts from the parent on-chain asset (Arbitrum USDC,
|
|
29
|
-
* 6 decimals); HyperCore expects an 8-decimal amount, so the target amount is
|
|
30
|
-
* shifted accordingly.
|
|
31
|
-
*
|
|
32
|
-
* Also handles the perps-withdraw direction: when `request.isHyperliquidSource`
|
|
33
|
-
* is set the source is rewritten to the HyperCore sentinel and the amount is
|
|
34
|
-
* shifted from 8 to 6 decimals.
|
|
35
|
-
*
|
|
36
|
-
* @param request - Quote request from the transaction-pay controller.
|
|
37
|
-
* @param transaction - Parent transaction whose calldata is inspected.
|
|
17
|
+
* @param transaction - Parent transaction whose calls are inspected.
|
|
38
18
|
* @returns Normalized request, or the original request if not a perps flow.
|
|
39
19
|
*/
|
|
40
20
|
export declare function normalizeServerPerpsRequest(request: QuoteRequest, transaction: Pick<TransactionMeta, 'txParams' | 'nestedTransactions'>): QuoteRequest;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perps.d.ts","sourceRoot":"","sources":["../../../src/strategy/server/perps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"perps.d.ts","sourceRoot":"","sources":["../../../src/strategy/server/perps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAMnD;;;;;GAKG;AACH,eAAO,MAAM,mCAAmC,EACE,GAAG,CAAC;AAEtD;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,YAAY,EACrB,WAAW,EAAE,IAAI,CAAC,eAAe,EAAE,UAAU,GAAG,oBAAoB,CAAC,GACpE,YAAY,CAad"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ARBITRUM_USDC_ADDRESS, CHAIN_ID_ARBITRUM, CHAIN_ID_HYPERCORE, HYPERCORE_USDC_DECIMALS, USDC_DECIMALS, } from '../../constants.js';
|
|
1
|
+
import { normalizePerpsDepositRequest, normalizePerpsWithdrawRequest, } from '../../utils/perps.js';
|
|
3
2
|
/**
|
|
4
3
|
* Shared 20-byte sentinel address emitted by the server strategy to flag a
|
|
5
4
|
* Hyperliquid perps deposit. Backend providers translate this to their own
|
|
@@ -7,77 +6,19 @@ import { ARBITRUM_USDC_ADDRESS, CHAIN_ID_ARBITRUM, CHAIN_ID_HYPERCORE, HYPERCORE
|
|
|
7
6
|
* native USDC-PERPS token at the same address).
|
|
8
7
|
*/
|
|
9
8
|
export const SERVER_HYPERCORE_USDC_PERPS_ADDRESS = '0x2100000000000000000000000000000000000000';
|
|
10
|
-
const HYPERLIQUID_BRIDGE_ADDRESS_LOWER = '0x2df1c51e09aecf9cacb7bc98cb1742757f163df7';
|
|
11
|
-
const HYPERLIQUID_BRIDGE_CALLDATA_FRAGMENT = HYPERLIQUID_BRIDGE_ADDRESS_LOWER.slice(2);
|
|
12
9
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* caller funnelling a bridge deposit through Pay is supported.
|
|
10
|
+
* Translate a Hyperliquid perps deposit or withdraw quote request into the
|
|
11
|
+
* HyperCore shape with a provider-agnostic sentinel address. Backend providers
|
|
12
|
+
* detect the sentinel and rewrite it to their respective on-chain addresses.
|
|
17
13
|
*
|
|
18
14
|
* @param request - Quote request from the transaction-pay controller.
|
|
19
|
-
* @param transaction - Parent transaction whose
|
|
20
|
-
* @returns Whether the request matches a Hyperliquid bridge deposit.
|
|
21
|
-
*/
|
|
22
|
-
export function isServerPerpsDepositRequest(request, transaction) {
|
|
23
|
-
if (request.isPostQuote === true ||
|
|
24
|
-
request.targetChainId !== CHAIN_ID_ARBITRUM ||
|
|
25
|
-
request.targetTokenAddress.toLowerCase() !==
|
|
26
|
-
ARBITRUM_USDC_ADDRESS.toLowerCase()) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
return transactionDataReferencesBridge(transaction);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Translate a Hyperliquid perps-deposit quote request into the HyperCore
|
|
33
|
-
* direct-deposit shape with a provider-agnostic sentinel destination. Backend
|
|
34
|
-
* providers detect the sentinel and rewrite it to their respective on-chain
|
|
35
|
-
* destinations.
|
|
36
|
-
*
|
|
37
|
-
* Transaction pay starts from the parent on-chain asset (Arbitrum USDC,
|
|
38
|
-
* 6 decimals); HyperCore expects an 8-decimal amount, so the target amount is
|
|
39
|
-
* shifted accordingly.
|
|
40
|
-
*
|
|
41
|
-
* Also handles the perps-withdraw direction: when `request.isHyperliquidSource`
|
|
42
|
-
* is set the source is rewritten to the HyperCore sentinel and the amount is
|
|
43
|
-
* shifted from 8 to 6 decimals.
|
|
44
|
-
*
|
|
45
|
-
* @param request - Quote request from the transaction-pay controller.
|
|
46
|
-
* @param transaction - Parent transaction whose calldata is inspected.
|
|
15
|
+
* @param transaction - Parent transaction whose calls are inspected.
|
|
47
16
|
* @returns Normalized request, or the original request if not a perps flow.
|
|
48
17
|
*/
|
|
49
18
|
export function normalizeServerPerpsRequest(request, transaction) {
|
|
50
19
|
if (request.isHyperliquidSource) {
|
|
51
|
-
return normalizePerpsWithdrawRequest(request);
|
|
52
|
-
}
|
|
53
|
-
if (!isServerPerpsDepositRequest(request, transaction)) {
|
|
54
|
-
return request;
|
|
20
|
+
return normalizePerpsWithdrawRequest(request, SERVER_HYPERCORE_USDC_PERPS_ADDRESS);
|
|
55
21
|
}
|
|
56
|
-
return
|
|
57
|
-
...request,
|
|
58
|
-
targetAmountMinimum: new BigNumber(request.targetAmountMinimum)
|
|
59
|
-
.shiftedBy(HYPERCORE_USDC_DECIMALS - USDC_DECIMALS)
|
|
60
|
-
.toFixed(0),
|
|
61
|
-
targetChainId: CHAIN_ID_HYPERCORE,
|
|
62
|
-
targetTokenAddress: SERVER_HYPERCORE_USDC_PERPS_ADDRESS,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function normalizePerpsWithdrawRequest(request) {
|
|
66
|
-
return {
|
|
67
|
-
...request,
|
|
68
|
-
sourceChainId: CHAIN_ID_HYPERCORE,
|
|
69
|
-
sourceTokenAddress: SERVER_HYPERCORE_USDC_PERPS_ADDRESS,
|
|
70
|
-
sourceTokenAmount: new BigNumber(request.sourceTokenAmount)
|
|
71
|
-
.shiftedBy(USDC_DECIMALS - HYPERCORE_USDC_DECIMALS)
|
|
72
|
-
.toFixed(0),
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function transactionDataReferencesBridge(transaction) {
|
|
76
|
-
const fragments = [
|
|
77
|
-
transaction.txParams?.to,
|
|
78
|
-
...(transaction.nestedTransactions ?? []).map((tx) => tx.to),
|
|
79
|
-
];
|
|
80
|
-
return fragments.some((value) => typeof value === 'string' &&
|
|
81
|
-
value.toLowerCase().includes(HYPERLIQUID_BRIDGE_CALLDATA_FRAGMENT));
|
|
22
|
+
return normalizePerpsDepositRequest(request, transaction, SERVER_HYPERCORE_USDC_PERPS_ADDRESS);
|
|
82
23
|
}
|
|
83
24
|
//# sourceMappingURL=perps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"perps.js","sourceRoot":"","sources":["../../../src/strategy/server/perps.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"perps.js","sourceRoot":"","sources":["../../../src/strategy/server/perps.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,sBAAsB,CAAC;AAE9B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mCAAmC,GAC9C,4CAAmD,CAAC;AAEtD;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAAqB,EACrB,WAAqE;IAErE,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC;QAChC,OAAO,6BAA6B,CAClC,OAAO,EACP,mCAAmC,CACpC,CAAC;IACJ,CAAC;IAED,OAAO,4BAA4B,CACjC,OAAO,EACP,WAAW,EACX,mCAAmC,CACpC,CAAC;AACJ,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { QuoteRequest } from '../../types.js';\nimport {\n normalizePerpsDepositRequest,\n normalizePerpsWithdrawRequest,\n} from '../../utils/perps.js';\n\n/**\n * Shared 20-byte sentinel address emitted by the server strategy to flag a\n * Hyperliquid perps deposit. Backend providers translate this to their own\n * on-chain destination (e.g. Relay's 16-byte HyperCore USDC sentinel, Across's\n * native USDC-PERPS token at the same address).\n */\nexport const SERVER_HYPERCORE_USDC_PERPS_ADDRESS =\n '0x2100000000000000000000000000000000000000' as Hex;\n\n/**\n * Translate a Hyperliquid perps deposit or withdraw quote request into the\n * HyperCore shape with a provider-agnostic sentinel address. Backend providers\n * detect the sentinel and rewrite it to their respective on-chain addresses.\n *\n * @param request - Quote request from the transaction-pay controller.\n * @param transaction - Parent transaction whose calls are inspected.\n * @returns Normalized request, or the original request if not a perps flow.\n */\nexport function normalizeServerPerpsRequest(\n request: QuoteRequest,\n transaction: Pick<TransactionMeta, 'txParams' | 'nestedTransactions'>,\n): QuoteRequest {\n if (request.isHyperliquidSource) {\n return normalizePerpsWithdrawRequest(\n request,\n SERVER_HYPERCORE_USDC_PERPS_ADDRESS,\n );\n }\n\n return normalizePerpsDepositRequest(\n request,\n transaction,\n SERVER_HYPERCORE_USDC_PERPS_ADDRESS,\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-quotes.d.ts","sourceRoot":"","sources":["../../../src/strategy/server/server-quotes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"server-quotes.d.ts","sourceRoot":"","sources":["../../../src/strategy/server/server-quotes.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,2BAA2B,EAI3B,mBAAmB,EACpB,MAAM,gBAAgB,CAAC;AAwBxB,OAAO,KAAK,EACV,WAAW,EAKZ,MAAM,YAAY,CAAC;AA6CpB;;;;;GAKG;AACH,wBAAsB,eAAe,CACnC,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,mBAAmB,CAAC,WAAW,CAAC,EAAE,CAAC,CAY7C"}
|
|
@@ -2,16 +2,17 @@ import { Interface } from '@ethersproject/abi';
|
|
|
2
2
|
import { toHex } from '@metamask/controller-utils';
|
|
3
3
|
import { createModuleLogger } from '@metamask/utils';
|
|
4
4
|
import { BigNumber } from 'bignumber.js';
|
|
5
|
-
import { CHAIN_ID_HYPERCORE,
|
|
5
|
+
import { CHAIN_ID_HYPERCORE, TransactionPayStrategy } from '../../constants.js';
|
|
6
6
|
import { projectLogger } from '../../logger.js';
|
|
7
7
|
import { getFiatValueFromUsd } from '../../utils/amounts.js';
|
|
8
8
|
import { getSlippage, isEIP7702Chain } from '../../utils/feature-flags.js';
|
|
9
9
|
import { GasPaymentMode, resolveGasPayment, resolveGasStationCost, } from '../../utils/gas-payment.js';
|
|
10
10
|
import { calculateGasCost, getGasFee } from '../../utils/gas.js';
|
|
11
11
|
import { getPolymarketDepositWalletOverrides, getPredictWithdrawFeeTokenAccount, getPredictWithdrawSafeAddress, } from '../../utils/polymarket/withdraw.js';
|
|
12
|
+
import { processPostQuotePaymentOverride } from '../../utils/post-quote-payment-override.js';
|
|
12
13
|
import { reservePostQuoteGas } from '../../utils/post-quote.js';
|
|
13
14
|
import { estimateSourceGas } from '../../utils/quote-gas.js';
|
|
14
|
-
import {
|
|
15
|
+
import { resolveQuoteRecipient } from '../../utils/quote-recipient.js';
|
|
15
16
|
import { getTokenFiatRate } from '../../utils/token.js';
|
|
16
17
|
import { getQuotePricing, TradeType } from '../../utils/trade-type.js';
|
|
17
18
|
import { hasServerDepositStep } from './deposit-step.js';
|
|
@@ -67,8 +68,7 @@ async function requoteProvider(quoteRequest, fullRequest, { provider }) {
|
|
|
67
68
|
}
|
|
68
69
|
async function fetchQuotes(quoteRequest, fullRequest, provider) {
|
|
69
70
|
const { accountSupports7702, messenger, signal, transaction } = fullRequest;
|
|
70
|
-
const
|
|
71
|
-
const body = await buildServerQuoteRequest(settledRequest, transaction, messenger, accountSupports7702);
|
|
71
|
+
const body = await buildServerQuoteRequest(quoteRequest, transaction, messenger, accountSupports7702);
|
|
72
72
|
if (provider) {
|
|
73
73
|
body.providers = [provider];
|
|
74
74
|
}
|
|
@@ -78,40 +78,40 @@ async function fetchQuotes(quoteRequest, fullRequest, provider) {
|
|
|
78
78
|
const fulfilledResults = response.results.filter((result) => isFulfilledResult(result) &&
|
|
79
79
|
(!provider || result.provider === provider) &&
|
|
80
80
|
isUsableDepositAddressQuote(body, result));
|
|
81
|
-
const normalized = await Promise.all(fulfilledResults.map((result) => normalizeQuote(result,
|
|
81
|
+
const normalized = await Promise.all(fulfilledResults.map((result) => normalizeQuote(result, { ...quoteRequest, recipient: body.recipient }, messenger, body, transaction, accountSupports7702, isSecondLegRequired(body, quoteRequest, transaction, result.quote))));
|
|
82
82
|
log('Normalized quotes', normalized);
|
|
83
83
|
return normalized;
|
|
84
84
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Carry the account the funds settle on as the request recipient.
|
|
87
|
-
*
|
|
88
|
-
* The second leg runs from `request.recipient`, which has to match where the
|
|
89
|
-
* funds actually landed. Non-atomic flows settle on the account submitting the
|
|
90
|
-
* second leg, such as the Money Account of a Predict withdraw. Otherwise the
|
|
91
|
-
* quote settles on the executing account rather than the payer.
|
|
92
|
-
*
|
|
93
|
-
* @param quoteRequest - Quote request.
|
|
94
|
-
* @param transaction - Original transaction meta.
|
|
95
|
-
* @param messenger - Controller messenger.
|
|
96
|
-
* @returns The request with the settlement recipient applied.
|
|
97
|
-
*/
|
|
98
|
-
async function resolveSettledRequest(quoteRequest, transaction, messenger) {
|
|
99
|
-
const recipient = (await resolveNonAtomicRecipient(transaction, quoteRequest, messenger)) ??
|
|
100
|
-
transaction.txParams.from;
|
|
101
|
-
return { ...quoteRequest, recipient };
|
|
102
|
-
}
|
|
103
85
|
async function buildServerQuoteRequest(quoteRequest, transaction, messenger, accountSupports7702) {
|
|
104
86
|
const normalizedRequest = normalizeServerPerpsRequest(quoteRequest, transaction);
|
|
105
|
-
const { atomic, from, isMaxAmount, isPolymarketDepositWallet, isPostQuote,
|
|
87
|
+
const { atomic, from, isMaxAmount, isPolymarketDepositWallet, isPostQuote, refundTo, sourceChainId, sourceTokenAddress, sourceTokenAmount, targetAmountMinimum, targetChainId, targetTokenAddress, } = normalizedRequest;
|
|
106
88
|
const singleData = getSingleTransactionData(transaction);
|
|
107
89
|
const isHypercore = targetChainId === CHAIN_ID_HYPERCORE;
|
|
108
|
-
const isTokenTransfer = !isHypercore &&
|
|
90
|
+
const isTokenTransfer = !isHypercore &&
|
|
91
|
+
atomic !== false &&
|
|
92
|
+
!isPostQuote &&
|
|
93
|
+
!isPolymarketDepositWallet &&
|
|
94
|
+
!normalizedRequest.skipProcessTransactions &&
|
|
95
|
+
Boolean(singleData?.startsWith(TOKEN_TRANSFER_FOUR_BYTE));
|
|
109
96
|
// `from` is the payer, which differs from the account the transaction's calls
|
|
110
97
|
// run from when an account override (e.g. Money Account) is active.
|
|
111
98
|
const executionAccount = transaction.txParams.from;
|
|
112
|
-
const
|
|
99
|
+
const tokenTransferRecipient = isTokenTransfer && singleData
|
|
113
100
|
? decodeTransferRecipient(singleData)
|
|
114
|
-
:
|
|
101
|
+
: undefined;
|
|
102
|
+
const override = await processPostQuotePaymentOverride({
|
|
103
|
+
messenger,
|
|
104
|
+
request: normalizedRequest,
|
|
105
|
+
transaction,
|
|
106
|
+
});
|
|
107
|
+
const recipient = await resolveQuoteRecipient({
|
|
108
|
+
messenger,
|
|
109
|
+
request: {
|
|
110
|
+
...normalizedRequest,
|
|
111
|
+
recipient: override?.recipient ?? tokenTransferRecipient,
|
|
112
|
+
},
|
|
113
|
+
transaction,
|
|
114
|
+
});
|
|
115
115
|
const isHypercoreSource = sourceChainId === CHAIN_ID_HYPERCORE;
|
|
116
116
|
// Deposit wallet withdraws are broadcast by the Polymarket relayer rather
|
|
117
117
|
// than as a gasless EIP-7702 batch, so the provider must not quote gasless.
|
|
@@ -143,10 +143,12 @@ async function buildServerQuoteRequest(quoteRequest, transaction, messenger, acc
|
|
|
143
143
|
// The deposit wallet funds the quote with a plain token transfer, so there
|
|
144
144
|
// are no calls to embed.
|
|
145
145
|
(isPolymarketDepositWallet ?? false);
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
if (override) {
|
|
147
|
+
body.amount = override.amount;
|
|
148
|
+
body.calls = override.calls;
|
|
149
|
+
if (override.authorizationList?.length) {
|
|
150
|
+
body.authorizationList = normalizeAuthorizationList(override.authorizationList);
|
|
151
|
+
}
|
|
150
152
|
}
|
|
151
153
|
else if (!skipDelegation) {
|
|
152
154
|
const delegation = await messenger.call('TransactionPayController:getDelegationTransaction', { transaction });
|
|
@@ -163,10 +165,8 @@ async function buildServerQuoteRequest(quoteRequest, transaction, messenger, acc
|
|
|
163
165
|
},
|
|
164
166
|
];
|
|
165
167
|
// Prefer atomic execution, but let providers that cannot run the calls
|
|
166
|
-
// still quote for the funds.
|
|
167
|
-
//
|
|
168
|
-
// we can submit them ourselves once the funds land. Post-quote flows submit
|
|
169
|
-
// their own calls and must not opt in.
|
|
168
|
+
// still quote for the funds. The response determines whether execution is
|
|
169
|
+
// deferred. Post-quote flows submit their own calls and must not opt in.
|
|
170
170
|
if (canDeferCalls({
|
|
171
171
|
accountSupports7702,
|
|
172
172
|
messenger,
|
|
@@ -256,39 +256,6 @@ function normalizeAuthorizationList(authorizationList) {
|
|
|
256
256
|
yParity: Number(entry.yParity),
|
|
257
257
|
}));
|
|
258
258
|
}
|
|
259
|
-
async function processMoneyAccountPostQuote(transaction, request, body, messenger) {
|
|
260
|
-
const { transactionData: transactionDataList } = messenger.call('TransactionPayController:getState');
|
|
261
|
-
const transactionData = transactionDataList[transaction.id];
|
|
262
|
-
const amountHuman = transactionData?.tokens?.[0]?.amountHuman ?? '0';
|
|
263
|
-
const { calls: overrideCalls, recipient, authorizationList, } = await messenger.call('TransactionPayController:getPaymentOverrideData', {
|
|
264
|
-
amount: amountHuman,
|
|
265
|
-
transaction,
|
|
266
|
-
transactionData,
|
|
267
|
-
});
|
|
268
|
-
if (!overrideCalls.length) {
|
|
269
|
-
log('No payment override calls for money account post-quote');
|
|
270
|
-
return;
|
|
271
|
-
}
|
|
272
|
-
const fundingRecipient = recipient ?? request.from;
|
|
273
|
-
const rawAmount = transactionData?.tokens?.[0]?.amountRaw ?? '0';
|
|
274
|
-
// The bundled calls transfer exactly this amount, so pin it rather than
|
|
275
|
-
// letting the amount be derived from the request.
|
|
276
|
-
body.amount = rawAmount;
|
|
277
|
-
// Settle directly on the Money Account. The deposit calls are delegated from
|
|
278
|
-
// the Money Account, so the funds have to be there before they run.
|
|
279
|
-
body.recipient = fundingRecipient;
|
|
280
|
-
body.calls = overrideCalls.map((call) => ({
|
|
281
|
-
data: call.data,
|
|
282
|
-
to: call.to,
|
|
283
|
-
value: call.value ?? '0x0',
|
|
284
|
-
}));
|
|
285
|
-
if (authorizationList?.length) {
|
|
286
|
-
body.authorizationList = normalizeAuthorizationList(authorizationList);
|
|
287
|
-
}
|
|
288
|
-
log('Added money account post-quote calls to server quote body', {
|
|
289
|
-
callCount: overrideCalls.length,
|
|
290
|
-
});
|
|
291
|
-
}
|
|
292
259
|
function shouldRequestQuote(quoteRequest) {
|
|
293
260
|
return (quoteRequest.targetAmountMinimum !== '0' ||
|
|
294
261
|
Boolean(quoteRequest.isPostQuote) ||
|
|
@@ -324,8 +291,7 @@ function isSecondLegRequired(body, quoteRequest, transaction, quote) {
|
|
|
324
291
|
// HyperCore settles off-chain, so there is no target-chain transfer to read
|
|
325
292
|
// a settled amount from. Checks the built body rather than the original
|
|
326
293
|
// request, since perps deposits are only rewritten to HyperCore there.
|
|
327
|
-
if (body.target.chainId === HYPERCORE_CHAIN_ID_NUMBER
|
|
328
|
-
body.source.chainId === HYPERCORE_CHAIN_ID_NUMBER) {
|
|
294
|
+
if (body.target.chainId === HYPERCORE_CHAIN_ID_NUMBER) {
|
|
329
295
|
return false;
|
|
330
296
|
}
|
|
331
297
|
// Post-quote flows submit the original transaction alongside the quote, so
|
|
@@ -334,6 +300,9 @@ function isSecondLegRequired(body, quoteRequest, transaction, quote) {
|
|
|
334
300
|
if (quoteRequest.isPostQuote) {
|
|
335
301
|
return quoteRequest.atomic === false;
|
|
336
302
|
}
|
|
303
|
+
if (body.source.chainId === HYPERCORE_CHAIN_ID_NUMBER) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
337
306
|
// No calls to run. Plain funding transfers and empty calldata are already
|
|
338
307
|
// satisfied by the quote delivering the target token to the recipient.
|
|
339
308
|
if (!transaction.nestedTransactions?.length) {
|