@ledgerhq/coin-multiversx 0.2.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (378) hide show
  1. package/.eslintrc.js +23 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +31 -0
  4. package/CHANGELOG.md +400 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/lib/api/apiCalls.d.ts +22 -0
  8. package/lib/api/apiCalls.d.ts.map +1 -0
  9. package/lib/api/apiCalls.js +153 -0
  10. package/lib/api/apiCalls.js.map +1 -0
  11. package/lib/api/dtos/multiversx-account.d.ts +9 -0
  12. package/lib/api/dtos/multiversx-account.d.ts.map +1 -0
  13. package/lib/api/dtos/multiversx-account.js +17 -0
  14. package/lib/api/dtos/multiversx-account.js.map +1 -0
  15. package/lib/api/index.d.ts +2 -0
  16. package/lib/api/index.d.ts.map +1 -0
  17. package/lib/api/index.js +16 -0
  18. package/lib/api/index.js.map +1 -0
  19. package/lib/api/sdk.d.ts +29 -0
  20. package/lib/api/sdk.d.ts.map +1 -0
  21. package/lib/api/sdk.js +281 -0
  22. package/lib/api/sdk.js.map +1 -0
  23. package/lib/bridge/js.d.ts +11 -0
  24. package/lib/bridge/js.d.ts.map +1 -0
  25. package/lib/bridge/js.js +62 -0
  26. package/lib/bridge/js.js.map +1 -0
  27. package/lib/bridge.integration.test.d.ts +4 -0
  28. package/lib/bridge.integration.test.d.ts.map +1 -0
  29. package/lib/bridge.integration.test.js +142 -0
  30. package/lib/bridge.integration.test.js.map +1 -0
  31. package/lib/broadcast.d.ts +9 -0
  32. package/lib/broadcast.d.ts.map +1 -0
  33. package/lib/broadcast.js +16 -0
  34. package/lib/broadcast.js.map +1 -0
  35. package/lib/buildOptimisticOperation.d.ts +4 -0
  36. package/lib/buildOptimisticOperation.d.ts.map +1 -0
  37. package/lib/buildOptimisticOperation.js +100 -0
  38. package/lib/buildOptimisticOperation.js.map +1 -0
  39. package/lib/buildOptimisticOperation.test.d.ts +2 -0
  40. package/lib/buildOptimisticOperation.test.d.ts.map +1 -0
  41. package/lib/buildOptimisticOperation.test.js +78 -0
  42. package/lib/buildOptimisticOperation.test.js.map +1 -0
  43. package/lib/buildSubAccounts.d.ts +11 -0
  44. package/lib/buildSubAccounts.d.ts.map +1 -0
  45. package/lib/buildSubAccounts.js +117 -0
  46. package/lib/buildSubAccounts.js.map +1 -0
  47. package/lib/buildTransaction.d.ts +19 -0
  48. package/lib/buildTransaction.d.ts.map +1 -0
  49. package/lib/buildTransaction.js +49 -0
  50. package/lib/buildTransaction.js.map +1 -0
  51. package/lib/buildTransaction.unit.test.d.ts +2 -0
  52. package/lib/buildTransaction.unit.test.d.ts.map +1 -0
  53. package/lib/buildTransaction.unit.test.js +47 -0
  54. package/lib/buildTransaction.unit.test.js.map +1 -0
  55. package/lib/cli-transaction.d.ts +16 -0
  56. package/lib/cli-transaction.d.ts.map +1 -0
  57. package/lib/cli-transaction.js +35 -0
  58. package/lib/cli-transaction.js.map +1 -0
  59. package/lib/config.d.ts +14 -0
  60. package/lib/config.d.ts.map +1 -0
  61. package/lib/config.js +16 -0
  62. package/lib/config.js.map +1 -0
  63. package/lib/constants.d.ts +21 -0
  64. package/lib/constants.d.ts.map +1 -0
  65. package/lib/constants.js +27 -0
  66. package/lib/constants.js.map +1 -0
  67. package/lib/createTransaction.d.ts +9 -0
  68. package/lib/createTransaction.d.ts.map +1 -0
  69. package/lib/createTransaction.js +26 -0
  70. package/lib/createTransaction.js.map +1 -0
  71. package/lib/datasets/multiversx1.d.ts +3 -0
  72. package/lib/datasets/multiversx1.d.ts.map +1 -0
  73. package/lib/datasets/multiversx1.js +21 -0
  74. package/lib/datasets/multiversx1.js.map +1 -0
  75. package/lib/deviceTransactionConfig.d.ts +10 -0
  76. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  77. package/lib/deviceTransactionConfig.js +60 -0
  78. package/lib/deviceTransactionConfig.js.map +1 -0
  79. package/lib/encode.d.ts +11 -0
  80. package/lib/encode.d.ts.map +1 -0
  81. package/lib/encode.js +39 -0
  82. package/lib/encode.js.map +1 -0
  83. package/lib/errors.d.ts +16 -0
  84. package/lib/errors.d.ts.map +1 -0
  85. package/lib/errors.js +10 -0
  86. package/lib/errors.js.map +1 -0
  87. package/lib/estimateMaxSpendable.d.ts +10 -0
  88. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  89. package/lib/estimateMaxSpendable.js +35 -0
  90. package/lib/estimateMaxSpendable.js.map +1 -0
  91. package/lib/formatters.d.ts +11 -0
  92. package/lib/formatters.d.ts.map +1 -0
  93. package/lib/formatters.js +65 -0
  94. package/lib/formatters.js.map +1 -0
  95. package/lib/getTransactionStatus.d.ts +5 -0
  96. package/lib/getTransactionStatus.d.ts.map +1 -0
  97. package/lib/getTransactionStatus.js +107 -0
  98. package/lib/getTransactionStatus.js.map +1 -0
  99. package/lib/helpers/denominate.d.ts +9 -0
  100. package/lib/helpers/denominate.d.ts.map +1 -0
  101. package/lib/helpers/denominate.js +75 -0
  102. package/lib/helpers/denominate.js.map +1 -0
  103. package/lib/helpers/handleTransactionStatus.d.ts +7 -0
  104. package/lib/helpers/handleTransactionStatus.d.ts.map +1 -0
  105. package/lib/helpers/handleTransactionStatus.js +18 -0
  106. package/lib/helpers/handleTransactionStatus.js.map +1 -0
  107. package/lib/helpers/hasMinimumDelegableBalance.d.ts +3 -0
  108. package/lib/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
  109. package/lib/helpers/hasMinimumDelegableBalance.js +7 -0
  110. package/lib/helpers/hasMinimumDelegableBalance.js.map +1 -0
  111. package/lib/helpers/randomizeProviders.d.ts +7 -0
  112. package/lib/helpers/randomizeProviders.d.ts.map +1 -0
  113. package/lib/helpers/randomizeProviders.js +12 -0
  114. package/lib/helpers/randomizeProviders.js.map +1 -0
  115. package/lib/hw-getAddress.d.ts +6 -0
  116. package/lib/hw-getAddress.d.ts.map +1 -0
  117. package/lib/hw-getAddress.js +14 -0
  118. package/lib/hw-getAddress.js.map +1 -0
  119. package/lib/logic.d.ts +15 -0
  120. package/lib/logic.d.ts.map +1 -0
  121. package/lib/logic.js +77 -0
  122. package/lib/logic.js.map +1 -0
  123. package/lib/preload.d.ts +11 -0
  124. package/lib/preload.d.ts.map +1 -0
  125. package/lib/preload.js +94 -0
  126. package/lib/preload.js.map +1 -0
  127. package/lib/prepareTransaction.d.ts +10 -0
  128. package/lib/prepareTransaction.d.ts.map +1 -0
  129. package/lib/prepareTransaction.js +72 -0
  130. package/lib/prepareTransaction.js.map +1 -0
  131. package/lib/reconciliation.d.ts +3 -0
  132. package/lib/reconciliation.d.ts.map +1 -0
  133. package/lib/reconciliation.js +56 -0
  134. package/lib/reconciliation.js.map +1 -0
  135. package/lib/serialization.d.ts +9 -0
  136. package/lib/serialization.d.ts.map +1 -0
  137. package/lib/serialization.js +65 -0
  138. package/lib/serialization.js.map +1 -0
  139. package/lib/signOperation.d.ts +10 -0
  140. package/lib/signOperation.d.ts.map +1 -0
  141. package/lib/signOperation.js +65 -0
  142. package/lib/signOperation.js.map +1 -0
  143. package/lib/signer.d.ts +16 -0
  144. package/lib/signer.d.ts.map +1 -0
  145. package/lib/signer.js +3 -0
  146. package/lib/signer.js.map +1 -0
  147. package/lib/specs.d.ts +7 -0
  148. package/lib/specs.d.ts.map +1 -0
  149. package/lib/specs.js +286 -0
  150. package/lib/specs.js.map +1 -0
  151. package/lib/speculos-deviceActions.d.ts +16 -0
  152. package/lib/speculos-deviceActions.d.ts.map +1 -0
  153. package/lib/speculos-deviceActions.js +250 -0
  154. package/lib/speculos-deviceActions.js.map +1 -0
  155. package/lib/synchronisation.d.ts +5 -0
  156. package/lib/synchronisation.d.ts.map +1 -0
  157. package/lib/synchronisation.js +69 -0
  158. package/lib/synchronisation.js.map +1 -0
  159. package/lib/transaction.d.ts +15 -0
  160. package/lib/transaction.d.ts.map +1 -0
  161. package/lib/transaction.js +62 -0
  162. package/lib/transaction.js.map +1 -0
  163. package/lib/types.d.ts +188 -0
  164. package/lib/types.d.ts.map +1 -0
  165. package/lib/types.js +17 -0
  166. package/lib/types.js.map +1 -0
  167. package/lib/utils/binary.utils.d.ts +5 -0
  168. package/lib/utils/binary.utils.d.ts.map +1 -0
  169. package/lib/utils/binary.utils.js +16 -0
  170. package/lib/utils/binary.utils.js.map +1 -0
  171. package/lib-es/api/apiCalls.d.ts +22 -0
  172. package/lib-es/api/apiCalls.d.ts.map +1 -0
  173. package/lib-es/api/apiCalls.js +147 -0
  174. package/lib-es/api/apiCalls.js.map +1 -0
  175. package/lib-es/api/dtos/multiversx-account.d.ts +9 -0
  176. package/lib-es/api/dtos/multiversx-account.d.ts.map +1 -0
  177. package/lib-es/api/dtos/multiversx-account.js +13 -0
  178. package/lib-es/api/dtos/multiversx-account.js.map +1 -0
  179. package/lib-es/api/index.d.ts +2 -0
  180. package/lib-es/api/index.d.ts.map +1 -0
  181. package/lib-es/api/index.js +2 -0
  182. package/lib-es/api/index.js.map +1 -0
  183. package/lib-es/api/sdk.d.ts +29 -0
  184. package/lib-es/api/sdk.d.ts.map +1 -0
  185. package/lib-es/api/sdk.js +264 -0
  186. package/lib-es/api/sdk.js.map +1 -0
  187. package/lib-es/bridge/js.d.ts +11 -0
  188. package/lib-es/bridge/js.d.ts.map +1 -0
  189. package/lib-es/bridge/js.js +53 -0
  190. package/lib-es/bridge/js.js.map +1 -0
  191. package/lib-es/bridge.integration.test.d.ts +4 -0
  192. package/lib-es/bridge.integration.test.d.ts.map +1 -0
  193. package/lib-es/bridge.integration.test.js +139 -0
  194. package/lib-es/bridge.integration.test.js.map +1 -0
  195. package/lib-es/broadcast.d.ts +9 -0
  196. package/lib-es/broadcast.d.ts.map +1 -0
  197. package/lib-es/broadcast.js +12 -0
  198. package/lib-es/broadcast.js.map +1 -0
  199. package/lib-es/buildOptimisticOperation.d.ts +4 -0
  200. package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
  201. package/lib-es/buildOptimisticOperation.js +93 -0
  202. package/lib-es/buildOptimisticOperation.js.map +1 -0
  203. package/lib-es/buildOptimisticOperation.test.d.ts +2 -0
  204. package/lib-es/buildOptimisticOperation.test.d.ts.map +1 -0
  205. package/lib-es/buildOptimisticOperation.test.js +73 -0
  206. package/lib-es/buildOptimisticOperation.test.js.map +1 -0
  207. package/lib-es/buildSubAccounts.d.ts +11 -0
  208. package/lib-es/buildSubAccounts.d.ts.map +1 -0
  209. package/lib-es/buildSubAccounts.js +112 -0
  210. package/lib-es/buildSubAccounts.js.map +1 -0
  211. package/lib-es/buildTransaction.d.ts +19 -0
  212. package/lib-es/buildTransaction.d.ts.map +1 -0
  213. package/lib-es/buildTransaction.js +44 -0
  214. package/lib-es/buildTransaction.js.map +1 -0
  215. package/lib-es/buildTransaction.unit.test.d.ts +2 -0
  216. package/lib-es/buildTransaction.unit.test.d.ts.map +1 -0
  217. package/lib-es/buildTransaction.unit.test.js +42 -0
  218. package/lib-es/buildTransaction.unit.test.js.map +1 -0
  219. package/lib-es/cli-transaction.d.ts +16 -0
  220. package/lib-es/cli-transaction.d.ts.map +1 -0
  221. package/lib-es/cli-transaction.js +29 -0
  222. package/lib-es/cli-transaction.js.map +1 -0
  223. package/lib-es/config.d.ts +14 -0
  224. package/lib-es/config.d.ts.map +1 -0
  225. package/lib-es/config.js +11 -0
  226. package/lib-es/config.js.map +1 -0
  227. package/lib-es/constants.d.ts +21 -0
  228. package/lib-es/constants.d.ts.map +1 -0
  229. package/lib-es/constants.js +21 -0
  230. package/lib-es/constants.js.map +1 -0
  231. package/lib-es/createTransaction.d.ts +9 -0
  232. package/lib-es/createTransaction.d.ts.map +1 -0
  233. package/lib-es/createTransaction.js +19 -0
  234. package/lib-es/createTransaction.js.map +1 -0
  235. package/lib-es/datasets/multiversx1.d.ts +3 -0
  236. package/lib-es/datasets/multiversx1.d.ts.map +1 -0
  237. package/lib-es/datasets/multiversx1.js +18 -0
  238. package/lib-es/datasets/multiversx1.js.map +1 -0
  239. package/lib-es/deviceTransactionConfig.d.ts +10 -0
  240. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  241. package/lib-es/deviceTransactionConfig.js +55 -0
  242. package/lib-es/deviceTransactionConfig.js.map +1 -0
  243. package/lib-es/encode.d.ts +11 -0
  244. package/lib-es/encode.d.ts.map +1 -0
  245. package/lib-es/encode.js +35 -0
  246. package/lib-es/encode.js.map +1 -0
  247. package/lib-es/errors.d.ts +16 -0
  248. package/lib-es/errors.d.ts.map +1 -0
  249. package/lib-es/errors.js +7 -0
  250. package/lib-es/errors.js.map +1 -0
  251. package/lib-es/estimateMaxSpendable.d.ts +10 -0
  252. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  253. package/lib-es/estimateMaxSpendable.js +31 -0
  254. package/lib-es/estimateMaxSpendable.js.map +1 -0
  255. package/lib-es/formatters.d.ts +11 -0
  256. package/lib-es/formatters.d.ts.map +1 -0
  257. package/lib-es/formatters.js +60 -0
  258. package/lib-es/formatters.js.map +1 -0
  259. package/lib-es/getTransactionStatus.d.ts +5 -0
  260. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  261. package/lib-es/getTransactionStatus.js +100 -0
  262. package/lib-es/getTransactionStatus.js.map +1 -0
  263. package/lib-es/helpers/denominate.d.ts +9 -0
  264. package/lib-es/helpers/denominate.d.ts.map +1 -0
  265. package/lib-es/helpers/denominate.js +71 -0
  266. package/lib-es/helpers/denominate.js.map +1 -0
  267. package/lib-es/helpers/handleTransactionStatus.d.ts +7 -0
  268. package/lib-es/helpers/handleTransactionStatus.d.ts.map +1 -0
  269. package/lib-es/helpers/handleTransactionStatus.js +14 -0
  270. package/lib-es/helpers/handleTransactionStatus.js.map +1 -0
  271. package/lib-es/helpers/hasMinimumDelegableBalance.d.ts +3 -0
  272. package/lib-es/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
  273. package/lib-es/helpers/hasMinimumDelegableBalance.js +3 -0
  274. package/lib-es/helpers/hasMinimumDelegableBalance.js.map +1 -0
  275. package/lib-es/helpers/randomizeProviders.d.ts +7 -0
  276. package/lib-es/helpers/randomizeProviders.d.ts.map +1 -0
  277. package/lib-es/helpers/randomizeProviders.js +8 -0
  278. package/lib-es/helpers/randomizeProviders.js.map +1 -0
  279. package/lib-es/hw-getAddress.d.ts +6 -0
  280. package/lib-es/hw-getAddress.d.ts.map +1 -0
  281. package/lib-es/hw-getAddress.js +12 -0
  282. package/lib-es/hw-getAddress.js.map +1 -0
  283. package/lib-es/logic.d.ts +15 -0
  284. package/lib-es/logic.d.ts.map +1 -0
  285. package/lib-es/logic.js +65 -0
  286. package/lib-es/logic.js.map +1 -0
  287. package/lib-es/preload.d.ts +11 -0
  288. package/lib-es/preload.d.ts.map +1 -0
  289. package/lib-es/preload.js +85 -0
  290. package/lib-es/preload.js.map +1 -0
  291. package/lib-es/prepareTransaction.d.ts +10 -0
  292. package/lib-es/prepareTransaction.d.ts.map +1 -0
  293. package/lib-es/prepareTransaction.js +68 -0
  294. package/lib-es/prepareTransaction.js.map +1 -0
  295. package/lib-es/reconciliation.d.ts +3 -0
  296. package/lib-es/reconciliation.d.ts.map +1 -0
  297. package/lib-es/reconciliation.js +52 -0
  298. package/lib-es/reconciliation.js.map +1 -0
  299. package/lib-es/serialization.d.ts +9 -0
  300. package/lib-es/serialization.d.ts.map +1 -0
  301. package/lib-es/serialization.js +53 -0
  302. package/lib-es/serialization.js.map +1 -0
  303. package/lib-es/signOperation.d.ts +10 -0
  304. package/lib-es/signOperation.d.ts.map +1 -0
  305. package/lib-es/signOperation.js +61 -0
  306. package/lib-es/signOperation.js.map +1 -0
  307. package/lib-es/signer.d.ts +16 -0
  308. package/lib-es/signer.d.ts.map +1 -0
  309. package/lib-es/signer.js +2 -0
  310. package/lib-es/signer.js.map +1 -0
  311. package/lib-es/specs.d.ts +7 -0
  312. package/lib-es/specs.d.ts.map +1 -0
  313. package/lib-es/specs.js +281 -0
  314. package/lib-es/specs.js.map +1 -0
  315. package/lib-es/speculos-deviceActions.d.ts +16 -0
  316. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  317. package/lib-es/speculos-deviceActions.js +244 -0
  318. package/lib-es/speculos-deviceActions.js.map +1 -0
  319. package/lib-es/synchronisation.d.ts +5 -0
  320. package/lib-es/synchronisation.d.ts.map +1 -0
  321. package/lib-es/synchronisation.js +62 -0
  322. package/lib-es/synchronisation.js.map +1 -0
  323. package/lib-es/transaction.d.ts +15 -0
  324. package/lib-es/transaction.d.ts.map +1 -0
  325. package/lib-es/transaction.js +56 -0
  326. package/lib-es/transaction.js.map +1 -0
  327. package/lib-es/types.d.ts +188 -0
  328. package/lib-es/types.d.ts.map +1 -0
  329. package/lib-es/types.js +12 -0
  330. package/lib-es/types.js.map +1 -0
  331. package/lib-es/utils/binary.utils.d.ts +5 -0
  332. package/lib-es/utils/binary.utils.d.ts.map +1 -0
  333. package/lib-es/utils/binary.utils.js +12 -0
  334. package/lib-es/utils/binary.utils.js.map +1 -0
  335. package/package.json +86 -0
  336. package/src/__snapshots__/bridge.integration.test.ts.snap +181 -0
  337. package/src/api/apiCalls.ts +243 -0
  338. package/src/api/dtos/multiversx-account.ts +20 -0
  339. package/src/api/index.ts +13 -0
  340. package/src/api/sdk.ts +368 -0
  341. package/src/bridge/js.ts +77 -0
  342. package/src/bridge.integration.test.ts +147 -0
  343. package/src/broadcast.ts +16 -0
  344. package/src/buildOptimisticOperation.test.ts +88 -0
  345. package/src/buildOptimisticOperation.ts +120 -0
  346. package/src/buildSubAccounts.ts +153 -0
  347. package/src/buildTransaction.ts +67 -0
  348. package/src/buildTransaction.unit.test.ts +49 -0
  349. package/src/cli-transaction.ts +41 -0
  350. package/src/config.ts +26 -0
  351. package/src/constants.ts +24 -0
  352. package/src/createTransaction.ts +21 -0
  353. package/src/datasets/multiversx1.ts +19 -0
  354. package/src/deviceTransactionConfig.ts +74 -0
  355. package/src/encode.ts +46 -0
  356. package/src/errors.ts +19 -0
  357. package/src/estimateMaxSpendable.ts +43 -0
  358. package/src/formatters.ts +76 -0
  359. package/src/getTransactionStatus.ts +151 -0
  360. package/src/helpers/denominate.ts +95 -0
  361. package/src/helpers/handleTransactionStatus.ts +26 -0
  362. package/src/helpers/hasMinimumDelegableBalance.ts +6 -0
  363. package/src/helpers/randomizeProviders.ts +20 -0
  364. package/src/hw-getAddress.ts +19 -0
  365. package/src/logic.ts +83 -0
  366. package/src/preload.ts +95 -0
  367. package/src/prepareTransaction.ts +78 -0
  368. package/src/reconciliation.ts +64 -0
  369. package/src/serialization.ts +72 -0
  370. package/src/signOperation.ts +99 -0
  371. package/src/signer.ts +21 -0
  372. package/src/specs.ts +387 -0
  373. package/src/speculos-deviceActions.ts +269 -0
  374. package/src/synchronisation.ts +74 -0
  375. package/src/transaction.ts +76 -0
  376. package/src/types.ts +235 -0
  377. package/src/utils/binary.utils.ts +13 -0
  378. package/tsconfig.json +13 -0
@@ -0,0 +1,243 @@
1
+ import network from "@ledgerhq/live-network";
2
+ import { SignedOperation } from "@ledgerhq/types-live/src";
3
+ import { MAX_PAGINATION_SIZE, METACHAIN_SHARD } from "../constants";
4
+ import {
5
+ ESDTToken,
6
+ MultiversXApiTransaction,
7
+ MultiversXDelegation,
8
+ MultiversXProvider,
9
+ MultiversXTransactionAction,
10
+ MultiversXTransactionMode,
11
+ MultiversXTransferOptions,
12
+ NetworkInfo,
13
+ } from "../types";
14
+ import { MultiversXAccount } from "./dtos/multiversx-account";
15
+
16
+ interface NetworkInfoResponse {
17
+ data: {
18
+ config: {
19
+ erd_chain_id: string;
20
+ erd_denomination: number;
21
+ erd_min_gas_limit: number;
22
+ erd_min_gas_price: number;
23
+ erd_gas_per_data_byte: number;
24
+ erd_gas_price_modifier: string;
25
+ };
26
+ };
27
+ }
28
+
29
+ interface SubmitTransactionResponse {
30
+ data: {
31
+ txHash: string;
32
+ };
33
+ }
34
+
35
+ interface BlockRoundResponse {
36
+ round: number;
37
+ }
38
+
39
+ const decodeTransactionMode = (action?: MultiversXTransactionAction): string => {
40
+ if (!action) {
41
+ return "send";
42
+ }
43
+
44
+ if (!action.category) {
45
+ return "send";
46
+ }
47
+
48
+ if (action.category !== "stake") {
49
+ return "send";
50
+ }
51
+
52
+ const mode = action.name;
53
+
54
+ return mode;
55
+ };
56
+
57
+ export default class MultiversXApi {
58
+ private API_URL: string;
59
+ private DELEGATION_API_URL: string;
60
+
61
+ constructor(API_URL: string, DELEGATION_API_URL: string) {
62
+ this.API_URL = API_URL;
63
+ this.DELEGATION_API_URL = DELEGATION_API_URL;
64
+ }
65
+
66
+ async getAccountDetails(addr: string) {
67
+ const {
68
+ data: { balance, nonce, isGuarded },
69
+ } = await network<MultiversXAccount>({
70
+ method: "GET",
71
+ url: `${this.API_URL}/accounts/${addr}?withGuardianInfo=true`,
72
+ });
73
+
74
+ return {
75
+ balance,
76
+ nonce,
77
+ isGuarded,
78
+ };
79
+ }
80
+
81
+ async getProviders(): Promise<MultiversXProvider[]> {
82
+ const { data: providers } = await network<MultiversXProvider[]>({
83
+ method: "GET",
84
+ url: `${this.DELEGATION_API_URL}/providers`,
85
+ });
86
+
87
+ return providers;
88
+ }
89
+
90
+ async getNetworkConfig(): Promise<NetworkInfo> {
91
+ const {
92
+ data: {
93
+ data: {
94
+ config: {
95
+ erd_chain_id: chainId,
96
+ erd_denomination: denomination,
97
+ erd_min_gas_limit: gasLimit,
98
+ erd_min_gas_price: gasPrice,
99
+ erd_gas_per_data_byte: gasPerByte,
100
+ erd_gas_price_modifier: gasPriceModifier,
101
+ },
102
+ },
103
+ },
104
+ } = await network<NetworkInfoResponse>({
105
+ method: "GET",
106
+ url: `${this.API_URL}/network/config`,
107
+ });
108
+
109
+ return {
110
+ chainID: chainId,
111
+ denomination,
112
+ gasLimit,
113
+ gasPrice,
114
+ gasPerByte,
115
+ gasPriceModifier,
116
+ };
117
+ }
118
+
119
+ async submit(signedOperation: SignedOperation): Promise<string> {
120
+ const transaction = {
121
+ ...signedOperation.rawData,
122
+ signature: signedOperation.signature,
123
+ };
124
+
125
+ const {
126
+ data: {
127
+ data: { txHash: hash },
128
+ },
129
+ } = await network<SubmitTransactionResponse>({
130
+ method: "POST",
131
+ url: `${this.API_URL}/transaction/send`,
132
+ data: transaction,
133
+ });
134
+
135
+ return hash;
136
+ }
137
+
138
+ async getHistory(addr: string, startAt: number): Promise<MultiversXApiTransaction[]> {
139
+ const { data: transactionsCount } = await network<number>({
140
+ method: "GET",
141
+ url: `${this.API_URL}/accounts/${addr}/transactions/count?after=${startAt}`,
142
+ });
143
+
144
+ let allTransactions: MultiversXApiTransaction[] = [];
145
+ let from = 0;
146
+ while (from < transactionsCount) {
147
+ const { data: transactions } = await network<MultiversXApiTransaction[]>({
148
+ method: "GET",
149
+ url: `${this.API_URL}/accounts/${addr}/transactions?after=${startAt}&from=${from}&size=${MAX_PAGINATION_SIZE}&withOperations=true&withScResults=true`,
150
+ });
151
+
152
+ for (const transaction of transactions) {
153
+ transaction.mode = decodeTransactionMode(transaction.action) as MultiversXTransactionMode;
154
+ }
155
+
156
+ allTransactions = [...allTransactions, ...transactions];
157
+
158
+ from = from + MAX_PAGINATION_SIZE;
159
+ }
160
+
161
+ return allTransactions;
162
+ }
163
+
164
+ async getAccountDelegations(addr: string): Promise<MultiversXDelegation[]> {
165
+ const { data: delegations } = await network<MultiversXDelegation[]>({
166
+ method: "GET",
167
+ url: `${this.DELEGATION_API_URL}/accounts/${addr}/delegations`,
168
+ });
169
+
170
+ return delegations;
171
+ }
172
+
173
+ async getESDTTransactionsForAddress(
174
+ addr: string,
175
+ token: string,
176
+ startAt: number,
177
+ ): Promise<MultiversXApiTransaction[]> {
178
+ const { data: tokenTransactionsCount } = await network<number>({
179
+ method: "GET",
180
+ url: `${this.API_URL}/accounts/${addr}/transactions/count?token=${token}&after=${startAt}`,
181
+ });
182
+
183
+ let allTokenTransactions: MultiversXApiTransaction[] = [];
184
+ let from = 0;
185
+ while (from < tokenTransactionsCount) {
186
+ const { data: tokenTransactions } = await network<MultiversXApiTransaction[]>({
187
+ method: "GET",
188
+ url: `${this.API_URL}/accounts/${addr}/transactions?token=${token}&from=${from}&after=${startAt}&size=${MAX_PAGINATION_SIZE}`,
189
+ });
190
+
191
+ allTokenTransactions = [...allTokenTransactions, ...tokenTransactions];
192
+
193
+ from = from + MAX_PAGINATION_SIZE;
194
+ }
195
+
196
+ for (const esdtTransaction of allTokenTransactions) {
197
+ esdtTransaction.transfer = MultiversXTransferOptions.esdt;
198
+ }
199
+
200
+ return allTokenTransactions;
201
+ }
202
+
203
+ async getESDTTokensForAddress(addr: string): Promise<ESDTToken[]> {
204
+ const { data: tokensCount } = await network<number>({
205
+ method: "GET",
206
+ url: `${this.API_URL}/accounts/${addr}/tokens/count`,
207
+ });
208
+
209
+ let allTokens: ESDTToken[] = [];
210
+ let from = 0;
211
+ while (from < tokensCount) {
212
+ const { data: tokens } = await network<ESDTToken[]>({
213
+ method: "GET",
214
+ url: `${this.API_URL}/accounts/${addr}/tokens?from=${from}&size=${MAX_PAGINATION_SIZE}`,
215
+ });
216
+
217
+ allTokens = [...allTokens, ...tokens];
218
+
219
+ from = from + MAX_PAGINATION_SIZE;
220
+ }
221
+
222
+ return allTokens;
223
+ }
224
+
225
+ async getESDTTokensCountForAddress(addr: string): Promise<number> {
226
+ const { data: tokensCount } = await network<number>({
227
+ method: "GET",
228
+ url: `${this.API_URL}/accounts/${addr}/tokens/count`,
229
+ });
230
+
231
+ return tokensCount;
232
+ }
233
+
234
+ async getBlockchainBlockHeight(): Promise<number> {
235
+ const {
236
+ data: [{ round: blockHeight }],
237
+ } = await network<BlockRoundResponse[]>({
238
+ method: "GET",
239
+ url: `${this.API_URL}/blocks?shard=${METACHAIN_SHARD}&fields=round`,
240
+ });
241
+ return blockHeight;
242
+ }
243
+ }
@@ -0,0 +1,20 @@
1
+ import BigNumber from "bignumber.js";
2
+
3
+ export class MultiversXAccount {
4
+ balance: BigNumber;
5
+ nonce: number;
6
+ isGuarded: boolean;
7
+ blockHeight: number;
8
+
9
+ constructor(
10
+ balance: BigNumber,
11
+ nonce: number,
12
+ isGuarded: boolean | null | undefined,
13
+ blockHeight: number,
14
+ ) {
15
+ this.balance = balance;
16
+ this.nonce = nonce;
17
+ this.isGuarded = isGuarded ? true : false;
18
+ this.blockHeight = blockHeight;
19
+ }
20
+ }
@@ -0,0 +1,13 @@
1
+ export {
2
+ getAccount,
3
+ getNetworkConfig,
4
+ getProviders,
5
+ getEGLDOperations,
6
+ getFees,
7
+ broadcastTransaction,
8
+ getAccountESDTTokens,
9
+ getAccountDelegations,
10
+ getESDTOperations,
11
+ hasESDTTokens,
12
+ getAccountNonce,
13
+ } from "./sdk";
package/src/api/sdk.ts ADDED
@@ -0,0 +1,368 @@
1
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
2
+ import { inferSubOperations } from "@ledgerhq/coin-framework/serialization/index";
3
+ import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets";
4
+ import { getEnv } from "@ledgerhq/live-env";
5
+ import type { OperationType, SignedOperation, TokenAccount } from "@ledgerhq/types-live";
6
+ import {
7
+ Address,
8
+ ApiNetworkProvider,
9
+ INetworkConfig,
10
+ INonce,
11
+ Transaction as MultiversXSdkTransaction,
12
+ TransactionPayload,
13
+ } from "@multiversx/sdk-core";
14
+ import { BigNumber } from "bignumber.js";
15
+ import {
16
+ CHAIN_ID,
17
+ GAS_PER_DATA_BYTE,
18
+ GAS_PRICE,
19
+ GAS_PRICE_MODIFIER,
20
+ MIN_GAS_LIMIT,
21
+ MULTIVERSX_STAKING_POOL,
22
+ } from "../constants";
23
+ import {
24
+ ESDTToken,
25
+ MultiversXApiTransaction,
26
+ MultiversXDelegation,
27
+ MultiversXOperation,
28
+ MultiversXProvider,
29
+ MultiversXTransactionOperation,
30
+ MultiversXTransferOptions,
31
+ Transaction,
32
+ } from "../types";
33
+ import { BinaryUtils } from "../utils/binary.utils";
34
+ import MultiversXApi from "./apiCalls";
35
+ import { MultiversXAccount } from "./dtos/multiversx-account";
36
+ const api = new MultiversXApi(
37
+ getEnv("MULTIVERSX_API_ENDPOINT"),
38
+ getEnv("MULTIVERSX_DELEGATION_API_ENDPOINT"),
39
+ );
40
+
41
+ const networkConfig = { clientName: "ledger-live" };
42
+ const proxy = new ApiNetworkProvider(getEnv("MULTIVERSX_API_ENDPOINT"), networkConfig);
43
+
44
+ /**
45
+ * Get account balances and nonce
46
+ */
47
+ export const getAccount = async (addr: string): Promise<MultiversXAccount> => {
48
+ const { balance, nonce, isGuarded } = await api.getAccountDetails(addr);
49
+ const blockHeight = await api.getBlockchainBlockHeight();
50
+
51
+ const account = new MultiversXAccount(new BigNumber(balance), nonce, isGuarded, blockHeight);
52
+ return account;
53
+ };
54
+
55
+ export const getProviders = async (): Promise<MultiversXProvider[]> => {
56
+ const providers = await api.getProviders();
57
+ return providers;
58
+ };
59
+
60
+ export const getNetworkConfig = async (): Promise<INetworkConfig> => {
61
+ return await proxy.getNetworkConfig();
62
+ };
63
+
64
+ export const getAccountNonce = async (addr: string): Promise<INonce> => {
65
+ const address = new Address(addr);
66
+
67
+ const account = await proxy.getAccount(address);
68
+
69
+ return account.nonce;
70
+ };
71
+
72
+ /**
73
+ * Returns true if account is the signer
74
+ */
75
+ function isSender(transaction: MultiversXApiTransaction, addr: string): boolean {
76
+ return transaction.sender === addr;
77
+ }
78
+
79
+ function isSelfSend(transaction: MultiversXApiTransaction): boolean {
80
+ return (
81
+ !!transaction.sender && !!transaction.receiver && transaction.sender === transaction.receiver
82
+ );
83
+ }
84
+
85
+ /**
86
+ * Map transaction to an Operation Type
87
+ */
88
+ function getEGLDOperationType(transaction: MultiversXApiTransaction, addr: string): OperationType {
89
+ if (transaction.action && transaction.action.category == "stake") {
90
+ const stakeAction = transaction.action.name;
91
+ switch (stakeAction) {
92
+ case "delegate":
93
+ return "DELEGATE";
94
+ case "unDelegate":
95
+ return "UNDELEGATE";
96
+ case "withdraw":
97
+ return "WITHDRAW_UNBONDED";
98
+ case "claimRewards":
99
+ return "REWARD";
100
+ case "reDelegateRewards":
101
+ return "DELEGATE";
102
+ }
103
+ }
104
+ return isSender(transaction, addr)
105
+ ? transaction.transfer === MultiversXTransferOptions.esdt
106
+ ? "FEES"
107
+ : "OUT"
108
+ : "IN";
109
+ }
110
+
111
+ function getESDTOperationValue(
112
+ transaction: MultiversXApiTransaction,
113
+ tokenIdentifier?: string,
114
+ ): BigNumber {
115
+ const hasFailed =
116
+ !transaction.status || transaction.status === "fail" || transaction.status === "invalid";
117
+
118
+ if (!transaction.action || hasFailed) {
119
+ return new BigNumber(0);
120
+ }
121
+ let token1, token2;
122
+ switch (transaction.action.name) {
123
+ case "transfer":
124
+ return new BigNumber(transaction.action.arguments.transfers[0].value ?? 0);
125
+ case "swap":
126
+ token1 = transaction.action.arguments.transfers[0];
127
+ token2 = transaction.action.arguments.transfers[1];
128
+ if (token1.token === tokenIdentifier) {
129
+ return new BigNumber(token1.value);
130
+ } else {
131
+ return new BigNumber(token2.value);
132
+ }
133
+ default:
134
+ return new BigNumber(transaction.tokenValue ?? 0);
135
+ }
136
+ }
137
+
138
+ function getStakingAmount(transaction: MultiversXApiTransaction, address: string): BigNumber {
139
+ const operation: MultiversXTransactionOperation | undefined = transaction.operations?.find(
140
+ ({ sender, receiver, action, type }) =>
141
+ action == "transfer" &&
142
+ type == "egld" &&
143
+ sender == transaction.receiver &&
144
+ (receiver == address || receiver == MULTIVERSX_STAKING_POOL),
145
+ );
146
+
147
+ let dataDecoded;
148
+ switch (transaction.mode) {
149
+ case "send":
150
+ return new BigNumber(0);
151
+ case "delegate":
152
+ return new BigNumber(transaction.value ?? 0);
153
+ case "unDelegate":
154
+ dataDecoded = BinaryUtils.base64Decode(transaction.data ?? "");
155
+ return new BigNumber(`0x${dataDecoded.split("@")[1]}`);
156
+ case "reDelegateRewards":
157
+ case "claimRewards":
158
+ case "withdraw":
159
+ default:
160
+ return new BigNumber(operation?.value ?? new BigNumber(0));
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Map transaction to a correct Operation Value (affecting account balance)
166
+ */
167
+ function getEGLDOperationValue(transaction: MultiversXApiTransaction, address: string): BigNumber {
168
+ if (transaction.mode === "send") {
169
+ if (transaction.transfer === MultiversXTransferOptions.esdt) {
170
+ // Only fees paid in EGLD for token transactions
171
+ return isSender(transaction, address) && transaction.fee
172
+ ? new BigNumber(transaction.fee)
173
+ : new BigNumber(0);
174
+ } else {
175
+ return isSender(transaction, address)
176
+ ? isSelfSend(transaction)
177
+ ? new BigNumber(transaction.fee ?? 0) // Self-send, only fees are paid
178
+ : new BigNumber(transaction.value ?? 0).plus(transaction.fee ?? 0) // The sender pays the amount and the fees
179
+ : new BigNumber(transaction.value ?? 0); // The recipient gets the amount
180
+ }
181
+ } else {
182
+ // Operation value for staking transactions are just the fees, plus possible rewards
183
+ // Other amounts are put in extra.amount
184
+ return new BigNumber(transaction.fee ?? 0);
185
+ }
186
+ }
187
+
188
+ /**
189
+ * Map the MultiversX history transaction to a Ledger Live Operation
190
+ */
191
+ function transactionToEGLDOperation(
192
+ accountId: string,
193
+ addr: string,
194
+ transaction: MultiversXApiTransaction,
195
+ subAccounts: TokenAccount[],
196
+ ): MultiversXOperation {
197
+ const type = getEGLDOperationType(transaction, addr);
198
+ const fee = new BigNumber(transaction.fee ?? 0);
199
+ const hasFailed =
200
+ !transaction.status || transaction.status === "fail" || transaction.status === "invalid";
201
+
202
+ const delegationAmount = getStakingAmount(transaction, addr);
203
+
204
+ const value = hasFailed
205
+ ? isSender(transaction, addr)
206
+ ? fee
207
+ : new BigNumber(0)
208
+ : transaction.mode === "claimRewards"
209
+ ? delegationAmount.minus(fee)
210
+ : getEGLDOperationValue(transaction, addr);
211
+
212
+ const operation: MultiversXOperation = {
213
+ id: encodeOperationId(accountId, transaction.txHash ?? "", type),
214
+ accountId,
215
+ fee,
216
+ value,
217
+ type,
218
+ hash: transaction.txHash ?? "",
219
+ blockHash: transaction.miniBlockHash,
220
+ blockHeight: transaction.round,
221
+ date: new Date(transaction.timestamp ? transaction.timestamp * 1000 : 0),
222
+ extra: {
223
+ amount: delegationAmount,
224
+ },
225
+ senders: (type == "OUT" || type == "IN") && transaction.sender ? [transaction.sender] : [],
226
+ recipients:
227
+ (type == "OUT" || type == "IN") && transaction.receiver ? [transaction.receiver] : [],
228
+ transactionSequenceNumber: isSender(transaction, addr) ? transaction.nonce : undefined,
229
+ hasFailed,
230
+ };
231
+
232
+ const subOperations = subAccounts
233
+ ? inferSubOperations(transaction.txHash ?? "", subAccounts)
234
+ : undefined;
235
+
236
+ if (subOperations) {
237
+ operation.subOperations = subOperations;
238
+ }
239
+
240
+ let contract: string | undefined = undefined;
241
+ if (transaction.receiver) {
242
+ const isReceiverSmartContract = Address.newFromBech32(transaction.receiver).isSmartContract();
243
+
244
+ contract = isReceiverSmartContract ? transaction.receiver : undefined;
245
+ }
246
+
247
+ if (contract) {
248
+ operation.contract = contract;
249
+ }
250
+
251
+ return operation;
252
+ }
253
+
254
+ const getESDTOperationType = (
255
+ transaction: MultiversXApiTransaction,
256
+ address: string,
257
+ ): OperationType => {
258
+ return isSender(transaction, address) ? "OUT" : "IN";
259
+ };
260
+
261
+ const transactionToESDTOperation = (
262
+ tokenAccountId: string,
263
+ addr: string,
264
+ transaction: MultiversXApiTransaction,
265
+ tokenIdentifier?: string,
266
+ ): MultiversXOperation => {
267
+ const type = getESDTOperationType(transaction, addr);
268
+ const value = getESDTOperationValue(transaction, tokenIdentifier);
269
+ const fee = new BigNumber(transaction.fee ?? 0);
270
+ const senders: string[] = transaction.sender ? [transaction.sender] : [];
271
+ const recipients: string[] = transaction.receiver ? [transaction.receiver] : [];
272
+ const hash = transaction.txHash ?? "";
273
+ const blockHeight = transaction.round;
274
+ const date = new Date(transaction.timestamp ? transaction.timestamp * 1000 : 0);
275
+
276
+ return {
277
+ id: encodeOperationId(tokenAccountId, hash, type),
278
+ accountId: tokenAccountId,
279
+ hash,
280
+ date,
281
+ type,
282
+ value,
283
+ fee,
284
+ senders,
285
+ recipients,
286
+ blockHeight,
287
+ blockHash: transaction.miniBlockHash,
288
+ extra: {},
289
+ };
290
+ };
291
+
292
+ /**
293
+ * Fetch operation list
294
+ */
295
+ export const getEGLDOperations = async (
296
+ accountId: string,
297
+ addr: string,
298
+ startAt: number,
299
+ subAccounts: TokenAccount[],
300
+ ): Promise<MultiversXOperation[]> => {
301
+ const rawTransactions = await api.getHistory(addr, startAt);
302
+ if (!rawTransactions) return rawTransactions;
303
+ return rawTransactions.map(transaction =>
304
+ transactionToEGLDOperation(accountId, addr, transaction, subAccounts),
305
+ );
306
+ };
307
+
308
+ export const getAccountESDTTokens = async (address: string): Promise<ESDTToken[]> => {
309
+ return await api.getESDTTokensForAddress(address);
310
+ };
311
+
312
+ export const getAccountDelegations = async (address: string): Promise<MultiversXDelegation[]> => {
313
+ return await api.getAccountDelegations(address);
314
+ };
315
+
316
+ export const hasESDTTokens = async (address: string): Promise<boolean> => {
317
+ const tokensCount = await api.getESDTTokensCountForAddress(address);
318
+ return tokensCount > 0;
319
+ };
320
+
321
+ export const getESDTOperations = async (
322
+ tokenAccountId: string,
323
+ address: string,
324
+ tokenIdentifier: string,
325
+ startAt: number,
326
+ ): Promise<MultiversXOperation[]> => {
327
+ const accountESDTTransactions = await api.getESDTTransactionsForAddress(
328
+ address,
329
+ tokenIdentifier,
330
+ startAt,
331
+ );
332
+
333
+ return accountESDTTransactions.map(transaction =>
334
+ transactionToESDTOperation(tokenAccountId, address, transaction, tokenIdentifier),
335
+ );
336
+ };
337
+
338
+ /**
339
+ * Obtain fees from blockchain
340
+ */
341
+ export const getFees = async (t: Transaction): Promise<BigNumber> => {
342
+ const networkConfig: INetworkConfig = {
343
+ MinGasLimit: MIN_GAS_LIMIT,
344
+ GasPerDataByte: GAS_PER_DATA_BYTE,
345
+ GasPriceModifier: GAS_PRICE_MODIFIER,
346
+ ChainID: CHAIN_ID,
347
+ };
348
+
349
+ const transaction = new MultiversXSdkTransaction({
350
+ data: TransactionPayload.fromEncoded(t.data?.trim()),
351
+ receiver: new Address(getAbandonSeedAddress("elrond")),
352
+ chainID: CHAIN_ID,
353
+ gasPrice: GAS_PRICE,
354
+ gasLimit: t.gasLimit ?? networkConfig.MinGasLimit,
355
+ sender: Address.empty(),
356
+ });
357
+
358
+ const feesStr = transaction.computeFee(networkConfig).toFixed();
359
+
360
+ return new BigNumber(feesStr);
361
+ };
362
+
363
+ /**
364
+ * Broadcast blob to blockchain
365
+ */
366
+ export const broadcastTransaction = async (signedOperation: SignedOperation): Promise<string> => {
367
+ return await api.submit(signedOperation);
368
+ };