@lifi/sdk-provider-tron 4.1.9 → 4.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @lifi/sdk-provider-tron
2
2
 
3
+ ## 4.1.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#521](https://github.com/lifinance/sdk/pull/521) [`7d9a726`](https://github.com/lifinance/sdk/commit/7d9a726e565345e75852a87ec5b65656c49140d7) Thanks [@Kayanski](https://github.com/Kayanski)! - A TRC-20 step can now get its spender from `/stepTransaction`. Some providers, such as Relay, only know the spender once they build the executable transaction, so the routing-time step carries no `estimate.approvalAddress`. Before, such a step skipped the allowance tasks, and its transaction went out against a spender with no allowance and reverted.
8
+
9
+ Now a new task runs after the transaction is prepared and before it is signed. When no allowance was checked before prepare and the re-quote brings an `approvalAddress`, the task reads the allowance for it and approves only if it falls short.
10
+
11
+ A step that already had an `approvalAddress` before prepare behaves as before, even if the re-quote changes it. The task also does not run for native TRX or when the step skips approval.
12
+
3
13
  ## 4.1.9
4
14
 
5
15
  ### Patch Changes
@@ -3,6 +3,7 @@ const require_utils_isZeroAddress = require("../utils/isZeroAddress.js");
3
3
  const require_errors_parseTronErrors = require("../errors/parseTronErrors.js");
4
4
  const require_core_tasks_TronCheckAllowanceTask = require("./tasks/TronCheckAllowanceTask.js");
5
5
  const require_core_tasks_TronSetAllowanceTask = require("./tasks/TronSetAllowanceTask.js");
6
+ const require_core_tasks_TronCheckAllowanceAfterPrepareTask = require("./tasks/TronCheckAllowanceAfterPrepareTask.js");
6
7
  const require_core_tasks_TronSignAndExecuteTask = require("./tasks/TronSignAndExecuteTask.js");
7
8
  const require_core_tasks_TronWaitForTransactionTask = require("./tasks/TronWaitForTransactionTask.js");
8
9
  let _lifi_sdk = require("@lifi/sdk");
@@ -33,6 +34,7 @@ var TronStepExecutor = class extends _lifi_sdk.BaseStepExecutor {
33
34
  new require_core_tasks_TronSetAllowanceTask.TronSetAllowanceTask(),
34
35
  new _lifi_sdk.CheckBalanceTask(),
35
36
  new _lifi_sdk.PrepareTransactionTask(),
37
+ new require_core_tasks_TronCheckAllowanceAfterPrepareTask.TronCheckAllowanceAfterPrepareTask(),
36
38
  new require_core_tasks_TronSignAndExecuteTask.TronSignAndExecuteTask(),
37
39
  new require_core_tasks_TronWaitForTransactionTask.TronWaitForTransactionTask(),
38
40
  new _lifi_sdk.WaitForTransactionStatusTask(isBridgeExecution ? "RECEIVING_CHAIN" : "SWAP")
@@ -1 +1 @@
1
- {"version":3,"file":"TronStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","parseTronErrors","isZeroAddress","TronCheckAllowanceTask","TronSetAllowanceTask","CheckBalanceTask","PrepareTransactionTask","TronSignAndExecuteTask","TronWaitForTransactionTask","WaitForTransactionStatusTask","hasOpenTransaction","TaskPipeline"],"sources":["../../../src/core/TronStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Adapter } from '@tronweb3/tronwallet-abstract-adapter'\nimport { parseTronErrors } from '../errors/parseTronErrors.js'\nimport type {\n TronStepExecutorContext,\n TronStepExecutorOptions,\n} from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { TronCheckAllowanceTask } from './tasks/TronCheckAllowanceTask.js'\nimport { TronSetAllowanceTask } from './tasks/TronSetAllowanceTask.js'\nimport { TronSignAndExecuteTask } from './tasks/TronSignAndExecuteTask.js'\nimport { TronWaitForTransactionTask } from './tasks/TronWaitForTransactionTask.js'\n\nexport class TronStepExecutor extends BaseStepExecutor {\n private wallet: Adapter\n\n constructor(options: TronStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n const address = this.wallet.address\n if (address && address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseTronErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<TronStepExecutorContext> => {\n return {\n ...baseContext,\n wallet: this.wallet,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (\n context: TronStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const isFromNativeToken = isZeroAddress(step.action.fromToken.address)\n\n const tasks = [\n new TronCheckAllowanceTask(),\n new TronSetAllowanceTask(),\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new TronSignAndExecuteTask(),\n new TronWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // A transaction signed for this action may still land (`txHash` after a\n // broadcast, `txHex` right after signing). Resume at the confirmation wait:\n // re-checking the allowance, re-preparing or re-signing could execute the\n // swap twice. A final failure is not open, so \"Try again\" signs anew.\n const isTransactionOpen = hasOpenTransaction(swapOrBridgeAction)\n\n const doCheckAllowance =\n !isTransactionOpen &&\n !isFromNativeToken &&\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval\n\n let firstTask:\n | typeof TronCheckAllowanceTask\n | typeof TronWaitForTransactionTask\n | typeof WaitForTransactionStatusTask\n | typeof CheckBalanceTask\n if (doCheckAllowance) {\n firstTask = TronCheckAllowanceTask\n } else if (isTransactionOpen) {\n firstTask =\n swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : TronWaitForTransactionTask\n } else {\n firstTask = CheckBalanceTask\n }\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'TronStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;AA0BA,IAAa,mBAAb,cAAsCA,UAAAA,iBAAiB;CACrD;CAEA,YAAY,SAAkC;EAC5C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAC9C,MAAM,UAAU,KAAK,OAAO;EAC5B,IAAI,WAAW,YAAY,KAAK,OAAO,aACrC,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,mHACF;CAEJ;CAEA,eACE,OACA,MACA,WACsBC,+BAAAA,gBAAgB,OAAO,MAAM,MAAM;CAE3D,gBAAyB,OACvB,gBACqC;EACrC,OAAO;GACL,GAAG;GACH,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,oBAAoBC,4BAAAA,cAAc,KAAK,OAAO,UAAU,OAAO;EAErE,MAAM,QAAQ;GACZ,IAAIC,0CAAAA,uBAAuB;GAC3B,IAAIC,wCAAAA,qBAAqB;GACzB,IAAIC,UAAAA,iBAAiB;GACrB,IAAIC,UAAAA,uBAAuB;GAC3B,IAAIC,0CAAAA,uBAAuB;GAC3B,IAAIC,8CAAAA,2BAA2B;GAC/B,IAAIC,UAAAA,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAMA,MAAM,qBAAA,GAAoBC,UAAAA,mBAAAA,CAAmB,kBAAkB;EAE/D,MAAM,mBACJ,CAAC,qBACD,CAAC,qBACD,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS;EAEjB,IAAI;EAKJ,IAAI,kBACF,YAAYP,0CAAAA;OACP,IAAI,mBACT,YACE,oBAAoB,WAAW,SAC3BM,UAAAA,+BACAD,8CAAAA;OAEN,YAAYH,UAAAA;EAKd,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAIN,UAAAA,iBACRC,UAAAA,cAAc,eACd,uDACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAIW,UAAAA,aAAa,UAAU;CACpC;AACF"}
1
+ {"version":3,"file":"TronStepExecutor.js","names":["BaseStepExecutor","TransactionError","LiFiErrorCode","parseTronErrors","isZeroAddress","TronCheckAllowanceTask","TronSetAllowanceTask","CheckBalanceTask","PrepareTransactionTask","TronCheckAllowanceAfterPrepareTask","TronSignAndExecuteTask","TronWaitForTransactionTask","WaitForTransactionStatusTask","hasOpenTransaction","TaskPipeline"],"sources":["../../../src/core/TronStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Adapter } from '@tronweb3/tronwallet-abstract-adapter'\nimport { parseTronErrors } from '../errors/parseTronErrors.js'\nimport type {\n TronStepExecutorContext,\n TronStepExecutorOptions,\n} from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { TronCheckAllowanceAfterPrepareTask } from './tasks/TronCheckAllowanceAfterPrepareTask.js'\nimport { TronCheckAllowanceTask } from './tasks/TronCheckAllowanceTask.js'\nimport { TronSetAllowanceTask } from './tasks/TronSetAllowanceTask.js'\nimport { TronSignAndExecuteTask } from './tasks/TronSignAndExecuteTask.js'\nimport { TronWaitForTransactionTask } from './tasks/TronWaitForTransactionTask.js'\n\nexport class TronStepExecutor extends BaseStepExecutor {\n private wallet: Adapter\n\n constructor(options: TronStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n const address = this.wallet.address\n if (address && address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseTronErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<TronStepExecutorContext> => {\n return {\n ...baseContext,\n wallet: this.wallet,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (\n context: TronStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const isFromNativeToken = isZeroAddress(step.action.fromToken.address)\n\n const tasks = [\n new TronCheckAllowanceTask(),\n new TronSetAllowanceTask(),\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new TronCheckAllowanceAfterPrepareTask(),\n new TronSignAndExecuteTask(),\n new TronWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // A transaction signed for this action may still land (`txHash` after a\n // broadcast, `txHex` right after signing). Resume at the confirmation wait:\n // re-checking the allowance, re-preparing or re-signing could execute the\n // swap twice. A final failure is not open, so \"Try again\" signs anew.\n const isTransactionOpen = hasOpenTransaction(swapOrBridgeAction)\n\n const doCheckAllowance =\n !isTransactionOpen &&\n !isFromNativeToken &&\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval\n\n let firstTask:\n | typeof TronCheckAllowanceTask\n | typeof TronWaitForTransactionTask\n | typeof WaitForTransactionStatusTask\n | typeof CheckBalanceTask\n if (doCheckAllowance) {\n firstTask = TronCheckAllowanceTask\n } else if (isTransactionOpen) {\n firstTask =\n swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : TronWaitForTransactionTask\n } else {\n firstTask = CheckBalanceTask\n }\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'TronStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;;AA2BA,IAAa,mBAAb,cAAsCA,UAAAA,iBAAiB;CACrD;CAEA,YAAY,SAAkC;EAC5C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAC9C,MAAM,UAAU,KAAK,OAAO;EAC5B,IAAI,WAAW,YAAY,KAAK,OAAO,aACrC,MAAM,IAAIC,UAAAA,iBACRC,UAAAA,cAAc,8BACd,mHACF;CAEJ;CAEA,eACE,OACA,MACA,WACsBC,+BAAAA,gBAAgB,OAAO,MAAM,MAAM;CAE3D,gBAAyB,OACvB,gBACqC;EACrC,OAAO;GACL,GAAG;GACH,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,oBAAoBC,4BAAAA,cAAc,KAAK,OAAO,UAAU,OAAO;EAErE,MAAM,QAAQ;GACZ,IAAIC,0CAAAA,uBAAuB;GAC3B,IAAIC,wCAAAA,qBAAqB;GACzB,IAAIC,UAAAA,iBAAiB;GACrB,IAAIC,UAAAA,uBAAuB;GAC3B,IAAIC,sDAAAA,mCAAmC;GACvC,IAAIC,0CAAAA,uBAAuB;GAC3B,IAAIC,8CAAAA,2BAA2B;GAC/B,IAAIC,UAAAA,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAMA,MAAM,qBAAA,GAAoBC,UAAAA,mBAAAA,CAAmB,kBAAkB;EAE/D,MAAM,mBACJ,CAAC,qBACD,CAAC,qBACD,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS;EAEjB,IAAI;EAKJ,IAAI,kBACF,YAAYR,0CAAAA;OACP,IAAI,mBACT,YACE,oBAAoB,WAAW,SAC3BO,UAAAA,+BACAD,8CAAAA;OAEN,YAAYJ,UAAAA;EAKd,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAIN,UAAAA,iBACRC,UAAAA,cAAc,eACd,uDACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAIY,UAAAA,aAAa,UAAU;CACpC;AACF"}
@@ -0,0 +1,19 @@
1
+ import { TronStepExecutorContext } from "../../types.js";
2
+ import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
3
+ //#region src/core/tasks/TronCheckAllowanceAfterPrepareTask.d.ts
4
+ /**
5
+ * Runs after PrepareTransaction. Some providers only know the spender once
6
+ * `/stepTransaction` builds the executable transaction, so the routing-time
7
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
8
+ * prepare do not run. When the re-quote brings one, the allowance is read for
9
+ * it, and set only if it falls short, before the transaction is signed.
10
+ *
11
+ * A spender that was already checked before prepare is not checked again.
12
+ */
13
+ export declare class TronCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {
14
+ private readonly allowancePipeline;
15
+ override shouldRun(context: TronStepExecutorContext): Promise<boolean>;
16
+ run(context: TronStepExecutorContext): Promise<TaskResult>;
17
+ }
18
+ //#endregion
19
+ //# sourceMappingURL=TronCheckAllowanceAfterPrepareTask.d.ts.map
@@ -0,0 +1,29 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_utils_isZeroAddress = require("../../utils/isZeroAddress.js");
3
+ const require_core_tasks_TronCheckAllowanceTask = require("./TronCheckAllowanceTask.js");
4
+ const require_core_tasks_TronSetAllowanceTask = require("./TronSetAllowanceTask.js");
5
+ let _lifi_sdk = require("@lifi/sdk");
6
+ //#region src/core/tasks/TronCheckAllowanceAfterPrepareTask.ts
7
+ /**
8
+ * Runs after PrepareTransaction. Some providers only know the spender once
9
+ * `/stepTransaction` builds the executable transaction, so the routing-time
10
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
11
+ * prepare do not run. When the re-quote brings one, the allowance is read for
12
+ * it, and set only if it falls short, before the transaction is signed.
13
+ *
14
+ * A spender that was already checked before prepare is not checked again.
15
+ */
16
+ var TronCheckAllowanceAfterPrepareTask = class extends _lifi_sdk.BaseStepExecutionTask {
17
+ allowancePipeline = new _lifi_sdk.TaskPipeline([new require_core_tasks_TronCheckAllowanceTask.TronCheckAllowanceTask(), new require_core_tasks_TronSetAllowanceTask.TronSetAllowanceTask()]);
18
+ async shouldRun(context) {
19
+ const { step, hasSufficientAllowance } = context;
20
+ return hasSufficientAllowance === void 0 && !require_utils_isZeroAddress.isZeroAddress(step.action.fromToken.address) && !!step.estimate.approvalAddress && !step.estimate.skipApproval;
21
+ }
22
+ async run(context) {
23
+ return this.allowancePipeline.run(context);
24
+ }
25
+ };
26
+ //#endregion
27
+ exports.TronCheckAllowanceAfterPrepareTask = TronCheckAllowanceAfterPrepareTask;
28
+
29
+ //# sourceMappingURL=TronCheckAllowanceAfterPrepareTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TronCheckAllowanceAfterPrepareTask.js","names":["BaseStepExecutionTask","TaskPipeline","TronCheckAllowanceTask","TronSetAllowanceTask","isZeroAddress"],"sources":["../../../../src/core/tasks/TronCheckAllowanceAfterPrepareTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, TaskPipeline, type TaskResult } from '@lifi/sdk'\nimport type { TronStepExecutorContext } from '../../types.js'\nimport { isZeroAddress } from '../../utils/isZeroAddress.js'\nimport { TronCheckAllowanceTask } from './TronCheckAllowanceTask.js'\nimport { TronSetAllowanceTask } from './TronSetAllowanceTask.js'\n\n/**\n * Runs after PrepareTransaction. Some providers only know the spender once\n * `/stepTransaction` builds the executable transaction, so the routing-time\n * step carries no `estimate.approvalAddress` and the allowance tasks before\n * prepare do not run. When the re-quote brings one, the allowance is read for\n * it, and set only if it falls short, before the transaction is signed.\n *\n * A spender that was already checked before prepare is not checked again.\n */\nexport class TronCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {\n private readonly allowancePipeline = new TaskPipeline([\n new TronCheckAllowanceTask(),\n new TronSetAllowanceTask(),\n ])\n\n override async shouldRun(context: TronStepExecutorContext): Promise<boolean> {\n const { step, hasSufficientAllowance } = context\n // `hasSufficientAllowance` is only set by the allowance tasks, so it is\n // unset exactly when none ran before prepare.\n return (\n hasSufficientAllowance === undefined &&\n !isZeroAddress(step.action.fromToken.address) &&\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval\n )\n }\n\n async run(context: TronStepExecutorContext): Promise<TaskResult> {\n return this.allowancePipeline.run(context)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;AAeA,IAAa,qCAAb,cAAwDA,UAAAA,sBAAsB;CAC5E,oBAAqC,IAAIC,UAAAA,aAAa,CACpD,IAAIC,0CAAAA,uBAAuB,GAC3B,IAAIC,wCAAAA,qBAAqB,CAC3B,CAAC;CAED,MAAe,UAAU,SAAoD;EAC3E,MAAM,EAAE,MAAM,2BAA2B;EAGzC,OACE,2BAA2B,KAAA,KAC3B,CAACC,4BAAAA,cAAc,KAAK,OAAO,UAAU,OAAO,KAC5C,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS;CAEnB;CAEA,MAAM,IAAI,SAAuD;EAC/D,OAAO,KAAK,kBAAkB,IAAI,OAAO;CAC3C;AACF"}
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
2
  export declare const name = "@lifi/sdk-provider-tron";
3
- export declare const version = "4.1.9";
3
+ export declare const version = "4.1.10";
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-provider-tron";
4
- const version = "4.1.9";
4
+ const version = "4.1.10";
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-provider-tron'\nexport const version = '4.1.9'\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-provider-tron'\nexport const version = '4.1.10'\n"],"mappings":";;AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
@@ -1 +1 @@
1
- {"version":3,"file":"TronStepExecutor.d.ts","names":[],"sources":["../../../src/core/TronStepExecutor.ts"],"mappings":";;;qBA0Ba,yBAAyB;UAC5B;EAER,YAAY,SAAS;EAKrB,cAAe,MAAM;WAUZ,cACP,OAAO,OACP,OAAO,kBACP,SAAS,oBACR,QAAQ;WAEF,gBACP,aAAa,4BACZ,QAAQ;WAQF,iBACP,SAAS,4BACR"}
1
+ {"version":3,"file":"TronStepExecutor.d.ts","names":[],"sources":["../../../src/core/TronStepExecutor.ts"],"mappings":";;;qBA2Ba,yBAAyB;UAC5B;EAER,YAAY,SAAS;EAKrB,cAAe,MAAM;WAUZ,cACP,OAAO,OACP,OAAO,kBACP,SAAS,oBACR,QAAQ;WAEF,gBACP,aAAa,4BACZ,QAAQ;WAQF,iBACP,SAAS,4BACR"}
@@ -2,6 +2,7 @@ import { isZeroAddress } from "../utils/isZeroAddress.js";
2
2
  import { parseTronErrors } from "../errors/parseTronErrors.js";
3
3
  import { TronCheckAllowanceTask } from "./tasks/TronCheckAllowanceTask.js";
4
4
  import { TronSetAllowanceTask } from "./tasks/TronSetAllowanceTask.js";
5
+ import { TronCheckAllowanceAfterPrepareTask } from "./tasks/TronCheckAllowanceAfterPrepareTask.js";
5
6
  import { TronSignAndExecuteTask } from "./tasks/TronSignAndExecuteTask.js";
6
7
  import { TronWaitForTransactionTask } from "./tasks/TronWaitForTransactionTask.js";
7
8
  import { BaseStepExecutor, CheckBalanceTask, LiFiErrorCode, PrepareTransactionTask, TaskPipeline, TransactionError, WaitForTransactionStatusTask, hasOpenTransaction } from "@lifi/sdk";
@@ -32,6 +33,7 @@ var TronStepExecutor = class extends BaseStepExecutor {
32
33
  new TronSetAllowanceTask(),
33
34
  new CheckBalanceTask(),
34
35
  new PrepareTransactionTask(),
36
+ new TronCheckAllowanceAfterPrepareTask(),
35
37
  new TronSignAndExecuteTask(),
36
38
  new TronWaitForTransactionTask(),
37
39
  new WaitForTransactionStatusTask(isBridgeExecution ? "RECEIVING_CHAIN" : "SWAP")
@@ -1 +1 @@
1
- {"version":3,"file":"TronStepExecutor.js","names":[],"sources":["../../../src/core/TronStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Adapter } from '@tronweb3/tronwallet-abstract-adapter'\nimport { parseTronErrors } from '../errors/parseTronErrors.js'\nimport type {\n TronStepExecutorContext,\n TronStepExecutorOptions,\n} from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { TronCheckAllowanceTask } from './tasks/TronCheckAllowanceTask.js'\nimport { TronSetAllowanceTask } from './tasks/TronSetAllowanceTask.js'\nimport { TronSignAndExecuteTask } from './tasks/TronSignAndExecuteTask.js'\nimport { TronWaitForTransactionTask } from './tasks/TronWaitForTransactionTask.js'\n\nexport class TronStepExecutor extends BaseStepExecutor {\n private wallet: Adapter\n\n constructor(options: TronStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n const address = this.wallet.address\n if (address && address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseTronErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<TronStepExecutorContext> => {\n return {\n ...baseContext,\n wallet: this.wallet,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (\n context: TronStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const isFromNativeToken = isZeroAddress(step.action.fromToken.address)\n\n const tasks = [\n new TronCheckAllowanceTask(),\n new TronSetAllowanceTask(),\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new TronSignAndExecuteTask(),\n new TronWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // A transaction signed for this action may still land (`txHash` after a\n // broadcast, `txHex` right after signing). Resume at the confirmation wait:\n // re-checking the allowance, re-preparing or re-signing could execute the\n // swap twice. A final failure is not open, so \"Try again\" signs anew.\n const isTransactionOpen = hasOpenTransaction(swapOrBridgeAction)\n\n const doCheckAllowance =\n !isTransactionOpen &&\n !isFromNativeToken &&\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval\n\n let firstTask:\n | typeof TronCheckAllowanceTask\n | typeof TronWaitForTransactionTask\n | typeof WaitForTransactionStatusTask\n | typeof CheckBalanceTask\n if (doCheckAllowance) {\n firstTask = TronCheckAllowanceTask\n } else if (isTransactionOpen) {\n firstTask =\n swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : TronWaitForTransactionTask\n } else {\n firstTask = CheckBalanceTask\n }\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'TronStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;AA0BA,IAAa,mBAAb,cAAsC,iBAAiB;CACrD;CAEA,YAAY,SAAkC;EAC5C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAC9C,MAAM,UAAU,KAAK,OAAO;EAC5B,IAAI,WAAW,YAAY,KAAK,OAAO,aACrC,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;CAEJ;CAEA,eACE,OACA,MACA,WACsB,gBAAgB,OAAO,MAAM,MAAM;CAE3D,gBAAyB,OACvB,gBACqC;EACrC,OAAO;GACL,GAAG;GACH,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,oBAAoB,cAAc,KAAK,OAAO,UAAU,OAAO;EAErE,MAAM,QAAQ;GACZ,IAAI,uBAAuB;GAC3B,IAAI,qBAAqB;GACzB,IAAI,iBAAiB;GACrB,IAAI,uBAAuB;GAC3B,IAAI,uBAAuB;GAC3B,IAAI,2BAA2B;GAC/B,IAAI,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAMA,MAAM,oBAAoB,mBAAmB,kBAAkB;EAE/D,MAAM,mBACJ,CAAC,qBACD,CAAC,qBACD,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS;EAEjB,IAAI;EAKJ,IAAI,kBACF,YAAY;OACP,IAAI,mBACT,YACE,oBAAoB,WAAW,SAC3B,+BACA;OAEN,YAAY;EAKd,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAI,iBACR,cAAc,eACd,uDACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
1
+ {"version":3,"file":"TronStepExecutor.js","names":[],"sources":["../../../src/core/TronStepExecutor.ts"],"sourcesContent":["import {\n BaseStepExecutor,\n CheckBalanceTask,\n type ExecutionAction,\n hasOpenTransaction,\n LiFiErrorCode,\n type LiFiStepExtended,\n PrepareTransactionTask,\n type SDKError,\n type StepExecutorBaseContext,\n TaskPipeline,\n TransactionError,\n WaitForTransactionStatusTask,\n} from '@lifi/sdk'\nimport type { Adapter } from '@tronweb3/tronwallet-abstract-adapter'\nimport { parseTronErrors } from '../errors/parseTronErrors.js'\nimport type {\n TronStepExecutorContext,\n TronStepExecutorOptions,\n} from '../types.js'\nimport { isZeroAddress } from '../utils/isZeroAddress.js'\nimport { TronCheckAllowanceAfterPrepareTask } from './tasks/TronCheckAllowanceAfterPrepareTask.js'\nimport { TronCheckAllowanceTask } from './tasks/TronCheckAllowanceTask.js'\nimport { TronSetAllowanceTask } from './tasks/TronSetAllowanceTask.js'\nimport { TronSignAndExecuteTask } from './tasks/TronSignAndExecuteTask.js'\nimport { TronWaitForTransactionTask } from './tasks/TronWaitForTransactionTask.js'\n\nexport class TronStepExecutor extends BaseStepExecutor {\n private wallet: Adapter\n\n constructor(options: TronStepExecutorOptions) {\n super(options)\n this.wallet = options.wallet\n }\n\n checkWallet = (step: LiFiStepExtended): void => {\n const address = this.wallet.address\n if (address && address !== step.action.fromAddress) {\n throw new TransactionError(\n LiFiErrorCode.WalletChangedDuringExecution,\n 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.'\n )\n }\n }\n\n override parseErrors = (\n error: Error,\n step?: LiFiStepExtended,\n action?: ExecutionAction\n ): Promise<SDKError> => parseTronErrors(error, step, action)\n\n override createContext = async (\n baseContext: StepExecutorBaseContext\n ): Promise<TronStepExecutorContext> => {\n return {\n ...baseContext,\n wallet: this.wallet,\n checkWallet: this.checkWallet,\n }\n }\n\n override createPipeline = (\n context: TronStepExecutorContext\n ): TaskPipeline => {\n const { step, isBridgeExecution } = context\n\n const isFromNativeToken = isZeroAddress(step.action.fromToken.address)\n\n const tasks = [\n new TronCheckAllowanceTask(),\n new TronSetAllowanceTask(),\n new CheckBalanceTask(),\n new PrepareTransactionTask(),\n new TronCheckAllowanceAfterPrepareTask(),\n new TronSignAndExecuteTask(),\n new TronWaitForTransactionTask(),\n new WaitForTransactionStatusTask(\n isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'\n ),\n ]\n\n const swapOrBridgeAction = this.statusManager.findAction(\n step,\n isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP'\n )\n\n // A transaction signed for this action may still land (`txHash` after a\n // broadcast, `txHex` right after signing). Resume at the confirmation wait:\n // re-checking the allowance, re-preparing or re-signing could execute the\n // swap twice. A final failure is not open, so \"Try again\" signs anew.\n const isTransactionOpen = hasOpenTransaction(swapOrBridgeAction)\n\n const doCheckAllowance =\n !isTransactionOpen &&\n !isFromNativeToken &&\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval\n\n let firstTask:\n | typeof TronCheckAllowanceTask\n | typeof TronWaitForTransactionTask\n | typeof WaitForTransactionStatusTask\n | typeof CheckBalanceTask\n if (doCheckAllowance) {\n firstTask = TronCheckAllowanceTask\n } else if (isTransactionOpen) {\n firstTask =\n swapOrBridgeAction?.status === 'DONE'\n ? WaitForTransactionStatusTask\n : TronWaitForTransactionTask\n } else {\n firstTask = CheckBalanceTask\n }\n\n // Compare classes, not names: a minifier can give two task classes the\n // same name.\n const firstTaskIndex = tasks.findIndex(\n (task) => task.constructor === firstTask\n )\n if (firstTaskIndex === -1) {\n throw new TransactionError(\n LiFiErrorCode.InternalError,\n 'TronStepExecutor.createPipeline: first task not found'\n )\n }\n\n const tasksToRun = tasks.slice(firstTaskIndex)\n\n return new TaskPipeline(tasksToRun)\n }\n}\n"],"mappings":";;;;;;;;;AA2BA,IAAa,mBAAb,cAAsC,iBAAiB;CACrD;CAEA,YAAY,SAAkC;EAC5C,MAAM,OAAO;EACb,KAAK,SAAS,QAAQ;CACxB;CAEA,eAAe,SAAiC;EAC9C,MAAM,UAAU,KAAK,OAAO;EAC5B,IAAI,WAAW,YAAY,KAAK,OAAO,aACrC,MAAM,IAAI,iBACR,cAAc,8BACd,mHACF;CAEJ;CAEA,eACE,OACA,MACA,WACsB,gBAAgB,OAAO,MAAM,MAAM;CAE3D,gBAAyB,OACvB,gBACqC;EACrC,OAAO;GACL,GAAG;GACH,QAAQ,KAAK;GACb,aAAa,KAAK;EACpB;CACF;CAEA,kBACE,YACiB;EACjB,MAAM,EAAE,MAAM,sBAAsB;EAEpC,MAAM,oBAAoB,cAAc,KAAK,OAAO,UAAU,OAAO;EAErE,MAAM,QAAQ;GACZ,IAAI,uBAAuB;GAC3B,IAAI,qBAAqB;GACzB,IAAI,iBAAiB;GACrB,IAAI,uBAAuB;GAC3B,IAAI,mCAAmC;GACvC,IAAI,uBAAuB;GAC3B,IAAI,2BAA2B;GAC/B,IAAI,6BACF,oBAAoB,oBAAoB,MAC1C;EACF;EAEA,MAAM,qBAAqB,KAAK,cAAc,WAC5C,MACA,oBAAoB,gBAAgB,MACtC;EAMA,MAAM,oBAAoB,mBAAmB,kBAAkB;EAE/D,MAAM,mBACJ,CAAC,qBACD,CAAC,qBACD,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS;EAEjB,IAAI;EAKJ,IAAI,kBACF,YAAY;OACP,IAAI,mBACT,YACE,oBAAoB,WAAW,SAC3B,+BACA;OAEN,YAAY;EAKd,MAAM,iBAAiB,MAAM,WAC1B,SAAS,KAAK,gBAAgB,SACjC;EACA,IAAI,mBAAmB,IACrB,MAAM,IAAI,iBACR,cAAc,eACd,uDACF;EAGF,MAAM,aAAa,MAAM,MAAM,cAAc;EAE7C,OAAO,IAAI,aAAa,UAAU;CACpC;AACF"}
@@ -0,0 +1,19 @@
1
+ import { TronStepExecutorContext } from "../../types.js";
2
+ import { BaseStepExecutionTask, TaskResult } from "@lifi/sdk";
3
+ //#region src/core/tasks/TronCheckAllowanceAfterPrepareTask.d.ts
4
+ /**
5
+ * Runs after PrepareTransaction. Some providers only know the spender once
6
+ * `/stepTransaction` builds the executable transaction, so the routing-time
7
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
8
+ * prepare do not run. When the re-quote brings one, the allowance is read for
9
+ * it, and set only if it falls short, before the transaction is signed.
10
+ *
11
+ * A spender that was already checked before prepare is not checked again.
12
+ */
13
+ export declare class TronCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {
14
+ private readonly allowancePipeline;
15
+ override shouldRun(context: TronStepExecutorContext): Promise<boolean>;
16
+ run(context: TronStepExecutorContext): Promise<TaskResult>;
17
+ }
18
+ //#endregion
19
+ //# sourceMappingURL=TronCheckAllowanceAfterPrepareTask.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TronCheckAllowanceAfterPrepareTask.d.ts","names":[],"sources":["../../../../src/core/tasks/TronCheckAllowanceAfterPrepareTask.ts"],"mappings":";;;;;;;;;;;;qBAea,2CAA2C;mBACrC;WAKF,UAAU,SAAS,0BAA0B;EAY5D,IAAU,SAAS,0BAA0B,QAAQ"}
@@ -0,0 +1,28 @@
1
+ import { isZeroAddress } from "../../utils/isZeroAddress.js";
2
+ import { TronCheckAllowanceTask } from "./TronCheckAllowanceTask.js";
3
+ import { TronSetAllowanceTask } from "./TronSetAllowanceTask.js";
4
+ import { BaseStepExecutionTask, TaskPipeline } from "@lifi/sdk";
5
+ //#region src/core/tasks/TronCheckAllowanceAfterPrepareTask.ts
6
+ /**
7
+ * Runs after PrepareTransaction. Some providers only know the spender once
8
+ * `/stepTransaction` builds the executable transaction, so the routing-time
9
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
10
+ * prepare do not run. When the re-quote brings one, the allowance is read for
11
+ * it, and set only if it falls short, before the transaction is signed.
12
+ *
13
+ * A spender that was already checked before prepare is not checked again.
14
+ */
15
+ var TronCheckAllowanceAfterPrepareTask = class extends BaseStepExecutionTask {
16
+ allowancePipeline = new TaskPipeline([new TronCheckAllowanceTask(), new TronSetAllowanceTask()]);
17
+ async shouldRun(context) {
18
+ const { step, hasSufficientAllowance } = context;
19
+ return hasSufficientAllowance === void 0 && !isZeroAddress(step.action.fromToken.address) && !!step.estimate.approvalAddress && !step.estimate.skipApproval;
20
+ }
21
+ async run(context) {
22
+ return this.allowancePipeline.run(context);
23
+ }
24
+ };
25
+ //#endregion
26
+ export { TronCheckAllowanceAfterPrepareTask };
27
+
28
+ //# sourceMappingURL=TronCheckAllowanceAfterPrepareTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TronCheckAllowanceAfterPrepareTask.js","names":[],"sources":["../../../../src/core/tasks/TronCheckAllowanceAfterPrepareTask.ts"],"sourcesContent":["import { BaseStepExecutionTask, TaskPipeline, type TaskResult } from '@lifi/sdk'\nimport type { TronStepExecutorContext } from '../../types.js'\nimport { isZeroAddress } from '../../utils/isZeroAddress.js'\nimport { TronCheckAllowanceTask } from './TronCheckAllowanceTask.js'\nimport { TronSetAllowanceTask } from './TronSetAllowanceTask.js'\n\n/**\n * Runs after PrepareTransaction. Some providers only know the spender once\n * `/stepTransaction` builds the executable transaction, so the routing-time\n * step carries no `estimate.approvalAddress` and the allowance tasks before\n * prepare do not run. When the re-quote brings one, the allowance is read for\n * it, and set only if it falls short, before the transaction is signed.\n *\n * A spender that was already checked before prepare is not checked again.\n */\nexport class TronCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {\n private readonly allowancePipeline = new TaskPipeline([\n new TronCheckAllowanceTask(),\n new TronSetAllowanceTask(),\n ])\n\n override async shouldRun(context: TronStepExecutorContext): Promise<boolean> {\n const { step, hasSufficientAllowance } = context\n // `hasSufficientAllowance` is only set by the allowance tasks, so it is\n // unset exactly when none ran before prepare.\n return (\n hasSufficientAllowance === undefined &&\n !isZeroAddress(step.action.fromToken.address) &&\n !!step.estimate.approvalAddress &&\n !step.estimate.skipApproval\n )\n }\n\n async run(context: TronStepExecutorContext): Promise<TaskResult> {\n return this.allowancePipeline.run(context)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA,IAAa,qCAAb,cAAwD,sBAAsB;CAC5E,oBAAqC,IAAI,aAAa,CACpD,IAAI,uBAAuB,GAC3B,IAAI,qBAAqB,CAC3B,CAAC;CAED,MAAe,UAAU,SAAoD;EAC3E,MAAM,EAAE,MAAM,2BAA2B;EAGzC,OACE,2BAA2B,KAAA,KAC3B,CAAC,cAAc,KAAK,OAAO,UAAU,OAAO,KAC5C,CAAC,CAAC,KAAK,SAAS,mBAChB,CAAC,KAAK,SAAS;CAEnB;CAEA,MAAM,IAAI,SAAuD;EAC/D,OAAO,KAAK,kBAAkB,IAAI,OAAO;CAC3C;AACF"}
@@ -1,5 +1,5 @@
1
1
  //#region src/version.d.ts
2
2
  export declare const name = "@lifi/sdk-provider-tron";
3
- export declare const version = "4.1.9";
3
+ export declare const version = "4.1.10";
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-provider-tron";
3
- const version = "4.1.9";
3
+ const version = "4.1.10";
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-provider-tron'\nexport const version = '4.1.9'\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-provider-tron'\nexport const version = '4.1.10'\n"],"mappings":";AAAA,MAAa,OAAO;AACpB,MAAa,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lifi/sdk-provider-tron",
3
- "version": "4.1.9",
3
+ "version": "4.1.10",
4
4
  "description": "LI.FI Tron SDK Provider for Any-to-Any Cross-Chain-Swap",
5
5
  "homepage": "https://github.com/lifinance/sdk",
6
6
  "bugs": {
@@ -19,6 +19,7 @@ import type {
19
19
  TronStepExecutorOptions,
20
20
  } from '../types.js'
21
21
  import { isZeroAddress } from '../utils/isZeroAddress.js'
22
+ import { TronCheckAllowanceAfterPrepareTask } from './tasks/TronCheckAllowanceAfterPrepareTask.js'
22
23
  import { TronCheckAllowanceTask } from './tasks/TronCheckAllowanceTask.js'
23
24
  import { TronSetAllowanceTask } from './tasks/TronSetAllowanceTask.js'
24
25
  import { TronSignAndExecuteTask } from './tasks/TronSignAndExecuteTask.js'
@@ -70,6 +71,7 @@ export class TronStepExecutor extends BaseStepExecutor {
70
71
  new TronSetAllowanceTask(),
71
72
  new CheckBalanceTask(),
72
73
  new PrepareTransactionTask(),
74
+ new TronCheckAllowanceAfterPrepareTask(),
73
75
  new TronSignAndExecuteTask(),
74
76
  new TronWaitForTransactionTask(),
75
77
  new WaitForTransactionStatusTask(
@@ -0,0 +1,37 @@
1
+ import { BaseStepExecutionTask, TaskPipeline, type TaskResult } from '@lifi/sdk'
2
+ import type { TronStepExecutorContext } from '../../types.js'
3
+ import { isZeroAddress } from '../../utils/isZeroAddress.js'
4
+ import { TronCheckAllowanceTask } from './TronCheckAllowanceTask.js'
5
+ import { TronSetAllowanceTask } from './TronSetAllowanceTask.js'
6
+
7
+ /**
8
+ * Runs after PrepareTransaction. Some providers only know the spender once
9
+ * `/stepTransaction` builds the executable transaction, so the routing-time
10
+ * step carries no `estimate.approvalAddress` and the allowance tasks before
11
+ * prepare do not run. When the re-quote brings one, the allowance is read for
12
+ * it, and set only if it falls short, before the transaction is signed.
13
+ *
14
+ * A spender that was already checked before prepare is not checked again.
15
+ */
16
+ export class TronCheckAllowanceAfterPrepareTask extends BaseStepExecutionTask {
17
+ private readonly allowancePipeline = new TaskPipeline([
18
+ new TronCheckAllowanceTask(),
19
+ new TronSetAllowanceTask(),
20
+ ])
21
+
22
+ override async shouldRun(context: TronStepExecutorContext): Promise<boolean> {
23
+ const { step, hasSufficientAllowance } = context
24
+ // `hasSufficientAllowance` is only set by the allowance tasks, so it is
25
+ // unset exactly when none ran before prepare.
26
+ return (
27
+ hasSufficientAllowance === undefined &&
28
+ !isZeroAddress(step.action.fromToken.address) &&
29
+ !!step.estimate.approvalAddress &&
30
+ !step.estimate.skipApproval
31
+ )
32
+ }
33
+
34
+ async run(context: TronStepExecutorContext): Promise<TaskResult> {
35
+ return this.allowancePipeline.run(context)
36
+ }
37
+ }
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export const name = '@lifi/sdk-provider-tron'
2
- export const version = '4.1.9'
2
+ export const version = '4.1.10'