@ledgerhq/coin-evm 2.28.0-nightly.3 → 2.28.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 (260) hide show
  1. package/.eslintrc.js +0 -1
  2. package/.turbo/turbo-build.log +1 -1
  3. package/CHANGELOG.md +20 -32
  4. package/{lib-es/__fixtures__/ethereum-erc20-weth.json → lib/__fixtures__/ethereum-erc20-usd_tether__erc20_.json} +8 -8
  5. package/lib/__fixtures__/{optimism-erc20-usd_coin.json → scroll_sepolia-erc20-new_token_mock.json} +20 -21
  6. package/lib/__tests__/fixtures/accounts.fixtures.d.ts +1 -1
  7. package/lib/__tests__/fixtures/accounts.fixtures.d.ts.map +1 -1
  8. package/lib/__tests__/fixtures/accounts.fixtures.js +19 -2
  9. package/lib/__tests__/fixtures/accounts.fixtures.js.map +1 -1
  10. package/lib/__tests__/fixtures/common.fixtures.d.ts +0 -1
  11. package/lib/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
  12. package/lib/__tests__/fixtures/common.fixtures.js +0 -1
  13. package/lib/__tests__/fixtures/common.fixtures.js.map +1 -1
  14. package/lib/__tests__/fixtures/prepareTransaction.fixtures.d.ts.map +1 -1
  15. package/lib/__tests__/fixtures/prepareTransaction.fixtures.js +2 -3
  16. package/lib/__tests__/fixtures/prepareTransaction.fixtures.js.map +1 -1
  17. package/lib/__tests__/fixtures/synchronization.fixtures.d.ts +1 -1
  18. package/lib/__tests__/fixtures/synchronization.fixtures.d.ts.map +1 -1
  19. package/lib/__tests__/fixtures/synchronization.fixtures.js +18 -3
  20. package/lib/__tests__/fixtures/synchronization.fixtures.js.map +1 -1
  21. package/lib/__tests__/fixtures/transaction.fixtures.d.ts +2 -2
  22. package/lib/__tests__/fixtures/transaction.fixtures.d.ts.map +1 -1
  23. package/lib/__tests__/fixtures/transaction.fixtures.js +2 -3
  24. package/lib/__tests__/fixtures/transaction.fixtures.js.map +1 -1
  25. package/lib/__tests__/unit/accounts.unit.test.js +27 -0
  26. package/lib/__tests__/unit/accounts.unit.test.js.map +1 -1
  27. package/lib/__tests__/unit/adapters/etherscan.unit.test.js +7 -72
  28. package/lib/__tests__/unit/adapters/etherscan.unit.test.js.map +1 -1
  29. package/lib/__tests__/unit/adapters/ledger.unit.test.js +2 -15
  30. package/lib/__tests__/unit/adapters/ledger.unit.test.js.map +1 -1
  31. package/lib/__tests__/unit/api/explorer/etherscan.unit.test.js +0 -8
  32. package/lib/__tests__/unit/api/explorer/etherscan.unit.test.js.map +1 -1
  33. package/lib/__tests__/unit/api/explorer/ledger.unit.test.js +0 -12
  34. package/lib/__tests__/unit/api/explorer/ledger.unit.test.js.map +1 -1
  35. package/lib/__tests__/unit/broadcast.unit.test.js +1 -3
  36. package/lib/__tests__/unit/broadcast.unit.test.js.map +1 -1
  37. package/lib/__tests__/unit/buildOptimisticOperation.unit.test.js +1 -3
  38. package/lib/__tests__/unit/buildOptimisticOperation.unit.test.js.map +1 -1
  39. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +1 -1
  40. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -1
  41. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js +0 -1
  42. package/lib/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
  43. package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js +1 -3
  44. package/lib/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -1
  45. package/lib/__tests__/unit/getTransactionStatus.unit.test.js +1 -3
  46. package/lib/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -1
  47. package/lib/__tests__/unit/logic.unit.test.js +18 -22
  48. package/lib/__tests__/unit/logic.unit.test.js.map +1 -1
  49. package/lib/__tests__/unit/operation.test.js +2 -6
  50. package/lib/__tests__/unit/operation.test.js.map +1 -1
  51. package/lib/__tests__/unit/prepareTransaction.unit.test.js +17 -4
  52. package/lib/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
  53. package/lib/adapters/etherscan.d.ts.map +1 -1
  54. package/lib/adapters/etherscan.js +2 -2
  55. package/lib/adapters/etherscan.js.map +1 -1
  56. package/lib/adapters/ledger.d.ts.map +1 -1
  57. package/lib/adapters/ledger.js +2 -2
  58. package/lib/adapters/ledger.js.map +1 -1
  59. package/lib/api/index.d.ts.map +1 -1
  60. package/lib/api/index.js +4 -2
  61. package/lib/api/index.js.map +1 -1
  62. package/lib/bridge/js.d.ts +1 -2
  63. package/lib/bridge/js.d.ts.map +1 -1
  64. package/lib/bridge/js.js +1 -3
  65. package/lib/bridge/js.js.map +1 -1
  66. package/lib/bridge/preload.d.ts +0 -1
  67. package/lib/bridge/preload.d.ts.map +1 -1
  68. package/lib/bridge/preload.js +1 -10
  69. package/lib/bridge/preload.js.map +1 -1
  70. package/lib/deviceTransactionConfig.d.ts.map +1 -1
  71. package/lib/deviceTransactionConfig.js +2 -2
  72. package/lib/deviceTransactionConfig.js.map +1 -1
  73. package/lib/logic/common.d.ts +0 -18
  74. package/lib/logic/common.d.ts.map +1 -1
  75. package/lib/logic/common.js +1 -35
  76. package/lib/logic/common.js.map +1 -1
  77. package/lib/logic/estimateFees.d.ts +1 -1
  78. package/lib/logic/estimateFees.d.ts.map +1 -1
  79. package/lib/logic/estimateFees.js +12 -25
  80. package/lib/logic/estimateFees.js.map +1 -1
  81. package/lib/logic/estimateFees.test.js +41 -93
  82. package/lib/logic/estimateFees.test.js.map +1 -1
  83. package/lib/logic/index.d.ts +0 -1
  84. package/lib/logic/index.d.ts.map +1 -1
  85. package/lib/logic/index.js +0 -1
  86. package/lib/logic/index.js.map +1 -1
  87. package/lib/types/transaction.d.ts +0 -9
  88. package/lib/types/transaction.d.ts.map +1 -1
  89. package/{lib/__fixtures__/ethereum-erc20-weth.json → lib-es/__fixtures__/ethereum-erc20-usd_tether__erc20_.json} +8 -8
  90. package/lib-es/__fixtures__/{optimism-erc20-usd_coin.json → scroll_sepolia-erc20-new_token_mock.json} +20 -21
  91. package/lib-es/__tests__/fixtures/accounts.fixtures.d.ts +1 -1
  92. package/lib-es/__tests__/fixtures/accounts.fixtures.d.ts.map +1 -1
  93. package/lib-es/__tests__/fixtures/accounts.fixtures.js +18 -1
  94. package/lib-es/__tests__/fixtures/accounts.fixtures.js.map +1 -1
  95. package/lib-es/__tests__/fixtures/common.fixtures.d.ts +0 -1
  96. package/lib-es/__tests__/fixtures/common.fixtures.d.ts.map +1 -1
  97. package/lib-es/__tests__/fixtures/common.fixtures.js +0 -1
  98. package/lib-es/__tests__/fixtures/common.fixtures.js.map +1 -1
  99. package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.d.ts.map +1 -1
  100. package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.js +2 -3
  101. package/lib-es/__tests__/fixtures/prepareTransaction.fixtures.js.map +1 -1
  102. package/lib-es/__tests__/fixtures/synchronization.fixtures.d.ts +1 -1
  103. package/lib-es/__tests__/fixtures/synchronization.fixtures.d.ts.map +1 -1
  104. package/lib-es/__tests__/fixtures/synchronization.fixtures.js +18 -3
  105. package/lib-es/__tests__/fixtures/synchronization.fixtures.js.map +1 -1
  106. package/lib-es/__tests__/fixtures/transaction.fixtures.d.ts +2 -2
  107. package/lib-es/__tests__/fixtures/transaction.fixtures.d.ts.map +1 -1
  108. package/lib-es/__tests__/fixtures/transaction.fixtures.js +2 -3
  109. package/lib-es/__tests__/fixtures/transaction.fixtures.js.map +1 -1
  110. package/lib-es/__tests__/unit/accounts.unit.test.js +27 -0
  111. package/lib-es/__tests__/unit/accounts.unit.test.js.map +1 -1
  112. package/lib-es/__tests__/unit/adapters/etherscan.unit.test.js +7 -72
  113. package/lib-es/__tests__/unit/adapters/etherscan.unit.test.js.map +1 -1
  114. package/lib-es/__tests__/unit/adapters/ledger.unit.test.js +2 -15
  115. package/lib-es/__tests__/unit/adapters/ledger.unit.test.js.map +1 -1
  116. package/lib-es/__tests__/unit/api/explorer/etherscan.unit.test.js +0 -8
  117. package/lib-es/__tests__/unit/api/explorer/etherscan.unit.test.js.map +1 -1
  118. package/lib-es/__tests__/unit/api/explorer/ledger.unit.test.js +0 -12
  119. package/lib-es/__tests__/unit/api/explorer/ledger.unit.test.js.map +1 -1
  120. package/lib-es/__tests__/unit/broadcast.unit.test.js +2 -4
  121. package/lib-es/__tests__/unit/broadcast.unit.test.js.map +1 -1
  122. package/lib-es/__tests__/unit/buildOptimisticOperation.unit.test.js +2 -4
  123. package/lib-es/__tests__/unit/buildOptimisticOperation.unit.test.js.map +1 -1
  124. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts +1 -1
  125. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.d.ts.map +1 -1
  126. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js +0 -1
  127. package/lib-es/__tests__/unit/deviceTransactionConfig.unit.test.js.map +1 -1
  128. package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js +2 -4
  129. package/lib-es/__tests__/unit/estimateMaxSpendable.unit.test.js.map +1 -1
  130. package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js +2 -4
  131. package/lib-es/__tests__/unit/getTransactionStatus.unit.test.js.map +1 -1
  132. package/lib-es/__tests__/unit/logic.unit.test.js +19 -23
  133. package/lib-es/__tests__/unit/logic.unit.test.js.map +1 -1
  134. package/lib-es/__tests__/unit/operation.test.js +3 -7
  135. package/lib-es/__tests__/unit/operation.test.js.map +1 -1
  136. package/lib-es/__tests__/unit/prepareTransaction.unit.test.js +17 -4
  137. package/lib-es/__tests__/unit/prepareTransaction.unit.test.js.map +1 -1
  138. package/lib-es/adapters/etherscan.d.ts.map +1 -1
  139. package/lib-es/adapters/etherscan.js +2 -2
  140. package/lib-es/adapters/etherscan.js.map +1 -1
  141. package/lib-es/adapters/ledger.d.ts.map +1 -1
  142. package/lib-es/adapters/ledger.js +2 -2
  143. package/lib-es/adapters/ledger.js.map +1 -1
  144. package/lib-es/api/index.d.ts.map +1 -1
  145. package/lib-es/api/index.js +5 -3
  146. package/lib-es/api/index.js.map +1 -1
  147. package/lib-es/bridge/js.d.ts +1 -2
  148. package/lib-es/bridge/js.d.ts.map +1 -1
  149. package/lib-es/bridge/js.js +1 -3
  150. package/lib-es/bridge/js.js.map +1 -1
  151. package/lib-es/bridge/preload.d.ts +0 -1
  152. package/lib-es/bridge/preload.d.ts.map +1 -1
  153. package/lib-es/bridge/preload.js +0 -8
  154. package/lib-es/bridge/preload.js.map +1 -1
  155. package/lib-es/deviceTransactionConfig.d.ts.map +1 -1
  156. package/lib-es/deviceTransactionConfig.js +2 -2
  157. package/lib-es/deviceTransactionConfig.js.map +1 -1
  158. package/lib-es/logic/common.d.ts +0 -18
  159. package/lib-es/logic/common.d.ts.map +1 -1
  160. package/lib-es/logic/common.js +0 -30
  161. package/lib-es/logic/common.js.map +1 -1
  162. package/lib-es/logic/estimateFees.d.ts +1 -1
  163. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  164. package/lib-es/logic/estimateFees.js +12 -25
  165. package/lib-es/logic/estimateFees.js.map +1 -1
  166. package/lib-es/logic/estimateFees.test.js +41 -93
  167. package/lib-es/logic/estimateFees.test.js.map +1 -1
  168. package/lib-es/logic/index.d.ts +0 -1
  169. package/lib-es/logic/index.d.ts.map +1 -1
  170. package/lib-es/logic/index.js +0 -1
  171. package/lib-es/logic/index.js.map +1 -1
  172. package/lib-es/types/transaction.d.ts +0 -9
  173. package/lib-es/types/transaction.d.ts.map +1 -1
  174. package/package.json +13 -13
  175. package/src/__tests__/fixtures/accounts.fixtures.ts +23 -1
  176. package/src/__tests__/fixtures/common.fixtures.ts +0 -1
  177. package/src/__tests__/fixtures/prepareTransaction.fixtures.ts +4 -4
  178. package/src/__tests__/fixtures/synchronization.fixtures.ts +20 -3
  179. package/src/__tests__/fixtures/transaction.fixtures.ts +3 -4
  180. package/src/__tests__/unit/accounts.unit.test.ts +36 -0
  181. package/src/__tests__/unit/adapters/etherscan.unit.test.ts +7 -87
  182. package/src/__tests__/unit/adapters/ledger.unit.test.ts +2 -20
  183. package/src/__tests__/unit/api/explorer/etherscan.unit.test.ts +0 -12
  184. package/src/__tests__/unit/api/explorer/ledger.unit.test.ts +0 -16
  185. package/src/__tests__/unit/broadcast.unit.test.ts +3 -5
  186. package/src/__tests__/unit/buildOptimisticOperation.unit.test.ts +2 -5
  187. package/src/__tests__/unit/deviceTransactionConfig.unit.test.ts +0 -1
  188. package/src/__tests__/unit/estimateMaxSpendable.unit.test.ts +3 -5
  189. package/src/__tests__/unit/getTransactionStatus.unit.test.ts +2 -5
  190. package/src/__tests__/unit/logic.unit.test.ts +29 -41
  191. package/src/__tests__/unit/operation.test.ts +5 -9
  192. package/src/__tests__/unit/prepareTransaction.unit.test.ts +18 -4
  193. package/src/adapters/etherscan.ts +2 -5
  194. package/src/adapters/ledger.ts +2 -5
  195. package/src/api/index.ts +5 -4
  196. package/src/bridge/js.ts +0 -4
  197. package/src/bridge/preload.ts +0 -8
  198. package/src/deviceTransactionConfig.ts +2 -3
  199. package/src/logic/common.ts +0 -52
  200. package/src/logic/estimateFees.test.ts +57 -98
  201. package/src/logic/estimateFees.ts +18 -28
  202. package/src/logic/index.ts +0 -1
  203. package/src/types/transaction.ts +0 -12
  204. package/lib/__fixtures__/cardano-native-8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc34c4f4253544552.json +0 -52
  205. package/lib/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-IN-i0.json +0 -20
  206. package/lib/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-OUT-i0.json +0 -19
  207. package/lib/__tests__/fixtures/cryptoAssetsStore.fixtures.d.ts +0 -2
  208. package/lib/__tests__/fixtures/cryptoAssetsStore.fixtures.d.ts.map +0 -1
  209. package/lib/__tests__/fixtures/cryptoAssetsStore.fixtures.js +0 -44
  210. package/lib/__tests__/fixtures/cryptoAssetsStore.fixtures.js.map +0 -1
  211. package/lib/cryptoAssetsStore.d.ts +0 -5
  212. package/lib/cryptoAssetsStore.d.ts.map +0 -1
  213. package/lib/cryptoAssetsStore.js +0 -17
  214. package/lib/cryptoAssetsStore.js.map +0 -1
  215. package/lib/cryptoAssetsStore.test.d.ts +0 -2
  216. package/lib/cryptoAssetsStore.test.d.ts.map +0 -1
  217. package/lib/cryptoAssetsStore.test.js +0 -15
  218. package/lib/cryptoAssetsStore.test.js.map +0 -1
  219. package/lib/logic/validateIntent.d.ts +0 -4
  220. package/lib/logic/validateIntent.d.ts.map +0 -1
  221. package/lib/logic/validateIntent.js +0 -192
  222. package/lib/logic/validateIntent.js.map +0 -1
  223. package/lib/logic/validateIntent.test.d.ts +0 -2
  224. package/lib/logic/validateIntent.test.d.ts.map +0 -1
  225. package/lib/logic/validateIntent.test.js +0 -485
  226. package/lib/logic/validateIntent.test.js.map +0 -1
  227. package/lib-es/__fixtures__/cardano-native-8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc34c4f4253544552.json +0 -52
  228. package/lib-es/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-IN-i0.json +0 -20
  229. package/lib-es/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-OUT-i0.json +0 -19
  230. package/lib-es/__tests__/fixtures/cryptoAssetsStore.fixtures.d.ts +0 -2
  231. package/lib-es/__tests__/fixtures/cryptoAssetsStore.fixtures.d.ts.map +0 -1
  232. package/lib-es/__tests__/fixtures/cryptoAssetsStore.fixtures.js +0 -19
  233. package/lib-es/__tests__/fixtures/cryptoAssetsStore.fixtures.js.map +0 -1
  234. package/lib-es/cryptoAssetsStore.d.ts +0 -5
  235. package/lib-es/cryptoAssetsStore.d.ts.map +0 -1
  236. package/lib-es/cryptoAssetsStore.js +0 -12
  237. package/lib-es/cryptoAssetsStore.js.map +0 -1
  238. package/lib-es/cryptoAssetsStore.test.d.ts +0 -2
  239. package/lib-es/cryptoAssetsStore.test.d.ts.map +0 -1
  240. package/lib-es/cryptoAssetsStore.test.js +0 -13
  241. package/lib-es/cryptoAssetsStore.test.js.map +0 -1
  242. package/lib-es/logic/validateIntent.d.ts +0 -4
  243. package/lib-es/logic/validateIntent.d.ts.map +0 -1
  244. package/lib-es/logic/validateIntent.js +0 -185
  245. package/lib-es/logic/validateIntent.js.map +0 -1
  246. package/lib-es/logic/validateIntent.test.d.ts +0 -2
  247. package/lib-es/logic/validateIntent.test.d.ts.map +0 -1
  248. package/lib-es/logic/validateIntent.test.js +0 -480
  249. package/lib-es/logic/validateIntent.test.js.map +0 -1
  250. package/src/__fixtures__/cardano-native-8654e8b350e298c80d2451beb5ed80fc9eee9f38ce6b039fb8706bc34c4f4253544552.json +0 -52
  251. package/src/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-IN-i0.json +0 -20
  252. package/src/__fixtures__/ethereum-erc20-usd__coin-0x02b972f304dc24c9bc362e6435c4ad654241f9af916689a4790145c9bcbdf4cf-OUT-i0.json +0 -19
  253. package/src/__fixtures__/ethereum-erc20-usd__coin-0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48.json +0 -73
  254. package/src/__fixtures__/ethereum-erc20-weth.json +0 -73
  255. package/src/__fixtures__/optimism-erc20-usd_coin.json +0 -69
  256. package/src/__tests__/fixtures/cryptoAssetsStore.fixtures.ts +0 -24
  257. package/src/cryptoAssetsStore.test.ts +0 -19
  258. package/src/cryptoAssetsStore.ts +0 -16
  259. package/src/logic/validateIntent.test.ts +0 -659
  260. package/src/logic/validateIntent.ts +0 -274
@@ -1,659 +0,0 @@
1
- import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
2
- import {
3
- AmountRequired,
4
- ETHAddressNonEIP,
5
- FeeNotLoaded,
6
- GasLessThanEstimate,
7
- InvalidAddress,
8
- MaxFeeTooLow,
9
- NotEnoughBalance,
10
- NotEnoughGas,
11
- PriorityFeeHigherThanMaxFee,
12
- PriorityFeeTooHigh,
13
- PriorityFeeTooLow,
14
- RecipientRequired,
15
- } from "@ledgerhq/errors";
16
- import { TransactionIntent } from "@ledgerhq/coin-framework/api/types";
17
- import BigNumber from "bignumber.js";
18
- import { Operation } from "@ledgerhq/types-live";
19
- import { EvmCoinConfig, setCoinConfig } from "../config";
20
- import ledgerNode from "../network/node/ledger";
21
- import ledgerExplorer from "../network/explorer/ledger";
22
- import ledgerGasTracker from "../network/gasTracker/ledger";
23
- import { validateIntent } from "./validateIntent";
24
-
25
- function legacyIntent(intent: Omit<Partial<TransactionIntent>, "type">): TransactionIntent {
26
- return {
27
- type: "send-legacy",
28
- sender: "",
29
- recipient: "",
30
- amount: 0n,
31
- asset: { type: "native" },
32
- ...intent,
33
- };
34
- }
35
-
36
- function eip1559Intent(intent: Omit<Partial<TransactionIntent>, "type">): TransactionIntent {
37
- return {
38
- type: "send-eip1559",
39
- sender: "",
40
- recipient: "",
41
- amount: 0n,
42
- asset: { type: "native" },
43
- ...intent,
44
- };
45
- }
46
-
47
- describe("validateIntent", () => {
48
- beforeEach(() => {
49
- setCoinConfig(
50
- () =>
51
- ({
52
- info: {
53
- node: { type: "ledger" },
54
- explorer: { type: "ledger" },
55
- gasTracker: { type: "ledger", explorerId: "eth" },
56
- },
57
- }) as unknown as EvmCoinConfig,
58
- );
59
-
60
- jest.spyOn(ledgerNode, "getGasEstimation").mockResolvedValue(new BigNumber(0));
61
- jest.spyOn(ledgerNode, "getFeeData").mockResolvedValue({
62
- maxFeePerGas: null,
63
- maxPriorityFeePerGas: null,
64
- gasPrice: null,
65
- nextBaseFee: null,
66
- });
67
- jest.spyOn(ledgerExplorer, "getLastOperations").mockResolvedValue({
68
- lastCoinOperations: [],
69
- lastInternalOperations: [],
70
- lastNftOperations: [],
71
- lastTokenOperations: [],
72
- });
73
- jest.spyOn(ledgerNode, "getCoinBalance").mockResolvedValue(new BigNumber(50));
74
- jest.spyOn(ledgerGasTracker, "getGasOptions").mockResolvedValue({
75
- slow: {
76
- maxFeePerGas: null,
77
- maxPriorityFeePerGas: null,
78
- gasPrice: null,
79
- nextBaseFee: null,
80
- },
81
- medium: {
82
- maxFeePerGas: null,
83
- maxPriorityFeePerGas: null,
84
- gasPrice: null,
85
- nextBaseFee: null,
86
- },
87
- fast: {
88
- maxFeePerGas: null,
89
- maxPriorityFeePerGas: null,
90
- gasPrice: null,
91
- nextBaseFee: null,
92
- },
93
- });
94
- });
95
- afterEach(() => {
96
- jest.restoreAllMocks();
97
- });
98
-
99
- describe("recipient", () => {
100
- it("detects the missing recipient with an error", async () => {
101
- const res = await validateIntent(
102
- {} as CryptoCurrency,
103
- eip1559Intent({ amount: 1n, recipient: "" }),
104
- );
105
-
106
- expect(res.errors).toEqual(
107
- expect.objectContaining({
108
- recipient: new RecipientRequired(),
109
- }),
110
- );
111
- });
112
-
113
- it("detects the incorrect recipient not being an eth address with an error", async () => {
114
- const res = await validateIntent(
115
- { name: "Ethereum" } as CryptoCurrency,
116
- eip1559Intent({ amount: 1n, recipient: "invalid-address" }),
117
- );
118
-
119
- expect(res.errors).toEqual(
120
- expect.objectContaining({
121
- recipient: new InvalidAddress("", {
122
- currencyName: "Ethereum",
123
- }),
124
- }),
125
- );
126
- });
127
-
128
- it("detects the recipient being an ICAP with an error", async () => {
129
- const res = await validateIntent(
130
- { name: "Ethereum" } as CryptoCurrency,
131
- eip1559Intent({
132
- amount: 1n,
133
- recipient: "XE89MW3Y75UITCQ4F53YDKR25UFLB1640YM", // ICAP version of recipient address
134
- }),
135
- );
136
- expect(res.errors).toEqual(
137
- expect.objectContaining({
138
- recipient: new InvalidAddress("", {
139
- currencyName: "Ethereum",
140
- }),
141
- }),
142
- );
143
- });
144
-
145
- it("detects the recipient not being an EIP55 address with a warning", async () => {
146
- const res = await validateIntent(
147
- { name: "Ethereum" } as CryptoCurrency,
148
- eip1559Intent({ amount: 1n, recipient: "0xe2ca7390e76c5a992749bb622087310d2e63ca29" }),
149
- );
150
-
151
- expect(res.warnings).toEqual(
152
- expect.objectContaining({
153
- recipient: new ETHAddressNonEIP(),
154
- }),
155
- );
156
- });
157
- });
158
-
159
- describe("amount", () => {
160
- it("detects an intent for native asset sending without amount with an error", async () => {
161
- const res = await validateIntent(
162
- {} as CryptoCurrency,
163
- eip1559Intent({
164
- amount: 0n,
165
- asset: { type: "native" },
166
- }),
167
- );
168
-
169
- expect(res.errors).toEqual(
170
- expect.objectContaining({
171
- amount: new AmountRequired(),
172
- }),
173
- );
174
- });
175
-
176
- it("detects an intent for token asset sending without amount with an error", async () => {
177
- const res = await validateIntent(
178
- {} as CryptoCurrency,
179
- eip1559Intent({
180
- recipient: "0xe2ca7390e76c5A992749bB622087310d2e63ca29",
181
- amount: 0n,
182
- asset: { type: "erc20" },
183
- }),
184
- );
185
-
186
- expect(res.errors).toEqual(
187
- expect.objectContaining({
188
- amount: new AmountRequired(),
189
- }),
190
- );
191
- });
192
-
193
- it("detects native asset sending intent with an error", async () => {
194
- jest.spyOn(ledgerNode, "getCoinBalance").mockResolvedValue(new BigNumber(10));
195
- const res = await validateIntent(
196
- {} as CryptoCurrency,
197
- eip1559Intent({
198
- amount: 20n,
199
- asset: { type: "native" },
200
- }),
201
- );
202
-
203
- expect(res.errors).toEqual(
204
- expect.objectContaining({
205
- amount: new NotEnoughBalance(),
206
- }),
207
- );
208
- });
209
-
210
- it("detects token asset sending intent with an error", async () => {
211
- jest.spyOn(ledgerExplorer, "getLastOperations").mockResolvedValue({
212
- lastCoinOperations: [],
213
- lastInternalOperations: [],
214
- lastNftOperations: [],
215
- lastTokenOperations: [{ contract: "contract-address" } as Operation],
216
- });
217
- const getTokenBalance = jest
218
- .spyOn(ledgerNode, "getTokenBalance")
219
- .mockResolvedValue(new BigNumber(10));
220
-
221
- const res = await validateIntent(
222
- {} as CryptoCurrency,
223
- eip1559Intent({
224
- sender: "sender-address",
225
- recipient: "0xe2ca7390e76c5A992749bB622087310d2e63ca29",
226
- amount: 20n,
227
- asset: { type: "erc20", assetReference: "contract-adress" },
228
- }),
229
- );
230
-
231
- expect(res.errors).toEqual(
232
- expect.objectContaining({
233
- amount: new NotEnoughBalance(),
234
- }),
235
- );
236
- expect(getTokenBalance).toHaveBeenCalledWith({}, "sender-address", "contract-address");
237
- });
238
- });
239
-
240
- describe("gas", () => {
241
- describe("common", () => {
242
- describe.each([
243
- ["a legacy intent", legacyIntent],
244
- ["an eip1559 intent", eip1559Intent],
245
- ])("for %s", (_s, createIntent) => {
246
- it("detects missing fees with an error", async () => {
247
- const res = await validateIntent({} as CryptoCurrency, createIntent({}), { value: 0n });
248
-
249
- expect(res.errors).toEqual(
250
- expect.objectContaining({
251
- gasPrice: new FeeNotLoaded(),
252
- }),
253
- );
254
- });
255
-
256
- it("detects a missing gasLimit with an error", async () => {
257
- const res = await validateIntent({} as CryptoCurrency, createIntent({}), {
258
- value: 0n,
259
- parameters: { gasLimit: undefined },
260
- });
261
-
262
- expect(res.errors).toEqual(
263
- expect.objectContaining({
264
- gasLimit: new FeeNotLoaded(),
265
- }),
266
- );
267
- });
268
-
269
- it("detects a gasLimit = 0 with an error", async () => {
270
- const res = await validateIntent({} as CryptoCurrency, createIntent({}), {
271
- value: 0n,
272
- parameters: { gasLimit: 0n },
273
- });
274
-
275
- expect(res.errors).toEqual(
276
- expect.objectContaining({
277
- gasLimit: new FeeNotLoaded(),
278
- }),
279
- );
280
- });
281
-
282
- it("detects a customGasLimit = 0 with an error", async () => {
283
- const res = await validateIntent({} as CryptoCurrency, createIntent({}), {
284
- value: 0n,
285
- parameters: { customGasLimit: 0n },
286
- });
287
-
288
- expect(res.errors).toEqual(
289
- expect.objectContaining({
290
- gasLimit: new FeeNotLoaded(),
291
- }),
292
- );
293
- });
294
-
295
- it("if the recipient has been set, detects fees being too high for the account balance with an error", async () => {
296
- jest.spyOn(ledgerNode, "getCoinBalance").mockResolvedValue(new BigNumber(10));
297
-
298
- const notEnoughBalanceRes = await validateIntent(
299
- { units: [{ code: "ETH", name: "ETH", magnitude: 18 }] } as CryptoCurrency,
300
- createIntent({ recipient: "recipient-address" }),
301
- {
302
- value: 11n,
303
- parameters: { gasPrice: 1n, maxFeePerGas: 1n, maxPriorityFeePerGas: 1n },
304
- },
305
- );
306
- const enoughBalanceRes = await validateIntent(
307
- { units: [{ code: "ETH", name: "ETH", magnitude: 18 }] } as CryptoCurrency,
308
- createIntent({ recipient: "recipient-address" }),
309
- {
310
- value: 9n,
311
- parameters: { gasPrice: 1n, maxFeePerGas: 1n, maxPriorityFeePerGas: 1n },
312
- },
313
- );
314
-
315
- expect(notEnoughBalanceRes.errors).toEqual(
316
- expect.objectContaining({
317
- gasPrice: new NotEnoughGas(),
318
- }),
319
- );
320
- expect(enoughBalanceRes.errors).not.toEqual(
321
- expect.objectContaining({
322
- gasPrice: new NotEnoughGas(),
323
- }),
324
- );
325
- });
326
-
327
- it("if the recipient has not been set, does not detect gas being too high", async () => {
328
- jest.spyOn(ledgerNode, "getCoinBalance").mockResolvedValue(new BigNumber(10));
329
-
330
- const notEnoughBalanceRes = await validateIntent(
331
- { units: [{ code: "ETH", name: "ETH", magnitude: 18 }] } as CryptoCurrency,
332
- createIntent({ recipient: "" }),
333
- {
334
- value: 11n,
335
- parameters: { gasPrice: 1n, maxFeePerGas: 1n, maxPriorityFeePerGas: 1n },
336
- },
337
- );
338
- const enoughBalanceRes = await validateIntent(
339
- { units: [{ code: "ETH", name: "ETH", magnitude: 18 }] } as CryptoCurrency,
340
- createIntent({ recipient: "" }),
341
- {
342
- value: 9n,
343
- parameters: { gasPrice: 1n, maxFeePerGas: 1n, maxPriorityFeePerGas: 1n },
344
- },
345
- );
346
-
347
- expect(notEnoughBalanceRes.errors).not.toEqual(
348
- expect.objectContaining({
349
- gasPrice: new NotEnoughGas(),
350
- }),
351
- );
352
- expect(enoughBalanceRes.errors).not.toEqual(
353
- expect.objectContaining({
354
- gasPrice: new NotEnoughGas(),
355
- }),
356
- );
357
- });
358
-
359
- it("detects gas limit being too low in a tx with an error", async () => {
360
- const res = await validateIntent({} as CryptoCurrency, createIntent({}), {
361
- value: 0n,
362
- parameters: { gasLimit: 20000n }, // min should be 21000
363
- });
364
-
365
- expect(res.errors).toEqual(
366
- expect.objectContaining({
367
- gasLimit: new GasLessThanEstimate(),
368
- }),
369
- );
370
- });
371
-
372
- it("detects custom gas limit being too low in a tx with an error", async () => {
373
- const res = await validateIntent({} as CryptoCurrency, createIntent({}), {
374
- value: 0n,
375
- parameters: { customGasLimit: 20000n }, // min should be 21000
376
- });
377
-
378
- expect(res.errors).toEqual(
379
- expect.objectContaining({
380
- gasLimit: new GasLessThanEstimate(),
381
- }),
382
- );
383
- });
384
-
385
- it("detects customGasLimit being lower than gasLimit with a warning", async () => {
386
- const res = await validateIntent({} as CryptoCurrency, createIntent({}), {
387
- value: 0n,
388
- parameters: {
389
- gasLimit: 22000n,
390
- customGasLimit: 21000n,
391
- },
392
- });
393
-
394
- expect(res.warnings).toEqual(
395
- expect.objectContaining({
396
- gasLimit: new GasLessThanEstimate(),
397
- }),
398
- );
399
- });
400
- });
401
- });
402
-
403
- describe("eip1559 specific", () => {
404
- it("detects a maxPriorityFeePerGas = 0 with an error", async () => {
405
- const res = await validateIntent({} as CryptoCurrency, eip1559Intent({}), {
406
- value: 0n,
407
- parameters: { maxPriorityFeePerGas: 0n, maxFeePerGas: 2n },
408
- });
409
-
410
- expect(res.errors).toEqual(
411
- expect.objectContaining({
412
- maxPriorityFee: new PriorityFeeTooLow(),
413
- }),
414
- );
415
- });
416
-
417
- it("detects maxFeePerGas being greater than max gasOptions maxFeePerGas with an error", async () => {
418
- const res = await validateIntent({} as CryptoCurrency, eip1559Intent({}), {
419
- value: 0n,
420
- parameters: { maxPriorityFeePerGas: 6n, maxFeePerGas: 5n },
421
- });
422
-
423
- expect(res.errors).toEqual(
424
- expect.objectContaining({
425
- maxPriorityFee: new PriorityFeeHigherThanMaxFee(),
426
- }),
427
- );
428
- });
429
-
430
- it("detects maxPriorityFeePerGas being greater than max gasOptions maxPriorityFeePerGas with a warning", async () => {
431
- jest.spyOn(ledgerGasTracker, "getGasOptions").mockResolvedValue({
432
- slow: {
433
- maxFeePerGas: null,
434
- maxPriorityFeePerGas: null,
435
- gasPrice: null,
436
- nextBaseFee: null,
437
- },
438
- medium: {
439
- maxFeePerGas: null,
440
- maxPriorityFeePerGas: null,
441
- gasPrice: null,
442
- nextBaseFee: null,
443
- },
444
- fast: {
445
- maxFeePerGas: null,
446
- maxPriorityFeePerGas: BigNumber(3),
447
- gasPrice: null,
448
- nextBaseFee: null,
449
- },
450
- });
451
-
452
- const res = await validateIntent({} as CryptoCurrency, eip1559Intent({}), {
453
- value: 0n,
454
- parameters: { maxPriorityFeePerGas: 4n, maxFeePerGas: 5n },
455
- });
456
-
457
- expect(res.warnings).toEqual(
458
- expect.objectContaining({
459
- maxPriorityFee: new PriorityFeeTooHigh(),
460
- }),
461
- );
462
- });
463
-
464
- it("detects maxPriorityFeePerGas being lower than min gasOptions maxPriorityFeePerGas with a warning", async () => {
465
- jest.spyOn(ledgerGasTracker, "getGasOptions").mockResolvedValue({
466
- slow: {
467
- maxFeePerGas: null,
468
- maxPriorityFeePerGas: BigNumber(3),
469
- gasPrice: null,
470
- nextBaseFee: null,
471
- },
472
- medium: {
473
- maxFeePerGas: null,
474
- maxPriorityFeePerGas: null,
475
- gasPrice: null,
476
- nextBaseFee: null,
477
- },
478
- fast: {
479
- maxFeePerGas: null,
480
- maxPriorityFeePerGas: null,
481
- gasPrice: null,
482
- nextBaseFee: null,
483
- },
484
- });
485
-
486
- const res = await validateIntent({} as CryptoCurrency, eip1559Intent({}), {
487
- value: 0n,
488
- parameters: { maxPriorityFeePerGas: 1n, maxFeePerGas: 5n },
489
- });
490
-
491
- expect(res.warnings).toEqual(
492
- expect.objectContaining({
493
- maxPriorityFee: new PriorityFeeTooLow(),
494
- }),
495
- );
496
- });
497
-
498
- it("detects maxFeePerGas being lower than recommanded next base fee with a warning", async () => {
499
- jest.spyOn(ledgerGasTracker, "getGasOptions").mockResolvedValue({
500
- slow: {
501
- maxFeePerGas: null,
502
- maxPriorityFeePerGas: null,
503
- gasPrice: null,
504
- nextBaseFee: null,
505
- },
506
- medium: {
507
- maxFeePerGas: null,
508
- maxPriorityFeePerGas: null,
509
- gasPrice: null,
510
- nextBaseFee: BigNumber(6),
511
- },
512
- fast: {
513
- maxFeePerGas: null,
514
- maxPriorityFeePerGas: null,
515
- gasPrice: null,
516
- nextBaseFee: null,
517
- },
518
- });
519
-
520
- const res = await validateIntent({} as CryptoCurrency, eip1559Intent({}), {
521
- value: 0n,
522
- parameters: { maxPriorityFeePerGas: 1n, maxFeePerGas: 5n },
523
- });
524
-
525
- expect(res.warnings).toEqual(
526
- expect.objectContaining({
527
- maxFee: new MaxFeeTooLow(),
528
- }),
529
- );
530
- });
531
- });
532
- });
533
-
534
- describe("valid intent", () => {
535
- it("does not return any error of warning for a valid legacy intent", async () => {
536
- const res = await validateIntent(
537
- {} as CryptoCurrency,
538
- legacyIntent({ amount: 2n, recipient: "0xe2ca7390e76c5A992749bB622087310d2e63ca29" }),
539
- {
540
- value: 4n,
541
- parameters: { gasLimit: 21000n, gasPrice: 10n },
542
- },
543
- );
544
-
545
- expect(res).toEqual({
546
- estimatedFees: 4n,
547
- totalSpent: 6n,
548
- amount: 2n,
549
- errors: {},
550
- warnings: {},
551
- });
552
- });
553
-
554
- it("does not return any error of warning for a valid eip1559 intent", async () => {
555
- jest.spyOn(ledgerGasTracker, "getGasOptions").mockResolvedValue({
556
- slow: {
557
- maxFeePerGas: null,
558
- maxPriorityFeePerGas: BigNumber(2),
559
- gasPrice: null,
560
- nextBaseFee: null,
561
- },
562
- medium: {
563
- maxFeePerGas: null,
564
- maxPriorityFeePerGas: null,
565
- gasPrice: null,
566
- nextBaseFee: BigNumber(4),
567
- },
568
- fast: {
569
- maxFeePerGas: null,
570
- maxPriorityFeePerGas: BigNumber(6),
571
- gasPrice: null,
572
- nextBaseFee: null,
573
- },
574
- });
575
-
576
- const res = await validateIntent(
577
- {} as CryptoCurrency,
578
- eip1559Intent({ amount: 2n, recipient: "0xe2ca7390e76c5A992749bB622087310d2e63ca29" }),
579
- {
580
- value: 4n,
581
- parameters: { gasLimit: 21000n, maxPriorityFeePerGas: 3n, maxFeePerGas: 5n },
582
- },
583
- );
584
-
585
- expect(res).toEqual({
586
- estimatedFees: 4n,
587
- totalSpent: 6n,
588
- amount: 2n,
589
- errors: {},
590
- warnings: {},
591
- });
592
- });
593
-
594
- it("does not call the gas tracker if unnecessary", async () => {
595
- const getGasOptions = jest.spyOn(ledgerGasTracker, "getGasOptions").mockResolvedValue({
596
- slow: {
597
- maxFeePerGas: null,
598
- maxPriorityFeePerGas: null,
599
- gasPrice: null,
600
- nextBaseFee: null,
601
- },
602
- medium: {
603
- maxFeePerGas: null,
604
- maxPriorityFeePerGas: null,
605
- gasPrice: null,
606
- nextBaseFee: null,
607
- },
608
- fast: {
609
- maxFeePerGas: null,
610
- maxPriorityFeePerGas: null,
611
- gasPrice: null,
612
- nextBaseFee: null,
613
- },
614
- });
615
-
616
- const res = await validateIntent(
617
- {} as CryptoCurrency,
618
- eip1559Intent({ amount: 2n, recipient: "0xe2ca7390e76c5A992749bB622087310d2e63ca29" }),
619
- {
620
- value: 4n,
621
- parameters: {
622
- gasLimit: 21000n,
623
- maxPriorityFeePerGas: 3n,
624
- maxFeePerGas: 5n,
625
- gasOptions: {
626
- slow: {
627
- maxFeePerGas: null,
628
- maxPriorityFeePerGas: 2n,
629
- gasPrice: null,
630
- nextBaseFee: null,
631
- },
632
- medium: {
633
- maxFeePerGas: null,
634
- maxPriorityFeePerGas: null,
635
- gasPrice: null,
636
- nextBaseFee: 4n,
637
- },
638
- fast: {
639
- maxFeePerGas: null,
640
- maxPriorityFeePerGas: 6n,
641
- gasPrice: null,
642
- nextBaseFee: null,
643
- },
644
- },
645
- },
646
- },
647
- );
648
-
649
- expect(res).toEqual({
650
- estimatedFees: 4n,
651
- totalSpent: 6n,
652
- amount: 2n,
653
- errors: {},
654
- warnings: {},
655
- });
656
- expect(getGasOptions).not.toHaveBeenCalled();
657
- });
658
- });
659
- });