@ledgerhq/coin-evm 5.3.4 → 5.3.9
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 +30 -0
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +2 -1
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/config.d.ts +4 -0
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js.map +1 -1
- package/lib/errors.d.ts +6 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +12 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/getBlock.js +2 -2
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/network/explorer/etherscan.d.ts.map +1 -1
- package/lib/network/explorer/etherscan.js +38 -24
- package/lib/network/explorer/etherscan.js.map +1 -1
- package/lib/network/explorer/ledger.d.ts.map +1 -1
- package/lib/network/explorer/ledger.js +6 -4
- package/lib/network/explorer/ledger.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +30 -6
- 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/network/withRetries.d.ts.map +1 -1
- package/lib/network/withRetries.js +13 -0
- package/lib/network/withRetries.js.map +1 -1
- package/lib/types/etherscan.d.ts +2 -0
- package/lib/types/etherscan.d.ts.map +1 -1
- package/lib/utils.d.ts +0 -2
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +0 -30
- package/lib/utils.js.map +1 -1
- package/lib-es/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +2 -1
- package/lib-es/adapters/etherscan.js.map +1 -1
- package/lib-es/config.d.ts +4 -0
- package/lib-es/config.d.ts.map +1 -1
- package/lib-es/config.js.map +1 -1
- package/lib-es/errors.d.ts +6 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +10 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/getBlock.js +2 -2
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/network/explorer/etherscan.d.ts.map +1 -1
- package/lib-es/network/explorer/etherscan.js +39 -25
- package/lib-es/network/explorer/etherscan.js.map +1 -1
- package/lib-es/network/explorer/ledger.d.ts.map +1 -1
- package/lib-es/network/explorer/ledger.js +7 -5
- package/lib-es/network/explorer/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 +30 -6
- 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/lib-es/network/withRetries.d.ts.map +1 -1
- package/lib-es/network/withRetries.js +10 -0
- package/lib-es/network/withRetries.js.map +1 -1
- package/lib-es/types/etherscan.d.ts +2 -0
- package/lib-es/types/etherscan.d.ts.map +1 -1
- package/lib-es/utils.d.ts +0 -2
- package/lib-es/utils.d.ts.map +1 -1
- package/lib-es/utils.js +0 -28
- package/lib-es/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/adapters/etherscan.test.ts +67 -0
- package/src/adapters/etherscan.ts +3 -1
- package/src/api/getBlock.integ.test.ts +1 -1
- package/src/api/index.avalanche_c_chain_fuji.integ.test.ts +1 -1
- package/src/api/index.integ.test.ts +7 -12
- package/src/api/index.linea.integ.test.ts +1 -1
- package/src/api/index.monad_testnet.integ.test.ts +1 -1
- package/src/api/index.optimism.integ.test.ts +30 -1
- package/src/api/index.rsk.integ.test.ts +1 -1
- package/src/api/index.shape.integ.test.ts +1 -1
- package/src/api/index.somnia.integ.test.ts +40 -0
- package/src/api/index.zksync.integ.test.ts +42 -0
- package/src/config.ts +4 -0
- package/src/errors.ts +10 -0
- package/src/logic/getBlock.test.ts +49 -0
- package/src/logic/getBlock.ts +3 -2
- package/src/network/explorer/etherscan.test.ts +407 -91
- package/src/network/explorer/etherscan.ts +69 -33
- package/src/network/explorer/ledger.test.ts +24 -13
- package/src/network/explorer/ledger.ts +27 -22
- package/src/network/node/rpc.common.ts +35 -6
- package/src/network/node/rpc.test.ts +73 -0
- package/src/network/node/types.ts +10 -1
- package/src/network/withRetries.test.ts +63 -0
- package/src/network/withRetries.ts +12 -0
- package/src/staking/validators.integ.test.ts +1 -1
- package/src/types/etherscan.ts +2 -0
- package/src/utils.test.ts +0 -86
- package/src/utils.ts +0 -41
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { EvmConfigInfo } from '../config'
|
|
5
|
+
import { createMockEvmContext } from '../fixtures/context.fixtures'
|
|
6
|
+
import { createApi } from './index'
|
|
7
|
+
|
|
8
|
+
describe('EVM Api (Somnia)', () => {
|
|
9
|
+
let module: ReturnType<typeof createApi>
|
|
10
|
+
|
|
11
|
+
const config: Partial<EvmConfigInfo> = {
|
|
12
|
+
node: { type: 'external', uri: 'https://api.infra.mainnet.somnia.network' },
|
|
13
|
+
explorer: { type: 'blockscout', uri: 'https://explorer.somnia.network/api/' },
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
beforeAll(() => {
|
|
17
|
+
module = createApi('somnia')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
describe('listOperations', () => {
|
|
21
|
+
it('keeps returning token operations on pages after the first when scanning from genesis', async () => {
|
|
22
|
+
const context = createMockEvmContext(config)
|
|
23
|
+
const address = '0x51d5ea8E6F98A73F823938Ff5731383aa92b0605'
|
|
24
|
+
const options = { minHeight: 0, order: 'asc' as const, limit: 3 }
|
|
25
|
+
|
|
26
|
+
const firstPage = await module.listOperations(context, address, options)
|
|
27
|
+
expect(firstPage.items.length).toBeGreaterThan(0)
|
|
28
|
+
expect(typeof firstPage.next).toBe('string')
|
|
29
|
+
|
|
30
|
+
const secondPage = await module.listOperations(context, address, {
|
|
31
|
+
...options,
|
|
32
|
+
cursor: firstPage.next,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// The regression: without re-querying the token endpoint this page is native-only.
|
|
36
|
+
const erc20Ops = secondPage.items.filter((op) => op.asset.type === 'erc20')
|
|
37
|
+
expect(erc20Ops.length).toBeGreaterThan(0)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
40
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { createMockEvmContext, mkExternalNode } from '../fixtures/context.fixtures'
|
|
5
|
+
import { createApi } from './index'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Non regression for GET /v1/zksync/account/{address}/operations?minHeight=0&order=asc&limit=1,
|
|
9
|
+
* which was timing out because 429 responses from the blockscout upstream were silently
|
|
10
|
+
* retried until the request timed out.
|
|
11
|
+
*
|
|
12
|
+
* `limit` must be passed: listOperations forces the explorer order to `desc` when it is
|
|
13
|
+
* undefined, so omitting it would query a different code path than the reported one.
|
|
14
|
+
*/
|
|
15
|
+
describe('ZkSync (blockscout explorer)', () => {
|
|
16
|
+
const ADDRESS = '0x060afdc8d583e134eebb50826695632f041c5153'
|
|
17
|
+
|
|
18
|
+
let module: ReturnType<typeof createApi>
|
|
19
|
+
|
|
20
|
+
beforeAll(() => {
|
|
21
|
+
module = createApi('zksync')
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
it('listOperations completes without timing out', async () => {
|
|
25
|
+
const { items } = await module.listOperations(
|
|
26
|
+
createMockEvmContext({
|
|
27
|
+
chainId: 324,
|
|
28
|
+
node: mkExternalNode({ uri: 'https://zksync.coin.ledger.com', retries: 0 }),
|
|
29
|
+
explorer: {
|
|
30
|
+
type: 'blockscout',
|
|
31
|
+
uri: 'https://proxyblockscout.api.live.ledger.com/324/api',
|
|
32
|
+
retries: 0,
|
|
33
|
+
},
|
|
34
|
+
}),
|
|
35
|
+
ADDRESS,
|
|
36
|
+
{ minHeight: 0, order: 'asc', limit: 1 }
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
expect(Array.isArray(items)).toBe(true)
|
|
40
|
+
expect(items.length).toBeLessThanOrEqual(1)
|
|
41
|
+
})
|
|
42
|
+
})
|
package/src/config.ts
CHANGED
|
@@ -52,11 +52,15 @@ export type EvmConfig = {
|
|
|
52
52
|
*/
|
|
53
53
|
maxLimit?: number | undefined
|
|
54
54
|
uri: string
|
|
55
|
+
/** Number of retries for explorer API calls. Defaults to 8 if not set. Set to 0 for no retries. */
|
|
56
|
+
retries?: number
|
|
55
57
|
}
|
|
56
58
|
| {
|
|
57
59
|
type: 'ledger'
|
|
58
60
|
explorerId: string
|
|
59
61
|
batchSize?: number | undefined
|
|
62
|
+
/** Number of retries for explorer API calls. Defaults to 2 if not set. Set to 0 for no retries. */
|
|
63
|
+
retries?: number
|
|
60
64
|
}
|
|
61
65
|
| {
|
|
62
66
|
type: 'none'
|
package/src/errors.ts
CHANGED
|
@@ -44,6 +44,16 @@ export class InvalidExplorerResponse extends Error {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/** Rate limit error (HTTP 429) from an upstream API — explorer or RPC node. */
|
|
48
|
+
export class RateLimitError extends Error {
|
|
49
|
+
override name = 'RateLimitError'
|
|
50
|
+
readonly statusCode = 429
|
|
51
|
+
constructor(message?: string, fields?: Record<string, unknown>) {
|
|
52
|
+
super(message || 'Upstream rate limit exceeded (429), please retry later')
|
|
53
|
+
if (fields) Object.assign(this, fields)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
// Node
|
|
48
58
|
export class UnknownNode extends Error {
|
|
49
59
|
override name = 'UnknownNode'
|
|
@@ -1145,6 +1145,55 @@ describe('getBlock', () => {
|
|
|
1145
1145
|
expect(result.transactions[0].fees).toEqual(21000n * 1000000000n)
|
|
1146
1146
|
})
|
|
1147
1147
|
|
|
1148
|
+
it('adds l1Fee to fees when bulk receipt includes l1Fee (OP-stack bulk path)', async () => {
|
|
1149
|
+
setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
|
|
1150
|
+
const gasUsed = 21000n
|
|
1151
|
+
const gasPrice = '1000000000'
|
|
1152
|
+
const l1Fee = '95394812830580'
|
|
1153
|
+
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
1154
|
+
mockGetNodeApi.mockReturnValue(
|
|
1155
|
+
mockNodeApi({
|
|
1156
|
+
getBlockByHeight: jest.fn().mockResolvedValueOnce(
|
|
1157
|
+
makeNodeBlock({
|
|
1158
|
+
transactions: [makeNodeBlockTx({ hash: '0xtx1', gasPrice })],
|
|
1159
|
+
})
|
|
1160
|
+
),
|
|
1161
|
+
getBlockReceipts: jest.fn().mockResolvedValueOnce([
|
|
1162
|
+
makeNodeBlockReceipt({
|
|
1163
|
+
hash: '0xtx1',
|
|
1164
|
+
gasUsed: gasUsed.toString(),
|
|
1165
|
+
gasPrice,
|
|
1166
|
+
l1Fee,
|
|
1167
|
+
erc20Transfers: [],
|
|
1168
|
+
}),
|
|
1169
|
+
]),
|
|
1170
|
+
getTransaction: jest.fn(),
|
|
1171
|
+
})
|
|
1172
|
+
)
|
|
1173
|
+
const result = await getBlock(createContext(), 'optimism', 12345)
|
|
1174
|
+
expect(result.transactions[0].fees).toEqual(gasUsed * BigInt(gasPrice) + BigInt(l1Fee))
|
|
1175
|
+
})
|
|
1176
|
+
|
|
1177
|
+
it('adds l1Fee to fees when getTransaction returns l1Fee (OP-stack per-tx fallback path)', async () => {
|
|
1178
|
+
setCoinConfig(() => createMockEvmCoinConfig({ chainId: 1, node: mkExternalNode() }))
|
|
1179
|
+
const gasUsed = '21000'
|
|
1180
|
+
const gasPrice = '1000000000'
|
|
1181
|
+
const l1Fee = '95394812830580'
|
|
1182
|
+
const mockGetNodeApi = jest.mocked(getNodeApi)
|
|
1183
|
+
mockGetNodeApi.mockReturnValue(
|
|
1184
|
+
mockNodeApi({
|
|
1185
|
+
getBlockByHeight: jest
|
|
1186
|
+
.fn()
|
|
1187
|
+
.mockResolvedValueOnce(makeNodeBlock({ transactionHashes: ['0xtx1'] })),
|
|
1188
|
+
getTransaction: jest
|
|
1189
|
+
.fn()
|
|
1190
|
+
.mockResolvedValueOnce(makeNodeTxInfo({ hash: '0xtx1', gasUsed, gasPrice, l1Fee })),
|
|
1191
|
+
})
|
|
1192
|
+
)
|
|
1193
|
+
const result = await getBlock(createContext(), 'optimism', 12345)
|
|
1194
|
+
expect(result.transactions[0].fees).toEqual(BigInt(gasUsed) * BigInt(gasPrice) + BigInt(l1Fee))
|
|
1195
|
+
})
|
|
1196
|
+
|
|
1148
1197
|
describe('zkSync L1→L2 priority transactions (receipt type 0xff)', () => {
|
|
1149
1198
|
const USER = '0xbEB30f27e61eFFF46Aa27dcE18E23ee8D5A7c6a4'
|
|
1150
1199
|
const L2_BASE_TOKEN = '0x000000000000000000000000000000000000800A'
|
package/src/logic/getBlock.ts
CHANGED
|
@@ -192,7 +192,7 @@ function prefetchedTransactionToBlockTransaction(
|
|
|
192
192
|
// (the node layer provides `0` when the raw `eth_getBlockByNumber(_, true)` payload omits it).
|
|
193
193
|
const receiptGasPrice = BigInt(receipt.gasPrice)
|
|
194
194
|
const gasPrice = receiptGasPrice > 0n ? receiptGasPrice : BigInt(tx.gasPrice)
|
|
195
|
-
const fees = BigInt(receipt.gasUsed) * gasPrice
|
|
195
|
+
const fees = BigInt(receipt.gasUsed) * gasPrice + (receipt.l1Fee ? BigInt(receipt.l1Fee) : 0n)
|
|
196
196
|
const operations = rpcTransactionToBlockOperations({
|
|
197
197
|
from: tx.from,
|
|
198
198
|
to: tx.to,
|
|
@@ -220,7 +220,8 @@ async function getTransactionFromHash(
|
|
|
220
220
|
const txInfo = await nodeApi.getTransaction(currencyId, txHash)
|
|
221
221
|
|
|
222
222
|
const failed = txInfo.status === 0
|
|
223
|
-
const fees =
|
|
223
|
+
const fees =
|
|
224
|
+
BigInt(txInfo.gasUsed) * BigInt(txInfo.gasPrice) + (txInfo.l1Fee ? BigInt(txInfo.l1Fee) : 0n)
|
|
224
225
|
|
|
225
226
|
const rawOperations = rpcTransactionToBlockOperations(txInfo)
|
|
226
227
|
const operations = applyChainSpecificCorrections(currencyId, rawOperations, txInfo.type)
|