@ledgerhq/coin-celo 1.1.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 (387) hide show
  1. package/.eslintrc.js +22 -0
  2. package/.turbo/turbo-build.log +4 -0
  3. package/.unimportedrc.json +56 -0
  4. package/CHANGELOG.md +15 -0
  5. package/LICENSE.txt +21 -0
  6. package/jest.config.js +8 -0
  7. package/jest.integ.config.js +8 -0
  8. package/lib/bridge/broadcast.d.ts +5 -0
  9. package/lib/bridge/broadcast.d.ts.map +1 -0
  10. package/lib/bridge/broadcast.js +13 -0
  11. package/lib/bridge/broadcast.js.map +1 -0
  12. package/lib/bridge/buildOptimisticOperation.d.ts +4 -0
  13. package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
  14. package/lib/bridge/buildOptimisticOperation.js +49 -0
  15. package/lib/bridge/buildOptimisticOperation.js.map +1 -0
  16. package/lib/bridge/buildTransaction.d.ts +5 -0
  17. package/lib/bridge/buildTransaction.d.ts.map +1 -0
  18. package/lib/bridge/buildTransaction.js +142 -0
  19. package/lib/bridge/buildTransaction.js.map +1 -0
  20. package/lib/bridge/createTransaction.d.ts +5 -0
  21. package/lib/bridge/createTransaction.d.ts.map +1 -0
  22. package/lib/bridge/createTransaction.js +16 -0
  23. package/lib/bridge/createTransaction.js.map +1 -0
  24. package/lib/bridge/deviceTransactionConfig.d.ts +4 -0
  25. package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
  26. package/lib/bridge/deviceTransactionConfig.js +16 -0
  27. package/lib/bridge/deviceTransactionConfig.js.map +1 -0
  28. package/lib/bridge/estimateMaxSpendable.d.ts +5 -0
  29. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
  30. package/lib/bridge/estimateMaxSpendable.js +23 -0
  31. package/lib/bridge/estimateMaxSpendable.js.map +1 -0
  32. package/lib/bridge/getFeesForTransaction.d.ts +8 -0
  33. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -0
  34. package/lib/bridge/getFeesForTransaction.js +93 -0
  35. package/lib/bridge/getFeesForTransaction.js.map +1 -0
  36. package/lib/bridge/getTransactionStatus.d.ts +5 -0
  37. package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
  38. package/lib/bridge/getTransactionStatus.js +98 -0
  39. package/lib/bridge/getTransactionStatus.js.map +1 -0
  40. package/lib/bridge/index.d.ts +11 -0
  41. package/lib/bridge/index.d.ts.map +1 -0
  42. package/lib/bridge/index.js +62 -0
  43. package/lib/bridge/index.js.map +1 -0
  44. package/lib/bridge/preload.d.ts +10 -0
  45. package/lib/bridge/preload.d.ts.map +1 -0
  46. package/lib/bridge/preload.js +72 -0
  47. package/lib/bridge/preload.js.map +1 -0
  48. package/lib/bridge/prepareTransaction.d.ts +5 -0
  49. package/lib/bridge/prepareTransaction.d.ts.map +1 -0
  50. package/lib/bridge/prepareTransaction.js +28 -0
  51. package/lib/bridge/prepareTransaction.js.map +1 -0
  52. package/lib/bridge/serialization.d.ts +9 -0
  53. package/lib/bridge/serialization.d.ts.map +1 -0
  54. package/lib/bridge/serialization.js +92 -0
  55. package/lib/bridge/serialization.js.map +1 -0
  56. package/lib/bridge/signOperation.d.ts +10 -0
  57. package/lib/bridge/signOperation.d.ts.map +1 -0
  58. package/lib/bridge/signOperation.js +77 -0
  59. package/lib/bridge/signOperation.js.map +1 -0
  60. package/lib/bridge/synchronisation.d.ts +5 -0
  61. package/lib/bridge/synchronisation.d.ts.map +1 -0
  62. package/lib/bridge/synchronisation.js +49 -0
  63. package/lib/bridge/synchronisation.js.map +1 -0
  64. package/lib/bridge/transaction.d.ts +14 -0
  65. package/lib/bridge/transaction.d.ts.map +1 -0
  66. package/lib/bridge/transaction.js +47 -0
  67. package/lib/bridge/transaction.js.map +1 -0
  68. package/lib/config.d.ts +3 -0
  69. package/lib/config.d.ts.map +1 -0
  70. package/lib/config.js +14 -0
  71. package/lib/config.js.map +1 -0
  72. package/lib/datasets/celo.scanAccounts.1.d.ts +5 -0
  73. package/lib/datasets/celo.scanAccounts.1.d.ts.map +1 -0
  74. package/lib/datasets/celo.scanAccounts.1.js +364 -0
  75. package/lib/datasets/celo.scanAccounts.1.js.map +1 -0
  76. package/lib/errors.d.ts +4 -0
  77. package/lib/errors.d.ts.map +1 -0
  78. package/lib/errors.js +6 -0
  79. package/lib/errors.js.map +1 -0
  80. package/lib/logic.d.ts +21 -0
  81. package/lib/logic.d.ts.map +1 -0
  82. package/lib/logic.js +97 -0
  83. package/lib/logic.js.map +1 -0
  84. package/lib/network/hubble.d.ts +12 -0
  85. package/lib/network/hubble.d.ts.map +1 -0
  86. package/lib/network/hubble.js +141 -0
  87. package/lib/network/hubble.js.map +1 -0
  88. package/lib/network/index.d.ts +4 -0
  89. package/lib/network/index.d.ts.map +1 -0
  90. package/lib/network/index.js +23 -0
  91. package/lib/network/index.js.map +1 -0
  92. package/lib/network/sdk.d.ts +27 -0
  93. package/lib/network/sdk.d.ts.map +1 -0
  94. package/lib/network/sdk.js +93 -0
  95. package/lib/network/sdk.js.map +1 -0
  96. package/lib/network/validators.d.ts +2 -0
  97. package/lib/network/validators.d.ts.map +1 -0
  98. package/lib/network/validators.js +6 -0
  99. package/lib/network/validators.js.map +1 -0
  100. package/lib/signer/hw-getAddress.d.ts +6 -0
  101. package/lib/signer/hw-getAddress.d.ts.map +1 -0
  102. package/lib/signer/hw-getAddress.js +26 -0
  103. package/lib/signer/hw-getAddress.js.map +1 -0
  104. package/lib/signer/index.d.ts +2 -0
  105. package/lib/signer/index.d.ts.map +1 -0
  106. package/lib/signer/index.js +18 -0
  107. package/lib/signer/index.js.map +1 -0
  108. package/lib/signer/signer.d.ts +16 -0
  109. package/lib/signer/signer.d.ts.map +1 -0
  110. package/lib/signer/signer.js +3 -0
  111. package/lib/signer/signer.js.map +1 -0
  112. package/lib/test/bot-specs.d.ts +7 -0
  113. package/lib/test/bot-specs.d.ts.map +1 -0
  114. package/lib/test/bot-specs.js +42 -0
  115. package/lib/test/bot-specs.js.map +1 -0
  116. package/lib/test/bridgeDatasetTest.d.ts +4 -0
  117. package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
  118. package/lib/test/bridgeDatasetTest.js +14 -0
  119. package/lib/test/bridgeDatasetTest.js.map +1 -0
  120. package/lib/test/cli-transaction.d.ts +25 -0
  121. package/lib/test/cli-transaction.d.ts.map +1 -0
  122. package/lib/test/cli-transaction.js +56 -0
  123. package/lib/test/cli-transaction.js.map +1 -0
  124. package/lib/test/please-add-coverage.test.d.ts +2 -0
  125. package/lib/test/please-add-coverage.test.d.ts.map +1 -0
  126. package/lib/test/please-add-coverage.test.js +6 -0
  127. package/lib/test/please-add-coverage.test.js.map +1 -0
  128. package/lib/test/specs/createActivateVoteMutation.d.ts +4 -0
  129. package/lib/test/specs/createActivateVoteMutation.d.ts.map +1 -0
  130. package/lib/test/specs/createActivateVoteMutation.js +37 -0
  131. package/lib/test/specs/createActivateVoteMutation.js.map +1 -0
  132. package/lib/test/specs/createLockMutation.d.ts +4 -0
  133. package/lib/test/specs/createLockMutation.d.ts.map +1 -0
  134. package/lib/test/specs/createLockMutation.js +37 -0
  135. package/lib/test/specs/createLockMutation.js.map +1 -0
  136. package/lib/test/specs/createRegisterAccountMutation.d.ts +4 -0
  137. package/lib/test/specs/createRegisterAccountMutation.d.ts.map +1 -0
  138. package/lib/test/specs/createRegisterAccountMutation.js +31 -0
  139. package/lib/test/specs/createRegisterAccountMutation.js.map +1 -0
  140. package/lib/test/specs/createRevokeVoteMutation.d.ts +4 -0
  141. package/lib/test/specs/createRevokeVoteMutation.d.ts.map +1 -0
  142. package/lib/test/specs/createRevokeVoteMutation.js +38 -0
  143. package/lib/test/specs/createRevokeVoteMutation.js.map +1 -0
  144. package/lib/test/specs/createSendMutation.d.ts +6 -0
  145. package/lib/test/specs/createSendMutation.d.ts.map +1 -0
  146. package/lib/test/specs/createSendMutation.js +45 -0
  147. package/lib/test/specs/createSendMutation.js.map +1 -0
  148. package/lib/test/specs/createUnlockMutation.d.ts +4 -0
  149. package/lib/test/specs/createUnlockMutation.d.ts.map +1 -0
  150. package/lib/test/specs/createUnlockMutation.js +37 -0
  151. package/lib/test/specs/createUnlockMutation.js.map +1 -0
  152. package/lib/test/specs/createVoteMutation.d.ts +4 -0
  153. package/lib/test/specs/createVoteMutation.d.ts.map +1 -0
  154. package/lib/test/specs/createVoteMutation.js +48 -0
  155. package/lib/test/specs/createVoteMutation.js.map +1 -0
  156. package/lib/test/specs/createWithdrawMutation.d.ts +4 -0
  157. package/lib/test/specs/createWithdrawMutation.d.ts.map +1 -0
  158. package/lib/test/specs/createWithdrawMutation.js +37 -0
  159. package/lib/test/specs/createWithdrawMutation.js.map +1 -0
  160. package/lib/test/specs/index.d.ts +9 -0
  161. package/lib/test/specs/index.d.ts.map +1 -0
  162. package/lib/test/specs/index.js +25 -0
  163. package/lib/test/specs/index.js.map +1 -0
  164. package/lib/test/speculos-deviceActions.d.ts +4 -0
  165. package/lib/test/speculos-deviceActions.d.ts.map +1 -0
  166. package/lib/test/speculos-deviceActions.js +58 -0
  167. package/lib/test/speculos-deviceActions.js.map +1 -0
  168. package/lib/types/index.d.ts +4 -0
  169. package/lib/types/index.d.ts.map +1 -0
  170. package/lib/types/index.js +19 -0
  171. package/lib/types/index.js.map +1 -0
  172. package/lib/types/types.d.ts +126 -0
  173. package/lib/types/types.d.ts.map +1 -0
  174. package/lib/types/types.js +11 -0
  175. package/lib/types/types.js.map +1 -0
  176. package/lib-es/bridge/broadcast.d.ts +5 -0
  177. package/lib-es/bridge/broadcast.d.ts.map +1 -0
  178. package/lib-es/bridge/broadcast.js +9 -0
  179. package/lib-es/bridge/broadcast.js.map +1 -0
  180. package/lib-es/bridge/buildOptimisticOperation.d.ts +4 -0
  181. package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
  182. package/lib-es/bridge/buildOptimisticOperation.js +42 -0
  183. package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
  184. package/lib-es/bridge/buildTransaction.d.ts +5 -0
  185. package/lib-es/bridge/buildTransaction.d.ts.map +1 -0
  186. package/lib-es/bridge/buildTransaction.js +140 -0
  187. package/lib-es/bridge/buildTransaction.js.map +1 -0
  188. package/lib-es/bridge/createTransaction.d.ts +5 -0
  189. package/lib-es/bridge/createTransaction.d.ts.map +1 -0
  190. package/lib-es/bridge/createTransaction.js +12 -0
  191. package/lib-es/bridge/createTransaction.js.map +1 -0
  192. package/lib-es/bridge/deviceTransactionConfig.d.ts +4 -0
  193. package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
  194. package/lib-es/bridge/deviceTransactionConfig.js +14 -0
  195. package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
  196. package/lib-es/bridge/estimateMaxSpendable.d.ts +5 -0
  197. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
  198. package/lib-es/bridge/estimateMaxSpendable.js +16 -0
  199. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
  200. package/lib-es/bridge/getFeesForTransaction.d.ts +8 -0
  201. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -0
  202. package/lib-es/bridge/getFeesForTransaction.js +91 -0
  203. package/lib-es/bridge/getFeesForTransaction.js.map +1 -0
  204. package/lib-es/bridge/getTransactionStatus.d.ts +5 -0
  205. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
  206. package/lib-es/bridge/getTransactionStatus.js +94 -0
  207. package/lib-es/bridge/getTransactionStatus.js.map +1 -0
  208. package/lib-es/bridge/index.d.ts +11 -0
  209. package/lib-es/bridge/index.d.ts.map +1 -0
  210. package/lib-es/bridge/index.js +54 -0
  211. package/lib-es/bridge/index.js.map +1 -0
  212. package/lib-es/bridge/preload.d.ts +10 -0
  213. package/lib-es/bridge/preload.d.ts.map +1 -0
  214. package/lib-es/bridge/preload.js +64 -0
  215. package/lib-es/bridge/preload.js.map +1 -0
  216. package/lib-es/bridge/prepareTransaction.d.ts +5 -0
  217. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
  218. package/lib-es/bridge/prepareTransaction.js +21 -0
  219. package/lib-es/bridge/prepareTransaction.js.map +1 -0
  220. package/lib-es/bridge/serialization.d.ts +9 -0
  221. package/lib-es/bridge/serialization.d.ts.map +1 -0
  222. package/lib-es/bridge/serialization.js +84 -0
  223. package/lib-es/bridge/serialization.js.map +1 -0
  224. package/lib-es/bridge/signOperation.d.ts +10 -0
  225. package/lib-es/bridge/signOperation.d.ts.map +1 -0
  226. package/lib-es/bridge/signOperation.js +70 -0
  227. package/lib-es/bridge/signOperation.js.map +1 -0
  228. package/lib-es/bridge/synchronisation.d.ts +5 -0
  229. package/lib-es/bridge/synchronisation.d.ts.map +1 -0
  230. package/lib-es/bridge/synchronisation.js +45 -0
  231. package/lib-es/bridge/synchronisation.js.map +1 -0
  232. package/lib-es/bridge/transaction.d.ts +14 -0
  233. package/lib-es/bridge/transaction.d.ts.map +1 -0
  234. package/lib-es/bridge/transaction.js +42 -0
  235. package/lib-es/bridge/transaction.js.map +1 -0
  236. package/lib-es/config.d.ts +3 -0
  237. package/lib-es/config.d.ts.map +1 -0
  238. package/lib-es/config.js +11 -0
  239. package/lib-es/config.js.map +1 -0
  240. package/lib-es/datasets/celo.scanAccounts.1.d.ts +5 -0
  241. package/lib-es/datasets/celo.scanAccounts.1.d.ts.map +1 -0
  242. package/lib-es/datasets/celo.scanAccounts.1.js +359 -0
  243. package/lib-es/datasets/celo.scanAccounts.1.js.map +1 -0
  244. package/lib-es/errors.d.ts +4 -0
  245. package/lib-es/errors.d.ts.map +1 -0
  246. package/lib-es/errors.js +3 -0
  247. package/lib-es/errors.js.map +1 -0
  248. package/lib-es/logic.d.ts +21 -0
  249. package/lib-es/logic.d.ts.map +1 -0
  250. package/lib-es/logic.js +77 -0
  251. package/lib-es/logic.js.map +1 -0
  252. package/lib-es/network/hubble.d.ts +12 -0
  253. package/lib-es/network/hubble.d.ts.map +1 -0
  254. package/lib-es/network/hubble.js +133 -0
  255. package/lib-es/network/hubble.js.map +1 -0
  256. package/lib-es/network/index.d.ts +4 -0
  257. package/lib-es/network/index.d.ts.map +1 -0
  258. package/lib-es/network/index.js +4 -0
  259. package/lib-es/network/index.js.map +1 -0
  260. package/lib-es/network/sdk.d.ts +27 -0
  261. package/lib-es/network/sdk.d.ts.map +1 -0
  262. package/lib-es/network/sdk.js +85 -0
  263. package/lib-es/network/sdk.js.map +1 -0
  264. package/lib-es/network/validators.d.ts +2 -0
  265. package/lib-es/network/validators.d.ts.map +1 -0
  266. package/lib-es/network/validators.js +2 -0
  267. package/lib-es/network/validators.js.map +1 -0
  268. package/lib-es/signer/hw-getAddress.d.ts +6 -0
  269. package/lib-es/signer/hw-getAddress.d.ts.map +1 -0
  270. package/lib-es/signer/hw-getAddress.js +21 -0
  271. package/lib-es/signer/hw-getAddress.js.map +1 -0
  272. package/lib-es/signer/index.d.ts +2 -0
  273. package/lib-es/signer/index.d.ts.map +1 -0
  274. package/lib-es/signer/index.js +2 -0
  275. package/lib-es/signer/index.js.map +1 -0
  276. package/lib-es/signer/signer.d.ts +16 -0
  277. package/lib-es/signer/signer.d.ts.map +1 -0
  278. package/lib-es/signer/signer.js +2 -0
  279. package/lib-es/signer/signer.js.map +1 -0
  280. package/lib-es/test/bot-specs.d.ts +7 -0
  281. package/lib-es/test/bot-specs.d.ts.map +1 -0
  282. package/lib-es/test/bot-specs.js +40 -0
  283. package/lib-es/test/bot-specs.js.map +1 -0
  284. package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
  285. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
  286. package/lib-es/test/bridgeDatasetTest.js +8 -0
  287. package/lib-es/test/bridgeDatasetTest.js.map +1 -0
  288. package/lib-es/test/cli-transaction.d.ts +25 -0
  289. package/lib-es/test/cli-transaction.d.ts.map +1 -0
  290. package/lib-es/test/cli-transaction.js +50 -0
  291. package/lib-es/test/cli-transaction.js.map +1 -0
  292. package/lib-es/test/please-add-coverage.test.d.ts +1 -0
  293. package/lib-es/test/please-add-coverage.test.d.ts.map +1 -0
  294. package/lib-es/test/please-add-coverage.test.js +5 -0
  295. package/lib-es/test/please-add-coverage.test.js.map +1 -0
  296. package/lib-es/test/specs/createActivateVoteMutation.d.ts +4 -0
  297. package/lib-es/test/specs/createActivateVoteMutation.d.ts.map +1 -0
  298. package/lib-es/test/specs/createActivateVoteMutation.js +30 -0
  299. package/lib-es/test/specs/createActivateVoteMutation.js.map +1 -0
  300. package/lib-es/test/specs/createLockMutation.d.ts +4 -0
  301. package/lib-es/test/specs/createLockMutation.d.ts.map +1 -0
  302. package/lib-es/test/specs/createLockMutation.js +30 -0
  303. package/lib-es/test/specs/createLockMutation.js.map +1 -0
  304. package/lib-es/test/specs/createRegisterAccountMutation.d.ts +4 -0
  305. package/lib-es/test/specs/createRegisterAccountMutation.d.ts.map +1 -0
  306. package/lib-es/test/specs/createRegisterAccountMutation.js +24 -0
  307. package/lib-es/test/specs/createRegisterAccountMutation.js.map +1 -0
  308. package/lib-es/test/specs/createRevokeVoteMutation.d.ts +4 -0
  309. package/lib-es/test/specs/createRevokeVoteMutation.d.ts.map +1 -0
  310. package/lib-es/test/specs/createRevokeVoteMutation.js +31 -0
  311. package/lib-es/test/specs/createRevokeVoteMutation.js.map +1 -0
  312. package/lib-es/test/specs/createSendMutation.d.ts +6 -0
  313. package/lib-es/test/specs/createSendMutation.d.ts.map +1 -0
  314. package/lib-es/test/specs/createSendMutation.js +37 -0
  315. package/lib-es/test/specs/createSendMutation.js.map +1 -0
  316. package/lib-es/test/specs/createUnlockMutation.d.ts +4 -0
  317. package/lib-es/test/specs/createUnlockMutation.d.ts.map +1 -0
  318. package/lib-es/test/specs/createUnlockMutation.js +30 -0
  319. package/lib-es/test/specs/createUnlockMutation.js.map +1 -0
  320. package/lib-es/test/specs/createVoteMutation.d.ts +4 -0
  321. package/lib-es/test/specs/createVoteMutation.d.ts.map +1 -0
  322. package/lib-es/test/specs/createVoteMutation.js +41 -0
  323. package/lib-es/test/specs/createVoteMutation.js.map +1 -0
  324. package/lib-es/test/specs/createWithdrawMutation.d.ts +4 -0
  325. package/lib-es/test/specs/createWithdrawMutation.d.ts.map +1 -0
  326. package/lib-es/test/specs/createWithdrawMutation.js +30 -0
  327. package/lib-es/test/specs/createWithdrawMutation.js.map +1 -0
  328. package/lib-es/test/specs/index.d.ts +9 -0
  329. package/lib-es/test/specs/index.d.ts.map +1 -0
  330. package/lib-es/test/specs/index.js +9 -0
  331. package/lib-es/test/specs/index.js.map +1 -0
  332. package/lib-es/test/speculos-deviceActions.d.ts +4 -0
  333. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
  334. package/lib-es/test/speculos-deviceActions.js +55 -0
  335. package/lib-es/test/speculos-deviceActions.js.map +1 -0
  336. package/lib-es/types/index.d.ts +4 -0
  337. package/lib-es/types/index.d.ts.map +1 -0
  338. package/lib-es/types/index.js +3 -0
  339. package/lib-es/types/index.js.map +1 -0
  340. package/lib-es/types/types.d.ts +126 -0
  341. package/lib-es/types/types.d.ts.map +1 -0
  342. package/lib-es/types/types.js +7 -0
  343. package/lib-es/types/types.js.map +1 -0
  344. package/package.json +156 -0
  345. package/src/bridge/broadcast.ts +14 -0
  346. package/src/bridge/buildOptimisticOperation.ts +53 -0
  347. package/src/bridge/buildTransaction.ts +154 -0
  348. package/src/bridge/createTransaction.ts +15 -0
  349. package/src/bridge/deviceTransactionConfig.ts +19 -0
  350. package/src/bridge/estimateMaxSpendable.ts +22 -0
  351. package/src/bridge/getFeesForTransaction.ts +115 -0
  352. package/src/bridge/getTransactionStatus.ts +120 -0
  353. package/src/bridge/index.ts +77 -0
  354. package/src/bridge/preload.ts +75 -0
  355. package/src/bridge/prepareTransaction.ts +33 -0
  356. package/src/bridge/serialization.ts +114 -0
  357. package/src/bridge/signOperation.ts +121 -0
  358. package/src/bridge/synchronisation.ts +60 -0
  359. package/src/bridge/transaction.ts +53 -0
  360. package/src/config.ts +12 -0
  361. package/src/datasets/celo.scanAccounts.1.ts +370 -0
  362. package/src/errors.ts +3 -0
  363. package/src/logic.ts +146 -0
  364. package/src/network/hubble.ts +183 -0
  365. package/src/network/index.ts +3 -0
  366. package/src/network/sdk.ts +101 -0
  367. package/src/network/validators.ts +1 -0
  368. package/src/signer/hw-getAddress.ts +27 -0
  369. package/src/signer/index.ts +1 -0
  370. package/src/signer/signer.ts +36 -0
  371. package/src/test/bot-specs.ts +55 -0
  372. package/src/test/bridgeDatasetTest.ts +10 -0
  373. package/src/test/cli-transaction.ts +70 -0
  374. package/src/test/please-add-coverage.test.ts +3 -0
  375. package/src/test/specs/createActivateVoteMutation.ts +37 -0
  376. package/src/test/specs/createLockMutation.ts +38 -0
  377. package/src/test/specs/createRegisterAccountMutation.ts +35 -0
  378. package/src/test/specs/createRevokeVoteMutation.ts +38 -0
  379. package/src/test/specs/createSendMutation.ts +41 -0
  380. package/src/test/specs/createUnlockMutation.ts +35 -0
  381. package/src/test/specs/createVoteMutation.ts +55 -0
  382. package/src/test/specs/createWithdrawMutation.ts +37 -0
  383. package/src/test/specs/index.ts +8 -0
  384. package/src/test/speculos-deviceActions.ts +63 -0
  385. package/src/types/index.ts +3 -0
  386. package/src/types/types.ts +155 -0
  387. package/tsconfig.json +12 -0
@@ -0,0 +1,370 @@
1
+ import BigNumber from "bignumber.js";
2
+ import {
3
+ AmountRequired,
4
+ InvalidAddress,
5
+ InvalidAddressBecauseDestinationIsAlsoSource,
6
+ NotEnoughBalance,
7
+ } from "@ledgerhq/errors";
8
+ import TransactionModule from "../bridge/transaction";
9
+ import { CeloAllFundsWarning } from "../errors";
10
+ import type { AccountRaw, CurrenciesData, TransactionStatusCommon } from "@ledgerhq/types-live";
11
+ import type { Transaction } from "../types/types";
12
+
13
+ // This account is registered for staking and has available funds, locked voting funds,
14
+ // locked non-voting funds, and withdrawable funds.
15
+ const LEDGER_CELO_ACCOUNT_1 = "0xcfD48e0FAf9f19377509cE68a6A6F4D9C85ff8AB";
16
+ // This account has no funds and isn't registered for staking.
17
+ const LEDGER_CELO_ACCOUNT_2 = "0x2cC7E5913bADa8FA2895bDeF7F4C2E36C2368Abb";
18
+ const VALIDATOR_ACCOUNT_1 = "0x0861a61Bf679A30680510EcC238ee43B82C5e843";
19
+
20
+ const dataset: CurrenciesData<Transaction> = {
21
+ scanAccounts: [
22
+ {
23
+ name: "Celo 1",
24
+ apdus: `
25
+ => e00200000d038000002c8000ce1080000000
26
+ <= 410453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a328383735443736394535333337363338363732386136374632463564326435666561374637356233399000
27
+ => e002000015058000002c8000ce10800000000000000000000000
28
+ <= 4104eedca4417737f2dae0e12320edba0e845e4ced411e6e2978a9165dde3891099402ff4906ecaab03232f8273592287a94866f14f17b5e2bf6e31837278127919c28636644343865304641663966313933373735303963453638613641364634443943383566663841429000
29
+ => e002000015058000002c8000ce10800000010000000000000000
30
+ <= 41042304dfd28a236eb03471986b90f0a3a111537b35766ae8ff78a9f588071f56ec127531a2498b36e856c759bc2734297a07f9f4b331153a8c9c21171f6488884e28326343374535393133624144613846413238393562446546374634433245333643323336384162629000
31
+ `,
32
+ },
33
+ ],
34
+ accounts: [
35
+ {
36
+ // Ignoring the "balance is sum of ops" test since that
37
+ // doesn't seem to take into account staked tokens properly.
38
+ FIXME_tests: ["balance is sum of ops"],
39
+ raw: {
40
+ id: `js:2:celo:${LEDGER_CELO_ACCOUNT_1}:`,
41
+ seedIdentifier:
42
+ "0453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a3",
43
+ name: "Celo 1",
44
+ derivationMode: "",
45
+ index: 0,
46
+ freshAddress: LEDGER_CELO_ACCOUNT_1,
47
+ freshAddressPath: "44'/52752'/0'/0/0",
48
+ blockHeight: 0,
49
+ operations: [],
50
+ pendingOperations: [],
51
+ currencyId: "celo",
52
+ lastSyncDate: "",
53
+ balance: "399893159500000000",
54
+ celoResources: {
55
+ registrationStatus: true,
56
+ lockedBalance: "1000000",
57
+ nonvotingLockedBalance: "900000",
58
+ pendingWithdrawals: [],
59
+ votes: [
60
+ {
61
+ validatorGroup: VALIDATOR_ACCOUNT_1,
62
+ amount: "100000",
63
+ activatable: true,
64
+ revokable: true,
65
+ type: "active",
66
+ index: 0,
67
+ },
68
+ ],
69
+ electionAddress: "0x8D6677192144292870907E3Fa8A5527fE55A7ff6",
70
+ lockedGoldAddress: "0x6cC083Aed9e3ebe302A6336dBC7c921C9f03349E",
71
+ },
72
+ } as AccountRaw,
73
+ transactions: [
74
+ {
75
+ name: "Same as Recipient",
76
+ transaction: t => ({
77
+ ...t,
78
+ amount: new BigNumber(100),
79
+ recipient: LEDGER_CELO_ACCOUNT_1,
80
+ }),
81
+ expectedStatus: {
82
+ errors: {
83
+ recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
84
+ },
85
+ warnings: {},
86
+ },
87
+ },
88
+ {
89
+ name: "Invalid Address",
90
+ transaction: t => ({
91
+ ...t,
92
+ amount: new BigNumber(100),
93
+ recipient: "dsadasdasdasdas",
94
+ }),
95
+ expectedStatus: {
96
+ errors: {
97
+ recipient: new InvalidAddress(),
98
+ },
99
+ warnings: {},
100
+ },
101
+ },
102
+ {
103
+ name: "Amount Required",
104
+ transaction: TransactionModule.fromTransactionRaw({
105
+ family: "celo",
106
+ recipient: LEDGER_CELO_ACCOUNT_2,
107
+ amount: "0",
108
+ mode: "send",
109
+ fees: null,
110
+ index: 0,
111
+ }),
112
+ expectedStatus: {
113
+ errors: {
114
+ amount: new AmountRequired(),
115
+ },
116
+ warnings: {},
117
+ },
118
+ },
119
+ {
120
+ name: "Not enough balance",
121
+ transaction: TransactionModule.fromTransactionRaw({
122
+ family: "celo",
123
+ recipient: LEDGER_CELO_ACCOUNT_2,
124
+ amount: "399893159500000005",
125
+ mode: "send",
126
+ fees: null,
127
+ index: 0,
128
+ }),
129
+ expectedStatus: {
130
+ errors: {
131
+ amount: new NotEnoughBalance(),
132
+ },
133
+ warnings: {},
134
+ },
135
+ },
136
+ {
137
+ name: "[send] use all amount - should warn all funds",
138
+ transaction: t => ({
139
+ ...t,
140
+ useAllAmount: true,
141
+ mode: "send",
142
+ recipient: LEDGER_CELO_ACCOUNT_2,
143
+ }),
144
+ expectedStatus: () => ({
145
+ errors: {},
146
+ warnings: {
147
+ amount: new CeloAllFundsWarning(),
148
+ },
149
+ }),
150
+ },
151
+ {
152
+ name: "Lock - success",
153
+ transaction: t => ({
154
+ ...t,
155
+ mode: "lock",
156
+ amount: new BigNumber(5000),
157
+ }),
158
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
159
+ return {
160
+ errors: {},
161
+ warnings: {},
162
+ amount: new BigNumber(5000),
163
+ };
164
+ },
165
+ },
166
+ {
167
+ name: "Unlock - success",
168
+ transaction: t => ({
169
+ ...t,
170
+ mode: "unlock",
171
+ amount: new BigNumber(50000),
172
+ }),
173
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
174
+ return {
175
+ errors: {},
176
+ warnings: {},
177
+ amount: new BigNumber(50000),
178
+ };
179
+ },
180
+ },
181
+ {
182
+ name: "Lock - amount required",
183
+ transaction: t => ({
184
+ ...t,
185
+ mode: "lock",
186
+ }),
187
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
188
+ return {
189
+ errors: {
190
+ amount: new AmountRequired(),
191
+ },
192
+ warnings: {},
193
+ };
194
+ },
195
+ },
196
+ {
197
+ name: "Unlock - amount required",
198
+ transaction: t => ({
199
+ ...t,
200
+ mode: "unlock",
201
+ }),
202
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
203
+ return {
204
+ errors: {
205
+ amount: new AmountRequired(),
206
+ },
207
+ warnings: {},
208
+ };
209
+ },
210
+ },
211
+ {
212
+ name: "Unlock - Not enough balance",
213
+ transaction: t => ({
214
+ ...t,
215
+ mode: "unlock",
216
+ amount: new BigNumber(200000000000000000),
217
+ }),
218
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
219
+ return {
220
+ errors: {
221
+ amount: new NotEnoughBalance(),
222
+ },
223
+ warnings: {},
224
+ };
225
+ },
226
+ },
227
+ {
228
+ name: "Vote - success",
229
+ transaction: t => ({
230
+ ...t,
231
+ mode: "vote",
232
+ useAllAmount: true,
233
+ recipient: VALIDATOR_ACCOUNT_1,
234
+ }),
235
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
236
+ return {
237
+ errors: {},
238
+ warnings: {},
239
+ amount: new BigNumber(100000000000000000),
240
+ };
241
+ },
242
+ },
243
+ {
244
+ name: "Vote - Not enough balance",
245
+ transaction: t => ({
246
+ ...t,
247
+ mode: "vote",
248
+ recipient: VALIDATOR_ACCOUNT_1,
249
+ amount: new BigNumber(200000000000000000),
250
+ }),
251
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
252
+ return {
253
+ errors: {
254
+ amount: new NotEnoughBalance(),
255
+ },
256
+ warnings: {},
257
+ };
258
+ },
259
+ },
260
+ {
261
+ name: "Activate Vote - success",
262
+ transaction: t => ({
263
+ ...t,
264
+ mode: "activate",
265
+ recipient: VALIDATOR_ACCOUNT_1,
266
+ }),
267
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
268
+ return {
269
+ errors: {},
270
+ warnings: {},
271
+ };
272
+ },
273
+ },
274
+ {
275
+ name: "Revoke Vote - success",
276
+ transaction: t => ({
277
+ ...t,
278
+ mode: "revoke",
279
+ recipient: VALIDATOR_ACCOUNT_1,
280
+ amount: new BigNumber(9000000),
281
+ index: 0,
282
+ }),
283
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
284
+ return {
285
+ errors: {},
286
+ warnings: {},
287
+ };
288
+ },
289
+ },
290
+ {
291
+ name: "Revoke Vote - Not enough balance",
292
+ transaction: t => ({
293
+ ...t,
294
+ mode: "revoke",
295
+ recipient: VALIDATOR_ACCOUNT_1,
296
+ amount: new BigNumber(20000000000000000000),
297
+ index: 0,
298
+ }),
299
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
300
+ return {
301
+ errors: {
302
+ amount: new NotEnoughBalance(),
303
+ },
304
+ warnings: {},
305
+ };
306
+ },
307
+ },
308
+ {
309
+ name: "Revoke Vote - voted amount should be used when revoke amount is set",
310
+ transaction: t => ({
311
+ ...t,
312
+ mode: "revoke",
313
+ recipient: VALIDATOR_ACCOUNT_1,
314
+ useAllAmount: true,
315
+ index: 0,
316
+ }),
317
+ expectedStatus: (): Partial<TransactionStatusCommon> => {
318
+ return {
319
+ errors: {},
320
+ warnings: {},
321
+ };
322
+ },
323
+ },
324
+ ],
325
+ },
326
+ {
327
+ FIXME_tests: ["balance is sum of ops"],
328
+ raw: {
329
+ id: `js:2:celo:${LEDGER_CELO_ACCOUNT_2}:`,
330
+ seedIdentifier:
331
+ "0453390dcc1e6f1be0fb34f837b278ed1b4c84097c7493c13a0d915c735af1d8aa445d2738a95e8f50bc22abd2e17cb868d4db22a623d99d861740eb93373d50a3",
332
+ name: "Celo 1",
333
+ derivationMode: "",
334
+ index: 0,
335
+ freshAddress: LEDGER_CELO_ACCOUNT_2,
336
+ freshAddressPath: "44'/52752'/0'/0/0",
337
+ blockHeight: 0,
338
+ operations: [],
339
+ pendingOperations: [],
340
+ currencyId: "celo",
341
+ lastSyncDate: "",
342
+ balance: "399893159500000000",
343
+ celoResources: {
344
+ registrationStatus: false,
345
+ lockedBalance: "0",
346
+ nonvotingLockedBalance: "0",
347
+ pendingWithdrawals: [],
348
+ votes: [],
349
+ electionAddress: "0x8D6677192144292870907E3Fa8A5527fE55A7ff6",
350
+ lockedGoldAddress: "0x6cC083Aed9e3ebe302A6336dBC7c921C9f03349E",
351
+ },
352
+ } as AccountRaw,
353
+ transactions: [
354
+ {
355
+ name: "Register Account - success",
356
+ transaction: t => ({
357
+ ...t,
358
+ mode: "register",
359
+ }),
360
+ expectedStatus: {
361
+ errors: {},
362
+ warnings: {},
363
+ },
364
+ },
365
+ ],
366
+ },
367
+ ],
368
+ };
369
+
370
+ export default dataset;
package/src/errors.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { createCustomErrorClass } from "@ledgerhq/errors";
2
+
3
+ export const CeloAllFundsWarning = createCustomErrorClass("CeloAllFundsWarning");
package/src/logic.ts ADDED
@@ -0,0 +1,146 @@
1
+ import {
2
+ CeloAccount,
3
+ CeloPendingWithdrawal,
4
+ CeloValidatorGroup,
5
+ CeloVote,
6
+ CeloVoteStatus,
7
+ PendingStakingOperationAmounts,
8
+ } from "./types/types";
9
+ import { BigNumber } from "bignumber.js";
10
+ import { Operation } from "@ledgerhq/types-live";
11
+
12
+ export const PRELOAD_MAX_AGE = 10 * 60 * 1000; // 10 minutes, used for max age in preload strategy
13
+ const LEDGER_BY_FIGMENT_VALIDATOR_GROUP_ADDRESS = "0x0861a61Bf679A30680510EcC238ee43B82C5e843";
14
+
15
+ export const availablePendingWithdrawals = (account: CeloAccount): CeloPendingWithdrawal[] => {
16
+ const { pendingWithdrawals } = account.celoResources || {};
17
+
18
+ return (pendingWithdrawals || []).filter(
19
+ withdrawal => new Date(withdrawal.time.toNumber() * 1000) < new Date(),
20
+ );
21
+ };
22
+
23
+ export const withdrawableBalance = (account: CeloAccount): BigNumber =>
24
+ availablePendingWithdrawals(account).reduce(
25
+ (sum, withdrawal) => sum.plus(withdrawal.value),
26
+ new BigNumber(0),
27
+ );
28
+
29
+ export const hasWithdrawableBalance = (account: CeloAccount): boolean =>
30
+ withdrawableBalance(account).isGreaterThan(0);
31
+
32
+ export const defaultValidatorGroupAddress = (): string => LEDGER_BY_FIGMENT_VALIDATOR_GROUP_ADDRESS;
33
+
34
+ export const isDefaultValidatorGroupAddress = (address: string): boolean =>
35
+ address === LEDGER_BY_FIGMENT_VALIDATOR_GROUP_ADDRESS;
36
+
37
+ export const isDefaultValidatorGroup = (validatorGroup: CeloValidatorGroup): boolean =>
38
+ isDefaultValidatorGroupAddress(validatorGroup.address);
39
+
40
+ export const activatableVotes = (account: CeloAccount): CeloVote[] => {
41
+ const { votes } = account.celoResources || {};
42
+
43
+ return (votes || []).filter(vote => vote.activatable);
44
+ };
45
+
46
+ export const hasActivatableVotes = (account: CeloAccount): boolean =>
47
+ activatableVotes(account).length > 0;
48
+
49
+ export const revokableVotes = (account: CeloAccount): CeloVote[] => {
50
+ const { votes } = account.celoResources || {};
51
+
52
+ return (votes || []).filter(vote => vote.revokable);
53
+ };
54
+
55
+ export const hasRevokableVotes = (account: CeloAccount): boolean =>
56
+ revokableVotes(account).length > 0;
57
+
58
+ export const getVote = (
59
+ account: CeloAccount,
60
+ validatorGroupAddress: string,
61
+ index: number | null | undefined,
62
+ ): CeloVote | undefined => {
63
+ const { votes } = account.celoResources || {};
64
+ return votes?.find(
65
+ revoke => revoke.validatorGroup === validatorGroupAddress && revoke.index == index,
66
+ );
67
+ };
68
+
69
+ export const voteStatus = (vote: CeloVote): CeloVoteStatus =>
70
+ vote.type === "pending" && vote.activatable ? "awaitingActivation" : vote.type;
71
+
72
+ export const fallbackValidatorGroup = (address: string): CeloValidatorGroup => ({
73
+ address: address,
74
+ name: address,
75
+ votes: new BigNumber(0),
76
+ });
77
+
78
+ export const isAccountRegistrationPending = (account: CeloAccount): boolean => {
79
+ // If there's a pending "REGISTER" operation and the
80
+ // account's registration status is false, then
81
+ // we know that the account is truly not registered yet.
82
+
83
+ const isAccountRegistrationPending =
84
+ !!account &&
85
+ account.pendingOperations.some(currentAccount => currentAccount.type === "REGISTER") &&
86
+ !account.celoResources?.registrationStatus;
87
+
88
+ return isAccountRegistrationPending;
89
+ };
90
+
91
+ const isOperationTrulyPending = (operation: Operation, activeOperations: Operation[]): boolean => {
92
+ return !activeOperations.some(activeOperation => activeOperation.hash === operation.hash);
93
+ };
94
+
95
+ export const getPendingStakingOperationAmounts = (
96
+ account: CeloAccount,
97
+ ): PendingStakingOperationAmounts => {
98
+ const operationAmounts = account.pendingOperations.reduce(
99
+ (acc, currentOperation) => {
100
+ if (currentOperation.type !== "VOTE" && currentOperation.type !== "LOCK") {
101
+ return acc;
102
+ }
103
+ if (isOperationTrulyPending(currentOperation, account.operations)) {
104
+ const value = new BigNumber(currentOperation.value);
105
+ switch (currentOperation.type) {
106
+ case "VOTE":
107
+ return {
108
+ ...acc,
109
+ vote: acc.vote.plus(value),
110
+ };
111
+ case "LOCK":
112
+ return {
113
+ ...acc,
114
+ lock: acc.lock.plus(value),
115
+ };
116
+ }
117
+ }
118
+
119
+ return acc;
120
+ },
121
+ {
122
+ vote: new BigNumber(0),
123
+ lock: new BigNumber(0),
124
+ },
125
+ );
126
+
127
+ return operationAmounts;
128
+ };
129
+
130
+ const getValidatorGroupsByVotingActivity = (
131
+ validatorGroups: CeloValidatorGroup[],
132
+ votes: CeloVote[],
133
+ withVotes: boolean,
134
+ ): CeloValidatorGroup[] => {
135
+ return validatorGroups.filter(v => votes.some(d => d.validatorGroup === v.address) === withVotes);
136
+ };
137
+
138
+ export const getValidatorGroupsWithVotes = (
139
+ validatorGroups: CeloValidatorGroup[],
140
+ votes: CeloVote[] | null,
141
+ ): CeloValidatorGroup[] => getValidatorGroupsByVotingActivity(validatorGroups, votes || [], true);
142
+
143
+ export const getValidatorGroupsWithoutVotes = (
144
+ validatorGroups: CeloValidatorGroup[],
145
+ votes: CeloVote[] | null = [],
146
+ ): CeloValidatorGroup[] => getValidatorGroupsByVotingActivity(validatorGroups, votes || [], false);
@@ -0,0 +1,183 @@
1
+ import network from "@ledgerhq/live-network/network";
2
+ import { OperationType } from "@ledgerhq/types-live";
3
+ import { BigNumber } from "bignumber.js";
4
+ import { getEnv } from "@ledgerhq/live-env";
5
+ import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
6
+ import { isDefaultValidatorGroup } from "../logic";
7
+ import { CeloOperation, CeloValidatorGroup, FigmentIndexerTransaction } from "../types/types";
8
+ import { celoKit } from "../network/sdk";
9
+
10
+ const DEFAULT_TRANSACTIONS_LIMIT = 200;
11
+ const getUrl = (route: string): string => `${getEnv("API_CELO_INDEXER")}${route || ""}`;
12
+
13
+ // Indexer returns both account data and transactions in one call.
14
+ // Transactions are just limited, there's no block height offset
15
+ const fetchAccountDetails = async (
16
+ address: string,
17
+ transactionsLimit: number = DEFAULT_TRANSACTIONS_LIMIT,
18
+ ) => {
19
+ const { data } = await network({
20
+ method: "GET",
21
+ url: getUrl(`/account_details/${address}?limit=${transactionsLimit}`),
22
+ });
23
+ return data;
24
+ };
25
+
26
+ const fetchStatus = async () => {
27
+ const { data } = await network({
28
+ method: "GET",
29
+ url: getUrl(`/status`),
30
+ });
31
+ return data;
32
+ };
33
+
34
+ const fetchValidatorGroups = async () => {
35
+ const { data } = await network({
36
+ method: "GET",
37
+ url: getUrl(`/validator_groups`),
38
+ });
39
+ return data.items;
40
+ };
41
+
42
+ const getOperationType = (type: string): OperationType => {
43
+ switch (type) {
44
+ case "InternalTransferSent":
45
+ return "OUT";
46
+ case "InternalTransferReceived":
47
+ return "IN";
48
+ case "GoldLocked":
49
+ return "LOCK";
50
+ case "GoldUnlocked":
51
+ return "UNLOCK";
52
+ case "GoldWithdrawn":
53
+ return "WITHDRAW";
54
+ case "ValidatorGroupVoteCastSent":
55
+ return "VOTE";
56
+ case "ValidatorGroupActiveVoteRevokedSent":
57
+ return "REVOKE";
58
+ case "ValidatorGroupPendingVoteRevokedSent":
59
+ return "REVOKE";
60
+ case "ValidatorGroupVoteActivatedSent":
61
+ return "ACTIVATE";
62
+ case "AccountCreated":
63
+ return "REGISTER";
64
+ case "AccountSlashed":
65
+ return "SLASH";
66
+ default:
67
+ return "NONE";
68
+ }
69
+ };
70
+
71
+ const transactionToOperation = (
72
+ accountId: string,
73
+ transaction: FigmentIndexerTransaction,
74
+ ): CeloOperation => {
75
+ const type: OperationType = getOperationType(transaction.kind);
76
+ const hasFailed = transaction.data?.success ? !transaction.data?.success : false;
77
+ const data = transaction.data;
78
+ const sender = data?.Account || data?.from;
79
+ const recipient = data?.Group || data?.to || data?.Raw?.address;
80
+ const fee = new BigNumber(transaction.data?.gas_used || 0).times(
81
+ new BigNumber(transaction.data?.gas_price || 0),
82
+ );
83
+
84
+ const value = ["LOCK", "UNLOCK", "ACTIVATE", "VOTE", "REVOKE", "REGISTER"].includes(type)
85
+ ? new BigNumber(fee)
86
+ : new BigNumber(transaction.amount);
87
+
88
+ return {
89
+ id: encodeOperationId(accountId, transaction.transaction_hash, type),
90
+ hash: transaction.transaction_hash,
91
+ accountId,
92
+ fee,
93
+ value,
94
+ type,
95
+ blockHeight: transaction.height,
96
+ date: new Date(transaction.time),
97
+ senders: sender ? [sender] : [],
98
+ recipients: recipient ? [recipient] : [],
99
+ hasFailed,
100
+ blockHash: null,
101
+ extra: {
102
+ celoOperationValue: new BigNumber(transaction.amount),
103
+ ...(["ACTIVATE", "VOTE", "REVOKE"].includes(type)
104
+ ? {
105
+ celoSourceValidator: recipient ? recipient : "",
106
+ }
107
+ : {}),
108
+ },
109
+ };
110
+ };
111
+
112
+ export const getAccountDetails = async (
113
+ address: string,
114
+ accountId: string,
115
+ ): Promise<{
116
+ blockHeight: any;
117
+ balance: BigNumber;
118
+ spendableBalance: BigNumber;
119
+ operations: CeloOperation[];
120
+ lockedBalance: BigNumber;
121
+ nonvotingLockedBalance: BigNumber;
122
+ }> => {
123
+ const accountDetails = await fetchAccountDetails(address);
124
+ const spendableBalance = new BigNumber(accountDetails.gold_balance);
125
+ const lockedBalance = new BigNumber(accountDetails.total_locked_gold);
126
+ const nonvotingLockedBalance = new BigNumber(accountDetails.total_nonvoting_locked_gold);
127
+ const balance = spendableBalance.plus(lockedBalance);
128
+ const indexerStatus = await fetchStatus();
129
+ const kit = celoKit();
130
+ const lockedGold = await kit.contracts.getLockedGold();
131
+
132
+ const allTransactions = accountDetails.internal_transfers
133
+ .filter(
134
+ (transfer: { data: { to: string; from: string } }) =>
135
+ transfer.data?.to != lockedGold.address && transfer.data?.from != lockedGold.address,
136
+ )
137
+ .concat(accountDetails.transactions);
138
+
139
+ const operations: CeloOperation[] = allTransactions.map(
140
+ (transaction: FigmentIndexerTransaction) => transactionToOperation(accountId, transaction),
141
+ );
142
+
143
+ return {
144
+ blockHeight: indexerStatus.last_indexed_height,
145
+ balance,
146
+ spendableBalance,
147
+ operations,
148
+ lockedBalance,
149
+ nonvotingLockedBalance,
150
+ };
151
+ };
152
+
153
+ export const getValidatorGroups = async (): Promise<CeloValidatorGroup[]> => {
154
+ const validatorGroups = await fetchValidatorGroups();
155
+
156
+ const result = validatorGroups.map(
157
+ (validatorGroup: {
158
+ address: string;
159
+ name: string;
160
+ active_votes: BigNumber.Value;
161
+ pending_votes: BigNumber.Value;
162
+ }) => ({
163
+ address: validatorGroup.address,
164
+ name: validatorGroup.name || validatorGroup.address,
165
+ votes: new BigNumber(validatorGroup.active_votes).plus(
166
+ new BigNumber(validatorGroup.pending_votes),
167
+ ),
168
+ }),
169
+ );
170
+ return customValidatorGroupsOrder(result);
171
+ };
172
+
173
+ const customValidatorGroupsOrder = (validatorGroups: any[]): CeloValidatorGroup[] => {
174
+ const defaultValidatorGroup = validatorGroups.find(isDefaultValidatorGroup);
175
+
176
+ const sortedValidatorGroups = [...validatorGroups]
177
+ .sort((a, b) => b.votes.minus(a.votes))
178
+ .filter(group => !isDefaultValidatorGroup(group));
179
+
180
+ return defaultValidatorGroup
181
+ ? [defaultValidatorGroup, ...sortedValidatorGroups]
182
+ : sortedValidatorGroups;
183
+ };
@@ -0,0 +1,3 @@
1
+ export { getAccountDetails, getValidatorGroups } from "./hubble";
2
+ export * from "./validators";
3
+ export * from "./sdk";