@lifi/sdk 4.11.0 → 4.12.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/core/StatusManager.js +5 -3
  3. package/dist/cjs/core/StatusManager.js.map +1 -1
  4. package/dist/cjs/core/transactionState.d.ts +8 -6
  5. package/dist/cjs/core/transactionState.js +9 -6
  6. package/dist/cjs/core/transactionState.js.map +1 -1
  7. package/dist/cjs/errors/constants.d.ts +2 -1
  8. package/dist/cjs/errors/constants.js +1 -0
  9. package/dist/cjs/errors/constants.js.map +1 -1
  10. package/dist/cjs/errors/errors.d.ts +3 -3
  11. package/dist/cjs/errors/errors.js.map +1 -1
  12. package/dist/cjs/types/core.d.ts +12 -5
  13. package/dist/cjs/utils/checkPackageUpdates.js +1 -1
  14. package/dist/cjs/version.d.ts +1 -1
  15. package/dist/cjs/version.js +1 -1
  16. package/dist/cjs/version.js.map +1 -1
  17. package/dist/esm/core/StatusManager.d.ts.map +1 -1
  18. package/dist/esm/core/StatusManager.js +5 -3
  19. package/dist/esm/core/StatusManager.js.map +1 -1
  20. package/dist/esm/core/transactionState.d.ts +8 -6
  21. package/dist/esm/core/transactionState.d.ts.map +1 -1
  22. package/dist/esm/core/transactionState.js +9 -6
  23. package/dist/esm/core/transactionState.js.map +1 -1
  24. package/dist/esm/errors/constants.d.ts +2 -1
  25. package/dist/esm/errors/constants.d.ts.map +1 -1
  26. package/dist/esm/errors/constants.js +1 -0
  27. package/dist/esm/errors/constants.js.map +1 -1
  28. package/dist/esm/errors/errors.d.ts +3 -3
  29. package/dist/esm/errors/errors.js.map +1 -1
  30. package/dist/esm/types/core.d.ts +12 -5
  31. package/dist/esm/types/core.d.ts.map +1 -1
  32. package/dist/esm/utils/checkPackageUpdates.js +1 -1
  33. package/dist/esm/version.d.ts +1 -1
  34. package/dist/esm/version.js +1 -1
  35. package/dist/esm/version.js.map +1 -1
  36. package/package.json +1 -1
  37. package/src/core/StatusManager.ts +8 -5
  38. package/src/core/transactionState.ts +12 -6
  39. package/src/errors/constants.ts +1 -0
  40. package/src/errors/errors.ts +3 -3
  41. package/src/types/core.ts +12 -5
  42. package/src/version.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @lifi/sdk
2
2
 
3
+ ## 4.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#514](https://github.com/lifinance/sdk/pull/514) [`5dc9cc5`](https://github.com/lifinance/sdk/commit/5dc9cc5f52b0308962b822cfacd766dbf27bab3c) Thanks [@chybisov](https://github.com/chybisov)! - `LiFiErrorCode` has a new code, `CallBundleNotFound` (1028). A step fails with this code when the wallet has no record of an EIP-5792 bundle. The SDK uses it only when it cannot prove that the wallet did not send the bundle. The outcome stays unknown: the action keeps the bundle id, and a resume waits for the bundle again and does not sign.
8
+
9
+ `ExecutionAction` has a new optional field, `callCount`. It is the number of calls of a batched (EIP-5792) transaction. The Ethereum provider sets it together with `taskId` for a batched transaction.
10
+
3
11
  ## 4.11.0
4
12
 
5
13
  ### Minor Changes
@@ -4,9 +4,10 @@ const require_core_executionState = require("./executionState.js");
4
4
  const require_core_transactionState = require("./transactionState.js");
5
5
  //#region src/core/StatusManager.ts
6
6
  /**
7
- * A write is transaction data when it changes one of these fields. `txLink`
8
- * and `signedAt` travel with such a write but never trigger one: the status
9
- * poll rewrites `txLink` every few seconds.
7
+ * A write is transaction data when it changes one of these fields. `txLink`,
8
+ * `signedAt` and `callCount` travel with such a write but never trigger one:
9
+ * the status poll rewrites `txLink` every few seconds, and `callCount` comes
10
+ * only with a `taskId`.
10
11
  */
11
12
  const TRANSACTION_KEYS = [
12
13
  "txHash",
@@ -47,6 +48,7 @@ const mergeLateTransaction = (liveRoute, lateStep, lateAction) => {
47
48
  txHex: lateAction.txHex,
48
49
  txFinal: lateAction.txFinal,
49
50
  taskId: lateAction.taskId,
51
+ callCount: lateAction.callCount,
50
52
  txType: lateAction.txType
51
53
  });
52
54
  }
@@ -1 +1 @@
1
- {"version":3,"file":"StatusManager.js","names":["hasOpenTransaction","TRANSACTION_ACTION_TYPES","hasStepOpenTransaction","getActionMessage","CLEARED_TRANSACTION_FIELDS","executionState"],"sources":["../../../src/core/StatusManager.ts"],"sourcesContent":["import type { ChainId, LiFiStep } from '@lifi/types'\nimport type {\n Execution,\n ExecutionAction,\n ExecutionActionStatus,\n ExecutionActionType,\n LiFiStepExtended,\n RouteExtended,\n UpdateRouteHook,\n} from '../types/core.js'\nimport { getActionMessage } from './actionMessages.js'\nimport { executionState } from './executionState.js'\nimport {\n CLEARED_TRANSACTION_FIELDS,\n hasOpenTransaction,\n hasStepOpenTransaction,\n TRANSACTION_ACTION_TYPES,\n} from './transactionState.js'\n\ntype ActionProps = {\n step: LiFiStepExtended\n type: ExecutionActionType\n chainId: ChainId\n status: ExecutionActionStatus\n}\n\n/**\n * The route and hook of an execution that `stopRouteExecution` ended. A task\n * that was still running (e.g. waiting in the wallet prompt) writes its\n * transaction data later; without these the write would never reach the\n * integrator, and a resume of the stored route would sign again.\n * `startCount` is `executionState.startCount` at the stop.\n */\ntype StoppedExecution = {\n route: RouteExtended\n updateRouteHook?: UpdateRouteHook\n startCount: number\n}\n\n/**\n * A write is transaction data when it changes one of these fields. `txLink`\n * and `signedAt` travel with such a write but never trigger one: the status\n * poll rewrites `txLink` every few seconds.\n */\nconst TRANSACTION_KEYS = ['txHash', 'txHex', 'taskId', 'txFinal'] as const\n\ntype TransactionFields = Pick<\n ExecutionAction,\n (typeof TRANSACTION_KEYS)[number]\n>\n\nconst readTransaction = (action: ExecutionAction): TransactionFields => ({\n txHash: action.txHash,\n txHex: action.txHex,\n taskId: action.taskId,\n txFinal: action.txFinal,\n})\n\n/** True when the write changed a transaction field, also to `undefined`. */\nconst changesTransaction = (\n before: TransactionFields,\n action: ExecutionAction\n): boolean => TRANSACTION_KEYS.some((key) => action[key] !== before[key])\n\n/**\n * Copies a late transaction into the route of a newer execution of the same\n * route id, running or ended. The step's objects are changed in place: a\n * running executor holds them, so its selector and its pre-sign guard see\n * the transaction. Returns true when something changed.\n */\nconst mergeLateTransaction = (\n liveRoute: RouteExtended,\n lateStep: LiFiStepExtended,\n lateAction: ExecutionAction\n): boolean => {\n // Cleared or final: the newer execution needs nothing from it.\n if (!hasOpenTransaction(lateAction)) {\n return false\n }\n const liveStep = liveRoute.steps.find(\n (routeStep) => routeStep.id === lateStep.id\n )\n if (!liveStep) {\n return false\n }\n if (!liveStep.execution) {\n liveStep.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [structuredClone(lateAction)],\n }\n } else {\n const liveAction = liveStep.execution.actions.find(\n (action) => action.type === lateAction.type\n )\n if (!liveAction) {\n liveStep.execution.actions.push(structuredClone(lateAction))\n } else if (hasOpenTransaction(liveAction)) {\n // The live action already has an open transaction (its own, or one\n // merged earlier); it is kept.\n return false\n } else {\n // All five fields, so a stale `txFinal` goes and the action is open.\n // `txType` goes with them: the live one described no open transaction.\n Object.assign(liveAction, {\n txHash: lateAction.txHash,\n txLink: lateAction.txLink,\n txHex: lateAction.txHex,\n txFinal: lateAction.txFinal,\n taskId: lateAction.taskId,\n txType: lateAction.txType,\n })\n }\n }\n // `signedAt` is the signing time of the step's own transaction: an\n // allowance does not set it, and a write without one keeps the live time.\n const signedAt = lateStep.execution?.signedAt\n if (\n TRANSACTION_ACTION_TYPES.includes(lateAction.type) &&\n signedAt !== undefined\n ) {\n liveStep.execution.signedAt = signedAt\n }\n return true\n}\n\n/**\n * Manages status updates of a route and provides various functions for tracking actions.\n */\nexport class StatusManager {\n private readonly routeId: string\n private shouldUpdate = true\n private stoppedExecution?: StoppedExecution\n\n constructor(routeId: string) {\n this.routeId = routeId\n }\n\n /**\n * Initializes the execution object of a Step.\n * @param step The current step in execution\n * @returns The initialized execution object for this step\n */\n initializeExecution = (step: LiFiStepExtended): Execution => {\n if (!step.execution) {\n step.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [],\n }\n this.updateStepInRoute(step)\n }\n\n // Change status to PENDING after resuming from FAILED\n if (step.execution.status === 'FAILED') {\n step.execution.startedAt = Date.now()\n step.execution.status = 'PENDING'\n // Keep the signing time while a signed transaction may still land: the\n // resume path uses it to decide when stored bytes are too old to resend\n // or old enough to be declared dropped.\n if (!hasStepOpenTransaction(step)) {\n step.execution.signedAt = undefined\n }\n step.execution.error = undefined\n this.updateStepInRoute(step)\n }\n\n return step.execution\n }\n\n /**\n * Updates the execution object of a Step.\n * @param step The current step in execution\n * @param execution Partial execution data to merge\n * @returns The step with the updated execution object\n */\n updateExecution(\n step: LiFiStepExtended,\n execution: Partial<Execution>\n ): LiFiStep {\n if (!step.execution) {\n throw Error(\"Can't update empty execution.\")\n }\n step.execution = {\n ...step.execution,\n ...execution,\n }\n this.updateStepInRoute(step)\n return step\n }\n\n /**\n * Finds an action of the specified type in the step's execution\n * @param step The step to search in\n * @param type The action type to find\n * @returns The found action or undefined if not found\n */\n findAction(\n step: LiFiStepExtended,\n type: ExecutionActionType\n ): ExecutionAction | undefined {\n if (!step.execution?.actions) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const action = step.execution.actions.find((p) => p.type === type)\n\n return action\n }\n\n /**\n * Create and push a new action into the execution.\n * Caller is responsible for ensuring an action of this type does not already exist.\n * @param step The step that should contain the new action.\n * @param type Type of the action.\n * @param chainId Chain Id of the action.\n * @param status The initial status for the new action.\n * @returns The created action.\n */\n createAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const newAction: ExecutionAction = {\n type,\n message: getActionMessage(type, status),\n status,\n chainId,\n }\n\n step.execution.actions.push(newAction)\n this.updateStepInRoute(step)\n return newAction\n }\n\n /**\n * Find an existing action by type and update it, or create a new one if none exists.\n * @param step The step that should contain the action.\n * @param type Type of the action. Used to identify already existing actions.\n * @param chainId Chain Id of the action (used when creating).\n * @param status The status to set on the found or newly created action.\n * @returns The updated or newly created action.\n */\n initializeAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n const action = this.findAction(step, type)\n\n if (action) {\n return this.updateAction(step, type, status, {\n error: undefined,\n // A final outcome is dead. A new attempt starts without its data, so\n // the pre-sign guard does not mistake it for an open transaction (the\n // route was run again without `prepareRestart`, e.g. `executeRoute`).\n ...(action.status === 'FAILED' &&\n action.txFinal === true &&\n CLEARED_TRANSACTION_FIELDS),\n })\n }\n\n return this.createAction({ step, type, chainId, status })\n }\n\n /**\n * Update an action object.\n * @param step The step where the action should be updated\n * @param type The action type to update\n * @param status The status the action gets.\n * @param [params] Additional parameters to append to the action.\n * @returns The updated action\n */\n updateAction = (\n step: LiFiStepExtended,\n type: ExecutionActionType,\n status: ExecutionActionStatus,\n params?: Partial<ExecutionAction & { signedAt?: number }>\n ): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Can't update an empty step execution.\")\n }\n const currentAction = this.findAction(step, type)\n\n if (!currentAction) {\n throw new Error(\"Can't find an action for the given type.\")\n }\n // Read before the write: after a stop, only a write that changes the\n // transaction reaches the integrator.\n const transactionBefore = this.shouldUpdate\n ? undefined\n : readTransaction(currentAction)\n\n switch (status) {\n case 'CANCELLED':\n break\n case 'FAILED':\n step.execution.status = 'FAILED'\n if (params?.error) {\n step.execution.error = params.error\n }\n break\n case 'DONE':\n break\n case 'PENDING':\n step.execution.status = 'PENDING'\n if (params?.signedAt) {\n step.execution.signedAt = params.signedAt\n }\n break\n case 'RESET_REQUIRED':\n case 'MESSAGE_REQUIRED':\n case 'ACTION_REQUIRED':\n step.execution.status = 'ACTION_REQUIRED'\n break\n default:\n break\n }\n\n currentAction.status = status\n currentAction.message = getActionMessage(type, status)\n // set extra parameters or overwrite the standard params set in the switch statement\n if (params) {\n const { signedAt: _signedAt, ...rest } = params\n Object.assign(currentAction, rest)\n }\n // Sort actions, the ones with DONE status go first\n step.execution.actions = [\n ...step.execution.actions.filter((action) => action.status === 'DONE'),\n ...step.execution.actions.filter((action) => action.status !== 'DONE'),\n ]\n if (\n transactionBefore &&\n changesTransaction(transactionBefore, currentAction)\n ) {\n this.deliverLateTransactionData(step, currentAction)\n } else {\n this.updateStepInRoute(step) // updates the step in the route\n }\n return currentAction\n }\n\n updateStepInRoute = (step: LiFiStep): LiFiStep => {\n if (!this.shouldUpdate) {\n return step\n }\n const data = executionState.get(this.routeId)\n\n if (!data) {\n throw new Error('Execution data not found.')\n }\n\n const stepIndex = data.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n\n if (stepIndex === -1) {\n throw new Error(\"Couldn't find a step to update.\")\n }\n\n // A shallow copy on purpose: the route's step must keep sharing the\n // step's `execution` object. `mergeLateTransaction` changes the live\n // route in place, and the running sign task's check after the wallet\n // must see the merge (pinned by the stop-and-resume race test in\n // `sdk-provider-ethereum/src/core/flows/reload.unit.spec.ts`).\n data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step }\n\n data.executionOptions?.updateRouteHook?.(data.route)\n return data.route.steps[stepIndex]\n }\n\n allowUpdates(value: boolean): void {\n this.shouldUpdate = value\n if (value) {\n this.stoppedExecution = undefined\n return\n }\n // `stopRouteExecution` turns updates off right before it deletes the\n // execution state, so the state is still here to keep.\n const data = executionState.get(this.routeId)\n if (data) {\n this.stoppedExecution = {\n route: data.route,\n updateRouteHook: data.executionOptions?.updateRouteHook,\n startCount: executionState.startCount(this.routeId),\n }\n }\n }\n\n /**\n * A write of transaction data after `stopRouteExecution`. With a newer\n * execution of the same route id running, the transaction is merged into\n * it. If no execution of the route started since the stop, the kept route\n * is updated and the kept hook is called. If a newer execution started and\n * ended since the stop, the transaction is merged into the route of the\n * last ended execution, and its hook is called.\n */\n private deliverLateTransactionData(\n step: LiFiStepExtended,\n lateAction: ExecutionAction\n ): void {\n const stopped = this.stoppedExecution\n if (!stopped) {\n return\n }\n // A late write must never fail the task that made it: its catch block\n // would mark the action FAILED while the transaction may still land.\n try {\n // Always a newer execution: `stopRouteExecution` deleted this one.\n const live = executionState.get(this.routeId)\n if (live) {\n if (mergeLateTransaction(live.route, step, lateAction)) {\n live.executionOptions?.updateRouteHook?.(live.route)\n }\n return\n }\n // A newer execution started and ended since the stop: the integrator\n // stored its route, which the kept one would roll back. The late\n // transaction goes into that route instead. With the records of the\n // route freed (no run in flight, `startCount` 0) the write is dropped.\n if (executionState.startCount(this.routeId) !== stopped.startCount) {\n const ended = executionState.lastEnded(this.routeId)\n if (ended && mergeLateTransaction(ended.route, step, lateAction)) {\n ended.updateRouteHook?.(ended.route)\n }\n return\n }\n const stepIndex = stopped.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n if (stepIndex === -1) {\n return\n }\n stopped.route.steps[stepIndex] = {\n ...stopped.route.steps[stepIndex],\n ...step,\n }\n stopped.updateRouteHook?.(stopped.route)\n } catch (error) {\n // Not rethrown, see above. The integrator's hook can throw here, so\n // the error is reported in development, as other swallowed errors are.\n if (process.env.NODE_ENV === 'development') {\n console.debug('Delivering late transaction data failed.', error)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;AA4CA,MAAM,mBAAmB;CAAC;CAAU;CAAS;CAAU;AAAS;AAOhE,MAAM,mBAAmB,YAAgD;CACvE,QAAQ,OAAO;CACf,OAAO,OAAO;CACd,QAAQ,OAAO;CACf,SAAS,OAAO;AAClB;;AAGA,MAAM,sBACJ,QACA,WACY,iBAAiB,MAAM,QAAQ,OAAO,SAAS,OAAO,IAAI;;;;;;;AAQxE,MAAM,wBACJ,WACA,UACA,eACY;CAEZ,IAAI,CAACA,8BAAAA,mBAAmB,UAAU,GAChC,OAAO;CAET,MAAM,WAAW,UAAU,MAAM,MAC9B,cAAc,UAAU,OAAO,SAAS,EAC3C;CACA,IAAI,CAAC,UACH,OAAO;CAET,IAAI,CAAC,SAAS,WACZ,SAAS,YAAY;EACnB,WAAW,KAAK,IAAI;EACpB,QAAQ;EACR,SAAS,CAAC,gBAAgB,UAAU,CAAC;CACv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AAC,SACH;EAIF,IAAI;GAEF,MAAM,OAAOA,4BAAAA,eAAe,IAAI,KAAK,OAAO;GAC5C,IAAI,MAAM;IACR,IAAI,qBAAqB,KAAK,OAAO,MAAM,UAAU,GACnD,KAAK,kBAAkB,kBAAkB,KAAK,KAAK;IAErD;GACF;GAKA,IAAIA,4BAAAA,eAAe,WAAW,KAAK,OAAO,MAAM,QAAQ,YAAY;IAClE,MAAM,QAAQA,4BAAAA,eAAe,UAAU,KAAK,OAAO;IACnD,IAAI,SAAS,qBAAqB,MAAM,OAAO,MAAM,UAAU,GAC7D,MAAM,kBAAkB,MAAM,KAAK;IAErC;GACF;GACA,MAAM,YAAY,QAAQ,MAAM,MAAM,WACnC,cAAc,UAAU,OAAO,KAAK,EACvC;GACA,IAAI,cAAc,IAChB;GAEF,QAAQ,MAAM,MAAM,aAAa;IAC/B,GAAG,QAAQ,MAAM,MAAM;IACvB,GAAG;GACL;GACA,QAAQ,kBAAkB,QAAQ,KAAK;EACzC,SAAS,OAAO;GAGd,IAAI,QAAQ,IAAI,aAAa,eAC3B,QAAQ,MAAM,4CAA4C,KAAK;EAEnE;CACF;AACF"}
1
+ {"version":3,"file":"StatusManager.js","names":["hasOpenTransaction","TRANSACTION_ACTION_TYPES","hasStepOpenTransaction","getActionMessage","CLEARED_TRANSACTION_FIELDS","executionState"],"sources":["../../../src/core/StatusManager.ts"],"sourcesContent":["import type { ChainId, LiFiStep } from '@lifi/types'\nimport type {\n Execution,\n ExecutionAction,\n ExecutionActionStatus,\n ExecutionActionType,\n LiFiStepExtended,\n RouteExtended,\n UpdateRouteHook,\n} from '../types/core.js'\nimport { getActionMessage } from './actionMessages.js'\nimport { executionState } from './executionState.js'\nimport {\n CLEARED_TRANSACTION_FIELDS,\n hasOpenTransaction,\n hasStepOpenTransaction,\n TRANSACTION_ACTION_TYPES,\n} from './transactionState.js'\n\ntype ActionProps = {\n step: LiFiStepExtended\n type: ExecutionActionType\n chainId: ChainId\n status: ExecutionActionStatus\n}\n\n/**\n * The route and hook of an execution that `stopRouteExecution` ended. A task\n * that was still running (e.g. waiting in the wallet prompt) writes its\n * transaction data later; without these the write would never reach the\n * integrator, and a resume of the stored route would sign again.\n * `startCount` is `executionState.startCount` at the stop.\n */\ntype StoppedExecution = {\n route: RouteExtended\n updateRouteHook?: UpdateRouteHook\n startCount: number\n}\n\n/**\n * A write is transaction data when it changes one of these fields. `txLink`,\n * `signedAt` and `callCount` travel with such a write but never trigger one:\n * the status poll rewrites `txLink` every few seconds, and `callCount` comes\n * only with a `taskId`.\n */\nconst TRANSACTION_KEYS = ['txHash', 'txHex', 'taskId', 'txFinal'] as const\n\ntype TransactionFields = Pick<\n ExecutionAction,\n (typeof TRANSACTION_KEYS)[number]\n>\n\nconst readTransaction = (action: ExecutionAction): TransactionFields => ({\n txHash: action.txHash,\n txHex: action.txHex,\n taskId: action.taskId,\n txFinal: action.txFinal,\n})\n\n/** True when the write changed a transaction field, also to `undefined`. */\nconst changesTransaction = (\n before: TransactionFields,\n action: ExecutionAction\n): boolean => TRANSACTION_KEYS.some((key) => action[key] !== before[key])\n\n/**\n * Copies a late transaction into the route of a newer execution of the same\n * route id, running or ended. The step's objects are changed in place: a\n * running executor holds them, so its selector and its pre-sign guard see\n * the transaction. Returns true when something changed.\n */\nconst mergeLateTransaction = (\n liveRoute: RouteExtended,\n lateStep: LiFiStepExtended,\n lateAction: ExecutionAction\n): boolean => {\n // Cleared or final: the newer execution needs nothing from it.\n if (!hasOpenTransaction(lateAction)) {\n return false\n }\n const liveStep = liveRoute.steps.find(\n (routeStep) => routeStep.id === lateStep.id\n )\n if (!liveStep) {\n return false\n }\n if (!liveStep.execution) {\n liveStep.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [structuredClone(lateAction)],\n }\n } else {\n const liveAction = liveStep.execution.actions.find(\n (action) => action.type === lateAction.type\n )\n if (!liveAction) {\n liveStep.execution.actions.push(structuredClone(lateAction))\n } else if (hasOpenTransaction(liveAction)) {\n // The live action already has an open transaction (its own, or one\n // merged earlier); it is kept.\n return false\n } else {\n // Every field of `CLEARED_TRANSACTION_FIELDS`, so a stale `txFinal`\n // goes and the action is open. `txType` goes with them: the live one\n // described no open transaction.\n Object.assign(liveAction, {\n txHash: lateAction.txHash,\n txLink: lateAction.txLink,\n txHex: lateAction.txHex,\n txFinal: lateAction.txFinal,\n taskId: lateAction.taskId,\n callCount: lateAction.callCount,\n txType: lateAction.txType,\n })\n }\n }\n // `signedAt` is the signing time of the step's own transaction: an\n // allowance does not set it, and a write without one keeps the live time.\n const signedAt = lateStep.execution?.signedAt\n if (\n TRANSACTION_ACTION_TYPES.includes(lateAction.type) &&\n signedAt !== undefined\n ) {\n liveStep.execution.signedAt = signedAt\n }\n return true\n}\n\n/**\n * Manages status updates of a route and provides various functions for tracking actions.\n */\nexport class StatusManager {\n private readonly routeId: string\n private shouldUpdate = true\n private stoppedExecution?: StoppedExecution\n\n constructor(routeId: string) {\n this.routeId = routeId\n }\n\n /**\n * Initializes the execution object of a Step.\n * @param step The current step in execution\n * @returns The initialized execution object for this step\n */\n initializeExecution = (step: LiFiStepExtended): Execution => {\n if (!step.execution) {\n step.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [],\n }\n this.updateStepInRoute(step)\n }\n\n // Change status to PENDING after resuming from FAILED\n if (step.execution.status === 'FAILED') {\n step.execution.startedAt = Date.now()\n step.execution.status = 'PENDING'\n // Keep the signing time while a signed transaction may still land: the\n // resume path uses it to decide when stored bytes are too old to resend\n // or old enough to be declared dropped.\n if (!hasStepOpenTransaction(step)) {\n step.execution.signedAt = undefined\n }\n step.execution.error = undefined\n this.updateStepInRoute(step)\n }\n\n return step.execution\n }\n\n /**\n * Updates the execution object of a Step.\n * @param step The current step in execution\n * @param execution Partial execution data to merge\n * @returns The step with the updated execution object\n */\n updateExecution(\n step: LiFiStepExtended,\n execution: Partial<Execution>\n ): LiFiStep {\n if (!step.execution) {\n throw Error(\"Can't update empty execution.\")\n }\n step.execution = {\n ...step.execution,\n ...execution,\n }\n this.updateStepInRoute(step)\n return step\n }\n\n /**\n * Finds an action of the specified type in the step's execution\n * @param step The step to search in\n * @param type The action type to find\n * @returns The found action or undefined if not found\n */\n findAction(\n step: LiFiStepExtended,\n type: ExecutionActionType\n ): ExecutionAction | undefined {\n if (!step.execution?.actions) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const action = step.execution.actions.find((p) => p.type === type)\n\n return action\n }\n\n /**\n * Create and push a new action into the execution.\n * Caller is responsible for ensuring an action of this type does not already exist.\n * @param step The step that should contain the new action.\n * @param type Type of the action.\n * @param chainId Chain Id of the action.\n * @param status The initial status for the new action.\n * @returns The created action.\n */\n createAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const newAction: ExecutionAction = {\n type,\n message: getActionMessage(type, status),\n status,\n chainId,\n }\n\n step.execution.actions.push(newAction)\n this.updateStepInRoute(step)\n return newAction\n }\n\n /**\n * Find an existing action by type and update it, or create a new one if none exists.\n * @param step The step that should contain the action.\n * @param type Type of the action. Used to identify already existing actions.\n * @param chainId Chain Id of the action (used when creating).\n * @param status The status to set on the found or newly created action.\n * @returns The updated or newly created action.\n */\n initializeAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n const action = this.findAction(step, type)\n\n if (action) {\n return this.updateAction(step, type, status, {\n error: undefined,\n // A final outcome is dead. A new attempt starts without its data, so\n // the pre-sign guard does not mistake it for an open transaction (the\n // route was run again without `prepareRestart`, e.g. `executeRoute`).\n ...(action.status === 'FAILED' &&\n action.txFinal === true &&\n CLEARED_TRANSACTION_FIELDS),\n })\n }\n\n return this.createAction({ step, type, chainId, status })\n }\n\n /**\n * Update an action object.\n * @param step The step where the action should be updated\n * @param type The action type to update\n * @param status The status the action gets.\n * @param [params] Additional parameters to append to the action.\n * @returns The updated action\n */\n updateAction = (\n step: LiFiStepExtended,\n type: ExecutionActionType,\n status: ExecutionActionStatus,\n params?: Partial<ExecutionAction & { signedAt?: number }>\n ): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Can't update an empty step execution.\")\n }\n const currentAction = this.findAction(step, type)\n\n if (!currentAction) {\n throw new Error(\"Can't find an action for the given type.\")\n }\n // Read before the write: after a stop, only a write that changes the\n // transaction reaches the integrator.\n const transactionBefore = this.shouldUpdate\n ? undefined\n : readTransaction(currentAction)\n\n switch (status) {\n case 'CANCELLED':\n break\n case 'FAILED':\n step.execution.status = 'FAILED'\n if (params?.error) {\n step.execution.error = params.error\n }\n break\n case 'DONE':\n break\n case 'PENDING':\n step.execution.status = 'PENDING'\n if (params?.signedAt) {\n step.execution.signedAt = params.signedAt\n }\n break\n case 'RESET_REQUIRED':\n case 'MESSAGE_REQUIRED':\n case 'ACTION_REQUIRED':\n step.execution.status = 'ACTION_REQUIRED'\n break\n default:\n break\n }\n\n currentAction.status = status\n currentAction.message = getActionMessage(type, status)\n // set extra parameters or overwrite the standard params set in the switch statement\n if (params) {\n const { signedAt: _signedAt, ...rest } = params\n Object.assign(currentAction, rest)\n }\n // Sort actions, the ones with DONE status go first\n step.execution.actions = [\n ...step.execution.actions.filter((action) => action.status === 'DONE'),\n ...step.execution.actions.filter((action) => action.status !== 'DONE'),\n ]\n if (\n transactionBefore &&\n changesTransaction(transactionBefore, currentAction)\n ) {\n this.deliverLateTransactionData(step, currentAction)\n } else {\n this.updateStepInRoute(step) // updates the step in the route\n }\n return currentAction\n }\n\n updateStepInRoute = (step: LiFiStep): LiFiStep => {\n if (!this.shouldUpdate) {\n return step\n }\n const data = executionState.get(this.routeId)\n\n if (!data) {\n throw new Error('Execution data not found.')\n }\n\n const stepIndex = data.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n\n if (stepIndex === -1) {\n throw new Error(\"Couldn't find a step to update.\")\n }\n\n // A shallow copy on purpose: the route's step must keep sharing the\n // step's `execution` object. `mergeLateTransaction` changes the live\n // route in place, and the running sign task's check after the wallet\n // must see the merge (pinned by the stop-and-resume race test in\n // `sdk-provider-ethereum/src/core/flows/reload.unit.spec.ts`).\n data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step }\n\n data.executionOptions?.updateRouteHook?.(data.route)\n return data.route.steps[stepIndex]\n }\n\n allowUpdates(value: boolean): void {\n this.shouldUpdate = value\n if (value) {\n this.stoppedExecution = undefined\n return\n }\n // `stopRouteExecution` turns updates off right before it deletes the\n // execution state, so the state is still here to keep.\n const data = executionState.get(this.routeId)\n if (data) {\n this.stoppedExecution = {\n route: data.route,\n updateRouteHook: data.executionOptions?.updateRouteHook,\n startCount: executionState.startCount(this.routeId),\n }\n }\n }\n\n /**\n * A write of transaction data after `stopRouteExecution`. With a newer\n * execution of the same route id running, the transaction is merged into\n * it. If no execution of the route started since the stop, the kept route\n * is updated and the kept hook is called. If a newer execution started and\n * ended since the stop, the transaction is merged into the route of the\n * last ended execution, and its hook is called.\n */\n private deliverLateTransactionData(\n step: LiFiStepExtended,\n lateAction: ExecutionAction\n ): void {\n const stopped = this.stoppedExecution\n if (!stopped) {\n return\n }\n // A late write must never fail the task that made it: its catch block\n // would mark the action FAILED while the transaction may still land.\n try {\n // Always a newer execution: `stopRouteExecution` deleted this one.\n const live = executionState.get(this.routeId)\n if (live) {\n if (mergeLateTransaction(live.route, step, lateAction)) {\n live.executionOptions?.updateRouteHook?.(live.route)\n }\n return\n }\n // A newer execution started and ended since the stop: the integrator\n // stored its route, which the kept one would roll back. The late\n // transaction goes into that route instead. With the records of the\n // route freed (no run in flight, `startCount` 0) the write is dropped.\n if (executionState.startCount(this.routeId) !== stopped.startCount) {\n const ended = executionState.lastEnded(this.routeId)\n if (ended && mergeLateTransaction(ended.route, step, lateAction)) {\n ended.updateRouteHook?.(ended.route)\n }\n return\n }\n const stepIndex = stopped.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n if (stepIndex === -1) {\n return\n }\n stopped.route.steps[stepIndex] = {\n ...stopped.route.steps[stepIndex],\n ...step,\n }\n stopped.updateRouteHook?.(stopped.route)\n } catch (error) {\n // Not rethrown, see above. The integrator's hook can throw here, so\n // the error is reported in development, as other swallowed errors are.\n if (process.env.NODE_ENV === 'development') {\n console.debug('Delivering late transaction data failed.', error)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AA6CA,MAAM,mBAAmB;CAAC;CAAU;CAAS;CAAU;AAAS;AAOhE,MAAM,mBAAmB,YAAgD;CACvE,QAAQ,OAAO;CACf,OAAO,OAAO;CACd,QAAQ,OAAO;CACf,SAAS,OAAO;AAClB;;AAGA,MAAM,sBACJ,QACA,WACY,iBAAiB,MAAM,QAAQ,OAAO,SAAS,OAAO,IAAI;;;;;;;AAQxE,MAAM,wBACJ,WACA,UACA,eACY;CAEZ,IAAI,CAACA,8BAAAA,mBAAmB,UAAU,GAChC,OAAO;CAET,MAAM,WAAW,UAAU,MAAM,MAC9B,cAAc,UAAU,OAAO,SAAS,EAC3C;CACA,IAAI,CAAC,UACH,OAAO;CAET,IAAI,CAAC,SAAS,WACZ,SAAS,YAAY;EACnB,WAAW,KAAK,IAAI;EACpB,QAAQ;EACR,SAAS,CAAC,gBAAgB,UAAU,CAAC;CACvC;MACK;EACL,MAAM,aAAa,SAAS,UAAU,QAAQ,MAC3C,WAAW,OAAO,SAAS,WAAW,IACzC;EACA,IAAI,CAAC,YACH,SAAS,UAAU,QAAQ,KAAK,gBAAgB,UAAU,CAAC;OACtD,IAAIA,8BAAAA,mBAAmB,UAAU,GAGtC,OAAO;OAKP,OAAO,OAAO,YAAY;GACxB,QAAQ,WAAW;GACnB,QAAQ,WAAW;GACnB,OAAO,WAAW;GAClB,SAAS,WAAW;GACpB,QAAQ,WAAW;GACnB,WAAW,WAAW;GACtB,QAAQ,WAAW;EACrB,CAAC;CAEL;CAGA,MAAM,WAAW,SAAS,WAAW;CACrC,IACEC,8BAAAA,yBAAyB,SAAS,WAAW,IAAI,KACjD,aAAa,KAAA,GAEb,SAAS,UAAU,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EACvC;GACA,IAAI,cAAc,IAChB;GAEF,QAAQ,MAAM,MAAM,aAAa;IAC/B,GAAG,QAAQ,MAAM,MAAM;IACvB,GAAG;GACL;GACA,QAAQ,kBAAkB,QAAQ,KAAK;EACzC,SAAS,OAAO;GAGd,IAAI,QAAQ,IAAI,aAAa,eAC3B,QAAQ,MAAM,4CAA4C,KAAK;EAEnE;CACF;AACF"}
@@ -34,10 +34,11 @@ export declare const CLOCK_SKEW_MARGIN_MS = 6e5;
34
34
  * Fields a sign task clears before it writes a new transaction's data, and
35
35
  * that re-initializing a final-failed action clears. `taskId` is included: a
36
36
  * stale relayed or batched task id would otherwise keep the action open.
37
+ * `callCount` goes with a batched task id.
37
38
  *
38
39
  * @internal
39
40
  */
40
- export declare const CLEARED_TRANSACTION_FIELDS: Readonly<Pick<ExecutionAction, "txHash" | "txLink" | "txHex" | "txFinal" | "taskId">>;
41
+ export declare const CLEARED_TRANSACTION_FIELDS: Readonly<Pick<ExecutionAction, "txHash" | "txLink" | "txHex" | "txFinal" | "taskId" | "callCount">>;
41
42
  /**
42
43
  * True when the action has a transaction to follow, landed or not: a hash, a
43
44
  * task id or stored signed bytes, unless the action FAILED with a final
@@ -60,11 +61,12 @@ export declare const CLEARED_TRANSACTION_FIELDS: Readonly<Pick<ExecutionAction,
60
61
  * stored bytes only while `isResendAllowed` (or the chain's own expiry)
61
62
  * allows it; otherwise it only waits.
62
63
  * 5. Mark an error final only on a verdict about the transaction: failed
63
- * or reverted (on chain or at the relayer), cancelled, replaced, or
64
- * dropped with proof. Dropped needs all three: the transaction can no
65
- * longer land, a node that covers its window reports it absent (in the
66
- * same response where the chain allows it), and `isKnownToStatusApi` is
67
- * false. In doubt, throw without the marker and keep the fields.
64
+ * or reverted (on chain or at the relayer), cancelled (also by a wallet
65
+ * that removed it before it sent it), replaced, or dropped with proof.
66
+ * Dropped needs all three: the transaction can no longer land, a node
67
+ * that covers its window reports it absent (in the same response where
68
+ * the chain allows it), and `isKnownToStatusApi` is false. In doubt,
69
+ * throw without the marker and keep the fields.
68
70
  * 6. Give `context.signal` only to waits that start after the broadcast. On
69
71
  * abort, return `PAUSED` and write nothing.
70
72
  */
@@ -35,6 +35,7 @@ const CLOCK_SKEW_MARGIN_MS = 6e5;
35
35
  * Fields a sign task clears before it writes a new transaction's data, and
36
36
  * that re-initializing a final-failed action clears. `taskId` is included: a
37
37
  * stale relayed or batched task id would otherwise keep the action open.
38
+ * `callCount` goes with a batched task id.
38
39
  *
39
40
  * @internal
40
41
  */
@@ -43,7 +44,8 @@ const CLEARED_TRANSACTION_FIELDS = Object.freeze({
43
44
  txLink: void 0,
44
45
  txHex: void 0,
45
46
  txFinal: void 0,
46
- taskId: void 0
47
+ taskId: void 0,
48
+ callCount: void 0
47
49
  });
48
50
  /**
49
51
  * True when the action has a transaction to follow, landed or not: a hash, a
@@ -67,11 +69,12 @@ const CLEARED_TRANSACTION_FIELDS = Object.freeze({
67
69
  * stored bytes only while `isResendAllowed` (or the chain's own expiry)
68
70
  * allows it; otherwise it only waits.
69
71
  * 5. Mark an error final only on a verdict about the transaction: failed
70
- * or reverted (on chain or at the relayer), cancelled, replaced, or
71
- * dropped with proof. Dropped needs all three: the transaction can no
72
- * longer land, a node that covers its window reports it absent (in the
73
- * same response where the chain allows it), and `isKnownToStatusApi` is
74
- * false. In doubt, throw without the marker and keep the fields.
72
+ * or reverted (on chain or at the relayer), cancelled (also by a wallet
73
+ * that removed it before it sent it), replaced, or dropped with proof.
74
+ * Dropped needs all three: the transaction can no longer land, a node
75
+ * that covers its window reports it absent (in the same response where
76
+ * the chain allows it), and `isKnownToStatusApi` is false. In doubt,
77
+ * throw without the marker and keep the fields.
75
78
  * 6. Give `context.signal` only to waits that start after the broadcast. On
76
79
  * abort, return `PAUSED` and write nothing.
77
80
  */
@@ -1 +1 @@
1
- {"version":3,"file":"transactionState.js","names":["TransactionError"],"sources":["../../../src/core/transactionState.ts"],"sourcesContent":["import { LiFiErrorCode } from '../errors/constants.js'\nimport { TransactionError } from '../errors/errors.js'\nimport type {\n ExecutionAction,\n ExecutionActionType,\n LiFiStepExtended,\n} from '../types/core.js'\n\n/**\n * Action types that carry the step's own transaction.\n *\n * @internal\n */\nexport const TRANSACTION_ACTION_TYPES: readonly ExecutionActionType[] = [\n 'SWAP',\n 'CROSS_CHAIN',\n]\n\n/**\n * Stored bytes on a chain without its own expiry (Sui, Solana with a durable\n * nonce, Bitcoin) are resent only this long after signing. Past it, a page\n * load could otherwise execute a swap on a quote the user no longer expects.\n *\n * @internal\n */\nexport const MAX_RESEND_AGE_MS = 120_000\n\n/**\n * Without an expiry verdict, a signature younger than this is never declared\n * dropped. Solana blockhashes and Tron transactions expire well before it.\n *\n * @internal\n */\nexport const DROPPED_FALLBACK_AGE_MS = 300_000\n\n/**\n * Subtracted from `execution.signedAt` (the device clock) when it anchors a\n * history-coverage check, so a device clock that runs fast cannot make a node\n * look like it covers the signing time when it does not.\n *\n * @internal\n */\nexport const CLOCK_SKEW_MARGIN_MS = 600_000\n\n/**\n * Fields a sign task clears before it writes a new transaction's data, and\n * that re-initializing a final-failed action clears. `taskId` is included: a\n * stale relayed or batched task id would otherwise keep the action open.\n *\n * @internal\n */\nexport const CLEARED_TRANSACTION_FIELDS: Readonly<\n Pick<ExecutionAction, 'txHash' | 'txLink' | 'txHex' | 'txFinal' | 'taskId'>\n> = Object.freeze({\n txHash: undefined,\n txLink: undefined,\n txHex: undefined,\n txFinal: undefined,\n taskId: undefined,\n})\n\n/**\n * True when the action has a transaction to follow, landed or not: a hash, a\n * task id or stored signed bytes, unless the action FAILED with a final\n * outcome. Every resume decision uses this one predicate, so the pipeline\n * selector and the pre-sign guard can never disagree.\n *\n * Resume rules for providers. A step never signs or sends a second\n * transaction while an earlier one can still land:\n * 1. Pick the first task with this predicate: open and DONE, the status\n * wait; open, the provider's wait task; otherwise the first task.\n * 2. In the sign task, call `assertNoOpenTransaction` at the start, right\n * before each wallet call and, where the SDK sends, right after the\n * wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`\n * and `signedAt`.\n * 3. From the last check, nothing awaits until the send or, where the SDK\n * sends signed bytes, until they are stored as `txHex`, before the first\n * send. Clear `txHex` only when the outcome is known, no node can still\n * hold the bytes, or they no longer decode.\n * 4. A resume never signs. It looks the transaction up and resends the\n * stored bytes only while `isResendAllowed` (or the chain's own expiry)\n * allows it; otherwise it only waits.\n * 5. Mark an error final only on a verdict about the transaction: failed\n * or reverted (on chain or at the relayer), cancelled, replaced, or\n * dropped with proof. Dropped needs all three: the transaction can no\n * longer land, a node that covers its window reports it absent (in the\n * same response where the chain allows it), and `isKnownToStatusApi` is\n * false. In doubt, throw without the marker and keep the fields.\n * 6. Give `context.signal` only to waits that start after the broadcast. On\n * abort, return `PAUSED` and write nothing.\n */\nexport function hasOpenTransaction(action?: ExecutionAction): boolean {\n if (!action) {\n return false\n }\n if (!(action.txHash || action.taskId || action.txHex)) {\n return false\n }\n return !(action.status === 'FAILED' && action.txFinal === true)\n}\n\n/**\n * True when any SWAP / CROSS_CHAIN action of the step has an open transaction.\n *\n * @internal\n */\nexport function hasStepOpenTransaction(step: LiFiStepExtended): boolean {\n return !!step.execution?.actions?.some(\n (action) =>\n TRANSACTION_ACTION_TYPES.includes(action.type) &&\n hasOpenTransaction(action)\n )\n}\n\n/**\n * Walks the error and its `cause` chain. Parsers may rebuild errors, so the\n * marker is read from the original error. A property check instead of\n * `instanceof` keeps it working across duplicated installs.\n *\n * @internal\n */\nexport function isFinalTransactionError(error: unknown): boolean {\n const seen = new Set<unknown>()\n let current: unknown = error\n while (current && typeof current === 'object' && !seen.has(current)) {\n seen.add(current)\n if ((current as { final?: unknown }).final === true) {\n return true\n }\n current = (current as { cause?: unknown }).cause\n }\n return false\n}\n\n/**\n * The error of a step that would sign a second transaction while its first\n * one may still land.\n *\n * @internal\n */\nexport function transactionConflictError(): TransactionError {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'A transaction for this step was already signed and may still land. Resume the route to wait for it instead of signing a new one.'\n )\n}\n\n/**\n * Called first in every sign task. With correct pipeline selectors it never\n * throws; it stops a second signature if a selector ever routes an open\n * transaction back to signing. Every sign task calls it again on the freshly\n * found action right before its wallet call: a late write of an older run can\n * merge a transaction into the action during the awaits in between. A sign\n * task that sends the transaction itself calls it once more after the wallet\n * returns, before it writes or sends anything: the merge can also land while\n * the prompt is open.\n *\n * @internal\n */\nexport function assertNoOpenTransaction(action?: ExecutionAction): void {\n if (hasOpenTransaction(action)) {\n throw transactionConflictError()\n }\n}\n\n/**\n * Unknown signing time never allows a resend. Nor does a signing time in the\n * future: a device clock that ran ahead at signing and was corrected later\n * would otherwise stretch the cap by the clock error.\n *\n * @internal\n */\nexport function isResendAllowed(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < MAX_RESEND_AGE_MS\n )\n}\n\n/**\n * Unknown signing time never allows a drop.\n *\n * @internal\n */\nexport function isOldEnoughToDrop(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return signedAt !== undefined && now - signedAt > DROPPED_FALLBACK_AGE_MS\n}\n"],"mappings":";;;;;;;;;AAaA,MAAa,2BAA2D,CACtE,QACA,aACF;;;;;;;;AASA,MAAa,oBAAoB;;;;;;;AAQjC,MAAa,0BAA0B;;;;;;;;AASvC,MAAa,uBAAuB;;;;;;;;AASpC,MAAa,6BAET,OAAO,OAAO;CAChB,QAAQ,KAAA;CACR,QAAQ,KAAA;CACR,OAAO,KAAA;CACP,SAAS,KAAA;CACT,QAAQ,KAAA;AACV,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCD,SAAgB,mBAAmB,QAAmC;CACpE,IAAI,CAAC,QACH,OAAO;CAET,IAAI,EAAE,OAAO,UAAU,OAAO,UAAU,OAAO,QAC7C,OAAO;CAET,OAAO,EAAE,OAAO,WAAW,YAAY,OAAO,YAAY;AAC5D;;;;;;AAOA,SAAgB,uBAAuB,MAAiC;CACtE,OAAO,CAAC,CAAC,KAAK,WAAW,SAAS,MAC/B,WACC,yBAAyB,SAAS,OAAO,IAAI,KAC7C,mBAAmB,MAAM,CAC7B;AACF;;;;;;;;AASA,SAAgB,wBAAwB,OAAyB;CAC/D,MAAM,uBAAO,IAAI,IAAa;CAC9B,IAAI,UAAmB;CACvB,OAAO,WAAW,OAAO,YAAY,YAAY,CAAC,KAAK,IAAI,OAAO,GAAG;EACnE,KAAK,IAAI,OAAO;EAChB,IAAK,QAAgC,UAAU,MAC7C,OAAO;EAET,UAAW,QAAgC;CAC7C;CACA,OAAO;AACT;;;;;;;AAQA,SAAgB,2BAA6C;CAC3D,OAAO,IAAIA,sBAAAA,iBAAAA,MAET,kIACF;AACF;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,QAAgC;CACtE,IAAI,mBAAmB,MAAM,GAC3B,MAAM,yBAAyB;AAEnC;;;;;;;;AASA,SAAgB,gBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAA;AAEV;;;;;;AAOA,SAAgB,kBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OAAO,aAAa,KAAA,KAAa,MAAM,WAAA;AACzC"}
1
+ {"version":3,"file":"transactionState.js","names":["TransactionError"],"sources":["../../../src/core/transactionState.ts"],"sourcesContent":["import { LiFiErrorCode } from '../errors/constants.js'\nimport { TransactionError } from '../errors/errors.js'\nimport type {\n ExecutionAction,\n ExecutionActionType,\n LiFiStepExtended,\n} from '../types/core.js'\n\n/**\n * Action types that carry the step's own transaction.\n *\n * @internal\n */\nexport const TRANSACTION_ACTION_TYPES: readonly ExecutionActionType[] = [\n 'SWAP',\n 'CROSS_CHAIN',\n]\n\n/**\n * Stored bytes on a chain without its own expiry (Sui, Solana with a durable\n * nonce, Bitcoin) are resent only this long after signing. Past it, a page\n * load could otherwise execute a swap on a quote the user no longer expects.\n *\n * @internal\n */\nexport const MAX_RESEND_AGE_MS = 120_000\n\n/**\n * Without an expiry verdict, a signature younger than this is never declared\n * dropped. Solana blockhashes and Tron transactions expire well before it.\n *\n * @internal\n */\nexport const DROPPED_FALLBACK_AGE_MS = 300_000\n\n/**\n * Subtracted from `execution.signedAt` (the device clock) when it anchors a\n * history-coverage check, so a device clock that runs fast cannot make a node\n * look like it covers the signing time when it does not.\n *\n * @internal\n */\nexport const CLOCK_SKEW_MARGIN_MS = 600_000\n\n/**\n * Fields a sign task clears before it writes a new transaction's data, and\n * that re-initializing a final-failed action clears. `taskId` is included: a\n * stale relayed or batched task id would otherwise keep the action open.\n * `callCount` goes with a batched task id.\n *\n * @internal\n */\nexport const CLEARED_TRANSACTION_FIELDS: Readonly<\n Pick<\n ExecutionAction,\n 'txHash' | 'txLink' | 'txHex' | 'txFinal' | 'taskId' | 'callCount'\n >\n> = Object.freeze({\n txHash: undefined,\n txLink: undefined,\n txHex: undefined,\n txFinal: undefined,\n taskId: undefined,\n callCount: undefined,\n})\n\n/**\n * True when the action has a transaction to follow, landed or not: a hash, a\n * task id or stored signed bytes, unless the action FAILED with a final\n * outcome. Every resume decision uses this one predicate, so the pipeline\n * selector and the pre-sign guard can never disagree.\n *\n * Resume rules for providers. A step never signs or sends a second\n * transaction while an earlier one can still land:\n * 1. Pick the first task with this predicate: open and DONE, the status\n * wait; open, the provider's wait task; otherwise the first task.\n * 2. In the sign task, call `assertNoOpenTransaction` at the start, right\n * before each wallet call and, where the SDK sends, right after the\n * wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`\n * and `signedAt`.\n * 3. From the last check, nothing awaits until the send or, where the SDK\n * sends signed bytes, until they are stored as `txHex`, before the first\n * send. Clear `txHex` only when the outcome is known, no node can still\n * hold the bytes, or they no longer decode.\n * 4. A resume never signs. It looks the transaction up and resends the\n * stored bytes only while `isResendAllowed` (or the chain's own expiry)\n * allows it; otherwise it only waits.\n * 5. Mark an error final only on a verdict about the transaction: failed\n * or reverted (on chain or at the relayer), cancelled (also by a wallet\n * that removed it before it sent it), replaced, or dropped with proof.\n * Dropped needs all three: the transaction can no longer land, a node\n * that covers its window reports it absent (in the same response where\n * the chain allows it), and `isKnownToStatusApi` is false. In doubt,\n * throw without the marker and keep the fields.\n * 6. Give `context.signal` only to waits that start after the broadcast. On\n * abort, return `PAUSED` and write nothing.\n */\nexport function hasOpenTransaction(action?: ExecutionAction): boolean {\n if (!action) {\n return false\n }\n if (!(action.txHash || action.taskId || action.txHex)) {\n return false\n }\n return !(action.status === 'FAILED' && action.txFinal === true)\n}\n\n/**\n * True when any SWAP / CROSS_CHAIN action of the step has an open transaction.\n *\n * @internal\n */\nexport function hasStepOpenTransaction(step: LiFiStepExtended): boolean {\n return !!step.execution?.actions?.some(\n (action) =>\n TRANSACTION_ACTION_TYPES.includes(action.type) &&\n hasOpenTransaction(action)\n )\n}\n\n/**\n * Walks the error and its `cause` chain. Parsers may rebuild errors, so the\n * marker is read from the original error. A property check instead of\n * `instanceof` keeps it working across duplicated installs.\n *\n * @internal\n */\nexport function isFinalTransactionError(error: unknown): boolean {\n const seen = new Set<unknown>()\n let current: unknown = error\n while (current && typeof current === 'object' && !seen.has(current)) {\n seen.add(current)\n if ((current as { final?: unknown }).final === true) {\n return true\n }\n current = (current as { cause?: unknown }).cause\n }\n return false\n}\n\n/**\n * The error of a step that would sign a second transaction while its first\n * one may still land.\n *\n * @internal\n */\nexport function transactionConflictError(): TransactionError {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'A transaction for this step was already signed and may still land. Resume the route to wait for it instead of signing a new one.'\n )\n}\n\n/**\n * Called first in every sign task. With correct pipeline selectors it never\n * throws; it stops a second signature if a selector ever routes an open\n * transaction back to signing. Every sign task calls it again on the freshly\n * found action right before its wallet call: a late write of an older run can\n * merge a transaction into the action during the awaits in between. A sign\n * task that sends the transaction itself calls it once more after the wallet\n * returns, before it writes or sends anything: the merge can also land while\n * the prompt is open.\n *\n * @internal\n */\nexport function assertNoOpenTransaction(action?: ExecutionAction): void {\n if (hasOpenTransaction(action)) {\n throw transactionConflictError()\n }\n}\n\n/**\n * Unknown signing time never allows a resend. Nor does a signing time in the\n * future: a device clock that ran ahead at signing and was corrected later\n * would otherwise stretch the cap by the clock error.\n *\n * @internal\n */\nexport function isResendAllowed(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < MAX_RESEND_AGE_MS\n )\n}\n\n/**\n * Unknown signing time never allows a drop.\n *\n * @internal\n */\nexport function isOldEnoughToDrop(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return signedAt !== undefined && now - signedAt > DROPPED_FALLBACK_AGE_MS\n}\n"],"mappings":";;;;;;;;;AAaA,MAAa,2BAA2D,CACtE,QACA,aACF;;;;;;;;AASA,MAAa,oBAAoB;;;;;;;AAQjC,MAAa,0BAA0B;;;;;;;;AASvC,MAAa,uBAAuB;;;;;;;;;AAUpC,MAAa,6BAKT,OAAO,OAAO;CAChB,QAAQ,KAAA;CACR,QAAQ,KAAA;CACR,OAAO,KAAA;CACP,SAAS,KAAA;CACT,QAAQ,KAAA;CACR,WAAW,KAAA;AACb,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCD,SAAgB,mBAAmB,QAAmC;CACpE,IAAI,CAAC,QACH,OAAO;CAET,IAAI,EAAE,OAAO,UAAU,OAAO,UAAU,OAAO,QAC7C,OAAO;CAET,OAAO,EAAE,OAAO,WAAW,YAAY,OAAO,YAAY;AAC5D;;;;;;AAOA,SAAgB,uBAAuB,MAAiC;CACtE,OAAO,CAAC,CAAC,KAAK,WAAW,SAAS,MAC/B,WACC,yBAAyB,SAAS,OAAO,IAAI,KAC7C,mBAAmB,MAAM,CAC7B;AACF;;;;;;;;AASA,SAAgB,wBAAwB,OAAyB;CAC/D,MAAM,uBAAO,IAAI,IAAa;CAC9B,IAAI,UAAmB;CACvB,OAAO,WAAW,OAAO,YAAY,YAAY,CAAC,KAAK,IAAI,OAAO,GAAG;EACnE,KAAK,IAAI,OAAO;EAChB,IAAK,QAAgC,UAAU,MAC7C,OAAO;EAET,UAAW,QAAgC;CAC7C;CACA,OAAO;AACT;;;;;;;AAQA,SAAgB,2BAA6C;CAC3D,OAAO,IAAIA,sBAAAA,iBAAAA,MAET,kIACF;AACF;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,QAAgC;CACtE,IAAI,mBAAmB,MAAM,GAC3B,MAAM,yBAAyB;AAEnC;;;;;;;;AASA,SAAgB,gBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAA;AAEV;;;;;;AAOA,SAAgB,kBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OAAO,aAAa,KAAA,KAAa,MAAM,WAAA;AACzC"}
@@ -42,7 +42,8 @@ export declare enum LiFiErrorCode {
42
42
  ThirdPartyError = 1024,
43
43
  InsufficientGas = 1025,
44
44
  ConfigError = 1026,
45
- RpcUnavailable = 1027
45
+ RpcUnavailable = 1027,
46
+ CallBundleNotFound = 1028
46
47
  }
47
48
  export declare enum ErrorMessage {
48
49
  UnknownError = "Unknown error occurred.",
@@ -44,6 +44,7 @@ let LiFiErrorCode = /* @__PURE__ */ function(LiFiErrorCode) {
44
44
  LiFiErrorCode[LiFiErrorCode["InsufficientGas"] = 1025] = "InsufficientGas";
45
45
  LiFiErrorCode[LiFiErrorCode["ConfigError"] = 1026] = "ConfigError";
46
46
  LiFiErrorCode[LiFiErrorCode["RpcUnavailable"] = 1027] = "RpcUnavailable";
47
+ LiFiErrorCode[LiFiErrorCode["CallBundleNotFound"] = 1028] = "CallBundleNotFound";
47
48
  return LiFiErrorCode;
48
49
  }({});
49
50
  let ErrorMessage = /* @__PURE__ */ function(ErrorMessage) {
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../../../src/errors/constants.ts"],"sourcesContent":["export enum ErrorName {\n RPCError = 'RPCError',\n ProviderError = 'ProviderError',\n ServerError = 'ServerError',\n TransactionError = 'TransactionError',\n ValidationError = 'ValidationError',\n BalanceError = 'BalanceError',\n NotFoundError = 'NotFoundError',\n UnknownError = 'UnknownError',\n SlippageError = 'SlippageError',\n HTTPError = 'HTTPError',\n ConfigError = 'ConfigError',\n ExecuteStepRetryError = 'ExecuteStepRetryError',\n}\n\nexport type ErrorCode = LiFiErrorCode\n\nexport enum LiFiErrorCode {\n InternalError = 1000,\n ValidationError = 1001,\n TransactionUnderpriced = 1002,\n TransactionFailed = 1003,\n Timeout = 1004,\n ProviderUnavailable = 1005,\n NotFound = 1006,\n ChainSwitchError = 1007,\n TransactionUnprepared = 1008,\n GasLimitError = 1009,\n TransactionCanceled = 1010,\n SlippageError = 1011,\n SignatureRejected = 1012,\n BalanceError = 1013,\n AllowanceRequired = 1014,\n InsufficientFunds = 1015,\n ExchangeRateUpdateCanceled = 1016,\n WalletChangedDuringExecution = 1017,\n TransactionExpired = 1018,\n TransactionSimulationFailed = 1019,\n TransactionConflict = 1020,\n TransactionNotFound = 1021,\n TransactionRejected = 1022,\n RateLimitExceeded = 1023,\n ThirdPartyError = 1024,\n InsufficientGas = 1025,\n ConfigError = 1026,\n RpcUnavailable = 1027,\n}\n\nexport enum ErrorMessage {\n UnknownError = 'Unknown error occurred.',\n SlippageError = 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.',\n GasLimitLow = 'Gas limit is too low.',\n TransactionUnderpriced = 'Transaction is underpriced.',\n TransactionReverted = 'Transaction was reverted.',\n}\n"],"mappings":";;AAAA,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,cAAA;CACA,UAAA,mBAAA;CACA,UAAA,iBAAA;CACA,UAAA,sBAAA;CACA,UAAA,qBAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,eAAA;CACA,UAAA,iBAAA;CACA,UAAA,2BAAA;;AACF,EAAA,CAAA,CAAA;AAIA,IAAY,gBAAL,yBAAA,eAAA;CACL,cAAA,cAAA,mBAAA,OAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,4BAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,aAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,cAAA,QAAA;CACA,cAAA,cAAA,sBAAA,QAAA;CACA,cAAA,cAAA,2BAAA,QAAA;CACA,cAAA,cAAA,mBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,mBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,kBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,gCAAA,QAAA;CACA,cAAA,cAAA,kCAAA,QAAA;CACA,cAAA,cAAA,wBAAA,QAAA;CACA,cAAA,cAAA,iCAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,iBAAA,QAAA;CACA,cAAA,cAAA,oBAAA,QAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAY,eAAL,yBAAA,cAAA;CACL,aAAA,kBAAA;CACA,aAAA,mBAAA;CACA,aAAA,iBAAA;CACA,aAAA,4BAAA;CACA,aAAA,yBAAA;;AACF,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../../src/errors/constants.ts"],"sourcesContent":["export enum ErrorName {\n RPCError = 'RPCError',\n ProviderError = 'ProviderError',\n ServerError = 'ServerError',\n TransactionError = 'TransactionError',\n ValidationError = 'ValidationError',\n BalanceError = 'BalanceError',\n NotFoundError = 'NotFoundError',\n UnknownError = 'UnknownError',\n SlippageError = 'SlippageError',\n HTTPError = 'HTTPError',\n ConfigError = 'ConfigError',\n ExecuteStepRetryError = 'ExecuteStepRetryError',\n}\n\nexport type ErrorCode = LiFiErrorCode\n\nexport enum LiFiErrorCode {\n InternalError = 1000,\n ValidationError = 1001,\n TransactionUnderpriced = 1002,\n TransactionFailed = 1003,\n Timeout = 1004,\n ProviderUnavailable = 1005,\n NotFound = 1006,\n ChainSwitchError = 1007,\n TransactionUnprepared = 1008,\n GasLimitError = 1009,\n TransactionCanceled = 1010,\n SlippageError = 1011,\n SignatureRejected = 1012,\n BalanceError = 1013,\n AllowanceRequired = 1014,\n InsufficientFunds = 1015,\n ExchangeRateUpdateCanceled = 1016,\n WalletChangedDuringExecution = 1017,\n TransactionExpired = 1018,\n TransactionSimulationFailed = 1019,\n TransactionConflict = 1020,\n TransactionNotFound = 1021,\n TransactionRejected = 1022,\n RateLimitExceeded = 1023,\n ThirdPartyError = 1024,\n InsufficientGas = 1025,\n ConfigError = 1026,\n RpcUnavailable = 1027,\n CallBundleNotFound = 1028,\n}\n\nexport enum ErrorMessage {\n UnknownError = 'Unknown error occurred.',\n SlippageError = 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.',\n GasLimitLow = 'Gas limit is too low.',\n TransactionUnderpriced = 'Transaction is underpriced.',\n TransactionReverted = 'Transaction was reverted.',\n}\n"],"mappings":";;AAAA,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,cAAA;CACA,UAAA,mBAAA;CACA,UAAA,iBAAA;CACA,UAAA,sBAAA;CACA,UAAA,qBAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,eAAA;CACA,UAAA,iBAAA;CACA,UAAA,2BAAA;;AACF,EAAA,CAAA,CAAA;AAIA,IAAY,gBAAL,yBAAA,eAAA;CACL,cAAA,cAAA,mBAAA,OAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,4BAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,aAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,cAAA,QAAA;CACA,cAAA,cAAA,sBAAA,QAAA;CACA,cAAA,cAAA,2BAAA,QAAA;CACA,cAAA,cAAA,mBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,mBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,kBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,gCAAA,QAAA;CACA,cAAA,cAAA,kCAAA,QAAA;CACA,cAAA,cAAA,wBAAA,QAAA;CACA,cAAA,cAAA,iCAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,iBAAA,QAAA;CACA,cAAA,cAAA,oBAAA,QAAA;CACA,cAAA,cAAA,wBAAA,QAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAY,eAAL,yBAAA,cAAA;CACL,aAAA,kBAAA;CACA,aAAA,mBAAA;CACA,aAAA,iBAAA;CACA,aAAA,4BAAA;CACA,aAAA,yBAAA;;AACF,EAAA,CAAA,CAAA"}
@@ -11,9 +11,9 @@ export declare class ProviderError extends BaseError {
11
11
  export interface TransactionErrorOptions {
12
12
  /**
13
13
  * A definite verdict about the transaction (failed or reverted on chain or
14
- * at the relayer, cancelled, replaced, or dropped with proof). The step
15
- * executor then flags the failed action with `txFinal`, so a restart signs
16
- * a new transaction.
14
+ * at the relayer, cancelled (also by a wallet that removed it before it
15
+ * sent it), replaced, or dropped with proof). The step executor then flags
16
+ * the failed action with `txFinal`, so a restart signs a new transaction.
17
17
  */
18
18
  final?: boolean;
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":["BaseError"],"sources":["../../../src/errors/errors.ts"],"sourcesContent":["import type { ExecuteStepRetryParams } from '../types/core.js'\nimport { BaseError } from './baseError.js'\nimport { ErrorName, LiFiErrorCode } from './constants.js'\n\nexport class RPCError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.RPCError, code, message, cause)\n }\n}\n\nexport class ProviderError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.ProviderError, code, message, cause)\n }\n}\n\nexport interface TransactionErrorOptions {\n /**\n * A definite verdict about the transaction (failed or reverted on chain or\n * at the relayer, cancelled, replaced, or dropped with proof). The step\n * executor then flags the failed action with `txFinal`, so a restart signs\n * a new transaction.\n */\n final?: boolean\n}\n\nexport class TransactionError extends BaseError {\n readonly final: boolean\n\n constructor(\n code: LiFiErrorCode,\n message: string,\n cause?: Error,\n options?: TransactionErrorOptions\n ) {\n super(ErrorName.TransactionError, code, message, cause)\n this.final = options?.final ?? false\n }\n}\n\nexport class UnknownError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)\n }\n}\n\nexport class BalanceError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)\n }\n}\n\nexport class ServerError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)\n }\n}\n\nexport class ValidationError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)\n }\n}\n\n/**\n * Thrown by a step executor when executeStep should be retried with the given params\n * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).\n * The execution layer catches this and retries executeStep(client, step, retryParams),\n * unless the route was stopped or the step has an open transaction.\n */\nexport class ExecuteStepRetryError extends BaseError {\n readonly retryParams: ExecuteStepRetryParams\n\n constructor(\n message: string,\n retryParams: ExecuteStepRetryParams,\n cause?: Error\n ) {\n super(\n ErrorName.ExecuteStepRetryError,\n LiFiErrorCode.InternalError,\n message,\n cause\n )\n this.retryParams = retryParams\n }\n}\n"],"mappings":";;;;AAIA,IAAa,WAAb,cAA8BA,yBAAAA,UAAU;CACtC,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,YAA0B,MAAM,SAAS,KAAK;CAChD;AACF;AAEA,IAAa,gBAAb,cAAmCA,yBAAAA,UAAU;CAC3C,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,iBAA+B,MAAM,SAAS,KAAK;CACrD;AACF;AAYA,IAAa,mBAAb,cAAsCA,yBAAAA,UAAU;CAC9C;CAEA,YACE,MACA,SACA,OACA,SACA;EACA,MAAA,oBAAkC,MAAM,SAAS,KAAK;EACtD,KAAK,QAAQ,SAAS,SAAS;CACjC;AACF;AAEA,IAAa,eAAb,cAAkCA,yBAAAA,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,KAA2D,SAAS,KAAK;CAC3E;AACF;AAEA,IAAa,eAAb,cAAkCA,yBAAAA,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,MAA0D,SAAS,KAAK;CAC1E;AACF;AAEA,IAAa,cAAb,cAAiCA,yBAAAA,UAAU;CACzC,YAAY,SAAiB;EAC3B,MAAA,eAAA,KAA0D,OAAO;CACnE;AACF;AAEA,IAAa,kBAAb,cAAqCA,yBAAAA,UAAU;CAC7C,YAAY,SAAiB;EAC3B,MAAA,mBAAA,MAAgE,OAAO;CACzE;AACF;;;;;;;AAQA,IAAa,wBAAb,cAA2CA,yBAAAA,UAAU;CACnD;CAEA,YACE,SACA,aACA,OACA;EACA,MAAA,yBAAA,KAGE,SACA,KACF;EACA,KAAK,cAAc;CACrB;AACF"}
1
+ {"version":3,"file":"errors.js","names":["BaseError"],"sources":["../../../src/errors/errors.ts"],"sourcesContent":["import type { ExecuteStepRetryParams } from '../types/core.js'\nimport { BaseError } from './baseError.js'\nimport { ErrorName, LiFiErrorCode } from './constants.js'\n\nexport class RPCError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.RPCError, code, message, cause)\n }\n}\n\nexport class ProviderError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.ProviderError, code, message, cause)\n }\n}\n\nexport interface TransactionErrorOptions {\n /**\n * A definite verdict about the transaction (failed or reverted on chain or\n * at the relayer, cancelled (also by a wallet that removed it before it\n * sent it), replaced, or dropped with proof). The step executor then flags\n * the failed action with `txFinal`, so a restart signs a new transaction.\n */\n final?: boolean\n}\n\nexport class TransactionError extends BaseError {\n readonly final: boolean\n\n constructor(\n code: LiFiErrorCode,\n message: string,\n cause?: Error,\n options?: TransactionErrorOptions\n ) {\n super(ErrorName.TransactionError, code, message, cause)\n this.final = options?.final ?? false\n }\n}\n\nexport class UnknownError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)\n }\n}\n\nexport class BalanceError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)\n }\n}\n\nexport class ServerError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)\n }\n}\n\nexport class ValidationError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)\n }\n}\n\n/**\n * Thrown by a step executor when executeStep should be retried with the given params\n * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).\n * The execution layer catches this and retries executeStep(client, step, retryParams),\n * unless the route was stopped or the step has an open transaction.\n */\nexport class ExecuteStepRetryError extends BaseError {\n readonly retryParams: ExecuteStepRetryParams\n\n constructor(\n message: string,\n retryParams: ExecuteStepRetryParams,\n cause?: Error\n ) {\n super(\n ErrorName.ExecuteStepRetryError,\n LiFiErrorCode.InternalError,\n message,\n cause\n )\n this.retryParams = retryParams\n }\n}\n"],"mappings":";;;;AAIA,IAAa,WAAb,cAA8BA,yBAAAA,UAAU;CACtC,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,YAA0B,MAAM,SAAS,KAAK;CAChD;AACF;AAEA,IAAa,gBAAb,cAAmCA,yBAAAA,UAAU;CAC3C,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,iBAA+B,MAAM,SAAS,KAAK;CACrD;AACF;AAYA,IAAa,mBAAb,cAAsCA,yBAAAA,UAAU;CAC9C;CAEA,YACE,MACA,SACA,OACA,SACA;EACA,MAAA,oBAAkC,MAAM,SAAS,KAAK;EACtD,KAAK,QAAQ,SAAS,SAAS;CACjC;AACF;AAEA,IAAa,eAAb,cAAkCA,yBAAAA,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,KAA2D,SAAS,KAAK;CAC3E;AACF;AAEA,IAAa,eAAb,cAAkCA,yBAAAA,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,MAA0D,SAAS,KAAK;CAC1E;AACF;AAEA,IAAa,cAAb,cAAiCA,yBAAAA,UAAU;CACzC,YAAY,SAAiB;EAC3B,MAAA,eAAA,KAA0D,OAAO;CACnE;AACF;AAEA,IAAa,kBAAb,cAAqCA,yBAAAA,UAAU;CAC7C,YAAY,SAAiB;EAC3B,MAAA,mBAAA,MAAgE,OAAO;CACzE;AACF;;;;;;;AAQA,IAAa,wBAAb,cAA2CA,yBAAAA,UAAU;CACnD;CAEA,YACE,SACA,aACA,OACA;EACA,MAAA,yBAAA,KAGE,SACA,KACF;EACA,KAAK,cAAc;CACrB;AACF"}
@@ -173,10 +173,10 @@ export type RouteExecutionDictionary = Partial<Record<string, Promise<Route>>>;
173
173
  * store it.
174
174
  *
175
175
  * After `stopRouteExecution` it can still be called, but only to deliver the
176
- * transaction data (`txHash`, `txHex`, `taskId`, `txFinal`) of a task that
177
- * was still running at the stop, for example in an open wallet prompt. Store
178
- * that data, so a resume waits for that transaction instead of signing
179
- * again. If you deleted the route, ignore the call.
176
+ * transaction data (`txHash`, `txHex`, `taskId`, `callCount`, `txFinal`) of a
177
+ * task that was still running at the stop, for example in an open wallet
178
+ * prompt. Store that data, so a resume waits for that transaction instead of
179
+ * signing again. If you deleted the route, ignore the call.
180
180
  */
181
181
  export type UpdateRouteHook = (updatedRoute: RouteExtended) => void;
182
182
  export interface TransactionRequestParameters extends TransactionParameters {
@@ -245,6 +245,12 @@ export type ExecutionAction = {
245
245
  txLink?: string;
246
246
  taskId?: string;
247
247
  txType?: TransactionMethodType;
248
+ /**
249
+ * The number of calls of a batched (EIP-5792) transaction. Set with
250
+ * `taskId` when `txType` is `batched`. The batched wait reads it after a
251
+ * reload, when the calls are gone.
252
+ */
253
+ callCount?: number;
248
254
  /**
249
255
  * Provider-specific serialized signed transaction (hex, XDR, base64 or JSON).
250
256
  * Present while the transaction may still need to be (re)sent or looked up.
@@ -255,7 +261,8 @@ export type ExecutionAction = {
255
261
  /**
256
262
  * Set together with status `FAILED` when the outcome of this action's
257
263
  * transaction is known and final (failed or reverted on chain or at the
258
- * relayer, cancelled, replaced, or dropped with proof).
264
+ * relayer, cancelled (also by a wallet that removed it before it sent it),
265
+ * replaced, or dropped with proof).
259
266
  * A FAILED action without this flag has an unknown outcome and is re-checked
260
267
  * on resume instead of being signed again.
261
268
  */
@@ -5,7 +5,7 @@ const checkPackageUpdates = async (packageName, packageVersion) => {
5
5
  try {
6
6
  const pkgName = packageName ?? "@lifi/sdk";
7
7
  const latestVersion = (await (await fetch(`https://registry.npmjs.org/${pkgName}/latest`)).json()).version;
8
- const currentVersion = packageVersion ?? "4.11.0";
8
+ const currentVersion = packageVersion ?? "4.12.0";
9
9
  if (latestVersion > currentVersion) console.warn(`${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`);
10
10
  } catch (_error) {}
11
11
  };
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
2
  export declare const name = "@lifi/sdk";
3
- export declare const version = "4.11.0";
3
+ export declare const version = "4.12.0";
4
4
  //#endregion
5
5
  //# sourceMappingURL=version.d.ts.map
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/version.ts
3
3
  const name = "@lifi/sdk";
4
- const version = "4.11.0";
4
+ const version = "4.12.0";
5
5
  //#endregion
6
6
  exports.name = name;
7
7
  exports.version = version;
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.11.0'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.12.0'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"StatusManager.d.ts","names":[],"sources":["../../../src/core/StatusManager.ts"],"mappings":";;;KAmBK;EACH,MAAM;EACN,MAAM;EACN,SAAS;EACT,QAAQ;;;;;qBA0GG;mBACM;UACT;UACA;EAER,YAAY;;;;;;EASZ,sBAAuB,MAAM,qBAAmB;;;;;;;EAiChD,gBACE,MAAM,kBACN,WAAW,QAAQ,aAClB;;;;;;;EAkBH,WACE,MAAM,kBACN,MAAM,sBACL;;;;;;;;;;EAmBH,iBACE,MACA,MACA,SACA,UACC,gBAAc;;;;;;;;;EAyBjB,qBACE,MACA,MACA,SACA,UACC,gBAAc;;;;;;;;;EA0BjB,eACE,MAAM,kBACN,MAAM,qBACN,QAAQ,uBACR,SAAS,QAAQ;IAAoB;SACpC;EAgEH,oBAAqB,MAAM,aAAW;EA6BtC,aAAa;;;;;;;;;UA0BL"}
1
+ {"version":3,"file":"StatusManager.d.ts","names":[],"sources":["../../../src/core/StatusManager.ts"],"mappings":";;;KAmBK;EACH,MAAM;EACN,MAAM;EACN,SAAS;EACT,QAAQ;;;;;qBA6GG;mBACM;UACT;UACA;EAER,YAAY;;;;;;EASZ,sBAAuB,MAAM,qBAAmB;;;;;;;EAiChD,gBACE,MAAM,kBACN,WAAW,QAAQ,aAClB;;;;;;;EAkBH,WACE,MAAM,kBACN,MAAM,sBACL;;;;;;;;;;EAmBH,iBACE,MACA,MACA,SACA,UACC,gBAAc;;;;;;;;;EAyBjB,qBACE,MACA,MACA,SACA,UACC,gBAAc;;;;;;;;;EA0BjB,eACE,MAAM,kBACN,MAAM,qBACN,QAAQ,uBACR,SAAS,QAAQ;IAAoB;SACpC;EAgEH,oBAAqB,MAAM,aAAW;EA6BtC,aAAa;;;;;;;;;UA0BL"}
@@ -3,9 +3,10 @@ import { executionState } from "./executionState.js";
3
3
  import { CLEARED_TRANSACTION_FIELDS, TRANSACTION_ACTION_TYPES, hasOpenTransaction, hasStepOpenTransaction } from "./transactionState.js";
4
4
  //#region src/core/StatusManager.ts
5
5
  /**
6
- * A write is transaction data when it changes one of these fields. `txLink`
7
- * and `signedAt` travel with such a write but never trigger one: the status
8
- * poll rewrites `txLink` every few seconds.
6
+ * A write is transaction data when it changes one of these fields. `txLink`,
7
+ * `signedAt` and `callCount` travel with such a write but never trigger one:
8
+ * the status poll rewrites `txLink` every few seconds, and `callCount` comes
9
+ * only with a `taskId`.
9
10
  */
10
11
  const TRANSACTION_KEYS = [
11
12
  "txHash",
@@ -46,6 +47,7 @@ const mergeLateTransaction = (liveRoute, lateStep, lateAction) => {
46
47
  txHex: lateAction.txHex,
47
48
  txFinal: lateAction.txFinal,
48
49
  taskId: lateAction.taskId,
50
+ callCount: lateAction.callCount,
49
51
  txType: lateAction.txType
50
52
  });
51
53
  }
@@ -1 +1 @@
1
- {"version":3,"file":"StatusManager.js","names":[],"sources":["../../../src/core/StatusManager.ts"],"sourcesContent":["import type { ChainId, LiFiStep } from '@lifi/types'\nimport type {\n Execution,\n ExecutionAction,\n ExecutionActionStatus,\n ExecutionActionType,\n LiFiStepExtended,\n RouteExtended,\n UpdateRouteHook,\n} from '../types/core.js'\nimport { getActionMessage } from './actionMessages.js'\nimport { executionState } from './executionState.js'\nimport {\n CLEARED_TRANSACTION_FIELDS,\n hasOpenTransaction,\n hasStepOpenTransaction,\n TRANSACTION_ACTION_TYPES,\n} from './transactionState.js'\n\ntype ActionProps = {\n step: LiFiStepExtended\n type: ExecutionActionType\n chainId: ChainId\n status: ExecutionActionStatus\n}\n\n/**\n * The route and hook of an execution that `stopRouteExecution` ended. A task\n * that was still running (e.g. waiting in the wallet prompt) writes its\n * transaction data later; without these the write would never reach the\n * integrator, and a resume of the stored route would sign again.\n * `startCount` is `executionState.startCount` at the stop.\n */\ntype StoppedExecution = {\n route: RouteExtended\n updateRouteHook?: UpdateRouteHook\n startCount: number\n}\n\n/**\n * A write is transaction data when it changes one of these fields. `txLink`\n * and `signedAt` travel with such a write but never trigger one: the status\n * poll rewrites `txLink` every few seconds.\n */\nconst TRANSACTION_KEYS = ['txHash', 'txHex', 'taskId', 'txFinal'] as const\n\ntype TransactionFields = Pick<\n ExecutionAction,\n (typeof TRANSACTION_KEYS)[number]\n>\n\nconst readTransaction = (action: ExecutionAction): TransactionFields => ({\n txHash: action.txHash,\n txHex: action.txHex,\n taskId: action.taskId,\n txFinal: action.txFinal,\n})\n\n/** True when the write changed a transaction field, also to `undefined`. */\nconst changesTransaction = (\n before: TransactionFields,\n action: ExecutionAction\n): boolean => TRANSACTION_KEYS.some((key) => action[key] !== before[key])\n\n/**\n * Copies a late transaction into the route of a newer execution of the same\n * route id, running or ended. The step's objects are changed in place: a\n * running executor holds them, so its selector and its pre-sign guard see\n * the transaction. Returns true when something changed.\n */\nconst mergeLateTransaction = (\n liveRoute: RouteExtended,\n lateStep: LiFiStepExtended,\n lateAction: ExecutionAction\n): boolean => {\n // Cleared or final: the newer execution needs nothing from it.\n if (!hasOpenTransaction(lateAction)) {\n return false\n }\n const liveStep = liveRoute.steps.find(\n (routeStep) => routeStep.id === lateStep.id\n )\n if (!liveStep) {\n return false\n }\n if (!liveStep.execution) {\n liveStep.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [structuredClone(lateAction)],\n }\n } else {\n const liveAction = liveStep.execution.actions.find(\n (action) => action.type === lateAction.type\n )\n if (!liveAction) {\n liveStep.execution.actions.push(structuredClone(lateAction))\n } else if (hasOpenTransaction(liveAction)) {\n // The live action already has an open transaction (its own, or one\n // merged earlier); it is kept.\n return false\n } else {\n // All five fields, so a stale `txFinal` goes and the action is open.\n // `txType` goes with them: the live one described no open transaction.\n Object.assign(liveAction, {\n txHash: lateAction.txHash,\n txLink: lateAction.txLink,\n txHex: lateAction.txHex,\n txFinal: lateAction.txFinal,\n taskId: lateAction.taskId,\n txType: lateAction.txType,\n })\n }\n }\n // `signedAt` is the signing time of the step's own transaction: an\n // allowance does not set it, and a write without one keeps the live time.\n const signedAt = lateStep.execution?.signedAt\n if (\n TRANSACTION_ACTION_TYPES.includes(lateAction.type) &&\n signedAt !== undefined\n ) {\n liveStep.execution.signedAt = signedAt\n }\n return true\n}\n\n/**\n * Manages status updates of a route and provides various functions for tracking actions.\n */\nexport class StatusManager {\n private readonly routeId: string\n private shouldUpdate = true\n private stoppedExecution?: StoppedExecution\n\n constructor(routeId: string) {\n this.routeId = routeId\n }\n\n /**\n * Initializes the execution object of a Step.\n * @param step The current step in execution\n * @returns The initialized execution object for this step\n */\n initializeExecution = (step: LiFiStepExtended): Execution => {\n if (!step.execution) {\n step.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [],\n }\n this.updateStepInRoute(step)\n }\n\n // Change status to PENDING after resuming from FAILED\n if (step.execution.status === 'FAILED') {\n step.execution.startedAt = Date.now()\n step.execution.status = 'PENDING'\n // Keep the signing time while a signed transaction may still land: the\n // resume path uses it to decide when stored bytes are too old to resend\n // or old enough to be declared dropped.\n if (!hasStepOpenTransaction(step)) {\n step.execution.signedAt = undefined\n }\n step.execution.error = undefined\n this.updateStepInRoute(step)\n }\n\n return step.execution\n }\n\n /**\n * Updates the execution object of a Step.\n * @param step The current step in execution\n * @param execution Partial execution data to merge\n * @returns The step with the updated execution object\n */\n updateExecution(\n step: LiFiStepExtended,\n execution: Partial<Execution>\n ): LiFiStep {\n if (!step.execution) {\n throw Error(\"Can't update empty execution.\")\n }\n step.execution = {\n ...step.execution,\n ...execution,\n }\n this.updateStepInRoute(step)\n return step\n }\n\n /**\n * Finds an action of the specified type in the step's execution\n * @param step The step to search in\n * @param type The action type to find\n * @returns The found action or undefined if not found\n */\n findAction(\n step: LiFiStepExtended,\n type: ExecutionActionType\n ): ExecutionAction | undefined {\n if (!step.execution?.actions) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const action = step.execution.actions.find((p) => p.type === type)\n\n return action\n }\n\n /**\n * Create and push a new action into the execution.\n * Caller is responsible for ensuring an action of this type does not already exist.\n * @param step The step that should contain the new action.\n * @param type Type of the action.\n * @param chainId Chain Id of the action.\n * @param status The initial status for the new action.\n * @returns The created action.\n */\n createAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const newAction: ExecutionAction = {\n type,\n message: getActionMessage(type, status),\n status,\n chainId,\n }\n\n step.execution.actions.push(newAction)\n this.updateStepInRoute(step)\n return newAction\n }\n\n /**\n * Find an existing action by type and update it, or create a new one if none exists.\n * @param step The step that should contain the action.\n * @param type Type of the action. Used to identify already existing actions.\n * @param chainId Chain Id of the action (used when creating).\n * @param status The status to set on the found or newly created action.\n * @returns The updated or newly created action.\n */\n initializeAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n const action = this.findAction(step, type)\n\n if (action) {\n return this.updateAction(step, type, status, {\n error: undefined,\n // A final outcome is dead. A new attempt starts without its data, so\n // the pre-sign guard does not mistake it for an open transaction (the\n // route was run again without `prepareRestart`, e.g. `executeRoute`).\n ...(action.status === 'FAILED' &&\n action.txFinal === true &&\n CLEARED_TRANSACTION_FIELDS),\n })\n }\n\n return this.createAction({ step, type, chainId, status })\n }\n\n /**\n * Update an action object.\n * @param step The step where the action should be updated\n * @param type The action type to update\n * @param status The status the action gets.\n * @param [params] Additional parameters to append to the action.\n * @returns The updated action\n */\n updateAction = (\n step: LiFiStepExtended,\n type: ExecutionActionType,\n status: ExecutionActionStatus,\n params?: Partial<ExecutionAction & { signedAt?: number }>\n ): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Can't update an empty step execution.\")\n }\n const currentAction = this.findAction(step, type)\n\n if (!currentAction) {\n throw new Error(\"Can't find an action for the given type.\")\n }\n // Read before the write: after a stop, only a write that changes the\n // transaction reaches the integrator.\n const transactionBefore = this.shouldUpdate\n ? undefined\n : readTransaction(currentAction)\n\n switch (status) {\n case 'CANCELLED':\n break\n case 'FAILED':\n step.execution.status = 'FAILED'\n if (params?.error) {\n step.execution.error = params.error\n }\n break\n case 'DONE':\n break\n case 'PENDING':\n step.execution.status = 'PENDING'\n if (params?.signedAt) {\n step.execution.signedAt = params.signedAt\n }\n break\n case 'RESET_REQUIRED':\n case 'MESSAGE_REQUIRED':\n case 'ACTION_REQUIRED':\n step.execution.status = 'ACTION_REQUIRED'\n break\n default:\n break\n }\n\n currentAction.status = status\n currentAction.message = getActionMessage(type, status)\n // set extra parameters or overwrite the standard params set in the switch statement\n if (params) {\n const { signedAt: _signedAt, ...rest } = params\n Object.assign(currentAction, rest)\n }\n // Sort actions, the ones with DONE status go first\n step.execution.actions = [\n ...step.execution.actions.filter((action) => action.status === 'DONE'),\n ...step.execution.actions.filter((action) => action.status !== 'DONE'),\n ]\n if (\n transactionBefore &&\n changesTransaction(transactionBefore, currentAction)\n ) {\n this.deliverLateTransactionData(step, currentAction)\n } else {\n this.updateStepInRoute(step) // updates the step in the route\n }\n return currentAction\n }\n\n updateStepInRoute = (step: LiFiStep): LiFiStep => {\n if (!this.shouldUpdate) {\n return step\n }\n const data = executionState.get(this.routeId)\n\n if (!data) {\n throw new Error('Execution data not found.')\n }\n\n const stepIndex = data.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n\n if (stepIndex === -1) {\n throw new Error(\"Couldn't find a step to update.\")\n }\n\n // A shallow copy on purpose: the route's step must keep sharing the\n // step's `execution` object. `mergeLateTransaction` changes the live\n // route in place, and the running sign task's check after the wallet\n // must see the merge (pinned by the stop-and-resume race test in\n // `sdk-provider-ethereum/src/core/flows/reload.unit.spec.ts`).\n data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step }\n\n data.executionOptions?.updateRouteHook?.(data.route)\n return data.route.steps[stepIndex]\n }\n\n allowUpdates(value: boolean): void {\n this.shouldUpdate = value\n if (value) {\n this.stoppedExecution = undefined\n return\n }\n // `stopRouteExecution` turns updates off right before it deletes the\n // execution state, so the state is still here to keep.\n const data = executionState.get(this.routeId)\n if (data) {\n this.stoppedExecution = {\n route: data.route,\n updateRouteHook: data.executionOptions?.updateRouteHook,\n startCount: executionState.startCount(this.routeId),\n }\n }\n }\n\n /**\n * A write of transaction data after `stopRouteExecution`. With a newer\n * execution of the same route id running, the transaction is merged into\n * it. If no execution of the route started since the stop, the kept route\n * is updated and the kept hook is called. If a newer execution started and\n * ended since the stop, the transaction is merged into the route of the\n * last ended execution, and its hook is called.\n */\n private deliverLateTransactionData(\n step: LiFiStepExtended,\n lateAction: ExecutionAction\n ): void {\n const stopped = this.stoppedExecution\n if (!stopped) {\n return\n }\n // A late write must never fail the task that made it: its catch block\n // would mark the action FAILED while the transaction may still land.\n try {\n // Always a newer execution: `stopRouteExecution` deleted this one.\n const live = executionState.get(this.routeId)\n if (live) {\n if (mergeLateTransaction(live.route, step, lateAction)) {\n live.executionOptions?.updateRouteHook?.(live.route)\n }\n return\n }\n // A newer execution started and ended since the stop: the integrator\n // stored its route, which the kept one would roll back. The late\n // transaction goes into that route instead. With the records of the\n // route freed (no run in flight, `startCount` 0) the write is dropped.\n if (executionState.startCount(this.routeId) !== stopped.startCount) {\n const ended = executionState.lastEnded(this.routeId)\n if (ended && mergeLateTransaction(ended.route, step, lateAction)) {\n ended.updateRouteHook?.(ended.route)\n }\n return\n }\n const stepIndex = stopped.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n if (stepIndex === -1) {\n return\n }\n stopped.route.steps[stepIndex] = {\n ...stopped.route.steps[stepIndex],\n ...step,\n }\n stopped.updateRouteHook?.(stopped.route)\n } catch (error) {\n // Not rethrown, see above. The integrator's hook can throw here, so\n // the error is reported in development, as other swallowed errors are.\n if (process.env.NODE_ENV === 'development') {\n console.debug('Delivering late transaction data failed.', error)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;AA4CA,MAAM,mBAAmB;CAAC;CAAU;CAAS;CAAU;AAAS;AAOhE,MAAM,mBAAmB,YAAgD;CACvE,QAAQ,OAAO;CACf,OAAO,OAAO;CACd,QAAQ,OAAO;CACf,SAAS,OAAO;AAClB;;AAGA,MAAM,sBACJ,QACA,WACY,iBAAiB,MAAM,QAAQ,OAAO,SAAS,OAAO,IAAI;;;;;;;AAQxE,MAAM,wBACJ,WACA,UACA,eACY;CAEZ,IAAI,CAAC,mBAAmB,UAAU,GAChC,OAAO;CAET,MAAM,WAAW,UAAU,MAAM,MAC9B,cAAc,UAAU,OAAO,SAAS,EAC3C;CACA,IAAI,CAAC,UACH,OAAO;CAET,IAAI,CAAC,SAAS,WACZ,SAAS,YAAY;EACnB,WAAW,KAAK,IAAI;EACpB,QAAQ;EACR,SAAS,CAAC,gBAAgB,UAAU,CAAC;CACvC;MACK;EACL,MAAM,aAAa,SAAS,UAAU,QAAQ,MAC3C,WAAW,OAAO,SAAS,WAAW,IACzC;EACA,IAAI,CAAC,YACH,SAAS,UAAU,QAAQ,KAAK,gBAAgB,UAAU,CAAC;OACtD,IAAI,mBAAmB,UAAU,GAGtC,OAAO;OAIP,OAAO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IAAI,SAAS,qBAAqB,MAAM,OAAO,MAAM,UAAU,GAC7D,MAAM,kBAAkB,MAAM,KAAK;IAErC;GACF;GACA,MAAM,YAAY,QAAQ,MAAM,MAAM,WACnC,cAAc,UAAU,OAAO,KAAK,EACvC;GACA,IAAI,cAAc,IAChB;GAEF,QAAQ,MAAM,MAAM,aAAa;IAC/B,GAAG,QAAQ,MAAM,MAAM;IACvB,GAAG;GACL;GACA,QAAQ,kBAAkB,QAAQ,KAAK;EACzC,SAAS,OAAO;GAGd,IAAI,QAAQ,IAAI,aAAa,eAC3B,QAAQ,MAAM,4CAA4C,KAAK;EAEnE;CACF;AACF"}
1
+ {"version":3,"file":"StatusManager.js","names":[],"sources":["../../../src/core/StatusManager.ts"],"sourcesContent":["import type { ChainId, LiFiStep } from '@lifi/types'\nimport type {\n Execution,\n ExecutionAction,\n ExecutionActionStatus,\n ExecutionActionType,\n LiFiStepExtended,\n RouteExtended,\n UpdateRouteHook,\n} from '../types/core.js'\nimport { getActionMessage } from './actionMessages.js'\nimport { executionState } from './executionState.js'\nimport {\n CLEARED_TRANSACTION_FIELDS,\n hasOpenTransaction,\n hasStepOpenTransaction,\n TRANSACTION_ACTION_TYPES,\n} from './transactionState.js'\n\ntype ActionProps = {\n step: LiFiStepExtended\n type: ExecutionActionType\n chainId: ChainId\n status: ExecutionActionStatus\n}\n\n/**\n * The route and hook of an execution that `stopRouteExecution` ended. A task\n * that was still running (e.g. waiting in the wallet prompt) writes its\n * transaction data later; without these the write would never reach the\n * integrator, and a resume of the stored route would sign again.\n * `startCount` is `executionState.startCount` at the stop.\n */\ntype StoppedExecution = {\n route: RouteExtended\n updateRouteHook?: UpdateRouteHook\n startCount: number\n}\n\n/**\n * A write is transaction data when it changes one of these fields. `txLink`,\n * `signedAt` and `callCount` travel with such a write but never trigger one:\n * the status poll rewrites `txLink` every few seconds, and `callCount` comes\n * only with a `taskId`.\n */\nconst TRANSACTION_KEYS = ['txHash', 'txHex', 'taskId', 'txFinal'] as const\n\ntype TransactionFields = Pick<\n ExecutionAction,\n (typeof TRANSACTION_KEYS)[number]\n>\n\nconst readTransaction = (action: ExecutionAction): TransactionFields => ({\n txHash: action.txHash,\n txHex: action.txHex,\n taskId: action.taskId,\n txFinal: action.txFinal,\n})\n\n/** True when the write changed a transaction field, also to `undefined`. */\nconst changesTransaction = (\n before: TransactionFields,\n action: ExecutionAction\n): boolean => TRANSACTION_KEYS.some((key) => action[key] !== before[key])\n\n/**\n * Copies a late transaction into the route of a newer execution of the same\n * route id, running or ended. The step's objects are changed in place: a\n * running executor holds them, so its selector and its pre-sign guard see\n * the transaction. Returns true when something changed.\n */\nconst mergeLateTransaction = (\n liveRoute: RouteExtended,\n lateStep: LiFiStepExtended,\n lateAction: ExecutionAction\n): boolean => {\n // Cleared or final: the newer execution needs nothing from it.\n if (!hasOpenTransaction(lateAction)) {\n return false\n }\n const liveStep = liveRoute.steps.find(\n (routeStep) => routeStep.id === lateStep.id\n )\n if (!liveStep) {\n return false\n }\n if (!liveStep.execution) {\n liveStep.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [structuredClone(lateAction)],\n }\n } else {\n const liveAction = liveStep.execution.actions.find(\n (action) => action.type === lateAction.type\n )\n if (!liveAction) {\n liveStep.execution.actions.push(structuredClone(lateAction))\n } else if (hasOpenTransaction(liveAction)) {\n // The live action already has an open transaction (its own, or one\n // merged earlier); it is kept.\n return false\n } else {\n // Every field of `CLEARED_TRANSACTION_FIELDS`, so a stale `txFinal`\n // goes and the action is open. `txType` goes with them: the live one\n // described no open transaction.\n Object.assign(liveAction, {\n txHash: lateAction.txHash,\n txLink: lateAction.txLink,\n txHex: lateAction.txHex,\n txFinal: lateAction.txFinal,\n taskId: lateAction.taskId,\n callCount: lateAction.callCount,\n txType: lateAction.txType,\n })\n }\n }\n // `signedAt` is the signing time of the step's own transaction: an\n // allowance does not set it, and a write without one keeps the live time.\n const signedAt = lateStep.execution?.signedAt\n if (\n TRANSACTION_ACTION_TYPES.includes(lateAction.type) &&\n signedAt !== undefined\n ) {\n liveStep.execution.signedAt = signedAt\n }\n return true\n}\n\n/**\n * Manages status updates of a route and provides various functions for tracking actions.\n */\nexport class StatusManager {\n private readonly routeId: string\n private shouldUpdate = true\n private stoppedExecution?: StoppedExecution\n\n constructor(routeId: string) {\n this.routeId = routeId\n }\n\n /**\n * Initializes the execution object of a Step.\n * @param step The current step in execution\n * @returns The initialized execution object for this step\n */\n initializeExecution = (step: LiFiStepExtended): Execution => {\n if (!step.execution) {\n step.execution = {\n startedAt: Date.now(),\n status: 'PENDING',\n actions: [],\n }\n this.updateStepInRoute(step)\n }\n\n // Change status to PENDING after resuming from FAILED\n if (step.execution.status === 'FAILED') {\n step.execution.startedAt = Date.now()\n step.execution.status = 'PENDING'\n // Keep the signing time while a signed transaction may still land: the\n // resume path uses it to decide when stored bytes are too old to resend\n // or old enough to be declared dropped.\n if (!hasStepOpenTransaction(step)) {\n step.execution.signedAt = undefined\n }\n step.execution.error = undefined\n this.updateStepInRoute(step)\n }\n\n return step.execution\n }\n\n /**\n * Updates the execution object of a Step.\n * @param step The current step in execution\n * @param execution Partial execution data to merge\n * @returns The step with the updated execution object\n */\n updateExecution(\n step: LiFiStepExtended,\n execution: Partial<Execution>\n ): LiFiStep {\n if (!step.execution) {\n throw Error(\"Can't update empty execution.\")\n }\n step.execution = {\n ...step.execution,\n ...execution,\n }\n this.updateStepInRoute(step)\n return step\n }\n\n /**\n * Finds an action of the specified type in the step's execution\n * @param step The step to search in\n * @param type The action type to find\n * @returns The found action or undefined if not found\n */\n findAction(\n step: LiFiStepExtended,\n type: ExecutionActionType\n ): ExecutionAction | undefined {\n if (!step.execution?.actions) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const action = step.execution.actions.find((p) => p.type === type)\n\n return action\n }\n\n /**\n * Create and push a new action into the execution.\n * Caller is responsible for ensuring an action of this type does not already exist.\n * @param step The step that should contain the new action.\n * @param type Type of the action.\n * @param chainId Chain Id of the action.\n * @param status The initial status for the new action.\n * @returns The created action.\n */\n createAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Execution hasn't been initialized.\")\n }\n\n const newAction: ExecutionAction = {\n type,\n message: getActionMessage(type, status),\n status,\n chainId,\n }\n\n step.execution.actions.push(newAction)\n this.updateStepInRoute(step)\n return newAction\n }\n\n /**\n * Find an existing action by type and update it, or create a new one if none exists.\n * @param step The step that should contain the action.\n * @param type Type of the action. Used to identify already existing actions.\n * @param chainId Chain Id of the action (used when creating).\n * @param status The status to set on the found or newly created action.\n * @returns The updated or newly created action.\n */\n initializeAction = ({\n step,\n type,\n chainId,\n status,\n }: ActionProps): ExecutionAction => {\n const action = this.findAction(step, type)\n\n if (action) {\n return this.updateAction(step, type, status, {\n error: undefined,\n // A final outcome is dead. A new attempt starts without its data, so\n // the pre-sign guard does not mistake it for an open transaction (the\n // route was run again without `prepareRestart`, e.g. `executeRoute`).\n ...(action.status === 'FAILED' &&\n action.txFinal === true &&\n CLEARED_TRANSACTION_FIELDS),\n })\n }\n\n return this.createAction({ step, type, chainId, status })\n }\n\n /**\n * Update an action object.\n * @param step The step where the action should be updated\n * @param type The action type to update\n * @param status The status the action gets.\n * @param [params] Additional parameters to append to the action.\n * @returns The updated action\n */\n updateAction = (\n step: LiFiStepExtended,\n type: ExecutionActionType,\n status: ExecutionActionStatus,\n params?: Partial<ExecutionAction & { signedAt?: number }>\n ): ExecutionAction => {\n if (!step.execution) {\n throw new Error(\"Can't update an empty step execution.\")\n }\n const currentAction = this.findAction(step, type)\n\n if (!currentAction) {\n throw new Error(\"Can't find an action for the given type.\")\n }\n // Read before the write: after a stop, only a write that changes the\n // transaction reaches the integrator.\n const transactionBefore = this.shouldUpdate\n ? undefined\n : readTransaction(currentAction)\n\n switch (status) {\n case 'CANCELLED':\n break\n case 'FAILED':\n step.execution.status = 'FAILED'\n if (params?.error) {\n step.execution.error = params.error\n }\n break\n case 'DONE':\n break\n case 'PENDING':\n step.execution.status = 'PENDING'\n if (params?.signedAt) {\n step.execution.signedAt = params.signedAt\n }\n break\n case 'RESET_REQUIRED':\n case 'MESSAGE_REQUIRED':\n case 'ACTION_REQUIRED':\n step.execution.status = 'ACTION_REQUIRED'\n break\n default:\n break\n }\n\n currentAction.status = status\n currentAction.message = getActionMessage(type, status)\n // set extra parameters or overwrite the standard params set in the switch statement\n if (params) {\n const { signedAt: _signedAt, ...rest } = params\n Object.assign(currentAction, rest)\n }\n // Sort actions, the ones with DONE status go first\n step.execution.actions = [\n ...step.execution.actions.filter((action) => action.status === 'DONE'),\n ...step.execution.actions.filter((action) => action.status !== 'DONE'),\n ]\n if (\n transactionBefore &&\n changesTransaction(transactionBefore, currentAction)\n ) {\n this.deliverLateTransactionData(step, currentAction)\n } else {\n this.updateStepInRoute(step) // updates the step in the route\n }\n return currentAction\n }\n\n updateStepInRoute = (step: LiFiStep): LiFiStep => {\n if (!this.shouldUpdate) {\n return step\n }\n const data = executionState.get(this.routeId)\n\n if (!data) {\n throw new Error('Execution data not found.')\n }\n\n const stepIndex = data.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n\n if (stepIndex === -1) {\n throw new Error(\"Couldn't find a step to update.\")\n }\n\n // A shallow copy on purpose: the route's step must keep sharing the\n // step's `execution` object. `mergeLateTransaction` changes the live\n // route in place, and the running sign task's check after the wallet\n // must see the merge (pinned by the stop-and-resume race test in\n // `sdk-provider-ethereum/src/core/flows/reload.unit.spec.ts`).\n data.route.steps[stepIndex] = { ...data.route.steps[stepIndex], ...step }\n\n data.executionOptions?.updateRouteHook?.(data.route)\n return data.route.steps[stepIndex]\n }\n\n allowUpdates(value: boolean): void {\n this.shouldUpdate = value\n if (value) {\n this.stoppedExecution = undefined\n return\n }\n // `stopRouteExecution` turns updates off right before it deletes the\n // execution state, so the state is still here to keep.\n const data = executionState.get(this.routeId)\n if (data) {\n this.stoppedExecution = {\n route: data.route,\n updateRouteHook: data.executionOptions?.updateRouteHook,\n startCount: executionState.startCount(this.routeId),\n }\n }\n }\n\n /**\n * A write of transaction data after `stopRouteExecution`. With a newer\n * execution of the same route id running, the transaction is merged into\n * it. If no execution of the route started since the stop, the kept route\n * is updated and the kept hook is called. If a newer execution started and\n * ended since the stop, the transaction is merged into the route of the\n * last ended execution, and its hook is called.\n */\n private deliverLateTransactionData(\n step: LiFiStepExtended,\n lateAction: ExecutionAction\n ): void {\n const stopped = this.stoppedExecution\n if (!stopped) {\n return\n }\n // A late write must never fail the task that made it: its catch block\n // would mark the action FAILED while the transaction may still land.\n try {\n // Always a newer execution: `stopRouteExecution` deleted this one.\n const live = executionState.get(this.routeId)\n if (live) {\n if (mergeLateTransaction(live.route, step, lateAction)) {\n live.executionOptions?.updateRouteHook?.(live.route)\n }\n return\n }\n // A newer execution started and ended since the stop: the integrator\n // stored its route, which the kept one would roll back. The late\n // transaction goes into that route instead. With the records of the\n // route freed (no run in flight, `startCount` 0) the write is dropped.\n if (executionState.startCount(this.routeId) !== stopped.startCount) {\n const ended = executionState.lastEnded(this.routeId)\n if (ended && mergeLateTransaction(ended.route, step, lateAction)) {\n ended.updateRouteHook?.(ended.route)\n }\n return\n }\n const stepIndex = stopped.route.steps.findIndex(\n (routeStep) => routeStep.id === step.id\n )\n if (stepIndex === -1) {\n return\n }\n stopped.route.steps[stepIndex] = {\n ...stopped.route.steps[stepIndex],\n ...step,\n }\n stopped.updateRouteHook?.(stopped.route)\n } catch (error) {\n // Not rethrown, see above. The integrator's hook can throw here, so\n // the error is reported in development, as other swallowed errors are.\n if (process.env.NODE_ENV === 'development') {\n console.debug('Delivering late transaction data failed.', error)\n }\n }\n }\n}\n"],"mappings":";;;;;;;;;;AA6CA,MAAM,mBAAmB;CAAC;CAAU;CAAS;CAAU;AAAS;AAOhE,MAAM,mBAAmB,YAAgD;CACvE,QAAQ,OAAO;CACf,OAAO,OAAO;CACd,QAAQ,OAAO;CACf,SAAS,OAAO;AAClB;;AAGA,MAAM,sBACJ,QACA,WACY,iBAA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O;GACT,KAAK,mBAAmB,KAAA;GACxB;EACF;EAGA,MAAM,OAAO,eAAe,IAAI,KAAK,OAAO;EAC5C,IAAI,MACF,KAAK,mBAAmB;GACtB,OAAO,KAAK;GACZ,iBAAiB,KAAK,kBAAkB;GACxC,YAAY,eAAe,WAAW,KAAK,OAAO;EACpD;CAEJ;;;;;;;;;CAUA,2BACE,MACA,YACM;EACN,MAAM,UAAU,KAAK;EACrB,IAAI,CAAC,SACH;EAIF,IAAI;GAEF,MAAM,OAAO,eAAe,IAAI,KAAK,OAAO;GAC5C,IAAI,MAAM;IACR,IAAI,qBAAqB,KAAK,OAAO,MAAM,UAAU,GACnD,KAAK,kBAAkB,kBAAkB,KAAK,KAAK;IAErD;GACF;GAKA,IAAI,eAAe,WAAW,KAAK,OAAO,MAAM,QAAQ,YAAY;IAClE,MAAM,QAAQ,eAAe,UAAU,KAAK,OAAO;IACnD,IAAI,SAAS,qBAAqB,MAAM,OAAO,MAAM,UAAU,GAC7D,MAAM,kBAAkB,MAAM,KAAK;IAErC;GACF;GACA,MAAM,YAAY,QAAQ,MAAM,MAAM,WACnC,cAAc,UAAU,OAAO,KAAK,EACvC;GACA,IAAI,cAAc,IAChB;GAEF,QAAQ,MAAM,MAAM,aAAa;IAC/B,GAAG,QAAQ,MAAM,MAAM;IACvB,GAAG;GACL;GACA,QAAQ,kBAAkB,QAAQ,KAAK;EACzC,SAAS,OAAO;GAGd,IAAI,QAAQ,IAAI,aAAa,eAC3B,QAAQ,MAAM,4CAA4C,KAAK;EAEnE;CACF;AACF"}
@@ -34,10 +34,11 @@ export declare const CLOCK_SKEW_MARGIN_MS = 6e5;
34
34
  * Fields a sign task clears before it writes a new transaction's data, and
35
35
  * that re-initializing a final-failed action clears. `taskId` is included: a
36
36
  * stale relayed or batched task id would otherwise keep the action open.
37
+ * `callCount` goes with a batched task id.
37
38
  *
38
39
  * @internal
39
40
  */
40
- export declare const CLEARED_TRANSACTION_FIELDS: Readonly<Pick<ExecutionAction, "txHash" | "txLink" | "txHex" | "txFinal" | "taskId">>;
41
+ export declare const CLEARED_TRANSACTION_FIELDS: Readonly<Pick<ExecutionAction, "txHash" | "txLink" | "txHex" | "txFinal" | "taskId" | "callCount">>;
41
42
  /**
42
43
  * True when the action has a transaction to follow, landed or not: a hash, a
43
44
  * task id or stored signed bytes, unless the action FAILED with a final
@@ -60,11 +61,12 @@ export declare const CLEARED_TRANSACTION_FIELDS: Readonly<Pick<ExecutionAction,
60
61
  * stored bytes only while `isResendAllowed` (or the chain's own expiry)
61
62
  * allows it; otherwise it only waits.
62
63
  * 5. Mark an error final only on a verdict about the transaction: failed
63
- * or reverted (on chain or at the relayer), cancelled, replaced, or
64
- * dropped with proof. Dropped needs all three: the transaction can no
65
- * longer land, a node that covers its window reports it absent (in the
66
- * same response where the chain allows it), and `isKnownToStatusApi` is
67
- * false. In doubt, throw without the marker and keep the fields.
64
+ * or reverted (on chain or at the relayer), cancelled (also by a wallet
65
+ * that removed it before it sent it), replaced, or dropped with proof.
66
+ * Dropped needs all three: the transaction can no longer land, a node
67
+ * that covers its window reports it absent (in the same response where
68
+ * the chain allows it), and `isKnownToStatusApi` is false. In doubt,
69
+ * throw without the marker and keep the fields.
68
70
  * 6. Give `context.signal` only to waits that start after the broadcast. On
69
71
  * abort, return `PAUSED` and write nothing.
70
72
  */
@@ -1 +1 @@
1
- {"version":3,"file":"transactionState.d.ts","names":[],"sources":["../../../src/core/transactionState.ts"],"mappings":";;;;;;;;qBAaa,mCAAmC;;;;;;;;qBAYnC;;;;;;;qBAQA;;;;;;;;qBASA;;;;;;;;qBASA,4BAA4B,SACvC,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAuCS,mBAAmB,SAAS;;;;;;wBAe5B,uBAAuB,MAAM;;;;;;;;wBAe7B,wBAAwB;;;;;;;wBAmBxB,4BAA4B;;;;;;;;;;;;;wBAmB5B,wBAAwB,SAAS;;;;;;;;wBAajC,gBACd,8BACA;;;;;;wBAcc,kBACd,8BACA"}
1
+ {"version":3,"file":"transactionState.d.ts","names":[],"sources":["../../../src/core/transactionState.ts"],"mappings":";;;;;;;;qBAaa,mCAAmC;;;;;;;;qBAYnC;;;;;;;qBAQA;;;;;;;;qBASA;;;;;;;;;qBAUA,4BAA4B,SACvC,KACE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2CY,mBAAmB,SAAS;;;;;;wBAe5B,uBAAuB,MAAM;;;;;;;;wBAe7B,wBAAwB;;;;;;;wBAmBxB,4BAA4B;;;;;;;;;;;;;wBAmB5B,wBAAwB,SAAS;;;;;;;;wBAajC,gBACd,8BACA;;;;;;wBAcc,kBACd,8BACA"}
@@ -34,6 +34,7 @@ const CLOCK_SKEW_MARGIN_MS = 6e5;
34
34
  * Fields a sign task clears before it writes a new transaction's data, and
35
35
  * that re-initializing a final-failed action clears. `taskId` is included: a
36
36
  * stale relayed or batched task id would otherwise keep the action open.
37
+ * `callCount` goes with a batched task id.
37
38
  *
38
39
  * @internal
39
40
  */
@@ -42,7 +43,8 @@ const CLEARED_TRANSACTION_FIELDS = Object.freeze({
42
43
  txLink: void 0,
43
44
  txHex: void 0,
44
45
  txFinal: void 0,
45
- taskId: void 0
46
+ taskId: void 0,
47
+ callCount: void 0
46
48
  });
47
49
  /**
48
50
  * True when the action has a transaction to follow, landed or not: a hash, a
@@ -66,11 +68,12 @@ const CLEARED_TRANSACTION_FIELDS = Object.freeze({
66
68
  * stored bytes only while `isResendAllowed` (or the chain's own expiry)
67
69
  * allows it; otherwise it only waits.
68
70
  * 5. Mark an error final only on a verdict about the transaction: failed
69
- * or reverted (on chain or at the relayer), cancelled, replaced, or
70
- * dropped with proof. Dropped needs all three: the transaction can no
71
- * longer land, a node that covers its window reports it absent (in the
72
- * same response where the chain allows it), and `isKnownToStatusApi` is
73
- * false. In doubt, throw without the marker and keep the fields.
71
+ * or reverted (on chain or at the relayer), cancelled (also by a wallet
72
+ * that removed it before it sent it), replaced, or dropped with proof.
73
+ * Dropped needs all three: the transaction can no longer land, a node
74
+ * that covers its window reports it absent (in the same response where
75
+ * the chain allows it), and `isKnownToStatusApi` is false. In doubt,
76
+ * throw without the marker and keep the fields.
74
77
  * 6. Give `context.signal` only to waits that start after the broadcast. On
75
78
  * abort, return `PAUSED` and write nothing.
76
79
  */
@@ -1 +1 @@
1
- {"version":3,"file":"transactionState.js","names":[],"sources":["../../../src/core/transactionState.ts"],"sourcesContent":["import { LiFiErrorCode } from '../errors/constants.js'\nimport { TransactionError } from '../errors/errors.js'\nimport type {\n ExecutionAction,\n ExecutionActionType,\n LiFiStepExtended,\n} from '../types/core.js'\n\n/**\n * Action types that carry the step's own transaction.\n *\n * @internal\n */\nexport const TRANSACTION_ACTION_TYPES: readonly ExecutionActionType[] = [\n 'SWAP',\n 'CROSS_CHAIN',\n]\n\n/**\n * Stored bytes on a chain without its own expiry (Sui, Solana with a durable\n * nonce, Bitcoin) are resent only this long after signing. Past it, a page\n * load could otherwise execute a swap on a quote the user no longer expects.\n *\n * @internal\n */\nexport const MAX_RESEND_AGE_MS = 120_000\n\n/**\n * Without an expiry verdict, a signature younger than this is never declared\n * dropped. Solana blockhashes and Tron transactions expire well before it.\n *\n * @internal\n */\nexport const DROPPED_FALLBACK_AGE_MS = 300_000\n\n/**\n * Subtracted from `execution.signedAt` (the device clock) when it anchors a\n * history-coverage check, so a device clock that runs fast cannot make a node\n * look like it covers the signing time when it does not.\n *\n * @internal\n */\nexport const CLOCK_SKEW_MARGIN_MS = 600_000\n\n/**\n * Fields a sign task clears before it writes a new transaction's data, and\n * that re-initializing a final-failed action clears. `taskId` is included: a\n * stale relayed or batched task id would otherwise keep the action open.\n *\n * @internal\n */\nexport const CLEARED_TRANSACTION_FIELDS: Readonly<\n Pick<ExecutionAction, 'txHash' | 'txLink' | 'txHex' | 'txFinal' | 'taskId'>\n> = Object.freeze({\n txHash: undefined,\n txLink: undefined,\n txHex: undefined,\n txFinal: undefined,\n taskId: undefined,\n})\n\n/**\n * True when the action has a transaction to follow, landed or not: a hash, a\n * task id or stored signed bytes, unless the action FAILED with a final\n * outcome. Every resume decision uses this one predicate, so the pipeline\n * selector and the pre-sign guard can never disagree.\n *\n * Resume rules for providers. A step never signs or sends a second\n * transaction while an earlier one can still land:\n * 1. Pick the first task with this predicate: open and DONE, the status\n * wait; open, the provider's wait task; otherwise the first task.\n * 2. In the sign task, call `assertNoOpenTransaction` at the start, right\n * before each wallet call and, where the SDK sends, right after the\n * wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`\n * and `signedAt`.\n * 3. From the last check, nothing awaits until the send or, where the SDK\n * sends signed bytes, until they are stored as `txHex`, before the first\n * send. Clear `txHex` only when the outcome is known, no node can still\n * hold the bytes, or they no longer decode.\n * 4. A resume never signs. It looks the transaction up and resends the\n * stored bytes only while `isResendAllowed` (or the chain's own expiry)\n * allows it; otherwise it only waits.\n * 5. Mark an error final only on a verdict about the transaction: failed\n * or reverted (on chain or at the relayer), cancelled, replaced, or\n * dropped with proof. Dropped needs all three: the transaction can no\n * longer land, a node that covers its window reports it absent (in the\n * same response where the chain allows it), and `isKnownToStatusApi` is\n * false. In doubt, throw without the marker and keep the fields.\n * 6. Give `context.signal` only to waits that start after the broadcast. On\n * abort, return `PAUSED` and write nothing.\n */\nexport function hasOpenTransaction(action?: ExecutionAction): boolean {\n if (!action) {\n return false\n }\n if (!(action.txHash || action.taskId || action.txHex)) {\n return false\n }\n return !(action.status === 'FAILED' && action.txFinal === true)\n}\n\n/**\n * True when any SWAP / CROSS_CHAIN action of the step has an open transaction.\n *\n * @internal\n */\nexport function hasStepOpenTransaction(step: LiFiStepExtended): boolean {\n return !!step.execution?.actions?.some(\n (action) =>\n TRANSACTION_ACTION_TYPES.includes(action.type) &&\n hasOpenTransaction(action)\n )\n}\n\n/**\n * Walks the error and its `cause` chain. Parsers may rebuild errors, so the\n * marker is read from the original error. A property check instead of\n * `instanceof` keeps it working across duplicated installs.\n *\n * @internal\n */\nexport function isFinalTransactionError(error: unknown): boolean {\n const seen = new Set<unknown>()\n let current: unknown = error\n while (current && typeof current === 'object' && !seen.has(current)) {\n seen.add(current)\n if ((current as { final?: unknown }).final === true) {\n return true\n }\n current = (current as { cause?: unknown }).cause\n }\n return false\n}\n\n/**\n * The error of a step that would sign a second transaction while its first\n * one may still land.\n *\n * @internal\n */\nexport function transactionConflictError(): TransactionError {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'A transaction for this step was already signed and may still land. Resume the route to wait for it instead of signing a new one.'\n )\n}\n\n/**\n * Called first in every sign task. With correct pipeline selectors it never\n * throws; it stops a second signature if a selector ever routes an open\n * transaction back to signing. Every sign task calls it again on the freshly\n * found action right before its wallet call: a late write of an older run can\n * merge a transaction into the action during the awaits in between. A sign\n * task that sends the transaction itself calls it once more after the wallet\n * returns, before it writes or sends anything: the merge can also land while\n * the prompt is open.\n *\n * @internal\n */\nexport function assertNoOpenTransaction(action?: ExecutionAction): void {\n if (hasOpenTransaction(action)) {\n throw transactionConflictError()\n }\n}\n\n/**\n * Unknown signing time never allows a resend. Nor does a signing time in the\n * future: a device clock that ran ahead at signing and was corrected later\n * would otherwise stretch the cap by the clock error.\n *\n * @internal\n */\nexport function isResendAllowed(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < MAX_RESEND_AGE_MS\n )\n}\n\n/**\n * Unknown signing time never allows a drop.\n *\n * @internal\n */\nexport function isOldEnoughToDrop(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return signedAt !== undefined && now - signedAt > DROPPED_FALLBACK_AGE_MS\n}\n"],"mappings":";;;;;;;;AAaA,MAAa,2BAA2D,CACtE,QACA,aACF;;;;;;;;AASA,MAAa,oBAAoB;;;;;;;AAQjC,MAAa,0BAA0B;;;;;;;;AASvC,MAAa,uBAAuB;;;;;;;;AASpC,MAAa,6BAET,OAAO,OAAO;CAChB,QAAQ,KAAA;CACR,QAAQ,KAAA;CACR,OAAO,KAAA;CACP,SAAS,KAAA;CACT,QAAQ,KAAA;AACV,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgCD,SAAgB,mBAAmB,QAAmC;CACpE,IAAI,CAAC,QACH,OAAO;CAET,IAAI,EAAE,OAAO,UAAU,OAAO,UAAU,OAAO,QAC7C,OAAO;CAET,OAAO,EAAE,OAAO,WAAW,YAAY,OAAO,YAAY;AAC5D;;;;;;AAOA,SAAgB,uBAAuB,MAAiC;CACtE,OAAO,CAAC,CAAC,KAAK,WAAW,SAAS,MAC/B,WACC,yBAAyB,SAAS,OAAO,IAAI,KAC7C,mBAAmB,MAAM,CAC7B;AACF;;;;;;;;AASA,SAAgB,wBAAwB,OAAyB;CAC/D,MAAM,uBAAO,IAAI,IAAa;CAC9B,IAAI,UAAmB;CACvB,OAAO,WAAW,OAAO,YAAY,YAAY,CAAC,KAAK,IAAI,OAAO,GAAG;EACnE,KAAK,IAAI,OAAO;EAChB,IAAK,QAAgC,UAAU,MAC7C,OAAO;EAET,UAAW,QAAgC;CAC7C;CACA,OAAO;AACT;;;;;;;AAQA,SAAgB,2BAA6C;CAC3D,OAAO,IAAI,iBAAA,MAET,kIACF;AACF;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,QAAgC;CACtE,IAAI,mBAAmB,MAAM,GAC3B,MAAM,yBAAyB;AAEnC;;;;;;;;AASA,SAAgB,gBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAA;AAEV;;;;;;AAOA,SAAgB,kBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OAAO,aAAa,KAAA,KAAa,MAAM,WAAA;AACzC"}
1
+ {"version":3,"file":"transactionState.js","names":[],"sources":["../../../src/core/transactionState.ts"],"sourcesContent":["import { LiFiErrorCode } from '../errors/constants.js'\nimport { TransactionError } from '../errors/errors.js'\nimport type {\n ExecutionAction,\n ExecutionActionType,\n LiFiStepExtended,\n} from '../types/core.js'\n\n/**\n * Action types that carry the step's own transaction.\n *\n * @internal\n */\nexport const TRANSACTION_ACTION_TYPES: readonly ExecutionActionType[] = [\n 'SWAP',\n 'CROSS_CHAIN',\n]\n\n/**\n * Stored bytes on a chain without its own expiry (Sui, Solana with a durable\n * nonce, Bitcoin) are resent only this long after signing. Past it, a page\n * load could otherwise execute a swap on a quote the user no longer expects.\n *\n * @internal\n */\nexport const MAX_RESEND_AGE_MS = 120_000\n\n/**\n * Without an expiry verdict, a signature younger than this is never declared\n * dropped. Solana blockhashes and Tron transactions expire well before it.\n *\n * @internal\n */\nexport const DROPPED_FALLBACK_AGE_MS = 300_000\n\n/**\n * Subtracted from `execution.signedAt` (the device clock) when it anchors a\n * history-coverage check, so a device clock that runs fast cannot make a node\n * look like it covers the signing time when it does not.\n *\n * @internal\n */\nexport const CLOCK_SKEW_MARGIN_MS = 600_000\n\n/**\n * Fields a sign task clears before it writes a new transaction's data, and\n * that re-initializing a final-failed action clears. `taskId` is included: a\n * stale relayed or batched task id would otherwise keep the action open.\n * `callCount` goes with a batched task id.\n *\n * @internal\n */\nexport const CLEARED_TRANSACTION_FIELDS: Readonly<\n Pick<\n ExecutionAction,\n 'txHash' | 'txLink' | 'txHex' | 'txFinal' | 'taskId' | 'callCount'\n >\n> = Object.freeze({\n txHash: undefined,\n txLink: undefined,\n txHex: undefined,\n txFinal: undefined,\n taskId: undefined,\n callCount: undefined,\n})\n\n/**\n * True when the action has a transaction to follow, landed or not: a hash, a\n * task id or stored signed bytes, unless the action FAILED with a final\n * outcome. Every resume decision uses this one predicate, so the pipeline\n * selector and the pre-sign guard can never disagree.\n *\n * Resume rules for providers. A step never signs or sends a second\n * transaction while an earlier one can still land:\n * 1. Pick the first task with this predicate: open and DONE, the status\n * wait; open, the provider's wait task; otherwise the first task.\n * 2. In the sign task, call `assertNoOpenTransaction` at the start, right\n * before each wallet call and, where the SDK sends, right after the\n * wallet returns. Write the new data with `CLEARED_TRANSACTION_FIELDS`\n * and `signedAt`.\n * 3. From the last check, nothing awaits until the send or, where the SDK\n * sends signed bytes, until they are stored as `txHex`, before the first\n * send. Clear `txHex` only when the outcome is known, no node can still\n * hold the bytes, or they no longer decode.\n * 4. A resume never signs. It looks the transaction up and resends the\n * stored bytes only while `isResendAllowed` (or the chain's own expiry)\n * allows it; otherwise it only waits.\n * 5. Mark an error final only on a verdict about the transaction: failed\n * or reverted (on chain or at the relayer), cancelled (also by a wallet\n * that removed it before it sent it), replaced, or dropped with proof.\n * Dropped needs all three: the transaction can no longer land, a node\n * that covers its window reports it absent (in the same response where\n * the chain allows it), and `isKnownToStatusApi` is false. In doubt,\n * throw without the marker and keep the fields.\n * 6. Give `context.signal` only to waits that start after the broadcast. On\n * abort, return `PAUSED` and write nothing.\n */\nexport function hasOpenTransaction(action?: ExecutionAction): boolean {\n if (!action) {\n return false\n }\n if (!(action.txHash || action.taskId || action.txHex)) {\n return false\n }\n return !(action.status === 'FAILED' && action.txFinal === true)\n}\n\n/**\n * True when any SWAP / CROSS_CHAIN action of the step has an open transaction.\n *\n * @internal\n */\nexport function hasStepOpenTransaction(step: LiFiStepExtended): boolean {\n return !!step.execution?.actions?.some(\n (action) =>\n TRANSACTION_ACTION_TYPES.includes(action.type) &&\n hasOpenTransaction(action)\n )\n}\n\n/**\n * Walks the error and its `cause` chain. Parsers may rebuild errors, so the\n * marker is read from the original error. A property check instead of\n * `instanceof` keeps it working across duplicated installs.\n *\n * @internal\n */\nexport function isFinalTransactionError(error: unknown): boolean {\n const seen = new Set<unknown>()\n let current: unknown = error\n while (current && typeof current === 'object' && !seen.has(current)) {\n seen.add(current)\n if ((current as { final?: unknown }).final === true) {\n return true\n }\n current = (current as { cause?: unknown }).cause\n }\n return false\n}\n\n/**\n * The error of a step that would sign a second transaction while its first\n * one may still land.\n *\n * @internal\n */\nexport function transactionConflictError(): TransactionError {\n return new TransactionError(\n LiFiErrorCode.TransactionConflict,\n 'A transaction for this step was already signed and may still land. Resume the route to wait for it instead of signing a new one.'\n )\n}\n\n/**\n * Called first in every sign task. With correct pipeline selectors it never\n * throws; it stops a second signature if a selector ever routes an open\n * transaction back to signing. Every sign task calls it again on the freshly\n * found action right before its wallet call: a late write of an older run can\n * merge a transaction into the action during the awaits in between. A sign\n * task that sends the transaction itself calls it once more after the wallet\n * returns, before it writes or sends anything: the merge can also land while\n * the prompt is open.\n *\n * @internal\n */\nexport function assertNoOpenTransaction(action?: ExecutionAction): void {\n if (hasOpenTransaction(action)) {\n throw transactionConflictError()\n }\n}\n\n/**\n * Unknown signing time never allows a resend. Nor does a signing time in the\n * future: a device clock that ran ahead at signing and was corrected later\n * would otherwise stretch the cap by the clock error.\n *\n * @internal\n */\nexport function isResendAllowed(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return (\n signedAt !== undefined &&\n now >= signedAt &&\n now - signedAt < MAX_RESEND_AGE_MS\n )\n}\n\n/**\n * Unknown signing time never allows a drop.\n *\n * @internal\n */\nexport function isOldEnoughToDrop(\n signedAt: number | undefined,\n now: number = Date.now()\n): boolean {\n return signedAt !== undefined && now - signedAt > DROPPED_FALLBACK_AGE_MS\n}\n"],"mappings":";;;;;;;;AAaA,MAAa,2BAA2D,CACtE,QACA,aACF;;;;;;;;AASA,MAAa,oBAAoB;;;;;;;AAQjC,MAAa,0BAA0B;;;;;;;;AASvC,MAAa,uBAAuB;;;;;;;;;AAUpC,MAAa,6BAKT,OAAO,OAAO;CAChB,QAAQ,KAAA;CACR,QAAQ,KAAA;CACR,OAAO,KAAA;CACP,SAAS,KAAA;CACT,QAAQ,KAAA;CACR,WAAW,KAAA;AACb,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCD,SAAgB,mBAAmB,QAAmC;CACpE,IAAI,CAAC,QACH,OAAO;CAET,IAAI,EAAE,OAAO,UAAU,OAAO,UAAU,OAAO,QAC7C,OAAO;CAET,OAAO,EAAE,OAAO,WAAW,YAAY,OAAO,YAAY;AAC5D;;;;;;AAOA,SAAgB,uBAAuB,MAAiC;CACtE,OAAO,CAAC,CAAC,KAAK,WAAW,SAAS,MAC/B,WACC,yBAAyB,SAAS,OAAO,IAAI,KAC7C,mBAAmB,MAAM,CAC7B;AACF;;;;;;;;AASA,SAAgB,wBAAwB,OAAyB;CAC/D,MAAM,uBAAO,IAAI,IAAa;CAC9B,IAAI,UAAmB;CACvB,OAAO,WAAW,OAAO,YAAY,YAAY,CAAC,KAAK,IAAI,OAAO,GAAG;EACnE,KAAK,IAAI,OAAO;EAChB,IAAK,QAAgC,UAAU,MAC7C,OAAO;EAET,UAAW,QAAgC;CAC7C;CACA,OAAO;AACT;;;;;;;AAQA,SAAgB,2BAA6C;CAC3D,OAAO,IAAI,iBAAA,MAET,kIACF;AACF;;;;;;;;;;;;;AAcA,SAAgB,wBAAwB,QAAgC;CACtE,IAAI,mBAAmB,MAAM,GAC3B,MAAM,yBAAyB;AAEnC;;;;;;;;AASA,SAAgB,gBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OACE,aAAa,KAAA,KACb,OAAO,YACP,MAAM,WAAA;AAEV;;;;;;AAOA,SAAgB,kBACd,UACA,MAAc,KAAK,IAAI,GACd;CACT,OAAO,aAAa,KAAA,KAAa,MAAM,WAAA;AACzC"}
@@ -42,7 +42,8 @@ export declare enum LiFiErrorCode {
42
42
  ThirdPartyError = 1024,
43
43
  InsufficientGas = 1025,
44
44
  ConfigError = 1026,
45
- RpcUnavailable = 1027
45
+ RpcUnavailable = 1027,
46
+ CallBundleNotFound = 1028
46
47
  }
47
48
  export declare enum ErrorMessage {
48
49
  UnknownError = "Unknown error occurred.",
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","names":[],"sources":["../../../src/errors/constants.ts"],"mappings":";oBAAY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;YAGU,YAAY;oBAEZ;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;oBAGU;EACV;EACA;EACA;EACA;EACA"}
1
+ {"version":3,"file":"constants.d.ts","names":[],"sources":["../../../src/errors/constants.ts"],"mappings":";oBAAY;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;YAGU,YAAY;oBAEZ;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;oBAGU;EACV;EACA;EACA;EACA;EACA"}
@@ -43,6 +43,7 @@ let LiFiErrorCode = /* @__PURE__ */ function(LiFiErrorCode) {
43
43
  LiFiErrorCode[LiFiErrorCode["InsufficientGas"] = 1025] = "InsufficientGas";
44
44
  LiFiErrorCode[LiFiErrorCode["ConfigError"] = 1026] = "ConfigError";
45
45
  LiFiErrorCode[LiFiErrorCode["RpcUnavailable"] = 1027] = "RpcUnavailable";
46
+ LiFiErrorCode[LiFiErrorCode["CallBundleNotFound"] = 1028] = "CallBundleNotFound";
46
47
  return LiFiErrorCode;
47
48
  }({});
48
49
  let ErrorMessage = /* @__PURE__ */ function(ErrorMessage) {
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../../../src/errors/constants.ts"],"sourcesContent":["export enum ErrorName {\n RPCError = 'RPCError',\n ProviderError = 'ProviderError',\n ServerError = 'ServerError',\n TransactionError = 'TransactionError',\n ValidationError = 'ValidationError',\n BalanceError = 'BalanceError',\n NotFoundError = 'NotFoundError',\n UnknownError = 'UnknownError',\n SlippageError = 'SlippageError',\n HTTPError = 'HTTPError',\n ConfigError = 'ConfigError',\n ExecuteStepRetryError = 'ExecuteStepRetryError',\n}\n\nexport type ErrorCode = LiFiErrorCode\n\nexport enum LiFiErrorCode {\n InternalError = 1000,\n ValidationError = 1001,\n TransactionUnderpriced = 1002,\n TransactionFailed = 1003,\n Timeout = 1004,\n ProviderUnavailable = 1005,\n NotFound = 1006,\n ChainSwitchError = 1007,\n TransactionUnprepared = 1008,\n GasLimitError = 1009,\n TransactionCanceled = 1010,\n SlippageError = 1011,\n SignatureRejected = 1012,\n BalanceError = 1013,\n AllowanceRequired = 1014,\n InsufficientFunds = 1015,\n ExchangeRateUpdateCanceled = 1016,\n WalletChangedDuringExecution = 1017,\n TransactionExpired = 1018,\n TransactionSimulationFailed = 1019,\n TransactionConflict = 1020,\n TransactionNotFound = 1021,\n TransactionRejected = 1022,\n RateLimitExceeded = 1023,\n ThirdPartyError = 1024,\n InsufficientGas = 1025,\n ConfigError = 1026,\n RpcUnavailable = 1027,\n}\n\nexport enum ErrorMessage {\n UnknownError = 'Unknown error occurred.',\n SlippageError = 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.',\n GasLimitLow = 'Gas limit is too low.',\n TransactionUnderpriced = 'Transaction is underpriced.',\n TransactionReverted = 'Transaction was reverted.',\n}\n"],"mappings":";AAAA,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,cAAA;CACA,UAAA,mBAAA;CACA,UAAA,iBAAA;CACA,UAAA,sBAAA;CACA,UAAA,qBAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,eAAA;CACA,UAAA,iBAAA;CACA,UAAA,2BAAA;;AACF,EAAA,CAAA,CAAA;AAIA,IAAY,gBAAL,yBAAA,eAAA;CACL,cAAA,cAAA,mBAAA,OAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,4BAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,aAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,cAAA,QAAA;CACA,cAAA,cAAA,sBAAA,QAAA;CACA,cAAA,cAAA,2BAAA,QAAA;CACA,cAAA,cAAA,mBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,mBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,kBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,gCAAA,QAAA;CACA,cAAA,cAAA,kCAAA,QAAA;CACA,cAAA,cAAA,wBAAA,QAAA;CACA,cAAA,cAAA,iCAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,iBAAA,QAAA;CACA,cAAA,cAAA,oBAAA,QAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAY,eAAL,yBAAA,cAAA;CACL,aAAA,kBAAA;CACA,aAAA,mBAAA;CACA,aAAA,iBAAA;CACA,aAAA,4BAAA;CACA,aAAA,yBAAA;;AACF,EAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../../../src/errors/constants.ts"],"sourcesContent":["export enum ErrorName {\n RPCError = 'RPCError',\n ProviderError = 'ProviderError',\n ServerError = 'ServerError',\n TransactionError = 'TransactionError',\n ValidationError = 'ValidationError',\n BalanceError = 'BalanceError',\n NotFoundError = 'NotFoundError',\n UnknownError = 'UnknownError',\n SlippageError = 'SlippageError',\n HTTPError = 'HTTPError',\n ConfigError = 'ConfigError',\n ExecuteStepRetryError = 'ExecuteStepRetryError',\n}\n\nexport type ErrorCode = LiFiErrorCode\n\nexport enum LiFiErrorCode {\n InternalError = 1000,\n ValidationError = 1001,\n TransactionUnderpriced = 1002,\n TransactionFailed = 1003,\n Timeout = 1004,\n ProviderUnavailable = 1005,\n NotFound = 1006,\n ChainSwitchError = 1007,\n TransactionUnprepared = 1008,\n GasLimitError = 1009,\n TransactionCanceled = 1010,\n SlippageError = 1011,\n SignatureRejected = 1012,\n BalanceError = 1013,\n AllowanceRequired = 1014,\n InsufficientFunds = 1015,\n ExchangeRateUpdateCanceled = 1016,\n WalletChangedDuringExecution = 1017,\n TransactionExpired = 1018,\n TransactionSimulationFailed = 1019,\n TransactionConflict = 1020,\n TransactionNotFound = 1021,\n TransactionRejected = 1022,\n RateLimitExceeded = 1023,\n ThirdPartyError = 1024,\n InsufficientGas = 1025,\n ConfigError = 1026,\n RpcUnavailable = 1027,\n CallBundleNotFound = 1028,\n}\n\nexport enum ErrorMessage {\n UnknownError = 'Unknown error occurred.',\n SlippageError = 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.',\n GasLimitLow = 'Gas limit is too low.',\n TransactionUnderpriced = 'Transaction is underpriced.',\n TransactionReverted = 'Transaction was reverted.',\n}\n"],"mappings":";AAAA,IAAY,YAAL,yBAAA,WAAA;CACL,UAAA,cAAA;CACA,UAAA,mBAAA;CACA,UAAA,iBAAA;CACA,UAAA,sBAAA;CACA,UAAA,qBAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,kBAAA;CACA,UAAA,mBAAA;CACA,UAAA,eAAA;CACA,UAAA,iBAAA;CACA,UAAA,2BAAA;;AACF,EAAA,CAAA,CAAA;AAIA,IAAY,gBAAL,yBAAA,eAAA;CACL,cAAA,cAAA,mBAAA,OAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,4BAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,aAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,cAAA,QAAA;CACA,cAAA,cAAA,sBAAA,QAAA;CACA,cAAA,cAAA,2BAAA,QAAA;CACA,cAAA,cAAA,mBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,mBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,kBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,gCAAA,QAAA;CACA,cAAA,cAAA,kCAAA,QAAA;CACA,cAAA,cAAA,wBAAA,QAAA;CACA,cAAA,cAAA,iCAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,yBAAA,QAAA;CACA,cAAA,cAAA,uBAAA,QAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,qBAAA,QAAA;CACA,cAAA,cAAA,iBAAA,QAAA;CACA,cAAA,cAAA,oBAAA,QAAA;CACA,cAAA,cAAA,wBAAA,QAAA;;AACF,EAAA,CAAA,CAAA;AAEA,IAAY,eAAL,yBAAA,cAAA;CACL,aAAA,kBAAA;CACA,aAAA,mBAAA;CACA,aAAA,iBAAA;CACA,aAAA,4BAAA;CACA,aAAA,yBAAA;;AACF,EAAA,CAAA,CAAA"}
@@ -11,9 +11,9 @@ export declare class ProviderError extends BaseError {
11
11
  export interface TransactionErrorOptions {
12
12
  /**
13
13
  * A definite verdict about the transaction (failed or reverted on chain or
14
- * at the relayer, cancelled, replaced, or dropped with proof). The step
15
- * executor then flags the failed action with `txFinal`, so a restart signs
16
- * a new transaction.
14
+ * at the relayer, cancelled (also by a wallet that removed it before it
15
+ * sent it), replaced, or dropped with proof). The step executor then flags
16
+ * the failed action with `txFinal`, so a restart signs a new transaction.
17
17
  */
18
18
  final?: boolean;
19
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","names":[],"sources":["../../../src/errors/errors.ts"],"sourcesContent":["import type { ExecuteStepRetryParams } from '../types/core.js'\nimport { BaseError } from './baseError.js'\nimport { ErrorName, LiFiErrorCode } from './constants.js'\n\nexport class RPCError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.RPCError, code, message, cause)\n }\n}\n\nexport class ProviderError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.ProviderError, code, message, cause)\n }\n}\n\nexport interface TransactionErrorOptions {\n /**\n * A definite verdict about the transaction (failed or reverted on chain or\n * at the relayer, cancelled, replaced, or dropped with proof). The step\n * executor then flags the failed action with `txFinal`, so a restart signs\n * a new transaction.\n */\n final?: boolean\n}\n\nexport class TransactionError extends BaseError {\n readonly final: boolean\n\n constructor(\n code: LiFiErrorCode,\n message: string,\n cause?: Error,\n options?: TransactionErrorOptions\n ) {\n super(ErrorName.TransactionError, code, message, cause)\n this.final = options?.final ?? false\n }\n}\n\nexport class UnknownError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)\n }\n}\n\nexport class BalanceError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)\n }\n}\n\nexport class ServerError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)\n }\n}\n\nexport class ValidationError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)\n }\n}\n\n/**\n * Thrown by a step executor when executeStep should be retried with the given params\n * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).\n * The execution layer catches this and retries executeStep(client, step, retryParams),\n * unless the route was stopped or the step has an open transaction.\n */\nexport class ExecuteStepRetryError extends BaseError {\n readonly retryParams: ExecuteStepRetryParams\n\n constructor(\n message: string,\n retryParams: ExecuteStepRetryParams,\n cause?: Error\n ) {\n super(\n ErrorName.ExecuteStepRetryError,\n LiFiErrorCode.InternalError,\n message,\n cause\n )\n this.retryParams = retryParams\n }\n}\n"],"mappings":";;;AAIA,IAAa,WAAb,cAA8B,UAAU;CACtC,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,YAA0B,MAAM,SAAS,KAAK;CAChD;AACF;AAEA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,iBAA+B,MAAM,SAAS,KAAK;CACrD;AACF;AAYA,IAAa,mBAAb,cAAsC,UAAU;CAC9C;CAEA,YACE,MACA,SACA,OACA,SACA;EACA,MAAA,oBAAkC,MAAM,SAAS,KAAK;EACtD,KAAK,QAAQ,SAAS,SAAS;CACjC;AACF;AAEA,IAAa,eAAb,cAAkC,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,KAA2D,SAAS,KAAK;CAC3E;AACF;AAEA,IAAa,eAAb,cAAkC,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,MAA0D,SAAS,KAAK;CAC1E;AACF;AAEA,IAAa,cAAb,cAAiC,UAAU;CACzC,YAAY,SAAiB;EAC3B,MAAA,eAAA,KAA0D,OAAO;CACnE;AACF;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC7C,YAAY,SAAiB;EAC3B,MAAA,mBAAA,MAAgE,OAAO;CACzE;AACF;;;;;;;AAQA,IAAa,wBAAb,cAA2C,UAAU;CACnD;CAEA,YACE,SACA,aACA,OACA;EACA,MAAA,yBAAA,KAGE,SACA,KACF;EACA,KAAK,cAAc;CACrB;AACF"}
1
+ {"version":3,"file":"errors.js","names":[],"sources":["../../../src/errors/errors.ts"],"sourcesContent":["import type { ExecuteStepRetryParams } from '../types/core.js'\nimport { BaseError } from './baseError.js'\nimport { ErrorName, LiFiErrorCode } from './constants.js'\n\nexport class RPCError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.RPCError, code, message, cause)\n }\n}\n\nexport class ProviderError extends BaseError {\n constructor(code: LiFiErrorCode, message: string, cause?: Error) {\n super(ErrorName.ProviderError, code, message, cause)\n }\n}\n\nexport interface TransactionErrorOptions {\n /**\n * A definite verdict about the transaction (failed or reverted on chain or\n * at the relayer, cancelled (also by a wallet that removed it before it\n * sent it), replaced, or dropped with proof). The step executor then flags\n * the failed action with `txFinal`, so a restart signs a new transaction.\n */\n final?: boolean\n}\n\nexport class TransactionError extends BaseError {\n readonly final: boolean\n\n constructor(\n code: LiFiErrorCode,\n message: string,\n cause?: Error,\n options?: TransactionErrorOptions\n ) {\n super(ErrorName.TransactionError, code, message, cause)\n this.final = options?.final ?? false\n }\n}\n\nexport class UnknownError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)\n }\n}\n\nexport class BalanceError extends BaseError {\n constructor(message: string, cause?: Error) {\n super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)\n }\n}\n\nexport class ServerError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)\n }\n}\n\nexport class ValidationError extends BaseError {\n constructor(message: string) {\n super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)\n }\n}\n\n/**\n * Thrown by a step executor when executeStep should be retried with the given params\n * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).\n * The execution layer catches this and retries executeStep(client, step, retryParams),\n * unless the route was stopped or the step has an open transaction.\n */\nexport class ExecuteStepRetryError extends BaseError {\n readonly retryParams: ExecuteStepRetryParams\n\n constructor(\n message: string,\n retryParams: ExecuteStepRetryParams,\n cause?: Error\n ) {\n super(\n ErrorName.ExecuteStepRetryError,\n LiFiErrorCode.InternalError,\n message,\n cause\n )\n this.retryParams = retryParams\n }\n}\n"],"mappings":";;;AAIA,IAAa,WAAb,cAA8B,UAAU;CACtC,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,YAA0B,MAAM,SAAS,KAAK;CAChD;AACF;AAEA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,YAAY,MAAqB,SAAiB,OAAe;EAC/D,MAAA,iBAA+B,MAAM,SAAS,KAAK;CACrD;AACF;AAYA,IAAa,mBAAb,cAAsC,UAAU;CAC9C;CAEA,YACE,MACA,SACA,OACA,SACA;EACA,MAAA,oBAAkC,MAAM,SAAS,KAAK;EACtD,KAAK,QAAQ,SAAS,SAAS;CACjC;AACF;AAEA,IAAa,eAAb,cAAkC,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,KAA2D,SAAS,KAAK;CAC3E;AACF;AAEA,IAAa,eAAb,cAAkC,UAAU;CAC1C,YAAY,SAAiB,OAAe;EAC1C,MAAA,gBAAA,MAA0D,SAAS,KAAK;CAC1E;AACF;AAEA,IAAa,cAAb,cAAiC,UAAU;CACzC,YAAY,SAAiB;EAC3B,MAAA,eAAA,KAA0D,OAAO;CACnE;AACF;AAEA,IAAa,kBAAb,cAAqC,UAAU;CAC7C,YAAY,SAAiB;EAC3B,MAAA,mBAAA,MAAgE,OAAO;CACzE;AACF;;;;;;;AAQA,IAAa,wBAAb,cAA2C,UAAU;CACnD;CAEA,YACE,SACA,aACA,OACA;EACA,MAAA,yBAAA,KAGE,SACA,KACF;EACA,KAAK,cAAc;CACrB;AACF"}
@@ -173,10 +173,10 @@ export type RouteExecutionDictionary = Partial<Record<string, Promise<Route>>>;
173
173
  * store it.
174
174
  *
175
175
  * After `stopRouteExecution` it can still be called, but only to deliver the
176
- * transaction data (`txHash`, `txHex`, `taskId`, `txFinal`) of a task that
177
- * was still running at the stop, for example in an open wallet prompt. Store
178
- * that data, so a resume waits for that transaction instead of signing
179
- * again. If you deleted the route, ignore the call.
176
+ * transaction data (`txHash`, `txHex`, `taskId`, `callCount`, `txFinal`) of a
177
+ * task that was still running at the stop, for example in an open wallet
178
+ * prompt. Store that data, so a resume waits for that transaction instead of
179
+ * signing again. If you deleted the route, ignore the call.
180
180
  */
181
181
  export type UpdateRouteHook = (updatedRoute: RouteExtended) => void;
182
182
  export interface TransactionRequestParameters extends TransactionParameters {
@@ -245,6 +245,12 @@ export type ExecutionAction = {
245
245
  txLink?: string;
246
246
  taskId?: string;
247
247
  txType?: TransactionMethodType;
248
+ /**
249
+ * The number of calls of a batched (EIP-5792) transaction. Set with
250
+ * `taskId` when `txType` is `batched`. The batched wait reads it after a
251
+ * reload, when the calls are gone.
252
+ */
253
+ callCount?: number;
248
254
  /**
249
255
  * Provider-specific serialized signed transaction (hex, XDR, base64 or JSON).
250
256
  * Present while the transaction may still need to be (re)sent or looked up.
@@ -255,7 +261,8 @@ export type ExecutionAction = {
255
261
  /**
256
262
  * Set together with status `FAILED` when the outcome of this action's
257
263
  * transaction is known and final (failed or reverted on chain or at the
258
- * relayer, cancelled, replaced, or dropped with proof).
264
+ * relayer, cancelled (also by a wallet that removed it before it sent it),
265
+ * replaced, or dropped with proof).
259
266
  * A FAILED action without this flag has an unknown outcome and is re-checked
260
267
  * on resume instead of being signed again.
261
268
  */
@@ -1 +1 @@
1
- {"version":3,"file":"core.d.ts","names":[],"sources":["../../../src/types/core.ts"],"mappings":";;;;YAmBY,sBACV,SAAS,wBACN,sBAAsB,QAAQ;iBAElB;EACf;EACA;EACA;EACA;EACA,eAAe;EACf,mBAAmB;EACnB,SAAS;EACT;EACA;EACA;EACA;EACA;EACA,qBAAqB;EACrB,UAAU;;iBAGK,kBACP,QAAQ,KAAK;EACrB;;;;;;EAMA,UAAU;EACV,YAAY;;;;;iBAMG;;;;;EAKf;;;;;;;;;;EAUA;;;;;;;;;EASA;;;;;;YAOU,gBAAgB,QAAQ,OAAO,oBAAoB;;YAGnD,UAAU,QAAQ,OAAO;iBAEpB;WACN,MAAM;;;;;WAKN,oBAAoB;;;;;;;EAO7B,UAAU,iBAAiB,UAAU;;;;;;EAMrC,gBAAgB;EAChB,eACE,cACA,QAAQ,WACR,UAAU,SACV,QAAQ,UACP;EACH,gBAAgB,SAAS,sBAAsB,QAAQ;EACvD,WACE,QAAQ,WACR,uBACA,QAAQ,UACP,QAAQ;;iBAGI;EACf,QAAQ;EACR,WAAW;EACX,YAAY,MAAM,WAAW,UAAU,UAAU;EACjD,aAAa,WAAW;EACxB,UAAU,QAAQ;EAClB,aAAa,QAAQ;EACrB,aAAa,SAAS,UAA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;;iBAGQ,yBAAyB;EACxC,YAAY;;YAGF,eAAe;EACzB,YAAY;;YAGF;EACV;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;YAGU,2BAA2B,QAAQ,eAAe,QAAQ;;;;;;;;;;;;;YAc1D,mBAAmB,cAAc;iBAE5B,qCAAqC;EACpD;;YAGU,gCACV,kBAAkB,iCACf,QAAQ;iBAEI;EACf,SAAS;EACT;EACA;EACA;EACA;;YAGU,4BACV,QAAQ,mCACL;iBAEY;EACf,SAAS;EACT;EACA;;YAGU,gCACV,QAAQ,6BACL;iBAEY;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;iBAGe;EACf;EACA;;iBAGe;EACf,eAAe;EACf;EACA,eAAe;;YAGL,wBACV,QAAQ,uBACL,QAAQ;iBAEI;EACf,+BAA+B;;;;;;EAM/B,kBAAkB;EAClB,+BAA+B;EAC/B,mBAAmB;EACnB;EACA;;YAGU;YAEA;YAUA;YAUA;EACV,MAAM;EACN,QAAQ;EACR;EACA,YAAY;EACZ;EACA;EACA;EACA;EACA;EACA,SAAS;;;;;;EAMT;;;;;;;EAOA;;;;;;;;;EASA;EAEA;IAAU;IAAuB;IAAiB;;;iBAGnC;EACf;EACA;EACA,QAAQ;EACR,SAAS,MAAM;EACf;EACA;EACA,UAAU;EACV,WAAW;EACX,WAAW;EACX;EACA;EAEA;IAAU;IAAuB;IAAiB;;;YAGxC"}
@@ -4,7 +4,7 @@ const checkPackageUpdates = async (packageName, packageVersion) => {
4
4
  try {
5
5
  const pkgName = packageName ?? "@lifi/sdk";
6
6
  const latestVersion = (await (await fetch(`https://registry.npmjs.org/${pkgName}/latest`)).json()).version;
7
- const currentVersion = packageVersion ?? "4.11.0";
7
+ const currentVersion = packageVersion ?? "4.12.0";
8
8
  if (latestVersion > currentVersion) console.warn(`${pkgName}: new package version is available. Please update as soon as possible to enjoy the newest features. Current version: ${currentVersion}. Latest version: ${latestVersion}.`);
9
9
  } catch (_error) {}
10
10
  };
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
2
  export declare const name = "@lifi/sdk";
3
- export declare const version = "4.11.0";
3
+ export declare const version = "4.12.0";
4
4
  //#endregion
5
5
  //# sourceMappingURL=version.d.ts.map
@@ -1,6 +1,6 @@
1
1
  //#region src/version.ts
2
2
  const name = "@lifi/sdk";
3
- const version = "4.11.0";
3
+ const version = "4.12.0";
4
4
  //#endregion
5
5
  export { name, version };
6
6
 
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.11.0'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
1
+ {"version":3,"file":"version.js","names":[],"sources":["../../src/version.ts"],"sourcesContent":["export const name = '@lifi/sdk'\nexport const version = '4.12.0'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk",
3
- "version": "4.11.0",
3
+ "version": "4.12.0",
4
4
  "description": "LI.FI SDK for Any-to-Any Cross-Chain-Swap",
5
5
  "homepage": "https://github.com/lifinance/sdk",
6
6
  "bugs": {
@@ -38,9 +38,10 @@ type StoppedExecution = {
38
38
  }
39
39
 
40
40
  /**
41
- * A write is transaction data when it changes one of these fields. `txLink`
42
- * and `signedAt` travel with such a write but never trigger one: the status
43
- * poll rewrites `txLink` every few seconds.
41
+ * A write is transaction data when it changes one of these fields. `txLink`,
42
+ * `signedAt` and `callCount` travel with such a write but never trigger one:
43
+ * the status poll rewrites `txLink` every few seconds, and `callCount` comes
44
+ * only with a `taskId`.
44
45
  */
45
46
  const TRANSACTION_KEYS = ['txHash', 'txHex', 'taskId', 'txFinal'] as const
46
47
 
@@ -100,14 +101,16 @@ const mergeLateTransaction = (
100
101
  // merged earlier); it is kept.
101
102
  return false
102
103
  } else {
103
- // All five fields, so a stale `txFinal` goes and the action is open.
104
- // `txType` goes with them: the live one described no open transaction.
104
+ // Every field of `CLEARED_TRANSACTION_FIELDS`, so a stale `txFinal`
105
+ // goes and the action is open. `txType` goes with them: the live one
106
+ // described no open transaction.
105
107
  Object.assign(liveAction, {
106
108
  txHash: lateAction.txHash,
107
109
  txLink: lateAction.txLink,
108
110
  txHex: lateAction.txHex,
109
111
  txFinal: lateAction.txFinal,
110
112
  taskId: lateAction.taskId,
113
+ callCount: lateAction.callCount,
111
114
  txType: lateAction.txType,
112
115
  })
113
116
  }
@@ -46,17 +46,22 @@ export const CLOCK_SKEW_MARGIN_MS = 600_000
46
46
  * Fields a sign task clears before it writes a new transaction's data, and
47
47
  * that re-initializing a final-failed action clears. `taskId` is included: a
48
48
  * stale relayed or batched task id would otherwise keep the action open.
49
+ * `callCount` goes with a batched task id.
49
50
  *
50
51
  * @internal
51
52
  */
52
53
  export const CLEARED_TRANSACTION_FIELDS: Readonly<
53
- Pick<ExecutionAction, 'txHash' | 'txLink' | 'txHex' | 'txFinal' | 'taskId'>
54
+ Pick<
55
+ ExecutionAction,
56
+ 'txHash' | 'txLink' | 'txHex' | 'txFinal' | 'taskId' | 'callCount'
57
+ >
54
58
  > = Object.freeze({
55
59
  txHash: undefined,
56
60
  txLink: undefined,
57
61
  txHex: undefined,
58
62
  txFinal: undefined,
59
63
  taskId: undefined,
64
+ callCount: undefined,
60
65
  })
61
66
 
62
67
  /**
@@ -81,11 +86,12 @@ export const CLEARED_TRANSACTION_FIELDS: Readonly<
81
86
  * stored bytes only while `isResendAllowed` (or the chain's own expiry)
82
87
  * allows it; otherwise it only waits.
83
88
  * 5. Mark an error final only on a verdict about the transaction: failed
84
- * or reverted (on chain or at the relayer), cancelled, replaced, or
85
- * dropped with proof. Dropped needs all three: the transaction can no
86
- * longer land, a node that covers its window reports it absent (in the
87
- * same response where the chain allows it), and `isKnownToStatusApi` is
88
- * false. In doubt, throw without the marker and keep the fields.
89
+ * or reverted (on chain or at the relayer), cancelled (also by a wallet
90
+ * that removed it before it sent it), replaced, or dropped with proof.
91
+ * Dropped needs all three: the transaction can no longer land, a node
92
+ * that covers its window reports it absent (in the same response where
93
+ * the chain allows it), and `isKnownToStatusApi` is false. In doubt,
94
+ * throw without the marker and keep the fields.
89
95
  * 6. Give `context.signal` only to waits that start after the broadcast. On
90
96
  * abort, return `PAUSED` and write nothing.
91
97
  */
@@ -44,6 +44,7 @@ export enum LiFiErrorCode {
44
44
  InsufficientGas = 1025,
45
45
  ConfigError = 1026,
46
46
  RpcUnavailable = 1027,
47
+ CallBundleNotFound = 1028,
47
48
  }
48
49
 
49
50
  export enum ErrorMessage {
@@ -17,9 +17,9 @@ export class ProviderError extends BaseError {
17
17
  export interface TransactionErrorOptions {
18
18
  /**
19
19
  * A definite verdict about the transaction (failed or reverted on chain or
20
- * at the relayer, cancelled, replaced, or dropped with proof). The step
21
- * executor then flags the failed action with `txFinal`, so a restart signs
22
- * a new transaction.
20
+ * at the relayer, cancelled (also by a wallet that removed it before it
21
+ * sent it), replaced, or dropped with proof). The step executor then flags
22
+ * the failed action with `txFinal`, so a restart signs a new transaction.
23
23
  */
24
24
  final?: boolean
25
25
  }
package/src/types/core.ts CHANGED
@@ -226,10 +226,10 @@ export type RouteExecutionDictionary = Partial<Record<string, Promise<Route>>>
226
226
  * store it.
227
227
  *
228
228
  * After `stopRouteExecution` it can still be called, but only to deliver the
229
- * transaction data (`txHash`, `txHex`, `taskId`, `txFinal`) of a task that
230
- * was still running at the stop, for example in an open wallet prompt. Store
231
- * that data, so a resume waits for that transaction instead of signing
232
- * again. If you deleted the route, ignore the call.
229
+ * transaction data (`txHash`, `txHex`, `taskId`, `callCount`, `txFinal`) of a
230
+ * task that was still running at the stop, for example in an open wallet
231
+ * prompt. Store that data, so a resume waits for that transaction instead of
232
+ * signing again. If you deleted the route, ignore the call.
233
233
  */
234
234
  export type UpdateRouteHook = (updatedRoute: RouteExtended) => void
235
235
 
@@ -337,6 +337,12 @@ export type ExecutionAction = {
337
337
  txLink?: string
338
338
  taskId?: string
339
339
  txType?: TransactionMethodType
340
+ /**
341
+ * The number of calls of a batched (EIP-5792) transaction. Set with
342
+ * `taskId` when `txType` is `batched`. The batched wait reads it after a
343
+ * reload, when the calls are gone.
344
+ */
345
+ callCount?: number
340
346
  /**
341
347
  * Provider-specific serialized signed transaction (hex, XDR, base64 or JSON).
342
348
  * Present while the transaction may still need to be (re)sent or looked up.
@@ -347,7 +353,8 @@ export type ExecutionAction = {
347
353
  /**
348
354
  * Set together with status `FAILED` when the outcome of this action's
349
355
  * transaction is known and final (failed or reverted on chain or at the
350
- * relayer, cancelled, replaced, or dropped with proof).
356
+ * relayer, cancelled (also by a wallet that removed it before it sent it),
357
+ * replaced, or dropped with proof).
351
358
  * A FAILED action without this flag has an unknown outcome and is re-checked
352
359
  * on resume instead of being signed again.
353
360
  */
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk'
2
- export const version = '4.11.0'
2
+ export const version = '4.12.0'