@ledgerhq/coin-tron 0.0.1

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 (351) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +25 -0
  4. package/LICENSE.txt +21 -0
  5. package/jest.config.js +8 -0
  6. package/jest.integ.config.js +7 -0
  7. package/lib/bridge/broadcast.d.ts +7 -0
  8. package/lib/bridge/broadcast.d.ts.map +1 -0
  9. package/lib/bridge/broadcast.js +26 -0
  10. package/lib/bridge/broadcast.js.map +1 -0
  11. package/lib/bridge/buildOptimisticOperation.d.ts +5 -0
  12. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  13. package/lib/bridge/buildOptimisticOperation.js +101 -0
  14. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  15. package/lib/bridge/createTransaction.d.ts +4 -0
  16. package/lib/bridge/createTransaction.d.ts.map +1 -0
  17. package/lib/bridge/createTransaction.js +19 -0
  18. package/lib/bridge/createTransaction.js.map +1 -0
  19. package/lib/bridge/deviceTransactionConfig.d.ts +20 -0
  20. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  21. package/lib/bridge/deviceTransactionConfig.js +65 -0
  22. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  23. package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
  24. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  25. package/lib/bridge/estimateMaxSpendable.js +30 -0
  26. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  27. package/lib/bridge/getEstimateFees.d.ts +6 -0
  28. package/lib/bridge/getEstimateFees.d.ts.map +1 -0
  29. package/lib/bridge/getEstimateFees.js +52 -0
  30. package/lib/bridge/getEstimateFees.js.map +1 -0
  31. package/lib/bridge/getTransactionStatus.d.ts +4 -0
  32. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  33. package/lib/bridge/getTransactionStatus.js +218 -0
  34. package/lib/bridge/getTransactionStatus.js.map +1 -0
  35. package/lib/bridge/index.d.ts +10 -0
  36. package/lib/bridge/index.d.ts.map +1 -0
  37. package/lib/bridge/index.js +60 -0
  38. package/lib/bridge/index.js.map +1 -0
  39. package/lib/bridge/preload.d.ts +8 -0
  40. package/lib/bridge/preload.d.ts.map +1 -0
  41. package/lib/bridge/preload.js +32 -0
  42. package/lib/bridge/preload.js.map +1 -0
  43. package/lib/bridge/prepareTransaction.d.ts +4 -0
  44. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  45. package/lib/bridge/prepareTransaction.js +19 -0
  46. package/lib/bridge/prepareTransaction.js.map +1 -0
  47. package/lib/bridge/serialization.d.ts +9 -0
  48. package/lib/bridge/serialization.d.ts.map +1 -0
  49. package/lib/bridge/serialization.js +238 -0
  50. package/lib/bridge/serialization.js.map +1 -0
  51. package/lib/bridge/signOperation.d.ts +5 -0
  52. package/lib/bridge/signOperation.d.ts.map +1 -0
  53. package/lib/bridge/signOperation.js +92 -0
  54. package/lib/bridge/signOperation.js.map +1 -0
  55. package/lib/bridge/synchronization.d.ts +5 -0
  56. package/lib/bridge/synchronization.d.ts.map +1 -0
  57. package/lib/bridge/synchronization.integ.test.d.ts +3 -0
  58. package/lib/bridge/synchronization.integ.test.d.ts.map +1 -0
  59. package/lib/bridge/synchronization.integ.test.js +96 -0
  60. package/lib/bridge/synchronization.integ.test.js.map +1 -0
  61. package/lib/bridge/synchronization.js +216 -0
  62. package/lib/bridge/synchronization.js.map +1 -0
  63. package/lib/bridge/transaction.d.ts +15 -0
  64. package/lib/bridge/transaction.d.ts.map +1 -0
  65. package/lib/bridge/transaction.js +61 -0
  66. package/lib/bridge/transaction.js.map +1 -0
  67. package/lib/config.d.ts +10 -0
  68. package/lib/config.d.ts.map +1 -0
  69. package/lib/config.js +17 -0
  70. package/lib/config.js.map +1 -0
  71. package/lib/index.d.ts +3 -0
  72. package/lib/index.d.ts.map +1 -0
  73. package/lib/index.js +21 -0
  74. package/lib/index.js.map +1 -0
  75. package/lib/logic/constants.d.ts +4 -0
  76. package/lib/logic/constants.d.ts.map +1 -0
  77. package/lib/logic/constants.js +7 -0
  78. package/lib/logic/constants.js.map +1 -0
  79. package/lib/logic/pagination.d.ts +3 -0
  80. package/lib/logic/pagination.d.ts.map +1 -0
  81. package/lib/logic/pagination.js +19 -0
  82. package/lib/logic/pagination.js.map +1 -0
  83. package/lib/logic/utils.d.ts +12 -0
  84. package/lib/logic/utils.d.ts.map +1 -0
  85. package/lib/logic/utils.js +177 -0
  86. package/lib/logic/utils.js.map +1 -0
  87. package/lib/network/format.d.ts +9 -0
  88. package/lib/network/format.d.ts.map +1 -0
  89. package/lib/network/format.js +127 -0
  90. package/lib/network/format.js.map +1 -0
  91. package/lib/network/index.d.ts +30 -0
  92. package/lib/network/index.d.ts.map +1 -0
  93. package/lib/network/index.integ.test.d.ts +2 -0
  94. package/lib/network/index.integ.test.d.ts.map +1 -0
  95. package/lib/network/index.integ.test.js +38 -0
  96. package/lib/network/index.integ.test.js.map +1 -0
  97. package/lib/network/index.js +555 -0
  98. package/lib/network/index.js.map +1 -0
  99. package/lib/network/index.test.d.ts +2 -0
  100. package/lib/network/index.test.d.ts.map +1 -0
  101. package/lib/network/index.test.js +66 -0
  102. package/lib/network/index.test.js.map +1 -0
  103. package/lib/network/superRepresentativesData.mock.d.ts +69 -0
  104. package/lib/network/superRepresentativesData.mock.d.ts.map +1 -0
  105. package/lib/network/superRepresentativesData.mock.js +2208 -0
  106. package/lib/network/superRepresentativesData.mock.js.map +1 -0
  107. package/lib/network/types.d.ts +122 -0
  108. package/lib/network/types.d.ts.map +1 -0
  109. package/lib/network/types.fixture.d.ts +498 -0
  110. package/lib/network/types.fixture.d.ts.map +1 -0
  111. package/lib/network/types.fixture.js +4375 -0
  112. package/lib/network/types.fixture.js.map +1 -0
  113. package/lib/network/types.js +13 -0
  114. package/lib/network/types.js.map +1 -0
  115. package/lib/signer/getAddress.d.ts +6 -0
  116. package/lib/signer/getAddress.d.ts.map +1 -0
  117. package/lib/signer/getAddress.js +19 -0
  118. package/lib/signer/getAddress.js.map +1 -0
  119. package/lib/signer/index.d.ts +6 -0
  120. package/lib/signer/index.d.ts.map +1 -0
  121. package/lib/signer/index.js +11 -0
  122. package/lib/signer/index.js.map +1 -0
  123. package/lib/test/bot-deviceActions.d.ts +4 -0
  124. package/lib/test/bot-deviceActions.d.ts.map +1 -0
  125. package/lib/test/bot-deviceActions.js +103 -0
  126. package/lib/test/bot-deviceActions.js.map +1 -0
  127. package/lib/test/bot-specs.d.ts +7 -0
  128. package/lib/test/bot-specs.d.ts.map +1 -0
  129. package/lib/test/bot-specs.js +433 -0
  130. package/lib/test/bot-specs.js.map +1 -0
  131. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  132. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  133. package/lib/test/bridgeDatasetTest.js +1284 -0
  134. package/lib/test/bridgeDatasetTest.js.map +1 -0
  135. package/lib/test/cli.d.ts +52 -0
  136. package/lib/test/cli.d.ts.map +1 -0
  137. package/lib/test/cli.js +155 -0
  138. package/lib/test/cli.js.map +1 -0
  139. package/lib/test/index.d.ts +6 -0
  140. package/lib/test/index.d.ts.map +1 -0
  141. package/lib/test/index.js +26 -0
  142. package/lib/test/index.js.map +1 -0
  143. package/lib/types/bridge.d.ts +245 -0
  144. package/lib/types/bridge.d.ts.map +1 -0
  145. package/lib/types/bridge.js +16 -0
  146. package/lib/types/bridge.js.map +1 -0
  147. package/lib/types/errors.d.ts +49 -0
  148. package/lib/types/errors.d.ts.map +1 -0
  149. package/lib/types/errors.js +21 -0
  150. package/lib/types/errors.js.map +1 -0
  151. package/lib/types/index.d.ts +4 -0
  152. package/lib/types/index.d.ts.map +1 -0
  153. package/lib/types/index.js +21 -0
  154. package/lib/types/index.js.map +1 -0
  155. package/lib/types/signer.d.ts +10 -0
  156. package/lib/types/signer.d.ts.map +1 -0
  157. package/lib/types/signer.js +3 -0
  158. package/lib/types/signer.js.map +1 -0
  159. package/lib-es/bridge/broadcast.d.ts +7 -0
  160. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  161. package/lib-es/bridge/broadcast.js +24 -0
  162. package/lib-es/bridge/broadcast.js.map +1 -0
  163. package/lib-es/bridge/buildOptimisticOperation.d.ts +5 -0
  164. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  165. package/lib-es/bridge/buildOptimisticOperation.js +94 -0
  166. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  167. package/lib-es/bridge/createTransaction.d.ts +4 -0
  168. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  169. package/lib-es/bridge/createTransaction.js +14 -0
  170. package/lib-es/bridge/createTransaction.js.map +1 -0
  171. package/lib-es/bridge/deviceTransactionConfig.d.ts +20 -0
  172. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  173. package/lib-es/bridge/deviceTransactionConfig.js +63 -0
  174. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  175. package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
  176. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  177. package/lib-es/bridge/estimateMaxSpendable.js +25 -0
  178. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  179. package/lib-es/bridge/getEstimateFees.d.ts +6 -0
  180. package/lib-es/bridge/getEstimateFees.d.ts.map +1 -0
  181. package/lib-es/bridge/getEstimateFees.js +47 -0
  182. package/lib-es/bridge/getEstimateFees.js.map +1 -0
  183. package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
  184. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  185. package/lib-es/bridge/getTransactionStatus.js +213 -0
  186. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  187. package/lib-es/bridge/index.d.ts +10 -0
  188. package/lib-es/bridge/index.d.ts.map +1 -0
  189. package/lib-es/bridge/index.js +53 -0
  190. package/lib-es/bridge/index.js.map +1 -0
  191. package/lib-es/bridge/preload.d.ts +8 -0
  192. package/lib-es/bridge/preload.d.ts.map +1 -0
  193. package/lib-es/bridge/preload.js +27 -0
  194. package/lib-es/bridge/preload.js.map +1 -0
  195. package/lib-es/bridge/prepareTransaction.d.ts +4 -0
  196. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  197. package/lib-es/bridge/prepareTransaction.js +15 -0
  198. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  199. package/lib-es/bridge/serialization.d.ts +9 -0
  200. package/lib-es/bridge/serialization.d.ts.map +1 -0
  201. package/lib-es/bridge/serialization.js +229 -0
  202. package/lib-es/bridge/serialization.js.map +1 -0
  203. package/lib-es/bridge/signOperation.d.ts +5 -0
  204. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  205. package/lib-es/bridge/signOperation.js +85 -0
  206. package/lib-es/bridge/signOperation.js.map +1 -0
  207. package/lib-es/bridge/synchronization.d.ts +5 -0
  208. package/lib-es/bridge/synchronization.d.ts.map +1 -0
  209. package/lib-es/bridge/synchronization.integ.test.d.ts +3 -0
  210. package/lib-es/bridge/synchronization.integ.test.d.ts.map +1 -0
  211. package/lib-es/bridge/synchronization.integ.test.js +89 -0
  212. package/lib-es/bridge/synchronization.integ.test.js.map +1 -0
  213. package/lib-es/bridge/synchronization.js +209 -0
  214. package/lib-es/bridge/synchronization.js.map +1 -0
  215. package/lib-es/bridge/transaction.d.ts +15 -0
  216. package/lib-es/bridge/transaction.d.ts.map +1 -0
  217. package/lib-es/bridge/transaction.js +55 -0
  218. package/lib-es/bridge/transaction.js.map +1 -0
  219. package/lib-es/config.d.ts +10 -0
  220. package/lib-es/config.d.ts.map +1 -0
  221. package/lib-es/config.js +12 -0
  222. package/lib-es/config.js.map +1 -0
  223. package/lib-es/index.d.ts +3 -0
  224. package/lib-es/index.d.ts.map +1 -0
  225. package/lib-es/index.js +3 -0
  226. package/lib-es/index.js.map +1 -0
  227. package/lib-es/logic/constants.d.ts +4 -0
  228. package/lib-es/logic/constants.d.ts.map +1 -0
  229. package/lib-es/logic/constants.js +4 -0
  230. package/lib-es/logic/constants.js.map +1 -0
  231. package/lib-es/logic/pagination.d.ts +3 -0
  232. package/lib-es/logic/pagination.d.ts.map +1 -0
  233. package/lib-es/logic/pagination.js +15 -0
  234. package/lib-es/logic/pagination.js.map +1 -0
  235. package/lib-es/logic/utils.d.ts +12 -0
  236. package/lib-es/logic/utils.d.ts.map +1 -0
  237. package/lib-es/logic/utils.js +167 -0
  238. package/lib-es/logic/utils.js.map +1 -0
  239. package/lib-es/network/format.d.ts +9 -0
  240. package/lib-es/network/format.d.ts.map +1 -0
  241. package/lib-es/network/format.js +117 -0
  242. package/lib-es/network/format.js.map +1 -0
  243. package/lib-es/network/index.d.ts +30 -0
  244. package/lib-es/network/index.d.ts.map +1 -0
  245. package/lib-es/network/index.integ.test.d.ts +2 -0
  246. package/lib-es/network/index.integ.test.d.ts.map +1 -0
  247. package/lib-es/network/index.integ.test.js +36 -0
  248. package/lib-es/network/index.integ.test.js.map +1 -0
  249. package/lib-es/network/index.js +524 -0
  250. package/lib-es/network/index.js.map +1 -0
  251. package/lib-es/network/index.test.d.ts +2 -0
  252. package/lib-es/network/index.test.d.ts.map +1 -0
  253. package/lib-es/network/index.test.js +63 -0
  254. package/lib-es/network/index.test.js.map +1 -0
  255. package/lib-es/network/superRepresentativesData.mock.d.ts +69 -0
  256. package/lib-es/network/superRepresentativesData.mock.d.ts.map +1 -0
  257. package/lib-es/network/superRepresentativesData.mock.js +2206 -0
  258. package/lib-es/network/superRepresentativesData.mock.js.map +1 -0
  259. package/lib-es/network/types.d.ts +122 -0
  260. package/lib-es/network/types.d.ts.map +1 -0
  261. package/lib-es/network/types.fixture.d.ts +498 -0
  262. package/lib-es/network/types.fixture.d.ts.map +1 -0
  263. package/lib-es/network/types.fixture.js +4371 -0
  264. package/lib-es/network/types.fixture.js.map +1 -0
  265. package/lib-es/network/types.js +8 -0
  266. package/lib-es/network/types.js.map +1 -0
  267. package/lib-es/signer/getAddress.d.ts +6 -0
  268. package/lib-es/signer/getAddress.d.ts.map +1 -0
  269. package/lib-es/signer/getAddress.js +17 -0
  270. package/lib-es/signer/getAddress.js.map +1 -0
  271. package/lib-es/signer/index.d.ts +6 -0
  272. package/lib-es/signer/index.d.ts.map +1 -0
  273. package/lib-es/signer/index.js +6 -0
  274. package/lib-es/signer/index.js.map +1 -0
  275. package/lib-es/test/bot-deviceActions.d.ts +4 -0
  276. package/lib-es/test/bot-deviceActions.d.ts.map +1 -0
  277. package/lib-es/test/bot-deviceActions.js +100 -0
  278. package/lib-es/test/bot-deviceActions.js.map +1 -0
  279. package/lib-es/test/bot-specs.d.ts +7 -0
  280. package/lib-es/test/bot-specs.d.ts.map +1 -0
  281. package/lib-es/test/bot-specs.js +428 -0
  282. package/lib-es/test/bot-specs.js.map +1 -0
  283. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  284. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  285. package/lib-es/test/bridgeDatasetTest.js +1278 -0
  286. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  287. package/lib-es/test/cli.d.ts +52 -0
  288. package/lib-es/test/cli.d.ts.map +1 -0
  289. package/lib-es/test/cli.js +149 -0
  290. package/lib-es/test/cli.js.map +1 -0
  291. package/lib-es/test/index.d.ts +6 -0
  292. package/lib-es/test/index.d.ts.map +1 -0
  293. package/lib-es/test/index.js +6 -0
  294. package/lib-es/test/index.js.map +1 -0
  295. package/lib-es/types/bridge.d.ts +245 -0
  296. package/lib-es/types/bridge.d.ts.map +1 -0
  297. package/lib-es/types/bridge.js +11 -0
  298. package/lib-es/types/bridge.js.map +1 -0
  299. package/lib-es/types/errors.d.ts +49 -0
  300. package/lib-es/types/errors.d.ts.map +1 -0
  301. package/lib-es/types/errors.js +18 -0
  302. package/lib-es/types/errors.js.map +1 -0
  303. package/lib-es/types/index.d.ts +4 -0
  304. package/lib-es/types/index.d.ts.map +1 -0
  305. package/lib-es/types/index.js +5 -0
  306. package/lib-es/types/index.js.map +1 -0
  307. package/lib-es/types/signer.d.ts +10 -0
  308. package/lib-es/types/signer.d.ts.map +1 -0
  309. package/lib-es/types/signer.js +2 -0
  310. package/lib-es/types/signer.js.map +1 -0
  311. package/package.json +133 -0
  312. package/src/bridge/broadcast.ts +24 -0
  313. package/src/bridge/buildOptimisticOperation.ts +133 -0
  314. package/src/bridge/createTransaction.ts +16 -0
  315. package/src/bridge/deviceTransactionConfig.ts +99 -0
  316. package/src/bridge/estimateMaxSpendable.ts +32 -0
  317. package/src/bridge/getEstimateFees.ts +52 -0
  318. package/src/bridge/getTransactionStatus.ts +263 -0
  319. package/src/bridge/index.ts +78 -0
  320. package/src/bridge/preload.ts +24 -0
  321. package/src/bridge/prepareTransaction.ts +12 -0
  322. package/src/bridge/serialization.ts +288 -0
  323. package/src/bridge/signOperation.ts +123 -0
  324. package/src/bridge/synchronization.integ.test.ts +105 -0
  325. package/src/bridge/synchronization.ts +284 -0
  326. package/src/bridge/transaction.ts +84 -0
  327. package/src/config.ts +24 -0
  328. package/src/index.ts +3 -0
  329. package/src/logic/constants.ts +4 -0
  330. package/src/logic/pagination.ts +21 -0
  331. package/src/logic/utils.ts +231 -0
  332. package/src/network/format.ts +148 -0
  333. package/src/network/index.integ.test.ts +33 -0
  334. package/src/network/index.test.ts +61 -0
  335. package/src/network/index.ts +747 -0
  336. package/src/network/superRepresentativesData.mock.ts +2205 -0
  337. package/src/network/types.fixture.ts +4476 -0
  338. package/src/network/types.ts +147 -0
  339. package/src/signer/getAddress.ts +13 -0
  340. package/src/signer/index.ts +7 -0
  341. package/src/test/bot-deviceActions.ts +121 -0
  342. package/src/test/bot-specs.ts +457 -0
  343. package/src/test/bridgeDatasetTest.ts +1343 -0
  344. package/src/test/cli.ts +219 -0
  345. package/src/test/index.ts +6 -0
  346. package/src/types/bridge.ts +304 -0
  347. package/src/types/errors.ts +22 -0
  348. package/src/types/index.ts +4 -0
  349. package/src/types/signer.ts +9 -0
  350. package/tsconfig.json +14 -0
  351. package/types/tronweb/index.d.ts +5 -0
@@ -0,0 +1,263 @@
1
+ import { getAccountCurrency } from "@ledgerhq/coin-framework/account";
2
+ import {
3
+ AmountRequired,
4
+ InvalidAddress,
5
+ InvalidAddressBecauseDestinationIsAlsoSource,
6
+ NotEnoughBalance,
7
+ RecipientRequired,
8
+ } from "@ledgerhq/errors";
9
+ import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
10
+ import BigNumber from "bignumber.js";
11
+ import sumBy from "lodash/sumBy";
12
+ import { ONE_TRX } from "../logic/constants";
13
+ import {
14
+ fetchTronAccount,
15
+ fetchTronContract,
16
+ getContractUserEnergyRatioConsumption,
17
+ getDelegatedResource,
18
+ getTronSuperRepresentatives,
19
+ validateAddress,
20
+ } from "../network";
21
+ import { Transaction, TransactionStatus, TronAccount } from "../types";
22
+ import {
23
+ TronInvalidFreezeAmount,
24
+ TronInvalidUnDelegateResourceAmount,
25
+ TronInvalidVoteCount,
26
+ TronLegacyUnfreezeNotExpired,
27
+ TronNoFrozenForBandwidth,
28
+ TronNoFrozenForEnergy,
29
+ TronNoReward,
30
+ TronNotEnoughEnergy,
31
+ TronNotEnoughTronPower,
32
+ TronNoUnfrozenResource,
33
+ TronRewardNotAvailable,
34
+ TronSendTrc20ToNewAccountForbidden,
35
+ TronUnexpectedFees,
36
+ TronUnfreezeNotExpired,
37
+ TronVoteRequired,
38
+ } from "../types/errors";
39
+ import getEstimatedFees from "./getEstimateFees";
40
+
41
+ const getTransactionStatus = async (
42
+ acc: TronAccount,
43
+ transaction: Transaction,
44
+ ): Promise<TransactionStatus> => {
45
+ const errors: Record<string, Error> = {};
46
+ const warnings: Record<string, Error> = {};
47
+ const { family, mode, recipient, resource, votes, useAllAmount = false } = transaction;
48
+ const tokenAccount = !transaction.subAccountId
49
+ ? null
50
+ : acc.subAccounts && acc.subAccounts.find(ta => ta.id === transaction.subAccountId);
51
+ const account = tokenAccount || acc;
52
+ const isContractAddressRecipient = (await fetchTronContract(recipient)) !== undefined;
53
+
54
+ if (mode === "send" && !recipient) {
55
+ errors.recipient = new RecipientRequired();
56
+ }
57
+
58
+ if (["send", "unDelegateResource", "legacyUnfreeze"].includes(mode)) {
59
+ if (recipient === acc.freshAddress) {
60
+ errors.recipient = new InvalidAddressBecauseDestinationIsAlsoSource();
61
+ } else if (recipient && !(await validateAddress(recipient))) {
62
+ errors.recipient = new InvalidAddress(undefined, {
63
+ currencyName: acc.currency.name,
64
+ });
65
+ } else if (
66
+ recipient &&
67
+ mode === "send" &&
68
+ account.type === "TokenAccount" &&
69
+ account.token.tokenType === "trc20" &&
70
+ !isContractAddressRecipient && // send trc20 to a smart contract is allowed
71
+ (await fetchTronAccount(recipient)).length === 0
72
+ ) {
73
+ // send trc20 to a new account is forbidden by us (because it will not activate the account)
74
+ errors.recipient = new TronSendTrc20ToNewAccountForbidden();
75
+ }
76
+ }
77
+
78
+ if (mode === "unfreeze") {
79
+ const { bandwidth, energy } = acc.tronResources.frozen;
80
+ if (resource === "BANDWIDTH" && transaction.amount.gt(bandwidth?.amount || new BigNumber(0))) {
81
+ errors.resource = new TronNoFrozenForBandwidth();
82
+ } else if (resource === "ENERGY" && transaction.amount.gt(energy?.amount || new BigNumber(0))) {
83
+ errors.resource = new TronNoFrozenForEnergy();
84
+ }
85
+ }
86
+
87
+ if (mode === "legacyUnfreeze") {
88
+ const now = new Date();
89
+ const expirationDate =
90
+ resource === "ENERGY"
91
+ ? acc.tronResources.legacyFrozen.energy?.expiredAt
92
+ : acc.tronResources.legacyFrozen.bandwidth?.expiredAt;
93
+
94
+ if (!expirationDate) {
95
+ if (resource === "BANDWIDTH") {
96
+ errors.resource = new TronNoFrozenForBandwidth();
97
+ } else {
98
+ errors.resource = new TronNoFrozenForEnergy();
99
+ }
100
+ } else if (now.getTime() < expirationDate.getTime()) {
101
+ errors.resource = new TronLegacyUnfreezeNotExpired();
102
+ }
103
+ }
104
+
105
+ if (mode === "withdrawExpireUnfreeze") {
106
+ const now = new Date();
107
+ if (
108
+ (!acc.tronResources.unFrozen.bandwidth ||
109
+ acc.tronResources.unFrozen.bandwidth.length === 0) &&
110
+ (!acc.tronResources.unFrozen.energy || acc.tronResources.unFrozen.energy.length === 0)
111
+ ) {
112
+ errors.resource = new TronNoUnfrozenResource();
113
+ } else {
114
+ const unfreezingResources = [
115
+ ...(acc.tronResources.unFrozen.bandwidth ?? []),
116
+ ...(acc.tronResources.unFrozen.energy ?? []),
117
+ ];
118
+
119
+ const hasNoExpiredResource = !unfreezingResources.some(
120
+ unfrozen => unfrozen.expireTime.getTime() <= now.getTime(),
121
+ );
122
+
123
+ if (hasNoExpiredResource) {
124
+ const closestExpireTime = unfreezingResources.reduce((closest, current) => {
125
+ if (!closest) {
126
+ return current;
127
+ }
128
+ const closestTimeDifference = Math.abs(closest.expireTime.getTime() - now.getTime());
129
+ const currentTimeDifference = Math.abs(current.expireTime.getTime() - now.getTime());
130
+
131
+ return currentTimeDifference < closestTimeDifference ? current : closest;
132
+ });
133
+ errors.resource = new TronUnfreezeNotExpired(undefined, {
134
+ time: closestExpireTime.expireTime.toISOString(),
135
+ });
136
+ }
137
+ }
138
+ }
139
+
140
+ if (mode === "unDelegateResource" && resource && acc.tronResources) {
141
+ const delegatedResourceAmount = await getDelegatedResource(acc, transaction, resource);
142
+ if (delegatedResourceAmount.lt(transaction.amount)) {
143
+ errors.resource = new TronInvalidUnDelegateResourceAmount();
144
+ }
145
+ }
146
+
147
+ if (mode === "vote") {
148
+ if (votes.length === 0) {
149
+ errors.vote = new TronVoteRequired();
150
+ } else {
151
+ const superRepresentatives = await getTronSuperRepresentatives();
152
+ const isValidVoteCounts = votes.every(v => v.voteCount > 0);
153
+ const isValidAddresses = votes.every(v =>
154
+ superRepresentatives.some(s => s.address === v.address),
155
+ );
156
+
157
+ if (!isValidAddresses) {
158
+ errors.vote = new InvalidAddress("", {
159
+ currencyName: acc.currency.name,
160
+ });
161
+ } else if (!isValidVoteCounts) {
162
+ errors.vote = new TronInvalidVoteCount();
163
+ } else {
164
+ const totalVoteCount = sumBy(votes, "voteCount");
165
+ const tronPower = (acc.tronResources && acc.tronResources.tronPower) || 0;
166
+
167
+ if (totalVoteCount > tronPower) {
168
+ errors.vote = new TronNotEnoughTronPower();
169
+ }
170
+ }
171
+ }
172
+ }
173
+
174
+ if (mode === "claimReward") {
175
+ const lastRewardOp = account.operations.find(o => o.type === "REWARD");
176
+ const claimableRewardDate = lastRewardOp
177
+ ? new Date(lastRewardOp.date.getTime() + 24 * 60 * 60 * 1000) // date + 24 hours
178
+ : new Date();
179
+
180
+ if (acc.tronResources && acc.tronResources.unwithdrawnReward.eq(0)) {
181
+ errors.reward = new TronNoReward();
182
+ } else if (lastRewardOp && claimableRewardDate.valueOf() > new Date().valueOf()) {
183
+ errors.reward = new TronRewardNotAvailable("Reward is not claimable", {
184
+ until: claimableRewardDate.toISOString(),
185
+ });
186
+ }
187
+ }
188
+
189
+ const estimatedFees =
190
+ Object.entries(errors).length > 0
191
+ ? new BigNumber(0)
192
+ : await getEstimatedFees(acc, transaction, isContractAddressRecipient);
193
+ const balance =
194
+ account.type === "Account"
195
+ ? BigNumber.max(0, account.spendableBalance.minus(estimatedFees))
196
+ : account.balance;
197
+ const amount = useAllAmount ? balance : transaction.amount;
198
+ const amountSpent = ["send", "freeze", "undelegateResource"].includes(mode)
199
+ ? amount
200
+ : new BigNumber(0);
201
+
202
+ if (mode === "freeze" && amount.lt(ONE_TRX)) {
203
+ errors.amount = new TronInvalidFreezeAmount();
204
+ }
205
+
206
+ // fees are applied in the parent only (TRX)
207
+ const totalSpent = account.type === "Account" ? amountSpent.plus(estimatedFees) : amountSpent;
208
+
209
+ if (["send", "freeze"].includes(mode)) {
210
+ if (amount.eq(0)) {
211
+ errors.amount = new AmountRequired();
212
+ }
213
+ if (amountSpent.eq(0)) {
214
+ errors.amount = useAllAmount ? new NotEnoughBalance() : new AmountRequired();
215
+ } else if (amount.gt(balance)) {
216
+ errors.amount = new NotEnoughBalance();
217
+ } else if (account.type === "TokenAccount" && estimatedFees.gt(acc.balance)) {
218
+ errors.amount = new NotEnoughBalance();
219
+ }
220
+
221
+ const energy = (acc.tronResources && acc.tronResources.energy) || new BigNumber(0);
222
+
223
+ // For the moment, we rely on this rule:
224
+ // Add a 'TronNotEnoughEnergy' warning only if the account sastifies theses 3 conditions:
225
+ // - no energy
226
+ // - balance is lower than 1 TRX
227
+ // - contract consumes user energy (ie: user's ratio > 0%)
228
+ if (
229
+ account.type === "TokenAccount" &&
230
+ account.token.tokenType === "trc20" &&
231
+ energy.lt(47619) // temporary value corresponding to usdt trc20 energy
232
+ ) {
233
+ const contractUserEnergyConsumption = await getContractUserEnergyRatioConsumption(
234
+ account.token.contractAddress,
235
+ );
236
+
237
+ if (contractUserEnergyConsumption > 0) {
238
+ warnings.amount = new TronNotEnoughEnergy();
239
+ }
240
+ }
241
+ }
242
+
243
+ if (!errors.recipient && estimatedFees.gt(0)) {
244
+ const fees = formatCurrencyUnit(getAccountCurrency(acc).units[0], estimatedFees, {
245
+ showCode: true,
246
+ disableRounding: true,
247
+ });
248
+ warnings.fee = new TronUnexpectedFees("Estimated fees", {
249
+ fees,
250
+ });
251
+ }
252
+
253
+ return Promise.resolve({
254
+ errors,
255
+ warnings,
256
+ amount: amountSpent,
257
+ estimatedFees,
258
+ totalSpent,
259
+ family,
260
+ });
261
+ };
262
+
263
+ export default getTransactionStatus;
@@ -0,0 +1,78 @@
1
+ import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
2
+ import {
3
+ defaultUpdateTransaction,
4
+ makeAccountBridgeReceive,
5
+ makeScanAccounts,
6
+ } from "@ledgerhq/coin-framework/bridge/jsHelpers";
7
+ import { CoinConfig } from "@ledgerhq/coin-framework/config";
8
+ import { SignerContext } from "@ledgerhq/coin-framework/signer";
9
+ import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
10
+ import { type Transaction, TronAccount, TronSigner } from "../types";
11
+ import signerGetAddress from "../signer";
12
+ import broadcast from "./broadcast";
13
+ import createTransaction from "./createTransaction";
14
+ import estimateMaxSpendable from "./estimateMaxSpendable";
15
+ import getTransactionStatus from "./getTransactionStatus";
16
+ import { hydrate, preload } from "./preload";
17
+ import { prepareTransaction } from "./prepareTransaction";
18
+ import {
19
+ assignFromAccountRaw,
20
+ assignToAccountRaw,
21
+ fromOperationExtraRaw,
22
+ toOperationExtraRaw,
23
+ } from "./serialization";
24
+ import { buildSignOperation } from "./signOperation";
25
+ import { getAccountShape, sync } from "./synchronization";
26
+ import { setCoinConfig, TronCoinConfig } from "../config";
27
+
28
+ function buildCurrencyBridge(signerContext: SignerContext<TronSigner>): CurrencyBridge {
29
+ const getAddress = signerGetAddress(signerContext);
30
+
31
+ const scanAccounts = makeScanAccounts({
32
+ getAccountShape,
33
+ getAddressFn: getAddressWrapper(getAddress),
34
+ });
35
+
36
+ return {
37
+ preload,
38
+ hydrate,
39
+ scanAccounts,
40
+ };
41
+ }
42
+
43
+ function buildAccountBridge(
44
+ signerContext: SignerContext<TronSigner>,
45
+ ): AccountBridge<Transaction, TronAccount> {
46
+ const getAddress = signerGetAddress(signerContext);
47
+
48
+ const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
49
+ const signOperation = buildSignOperation(signerContext);
50
+
51
+ return {
52
+ estimateMaxSpendable,
53
+ createTransaction,
54
+ updateTransaction: defaultUpdateTransaction,
55
+ getTransactionStatus,
56
+ prepareTransaction,
57
+ sync,
58
+ receive,
59
+ signOperation,
60
+ broadcast,
61
+ assignFromAccountRaw,
62
+ assignToAccountRaw,
63
+ fromOperationExtraRaw,
64
+ toOperationExtraRaw,
65
+ };
66
+ }
67
+
68
+ export function createBridges(
69
+ signerContext: SignerContext<TronSigner>,
70
+ coinConfig: CoinConfig<TronCoinConfig>,
71
+ ) {
72
+ setCoinConfig(coinConfig);
73
+
74
+ return {
75
+ currencyBridge: buildCurrencyBridge(signerContext),
76
+ accountBridge: buildAccountBridge(signerContext),
77
+ };
78
+ }
@@ -0,0 +1,24 @@
1
+ import { getTronSuperRepresentatives, hydrateSuperRepresentatives } from "../network";
2
+ import { SuperRepresentative } from "../types";
3
+
4
+ export const preload = async () => {
5
+ const superRepresentatives = await getTronSuperRepresentatives();
6
+ return {
7
+ superRepresentatives,
8
+ };
9
+ };
10
+
11
+ export const hydrate = (data?: { superRepresentatives?: SuperRepresentative[] }) => {
12
+ if (!data || !data.superRepresentatives) return;
13
+
14
+ const { superRepresentatives } = data;
15
+
16
+ if (
17
+ !superRepresentatives ||
18
+ typeof superRepresentatives !== "object" ||
19
+ !Array.isArray(superRepresentatives)
20
+ )
21
+ return;
22
+
23
+ hydrateSuperRepresentatives(superRepresentatives);
24
+ };
@@ -0,0 +1,12 @@
1
+ import { AccountBridge } from "@ledgerhq/types-live";
2
+ import { getTronAccountNetwork } from "../network";
3
+ import { Transaction, TronAccount } from "../types";
4
+
5
+ export const prepareTransaction: AccountBridge<
6
+ Transaction,
7
+ TronAccount
8
+ >["prepareTransaction"] = async (account, transaction) => {
9
+ const networkInfo =
10
+ transaction.networkInfo || (await getTronAccountNetwork(account.freshAddress));
11
+ return transaction.networkInfo === networkInfo ? transaction : { ...transaction, networkInfo };
12
+ };
@@ -0,0 +1,288 @@
1
+ import { BigNumber } from "bignumber.js";
2
+ import {
3
+ TronTransactionInfo,
4
+ TronTransactionInfoRaw,
5
+ isTrongridExtraTxInfo,
6
+ isTrongridExtraTxInfoRaw,
7
+ type TronAccount,
8
+ type TronAccountRaw,
9
+ type TronResources,
10
+ type TronResourcesRaw,
11
+ type TrongridExtraTxInfo,
12
+ type TrongridExtraTxInfoRaw,
13
+ } from "../types";
14
+ import { Account, AccountRaw, OperationExtra, OperationExtraRaw } from "@ledgerhq/types-live";
15
+
16
+ export const toTronResourcesRaw = ({
17
+ frozen,
18
+ unFrozen,
19
+ delegatedFrozen,
20
+ legacyFrozen,
21
+ votes,
22
+ tronPower,
23
+ energy,
24
+ bandwidth,
25
+ unwithdrawnReward,
26
+ lastWithdrawnRewardDate,
27
+ lastVotedDate,
28
+ cacheTransactionInfoById: cacheTx,
29
+ }: TronResources): TronResourcesRaw => {
30
+ const frozenBandwidth = frozen.bandwidth;
31
+ const frozenEnergy = frozen.energy;
32
+ const delegatedFrozenBandwidth = delegatedFrozen.bandwidth;
33
+ const delegatedFrozenEnergy = delegatedFrozen.energy;
34
+ const cacheTransactionInfoById: Record<string, TronTransactionInfoRaw> = {};
35
+ const unFrozenBandwidth = unFrozen?.bandwidth;
36
+ const unFrozenEnergy = unFrozen?.energy;
37
+ const legacyFrozenBandwidth = legacyFrozen?.bandwidth;
38
+ const legacyFrozenEnergy = legacyFrozen?.energy;
39
+
40
+ for (const k in cacheTx) {
41
+ const { fee, blockNumber, withdraw_amount, unfreeze_amount } = cacheTx[k];
42
+ cacheTransactionInfoById[k] = [fee, blockNumber, withdraw_amount, unfreeze_amount];
43
+ }
44
+
45
+ return {
46
+ frozen: {
47
+ bandwidth: frozenBandwidth
48
+ ? {
49
+ amount: frozenBandwidth.amount.toString(),
50
+ }
51
+ : undefined,
52
+ energy: frozenEnergy
53
+ ? {
54
+ amount: frozenEnergy.amount.toString(),
55
+ }
56
+ : undefined,
57
+ },
58
+ delegatedFrozen: {
59
+ bandwidth: delegatedFrozenBandwidth
60
+ ? {
61
+ amount: delegatedFrozenBandwidth.amount.toString(),
62
+ }
63
+ : undefined,
64
+ energy: delegatedFrozenEnergy
65
+ ? {
66
+ amount: delegatedFrozenEnergy.amount.toString(),
67
+ }
68
+ : undefined,
69
+ },
70
+ unFrozen: {
71
+ bandwidth: unFrozenBandwidth
72
+ ? unFrozenBandwidth.map(entry => {
73
+ return { amount: entry.amount.toString(), expireTime: entry.expireTime.toISOString() };
74
+ })
75
+ : undefined,
76
+ energy: unFrozenEnergy
77
+ ? unFrozenEnergy.map(entry => {
78
+ return { amount: entry.amount.toString(), expireTime: entry.expireTime.toISOString() };
79
+ })
80
+ : undefined,
81
+ },
82
+ legacyFrozen: {
83
+ bandwidth: legacyFrozenBandwidth
84
+ ? {
85
+ amount: legacyFrozenBandwidth.amount.toString(),
86
+ expiredAt: legacyFrozenBandwidth.expiredAt.toISOString(),
87
+ }
88
+ : undefined,
89
+ energy: legacyFrozenEnergy
90
+ ? {
91
+ amount: legacyFrozenEnergy.amount.toString(),
92
+ expiredAt: legacyFrozenEnergy.expiredAt.toISOString(),
93
+ }
94
+ : undefined,
95
+ },
96
+ votes,
97
+ tronPower,
98
+ energy: energy.toString(),
99
+ bandwidth: {
100
+ freeUsed: bandwidth.freeUsed.toString(),
101
+ freeLimit: bandwidth.freeLimit.toString(),
102
+ gainedUsed: bandwidth.gainedUsed.toString(),
103
+ gainedLimit: bandwidth.gainedLimit.toString(),
104
+ },
105
+ unwithdrawnReward: unwithdrawnReward.toString(),
106
+ lastWithdrawnRewardDate: lastWithdrawnRewardDate
107
+ ? lastWithdrawnRewardDate.toISOString()
108
+ : undefined,
109
+ lastVotedDate: lastVotedDate ? lastVotedDate.toISOString() : undefined,
110
+ cacheTransactionInfoById,
111
+ };
112
+ };
113
+ export const fromTronResourcesRaw = ({
114
+ frozen,
115
+ unFrozen,
116
+ delegatedFrozen,
117
+ legacyFrozen,
118
+ votes,
119
+ tronPower,
120
+ energy,
121
+ bandwidth,
122
+ unwithdrawnReward,
123
+ lastWithdrawnRewardDate,
124
+ lastVotedDate,
125
+ cacheTransactionInfoById: cacheTransactionInfoByIdRaw,
126
+ }: TronResourcesRaw): TronResources => {
127
+ const frozenBandwidth = frozen.bandwidth;
128
+ const frozenEnergy = frozen.energy;
129
+ const delegatedFrozenBandwidth = delegatedFrozen.bandwidth;
130
+ const delegatedFrozenEnergy = delegatedFrozen.energy;
131
+ const unFrozenBandwidth = unFrozen?.bandwidth;
132
+ const unFrozenEnergy = unFrozen?.energy;
133
+ const legacyFrozenBandwidth = legacyFrozen?.bandwidth;
134
+ const legacyFrozenEnergy = legacyFrozen?.energy;
135
+
136
+ const cacheTransactionInfoById: Record<string, TronTransactionInfo> = {};
137
+
138
+ if (cacheTransactionInfoByIdRaw) {
139
+ for (const k in cacheTransactionInfoByIdRaw) {
140
+ const [fee, blockNumber, withdraw_amount, unfreeze_amount] = cacheTransactionInfoByIdRaw[k];
141
+ cacheTransactionInfoById[k] = {
142
+ fee,
143
+ blockNumber,
144
+ withdraw_amount,
145
+ unfreeze_amount,
146
+ };
147
+ }
148
+ }
149
+
150
+ return {
151
+ frozen: {
152
+ bandwidth: frozenBandwidth
153
+ ? {
154
+ amount: new BigNumber(frozenBandwidth.amount),
155
+ }
156
+ : undefined,
157
+ energy: frozenEnergy
158
+ ? {
159
+ amount: new BigNumber(frozenEnergy.amount),
160
+ }
161
+ : undefined,
162
+ },
163
+ delegatedFrozen: {
164
+ bandwidth: delegatedFrozenBandwidth
165
+ ? {
166
+ amount: new BigNumber(delegatedFrozenBandwidth.amount),
167
+ }
168
+ : undefined,
169
+ energy: delegatedFrozenEnergy
170
+ ? {
171
+ amount: new BigNumber(delegatedFrozenEnergy.amount),
172
+ }
173
+ : undefined,
174
+ },
175
+ unFrozen: {
176
+ bandwidth: unFrozenBandwidth
177
+ ? unFrozenBandwidth.map(entry => {
178
+ return { amount: new BigNumber(entry.amount), expireTime: new Date(entry.expireTime) };
179
+ })
180
+ : undefined,
181
+ energy: unFrozenEnergy
182
+ ? unFrozenEnergy.map(entry => {
183
+ return { amount: new BigNumber(entry.amount), expireTime: new Date(entry.expireTime) };
184
+ })
185
+ : undefined,
186
+ },
187
+ legacyFrozen: {
188
+ bandwidth: legacyFrozenBandwidth
189
+ ? {
190
+ amount: new BigNumber(legacyFrozenBandwidth.amount),
191
+ expiredAt: new Date(legacyFrozenBandwidth.expiredAt),
192
+ }
193
+ : undefined,
194
+ energy: legacyFrozenEnergy
195
+ ? {
196
+ amount: new BigNumber(legacyFrozenEnergy.amount),
197
+ expiredAt: new Date(legacyFrozenEnergy.expiredAt),
198
+ }
199
+ : undefined,
200
+ },
201
+ votes,
202
+ tronPower,
203
+ energy: new BigNumber(energy),
204
+ bandwidth: {
205
+ freeUsed: new BigNumber(bandwidth.freeUsed),
206
+ freeLimit: new BigNumber(bandwidth.freeLimit),
207
+ gainedUsed: new BigNumber(bandwidth.gainedUsed),
208
+ gainedLimit: new BigNumber(bandwidth.gainedLimit),
209
+ },
210
+ unwithdrawnReward: new BigNumber(unwithdrawnReward),
211
+ lastWithdrawnRewardDate: lastWithdrawnRewardDate
212
+ ? new Date(lastWithdrawnRewardDate)
213
+ : undefined,
214
+ lastVotedDate: lastVotedDate ? new Date(lastVotedDate) : undefined,
215
+ cacheTransactionInfoById,
216
+ };
217
+ };
218
+
219
+ export function assignToAccountRaw(account: Account, accountRaw: AccountRaw) {
220
+ const tronAccount = account as TronAccount;
221
+ if (tronAccount.tronResources) {
222
+ (accountRaw as TronAccountRaw).tronResources = toTronResourcesRaw(tronAccount.tronResources);
223
+ }
224
+ }
225
+
226
+ export function assignFromAccountRaw(accountRaw: AccountRaw, account: Account) {
227
+ const tronResourcesRaw = (accountRaw as TronAccountRaw).tronResources;
228
+ if (tronResourcesRaw)
229
+ (account as TronAccount).tronResources = fromTronResourcesRaw(tronResourcesRaw);
230
+ }
231
+
232
+ export function fromOperationExtraRaw(extraRaw: OperationExtraRaw): TrongridExtraTxInfo {
233
+ const extra: TrongridExtraTxInfo = {};
234
+ if (!isTrongridExtraTxInfoRaw(extraRaw)) {
235
+ return extra;
236
+ }
237
+
238
+ if (extraRaw.frozenAmount) {
239
+ extra.frozenAmount = new BigNumber(extraRaw.frozenAmount);
240
+ }
241
+
242
+ if (extraRaw.unfreezeAmount) {
243
+ extra.unfreezeAmount = new BigNumber(extraRaw.unfreezeAmount);
244
+ }
245
+
246
+ if (extraRaw.votes) {
247
+ extra.votes = extraRaw.votes;
248
+ }
249
+
250
+ if (extraRaw.unDelegatedAmount) {
251
+ extra.unDelegatedAmount = new BigNumber(extraRaw.unDelegatedAmount);
252
+ }
253
+
254
+ if (extraRaw.receiverAddress) {
255
+ extra.receiverAddress = extraRaw.receiverAddress;
256
+ }
257
+
258
+ return extra;
259
+ }
260
+
261
+ export function toOperationExtraRaw(extra: OperationExtra): TrongridExtraTxInfoRaw {
262
+ const extraRaw: TrongridExtraTxInfoRaw = {};
263
+ if (!isTrongridExtraTxInfo(extra)) {
264
+ return extraRaw;
265
+ }
266
+
267
+ if (extra.frozenAmount) {
268
+ extraRaw.frozenAmount = extra.frozenAmount.toString();
269
+ }
270
+
271
+ if (extra.unfreezeAmount) {
272
+ extraRaw.unfreezeAmount = extra.unfreezeAmount.toString();
273
+ }
274
+
275
+ if (extra.votes) {
276
+ extraRaw.votes = extra.votes;
277
+ }
278
+
279
+ if (extra.unDelegatedAmount) {
280
+ extraRaw.unDelegatedAmount = extra.unDelegatedAmount.toString();
281
+ }
282
+
283
+ if (extra.receiverAddress) {
284
+ extraRaw.receiverAddress = extra.receiverAddress;
285
+ }
286
+
287
+ return extraRaw;
288
+ }