@ledgerhq/coin-tezos 7.12.0 → 9.0.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 (199) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/lib/api/index.d.ts +1 -2
  3. package/lib/api/index.d.ts.map +1 -1
  4. package/lib/api/index.js +45 -44
  5. package/lib/api/index.js.map +1 -1
  6. package/lib/api/types.d.ts +3 -2
  7. package/lib/api/types.d.ts.map +1 -1
  8. package/lib/config.d.ts +3 -1
  9. package/lib/config.d.ts.map +1 -1
  10. package/lib/config.js.map +1 -1
  11. package/lib/logic/broadcast.d.ts +2 -1
  12. package/lib/logic/broadcast.d.ts.map +1 -1
  13. package/lib/logic/broadcast.js +3 -2
  14. package/lib/logic/broadcast.js.map +1 -1
  15. package/lib/logic/combine.d.ts +1 -1
  16. package/lib/logic/combine.d.ts.map +1 -1
  17. package/lib/logic/combine.js +4 -1
  18. package/lib/logic/combine.js.map +1 -1
  19. package/lib/logic/craftRawOperations.d.ts +2 -1
  20. package/lib/logic/craftRawOperations.d.ts.map +1 -1
  21. package/lib/logic/craftRawOperations.js +5 -8
  22. package/lib/logic/craftRawOperations.js.map +1 -1
  23. package/lib/logic/craftTransaction.d.ts +3 -2
  24. package/lib/logic/craftTransaction.d.ts.map +1 -1
  25. package/lib/logic/craftTransaction.js +6 -9
  26. package/lib/logic/craftTransaction.js.map +1 -1
  27. package/lib/logic/estimateFees.d.ts +2 -1
  28. package/lib/logic/estimateFees.d.ts.map +1 -1
  29. package/lib/logic/estimateFees.js +24 -19
  30. package/lib/logic/estimateFees.js.map +1 -1
  31. package/lib/logic/getBalance.d.ts +2 -1
  32. package/lib/logic/getBalance.d.ts.map +1 -1
  33. package/lib/logic/getBalance.js +7 -8
  34. package/lib/logic/getBalance.js.map +1 -1
  35. package/lib/logic/getBlock.d.ts +2 -1
  36. package/lib/logic/getBlock.d.ts.map +1 -1
  37. package/lib/logic/getBlock.js +12 -10
  38. package/lib/logic/getBlock.js.map +1 -1
  39. package/lib/logic/getBlockInfo.d.ts +2 -1
  40. package/lib/logic/getBlockInfo.d.ts.map +1 -1
  41. package/lib/logic/getBlockInfo.js +5 -3
  42. package/lib/logic/getBlockInfo.js.map +1 -1
  43. package/lib/logic/getStakes.d.ts +3 -2
  44. package/lib/logic/getStakes.d.ts.map +1 -1
  45. package/lib/logic/getStakes.js +9 -9
  46. package/lib/logic/getStakes.js.map +1 -1
  47. package/lib/logic/lastBlock.d.ts +2 -1
  48. package/lib/logic/lastBlock.d.ts.map +1 -1
  49. package/lib/logic/lastBlock.js +4 -6
  50. package/lib/logic/lastBlock.js.map +1 -1
  51. package/lib/logic/listOperations.d.ts +2 -1
  52. package/lib/logic/listOperations.d.ts.map +1 -1
  53. package/lib/logic/listOperations.js +8 -6
  54. package/lib/logic/listOperations.js.map +1 -1
  55. package/lib/logic/tezosToolkit.d.ts +2 -1
  56. package/lib/logic/tezosToolkit.d.ts.map +1 -1
  57. package/lib/logic/tezosToolkit.js +2 -6
  58. package/lib/logic/tezosToolkit.js.map +1 -1
  59. package/lib/logic/validateIntent.d.ts +2 -1
  60. package/lib/logic/validateIntent.d.ts.map +1 -1
  61. package/lib/logic/validateIntent.js +12 -13
  62. package/lib/logic/validateIntent.js.map +1 -1
  63. package/lib/network/bakers.d.ts +5 -4
  64. package/lib/network/bakers.d.ts.map +1 -1
  65. package/lib/network/bakers.js +9 -10
  66. package/lib/network/bakers.js.map +1 -1
  67. package/lib/network/index.d.ts +1 -1
  68. package/lib/network/index.d.ts.map +1 -1
  69. package/lib/network/index.js +2 -5
  70. package/lib/network/index.js.map +1 -1
  71. package/lib/network/tzkt.d.ts +16 -9
  72. package/lib/network/tzkt.d.ts.map +1 -1
  73. package/lib/network/tzkt.js +341 -333
  74. package/lib/network/tzkt.js.map +1 -1
  75. package/lib/utils.d.ts +2 -1
  76. package/lib/utils.d.ts.map +1 -1
  77. package/lib/utils.js +1 -6
  78. package/lib/utils.js.map +1 -1
  79. package/lib-es/api/index.d.ts +1 -2
  80. package/lib-es/api/index.d.ts.map +1 -1
  81. package/lib-es/api/index.js +40 -36
  82. package/lib-es/api/index.js.map +1 -1
  83. package/lib-es/api/types.d.ts +3 -2
  84. package/lib-es/api/types.d.ts.map +1 -1
  85. package/lib-es/config.d.ts +3 -1
  86. package/lib-es/config.d.ts.map +1 -1
  87. package/lib-es/config.js.map +1 -1
  88. package/lib-es/logic/broadcast.d.ts +2 -1
  89. package/lib-es/logic/broadcast.d.ts.map +1 -1
  90. package/lib-es/logic/broadcast.js +3 -2
  91. package/lib-es/logic/broadcast.js.map +1 -1
  92. package/lib-es/logic/combine.d.ts +1 -1
  93. package/lib-es/logic/combine.d.ts.map +1 -1
  94. package/lib-es/logic/combine.js +4 -1
  95. package/lib-es/logic/combine.js.map +1 -1
  96. package/lib-es/logic/craftRawOperations.d.ts +2 -1
  97. package/lib-es/logic/craftRawOperations.d.ts.map +1 -1
  98. package/lib-es/logic/craftRawOperations.js +5 -5
  99. package/lib-es/logic/craftRawOperations.js.map +1 -1
  100. package/lib-es/logic/craftTransaction.d.ts +3 -2
  101. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  102. package/lib-es/logic/craftTransaction.js +6 -6
  103. package/lib-es/logic/craftTransaction.js.map +1 -1
  104. package/lib-es/logic/estimateFees.d.ts +2 -1
  105. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  106. package/lib-es/logic/estimateFees.js +24 -16
  107. package/lib-es/logic/estimateFees.js.map +1 -1
  108. package/lib-es/logic/getBalance.d.ts +2 -1
  109. package/lib-es/logic/getBalance.d.ts.map +1 -1
  110. package/lib-es/logic/getBalance.js +5 -3
  111. package/lib-es/logic/getBalance.js.map +1 -1
  112. package/lib-es/logic/getBlock.d.ts +2 -1
  113. package/lib-es/logic/getBlock.d.ts.map +1 -1
  114. package/lib-es/logic/getBlock.js +10 -8
  115. package/lib-es/logic/getBlock.js.map +1 -1
  116. package/lib-es/logic/getBlockInfo.d.ts +2 -1
  117. package/lib-es/logic/getBlockInfo.d.ts.map +1 -1
  118. package/lib-es/logic/getBlockInfo.js +4 -2
  119. package/lib-es/logic/getBlockInfo.js.map +1 -1
  120. package/lib-es/logic/getStakes.d.ts +3 -2
  121. package/lib-es/logic/getStakes.d.ts.map +1 -1
  122. package/lib-es/logic/getStakes.js +9 -6
  123. package/lib-es/logic/getStakes.js.map +1 -1
  124. package/lib-es/logic/lastBlock.d.ts +2 -1
  125. package/lib-es/logic/lastBlock.d.ts.map +1 -1
  126. package/lib-es/logic/lastBlock.js +4 -3
  127. package/lib-es/logic/lastBlock.js.map +1 -1
  128. package/lib-es/logic/listOperations.d.ts +2 -1
  129. package/lib-es/logic/listOperations.d.ts.map +1 -1
  130. package/lib-es/logic/listOperations.js +7 -5
  131. package/lib-es/logic/listOperations.js.map +1 -1
  132. package/lib-es/logic/tezosToolkit.d.ts +2 -1
  133. package/lib-es/logic/tezosToolkit.d.ts.map +1 -1
  134. package/lib-es/logic/tezosToolkit.js +2 -3
  135. package/lib-es/logic/tezosToolkit.js.map +1 -1
  136. package/lib-es/logic/validateIntent.d.ts +2 -1
  137. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  138. package/lib-es/logic/validateIntent.js +10 -8
  139. package/lib-es/logic/validateIntent.js.map +1 -1
  140. package/lib-es/network/bakers.d.ts +5 -4
  141. package/lib-es/network/bakers.d.ts.map +1 -1
  142. package/lib-es/network/bakers.js +9 -10
  143. package/lib-es/network/bakers.js.map +1 -1
  144. package/lib-es/network/index.d.ts +1 -1
  145. package/lib-es/network/index.d.ts.map +1 -1
  146. package/lib-es/network/index.js +1 -1
  147. package/lib-es/network/index.js.map +1 -1
  148. package/lib-es/network/tzkt.d.ts +16 -9
  149. package/lib-es/network/tzkt.d.ts.map +1 -1
  150. package/lib-es/network/tzkt.js +340 -333
  151. package/lib-es/network/tzkt.js.map +1 -1
  152. package/lib-es/utils.d.ts +2 -1
  153. package/lib-es/utils.d.ts.map +1 -1
  154. package/lib-es/utils.js +1 -3
  155. package/lib-es/utils.js.map +1 -1
  156. package/package.json +2 -2
  157. package/src/api/index-mainnet.integ.test.ts +34 -30
  158. package/src/api/index.integ.test.ts +69 -53
  159. package/src/api/index.test.ts +99 -60
  160. package/src/api/index.ts +52 -36
  161. package/src/api/types.ts +3 -2
  162. package/src/config.ts +4 -1
  163. package/src/logic/broadcast.integ.test.ts +12 -13
  164. package/src/logic/broadcast.ts +4 -2
  165. package/src/logic/combine.test.ts +17 -0
  166. package/src/logic/combine.ts +5 -2
  167. package/src/logic/craftRawOperations.test.ts +47 -33
  168. package/src/logic/craftRawOperations.ts +6 -4
  169. package/src/logic/craftTransaction.integ.test.ts +12 -5
  170. package/src/logic/craftTransaction.test.ts +39 -31
  171. package/src/logic/craftTransaction.ts +10 -5
  172. package/src/logic/estimateFees.integ.test.ts +7 -7
  173. package/src/logic/estimateFees.test.ts +52 -49
  174. package/src/logic/estimateFees.ts +34 -22
  175. package/src/logic/getBalance.test.ts +19 -17
  176. package/src/logic/getBalance.ts +6 -3
  177. package/src/logic/getBlock.integ.test.ts +8 -30
  178. package/src/logic/getBlock.test.ts +91 -81
  179. package/src/logic/getBlock.ts +11 -8
  180. package/src/logic/getBlockInfo.integ.test.ts +9 -18
  181. package/src/logic/getBlockInfo.test.ts +19 -9
  182. package/src/logic/getBlockInfo.ts +5 -2
  183. package/src/logic/getStakes.test.ts +46 -49
  184. package/src/logic/getStakes.ts +14 -5
  185. package/src/logic/lastBlock.ts +5 -3
  186. package/src/logic/listOperations.integ.test.ts +40 -67
  187. package/src/logic/listOperations.test.ts +65 -59
  188. package/src/logic/listOperations.ts +8 -3
  189. package/src/logic/tezosToolkit.ts +3 -3
  190. package/src/logic/validateIntent.test.ts +78 -74
  191. package/src/logic/validateIntent.ts +17 -7
  192. package/src/network/bakers.integ.test.ts +2 -5
  193. package/src/network/bakers.test.ts +5 -6
  194. package/src/network/bakers.ts +13 -10
  195. package/src/network/index.ts +2 -1
  196. package/src/network/tzkt.integ.test.ts +3 -14
  197. package/src/network/tzkt.test.ts +128 -96
  198. package/src/network/tzkt.ts +426 -393
  199. package/src/utils.ts +2 -3
@@ -1,17 +1,13 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import type { TezosCoinConfig, TezosContext } from '../config'
4
5
  import { getRevealFee } from '@taquito/taquito'
5
- import coinConfig from '../config'
6
6
  import { normalizePublicKeyForAddress, STAKE_USE_ALL_RESERVE_MUTEZ } from '../utils'
7
7
  import { estimateFees } from './estimateFees'
8
8
  import { getTezosToolkit } from './tezosToolkit'
9
9
 
10
10
  jest.mock('./tezosToolkit')
11
- jest.mock('../config', () => ({
12
- __esModule: true,
13
- default: { getCoinConfig: jest.fn() },
14
- }))
15
11
 
16
12
  const defaultFeesConfig = {
17
13
  minGasLimit: 600,
@@ -58,12 +54,19 @@ describe('estimateFees', () => {
58
54
  setProvider: jest.fn(),
59
55
  }
60
56
 
57
+ let currentConfig: TezosCoinConfig
58
+ const context: TezosContext = {
59
+ config: async () => currentConfig,
60
+ logger: () => undefined,
61
+ }
62
+ const mkConfig = (cfg: unknown): TezosCoinConfig => cfg as unknown as TezosCoinConfig
63
+
61
64
  beforeEach(() => {
62
65
  jest.clearAllMocks()
63
66
  ;(getTezosToolkit as jest.Mock).mockReturnValue(mockTezosToolkit)
64
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
67
+ currentConfig = {
65
68
  fees: defaultFeesConfig,
66
- })
69
+ } as unknown as TezosCoinConfig
67
70
  })
68
71
 
69
72
  describe('signer public key from account.xpub', () => {
@@ -77,7 +80,7 @@ describe('estimateFees', () => {
77
80
  opSize: 100,
78
81
  })
79
82
 
80
- await estimateFees({
83
+ await estimateFees(context, {
81
84
  account: { ...unrevealedAccount },
82
85
  transaction: {
83
86
  mode: 'delegate',
@@ -109,11 +112,11 @@ describe('estimateFees', () => {
109
112
  burnFeeMutez: 0,
110
113
  opSize: 100,
111
114
  })
112
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
115
+ currentConfig = mkConfig({
113
116
  fees: { ...defaultFeesConfig, minFees },
114
117
  })
115
118
 
116
- const result = await estimateFees({
119
+ const result = await estimateFees(context, {
117
120
  account: revealedAccount,
118
121
  transaction: {
119
122
  mode: 'delegate',
@@ -135,11 +138,11 @@ describe('estimateFees', () => {
135
138
  burnFeeMutez: 0,
136
139
  opSize: 100,
137
140
  })
138
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
141
+ currentConfig = mkConfig({
139
142
  fees: { ...defaultFeesConfig, minFees },
140
143
  })
141
144
 
142
- const result = await estimateFees({
145
+ const result = await estimateFees(context, {
143
146
  account: revealedAccount,
144
147
  transaction: {
145
148
  mode: 'delegate',
@@ -161,7 +164,7 @@ describe('estimateFees', () => {
161
164
  burnFeeMutez: 0,
162
165
  opSize: 100,
163
166
  })
164
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
167
+ currentConfig = mkConfig({
165
168
  fees: { ...defaultFeesConfig, minFees },
166
169
  })
167
170
 
@@ -172,7 +175,7 @@ describe('estimateFees', () => {
172
175
  amount: BigInt(0),
173
176
  }
174
177
 
175
- const result = await estimateFees({ account, transaction })
178
+ const result = await estimateFees(context, { account, transaction })
176
179
 
177
180
  expect(result.fees).toBe(BigInt(minFees))
178
181
  expect(result.estimatedFees).toBe(BigInt(minFees * 2))
@@ -188,7 +191,7 @@ describe('estimateFees', () => {
188
191
  burnFeeMutez: 0,
189
192
  opSize: 100,
190
193
  })
191
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
194
+ currentConfig = mkConfig({
192
195
  fees: { ...defaultFeesConfig, minFees: 0, minEstimatedFees: 0 },
193
196
  })
194
197
 
@@ -199,7 +202,7 @@ describe('estimateFees', () => {
199
202
  amount: BigInt(0),
200
203
  }
201
204
 
202
- const result = await estimateFees({ account, transaction })
205
+ const result = await estimateFees(context, { account, transaction })
203
206
 
204
207
  const expectedRevealFee = getRevealFee(account.address)
205
208
  expect(result.estimatedFees).toBe(BigInt(delegationFee + expectedRevealFee))
@@ -215,7 +218,7 @@ describe('estimateFees', () => {
215
218
  opSize: 100,
216
219
  })
217
220
 
218
- const result = await estimateFees({
221
+ const result = await estimateFees(context, {
219
222
  account: revealedAccount,
220
223
  transaction: {
221
224
  mode: 'undelegate',
@@ -240,7 +243,7 @@ describe('estimateFees', () => {
240
243
  opSize: 100,
241
244
  })
242
245
 
243
- const result = await estimateFees({
246
+ const result = await estimateFees(context, {
244
247
  account: revealedAccount,
245
248
  transaction: {
246
249
  mode: 'stake',
@@ -269,7 +272,7 @@ describe('estimateFees', () => {
269
272
  opSize: 100,
270
273
  })
271
274
 
272
- const result = await estimateFees({
275
+ const result = await estimateFees(context, {
273
276
  account: revealedAccount,
274
277
  transaction: {
275
278
  mode: 'unstake',
@@ -298,7 +301,7 @@ describe('estimateFees', () => {
298
301
  opSize: 100,
299
302
  })
300
303
 
301
- const result = await estimateFees({
304
+ const result = await estimateFees(context, {
302
305
  account: { ...revealedAccount, stakedBalance: 5000n },
303
306
  transaction: {
304
307
  mode: 'unstake',
@@ -322,7 +325,7 @@ describe('estimateFees', () => {
322
325
  opSize: 100,
323
326
  })
324
327
 
325
- const result = await estimateFees({
328
+ const result = await estimateFees(context, {
326
329
  account: { ...revealedAccount, balance },
327
330
  transaction: {
328
331
  mode: 'stake',
@@ -351,7 +354,7 @@ describe('estimateFees', () => {
351
354
  opSize: 100,
352
355
  })
353
356
 
354
- const result = await estimateFees({
357
+ const result = await estimateFees(context, {
355
358
  account: { ...unrevealedAccount, balance },
356
359
  transaction: {
357
360
  mode: 'stake',
@@ -377,7 +380,7 @@ describe('estimateFees', () => {
377
380
  opSize: 100,
378
381
  })
379
382
 
380
- const result = await estimateFees({
383
+ const result = await estimateFees(context, {
381
384
  account: { ...revealedAccount, balance },
382
385
  transaction: {
383
386
  mode: 'stake',
@@ -402,7 +405,7 @@ describe('estimateFees', () => {
402
405
  opSize: 100,
403
406
  })
404
407
 
405
- const result = await estimateFees({
408
+ const result = await estimateFees(context, {
406
409
  account: { ...revealedAccount, balance, stakedBalance },
407
410
  transaction: {
408
411
  mode: 'stake',
@@ -430,7 +433,7 @@ describe('estimateFees', () => {
430
433
  opSize: 100,
431
434
  })
432
435
 
433
- const result = await estimateFees({
436
+ const result = await estimateFees(context, {
434
437
  account: { ...revealedAccount, balance, stakedBalance, unstakedBalance },
435
438
  transaction: {
436
439
  mode: 'stake',
@@ -454,7 +457,7 @@ describe('estimateFees', () => {
454
457
  opSize: 100,
455
458
  })
456
459
 
457
- const result = await estimateFees({
460
+ const result = await estimateFees(context, {
458
461
  account: revealedAccount,
459
462
  transaction: {
460
463
  mode: 'unstake',
@@ -481,7 +484,7 @@ describe('estimateFees', () => {
481
484
  opSize: 100,
482
485
  })
483
486
 
484
- const result = await estimateFees({
487
+ const result = await estimateFees(context, {
485
488
  account: revealedAccount,
486
489
  transaction: {
487
490
  mode: 'finalize_unstake',
@@ -508,11 +511,11 @@ describe('estimateFees', () => {
508
511
  burnFeeMutez: 0,
509
512
  opSize: 200,
510
513
  })
511
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
514
+ currentConfig = mkConfig({
512
515
  fees: { ...defaultFeesConfig, minFees },
513
516
  })
514
517
 
515
- const result = await estimateFees({
518
+ const result = await estimateFees(context, {
516
519
  account: revealedAccount,
517
520
  transaction: {
518
521
  mode: 'send',
@@ -538,7 +541,7 @@ describe('estimateFees', () => {
538
541
  opSize: 200,
539
542
  })
540
543
 
541
- const result = await estimateFees({
544
+ const result = await estimateFees(context, {
542
545
  account: unrevealedAccount,
543
546
  transaction: {
544
547
  mode: 'send',
@@ -553,7 +556,7 @@ describe('estimateFees', () => {
553
556
  })
554
557
 
555
558
  it('returns zero estimation when balance is 0 and not useAllAmount', async () => {
556
- const result = await estimateFees({
559
+ const result = await estimateFees(context, {
557
560
  account: { ...revealedAccount, balance: 0n },
558
561
  transaction: {
559
562
  mode: 'delegate',
@@ -568,7 +571,7 @@ describe('estimateFees', () => {
568
571
  })
569
572
 
570
573
  it('returns estimation with amount 0 when balance is 0 and useAllAmount', async () => {
571
- const result = await estimateFees({
574
+ const result = await estimateFees(context, {
572
575
  account: { ...revealedAccount, balance: 0n },
573
576
  transaction: {
574
577
  mode: 'send',
@@ -583,7 +586,7 @@ describe('estimateFees', () => {
583
586
  })
584
587
 
585
588
  it('returns fallback estimation when send has no recipient', async () => {
586
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
589
+ currentConfig = mkConfig({
587
590
  fees: {
588
591
  ...defaultFeesConfig,
589
592
  minEstimatedFees: 300,
@@ -592,7 +595,7 @@ describe('estimateFees', () => {
592
595
  },
593
596
  })
594
597
 
595
- const result = await estimateFees({
598
+ const result = await estimateFees(context, {
596
599
  account: revealedAccount,
597
600
  transaction: {
598
601
  mode: 'send',
@@ -610,7 +613,7 @@ describe('estimateFees', () => {
610
613
 
611
614
  it('uses fallback estimation and adds reveal fee when Taquito throws Public key not found (unrevealed)', async () => {
612
615
  const minEstimatedFees = 400
613
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
616
+ currentConfig = mkConfig({
614
617
  fees: {
615
618
  ...defaultFeesConfig,
616
619
  minEstimatedFees,
@@ -622,7 +625,7 @@ describe('estimateFees', () => {
622
625
  Object.assign(new Error('Fail'), { status: 404, message: 'Public key not found' })
623
626
  )
624
627
 
625
- const result = await estimateFees({
628
+ const result = await estimateFees(context, {
626
629
  account: unrevealedAccount,
627
630
  transaction: {
628
631
  mode: 'send',
@@ -648,7 +651,7 @@ describe('estimateFees', () => {
648
651
  })
649
652
 
650
653
  const contractAddress = 'KT1CpeSQKdkhWi4pinYcseCFKmDhs5M74BkU'
651
- const result = await estimateFees({
654
+ const result = await estimateFees(context, {
652
655
  account: revealedAccount,
653
656
  transaction: {
654
657
  mode: 'send_token',
@@ -685,7 +688,7 @@ describe('estimateFees', () => {
685
688
  })
686
689
 
687
690
  const contractAddress = 'KT1CpeSQKdkhWi4pinYcseCFKmDhs5M74BkU'
688
- const result = await estimateFees({
691
+ const result = await estimateFees(context, {
689
692
  account: unrevealedAccount,
690
693
  transaction: {
691
694
  mode: 'send_token',
@@ -703,7 +706,7 @@ describe('estimateFees', () => {
703
706
 
704
707
  it('send_token uses fallback when Taquito throws Public key not found', async () => {
705
708
  const minEstimatedFees = 400
706
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
709
+ currentConfig = mkConfig({
707
710
  fees: {
708
711
  ...defaultFeesConfig,
709
712
  minEstimatedFees,
@@ -718,7 +721,7 @@ describe('estimateFees', () => {
718
721
  )
719
722
 
720
723
  const contractAddress = 'KT1CpeSQKdkhWi4pinYcseCFKmDhs5M74BkU'
721
- const result = await estimateFees({
724
+ const result = await estimateFees(context, {
722
725
  account: unrevealedAccount,
723
726
  transaction: {
724
727
  mode: 'send_token',
@@ -739,7 +742,7 @@ describe('estimateFees', () => {
739
742
  const { transfer } = setupFa2ContractMock()
740
743
  mockTezosToolkit.contract.at.mockResolvedValue({ methods: { transfer } })
741
744
 
742
- const result = await estimateFees({
745
+ const result = await estimateFees(context, {
743
746
  account: revealedAccount,
744
747
  transaction: {
745
748
  mode: 'send_token',
@@ -759,7 +762,7 @@ describe('estimateFees', () => {
759
762
  mockTezosToolkit.contract.at.mockRejectedValue(new Error('Invalid contract'))
760
763
 
761
764
  await expect(
762
- estimateFees({
765
+ estimateFees(context, {
763
766
  account: revealedAccount,
764
767
  transaction: {
765
768
  mode: 'send_token',
@@ -774,7 +777,7 @@ describe('estimateFees', () => {
774
777
 
775
778
  it('send_token throws when contractAddress or tokenId is missing', async () => {
776
779
  await expect(
777
- estimateFees({
780
+ estimateFees(context, {
778
781
  account: revealedAccount,
779
782
  transaction: {
780
783
  mode: 'send_token',
@@ -796,11 +799,11 @@ describe('estimateFees', () => {
796
799
  burnFeeMutez: 0,
797
800
  opSize: 200,
798
801
  })
799
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
802
+ currentConfig = mkConfig({
800
803
  fees: { ...defaultFeesConfig, minFees },
801
804
  })
802
805
 
803
- const result = await estimateFees({
806
+ const result = await estimateFees(context, {
804
807
  account: { ...revealedAccount, balance: BigInt(balance) },
805
808
  transaction: {
806
809
  mode: 'send',
@@ -836,11 +839,11 @@ describe('estimateFees', () => {
836
839
  burnFeeMutez,
837
840
  opSize: 200,
838
841
  })
839
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
842
+ currentConfig = mkConfig({
840
843
  fees: { ...defaultFeesConfig, minFees },
841
844
  })
842
845
 
843
- const result = await estimateFees({
846
+ const result = await estimateFees(context, {
844
847
  account: { ...revealedAccount, balance },
845
848
  transaction: {
846
849
  mode: 'send',
@@ -867,11 +870,11 @@ describe('estimateFees', () => {
867
870
  burnFeeMutez: 0,
868
871
  opSize: 200,
869
872
  })
870
- ;(coinConfig.getCoinConfig as jest.Mock).mockReturnValue({
873
+ currentConfig = mkConfig({
871
874
  fees: { ...defaultFeesConfig, minFees: 0 },
872
875
  })
873
876
 
874
- const result = await estimateFees({
877
+ const result = await estimateFees(context, {
875
878
  account: { ...revealedAccount, balance, stakedBalance, unstakedBalance },
876
879
  transaction: {
877
880
  mode: 'send',
@@ -1,12 +1,12 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
+ import type { TezosCoinConfig, TezosContext } from '../config'
4
5
  import type { TezosOperationMode } from '../types/model'
5
6
  import type { Estimate } from '@taquito/taquito'
6
7
  import { log } from '@ledgerhq/logs'
7
8
  import { COST_PER_BYTE, getRevealFee, ORIGINATION_SIZE } from '@taquito/taquito'
8
9
  import { validatePublicKey, ValidationResult } from '@taquito/utils'
9
- import coinConfig from '../config'
10
10
  import { UnsupportedTransactionMode } from '../types/errors'
11
11
  import {
12
12
  computeMaxStakeAmount,
@@ -54,20 +54,24 @@ export type EstimatedFees = {
54
54
  * @param {Account} account
55
55
  * @param {Transaction} transaction
56
56
  */
57
- export async function estimateFees({
58
- account,
59
- transaction,
60
- }: {
61
- account: CoreAccountInfo
62
- transaction: CoreTransactionInfo
63
- }): Promise<EstimatedFees> {
57
+ export async function estimateFees(
58
+ context: TezosContext,
59
+ {
60
+ account,
61
+ transaction,
62
+ }: {
63
+ account: CoreAccountInfo
64
+ transaction: CoreTransactionInfo
65
+ }
66
+ ): Promise<EstimatedFees> {
67
+ const config = await context.config()
64
68
  // Normalize public key (hex -> base58) when provided (may be undefined for unrevealed accounts)
65
69
  // before the device is connected
66
70
  const encodedPubKey = account.xpub
67
71
  ? normalizePublicKeyForAddress(account.xpub, account.address)
68
72
  : undefined
69
73
 
70
- const tezosToolkit = getTezosToolkit()
74
+ const tezosToolkit = getTezosToolkit(config)
71
75
  if (encodedPubKey && validatePublicKey(encodedPubKey) === ValidationResult.VALID) {
72
76
  tezosToolkit.setProvider({ signer: createMockSigner(account.address, encodedPubKey) })
73
77
  } else {
@@ -112,7 +116,7 @@ export async function estimateFees({
112
116
  ) {
113
117
  return {
114
118
  ...estimation,
115
- ...createFallbackEstimation(),
119
+ ...createFallbackEstimation(config),
116
120
  }
117
121
  }
118
122
  let estimate: Estimate
@@ -181,9 +185,11 @@ export async function estimateFees({
181
185
  throw new UnsupportedTransactionMode('unsupported mode', { mode: transaction.mode })
182
186
  }
183
187
 
184
- const minFees = coinConfig.getCoinConfig().fees.minFees ?? 0
188
+ const minFees = config.fees.minFees ?? 0
185
189
  const mainOpFee = Math.max(minFees, estimate.suggestedFeeMutez)
186
- const revealFee = account.revealed ? 0n : BigInt(getRevealFeeForEstimation(account.address))
190
+ const revealFee = account.revealed
191
+ ? 0n
192
+ : BigInt(getRevealFeeForEstimation(config, account.address))
187
193
 
188
194
  // NOTE: send-max only applies to native XTZ transfer, not FA2
189
195
  if (transaction.useAllAmount && transaction.mode === 'send') {
@@ -248,14 +254,14 @@ export async function estimateFees({
248
254
  transaction: transaction,
249
255
  }
250
256
  )
251
- const fallback = createFallbackEstimation()
257
+ const fallback = createFallbackEstimation(config)
252
258
  estimation.fees = fallback.fees
253
259
  estimation.gasLimit = fallback.gasLimit
254
260
  estimation.storageLimit = fallback.storageLimit
255
261
  estimation.estimatedFees = fallback.fees
256
262
  if (!account.revealed) {
257
263
  estimation.estimatedFees =
258
- estimation.estimatedFees + BigInt(getRevealFeeForEstimation(account.address))
264
+ estimation.estimatedFees + BigInt(getRevealFeeForEstimation(config, account.address))
259
265
  }
260
266
  // Handle useAllAmount also for send mode when estimation falls back
261
267
  if (transaction.useAllAmount && transaction.mode === 'send') {
@@ -269,7 +275,8 @@ export async function estimateFees({
269
275
  estimation.estimatedFees = BigInt(suggestedFee)
270
276
  if (!account.revealed) {
271
277
  estimation.estimatedFees =
272
- estimation.estimatedFees + BigInt(getRevealFeeForEstimation(account.address))
278
+ estimation.estimatedFees +
279
+ BigInt(getRevealFeeForEstimation(config, account.address))
273
280
  }
274
281
  }
275
282
 
@@ -277,7 +284,9 @@ export async function estimateFees({
277
284
  const totalFees =
278
285
  suggestedFee + (burnFeeMutez > 0 ? burnFeeMutez - 20 * COST_PER_BYTE : 0)
279
286
 
280
- const revealFee = account.revealed ? 0 : getRevealFeeForEstimation(account.address)
287
+ const revealFee = account.revealed
288
+ ? 0
289
+ : getRevealFeeForEstimation(config, account.address)
281
290
  const maxAmount = spendableForMax - (totalFees + revealFee)
282
291
 
283
292
  const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1
@@ -297,14 +306,14 @@ export async function estimateFees({
297
306
  } else {
298
307
  const msg = String((e as any).message || '')
299
308
  if (msg.includes('No signer has been configured')) {
300
- const fallback = createFallbackEstimation()
309
+ const fallback = createFallbackEstimation(config)
301
310
  estimation.fees = fallback.fees
302
311
  estimation.gasLimit = fallback.gasLimit
303
312
  estimation.storageLimit = fallback.storageLimit
304
313
  estimation.estimatedFees = fallback.estimatedFees
305
314
  if (!account.revealed) {
306
315
  estimation.estimatedFees =
307
- estimation.estimatedFees + BigInt(getRevealFeeForEstimation(account.address))
316
+ estimation.estimatedFees + BigInt(getRevealFeeForEstimation(config, account.address))
308
317
  }
309
318
  if (transaction.useAllAmount && transaction.mode === 'send') {
310
319
  const suggestedFee =
@@ -315,14 +324,17 @@ export async function estimateFees({
315
324
  estimation.estimatedFees = BigInt(suggestedFee)
316
325
  if (!account.revealed) {
317
326
  estimation.estimatedFees =
318
- estimation.estimatedFees + BigInt(getRevealFeeForEstimation(account.address))
327
+ estimation.estimatedFees +
328
+ BigInt(getRevealFeeForEstimation(config, account.address))
319
329
  }
320
330
  }
321
331
 
322
332
  const burnFeeMutez = Number(estimation.storageLimit) * COST_PER_BYTE
323
333
  const totalFees =
324
334
  suggestedFee + (burnFeeMutez > 0 ? burnFeeMutez - 20 * COST_PER_BYTE : 0)
325
- const revealFee = account.revealed ? 0 : getRevealFeeForEstimation(account.address)
335
+ const revealFee = account.revealed
336
+ ? 0
337
+ : getRevealFeeForEstimation(config, account.address)
326
338
  const maxAmount = spendableForMax - (totalFees + revealFee)
327
339
  const MINIMAL_FEE_PER_GAS_MUTEZ = 0.1
328
340
  const incr = OP_SIZE_XTZ_TRANSFER + DUST_MARGIN_MUTEZ * MINIMAL_FEE_PER_GAS_MUTEZ
@@ -340,7 +352,7 @@ export async function estimateFees({
340
352
  return estimation
341
353
  }
342
354
 
343
- function getRevealFeeForEstimation(address: string): number {
344
- const minFees = coinConfig.getCoinConfig().fees.minFees ?? 0
355
+ function getRevealFeeForEstimation(config: TezosCoinConfig, address: string): number {
356
+ const minFees = config.fees.minFees ?? 0
345
357
  return Math.max(minFees, getRevealFee(address))
346
358
  }
@@ -1,11 +1,10 @@
1
1
  // SPDX-FileCopyrightText: © 2026 LEDGER SAS
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import type { TezosCoinConfig } from '../config'
4
+ import type { TezosCoinConfig, TezosContext } from '../config'
5
5
  import type { APITokenBalance } from '../network/types'
6
6
  import { HttpResponse, http } from 'msw'
7
7
  import { setupServer } from 'msw/node'
8
- import coinConfig from '../config'
9
8
  import { getBalance } from './getBalance'
10
9
 
11
10
  const mockTokensBalancesWithAllInfo: APITokenBalance[] = [
@@ -62,13 +61,14 @@ describe('getBalance', () => {
62
61
  mockServer.close()
63
62
  })
64
63
 
65
- coinConfig.setCoinConfig(
66
- () =>
64
+ const context: TezosContext = {
65
+ config: async () =>
67
66
  ({
68
67
  status: { type: 'active' },
69
68
  explorer: { url: 'http://tezos.explorer.com' },
70
- }) as unknown as TezosCoinConfig
71
- )
69
+ }) as unknown as TezosCoinConfig,
70
+ logger: () => undefined,
71
+ }
72
72
  it('gets the balance of a Tezos account', async () => {
73
73
  mockServer.use(
74
74
  http.get('http://tezos.explorer.com/v1/accounts/tz1WvvbEGpBXGeTVbLiR6DYBe1izmgiYuZbq', () =>
@@ -100,13 +100,13 @@ describe('getBalance', () => {
100
100
  })
101
101
  )
102
102
 
103
- expect(await getBalance('tz1WvvbEGpBXGeTVbLiR6DYBe1izmgiYuZbq')).toEqual([
103
+ expect(await getBalance(context, 'tz1WvvbEGpBXGeTVbLiR6DYBe1izmgiYuZbq')).toEqual([
104
104
  {
105
105
  value: 0n,
106
106
  asset: { type: 'native' },
107
107
  },
108
108
  ])
109
- expect(await getBalance('tz1TzrmTBSuiVHV2VfMnGRMYvTEPCP42oSM8')).toEqual([
109
+ expect(await getBalance(context, 'tz1TzrmTBSuiVHV2VfMnGRMYvTEPCP42oSM8')).toEqual([
110
110
  {
111
111
  value: BigInt(25),
112
112
  asset: { type: 'native' },
@@ -122,7 +122,7 @@ describe('getBalance', () => {
122
122
  },
123
123
  },
124
124
  ])
125
- expect(await getBalance('tz1TzrmTBSuiVHV2VfMnGRMYvTEPCP42oMMM')).toEqual([
125
+ expect(await getBalance(context, 'tz1TzrmTBSuiVHV2VfMnGRMYvTEPCP42oMMM')).toEqual([
126
126
  {
127
127
  value: 15n,
128
128
  asset: { type: 'native' },
@@ -178,7 +178,7 @@ describe('getBalance', () => {
178
178
  it('attaches a delegation Stake when only delegate is set', async () => {
179
179
  mockAccount({ balance: 100, delegate: { address: delegateAddress } })
180
180
 
181
- expect(await getBalance(address)).toEqual([
181
+ expect(await getBalance(context, address)).toEqual([
182
182
  { value: 100n, asset: { type: 'native' } },
183
183
  {
184
184
  value: 100n,
@@ -203,7 +203,7 @@ describe('getBalance', () => {
203
203
  it('attaches a stake Stake when stakedBalance > 0 (no delegate)', async () => {
204
204
  mockAccount({ balance: 100, stakedBalance: 30 })
205
205
 
206
- expect(await getBalance(address)).toEqual([
206
+ expect(await getBalance(context, address)).toEqual([
207
207
  { value: 100n, asset: { type: 'native' }, locked: 30n },
208
208
  {
209
209
  value: 30n,
@@ -231,7 +231,7 @@ describe('getBalance', () => {
231
231
  delegate: { address: delegateAddress },
232
232
  })
233
233
 
234
- expect(await getBalance(address)).toEqual([
234
+ expect(await getBalance(context, address)).toEqual([
235
235
  { value: 100n, asset: { type: 'native' }, locked: 30n },
236
236
  {
237
237
  value: 70n,
@@ -297,7 +297,7 @@ describe('getBalance', () => {
297
297
  http.get('http://tezos.explorer.com/v1/tokens/balances', () => HttpResponse.json([]))
298
298
  )
299
299
 
300
- const result = await getBalance(address)
300
+ const result = await getBalance(context, address)
301
301
 
302
302
  expect(result).toHaveLength(4)
303
303
  expect(result[0]).toEqual({ value: 100n, asset: { type: 'native' }, locked: 40n })
@@ -352,7 +352,7 @@ describe('getBalance', () => {
352
352
  http.get('http://tezos.explorer.com/v1/tokens/balances', () => HttpResponse.json([]))
353
353
  )
354
354
 
355
- const result = await getBalance(address)
355
+ const result = await getBalance(context, address)
356
356
 
357
357
  expect(result[0]).toEqual({ value: 100n, asset: { type: 'native' }, locked: 50n })
358
358
 
@@ -421,7 +421,7 @@ describe('getBalance', () => {
421
421
  )
422
422
  )
423
423
 
424
- expect(await getBalance(address)).toEqual([
424
+ expect(await getBalance(context, address)).toEqual([
425
425
  { value: 100n, asset: { type: 'native' }, locked: 40n },
426
426
  {
427
427
  value: 30n,
@@ -455,7 +455,9 @@ describe('getBalance', () => {
455
455
  it('returns only the primary native Balance when no staking activity', async () => {
456
456
  mockAccount({ balance: 50 })
457
457
 
458
- expect(await getBalance(address)).toEqual([{ value: 50n, asset: { type: 'native' } }])
458
+ expect(await getBalance(context, address)).toEqual([
459
+ { value: 50n, asset: { type: 'native' } },
460
+ ])
459
461
  })
460
462
 
461
463
  it('still excludes unstaked-frozen funds from spendable when the unstake_requests endpoint fails', async () => {
@@ -474,7 +476,7 @@ describe('getBalance', () => {
474
476
  http.get('http://tezos.explorer.com/v1/tokens/balances', () => HttpResponse.json([]))
475
477
  )
476
478
 
477
- const result = await getBalance(address)
479
+ const result = await getBalance(context, address)
478
480
 
479
481
  // Breakdown rows are lost, but locked/delegated still derive from the account-level unstakedBalance.
480
482
  expect(result).toHaveLength(2)