@lifi/sdk-provider-tron 4.0.0-alpha.21

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 (95) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +79 -0
  3. package/dist/cjs/TronProvider.d.ts +2 -0
  4. package/dist/cjs/TronProvider.js +37 -0
  5. package/dist/cjs/TronProvider.js.map +1 -0
  6. package/dist/cjs/actions/getTronBalance.d.ts +2 -0
  7. package/dist/cjs/actions/getTronBalance.js +75 -0
  8. package/dist/cjs/actions/getTronBalance.js.map +1 -0
  9. package/dist/cjs/actions/resolveTronAddress.d.ts +1 -0
  10. package/dist/cjs/actions/resolveTronAddress.js +7 -0
  11. package/dist/cjs/actions/resolveTronAddress.js.map +1 -0
  12. package/dist/cjs/core/TronStepExecutor.d.ts +10 -0
  13. package/dist/cjs/core/TronStepExecutor.js +47 -0
  14. package/dist/cjs/core/TronStepExecutor.js.map +1 -0
  15. package/dist/cjs/core/tasks/TronSignAndExecuteTask.d.ts +5 -0
  16. package/dist/cjs/core/tasks/TronSignAndExecuteTask.js +26 -0
  17. package/dist/cjs/core/tasks/TronSignAndExecuteTask.js.map +1 -0
  18. package/dist/cjs/core/tasks/TronWaitForTransactionTask.d.ts +5 -0
  19. package/dist/cjs/core/tasks/TronWaitForTransactionTask.js +56 -0
  20. package/dist/cjs/core/tasks/TronWaitForTransactionTask.js.map +1 -0
  21. package/dist/cjs/errors/parseTronErrors.d.ts +2 -0
  22. package/dist/cjs/errors/parseTronErrors.js +43 -0
  23. package/dist/cjs/errors/parseTronErrors.js.map +1 -0
  24. package/dist/cjs/index.d.ts +3 -0
  25. package/dist/cjs/index.js +8 -0
  26. package/dist/cjs/index.js.map +1 -0
  27. package/dist/cjs/package.json +1 -0
  28. package/dist/cjs/types.d.ts +20 -0
  29. package/dist/cjs/types.js +8 -0
  30. package/dist/cjs/types.js.map +1 -0
  31. package/dist/cjs/version.d.ts +2 -0
  32. package/dist/cjs/version.js +6 -0
  33. package/dist/cjs/version.js.map +1 -0
  34. package/dist/esm/TronProvider.d.ts +2 -0
  35. package/dist/esm/TronProvider.js +34 -0
  36. package/dist/esm/TronProvider.js.map +1 -0
  37. package/dist/esm/actions/getTronBalance.d.ts +2 -0
  38. package/dist/esm/actions/getTronBalance.js +72 -0
  39. package/dist/esm/actions/getTronBalance.js.map +1 -0
  40. package/dist/esm/actions/resolveTronAddress.d.ts +1 -0
  41. package/dist/esm/actions/resolveTronAddress.js +5 -0
  42. package/dist/esm/actions/resolveTronAddress.js.map +1 -0
  43. package/dist/esm/core/TronStepExecutor.d.ts +10 -0
  44. package/dist/esm/core/TronStepExecutor.js +43 -0
  45. package/dist/esm/core/TronStepExecutor.js.map +1 -0
  46. package/dist/esm/core/tasks/TronSignAndExecuteTask.d.ts +5 -0
  47. package/dist/esm/core/tasks/TronSignAndExecuteTask.js +22 -0
  48. package/dist/esm/core/tasks/TronSignAndExecuteTask.js.map +1 -0
  49. package/dist/esm/core/tasks/TronWaitForTransactionTask.d.ts +5 -0
  50. package/dist/esm/core/tasks/TronWaitForTransactionTask.js +53 -0
  51. package/dist/esm/core/tasks/TronWaitForTransactionTask.js.map +1 -0
  52. package/dist/esm/errors/parseTronErrors.d.ts +2 -0
  53. package/dist/esm/errors/parseTronErrors.js +40 -0
  54. package/dist/esm/errors/parseTronErrors.js.map +1 -0
  55. package/dist/esm/index.d.ts +3 -0
  56. package/dist/esm/index.js +4 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/esm/package.json +1 -0
  59. package/dist/esm/types.d.ts +20 -0
  60. package/dist/esm/types.js +5 -0
  61. package/dist/esm/types.js.map +1 -0
  62. package/dist/esm/version.d.ts +2 -0
  63. package/dist/esm/version.js +3 -0
  64. package/dist/esm/version.js.map +1 -0
  65. package/dist/types/TronProvider.d.ts +3 -0
  66. package/dist/types/TronProvider.d.ts.map +1 -0
  67. package/dist/types/actions/getTronBalance.d.ts +3 -0
  68. package/dist/types/actions/getTronBalance.d.ts.map +1 -0
  69. package/dist/types/actions/resolveTronAddress.d.ts +2 -0
  70. package/dist/types/actions/resolveTronAddress.d.ts.map +1 -0
  71. package/dist/types/core/TronStepExecutor.d.ts +11 -0
  72. package/dist/types/core/TronStepExecutor.d.ts.map +1 -0
  73. package/dist/types/core/tasks/TronSignAndExecuteTask.d.ts +6 -0
  74. package/dist/types/core/tasks/TronSignAndExecuteTask.d.ts.map +1 -0
  75. package/dist/types/core/tasks/TronWaitForTransactionTask.d.ts +6 -0
  76. package/dist/types/core/tasks/TronWaitForTransactionTask.d.ts.map +1 -0
  77. package/dist/types/errors/parseTronErrors.d.ts +3 -0
  78. package/dist/types/errors/parseTronErrors.d.ts.map +1 -0
  79. package/dist/types/index.d.ts +4 -0
  80. package/dist/types/index.d.ts.map +1 -0
  81. package/dist/types/types.d.ts +21 -0
  82. package/dist/types/types.d.ts.map +1 -0
  83. package/dist/types/version.d.ts +3 -0
  84. package/dist/types/version.d.ts.map +1 -0
  85. package/package.json +76 -0
  86. package/src/TronProvider.ts +48 -0
  87. package/src/actions/getTronBalance.ts +108 -0
  88. package/src/actions/resolveTronAddress.ts +6 -0
  89. package/src/core/TronStepExecutor.ts +88 -0
  90. package/src/core/tasks/TronSignAndExecuteTask.ts +53 -0
  91. package/src/core/tasks/TronWaitForTransactionTask.ts +102 -0
  92. package/src/errors/parseTronErrors.ts +83 -0
  93. package/src/index.ts +4 -0
  94. package/src/types.ts +38 -0
  95. package/src/version.ts +2 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright LI.FI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,79 @@
1
+ <div align="center">
2
+
3
+ [![license](https://img.shields.io/github/license/lifinance/sdk)](/LICENSE)
4
+ [![npm latest package](https://img.shields.io/npm/v/@lifi/sdk/latest.svg)](https://www.npmjs.com/package/@lifi/sdk)
5
+ [![npm downloads](https://img.shields.io/npm/dm/@lifi/sdk.svg)](https://www.npmjs.com/package/@lifi/sdk)
6
+ [![Follow on Twitter](https://img.shields.io/twitter/follow/lifiprotocol.svg?label=follow+LI.FI)](https://twitter.com/lifiprotocol)
7
+
8
+ </div>
9
+
10
+ <h1 align="center">LI.FI SDK</h1>
11
+
12
+ [**LI.FI SDK**](https://docs.li.fi/sdk/overview) provides a powerful toolkit for developers to enable seamless cross-chain and on-chain swaps and bridging within their applications. Our JavaScript/TypeScript SDK can be implemented in front-end or back-end environments, allowing you to build robust UX/UI around our advanced bridge and swap functionalities. LI.FI SDK efficiently manages all communications between our smart routing API and smart contracts and ensures optimal performance, security, and scalability for your cross-chain and on-chain needs.
13
+
14
+ [**LI.FI SDK**](https://docs.li.fi/sdk/overview) features include:
15
+
16
+ - All ecosystems, chains, bridges, exchanges, and solvers that [LI.FI](https://docs.li.fi/introduction/chains) supports
17
+ - Complete functionality covering full-cycle from obtaining routes/quotes to executing transactions
18
+ - Easy tracking of the route and quote execution through the robust event and hooks handling
19
+ - Highly customizable settings to tailor the SDK to your specific needs including configuration of RPCs and options to allow or deny certain chains, tokens, bridges, exchanges, solvers
20
+ - Supports widely adopted industry standards, including [EIP-5792](https://eips.ethereum.org/EIPS/eip-5792), [ERC-2612](https://eips.ethereum.org/EIPS/eip-2612), [EIP-712](https://eips.ethereum.org/EIPS/eip-712), and [Permit2](https://github.com/Uniswap/permit2)
21
+ - SDK ecosystem providers are based on industry-standard libraries ([Viem](https://viem.sh/), [Wallet Standard](https://github.com/wallet-standard/wallet-standard), [Bigmi](https://github.com/lifinance/bigmi))
22
+ - Support for arbitrary contract calls on the destination chain
23
+ - Designed for optimal performance with tree-shaking and dead-code elimination, ensuring minimal bundle sizes and faster page load times in front-end environments
24
+ - Compatibility tested with Node.js and popular front-end tools like Vite
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pnpm add @lifi/sdk
30
+ ```
31
+
32
+ or
33
+
34
+ ```bash
35
+ npm install --save @lifi/sdk
36
+ ```
37
+
38
+ ## Quick Start
39
+
40
+ ### Set up the SDK
41
+
42
+ Firstly, create SDK config with your integrator string.
43
+
44
+ ```ts
45
+ import { createConfig } from '@lifi/sdk'
46
+
47
+ createConfig({
48
+ integrator: 'Your dApp/company name',
49
+ })
50
+ ```
51
+
52
+ ### Request a Quote
53
+
54
+ Now you can interact with the SDK and for example request a quote.
55
+
56
+ ```ts
57
+ import { ChainId, getQuote } from '@lifi/sdk'
58
+
59
+ const quote = await getQuote({
60
+ fromAddress: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
61
+ fromChain: ChainId.ARB,
62
+ toChain: ChainId.OPT,
63
+ fromToken: '0x0000000000000000000000000000000000000000',
64
+ toToken: '0x0000000000000000000000000000000000000000',
65
+ fromAmount: '1000000000000000000',
66
+ })
67
+ ```
68
+
69
+ ## Examples
70
+
71
+ See [examples](/examples) folder in this repository.
72
+
73
+ ## Documentation
74
+
75
+ Please checkout the [SDK documentation](https://docs.li.fi/sdk/overview) and our [API reference](https://docs.li.fi/api-reference/introduction) for further information.
76
+
77
+ ## Changelog
78
+
79
+ The [changelog](/CHANGELOG.md) is regularly updated to reflect what's changed in each new release.
@@ -0,0 +1,2 @@
1
+ import type { TronProviderOptions, TronSDKProvider } from './types.js';
2
+ export declare function TronProvider(options?: TronProviderOptions): TronSDKProvider;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TronProvider = TronProvider;
4
+ const sdk_1 = require("@lifi/sdk");
5
+ const tronweb_1 = require("tronweb");
6
+ const getTronBalance_js_1 = require("./actions/getTronBalance.js");
7
+ const resolveTronAddress_js_1 = require("./actions/resolveTronAddress.js");
8
+ const TronStepExecutor_js_1 = require("./core/TronStepExecutor.js");
9
+ function TronProvider(options) {
10
+ const _options = options ?? {};
11
+ return {
12
+ get type() {
13
+ return sdk_1.ChainType.TVM;
14
+ },
15
+ isAddress: (address) => tronweb_1.TronWeb.isAddress(address),
16
+ resolveAddress: resolveTronAddress_js_1.resolveTronAddress,
17
+ getBalance: getTronBalance_js_1.getTronBalance,
18
+ async getStepExecutor(options) {
19
+ if (!_options.getWallet) {
20
+ throw new sdk_1.ProviderError(sdk_1.LiFiErrorCode.ProviderUnavailable, 'TronProvider requires a getWallet function.');
21
+ }
22
+ const wallet = await _options.getWallet();
23
+ const executor = new TronStepExecutor_js_1.TronStepExecutor({
24
+ wallet,
25
+ routeId: options.routeId,
26
+ executionOptions: {
27
+ ...options.executionOptions,
28
+ },
29
+ });
30
+ return executor;
31
+ },
32
+ setOptions(options) {
33
+ Object.assign(_options, options);
34
+ },
35
+ };
36
+ }
37
+ //# sourceMappingURL=TronProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TronProvider.js","sourceRoot":"","sources":["../../src/TronProvider.ts"],"names":[],"mappings":";;AAYA,oCAmCC;AA/CD,mCAKkB;AAClB,qCAAiC;AACjC,mEAA4D;AAC5D,2EAAoE;AACpE,oEAA6D;AAG7D,SAAgB,YAAY,CAAC,OAA6B;IACxD,MAAM,QAAQ,GAAwB,OAAO,IAAI,EAAE,CAAA;IACnD,OAAO;QACL,IAAI,IAAI;YACN,OAAO,eAAS,CAAC,GAAG,CAAA;QACtB,CAAC;QACD,SAAS,EAAE,CAAC,OAAe,EAAE,EAAE,CAAC,iBAAO,CAAC,SAAS,CAAC,OAAO,CAAC;QAC1D,cAAc,EAAE,0CAAkB;QAClC,UAAU,EAAE,kCAAc;QAC1B,KAAK,CAAC,eAAe,CACnB,OAA4B;YAE5B,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACxB,MAAM,IAAI,mBAAa,CACrB,mBAAa,CAAC,mBAAmB,EACjC,6CAA6C,CAC9C,CAAA;YACH,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAA;YAEzC,MAAM,QAAQ,GAAG,IAAI,sCAAgB,CAAC;gBACpC,MAAM;gBACN,OAAO,EAAE,OAAO,CAAC,OAAO;gBACxB,gBAAgB,EAAE;oBAChB,GAAG,OAAO,CAAC,gBAAgB;iBAC5B;aACF,CAAC,CAAA;YAEF,OAAO,QAAQ,CAAA;QACjB,CAAC;QACD,UAAU,CAAC,OAA4B;YACrC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;QAClC,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { SDKClient, Token, TokenAmount } from '@lifi/sdk';
2
+ export declare const getTronBalance: (client: SDKClient, walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTronBalance = void 0;
4
+ const sdk_1 = require("@lifi/sdk");
5
+ const tronweb_1 = require("tronweb");
6
+ const getTronBalance = async (client, walletAddress, tokens) => {
7
+ if (tokens.length === 0) {
8
+ return [];
9
+ }
10
+ const { chainId } = tokens[0];
11
+ for (const token of tokens) {
12
+ if (token.chainId !== chainId) {
13
+ console.warn('Requested tokens have to be on the same chain.');
14
+ }
15
+ }
16
+ return getTronBalanceDefault(client, tokens, walletAddress);
17
+ };
18
+ exports.getTronBalance = getTronBalance;
19
+ const getTronBalanceDefault = async (client, tokens, walletAddress) => {
20
+ const rpcUrls = await client.getRpcUrlsByChainId(tokens[0].chainId);
21
+ const fullHost = rpcUrls[0] || 'https://api.trongrid.io';
22
+ const tronWeb = new tronweb_1.TronWeb({ fullHost });
23
+ const [trxBalance, currentBlock] = await Promise.allSettled([
24
+ (0, sdk_1.withDedupe)(() => tronWeb.trx.getBalance(walletAddress), {
25
+ id: `${getTronBalanceDefault.name}.getBalance`,
26
+ }),
27
+ (0, sdk_1.withDedupe)(() => tronWeb.trx.getCurrentBlock(), {
28
+ id: `${getTronBalanceDefault.name}.getCurrentBlock`,
29
+ }),
30
+ ]);
31
+ const nativeBalance = trxBalance.status === 'fulfilled' ? BigInt(trxBalance.value) : 0n;
32
+ const blockNumber = currentBlock.status === 'fulfilled'
33
+ ? BigInt(currentBlock.value.block_header?.raw_data?.number ?? 0)
34
+ : 0n;
35
+ const walletTokenAmounts = {};
36
+ const nativeTokens = tokens.filter((token) => token.address === 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb' ||
37
+ token.address === '0x0000000000000000000000000000000000000000');
38
+ const trc20Tokens = tokens.filter((token) => token.address !== 'T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb' &&
39
+ token.address !== '0x0000000000000000000000000000000000000000');
40
+ for (const token of nativeTokens) {
41
+ walletTokenAmounts[token.address] = nativeBalance;
42
+ }
43
+ if (trc20Tokens.length > 0) {
44
+ const trc20Balances = await Promise.allSettled(trc20Tokens.map((token) => (0, sdk_1.withDedupe)(async () => {
45
+ const contract = await tronWeb.contract().at(token.address);
46
+ const balance = await contract.balanceOf(walletAddress).call();
47
+ return {
48
+ address: token.address,
49
+ balance: BigInt(balance.toString()),
50
+ };
51
+ }, {
52
+ id: `${getTronBalanceDefault.name}.balanceOf.${token.address}`,
53
+ })));
54
+ for (const result of trc20Balances) {
55
+ if (result.status === 'fulfilled' && result.value.balance > 0n) {
56
+ walletTokenAmounts[result.value.address] = result.value.balance;
57
+ }
58
+ }
59
+ }
60
+ const tokenAmounts = tokens.map((token) => {
61
+ if (walletTokenAmounts[token.address]) {
62
+ return {
63
+ ...token,
64
+ amount: walletTokenAmounts[token.address],
65
+ blockNumber,
66
+ };
67
+ }
68
+ return {
69
+ ...token,
70
+ blockNumber,
71
+ };
72
+ });
73
+ return tokenAmounts;
74
+ };
75
+ //# sourceMappingURL=getTronBalance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getTronBalance.js","sourceRoot":"","sources":["../../../src/actions/getTronBalance.ts"],"names":[],"mappings":";;;AACA,mCAAsC;AACtC,qCAAiC;AAE1B,MAAM,cAAc,GAAG,KAAK,EACjC,MAAiB,EACjB,aAAqB,EACrB,MAAe,EACS,EAAE;IAC1B,IAAI,MAA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C,QAAQ,EAAE,CAAC;aACpC,CAAA;QACH,CAAC,EACD;YACE,EAAE,EAAE,GAAG,qBAAqB,CAAC,IAAI,cAAc,KAAK,CAAC,OAAO,EAAE;SAC/D,CACF,CACF,CACF,CAAA;QAED,KAAK,MAAM,MAAM,IAAI,aAAa,EAAE,CAAC;YACnC,IAAI,MAAM,CAAC,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,EAAE,CAAC;gBAC/D,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAA;YACjE,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,YAAY,GAAkB,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QACvD,IAAI,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;YACtC,OAAO;gBACL,GAAG,KAAK;gBACR,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,OAAO,CAAC;gBACzC,WAAW;aACZ,CAAA;QACH,CAAC;QACD,OAAO;YACL,GAAG,KAAK;YACR,WAAW;SACZ,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,YAAY,CAAA;AACrB,CAAC,CAAA"}
@@ -0,0 +1 @@
1
+ export declare function resolveTronAddress(_name: string): Promise<string | undefined>;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveTronAddress = resolveTronAddress;
4
+ async function resolveTronAddress(_name) {
5
+ return undefined;
6
+ }
7
+ //# sourceMappingURL=resolveTronAddress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveTronAddress.js","sourceRoot":"","sources":["../../../src/actions/resolveTronAddress.ts"],"names":[],"mappings":";;AAAA,gDAKC;AALM,KAAK,UAAU,kBAAkB,CACtC,KAAa;IAGb,OAAO,SAAS,CAAA;AAClB,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { BaseStepExecutor, type ExecutionAction, type LiFiStepExtended, type SDKError, type StepExecutorBaseContext, TaskPipeline } from '@lifi/sdk';
2
+ import type { TronStepExecutorContext, TronStepExecutorOptions } from '../types.js';
3
+ export declare class TronStepExecutor extends BaseStepExecutor {
4
+ private wallet;
5
+ constructor(options: TronStepExecutorOptions);
6
+ checkWallet: (step: LiFiStepExtended) => void;
7
+ parseErrors: (error: Error, step?: LiFiStepExtended, action?: ExecutionAction) => Promise<SDKError>;
8
+ createContext: (baseContext: StepExecutorBaseContext) => Promise<TronStepExecutorContext>;
9
+ createPipeline: (context: TronStepExecutorContext) => TaskPipeline;
10
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TronStepExecutor = void 0;
4
+ const sdk_1 = require("@lifi/sdk");
5
+ const parseTronErrors_js_1 = require("../errors/parseTronErrors.js");
6
+ const TronSignAndExecuteTask_js_1 = require("./tasks/TronSignAndExecuteTask.js");
7
+ const TronWaitForTransactionTask_js_1 = require("./tasks/TronWaitForTransactionTask.js");
8
+ class TronStepExecutor extends sdk_1.BaseStepExecutor {
9
+ wallet;
10
+ constructor(options) {
11
+ super(options);
12
+ this.wallet = options.wallet;
13
+ }
14
+ checkWallet = (step) => {
15
+ const address = this.wallet.address;
16
+ if (address && address !== step.action.fromAddress) {
17
+ throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.WalletChangedDuringExecution, 'The wallet address that requested the quote does not match the wallet address attempting to sign the transaction.');
18
+ }
19
+ };
20
+ parseErrors = (error, step, action) => (0, parseTronErrors_js_1.parseTronErrors)(error, step, action);
21
+ createContext = async (baseContext) => {
22
+ return {
23
+ ...baseContext,
24
+ wallet: this.wallet,
25
+ checkWallet: this.checkWallet,
26
+ };
27
+ };
28
+ createPipeline = (context) => {
29
+ const { step, isBridgeExecution } = context;
30
+ const tasks = [
31
+ new sdk_1.CheckBalanceTask(),
32
+ new sdk_1.PrepareTransactionTask(),
33
+ new TronSignAndExecuteTask_js_1.TronSignAndExecuteTask(),
34
+ new TronWaitForTransactionTask_js_1.TronWaitForTransactionTask(),
35
+ new sdk_1.WaitForTransactionStatusTask(isBridgeExecution ? 'RECEIVING_CHAIN' : 'SWAP'),
36
+ ];
37
+ const swapOrBridgeAction = this.statusManager.findAction(step, isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP');
38
+ const taskName = swapOrBridgeAction?.txHash && swapOrBridgeAction?.status === 'DONE'
39
+ ? sdk_1.WaitForTransactionStatusTask.name
40
+ : sdk_1.CheckBalanceTask.name;
41
+ const firstTaskIndex = tasks.findIndex((task) => task.constructor.name === taskName);
42
+ const tasksToRun = tasks.slice(firstTaskIndex);
43
+ return new sdk_1.TaskPipeline(tasksToRun);
44
+ };
45
+ }
46
+ exports.TronStepExecutor = TronStepExecutor;
47
+ //# sourceMappingURL=TronStepExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TronStepExecutor.js","sourceRoot":"","sources":["../../../src/core/TronStepExecutor.ts"],"names":[],"mappings":";;;AAAA,mCAYkB;AAElB,qEAA8D;AAK9D,iFAA0E;AAC1E,yFAAkF;AAElF,MAAa,gBAAiB,SAAQ,sBAAgB;IAC5C,MAAM,CAAS;IAEvB,YAAY,OAAgC;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAA;IAC9B,CAAC;IAED,WAAW,GAAG,CAAC,IAAsB,EAAE,EAAE;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAA;QACnC,IAAI,OAAO,IAAI,OAAO,KAAK,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;YACnD,MAAM,IAAI,sBAAgB,CACxB,mBAAa,CAAC,4BAA4B,EAC1C,mHAAmH,CACpH,CAAA;QACH,CAAC;IACH,CAAC,CAAA;IAEQ,WAAW,GAAG,CACrB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iEC"}
@@ -0,0 +1,5 @@
1
+ import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk';
2
+ import type { TronStepExecutorContext } from '../../types.js';
3
+ export declare class TronSignAndExecuteTask extends BaseStepExecutionTask {
4
+ run(context: TronStepExecutorContext): Promise<TaskResult>;
5
+ }
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TronSignAndExecuteTask = void 0;
4
+ const sdk_1 = require("@lifi/sdk");
5
+ class TronSignAndExecuteTask extends sdk_1.BaseStepExecutionTask {
6
+ async run(context) {
7
+ const { step, wallet, statusManager, executionOptions, isBridgeExecution, checkWallet, } = context;
8
+ const action = statusManager.findAction(step, isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP');
9
+ if (!action) {
10
+ throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction. Action not found.');
11
+ }
12
+ const transactionRequestData = await (0, sdk_1.getTransactionRequestData)(step, executionOptions);
13
+ checkWallet(step);
14
+ const unsignedTransaction = JSON.parse(transactionRequestData);
15
+ const signedTransaction = await wallet.signTransaction(unsignedTransaction);
16
+ statusManager.updateAction(step, action.type, 'PENDING', {
17
+ signedAt: Date.now(),
18
+ });
19
+ return {
20
+ status: 'COMPLETED',
21
+ context: { signedTransaction },
22
+ };
23
+ }
24
+ }
25
+ exports.TronSignAndExecuteTask = TronSignAndExecuteTask;
26
+ //# sourceMappingURL=TronSignAndExecuteTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TronSignAndExecuteTask.js","sourceRoot":"","sources":["../../../../src/core/tasks/TronSignAndExecuteTask.ts"],"names":[],"mappings":";;;AAAA,mCAMkB;AAGlB,MAAa,sBAAuB,SAAQ,2BAAqB;IAC/D,KAAK,CAAC,GAAG,CAAC,OAAgC;QACxC,MAAM,EACJ,IAAI,EACJ,MAAM,EACN,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,GACZ,GAAG,OAAO,CAAA;QAEX,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,CACrC,IAAI,EACJ,iBAAiB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAC3C,CAAA;QAED,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,sBAAgB,CACxB,mBAAa,CAAC,qBAAqB,EACnC,kDAAkD,CACnD,CAAA;QACH,CAAC;QAED,MAAM,sBAAsB,GAAG,MAAM,IAAA,+BAAyB,EAC5D,IAAI,EACJ,gBAAgB,CACjB,CAAA;QAED,WAAW,CAAC,IAAI,CAAC,CAAA;QAEjB,MAAM,mBAAmB,GAAG,IAAI,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAA;QAE9D,MAAM,iBAAiB,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,mBAAmB,CAAC,CAAA;QAE3E,aAAa,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE;YACvD,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE;SACrB,CAAC,CAAA;QAEF,OAAO;YACL,MAAM,EAAE,WAAW;YACnB,OAAO,EAAE,EAAE,iBAAiB,EAAE;SAC/B,CAAA;IACH,CAAC;CACF;AA3CD,wDA2CC"}
@@ -0,0 +1,5 @@
1
+ import { BaseStepExecutionTask, type TaskResult } from '@lifi/sdk';
2
+ import type { TronStepExecutorContext } from '../../types.js';
3
+ export declare class TronWaitForTransactionTask extends BaseStepExecutionTask {
4
+ run(context: TronStepExecutorContext): Promise<TaskResult>;
5
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TronWaitForTransactionTask = void 0;
4
+ const sdk_1 = require("@lifi/sdk");
5
+ const tronweb_1 = require("tronweb");
6
+ class TronWaitForTransactionTask extends sdk_1.BaseStepExecutionTask {
7
+ async run(context) {
8
+ const { client, step, statusManager, fromChain, isBridgeExecution, signedTransaction, } = context;
9
+ if (!signedTransaction) {
10
+ throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction. Signed transaction is not found.');
11
+ }
12
+ const action = statusManager.findAction(step, isBridgeExecution ? 'CROSS_CHAIN' : 'SWAP');
13
+ if (!action) {
14
+ throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionUnprepared, 'Unable to prepare transaction. Action not found.');
15
+ }
16
+ const rpcUrls = await client.getRpcUrlsByChainId(fromChain.id);
17
+ const fullHost = rpcUrls[0] || 'https://api.trongrid.io';
18
+ const tronWeb = new tronweb_1.TronWeb({ fullHost });
19
+ const broadcastResult = await tronWeb.trx.sendRawTransaction(signedTransaction);
20
+ if (!broadcastResult.result) {
21
+ throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionFailed, `Transaction broadcast failed: ${broadcastResult.code || 'Unknown error'}`);
22
+ }
23
+ const txHash = broadcastResult.transaction.txID;
24
+ statusManager.updateAction(step, action.type, 'PENDING', {
25
+ txHash,
26
+ txLink: `${fromChain.metamask.blockExplorerUrls[0]}#/transaction/${txHash}`,
27
+ });
28
+ await waitForTronConfirmation(tronWeb, txHash);
29
+ if (isBridgeExecution) {
30
+ statusManager.updateAction(step, action.type, 'DONE');
31
+ }
32
+ return { status: 'COMPLETED' };
33
+ }
34
+ }
35
+ exports.TronWaitForTransactionTask = TronWaitForTransactionTask;
36
+ async function waitForTronConfirmation(tronWeb, txHash, maxRetries = 20, intervalMs = 3000) {
37
+ for (let i = 0; i < maxRetries; i++) {
38
+ try {
39
+ const txInfo = await tronWeb.trx.getTransactionInfo(txHash);
40
+ if (txInfo?.id) {
41
+ if (txInfo.receipt?.result === 'FAILED') {
42
+ throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionFailed, `Transaction failed on-chain: ${txInfo.receipt.result}`);
43
+ }
44
+ return;
45
+ }
46
+ }
47
+ catch (error) {
48
+ if (error instanceof sdk_1.TransactionError) {
49
+ throw error;
50
+ }
51
+ }
52
+ await new Promise((resolve) => setTimeout(resolve, intervalMs));
53
+ }
54
+ throw new sdk_1.TransactionError(sdk_1.LiFiErrorCode.TransactionFailed, 'Transaction confirmation timeout.');
55
+ }
56
+ //# sourceMappingURL=TronWaitForTransactionTask.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TronWaitForTransactionTask.js","sourceRoot":"","sources":["../../../../src/core/tasks/TronWaitForTransactionTask.ts"],"names":[],"mappings":";;;AAAA,mCAKkB;AAClB,qCAAiC;AAGjC,MAAa,0BAA2B,SAAQ,2BAAqB;IACnE,KAAK,CAAC,GAAG,CAAC,OAAgC;QACxC,MAAM,EACJ,MAAM,EACN,IAAI,EACJ,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,iBAAiB,GAClB,GAAG,OAAO,CAAA;QAEX,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACvB,MAAM,IAAI,sBAAgB,CACxB,mBAAa,CAAC,qBAAqB,EACnC,iEAAiE,CAClE,CAAA;QACH,CAAC;QAED,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,CACrC,IAAI,EACJ,iBAAiB,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,MAAM,CAC3C,CAAA;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,sBAAgB,CACxB,mBAAa,CAAC,qBAAqB,EACnC,kDAAkD,CACnD,CAAA;QACH,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,yBAAyB,CAAA;QACxD,MAAM,OAAO,GAAG,IAAI,iBAAO,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAA;QAEzC,MAAM,eAAe,GACnB,MAAM,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC,iBAAiB,CAAC,CAAA;QAE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H,CAAC;gBACD,OAAM;YACR,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,sBAAgB,EAAE,CAAC;gBACtC,MAAM,KAAK,CAAA;YACb,CAAC;QAEH,CAAC;QACD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAA;IACjE,CAAC;IAED,MAAM,IAAI,sBAAgB,CACxB,mBAAa,CAAC,iBAAiB,EAC/B,mCAAmC,CACpC,CAAA;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { type ExecutionAction, type LiFiStep, SDKError } from '@lifi/sdk';
2
+ export declare const parseTronErrors: (e: Error, step?: LiFiStep, action?: ExecutionAction) => Promise<SDKError>;