@ledgerhq/coin-evm 15.2.0 → 16.2.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 (259) hide show
  1. package/.oxlintrc.json +78 -1
  2. package/CHANGELOG.md +45 -0
  3. package/lib/api/index.d.ts +1 -1
  4. package/lib/api/index.d.ts.map +1 -1
  5. package/lib/api/index.js +14 -14
  6. package/lib/api/index.js.map +1 -1
  7. package/lib/chains.d.ts +6 -2
  8. package/lib/chains.d.ts.map +1 -1
  9. package/lib/chains.js +14 -3
  10. package/lib/chains.js.map +1 -1
  11. package/lib/config.d.ts +1 -1
  12. package/lib/config.d.ts.map +1 -1
  13. package/lib/config.js +2 -1
  14. package/lib/config.js.map +1 -1
  15. package/lib/errors.d.ts +11 -0
  16. package/lib/errors.d.ts.map +1 -1
  17. package/lib/errors.js +17 -1
  18. package/lib/errors.js.map +1 -1
  19. package/lib/logic/broadcast.d.ts +1 -1
  20. package/lib/logic/broadcast.d.ts.map +1 -1
  21. package/lib/logic/broadcast.js +2 -2
  22. package/lib/logic/broadcast.js.map +1 -1
  23. package/lib/logic/craftTransaction.d.ts +1 -1
  24. package/lib/logic/craftTransaction.d.ts.map +1 -1
  25. package/lib/logic/craftTransaction.js +3 -3
  26. package/lib/logic/craftTransaction.js.map +1 -1
  27. package/lib/logic/estimateFees.d.ts +1 -1
  28. package/lib/logic/estimateFees.d.ts.map +1 -1
  29. package/lib/logic/estimateFees.js +19 -4
  30. package/lib/logic/estimateFees.js.map +1 -1
  31. package/lib/logic/getBalance.d.ts +1 -2
  32. package/lib/logic/getBalance.d.ts.map +1 -1
  33. package/lib/logic/getBalance.js +5 -6
  34. package/lib/logic/getBalance.js.map +1 -1
  35. package/lib/logic/getBlock.d.ts +1 -1
  36. package/lib/logic/getBlock.d.ts.map +1 -1
  37. package/lib/logic/getBlock.js +2 -2
  38. package/lib/logic/getBlock.js.map +1 -1
  39. package/lib/logic/getBlockInfo.d.ts +1 -1
  40. package/lib/logic/getBlockInfo.d.ts.map +1 -1
  41. package/lib/logic/getBlockInfo.js +2 -2
  42. package/lib/logic/getBlockInfo.js.map +1 -1
  43. package/lib/logic/getNextSequence.d.ts +1 -1
  44. package/lib/logic/getNextSequence.d.ts.map +1 -1
  45. package/lib/logic/getNextSequence.js +2 -2
  46. package/lib/logic/getNextSequence.js.map +1 -1
  47. package/lib/logic/getStakes.d.ts +1 -1
  48. package/lib/logic/getStakes.d.ts.map +1 -1
  49. package/lib/logic/getStakes.js +2 -2
  50. package/lib/logic/getStakes.js.map +1 -1
  51. package/lib/logic/lastBlock.d.ts +1 -1
  52. package/lib/logic/lastBlock.d.ts.map +1 -1
  53. package/lib/logic/lastBlock.js +2 -2
  54. package/lib/logic/lastBlock.js.map +1 -1
  55. package/lib/logic/listOperations.d.ts +1 -1
  56. package/lib/logic/listOperations.d.ts.map +1 -1
  57. package/lib/logic/listOperations.js +2 -2
  58. package/lib/logic/listOperations.js.map +1 -1
  59. package/lib/logic/validateIntent.d.ts +1 -1
  60. package/lib/logic/validateIntent.d.ts.map +1 -1
  61. package/lib/logic/validateIntent.js +3 -3
  62. package/lib/logic/validateIntent.js.map +1 -1
  63. package/lib/logic.d.ts.map +1 -1
  64. package/lib/logic.js +5 -10
  65. package/lib/logic.js.map +1 -1
  66. package/lib/network/node/ledger.d.ts.map +1 -1
  67. package/lib/network/node/ledger.js +1 -9
  68. package/lib/network/node/ledger.js.map +1 -1
  69. package/lib/network/node/rpc.common.d.ts.map +1 -1
  70. package/lib/network/node/rpc.common.js +3 -11
  71. package/lib/network/node/rpc.common.js.map +1 -1
  72. package/lib/network/node/types.d.ts +1 -1
  73. package/lib/network/node/types.d.ts.map +1 -1
  74. package/lib/staking/detectOperationType.js +1 -1
  75. package/lib/staking/fetchers.js +0 -2
  76. package/lib/staking/fetchers.js.map +1 -1
  77. package/lib/staking/unbondings.d.ts.map +1 -1
  78. package/lib/staking/unbondings.js +0 -2
  79. package/lib/staking/unbondings.js.map +1 -1
  80. package/lib/staking/validators/index.d.ts +1 -1
  81. package/lib/staking/validators/index.d.ts.map +1 -1
  82. package/lib/staking/validators/index.js +2 -2
  83. package/lib/staking/validators/index.js.map +1 -1
  84. package/lib/staking/validators/monad.d.ts.map +1 -1
  85. package/lib/staking/validators/monad.js +0 -2
  86. package/lib/staking/validators/monad.js.map +1 -1
  87. package/lib/staking/validators/monadResolver.js +1 -1
  88. package/lib/staking/validators/monadResolver.js.map +1 -1
  89. package/lib/staking/validators/somnia.d.ts.map +1 -1
  90. package/lib/staking/validators/somnia.js +0 -2
  91. package/lib/staking/validators/somnia.js.map +1 -1
  92. package/lib/staking/validators/zero_gravity.d.ts.map +1 -1
  93. package/lib/staking/validators/zero_gravity.js +0 -2
  94. package/lib/staking/validators/zero_gravity.js.map +1 -1
  95. package/lib/types/etherscan.d.ts +1 -1
  96. package/lib/types/etherscan.d.ts.map +1 -1
  97. package/lib-es/api/index.d.ts +1 -1
  98. package/lib-es/api/index.d.ts.map +1 -1
  99. package/lib-es/api/index.js +14 -14
  100. package/lib-es/api/index.js.map +1 -1
  101. package/lib-es/chains.d.ts +6 -2
  102. package/lib-es/chains.d.ts.map +1 -1
  103. package/lib-es/chains.js +13 -2
  104. package/lib-es/chains.js.map +1 -1
  105. package/lib-es/config.d.ts +1 -1
  106. package/lib-es/config.d.ts.map +1 -1
  107. package/lib-es/config.js +1 -1
  108. package/lib-es/config.js.map +1 -1
  109. package/lib-es/errors.d.ts +11 -0
  110. package/lib-es/errors.d.ts.map +1 -1
  111. package/lib-es/errors.js +15 -0
  112. package/lib-es/errors.js.map +1 -1
  113. package/lib-es/logic/broadcast.d.ts +1 -1
  114. package/lib-es/logic/broadcast.d.ts.map +1 -1
  115. package/lib-es/logic/broadcast.js +2 -2
  116. package/lib-es/logic/broadcast.js.map +1 -1
  117. package/lib-es/logic/craftTransaction.d.ts +1 -1
  118. package/lib-es/logic/craftTransaction.d.ts.map +1 -1
  119. package/lib-es/logic/craftTransaction.js +3 -3
  120. package/lib-es/logic/craftTransaction.js.map +1 -1
  121. package/lib-es/logic/estimateFees.d.ts +1 -1
  122. package/lib-es/logic/estimateFees.d.ts.map +1 -1
  123. package/lib-es/logic/estimateFees.js +19 -4
  124. package/lib-es/logic/estimateFees.js.map +1 -1
  125. package/lib-es/logic/getBalance.d.ts +1 -2
  126. package/lib-es/logic/getBalance.d.ts.map +1 -1
  127. package/lib-es/logic/getBalance.js +5 -6
  128. package/lib-es/logic/getBalance.js.map +1 -1
  129. package/lib-es/logic/getBlock.d.ts +1 -1
  130. package/lib-es/logic/getBlock.d.ts.map +1 -1
  131. package/lib-es/logic/getBlock.js +2 -2
  132. package/lib-es/logic/getBlock.js.map +1 -1
  133. package/lib-es/logic/getBlockInfo.d.ts +1 -1
  134. package/lib-es/logic/getBlockInfo.d.ts.map +1 -1
  135. package/lib-es/logic/getBlockInfo.js +2 -2
  136. package/lib-es/logic/getBlockInfo.js.map +1 -1
  137. package/lib-es/logic/getNextSequence.d.ts +1 -1
  138. package/lib-es/logic/getNextSequence.d.ts.map +1 -1
  139. package/lib-es/logic/getNextSequence.js +2 -2
  140. package/lib-es/logic/getNextSequence.js.map +1 -1
  141. package/lib-es/logic/getStakes.d.ts +1 -1
  142. package/lib-es/logic/getStakes.d.ts.map +1 -1
  143. package/lib-es/logic/getStakes.js +2 -2
  144. package/lib-es/logic/getStakes.js.map +1 -1
  145. package/lib-es/logic/lastBlock.d.ts +1 -1
  146. package/lib-es/logic/lastBlock.d.ts.map +1 -1
  147. package/lib-es/logic/lastBlock.js +2 -2
  148. package/lib-es/logic/lastBlock.js.map +1 -1
  149. package/lib-es/logic/listOperations.d.ts +1 -1
  150. package/lib-es/logic/listOperations.d.ts.map +1 -1
  151. package/lib-es/logic/listOperations.js +2 -2
  152. package/lib-es/logic/listOperations.js.map +1 -1
  153. package/lib-es/logic/validateIntent.d.ts +1 -1
  154. package/lib-es/logic/validateIntent.d.ts.map +1 -1
  155. package/lib-es/logic/validateIntent.js +3 -3
  156. package/lib-es/logic/validateIntent.js.map +1 -1
  157. package/lib-es/logic.d.ts.map +1 -1
  158. package/lib-es/logic.js +6 -11
  159. package/lib-es/logic.js.map +1 -1
  160. package/lib-es/network/node/ledger.d.ts.map +1 -1
  161. package/lib-es/network/node/ledger.js +2 -10
  162. package/lib-es/network/node/ledger.js.map +1 -1
  163. package/lib-es/network/node/rpc.common.d.ts.map +1 -1
  164. package/lib-es/network/node/rpc.common.js +4 -12
  165. package/lib-es/network/node/rpc.common.js.map +1 -1
  166. package/lib-es/network/node/types.d.ts +1 -1
  167. package/lib-es/network/node/types.d.ts.map +1 -1
  168. package/lib-es/staking/detectOperationType.js +1 -1
  169. package/lib-es/staking/fetchers.js +0 -2
  170. package/lib-es/staking/fetchers.js.map +1 -1
  171. package/lib-es/staking/unbondings.d.ts.map +1 -1
  172. package/lib-es/staking/unbondings.js +0 -2
  173. package/lib-es/staking/unbondings.js.map +1 -1
  174. package/lib-es/staking/validators/index.d.ts +1 -1
  175. package/lib-es/staking/validators/index.d.ts.map +1 -1
  176. package/lib-es/staking/validators/index.js +2 -2
  177. package/lib-es/staking/validators/index.js.map +1 -1
  178. package/lib-es/staking/validators/monad.d.ts.map +1 -1
  179. package/lib-es/staking/validators/monad.js +0 -2
  180. package/lib-es/staking/validators/monad.js.map +1 -1
  181. package/lib-es/staking/validators/monadResolver.js +1 -1
  182. package/lib-es/staking/validators/monadResolver.js.map +1 -1
  183. package/lib-es/staking/validators/somnia.d.ts.map +1 -1
  184. package/lib-es/staking/validators/somnia.js +0 -2
  185. package/lib-es/staking/validators/somnia.js.map +1 -1
  186. package/lib-es/staking/validators/zero_gravity.d.ts.map +1 -1
  187. package/lib-es/staking/validators/zero_gravity.js +0 -2
  188. package/lib-es/staking/validators/zero_gravity.js.map +1 -1
  189. package/lib-es/types/etherscan.d.ts +1 -1
  190. package/lib-es/types/etherscan.d.ts.map +1 -1
  191. package/package.json +2 -2
  192. package/src/api/index.ts +14 -16
  193. package/src/api/tests/getBlock.integ.test.ts +3 -3
  194. package/src/api/tests/index.arbitrum.integ.test.ts +1 -1
  195. package/src/api/tests/index.arc.integ.test.ts +1 -1
  196. package/src/api/tests/index.avalanche_c_chain_fuji.integ.test.ts +1 -1
  197. package/src/api/tests/index.cronos.integ.test.ts +1 -1
  198. package/src/api/tests/index.flare.integ.test.ts +1 -1
  199. package/src/api/tests/index.integ.test.ts +5 -5
  200. package/src/api/tests/index.linea.integ.test.ts +1 -1
  201. package/src/api/tests/index.monad_testnet.integ.test.ts +1 -1
  202. package/src/api/tests/index.optimism.integ.test.ts +1 -1
  203. package/src/api/tests/index.rsk.integ.test.ts +1 -1
  204. package/src/api/tests/index.shape.integ.test.ts +1 -1
  205. package/src/api/tests/index.somnia.integ.test.ts +1 -1
  206. package/src/api/tests/index.test.ts +6 -6
  207. package/src/api/tests/index.zksync.integ.test.ts +1 -1
  208. package/src/chains.ts +14 -2
  209. package/src/config.ts +1 -1
  210. package/src/errors.ts +14 -0
  211. package/src/fixtures/context.fixtures.ts +2 -4
  212. package/src/logic/broadcast.ts +1 -2
  213. package/src/logic/craftTransaction.ts +2 -3
  214. package/src/logic/estimateFees.ts +22 -4
  215. package/src/logic/getBalance.ts +3 -6
  216. package/src/logic/getBlock.ts +2 -6
  217. package/src/logic/getBlockInfo.ts +2 -6
  218. package/src/logic/getNextSequence.ts +2 -6
  219. package/src/logic/getStakes.ts +1 -2
  220. package/src/logic/lastBlock.ts +2 -2
  221. package/src/logic/listOperations.ts +1 -2
  222. package/src/logic/tests/broadcast.integ.test.ts +1 -1
  223. package/src/logic/tests/broadcast.test.ts +4 -4
  224. package/src/logic/tests/broadcastSource.test.ts +3 -3
  225. package/src/logic/tests/craftTransaction.test.ts +15 -20
  226. package/src/logic/tests/estimateFees.test.ts +39 -17
  227. package/src/logic/tests/getBalance.test.ts +19 -22
  228. package/src/logic/tests/getBlock.test.ts +37 -38
  229. package/src/logic/tests/getBlockInfo.test.ts +5 -5
  230. package/src/logic/tests/getNextSequence.test.ts +1 -1
  231. package/src/logic/tests/getStakes.test.ts +14 -22
  232. package/src/logic/tests/lastBlock.test.ts +3 -3
  233. package/src/logic/tests/listOperations.test.ts +46 -52
  234. package/src/logic/tests/validateIntent.test.ts +3 -61
  235. package/src/logic/validateIntent.ts +2 -3
  236. package/src/logic.test.ts +23 -6
  237. package/src/logic.ts +6 -11
  238. package/src/network/node/ledger.ts +2 -10
  239. package/src/network/node/rpc.common.ts +4 -12
  240. package/src/network/node/types.ts +1 -1
  241. package/src/network/tests/explorer/index.test.ts +4 -4
  242. package/src/network/tests/node/ledger.test.ts +2 -2
  243. package/src/network/tests/node/rpc.test.ts +42 -0
  244. package/src/staking/detectOperationType.ts +1 -1
  245. package/src/staking/fetchers.ts +0 -2
  246. package/src/staking/redelegations.test.ts +3 -3
  247. package/src/staking/unbondings.test.ts +1 -1
  248. package/src/staking/unbondings.ts +0 -2
  249. package/src/staking/validators/index.ts +1 -2
  250. package/src/staking/validators/monad.test.ts +0 -6
  251. package/src/staking/validators/monad.ts +0 -2
  252. package/src/staking/validators/monadResolver.ts +1 -1
  253. package/src/staking/validators/somnia.test.ts +0 -2
  254. package/src/staking/validators/somnia.ts +0 -2
  255. package/src/staking/validators/zero_gravity.test.ts +0 -2
  256. package/src/staking/validators/zero_gravity.ts +0 -2
  257. package/src/staking/validators.integ.test.ts +1 -1
  258. package/src/staking/validators.test.ts +1 -1
  259. package/src/types/etherscan.ts +1 -1
package/src/chains.ts CHANGED
@@ -78,7 +78,6 @@ export const CHAIN_ID = {
78
78
  LINEA: 59144,
79
79
  POLYGON_AMOY: 80002,
80
80
  BERACHAIN: 80094,
81
- BLAST: 81457,
82
81
  BASE_SEPOLIA: 84532,
83
82
  AKROMA: 200625,
84
83
  BITLAYER: 200901,
@@ -90,9 +89,22 @@ export const CHAIN_ID = {
90
89
  MUSICOIN: 7762959,
91
90
  ETHEREUM_SEPOLIA: 11155111,
92
91
  OPTIMISM_SEPOLIA: 11155420,
93
- BLAST_SEPOLIA: 168587773,
94
92
  NEON_EVM: 245022934,
95
93
  PIRL: 3125659152,
96
94
  } as const
97
95
 
98
96
  export type ChainId = (typeof CHAIN_ID)[keyof typeof CHAIN_ID]
97
+
98
+ /**
99
+ * OP Stack chains that bill an L1 data fee on top of L2 execution gas.
100
+ * The fee is read from the GasPriceOracle predeploy (`getL1Fee`).
101
+ * @see https://docs.optimism.io/stack/transactions/fees
102
+ */
103
+ export const OP_STACK_L1_FEE_CHAIN_IDS: readonly ChainId[] = [
104
+ CHAIN_ID.OPTIMISM,
105
+ CHAIN_ID.OPTIMISM_SEPOLIA,
106
+ CHAIN_ID.BASE,
107
+ CHAIN_ID.BASE_SEPOLIA,
108
+ CHAIN_ID.SHAPE,
109
+ CHAIN_ID.BOBA,
110
+ ]
package/src/config.ts CHANGED
@@ -6,7 +6,7 @@ import type { InternalTxSourceList } from './internalTxSources'
6
6
  import type { NodeSourceList } from './nodeSources'
7
7
  import type { Context, CurrencyConfig } from '@ledgerhq/coin-module-framework/config'
8
8
 
9
- export { CHAIN_ID } from './chains'
9
+ export { CHAIN_ID, OP_STACK_L1_FEE_CHAIN_IDS } from './chains'
10
10
  export type { ChainId } from './chains'
11
11
 
12
12
  export type { InternalTxSource, InternalTxSourceList, NonEmptySource } from './internalTxSources'
package/src/errors.ts CHANGED
@@ -133,6 +133,20 @@ export class GasPriceTooLow extends Error {
133
133
  }
134
134
  }
135
135
 
136
+ /**
137
+ * The L1 data fee of a rollup (e.g. OP Stack `GasPriceOracle.getL1Fee`) could not be read.
138
+ * Raised instead of reporting a zero fee, which would under-estimate the total fee.
139
+ */
140
+ export class L1DataFeeUnavailableError extends Error {
141
+ override name = 'L1DataFeeUnavailableError'
142
+ readonly statusCode = 503
143
+ constructor(message?: string, fields?: Record<string, unknown>, options?: { cause?: unknown }) {
144
+ super(message || 'L1 data fee is unavailable, please retry later')
145
+ if (fields) Object.assign(this, fields)
146
+ if (options?.cause !== undefined) Object.assign(this, { cause: options.cause })
147
+ }
148
+ }
149
+
136
150
  export class GasEstimationError extends Error {
137
151
  override name = 'GasEstimationError'
138
152
  constructor(message?: string, fields?: Record<string, unknown>) {
@@ -88,14 +88,12 @@ export const createMockEvmCoinConfig = (
88
88
  /**
89
89
  * Builds a mock {@link EvmContext} for tests.
90
90
  *
91
- * The logic layer resolves its configuration through `context.config(currency.id)`, so this
91
+ * The logic layer resolves its configuration through `context.config()`, so this
92
92
  * accessor is the single source of config for the delegated calls. Pass an optional `config`
93
93
  * to override what `context.config()` resolves to (merged over an `active` status default).
94
- * The `currencyId` argument is accepted for signature parity but ignored — the mock always
95
- * resolves the same config regardless of currency.
96
94
  */
97
95
  export const createMockEvmContext = (config?: Partial<EvmConfigInfo>): EvmContext => ({
98
- config: async (_currencyId?: string): Promise<EvmConfigInfo> =>
96
+ config: async (): Promise<EvmConfigInfo> =>
99
97
  createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode(), ...config }),
100
98
  logger: jest.fn(),
101
99
  })
@@ -7,7 +7,6 @@ import { getNodeApi } from '../network/node/index'
7
7
 
8
8
  export async function broadcast(
9
9
  context: EvmContext,
10
- currencyId: string,
11
10
  {
12
11
  signature,
13
12
  broadcastConfig,
@@ -16,7 +15,7 @@ export async function broadcast(
16
15
  broadcastConfig?: BroadcastConfig | undefined
17
16
  }
18
17
  ): Promise<string> {
19
- const config = await context.config(currencyId)
18
+ const config = await context.config()
20
19
  const nodeApi = getNodeApi(config, context.logger)
21
20
  return await nodeApi.broadcastTransaction(signature, broadcastConfig)
22
21
  }
@@ -20,7 +20,6 @@ import { isFeesStrategy } from './predicates'
20
20
 
21
21
  export async function craftTransaction(
22
22
  context: EvmContext,
23
- currencyId: string,
24
23
  {
25
24
  transactionIntent,
26
25
  customFees,
@@ -29,7 +28,7 @@ export async function craftTransaction(
29
28
  customFees?: FeeEstimation | undefined
30
29
  }
31
30
  ): Promise<CraftedTransaction> {
32
- const config = await context.config(currencyId)
31
+ const config = await context.config()
33
32
  const { type, to, data, value, gasLimit } = await prepareUnsignedTxParams(
34
33
  config,
35
34
  transactionIntent,
@@ -48,7 +47,7 @@ export async function craftTransaction(
48
47
  const nonce =
49
48
  typeof transactionIntent.sequence === 'bigint' && transactionIntent.sequence >= 0n
50
49
  ? transactionIntent.sequence
51
- : await getNextSequence(context, currencyId, transactionIntent.sender)
50
+ : await getNextSequence(context, transactionIntent.sender)
52
51
  const chainId = config.chainId
53
52
 
54
53
  const unsignedTransaction: TransactionLike = {
@@ -14,6 +14,7 @@ import type { Logger } from '@ledgerhq/coin-module-framework/config'
14
14
  import type { TransactionLike } from 'ethers'
15
15
  import BigNumber from 'bignumber.js'
16
16
  import { Transaction } from 'ethers'
17
+ import { L1DataFeeUnavailableError } from '../errors'
17
18
  import { getAdditionalLayer2Fees } from '../logic'
18
19
  import { isEthAddress, isStakingIntent } from '../logic-public'
19
20
  import { getGasTracker } from '../network/gasTracker'
@@ -24,6 +25,12 @@ import { getTransactionType, prepareUnsignedTxParams } from './common'
24
25
  import { getNextSequence } from './getNextSequence'
25
26
  import { isFeesStrategy } from './predicates'
26
27
 
28
+ /**
29
+ * Multiplier applied to the L1 data fee (`additionalFees`) of a send-max estimate only.
30
+ * The L1 fee follows the L1 base fee, which can rise between estimate and broadcast; for a
31
+ * send-max the amount is balance minus fees, so an under-estimate would make the transaction fail.
32
+ * Other estimates return the raw oracle value.
33
+ */
27
34
  const SEND_MAX_L1_FEE_BUFFER = new BigNumber(2)
28
35
 
29
36
  async function computeAdditionalFees(
@@ -41,11 +48,23 @@ async function computeAdditionalFees(
41
48
  },
42
49
  }
43
50
 
51
+ let serialized: string
44
52
  try {
45
- return await getAdditionalLayer2Fees(config, Transaction.from(transaction).serialized, logger)
53
+ serialized = Transaction.from(transaction).serialized
46
54
  } catch {
47
55
  return new BigNumber(0)
48
56
  }
57
+
58
+ try {
59
+ return await getAdditionalLayer2Fees(config, serialized, logger)
60
+ } catch (error) {
61
+ const reason = error instanceof Error ? error.message : String(error)
62
+ throw new L1DataFeeUnavailableError(
63
+ `Could not get the L1 data fee for chain ${config.name}: ${reason}`,
64
+ { chainId: config.chainId },
65
+ { cause: error }
66
+ )
67
+ }
49
68
  }
50
69
 
51
70
  function toApiFeeData(feeData: FeeData): ApiFeeData {
@@ -117,7 +136,6 @@ function extractGasOptions(
117
136
 
118
137
  export async function estimateFees(
119
138
  context: EvmContext,
120
- currencyId: string,
121
139
  transactionIntent: TransactionIntent<MemoNotSupported, BufferTxData>,
122
140
  customFeesParameters?: FeeEstimation['parameters']
123
141
  ): Promise<FeeEstimation> {
@@ -125,7 +143,7 @@ export async function estimateFees(
125
143
  return { value: 0n }
126
144
  }
127
145
 
128
- const config = await context.config(currencyId)
146
+ const config = await context.config()
129
147
 
130
148
  // Skip fee estimation for redelegate without a destination validator — the
131
149
  // validateStaking step in validateIntent will surface RedelegateDstValAddressRequired.
@@ -147,7 +165,7 @@ export async function estimateFees(
147
165
  const noncePromise: Promise<bigint> =
148
166
  typeof transactionIntent.sequence === 'bigint' && transactionIntent.sequence >= 0n
149
167
  ? Promise.resolve(transactionIntent.sequence)
150
- : getNextSequence(context, currencyId, transactionIntent.sender)
168
+ : getNextSequence(context, transactionIntent.sender)
151
169
 
152
170
  const feeDataPromise = (async (): Promise<{
153
171
  finalFeeData: FeeData
@@ -16,23 +16,21 @@ export const TOKEN_BALANCE_BATCH_SIZE = 8
16
16
  /**
17
17
  * Get all assets linked to the user (native, tokens, ...)
18
18
  * @param context - The coin-module context (config + logger)
19
- * @param currencyId - The currency id we must get the balances of
20
19
  * @param address - The user's address
21
20
  * @returns Promise<Balance[]> - Array of balances for all assets (first element will always be the native asset)
22
21
  */
23
22
  export async function getBalance(
24
23
  context: EvmContext,
25
- currencyId: string,
26
24
  address: string,
27
25
  options?: BalanceOptions
28
26
  ): Promise<Balance[]> {
29
- const config = await context.config(currencyId)
27
+ const config = await context.config()
30
28
  const nodeApi = getNodeApi(config, context.logger)
31
29
  const explorerApi = getExplorerApi(config)
32
30
 
33
31
  const [nativeBalance, tokensBalances] = await Promise.all([
34
32
  getNativeBalance(address, nodeApi),
35
- getTokenBalances(context, currencyId, address, nodeApi, explorerApi, config, options),
33
+ getTokenBalances(context, address, nodeApi, explorerApi, config, options),
36
34
  ])
37
35
 
38
36
  return [nativeBalance].concat(tokensBalances)
@@ -50,7 +48,6 @@ async function getNativeBalance(address: string, nodeApi: NodeApi): Promise<Bala
50
48
 
51
49
  async function getTokenBalances(
52
50
  context: EvmContext,
53
- currencyId: string,
54
51
  address: string,
55
52
  nodeApi: NodeApi,
56
53
  explorerApi: ExplorerApi,
@@ -124,7 +121,7 @@ async function getTokenBalances(
124
121
  // Staking and token-asset collection run in parallel; staking depends on the coin operations
125
122
  // fetched above (Monad only), token-asset collection on the discovered/known assets union.
126
123
  const [stakingResult, tokenAssetsResult] = await Promise.allSettled([
127
- getStakes(context, currencyId, address, { knownValidatorIds }),
124
+ getStakes(context, address, { knownValidatorIds }),
128
125
  collectTokenAssets(
129
126
  Array.from(knownAssetsByReference.values()),
130
127
  address,
@@ -21,11 +21,7 @@ import { getNodeApi } from '../network/node'
21
21
  import { createInternalTransactionsFetcher } from './internalTransactionsFetcher'
22
22
  import { dropRootTraceDuplicates } from './rootTraceDedup'
23
23
 
24
- export async function getBlock(
25
- context: EvmContext,
26
- currencyId: string,
27
- height: number
28
- ): Promise<Block> {
24
+ export async function getBlock(context: EvmContext, height: number): Promise<Block> {
29
25
  // Note: to use RPC calls efficiently, the strategy here is:
30
26
  // - fetch the block + transactions in one call (using prefetchTxs=true)
31
27
  // - fetch transaction receipts in one call using eth_getBlockReceipts
@@ -34,7 +30,7 @@ export async function getBlock(
34
30
  // - unless the block is empty, fetch internal transactions (RPC trace methods or explorer,
35
31
  // per `getBlockInternalTxsSources`) in parallel with the receipts, and merge them into the
36
32
  // block transactions
37
- const config = await context.config(currencyId)
33
+ const config = await context.config()
38
34
  const nodeApi = getNodeApi(config, context.logger)
39
35
  const internalTxSources = config.getBlockInternalTxsSources ?? DEFAULT_INTERNAL_TX_SOURCES
40
36
  const fetchInternalTxs = createInternalTransactionsFetcher(
@@ -5,12 +5,8 @@ import type { EvmContext } from '../config'
5
5
  import type { BlockInfo } from '@ledgerhq/coin-module-framework/api/index'
6
6
  import { getNodeApi } from '../network/node'
7
7
 
8
- export async function getBlockInfo(
9
- context: EvmContext,
10
- currencyId: string,
11
- height: number
12
- ): Promise<BlockInfo> {
13
- const config = await context.config(currencyId)
8
+ export async function getBlockInfo(context: EvmContext, height: number): Promise<BlockInfo> {
9
+ const config = await context.config()
14
10
  const api = getNodeApi(config, context.logger)
15
11
  const result = await api.getBlockByHeight(height)
16
12
 
@@ -4,12 +4,8 @@
4
4
  import type { EvmContext } from '../config'
5
5
  import { getNodeApi } from '../network/node'
6
6
 
7
- export async function getNextSequence(
8
- context: EvmContext,
9
- currencyId: string,
10
- address: string
11
- ): Promise<bigint> {
12
- const config = await context.config(currencyId)
7
+ export async function getNextSequence(context: EvmContext, address: string): Promise<bigint> {
8
+ const config = await context.config()
13
9
  const txCount = await getNodeApi(config, context.logger).getTransactionCount(address)
14
10
  return typeof txCount === 'number' ? BigInt(txCount) : txCount
15
11
  }
@@ -8,12 +8,11 @@ import { fetchUnbondings } from '../staking/unbondings'
8
8
 
9
9
  export const getStakes = async (
10
10
  context: EvmContext,
11
- currencyId: string,
12
11
  address: string,
13
12
  options?: StakesOptions
14
13
  ): Promise<Page<Stake>> => {
15
14
  try {
16
- const config = await context.config(currencyId)
15
+ const config = await context.config()
17
16
  const contractConfig = STAKING_CONTRACTS[config.chainId]
18
17
  if (!contractConfig) {
19
18
  return { items: [] }
@@ -5,8 +5,8 @@ import type { EvmContext } from '../config'
5
5
  import type { BlockInfo } from '@ledgerhq/coin-module-framework/api/index'
6
6
  import { getNodeApi } from '../network/node'
7
7
 
8
- export async function lastBlock(context: EvmContext, currencyId: string): Promise<BlockInfo> {
9
- const config = await context.config(currencyId)
8
+ export async function lastBlock(context: EvmContext): Promise<BlockInfo> {
9
+ const config = await context.config()
10
10
  const api = getNodeApi(config, context.logger)
11
11
  const { finalizationLevel = 'latest' } = config
12
12
  const result = await api.getBlockByHeight(finalizationLevel)
@@ -44,7 +44,6 @@ function typeFromAddressPerspective(
44
44
 
45
45
  export async function listOperations(
46
46
  context: EvmContext,
47
- currencyId: string,
48
47
  address: string,
49
48
  options: ListOperationsOptions
50
49
  ): Promise<Page<Operation<MemoNotSupported>>> {
@@ -59,7 +58,7 @@ export async function listOperations(
59
58
  )
60
59
  }
61
60
 
62
- const config = await context.config(currencyId)
61
+ const config = await context.config()
63
62
  const explorerApi = getExplorerApi(config)
64
63
  const explorerOrder = options.limit === undefined ? 'desc' : (options.order ?? 'desc')
65
64
  const {
@@ -46,7 +46,7 @@ describe('Broadcast', () => {
46
46
  }
47
47
  const signature = await wallet.signTransaction(tx)
48
48
 
49
- await expect(broadcast(contextForNetwork(network), network, { signature })).rejects.toThrow(
49
+ await expect(broadcast(contextForNetwork(network), { signature })).rejects.toThrow(
50
50
  /insufficient funds for gas \* price \+ value|InsufficientFunds/
51
51
  )
52
52
  })
@@ -23,7 +23,7 @@ describe('broadcastLogic', () => {
23
23
 
24
24
  it('should call getNodeApi and broadcastTransaction with correct arguments', async () => {
25
25
  nodeApiMock.broadcastTransaction.mockResolvedValue('txid123')
26
- const result = await broadcast(mockEvmContext, 'ethereum', {
26
+ const result = await broadcast(mockEvmContext, {
27
27
  signature: '0xabcdef',
28
28
  broadcastConfig: { mevProtected: true },
29
29
  })
@@ -37,7 +37,7 @@ describe('broadcastLogic', () => {
37
37
  it('should propagate errors from broadcastTransaction', async () => {
38
38
  nodeApiMock.broadcastTransaction.mockRejectedValue(new Error('Broadcast failed'))
39
39
  await expect(
40
- broadcast(mockEvmContext, 'ethereum', {
40
+ broadcast(mockEvmContext, {
41
41
  signature: '0xabcdef',
42
42
  broadcastConfig: { mevProtected: true },
43
43
  })
@@ -46,7 +46,7 @@ describe('broadcastLogic', () => {
46
46
 
47
47
  it('should handle undefined broadcastConfig', async () => {
48
48
  nodeApiMock.broadcastTransaction.mockResolvedValue('txid456')
49
- const result = await broadcast(mockEvmContext, 'ethereum', {
49
+ const result = await broadcast(mockEvmContext, {
50
50
  signature: '0xabcdef',
51
51
  broadcastConfig: undefined,
52
52
  })
@@ -56,7 +56,7 @@ describe('broadcastLogic', () => {
56
56
 
57
57
  it('should handle different signature values', async () => {
58
58
  nodeApiMock.broadcastTransaction.mockResolvedValue('txid789')
59
- const result = await broadcast(mockEvmContext, 'ethereum', {
59
+ const result = await broadcast(mockEvmContext, {
60
60
  signature: '0x123456',
61
61
  broadcastConfig: { mevProtected: true },
62
62
  })
@@ -23,7 +23,7 @@ describe('EVM broadcast with source', () => {
23
23
  })
24
24
 
25
25
  it('should broadcast with source headers from broadcastConfig', async () => {
26
- const result = await broadcast(mockEvmContext, 'ethereum', {
26
+ const result = await broadcast(mockEvmContext, {
27
27
  signature: '0xsignature',
28
28
  broadcastConfig: {
29
29
  mevProtected: true,
@@ -48,7 +48,7 @@ describe('EVM broadcast with source', () => {
48
48
  })
49
49
 
50
50
  it('should broadcast swap transaction with swap source', async () => {
51
- const result = await broadcast(mockEvmContext, 'ethereum', {
51
+ const result = await broadcast(mockEvmContext, {
52
52
  signature: '0xsignature',
53
53
  broadcastConfig: {
54
54
  mevProtected: false,
@@ -73,7 +73,7 @@ describe('EVM broadcast with source', () => {
73
73
  })
74
74
 
75
75
  it('should broadcast without source when not provided', async () => {
76
- const result = await broadcast(mockEvmContext, 'ethereum', {
76
+ const result = await broadcast(mockEvmContext, {
77
77
  signature: '0xsignature',
78
78
  broadcastConfig: {
79
79
  mevProtected: false,
@@ -37,7 +37,7 @@ describe('craftTransaction', () => {
37
37
 
38
38
  it('fails to craft an unknown intent type', async () => {
39
39
  await expect(
40
- craftTransaction(createMockEvmContext(), 'ethereum', {
40
+ craftTransaction(createMockEvmContext(), {
41
41
  // @ts-ignore — intentionally invalid intent type to test the unsupported-type error path
42
42
  transactionIntent: { type: 'any' },
43
43
  })
@@ -69,7 +69,6 @@ describe('craftTransaction', () => {
69
69
 
70
70
  const { transaction } = await craftTransaction(
71
71
  createMockEvmContext({ node: mkExternalNode(), chainId: 42 }),
72
- 'ethereum',
73
72
  {
74
73
  transactionIntent: intent,
75
74
  customFees: { value: 0n, parameters: { gasPrice: 8n, gasLimit: 0n } },
@@ -84,14 +83,10 @@ describe('craftTransaction', () => {
84
83
  externalMocks.getGasEstimation.mockRejectedValue(new Error('node is down'))
85
84
 
86
85
  await expect(
87
- craftTransaction(
88
- createMockEvmContext({ node: mkExternalNode(), chainId: 42 }),
89
- 'ethereum',
90
- {
91
- transactionIntent: intent,
92
- customFees: { value: 0n, parameters: { gasPrice: 8n } },
93
- }
94
- )
86
+ craftTransaction(createMockEvmContext({ node: mkExternalNode(), chainId: 42 }), {
87
+ transactionIntent: intent,
88
+ customFees: { value: 0n, parameters: { gasPrice: 8n } },
89
+ })
95
90
  ).rejects.toThrow('GasEstimationError')
96
91
  })
97
92
  })
@@ -134,7 +129,7 @@ describe('craftTransaction', () => {
134
129
  mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
135
130
  mocks.getFeeData.mockResolvedValue(feeData)
136
131
 
137
- const { transaction } = await craftTransaction(context, 'ethereum', {
132
+ const { transaction } = await craftTransaction(context, {
138
133
  transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
139
134
  type: `send-${transactionType}`,
140
135
  recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
@@ -172,7 +167,7 @@ describe('craftTransaction', () => {
172
167
  mocks.getGasEstimation.mockResolvedValue(new BigNumber(2300))
173
168
  mocks.getFeeData.mockResolvedValue(feeData)
174
169
 
175
- const { transaction } = await craftTransaction(context, 'ethereum', {
170
+ const { transaction } = await craftTransaction(context, {
176
171
  transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
177
172
  type: `send-${transactionType}`,
178
173
  recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
@@ -219,7 +214,7 @@ describe('craftTransaction', () => {
219
214
  const context = createMockEvmContext({ node: nodeFor(type), chainId: 42 })
220
215
  mocks.getTransactionCount.mockResolvedValue(18)
221
216
 
222
- const { transaction } = await craftTransaction(context, 'ethereum', {
217
+ const { transaction } = await craftTransaction(context, {
223
218
  transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
224
219
  type: `send-${transactionType}`,
225
220
  recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
@@ -280,7 +275,7 @@ describe('craftTransaction', () => {
280
275
  nextBaseFee: null,
281
276
  })
282
277
 
283
- const { transaction } = await craftTransaction(context, 'ethereum', {
278
+ const { transaction } = await craftTransaction(context, {
284
279
  transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
285
280
  type: 'send-legacy',
286
281
  recipient: '0x7b2c7232f9e38f30e2868f0e5bf311cd83554b5a',
@@ -314,7 +309,7 @@ describe('craftTransaction', () => {
314
309
  nextBaseFee: null,
315
310
  })
316
311
 
317
- const { transaction } = await craftTransaction(context, 'ethereum', {
312
+ const { transaction } = await craftTransaction(context, {
318
313
  transactionIntent: createSendTransactionIntentMockData<MemoNotSupported, BufferTxData>({
319
314
  type: 'send-legacy',
320
315
  sequence: 15n,
@@ -385,7 +380,7 @@ describe('craftTransaction', () => {
385
380
  mocks.getGasEstimation.mockResolvedValue(new BigNumber(45000))
386
381
  mocks.getFeeData.mockResolvedValue(feeData)
387
382
 
388
- const { transaction } = await craftTransaction(context, 'sei_evm', {
383
+ const { transaction } = await craftTransaction(context, {
389
384
  transactionIntent: createStakingTransactionIntentMockData<
390
385
  MemoNotSupported,
391
386
  BufferTxData
@@ -427,7 +422,7 @@ describe('craftTransaction', () => {
427
422
  mocks.getGasEstimation.mockResolvedValue(new BigNumber(50000))
428
423
  mocks.getFeeData.mockResolvedValue(feeData)
429
424
 
430
- const { transaction } = await craftTransaction(context, 'sei_evm', {
425
+ const { transaction } = await craftTransaction(context, {
431
426
  transactionIntent: createStakingTransactionIntentMockData<
432
427
  MemoNotSupported,
433
428
  BufferTxData
@@ -466,7 +461,7 @@ describe('craftTransaction', () => {
466
461
  mocks.getGasEstimation.mockResolvedValue(new BigNumber(60000))
467
462
  mocks.getFeeData.mockResolvedValue(feeData)
468
463
 
469
- const { transaction } = await craftTransaction(context, 'celo', {
464
+ const { transaction } = await craftTransaction(context, {
470
465
  transactionIntent: createStakingTransactionIntentMockData<
471
466
  MemoNotSupported,
472
467
  BufferTxData
@@ -500,7 +495,7 @@ describe('craftTransaction', () => {
500
495
  const context = createMockEvmContext({ node: mkExternalNode() })
501
496
 
502
497
  await expect(
503
- craftTransaction(context, 'unsupported_network', {
498
+ craftTransaction(context, {
504
499
  // @ts-expect-error bare staking intent
505
500
  transactionIntent: { type: 'staking', mode: 'delegate' },
506
501
  })
@@ -513,7 +508,7 @@ describe('craftTransaction', () => {
513
508
  const context = createMockEvmContext({ node: mkExternalNode(), chainId: CHAIN_ID.SEI_EVM })
514
509
 
515
510
  await expect(
516
- craftTransaction(context, 'sei_evm', {
511
+ craftTransaction(context, {
517
512
  transactionIntent: {
518
513
  type: 'staking-legacy',
519
514
  intentType: 'staking',