@metamask-previews/transaction-pay-controller 31.2.1-preview-1ae799a5c → 31.2.1-preview-1d88b8ba5
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 +3 -0
- package/dist/strategy/server/server-quotes.d.ts.map +1 -1
- package/dist/strategy/server/server-quotes.js +47 -7
- package/dist/strategy/server/server-quotes.js.map +1 -1
- package/dist/strategy/server/server-support.d.ts +1 -3
- package/dist/strategy/server/server-support.d.ts.map +1 -1
- package/dist/strategy/server/server-support.js +0 -5
- package/dist/strategy/server/server-support.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
12
12
|
- Support non-EVM payment tokens, such as Solana SOL and SPL tokens ([#10272](https://github.com/MetaMask/core/pull/10272))
|
|
13
13
|
- `updatePaymentToken` accepts a non-EVM `assetId`, reading its metadata, balance, and price from `AssetsController` state.
|
|
14
14
|
- The non-EVM source account defaults to the account in the same account group as the transaction account that supports the asset chain, or is selected explicitly by `accountOverride`.
|
|
15
|
+
- Support max-amount quotes in `ServerStrategy`, using the same max flow as `RelayStrategy` ([#11418](https://github.com/MetaMask/core/pull/11418))
|
|
16
|
+
- Re-quote with a reduced source amount so origin gas can be paid from the source token when the user lacks native balance.
|
|
17
|
+
- Quote subsidized routes atomically when `payStrategies.relay.atomicMaxEnabled` is enabled, embedding the transaction's calls re-encoded for the max amount.
|
|
15
18
|
|
|
16
19
|
### Changed
|
|
17
20
|
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AA+BxB,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,CAuB7C"}
|
|
@@ -8,6 +8,7 @@ import { getFiatValueFromUsd } from '../../utils/amounts.js';
|
|
|
8
8
|
import { getSlippage, isEIP7702Chain, isServerGaslessEnabled, } 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
|
+
import { getMaxQuotes, isAtomicMaxSupported } from '../../utils/max-quote.js';
|
|
11
12
|
import { getPolymarketDepositWalletOverrides, getPredictWithdrawFeeTokenAccount, getPredictWithdrawSafeAddress, } from '../../utils/polymarket/withdraw.js';
|
|
12
13
|
import { processPostQuotePaymentOverride } from '../../utils/post-quote-payment-override.js';
|
|
13
14
|
import { reservePostQuoteGas } from '../../utils/post-quote.js';
|
|
@@ -52,6 +53,15 @@ export async function getServerQuotes(request) {
|
|
|
52
53
|
}
|
|
53
54
|
async function getQuotesForRequest(quoteRequest, fullRequest) {
|
|
54
55
|
try {
|
|
56
|
+
if (quoteRequest.isMaxAmount) {
|
|
57
|
+
return await getMaxQuotes({
|
|
58
|
+
fullRequest,
|
|
59
|
+
getQuoteDetails: getServerMaxQuoteDetails,
|
|
60
|
+
getQuotes: (request, transaction) => fetchQuotes(request, { ...fullRequest, transaction }),
|
|
61
|
+
request: quoteRequest,
|
|
62
|
+
requote: (quote, request, transaction) => requoteProvider(request, { ...fullRequest, transaction }, quote.original),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
55
65
|
const quotes = await fetchQuotes(quoteRequest, fullRequest);
|
|
56
66
|
if (!quoteRequest.isPostQuote) {
|
|
57
67
|
return quotes;
|
|
@@ -150,7 +160,14 @@ async function buildServerQuoteRequest(quoteRequest, transaction, messenger, acc
|
|
|
150
160
|
// they must not be embedded in the quote.
|
|
151
161
|
atomic === false ||
|
|
152
162
|
(isPostQuote ?? false) ||
|
|
153
|
-
|
|
163
|
+
// Max requests only embed calls when quoted atomically, as the calls must
|
|
164
|
+
// be re-encoded for the amount the max quote delivers.
|
|
165
|
+
(isMaxAmount === true &&
|
|
166
|
+
!isAtomicMaxSupported({
|
|
167
|
+
messenger,
|
|
168
|
+
request: normalizedRequest,
|
|
169
|
+
transaction,
|
|
170
|
+
})) ||
|
|
154
171
|
// The deposit wallet funds the quote with a plain token transfer, so there
|
|
155
172
|
// are no calls to embed.
|
|
156
173
|
(isPolymarketDepositWallet ?? false);
|
|
@@ -178,12 +195,15 @@ async function buildServerQuoteRequest(quoteRequest, transaction, messenger, acc
|
|
|
178
195
|
// Prefer atomic execution, but let providers that cannot run the calls
|
|
179
196
|
// still quote for the funds. The response determines whether execution is
|
|
180
197
|
// deferred. Post-quote flows submit their own calls and must not opt in.
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
198
|
+
// Atomic max quotes are only valid when the calls are executed by the
|
|
199
|
+
// provider, so they must not opt in either.
|
|
200
|
+
if (!isMaxAmount &&
|
|
201
|
+
canDeferCalls({
|
|
202
|
+
accountSupports7702,
|
|
203
|
+
messenger,
|
|
204
|
+
targetChainId,
|
|
205
|
+
transaction,
|
|
206
|
+
})) {
|
|
187
207
|
body.supportsDeferredCalls = true;
|
|
188
208
|
}
|
|
189
209
|
if (delegation.authorizationList?.length) {
|
|
@@ -522,6 +542,26 @@ async function calculateSourceNetworkCost({ accountSupports7702, gasless, messen
|
|
|
522
542
|
...fees,
|
|
523
543
|
};
|
|
524
544
|
}
|
|
545
|
+
function getServerMaxQuoteDetails({ original, }) {
|
|
546
|
+
const transactionSteps = original.steps.filter(isTransactionStep);
|
|
547
|
+
const [firstStep] = transactionSteps;
|
|
548
|
+
return {
|
|
549
|
+
gasLimits: original.client.gasLimits,
|
|
550
|
+
gasStationTransactions: firstStep
|
|
551
|
+
? {
|
|
552
|
+
firstStepData: {
|
|
553
|
+
data: firstStep.data,
|
|
554
|
+
to: firstStep.to,
|
|
555
|
+
value: firstStep.value,
|
|
556
|
+
},
|
|
557
|
+
totalItemCount: transactionSteps.length,
|
|
558
|
+
}
|
|
559
|
+
: undefined,
|
|
560
|
+
isGasless: original.gasless || !firstStep,
|
|
561
|
+
isSubsidized: original.fees.subsidized,
|
|
562
|
+
targetAmountRaw: original.output.raw,
|
|
563
|
+
};
|
|
564
|
+
}
|
|
525
565
|
function stepToGasTransaction(step, from) {
|
|
526
566
|
return {
|
|
527
567
|
chainId: toHex(step.chainId),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-quotes.js","sourceRoot":"","sources":["../../../src/strategy/server/server-quotes.ts"],"names":[],"mappings":"AAAA,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,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAQhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,EACL,WAAW,EACX,cAAc,EACd,sBAAsB,GACvB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,cAAc,EACd,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,E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C;AAED,SAAS,uBAAuB,CAAC,IAAS;IACxC,OAAO,kBAAkB,CAAC,kBAAkB,CAC1C,UAAU,EACV,IAAI,CACL,CAAC,EAAE,CAAC,WAAW,EAAS,CAAC;AAC5B,CAAC;AAED,SAAS,iBAAiB,CAAC,SAAc,EAAE,SAAiB;IAC1D,OAAO,kBAAkB,CAAC,kBAAkB,CAAC,UAAU,EAAE;QACvD,SAAS;QACT,SAAS;KACV,CAAQ,CAAC;AACZ,CAAC","sourcesContent":["import { 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 { CHAIN_ID_HYPERCORE, TransactionPayStrategy } from '../../constants.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayControllerMessenger,\n TransactionPayFees,\n TransactionPayQuote,\n} from '../../types.js';\nimport { getFiatValueFromUsd } from '../../utils/amounts.js';\nimport {\n getSlippage,\n isEIP7702Chain,\n isServerGaslessEnabled,\n} from '../../utils/feature-flags.js';\nimport {\n GasPaymentMode,\n resolveGasPayment,\n resolveGasStationCost,\n} from '../../utils/gas-payment.js';\nimport { calculateGasCost, getGasFee } from '../../utils/gas.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 { getEvmQuoteSource, getTokenFiatRate } from '../../utils/token.js';\nimport { getQuotePricing, TradeType } from '../../utils/trade-type.js';\nimport { hasServerDepositStep } from './deposit-step.js';\nimport { normalizeServerPerpsRequest } from './perps.js';\nimport { fetchServerQuote } from './server-api.js';\nimport { validateServerQuotes } from './server-validation.js';\nimport type {\n ServerQuote,\n ServerQuotePayload,\n ServerQuoteRequest,\n ServerQuoteResult,\n ServerTransactionStep,\n} from './types.js';\n\nconst log = createModuleLogger(projectLogger, 'server-quotes');\nconst HYPERCORE_CHAIN_ID_NUMBER = Number(CHAIN_ID_HYPERCORE);\nconst TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';\nconst TRANSFER_INTERFACE = new Interface([\n 'function transfer(address to, uint256 amount)',\n]);\nconst ZERO_AMOUNT = { fiat: '0', human: '0', raw: '0', usd: '0' };\nconst ZERO_FIAT_VALUE = { fiat: '0', usd: '0' };\n\ntype FulfilledServerQuoteResult = ServerQuoteResult & {\n quote: NonNullable<ServerQuoteResult['quote']>;\n};\n\n/**\n * A quote request whose pricing is not yet decided.\n *\n * The pricing basis depends on whether calls end up bundled into the request,\n * so it is derived once the calls are known. A step that bundles calls may pin\n * `amount` itself, in which case that amount wins.\n */\ntype ServerQuoteRequestDraft = Omit<\n ServerQuoteRequest,\n 'amount' | 'tradeType'\n> &\n Partial<Pick<ServerQuoteRequest, 'amount'>>;\n\ntype SourceNetworkCost = Pick<\n TransactionPayFees['sourceNetwork'],\n 'estimate' | 'max'\n> & {\n gasLimits: number[];\n is7702: boolean;\n isSourceGasFeeToken?: boolean;\n maxFeePerGas: string | undefined;\n maxPriorityFeePerGas: string | undefined;\n};\n\nfunction isTransactionStep(\n step: ServerQuote['steps'][number],\n): step is ServerTransactionStep {\n return step.type === 'transaction';\n}\n\n/**\n * Fetch server intents-api quotes and normalize them into Transaction Pay quotes.\n *\n * @param request - Quote request context.\n * @returns Normalized server strategy quotes.\n */\nexport async function getServerQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<ServerQuote>[]> {\n const quoteRequests = request.requests.filter(shouldRequestQuote);\n\n log('Fetching quotes', { quoteRequests });\n\n const quotes = (\n await Promise.all(\n quoteRequests.map((quoteRequest) =>\n getQuotesForRequest(quoteRequest, request),\n ),\n )\n ).flat();\n\n if (quotes.length) {\n await validateServerQuotes({\n messenger: request.messenger,\n quotes,\n signal: request.signal,\n transaction: request.transaction,\n });\n }\n\n return quotes;\n}\n\nasync function getQuotesForRequest(\n quoteRequest: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<ServerQuote>[]> {\n try {\n const quotes = await fetchQuotes(quoteRequest, fullRequest);\n\n if (!quoteRequest.isPostQuote) {\n return quotes;\n }\n\n // Post-quote flows commit the whole source balance, so any gas paid in the\n // source token has to be reserved by re-quoting the same provider for less.\n return await Promise.all(\n quotes.map((quote) =>\n reservePostQuoteGas({\n quote,\n requote: (adjustedRequest) =>\n requoteProvider(adjustedRequest, fullRequest, quote.original),\n }),\n ),\n );\n } catch (error) {\n log('Error fetching quotes', { error });\n return [];\n }\n}\n\nasync function requoteProvider(\n quoteRequest: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n { provider }: ServerQuote,\n): Promise<TransactionPayQuote<ServerQuote>> {\n const [quote] = await fetchQuotes(quoteRequest, fullRequest, provider);\n\n if (!quote) {\n throw new Error(`No re-quote from provider: ${provider}`);\n }\n\n return quote;\n}\n\nasync function fetchQuotes(\n quoteRequest: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n provider?: string,\n): Promise<TransactionPayQuote<ServerQuote>[]> {\n const { accountSupports7702, messenger, signal, transaction } = fullRequest;\n\n const body = await buildServerQuoteRequest(\n quoteRequest,\n transaction,\n messenger,\n accountSupports7702,\n );\n\n if (provider) {\n body.providers = [provider];\n }\n\n log('Request body', body);\n\n const response = await fetchServerQuote(messenger, body, signal);\n\n log('Raw quote response', response);\n\n const fulfilledResults = response.results.filter(\n (result): result is FulfilledServerQuoteResult =>\n isFulfilledResult(result) &&\n (!provider || result.provider === provider) &&\n isUsableDepositAddressQuote(body, result),\n );\n\n const normalized = await Promise.all(\n fulfilledResults.map((result) =>\n normalizeQuote(\n result,\n { ...quoteRequest, recipient: body.recipient },\n messenger,\n body,\n transaction,\n accountSupports7702,\n isSecondLegRequired(body, quoteRequest, transaction, result.quote),\n ),\n ),\n );\n\n log('Normalized quotes', normalized);\n\n return normalized;\n}\n\nasync function buildServerQuoteRequest(\n quoteRequest: QuoteRequest,\n transaction: TransactionMeta,\n messenger: TransactionPayControllerMessenger,\n accountSupports7702: boolean,\n): Promise<ServerQuoteRequest> {\n const normalizedRequest = normalizeServerPerpsRequest(\n quoteRequest,\n transaction,\n );\n const {\n atomic,\n from,\n isMaxAmount,\n isPolymarketDepositWallet,\n isPostQuote,\n refundTo,\n sourceTokenAmount,\n targetAmountMinimum,\n targetChainId,\n targetTokenAddress,\n } = normalizedRequest;\n const { chainId: sourceChainId, tokenAddress: sourceTokenAddress } =\n getEvmQuoteSource(normalizedRequest);\n\n const singleData = getSingleTransactionData(transaction);\n const isHypercore = targetChainId === CHAIN_ID_HYPERCORE;\n const isTokenTransfer =\n !isHypercore &&\n atomic !== false &&\n !isPostQuote &&\n !isPolymarketDepositWallet &&\n !normalizedRequest.skipProcessTransactions &&\n Boolean(singleData?.startsWith(TOKEN_TRANSFER_FOUR_BYTE));\n\n // `from` is the payer, which differs from the account the transaction's calls\n // run from when an account override (e.g. Money Account) is active.\n const executionAccount = transaction.txParams.from as Hex;\n\n const tokenTransferRecipient =\n isTokenTransfer && singleData\n ? decodeTransferRecipient(singleData)\n : undefined;\n\n const override = await processPostQuotePaymentOverride({\n messenger,\n request: normalizedRequest,\n transaction,\n });\n const recipient = await resolveQuoteRecipient({\n messenger,\n request: {\n ...normalizedRequest,\n recipient: override?.recipient ?? tokenTransferRecipient,\n },\n transaction,\n });\n\n const isHypercoreSource = sourceChainId === CHAIN_ID_HYPERCORE;\n\n // Deposit wallet withdraws are broadcast by the Polymarket relayer rather\n // than as a gasless EIP-7702 batch, so the provider must not quote gasless.\n const supportsGasless =\n isServerGaslessEnabled(messenger) &&\n !isHypercoreSource &&\n !isPolymarketDepositWallet &&\n accountSupports7702 &&\n isEIP7702Chain(messenger, sourceChainId);\n\n const body: ServerQuoteRequestDraft = {\n source: { chainId: Number(sourceChainId), token: sourceTokenAddress },\n target: { chainId: Number(targetChainId), token: targetTokenAddress },\n sender: from,\n recipient,\n slippage: Math.round(\n getSlippage(messenger, sourceChainId, sourceTokenAddress) * 10000,\n ),\n supportsGasless,\n };\n\n if (isPolymarketDepositWallet) {\n await applyDepositWalletOverrides(body, from, messenger);\n }\n\n const hasNoData = singleData === undefined || singleData === '0x';\n const skipDelegation =\n hasNoData ||\n isTokenTransfer ||\n isHypercore ||\n isHypercoreSource ||\n // Explicitly non-atomic requests want the calls run after settlement, so\n // they must not be embedded in the quote.\n atomic === false ||\n (isPostQuote ?? false) ||\n (isMaxAmount ?? false) ||\n // The deposit wallet funds the quote with a plain token transfer, so there\n // are no calls to embed.\n (isPolymarketDepositWallet ?? false);\n\n if (override) {\n body.amount = override.amount;\n body.calls = override.calls;\n\n if (override.authorizationList?.length) {\n body.authorizationList = normalizeAuthorizationList(\n override.authorizationList,\n );\n }\n } else if (!skipDelegation) {\n const delegation = await messenger.call(\n 'TransactionPayController:getDelegationTransaction',\n { transaction },\n );\n\n body.calls = [\n {\n data: buildTransferData(executionAccount, targetAmountMinimum),\n to: targetTokenAddress,\n value: '0x0',\n },\n {\n data: delegation.data,\n to: delegation.to,\n value: delegation.value,\n },\n ];\n\n // Prefer atomic execution, but let providers that cannot run the calls\n // still quote for the funds. The response determines whether execution is\n // deferred. Post-quote flows submit their own calls and must not opt in.\n if (\n canDeferCalls({\n accountSupports7702,\n messenger,\n targetChainId,\n transaction,\n })\n ) {\n body.supportsDeferredCalls = true;\n }\n\n if (delegation.authorizationList?.length) {\n body.authorizationList = normalizeAuthorizationList(\n delegation.authorizationList,\n );\n }\n } else if (isPostQuote || atomic === false) {\n // Honour the caller's refund address so a failed quote refunds the account\n // the funds came from, such as the Predict Safe, rather than the payer. A\n // deposit wallet refund address is kept, as the sweep reads refunds there.\n body.refundTo ??= refundTo;\n }\n\n const pricing = getQuotePricing({\n hasCalls: Boolean(body.calls?.length),\n sourceTokenAmount,\n targetAmountMinimum,\n transaction,\n });\n\n return {\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\n/**\n * Whether we can run the calls ourselves after the quote settles without\n * involving the user, so a funds-only quote is acceptable.\n *\n * The second leg is an internal, sponsored EIP-7702 batch on the target chain,\n * so the account must be able to sign EIP-7702 authorizations, the target chain\n * must support EIP-7702, and MetaMask must sponsor gas for the transaction on\n * that chain. Otherwise the user would need native gas on the target chain.\n *\n * Temporarily, only nested transactions are supported as second-leg calls, as\n * they are what the second leg re-encodes for the settled amount. Calls that\n * exist only on the top-level transaction are not deferred, so a provider that\n * cannot execute them declines rather than returning a funds-only quote.\n *\n * @param options - Check options.\n * @param options.accountSupports7702 - Whether the account can sign EIP-7702\n * authorizations.\n * @param options.messenger - Controller messenger.\n * @param options.targetChainId - Chain the second leg would run on.\n * @param options.transaction - Transaction being paid for.\n * @returns Whether the calls can be deferred to a second leg.\n */\nfunction canDeferCalls({\n accountSupports7702,\n messenger,\n targetChainId,\n transaction,\n}: {\n accountSupports7702: boolean;\n messenger: TransactionPayControllerMessenger;\n targetChainId: Hex;\n transaction: TransactionMeta;\n}): boolean {\n return (\n Boolean(transaction.nestedTransactions?.length) &&\n accountSupports7702 &&\n transaction.isGasFeeSponsored === true &&\n transaction.chainId === targetChainId &&\n isEIP7702Chain(messenger, targetChainId)\n );\n}\n\n/**\n * Quote a deposit wallet Predict withdraw from the deposit wallet itself.\n *\n * The deposit wallet funds the provider's deposit address with the USDC.e\n * unwrapped from its pUSD, and is also the refund address so the sweep can wrap\n * any refund back into pUSD.\n *\n * @param body - Quote request body to update.\n * @param from - The user EOA that owns the deposit wallet.\n * @param messenger - Controller messenger.\n */\nasync function applyDepositWalletOverrides(\n body: ServerQuoteRequestDraft,\n from: Hex,\n messenger: TransactionPayControllerMessenger,\n): Promise<void> {\n const { depositWallet, sourceTokenAddress } =\n await getPolymarketDepositWalletOverrides(from, messenger);\n\n body.source = { ...body.source, token: sourceTokenAddress };\n body.sender = depositWallet;\n body.refundTo = depositWallet;\n body.useDepositAddress = true;\n}\n\nfunction normalizeAuthorizationList(\n authorizationList: AuthorizationList,\n): NonNullable<ServerQuoteRequest['authorizationList']> {\n return authorizationList.map((entry) => ({\n address: entry.address,\n chainId: Number(entry.chainId),\n nonce: Number(entry.nonce),\n r: entry.r as Hex,\n s: entry.s as Hex,\n yParity: Number(entry.yParity),\n }));\n}\n\nfunction shouldRequestQuote(quoteRequest: QuoteRequest): boolean {\n return (\n quoteRequest.targetAmountMinimum !== '0' ||\n Boolean(quoteRequest.isPostQuote) ||\n Boolean(quoteRequest.isMaxAmount) ||\n Boolean(quoteRequest.isHyperliquidSource)\n );\n}\n\n/**\n * Determines whether the transaction's calls must be submitted as a separate\n * second leg on the target chain after the quote settles.\n *\n * `atomic` is only a hint: whether the calls can be executed by the provider\n * depends on the flow, so this checks what the built request actually carries\n * rather than what the caller asked for. Flows with nothing to run, or that\n * submit their own calls, are excluded.\n *\n * A second leg is needed either because we declined to embed the calls, or\n * because the provider that won the quote told us it will not execute them.\n * Non-atomic post-quote flows always need one: their calls come from the\n * payment override rather than the transaction, and run once funds settle.\n *\n * @param body - The built server quote request.\n * @param quoteRequest - The originating quote request.\n * @param transaction - Original transaction meta.\n * @param quote - The provider's quote payload.\n * @returns `true` when a second leg is required.\n */\nfunction isSecondLegRequired(\n body: ServerQuoteRequest,\n quoteRequest: QuoteRequest,\n transaction: TransactionMeta,\n quote: ServerQuotePayload,\n): boolean {\n // Embedded calls are executed by the provider as part of the quote, unless\n // it quoted for the funds alone and told us to run the calls ourselves.\n if (body.calls?.length && !quote.callsDeferred) {\n return false;\n }\n\n // HyperCore settles off-chain, so there is no target-chain transfer to read\n // a settled amount from. Checks the built body rather than the original\n // request, since perps deposits are only rewritten to HyperCore there.\n if (body.target.chainId === HYPERCORE_CHAIN_ID_NUMBER) {\n return false;\n }\n\n // Post-quote flows submit the original transaction alongside the quote, so\n // the second leg never re-runs it. Only non-atomic flows have override calls\n // left to run once the funds settle.\n if (quoteRequest.isPostQuote) {\n return quoteRequest.atomic === false;\n }\n\n if (body.source.chainId === HYPERCORE_CHAIN_ID_NUMBER) {\n return false;\n }\n\n // No calls to run. Plain funding transfers and empty calldata are already\n // satisfied by the quote delivering the target token to the recipient.\n if (!transaction.nestedTransactions?.length) {\n return false;\n }\n\n const singleData = getSingleTransactionData(transaction);\n\n if (singleData === undefined || singleData === '0x') {\n return false;\n }\n\n if (singleData.startsWith(TOKEN_TRANSFER_FOUR_BYTE)) {\n return false;\n }\n\n return true;\n}\n\nasync function normalizeQuote(\n result: FulfilledServerQuoteResult,\n quoteRequest: QuoteRequest,\n messenger: TransactionPayControllerMessenger,\n body: ServerQuoteRequest,\n transaction: TransactionMeta,\n accountSupports7702: boolean,\n requiresSecondLeg: boolean,\n): Promise<TransactionPayQuote<ServerQuote>> {\n const { quote } = result;\n const { gasless } = quote;\n const isInputBased = body.tradeType === TradeType.ExactInput;\n const transactionSteps = quote.steps.filter(isTransactionStep);\n const isSignatureOnly = transactionSteps.length === 0;\n const sourceNetwork = await calculateSourceNetworkCost({\n accountSupports7702,\n gasless: gasless || isSignatureOnly,\n messenger,\n quoteRequest,\n sender: body.sender,\n steps: transactionSteps,\n transaction,\n });\n\n const { chainId: sourceChainId, tokenAddress: sourceTokenAddress } =\n getEvmQuoteSource(quoteRequest);\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n sourceTokenAddress,\n sourceChainId,\n );\n\n const usdToFiatRate = sourceFiatRate\n ? new BigNumber(sourceFiatRate.fiatRate).dividedBy(sourceFiatRate.usdRate)\n : new BigNumber(1);\n\n const targetFiatRate = getTokenFiatRate(\n messenger,\n quoteRequest.targetTokenAddress,\n quoteRequest.targetChainId,\n );\n\n const metaMask = getFiatValueFromUsd(\n new BigNumber(quote.fees.metamask),\n usdToFiatRate,\n );\n\n const provider = getFiatValueFromUsd(\n new BigNumber(quote.fees.provider),\n usdToFiatRate,\n );\n\n return {\n dust: ZERO_FIAT_VALUE,\n estimatedDuration: quote.duration,\n fees: {\n ...(sourceNetwork.isSourceGasFeeToken\n ? { isSourceGasFeeToken: true }\n : {}),\n metaMask,\n provider,\n sourceNetwork: {\n estimate: sourceNetwork.estimate,\n max: sourceNetwork.max,\n },\n targetNetwork: ZERO_FIAT_VALUE,\n },\n isInputBased,\n original: {\n client: {\n gasLimits: sourceNetwork.gasLimits,\n is7702: sourceNetwork.is7702,\n maxFeePerGas: sourceNetwork.maxFeePerGas,\n maxPriorityFeePerGas: sourceNetwork.maxPriorityFeePerGas,\n },\n duration: quote.duration,\n fees: quote.fees,\n gasless,\n id: quote.id,\n input: quote.input,\n output: quote.output,\n provider: result.provider,\n steps: quote.steps,\n },\n request: quoteRequest,\n requiresSecondLeg,\n sourceAmount: {\n fiat: sourceFiatRate\n ? new BigNumber(quote.input.formatted)\n .multipliedBy(sourceFiatRate.fiatRate)\n .toString(10)\n : '0',\n human: quote.input.formatted,\n raw: quote.input.raw,\n usd: sourceFiatRate\n ? new BigNumber(quote.input.formatted)\n .multipliedBy(sourceFiatRate.usdRate)\n .toString(10)\n : '0',\n },\n strategy: TransactionPayStrategy.Server,\n targetAmount: {\n fiat: targetFiatRate\n ? new BigNumber(quote.output.formatted)\n .multipliedBy(targetFiatRate.fiatRate)\n .toString(10)\n : '0',\n usd: targetFiatRate\n ? new BigNumber(quote.output.formatted)\n .multipliedBy(targetFiatRate.usdRate)\n .toString(10)\n : '0',\n },\n };\n}\n\nasync function calculateSourceNetworkCost({\n accountSupports7702,\n gasless,\n messenger,\n quoteRequest,\n sender,\n steps,\n transaction,\n}: {\n accountSupports7702: boolean | undefined;\n gasless: boolean;\n messenger: TransactionPayControllerMessenger;\n quoteRequest: QuoteRequest;\n sender: Hex;\n steps: ServerTransactionStep[];\n transaction: TransactionMeta;\n}): Promise<SourceNetworkCost> {\n const noFees = {\n estimate: ZERO_AMOUNT,\n gasLimits: [],\n is7702: false,\n max: ZERO_AMOUNT,\n maxFeePerGas: undefined,\n maxPriorityFeePerGas: undefined,\n };\n\n const { from, isPolymarketDepositWallet } = quoteRequest;\n const { chainId: sourceChainId, tokenAddress: sourceTokenAddress } =\n getEvmQuoteSource(quoteRequest);\n\n // A deposit wallet withdraw is broadcast by the Polymarket relayer, which\n // pays the gas, so the user only signs.\n const gasPayment = resolveGasPayment({\n isDelegated: gasless || Boolean(isPolymarketDepositWallet),\n sourceTokenAddress,\n sponsorship: {\n accountSupports7702,\n request: quoteRequest,\n transaction,\n },\n });\n\n if (gasPayment.mode === GasPaymentMode.Delegation) {\n log('Zeroing source network fees as the user does not pay origin gas', {\n gasless,\n isPolymarketDepositWallet,\n });\n return noFees;\n }\n\n if (gasPayment.mode === GasPaymentMode.Sponsored) {\n log('Zeroing source network fees for sponsored same-chain server 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 { ...noFees, gasLimits: [0], is7702: true };\n }\n\n const firstStep = steps[0];\n const chainIdHex = toHex(firstStep.chainId);\n\n const needsGasFeeEstimate =\n !firstStep.maxFeePerGas && !firstStep.maxPriorityFeePerGas;\n\n const gasFeeEstimate = needsGasFeeEstimate\n ? getGasFee(chainIdHex, messenger)\n : { maxFeePerGas: undefined, maxPriorityFeePerGas: undefined };\n\n const maxFeePerGas = firstStep.maxFeePerGas ?? gasFeeEstimate.maxFeePerGas;\n const maxPriorityFeePerGas =\n firstStep.maxPriorityFeePerGas ?? gasFeeEstimate.maxPriorityFeePerGas;\n\n // Legacy Safe Predict withdraws hold the source token in the Safe, so deposit\n // routes are estimated from the Safe. Swap routes keep the sender, as DEX\n // aggregators reject contract callers.\n const fromOverride = getPredictWithdrawSafeAddress(\n quoteRequest,\n transaction,\n hasServerDepositStep(steps),\n );\n\n const { gasLimits, is7702, totalGasEstimate, totalGasLimit } =\n await estimateSourceGas({\n fromOverride,\n messenger,\n request: quoteRequest,\n transaction,\n transactions: steps.map((step) => stepToGasTransaction(step, sender)),\n });\n\n const estimate = calculateGasCost({\n chainId: chainIdHex,\n gas: totalGasEstimate,\n maxFeePerGas: maxFeePerGas ?? '0',\n maxPriorityFeePerGas: maxPriorityFeePerGas ?? '0',\n messenger,\n });\n\n const max = calculateGasCost({\n chainId: chainIdHex,\n gas: totalGasLimit,\n isMax: true,\n maxFeePerGas: maxFeePerGas ?? '0',\n maxPriorityFeePerGas: maxPriorityFeePerGas ?? '0',\n messenger,\n });\n\n const fees = { maxFeePerGas, maxPriorityFeePerGas };\n\n // Every Predict withdraw holds the source token in the Safe, so the fee token\n // lookup must use it even on swap routes.\n const feeTokenAccount = getPredictWithdrawFeeTokenAccount(\n quoteRequest,\n transaction,\n );\n\n const gasStationCost = await resolveGasStationCost({\n feeTokenAccount,\n firstStepData: {\n data: firstStep.data,\n to: firstStep.to,\n value: firstStep.value,\n },\n messenger,\n nativeGasCostRaw: max.raw,\n request: {\n from,\n sourceChainId,\n sourceTokenAddress,\n },\n totalGasEstimate,\n totalItemCount: feeTokenAccount\n ? steps.length + 1\n : Math.max(steps.length, gasLimits.length),\n });\n\n if (!gasStationCost.amount) {\n return { estimate, gasLimits, is7702, max, ...fees };\n }\n\n log('Using gas fee token for source network', {\n feeTokenAccount,\n gasFeeTokenCost: gasStationCost.amount,\n });\n\n return {\n estimate: gasStationCost.amount,\n gasLimits,\n is7702,\n isSourceGasFeeToken: true,\n max: gasStationCost.amount,\n ...fees,\n };\n}\n\nfunction stepToGasTransaction(\n step: ServerTransactionStep,\n from: Hex,\n): QuoteGasTransaction {\n return {\n chainId: toHex(step.chainId),\n data: step.data,\n from,\n to: step.to,\n value: step.value,\n };\n}\n\nfunction getSingleTransactionData(\n transaction: TransactionMeta,\n): Hex | undefined {\n for (const nested of transaction.nestedTransactions ?? []) {\n if (nested.data && nested.data !== '0x') {\n return nested.data;\n }\n }\n\n return transaction.txParams?.data as Hex | undefined;\n}\n\nfunction isFulfilledResult(\n result: ServerQuoteResult,\n): result is FulfilledServerQuoteResult {\n return (\n result.quote?.id !== undefined &&\n result.quote.input !== undefined &&\n result.quote.output !== undefined\n );\n}\n\n/**\n * Whether a quote can be funded as requested. A deposit-address request is only\n * usable when the quote funds the provider with a plain token transfer, since\n * that transfer is what gets replaced by an unwrap straight to the deposit\n * address.\n *\n * @param body - The built server quote request.\n * @param result - Fulfilled provider result.\n * @returns True when the quote is usable.\n */\nfunction isUsableDepositAddressQuote(\n body: ServerQuoteRequest,\n result: FulfilledServerQuoteResult,\n): boolean {\n if (!body.useDepositAddress || hasServerDepositStep(result.quote.steps)) {\n return true;\n }\n\n log('Ignoring deposit address quote without a plain token transfer', {\n provider: result.provider,\n });\n\n return false;\n}\n\nfunction decodeTransferRecipient(data: Hex): Hex {\n return TRANSFER_INTERFACE.decodeFunctionData(\n 'transfer',\n data,\n ).to.toLowerCase() as Hex;\n}\n\nfunction buildTransferData(recipient: Hex, amountRaw: string): Hex {\n return TRANSFER_INTERFACE.encodeFunctionData('transfer', [\n recipient,\n amountRaw,\n ]) as Hex;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"server-quotes.js","sourceRoot":"","sources":["../../../src/strategy/server/server-quotes.ts"],"names":[],"mappings":"AAAA,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,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;A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,CAAC;AACJ,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,2BAA2B,CAClC,IAAwB,EACxB,MAAkC;IAElC,IAAI,CAAC,IAAI,CAAC,iBAAiB,IAAI,oBAAoB,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACxE,OAAO,IAAI,CAAC;IACd,CAAC;IAED,GAAG,CAAC,+DAA+D,EAAE;QACnE,QAAQ,EAAE,MAAM,CAAC,QAAQ;KAC1B,CAAC,CAAC;IAEH,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,uBAAuB,CAAC,IAAS;IACxC,OAAO,kBAAkB,CAAC,kBAAkB,CAC1C,UAAU,EACV,IAAI,CACL,CAAC,EAAE,CAAC,WAAW,EAAS,CAAC;AAC5B,CAAC;AAED,SAAS,iBAAiB,CAAC,SAAc,EAAE,SAAiB;IAC1D,OAAO,kBAAkB,CAAC,kBAAkB,CAAC,UAAU,EAAE;QACvD,SAAS;QACT,SAAS;KACV,CAAQ,CAAC;AACZ,CAAC","sourcesContent":["import { 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 { CHAIN_ID_HYPERCORE, TransactionPayStrategy } from '../../constants.js';\nimport { projectLogger } from '../../logger.js';\nimport type {\n PayStrategyGetQuotesRequest,\n QuoteRequest,\n TransactionPayControllerMessenger,\n TransactionPayFees,\n TransactionPayQuote,\n} from '../../types.js';\nimport { getFiatValueFromUsd } from '../../utils/amounts.js';\nimport {\n getSlippage,\n isEIP7702Chain,\n isServerGaslessEnabled,\n} from '../../utils/feature-flags.js';\nimport {\n GasPaymentMode,\n resolveGasPayment,\n resolveGasStationCost,\n} from '../../utils/gas-payment.js';\nimport { calculateGasCost, getGasFee } from '../../utils/gas.js';\nimport { getMaxQuotes, isAtomicMaxSupported } from '../../utils/max-quote.js';\nimport type { MaxQuoteDetails } from '../../utils/max-quote.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 { getEvmQuoteSource, getTokenFiatRate } from '../../utils/token.js';\nimport { getQuotePricing, TradeType } from '../../utils/trade-type.js';\nimport { hasServerDepositStep } from './deposit-step.js';\nimport { normalizeServerPerpsRequest } from './perps.js';\nimport { fetchServerQuote } from './server-api.js';\nimport { validateServerQuotes } from './server-validation.js';\nimport type {\n ServerQuote,\n ServerQuotePayload,\n ServerQuoteRequest,\n ServerQuoteResult,\n ServerTransactionStep,\n} from './types.js';\n\nconst log = createModuleLogger(projectLogger, 'server-quotes');\nconst HYPERCORE_CHAIN_ID_NUMBER = Number(CHAIN_ID_HYPERCORE);\nconst TOKEN_TRANSFER_FOUR_BYTE = '0xa9059cbb';\nconst TRANSFER_INTERFACE = new Interface([\n 'function transfer(address to, uint256 amount)',\n]);\nconst ZERO_AMOUNT = { fiat: '0', human: '0', raw: '0', usd: '0' };\nconst ZERO_FIAT_VALUE = { fiat: '0', usd: '0' };\n\ntype FulfilledServerQuoteResult = ServerQuoteResult & {\n quote: NonNullable<ServerQuoteResult['quote']>;\n};\n\n/**\n * A quote request whose pricing is not yet decided.\n *\n * The pricing basis depends on whether calls end up bundled into the request,\n * so it is derived once the calls are known. A step that bundles calls may pin\n * `amount` itself, in which case that amount wins.\n */\ntype ServerQuoteRequestDraft = Omit<\n ServerQuoteRequest,\n 'amount' | 'tradeType'\n> &\n Partial<Pick<ServerQuoteRequest, 'amount'>>;\n\ntype SourceNetworkCost = Pick<\n TransactionPayFees['sourceNetwork'],\n 'estimate' | 'max'\n> & {\n gasLimits: number[];\n is7702: boolean;\n isSourceGasFeeToken?: boolean;\n maxFeePerGas: string | undefined;\n maxPriorityFeePerGas: string | undefined;\n};\n\nfunction isTransactionStep(\n step: ServerQuote['steps'][number],\n): step is ServerTransactionStep {\n return step.type === 'transaction';\n}\n\n/**\n * Fetch server intents-api quotes and normalize them into Transaction Pay quotes.\n *\n * @param request - Quote request context.\n * @returns Normalized server strategy quotes.\n */\nexport async function getServerQuotes(\n request: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<ServerQuote>[]> {\n const quoteRequests = request.requests.filter(shouldRequestQuote);\n\n log('Fetching quotes', { quoteRequests });\n\n const quotes = (\n await Promise.all(\n quoteRequests.map((quoteRequest) =>\n getQuotesForRequest(quoteRequest, request),\n ),\n )\n ).flat();\n\n if (quotes.length) {\n await validateServerQuotes({\n messenger: request.messenger,\n quotes,\n signal: request.signal,\n transaction: request.transaction,\n });\n }\n\n return quotes;\n}\n\nasync function getQuotesForRequest(\n quoteRequest: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n): Promise<TransactionPayQuote<ServerQuote>[]> {\n try {\n if (quoteRequest.isMaxAmount) {\n return await getMaxQuotes({\n fullRequest,\n getQuoteDetails: getServerMaxQuoteDetails,\n getQuotes: (request, transaction) =>\n fetchQuotes(request, { ...fullRequest, transaction }),\n request: quoteRequest,\n requote: (quote, request, transaction) =>\n requoteProvider(\n request,\n { ...fullRequest, transaction },\n quote.original,\n ),\n });\n }\n\n const quotes = await fetchQuotes(quoteRequest, fullRequest);\n\n if (!quoteRequest.isPostQuote) {\n return quotes;\n }\n\n // Post-quote flows commit the whole source balance, so any gas paid in the\n // source token has to be reserved by re-quoting the same provider for less.\n return await Promise.all(\n quotes.map((quote) =>\n reservePostQuoteGas({\n quote,\n requote: (adjustedRequest) =>\n requoteProvider(adjustedRequest, fullRequest, quote.original),\n }),\n ),\n );\n } catch (error) {\n log('Error fetching quotes', { error });\n return [];\n }\n}\n\nasync function requoteProvider(\n quoteRequest: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n { provider }: ServerQuote,\n): Promise<TransactionPayQuote<ServerQuote>> {\n const [quote] = await fetchQuotes(quoteRequest, fullRequest, provider);\n\n if (!quote) {\n throw new Error(`No re-quote from provider: ${provider}`);\n }\n\n return quote;\n}\n\nasync function fetchQuotes(\n quoteRequest: QuoteRequest,\n fullRequest: PayStrategyGetQuotesRequest,\n provider?: string,\n): Promise<TransactionPayQuote<ServerQuote>[]> {\n const { accountSupports7702, messenger, signal, transaction } = fullRequest;\n\n const body = await buildServerQuoteRequest(\n quoteRequest,\n transaction,\n messenger,\n accountSupports7702,\n );\n\n if (provider) {\n body.providers = [provider];\n }\n\n log('Request body', body);\n\n const response = await fetchServerQuote(messenger, body, signal);\n\n log('Raw quote response', response);\n\n const fulfilledResults = response.results.filter(\n (result): result is FulfilledServerQuoteResult =>\n isFulfilledResult(result) &&\n (!provider || result.provider === provider) &&\n isUsableDepositAddressQuote(body, result),\n );\n\n const normalized = await Promise.all(\n fulfilledResults.map((result) =>\n normalizeQuote(\n result,\n { ...quoteRequest, recipient: body.recipient },\n messenger,\n body,\n transaction,\n accountSupports7702,\n isSecondLegRequired(body, quoteRequest, transaction, result.quote),\n ),\n ),\n );\n\n log('Normalized quotes', normalized);\n\n return normalized;\n}\n\nasync function buildServerQuoteRequest(\n quoteRequest: QuoteRequest,\n transaction: TransactionMeta,\n messenger: TransactionPayControllerMessenger,\n accountSupports7702: boolean,\n): Promise<ServerQuoteRequest> {\n const normalizedRequest = normalizeServerPerpsRequest(\n quoteRequest,\n transaction,\n );\n const {\n atomic,\n from,\n isMaxAmount,\n isPolymarketDepositWallet,\n isPostQuote,\n refundTo,\n sourceTokenAmount,\n targetAmountMinimum,\n targetChainId,\n targetTokenAddress,\n } = normalizedRequest;\n const { chainId: sourceChainId, tokenAddress: sourceTokenAddress } =\n getEvmQuoteSource(normalizedRequest);\n\n const singleData = getSingleTransactionData(transaction);\n const isHypercore = targetChainId === CHAIN_ID_HYPERCORE;\n const isTokenTransfer =\n !isHypercore &&\n atomic !== false &&\n !isPostQuote &&\n !isPolymarketDepositWallet &&\n !normalizedRequest.skipProcessTransactions &&\n Boolean(singleData?.startsWith(TOKEN_TRANSFER_FOUR_BYTE));\n\n // `from` is the payer, which differs from the account the transaction's calls\n // run from when an account override (e.g. Money Account) is active.\n const executionAccount = transaction.txParams.from as Hex;\n\n const tokenTransferRecipient =\n isTokenTransfer && singleData\n ? decodeTransferRecipient(singleData)\n : undefined;\n\n const override = await processPostQuotePaymentOverride({\n messenger,\n request: normalizedRequest,\n transaction,\n });\n const recipient = await resolveQuoteRecipient({\n messenger,\n request: {\n ...normalizedRequest,\n recipient: override?.recipient ?? tokenTransferRecipient,\n },\n transaction,\n });\n\n const isHypercoreSource = sourceChainId === CHAIN_ID_HYPERCORE;\n\n // Deposit wallet withdraws are broadcast by the Polymarket relayer rather\n // than as a gasless EIP-7702 batch, so the provider must not quote gasless.\n const supportsGasless =\n isServerGaslessEnabled(messenger) &&\n !isHypercoreSource &&\n !isPolymarketDepositWallet &&\n accountSupports7702 &&\n isEIP7702Chain(messenger, sourceChainId);\n\n const body: ServerQuoteRequestDraft = {\n source: { chainId: Number(sourceChainId), token: sourceTokenAddress },\n target: { chainId: Number(targetChainId), token: targetTokenAddress },\n sender: from,\n recipient,\n slippage: Math.round(\n getSlippage(messenger, sourceChainId, sourceTokenAddress) * 10000,\n ),\n supportsGasless,\n };\n\n if (isPolymarketDepositWallet) {\n await applyDepositWalletOverrides(body, from, messenger);\n }\n\n const hasNoData = singleData === undefined || singleData === '0x';\n const skipDelegation =\n hasNoData ||\n isTokenTransfer ||\n isHypercore ||\n isHypercoreSource ||\n // Explicitly non-atomic requests want the calls run after settlement, so\n // they must not be embedded in the quote.\n atomic === false ||\n (isPostQuote ?? false) ||\n // Max requests only embed calls when quoted atomically, as the calls must\n // be re-encoded for the amount the max quote delivers.\n (isMaxAmount === true &&\n !isAtomicMaxSupported({\n messenger,\n request: normalizedRequest,\n transaction,\n })) ||\n // The deposit wallet funds the quote with a plain token transfer, so there\n // are no calls to embed.\n (isPolymarketDepositWallet ?? false);\n\n if (override) {\n body.amount = override.amount;\n body.calls = override.calls;\n\n if (override.authorizationList?.length) {\n body.authorizationList = normalizeAuthorizationList(\n override.authorizationList,\n );\n }\n } else if (!skipDelegation) {\n const delegation = await messenger.call(\n 'TransactionPayController:getDelegationTransaction',\n { transaction },\n );\n\n body.calls = [\n {\n data: buildTransferData(executionAccount, targetAmountMinimum),\n to: targetTokenAddress,\n value: '0x0',\n },\n {\n data: delegation.data,\n to: delegation.to,\n value: delegation.value,\n },\n ];\n\n // Prefer atomic execution, but let providers that cannot run the calls\n // still quote for the funds. The response determines whether execution is\n // deferred. Post-quote flows submit their own calls and must not opt in.\n // Atomic max quotes are only valid when the calls are executed by the\n // provider, so they must not opt in either.\n if (\n !isMaxAmount &&\n canDeferCalls({\n accountSupports7702,\n messenger,\n targetChainId,\n transaction,\n })\n ) {\n body.supportsDeferredCalls = true;\n }\n\n if (delegation.authorizationList?.length) {\n body.authorizationList = normalizeAuthorizationList(\n delegation.authorizationList,\n );\n }\n } else if (isPostQuote || atomic === false) {\n // Honour the caller's refund address so a failed quote refunds the account\n // the funds came from, such as the Predict Safe, rather than the payer. A\n // deposit wallet refund address is kept, as the sweep reads refunds there.\n body.refundTo ??= refundTo;\n }\n\n const pricing = getQuotePricing({\n hasCalls: Boolean(body.calls?.length),\n sourceTokenAmount,\n targetAmountMinimum,\n transaction,\n });\n\n return {\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\n/**\n * Whether we can run the calls ourselves after the quote settles without\n * involving the user, so a funds-only quote is acceptable.\n *\n * The second leg is an internal, sponsored EIP-7702 batch on the target chain,\n * so the account must be able to sign EIP-7702 authorizations, the target chain\n * must support EIP-7702, and MetaMask must sponsor gas for the transaction on\n * that chain. Otherwise the user would need native gas on the target chain.\n *\n * Temporarily, only nested transactions are supported as second-leg calls, as\n * they are what the second leg re-encodes for the settled amount. Calls that\n * exist only on the top-level transaction are not deferred, so a provider that\n * cannot execute them declines rather than returning a funds-only quote.\n *\n * @param options - Check options.\n * @param options.accountSupports7702 - Whether the account can sign EIP-7702\n * authorizations.\n * @param options.messenger - Controller messenger.\n * @param options.targetChainId - Chain the second leg would run on.\n * @param options.transaction - Transaction being paid for.\n * @returns Whether the calls can be deferred to a second leg.\n */\nfunction canDeferCalls({\n accountSupports7702,\n messenger,\n targetChainId,\n transaction,\n}: {\n accountSupports7702: boolean;\n messenger: TransactionPayControllerMessenger;\n targetChainId: Hex;\n transaction: TransactionMeta;\n}): boolean {\n return (\n Boolean(transaction.nestedTransactions?.length) &&\n accountSupports7702 &&\n transaction.isGasFeeSponsored === true &&\n transaction.chainId === targetChainId &&\n isEIP7702Chain(messenger, targetChainId)\n );\n}\n\n/**\n * Quote a deposit wallet Predict withdraw from the deposit wallet itself.\n *\n * The deposit wallet funds the provider's deposit address with the USDC.e\n * unwrapped from its pUSD, and is also the refund address so the sweep can wrap\n * any refund back into pUSD.\n *\n * @param body - Quote request body to update.\n * @param from - The user EOA that owns the deposit wallet.\n * @param messenger - Controller messenger.\n */\nasync function applyDepositWalletOverrides(\n body: ServerQuoteRequestDraft,\n from: Hex,\n messenger: TransactionPayControllerMessenger,\n): Promise<void> {\n const { depositWallet, sourceTokenAddress } =\n await getPolymarketDepositWalletOverrides(from, messenger);\n\n body.source = { ...body.source, token: sourceTokenAddress };\n body.sender = depositWallet;\n body.refundTo = depositWallet;\n body.useDepositAddress = true;\n}\n\nfunction normalizeAuthorizationList(\n authorizationList: AuthorizationList,\n): NonNullable<ServerQuoteRequest['authorizationList']> {\n return authorizationList.map((entry) => ({\n address: entry.address,\n chainId: Number(entry.chainId),\n nonce: Number(entry.nonce),\n r: entry.r as Hex,\n s: entry.s as Hex,\n yParity: Number(entry.yParity),\n }));\n}\n\nfunction shouldRequestQuote(quoteRequest: QuoteRequest): boolean {\n return (\n quoteRequest.targetAmountMinimum !== '0' ||\n Boolean(quoteRequest.isPostQuote) ||\n Boolean(quoteRequest.isMaxAmount) ||\n Boolean(quoteRequest.isHyperliquidSource)\n );\n}\n\n/**\n * Determines whether the transaction's calls must be submitted as a separate\n * second leg on the target chain after the quote settles.\n *\n * `atomic` is only a hint: whether the calls can be executed by the provider\n * depends on the flow, so this checks what the built request actually carries\n * rather than what the caller asked for. Flows with nothing to run, or that\n * submit their own calls, are excluded.\n *\n * A second leg is needed either because we declined to embed the calls, or\n * because the provider that won the quote told us it will not execute them.\n * Non-atomic post-quote flows always need one: their calls come from the\n * payment override rather than the transaction, and run once funds settle.\n *\n * @param body - The built server quote request.\n * @param quoteRequest - The originating quote request.\n * @param transaction - Original transaction meta.\n * @param quote - The provider's quote payload.\n * @returns `true` when a second leg is required.\n */\nfunction isSecondLegRequired(\n body: ServerQuoteRequest,\n quoteRequest: QuoteRequest,\n transaction: TransactionMeta,\n quote: ServerQuotePayload,\n): boolean {\n // Embedded calls are executed by the provider as part of the quote, unless\n // it quoted for the funds alone and told us to run the calls ourselves.\n if (body.calls?.length && !quote.callsDeferred) {\n return false;\n }\n\n // HyperCore settles off-chain, so there is no target-chain transfer to read\n // a settled amount from. Checks the built body rather than the original\n // request, since perps deposits are only rewritten to HyperCore there.\n if (body.target.chainId === HYPERCORE_CHAIN_ID_NUMBER) {\n return false;\n }\n\n // Post-quote flows submit the original transaction alongside the quote, so\n // the second leg never re-runs it. Only non-atomic flows have override calls\n // left to run once the funds settle.\n if (quoteRequest.isPostQuote) {\n return quoteRequest.atomic === false;\n }\n\n if (body.source.chainId === HYPERCORE_CHAIN_ID_NUMBER) {\n return false;\n }\n\n // No calls to run. Plain funding transfers and empty calldata are already\n // satisfied by the quote delivering the target token to the recipient.\n if (!transaction.nestedTransactions?.length) {\n return false;\n }\n\n const singleData = getSingleTransactionData(transaction);\n\n if (singleData === undefined || singleData === '0x') {\n return false;\n }\n\n if (singleData.startsWith(TOKEN_TRANSFER_FOUR_BYTE)) {\n return false;\n }\n\n return true;\n}\n\nasync function normalizeQuote(\n result: FulfilledServerQuoteResult,\n quoteRequest: QuoteRequest,\n messenger: TransactionPayControllerMessenger,\n body: ServerQuoteRequest,\n transaction: TransactionMeta,\n accountSupports7702: boolean,\n requiresSecondLeg: boolean,\n): Promise<TransactionPayQuote<ServerQuote>> {\n const { quote } = result;\n const { gasless } = quote;\n const isInputBased = body.tradeType === TradeType.ExactInput;\n const transactionSteps = quote.steps.filter(isTransactionStep);\n const isSignatureOnly = transactionSteps.length === 0;\n const sourceNetwork = await calculateSourceNetworkCost({\n accountSupports7702,\n gasless: gasless || isSignatureOnly,\n messenger,\n quoteRequest,\n sender: body.sender,\n steps: transactionSteps,\n transaction,\n });\n\n const { chainId: sourceChainId, tokenAddress: sourceTokenAddress } =\n getEvmQuoteSource(quoteRequest);\n const sourceFiatRate = getTokenFiatRate(\n messenger,\n sourceTokenAddress,\n sourceChainId,\n );\n\n const usdToFiatRate = sourceFiatRate\n ? new BigNumber(sourceFiatRate.fiatRate).dividedBy(sourceFiatRate.usdRate)\n : new BigNumber(1);\n\n const targetFiatRate = getTokenFiatRate(\n messenger,\n quoteRequest.targetTokenAddress,\n quoteRequest.targetChainId,\n );\n\n const metaMask = getFiatValueFromUsd(\n new BigNumber(quote.fees.metamask),\n usdToFiatRate,\n );\n\n const provider = getFiatValueFromUsd(\n new BigNumber(quote.fees.provider),\n usdToFiatRate,\n );\n\n return {\n dust: ZERO_FIAT_VALUE,\n estimatedDuration: quote.duration,\n fees: {\n ...(sourceNetwork.isSourceGasFeeToken\n ? { isSourceGasFeeToken: true }\n : {}),\n metaMask,\n provider,\n sourceNetwork: {\n estimate: sourceNetwork.estimate,\n max: sourceNetwork.max,\n },\n targetNetwork: ZERO_FIAT_VALUE,\n },\n isInputBased,\n original: {\n client: {\n gasLimits: sourceNetwork.gasLimits,\n is7702: sourceNetwork.is7702,\n maxFeePerGas: sourceNetwork.maxFeePerGas,\n maxPriorityFeePerGas: sourceNetwork.maxPriorityFeePerGas,\n },\n duration: quote.duration,\n fees: quote.fees,\n gasless,\n id: quote.id,\n input: quote.input,\n output: quote.output,\n provider: result.provider,\n steps: quote.steps,\n },\n request: quoteRequest,\n requiresSecondLeg,\n sourceAmount: {\n fiat: sourceFiatRate\n ? new BigNumber(quote.input.formatted)\n .multipliedBy(sourceFiatRate.fiatRate)\n .toString(10)\n : '0',\n human: quote.input.formatted,\n raw: quote.input.raw,\n usd: sourceFiatRate\n ? new BigNumber(quote.input.formatted)\n .multipliedBy(sourceFiatRate.usdRate)\n .toString(10)\n : '0',\n },\n strategy: TransactionPayStrategy.Server,\n targetAmount: {\n fiat: targetFiatRate\n ? new BigNumber(quote.output.formatted)\n .multipliedBy(targetFiatRate.fiatRate)\n .toString(10)\n : '0',\n usd: targetFiatRate\n ? new BigNumber(quote.output.formatted)\n .multipliedBy(targetFiatRate.usdRate)\n .toString(10)\n : '0',\n },\n };\n}\n\nasync function calculateSourceNetworkCost({\n accountSupports7702,\n gasless,\n messenger,\n quoteRequest,\n sender,\n steps,\n transaction,\n}: {\n accountSupports7702: boolean | undefined;\n gasless: boolean;\n messenger: TransactionPayControllerMessenger;\n quoteRequest: QuoteRequest;\n sender: Hex;\n steps: ServerTransactionStep[];\n transaction: TransactionMeta;\n}): Promise<SourceNetworkCost> {\n const noFees = {\n estimate: ZERO_AMOUNT,\n gasLimits: [],\n is7702: false,\n max: ZERO_AMOUNT,\n maxFeePerGas: undefined,\n maxPriorityFeePerGas: undefined,\n };\n\n const { from, isPolymarketDepositWallet } = quoteRequest;\n const { chainId: sourceChainId, tokenAddress: sourceTokenAddress } =\n getEvmQuoteSource(quoteRequest);\n\n // A deposit wallet withdraw is broadcast by the Polymarket relayer, which\n // pays the gas, so the user only signs.\n const gasPayment = resolveGasPayment({\n isDelegated: gasless || Boolean(isPolymarketDepositWallet),\n sourceTokenAddress,\n sponsorship: {\n accountSupports7702,\n request: quoteRequest,\n transaction,\n },\n });\n\n if (gasPayment.mode === GasPaymentMode.Delegation) {\n log('Zeroing source network fees as the user does not pay origin gas', {\n gasless,\n isPolymarketDepositWallet,\n });\n return noFees;\n }\n\n if (gasPayment.mode === GasPaymentMode.Sponsored) {\n log('Zeroing source network fees for sponsored same-chain server 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 { ...noFees, gasLimits: [0], is7702: true };\n }\n\n const firstStep = steps[0];\n const chainIdHex = toHex(firstStep.chainId);\n\n const needsGasFeeEstimate =\n !firstStep.maxFeePerGas && !firstStep.maxPriorityFeePerGas;\n\n const gasFeeEstimate = needsGasFeeEstimate\n ? getGasFee(chainIdHex, messenger)\n : { maxFeePerGas: undefined, maxPriorityFeePerGas: undefined };\n\n const maxFeePerGas = firstStep.maxFeePerGas ?? gasFeeEstimate.maxFeePerGas;\n const maxPriorityFeePerGas =\n firstStep.maxPriorityFeePerGas ?? gasFeeEstimate.maxPriorityFeePerGas;\n\n // Legacy Safe Predict withdraws hold the source token in the Safe, so deposit\n // routes are estimated from the Safe. Swap routes keep the sender, as DEX\n // aggregators reject contract callers.\n const fromOverride = getPredictWithdrawSafeAddress(\n quoteRequest,\n transaction,\n hasServerDepositStep(steps),\n );\n\n const { gasLimits, is7702, totalGasEstimate, totalGasLimit } =\n await estimateSourceGas({\n fromOverride,\n messenger,\n request: quoteRequest,\n transaction,\n transactions: steps.map((step) => stepToGasTransaction(step, sender)),\n });\n\n const estimate = calculateGasCost({\n chainId: chainIdHex,\n gas: totalGasEstimate,\n maxFeePerGas: maxFeePerGas ?? '0',\n maxPriorityFeePerGas: maxPriorityFeePerGas ?? '0',\n messenger,\n });\n\n const max = calculateGasCost({\n chainId: chainIdHex,\n gas: totalGasLimit,\n isMax: true,\n maxFeePerGas: maxFeePerGas ?? '0',\n maxPriorityFeePerGas: maxPriorityFeePerGas ?? '0',\n messenger,\n });\n\n const fees = { maxFeePerGas, maxPriorityFeePerGas };\n\n // Every Predict withdraw holds the source token in the Safe, so the fee token\n // lookup must use it even on swap routes.\n const feeTokenAccount = getPredictWithdrawFeeTokenAccount(\n quoteRequest,\n transaction,\n );\n\n const gasStationCost = await resolveGasStationCost({\n feeTokenAccount,\n firstStepData: {\n data: firstStep.data,\n to: firstStep.to,\n value: firstStep.value,\n },\n messenger,\n nativeGasCostRaw: max.raw,\n request: {\n from,\n sourceChainId,\n sourceTokenAddress,\n },\n totalGasEstimate,\n totalItemCount: feeTokenAccount\n ? steps.length + 1\n : Math.max(steps.length, gasLimits.length),\n });\n\n if (!gasStationCost.amount) {\n return { estimate, gasLimits, is7702, max, ...fees };\n }\n\n log('Using gas fee token for source network', {\n feeTokenAccount,\n gasFeeTokenCost: gasStationCost.amount,\n });\n\n return {\n estimate: gasStationCost.amount,\n gasLimits,\n is7702,\n isSourceGasFeeToken: true,\n max: gasStationCost.amount,\n ...fees,\n };\n}\n\nfunction getServerMaxQuoteDetails({\n original,\n}: TransactionPayQuote<ServerQuote>): MaxQuoteDetails {\n const transactionSteps = original.steps.filter(isTransactionStep);\n const [firstStep] = transactionSteps;\n\n return {\n gasLimits: original.client.gasLimits,\n gasStationTransactions: firstStep\n ? {\n firstStepData: {\n data: firstStep.data,\n to: firstStep.to,\n value: firstStep.value,\n },\n totalItemCount: transactionSteps.length,\n }\n : undefined,\n isGasless: original.gasless || !firstStep,\n isSubsidized: original.fees.subsidized,\n targetAmountRaw: original.output.raw,\n };\n}\n\nfunction stepToGasTransaction(\n step: ServerTransactionStep,\n from: Hex,\n): QuoteGasTransaction {\n return {\n chainId: toHex(step.chainId),\n data: step.data,\n from,\n to: step.to,\n value: step.value,\n };\n}\n\nfunction getSingleTransactionData(\n transaction: TransactionMeta,\n): Hex | undefined {\n for (const nested of transaction.nestedTransactions ?? []) {\n if (nested.data && nested.data !== '0x') {\n return nested.data;\n }\n }\n\n return transaction.txParams?.data as Hex | undefined;\n}\n\nfunction isFulfilledResult(\n result: ServerQuoteResult,\n): result is FulfilledServerQuoteResult {\n return (\n result.quote?.id !== undefined &&\n result.quote.input !== undefined &&\n result.quote.output !== undefined\n );\n}\n\n/**\n * Whether a quote can be funded as requested. A deposit-address request is only\n * usable when the quote funds the provider with a plain token transfer, since\n * that transfer is what gets replaced by an unwrap straight to the deposit\n * address.\n *\n * @param body - The built server quote request.\n * @param result - Fulfilled provider result.\n * @returns True when the quote is usable.\n */\nfunction isUsableDepositAddressQuote(\n body: ServerQuoteRequest,\n result: FulfilledServerQuoteResult,\n): boolean {\n if (!body.useDepositAddress || hasServerDepositStep(result.quote.steps)) {\n return true;\n }\n\n log('Ignoring deposit address quote without a plain token transfer', {\n provider: result.provider,\n });\n\n return false;\n}\n\nfunction decodeTransferRecipient(data: Hex): Hex {\n return TRANSFER_INTERFACE.decodeFunctionData(\n 'transfer',\n data,\n ).to.toLowerCase() as Hex;\n}\n\nfunction buildTransferData(recipient: Hex, amountRaw: string): Hex {\n return TRANSFER_INTERFACE.encodeFunctionData('transfer', [\n recipient,\n amountRaw,\n ]) as Hex;\n}\n"]}
|
|
@@ -18,9 +18,7 @@ export declare enum ServerUnsupportedReason {
|
|
|
18
18
|
/** The parent transaction type is not in the remote-flag allowlist. */
|
|
19
19
|
DisabledTransactionType = "disabledTransactionType",
|
|
20
20
|
/** Reserving the HyperLiquid activation fee is not implemented. */
|
|
21
|
-
HyperliquidActivationFee = "hyperliquidActivationFee"
|
|
22
|
-
/** Two-phase max-amount gas station probing is not implemented. */
|
|
23
|
-
MaxAmount = "maxAmount"
|
|
21
|
+
HyperliquidActivationFee = "hyperliquidActivationFee"
|
|
24
22
|
}
|
|
25
23
|
/**
|
|
26
24
|
* Determine whether the server strategy can handle a set of quote requests.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-support.d.ts","sourceRoot":"","sources":["../../../src/strategy/server/server-support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAEL,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,wCAAwC,EAAE,eAAe,EAAO,CAAC;AAE9E,4DAA4D;AAC5D,oBAAY,uBAAuB;IACjC,kEAAkE;IAClE,sBAAsB,2BAA2B;IAEjD,uEAAuE;IACvE,uBAAuB,4BAA4B;IAEnD,mEAAmE;IACnE,wBAAwB,6BAA6B;
|
|
1
|
+
{"version":3,"file":"server-support.d.ts","sourceRoot":"","sources":["../../../src/strategy/server/server-support.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAEL,eAAe,EAChB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;;;;;;;GAQG;AACH,eAAO,MAAM,wCAAwC,EAAE,eAAe,EAAO,CAAC;AAE9E,4DAA4D;AAC5D,oBAAY,uBAAuB;IACjC,kEAAkE;IAClE,sBAAsB,2BAA2B;IAEjD,uEAAuE;IACvE,uBAAuB,4BAA4B;IAEnD,mEAAmE;IACnE,wBAAwB,6BAA6B;CACtD;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,0BAA0B,CAAC,EACzC,uBAAuB,EACvB,QAAQ,EACR,WAAW,GACZ,EAAE;IACD,uBAAuB,EAAE,eAAe,EAAE,CAAC;IAC3C,QAAQ,EAAE,YAAY,EAAE,CAAC;IACzB,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B,GAAG,uBAAuB,GAAG,SAAS,CActC"}
|
|
@@ -18,8 +18,6 @@ export var ServerUnsupportedReason;
|
|
|
18
18
|
ServerUnsupportedReason["DisabledTransactionType"] = "disabledTransactionType";
|
|
19
19
|
/** Reserving the HyperLiquid activation fee is not implemented. */
|
|
20
20
|
ServerUnsupportedReason["HyperliquidActivationFee"] = "hyperliquidActivationFee";
|
|
21
|
-
/** Two-phase max-amount gas station probing is not implemented. */
|
|
22
|
-
ServerUnsupportedReason["MaxAmount"] = "maxAmount";
|
|
23
21
|
})(ServerUnsupportedReason || (ServerUnsupportedReason = {}));
|
|
24
22
|
/**
|
|
25
23
|
* Determine whether the server strategy can handle a set of quote requests.
|
|
@@ -69,9 +67,6 @@ function getRequestUnsupportedReason(request) {
|
|
|
69
67
|
if (request.isDirectMusdMoneyAccount === true) {
|
|
70
68
|
return ServerUnsupportedReason.DirectMusdMoneyAccount;
|
|
71
69
|
}
|
|
72
|
-
if (request.isMaxAmount === true) {
|
|
73
|
-
return ServerUnsupportedReason.MaxAmount;
|
|
74
|
-
}
|
|
75
70
|
return undefined;
|
|
76
71
|
}
|
|
77
72
|
//# sourceMappingURL=server-support.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-support.js","sourceRoot":"","sources":["../../../src/strategy/server/server-support.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,GAEnB,MAAM,kCAAkC,CAAC;AAI1C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAsB,EAAE,CAAC;AAE9E,4DAA4D;AAC5D,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"server-support.js","sourceRoot":"","sources":["../../../src/strategy/server/server-support.ts"],"names":[],"mappings":"AACA,OAAO,EACL,kBAAkB,GAEnB,MAAM,kCAAkC,CAAC;AAI1C;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAsB,EAAE,CAAC;AAE9E,4DAA4D;AAC5D,MAAM,CAAN,IAAY,uBASX;AATD,WAAY,uBAAuB;IACjC,kEAAkE;IAClE,4EAAiD,CAAA;IAEjD,uEAAuE;IACvE,8EAAmD,CAAA;IAEnD,mEAAmE;IACnE,gFAAqD,CAAA;AACvD,CAAC,EATW,uBAAuB,KAAvB,uBAAuB,QASlC;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,UAAU,0BAA0B,CAAC,EACzC,uBAAuB,EACvB,QAAQ,EACR,WAAW,GAKZ;IACC,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,uBAAuB,CAAC,EAAE,CAAC;QAC9D,OAAO,uBAAuB,CAAC,uBAAuB,CAAC;IACzD,CAAC;IAED,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,MAAM,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;QAEpD,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;;;;;GAMG;AACH,SAAS,2BAA2B,CAClC,OAAqB;IAErB,IAAI,OAAO,CAAC,2BAA2B,KAAK,SAAS,EAAE,CAAC;QACtD,OAAO,uBAAuB,CAAC,wBAAwB,CAAC;IAC1D,CAAC;IAED,IAAI,OAAO,CAAC,wBAAwB,KAAK,IAAI,EAAE,CAAC;QAC9C,OAAO,uBAAuB,CAAC,sBAAsB,CAAC;IACxD,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC","sourcesContent":["import type { TransactionMeta } from '@metamask/transaction-controller';\nimport {\n hasTransactionType,\n TransactionType,\n} from '@metamask/transaction-controller';\n\nimport type { QuoteRequest } from '../../types.js';\n\n/**\n * Parent transaction types enabled for the server strategy by default.\n *\n * Intentionally empty so that turning on `payStrategies.server.enabled` alone\n * never diverts live traffic away from the relay strategy. Flows are opted in\n * one at a time via the `payStrategies.server.enabledTransactionTypes` remote\n * feature flag, which lets a single flow be validated in isolation before the\n * next one is added.\n */\nexport const DEFAULT_SERVER_ENABLED_TRANSACTION_TYPES: TransactionType[] = [];\n\n/** Why the server strategy declined to handle a request. */\nexport enum ServerUnsupportedReason {\n /** The direct mUSD Money Account fiat flow is not implemented. */\n DirectMusdMoneyAccount = 'directMusdMoneyAccount',\n\n /** The parent transaction type is not in the remote-flag allowlist. */\n DisabledTransactionType = 'disabledTransactionType',\n\n /** Reserving the HyperLiquid activation fee is not implemented. */\n HyperliquidActivationFee = 'hyperliquidActivationFee',\n}\n\n/**\n * Determine whether the server strategy can handle a set of quote requests.\n *\n * Gating has two independent layers:\n *\n * 1. A remote-flag allowlist of transaction types, so flows can be rolled out\n * and rolled back one at a time.\n * 2. Code-level capability guards for request shapes the server strategy does\n * not implement yet. These cannot be overridden by the flag; each one is\n * deleted as the corresponding capability lands.\n *\n * A transaction can carry several types across its nested transactions, so\n * both layers match against the transaction and its nested transactions.\n *\n * @param options - Options bag.\n * @param options.enabledTransactionTypes - Transaction types opted in via\n * remote feature flag.\n * @param options.requests - Quote requests for required tokens.\n * @param options.transaction - Metadata of the original target transaction.\n * @returns The first reason the requests are unsupported, or `undefined` if\n * every request is supported.\n */\nexport function getServerUnsupportedReason({\n enabledTransactionTypes,\n requests,\n transaction,\n}: {\n enabledTransactionTypes: TransactionType[];\n requests: QuoteRequest[];\n transaction?: TransactionMeta;\n}): ServerUnsupportedReason | undefined {\n if (!hasTransactionType(transaction, enabledTransactionTypes)) {\n return ServerUnsupportedReason.DisabledTransactionType;\n }\n\n for (const request of requests) {\n const reason = getRequestUnsupportedReason(request);\n\n if (reason) {\n return reason;\n }\n }\n\n return undefined;\n}\n\n/**\n * Determine whether a single quote request uses a capability the server\n * strategy has not implemented yet.\n *\n * @param request - Quote request for a required token.\n * @returns The reason the request is unsupported, or `undefined`.\n */\nfunction getRequestUnsupportedReason(\n request: QuoteRequest,\n): ServerUnsupportedReason | undefined {\n if (request.hyperliquidActivationFeeUsd !== undefined) {\n return ServerUnsupportedReason.HyperliquidActivationFee;\n }\n\n if (request.isDirectMusdMoneyAccount === true) {\n return ServerUnsupportedReason.DirectMusdMoneyAccount;\n }\n\n return undefined;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/transaction-pay-controller",
|
|
3
|
-
"version": "31.2.1-preview-
|
|
3
|
+
"version": "31.2.1-preview-1d88b8ba5",
|
|
4
4
|
"description": "Manages alternate payment strategies to provide required funds for transactions in MetaMask",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|