@avalabs/fusion-sdk 0.24.0 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +18 -1
- package/dist/errors.d.ts +18 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/transfer-service/avalanche-cct/_handlers/transfer-asset.cjs +1 -1
- package/dist/transfer-service/avalanche-cct/_handlers/transfer-asset.cjs.map +1 -1
- package/dist/transfer-service/avalanche-cct/_handlers/transfer-asset.js +1 -1
- package/dist/transfer-service/avalanche-cct/_handlers/transfer-asset.js.map +1 -1
- package/dist/transfer-service/markr/_schema.cjs +1 -1
- package/dist/transfer-service/markr/_schema.cjs.map +1 -1
- package/dist/transfer-service/markr/_schema.js +1 -1
- package/dist/transfer-service/markr/_schema.js.map +1 -1
- package/dist/transfer-service/markr/_utils.cjs +1 -1
- package/dist/transfer-service/markr/_utils.cjs.map +1 -1
- package/dist/transfer-service/markr/_utils.js +1 -1
- package/dist/transfer-service/markr/_utils.js.map +1 -1
- package/dist/transfer-service/markr/recurring/_api.cjs +1 -1
- package/dist/transfer-service/markr/recurring/_api.cjs.map +1 -1
- package/dist/transfer-service/markr/recurring/_api.js +1 -1
- package/dist/transfer-service/markr/recurring/_api.js.map +1 -1
- package/dist/transfer-service/markr/recurring/_chain-info.cjs +1 -1
- package/dist/transfer-service/markr/recurring/_chain-info.cjs.map +1 -1
- package/dist/transfer-service/markr/recurring/_chain-info.js +1 -1
- package/dist/transfer-service/markr/recurring/_chain-info.js.map +1 -1
- package/dist/transfer-service/markr/recurring/_eligibility.cjs +1 -1
- package/dist/transfer-service/markr/recurring/_eligibility.cjs.map +1 -1
- package/dist/transfer-service/markr/recurring/_eligibility.js +1 -1
- package/dist/transfer-service/markr/recurring/_eligibility.js.map +1 -1
- package/dist/transfer-service/markr/recurring/_namespace.cjs +1 -1
- package/dist/transfer-service/markr/recurring/_namespace.cjs.map +1 -1
- package/dist/transfer-service/markr/recurring/_namespace.js +1 -1
- package/dist/transfer-service/markr/recurring/_namespace.js.map +1 -1
- package/dist/transfer-service/markr/recurring/_schema.cjs +1 -1
- package/dist/transfer-service/markr/recurring/_schema.cjs.map +1 -1
- package/dist/transfer-service/markr/recurring/_schema.js +1 -1
- package/dist/transfer-service/markr/recurring/_schema.js.map +1 -1
- package/dist/transfer-service/markr/recurring/types.cjs +1 -1
- package/dist/transfer-service/markr/recurring/types.cjs.map +1 -1
- package/dist/transfer-service/markr/recurring/types.d.cts +32 -23
- package/dist/transfer-service/markr/recurring/types.d.ts +32 -23
- package/dist/transfer-service/markr/recurring/types.js +1 -1
- package/dist/transfer-service/markr/recurring/types.js.map +1 -1
- package/dist/types/service.d.cts +1 -1
- package/dist/types/service.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_namespace.cjs","names":["markrRecurringQuote","markrListRecurringOrders","TransferSignatureReason","markrPrepareCancellation","markrPreparePause","markrPrepareUnpause","checkRecurringEligibility","InvalidParamsError","ErrorReason","caip2ToEip155ChainId","getEvmClientForChain","caip2ToEip155HexChainId","markrGetSpenderAddress","SdkError","ErrorCode","buildErc20ApprovalRequest","markrRecurringSwap","maybe1559","signApprovalAndAssertConfirmed","getMarkrSwapWrapperAbi","estimateGasWithRevert","applyFeeUnitsBpsMargin","erc20Abi","TokenType","ServiceType"],"sources":["../../../../src/transfer-service/markr/recurring/_namespace.ts"],"sourcesContent":["import { erc20Abi } from 'viem';\nimport { ServiceType, TokenType, TransferSignatureReason } from '../../../constants';\nimport { ErrorCode, ErrorReason, InvalidParamsError, SdkError } from '../../../errors';\nimport type { Chain } from '../../../types/chain';\nimport type { Quote } from '../../../types/quote';\nimport type { EvmSigner, EvmTransactionRequest } from '../../../types/signer';\nimport type { TransferStepDetails } from '../../../types/transfer';\nimport { caip2ToEip155ChainId, caip2ToEip155HexChainId } from '../../../utils/caip';\nimport { applyFeeUnitsBpsMargin, getEvmClientForChain, maybe1559 } from '../../_utils';\nimport { buildErc20ApprovalRequest, signApprovalAndAssertConfirmed } from '../../_evm-approval';\nimport { estimateGasWithRevert } from '../../_evm-errors';\nimport type { WrappedSwapTransactionResponse } from '../_schema';\nimport { markrGetSpenderAddress, type ApiOptions } from '../_api';\nimport { getMarkrSwapWrapperAbi } from '../_utils';\nimport {\n markrListRecurringOrders,\n markrPrepareCancellation,\n markrPreparePause,\n markrPrepareUnpause,\n markrRecurringQuote,\n markrRecurringSwap,\n} from './_api';\nimport { checkRecurringEligibility } from './_eligibility';\nimport type {\n RecurringChainInfoMap,\n RecurringExecuteFirstFillParams,\n RecurringExecuteOrderActionParams,\n RecurringExecuteResult,\n RecurringNamespace,\n RecurringQuoteResponse,\n} from './types';\n\nexport interface CreateRecurringNamespaceOptions {\n apiOptions: ApiOptions;\n appId: string;\n evmSigner: EvmSigner;\n /**\n * The cached `/info/chains` recurring metadata. Captured by value at\n * namespace construction time — matches how `partnerFeeBps`,\n * `supportedChains`, and `supportedTokens` are also frozen at\n * `createMarkrService` init. If staleness ever becomes a real consumer\n * concern, the fix is a top-level `manager.refresh()` (not a per-namespace\n * lazy-read pattern).\n */\n recurringChainInfo: RecurringChainInfoMap;\n}\n\nexport function createRecurringNamespace({\n apiOptions,\n appId,\n evmSigner,\n recurringChainInfo,\n}: CreateRecurringNamespaceOptions): RecurringNamespace {\n return {\n quote: (props) => markrRecurringQuote(apiOptions, { ...props, appId }),\n\n executeFirstFill: (props) => executeFirstFillImpl({ ...props, apiOptions, appId, evmSigner }),\n\n listOrders: (props) => markrListRecurringOrders(apiOptions, props),\n\n executeCancellation: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.CancelRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPrepareCancellation,\n }),\n\n executePause: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.PauseRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPreparePause,\n }),\n\n executeUnpause: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.ResumeRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPrepareUnpause,\n }),\n\n checkEligibility: (props) => checkRecurringEligibility({ ...props, recurringChainInfo }),\n\n getRecurringChainInfo: () => recurringChainInfo,\n };\n}\n\n// ---------------------------------------------------------------------------\n// First-fill execution (allowance check + approve-if-needed + first-fill swap)\n// ---------------------------------------------------------------------------\n\ninterface ExecuteFirstFillImplParams extends RecurringExecuteFirstFillParams {\n apiOptions: ApiOptions;\n appId: string;\n evmSigner: EvmSigner;\n}\n\nasync function executeFirstFillImpl({\n apiOptions,\n appId,\n evmSigner,\n fallbackToDefaultOnBatchFailure,\n fromAddress,\n gasSettings,\n quote,\n signerContext,\n sourceChain,\n}: ExecuteFirstFillImplParams): Promise<RecurringExecuteResult> {\n // Mirror the one-shot guard at `TransferManager.estimateNativeFee` — fail at\n // the SDK boundary with `QUOTE_EXPIRED` instead of an opaque `HttpError`\n // from `/recurring/swap` for a slow-to-approve user.\n const now = Math.floor(Date.now() / 1_000);\n if (quote.expiredAt <= now) {\n const expiredSecondsAgo = now - quote.expiredAt;\n throw new InvalidParamsError(\n ErrorReason.QUOTE_EXPIRED,\n `Recurring quote expired ${expiredSecondsAgo} seconds ago.`,\n );\n }\n\n // Wiring-mistake guard: the passed `sourceChain.chainId` (CAIP-2) must agree\n // with the `chainId` (numeric) the quote was issued against. Otherwise the\n // allowance / gas reads hit the wrong chain.\n const sourceChainIdNumeric = caip2ToEip155ChainId(sourceChain.chainId);\n if (sourceChainIdNumeric !== quote.chainId) {\n throw new InvalidParamsError(\n 'sourceChain does not match quote.chainId',\n `sourceChain.chainId=${sourceChain.chainId} resolves to ${sourceChainIdNumeric}, but quote.chainId=${quote.chainId}.`,\n );\n }\n\n const sourceClient = getEvmClientForChain({ chain: sourceChain });\n const chainIdHex = caip2ToEip155HexChainId(sourceChain.chainId);\n\n const { address: spenderAddress } = await markrGetSpenderAddress(apiOptions, {\n chainId: quote.chainId,\n crossChainSwap: false,\n quoteId: quote.uuid,\n });\n\n if (!spenderAddress) {\n throw new SdkError(ErrorReason.CHAIN_NOT_SUPPORTED, ErrorCode.INVALID_PARAMS, {\n details: `Missing Markr spender address for source chain ${sourceChain.chainId}.`,\n });\n }\n\n const approvalRequest = await buildErc20ApprovalRequest({\n chainIdHex,\n client: sourceClient,\n gasSettings,\n owner: fromAddress,\n requiredAllowance: quote.totalAmountIn,\n spender: spenderAddress,\n token: quote.tokenIn,\n });\n\n const syntheticQuote = buildSyntheticQuoteForFirstFill({ fromAddress, quote, sourceChain });\n\n const swap = await markrRecurringSwap(apiOptions, { uuid: quote.uuid, appId });\n\n // One-click batch path: same-chain DCA, approval required, signer exposes\n // `signBatch`. Matches `_executeEvmTransfer`'s eligibility check (recurring\n // is always same-chain so the cross-chain check there collapses to true).\n if (approvalRequest !== undefined && typeof evmSigner.signBatch === 'function') {\n const batchStep: TransferStepDetails = {\n currentSignature: 1,\n currentSignatureReason: TransferSignatureReason.ScheduleRecurringSwap,\n quote: syntheticQuote,\n requiredSignatures: 1,\n signerContext,\n };\n\n // Gas is left undefined on the swap leg — the wallet handles batched gas\n // estimation since the approval hasn't executed yet.\n const swapRequest: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: swap.data,\n from: fromAddress,\n gas: undefined,\n to: swap.to,\n value: swap.value,\n ...maybe1559(gasSettings),\n };\n\n try {\n const txHashes = await evmSigner.signBatch(\n [approvalRequest, swapRequest],\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n batchStep,\n );\n const swapTxHash = txHashes.at(-1);\n if (!swapTxHash) {\n throw new SdkError('One-click batch signing returned no transaction hashes.', ErrorCode.SIGNING_FAILED);\n }\n return { txHash: swapTxHash };\n } catch (error) {\n if (!fallbackToDefaultOnBatchFailure) {\n throw error;\n }\n // Fall through to the two-signature path below.\n }\n }\n\n if (approvalRequest) {\n await signApprovalAndAssertConfirmed({\n client: sourceClient,\n evmSigner,\n request: approvalRequest,\n step: {\n currentSignature: 1,\n currentSignatureReason: TransferSignatureReason.AllowanceApproval,\n quote: syntheticQuote,\n requiredSignatures: 2,\n signerContext,\n },\n });\n }\n\n // Use the Markr same-chain swap wrapper ABI for best-effort revert decoding\n // — matches `_estimateGasFromSwapResponse` in `estimate-native-fee.ts`.\n // Recurring is always same-chain, so `crossChain: false`. Built-in\n // `Error(string)` / `Panic(uint256)` are decoded regardless of ABI.\n const markrAbi = await getMarkrSwapWrapperAbi(false);\n const swapGasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: fromAddress, to: swap.to, data: swap.data, value: swap.value },\n markrAbi,\n 'Failed to estimate gas for recurring first-fill swap transaction.',\n );\n\n const swapRequest: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: swap.data,\n from: fromAddress,\n gas: applyFeeUnitsBpsMargin(swapGasEstimate, gasSettings?.estimateGasMarginBps),\n to: swap.to,\n value: swap.value,\n ...maybe1559(gasSettings),\n };\n\n const swapStep: TransferStepDetails = {\n currentSignature: approvalRequest ? 2 : 1,\n currentSignatureReason: TransferSignatureReason.ScheduleRecurringSwap,\n quote: syntheticQuote,\n requiredSignatures: approvalRequest ? 2 : 1,\n signerContext,\n };\n\n const txHash = await evmSigner.sign(\n swapRequest,\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n swapStep,\n );\n\n return { txHash };\n}\n\n// ---------------------------------------------------------------------------\n// Order-action execution (cancel / pause / unpause — single-tx state change)\n// ---------------------------------------------------------------------------\n\ninterface ExecuteOrderActionImplParams extends RecurringExecuteOrderActionParams {\n signatureReason:\n | TransferSignatureReason.PauseRecurringSwap\n | TransferSignatureReason.ResumeRecurringSwap\n | TransferSignatureReason.CancelRecurringSwap;\n apiOptions: ApiOptions;\n evmSigner: EvmSigner;\n fetchCalldata: (\n apiOptions: ApiOptions,\n params: { orderId: `0x${string}`; address: `0x${string}`; chainId: number },\n ) => Promise<WrappedSwapTransactionResponse>;\n}\n\n// Short verbs for error-message interpolation — avoids the doubled-\"recurring\"\n// + kebab-case-in-prose readout you'd get from interpolating the raw enum\n// wire value (e.g. `recurring pause-recurring-swap transaction`).\nconst ORDER_ACTION_LABEL: Record<ExecuteOrderActionImplParams['signatureReason'], string> = {\n [TransferSignatureReason.PauseRecurringSwap]: 'pause',\n [TransferSignatureReason.ResumeRecurringSwap]: 'resume',\n [TransferSignatureReason.CancelRecurringSwap]: 'cancel',\n};\n\nasync function executeOrderActionImpl({\n signatureReason,\n address,\n apiOptions,\n evmSigner,\n fetchCalldata,\n gasSettings,\n orderId,\n signerContext,\n sourceChain,\n}: ExecuteOrderActionImplParams): Promise<RecurringExecuteResult> {\n const sourceClient = getEvmClientForChain({ chain: sourceChain });\n const chainIdNumeric = caip2ToEip155ChainId(sourceChain.chainId);\n const chainIdHex = caip2ToEip155HexChainId(sourceChain.chainId);\n\n const calldata = await fetchCalldata(apiOptions, { orderId, address, chainId: chainIdNumeric });\n\n const gasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: address, to: calldata.to, data: calldata.data, value: calldata.value },\n erc20Abi,\n `Failed to estimate gas for recurring ${ORDER_ACTION_LABEL[signatureReason]} transaction.`,\n );\n\n const request: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: calldata.data,\n from: address,\n gas: applyFeeUnitsBpsMargin(gasEstimate, gasSettings?.estimateGasMarginBps),\n to: calldata.to,\n value: calldata.value,\n ...maybe1559(gasSettings),\n };\n\n const step: TransferStepDetails = {\n currentSignature: 1,\n currentSignatureReason: signatureReason,\n quote: buildSyntheticQuoteForOrderAction({ address, signatureReason, orderId, sourceChain }),\n requiredSignatures: 1,\n signerContext,\n };\n\n const txHash = await evmSigner.sign(\n request,\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n step,\n );\n\n return { txHash };\n}\n\n// ---------------------------------------------------------------------------\n// Internal: synthetic Quote objects for `TransferStepDetails.quote`\n// ---------------------------------------------------------------------------\n\n/**\n * Builds a minimum-viable {@link Quote} for the signer step so consumer\n * `EvmSigner` impls can render meaningful wallet prompts for a recurring\n * action (which has no real `Quote` in the swap-quoter sense). The synthetic\n * value carries enough recurring context (uuid, chain, amounts, tokens) for\n * a wallet UI to label the popup; the `aggregator.id` (`'markr-recurring'`)\n * lets advanced signers detect the recurring path explicitly.\n *\n * Asset fields use placeholder `name`/`symbol`/`decimals` because the\n * recurring quote doesn't echo those — consumers needing rich asset display\n * should resolve token metadata against their own asset map keyed by\n * `quote.tokenIn`/`tokenOut`.\n */\nfunction buildSyntheticQuoteForFirstFill({\n fromAddress,\n quote,\n sourceChain,\n}: {\n fromAddress: `0x${string}`;\n quote: RecurringQuoteResponse;\n sourceChain: Chain;\n}): Quote {\n return {\n // Keep the stable `'markr-recurring'` marker (shipped in #240) — consumer\n // signers may detect the recurring path via `quote.aggregator.id`. The\n // typed `TransferStepDetails.currentSignatureReason` is now the preferred\n // discriminant for new integrations, but this id stays for back-compat.\n aggregator: { id: 'markr-recurring', name: 'Markr recurring' },\n amountIn: quote.amount,\n amountOut: quote.amountOut,\n assetIn: { type: TokenType.ERC20, address: quote.tokenIn, name: '', symbol: '', decimals: 0 },\n assetOut: { type: TokenType.ERC20, address: quote.tokenOut, name: '', symbol: '', decimals: 0 },\n expiresAt: quote.expiredAt,\n fees: [],\n fromAddress,\n id: quote.uuid,\n partnerFeeBps: null,\n serviceType: ServiceType.MARKR,\n slippageBps: quote.recommendedSlippage,\n // Pass the caller-provided `Chain` straight through — recurring is always\n // same-chain, so source === target. Avoids stripping `chainName` /\n // `networkToken` / `rpcUrl` that consumer signers may use for display.\n sourceChain,\n targetChain: sourceChain,\n toAddress: fromAddress,\n };\n}\n\nfunction buildSyntheticQuoteForOrderAction({\n signatureReason,\n address,\n orderId,\n sourceChain,\n}: {\n signatureReason:\n | TransferSignatureReason.PauseRecurringSwap\n | TransferSignatureReason.ResumeRecurringSwap\n | TransferSignatureReason.CancelRecurringSwap;\n address: `0x${string}`;\n orderId: `0x${string}`;\n sourceChain: Chain;\n}): Quote {\n const action = ORDER_ACTION_LABEL[signatureReason];\n return {\n // Same back-compat rationale as `buildSyntheticQuoteForFirstFill` — preserve\n // the original lowercase `markr-recurring-${action}` id shape (shipped in\n // #240) so consumers keying off `quote.aggregator.id` keep working.\n aggregator: {\n id: `markr-recurring-${action}`,\n name: `Markr recurring (${action})`,\n },\n amountIn: 0n,\n amountOut: 0n,\n assetIn: emptyNativeAsset(),\n assetOut: emptyNativeAsset(),\n expiresAt: 0,\n fees: [],\n fromAddress: address,\n id: orderId,\n partnerFeeBps: null,\n serviceType: ServiceType.MARKR,\n slippageBps: 0,\n // See `buildSyntheticQuoteForFirstFill` — pass the real `Chain` through.\n sourceChain,\n targetChain: sourceChain,\n toAddress: address,\n };\n}\n\nfunction emptyNativeAsset() {\n return { type: TokenType.NATIVE, name: '', symbol: '', decimals: 0 } as const;\n}\n"],"mappings":"2YA+CA,SAAgB,EAAyB,CACvC,aACA,QACA,YACA,sBACsD,CACtD,MAAO,CACL,MAAQ,GAAUA,EAAAA,oBAAoB,EAAY,CAAE,GAAG,EAAO,QAAO,CAAC,CAEtE,iBAAmB,GAAU,EAAqB,CAAE,GAAG,EAAO,aAAY,QAAO,YAAW,CAAC,CAE7F,WAAa,GAAUC,EAAAA,yBAAyB,EAAY,EAAM,CAElE,oBAAsB,GACpB,EAAuB,CACrB,GAAG,EACH,gBAAiBC,EAAAA,wBAAwB,oBACzC,aACA,YACA,cAAeC,EAAAA,yBAChB,CAAC,CAEJ,aAAe,GACb,EAAuB,CACrB,GAAG,EACH,gBAAiBD,EAAAA,wBAAwB,mBACzC,aACA,YACA,cAAeE,EAAAA,kBAChB,CAAC,CAEJ,eAAiB,GACf,EAAuB,CACrB,GAAG,EACH,gBAAiBF,EAAAA,wBAAwB,oBACzC,aACA,YACA,cAAeG,EAAAA,oB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E,KAAMM,EAAAA,UAAU,MAAO,QAAS,EAAM,QAAS,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG,CAC7F,SAAU,CAAE,KAAMA,EAAAA,UAAU,MAAO,QAAS,EAAM,SAAU,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG,CAC/F,UAAW,EAAM,UACjB,KAAM,EAAE,CACR,cACA,GAAI,EAAM,KACV,cAAe,KACf,YAAaC,EAAAA,YAAY,MACzB,YAAa,EAAM,oBAInB,cACA,YAAa,EACb,UAAW,EACZ,CAGH,SAAS,EAAkC,CACzC,kBACA,UACA,UACA,eASQ,CACR,IAAM,EAAS,EAAmB,GAClC,MAAO,CAIL,WAAY,CACV,GAAI,mBAAmB,IACvB,KAAM,oBAAoB,EAAO,GAClC,CACD,SAAU,GACV,UAAW,GACX,QAAS,GAAkB,CAC3B,SAAU,GAAkB,CAC5B,UAAW,EACX,KAAM,EAAE,CACR,YAAa,EACb,GAAI,EACJ,cAAe,KACf,YAAaA,EAAAA,YAAY,MACzB,YAAa,EAEb,cACA,YAAa,EACb,UAAW,EACZ,CAGH,SAAS,GAAmB,CAC1B,MAAO,CAAE,KAAMD,EAAAA,UAAU,OAAQ,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG"}
|
|
1
|
+
{"version":3,"file":"_namespace.cjs","names":["markrListRecurringOrders","TransferSignatureReason","markrPrepareCancellation","markrPreparePause","markrPrepareUnpause","checkRecurringEligibility","InvalidParamsError","ErrorReason","markrRecurringQuote","caip2ToEip155ChainId","getEvmClientForChain","caip2ToEip155HexChainId","ERC_ZERO_ADDRESS","markrGetSpenderAddress","SdkError","ErrorCode","markrRecurringSwap","buildErc20ApprovalRequest","maybe1559","estimateGasWithRevert","applyFeeUnitsBpsMargin","signApprovalAndAssertConfirmed","getMarkrSwapWrapperAbi","erc20Abi","TokenType","ServiceType"],"sources":["../../../../src/transfer-service/markr/recurring/_namespace.ts"],"sourcesContent":["import { erc20Abi, isAddressEqual } from 'viem';\nimport { ERC_ZERO_ADDRESS, ServiceType, TokenType, TransferSignatureReason } from '../../../constants';\nimport { ErrorCode, ErrorReason, InvalidParamsError, SdkError } from '../../../errors';\nimport type { Chain } from '../../../types/chain';\nimport type { Quote } from '../../../types/quote';\nimport type { EvmSigner, EvmTransactionRequest, Hex } from '../../../types/signer';\nimport type { TransferStepDetails } from '../../../types/transfer';\nimport { caip2ToEip155ChainId, caip2ToEip155HexChainId } from '../../../utils/caip';\nimport { applyFeeUnitsBpsMargin, getEvmClientForChain, maybe1559 } from '../../_utils';\nimport type { EvmSourceClient } from '../../_utils';\nimport { buildErc20ApprovalRequest, signApprovalAndAssertConfirmed } from '../../_evm-approval';\nimport { estimateGasWithRevert } from '../../_evm-errors';\nimport type { WrappedSwapTransactionResponse } from '../_schema';\nimport { markrGetSpenderAddress, type ApiOptions } from '../_api';\nimport { getMarkrSwapWrapperAbi } from '../_utils';\nimport {\n markrListRecurringOrders,\n markrPrepareCancellation,\n markrPreparePause,\n markrPrepareUnpause,\n markrRecurringQuote,\n markrRecurringSwap,\n} from './_api';\nimport { checkRecurringEligibility } from './_eligibility';\nimport type {\n RecurringChainInfoMap,\n RecurringExecuteFirstFillParams,\n RecurringExecuteOrderActionParams,\n RecurringExecuteResult,\n RecurringNamespace,\n RecurringNamespaceQuoteParams,\n RecurringQuoteResponse,\n} from './types';\n\nexport interface CreateRecurringNamespaceOptions {\n apiOptions: ApiOptions;\n appId: string;\n evmSigner: EvmSigner;\n /**\n * The cached `/info/chains` recurring metadata. Captured by value at\n * namespace construction time — matches how `partnerFeeBps`,\n * `supportedChains`, and `supportedTokens` are also frozen at\n * `createMarkrService` init. If staleness ever becomes a real consumer\n * concern, the fix is a top-level `manager.refresh()` (not a per-namespace\n * lazy-read pattern).\n */\n recurringChainInfo: RecurringChainInfoMap;\n}\n\nexport function createRecurringNamespace({\n apiOptions,\n appId,\n evmSigner,\n recurringChainInfo,\n}: CreateRecurringNamespaceOptions): RecurringNamespace {\n return {\n quote: (props) => quoteImpl({ ...props, apiOptions, appId, recurringChainInfo }),\n\n executeFirstFill: (props) => executeFirstFillImpl({ ...props, apiOptions, appId, evmSigner, recurringChainInfo }),\n\n listOrders: (props) => markrListRecurringOrders(apiOptions, props),\n\n executeCancellation: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.CancelRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPrepareCancellation,\n }),\n\n executePause: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.PauseRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPreparePause,\n }),\n\n executeUnpause: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.ResumeRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPrepareUnpause,\n }),\n\n checkEligibility: (props) => checkRecurringEligibility({ ...props, recurringChainInfo }),\n\n getRecurringChainInfo: () => recurringChainInfo,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Quote — native input (`tokenIn === 0x0…`) is passed through to Markr\n// verbatim (the recurring API accepts the zero address as `tokenIn`). The\n// chain's wrapped-native address is read off the cached chain info (sourced\n// from `/info/chains[].wrapped_token`); the SDK only fails fast at this\n// boundary when Markr hasn't published one for the chain — we'd be issuing\n// a quote we couldn't honor.\n// ---------------------------------------------------------------------------\n\ninterface QuoteImplParams extends RecurringNamespaceQuoteParams {\n apiOptions: ApiOptions;\n appId: string;\n recurringChainInfo: RecurringChainInfoMap;\n}\n\nasync function quoteImpl({\n apiOptions,\n appId,\n recurringChainInfo,\n ...quoteParams\n}: QuoteImplParams): Promise<RecurringQuoteResponse> {\n const isNativeInput = isAddressEqual(quoteParams.tokenIn, ERC_ZERO_ADDRESS);\n\n if (isNativeInput && !recurringChainInfo.get(quoteParams.chainId)?.wrappedNativeAddress) {\n throw new InvalidParamsError(\n ErrorReason.CHAIN_NOT_SUPPORTED,\n `No wrapped-native ERC-20 address known for EVM chainId ${quoteParams.chainId}. ` +\n 'Native-input recurring swaps require Markr to publish `wrapped_token` for the chain in `/info/chains`.',\n );\n }\n\n return markrRecurringQuote(apiOptions, { ...quoteParams, appId });\n}\n\n// ---------------------------------------------------------------------------\n// First-fill execution (allowance check + approve-if-needed + first-fill swap)\n// ---------------------------------------------------------------------------\n\ninterface ExecuteFirstFillImplParams extends RecurringExecuteFirstFillParams {\n apiOptions: ApiOptions;\n appId: string;\n evmSigner: EvmSigner;\n recurringChainInfo: RecurringChainInfoMap;\n}\n\nasync function executeFirstFillImpl({\n apiOptions,\n appId,\n evmSigner,\n fallbackToDefaultOnBatchFailure,\n fromAddress,\n gasSettings,\n quote,\n recurringChainInfo,\n signerContext,\n sourceChain,\n}: ExecuteFirstFillImplParams): Promise<RecurringExecuteResult> {\n // Mirror the one-shot guard at `TransferManager.estimateNativeFee` — fail at\n // the SDK boundary with `QUOTE_EXPIRED` instead of an opaque `HttpError`\n // from `/recurring/swap` for a slow-to-approve user.\n const now = Math.floor(Date.now() / 1_000);\n if (quote.expiredAt <= now) {\n const expiredSecondsAgo = now - quote.expiredAt;\n throw new InvalidParamsError(\n ErrorReason.QUOTE_EXPIRED,\n `Recurring quote expired ${expiredSecondsAgo} seconds ago.`,\n );\n }\n\n // Wiring-mistake guard: the passed `sourceChain.chainId` (CAIP-2) must agree\n // with the `chainId` (numeric) the quote was issued against. Otherwise the\n // allowance / gas reads hit the wrong chain.\n const sourceChainIdNumeric = caip2ToEip155ChainId(sourceChain.chainId);\n if (sourceChainIdNumeric !== quote.chainId) {\n throw new InvalidParamsError(\n 'sourceChain does not match quote.chainId',\n `sourceChain.chainId=${sourceChain.chainId} resolves to ${sourceChainIdNumeric}, but quote.chainId=${quote.chainId}.`,\n );\n }\n\n const sourceClient = getEvmClientForChain({ chain: sourceChain });\n const chainIdHex = caip2ToEip155HexChainId(sourceChain.chainId);\n\n const isNativeInput = isAddressEqual(quote.tokenIn, ERC_ZERO_ADDRESS);\n\n const { address: spenderAddress } = await markrGetSpenderAddress(apiOptions, {\n chainId: quote.chainId,\n crossChainSwap: false,\n quoteId: quote.uuid,\n });\n\n if (!spenderAddress) {\n throw new SdkError(ErrorReason.CHAIN_NOT_SUPPORTED, ErrorCode.INVALID_PARAMS, {\n details: `Missing Markr spender address for source chain ${sourceChain.chainId}.`,\n });\n }\n\n // Fetch the ordered transaction array from Markr's `/recurring/swap`:\n // - ERC-20 `tokenIn`: `[createOrder]` (1 element).\n // - Native `tokenIn` (`0x0…`): `[wrap, createOrder]` (2 elements).\n // The wrap's `to` is the wrapped-native ERC-20 we'll then approve against\n // (Markr does not return an approval entry — the SDK inserts that step).\n const recurringSwapTxs = await markrRecurringSwap(apiOptions, { uuid: quote.uuid, appId });\n\n const wrapTx = recurringSwapTxs.find((tx) => tx.type === 'wrap');\n const createOrderTx = recurringSwapTxs.find((tx) => tx.type === 'createOrder');\n\n if (!createOrderTx) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `Missing createOrder step (quote uuid: ${quote.uuid}).`,\n });\n }\n\n // Cross-check: native input must come back with a wrap leg, and an ERC-20\n // input must not. If Markr disagrees with the cached quote's `tokenIn`,\n // bail rather than silently signing a mismatched flow (e.g. broadcasting\n // a wrap when the user thought they were spending ERC-20, or skipping a\n // wrap when the user expected to fund the schedule with native).\n if (isNativeInput && !wrapTx) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `Native-input quote returned no wrap step (quote uuid: ${quote.uuid}).`,\n });\n }\n if (!isNativeInput && wrapTx) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `ERC-20 input quote returned a wrap step (quote uuid: ${quote.uuid}, tokenIn: ${quote.tokenIn}).`,\n });\n }\n\n // Defense-in-depth on the wrap leg before we hand it to the wallet:\n // - `wrap.value` must equal `quote.totalAmountIn` — that's what funds the\n // full schedule; a smaller value would under-fund subsequent fills, a\n // larger one would silently overcharge the user.\n // - `wrap.to` must match the chain's published wrapped-native (from\n // `/info/chains[].wrapped_token`) when one is known. Cross-check guards\n // against a misrouted approval — we're about to grant `totalAmountIn`\n // allowance to whatever `wrap.to` points at. When the chain entry has\n // no published wrapped-native, defer to Markr (`wrap.to` is server-\n // authoritative); the quote boundary already failed-closed in that\n // case anyway, so this is purely belt-and-suspenders.\n if (wrapTx) {\n if (wrapTx.value !== quote.totalAmountIn) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `Wrap step value ${wrapTx.value} does not match quote.totalAmountIn ${quote.totalAmountIn} (quote uuid: ${quote.uuid}).`,\n });\n }\n const expectedWrappedNative = recurringChainInfo.get(quote.chainId)?.wrappedNativeAddress;\n if (expectedWrappedNative && !isAddressEqual(wrapTx.to, expectedWrappedNative)) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `Wrap step target ${wrapTx.to} does not match the published wrapped-native ${expectedWrappedNative} for chainId ${quote.chainId} (quote uuid: ${quote.uuid}).`,\n });\n }\n }\n\n // Approval target: for native input, the wrapped-native ERC-20 returned\n // by Markr in `wrap.to` (cross-checked above). For ERC-20 input, the\n // quote's `tokenIn`. Either way the spender is the RecurringSwaps router.\n const approvalTokenAddress = wrapTx?.to ?? quote.tokenIn;\n\n const approvalRequest = await buildErc20ApprovalRequest({\n chainIdHex,\n client: sourceClient,\n gasSettings,\n owner: fromAddress,\n requiredAllowance: quote.totalAmountIn,\n spender: spenderAddress,\n token: approvalTokenAddress,\n });\n\n // Wrap leg comes straight from Markr — `wrap.to` is the chain wrapped-native\n // contract, `data` is `deposit()`, `value` is `totalAmountIn`. Gas is left\n // undefined: when batched the wallet handles atomic estimation; sequentially\n // the wrap is the first call so the wallet's own estimation fires the prompt.\n const wrapRequest: EvmTransactionRequest | undefined = wrapTx\n ? {\n chainId: chainIdHex,\n data: wrapTx.data,\n from: fromAddress,\n gas: undefined,\n to: wrapTx.to,\n value: wrapTx.value,\n ...maybe1559(gasSettings),\n }\n : undefined;\n\n const syntheticQuote = buildSyntheticQuoteForFirstFill({ fromAddress, quote, sourceChain });\n\n // One-click batch path: same-chain DCA, signer exposes `signBatch`, and at\n // least one leg precedes the swap (otherwise there's nothing to batch — we\n // sign the swap solo). The batch shape adapts to the recurring setup:\n // - native + needs approval: [wrap, approve, swap] (3 elements)\n // - native + allowance covers: [wrap, swap] (2 elements)\n // - ERC-20 + needs approval: [approve, swap] (2 elements)\n // - ERC-20 + allowance covers: swap solo (no batch)\n const batchPreSwap: EvmTransactionRequest[] = [];\n if (wrapRequest) batchPreSwap.push(wrapRequest);\n if (approvalRequest) batchPreSwap.push(approvalRequest);\n\n if (batchPreSwap.length > 0 && typeof evmSigner.signBatch === 'function') {\n const batchStep: TransferStepDetails = {\n currentSignature: 1,\n currentSignatureReason: TransferSignatureReason.ScheduleRecurringSwap,\n quote: syntheticQuote,\n requiredSignatures: 1,\n signerContext,\n };\n\n // Gas is left undefined on the swap leg — the wallet handles batched gas\n // estimation since the preceding leg(s) haven't executed yet.\n const swapRequest: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: createOrderTx.data,\n from: fromAddress,\n gas: undefined,\n to: createOrderTx.to,\n value: createOrderTx.value,\n ...maybe1559(gasSettings),\n };\n\n try {\n const txHashes = await evmSigner.signBatch(\n [...batchPreSwap, swapRequest],\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n batchStep,\n );\n const swapTxHash = txHashes.at(-1);\n if (!swapTxHash) {\n throw new SdkError('One-click batch signing returned no transaction hashes.', ErrorCode.SIGNING_FAILED);\n }\n return { txHash: swapTxHash };\n } catch (error) {\n if (!fallbackToDefaultOnBatchFailure) {\n throw error;\n }\n // Fall through to the sequential path below.\n }\n }\n\n // Sequential path — sign each preceding leg, await its receipt, then sign\n // the swap. Signature counters reflect the actual prompt count the user\n // will see (1 + wrap? + approval?).\n const requiredSignatures = 1 + batchPreSwap.length;\n let signatureCursor = 0;\n\n if (wrapRequest && wrapTx) {\n // Estimate gas for the wrap leg on the sequential path. On the batch\n // path we leave gas undefined and let the wallet do atomic estimation;\n // sequentially the wrap is a real first-tx prompt so it gets the same\n // treatment as the approval and swap legs (estimate + bps margin) for\n // wallets that don't auto-estimate. Read `to`/`data` off `wrapTx` (the\n // narrow `RecurringSwapTransaction` shape) rather than the wider\n // `EvmTransactionRequest` so the args are non-nullable.\n const wrapGasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: fromAddress, to: wrapTx.to, data: wrapTx.data, value: wrapTx.value },\n // No router ABI to decode against — wrap is a plain\n // `WAVAX.deposit{value}()`; built-in `Error(string)` / `Panic(uint256)`\n // are still decoded regardless of the ABI argument.\n [],\n 'Failed to estimate gas for recurring first-fill wrap transaction.',\n );\n const wrapRequestWithGas: EvmTransactionRequest = {\n ...wrapRequest,\n gas: applyFeeUnitsBpsMargin(wrapGasEstimate, gasSettings?.estimateGasMarginBps),\n };\n\n signatureCursor += 1;\n await signWrapAndAssertConfirmed({\n client: sourceClient,\n evmSigner,\n request: wrapRequestWithGas,\n step: {\n currentSignature: signatureCursor,\n currentSignatureReason: TransferSignatureReason.WrapToken,\n quote: syntheticQuote,\n requiredSignatures,\n signerContext,\n },\n });\n }\n\n if (approvalRequest) {\n signatureCursor += 1;\n await signApprovalAndAssertConfirmed({\n client: sourceClient,\n evmSigner,\n request: approvalRequest,\n step: {\n currentSignature: signatureCursor,\n currentSignatureReason: TransferSignatureReason.AllowanceApproval,\n quote: syntheticQuote,\n requiredSignatures,\n signerContext,\n },\n });\n }\n\n // Use the Markr same-chain swap wrapper ABI for best-effort revert decoding\n // — matches `_estimateGasFromSwapResponse` in `estimate-native-fee.ts`.\n // Recurring is always same-chain, so `crossChain: false`. Built-in\n // `Error(string)` / `Panic(uint256)` are decoded regardless of ABI.\n const markrAbi = await getMarkrSwapWrapperAbi(false);\n const swapGasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: fromAddress, to: createOrderTx.to, data: createOrderTx.data, value: createOrderTx.value },\n markrAbi,\n 'Failed to estimate gas for recurring first-fill swap transaction.',\n );\n\n const swapRequest: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: createOrderTx.data,\n from: fromAddress,\n gas: applyFeeUnitsBpsMargin(swapGasEstimate, gasSettings?.estimateGasMarginBps),\n to: createOrderTx.to,\n value: createOrderTx.value,\n ...maybe1559(gasSettings),\n };\n\n signatureCursor += 1;\n const swapStep: TransferStepDetails = {\n currentSignature: signatureCursor,\n currentSignatureReason: TransferSignatureReason.ScheduleRecurringSwap,\n quote: syntheticQuote,\n requiredSignatures,\n signerContext,\n };\n\n const txHash = await evmSigner.sign(\n swapRequest,\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n swapStep,\n );\n\n return { txHash };\n}\n\n/**\n * Signs a `WAVAX.deposit{value}()` wrap request, dispatches it, and waits for\n * the receipt. Mirrors {@link signApprovalAndAssertConfirmed} so the\n * sequential native path fails loudly if the wrap reverts on-chain (without\n * which the downstream approve would silently fail for \"insufficient WAVAX\").\n */\nasync function signWrapAndAssertConfirmed({\n client,\n evmSigner,\n request,\n step,\n}: {\n client: EvmSourceClient;\n evmSigner: EvmSigner;\n request: EvmTransactionRequest;\n step: TransferStepDetails;\n}): Promise<Hex> {\n const wrapTxHash = await evmSigner.sign(\n request,\n (signedTxHash) => client.sendRawTransaction({ serializedTransaction: signedTxHash }),\n step,\n );\n\n const receipt = await client.waitForTransactionReceipt({ hash: wrapTxHash });\n\n if (receipt.status === 'reverted') {\n throw new SdkError(ErrorReason.NATIVE_WRAP_REVERTED, ErrorCode.TRANSACTION_REVERTED, {\n details: `Wrap tx reverted on-chain (tx hash: ${wrapTxHash}).`,\n });\n }\n\n return wrapTxHash;\n}\n\n// ---------------------------------------------------------------------------\n// Order-action execution (cancel / pause / unpause — single-tx state change)\n// ---------------------------------------------------------------------------\n\ninterface ExecuteOrderActionImplParams extends RecurringExecuteOrderActionParams {\n signatureReason:\n | TransferSignatureReason.PauseRecurringSwap\n | TransferSignatureReason.ResumeRecurringSwap\n | TransferSignatureReason.CancelRecurringSwap;\n apiOptions: ApiOptions;\n evmSigner: EvmSigner;\n fetchCalldata: (\n apiOptions: ApiOptions,\n params: { orderId: `0x${string}`; address: `0x${string}`; chainId: number },\n ) => Promise<WrappedSwapTransactionResponse>;\n}\n\n// Short verbs for error-message interpolation — avoids the doubled-\"recurring\"\n// + kebab-case-in-prose readout you'd get from interpolating the raw enum\n// wire value (e.g. `recurring pause-recurring-swap transaction`).\nconst ORDER_ACTION_LABEL: Record<ExecuteOrderActionImplParams['signatureReason'], string> = {\n [TransferSignatureReason.PauseRecurringSwap]: 'pause',\n [TransferSignatureReason.ResumeRecurringSwap]: 'resume',\n [TransferSignatureReason.CancelRecurringSwap]: 'cancel',\n};\n\nasync function executeOrderActionImpl({\n signatureReason,\n address,\n apiOptions,\n evmSigner,\n fetchCalldata,\n gasSettings,\n orderId,\n signerContext,\n sourceChain,\n}: ExecuteOrderActionImplParams): Promise<RecurringExecuteResult> {\n const sourceClient = getEvmClientForChain({ chain: sourceChain });\n const chainIdNumeric = caip2ToEip155ChainId(sourceChain.chainId);\n const chainIdHex = caip2ToEip155HexChainId(sourceChain.chainId);\n\n const calldata = await fetchCalldata(apiOptions, { orderId, address, chainId: chainIdNumeric });\n\n const gasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: address, to: calldata.to, data: calldata.data, value: calldata.value },\n erc20Abi,\n `Failed to estimate gas for recurring ${ORDER_ACTION_LABEL[signatureReason]} transaction.`,\n );\n\n const request: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: calldata.data,\n from: address,\n gas: applyFeeUnitsBpsMargin(gasEstimate, gasSettings?.estimateGasMarginBps),\n to: calldata.to,\n value: calldata.value,\n ...maybe1559(gasSettings),\n };\n\n const step: TransferStepDetails = {\n currentSignature: 1,\n currentSignatureReason: signatureReason,\n quote: buildSyntheticQuoteForOrderAction({ address, signatureReason, orderId, sourceChain }),\n requiredSignatures: 1,\n signerContext,\n };\n\n const txHash = await evmSigner.sign(\n request,\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n step,\n );\n\n return { txHash };\n}\n\n// ---------------------------------------------------------------------------\n// Internal: synthetic Quote objects for `TransferStepDetails.quote`\n// ---------------------------------------------------------------------------\n\n/**\n * Builds a minimum-viable {@link Quote} for the signer step so consumer\n * `EvmSigner` impls can render meaningful wallet prompts for a recurring\n * action (which has no real `Quote` in the swap-quoter sense). The synthetic\n * value carries enough recurring context (uuid, chain, amounts, tokens) for\n * a wallet UI to label the popup; the `aggregator.id` (`'markr-recurring'`)\n * lets advanced signers detect the recurring path explicitly.\n *\n * Asset fields use placeholder `name`/`symbol`/`decimals` because the\n * recurring quote doesn't echo those — consumers needing rich asset display\n * should resolve token metadata against their own asset map keyed by\n * `quote.tokenIn`/`tokenOut`.\n */\nfunction buildSyntheticQuoteForFirstFill({\n fromAddress,\n quote,\n sourceChain,\n}: {\n fromAddress: `0x${string}`;\n quote: RecurringQuoteResponse;\n sourceChain: Chain;\n}): Quote {\n return {\n // Keep the stable `'markr-recurring'` marker (shipped in #240) — consumer\n // signers may detect the recurring path via `quote.aggregator.id`. The\n // typed `TransferStepDetails.currentSignatureReason` is now the preferred\n // discriminant for new integrations, but this id stays for back-compat.\n aggregator: { id: 'markr-recurring', name: 'Markr recurring' },\n amountIn: quote.amount,\n amountOut: quote.amountOut,\n assetIn: { type: TokenType.ERC20, address: quote.tokenIn, name: '', symbol: '', decimals: 0 },\n assetOut: { type: TokenType.ERC20, address: quote.tokenOut, name: '', symbol: '', decimals: 0 },\n expiresAt: quote.expiredAt,\n fees: [],\n fromAddress,\n id: quote.uuid,\n partnerFeeBps: null,\n serviceType: ServiceType.MARKR,\n slippageBps: quote.recommendedSlippage,\n // Pass the caller-provided `Chain` straight through — recurring is always\n // same-chain, so source === target. Avoids stripping `chainName` /\n // `networkToken` / `rpcUrl` that consumer signers may use for display.\n sourceChain,\n targetChain: sourceChain,\n toAddress: fromAddress,\n };\n}\n\nfunction buildSyntheticQuoteForOrderAction({\n signatureReason,\n address,\n orderId,\n sourceChain,\n}: {\n signatureReason:\n | TransferSignatureReason.PauseRecurringSwap\n | TransferSignatureReason.ResumeRecurringSwap\n | TransferSignatureReason.CancelRecurringSwap;\n address: `0x${string}`;\n orderId: `0x${string}`;\n sourceChain: Chain;\n}): Quote {\n const action = ORDER_ACTION_LABEL[signatureReason];\n return {\n // Same back-compat rationale as `buildSyntheticQuoteForFirstFill` — preserve\n // the original lowercase `markr-recurring-${action}` id shape (shipped in\n // #240) so consumers keying off `quote.aggregator.id` keep working.\n aggregator: {\n id: `markr-recurring-${action}`,\n name: `Markr recurring (${action})`,\n },\n amountIn: 0n,\n amountOut: 0n,\n assetIn: emptyNativeAsset(),\n assetOut: emptyNativeAsset(),\n expiresAt: 0,\n fees: [],\n fromAddress: address,\n id: orderId,\n partnerFeeBps: null,\n serviceType: ServiceType.MARKR,\n slippageBps: 0,\n // See `buildSyntheticQuoteForFirstFill` — pass the real `Chain` through.\n sourceChain,\n targetChain: sourceChain,\n toAddress: address,\n };\n}\n\nfunction emptyNativeAsset() {\n return { type: TokenType.NATIVE, name: '', symbol: '', decimals: 0 } as const;\n}\n"],"mappings":"2YAiDA,SAAgB,EAAyB,CACvC,aACA,QACA,YACA,sBACsD,CACtD,MAAO,CACL,MAAQ,GAAU,EAAU,CAAE,GAAG,EAAO,aAAY,QAAO,qBAAoB,CAAC,CAEhF,iBAAmB,GAAU,EAAqB,CAAE,GAAG,EAAO,aAAY,QAAO,YAAW,qBAAoB,CAAC,CAEjH,WAAa,GAAUA,EAAAA,yBAAyB,EAAY,EAAM,CAElE,oBAAsB,GACpB,EAAuB,CACrB,GAAG,EACH,gBAAiBC,EAAAA,wBAAwB,oBACzC,aAC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CAC5F,mBAAoB,EACpB,gBACD,CAQD,MAAO,CAAE,OANM,MAAM,EAAU,KAC7B,EACC,GAAiB,EAAa,mBAAmB,CAAE,sBAAuB,EAAc,CAAC,CAC1F,EACD,CAEgB,CAoBnB,SAAS,EAAgC,CACvC,cACA,QACA,eAKQ,CACR,MAAO,CAKL,WAAY,CAAE,GAAI,kBAAmB,KAAM,kBAAmB,CAC9D,SAAU,EAAM,OAChB,UAAW,EAAM,UACjB,QAAS,CAAE,KAAMM,EAAAA,UAAU,MAAO,QAAS,EAAM,QAAS,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG,CAC7F,SAAU,CAAE,KAAMA,EAAAA,UAAU,MAAO,QAAS,EAAM,SAAU,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG,CAC/F,UAAW,EAAM,UACjB,KAAM,EAAE,CACR,cACA,GAAI,EAAM,KACV,cAAe,KACf,YAAaC,EAAAA,YAAY,MACzB,YAAa,EAAM,oBAInB,cACA,YAAa,EACb,UAAW,EACZ,CAGH,SAAS,EAAkC,CACzC,kBACA,UACA,UACA,eASQ,CACR,IAAM,EAAS,EAAmB,GAClC,MAAO,CAIL,WAAY,CACV,GAAI,mBAAmB,IACvB,KAAM,oBAAoB,EAAO,GAClC,CACD,SAAU,GACV,UAAW,GACX,QAAS,GAAkB,CAC3B,SAAU,GAAkB,CAC5B,UAAW,EACX,KAAM,EAAE,CACR,YAAa,EACb,GAAI,EACJ,cAAe,KACf,YAAaA,EAAAA,YAAY,MACzB,YAAa,EAEb,cACA,YAAa,EACb,UAAW,EACZ,CAGH,SAAS,GAAmB,CAC1B,MAAO,CAAE,KAAMD,EAAAA,UAAU,OAAQ,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{ERC_ZERO_ADDRESS as e,ServiceType as t,TokenType as n,TransferSignatureReason as r}from"../../../constants.js";import{ErrorCode as i,ErrorReason as a,InvalidParamsError as o,SdkError as s}from"../../../errors.js";import{caip2ToEip155ChainId as c,caip2ToEip155HexChainId as l}from"../../../utils/caip.js";import{applyFeeUnitsBpsMargin as u,getEvmClientForChain as d,maybe1559 as f}from"../../_utils.js";import{estimateGasWithRevert as p}from"../../_evm-errors.js";import{buildErc20ApprovalRequest as m,signApprovalAndAssertConfirmed as h}from"../../_evm-approval.js";import{markrGetSpenderAddress as g}from"../_api.js";import{getMarkrSwapWrapperAbi as _}from"../_utils.js";import{markrListRecurringOrders as v,markrPrepareCancellation as y,markrPreparePause as b,markrPrepareUnpause as x,markrRecurringQuote as S,markrRecurringSwap as C}from"./_api.js";import{checkRecurringEligibility as w}from"./_eligibility.js";import{erc20Abi as T,isAddressEqual as E}from"viem";function D({apiOptions:e,appId:t,evmSigner:n,recurringChainInfo:i}){return{quote:n=>O({...n,apiOptions:e,appId:t,recurringChainInfo:i}),executeFirstFill:r=>k({...r,apiOptions:e,appId:t,evmSigner:n,recurringChainInfo:i}),listOrders:t=>v(e,t),executeCancellation:t=>M({...t,signatureReason:r.CancelRecurringSwap,apiOptions:e,evmSigner:n,fetchCalldata:y}),executePause:t=>M({...t,signatureReason:r.PauseRecurringSwap,apiOptions:e,evmSigner:n,fetchCalldata:b}),executeUnpause:t=>M({...t,signatureReason:r.ResumeRecurringSwap,apiOptions:e,evmSigner:n,fetchCalldata:x}),checkEligibility:e=>w({...e,recurringChainInfo:i}),getRecurringChainInfo:()=>i}}async function O({apiOptions:e,appId:t,recurringChainInfo:n,...r}){if(E(r.tokenIn,`0x0000000000000000000000000000000000000000`)&&!n.get(r.chainId)?.wrappedNativeAddress)throw new o(a.CHAIN_NOT_SUPPORTED,`No wrapped-native ERC-20 address known for EVM chainId ${r.chainId}. Native-input recurring swaps require Markr to publish \`wrapped_token\` for the chain in \`/info/chains\`.`);return S(e,{...r,appId:t})}async function k({apiOptions:t,appId:n,evmSigner:v,fallbackToDefaultOnBatchFailure:y,fromAddress:b,gasSettings:x,quote:S,recurringChainInfo:w,signerContext:T,sourceChain:D}){let O=Math.floor(Date.now()/1e3);if(S.expiredAt<=O){let e=O-S.expiredAt;throw new o(a.QUOTE_EXPIRED,`Recurring quote expired ${e} seconds ago.`)}let k=c(D.chainId);if(k!==S.chainId)throw new o(`sourceChain does not match quote.chainId`,`sourceChain.chainId=${D.chainId} resolves to ${k}, but quote.chainId=${S.chainId}.`);let j=d({chain:D}),M=l(D.chainId),P=E(S.tokenIn,e),{address:F}=await g(t,{chainId:S.chainId,crossChainSwap:!1,quoteId:S.uuid});if(!F)throw new s(a.CHAIN_NOT_SUPPORTED,i.INVALID_PARAMS,{details:`Missing Markr spender address for source chain ${D.chainId}.`});let I=await C(t,{uuid:S.uuid,appId:n}),L=I.find(e=>e.type===`wrap`),R=I.find(e=>e.type===`createOrder`);if(!R)throw new s(a.RECURRING_SWAP_RESPONSE_INCONSISTENT,i.INVALID_PARAMS,{details:`Missing createOrder step (quote uuid: ${S.uuid}).`});if(P&&!L)throw new s(a.RECURRING_SWAP_RESPONSE_INCONSISTENT,i.INVALID_PARAMS,{details:`Native-input quote returned no wrap step (quote uuid: ${S.uuid}).`});if(!P&&L)throw new s(a.RECURRING_SWAP_RESPONSE_INCONSISTENT,i.INVALID_PARAMS,{details:`ERC-20 input quote returned a wrap step (quote uuid: ${S.uuid}, tokenIn: ${S.tokenIn}).`});if(L){if(L.value!==S.totalAmountIn)throw new s(a.RECURRING_SWAP_RESPONSE_INCONSISTENT,i.INVALID_PARAMS,{details:`Wrap step value ${L.value} does not match quote.totalAmountIn ${S.totalAmountIn} (quote uuid: ${S.uuid}).`});let e=w.get(S.chainId)?.wrappedNativeAddress;if(e&&!E(L.to,e))throw new s(a.RECURRING_SWAP_RESPONSE_INCONSISTENT,i.INVALID_PARAMS,{details:`Wrap step target ${L.to} does not match the published wrapped-native ${e} for chainId ${S.chainId} (quote uuid: ${S.uuid}).`})}let z=L?.to??S.tokenIn,B=await m({chainIdHex:M,client:j,gasSettings:x,owner:b,requiredAllowance:S.totalAmountIn,spender:F,token:z}),V=L?{chainId:M,data:L.data,from:b,gas:void 0,to:L.to,value:L.value,...f(x)}:void 0,H=N({fromAddress:b,quote:S,sourceChain:D}),U=[];if(V&&U.push(V),B&&U.push(B),U.length>0&&typeof v.signBatch==`function`){let e={currentSignature:1,currentSignatureReason:r.ScheduleRecurringSwap,quote:H,requiredSignatures:1,signerContext:T},t={chainId:M,data:R.data,from:b,gas:void 0,to:R.to,value:R.value,...f(x)};try{let n=(await v.signBatch([...U,t],e=>j.sendRawTransaction({serializedTransaction:e}),e)).at(-1);if(!n)throw new s(`One-click batch signing returned no transaction hashes.`,i.SIGNING_FAILED);return{txHash:n}}catch(e){if(!y)throw e}}let W=1+U.length,G=0;if(V&&L){let e=await p(j,{account:b,to:L.to,data:L.data,value:L.value},[],`Failed to estimate gas for recurring first-fill wrap transaction.`),t={...V,gas:u(e,x?.estimateGasMarginBps)};G+=1,await A({client:j,evmSigner:v,request:t,step:{currentSignature:G,currentSignatureReason:r.WrapToken,quote:H,requiredSignatures:W,signerContext:T}})}B&&(G+=1,await h({client:j,evmSigner:v,request:B,step:{currentSignature:G,currentSignatureReason:r.AllowanceApproval,quote:H,requiredSignatures:W,signerContext:T}}));let K=await _(!1),q=await p(j,{account:b,to:R.to,data:R.data,value:R.value},K,`Failed to estimate gas for recurring first-fill swap transaction.`),J={chainId:M,data:R.data,from:b,gas:u(q,x?.estimateGasMarginBps),to:R.to,value:R.value,...f(x)};G+=1;let Y={currentSignature:G,currentSignatureReason:r.ScheduleRecurringSwap,quote:H,requiredSignatures:W,signerContext:T};return{txHash:await v.sign(J,e=>j.sendRawTransaction({serializedTransaction:e}),Y)}}async function A({client:e,evmSigner:t,request:n,step:r}){let o=await t.sign(n,t=>e.sendRawTransaction({serializedTransaction:t}),r);if((await e.waitForTransactionReceipt({hash:o})).status===`reverted`)throw new s(a.NATIVE_WRAP_REVERTED,i.TRANSACTION_REVERTED,{details:`Wrap tx reverted on-chain (tx hash: ${o}).`});return o}const j={[r.PauseRecurringSwap]:`pause`,[r.ResumeRecurringSwap]:`resume`,[r.CancelRecurringSwap]:`cancel`};async function M({signatureReason:e,address:t,apiOptions:n,evmSigner:r,fetchCalldata:i,gasSettings:a,orderId:o,signerContext:s,sourceChain:m}){let h=d({chain:m}),g=c(m.chainId),_=l(m.chainId),v=await i(n,{orderId:o,address:t,chainId:g}),y=await p(h,{account:t,to:v.to,data:v.data,value:v.value},T,`Failed to estimate gas for recurring ${j[e]} transaction.`),b={chainId:_,data:v.data,from:t,gas:u(y,a?.estimateGasMarginBps),to:v.to,value:v.value,...f(a)},x={currentSignature:1,currentSignatureReason:e,quote:P({address:t,signatureReason:e,orderId:o,sourceChain:m}),requiredSignatures:1,signerContext:s};return{txHash:await r.sign(b,e=>h.sendRawTransaction({serializedTransaction:e}),x)}}function N({fromAddress:e,quote:r,sourceChain:i}){return{aggregator:{id:`markr-recurring`,name:`Markr recurring`},amountIn:r.amount,amountOut:r.amountOut,assetIn:{type:n.ERC20,address:r.tokenIn,name:``,symbol:``,decimals:0},assetOut:{type:n.ERC20,address:r.tokenOut,name:``,symbol:``,decimals:0},expiresAt:r.expiredAt,fees:[],fromAddress:e,id:r.uuid,partnerFeeBps:null,serviceType:t.MARKR,slippageBps:r.recommendedSlippage,sourceChain:i,targetChain:i,toAddress:e}}function P({signatureReason:e,address:n,orderId:r,sourceChain:i}){let a=j[e];return{aggregator:{id:`markr-recurring-${a}`,name:`Markr recurring (${a})`},amountIn:0n,amountOut:0n,assetIn:F(),assetOut:F(),expiresAt:0,fees:[],fromAddress:n,id:r,partnerFeeBps:null,serviceType:t.MARKR,slippageBps:0,sourceChain:i,targetChain:i,toAddress:n}}function F(){return{type:n.NATIVE,name:``,symbol:``,decimals:0}}export{D as createRecurringNamespace};
|
|
2
2
|
//# sourceMappingURL=_namespace.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_namespace.js","names":[],"sources":["../../../../src/transfer-service/markr/recurring/_namespace.ts"],"sourcesContent":["import { erc20Abi } from 'viem';\nimport { ServiceType, TokenType, TransferSignatureReason } from '../../../constants';\nimport { ErrorCode, ErrorReason, InvalidParamsError, SdkError } from '../../../errors';\nimport type { Chain } from '../../../types/chain';\nimport type { Quote } from '../../../types/quote';\nimport type { EvmSigner, EvmTransactionRequest } from '../../../types/signer';\nimport type { TransferStepDetails } from '../../../types/transfer';\nimport { caip2ToEip155ChainId, caip2ToEip155HexChainId } from '../../../utils/caip';\nimport { applyFeeUnitsBpsMargin, getEvmClientForChain, maybe1559 } from '../../_utils';\nimport { buildErc20ApprovalRequest, signApprovalAndAssertConfirmed } from '../../_evm-approval';\nimport { estimateGasWithRevert } from '../../_evm-errors';\nimport type { WrappedSwapTransactionResponse } from '../_schema';\nimport { markrGetSpenderAddress, type ApiOptions } from '../_api';\nimport { getMarkrSwapWrapperAbi } from '../_utils';\nimport {\n markrListRecurringOrders,\n markrPrepareCancellation,\n markrPreparePause,\n markrPrepareUnpause,\n markrRecurringQuote,\n markrRecurringSwap,\n} from './_api';\nimport { checkRecurringEligibility } from './_eligibility';\nimport type {\n RecurringChainInfoMap,\n RecurringExecuteFirstFillParams,\n RecurringExecuteOrderActionParams,\n RecurringExecuteResult,\n RecurringNamespace,\n RecurringQuoteResponse,\n} from './types';\n\nexport interface CreateRecurringNamespaceOptions {\n apiOptions: ApiOptions;\n appId: string;\n evmSigner: EvmSigner;\n /**\n * The cached `/info/chains` recurring metadata. Captured by value at\n * namespace construction time — matches how `partnerFeeBps`,\n * `supportedChains`, and `supportedTokens` are also frozen at\n * `createMarkrService` init. If staleness ever becomes a real consumer\n * concern, the fix is a top-level `manager.refresh()` (not a per-namespace\n * lazy-read pattern).\n */\n recurringChainInfo: RecurringChainInfoMap;\n}\n\nexport function createRecurringNamespace({\n apiOptions,\n appId,\n evmSigner,\n recurringChainInfo,\n}: CreateRecurringNamespaceOptions): RecurringNamespace {\n return {\n quote: (props) => markrRecurringQuote(apiOptions, { ...props, appId }),\n\n executeFirstFill: (props) => executeFirstFillImpl({ ...props, apiOptions, appId, evmSigner }),\n\n listOrders: (props) => markrListRecurringOrders(apiOptions, props),\n\n executeCancellation: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.CancelRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPrepareCancellation,\n }),\n\n executePause: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.PauseRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPreparePause,\n }),\n\n executeUnpause: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.ResumeRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPrepareUnpause,\n }),\n\n checkEligibility: (props) => checkRecurringEligibility({ ...props, recurringChainInfo }),\n\n getRecurringChainInfo: () => recurringChainInfo,\n };\n}\n\n// ---------------------------------------------------------------------------\n// First-fill execution (allowance check + approve-if-needed + first-fill swap)\n// ---------------------------------------------------------------------------\n\ninterface ExecuteFirstFillImplParams extends RecurringExecuteFirstFillParams {\n apiOptions: ApiOptions;\n appId: string;\n evmSigner: EvmSigner;\n}\n\nasync function executeFirstFillImpl({\n apiOptions,\n appId,\n evmSigner,\n fallbackToDefaultOnBatchFailure,\n fromAddress,\n gasSettings,\n quote,\n signerContext,\n sourceChain,\n}: ExecuteFirstFillImplParams): Promise<RecurringExecuteResult> {\n // Mirror the one-shot guard at `TransferManager.estimateNativeFee` — fail at\n // the SDK boundary with `QUOTE_EXPIRED` instead of an opaque `HttpError`\n // from `/recurring/swap` for a slow-to-approve user.\n const now = Math.floor(Date.now() / 1_000);\n if (quote.expiredAt <= now) {\n const expiredSecondsAgo = now - quote.expiredAt;\n throw new InvalidParamsError(\n ErrorReason.QUOTE_EXPIRED,\n `Recurring quote expired ${expiredSecondsAgo} seconds ago.`,\n );\n }\n\n // Wiring-mistake guard: the passed `sourceChain.chainId` (CAIP-2) must agree\n // with the `chainId` (numeric) the quote was issued against. Otherwise the\n // allowance / gas reads hit the wrong chain.\n const sourceChainIdNumeric = caip2ToEip155ChainId(sourceChain.chainId);\n if (sourceChainIdNumeric !== quote.chainId) {\n throw new InvalidParamsError(\n 'sourceChain does not match quote.chainId',\n `sourceChain.chainId=${sourceChain.chainId} resolves to ${sourceChainIdNumeric}, but quote.chainId=${quote.chainId}.`,\n );\n }\n\n const sourceClient = getEvmClientForChain({ chain: sourceChain });\n const chainIdHex = caip2ToEip155HexChainId(sourceChain.chainId);\n\n const { address: spenderAddress } = await markrGetSpenderAddress(apiOptions, {\n chainId: quote.chainId,\n crossChainSwap: false,\n quoteId: quote.uuid,\n });\n\n if (!spenderAddress) {\n throw new SdkError(ErrorReason.CHAIN_NOT_SUPPORTED, ErrorCode.INVALID_PARAMS, {\n details: `Missing Markr spender address for source chain ${sourceChain.chainId}.`,\n });\n }\n\n const approvalRequest = await buildErc20ApprovalRequest({\n chainIdHex,\n client: sourceClient,\n gasSettings,\n owner: fromAddress,\n requiredAllowance: quote.totalAmountIn,\n spender: spenderAddress,\n token: quote.tokenIn,\n });\n\n const syntheticQuote = buildSyntheticQuoteForFirstFill({ fromAddress, quote, sourceChain });\n\n const swap = await markrRecurringSwap(apiOptions, { uuid: quote.uuid, appId });\n\n // One-click batch path: same-chain DCA, approval required, signer exposes\n // `signBatch`. Matches `_executeEvmTransfer`'s eligibility check (recurring\n // is always same-chain so the cross-chain check there collapses to true).\n if (approvalRequest !== undefined && typeof evmSigner.signBatch === 'function') {\n const batchStep: TransferStepDetails = {\n currentSignature: 1,\n currentSignatureReason: TransferSignatureReason.ScheduleRecurringSwap,\n quote: syntheticQuote,\n requiredSignatures: 1,\n signerContext,\n };\n\n // Gas is left undefined on the swap leg — the wallet handles batched gas\n // estimation since the approval hasn't executed yet.\n const swapRequest: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: swap.data,\n from: fromAddress,\n gas: undefined,\n to: swap.to,\n value: swap.value,\n ...maybe1559(gasSettings),\n };\n\n try {\n const txHashes = await evmSigner.signBatch(\n [approvalRequest, swapRequest],\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n batchStep,\n );\n const swapTxHash = txHashes.at(-1);\n if (!swapTxHash) {\n throw new SdkError('One-click batch signing returned no transaction hashes.', ErrorCode.SIGNING_FAILED);\n }\n return { txHash: swapTxHash };\n } catch (error) {\n if (!fallbackToDefaultOnBatchFailure) {\n throw error;\n }\n // Fall through to the two-signature path below.\n }\n }\n\n if (approvalRequest) {\n await signApprovalAndAssertConfirmed({\n client: sourceClient,\n evmSigner,\n request: approvalRequest,\n step: {\n currentSignature: 1,\n currentSignatureReason: TransferSignatureReason.AllowanceApproval,\n quote: syntheticQuote,\n requiredSignatures: 2,\n signerContext,\n },\n });\n }\n\n // Use the Markr same-chain swap wrapper ABI for best-effort revert decoding\n // — matches `_estimateGasFromSwapResponse` in `estimate-native-fee.ts`.\n // Recurring is always same-chain, so `crossChain: false`. Built-in\n // `Error(string)` / `Panic(uint256)` are decoded regardless of ABI.\n const markrAbi = await getMarkrSwapWrapperAbi(false);\n const swapGasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: fromAddress, to: swap.to, data: swap.data, value: swap.value },\n markrAbi,\n 'Failed to estimate gas for recurring first-fill swap transaction.',\n );\n\n const swapRequest: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: swap.data,\n from: fromAddress,\n gas: applyFeeUnitsBpsMargin(swapGasEstimate, gasSettings?.estimateGasMarginBps),\n to: swap.to,\n value: swap.value,\n ...maybe1559(gasSettings),\n };\n\n const swapStep: TransferStepDetails = {\n currentSignature: approvalRequest ? 2 : 1,\n currentSignatureReason: TransferSignatureReason.ScheduleRecurringSwap,\n quote: syntheticQuote,\n requiredSignatures: approvalRequest ? 2 : 1,\n signerContext,\n };\n\n const txHash = await evmSigner.sign(\n swapRequest,\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n swapStep,\n );\n\n return { txHash };\n}\n\n// ---------------------------------------------------------------------------\n// Order-action execution (cancel / pause / unpause — single-tx state change)\n// ---------------------------------------------------------------------------\n\ninterface ExecuteOrderActionImplParams extends RecurringExecuteOrderActionParams {\n signatureReason:\n | TransferSignatureReason.PauseRecurringSwap\n | TransferSignatureReason.ResumeRecurringSwap\n | TransferSignatureReason.CancelRecurringSwap;\n apiOptions: ApiOptions;\n evmSigner: EvmSigner;\n fetchCalldata: (\n apiOptions: ApiOptions,\n params: { orderId: `0x${string}`; address: `0x${string}`; chainId: number },\n ) => Promise<WrappedSwapTransactionResponse>;\n}\n\n// Short verbs for error-message interpolation — avoids the doubled-\"recurring\"\n// + kebab-case-in-prose readout you'd get from interpolating the raw enum\n// wire value (e.g. `recurring pause-recurring-swap transaction`).\nconst ORDER_ACTION_LABEL: Record<ExecuteOrderActionImplParams['signatureReason'], string> = {\n [TransferSignatureReason.PauseRecurringSwap]: 'pause',\n [TransferSignatureReason.ResumeRecurringSwap]: 'resume',\n [TransferSignatureReason.CancelRecurringSwap]: 'cancel',\n};\n\nasync function executeOrderActionImpl({\n signatureReason,\n address,\n apiOptions,\n evmSigner,\n fetchCalldata,\n gasSettings,\n orderId,\n signerContext,\n sourceChain,\n}: ExecuteOrderActionImplParams): Promise<RecurringExecuteResult> {\n const sourceClient = getEvmClientForChain({ chain: sourceChain });\n const chainIdNumeric = caip2ToEip155ChainId(sourceChain.chainId);\n const chainIdHex = caip2ToEip155HexChainId(sourceChain.chainId);\n\n const calldata = await fetchCalldata(apiOptions, { orderId, address, chainId: chainIdNumeric });\n\n const gasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: address, to: calldata.to, data: calldata.data, value: calldata.value },\n erc20Abi,\n `Failed to estimate gas for recurring ${ORDER_ACTION_LABEL[signatureReason]} transaction.`,\n );\n\n const request: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: calldata.data,\n from: address,\n gas: applyFeeUnitsBpsMargin(gasEstimate, gasSettings?.estimateGasMarginBps),\n to: calldata.to,\n value: calldata.value,\n ...maybe1559(gasSettings),\n };\n\n const step: TransferStepDetails = {\n currentSignature: 1,\n currentSignatureReason: signatureReason,\n quote: buildSyntheticQuoteForOrderAction({ address, signatureReason, orderId, sourceChain }),\n requiredSignatures: 1,\n signerContext,\n };\n\n const txHash = await evmSigner.sign(\n request,\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n step,\n );\n\n return { txHash };\n}\n\n// ---------------------------------------------------------------------------\n// Internal: synthetic Quote objects for `TransferStepDetails.quote`\n// ---------------------------------------------------------------------------\n\n/**\n * Builds a minimum-viable {@link Quote} for the signer step so consumer\n * `EvmSigner` impls can render meaningful wallet prompts for a recurring\n * action (which has no real `Quote` in the swap-quoter sense). The synthetic\n * value carries enough recurring context (uuid, chain, amounts, tokens) for\n * a wallet UI to label the popup; the `aggregator.id` (`'markr-recurring'`)\n * lets advanced signers detect the recurring path explicitly.\n *\n * Asset fields use placeholder `name`/`symbol`/`decimals` because the\n * recurring quote doesn't echo those — consumers needing rich asset display\n * should resolve token metadata against their own asset map keyed by\n * `quote.tokenIn`/`tokenOut`.\n */\nfunction buildSyntheticQuoteForFirstFill({\n fromAddress,\n quote,\n sourceChain,\n}: {\n fromAddress: `0x${string}`;\n quote: RecurringQuoteResponse;\n sourceChain: Chain;\n}): Quote {\n return {\n // Keep the stable `'markr-recurring'` marker (shipped in #240) — consumer\n // signers may detect the recurring path via `quote.aggregator.id`. The\n // typed `TransferStepDetails.currentSignatureReason` is now the preferred\n // discriminant for new integrations, but this id stays for back-compat.\n aggregator: { id: 'markr-recurring', name: 'Markr recurring' },\n amountIn: quote.amount,\n amountOut: quote.amountOut,\n assetIn: { type: TokenType.ERC20, address: quote.tokenIn, name: '', symbol: '', decimals: 0 },\n assetOut: { type: TokenType.ERC20, address: quote.tokenOut, name: '', symbol: '', decimals: 0 },\n expiresAt: quote.expiredAt,\n fees: [],\n fromAddress,\n id: quote.uuid,\n partnerFeeBps: null,\n serviceType: ServiceType.MARKR,\n slippageBps: quote.recommendedSlippage,\n // Pass the caller-provided `Chain` straight through — recurring is always\n // same-chain, so source === target. Avoids stripping `chainName` /\n // `networkToken` / `rpcUrl` that consumer signers may use for display.\n sourceChain,\n targetChain: sourceChain,\n toAddress: fromAddress,\n };\n}\n\nfunction buildSyntheticQuoteForOrderAction({\n signatureReason,\n address,\n orderId,\n sourceChain,\n}: {\n signatureReason:\n | TransferSignatureReason.PauseRecurringSwap\n | TransferSignatureReason.ResumeRecurringSwap\n | TransferSignatureReason.CancelRecurringSwap;\n address: `0x${string}`;\n orderId: `0x${string}`;\n sourceChain: Chain;\n}): Quote {\n const action = ORDER_ACTION_LABEL[signatureReason];\n return {\n // Same back-compat rationale as `buildSyntheticQuoteForFirstFill` — preserve\n // the original lowercase `markr-recurring-${action}` id shape (shipped in\n // #240) so consumers keying off `quote.aggregator.id` keep working.\n aggregator: {\n id: `markr-recurring-${action}`,\n name: `Markr recurring (${action})`,\n },\n amountIn: 0n,\n amountOut: 0n,\n assetIn: emptyNativeAsset(),\n assetOut: emptyNativeAsset(),\n expiresAt: 0,\n fees: [],\n fromAddress: address,\n id: orderId,\n partnerFeeBps: null,\n serviceType: ServiceType.MARKR,\n slippageBps: 0,\n // See `buildSyntheticQuoteForFirstFill` — pass the real `Chain` through.\n sourceChain,\n targetChain: sourceChain,\n toAddress: address,\n };\n}\n\nfunction emptyNativeAsset() {\n return { type: TokenType.NATIVE, name: '', symbol: '', decimals: 0 } as const;\n}\n"],"mappings":"m6BA+CA,SAAgB,EAAyB,CACvC,aACA,QACA,YACA,sBACsD,CACtD,MAAO,CACL,MAAQ,GAAU,EAAoB,EAAY,CAAE,GAAG,EAAO,QAAO,CAAC,CAEtE,iBAAmB,GAAU,EAAqB,CAAE,GAAG,EAAO,aAAY,QAAO,YAAW,CAAC,CAE7F,WAAa,GAAU,EAAyB,EAAY,EAAM,CAElE,oBAAsB,GACpB,EAAuB,CACrB,GAAG,EACH,gBAAiB,EAAwB,oBACzC,aACA,YAC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SAAU,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG,CAC/F,UAAW,EAAM,UACjB,KAAM,EAAE,CACR,cACA,GAAI,EAAM,KACV,cAAe,KACf,YAAa,EAAY,MACzB,YAAa,EAAM,oBAInB,cACA,YAAa,EACb,UAAW,EACZ,CAGH,SAAS,EAAkC,CACzC,kBACA,UACA,UACA,eASQ,CACR,IAAM,EAAS,EAAmB,GAClC,MAAO,CAIL,WAAY,CACV,GAAI,mBAAmB,IACvB,KAAM,oBAAoB,EAAO,GAClC,CACD,SAAU,GACV,UAAW,GACX,QAAS,GAAkB,CAC3B,SAAU,GAAkB,CAC5B,UAAW,EACX,KAAM,EAAE,CACR,YAAa,EACb,GAAI,EACJ,cAAe,KACf,YAAa,EAAY,MACzB,YAAa,EAEb,cACA,YAAa,EACb,UAAW,EACZ,CAGH,SAAS,GAAmB,CAC1B,MAAO,CAAE,KAAM,EAAU,OAAQ,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG"}
|
|
1
|
+
{"version":3,"file":"_namespace.js","names":[],"sources":["../../../../src/transfer-service/markr/recurring/_namespace.ts"],"sourcesContent":["import { erc20Abi, isAddressEqual } from 'viem';\nimport { ERC_ZERO_ADDRESS, ServiceType, TokenType, TransferSignatureReason } from '../../../constants';\nimport { ErrorCode, ErrorReason, InvalidParamsError, SdkError } from '../../../errors';\nimport type { Chain } from '../../../types/chain';\nimport type { Quote } from '../../../types/quote';\nimport type { EvmSigner, EvmTransactionRequest, Hex } from '../../../types/signer';\nimport type { TransferStepDetails } from '../../../types/transfer';\nimport { caip2ToEip155ChainId, caip2ToEip155HexChainId } from '../../../utils/caip';\nimport { applyFeeUnitsBpsMargin, getEvmClientForChain, maybe1559 } from '../../_utils';\nimport type { EvmSourceClient } from '../../_utils';\nimport { buildErc20ApprovalRequest, signApprovalAndAssertConfirmed } from '../../_evm-approval';\nimport { estimateGasWithRevert } from '../../_evm-errors';\nimport type { WrappedSwapTransactionResponse } from '../_schema';\nimport { markrGetSpenderAddress, type ApiOptions } from '../_api';\nimport { getMarkrSwapWrapperAbi } from '../_utils';\nimport {\n markrListRecurringOrders,\n markrPrepareCancellation,\n markrPreparePause,\n markrPrepareUnpause,\n markrRecurringQuote,\n markrRecurringSwap,\n} from './_api';\nimport { checkRecurringEligibility } from './_eligibility';\nimport type {\n RecurringChainInfoMap,\n RecurringExecuteFirstFillParams,\n RecurringExecuteOrderActionParams,\n RecurringExecuteResult,\n RecurringNamespace,\n RecurringNamespaceQuoteParams,\n RecurringQuoteResponse,\n} from './types';\n\nexport interface CreateRecurringNamespaceOptions {\n apiOptions: ApiOptions;\n appId: string;\n evmSigner: EvmSigner;\n /**\n * The cached `/info/chains` recurring metadata. Captured by value at\n * namespace construction time — matches how `partnerFeeBps`,\n * `supportedChains`, and `supportedTokens` are also frozen at\n * `createMarkrService` init. If staleness ever becomes a real consumer\n * concern, the fix is a top-level `manager.refresh()` (not a per-namespace\n * lazy-read pattern).\n */\n recurringChainInfo: RecurringChainInfoMap;\n}\n\nexport function createRecurringNamespace({\n apiOptions,\n appId,\n evmSigner,\n recurringChainInfo,\n}: CreateRecurringNamespaceOptions): RecurringNamespace {\n return {\n quote: (props) => quoteImpl({ ...props, apiOptions, appId, recurringChainInfo }),\n\n executeFirstFill: (props) => executeFirstFillImpl({ ...props, apiOptions, appId, evmSigner, recurringChainInfo }),\n\n listOrders: (props) => markrListRecurringOrders(apiOptions, props),\n\n executeCancellation: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.CancelRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPrepareCancellation,\n }),\n\n executePause: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.PauseRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPreparePause,\n }),\n\n executeUnpause: (props) =>\n executeOrderActionImpl({\n ...props,\n signatureReason: TransferSignatureReason.ResumeRecurringSwap,\n apiOptions,\n evmSigner,\n fetchCalldata: markrPrepareUnpause,\n }),\n\n checkEligibility: (props) => checkRecurringEligibility({ ...props, recurringChainInfo }),\n\n getRecurringChainInfo: () => recurringChainInfo,\n };\n}\n\n// ---------------------------------------------------------------------------\n// Quote — native input (`tokenIn === 0x0…`) is passed through to Markr\n// verbatim (the recurring API accepts the zero address as `tokenIn`). The\n// chain's wrapped-native address is read off the cached chain info (sourced\n// from `/info/chains[].wrapped_token`); the SDK only fails fast at this\n// boundary when Markr hasn't published one for the chain — we'd be issuing\n// a quote we couldn't honor.\n// ---------------------------------------------------------------------------\n\ninterface QuoteImplParams extends RecurringNamespaceQuoteParams {\n apiOptions: ApiOptions;\n appId: string;\n recurringChainInfo: RecurringChainInfoMap;\n}\n\nasync function quoteImpl({\n apiOptions,\n appId,\n recurringChainInfo,\n ...quoteParams\n}: QuoteImplParams): Promise<RecurringQuoteResponse> {\n const isNativeInput = isAddressEqual(quoteParams.tokenIn, ERC_ZERO_ADDRESS);\n\n if (isNativeInput && !recurringChainInfo.get(quoteParams.chainId)?.wrappedNativeAddress) {\n throw new InvalidParamsError(\n ErrorReason.CHAIN_NOT_SUPPORTED,\n `No wrapped-native ERC-20 address known for EVM chainId ${quoteParams.chainId}. ` +\n 'Native-input recurring swaps require Markr to publish `wrapped_token` for the chain in `/info/chains`.',\n );\n }\n\n return markrRecurringQuote(apiOptions, { ...quoteParams, appId });\n}\n\n// ---------------------------------------------------------------------------\n// First-fill execution (allowance check + approve-if-needed + first-fill swap)\n// ---------------------------------------------------------------------------\n\ninterface ExecuteFirstFillImplParams extends RecurringExecuteFirstFillParams {\n apiOptions: ApiOptions;\n appId: string;\n evmSigner: EvmSigner;\n recurringChainInfo: RecurringChainInfoMap;\n}\n\nasync function executeFirstFillImpl({\n apiOptions,\n appId,\n evmSigner,\n fallbackToDefaultOnBatchFailure,\n fromAddress,\n gasSettings,\n quote,\n recurringChainInfo,\n signerContext,\n sourceChain,\n}: ExecuteFirstFillImplParams): Promise<RecurringExecuteResult> {\n // Mirror the one-shot guard at `TransferManager.estimateNativeFee` — fail at\n // the SDK boundary with `QUOTE_EXPIRED` instead of an opaque `HttpError`\n // from `/recurring/swap` for a slow-to-approve user.\n const now = Math.floor(Date.now() / 1_000);\n if (quote.expiredAt <= now) {\n const expiredSecondsAgo = now - quote.expiredAt;\n throw new InvalidParamsError(\n ErrorReason.QUOTE_EXPIRED,\n `Recurring quote expired ${expiredSecondsAgo} seconds ago.`,\n );\n }\n\n // Wiring-mistake guard: the passed `sourceChain.chainId` (CAIP-2) must agree\n // with the `chainId` (numeric) the quote was issued against. Otherwise the\n // allowance / gas reads hit the wrong chain.\n const sourceChainIdNumeric = caip2ToEip155ChainId(sourceChain.chainId);\n if (sourceChainIdNumeric !== quote.chainId) {\n throw new InvalidParamsError(\n 'sourceChain does not match quote.chainId',\n `sourceChain.chainId=${sourceChain.chainId} resolves to ${sourceChainIdNumeric}, but quote.chainId=${quote.chainId}.`,\n );\n }\n\n const sourceClient = getEvmClientForChain({ chain: sourceChain });\n const chainIdHex = caip2ToEip155HexChainId(sourceChain.chainId);\n\n const isNativeInput = isAddressEqual(quote.tokenIn, ERC_ZERO_ADDRESS);\n\n const { address: spenderAddress } = await markrGetSpenderAddress(apiOptions, {\n chainId: quote.chainId,\n crossChainSwap: false,\n quoteId: quote.uuid,\n });\n\n if (!spenderAddress) {\n throw new SdkError(ErrorReason.CHAIN_NOT_SUPPORTED, ErrorCode.INVALID_PARAMS, {\n details: `Missing Markr spender address for source chain ${sourceChain.chainId}.`,\n });\n }\n\n // Fetch the ordered transaction array from Markr's `/recurring/swap`:\n // - ERC-20 `tokenIn`: `[createOrder]` (1 element).\n // - Native `tokenIn` (`0x0…`): `[wrap, createOrder]` (2 elements).\n // The wrap's `to` is the wrapped-native ERC-20 we'll then approve against\n // (Markr does not return an approval entry — the SDK inserts that step).\n const recurringSwapTxs = await markrRecurringSwap(apiOptions, { uuid: quote.uuid, appId });\n\n const wrapTx = recurringSwapTxs.find((tx) => tx.type === 'wrap');\n const createOrderTx = recurringSwapTxs.find((tx) => tx.type === 'createOrder');\n\n if (!createOrderTx) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `Missing createOrder step (quote uuid: ${quote.uuid}).`,\n });\n }\n\n // Cross-check: native input must come back with a wrap leg, and an ERC-20\n // input must not. If Markr disagrees with the cached quote's `tokenIn`,\n // bail rather than silently signing a mismatched flow (e.g. broadcasting\n // a wrap when the user thought they were spending ERC-20, or skipping a\n // wrap when the user expected to fund the schedule with native).\n if (isNativeInput && !wrapTx) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `Native-input quote returned no wrap step (quote uuid: ${quote.uuid}).`,\n });\n }\n if (!isNativeInput && wrapTx) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `ERC-20 input quote returned a wrap step (quote uuid: ${quote.uuid}, tokenIn: ${quote.tokenIn}).`,\n });\n }\n\n // Defense-in-depth on the wrap leg before we hand it to the wallet:\n // - `wrap.value` must equal `quote.totalAmountIn` — that's what funds the\n // full schedule; a smaller value would under-fund subsequent fills, a\n // larger one would silently overcharge the user.\n // - `wrap.to` must match the chain's published wrapped-native (from\n // `/info/chains[].wrapped_token`) when one is known. Cross-check guards\n // against a misrouted approval — we're about to grant `totalAmountIn`\n // allowance to whatever `wrap.to` points at. When the chain entry has\n // no published wrapped-native, defer to Markr (`wrap.to` is server-\n // authoritative); the quote boundary already failed-closed in that\n // case anyway, so this is purely belt-and-suspenders.\n if (wrapTx) {\n if (wrapTx.value !== quote.totalAmountIn) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `Wrap step value ${wrapTx.value} does not match quote.totalAmountIn ${quote.totalAmountIn} (quote uuid: ${quote.uuid}).`,\n });\n }\n const expectedWrappedNative = recurringChainInfo.get(quote.chainId)?.wrappedNativeAddress;\n if (expectedWrappedNative && !isAddressEqual(wrapTx.to, expectedWrappedNative)) {\n throw new SdkError(ErrorReason.RECURRING_SWAP_RESPONSE_INCONSISTENT, ErrorCode.INVALID_PARAMS, {\n details: `Wrap step target ${wrapTx.to} does not match the published wrapped-native ${expectedWrappedNative} for chainId ${quote.chainId} (quote uuid: ${quote.uuid}).`,\n });\n }\n }\n\n // Approval target: for native input, the wrapped-native ERC-20 returned\n // by Markr in `wrap.to` (cross-checked above). For ERC-20 input, the\n // quote's `tokenIn`. Either way the spender is the RecurringSwaps router.\n const approvalTokenAddress = wrapTx?.to ?? quote.tokenIn;\n\n const approvalRequest = await buildErc20ApprovalRequest({\n chainIdHex,\n client: sourceClient,\n gasSettings,\n owner: fromAddress,\n requiredAllowance: quote.totalAmountIn,\n spender: spenderAddress,\n token: approvalTokenAddress,\n });\n\n // Wrap leg comes straight from Markr — `wrap.to` is the chain wrapped-native\n // contract, `data` is `deposit()`, `value` is `totalAmountIn`. Gas is left\n // undefined: when batched the wallet handles atomic estimation; sequentially\n // the wrap is the first call so the wallet's own estimation fires the prompt.\n const wrapRequest: EvmTransactionRequest | undefined = wrapTx\n ? {\n chainId: chainIdHex,\n data: wrapTx.data,\n from: fromAddress,\n gas: undefined,\n to: wrapTx.to,\n value: wrapTx.value,\n ...maybe1559(gasSettings),\n }\n : undefined;\n\n const syntheticQuote = buildSyntheticQuoteForFirstFill({ fromAddress, quote, sourceChain });\n\n // One-click batch path: same-chain DCA, signer exposes `signBatch`, and at\n // least one leg precedes the swap (otherwise there's nothing to batch — we\n // sign the swap solo). The batch shape adapts to the recurring setup:\n // - native + needs approval: [wrap, approve, swap] (3 elements)\n // - native + allowance covers: [wrap, swap] (2 elements)\n // - ERC-20 + needs approval: [approve, swap] (2 elements)\n // - ERC-20 + allowance covers: swap solo (no batch)\n const batchPreSwap: EvmTransactionRequest[] = [];\n if (wrapRequest) batchPreSwap.push(wrapRequest);\n if (approvalRequest) batchPreSwap.push(approvalRequest);\n\n if (batchPreSwap.length > 0 && typeof evmSigner.signBatch === 'function') {\n const batchStep: TransferStepDetails = {\n currentSignature: 1,\n currentSignatureReason: TransferSignatureReason.ScheduleRecurringSwap,\n quote: syntheticQuote,\n requiredSignatures: 1,\n signerContext,\n };\n\n // Gas is left undefined on the swap leg — the wallet handles batched gas\n // estimation since the preceding leg(s) haven't executed yet.\n const swapRequest: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: createOrderTx.data,\n from: fromAddress,\n gas: undefined,\n to: createOrderTx.to,\n value: createOrderTx.value,\n ...maybe1559(gasSettings),\n };\n\n try {\n const txHashes = await evmSigner.signBatch(\n [...batchPreSwap, swapRequest],\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n batchStep,\n );\n const swapTxHash = txHashes.at(-1);\n if (!swapTxHash) {\n throw new SdkError('One-click batch signing returned no transaction hashes.', ErrorCode.SIGNING_FAILED);\n }\n return { txHash: swapTxHash };\n } catch (error) {\n if (!fallbackToDefaultOnBatchFailure) {\n throw error;\n }\n // Fall through to the sequential path below.\n }\n }\n\n // Sequential path — sign each preceding leg, await its receipt, then sign\n // the swap. Signature counters reflect the actual prompt count the user\n // will see (1 + wrap? + approval?).\n const requiredSignatures = 1 + batchPreSwap.length;\n let signatureCursor = 0;\n\n if (wrapRequest && wrapTx) {\n // Estimate gas for the wrap leg on the sequential path. On the batch\n // path we leave gas undefined and let the wallet do atomic estimation;\n // sequentially the wrap is a real first-tx prompt so it gets the same\n // treatment as the approval and swap legs (estimate + bps margin) for\n // wallets that don't auto-estimate. Read `to`/`data` off `wrapTx` (the\n // narrow `RecurringSwapTransaction` shape) rather than the wider\n // `EvmTransactionRequest` so the args are non-nullable.\n const wrapGasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: fromAddress, to: wrapTx.to, data: wrapTx.data, value: wrapTx.value },\n // No router ABI to decode against — wrap is a plain\n // `WAVAX.deposit{value}()`; built-in `Error(string)` / `Panic(uint256)`\n // are still decoded regardless of the ABI argument.\n [],\n 'Failed to estimate gas for recurring first-fill wrap transaction.',\n );\n const wrapRequestWithGas: EvmTransactionRequest = {\n ...wrapRequest,\n gas: applyFeeUnitsBpsMargin(wrapGasEstimate, gasSettings?.estimateGasMarginBps),\n };\n\n signatureCursor += 1;\n await signWrapAndAssertConfirmed({\n client: sourceClient,\n evmSigner,\n request: wrapRequestWithGas,\n step: {\n currentSignature: signatureCursor,\n currentSignatureReason: TransferSignatureReason.WrapToken,\n quote: syntheticQuote,\n requiredSignatures,\n signerContext,\n },\n });\n }\n\n if (approvalRequest) {\n signatureCursor += 1;\n await signApprovalAndAssertConfirmed({\n client: sourceClient,\n evmSigner,\n request: approvalRequest,\n step: {\n currentSignature: signatureCursor,\n currentSignatureReason: TransferSignatureReason.AllowanceApproval,\n quote: syntheticQuote,\n requiredSignatures,\n signerContext,\n },\n });\n }\n\n // Use the Markr same-chain swap wrapper ABI for best-effort revert decoding\n // — matches `_estimateGasFromSwapResponse` in `estimate-native-fee.ts`.\n // Recurring is always same-chain, so `crossChain: false`. Built-in\n // `Error(string)` / `Panic(uint256)` are decoded regardless of ABI.\n const markrAbi = await getMarkrSwapWrapperAbi(false);\n const swapGasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: fromAddress, to: createOrderTx.to, data: createOrderTx.data, value: createOrderTx.value },\n markrAbi,\n 'Failed to estimate gas for recurring first-fill swap transaction.',\n );\n\n const swapRequest: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: createOrderTx.data,\n from: fromAddress,\n gas: applyFeeUnitsBpsMargin(swapGasEstimate, gasSettings?.estimateGasMarginBps),\n to: createOrderTx.to,\n value: createOrderTx.value,\n ...maybe1559(gasSettings),\n };\n\n signatureCursor += 1;\n const swapStep: TransferStepDetails = {\n currentSignature: signatureCursor,\n currentSignatureReason: TransferSignatureReason.ScheduleRecurringSwap,\n quote: syntheticQuote,\n requiredSignatures,\n signerContext,\n };\n\n const txHash = await evmSigner.sign(\n swapRequest,\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n swapStep,\n );\n\n return { txHash };\n}\n\n/**\n * Signs a `WAVAX.deposit{value}()` wrap request, dispatches it, and waits for\n * the receipt. Mirrors {@link signApprovalAndAssertConfirmed} so the\n * sequential native path fails loudly if the wrap reverts on-chain (without\n * which the downstream approve would silently fail for \"insufficient WAVAX\").\n */\nasync function signWrapAndAssertConfirmed({\n client,\n evmSigner,\n request,\n step,\n}: {\n client: EvmSourceClient;\n evmSigner: EvmSigner;\n request: EvmTransactionRequest;\n step: TransferStepDetails;\n}): Promise<Hex> {\n const wrapTxHash = await evmSigner.sign(\n request,\n (signedTxHash) => client.sendRawTransaction({ serializedTransaction: signedTxHash }),\n step,\n );\n\n const receipt = await client.waitForTransactionReceipt({ hash: wrapTxHash });\n\n if (receipt.status === 'reverted') {\n throw new SdkError(ErrorReason.NATIVE_WRAP_REVERTED, ErrorCode.TRANSACTION_REVERTED, {\n details: `Wrap tx reverted on-chain (tx hash: ${wrapTxHash}).`,\n });\n }\n\n return wrapTxHash;\n}\n\n// ---------------------------------------------------------------------------\n// Order-action execution (cancel / pause / unpause — single-tx state change)\n// ---------------------------------------------------------------------------\n\ninterface ExecuteOrderActionImplParams extends RecurringExecuteOrderActionParams {\n signatureReason:\n | TransferSignatureReason.PauseRecurringSwap\n | TransferSignatureReason.ResumeRecurringSwap\n | TransferSignatureReason.CancelRecurringSwap;\n apiOptions: ApiOptions;\n evmSigner: EvmSigner;\n fetchCalldata: (\n apiOptions: ApiOptions,\n params: { orderId: `0x${string}`; address: `0x${string}`; chainId: number },\n ) => Promise<WrappedSwapTransactionResponse>;\n}\n\n// Short verbs for error-message interpolation — avoids the doubled-\"recurring\"\n// + kebab-case-in-prose readout you'd get from interpolating the raw enum\n// wire value (e.g. `recurring pause-recurring-swap transaction`).\nconst ORDER_ACTION_LABEL: Record<ExecuteOrderActionImplParams['signatureReason'], string> = {\n [TransferSignatureReason.PauseRecurringSwap]: 'pause',\n [TransferSignatureReason.ResumeRecurringSwap]: 'resume',\n [TransferSignatureReason.CancelRecurringSwap]: 'cancel',\n};\n\nasync function executeOrderActionImpl({\n signatureReason,\n address,\n apiOptions,\n evmSigner,\n fetchCalldata,\n gasSettings,\n orderId,\n signerContext,\n sourceChain,\n}: ExecuteOrderActionImplParams): Promise<RecurringExecuteResult> {\n const sourceClient = getEvmClientForChain({ chain: sourceChain });\n const chainIdNumeric = caip2ToEip155ChainId(sourceChain.chainId);\n const chainIdHex = caip2ToEip155HexChainId(sourceChain.chainId);\n\n const calldata = await fetchCalldata(apiOptions, { orderId, address, chainId: chainIdNumeric });\n\n const gasEstimate = await estimateGasWithRevert(\n sourceClient,\n { account: address, to: calldata.to, data: calldata.data, value: calldata.value },\n erc20Abi,\n `Failed to estimate gas for recurring ${ORDER_ACTION_LABEL[signatureReason]} transaction.`,\n );\n\n const request: EvmTransactionRequest = {\n chainId: chainIdHex,\n data: calldata.data,\n from: address,\n gas: applyFeeUnitsBpsMargin(gasEstimate, gasSettings?.estimateGasMarginBps),\n to: calldata.to,\n value: calldata.value,\n ...maybe1559(gasSettings),\n };\n\n const step: TransferStepDetails = {\n currentSignature: 1,\n currentSignatureReason: signatureReason,\n quote: buildSyntheticQuoteForOrderAction({ address, signatureReason, orderId, sourceChain }),\n requiredSignatures: 1,\n signerContext,\n };\n\n const txHash = await evmSigner.sign(\n request,\n (signedTxHash) => sourceClient.sendRawTransaction({ serializedTransaction: signedTxHash }),\n step,\n );\n\n return { txHash };\n}\n\n// ---------------------------------------------------------------------------\n// Internal: synthetic Quote objects for `TransferStepDetails.quote`\n// ---------------------------------------------------------------------------\n\n/**\n * Builds a minimum-viable {@link Quote} for the signer step so consumer\n * `EvmSigner` impls can render meaningful wallet prompts for a recurring\n * action (which has no real `Quote` in the swap-quoter sense). The synthetic\n * value carries enough recurring context (uuid, chain, amounts, tokens) for\n * a wallet UI to label the popup; the `aggregator.id` (`'markr-recurring'`)\n * lets advanced signers detect the recurring path explicitly.\n *\n * Asset fields use placeholder `name`/`symbol`/`decimals` because the\n * recurring quote doesn't echo those — consumers needing rich asset display\n * should resolve token metadata against their own asset map keyed by\n * `quote.tokenIn`/`tokenOut`.\n */\nfunction buildSyntheticQuoteForFirstFill({\n fromAddress,\n quote,\n sourceChain,\n}: {\n fromAddress: `0x${string}`;\n quote: RecurringQuoteResponse;\n sourceChain: Chain;\n}): Quote {\n return {\n // Keep the stable `'markr-recurring'` marker (shipped in #240) — consumer\n // signers may detect the recurring path via `quote.aggregator.id`. The\n // typed `TransferStepDetails.currentSignatureReason` is now the preferred\n // discriminant for new integrations, but this id stays for back-compat.\n aggregator: { id: 'markr-recurring', name: 'Markr recurring' },\n amountIn: quote.amount,\n amountOut: quote.amountOut,\n assetIn: { type: TokenType.ERC20, address: quote.tokenIn, name: '', symbol: '', decimals: 0 },\n assetOut: { type: TokenType.ERC20, address: quote.tokenOut, name: '', symbol: '', decimals: 0 },\n expiresAt: quote.expiredAt,\n fees: [],\n fromAddress,\n id: quote.uuid,\n partnerFeeBps: null,\n serviceType: ServiceType.MARKR,\n slippageBps: quote.recommendedSlippage,\n // Pass the caller-provided `Chain` straight through — recurring is always\n // same-chain, so source === target. Avoids stripping `chainName` /\n // `networkToken` / `rpcUrl` that consumer signers may use for display.\n sourceChain,\n targetChain: sourceChain,\n toAddress: fromAddress,\n };\n}\n\nfunction buildSyntheticQuoteForOrderAction({\n signatureReason,\n address,\n orderId,\n sourceChain,\n}: {\n signatureReason:\n | TransferSignatureReason.PauseRecurringSwap\n | TransferSignatureReason.ResumeRecurringSwap\n | TransferSignatureReason.CancelRecurringSwap;\n address: `0x${string}`;\n orderId: `0x${string}`;\n sourceChain: Chain;\n}): Quote {\n const action = ORDER_ACTION_LABEL[signatureReason];\n return {\n // Same back-compat rationale as `buildSyntheticQuoteForFirstFill` — preserve\n // the original lowercase `markr-recurring-${action}` id shape (shipped in\n // #240) so consumers keying off `quote.aggregator.id` keep working.\n aggregator: {\n id: `markr-recurring-${action}`,\n name: `Markr recurring (${action})`,\n },\n amountIn: 0n,\n amountOut: 0n,\n assetIn: emptyNativeAsset(),\n assetOut: emptyNativeAsset(),\n expiresAt: 0,\n fees: [],\n fromAddress: address,\n id: orderId,\n partnerFeeBps: null,\n serviceType: ServiceType.MARKR,\n slippageBps: 0,\n // See `buildSyntheticQuoteForFirstFill` — pass the real `Chain` through.\n sourceChain,\n targetChain: sourceChain,\n toAddress: address,\n };\n}\n\nfunction emptyNativeAsset() {\n return { type: TokenType.NATIVE, name: '', symbol: '', decimals: 0 } as const;\n}\n"],"mappings":"68BAiDA,SAAgB,EAAyB,CACvC,aACA,QACA,YACA,sBACsD,CACtD,MAAO,CACL,MAAQ,GAAU,EAAU,CAAE,GAAG,EAAO,aAAY,QAAO,qBAAoB,CAAC,CAEhF,iBAAmB,GAAU,EAAqB,CAAE,GAAG,EAAO,aAAY,QAAO,YAAW,qBAAoB,CAAC,CAEjH,WAAa,GAAU,EAAyB,EAAY,EAAM,CAElE,oBAAsB,GACpB,EAAuB,CACrB,GAAG,EACH,gBAAiB,EAAwB,oBACzC,aACA,YACA,cAAe,EAChB,CAAC,CAEJ,aAAe,GACb,EAAuB,CACrB,GAAG,EACH,gBAAiB,EAAwB,mBACzC,aACA,YACA,cAAe,EAChB,CAAC,CAEJ,eAAiB,GACf,EAAuB,CACrB,GAAG,EACH,gBAAiB,EAAwB,oBACzC,aACA,YACA,cAAe,EAChB,CAAC,CAEJ,iBAAmB,GAAU,EAA0B,CAAE,GAAG,EAAO,qBAAoB,CAAC,CAExF,0BAA6B,EAC9B,CAkBH,eAAe,EAAU,CACvB,aACA,QACA,qBACA,GAAG,GACgD,CAGnD,GAFsB,EAAe,EAAY,QAAA,6CAA0B,EAEtD,CAAC,EAAmB,IAAI,EAAY,QAAQ,EAAE,qBACjE,MAAM,IAAI,EACR,EAAY,oBACZ,0DAA0D,EAAY,QAAQ,8GAE/E,CAGH,OAAO,EA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,iBAAkB,EAClB,uBAAwB,EACxB,MAAO,EAAkC,CAAE,UAAS,kBAAiB,UAAS,cAAa,CAAC,CAC5F,mBAAoB,EACpB,gBACD,CAQD,MAAO,CAAE,OANM,MAAM,EAAU,KAC7B,EACC,GAAiB,EAAa,mBAAmB,CAAE,sBAAuB,EAAc,CAAC,CAC1F,EACD,CAEgB,CAoBnB,SAAS,EAAgC,CACvC,cACA,QACA,eAKQ,CACR,MAAO,CAKL,WAAY,CAAE,GAAI,kBAAmB,KAAM,kBAAmB,CAC9D,SAAU,EAAM,OAChB,UAAW,EAAM,UACjB,QAAS,CAAE,KAAM,EAAU,MAAO,QAAS,EAAM,QAAS,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG,CAC7F,SAAU,CAAE,KAAM,EAAU,MAAO,QAAS,EAAM,SAAU,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG,CAC/F,UAAW,EAAM,UACjB,KAAM,EAAE,CACR,cACA,GAAI,EAAM,KACV,cAAe,KACf,YAAa,EAAY,MACzB,YAAa,EAAM,oBAInB,cACA,YAAa,EACb,UAAW,EACZ,CAGH,SAAS,EAAkC,CACzC,kBACA,UACA,UACA,eASQ,CACR,IAAM,EAAS,EAAmB,GAClC,MAAO,CAIL,WAAY,CACV,GAAI,mBAAmB,IACvB,KAAM,oBAAoB,EAAO,GAClC,CACD,SAAU,GACV,UAAW,GACX,QAAS,GAAkB,CAC3B,SAAU,GAAkB,CAC5B,UAAW,EACX,KAAM,EAAE,CACR,YAAa,EACb,GAAI,EACJ,cAAe,KACf,YAAa,EAAY,MACzB,YAAa,EAEb,cACA,YAAa,EACb,UAAW,EACZ,CAGH,SAAS,GAAmB,CAC1B,MAAO,CAAE,KAAM,EAAU,OAAQ,KAAM,GAAI,OAAQ,GAAI,SAAU,EAAG"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`./types.cjs`),t=require(`../../service-schemas.cjs`);let n=require(`zod`);const r=/^0x[0-9a-fA-F]{64}$/,i=n.z.enum(e.RECURRING_FREQUENCY_UNITS),a=n.z.object({unit:i,value:n.z.number().int().min(1)}),o=n.z.enum(Object.values(e.RecurringOrderStatus)),s=n.z.object({executionIndex:n.z.number().int().nonnegative(),reasons:n.z.array(n.z.string()),tryCount:n.z.number().int().nonnegative(),failedAt:n.z.number().int().nonnegative()}),c=n.z.string().regex(r,`Invalid recurring order id (expected 0x-prefixed bytes32)`).transform(e=>e),
|
|
1
|
+
require(`../../../_virtual/_rolldown/runtime.cjs`);const e=require(`./types.cjs`),t=require(`../../service-schemas.cjs`);let n=require(`zod`);const r=/^0x[0-9a-fA-F]{64}$/,i=n.z.enum(e.RECURRING_FREQUENCY_UNITS),a=n.z.object({unit:i,value:n.z.number().int().min(1)}),o=n.z.enum(Object.values(e.RecurringOrderStatus)),s=n.z.object({executionIndex:n.z.number().int().nonnegative(),reasons:n.z.array(n.z.string()),tryCount:n.z.number().int().nonnegative(),failedAt:n.z.number().int().nonnegative()}),c=n.z.object({type:n.z.enum([`wrap`,`createOrder`]),to:t.EvmAddressSchema,data:t.HexSchema,value:n.z.coerce.bigint().nonnegative()}),l=n.z.array(c),u=n.z.string().regex(r,`Invalid recurring order id (expected 0x-prefixed bytes32)`).transform(e=>e),d=n.z.object({orderId:u,owner:t.EvmAddressSchema,chainId:n.z.coerce.number().int().nonnegative(),tokenIn:t.EvmAddressSchema,tokenOut:t.EvmAddressSchema,amount:n.z.coerce.bigint().nonnegative(),numberOfOrders:n.z.number().int(),executedOrders:n.z.number().int().nonnegative(),remainingOrders:n.z.number().int().nonnegative().nullish().transform(e=>e??null),frequency:a,totalAmountIn:n.z.coerce.bigint().nonnegative(),tryCount:n.z.number().int().nonnegative(),failures:n.z.array(s),status:o,createdAt:n.z.number().int().nonnegative(),nextExecutionAt:n.z.number().int().nonnegative().nullish().transform(e=>e??null),cancelledAt:n.z.number().int().nonnegative().nullish().transform(e=>e??null)}),f=n.z.object({type:n.z.enum([`gas`,`recurring`,`protocol`,`bridge`,`slippage`,`swap`,`other`]).or(n.z.string()),name:n.z.string(),amount:n.z.coerce.bigint().nonnegative(),token:n.z.object({chainId:n.z.coerce.number().int().nonnegative(),address:t.EvmAddressSchema}),extra:n.z.union([n.z.boolean(),n.z.record(n.z.string(),n.z.unknown())]).optional()}),p=n.z.object({uuid:n.z.uuid(),chainId:n.z.coerce.number().int().nonnegative(),tokenIn:t.EvmAddressSchema,tokenOut:t.EvmAddressSchema,amount:n.z.coerce.bigint().nonnegative(),numberOfOrders:n.z.number().int(),frequency:a,intervalSeconds:n.z.number().int().nonnegative(),totalAmountIn:n.z.coerce.bigint().nonnegative(),amountOut:n.z.coerce.bigint().nonnegative(),minAmountOut:n.z.coerce.bigint().nonnegative(),fees:n.z.array(f),recommendedSlippage:n.z.number().int().nonnegative(),expiredAt:n.z.number().int().nonnegative()}),m=n.z.object({address:t.EvmAddressSchema,count:n.z.number().int().nonnegative(),orders:n.z.array(d)});exports.ListRecurringOrdersResponseSchema=m,exports.RecurringQuoteResponseSchema=p,exports.RecurringSwapResponseSchema=l;
|
|
2
2
|
//# sourceMappingURL=_schema.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_schema.cjs","names":["z","RECURRING_FREQUENCY_UNITS","RecurringOrderStatus","EvmAddressSchema"],"sources":["../../../../src/transfer-service/markr/recurring/_schema.ts"],"sourcesContent":["import { z } from 'zod';\nimport { EvmAddressSchema } from '../../service-schemas';\nimport {\n RECURRING_FREQUENCY_UNITS,\n RecurringOrderStatus,\n type ListRecurringOrdersResponse,\n type RecurringFrequency,\n type RecurringFrequencyUnit,\n type RecurringOrder,\n type RecurringOrderFailure,\n type RecurringQuoteResponse,\n} from './types';\n\nconst ORDER_ID_REGEX = /^0x[0-9a-fA-F]{64}$/;\n\nexport const RecurringFrequencyUnitSchema: z.ZodType<RecurringFrequencyUnit> = z.enum(RECURRING_FREQUENCY_UNITS);\n\nexport const RecurringFrequencySchema: z.ZodType<RecurringFrequency> = z.object({\n unit: RecurringFrequencyUnitSchema,\n value: z.number().int().min(1),\n});\n\n/**\n * Closed enum — see {@link RecurringOrderStatus}. Unknown server-side values\n * (e.g. a hypothetical `'expired'`) will fail parsing loudly, which gates\n * UI behavior on an SDK update rather than silently surfacing an unhandled\n * status to the consumer.\n */\nexport const RecurringOrderStatusSchema: z.ZodType<RecurringOrderStatus> = z.enum(\n Object.values(RecurringOrderStatus) as [RecurringOrderStatus, ...RecurringOrderStatus[]],\n);\n\nexport const RecurringOrderFailureSchema: z.ZodType<RecurringOrderFailure> = z.object({\n // `nonnegative` (not `positive`) — Markr documents `executionIndex` as\n // 1-based today, but forward-compat with a future setup-time failure\n // emitting index `0` costs nothing and matches the same brittleness fix\n // applied to the status / fee-type enums.\n executionIndex: z.number().int().nonnegative(),\n reasons: z.array(z.string()),\n tryCount: z.number().int().nonnegative(),\n failedAt: z.number().int().nonnegative(),\n});\n\n/**\n * `0x`-prefixed bytes32 hex. Use `.transform()` to widen `string` into the\n * template-literal type that `RecurringOrder.orderId` declares — mirrors the\n * `EvmAddressSchema` pattern from `service-schemas.ts`.\n */\nconst OrderIdSchema: z.ZodType<`0x${string}`> = z\n .string()\n .regex(ORDER_ID_REGEX, 'Invalid recurring order id (expected 0x-prefixed bytes32)')\n .transform((value) => value as `0x${string}`);\n\n/**\n * Schema for a single `RecurringOrder` element as returned by Markr's\n * `/recurring/orders` (list) and `/recurring/orders/{orderId}/cancel`\n * endpoints.\n */\nexport const RecurringOrderSchema: z.ZodType<RecurringOrder> = z.object({\n orderId: OrderIdSchema,\n owner: EvmAddressSchema,\n chainId: z.coerce.number().int().nonnegative(),\n tokenIn: EvmAddressSchema,\n tokenOut: EvmAddressSchema,\n amount: z.coerce.bigint().nonnegative(),\n numberOfOrders: z.number().int(),\n executedOrders: z.number().int().nonnegative(),\n // `null` (or omitted) on unlimited schedules per the Markr OpenAPI spec —\n // `numberOfOrders: -1` schedules have no finite remainder to report. Finite\n // schedules carry `numberOfOrders - executedOrders` as a non-negative int.\n // `.nullish()` accepts both `null` and `undefined`; we normalize to `null`\n // by coercing `undefined` via a default transform so consumers can use a\n // simple `if (order.remainingOrders === null)` check instead of also\n // guarding for `undefined`.\n remainingOrders: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n frequency: RecurringFrequencySchema,\n totalAmountIn: z.coerce.bigint().nonnegative(),\n tryCount: z.number().int().nonnegative(),\n failures: z.array(RecurringOrderFailureSchema),\n status: RecurringOrderStatusSchema,\n createdAt: z.number().int().nonnegative(),\n // OpenAPI marks `nextExecutionAt` as optional + nullable — accept all\n // three wire shapes (number / null / omitted) and normalize to\n // `number | null` so consumers can use a single `=== null` check.\n // Same pattern as `remainingOrders` above.\n nextExecutionAt: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n // OpenAPI marks `cancelledAt` as optional + nullable; populated only when\n // `status === 'cancelled'`. Normalize to `number | null` (always present\n // in the parsed shape) for the same consumer-ergonomics reason as\n // `nextExecutionAt` / `remainingOrders`.\n cancelledAt: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n});\n\nconst RecurringQuoteFeeSchema = z.object({\n // Tolerant of unknown fee categories (forward-compat). Unlike\n // `RecurringOrderStatusSchema` (closed enum — see comment there), a new\n // fee category from Markr is safe to render as \"Other fee\" instead of\n // bricking parsing on already-shipped clients.\n type: z.enum(['gas', 'recurring', 'protocol', 'bridge', 'slippage', 'swap', 'other']).or(z.string()),\n name: z.string(),\n amount: z.coerce.bigint().nonnegative(),\n token: z.object({\n chainId: z.coerce.number().int().nonnegative(),\n address: EvmAddressSchema,\n }),\n // Docs: `extra: boolean or object` — accept both. See the equivalent\n // widening on the one-shot quote schema in `markr/_schema.ts`.\n extra: z.union([z.boolean(), z.record(z.string(), z.unknown())]).optional(),\n});\n\n/**\n * Schema for the response from Markr's `/recurring/quote` endpoint.\n */\nexport const RecurringQuoteResponseSchema: z.ZodType<RecurringQuoteResponse> = z.object({\n uuid: z.uuid(),\n chainId: z.coerce.number().int().nonnegative(),\n tokenIn: EvmAddressSchema,\n tokenOut: EvmAddressSchema,\n amount: z.coerce.bigint().nonnegative(),\n numberOfOrders: z.number().int(),\n frequency: RecurringFrequencySchema,\n intervalSeconds: z.number().int().nonnegative(),\n totalAmountIn: z.coerce.bigint().nonnegative(),\n amountOut: z.coerce.bigint().nonnegative(),\n minAmountOut: z.coerce.bigint().nonnegative(),\n fees: z.array(RecurringQuoteFeeSchema),\n recommendedSlippage: z.number().int().nonnegative(),\n expiredAt: z.number().int().nonnegative(),\n});\n\n/**\n * Schema for the response from Markr's `/recurring/orders` (list) endpoint.\n */\nexport const ListRecurringOrdersResponseSchema: z.ZodType<ListRecurringOrdersResponse> = z.object({\n address: EvmAddressSchema,\n count: z.number().int().nonnegative(),\n orders: z.array(RecurringOrderSchema),\n});\n"],"mappings":"8IAaA,MAAM,EAAiB,sBAEV,EAAkEA,EAAAA,EAAE,KAAKC,EAAAA,0BAA0B,CAEnG,EAA0DD,EAAAA,EAAE,OAAO,CAC9E,KAAM,EACN,MAAOA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAC/B,CAAC,CAQW,EAA8DA,EAAAA,EAAE,KAC3E,OAAO,OAAOE,EAAAA,qBAAqB,CACpC,CAEY,EAAgEF,EAAAA,EAAE,OAAO,CAKpF,eAAgBA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC9C,QAASA,EAAAA,EAAE,MAAMA,EAAAA,EAAE,QAAQ,CAAC,CAC5B,SAAUA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CACxC,SAAUA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CACzC,CAAC,CAOI,EAA0CA,EAAAA,EAC7C,QAAQ,CACR,MAAM,EAAgB,4DAA4D,CAClF,UAAW,GAAU,EAAuB,CAOlC,EAAkDA,EAA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EAAAA,EAAE,MAAM,CAACA,EAAAA,EAAE,SAAS,CAAEA,EAAAA,EAAE,OAAOA,EAAAA,EAAE,QAAQ,CAAEA,EAAAA,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,UAAU,CAC5E,CAAC,CAKW,EAAkEA,EAAAA,EAAE,OAAO,CACtF,KAAMA,EAAAA,EAAE,MAAM,CACd,QAASA,EAAAA,EAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC9C,QAASG,EAAAA,iBACT,SAAUA,EAAAA,iBACV,OAAQH,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CACvC,eAAgBA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAChC,UAAW,EACX,gBAAiBA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC/C,cAAeA,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CAC9C,UAAWA,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CAC1C,aAAcA,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CAC7C,KAAMA,EAAAA,EAAE,MAAM,EAAwB,CACtC,oBAAqBA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CACnD,UAAWA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC1C,CAAC,CAKW,EAA4EA,EAAAA,EAAE,OAAO,CAChG,QAASG,EAAAA,iBACT,MAAOH,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CACrC,OAAQA,EAAAA,EAAE,MAAM,EAAqB,CACtC,CAAC"}
|
|
1
|
+
{"version":3,"file":"_schema.cjs","names":["z","RECURRING_FREQUENCY_UNITS","RecurringOrderStatus","EvmAddressSchema","HexSchema"],"sources":["../../../../src/transfer-service/markr/recurring/_schema.ts"],"sourcesContent":["import { z } from 'zod';\nimport { EvmAddressSchema, HexSchema } from '../../service-schemas';\nimport {\n RECURRING_FREQUENCY_UNITS,\n RecurringOrderStatus,\n type ListRecurringOrdersResponse,\n type RecurringFrequency,\n type RecurringFrequencyUnit,\n type RecurringOrder,\n type RecurringOrderFailure,\n type RecurringQuoteResponse,\n type RecurringSwapResponse,\n type RecurringSwapTransaction,\n} from './types';\n\nconst ORDER_ID_REGEX = /^0x[0-9a-fA-F]{64}$/;\n\nexport const RecurringFrequencyUnitSchema: z.ZodType<RecurringFrequencyUnit> = z.enum(RECURRING_FREQUENCY_UNITS);\n\nexport const RecurringFrequencySchema: z.ZodType<RecurringFrequency> = z.object({\n unit: RecurringFrequencyUnitSchema,\n value: z.number().int().min(1),\n});\n\n/**\n * Closed enum — see {@link RecurringOrderStatus}. Unknown server-side values\n * (e.g. a hypothetical `'expired'`) will fail parsing loudly, which gates\n * UI behavior on an SDK update rather than silently surfacing an unhandled\n * status to the consumer.\n */\nexport const RecurringOrderStatusSchema: z.ZodType<RecurringOrderStatus> = z.enum(\n Object.values(RecurringOrderStatus) as [RecurringOrderStatus, ...RecurringOrderStatus[]],\n);\n\nexport const RecurringOrderFailureSchema: z.ZodType<RecurringOrderFailure> = z.object({\n // `nonnegative` (not `positive`) — Markr documents `executionIndex` as\n // 1-based today, but forward-compat with a future setup-time failure\n // emitting index `0` costs nothing and matches the same brittleness fix\n // applied to the status / fee-type enums.\n executionIndex: z.number().int().nonnegative(),\n reasons: z.array(z.string()),\n tryCount: z.number().int().nonnegative(),\n failedAt: z.number().int().nonnegative(),\n});\n\n/**\n * Schema for a single step in {@link RecurringSwapResponse}. Markr's\n * `/recurring/swap` doc documents two `type` values; we keep this as a\n * closed enum so an unrecognized step (e.g. a hypothetical future\n * `'approve'`) fails parsing loudly — the SDK builds the approval itself\n * and a server-side change to that contract should gate on an SDK update.\n */\nexport const RecurringSwapTransactionSchema: z.ZodType<RecurringSwapTransaction> = z.object({\n type: z.enum(['wrap', 'createOrder']),\n to: EvmAddressSchema,\n data: HexSchema,\n value: z.coerce.bigint().nonnegative(),\n});\n\n/**\n * Response schema for Markr's `/recurring/swap`. Always an array, ordered;\n * the consumer signs each entry in array order. See\n * {@link RecurringSwapResponse}.\n */\nexport const RecurringSwapResponseSchema: z.ZodType<RecurringSwapResponse> = z.array(RecurringSwapTransactionSchema);\n\n/**\n * `0x`-prefixed bytes32 hex. Use `.transform()` to widen `string` into the\n * template-literal type that `RecurringOrder.orderId` declares — mirrors the\n * `EvmAddressSchema` pattern from `service-schemas.ts`.\n */\nconst OrderIdSchema: z.ZodType<`0x${string}`> = z\n .string()\n .regex(ORDER_ID_REGEX, 'Invalid recurring order id (expected 0x-prefixed bytes32)')\n .transform((value) => value as `0x${string}`);\n\n/**\n * Schema for a single `RecurringOrder` element as returned by Markr's\n * `/recurring/orders` (list) and `/recurring/orders/{orderId}/cancel`\n * endpoints.\n */\nexport const RecurringOrderSchema: z.ZodType<RecurringOrder> = z.object({\n orderId: OrderIdSchema,\n owner: EvmAddressSchema,\n chainId: z.coerce.number().int().nonnegative(),\n tokenIn: EvmAddressSchema,\n tokenOut: EvmAddressSchema,\n amount: z.coerce.bigint().nonnegative(),\n numberOfOrders: z.number().int(),\n executedOrders: z.number().int().nonnegative(),\n // `null` (or omitted) on unlimited schedules per the Markr OpenAPI spec —\n // `numberOfOrders: -1` schedules have no finite remainder to report. Finite\n // schedules carry `numberOfOrders - executedOrders` as a non-negative int.\n // `.nullish()` accepts both `null` and `undefined`; we normalize to `null`\n // by coercing `undefined` via a default transform so consumers can use a\n // simple `if (order.remainingOrders === null)` check instead of also\n // guarding for `undefined`.\n remainingOrders: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n frequency: RecurringFrequencySchema,\n totalAmountIn: z.coerce.bigint().nonnegative(),\n tryCount: z.number().int().nonnegative(),\n failures: z.array(RecurringOrderFailureSchema),\n status: RecurringOrderStatusSchema,\n createdAt: z.number().int().nonnegative(),\n // OpenAPI marks `nextExecutionAt` as optional + nullable — accept all\n // three wire shapes (number / null / omitted) and normalize to\n // `number | null` so consumers can use a single `=== null` check.\n // Same pattern as `remainingOrders` above.\n nextExecutionAt: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n // OpenAPI marks `cancelledAt` as optional + nullable; populated only when\n // `status === 'cancelled'`. Normalize to `number | null` (always present\n // in the parsed shape) for the same consumer-ergonomics reason as\n // `nextExecutionAt` / `remainingOrders`.\n cancelledAt: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n});\n\nconst RecurringQuoteFeeSchema = z.object({\n // Tolerant of unknown fee categories (forward-compat). Unlike\n // `RecurringOrderStatusSchema` (closed enum — see comment there), a new\n // fee category from Markr is safe to render as \"Other fee\" instead of\n // bricking parsing on already-shipped clients.\n type: z.enum(['gas', 'recurring', 'protocol', 'bridge', 'slippage', 'swap', 'other']).or(z.string()),\n name: z.string(),\n amount: z.coerce.bigint().nonnegative(),\n token: z.object({\n chainId: z.coerce.number().int().nonnegative(),\n address: EvmAddressSchema,\n }),\n // Docs: `extra: boolean or object` — accept both. See the equivalent\n // widening on the one-shot quote schema in `markr/_schema.ts`.\n extra: z.union([z.boolean(), z.record(z.string(), z.unknown())]).optional(),\n});\n\n/**\n * Schema for the response from Markr's `/recurring/quote` endpoint.\n */\nexport const RecurringQuoteResponseSchema: z.ZodType<RecurringQuoteResponse> = z.object({\n uuid: z.uuid(),\n chainId: z.coerce.number().int().nonnegative(),\n tokenIn: EvmAddressSchema,\n tokenOut: EvmAddressSchema,\n amount: z.coerce.bigint().nonnegative(),\n numberOfOrders: z.number().int(),\n frequency: RecurringFrequencySchema,\n intervalSeconds: z.number().int().nonnegative(),\n totalAmountIn: z.coerce.bigint().nonnegative(),\n amountOut: z.coerce.bigint().nonnegative(),\n minAmountOut: z.coerce.bigint().nonnegative(),\n fees: z.array(RecurringQuoteFeeSchema),\n recommendedSlippage: z.number().int().nonnegative(),\n expiredAt: z.number().int().nonnegative(),\n});\n\n/**\n * Schema for the response from Markr's `/recurring/orders` (list) endpoint.\n */\nexport const ListRecurringOrdersResponseSchema: z.ZodType<ListRecurringOrdersResponse> = z.object({\n address: EvmAddressSchema,\n count: z.number().int().nonnegative(),\n orders: z.array(RecurringOrderSchema),\n});\n"],"mappings":"8IAeA,MAAM,EAAiB,sBAEV,EAAkEA,EAAAA,EAAE,KAAKC,EAAAA,0BAA0B,CAEnG,EAA0DD,EAAAA,EAAE,OAAO,CAC9E,KAAM,EACN,MAAOA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,CAC/B,CAAC,CAQW,EAA8DA,EAAAA,EAAE,KAC3E,OAAO,OAAOE,EAAAA,qBAAqB,CACpC,CAEY,EAAgEF,EAAAA,EAAE,OAAO,CAKpF,eAAgBA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC9C,QAASA,EAAAA,EAAE,MAAMA,EAAAA,EAAE,QAAQ,CAAC,CAC5B,SAAUA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CACxC,SAAUA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CACzC,CAAC,CASW,EAAsEA,EAAAA,EAAE,OAAO,CAC1F,KAAMA,EAAAA,EAAE,KAAK,CAAC,OAAQ,cAAc,CAAC,CACrC,GAAIG,EAAAA,iBACJ,KAAMC,EAAAA,UACN,MAAOJ,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CACvC,CAAC,CAOW,EAAgEA,EAAAA,EAAE,MAAM,EAA+B,CAO9G,EAA0CA,EAAAA,EAC7C,QAAQ,CACR,MAAM,EAAgB,4DAA4D,CAClF,UAAW,GAAU,EAAuB,CAOlC,EAAkDA,EAAAA,EAAE,OAAO,CACtE,QAAS,EACT,MAAOG,EAAAA,iBACP,QAASH,EAAAA,EAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC9C,QAASG,EAAAA,iBACT,SAAUA,EAAAA,iBACV,OAAQH,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CACvC,eAAgBA,E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AAE,MAAM,CACd,QAASA,EAAAA,EAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC9C,QAASG,EAAAA,iBACT,SAAUA,EAAAA,iBACV,OAAQH,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CACvC,eAAgBA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAChC,UAAW,EACX,gBAAiBA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC/C,cAAeA,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CAC9C,UAAWA,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CAC1C,aAAcA,EAAAA,EAAE,OAAO,QAAQ,CAAC,aAAa,CAC7C,KAAMA,EAAAA,EAAE,MAAM,EAAwB,CACtC,oBAAqBA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CACnD,UAAWA,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CAC1C,CAAC,CAKW,EAA4EA,EAAAA,EAAE,OAAO,CAChG,QAASG,EAAAA,iBACT,MAAOH,EAAAA,EAAE,QAAQ,CAAC,KAAK,CAAC,aAAa,CACrC,OAAQA,EAAAA,EAAE,MAAM,EAAqB,CACtC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{RECURRING_FREQUENCY_UNITS as e,RecurringOrderStatus as t}from"./types.js";import{EvmAddressSchema as n}from"../../service-schemas.js";import{z as
|
|
1
|
+
import{RECURRING_FREQUENCY_UNITS as e,RecurringOrderStatus as t}from"./types.js";import{EvmAddressSchema as n,HexSchema as r}from"../../service-schemas.js";import{z as i}from"zod";const a=/^0x[0-9a-fA-F]{64}$/,o=i.enum(e),s=i.object({unit:o,value:i.number().int().min(1)}),c=i.enum(Object.values(t)),l=i.object({executionIndex:i.number().int().nonnegative(),reasons:i.array(i.string()),tryCount:i.number().int().nonnegative(),failedAt:i.number().int().nonnegative()}),u=i.object({type:i.enum([`wrap`,`createOrder`]),to:n,data:r,value:i.coerce.bigint().nonnegative()}),d=i.array(u),f=i.string().regex(a,`Invalid recurring order id (expected 0x-prefixed bytes32)`).transform(e=>e),p=i.object({orderId:f,owner:n,chainId:i.coerce.number().int().nonnegative(),tokenIn:n,tokenOut:n,amount:i.coerce.bigint().nonnegative(),numberOfOrders:i.number().int(),executedOrders:i.number().int().nonnegative(),remainingOrders:i.number().int().nonnegative().nullish().transform(e=>e??null),frequency:s,totalAmountIn:i.coerce.bigint().nonnegative(),tryCount:i.number().int().nonnegative(),failures:i.array(l),status:c,createdAt:i.number().int().nonnegative(),nextExecutionAt:i.number().int().nonnegative().nullish().transform(e=>e??null),cancelledAt:i.number().int().nonnegative().nullish().transform(e=>e??null)}),m=i.object({type:i.enum([`gas`,`recurring`,`protocol`,`bridge`,`slippage`,`swap`,`other`]).or(i.string()),name:i.string(),amount:i.coerce.bigint().nonnegative(),token:i.object({chainId:i.coerce.number().int().nonnegative(),address:n}),extra:i.union([i.boolean(),i.record(i.string(),i.unknown())]).optional()}),h=i.object({uuid:i.uuid(),chainId:i.coerce.number().int().nonnegative(),tokenIn:n,tokenOut:n,amount:i.coerce.bigint().nonnegative(),numberOfOrders:i.number().int(),frequency:s,intervalSeconds:i.number().int().nonnegative(),totalAmountIn:i.coerce.bigint().nonnegative(),amountOut:i.coerce.bigint().nonnegative(),minAmountOut:i.coerce.bigint().nonnegative(),fees:i.array(m),recommendedSlippage:i.number().int().nonnegative(),expiredAt:i.number().int().nonnegative()}),g=i.object({address:n,count:i.number().int().nonnegative(),orders:i.array(p)});export{g as ListRecurringOrdersResponseSchema,h as RecurringQuoteResponseSchema,d as RecurringSwapResponseSchema};
|
|
2
2
|
//# sourceMappingURL=_schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_schema.js","names":[],"sources":["../../../../src/transfer-service/markr/recurring/_schema.ts"],"sourcesContent":["import { z } from 'zod';\nimport { EvmAddressSchema } from '../../service-schemas';\nimport {\n RECURRING_FREQUENCY_UNITS,\n RecurringOrderStatus,\n type ListRecurringOrdersResponse,\n type RecurringFrequency,\n type RecurringFrequencyUnit,\n type RecurringOrder,\n type RecurringOrderFailure,\n type RecurringQuoteResponse,\n} from './types';\n\nconst ORDER_ID_REGEX = /^0x[0-9a-fA-F]{64}$/;\n\nexport const RecurringFrequencyUnitSchema: z.ZodType<RecurringFrequencyUnit> = z.enum(RECURRING_FREQUENCY_UNITS);\n\nexport const RecurringFrequencySchema: z.ZodType<RecurringFrequency> = z.object({\n unit: RecurringFrequencyUnitSchema,\n value: z.number().int().min(1),\n});\n\n/**\n * Closed enum — see {@link RecurringOrderStatus}. Unknown server-side values\n * (e.g. a hypothetical `'expired'`) will fail parsing loudly, which gates\n * UI behavior on an SDK update rather than silently surfacing an unhandled\n * status to the consumer.\n */\nexport const RecurringOrderStatusSchema: z.ZodType<RecurringOrderStatus> = z.enum(\n Object.values(RecurringOrderStatus) as [RecurringOrderStatus, ...RecurringOrderStatus[]],\n);\n\nexport const RecurringOrderFailureSchema: z.ZodType<RecurringOrderFailure> = z.object({\n // `nonnegative` (not `positive`) — Markr documents `executionIndex` as\n // 1-based today, but forward-compat with a future setup-time failure\n // emitting index `0` costs nothing and matches the same brittleness fix\n // applied to the status / fee-type enums.\n executionIndex: z.number().int().nonnegative(),\n reasons: z.array(z.string()),\n tryCount: z.number().int().nonnegative(),\n failedAt: z.number().int().nonnegative(),\n});\n\n/**\n * `0x`-prefixed bytes32 hex. Use `.transform()` to widen `string` into the\n * template-literal type that `RecurringOrder.orderId` declares — mirrors the\n * `EvmAddressSchema` pattern from `service-schemas.ts`.\n */\nconst OrderIdSchema: z.ZodType<`0x${string}`> = z\n .string()\n .regex(ORDER_ID_REGEX, 'Invalid recurring order id (expected 0x-prefixed bytes32)')\n .transform((value) => value as `0x${string}`);\n\n/**\n * Schema for a single `RecurringOrder` element as returned by Markr's\n * `/recurring/orders` (list) and `/recurring/orders/{orderId}/cancel`\n * endpoints.\n */\nexport const RecurringOrderSchema: z.ZodType<RecurringOrder> = z.object({\n orderId: OrderIdSchema,\n owner: EvmAddressSchema,\n chainId: z.coerce.number().int().nonnegative(),\n tokenIn: EvmAddressSchema,\n tokenOut: EvmAddressSchema,\n amount: z.coerce.bigint().nonnegative(),\n numberOfOrders: z.number().int(),\n executedOrders: z.number().int().nonnegative(),\n // `null` (or omitted) on unlimited schedules per the Markr OpenAPI spec —\n // `numberOfOrders: -1` schedules have no finite remainder to report. Finite\n // schedules carry `numberOfOrders - executedOrders` as a non-negative int.\n // `.nullish()` accepts both `null` and `undefined`; we normalize to `null`\n // by coercing `undefined` via a default transform so consumers can use a\n // simple `if (order.remainingOrders === null)` check instead of also\n // guarding for `undefined`.\n remainingOrders: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n frequency: RecurringFrequencySchema,\n totalAmountIn: z.coerce.bigint().nonnegative(),\n tryCount: z.number().int().nonnegative(),\n failures: z.array(RecurringOrderFailureSchema),\n status: RecurringOrderStatusSchema,\n createdAt: z.number().int().nonnegative(),\n // OpenAPI marks `nextExecutionAt` as optional + nullable — accept all\n // three wire shapes (number / null / omitted) and normalize to\n // `number | null` so consumers can use a single `=== null` check.\n // Same pattern as `remainingOrders` above.\n nextExecutionAt: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n // OpenAPI marks `cancelledAt` as optional + nullable; populated only when\n // `status === 'cancelled'`. Normalize to `number | null` (always present\n // in the parsed shape) for the same consumer-ergonomics reason as\n // `nextExecutionAt` / `remainingOrders`.\n cancelledAt: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n});\n\nconst RecurringQuoteFeeSchema = z.object({\n // Tolerant of unknown fee categories (forward-compat). Unlike\n // `RecurringOrderStatusSchema` (closed enum — see comment there), a new\n // fee category from Markr is safe to render as \"Other fee\" instead of\n // bricking parsing on already-shipped clients.\n type: z.enum(['gas', 'recurring', 'protocol', 'bridge', 'slippage', 'swap', 'other']).or(z.string()),\n name: z.string(),\n amount: z.coerce.bigint().nonnegative(),\n token: z.object({\n chainId: z.coerce.number().int().nonnegative(),\n address: EvmAddressSchema,\n }),\n // Docs: `extra: boolean or object` — accept both. See the equivalent\n // widening on the one-shot quote schema in `markr/_schema.ts`.\n extra: z.union([z.boolean(), z.record(z.string(), z.unknown())]).optional(),\n});\n\n/**\n * Schema for the response from Markr's `/recurring/quote` endpoint.\n */\nexport const RecurringQuoteResponseSchema: z.ZodType<RecurringQuoteResponse> = z.object({\n uuid: z.uuid(),\n chainId: z.coerce.number().int().nonnegative(),\n tokenIn: EvmAddressSchema,\n tokenOut: EvmAddressSchema,\n amount: z.coerce.bigint().nonnegative(),\n numberOfOrders: z.number().int(),\n frequency: RecurringFrequencySchema,\n intervalSeconds: z.number().int().nonnegative(),\n totalAmountIn: z.coerce.bigint().nonnegative(),\n amountOut: z.coerce.bigint().nonnegative(),\n minAmountOut: z.coerce.bigint().nonnegative(),\n fees: z.array(RecurringQuoteFeeSchema),\n recommendedSlippage: z.number().int().nonnegative(),\n expiredAt: z.number().int().nonnegative(),\n});\n\n/**\n * Schema for the response from Markr's `/recurring/orders` (list) endpoint.\n */\nexport const ListRecurringOrdersResponseSchema: z.ZodType<ListRecurringOrdersResponse> = z.object({\n address: EvmAddressSchema,\n count: z.number().int().nonnegative(),\n orders: z.array(RecurringOrderSchema),\n});\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"_schema.js","names":[],"sources":["../../../../src/transfer-service/markr/recurring/_schema.ts"],"sourcesContent":["import { z } from 'zod';\nimport { EvmAddressSchema, HexSchema } from '../../service-schemas';\nimport {\n RECURRING_FREQUENCY_UNITS,\n RecurringOrderStatus,\n type ListRecurringOrdersResponse,\n type RecurringFrequency,\n type RecurringFrequencyUnit,\n type RecurringOrder,\n type RecurringOrderFailure,\n type RecurringQuoteResponse,\n type RecurringSwapResponse,\n type RecurringSwapTransaction,\n} from './types';\n\nconst ORDER_ID_REGEX = /^0x[0-9a-fA-F]{64}$/;\n\nexport const RecurringFrequencyUnitSchema: z.ZodType<RecurringFrequencyUnit> = z.enum(RECURRING_FREQUENCY_UNITS);\n\nexport const RecurringFrequencySchema: z.ZodType<RecurringFrequency> = z.object({\n unit: RecurringFrequencyUnitSchema,\n value: z.number().int().min(1),\n});\n\n/**\n * Closed enum — see {@link RecurringOrderStatus}. Unknown server-side values\n * (e.g. a hypothetical `'expired'`) will fail parsing loudly, which gates\n * UI behavior on an SDK update rather than silently surfacing an unhandled\n * status to the consumer.\n */\nexport const RecurringOrderStatusSchema: z.ZodType<RecurringOrderStatus> = z.enum(\n Object.values(RecurringOrderStatus) as [RecurringOrderStatus, ...RecurringOrderStatus[]],\n);\n\nexport const RecurringOrderFailureSchema: z.ZodType<RecurringOrderFailure> = z.object({\n // `nonnegative` (not `positive`) — Markr documents `executionIndex` as\n // 1-based today, but forward-compat with a future setup-time failure\n // emitting index `0` costs nothing and matches the same brittleness fix\n // applied to the status / fee-type enums.\n executionIndex: z.number().int().nonnegative(),\n reasons: z.array(z.string()),\n tryCount: z.number().int().nonnegative(),\n failedAt: z.number().int().nonnegative(),\n});\n\n/**\n * Schema for a single step in {@link RecurringSwapResponse}. Markr's\n * `/recurring/swap` doc documents two `type` values; we keep this as a\n * closed enum so an unrecognized step (e.g. a hypothetical future\n * `'approve'`) fails parsing loudly — the SDK builds the approval itself\n * and a server-side change to that contract should gate on an SDK update.\n */\nexport const RecurringSwapTransactionSchema: z.ZodType<RecurringSwapTransaction> = z.object({\n type: z.enum(['wrap', 'createOrder']),\n to: EvmAddressSchema,\n data: HexSchema,\n value: z.coerce.bigint().nonnegative(),\n});\n\n/**\n * Response schema for Markr's `/recurring/swap`. Always an array, ordered;\n * the consumer signs each entry in array order. See\n * {@link RecurringSwapResponse}.\n */\nexport const RecurringSwapResponseSchema: z.ZodType<RecurringSwapResponse> = z.array(RecurringSwapTransactionSchema);\n\n/**\n * `0x`-prefixed bytes32 hex. Use `.transform()` to widen `string` into the\n * template-literal type that `RecurringOrder.orderId` declares — mirrors the\n * `EvmAddressSchema` pattern from `service-schemas.ts`.\n */\nconst OrderIdSchema: z.ZodType<`0x${string}`> = z\n .string()\n .regex(ORDER_ID_REGEX, 'Invalid recurring order id (expected 0x-prefixed bytes32)')\n .transform((value) => value as `0x${string}`);\n\n/**\n * Schema for a single `RecurringOrder` element as returned by Markr's\n * `/recurring/orders` (list) and `/recurring/orders/{orderId}/cancel`\n * endpoints.\n */\nexport const RecurringOrderSchema: z.ZodType<RecurringOrder> = z.object({\n orderId: OrderIdSchema,\n owner: EvmAddressSchema,\n chainId: z.coerce.number().int().nonnegative(),\n tokenIn: EvmAddressSchema,\n tokenOut: EvmAddressSchema,\n amount: z.coerce.bigint().nonnegative(),\n numberOfOrders: z.number().int(),\n executedOrders: z.number().int().nonnegative(),\n // `null` (or omitted) on unlimited schedules per the Markr OpenAPI spec —\n // `numberOfOrders: -1` schedules have no finite remainder to report. Finite\n // schedules carry `numberOfOrders - executedOrders` as a non-negative int.\n // `.nullish()` accepts both `null` and `undefined`; we normalize to `null`\n // by coercing `undefined` via a default transform so consumers can use a\n // simple `if (order.remainingOrders === null)` check instead of also\n // guarding for `undefined`.\n remainingOrders: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n frequency: RecurringFrequencySchema,\n totalAmountIn: z.coerce.bigint().nonnegative(),\n tryCount: z.number().int().nonnegative(),\n failures: z.array(RecurringOrderFailureSchema),\n status: RecurringOrderStatusSchema,\n createdAt: z.number().int().nonnegative(),\n // OpenAPI marks `nextExecutionAt` as optional + nullable — accept all\n // three wire shapes (number / null / omitted) and normalize to\n // `number | null` so consumers can use a single `=== null` check.\n // Same pattern as `remainingOrders` above.\n nextExecutionAt: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n // OpenAPI marks `cancelledAt` as optional + nullable; populated only when\n // `status === 'cancelled'`. Normalize to `number | null` (always present\n // in the parsed shape) for the same consumer-ergonomics reason as\n // `nextExecutionAt` / `remainingOrders`.\n cancelledAt: z\n .number()\n .int()\n .nonnegative()\n .nullish()\n .transform((value) => value ?? null),\n});\n\nconst RecurringQuoteFeeSchema = z.object({\n // Tolerant of unknown fee categories (forward-compat). Unlike\n // `RecurringOrderStatusSchema` (closed enum — see comment there), a new\n // fee category from Markr is safe to render as \"Other fee\" instead of\n // bricking parsing on already-shipped clients.\n type: z.enum(['gas', 'recurring', 'protocol', 'bridge', 'slippage', 'swap', 'other']).or(z.string()),\n name: z.string(),\n amount: z.coerce.bigint().nonnegative(),\n token: z.object({\n chainId: z.coerce.number().int().nonnegative(),\n address: EvmAddressSchema,\n }),\n // Docs: `extra: boolean or object` — accept both. See the equivalent\n // widening on the one-shot quote schema in `markr/_schema.ts`.\n extra: z.union([z.boolean(), z.record(z.string(), z.unknown())]).optional(),\n});\n\n/**\n * Schema for the response from Markr's `/recurring/quote` endpoint.\n */\nexport const RecurringQuoteResponseSchema: z.ZodType<RecurringQuoteResponse> = z.object({\n uuid: z.uuid(),\n chainId: z.coerce.number().int().nonnegative(),\n tokenIn: EvmAddressSchema,\n tokenOut: EvmAddressSchema,\n amount: z.coerce.bigint().nonnegative(),\n numberOfOrders: z.number().int(),\n frequency: RecurringFrequencySchema,\n intervalSeconds: z.number().int().nonnegative(),\n totalAmountIn: z.coerce.bigint().nonnegative(),\n amountOut: z.coerce.bigint().nonnegative(),\n minAmountOut: z.coerce.bigint().nonnegative(),\n fees: z.array(RecurringQuoteFeeSchema),\n recommendedSlippage: z.number().int().nonnegative(),\n expiredAt: z.number().int().nonnegative(),\n});\n\n/**\n * Schema for the response from Markr's `/recurring/orders` (list) endpoint.\n */\nexport const ListRecurringOrdersResponseSchema: z.ZodType<ListRecurringOrdersResponse> = z.object({\n address: EvmAddressSchema,\n count: z.number().int().nonnegative(),\n orders: z.array(RecurringOrderSchema),\n});\n"],"mappings":"oLAeA,MAAM,EAAiB,sBAEV,EAAkE,EAAE,KAAK,EAA0B,CAEnG,EAA0D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CACrC,OAAQ,EAAE,MAAM,EAAqB,CACtC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=[`minute`,`hour`,`day`,`week`,`month`];let t=function(e){return e.Active=`active`,e.Completed=`completed`,e.Cancelled=`cancelled`,e.Paused=`paused`,e}({}),n=function(e){return e.CrossChain=`cross-chain`,e.UnsupportedSourceChain=`unsupported-source-chain`,e.UnsupportedToken=`unsupported-token`,e.NoEvmAddress=`no-evm-address`,e.
|
|
1
|
+
const e=[`minute`,`hour`,`day`,`week`,`month`];let t=function(e){return e.Active=`active`,e.Completed=`completed`,e.Cancelled=`cancelled`,e.Paused=`paused`,e}({}),n=function(e){return e.CrossChain=`cross-chain`,e.UnsupportedSourceChain=`unsupported-source-chain`,e.UnsupportedToken=`unsupported-token`,e.NoEvmAddress=`no-evm-address`,e.NativeToWrappedNative=`native-to-wrapped-native`,e}({});exports.RECURRING_FREQUENCY_UNITS=e,exports.RECURRING_UNLIMITED_ORDERS_SENTINEL=-1,exports.RecurringEligibilityReason=n,exports.RecurringOrderStatus=t;
|
|
2
2
|
//# sourceMappingURL=types.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","names":[],"sources":["../../../../src/transfer-service/markr/recurring/types.ts"],"sourcesContent":["import type { Address as EvmAddress } from 'viem';\nimport type { Chain } from '../../../types/chain';\nimport type { GasSettings } from '../../../types/service';\nimport type { Hex } from '../../../types/signer';\n\n/**\n * Frequency units accepted by Markr's `/recurring/quote` and `/recurring/orders` endpoints.\n *\n * @see https://orchestrator-docs.markr.io/#/paths/~1recurring~1quote/post\n */\nexport const RECURRING_FREQUENCY_UNITS = ['minute', 'hour', 'day', 'week', 'month'] as const;\n\nexport type RecurringFrequencyUnit = (typeof RECURRING_FREQUENCY_UNITS)[number];\n\nexport interface RecurringFrequency {\n unit: RecurringFrequencyUnit;\n /**\n * Integer in `[1, 365]` (server-enforced upper bound). `validateFrequency`\n * surfaces violations as `{ ok: false, reason: 'invalid-value' }`.\n */\n value: number;\n}\n\n/**\n * Markr's \"unlimited orders\" sentinel. Sent to the server as `-1`, which the\n * router expands to `uint256` max on-chain. Callers can also pass `Infinity`\n * to {@link RecurringQuoteParams.numberOfOrders} for the same effect; the API\n * helpers translate to `-1` at the wire boundary.\n */\nexport const RECURRING_UNLIMITED_ORDERS_SENTINEL = -1;\n\n/**\n * Status values emitted by Markr for a recurring schedule. Treated as a\n * closed set — if Markr ever adds a new value server-side, the schema\n * will reject it loudly so the SDK update gates rendering changes\n * (instead of silently passing an unhandled state through to the UI).\n *\n * Mirrors the existing `TransferSignatureReason` enum pattern in\n * `constants.ts`: PascalCase members with kebab/lowercase wire values.\n */\nexport enum RecurringOrderStatus {\n Active = 'active',\n Completed = 'completed',\n Cancelled = 'cancelled',\n Paused = 'paused',\n}\n\nexport interface RecurringOrderFailure {\n /** 1-based index of the failed scheduled swap. */\n executionIndex: number;\n /** Reason strings supplied by the orchestrator (e.g. `\"Slippage tolerance exceeded\"`). */\n reasons: ReadonlyArray<string>;\n /** On-chain attempts before the execution was marked failed. */\n tryCount: number;\n /** Unix seconds. */\n failedAt: number;\n}\n\n/**\n * Server-side recurring-swap order returned by `GET /recurring/orders` and\n * `POST /recurring/orders/{orderId}/cancel`.\n *\n * @see https://orchestrator-docs.markr.io/#/Recurring%20Swaps\n */\nexport interface RecurringOrder {\n /**\n * bytes32 hex (`0x` + 64 hex chars). Used as the path param for cancellation.\n * Typed as a template-literal `0x`-prefixed string to catch the obvious\n * \"I forgot the `0x`\" mistake at compile time; the wire-level regex check\n * (in `markrCancelRecurringOrder`) enforces the full bytes32 shape.\n */\n orderId: `0x${string}`;\n /** EVM wallet that created the schedule. */\n owner: EvmAddress;\n chainId: number;\n tokenIn: EvmAddress;\n tokenOut: EvmAddress;\n /** Per-order input amount, in `tokenIn`'s smallest unit. */\n amount: bigint;\n /** -1 when unlimited; otherwise a positive integer (server-clamped to ≤ 365). */\n numberOfOrders: number;\n executedOrders: number;\n /**\n * `numberOfOrders - executedOrders` on finite schedules. `null` on\n * unlimited schedules (`numberOfOrders === -1`) — they have no finite\n * remainder to report. Per the Markr OpenAPI spec the field is\n * nullable; the schema also normalizes `undefined` to `null` so a\n * `=== null` check is sufficient.\n */\n remainingOrders: number | null;\n frequency: RecurringFrequency;\n /** `amount × numberOfOrders` — the ERC-20 allowance granted at setup. */\n totalAmountIn: bigint;\n /** Retry count for the *next* pending execution. `0` when none is pending. */\n tryCount: number;\n /** History of failed `executionIndex` values, newest last. */\n failures: ReadonlyArray<RecurringOrderFailure>;\n status: RecurringOrderStatus;\n /** Unix seconds. */\n createdAt: number;\n /**\n * Unix seconds. `null` once the schedule is completed / cancelled /\n * inactive. Per the Markr OpenAPI spec this field is optional + nullable;\n * the schema normalizes an omitted-field response to `null` so consumers\n * can branch on a single `=== null` check.\n */\n nextExecutionAt: number | null;\n /**\n * Unix seconds when the order was cancelled; `null` otherwise. Populated\n * with a number when `status === 'cancelled'`. Per the Markr OpenAPI spec\n * this field is optional + nullable; the schema normalizes both wire\n * shapes (`null` and omitted) to `null` for consumer ergonomics.\n */\n cancelledAt: number | null;\n}\n\n/**\n * Known fee types emitted by Markr today. Open at runtime — the schema\n * tolerates unknown values so a new fee category from the orchestrator doesn't\n * fail quote parsing. See {@link RecurringOrderStatus} for the widening\n * pattern.\n */\nexport type RecurringQuoteFeeType =\n | 'gas'\n | 'recurring'\n | 'protocol'\n | 'bridge'\n | 'slippage'\n | 'swap'\n | 'other'\n // See `RecurringOrderStatus` for why `Record<never, never>` replaces `{}`.\n | (string & Record<never, never>);\n\nexport interface RecurringQuoteFee {\n type: RecurringQuoteFeeType;\n name: string;\n amount: bigint;\n token: { chainId: number; address: EvmAddress };\n /**\n * Docs document `extra` as `boolean or object`. The boolean form is the\n * legacy \"additive one-time charge\" flag (e.g. the one-time native\n * schedule fee with `type: 'recurring'`); the object form is reserved\n * for future structured metadata. Consumers should treat any truthy\n * value as \"additive — balance-check separately.\"\n */\n extra?: boolean | Record<string, unknown>;\n}\n\nexport interface RecurringQuoteResponse {\n uuid: string;\n chainId: number;\n tokenIn: EvmAddress;\n tokenOut: EvmAddress;\n /** Per-order input. */\n amount: bigint;\n /** Server-side clamped value (may be 365 if the request was unlimited). */\n numberOfOrders: number;\n frequency: RecurringFrequency;\n /** Server-derived from `frequency`. */\n intervalSeconds: number;\n /** `amount × numberOfOrders` — the ERC-20 allowance the caller must grant. */\n totalAmountIn: bigint;\n /** First-fill output estimate. */\n amountOut: bigint;\n /** First-fill `minAmountOut` (slippage applied). */\n minAmountOut: bigint;\n fees: ReadonlyArray<RecurringQuoteFee>;\n /** Basis points. */\n recommendedSlippage: number;\n /** Unix seconds. */\n expiredAt: number;\n}\n\nexport interface RecurringQuoteParams {\n appId: string;\n chainId: number;\n tokenIn: EvmAddress;\n tokenInDecimals: number;\n tokenOut: EvmAddress;\n tokenOutDecimals: number;\n /**\n * Per-order input in smallest unit. `bigint` only — matches the rest of the\n * SDK's internal amount types (response amounts, `Quote.amountIn`, etc.).\n * Callers holding a decimal string should coerce with `BigInt(s)` at the\n * call site.\n */\n amount: bigint;\n /**\n * Number of orders. Accepts:\n * - `Infinity` or `-1` — translated to the unlimited sentinel (`-1`) on the wire.\n * - Integer in `[2, 365]` — Markr's documented finite bound.\n *\n * Anything else (`NaN`, `0`, `1`, negatives other than `-1`, non-integers,\n * values > 365) throws `InvalidParamsError` at the SDK boundary so a\n * misbehaving form parse (`parseInt('')` → `NaN`, or a stale \"minimum is 1\"\n * assumption) can't silently become an unlimited schedule or a guaranteed\n * server-side rejection.\n */\n numberOfOrders: number;\n frequency: RecurringFrequency;\n /** Basis points (matches `/quote` semantics). */\n slippage?: number;\n}\n\nexport interface RecurringSwapParams {\n uuid: string;\n appId: string;\n}\n\nexport interface ListRecurringOrdersParams {\n address: EvmAddress;\n chainId?: number;\n status?: RecurringOrderStatus;\n}\n\nexport interface ListRecurringOrdersResponse {\n address: EvmAddress;\n count: number;\n orders: ReadonlyArray<RecurringOrder>;\n}\n\n/**\n * Wire-level params for the internal `_api.ts` cancel/pause/unpause helpers\n * (`markrPrepareCancellation` etc.). Public consumers reach the same endpoints\n * via {@link RecurringNamespace.executeCancellation}/`executePause`/\n * `executeUnpause`, which take {@link RecurringExecuteOrderActionParams}\n * instead and derive `chainId` from the passed `sourceChain`.\n */\nexport interface RecurringOrderActionApiParams {\n /** See {@link RecurringOrder.orderId} for the shape. */\n orderId: `0x${string}`;\n address: EvmAddress;\n /**\n * Chain the schedule lives on — required by Markr's\n * `POST /recurring/orders/{orderId}/{action}` endpoints (the orchestrator\n * scopes orderIds per chain, so the same bytes32 could in principle exist\n * on multiple chains).\n */\n chainId: number;\n}\n\n/**\n * Shared params for the three order-action execute methods\n * ({@link RecurringNamespace.executeCancellation},\n * {@link RecurringNamespace.executePause},\n * {@link RecurringNamespace.executeUnpause}). The SDK derives the wire-level\n * `chainId` from `sourceChain`, estimates gas via the chain's RPC, then signs\n * and broadcasts via the configured `evmSigner`.\n */\nexport interface RecurringExecuteOrderActionParams {\n /** See {@link RecurringOrder.orderId} for the shape. */\n orderId: `0x${string}`;\n /** Owner address of the schedule — must match the order's `owner`. */\n address: EvmAddress;\n /**\n * Source chain the schedule lives on — pass the same `Chain` that backs\n * `sourceChain` on the recurring order (the SDK reads `rpcUrl` + multicall\n * for the on-chain gas estimate and uses `chainId` for the wire request).\n */\n sourceChain: Chain;\n /** Optional fee-margin + 1559 overrides forwarded to the signed TX. */\n gasSettings?: GasSettings;\n /**\n * Opaque payload forwarded unchanged onto the `step.signerContext` field\n * seen by the configured `EvmSigner`. Lets consumers correlate the wallet\n * prompt back to the specific cancel / pause / unpause request that\n * produced it (e.g. UI slot id, display label) without relying on an\n * action-type-keyed lookup map that two concurrent same-type actions\n * could clobber.\n */\n signerContext?: unknown;\n}\n\n/**\n * Params for {@link RecurringNamespace.executeFirstFill}. Replaces the\n * pre-signer `prepareFirstFill` shape; the SDK now reads the on-chain\n * allowance against `totalAmountIn`, signs an `approve` if needed (batched\n * one-click when `evmSigner.signBatch` is available and the swap is\n * same-chain), then signs and broadcasts the first-fill swap.\n */\nexport interface RecurringExecuteFirstFillParams {\n /** Full recurring quote — carries `uuid`, `totalAmountIn`, `expiredAt`. */\n quote: RecurringQuoteResponse;\n /** EVM address creating the schedule (and signing the first fill). */\n fromAddress: EvmAddress;\n /**\n * Source chain — same `Chain` used to obtain the recurring quote. The SDK\n * reads `rpcUrl` for allowance + gas calls; `chainId` is cross-checked\n * against `quote.chainId` to catch obvious wiring mistakes.\n */\n sourceChain: Chain;\n /** Optional fee-margin + 1559 overrides. */\n gasSettings?: GasSettings;\n /**\n * Mirrors the same flag on `TransferService.transferAsset`: when the\n * one-click batch (approval + first-fill) is attempted and the consumer's\n * wallet rejects the batch, fall back to two sequential signatures\n * (`approve`, then `swap`) instead of bubbling the batch error up.\n */\n fallbackToDefaultOnBatchFailure?: boolean;\n /**\n * Opaque payload forwarded unchanged onto the `step.signerContext` field\n * seen by the configured `EvmSigner` for both the optional approval step\n * and the first-fill swap step. See\n * {@link RecurringExecuteOrderActionParams.signerContext}.\n */\n signerContext?: unknown;\n}\n\n/** Result of any `recurring.execute*` method — broadcast TX hash. */\nexport interface RecurringExecuteResult {\n txHash: Hex;\n}\n\nexport interface RecurringChainInfoEntry {\n /** Server-published lower bound for `intervalSeconds` (today: 300s on enabled chains). */\n minFrequencySeconds: number;\n supportedTokens: ReadonlyArray<{\n address: EvmAddress;\n /**\n * Smallest-unit decimal string — must be `BigInt()`-parseable (i.e.\n * matches `/^\\d+$/`). The Zod schema enforces this on the wire, but the\n * TS type alone is plain `string`; consumers constructing this map by\n * hand (caching, tests) should pass a digits-only decimal string or\n * `BigInt(minimumAmount)` will throw downstream in `checkEligibility`.\n */\n minimumAmount: string;\n }>;\n}\n\n/**\n * Cached `/info/chains` recurring metadata keyed by EVM chainId. SVM chains\n * are omitted — Markr supports recurring on same-chain EVM only.\n */\nexport type RecurringChainInfoMap = ReadonlyMap<number, RecurringChainInfoEntry>;\n\n/**\n * Reasons surfaced when {@link checkRecurringEligibility} returns\n * `{ eligible: false, … }`. Mirrors the existing `TransferSignatureReason`\n * enum pattern (PascalCase member, kebab-case wire value) so external\n * consumers comparing the raw string still match.\n */\nexport enum RecurringEligibilityReason {\n CrossChain = 'cross-chain',\n UnsupportedSourceChain = 'unsupported-source-chain',\n UnsupportedToken = 'unsupported-token',\n NoEvmAddress = 'no-evm-address',\n AmountBelowMinimum = 'amount-below-minimum',\n}\n\nexport type RecurringEligibility =\n | { eligible: true; minimumAmount: string; minIntervalSeconds: number }\n // `AmountBelowMinimum` carries the floor so error UIs can say \"Min is X\"\n // without a second `getRecurringChainInfo()` lookup. The value is the same\n // smallest-unit decimal string as the success branch's `minimumAmount`.\n | { eligible: false; reason: RecurringEligibilityReason.AmountBelowMinimum; minimumAmount: string }\n | { eligible: false; reason: Exclude<RecurringEligibilityReason, RecurringEligibilityReason.AmountBelowMinimum> };\n\nexport interface CheckRecurringEligibilityParams {\n recurringChainInfo: RecurringChainInfoMap;\n fromTokenAddress: EvmAddress;\n toTokenAddress: EvmAddress;\n sourceChainId: number;\n targetChainId: number;\n ownerAddress?: EvmAddress;\n /** Per-order amount; when present, enables the `amount-below-minimum` check. */\n amount?: bigint;\n}\n\n/**\n * Params passed to `RecurringNamespace.checkEligibility`. Same as\n * `CheckRecurringEligibilityParams` minus the chain-info map, which the\n * namespace closure injects.\n */\nexport type RecurringNamespaceCheckEligibilityParams = Omit<CheckRecurringEligibilityParams, 'recurringChainInfo'>;\n\n/**\n * Params passed to `RecurringNamespace.quote`. Same as `RecurringQuoteParams`\n * minus `appId`, which the namespace closure injects.\n */\nexport type RecurringNamespaceQuoteParams = Omit<RecurringQuoteParams, 'appId'>;\n\n/**\n * High-level wrapper exposed as `MarkrService.recurring`. Methods curry\n * `apiOptions`, `appId`, and the cached `recurringChainInfo` so callers only\n * pass per-call inputs.\n */\nexport interface RecurringNamespace {\n /** POST `/recurring/quote` — full quote with `totalAmountIn`, fees, expiry, uuid. */\n quote(props: RecurringNamespaceQuoteParams): Promise<RecurringQuoteResponse>;\n\n /**\n * Creates the schedule on-chain by signing and broadcasting the first\n * `/recurring/swap` fill via the configured `evmSigner`. Mirrors\n * `TransferService.transferAsset`:\n *\n * 1. Reads on-chain `allowance(tokenIn → router)` against `quote.totalAmountIn`.\n * 2. If allowance is short, builds an `approve(router, totalAmountIn)` TX.\n * When the consumer's signer exposes `signBatch`, the SDK attempts a\n * one-click batch (approve + swap) — set\n * {@link RecurringExecuteFirstFillParams.fallbackToDefaultOnBatchFailure}\n * to fall back to two sequential signatures if the wallet rejects the\n * batch.\n * 3. Estimates gas (with `gasSettings.estimateGasMarginBps` margin) for\n * each TX before signing, and dispatches the signed serialized TX via\n * the chain's RPC.\n *\n * Quote-expiry guard mirrors the previous `prepareFirstFill` behavior —\n * `quote.expiredAt <= now` throws `InvalidParamsError(QUOTE_EXPIRED)` at\n * the SDK boundary before any HTTP / on-chain call.\n *\n * Returns the broadcast first-fill TX hash; the schedule transitions to\n * `'active'` once Markr observes the on-chain event (poll `listOrders`).\n */\n executeFirstFill(props: RecurringExecuteFirstFillParams): Promise<RecurringExecuteResult>;\n\n /**\n * GET `/recurring/orders?address=…&chainId?=…&status?=…` — returns the\n * full response (`{ address, count, orders }`) so callers can render the\n * server-echoed `address` (e.g. confirming the queried wallet matches the\n * current EVM signer) and `count` (pagination / \"you have N schedules\"\n * affordances) without an extra lookup. Consumers that only care about the\n * orders array can destructure: `const { orders } = await listOrders(…)`.\n */\n listOrders(props: ListRecurringOrdersParams): Promise<ListRecurringOrdersResponse>;\n\n /**\n * Cancels the recurring schedule identified by `orderId`: fetches the\n * `/recurring/orders/{orderId}/cancel` calldata, estimates gas, then signs\n * and broadcasts via the configured `evmSigner`. The schedule transitions\n * to `status: 'cancelled'` only once the TX confirms and Markr observes\n * the on-chain event.\n *\n * Eligibility: only `'active'` and `'paused'` orders can be cancelled per\n * Markr's docs. An attempt to cancel a `'completed'` order surfaces as\n * `HttpError(400)` from the orchestrator before signing.\n */\n executeCancellation(props: RecurringExecuteOrderActionParams): Promise<RecurringExecuteResult>;\n\n /**\n * Pauses the recurring schedule identified by `orderId`: fetches the\n * `/recurring/orders/{orderId}/pause` calldata, estimates gas, then signs\n * and broadcasts via the configured `evmSigner`. The schedule transitions\n * to `status: 'paused'` only once the TX confirms and Markr observes the\n * on-chain event.\n *\n * Eligibility: only `'active'` orders can be paused per Markr's docs.\n * Attempting to pause a non-`active` order surfaces as `HttpError(400)`.\n *\n * Pausing preserves the schedule's existing ERC-20 allowance — when the\n * user later unpauses, no re-approval and no new native schedule fee are\n * required (this is the key UX benefit of pause over cancel-and-recreate).\n *\n * @see https://orchestrator-docs.markr.io/#tag/Recurring-Swaps/paths/~1recurring~1orders~1{orderId}~1pause/post\n */\n executePause(props: RecurringExecuteOrderActionParams): Promise<RecurringExecuteResult>;\n\n /**\n * Unpauses (resumes) the recurring schedule identified by `orderId`:\n * fetches the `/recurring/orders/{orderId}/unpause` calldata, estimates\n * gas, then signs and broadcasts via the configured `evmSigner`. The\n * schedule transitions back to `status: 'active'` only once the TX\n * confirms and Markr observes the on-chain event.\n *\n * Eligibility: only `'paused'` orders can be unpaused per Markr's docs.\n * Attempting to unpause a non-`paused` order surfaces as `HttpError(400)`.\n *\n * Resumes execution from where the schedule left off — remaining fills\n * continue on the original `frequency` cadence. The orchestrator recomputes\n * `nextExecutionAt` after the TX confirms.\n *\n * @see https://orchestrator-docs.markr.io/#tag/Recurring-Swaps/paths/~1recurring~1orders~1{orderId}~1unpause/post\n */\n executeUnpause(props: RecurringExecuteOrderActionParams): Promise<RecurringExecuteResult>;\n\n /**\n * Pure (no fetch) — uses the cached `/info/chains` recurring metadata.\n *\n * **Covers:** chain support, token support, EVM-address presence, same-chain\n * (cross-chain rejected), and per-order minimum (when `amount` is passed —\n * failure carries `minimumAmount`).\n *\n * **Does NOT cover wallet balance.** This helper has no wallet/RPC context.\n * Checking that the user holds `amount × numberOfOrders` of `tokenIn` (plus\n * native gas for the first fill) is the consumer's responsibility, same as\n * the one-shot swap flow. There is no `InsufficientBalance` reason on\n * {@link RecurringEligibilityReason} by design.\n *\n * **Does NOT cover post-fill failures.** Once a schedule is live, on-chain\n * reverts (slippage, runtime insufficient balance, etc.) surface server-side\n * as open-ended strings on `RecurringOrder.failures[].reasons` — substring-\n * match those for client-driven auto-cancel (AC4 pattern) and call\n * {@link RecurringNamespace.prepareCancellation} when applicable.\n *\n * **Does NOT cover server-side quote rejection.** Slippage, target-token\n * unsupported, liquidity, etc. are decided at `/recurring/quote` time and\n * surface as `HttpError` from {@link RecurringNamespace.quote}.\n */\n checkEligibility(props: RecurringNamespaceCheckEligibilityParams): RecurringEligibility;\n\n /** Returns the cached `/info/chains` recurring metadata. */\n getRecurringChainInfo(): RecurringChainInfoMap;\n}\n"],"mappings":"AAUA,MAAa,EAA4B,CAAC,SAAU,OAAQ,MAAO,OAAQ,QAAQ,CA8BnF,IAAY,EAAL,SAAA,EAAA,OACL,GAAA,OAAA,SACA,EAAA,UAAA,YACA,EAAA,UAAA,YACA,EAAA,OAAA,eACD,CAySW,EAAL,SAAA,EAAA,OACL,GAAA,WAAA,cACA,EAAA,uBAAA,2BACA,EAAA,iBAAA,oBACA,EAAA,aAAA,iBACA,EAAA,mBAAA,6BACD"}
|
|
1
|
+
{"version":3,"file":"types.cjs","names":[],"sources":["../../../../src/transfer-service/markr/recurring/types.ts"],"sourcesContent":["import type { Address as EvmAddress } from 'viem';\nimport type { Chain } from '../../../types/chain';\nimport type { GasSettings } from '../../../types/service';\nimport type { Hex } from '../../../types/signer';\n\n/**\n * Frequency units accepted by Markr's `/recurring/quote` and `/recurring/orders` endpoints.\n *\n * @see https://orchestrator-docs.markr.io/#/paths/~1recurring~1quote/post\n */\nexport const RECURRING_FREQUENCY_UNITS = ['minute', 'hour', 'day', 'week', 'month'] as const;\n\nexport type RecurringFrequencyUnit = (typeof RECURRING_FREQUENCY_UNITS)[number];\n\nexport interface RecurringFrequency {\n unit: RecurringFrequencyUnit;\n /**\n * Integer in `[1, 365]` (server-enforced upper bound). `validateFrequency`\n * surfaces violations as `{ ok: false, reason: 'invalid-value' }`.\n */\n value: number;\n}\n\n/**\n * Markr's \"unlimited orders\" sentinel. Sent to the server as `-1`, which the\n * router expands to `uint256` max on-chain. Callers can also pass `Infinity`\n * to {@link RecurringQuoteParams.numberOfOrders} for the same effect; the API\n * helpers translate to `-1` at the wire boundary.\n */\nexport const RECURRING_UNLIMITED_ORDERS_SENTINEL = -1;\n\n/**\n * Status values emitted by Markr for a recurring schedule. Treated as a\n * closed set — if Markr ever adds a new value server-side, the schema\n * will reject it loudly so the SDK update gates rendering changes\n * (instead of silently passing an unhandled state through to the UI).\n *\n * Mirrors the existing `TransferSignatureReason` enum pattern in\n * `constants.ts`: PascalCase members with kebab/lowercase wire values.\n */\nexport enum RecurringOrderStatus {\n Active = 'active',\n Completed = 'completed',\n Cancelled = 'cancelled',\n Paused = 'paused',\n}\n\nexport interface RecurringOrderFailure {\n /** 1-based index of the failed scheduled swap. */\n executionIndex: number;\n /** Reason strings supplied by the orchestrator (e.g. `\"Slippage tolerance exceeded\"`). */\n reasons: ReadonlyArray<string>;\n /** On-chain attempts before the execution was marked failed. */\n tryCount: number;\n /** Unix seconds. */\n failedAt: number;\n}\n\n/**\n * Server-side recurring-swap order returned by `GET /recurring/orders` and\n * `POST /recurring/orders/{orderId}/cancel`.\n *\n * @see https://orchestrator-docs.markr.io/#/Recurring%20Swaps\n */\nexport interface RecurringOrder {\n /**\n * bytes32 hex (`0x` + 64 hex chars). Used as the path param for cancellation.\n * Typed as a template-literal `0x`-prefixed string to catch the obvious\n * \"I forgot the `0x`\" mistake at compile time; the wire-level regex check\n * (in `markrCancelRecurringOrder`) enforces the full bytes32 shape.\n */\n orderId: `0x${string}`;\n /** EVM wallet that created the schedule. */\n owner: EvmAddress;\n chainId: number;\n tokenIn: EvmAddress;\n tokenOut: EvmAddress;\n /** Per-order input amount, in `tokenIn`'s smallest unit. */\n amount: bigint;\n /** -1 when unlimited; otherwise a positive integer (server-clamped to ≤ 365). */\n numberOfOrders: number;\n executedOrders: number;\n /**\n * `numberOfOrders - executedOrders` on finite schedules. `null` on\n * unlimited schedules (`numberOfOrders === -1`) — they have no finite\n * remainder to report. Per the Markr OpenAPI spec the field is\n * nullable; the schema also normalizes `undefined` to `null` so a\n * `=== null` check is sufficient.\n */\n remainingOrders: number | null;\n frequency: RecurringFrequency;\n /** `amount × numberOfOrders` — the ERC-20 allowance granted at setup. */\n totalAmountIn: bigint;\n /** Retry count for the *next* pending execution. `0` when none is pending. */\n tryCount: number;\n /** History of failed `executionIndex` values, newest last. */\n failures: ReadonlyArray<RecurringOrderFailure>;\n status: RecurringOrderStatus;\n /** Unix seconds. */\n createdAt: number;\n /**\n * Unix seconds. `null` once the schedule is completed / cancelled /\n * inactive. Per the Markr OpenAPI spec this field is optional + nullable;\n * the schema normalizes an omitted-field response to `null` so consumers\n * can branch on a single `=== null` check.\n */\n nextExecutionAt: number | null;\n /**\n * Unix seconds when the order was cancelled; `null` otherwise. Populated\n * with a number when `status === 'cancelled'`. Per the Markr OpenAPI spec\n * this field is optional + nullable; the schema normalizes both wire\n * shapes (`null` and omitted) to `null` for consumer ergonomics.\n */\n cancelledAt: number | null;\n}\n\n/**\n * Known fee types emitted by Markr today. Open at runtime — the schema\n * tolerates unknown values so a new fee category from the orchestrator doesn't\n * fail quote parsing. See {@link RecurringOrderStatus} for the widening\n * pattern.\n */\nexport type RecurringQuoteFeeType =\n | 'gas'\n | 'recurring'\n | 'protocol'\n | 'bridge'\n | 'slippage'\n | 'swap'\n | 'other'\n // See `RecurringOrderStatus` for why `Record<never, never>` replaces `{}`.\n | (string & Record<never, never>);\n\nexport interface RecurringQuoteFee {\n type: RecurringQuoteFeeType;\n name: string;\n amount: bigint;\n token: { chainId: number; address: EvmAddress };\n /**\n * Docs document `extra` as `boolean or object`. The boolean form is the\n * legacy \"additive one-time charge\" flag (e.g. the one-time native\n * schedule fee with `type: 'recurring'`); the object form is reserved\n * for future structured metadata. Consumers should treat any truthy\n * value as \"additive — balance-check separately.\"\n */\n extra?: boolean | Record<string, unknown>;\n}\n\nexport interface RecurringQuoteResponse {\n uuid: string;\n chainId: number;\n tokenIn: EvmAddress;\n tokenOut: EvmAddress;\n /** Per-order input. */\n amount: bigint;\n /** Server-side clamped value (may be 365 if the request was unlimited). */\n numberOfOrders: number;\n frequency: RecurringFrequency;\n /** Server-derived from `frequency`. */\n intervalSeconds: number;\n /** `amount × numberOfOrders` — the ERC-20 allowance the caller must grant. */\n totalAmountIn: bigint;\n /** First-fill output estimate. */\n amountOut: bigint;\n /** First-fill `minAmountOut` (slippage applied). */\n minAmountOut: bigint;\n fees: ReadonlyArray<RecurringQuoteFee>;\n /** Basis points. */\n recommendedSlippage: number;\n /** Unix seconds. */\n expiredAt: number;\n}\n\nexport interface RecurringQuoteParams {\n appId: string;\n chainId: number;\n tokenIn: EvmAddress;\n tokenInDecimals: number;\n tokenOut: EvmAddress;\n tokenOutDecimals: number;\n /**\n * Per-order input in smallest unit. `bigint` only — matches the rest of the\n * SDK's internal amount types (response amounts, `Quote.amountIn`, etc.).\n * Callers holding a decimal string should coerce with `BigInt(s)` at the\n * call site.\n */\n amount: bigint;\n /**\n * Number of orders. Accepts:\n * - `Infinity` or `-1` — translated to the unlimited sentinel (`-1`) on the wire.\n * - Integer in `[2, 365]` — Markr's documented finite bound.\n *\n * Anything else (`NaN`, `0`, `1`, negatives other than `-1`, non-integers,\n * values > 365) throws `InvalidParamsError` at the SDK boundary so a\n * misbehaving form parse (`parseInt('')` → `NaN`, or a stale \"minimum is 1\"\n * assumption) can't silently become an unlimited schedule or a guaranteed\n * server-side rejection.\n */\n numberOfOrders: number;\n frequency: RecurringFrequency;\n /** Basis points (matches `/quote` semantics). */\n slippage?: number;\n}\n\nexport interface RecurringSwapParams {\n uuid: string;\n appId: string;\n}\n\n/**\n * Step type for entries in {@link RecurringSwapResponse}. Mirrors Markr's\n * `/recurring/swap` documented discriminator (`type: \"wrap\" | \"createOrder\"`).\n *\n * - `wrap`: `WAVAX.deposit{value: totalAmountIn}()` against the chain\n * wrapped-native contract. Only present when the recurring quote was\n * issued against a native `tokenIn` (`0x0…`); first leg in the array.\n * - `createOrder`: the RecurringSwaps router call that creates the on-chain\n * schedule. Always present. `value` is the one-time native schedule fee\n * (NOT the total funded amount — that comes from the wrap leg / prior\n * ERC-20 approval).\n */\nexport type RecurringSwapTransactionType = 'wrap' | 'createOrder';\n\n/**\n * Single ordered step in {@link RecurringSwapResponse}. Submitted to the\n * chain in array order; the consumer also signs an ERC-20 `approve` for the\n * wrapped-native between the `wrap` and `createOrder` legs (SDK-built —\n * Markr does not return an approval step).\n */\nexport interface RecurringSwapTransaction {\n type: RecurringSwapTransactionType;\n to: `0x${string}`;\n data: `0x${string}`;\n value: bigint;\n}\n\n/**\n * Response type for Markr's `/recurring/swap` endpoint. Always an array,\n * ordered:\n * - ERC-20 `tokenIn`: `[createOrder]` (1 element).\n * - Native `tokenIn` (`0x0…`): `[wrap, createOrder]` (2 elements).\n *\n * @see https://orchestrator-docs.markr.io/#tag/Recurring-Swaps/paths/~1recurring~1swap/post\n */\nexport type RecurringSwapResponse = ReadonlyArray<RecurringSwapTransaction>;\n\nexport interface ListRecurringOrdersParams {\n address: EvmAddress;\n chainId?: number;\n status?: RecurringOrderStatus;\n}\n\nexport interface ListRecurringOrdersResponse {\n address: EvmAddress;\n count: number;\n orders: ReadonlyArray<RecurringOrder>;\n}\n\n/**\n * Wire-level params for the internal `_api.ts` cancel/pause/unpause helpers\n * (`markrPrepareCancellation` etc.). Public consumers reach the same endpoints\n * via {@link RecurringNamespace.executeCancellation}/`executePause`/\n * `executeUnpause`, which take {@link RecurringExecuteOrderActionParams}\n * instead and derive `chainId` from the passed `sourceChain`.\n */\nexport interface RecurringOrderActionApiParams {\n /** See {@link RecurringOrder.orderId} for the shape. */\n orderId: `0x${string}`;\n address: EvmAddress;\n /**\n * Chain the schedule lives on — required by Markr's\n * `POST /recurring/orders/{orderId}/{action}` endpoints (the orchestrator\n * scopes orderIds per chain, so the same bytes32 could in principle exist\n * on multiple chains).\n */\n chainId: number;\n}\n\n/**\n * Shared params for the three order-action execute methods\n * ({@link RecurringNamespace.executeCancellation},\n * {@link RecurringNamespace.executePause},\n * {@link RecurringNamespace.executeUnpause}). The SDK derives the wire-level\n * `chainId` from `sourceChain`, estimates gas via the chain's RPC, then signs\n * and broadcasts via the configured `evmSigner`.\n */\nexport interface RecurringExecuteOrderActionParams {\n /** See {@link RecurringOrder.orderId} for the shape. */\n orderId: `0x${string}`;\n /** Owner address of the schedule — must match the order's `owner`. */\n address: EvmAddress;\n /**\n * Source chain the schedule lives on — pass the same `Chain` that backs\n * `sourceChain` on the recurring order (the SDK reads `rpcUrl` + multicall\n * for the on-chain gas estimate and uses `chainId` for the wire request).\n */\n sourceChain: Chain;\n /** Optional fee-margin + 1559 overrides forwarded to the signed TX. */\n gasSettings?: GasSettings;\n /**\n * Opaque payload forwarded unchanged onto the `step.signerContext` field\n * seen by the configured `EvmSigner`. Lets consumers correlate the wallet\n * prompt back to the specific cancel / pause / unpause request that\n * produced it (e.g. UI slot id, display label) without relying on an\n * action-type-keyed lookup map that two concurrent same-type actions\n * could clobber.\n */\n signerContext?: unknown;\n}\n\n/**\n * Params for {@link RecurringNamespace.executeFirstFill}. Replaces the\n * pre-signer `prepareFirstFill` shape; the SDK now reads the on-chain\n * allowance against `totalAmountIn`, signs an `approve` if needed (batched\n * one-click when `evmSigner.signBatch` is available and the swap is\n * same-chain), then signs and broadcasts the first-fill swap.\n */\nexport interface RecurringExecuteFirstFillParams {\n /** Full recurring quote — carries `uuid`, `totalAmountIn`, `expiredAt`. */\n quote: RecurringQuoteResponse;\n /** EVM address creating the schedule (and signing the first fill). */\n fromAddress: EvmAddress;\n /**\n * Source chain — same `Chain` used to obtain the recurring quote. The SDK\n * reads `rpcUrl` for allowance + gas calls; `chainId` is cross-checked\n * against `quote.chainId` to catch obvious wiring mistakes.\n */\n sourceChain: Chain;\n /** Optional fee-margin + 1559 overrides. */\n gasSettings?: GasSettings;\n /**\n * Mirrors the same flag on `TransferService.transferAsset`: when the\n * one-click batch (approval + first-fill) is attempted and the consumer's\n * wallet rejects the batch, fall back to two sequential signatures\n * (`approve`, then `swap`) instead of bubbling the batch error up.\n */\n fallbackToDefaultOnBatchFailure?: boolean;\n /**\n * Opaque payload forwarded unchanged onto the `step.signerContext` field\n * seen by the configured `EvmSigner` for both the optional approval step\n * and the first-fill swap step. See\n * {@link RecurringExecuteOrderActionParams.signerContext}.\n */\n signerContext?: unknown;\n}\n\n/** Result of any `recurring.execute*` method — broadcast TX hash. */\nexport interface RecurringExecuteResult {\n txHash: Hex;\n}\n\nexport interface RecurringChainInfoEntry {\n /** Server-published lower bound for `intervalSeconds` (today: 300s on enabled chains). */\n minFrequencySeconds: number;\n /**\n * Chain wrapped-native ERC-20 (e.g. WAVAX on 43114, WETH on 1). Sourced\n * from `/info/chains[].wrapped_token` so the SDK doesn't need its own\n * static wrapped-native map. Used by:\n * - `_eligibility.ts` — to reject the native → wrapped-native pairing\n * (e.g. AVAX → WAVAX) with the dedicated `NativeToWrappedNative` reason,\n * and to fail-closed when the chain has no known wrapped-native.\n * - `_namespace.ts` — to fail-fast at `quote()` for native input on a\n * chain Markr hasn't published a wrapped-native for, and to cross-check\n * `wrap.to` from `/recurring/swap` before granting the user's allowance.\n *\n * Undefined for chains where Markr did not return `wrapped_token` — the\n * SDK fails closed on native input in that case.\n */\n wrappedNativeAddress?: EvmAddress;\n}\n\n/**\n * Cached `/info/chains` recurring metadata keyed by EVM chainId. SVM chains\n * are omitted — Markr supports recurring on same-chain EVM only.\n */\nexport type RecurringChainInfoMap = ReadonlyMap<number, RecurringChainInfoEntry>;\n\n/**\n * Reasons surfaced when {@link checkRecurringEligibility} returns\n * `{ eligible: false, … }`. Mirrors the existing `TransferSignatureReason`\n * enum pattern (PascalCase member, kebab-case wire value) so external\n * consumers comparing the raw string still match.\n */\nexport enum RecurringEligibilityReason {\n CrossChain = 'cross-chain',\n UnsupportedSourceChain = 'unsupported-source-chain',\n UnsupportedToken = 'unsupported-token',\n NoEvmAddress = 'no-evm-address',\n /**\n * Caller asked for a recurring schedule from the chain's native asset to\n * its wrapped-native ERC-20 (e.g. AVAX → WAVAX on C-Chain). Economically\n * just a scheduled wrap, not a swap — Markr would have nothing to route\n * after the on-chain wrap leg. Surfaced as a dedicated reason (vs.\n * {@link RecurringEligibilityReason.UnsupportedToken}) so consumer UI can\n * steer the user to a one-shot wrap rather than failing with a generic\n * \"token not supported\" message.\n */\n NativeToWrappedNative = 'native-to-wrapped-native',\n}\n\nexport type RecurringEligibility =\n | { eligible: true; minIntervalSeconds: number }\n | { eligible: false; reason: RecurringEligibilityReason };\n\nexport interface CheckRecurringEligibilityParams {\n recurringChainInfo: RecurringChainInfoMap;\n fromTokenAddress: EvmAddress;\n toTokenAddress: EvmAddress;\n sourceChainId: number;\n targetChainId: number;\n ownerAddress?: EvmAddress;\n}\n\n/**\n * Params passed to `RecurringNamespace.checkEligibility`. Same as\n * `CheckRecurringEligibilityParams` minus the chain-info map, which the\n * namespace closure injects.\n */\nexport type RecurringNamespaceCheckEligibilityParams = Omit<CheckRecurringEligibilityParams, 'recurringChainInfo'>;\n\n/**\n * Params passed to `RecurringNamespace.quote`. Same as `RecurringQuoteParams`\n * minus `appId`, which the namespace closure injects.\n */\nexport type RecurringNamespaceQuoteParams = Omit<RecurringQuoteParams, 'appId'>;\n\n/**\n * High-level wrapper exposed as `MarkrService.recurring`. Methods curry\n * `apiOptions`, `appId`, and the cached `recurringChainInfo` so callers only\n * pass per-call inputs.\n */\nexport interface RecurringNamespace {\n /** POST `/recurring/quote` — full quote with `totalAmountIn`, fees, expiry, uuid. */\n quote(props: RecurringNamespaceQuoteParams): Promise<RecurringQuoteResponse>;\n\n /**\n * Creates the schedule on-chain by signing and broadcasting the first\n * `/recurring/swap` fill via the configured `evmSigner`. Mirrors\n * `TransferService.transferAsset`:\n *\n * 1. Reads on-chain `allowance(tokenIn → router)` against `quote.totalAmountIn`.\n * 2. If allowance is short, builds an `approve(router, totalAmountIn)` TX.\n * When the consumer's signer exposes `signBatch`, the SDK attempts a\n * one-click batch (approve + swap) — set\n * {@link RecurringExecuteFirstFillParams.fallbackToDefaultOnBatchFailure}\n * to fall back to two sequential signatures if the wallet rejects the\n * batch.\n * 3. Estimates gas (with `gasSettings.estimateGasMarginBps` margin) for\n * each TX before signing, and dispatches the signed serialized TX via\n * the chain's RPC.\n *\n * Quote-expiry guard mirrors the previous `prepareFirstFill` behavior —\n * `quote.expiredAt <= now` throws `InvalidParamsError(QUOTE_EXPIRED)` at\n * the SDK boundary before any HTTP / on-chain call.\n *\n * Returns the broadcast first-fill TX hash; the schedule transitions to\n * `'active'` once Markr observes the on-chain event (poll `listOrders`).\n */\n executeFirstFill(props: RecurringExecuteFirstFillParams): Promise<RecurringExecuteResult>;\n\n /**\n * GET `/recurring/orders?address=…&chainId?=…&status?=…` — returns the\n * full response (`{ address, count, orders }`) so callers can render the\n * server-echoed `address` (e.g. confirming the queried wallet matches the\n * current EVM signer) and `count` (pagination / \"you have N schedules\"\n * affordances) without an extra lookup. Consumers that only care about the\n * orders array can destructure: `const { orders } = await listOrders(…)`.\n */\n listOrders(props: ListRecurringOrdersParams): Promise<ListRecurringOrdersResponse>;\n\n /**\n * Cancels the recurring schedule identified by `orderId`: fetches the\n * `/recurring/orders/{orderId}/cancel` calldata, estimates gas, then signs\n * and broadcasts via the configured `evmSigner`. The schedule transitions\n * to `status: 'cancelled'` only once the TX confirms and Markr observes\n * the on-chain event.\n *\n * Eligibility: only `'active'` and `'paused'` orders can be cancelled per\n * Markr's docs. An attempt to cancel a `'completed'` order surfaces as\n * `HttpError(400)` from the orchestrator before signing.\n */\n executeCancellation(props: RecurringExecuteOrderActionParams): Promise<RecurringExecuteResult>;\n\n /**\n * Pauses the recurring schedule identified by `orderId`: fetches the\n * `/recurring/orders/{orderId}/pause` calldata, estimates gas, then signs\n * and broadcasts via the configured `evmSigner`. The schedule transitions\n * to `status: 'paused'` only once the TX confirms and Markr observes the\n * on-chain event.\n *\n * Eligibility: only `'active'` orders can be paused per Markr's docs.\n * Attempting to pause a non-`active` order surfaces as `HttpError(400)`.\n *\n * Pausing preserves the schedule's existing ERC-20 allowance — when the\n * user later unpauses, no re-approval and no new native schedule fee are\n * required (this is the key UX benefit of pause over cancel-and-recreate).\n *\n * @see https://orchestrator-docs.markr.io/#tag/Recurring-Swaps/paths/~1recurring~1orders~1{orderId}~1pause/post\n */\n executePause(props: RecurringExecuteOrderActionParams): Promise<RecurringExecuteResult>;\n\n /**\n * Unpauses (resumes) the recurring schedule identified by `orderId`:\n * fetches the `/recurring/orders/{orderId}/unpause` calldata, estimates\n * gas, then signs and broadcasts via the configured `evmSigner`. The\n * schedule transitions back to `status: 'active'` only once the TX\n * confirms and Markr observes the on-chain event.\n *\n * Eligibility: only `'paused'` orders can be unpaused per Markr's docs.\n * Attempting to unpause a non-`paused` order surfaces as `HttpError(400)`.\n *\n * Resumes execution from where the schedule left off — remaining fills\n * continue on the original `frequency` cadence. The orchestrator recomputes\n * `nextExecutionAt` after the TX confirms.\n *\n * @see https://orchestrator-docs.markr.io/#tag/Recurring-Swaps/paths/~1recurring~1orders~1{orderId}~1unpause/post\n */\n executeUnpause(props: RecurringExecuteOrderActionParams): Promise<RecurringExecuteResult>;\n\n /**\n * Pure (no fetch) — uses the cached `/info/chains` recurring metadata.\n *\n * **Covers:** chain support (recurring enabled on the source chain),\n * EVM-address presence, same-chain (cross-chain rejected), and the\n * native → wrapped-native rejection. Markr no longer publishes a\n * per-chain supported-token list, so every ERC-20 (and the chain's\n * native asset) is treated as recurring-eligible — token-level support is\n * decided server-side at `/recurring/quote` time.\n *\n * **Does NOT cover wallet balance.** This helper has no wallet/RPC context.\n * Checking that the user holds `amount × numberOfOrders` of `tokenIn` (plus\n * native gas for the first fill) is the consumer's responsibility, same as\n * the one-shot swap flow. There is no `InsufficientBalance` reason on\n * {@link RecurringEligibilityReason} by design.\n *\n * **Does NOT cover post-fill failures.** Once a schedule is live, on-chain\n * reverts (slippage, runtime insufficient balance, etc.) surface server-side\n * as open-ended strings on `RecurringOrder.failures[].reasons` — substring-\n * match those for client-driven auto-cancel (AC4 pattern) and call\n * {@link RecurringNamespace.prepareCancellation} when applicable.\n *\n * **Does NOT cover server-side quote rejection.** Slippage, target-token\n * unsupported, liquidity, etc. are decided at `/recurring/quote` time and\n * surface as `HttpError` from {@link RecurringNamespace.quote}.\n */\n checkEligibility(props: RecurringNamespaceCheckEligibilityParams): RecurringEligibility;\n\n /** Returns the cached `/info/chains` recurring metadata. */\n getRecurringChainInfo(): RecurringChainInfoMap;\n}\n"],"mappings":"AAUA,MAAa,EAA4B,CAAC,SAAU,OAAQ,MAAO,OAAQ,QAAQ,CA8BnF,IAAY,EAAL,SAAA,EAAA,OACL,GAAA,OAAA,SACA,EAAA,UAAA,YACA,EAAA,UAAA,YACA,EAAA,OAAA,eACD,CAkVW,EAAL,SAAA,EAAA,OACL,GAAA,WAAA,cACA,EAAA,uBAAA,2BACA,EAAA,iBAAA,oBACA,EAAA,aAAA,iBAUA,EAAA,sBAAA,iCACD"}
|