@ledgerhq/coin-evm 0.2.1 → 0.2.2-nightly.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 (462) hide show
  1. package/.eslintrc.js +11 -46
  2. package/.turbo/turbo-build.log +1 -1
  3. package/CHANGELOG.md +29 -1
  4. package/lib/__tests__/adapters.unit.test.d.ts +2 -0
  5. package/lib/__tests__/adapters.unit.test.d.ts.map +1 -0
  6. package/lib/__tests__/adapters.unit.test.js +455 -0
  7. package/lib/__tests__/adapters.unit.test.js.map +1 -0
  8. package/lib/__tests__/broadcast.unit.test.d.ts +2 -0
  9. package/lib/__tests__/broadcast.unit.test.d.ts.map +1 -0
  10. package/lib/__tests__/broadcast.unit.test.js +181 -0
  11. package/lib/__tests__/broadcast.unit.test.js.map +1 -0
  12. package/lib/__tests__/buildOptimisticOperation.unit.test.d.ts +2 -0
  13. package/lib/__tests__/buildOptimisticOperation.unit.test.d.ts.map +1 -0
  14. package/lib/__tests__/buildOptimisticOperation.unit.test.js +166 -0
  15. package/lib/__tests__/buildOptimisticOperation.unit.test.js.map +1 -0
  16. package/lib/__tests__/createTransaction.unit.test.d.ts +2 -0
  17. package/lib/__tests__/createTransaction.unit.test.d.ts.map +1 -0
  18. package/lib/__tests__/createTransaction.unit.test.js +50 -0
  19. package/lib/__tests__/createTransaction.unit.test.js.map +1 -0
  20. package/lib/__tests__/deviceTransactionConfig.unit.test.d.ts +2 -0
  21. package/lib/__tests__/deviceTransactionConfig.unit.test.d.ts.map +1 -0
  22. package/lib/__tests__/deviceTransactionConfig.unit.test.js +231 -0
  23. package/lib/__tests__/deviceTransactionConfig.unit.test.js.map +1 -0
  24. package/lib/__tests__/estimateMaxSpendable.unit.test.d.ts +2 -0
  25. package/lib/__tests__/estimateMaxSpendable.unit.test.d.ts.map +1 -0
  26. package/lib/__tests__/estimateMaxSpendable.unit.test.js +145 -0
  27. package/lib/__tests__/estimateMaxSpendable.unit.test.js.map +1 -0
  28. package/lib/__tests__/gasTracker/index.unit.test.d.ts +2 -0
  29. package/lib/__tests__/gasTracker/index.unit.test.d.ts.map +1 -0
  30. package/lib/__tests__/gasTracker/index.unit.test.js +35 -0
  31. package/lib/__tests__/gasTracker/index.unit.test.js.map +1 -0
  32. package/lib/__tests__/gasTracker/ledger.unit.test.d.ts +2 -0
  33. package/lib/__tests__/gasTracker/ledger.unit.test.d.ts.map +1 -0
  34. package/lib/__tests__/gasTracker/ledger.unit.test.js +110 -0
  35. package/lib/__tests__/gasTracker/ledger.unit.test.js.map +1 -0
  36. package/lib/__tests__/getTransactionStatus.unit.test.d.ts +2 -0
  37. package/lib/__tests__/getTransactionStatus.unit.test.d.ts.map +1 -0
  38. package/lib/__tests__/getTransactionStatus.unit.test.js +216 -0
  39. package/lib/__tests__/getTransactionStatus.unit.test.js.map +1 -0
  40. package/lib/__tests__/hw-getAddress.unit.test.d.ts +2 -0
  41. package/lib/__tests__/hw-getAddress.unit.test.d.ts.map +1 -0
  42. package/lib/__tests__/hw-getAddress.unit.test.js +47 -0
  43. package/lib/__tests__/hw-getAddress.unit.test.js.map +1 -0
  44. package/lib/__tests__/logic.unit.test.d.ts +2 -0
  45. package/lib/__tests__/logic.unit.test.d.ts.map +1 -0
  46. package/lib/__tests__/logic.unit.test.js +296 -0
  47. package/lib/__tests__/logic.unit.test.js.map +1 -0
  48. package/lib/__tests__/preload.unit.test.d.ts +2 -0
  49. package/lib/__tests__/preload.unit.test.d.ts.map +1 -0
  50. package/lib/__tests__/preload.unit.test.js +149 -0
  51. package/lib/__tests__/preload.unit.test.js.map +1 -0
  52. package/lib/__tests__/prepareTransaction.unit.test.d.ts +2 -0
  53. package/lib/__tests__/prepareTransaction.unit.test.d.ts.map +1 -0
  54. package/lib/__tests__/prepareTransaction.unit.test.js +248 -0
  55. package/lib/__tests__/prepareTransaction.unit.test.js.map +1 -0
  56. package/lib/__tests__/rpc.unit.test.d.ts +2 -0
  57. package/lib/__tests__/rpc.unit.test.d.ts.map +1 -0
  58. package/lib/__tests__/rpc.unit.test.js +444 -0
  59. package/lib/__tests__/rpc.unit.test.js.map +1 -0
  60. package/lib/__tests__/signOperation.unit.test.d.ts +2 -0
  61. package/lib/__tests__/signOperation.unit.test.d.ts.map +1 -0
  62. package/lib/__tests__/signOperation.unit.test.js +160 -0
  63. package/lib/__tests__/signOperation.unit.test.js.map +1 -0
  64. package/lib/__tests__/synchronization.unit.test.d.ts +2 -0
  65. package/lib/__tests__/synchronization.unit.test.d.ts.map +1 -0
  66. package/lib/__tests__/synchronization.unit.test.js +499 -0
  67. package/lib/__tests__/synchronization.unit.test.js.map +1 -0
  68. package/lib/__tests__/transaction.unit.test.d.ts +2 -0
  69. package/lib/__tests__/transaction.unit.test.d.ts.map +1 -0
  70. package/lib/__tests__/transaction.unit.test.js +201 -0
  71. package/lib/__tests__/transaction.unit.test.js.map +1 -0
  72. package/lib/abis/erc20.abi.json +222 -0
  73. package/lib/abis/optimismGasPriceOracle.abi.json +252 -0
  74. package/lib/adapters.d.ts +21 -0
  75. package/lib/adapters.d.ts.map +1 -0
  76. package/lib/adapters.js +118 -0
  77. package/lib/adapters.js.map +1 -0
  78. package/lib/api/explorer/etherscan.d.ts +24 -0
  79. package/lib/api/explorer/etherscan.d.ts.map +1 -0
  80. package/lib/api/explorer/etherscan.js +90 -0
  81. package/lib/api/explorer/etherscan.js.map +1 -0
  82. package/lib/api/explorer/index.d.ts +26 -0
  83. package/lib/api/explorer/index.d.ts.map +1 -0
  84. package/lib/api/explorer/index.js +23 -0
  85. package/lib/api/explorer/index.js.map +1 -0
  86. package/lib/api/gasTracker/index.d.ts +13 -0
  87. package/lib/api/gasTracker/index.d.ts.map +1 -0
  88. package/lib/api/gasTracker/index.js +21 -0
  89. package/lib/api/gasTracker/index.js.map +1 -0
  90. package/lib/api/gasTracker/ledger.d.ts +9 -0
  91. package/lib/api/gasTracker/ledger.d.ts.map +1 -0
  92. package/lib/api/gasTracker/ledger.js +90 -0
  93. package/lib/api/gasTracker/ledger.js.map +1 -0
  94. package/lib/api/rpc/index.d.ts +3 -0
  95. package/lib/api/rpc/index.d.ts.map +1 -0
  96. package/lib/api/rpc/index.js +32 -0
  97. package/lib/api/rpc/index.js.map +1 -0
  98. package/lib/api/rpc/rpc.common.d.ts +93 -0
  99. package/lib/api/rpc/rpc.common.d.ts.map +1 -0
  100. package/lib/api/rpc/rpc.common.js +284 -0
  101. package/lib/api/rpc/rpc.common.js.map +1 -0
  102. package/lib/api/rpc/rpc.native.d.ts +6 -0
  103. package/lib/api/rpc/rpc.native.d.ts.map +1 -0
  104. package/lib/api/rpc/rpc.native.js +35 -0
  105. package/lib/api/rpc/rpc.native.js.map +1 -0
  106. package/lib/bridge/js.d.ts +11 -0
  107. package/lib/bridge/js.d.ts.map +1 -0
  108. package/lib/bridge/js.js +58 -0
  109. package/lib/bridge/js.js.map +1 -0
  110. package/lib/bridge.integration.test.d.ts +14 -0
  111. package/lib/bridge.integration.test.d.ts.map +1 -0
  112. package/lib/bridge.integration.test.js +85 -0
  113. package/lib/bridge.integration.test.js.map +1 -0
  114. package/lib/broadcast.d.ts +8 -0
  115. package/lib/broadcast.d.ts.map +1 -0
  116. package/lib/broadcast.js +25 -0
  117. package/lib/broadcast.js.map +1 -0
  118. package/lib/buildOptimisticOperation.d.ts +16 -0
  119. package/lib/buildOptimisticOperation.d.ts.map +1 -0
  120. package/lib/buildOptimisticOperation.js +80 -0
  121. package/lib/buildOptimisticOperation.js.map +1 -0
  122. package/lib/cli-transaction.d.ts +2 -0
  123. package/lib/cli-transaction.d.ts.map +1 -0
  124. package/lib/cli-transaction.js +9 -0
  125. package/lib/cli-transaction.js.map +1 -0
  126. package/lib/createTransaction.d.ts +9 -0
  127. package/lib/createTransaction.d.ts.map +1 -0
  128. package/lib/createTransaction.js +32 -0
  129. package/lib/createTransaction.js.map +1 -0
  130. package/lib/datasets/ethereum.scanAccounts.1.d.ts +7 -0
  131. package/lib/datasets/ethereum.scanAccounts.1.d.ts.map +1 -0
  132. package/lib/datasets/ethereum.scanAccounts.1.js +51 -0
  133. package/lib/datasets/ethereum.scanAccounts.1.js.map +1 -0
  134. package/lib/datasets/ethereum1.d.ts +3 -0
  135. package/lib/datasets/ethereum1.d.ts.map +1 -0
  136. package/lib/datasets/ethereum1.js +22 -0
  137. package/lib/datasets/ethereum1.js.map +1 -0
  138. package/lib/datasets/ethereum2.d.ts +3 -0
  139. package/lib/datasets/ethereum2.d.ts.map +1 -0
  140. package/lib/datasets/ethereum2.js +22 -0
  141. package/lib/datasets/ethereum2.js.map +1 -0
  142. package/lib/datasets/ethereum_classic.d.ts +5 -0
  143. package/lib/datasets/ethereum_classic.d.ts.map +1 -0
  144. package/lib/datasets/ethereum_classic.js +69 -0
  145. package/lib/datasets/ethereum_classic.js.map +1 -0
  146. package/lib/deviceTransactionConfig.d.ts +15 -0
  147. package/lib/deviceTransactionConfig.d.ts.map +1 -0
  148. package/lib/deviceTransactionConfig.js +44 -0
  149. package/lib/deviceTransactionConfig.js.map +1 -0
  150. package/lib/errors.d.ts +16 -0
  151. package/lib/errors.d.ts.map +1 -0
  152. package/lib/errors.js +11 -0
  153. package/lib/errors.js.map +1 -0
  154. package/lib/estimateMaxSpendable.d.ts +4 -0
  155. package/lib/estimateMaxSpendable.d.ts.map +1 -0
  156. package/lib/estimateMaxSpendable.js +23 -0
  157. package/lib/estimateMaxSpendable.js.map +1 -0
  158. package/lib/getTransactionStatus.d.ts +23 -0
  159. package/lib/getTransactionStatus.d.ts.map +1 -0
  160. package/lib/getTransactionStatus.js +132 -0
  161. package/lib/getTransactionStatus.js.map +1 -0
  162. package/lib/hw-getAddress.d.ts +6 -0
  163. package/lib/hw-getAddress.d.ts.map +1 -0
  164. package/lib/hw-getAddress.js +28 -0
  165. package/lib/hw-getAddress.js.map +1 -0
  166. package/lib/logic.d.ts +31 -0
  167. package/lib/logic.d.ts.map +1 -0
  168. package/lib/logic.js +131 -0
  169. package/lib/logic.js.map +1 -0
  170. package/lib/preload.d.ts +6 -0
  171. package/lib/preload.d.ts.map +1 -0
  172. package/lib/preload.js +58 -0
  173. package/lib/preload.js.map +1 -0
  174. package/lib/prepareTransaction.d.ts +26 -0
  175. package/lib/prepareTransaction.d.ts.map +1 -0
  176. package/lib/prepareTransaction.js +128 -0
  177. package/lib/prepareTransaction.js.map +1 -0
  178. package/lib/signOperation.d.ts +18 -0
  179. package/lib/signOperation.d.ts.map +1 -0
  180. package/lib/signOperation.js +88 -0
  181. package/lib/signOperation.js.map +1 -0
  182. package/lib/signer.d.ts +27 -0
  183. package/lib/signer.d.ts.map +1 -0
  184. package/lib/signer.js +3 -0
  185. package/lib/signer.js.map +1 -0
  186. package/lib/specs.d.ts +3 -0
  187. package/lib/specs.d.ts.map +1 -0
  188. package/lib/specs.js +238 -0
  189. package/lib/specs.js.map +1 -0
  190. package/lib/speculos-deviceActions.d.ts +8 -0
  191. package/lib/speculos-deviceActions.d.ts.map +1 -0
  192. package/lib/speculos-deviceActions.js +66 -0
  193. package/lib/speculos-deviceActions.js.map +1 -0
  194. package/lib/synchronization.d.ts +27 -0
  195. package/lib/synchronization.d.ts.map +1 -0
  196. package/lib/synchronization.js +220 -0
  197. package/lib/synchronization.js.map +1 -0
  198. package/lib/testUtils.d.ts +6 -0
  199. package/lib/testUtils.d.ts.map +1 -0
  200. package/lib/testUtils.js +111 -0
  201. package/lib/testUtils.js.map +1 -0
  202. package/lib/transaction.d.ts +43 -0
  203. package/lib/transaction.d.ts.map +1 -0
  204. package/lib/transaction.js +124 -0
  205. package/lib/transaction.js.map +1 -0
  206. package/lib/types.d.ts +111 -0
  207. package/lib/types.d.ts.map +1 -0
  208. package/lib/types.js +3 -0
  209. package/lib/types.js.map +1 -0
  210. package/lib-es/__tests__/adapters.unit.test.d.ts +2 -0
  211. package/lib-es/__tests__/adapters.unit.test.d.ts.map +1 -0
  212. package/lib-es/__tests__/adapters.unit.test.js +450 -0
  213. package/lib-es/__tests__/adapters.unit.test.js.map +1 -0
  214. package/lib-es/__tests__/broadcast.unit.test.d.ts +2 -0
  215. package/lib-es/__tests__/broadcast.unit.test.d.ts.map +1 -0
  216. package/lib-es/__tests__/broadcast.unit.test.js +153 -0
  217. package/lib-es/__tests__/broadcast.unit.test.js.map +1 -0
  218. package/lib-es/__tests__/buildOptimisticOperation.unit.test.d.ts +2 -0
  219. package/lib-es/__tests__/buildOptimisticOperation.unit.test.d.ts.map +1 -0
  220. package/lib-es/__tests__/buildOptimisticOperation.unit.test.js +161 -0
  221. package/lib-es/__tests__/buildOptimisticOperation.unit.test.js.map +1 -0
  222. package/lib-es/__tests__/createTransaction.unit.test.d.ts +2 -0
  223. package/lib-es/__tests__/createTransaction.unit.test.d.ts.map +1 -0
  224. package/lib-es/__tests__/createTransaction.unit.test.js +45 -0
  225. package/lib-es/__tests__/createTransaction.unit.test.js.map +1 -0
  226. package/lib-es/__tests__/deviceTransactionConfig.unit.test.d.ts +2 -0
  227. package/lib-es/__tests__/deviceTransactionConfig.unit.test.d.ts.map +1 -0
  228. package/lib-es/__tests__/deviceTransactionConfig.unit.test.js +226 -0
  229. package/lib-es/__tests__/deviceTransactionConfig.unit.test.js.map +1 -0
  230. package/lib-es/__tests__/estimateMaxSpendable.unit.test.d.ts +2 -0
  231. package/lib-es/__tests__/estimateMaxSpendable.unit.test.d.ts.map +1 -0
  232. package/lib-es/__tests__/estimateMaxSpendable.unit.test.js +117 -0
  233. package/lib-es/__tests__/estimateMaxSpendable.unit.test.js.map +1 -0
  234. package/lib-es/__tests__/gasTracker/index.unit.test.d.ts +2 -0
  235. package/lib-es/__tests__/gasTracker/index.unit.test.d.ts.map +1 -0
  236. package/lib-es/__tests__/gasTracker/index.unit.test.js +33 -0
  237. package/lib-es/__tests__/gasTracker/index.unit.test.js.map +1 -0
  238. package/lib-es/__tests__/gasTracker/ledger.unit.test.d.ts +2 -0
  239. package/lib-es/__tests__/gasTracker/ledger.unit.test.d.ts.map +1 -0
  240. package/lib-es/__tests__/gasTracker/ledger.unit.test.js +105 -0
  241. package/lib-es/__tests__/gasTracker/ledger.unit.test.js.map +1 -0
  242. package/lib-es/__tests__/getTransactionStatus.unit.test.d.ts +2 -0
  243. package/lib-es/__tests__/getTransactionStatus.unit.test.d.ts.map +1 -0
  244. package/lib-es/__tests__/getTransactionStatus.unit.test.js +211 -0
  245. package/lib-es/__tests__/getTransactionStatus.unit.test.js.map +1 -0
  246. package/lib-es/__tests__/hw-getAddress.unit.test.d.ts +2 -0
  247. package/lib-es/__tests__/hw-getAddress.unit.test.d.ts.map +1 -0
  248. package/lib-es/__tests__/hw-getAddress.unit.test.js +42 -0
  249. package/lib-es/__tests__/hw-getAddress.unit.test.js.map +1 -0
  250. package/lib-es/__tests__/logic.unit.test.d.ts +2 -0
  251. package/lib-es/__tests__/logic.unit.test.d.ts.map +1 -0
  252. package/lib-es/__tests__/logic.unit.test.js +268 -0
  253. package/lib-es/__tests__/logic.unit.test.js.map +1 -0
  254. package/lib-es/__tests__/preload.unit.test.d.ts +2 -0
  255. package/lib-es/__tests__/preload.unit.test.d.ts.map +1 -0
  256. package/lib-es/__tests__/preload.unit.test.js +121 -0
  257. package/lib-es/__tests__/preload.unit.test.js.map +1 -0
  258. package/lib-es/__tests__/prepareTransaction.unit.test.d.ts +2 -0
  259. package/lib-es/__tests__/prepareTransaction.unit.test.d.ts.map +1 -0
  260. package/lib-es/__tests__/prepareTransaction.unit.test.js +220 -0
  261. package/lib-es/__tests__/prepareTransaction.unit.test.js.map +1 -0
  262. package/lib-es/__tests__/rpc.unit.test.d.ts +2 -0
  263. package/lib-es/__tests__/rpc.unit.test.d.ts.map +1 -0
  264. package/lib-es/__tests__/rpc.unit.test.js +416 -0
  265. package/lib-es/__tests__/rpc.unit.test.js.map +1 -0
  266. package/lib-es/__tests__/signOperation.unit.test.d.ts +2 -0
  267. package/lib-es/__tests__/signOperation.unit.test.d.ts.map +1 -0
  268. package/lib-es/__tests__/signOperation.unit.test.js +132 -0
  269. package/lib-es/__tests__/signOperation.unit.test.js.map +1 -0
  270. package/lib-es/__tests__/synchronization.unit.test.d.ts +2 -0
  271. package/lib-es/__tests__/synchronization.unit.test.d.ts.map +1 -0
  272. package/lib-es/__tests__/synchronization.unit.test.js +471 -0
  273. package/lib-es/__tests__/synchronization.unit.test.js.map +1 -0
  274. package/lib-es/__tests__/transaction.unit.test.d.ts +2 -0
  275. package/lib-es/__tests__/transaction.unit.test.d.ts.map +1 -0
  276. package/lib-es/__tests__/transaction.unit.test.js +173 -0
  277. package/lib-es/__tests__/transaction.unit.test.js.map +1 -0
  278. package/lib-es/abis/erc20.abi.json +222 -0
  279. package/lib-es/abis/optimismGasPriceOracle.abi.json +252 -0
  280. package/lib-es/adapters.d.ts +21 -0
  281. package/lib-es/adapters.d.ts.map +1 -0
  282. package/lib-es/adapters.js +109 -0
  283. package/lib-es/adapters.js.map +1 -0
  284. package/lib-es/api/explorer/etherscan.d.ts +24 -0
  285. package/lib-es/api/explorer/etherscan.d.ts.map +1 -0
  286. package/lib-es/api/explorer/etherscan.js +84 -0
  287. package/lib-es/api/explorer/etherscan.js.map +1 -0
  288. package/lib-es/api/explorer/index.d.ts +26 -0
  289. package/lib-es/api/explorer/index.d.ts.map +1 -0
  290. package/lib-es/api/explorer/index.js +16 -0
  291. package/lib-es/api/explorer/index.js.map +1 -0
  292. package/lib-es/api/gasTracker/index.d.ts +13 -0
  293. package/lib-es/api/gasTracker/index.d.ts.map +1 -0
  294. package/lib-es/api/gasTracker/index.js +17 -0
  295. package/lib-es/api/gasTracker/index.js.map +1 -0
  296. package/lib-es/api/gasTracker/ledger.d.ts +9 -0
  297. package/lib-es/api/gasTracker/ledger.d.ts.map +1 -0
  298. package/lib-es/api/gasTracker/ledger.js +83 -0
  299. package/lib-es/api/gasTracker/ledger.js.map +1 -0
  300. package/lib-es/api/rpc/index.d.ts +3 -0
  301. package/lib-es/api/rpc/index.d.ts.map +1 -0
  302. package/lib-es/api/rpc/index.js +4 -0
  303. package/lib-es/api/rpc/index.js.map +1 -0
  304. package/lib-es/api/rpc/rpc.common.d.ts +93 -0
  305. package/lib-es/api/rpc/rpc.common.d.ts.map +1 -0
  306. package/lib-es/api/rpc/rpc.common.js +267 -0
  307. package/lib-es/api/rpc/rpc.common.js.map +1 -0
  308. package/lib-es/api/rpc/rpc.native.d.ts +6 -0
  309. package/lib-es/api/rpc/rpc.native.d.ts.map +1 -0
  310. package/lib-es/api/rpc/rpc.native.js +7 -0
  311. package/lib-es/api/rpc/rpc.native.js.map +1 -0
  312. package/lib-es/bridge/js.d.ts +11 -0
  313. package/lib-es/bridge/js.d.ts.map +1 -0
  314. package/lib-es/bridge/js.js +49 -0
  315. package/lib-es/bridge/js.js.map +1 -0
  316. package/lib-es/bridge.integration.test.d.ts +14 -0
  317. package/lib-es/bridge.integration.test.d.ts.map +1 -0
  318. package/lib-es/bridge.integration.test.js +79 -0
  319. package/lib-es/bridge.integration.test.js.map +1 -0
  320. package/lib-es/broadcast.d.ts +8 -0
  321. package/lib-es/broadcast.d.ts.map +1 -0
  322. package/lib-es/broadcast.js +21 -0
  323. package/lib-es/broadcast.js.map +1 -0
  324. package/lib-es/buildOptimisticOperation.d.ts +16 -0
  325. package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
  326. package/lib-es/buildOptimisticOperation.js +71 -0
  327. package/lib-es/buildOptimisticOperation.js.map +1 -0
  328. package/lib-es/cli-transaction.d.ts +2 -0
  329. package/lib-es/cli-transaction.d.ts.map +1 -0
  330. package/lib-es/cli-transaction.js +6 -0
  331. package/lib-es/cli-transaction.js.map +1 -0
  332. package/lib-es/createTransaction.d.ts +9 -0
  333. package/lib-es/createTransaction.d.ts.map +1 -0
  334. package/lib-es/createTransaction.js +25 -0
  335. package/lib-es/createTransaction.js.map +1 -0
  336. package/lib-es/datasets/ethereum.scanAccounts.1.d.ts +7 -0
  337. package/lib-es/datasets/ethereum.scanAccounts.1.d.ts.map +1 -0
  338. package/lib-es/datasets/ethereum.scanAccounts.1.js +49 -0
  339. package/lib-es/datasets/ethereum.scanAccounts.1.js.map +1 -0
  340. package/lib-es/datasets/ethereum1.d.ts +3 -0
  341. package/lib-es/datasets/ethereum1.d.ts.map +1 -0
  342. package/lib-es/datasets/ethereum1.js +19 -0
  343. package/lib-es/datasets/ethereum1.js.map +1 -0
  344. package/lib-es/datasets/ethereum2.d.ts +3 -0
  345. package/lib-es/datasets/ethereum2.d.ts.map +1 -0
  346. package/lib-es/datasets/ethereum2.js +19 -0
  347. package/lib-es/datasets/ethereum2.js.map +1 -0
  348. package/lib-es/datasets/ethereum_classic.d.ts +5 -0
  349. package/lib-es/datasets/ethereum_classic.d.ts.map +1 -0
  350. package/lib-es/datasets/ethereum_classic.js +67 -0
  351. package/lib-es/datasets/ethereum_classic.js.map +1 -0
  352. package/lib-es/deviceTransactionConfig.d.ts +15 -0
  353. package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
  354. package/lib-es/deviceTransactionConfig.js +42 -0
  355. package/lib-es/deviceTransactionConfig.js.map +1 -0
  356. package/lib-es/errors.d.ts +16 -0
  357. package/lib-es/errors.d.ts.map +1 -0
  358. package/lib-es/errors.js +8 -0
  359. package/lib-es/errors.js.map +1 -0
  360. package/lib-es/estimateMaxSpendable.d.ts +4 -0
  361. package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
  362. package/lib-es/estimateMaxSpendable.js +19 -0
  363. package/lib-es/estimateMaxSpendable.js.map +1 -0
  364. package/lib-es/getTransactionStatus.d.ts +23 -0
  365. package/lib-es/getTransactionStatus.d.ts.map +1 -0
  366. package/lib-es/getTransactionStatus.js +125 -0
  367. package/lib-es/getTransactionStatus.js.map +1 -0
  368. package/lib-es/hw-getAddress.d.ts +6 -0
  369. package/lib-es/hw-getAddress.d.ts.map +1 -0
  370. package/lib-es/hw-getAddress.js +23 -0
  371. package/lib-es/hw-getAddress.js.map +1 -0
  372. package/lib-es/logic.d.ts +31 -0
  373. package/lib-es/logic.d.ts.map +1 -0
  374. package/lib-es/logic.js +119 -0
  375. package/lib-es/logic.js.map +1 -0
  376. package/lib-es/preload.d.ts +6 -0
  377. package/lib-es/preload.d.ts.map +1 -0
  378. package/lib-es/preload.js +49 -0
  379. package/lib-es/preload.js.map +1 -0
  380. package/lib-es/prepareTransaction.d.ts +26 -0
  381. package/lib-es/prepareTransaction.d.ts.map +1 -0
  382. package/lib-es/prepareTransaction.js +118 -0
  383. package/lib-es/prepareTransaction.js.map +1 -0
  384. package/lib-es/signOperation.d.ts +18 -0
  385. package/lib-es/signOperation.d.ts.map +1 -0
  386. package/lib-es/signOperation.js +83 -0
  387. package/lib-es/signOperation.js.map +1 -0
  388. package/lib-es/signer.d.ts +27 -0
  389. package/lib-es/signer.d.ts.map +1 -0
  390. package/lib-es/signer.js +2 -0
  391. package/lib-es/signer.js.map +1 -0
  392. package/lib-es/specs.d.ts +3 -0
  393. package/lib-es/specs.d.ts.map +1 -0
  394. package/lib-es/specs.js +233 -0
  395. package/lib-es/specs.js.map +1 -0
  396. package/lib-es/speculos-deviceActions.d.ts +8 -0
  397. package/lib-es/speculos-deviceActions.d.ts.map +1 -0
  398. package/lib-es/speculos-deviceActions.js +63 -0
  399. package/lib-es/speculos-deviceActions.js.map +1 -0
  400. package/lib-es/synchronization.d.ts +27 -0
  401. package/lib-es/synchronization.d.ts.map +1 -0
  402. package/lib-es/synchronization.js +212 -0
  403. package/lib-es/synchronization.js.map +1 -0
  404. package/lib-es/testUtils.d.ts +6 -0
  405. package/lib-es/testUtils.d.ts.map +1 -0
  406. package/lib-es/testUtils.js +102 -0
  407. package/lib-es/testUtils.js.map +1 -0
  408. package/lib-es/transaction.d.ts +43 -0
  409. package/lib-es/transaction.d.ts.map +1 -0
  410. package/lib-es/transaction.js +112 -0
  411. package/lib-es/transaction.js.map +1 -0
  412. package/lib-es/types.d.ts +111 -0
  413. package/lib-es/types.d.ts.map +1 -0
  414. package/lib-es/types.js +2 -0
  415. package/lib-es/types.js.map +1 -0
  416. package/package.json +8 -23
  417. package/src/__tests__/adapters.unit.test.ts +22 -52
  418. package/src/__tests__/broadcast.unit.test.ts +9 -27
  419. package/src/__tests__/buildOptimisticOperation.unit.test.ts +4 -4
  420. package/src/__tests__/deviceTransactionConfig.unit.test.ts +7 -7
  421. package/src/__tests__/estimateMaxSpendable.unit.test.ts +2 -4
  422. package/src/__tests__/gasTracker/index.unit.test.ts +36 -0
  423. package/src/__tests__/gasTracker/ledger.unit.test.ts +108 -0
  424. package/src/__tests__/getTransactionStatus.unit.test.ts +35 -40
  425. package/src/__tests__/hw-getAddress.unit.test.ts +15 -2
  426. package/src/__tests__/logic.unit.test.ts +25 -72
  427. package/src/__tests__/preload.unit.test.ts +3 -9
  428. package/src/__tests__/prepareTransaction.unit.test.ts +131 -76
  429. package/src/__tests__/rpc.unit.test.ts +46 -80
  430. package/src/__tests__/signOperation.unit.test.ts +27 -25
  431. package/src/__tests__/synchronization.unit.test.ts +101 -153
  432. package/src/__tests__/transaction.unit.test.ts +6 -14
  433. package/src/adapters.ts +8 -18
  434. package/src/api/{etherscan.ts → explorer/etherscan.ts} +14 -29
  435. package/src/api/explorer/index.ts +34 -0
  436. package/src/api/gasTracker/index.ts +31 -0
  437. package/src/api/gasTracker/ledger.ts +103 -0
  438. package/src/api/{rpc.common.ts → rpc/rpc.common.ts} +41 -64
  439. package/src/bridge/js.ts +15 -22
  440. package/src/bridge.integration.test.ts +3 -10
  441. package/src/broadcast.ts +3 -7
  442. package/src/buildOptimisticOperation.ts +7 -17
  443. package/src/cli-transaction.ts +1 -7
  444. package/src/createTransaction.ts +14 -15
  445. package/src/deviceTransactionConfig.ts +1 -1
  446. package/src/errors.ts +6 -0
  447. package/src/estimateMaxSpendable.ts +14 -11
  448. package/src/getTransactionStatus.ts +41 -52
  449. package/src/hw-getAddress.ts +18 -19
  450. package/src/logic.ts +5 -15
  451. package/src/preload.ts +6 -16
  452. package/src/prepareTransaction.ts +30 -31
  453. package/src/signOperation.ts +57 -69
  454. package/src/signer.ts +35 -0
  455. package/src/specs.ts +27 -52
  456. package/src/speculos-deviceActions.ts +56 -65
  457. package/src/synchronization.ts +21 -60
  458. package/src/testUtils.ts +5 -19
  459. package/src/transaction.ts +6 -10
  460. package/src/types.ts +6 -0
  461. /package/src/api/{rpc.ts → rpc/index.ts} +0 -0
  462. /package/src/api/{rpc.native.ts → rpc/rpc.native.ts} +0 -0
@@ -1,12 +1,8 @@
1
1
  import BigNumber from "bignumber.js";
2
2
  import { ethers } from "ethers";
3
3
  import { transactionToEthersTransaction } from "../adapters";
4
- import * as rpcAPI from "../api/rpc.common";
5
- import {
6
- fromTransactionRaw,
7
- getSerializedTransaction,
8
- toTransactionRaw,
9
- } from "../transaction";
4
+ import * as rpcAPI from "../api/rpc/rpc.common";
5
+ import { fromTransactionRaw, getSerializedTransaction, toTransactionRaw } from "../transaction";
10
6
  import {
11
7
  Transaction as EvmTransaction,
12
8
  EvmTransactionEIP1559,
@@ -134,17 +130,13 @@ describe("EVM Family", () => {
134
130
  gasPrice: ethers.BigNumber.from(10000),
135
131
  };
136
132
 
137
- expect(transactionToEthersTransaction(legacyTx)).toEqual(
138
- legacyEthersTx
139
- );
133
+ expect(transactionToEthersTransaction(legacyTx)).toEqual(legacyEthersTx);
140
134
  });
141
135
  });
142
136
 
143
137
  describe("getSerializedTransaction", () => {
144
138
  beforeAll(() => {
145
- jest
146
- .spyOn(rpcAPI, "getTransactionCount")
147
- .mockImplementation(() => Promise.resolve(0));
139
+ jest.spyOn(rpcAPI, "getTransactionCount").mockImplementation(() => Promise.resolve(0));
148
140
  });
149
141
 
150
142
  it("should serialize a type 0 transaction", async () => {
@@ -165,7 +157,7 @@ describe("EVM Family", () => {
165
157
  const serializedTx = await getSerializedTransaction(transactionLegacy);
166
158
 
167
159
  expect(serializedTx).toBe(
168
- "0xdf8064825208946775e49108cb77cda06fc3bef51bcd497602ad886480018080"
160
+ "0xdf8064825208946775e49108cb77cda06fc3bef51bcd497602ad886480018080",
169
161
  );
170
162
  });
171
163
 
@@ -188,7 +180,7 @@ describe("EVM Family", () => {
188
180
  const serializedTx = await getSerializedTransaction(transactionEIP1559);
189
181
 
190
182
  expect(serializedTx).toBe(
191
- "0x02df01806464825208946775e49108cb77cda06fc3bef51bcd497602ad886480c0"
183
+ "0x02df01806464825208946775e49108cb77cda06fc3bef51bcd497602ad886480c0",
192
184
  );
193
185
  });
194
186
  });
package/src/adapters.ts CHANGED
@@ -4,10 +4,7 @@ import BigNumber from "bignumber.js";
4
4
  import { TokenCurrency } from "@ledgerhq/types-cryptoassets";
5
5
  import { Operation, OperationType } from "@ledgerhq/types-live";
6
6
  import { findTokenByAddressInCurrency } from "@ledgerhq/cryptoassets";
7
- import {
8
- decodeAccountId,
9
- encodeTokenAccountId,
10
- } from "@ledgerhq/coin-framework/account/index";
7
+ import { decodeAccountId, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
11
8
  import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
12
9
  import {
13
10
  Transaction as EvmTransaction,
@@ -20,9 +17,7 @@ import {
20
17
  /**
21
18
  * Adapter to convert a Ledger Live transaction to an Ethers transaction
22
19
  */
23
- export const transactionToEthersTransaction = (
24
- tx: EvmTransaction
25
- ): ethers.Transaction => {
20
+ export const transactionToEthersTransaction = (tx: EvmTransaction): ethers.Transaction => {
26
21
  const ethersTx = {
27
22
  to: tx.recipient,
28
23
  value: ethers.BigNumber.from(tx.amount.toFixed()),
@@ -36,16 +31,14 @@ export const transactionToEthersTransaction = (
36
31
  // is EIP-1559 transaction (type 2)
37
32
  if (tx.type === 2) {
38
33
  ethersTx.maxFeePerGas = ethers.BigNumber.from(
39
- (tx as EvmTransactionEIP1559).maxFeePerGas.toFixed()
34
+ (tx as EvmTransactionEIP1559).maxFeePerGas.toFixed(),
40
35
  );
41
36
  ethersTx.maxPriorityFeePerGas = ethers.BigNumber.from(
42
- (tx as EvmTransactionEIP1559).maxPriorityFeePerGas.toFixed()
37
+ (tx as EvmTransactionEIP1559).maxPriorityFeePerGas.toFixed(),
43
38
  );
44
39
  } else {
45
40
  // is Legacy transaction (type 0)
46
- ethersTx.gasPrice = ethers.BigNumber.from(
47
- (tx as EvmTransactionLegacy).gasPrice.toFixed()
48
- );
41
+ ethersTx.gasPrice = ethers.BigNumber.from((tx as EvmTransactionLegacy).gasPrice.toFixed());
49
42
  }
50
43
 
51
44
  return ethersTx as ethers.Transaction;
@@ -56,7 +49,7 @@ export const transactionToEthersTransaction = (
56
49
  */
57
50
  export const etherscanOperationToOperation = (
58
51
  accountId: string,
59
- tx: EtherscanOperation
52
+ tx: EtherscanOperation,
60
53
  ): Operation => {
61
54
  const { xpubOrAddress: address } = decodeAccountId(accountId);
62
55
  const checksummedAddress = eip55.encode(address);
@@ -99,13 +92,10 @@ export const etherscanOperationToOperation = (
99
92
  */
100
93
  export const etherscanERC20EventToOperation = (
101
94
  accountId: string,
102
- event: EtherscanERC20Event
95
+ event: EtherscanERC20Event,
103
96
  ): { tokenCurrency: TokenCurrency; operation: Operation } | null => {
104
97
  const { currencyId, xpubOrAddress: address } = decodeAccountId(accountId);
105
- const tokenCurrency = findTokenByAddressInCurrency(
106
- event.contractAddress,
107
- currencyId
108
- );
98
+ const tokenCurrency = findTokenByAddressInCurrency(event.contractAddress, currencyId);
109
99
  if (!tokenCurrency) return null;
110
100
 
111
101
  const tokenAccountId = encodeTokenAccountId(accountId, tokenCurrency);
@@ -3,19 +3,16 @@ import { Operation } from "@ledgerhq/types-live";
3
3
  import axios, { AxiosRequestConfig } from "axios";
4
4
  import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
5
5
  import { makeLRUCache } from "@ledgerhq/live-network/cache";
6
- import { EtherscanERC20Event, EtherscanOperation } from "../types";
7
- import { EtherscanAPIError } from "../errors";
8
- import {
9
- etherscanERC20EventToOperation,
10
- etherscanOperationToOperation,
11
- } from "../adapters";
6
+ import { EtherscanERC20Event, EtherscanOperation } from "../../types";
7
+ import { EtherscanAPIError } from "../../errors";
8
+ import { etherscanERC20EventToOperation, etherscanOperationToOperation } from "../../adapters";
12
9
 
13
10
  export const ETHERSCAN_TIMEOUT = 5000; // 5 seconds between 2 calls
14
11
  export const DEFAULT_RETRIES_API = 8;
15
12
 
16
13
  async function fetchWithRetries<T>(
17
14
  params: AxiosRequestConfig,
18
- retries = DEFAULT_RETRIES_API
15
+ retries = DEFAULT_RETRIES_API,
19
16
  ): Promise<T> {
20
17
  try {
21
18
  const { data } = await axios.request<{
@@ -25,10 +22,10 @@ async function fetchWithRetries<T>(
25
22
  }>(params);
26
23
 
27
24
  if (!Number(data.status) && data.message === "NOTOK") {
28
- throw new EtherscanAPIError(
29
- "Error while fetching data from Etherscan like API",
30
- { params, data }
31
- );
25
+ throw new EtherscanAPIError("Error while fetching data from Etherscan like API", {
26
+ params,
27
+ data,
28
+ });
32
29
  }
33
30
 
34
31
  return data.result;
@@ -47,12 +44,7 @@ async function fetchWithRetries<T>(
47
44
  * Get all the last "normal" transactions (no tokens / NFTs)
48
45
  */
49
46
  export const getLastCoinOperations = makeLRUCache<
50
- [
51
- currency: CryptoCurrency,
52
- address: string,
53
- accountId: string,
54
- fromBlock: number
55
- ],
47
+ [currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
56
48
  Operation[]
57
49
  >(
58
50
  async (currency, address, accountId, fromBlock) => {
@@ -72,23 +64,18 @@ export const getLastCoinOperations = makeLRUCache<
72
64
  });
73
65
 
74
66
  return ops
75
- .map((tx) => etherscanOperationToOperation(accountId, tx))
67
+ .map(tx => etherscanOperationToOperation(accountId, tx))
76
68
  .filter(Boolean) as Operation[];
77
69
  },
78
70
  (currency, address, accountId, fromBlock) => accountId + fromBlock,
79
- { ttl: 5 * 1000 }
71
+ { ttl: 5 * 1000 },
80
72
  );
81
73
 
82
74
  /**
83
75
  * Get all the last ERC20 transactions
84
76
  */
85
77
  export const getLastTokenOperations = makeLRUCache<
86
- [
87
- currency: CryptoCurrency,
88
- address: string,
89
- accountId: string,
90
- fromBlock: number
91
- ],
78
+ [currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
92
79
  { tokenCurrency: TokenCurrency; operation: Operation }[]
93
80
  >(
94
81
  async (currency, address, accountId, fromBlock) => {
@@ -107,15 +94,13 @@ export const getLastTokenOperations = makeLRUCache<
107
94
  url,
108
95
  });
109
96
 
110
- return ops
111
- .map((event) => etherscanERC20EventToOperation(accountId, event))
112
- .filter(Boolean) as {
97
+ return ops.map(event => etherscanERC20EventToOperation(accountId, event)).filter(Boolean) as {
113
98
  tokenCurrency: TokenCurrency;
114
99
  operation: Operation;
115
100
  }[];
116
101
  },
117
102
  (currency, address, accountId, fromBlock) => accountId + fromBlock,
118
- { ttl: 5 * 1000 }
103
+ { ttl: 5 * 1000 },
119
104
  );
120
105
 
121
106
  export default {
@@ -0,0 +1,34 @@
1
+ import { CacheRes } from "@ledgerhq/live-network/cache";
2
+ import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
3
+ import { Operation } from "@ledgerhq/types-live";
4
+ import etherscanLikeApi from "./etherscan";
5
+
6
+ type ExplorerApi = {
7
+ getLastCoinOperations: CacheRes<
8
+ [currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
9
+ Operation[]
10
+ >;
11
+ getLastTokenOperations: CacheRes<
12
+ [currency: CryptoCurrency, address: string, accountId: string, fromBlock: number],
13
+ {
14
+ tokenCurrency: TokenCurrency;
15
+ operation: Operation;
16
+ }[]
17
+ >;
18
+ };
19
+
20
+ /**
21
+ * Switch to select one of the compatible explorer
22
+ */
23
+ export const getExplorerApi = (currency: CryptoCurrency): ExplorerApi => {
24
+ const apiType = currency.ethereumLikeInfo?.explorer?.type;
25
+
26
+ switch (apiType) {
27
+ case "etherscan":
28
+ case "blockscout":
29
+ return etherscanLikeApi;
30
+
31
+ default:
32
+ throw new Error(`No explorer found for currency "${currency.id}"`);
33
+ }
34
+ };
@@ -0,0 +1,31 @@
1
+ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
+ import { GasOptions } from "../../types";
3
+ import { getGasOptions as ledgerGetGasOptions } from "./ledger";
4
+
5
+ type GasTrackerApi = {
6
+ getGasOptions: ({
7
+ currency,
8
+ options,
9
+ }: {
10
+ currency: CryptoCurrency;
11
+ options?: {
12
+ useEIP1559: boolean;
13
+ };
14
+ }) => Promise<GasOptions>;
15
+ };
16
+
17
+ export const getGasTracker = (currency: CryptoCurrency): GasTrackerApi | null => {
18
+ switch (currency.ethereumLikeInfo?.gasTracker?.type) {
19
+ case "ledger":
20
+ return {
21
+ getGasOptions: ledgerGetGasOptions,
22
+ };
23
+
24
+ /**
25
+ * We return null instead of throwing an error because not having a gas tracker
26
+ * is not necessarily an error.
27
+ */
28
+ default:
29
+ return null;
30
+ }
31
+ };
@@ -0,0 +1,103 @@
1
+ import { getEnv } from "@ledgerhq/live-env";
2
+ import network from "@ledgerhq/live-network/network";
3
+ import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
4
+ import { BigNumber } from "bignumber.js";
5
+ import { GasOptions } from "../../types";
6
+ import { GasTrackerDoesNotSupportEIP1559, NoGasTrackerFound } from "../../errors";
7
+
8
+ type GasTracker = {
9
+ explorerId: string;
10
+ compatibilty: {
11
+ eip1559: boolean;
12
+ };
13
+ };
14
+
15
+ // FIXME: how to know if a Ledger gasTracker supports EIP1559?
16
+ // Shouldn't this be a dynamic / remote config? For example if there is an
17
+ // update of the explorer backend to support EIP1559, we should be able to
18
+ // update this config without having to release a new version of the app?
19
+ const currencyIdGasTrackerMap = new Map<CryptoCurrency["id"], GasTracker>([
20
+ ["avalanche_c_chain", { explorerId: "avax", compatibilty: { eip1559: false } }],
21
+ ["bsc", { explorerId: "bnb", compatibilty: { eip1559: false } }],
22
+ ["ethereum", { explorerId: "eth", compatibilty: { eip1559: true } }],
23
+ ["ethereum_classic", { explorerId: "etc", compatibilty: { eip1559: false } }],
24
+ ["polygon", { explorerId: "matic", compatibilty: { eip1559: true } }],
25
+ ["ethereum_ropsten", { explorerId: "eth_ropsten", compatibilty: { eip1559: true } }],
26
+ ["ethereum_goerli", { explorerId: "eth_goerli", compatibilty: { eip1559: true } }],
27
+ ]);
28
+
29
+ export const getGasOptions = async ({
30
+ currency,
31
+ options,
32
+ }: {
33
+ currency: CryptoCurrency;
34
+ options?: {
35
+ useEIP1559: boolean;
36
+ };
37
+ }): Promise<GasOptions> => {
38
+ const gasTrackerConfig = currencyIdGasTrackerMap.get(currency.id);
39
+
40
+ if (!gasTrackerConfig) {
41
+ throw new NoGasTrackerFound(`No gas tracker found for ${currency.id}`);
42
+ }
43
+
44
+ const { useEIP1559 = false } = options || {};
45
+
46
+ if (useEIP1559 && !gasTrackerConfig.compatibilty.eip1559) {
47
+ throw new GasTrackerDoesNotSupportEIP1559(
48
+ `Gas tracker does not support EIP1559 for ${currency.id}`,
49
+ );
50
+ }
51
+
52
+ const { low, medium, high, next_base } = await network({
53
+ method: "GET",
54
+ url: `${getEnv("EXPLORER")}/blockchain/v4/${gasTrackerConfig.explorerId}/gastracker/barometer${
55
+ useEIP1559 ? "?display=eip1559" : ""
56
+ }`,
57
+ }).then(({ data }) => ({
58
+ low: new BigNumber(data.low),
59
+ medium: new BigNumber(data.medium),
60
+ high: new BigNumber(data.high),
61
+ next_base: new BigNumber(data.next_base),
62
+ }));
63
+
64
+ const EIP1559_BASE_FEE_MULTIPLIER: number = getEnv("EIP1559_BASE_FEE_MULTIPLIER");
65
+
66
+ if (useEIP1559) {
67
+ return {
68
+ slow: {
69
+ maxFeePerGas: next_base.times(EIP1559_BASE_FEE_MULTIPLIER).plus(low),
70
+ maxPriorityFeePerGas: low,
71
+ gasPrice: null,
72
+ },
73
+ medium: {
74
+ maxFeePerGas: next_base.times(EIP1559_BASE_FEE_MULTIPLIER).plus(medium),
75
+ maxPriorityFeePerGas: medium,
76
+ gasPrice: null,
77
+ },
78
+ fast: {
79
+ maxFeePerGas: next_base.times(EIP1559_BASE_FEE_MULTIPLIER).plus(high),
80
+ maxPriorityFeePerGas: high,
81
+ gasPrice: null,
82
+ },
83
+ };
84
+ }
85
+
86
+ return {
87
+ slow: {
88
+ gasPrice: low,
89
+ maxFeePerGas: null,
90
+ maxPriorityFeePerGas: null,
91
+ },
92
+ medium: {
93
+ gasPrice: medium,
94
+ maxFeePerGas: null,
95
+ maxPriorityFeePerGas: null,
96
+ },
97
+ fast: {
98
+ gasPrice: high,
99
+ maxFeePerGas: null,
100
+ maxPriorityFeePerGas: null,
101
+ },
102
+ };
103
+ };
@@ -6,12 +6,12 @@ import { delay } from "@ledgerhq/live-promise";
6
6
  import { Account } from "@ledgerhq/types-live";
7
7
  import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
8
8
  import { makeLRUCache } from "@ledgerhq/live-network/cache";
9
- import OptimismGasPriceOracleAbi from "../abis/optimismGasPriceOracle.abi.json";
10
- import { FeeData, FeeHistory, Transaction as EvmTransaction } from "../types";
11
- import { GasEstimationError, InsufficientFunds } from "../errors";
12
- import { transactionToEthersTransaction } from "../adapters";
13
- import { getSerializedTransaction } from "../transaction";
14
- import ERC20Abi from "../abis/erc20.abi.json";
9
+ import OptimismGasPriceOracleAbi from "../../abis/optimismGasPriceOracle.abi.json";
10
+ import { FeeData, FeeHistory, Transaction as EvmTransaction } from "../../types";
11
+ import { GasEstimationError, InsufficientFunds } from "../../errors";
12
+ import { transactionToEthersTransaction } from "../../adapters";
13
+ import { getSerializedTransaction } from "../../transaction";
14
+ import ERC20Abi from "../../abis/erc20.abi.json";
15
15
 
16
16
  export const RPC_TIMEOUT = 5000; // wait 5 sec after a fail
17
17
  export const DEFAULT_RETRIES_RPC_METHODS = 3;
@@ -22,8 +22,7 @@ export const DEFAULT_RETRIES_RPC_METHODS = 3;
22
22
  * at instanciation which could result in rate limits being reached
23
23
  * on some specific nodes (E.g. the main Optimism RPC)
24
24
  */
25
- const PROVIDERS_BY_RPC: Record<string, ethers.providers.StaticJsonRpcProvider> =
26
- {};
25
+ const PROVIDERS_BY_RPC: Record<string, ethers.providers.StaticJsonRpcProvider> = {};
27
26
 
28
27
  /**
29
28
  * Connects to RPC Node
@@ -36,7 +35,7 @@ const PROVIDERS_BY_RPC: Record<string, ethers.providers.StaticJsonRpcProvider> =
36
35
  export async function withApi<T>(
37
36
  currency: CryptoCurrency,
38
37
  execute: (api: ethers.providers.StaticJsonRpcProvider) => Promise<T>,
39
- retries = DEFAULT_RETRIES_RPC_METHODS
38
+ retries = DEFAULT_RETRIES_RPC_METHODS,
40
39
  ): Promise<T> {
41
40
  if (!currency?.ethereumLikeInfo?.rpc) {
42
41
  throw new Error("Currency doesn't have an RPC node provided");
@@ -44,10 +43,9 @@ export async function withApi<T>(
44
43
 
45
44
  try {
46
45
  if (!PROVIDERS_BY_RPC[currency.ethereumLikeInfo.rpc]) {
47
- PROVIDERS_BY_RPC[currency.ethereumLikeInfo.rpc] =
48
- new ethers.providers.StaticJsonRpcProvider(
49
- currency.ethereumLikeInfo.rpc
50
- );
46
+ PROVIDERS_BY_RPC[currency.ethereumLikeInfo.rpc] = new ethers.providers.StaticJsonRpcProvider(
47
+ currency.ethereumLikeInfo.rpc,
48
+ );
51
49
  }
52
50
 
53
51
  const provider = PROVIDERS_BY_RPC[currency.ethereumLikeInfo.rpc];
@@ -68,12 +66,9 @@ export async function withApi<T>(
68
66
  */
69
67
  export const getBalanceAndBlock: (
70
68
  currency: CryptoCurrency,
71
- addr: string
72
- ) => Promise<{ blockHeight: number; balance: BigNumber }> = async (
73
- currency,
74
- addr
75
- ) =>
76
- withApi(currency, async (api) => {
69
+ addr: string,
70
+ ) => Promise<{ blockHeight: number; balance: BigNumber }> = async (currency, addr) =>
71
+ withApi(currency, async api => {
77
72
  const [balance, blockHeight] = await Promise.all([
78
73
  getCoinBalance(currency, addr),
79
74
  api.getBlockNumber(),
@@ -90,20 +85,17 @@ export const getBalanceAndBlock: (
90
85
  */
91
86
  export const getTransaction = (
92
87
  currency: CryptoCurrency,
93
- hash: string
88
+ hash: string,
94
89
  ): Promise<ethers.providers.TransactionResponse> =>
95
- withApi(currency, (api) => {
90
+ withApi(currency, api => {
96
91
  return api.getTransaction(hash);
97
92
  });
98
93
 
99
94
  /**
100
95
  * Get the balance of an address
101
96
  */
102
- export const getCoinBalance = (
103
- currency: CryptoCurrency,
104
- address: string
105
- ): Promise<BigNumber> =>
106
- withApi(currency, async (api) => {
97
+ export const getCoinBalance = (currency: CryptoCurrency, address: string): Promise<BigNumber> =>
98
+ withApi(currency, async api => {
107
99
  const balance = await api.getBalance(address);
108
100
  return new BigNumber(balance.toString());
109
101
  });
@@ -114,9 +106,9 @@ export const getCoinBalance = (
114
106
  export const getTokenBalance = (
115
107
  currency: CryptoCurrency,
116
108
  address: string,
117
- contractAddress: string
109
+ contractAddress: string,
118
110
  ): Promise<BigNumber> =>
119
- withApi(currency, async (api) => {
111
+ withApi(currency, async api => {
120
112
  const erc20 = new ethers.Contract(contractAddress, ERC20Abi, api);
121
113
  const balance = await erc20.balanceOf(address);
122
114
  return new BigNumber(balance.toString());
@@ -125,11 +117,8 @@ export const getTokenBalance = (
125
117
  /**
126
118
  * Get account nonce
127
119
  */
128
- export const getTransactionCount = (
129
- currency: CryptoCurrency,
130
- addr: string
131
- ): Promise<number> =>
132
- withApi(currency, async (api) => {
120
+ export const getTransactionCount = (currency: CryptoCurrency, addr: string): Promise<number> =>
121
+ withApi(currency, async api => {
133
122
  return api.getTransactionCount(addr);
134
123
  });
135
124
 
@@ -138,9 +127,9 @@ export const getTransactionCount = (
138
127
  */
139
128
  export const getGasEstimation = (
140
129
  account: Account,
141
- transaction: EvmTransaction
130
+ transaction: EvmTransaction,
142
131
  ): Promise<BigNumber> =>
143
- withApi(account.currency, async (api) => {
132
+ withApi(account.currency, async api => {
144
133
  const { to, value, data } = transactionToEthersTransaction(transaction);
145
134
 
146
135
  try {
@@ -162,7 +151,7 @@ export const getGasEstimation = (
162
151
  * Get an estimation of fees on the network
163
152
  */
164
153
  export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
165
- withApi(currency, async (api) => {
154
+ withApi(currency, async api => {
166
155
  const block = await api.getBlock("latest");
167
156
  const currencySupports1559 = Boolean(block.baseFeePerGas);
168
157
 
@@ -175,10 +164,7 @@ export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
175
164
  ]);
176
165
  // Taking the average priority fee used on the last 5 blocks
177
166
  const maxPriorityFeeAverage = feeHistory.reward
178
- .reduce(
179
- (acc, [curr]) => acc.plus(new BigNumber(curr)),
180
- new BigNumber(0)
181
- )
167
+ .reduce((acc, [curr]) => acc.plus(new BigNumber(curr)), new BigNumber(0))
182
168
  .dividedToIntegerBy(feeHistory.reward.length);
183
169
 
184
170
  // A maxPriorityFeePerGas too low might make a transaction stuck forever
@@ -189,7 +175,7 @@ export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
189
175
  : maxPriorityFeeAverage;
190
176
 
191
177
  const nextBaseFee = new BigNumber(
192
- feeHistory.baseFeePerGas[feeHistory.baseFeePerGas.length - 1]
178
+ feeHistory.baseFeePerGas[feeHistory.baseFeePerGas.length - 1],
193
179
  );
194
180
 
195
181
  return {
@@ -206,15 +192,11 @@ export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
206
192
  })();
207
193
 
208
194
  return {
209
- maxFeePerGas: feeData.maxFeePerGas
210
- ? new BigNumber(feeData.maxFeePerGas.toString())
211
- : null,
195
+ maxFeePerGas: feeData.maxFeePerGas ? new BigNumber(feeData.maxFeePerGas.toString()) : null,
212
196
  maxPriorityFeePerGas: feeData.maxPriorityFeePerGas
213
197
  ? new BigNumber(feeData.maxPriorityFeePerGas.toString())
214
198
  : null,
215
- gasPrice: feeData.gasPrice
216
- ? new BigNumber(feeData.gasPrice.toString())
217
- : null,
199
+ gasPrice: feeData.gasPrice ? new BigNumber(feeData.gasPrice.toString()) : null,
218
200
  };
219
201
  });
220
202
 
@@ -223,11 +205,11 @@ export const getFeesEstimation = (currency: CryptoCurrency): Promise<FeeData> =>
223
205
  */
224
206
  export const broadcastTransaction = (
225
207
  currency: CryptoCurrency,
226
- signedTxHex: string
208
+ signedTxHex: string,
227
209
  ): Promise<ethers.providers.TransactionResponse> =>
228
210
  withApi(
229
211
  currency,
230
- async (api) => {
212
+ async api => {
231
213
  try {
232
214
  return await api.sendTransaction(signedTxHex);
233
215
  } catch (e) {
@@ -238,7 +220,7 @@ export const broadcastTransaction = (
238
220
  throw e;
239
221
  }
240
222
  },
241
- 0
223
+ 0,
242
224
  );
243
225
 
244
226
  /**
@@ -246,9 +228,9 @@ export const broadcastTransaction = (
246
228
  */
247
229
  export const getBlock = (
248
230
  currency: CryptoCurrency,
249
- blockHeight: number
231
+ blockHeight: number,
250
232
  ): Promise<ethers.providers.Block> =>
251
- withApi(currency, async (api) => {
233
+ withApi(currency, async api => {
252
234
  return api.getBlock(blockHeight);
253
235
  });
254
236
 
@@ -257,13 +239,13 @@ export const getBlock = (
257
239
  */
258
240
  export const getSubAccount: (
259
241
  currency: CryptoCurrency,
260
- addr: string
242
+ addr: string,
261
243
  ) => Promise<{
262
244
  blockHeight: number;
263
245
  balance: BigNumber;
264
246
  nonce: number;
265
247
  }> = async (currency, addr) =>
266
- withApi(currency, async (api) => {
248
+ withApi(currency, async api => {
267
249
  const [balance, nonce, blockHeight] = await Promise.all([
268
250
  getCoinBalance(currency, addr),
269
251
  getTransactionCount(currency, addr),
@@ -286,12 +268,9 @@ export const getSubAccount: (
286
268
  *
287
269
  * @see https://help.optimism.io/hc/en-us/articles/4411895794715-How-do-transaction-fees-on-Optimism-work-
288
270
  */
289
- export const getOptimismAdditionalFees = makeLRUCache<
290
- [CryptoCurrency, EvmTransaction],
291
- BigNumber
292
- >(
271
+ export const getOptimismAdditionalFees = makeLRUCache<[CryptoCurrency, EvmTransaction], BigNumber>(
293
272
  async (currency, transaction) =>
294
- withApi(currency, async (api) => {
273
+ withApi(currency, async api => {
295
274
  if (!["optimism", "optimism_goerli"].includes(currency.id)) {
296
275
  return new BigNumber(0);
297
276
  }
@@ -317,11 +296,9 @@ export const getOptimismAdditionalFees = makeLRUCache<
317
296
  // @see https://community.optimism.io/docs/developers/build/transaction-fees/#displaying-fees-to-users
318
297
  "0x420000000000000000000000000000000000000F",
319
298
  OptimismGasPriceOracleAbi,
320
- api
321
- );
322
- const additionalL1Fees = await optimismGasOracle.getL1Fee(
323
- serializedTransaction
299
+ api,
324
300
  );
301
+ const additionalL1Fees = await optimismGasOracle.getL1Fee(serializedTransaction);
325
302
  return new BigNumber(additionalL1Fees.toString());
326
303
  }),
327
304
  (currency, transaction) => {
@@ -335,7 +312,7 @@ export const getOptimismAdditionalFees = makeLRUCache<
335
312
 
336
313
  return "getOptimismL1BaseFee_" + currency.id + "_" + serializedTransaction;
337
314
  },
338
- { ttl: 15 * 1000 } // preventing rate limit by caching this for at least 15sec
315
+ { ttl: 15 * 1000 }, // preventing rate limit by caching this for at least 15sec
339
316
  );
340
317
 
341
318
  export default {