@ledgerhq/coin-evm 5.3.6 → 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 +18 -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/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 +23 -5
- package/lib/network/explorer/etherscan.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/types/etherscan.d.ts +2 -0
- package/lib/types/etherscan.d.ts.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/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 +23 -5
- package/lib-es/network/explorer/etherscan.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/types/etherscan.d.ts +2 -0
- package/lib-es/types/etherscan.d.ts.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 -4
- 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 +6 -2
- package/src/logic/getBlock.test.ts +49 -0
- package/src/logic/getBlock.ts +3 -2
- package/src/network/explorer/etherscan.test.ts +339 -90
- package/src/network/explorer/etherscan.ts +32 -6
- 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/staking/validators.integ.test.ts +1 -1
- package/src/types/etherscan.ts +2 -0
|
@@ -776,9 +776,20 @@ export const getOperations = makeLRUCache<
|
|
|
776
776
|
endpoint: FetchOperations,
|
|
777
777
|
boundBlock: number | undefined,
|
|
778
778
|
isDone: boolean | undefined
|
|
779
|
-
): Promise<{
|
|
779
|
+
): Promise<{
|
|
780
|
+
result: EndpointResult
|
|
781
|
+
effectiveBoundBlock: number | undefined
|
|
782
|
+
// True when the endpoint's block range was narrowed by a prior endpoint's bound.
|
|
783
|
+
// An isDone=true result in this case means "no more data in the constrained window",
|
|
784
|
+
// NOT "globally done" — more data may exist beyond the window.
|
|
785
|
+
wasConstrainedByBoundBlock: boolean
|
|
786
|
+
}> {
|
|
780
787
|
if (isDone) {
|
|
781
|
-
return {
|
|
788
|
+
return {
|
|
789
|
+
result: EMPTY_RESULT,
|
|
790
|
+
effectiveBoundBlock: boundBlock,
|
|
791
|
+
wasConstrainedByBoundBlock: false,
|
|
792
|
+
}
|
|
782
793
|
}
|
|
783
794
|
// in asc mode, the cursor is the toBlock
|
|
784
795
|
// in desc mode the cursor is the fromBlock
|
|
@@ -799,7 +810,19 @@ export const getOperations = makeLRUCache<
|
|
|
799
810
|
result,
|
|
800
811
|
cmp
|
|
801
812
|
)
|
|
802
|
-
|
|
813
|
+
// The endpoint was "additionally constrained" only when boundBlock tightens the range
|
|
814
|
+
// beyond what the user already specified:
|
|
815
|
+
// asc: boundBlock sets effectiveToBlock — tighter when boundBlock < user's toBlock (or toBlock=∞)
|
|
816
|
+
// desc: boundBlock sets effectiveFromBlock — tighter when boundBlock > user's fromBlock
|
|
817
|
+
const wasConstrainedByBoundBlock =
|
|
818
|
+
order === 'asc'
|
|
819
|
+
? boundBlock !== undefined && (toBlock === undefined || boundBlock < toBlock)
|
|
820
|
+
: boundBlock !== undefined && boundBlock > fromBlock
|
|
821
|
+
return {
|
|
822
|
+
result: result,
|
|
823
|
+
effectiveBoundBlock: effectiveBoundBlock,
|
|
824
|
+
wasConstrainedByBoundBlock,
|
|
825
|
+
}
|
|
803
826
|
}
|
|
804
827
|
|
|
805
828
|
// endpoint calls are sorted by likelihood of having more operations than the next
|
|
@@ -855,9 +878,12 @@ export const getOperations = makeLRUCache<
|
|
|
855
878
|
lastInternalOperations: internalsResult.operations,
|
|
856
879
|
nextPagingToken: serializePagingToken(nextBoundBlock, {
|
|
857
880
|
coinIsDone: coinsResult.isDone,
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
881
|
+
// An endpoint constrained by a prior endpoint's bound block is only locally done
|
|
882
|
+
// (no more data in the constrained window). It must be re-queried on the next page
|
|
883
|
+
// because more data may exist beyond that window.
|
|
884
|
+
internalIsDone: internalsResult.isDone && !internals.wasConstrainedByBoundBlock,
|
|
885
|
+
tokenIsDone: tokensResult.isDone && !tokens.wasConstrainedByBoundBlock,
|
|
886
|
+
nftIsDone: nftsResult.isDone && !nfts.wasConstrainedByBoundBlock,
|
|
861
887
|
}),
|
|
862
888
|
}
|
|
863
889
|
} catch (err) {
|
|
@@ -223,37 +223,63 @@ export async function withApi<T>(
|
|
|
223
223
|
)
|
|
224
224
|
}
|
|
225
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Read the L1 data/security fee from a raw RPC receipt, normalized to a decimal string.
|
|
228
|
+
*
|
|
229
|
+
* Only OP-stack chains (Optimism, Base, Blast, …) report it; it is a non-standard field, so it is read off the raw
|
|
230
|
+
* record rather than the typed receipt.
|
|
231
|
+
*
|
|
232
|
+
* @param raw raw RPC receipt
|
|
233
|
+
*/
|
|
234
|
+
function parseReceiptL1Fee(raw: Record<string, unknown>): string | undefined {
|
|
235
|
+
const l1Fee = raw.l1Fee
|
|
236
|
+
return typeof l1Fee === 'string' ? BigInt(l1Fee).toString() : undefined
|
|
237
|
+
}
|
|
238
|
+
|
|
226
239
|
async function getTransaction(
|
|
227
240
|
api: JsonRpcProvider,
|
|
228
241
|
_currencyId: string,
|
|
229
242
|
txHash: string
|
|
230
243
|
): Promise<TransactionInfo> {
|
|
244
|
+
// Note: raw RPC call is used to get transaction receipt, as ethers method drops extra fields. We need optimism's
|
|
245
|
+
// extra fields that contain L1 fees.
|
|
246
|
+
// A pull request for ethers is open to avoid this: https://github.com/ethers-io/ethers.js/pull/5189
|
|
231
247
|
const [tx, receipt] = await Promise.all([
|
|
232
248
|
api.getTransaction(txHash),
|
|
233
|
-
api.
|
|
249
|
+
api.send('eth_getTransactionReceipt', [txHash]) as Promise<TransactionReceipt | null>,
|
|
234
250
|
])
|
|
235
251
|
|
|
236
252
|
if (!tx || !receipt) {
|
|
237
253
|
throw new Error('Transaction or receipt not found')
|
|
238
254
|
}
|
|
239
255
|
|
|
256
|
+
const raw = receipt as TransactionReceipt & Record<string, unknown>
|
|
257
|
+
const contractAddressRaw = raw.contractAddress
|
|
258
|
+
const contractAddress =
|
|
259
|
+
typeof contractAddressRaw === 'string' && contractAddressRaw.startsWith('0x')
|
|
260
|
+
? contractAddressRaw
|
|
261
|
+
: undefined
|
|
262
|
+
|
|
263
|
+
const l1Fee = parseReceiptL1Fee(raw)
|
|
264
|
+
|
|
240
265
|
return {
|
|
241
266
|
hash: tx.hash,
|
|
242
267
|
blockHeight: tx.blockNumber ?? undefined,
|
|
243
268
|
blockHash: tx.blockHash ?? undefined,
|
|
244
269
|
nonce: tx.nonce,
|
|
245
|
-
gasUsed: receipt.gasUsed.toString(),
|
|
246
|
-
gasPrice: receipt.gasPrice.toString(),
|
|
247
|
-
status: receipt.status,
|
|
270
|
+
gasUsed: BigInt(receipt.gasUsed).toString(),
|
|
271
|
+
gasPrice: BigInt(receipt.effectiveGasPrice ?? receipt.gasPrice ?? '0x0').toString(),
|
|
272
|
+
status: receipt.status === null ? null : Number(receipt.status),
|
|
248
273
|
value: tx.value.toString(),
|
|
249
274
|
from: tx.from,
|
|
250
275
|
to: tx.to ?? undefined,
|
|
251
|
-
type: receipt.type
|
|
276
|
+
type: receipt.type !== undefined ? Number(receipt.type) : (tx.type ?? undefined),
|
|
252
277
|
...(tx.data !== null && tx.data !== undefined && isSmartContractInput(tx.data)
|
|
253
278
|
? { input: tx.data }
|
|
254
279
|
: {}),
|
|
255
|
-
...(
|
|
280
|
+
...(contractAddress ? { contractAddress } : {}),
|
|
256
281
|
erc20Transfers: parseERC20TransfersFromLogs(receipt.logs),
|
|
282
|
+
...(l1Fee !== undefined ? { l1Fee } : {}),
|
|
257
283
|
}
|
|
258
284
|
}
|
|
259
285
|
|
|
@@ -710,6 +736,8 @@ async function getBlockReceipts(
|
|
|
710
736
|
? contractAddressRaw
|
|
711
737
|
: undefined
|
|
712
738
|
|
|
739
|
+
const l1Fee = parseReceiptL1Fee(raw)
|
|
740
|
+
|
|
713
741
|
return {
|
|
714
742
|
hash: receipt.transactionHash,
|
|
715
743
|
gasUsed: BigInt(receipt.gasUsed).toString(),
|
|
@@ -718,6 +746,7 @@ async function getBlockReceipts(
|
|
|
718
746
|
erc20Transfers: parseERC20TransfersFromLogs(receipt.logs),
|
|
719
747
|
...(contractAddress ? { contractAddress } : {}),
|
|
720
748
|
...(receipt.type !== undefined ? { type: Number(receipt.type) } : {}),
|
|
749
|
+
...(l1Fee !== undefined ? { l1Fee } : {}),
|
|
721
750
|
}
|
|
722
751
|
})
|
|
723
752
|
}
|
|
@@ -281,6 +281,50 @@ describe('EVM Family', () => {
|
|
|
281
281
|
})
|
|
282
282
|
|
|
283
283
|
describe('getTransaction', () => {
|
|
284
|
+
// Mocks the raw eth_getTransactionReceipt response, as ethers' getTransactionReceipt would
|
|
285
|
+
// drop the non-standard fields (l1Fee) this path reads.
|
|
286
|
+
function mockRawReceipt(overrides: Record<string, unknown> = {}): void {
|
|
287
|
+
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method) => {
|
|
288
|
+
if (method === 'eth_getTransactionReceipt') {
|
|
289
|
+
return {
|
|
290
|
+
transactionHash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
291
|
+
gasUsed: '0x7a',
|
|
292
|
+
gasPrice: '0x315',
|
|
293
|
+
status: '0x1',
|
|
294
|
+
logs: [],
|
|
295
|
+
type: '0x0',
|
|
296
|
+
contractAddress: null,
|
|
297
|
+
...overrides,
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
return null
|
|
301
|
+
})
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
beforeEach(() => {
|
|
305
|
+
mockRawReceipt()
|
|
306
|
+
})
|
|
307
|
+
|
|
308
|
+
it('should normalize the hex l1Fee of an OP-stack receipt to a decimal string', async () => {
|
|
309
|
+
mockRawReceipt({ l1Fee: '0x56c2d5eea374' }) // 95394812830580
|
|
310
|
+
|
|
311
|
+
const tx = await nodeApi.getTransaction(
|
|
312
|
+
currencyId,
|
|
313
|
+
'0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59'
|
|
314
|
+
)
|
|
315
|
+
|
|
316
|
+
expect(tx.l1Fee).toBe('95394812830580')
|
|
317
|
+
})
|
|
318
|
+
|
|
319
|
+
it('should leave l1Fee undefined when the receipt has none (non OP-stack chains)', async () => {
|
|
320
|
+
const tx = await nodeApi.getTransaction(
|
|
321
|
+
currencyId,
|
|
322
|
+
'0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59'
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
expect(tx.l1Fee).toBeUndefined()
|
|
326
|
+
})
|
|
327
|
+
|
|
284
328
|
it('should return the expected payload', async () => {
|
|
285
329
|
expect(
|
|
286
330
|
await nodeApi.getTransaction(
|
|
@@ -1368,6 +1412,35 @@ describe('EVM Family', () => {
|
|
|
1368
1412
|
])
|
|
1369
1413
|
})
|
|
1370
1414
|
|
|
1415
|
+
it('should normalize the hex l1Fee of an OP-stack receipt to a decimal string', async () => {
|
|
1416
|
+
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementationOnce(async (method) => {
|
|
1417
|
+
if (method === 'eth_getBlockReceipts') {
|
|
1418
|
+
return [
|
|
1419
|
+
{
|
|
1420
|
+
transactionHash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
1421
|
+
gasUsed: '0x5208', // 21000
|
|
1422
|
+
effectiveGasPrice: '0x3b9aca00', // 1000000000
|
|
1423
|
+
status: '0x1',
|
|
1424
|
+
logs: [],
|
|
1425
|
+
l1Fee: '0x56c2d5eea374', // 95394812830580
|
|
1426
|
+
},
|
|
1427
|
+
]
|
|
1428
|
+
}
|
|
1429
|
+
throw new Error(`Method not mocked: ${method}`)
|
|
1430
|
+
})
|
|
1431
|
+
|
|
1432
|
+
expect(await nodeApi.getBlockReceipts!(currencyId, 1)).toEqual([
|
|
1433
|
+
{
|
|
1434
|
+
hash: '0x435b00d28a10febbcfefbdea080134d08ef843df122d5bc9174b09de7fce6a59',
|
|
1435
|
+
gasUsed: '21000',
|
|
1436
|
+
gasPrice: '1000000000',
|
|
1437
|
+
status: 1,
|
|
1438
|
+
erc20Transfers: [],
|
|
1439
|
+
l1Fee: '95394812830580',
|
|
1440
|
+
},
|
|
1441
|
+
])
|
|
1442
|
+
})
|
|
1443
|
+
|
|
1371
1444
|
it('should throw UnsupportedRpcMethodError for RPC -32601', async () => {
|
|
1372
1445
|
jest.spyOn(JsonRpcProvider.prototype, 'send').mockImplementation(async (method) => {
|
|
1373
1446
|
if (method === 'eth_chainId') {
|
|
@@ -146,6 +146,8 @@ export type TransactionInfo = {
|
|
|
146
146
|
erc20Transfers: ERC20Transfer[]
|
|
147
147
|
/** Tx envelope type per EIP-2718 (decimal), e.g. 2 for EIP-1559. */
|
|
148
148
|
type?: number
|
|
149
|
+
/** L1 data/security fee in wei (OP-stack chains: Optimism, Base, Blast, …). Present only when the receipt includes the field. */
|
|
150
|
+
l1Fee?: string
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
export type PrefetchedBlockTransaction = Pick<
|
|
@@ -155,7 +157,14 @@ export type PrefetchedBlockTransaction = Pick<
|
|
|
155
157
|
|
|
156
158
|
export type BlockReceiptInfo = Pick<
|
|
157
159
|
TransactionInfo,
|
|
158
|
-
|
|
160
|
+
| 'hash'
|
|
161
|
+
| 'gasUsed'
|
|
162
|
+
| 'gasPrice'
|
|
163
|
+
| 'status'
|
|
164
|
+
| 'erc20Transfers'
|
|
165
|
+
| 'contractAddress'
|
|
166
|
+
| 'type'
|
|
167
|
+
| 'l1Fee'
|
|
159
168
|
>
|
|
160
169
|
|
|
161
170
|
export type BlockByHeightResult = {
|
|
@@ -24,7 +24,7 @@ describe('getValidators', () => {
|
|
|
24
24
|
'somnia',
|
|
25
25
|
createMockEvmCoinConfig({
|
|
26
26
|
chainId: 5031,
|
|
27
|
-
node: mkExternalNode({ uri: 'https://somnia
|
|
27
|
+
node: mkExternalNode({ uri: 'https://api.infra.mainnet.somnia.network' }),
|
|
28
28
|
}),
|
|
29
29
|
],
|
|
30
30
|
])("fetches validators on '%s'", async (currencyId, config) => {
|
package/src/types/etherscan.ts
CHANGED
|
@@ -28,6 +28,8 @@ export type EtherscanOperation = {
|
|
|
28
28
|
confirmations: string
|
|
29
29
|
methodId: string
|
|
30
30
|
functionName: string
|
|
31
|
+
/** L1 data/security fee in wei, as reported by OP-stack explorers (Optimism, Base, Blast, …). */
|
|
32
|
+
L1FeesPaid?: string
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export type EtherscanERC20Event = {
|