@ledgerhq/coin-evm 15.0.0 → 15.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.
- package/CHANGELOG.md +16 -0
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +14 -0
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.d.ts.map +1 -1
- package/lib/adapters/ledger.js +2 -0
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +0 -1
- package/lib/api/index.js.map +1 -1
- package/lib/chains.d.ts +1 -0
- package/lib/chains.d.ts.map +1 -1
- package/lib/chains.js +1 -0
- package/lib/chains.js.map +1 -1
- package/lib/logic/getBlock.js +21 -4
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +2 -0
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/network/node/explorerProxy.d.ts.map +1 -1
- package/lib/network/node/explorerProxy.js +2 -0
- package/lib/network/node/explorerProxy.js.map +1 -1
- package/lib/network/node/ledger.d.ts.map +1 -1
- package/lib/network/node/ledger.js +1 -0
- package/lib/network/node/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +17 -0
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +3 -1
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js.map +1 -1
- package/lib-es/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +14 -0
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/adapters/ledger.d.ts.map +1 -1
- package/lib-es/adapters/ledger.js +2 -0
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +0 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/chains.d.ts +1 -0
- package/lib-es/chains.d.ts.map +1 -1
- package/lib-es/chains.js +1 -0
- package/lib-es/chains.js.map +1 -1
- package/lib-es/logic/getBlock.js +21 -4
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/logic/listOperations.d.ts.map +1 -1
- package/lib-es/logic/listOperations.js +2 -0
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/network/node/explorerProxy.d.ts.map +1 -1
- package/lib-es/network/node/explorerProxy.js +2 -0
- package/lib-es/network/node/explorerProxy.js.map +1 -1
- package/lib-es/network/node/ledger.d.ts.map +1 -1
- package/lib-es/network/node/ledger.js +1 -0
- package/lib-es/network/node/ledger.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +17 -0
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +3 -1
- package/lib-es/network/node/types.d.ts.map +1 -1
- package/lib-es/network/node/types.js.map +1 -1
- package/package.json +2 -2
- package/src/adapters/etherscan.test.ts +57 -5
- package/src/adapters/etherscan.ts +15 -0
- package/src/adapters/ledger.test.ts +57 -9
- package/src/adapters/ledger.ts +2 -0
- package/src/api/index.ts +0 -1
- package/src/api/{getBlock.integ.test.ts → tests/getBlock.integ.test.ts} +4 -4
- package/src/api/{index.arbitrum.integ.test.ts → tests/index.arbitrum.integ.test.ts} +3 -3
- package/src/api/{index.arc.integ.test.ts → tests/index.arc.integ.test.ts} +3 -3
- package/src/api/{index.avalanche_c_chain_fuji.integ.test.ts → tests/index.avalanche_c_chain_fuji.integ.test.ts} +3 -3
- package/src/api/{index.cronos.integ.test.ts → tests/index.cronos.integ.test.ts} +3 -3
- package/src/api/{index.flare.integ.test.ts → tests/index.flare.integ.test.ts} +3 -3
- package/src/api/{index.integ.test.ts → tests/index.integ.test.ts} +3 -3
- package/src/api/{index.linea.integ.test.ts → tests/index.linea.integ.test.ts} +3 -3
- package/src/api/{index.monad_testnet.integ.test.ts → tests/index.monad_testnet.integ.test.ts} +4 -4
- package/src/api/{index.optimism.integ.test.ts → tests/index.optimism.integ.test.ts} +3 -3
- package/src/api/{index.rsk.integ.test.ts → tests/index.rsk.integ.test.ts} +3 -3
- package/src/api/{index.shape.integ.test.ts → tests/index.shape.integ.test.ts} +3 -3
- package/src/api/{index.somnia.integ.test.ts → tests/index.somnia.integ.test.ts} +3 -3
- package/src/api/{index.test.ts → tests/index.test.ts} +4 -4
- package/src/api/{index.zksync.integ.test.ts → tests/index.zksync.integ.test.ts} +2 -2
- package/src/chains.ts +1 -0
- package/src/logic/getBlock.ts +37 -4
- package/src/logic/listOperations.ts +2 -0
- package/src/logic/tests/broadcast.test.ts +1 -1
- package/src/logic/tests/broadcastSource.test.ts +1 -1
- package/src/logic/tests/common.test.ts +1 -1
- package/src/logic/tests/craftTransaction.test.ts +1 -1
- package/src/logic/tests/estimateFees.test.ts +1 -1
- package/src/logic/tests/getBalance.test.ts +1 -1
- package/src/logic/tests/getBlock.test.ts +126 -5
- package/src/logic/tests/getBlockInfo.test.ts +1 -1
- package/src/logic/tests/getNextSequence.test.ts +1 -1
- package/src/logic/tests/internalTransactionsFetcher.test.ts +1 -1
- package/src/logic/tests/lastBlock.test.ts +1 -1
- package/src/logic/tests/listOperations.test.ts +5 -3
- package/src/logic/tests/validateIntent.test.ts +37 -1
- package/src/logic.test.ts +1 -1
- package/src/network/node/explorerProxy.ts +2 -0
- package/src/network/node/ledger.ts +1 -0
- package/src/network/node/rpc.common.ts +21 -0
- package/src/network/node/types.ts +5 -2
- package/src/network/{explorer → tests/explorer}/etherscan.test.ts +8 -8
- package/src/network/{explorer → tests/explorer}/index.test.ts +7 -7
- package/src/network/{explorer → tests/explorer}/ledger.test.ts +11 -11
- package/src/network/{explorer → tests/explorer}/types.test.ts +1 -1
- package/src/network/{gasTracker → tests/gasTracker}/index.test.ts +3 -3
- package/src/network/{gasTracker → tests/gasTracker}/ledger.test.ts +4 -4
- package/src/network/{gasTracker → tests/gasTracker}/types.test.ts +1 -1
- package/src/network/{node → tests/node}/explorerProxy.test.ts +5 -2
- package/src/network/{node → tests/node}/gethCallTracerToTraceBlockItems.test.ts +4 -4
- package/src/network/{node → tests/node}/index.memoization.test.ts +3 -3
- package/src/network/{node → tests/node}/index.test.ts +3 -3
- package/src/network/{node → tests/node}/ledger.test.ts +7 -6
- package/src/network/{node → tests/node}/node.fixtures.ts +1 -1
- package/src/network/{node → tests/node}/rpc.errors.test.ts +1 -1
- package/src/network/{node → tests/node}/rpc.test.ts +15 -6
- package/src/network/{node → tests/node}/types.test.ts +1 -1
- package/src/network/{node → tests/node}/withNodeSources.test.ts +3 -3
- package/src/network/{withRetries.test.ts → tests/withRetries.test.ts} +2 -2
package/src/logic/getBlock.ts
CHANGED
|
@@ -229,7 +229,12 @@ function prefetchedTransactionToBlockTransaction(
|
|
|
229
229
|
logger
|
|
230
230
|
)
|
|
231
231
|
|
|
232
|
-
const details =
|
|
232
|
+
const details = buildTransactionDetails(
|
|
233
|
+
gasPrice,
|
|
234
|
+
tx.gasLimit,
|
|
235
|
+
tx.nonce,
|
|
236
|
+
buildSmartContractDetails(tx.to, tx.input, logger, receipt.contractAddress)
|
|
237
|
+
)
|
|
233
238
|
|
|
234
239
|
return {
|
|
235
240
|
hash: tx.hash,
|
|
@@ -237,7 +242,7 @@ function prefetchedTransactionToBlockTransaction(
|
|
|
237
242
|
operations,
|
|
238
243
|
fees,
|
|
239
244
|
feesPayer: tx.from,
|
|
240
|
-
|
|
245
|
+
details,
|
|
241
246
|
}
|
|
242
247
|
}
|
|
243
248
|
|
|
@@ -256,7 +261,12 @@ async function getTransactionFromHash(
|
|
|
256
261
|
const rawOperations = rpcTransactionToBlockOperations(txInfo, logger)
|
|
257
262
|
const operations = applyChainSpecificCorrections(chainId, rawOperations, txInfo.type, logger)
|
|
258
263
|
|
|
259
|
-
const details =
|
|
264
|
+
const details = buildTransactionDetails(
|
|
265
|
+
BigInt(txInfo.gasPrice),
|
|
266
|
+
txInfo.gasLimit,
|
|
267
|
+
txInfo.nonce,
|
|
268
|
+
buildSmartContractDetails(txInfo.to, txInfo.input, logger, txInfo.contractAddress)
|
|
269
|
+
)
|
|
260
270
|
|
|
261
271
|
return {
|
|
262
272
|
hash: txHash,
|
|
@@ -264,7 +274,30 @@ async function getTransactionFromHash(
|
|
|
264
274
|
operations,
|
|
265
275
|
fees,
|
|
266
276
|
feesPayer: txInfo.from,
|
|
267
|
-
|
|
277
|
+
details,
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Builds the transaction details. The gas and nonce keys match the ones set by
|
|
283
|
+
* {@link listOperations}, so consumers get the same keys whichever sync wrote the transaction.
|
|
284
|
+
*
|
|
285
|
+
* @param gasPrice gas price actually paid, in wei
|
|
286
|
+
* @param gasLimit gas limit set by the sender (decimal), when known
|
|
287
|
+
* @param nonce nonce of the transaction, when known
|
|
288
|
+
* @param smartContractDetails details of the contract interaction or deployment, if any
|
|
289
|
+
*/
|
|
290
|
+
function buildTransactionDetails(
|
|
291
|
+
gasPrice: bigint,
|
|
292
|
+
gasLimit: string | undefined,
|
|
293
|
+
nonce: number | undefined,
|
|
294
|
+
smartContractDetails: Record<string, unknown> | undefined
|
|
295
|
+
): Record<string, unknown> {
|
|
296
|
+
return {
|
|
297
|
+
gasPrice: gasPrice.toString(),
|
|
298
|
+
...(gasLimit !== undefined ? { gasLimit } : {}),
|
|
299
|
+
...(nonce !== undefined ? { sequence: nonce } : {}),
|
|
300
|
+
...(smartContractDetails ?? {}),
|
|
268
301
|
}
|
|
269
302
|
}
|
|
270
303
|
|
|
@@ -146,6 +146,8 @@ export async function listOperations(
|
|
|
146
146
|
details: {
|
|
147
147
|
...(op.details ?? {}),
|
|
148
148
|
sequence: op.details?.sequence ?? parent.details?.sequence,
|
|
149
|
+
gasPrice: op.details?.gasPrice ?? parent.details?.gasPrice,
|
|
150
|
+
gasLimit: op.details?.gasLimit ?? parent.details?.gasLimit,
|
|
149
151
|
parentSenders: parent.senders,
|
|
150
152
|
parentRecipients: parent.recipients,
|
|
151
153
|
...parentContractDetails,
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { mockEvmContext } from '../../fixtures/context.fixtures'
|
|
5
5
|
import { getNodeApi } from '../../network/node/index'
|
|
6
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
6
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
7
7
|
import { broadcast } from '../broadcast'
|
|
8
8
|
|
|
9
9
|
jest.mock('../../network/node/index', () => ({
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { mockEvmContext } from '../../fixtures/context.fixtures'
|
|
5
5
|
import { getNodeApi } from '../../network/node/index'
|
|
6
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
6
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
7
7
|
import { broadcast } from '../broadcast'
|
|
8
8
|
|
|
9
9
|
jest.mock('../../network/node/index', () => ({
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
testLogger,
|
|
16
16
|
} from '../../fixtures/context.fixtures'
|
|
17
17
|
import { getNodeApi } from '../../network/node'
|
|
18
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
18
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
19
19
|
import { buildStakingTransactionParams } from '../../staking'
|
|
20
20
|
import { USEI_TO_EVM_SCALE } from '../../staking/utils'
|
|
21
21
|
import { getCallData, prepareUnsignedTxParams } from '../common'
|
|
@@ -12,7 +12,7 @@ import { ethers } from 'ethers'
|
|
|
12
12
|
import { CHAIN_ID } from '../../config'
|
|
13
13
|
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../../fixtures/context.fixtures'
|
|
14
14
|
import { getNodeApi } from '../../network/node'
|
|
15
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
15
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
16
16
|
import { craftTransaction } from '../craftTransaction'
|
|
17
17
|
|
|
18
18
|
jest.mock('../../network/node', () => ({
|
|
@@ -15,7 +15,7 @@ import { GasEstimationError } from '../../errors'
|
|
|
15
15
|
import { createMockEvmContext } from '../../fixtures/context.fixtures'
|
|
16
16
|
import { getGasTracker } from '../../network/gasTracker'
|
|
17
17
|
import { getNodeApi } from '../../network/node'
|
|
18
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
18
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
19
19
|
import { estimateFees } from '../estimateFees'
|
|
20
20
|
|
|
21
21
|
jest.mock('../../network/node', () => ({
|
|
@@ -9,7 +9,7 @@ import { CHAIN_ID } from '../../config'
|
|
|
9
9
|
import { createMockEvmContext } from '../../fixtures/context.fixtures'
|
|
10
10
|
import { getExplorerApi } from '../../network/explorer'
|
|
11
11
|
import { getNodeApi } from '../../network/node'
|
|
12
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
12
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
13
13
|
import { getStakes } from '../getStakes'
|
|
14
14
|
import { getBalance } from '../index'
|
|
15
15
|
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
import { safeEncodeEIP55 } from '../../logic-public'
|
|
27
27
|
import { getInternalTransactionsByBlock } from '../../network/explorer/etherscan'
|
|
28
28
|
import { getNodeApi } from '../../network/node'
|
|
29
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
29
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
30
30
|
import { getBlock } from '../getBlock'
|
|
31
31
|
import { dropRootTraceDuplicates } from '../rootTraceDedup'
|
|
32
32
|
|
|
@@ -401,10 +401,131 @@ describe('getBlock', () => {
|
|
|
401
401
|
|
|
402
402
|
const result = await getBlock(context, '', 12345)
|
|
403
403
|
|
|
404
|
-
expect(
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
404
|
+
expect(result.transactions[0].details).not.toHaveProperty('contractInteraction')
|
|
405
|
+
})
|
|
406
|
+
|
|
407
|
+
it('adds the receipt gas price, the gas limit and the nonce to prefetched tx details', async () => {
|
|
408
|
+
const context = createMockEvmContext(
|
|
409
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
mockGetBlockNodeApi(
|
|
413
|
+
mockNodeApi({
|
|
414
|
+
getBlockByHeight: jest.fn().mockResolvedValueOnce(
|
|
415
|
+
makeNodeBlock({
|
|
416
|
+
transactions: [
|
|
417
|
+
makeNodeBlockTx({
|
|
418
|
+
hash: '0xtx1',
|
|
419
|
+
gasPrice: '30000000000', // maxFeePerGas fallback of a type-2 tx: must NOT win
|
|
420
|
+
gasLimit: '73330',
|
|
421
|
+
nonce: 42,
|
|
422
|
+
}),
|
|
423
|
+
],
|
|
424
|
+
})
|
|
425
|
+
),
|
|
426
|
+
getBlockReceipts: jest
|
|
427
|
+
.fn()
|
|
428
|
+
.mockResolvedValueOnce([makeNodeBlockReceipt({ hash: '0xtx1', gasPrice: '1000000000' })]),
|
|
429
|
+
getTransaction: jest.fn(),
|
|
430
|
+
})
|
|
431
|
+
)
|
|
432
|
+
|
|
433
|
+
const result = await getBlock(context, '', 12345)
|
|
434
|
+
|
|
435
|
+
expect(result.transactions[0].details).toEqual({
|
|
436
|
+
gasPrice: '1000000000',
|
|
437
|
+
gasLimit: '73330',
|
|
438
|
+
sequence: 42,
|
|
439
|
+
})
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
it('adds the gas price, the gas limit and the nonce to contract details', async () => {
|
|
443
|
+
const context = createMockEvmContext(
|
|
444
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
mockGetBlockNodeApi(
|
|
448
|
+
mockNodeApi({
|
|
449
|
+
getBlockByHeight: jest.fn().mockResolvedValueOnce(
|
|
450
|
+
makeNodeBlock({
|
|
451
|
+
transactions: [
|
|
452
|
+
makeNodeBlockTx({ hash: '0xtx1', input: '0xdeadbeef', gasLimit: '73330', nonce: 0 }),
|
|
453
|
+
],
|
|
454
|
+
})
|
|
455
|
+
),
|
|
456
|
+
getBlockReceipts: jest
|
|
457
|
+
.fn()
|
|
458
|
+
.mockResolvedValueOnce([makeNodeBlockReceipt({ hash: '0xtx1', gasPrice: '1000000000' })]),
|
|
459
|
+
getTransaction: jest.fn(),
|
|
460
|
+
})
|
|
461
|
+
)
|
|
462
|
+
|
|
463
|
+
const result = await getBlock(context, '', 12345)
|
|
464
|
+
|
|
465
|
+
expect(result.transactions[0].details).toEqual({
|
|
466
|
+
gasPrice: '1000000000',
|
|
467
|
+
gasLimit: '73330',
|
|
468
|
+
sequence: 0,
|
|
469
|
+
contractInteraction: 'SmartContractInteraction',
|
|
470
|
+
contractAddress: safeEncodeEIP55(address2, testLogger),
|
|
471
|
+
contractPayload: '0xdeadbeef',
|
|
472
|
+
})
|
|
473
|
+
})
|
|
474
|
+
|
|
475
|
+
it('omits the gas limit and the nonce when the prefetched tx does not report them', async () => {
|
|
476
|
+
const context = createMockEvmContext(
|
|
477
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
478
|
+
)
|
|
479
|
+
|
|
480
|
+
mockGetBlockNodeApi(
|
|
481
|
+
mockNodeApi({
|
|
482
|
+
getBlockByHeight: jest
|
|
483
|
+
.fn()
|
|
484
|
+
.mockResolvedValueOnce(makeNodeBlock({ transactions: [makeNodeBlockTx()] })),
|
|
485
|
+
getBlockReceipts: jest.fn().mockResolvedValueOnce([makeNodeBlockReceipt()]),
|
|
486
|
+
getTransaction: jest.fn(),
|
|
487
|
+
})
|
|
488
|
+
)
|
|
489
|
+
|
|
490
|
+
const result = await getBlock(context, '', 12345)
|
|
491
|
+
|
|
492
|
+
expect(result.transactions[0].details).toEqual({ gasPrice: '20000000000' })
|
|
493
|
+
})
|
|
494
|
+
|
|
495
|
+
it('adds the gas price, the gas limit and the nonce when falling back to getTransaction', async () => {
|
|
496
|
+
const context = createMockEvmContext(
|
|
497
|
+
createMockEvmConfigInfo({ chainId: 1, node: mkExternalNode() })
|
|
498
|
+
)
|
|
499
|
+
|
|
500
|
+
mockGetBlockNodeApi(
|
|
501
|
+
mockNodeApi({
|
|
502
|
+
getBlockByHeight: jest
|
|
503
|
+
.fn()
|
|
504
|
+
.mockResolvedValueOnce(makeNodeBlock({ transactions: [makeNodeBlockTx()] })),
|
|
505
|
+
getBlockReceipts: jest.fn().mockRejectedValueOnce(
|
|
506
|
+
new UnsupportedRpcMethodError(
|
|
507
|
+
'eth_getBlockReceipts is not supported by this RPC provider',
|
|
508
|
+
{
|
|
509
|
+
method: 'eth_getBlockReceipts',
|
|
510
|
+
rawError: { code: -32601 },
|
|
511
|
+
}
|
|
512
|
+
)
|
|
513
|
+
),
|
|
514
|
+
getTransaction: jest
|
|
515
|
+
.fn()
|
|
516
|
+
.mockResolvedValueOnce(
|
|
517
|
+
makeNodeTxInfo({ gasPrice: '1000000000', gasLimit: '21000', nonce: 7 })
|
|
518
|
+
),
|
|
519
|
+
})
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
const result = await getBlock(context, '', 12345)
|
|
523
|
+
|
|
524
|
+
expect(result.transactions[0].details).toEqual({
|
|
525
|
+
gasPrice: '1000000000',
|
|
526
|
+
gasLimit: '21000',
|
|
527
|
+
sequence: 7,
|
|
528
|
+
})
|
|
408
529
|
})
|
|
409
530
|
|
|
410
531
|
it('adds contract details when falling back to getTransaction with non-trivial input', async () => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { EvmConfigInfo } from '../../config'
|
|
5
5
|
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../../fixtures/context.fixtures'
|
|
6
6
|
import { getNodeApi } from '../../network/node'
|
|
7
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
7
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
8
8
|
import { getBlockInfo } from '../getBlockInfo'
|
|
9
9
|
|
|
10
10
|
jest.mock('../../network/node', () => ({
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import type { EvmConfigInfo } from '../../config'
|
|
5
5
|
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../../fixtures/context.fixtures'
|
|
6
6
|
import { getNodeApi } from '../../network/node'
|
|
7
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
7
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
8
8
|
import { getNextSequence } from '../getNextSequence'
|
|
9
9
|
|
|
10
10
|
jest.mock('../../network/node', () => ({
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
testLogger,
|
|
14
14
|
} from '../../fixtures/context.fixtures'
|
|
15
15
|
import { getInternalTransactionsByBlock } from '../../network/explorer/etherscan'
|
|
16
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
16
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
17
17
|
import { composeInternalTxsFetcher, makeSourceFetchers } from '../internalTransactionsFetcher'
|
|
18
18
|
|
|
19
19
|
jest.mock('../../network/explorer/etherscan', () => ({
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
} from '../../config'
|
|
10
10
|
import { createMockEvmContext, mkExternalNode, mkLedgerNode } from '../../fixtures/context.fixtures'
|
|
11
11
|
import { getNodeApi } from '../../network/node'
|
|
12
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
12
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
13
13
|
import { lastBlock } from '../lastBlock'
|
|
14
14
|
|
|
15
15
|
jest.mock('../../network/node', () => ({
|
|
@@ -998,8 +998,8 @@ describe('listOperations', () => {
|
|
|
998
998
|
expect(tokenOp?.tx.block.hash).toBe(parentBlockHash)
|
|
999
999
|
})
|
|
1000
1000
|
|
|
1001
|
-
it('inherits the parent nonce on token ops, whose fees-only native op is dropped', async () => {
|
|
1002
|
-
// LIVE-35844: the Ledger explorer only reports the nonce on the native op
|
|
1001
|
+
it('inherits the parent nonce and gas on token ops, whose fees-only native op is dropped', async () => {
|
|
1002
|
+
// LIVE-35844: the Ledger explorer only reports the nonce and gas on the native op
|
|
1003
1003
|
const testContext = ctxWithExplorer(mkLedgerExplorer())
|
|
1004
1004
|
|
|
1005
1005
|
const address = '0xb69b37a4fb4a18b3258f974ff6e9f529ad2647b1'
|
|
@@ -1017,7 +1017,7 @@ describe('listOperations', () => {
|
|
|
1017
1017
|
value: 0n,
|
|
1018
1018
|
asset: { type: 'native' as const },
|
|
1019
1019
|
tx: { ...tx, feesPayer: address },
|
|
1020
|
-
details: { sequence: 316 },
|
|
1020
|
+
details: { sequence: 316, gasPrice: '570000000', gasLimit: '73330' },
|
|
1021
1021
|
},
|
|
1022
1022
|
],
|
|
1023
1023
|
lastTokenOperations: [
|
|
@@ -1048,6 +1048,8 @@ describe('listOperations', () => {
|
|
|
1048
1048
|
|
|
1049
1049
|
// a cancel is a self transfer of 0, so the explorer reports both sides
|
|
1050
1050
|
expect(items.map((op) => op.details?.sequence)).toEqual([316, 316])
|
|
1051
|
+
expect(items.map((op) => op.details?.gasPrice)).toEqual(['570000000', '570000000'])
|
|
1052
|
+
expect(items.map((op) => op.details?.gasLimit)).toEqual(['73330', '73330'])
|
|
1051
1053
|
})
|
|
1052
1054
|
|
|
1053
1055
|
it('should emit both native and token operations when tx has native value > 0 and token transfers', async () => {
|
|
@@ -42,7 +42,7 @@ import {
|
|
|
42
42
|
import ledgerExplorer from '../../network/explorer/ledger'
|
|
43
43
|
import ledgerGasTracker from '../../network/gasTracker/ledger'
|
|
44
44
|
import { getNodeApi } from '../../network/node'
|
|
45
|
-
import { mockNodeApi } from '../../network/node/node.fixtures'
|
|
45
|
+
import { mockNodeApi } from '../../network/tests/node/node.fixtures'
|
|
46
46
|
import * as computeGasLimitModule from '../computeGasLimit'
|
|
47
47
|
import { validateIntent } from '../validateIntent'
|
|
48
48
|
|
|
@@ -1050,6 +1050,42 @@ describe('validateIntent', () => {
|
|
|
1050
1050
|
)
|
|
1051
1051
|
})
|
|
1052
1052
|
|
|
1053
|
+
it('renders the native unit and network name in NotEnoughGas for Alpen', async () => {
|
|
1054
|
+
const alpenContext = createMockEvmContext(
|
|
1055
|
+
createMockEvmConfigInfo({
|
|
1056
|
+
chainId: CHAIN_ID.ALPEN_TESTNET,
|
|
1057
|
+
node: mkLedgerNode({ explorerId: 'eth' }),
|
|
1058
|
+
name: 'Alpen Testnet',
|
|
1059
|
+
unit: { name: 'BTC', code: 'BTC', magnitude: 18 },
|
|
1060
|
+
explorer: mkLedgerExplorer({ explorerId: 'eth' }),
|
|
1061
|
+
gasTracker: mkLedgerGasTracker({ explorerId: 'eth' }),
|
|
1062
|
+
})
|
|
1063
|
+
)
|
|
1064
|
+
|
|
1065
|
+
const res = await validateIntent(
|
|
1066
|
+
alpenContext,
|
|
1067
|
+
'alpen_testnet',
|
|
1068
|
+
createIntent({ recipient: 'recipient-address' }),
|
|
1069
|
+
[{ value: 10n, asset: { type: 'native' } }],
|
|
1070
|
+
{
|
|
1071
|
+
value: 11n,
|
|
1072
|
+
parameters: {
|
|
1073
|
+
gasLimit: 11n,
|
|
1074
|
+
gasPrice: 1n,
|
|
1075
|
+
maxFeePerGas: 1n,
|
|
1076
|
+
maxPriorityFeePerGas: 1n,
|
|
1077
|
+
},
|
|
1078
|
+
}
|
|
1079
|
+
)
|
|
1080
|
+
|
|
1081
|
+
expect(res.errors.gasPrice).toBeInstanceOf(NotEnoughGas)
|
|
1082
|
+
expect(res.errors.gasPrice).toMatchObject({
|
|
1083
|
+
ticker: 'BTC',
|
|
1084
|
+
cryptoName: 'Alpen Testnet',
|
|
1085
|
+
fees: expect.stringMatching(/\S/),
|
|
1086
|
+
})
|
|
1087
|
+
})
|
|
1088
|
+
|
|
1053
1089
|
it('includes additionalFees (L2 L1-data fee) when deciding NotEnoughGas', async () => {
|
|
1054
1090
|
// gas fee alone fits in the available balance, but the additionalFees
|
|
1055
1091
|
// (e.g. L1 data fee on L2s) push the total above the native balance.
|
package/src/logic.test.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { createMockEvmConfigInfo, mkExternalNode, testLogger } from './fixtures/
|
|
|
13
13
|
import { getAdditionalLayer2Fees } from './logic'
|
|
14
14
|
import { padHexString, safeEncodeEIP55 } from './logic-public'
|
|
15
15
|
import { getNodeApi } from './network/node/index'
|
|
16
|
-
import { mockNodeApi } from './network/node/node.fixtures'
|
|
16
|
+
import { mockNodeApi } from './network/tests/node/node.fixtures'
|
|
17
17
|
|
|
18
18
|
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
19
19
|
const nodeApiMock = mockNodeApi()
|
|
@@ -187,6 +187,7 @@ export async function getTransactionFromExplorerProxy(
|
|
|
187
187
|
parseHexBigInt(receipt.gasPrice) ??
|
|
188
188
|
parseHexBigInt(tx.gasPrice) ??
|
|
189
189
|
0n
|
|
190
|
+
const gasLimitBig = parseHexBigInt(tx.gas)
|
|
190
191
|
const statusBig = parseHexBigInt(receipt.status)
|
|
191
192
|
const blockNumberBig = parseHexBigInt(tx.blockNumber)
|
|
192
193
|
const txTypeBig = parseHexBigInt(receipt.type) ?? parseHexBigInt(tx.type)
|
|
@@ -241,6 +242,7 @@ export async function getTransactionFromExplorerProxy(
|
|
|
241
242
|
nonce: Number(nonceBig),
|
|
242
243
|
gasUsed: gasUsedBig.toString(),
|
|
243
244
|
gasPrice: gasPriceBig.toString(),
|
|
245
|
+
...(gasLimitBig !== null ? { gasLimit: gasLimitBig.toString() } : {}),
|
|
244
246
|
status: statusBig !== null ? Number(statusBig) : null,
|
|
245
247
|
value: valueBig.toString(),
|
|
246
248
|
from,
|
|
@@ -79,6 +79,7 @@ async function getTransaction(
|
|
|
79
79
|
blockHash: ledgerTransaction.block?.hash,
|
|
80
80
|
nonce: ledgerTransaction.nonce_value,
|
|
81
81
|
gasPrice: ledgerTransaction.gas_price,
|
|
82
|
+
...(ledgerTransaction.gas ? { gasLimit: ledgerTransaction.gas } : {}),
|
|
82
83
|
gasUsed: ledgerTransaction.gas_used,
|
|
83
84
|
value: ledgerTransaction.value,
|
|
84
85
|
status: ledgerTransaction.status,
|
|
@@ -301,6 +301,7 @@ async function getTransaction(
|
|
|
301
301
|
nonce: tx.nonce,
|
|
302
302
|
gasUsed: quantityToDecimal(receipt.gasUsed),
|
|
303
303
|
gasPrice: receiptGasPrice(receipt),
|
|
304
|
+
gasLimit: tx.gasLimit.toString(),
|
|
304
305
|
status: receiptStatus(receipt.status),
|
|
305
306
|
value: tx.value.toString(),
|
|
306
307
|
from: tx.from,
|
|
@@ -597,6 +598,10 @@ async function getBlockByHeight(
|
|
|
597
598
|
...(typeof data === 'string' && isSmartContractInput(data) ? { input: data } : {}),
|
|
598
599
|
// EIP-1559 transactions have gasPrice: null; fall back to maxFeePerGas then 0
|
|
599
600
|
gasPrice: (tx.gasPrice ?? tx.maxFeePerGas ?? 0n).toString(),
|
|
601
|
+
...(tx.gasLimit !== null && tx.gasLimit !== undefined
|
|
602
|
+
? { gasLimit: BigInt(tx.gasLimit).toString() }
|
|
603
|
+
: {}),
|
|
604
|
+
...(typeof tx.nonce === 'number' ? { nonce: tx.nonce } : {}),
|
|
600
605
|
}
|
|
601
606
|
})
|
|
602
607
|
|
|
@@ -691,6 +696,12 @@ async function getBlockByHeightFromRawRpc(
|
|
|
691
696
|
throw new Error(
|
|
692
697
|
'Malformed prefetched transaction gasPrice in eth_getBlockByNumber response'
|
|
693
698
|
)
|
|
699
|
+
if ('gas' in tx && tx.gas !== undefined && typeof tx.gas !== 'string')
|
|
700
|
+
throw new Error('Malformed prefetched transaction gas in eth_getBlockByNumber response')
|
|
701
|
+
if ('nonce' in tx && tx.nonce !== undefined && typeof tx.nonce !== 'string')
|
|
702
|
+
throw new Error(
|
|
703
|
+
'Malformed prefetched transaction nonce in eth_getBlockByNumber response'
|
|
704
|
+
)
|
|
694
705
|
if (
|
|
695
706
|
'input' in tx &&
|
|
696
707
|
tx.input !== undefined &&
|
|
@@ -710,6 +721,12 @@ async function getBlockByHeightFromRawRpc(
|
|
|
710
721
|
? { input: tx.input }
|
|
711
722
|
: {}),
|
|
712
723
|
gasPrice: BigInt(tx.gasPrice ?? '0x0').toString(),
|
|
724
|
+
...('gas' in tx && typeof tx.gas === 'string'
|
|
725
|
+
? { gasLimit: BigInt(tx.gas).toString() }
|
|
726
|
+
: {}),
|
|
727
|
+
...('nonce' in tx && typeof tx.nonce === 'string'
|
|
728
|
+
? { nonce: Number(BigInt(tx.nonce)) }
|
|
729
|
+
: {}),
|
|
713
730
|
}
|
|
714
731
|
})
|
|
715
732
|
: undefined
|
|
@@ -838,6 +855,8 @@ type EthersPrefetchedTransaction = {
|
|
|
838
855
|
data?: string | null
|
|
839
856
|
gasPrice?: bigint | string | null
|
|
840
857
|
maxFeePerGas?: bigint | string | null
|
|
858
|
+
gasLimit?: bigint | string | null
|
|
859
|
+
nonce?: number | null
|
|
841
860
|
}
|
|
842
861
|
|
|
843
862
|
function recordOf(value: object): Record<string, unknown> {
|
|
@@ -854,6 +873,8 @@ function isPrefetchedBlockTransaction(value: unknown): value is EthersPrefetched
|
|
|
854
873
|
isOptionalString(value.to) &&
|
|
855
874
|
isOptionalQuantity(value.gasPrice) &&
|
|
856
875
|
isOptionalQuantity(value.maxFeePerGas) &&
|
|
876
|
+
isOptionalQuantity(value.gasLimit) &&
|
|
877
|
+
(value.nonce === undefined || value.nonce === null || typeof value.nonce === 'number') &&
|
|
857
878
|
isOptionalString(value.data)
|
|
858
879
|
)
|
|
859
880
|
}
|
|
@@ -105,6 +105,8 @@ export type TransactionInfo = {
|
|
|
105
105
|
nonce: number
|
|
106
106
|
gasUsed: string
|
|
107
107
|
gasPrice: string
|
|
108
|
+
/** Gas limit set by the sender (decimal), when the source reports it */
|
|
109
|
+
gasLimit?: string
|
|
108
110
|
value: string | bigint // can be returned as bigint by ethers prefetched txs, or string in raw payloads
|
|
109
111
|
status: number | null
|
|
110
112
|
from: string
|
|
@@ -123,8 +125,9 @@ export type TransactionInfo = {
|
|
|
123
125
|
|
|
124
126
|
export type PrefetchedBlockTransaction = Pick<
|
|
125
127
|
TransactionInfo,
|
|
126
|
-
'hash' | 'value' | 'from' | 'to' | 'input' | 'gasPrice'
|
|
127
|
-
>
|
|
128
|
+
'hash' | 'value' | 'from' | 'to' | 'input' | 'gasPrice' | 'gasLimit'
|
|
129
|
+
> &
|
|
130
|
+
Partial<Pick<TransactionInfo, 'nonce'>>
|
|
128
131
|
|
|
129
132
|
export type BlockReceiptInfo = Pick<
|
|
130
133
|
TransactionInfo,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { PagingState } from '
|
|
5
|
-
import type { EvmConfigInfo, NftStandard } from '
|
|
4
|
+
import type { PagingState } from '../../../adapters'
|
|
5
|
+
import type { EvmConfigInfo, NftStandard } from '../../../config'
|
|
6
6
|
import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
7
7
|
import type { AxiosRequestConfig } from 'axios'
|
|
8
8
|
import { AssertionError, fail } from 'assert'
|
|
@@ -16,26 +16,26 @@ import {
|
|
|
16
16
|
etherscanOperationToOperations,
|
|
17
17
|
deserializePagingToken,
|
|
18
18
|
serializePagingToken,
|
|
19
|
-
} from '
|
|
20
|
-
import { CHAIN_ID } from '
|
|
19
|
+
} from '../../../adapters'
|
|
20
|
+
import { CHAIN_ID } from '../../../config'
|
|
21
21
|
import {
|
|
22
22
|
EtherscanAPIError,
|
|
23
23
|
EtherscanLikeExplorerUsedIncorrectly,
|
|
24
24
|
RateLimitError,
|
|
25
|
-
} from '
|
|
25
|
+
} from '../../../errors'
|
|
26
26
|
import {
|
|
27
27
|
createMockEvmConfigInfo,
|
|
28
28
|
mkExternalNode,
|
|
29
29
|
testLogger,
|
|
30
|
-
} from '
|
|
30
|
+
} from '../../../fixtures/context.fixtures'
|
|
31
31
|
import {
|
|
32
32
|
etherscanCoinOperations,
|
|
33
33
|
etherscanERC1155Operations,
|
|
34
34
|
etherscanERC721Operations,
|
|
35
35
|
etherscanInternalOperations,
|
|
36
36
|
etherscanTokenOperations,
|
|
37
|
-
} from '
|
|
38
|
-
import * as ETHERSCAN_API from '
|
|
37
|
+
} from '../../../fixtures/etherscan.fixtures'
|
|
38
|
+
import * as ETHERSCAN_API from '../../explorer/etherscan'
|
|
39
39
|
|
|
40
40
|
jest.mock('axios')
|
|
41
41
|
jest.mock('@ledgerhq/coin-module-framework/promises')
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import type { EvmConfigInfo } from '
|
|
4
|
+
import type { EvmConfigInfo } from '../../../config'
|
|
5
5
|
import { AssertionError, fail } from 'assert'
|
|
6
|
-
import { UnknownExplorer } from '
|
|
6
|
+
import { UnknownExplorer } from '../../../errors'
|
|
7
7
|
import {
|
|
8
8
|
createMockEvmConfigInfo,
|
|
9
9
|
mkEtherscanExplorer,
|
|
10
10
|
mkExternalNode,
|
|
11
11
|
mkLedgerExplorer,
|
|
12
12
|
testLogger,
|
|
13
|
-
} from '
|
|
14
|
-
import etherscanLikeApi from '
|
|
15
|
-
import
|
|
16
|
-
import
|
|
17
|
-
import
|
|
13
|
+
} from '../../../fixtures/context.fixtures'
|
|
14
|
+
import etherscanLikeApi from '../../explorer/etherscan'
|
|
15
|
+
import { getExplorerApi } from '../../explorer/index'
|
|
16
|
+
import ledgerExplorerApi from '../../explorer/ledger'
|
|
17
|
+
import noExplorerAPI from '../../explorer/none'
|
|
18
18
|
|
|
19
19
|
const configFor = (currencyId: string): EvmConfigInfo => {
|
|
20
20
|
const node = mkExternalNode()
|