@ledgerhq/coin-evm 16.5.3 → 16.6.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 +12 -0
- package/lib/api/index.d.ts +5 -2
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +2 -1
- package/lib/api/index.js.map +1 -1
- package/lib/errors.d.ts +17 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +26 -1
- package/lib/errors.js.map +1 -1
- package/lib/logic/cip64Fees.d.ts +43 -0
- package/lib/logic/cip64Fees.d.ts.map +1 -0
- package/lib/logic/cip64Fees.js +139 -0
- package/lib/logic/cip64Fees.js.map +1 -0
- package/lib/logic/feeCollectorOperations.d.ts +2 -2
- package/lib/logic/feeCollectorOperations.js +2 -2
- package/lib/logic/getBlock.d.ts +2 -2
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +99 -19
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +59 -6
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +8 -1
- package/lib/network/node/types.d.ts.map +1 -1
- package/lib/network/node/types.js.map +1 -1
- package/lib/network/node/withNodeSources.d.ts.map +1 -1
- package/lib/network/node/withNodeSources.js +2 -0
- package/lib/network/node/withNodeSources.js.map +1 -1
- package/lib-es/api/index.d.ts +5 -2
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +2 -1
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/errors.d.ts +17 -0
- package/lib-es/errors.d.ts.map +1 -1
- package/lib-es/errors.js +21 -0
- package/lib-es/errors.js.map +1 -1
- package/lib-es/logic/cip64Fees.d.ts +43 -0
- package/lib-es/logic/cip64Fees.d.ts.map +1 -0
- package/lib-es/logic/cip64Fees.js +134 -0
- package/lib-es/logic/cip64Fees.js.map +1 -0
- package/lib-es/logic/feeCollectorOperations.d.ts +2 -2
- package/lib-es/logic/feeCollectorOperations.js +2 -2
- package/lib-es/logic/getBlock.d.ts +2 -2
- package/lib-es/logic/getBlock.d.ts.map +1 -1
- package/lib-es/logic/getBlock.js +99 -19
- package/lib-es/logic/getBlock.js.map +1 -1
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +59 -6
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +8 -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/node/withNodeSources.d.ts.map +1 -1
- package/lib-es/network/node/withNodeSources.js +2 -0
- package/lib-es/network/node/withNodeSources.js.map +1 -1
- package/package.json +2 -2
- package/src/api/index.ts +4 -1
- package/src/api/tests/index.celo.integ.test.ts +93 -0
- package/src/api/tests/index.flare.integ.test.ts +2 -1
- package/src/api/tests/index.test.ts +9 -0
- package/src/errors.ts +24 -0
- package/src/logic/cip64Fees.ts +193 -0
- package/src/logic/feeCollectorOperations.ts +2 -2
- package/src/logic/getBlock.ts +170 -30
- package/src/logic/tests/cip64Fees.test.ts +277 -0
- package/src/logic/tests/getBlock.test.ts +249 -2
- package/src/network/node/rpc.common.ts +74 -7
- package/src/network/node/types.ts +8 -1
- package/src/network/node/withNodeSources.ts +3 -0
- package/src/network/tests/node/rpc.test.ts +197 -0
- package/src/network/tests/node/withNodeSources.test.ts +18 -0
|
@@ -15,7 +15,7 @@ import type { EtherscanInternalTransaction } from '../../types'
|
|
|
15
15
|
import type { BlockOperation } from '@ledgerhq/coin-module-framework/api/index'
|
|
16
16
|
import { ethers } from 'ethers'
|
|
17
17
|
import { CHAIN_ID, evmDefaults, internalTxSourcesFromList } from '../../config'
|
|
18
|
-
import { UnsupportedRpcMethodError } from '../../errors'
|
|
18
|
+
import { UnsupportedFeeCurrencyError, UnsupportedRpcMethodError } from '../../errors'
|
|
19
19
|
import {
|
|
20
20
|
createMockEvmConfigInfo,
|
|
21
21
|
createMockEvmContext,
|
|
@@ -1096,7 +1096,8 @@ describe('getBlock', () => {
|
|
|
1096
1096
|
}
|
|
1097
1097
|
|
|
1098
1098
|
function mockBulkBlock(
|
|
1099
|
-
network: Pick<EvmConfigInfo, 'chainId' | 'feeCollectorContracts'
|
|
1099
|
+
network: Pick<EvmConfigInfo, 'chainId' | 'feeCollectorContracts' | 'feeCollectorTokens'>,
|
|
1100
|
+
otherTransfers: ERC20Transfer[] = []
|
|
1100
1101
|
): EvmContext {
|
|
1101
1102
|
const context = createMockEvmContext(
|
|
1102
1103
|
createMockEvmConfigInfo({
|
|
@@ -1131,6 +1132,7 @@ describe('getBlock', () => {
|
|
|
1131
1132
|
to: USER,
|
|
1132
1133
|
value: REFUND.toString(),
|
|
1133
1134
|
}),
|
|
1135
|
+
...otherTransfers,
|
|
1134
1136
|
],
|
|
1135
1137
|
}),
|
|
1136
1138
|
]),
|
|
@@ -1333,6 +1335,109 @@ describe('getBlock', () => {
|
|
|
1333
1335
|
expect(bootloaderNativeOps(tx.operations)).toHaveLength(2)
|
|
1334
1336
|
expect(userNativeDelta(tx.operations)).toBe(-PREPAYMENT)
|
|
1335
1337
|
})
|
|
1338
|
+
|
|
1339
|
+
it('drops the base-token fee legs too when the caller asks for the fee asset', async () => {
|
|
1340
|
+
const otherTransfer = makeNodeErc20Transfer({
|
|
1341
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1342
|
+
from: USER,
|
|
1343
|
+
to: address2,
|
|
1344
|
+
value: '1000',
|
|
1345
|
+
})
|
|
1346
|
+
const context = mockBulkBlock(
|
|
1347
|
+
{
|
|
1348
|
+
chainId: CHAIN_ID.ZKSYNC,
|
|
1349
|
+
feeCollectorContracts: [BOOTLOADER],
|
|
1350
|
+
feeCollectorTokens: [L2_BASE_TOKEN],
|
|
1351
|
+
},
|
|
1352
|
+
[otherTransfer]
|
|
1353
|
+
)
|
|
1354
|
+
jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
|
|
1355
|
+
makeExplorerInternalTransaction({
|
|
1356
|
+
from: USER,
|
|
1357
|
+
to: BOOTLOADER,
|
|
1358
|
+
value: PREPAYMENT.toString(),
|
|
1359
|
+
}),
|
|
1360
|
+
])
|
|
1361
|
+
|
|
1362
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
1363
|
+
|
|
1364
|
+
expect(tx.operations).toEqual([
|
|
1365
|
+
{
|
|
1366
|
+
type: 'transfer',
|
|
1367
|
+
address: USER,
|
|
1368
|
+
peer: address2,
|
|
1369
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1370
|
+
amount: -1000n,
|
|
1371
|
+
},
|
|
1372
|
+
{
|
|
1373
|
+
type: 'transfer',
|
|
1374
|
+
address: address2,
|
|
1375
|
+
peer: USER,
|
|
1376
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1377
|
+
amount: 1000n,
|
|
1378
|
+
},
|
|
1379
|
+
])
|
|
1380
|
+
expect(tx.fees).toBe(FEE)
|
|
1381
|
+
expect(tx.feesPayer).toBe(USER)
|
|
1382
|
+
expect(tx).not.toHaveProperty('feesAsset')
|
|
1383
|
+
})
|
|
1384
|
+
|
|
1385
|
+
it.each([
|
|
1386
|
+
['no internal transfer', false],
|
|
1387
|
+
['only its internal refund', true],
|
|
1388
|
+
])('reads a paymaster from its base-token prepayment, with %s', async (_, withRefund) => {
|
|
1389
|
+
const PAYMASTER = '0xA2Aac7bC9725c36ad9B12D2407dF8de6B2B68359'
|
|
1390
|
+
if (withRefund) {
|
|
1391
|
+
jest.mocked(getInternalTransactionsByBlock).mockResolvedValueOnce([
|
|
1392
|
+
makeExplorerInternalTransaction({
|
|
1393
|
+
from: BOOTLOADER,
|
|
1394
|
+
to: PAYMASTER,
|
|
1395
|
+
value: '42357348500000',
|
|
1396
|
+
}),
|
|
1397
|
+
])
|
|
1398
|
+
}
|
|
1399
|
+
const context = createMockEvmContext(
|
|
1400
|
+
createMockEvmConfigInfo({
|
|
1401
|
+
chainId: CHAIN_ID.ZKSYNC,
|
|
1402
|
+
feeCollectorContracts: [BOOTLOADER],
|
|
1403
|
+
feeCollectorTokens: [L2_BASE_TOKEN],
|
|
1404
|
+
node: mkExternalNode(),
|
|
1405
|
+
explorer: mkEtherscanExplorer(),
|
|
1406
|
+
})
|
|
1407
|
+
)
|
|
1408
|
+
mockGetBlockNodeApi(
|
|
1409
|
+
mockNodeApi({
|
|
1410
|
+
getBlockByHeight: jest.fn().mockResolvedValueOnce(
|
|
1411
|
+
makeNodeBlock({
|
|
1412
|
+
transactions: [makeNodeBlockTx({ from: USER, to: address2, value: '0' })],
|
|
1413
|
+
})
|
|
1414
|
+
),
|
|
1415
|
+
getBlockReceipts: jest.fn().mockResolvedValueOnce([
|
|
1416
|
+
makeNodeBlockReceipt({
|
|
1417
|
+
erc20Transfers: [
|
|
1418
|
+
makeNodeErc20Transfer({
|
|
1419
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1420
|
+
from: PAYMASTER,
|
|
1421
|
+
to: BOOTLOADER,
|
|
1422
|
+
value: '49775000000000',
|
|
1423
|
+
}),
|
|
1424
|
+
makeNodeErc20Transfer({
|
|
1425
|
+
asset: { type: 'erc20', assetReference: L2_BASE_TOKEN },
|
|
1426
|
+
from: BOOTLOADER,
|
|
1427
|
+
to: PAYMASTER,
|
|
1428
|
+
value: '42357348500000',
|
|
1429
|
+
}),
|
|
1430
|
+
],
|
|
1431
|
+
}),
|
|
1432
|
+
]),
|
|
1433
|
+
})
|
|
1434
|
+
)
|
|
1435
|
+
|
|
1436
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
1437
|
+
|
|
1438
|
+
expect(tx.feesPayer).toBe(PAYMASTER)
|
|
1439
|
+
expect(tx.operations).toEqual([])
|
|
1440
|
+
})
|
|
1336
1441
|
})
|
|
1337
1442
|
|
|
1338
1443
|
it('when explorer is not etherscan like, falls back to node.traceBlockErigon', async () => {
|
|
@@ -2195,6 +2300,148 @@ describe('getBlock', () => {
|
|
|
2195
2300
|
])
|
|
2196
2301
|
})
|
|
2197
2302
|
})
|
|
2303
|
+
|
|
2304
|
+
describe('Celo CIP-64 fee currencies', () => {
|
|
2305
|
+
// Fee logs of tx 0x45e41cf20fca9b079f8b23510bb9637d14df647cb6d25d85157924cd27df09d7 (block
|
|
2306
|
+
// 80494727), which pays its fee in USD₮ through the USD₮ adapter
|
|
2307
|
+
const PAYER = '0x5362C723476b46a1e65D54E667C00e46b46F6f12'
|
|
2308
|
+
const USDT = '0x48065fbBE25f71C9282ddf5e1cD6D6A887483D5e'
|
|
2309
|
+
const USDT_ADAPTER = '0x0E2A3e05bc9A16F5292A6170456A710cb89C6f72'
|
|
2310
|
+
const HOLDER = '0x000000000000000000000000000000000Ce106A5'
|
|
2311
|
+
const FEE_HANDLER = '0xcD437749E43A154C07F3553504c68fBfD56B8778'
|
|
2312
|
+
const SEQUENCER_VAULT = '0x4200000000000000000000000000000000000011'
|
|
2313
|
+
const GAS_USED = '100000'
|
|
2314
|
+
const GAS_PRICE = '31763731729'
|
|
2315
|
+
const NATIVE_FEES = 3176373172900000n
|
|
2316
|
+
|
|
2317
|
+
const usdt = (from: string, to: string, value: string): ERC20Transfer =>
|
|
2318
|
+
makeNodeErc20Transfer({ asset: { type: 'erc20', assetReference: USDT }, from, to, value })
|
|
2319
|
+
const userTransfer = usdt(address2, PAYER, '5800')
|
|
2320
|
+
const transfers = [
|
|
2321
|
+
usdt(PAYER, HOLDER, '4252'),
|
|
2322
|
+
userTransfer,
|
|
2323
|
+
usdt(HOLDER, SEQUENCER_VAULT, '0'),
|
|
2324
|
+
usdt(HOLDER, FEE_HANDLER, '3176'),
|
|
2325
|
+
usdt(HOLDER, PAYER, '1076'),
|
|
2326
|
+
]
|
|
2327
|
+
const userOperations: BlockOperation[] = [
|
|
2328
|
+
{
|
|
2329
|
+
type: 'transfer',
|
|
2330
|
+
address: address2,
|
|
2331
|
+
peer: PAYER,
|
|
2332
|
+
asset: { type: 'erc20', assetReference: USDT },
|
|
2333
|
+
amount: -5800n,
|
|
2334
|
+
},
|
|
2335
|
+
{
|
|
2336
|
+
type: 'transfer',
|
|
2337
|
+
address: PAYER,
|
|
2338
|
+
peer: address2,
|
|
2339
|
+
asset: { type: 'erc20', assetReference: USDT },
|
|
2340
|
+
amount: 5800n,
|
|
2341
|
+
},
|
|
2342
|
+
]
|
|
2343
|
+
|
|
2344
|
+
function mockCeloBlock({
|
|
2345
|
+
chainId = CHAIN_ID.CELO,
|
|
2346
|
+
feeCurrency = USDT_ADAPTER,
|
|
2347
|
+
prefetched = true,
|
|
2348
|
+
receiptType = 0x7b,
|
|
2349
|
+
}: {
|
|
2350
|
+
chainId?: ChainId
|
|
2351
|
+
feeCurrency?: string | null
|
|
2352
|
+
prefetched?: boolean
|
|
2353
|
+
receiptType?: number | null
|
|
2354
|
+
} = {}): { context: EvmContext; nodeApi: ReturnType<typeof mockNodeApi> } {
|
|
2355
|
+
const context = createMockEvmContext(
|
|
2356
|
+
createMockEvmConfigInfo({
|
|
2357
|
+
chainId,
|
|
2358
|
+
node: mkExternalNode(),
|
|
2359
|
+
explorer: mkEtherscanExplorer(),
|
|
2360
|
+
})
|
|
2361
|
+
)
|
|
2362
|
+
const receipt = {
|
|
2363
|
+
hash: '0xtx1',
|
|
2364
|
+
gasUsed: GAS_USED,
|
|
2365
|
+
gasPrice: GAS_PRICE,
|
|
2366
|
+
...(receiptType !== null ? { type: receiptType } : {}),
|
|
2367
|
+
erc20Transfers: transfers,
|
|
2368
|
+
}
|
|
2369
|
+
const nodeApi = mockNodeApi({
|
|
2370
|
+
getBlockByHeight: jest.fn().mockResolvedValueOnce(
|
|
2371
|
+
prefetched
|
|
2372
|
+
? makeNodeBlock({
|
|
2373
|
+
transactions: [makeNodeBlockTx({ from: PAYER, value: '0', gasPrice: GAS_PRICE })],
|
|
2374
|
+
})
|
|
2375
|
+
: makeNodeBlock({ transactionHashes: ['0xtx1'] })
|
|
2376
|
+
),
|
|
2377
|
+
getBlockReceipts: jest.fn().mockResolvedValueOnce([makeNodeBlockReceipt(receipt)]),
|
|
2378
|
+
getTransaction: jest
|
|
2379
|
+
.fn()
|
|
2380
|
+
.mockResolvedValueOnce(makeNodeTxInfo({ ...receipt, from: PAYER, value: '0' })),
|
|
2381
|
+
getFeeCurrencies: jest.fn().mockResolvedValue(new Map([['0xtx1', feeCurrency]])),
|
|
2382
|
+
})
|
|
2383
|
+
mockGetBlockNodeApi(nodeApi)
|
|
2384
|
+
return { context, nodeApi }
|
|
2385
|
+
}
|
|
2386
|
+
|
|
2387
|
+
it.each([
|
|
2388
|
+
['prefetched with block receipts', true, 0x7b],
|
|
2389
|
+
['fetched one by one', false, 0x7b],
|
|
2390
|
+
['whose block receipt has no type', true, null],
|
|
2391
|
+
])(
|
|
2392
|
+
'reports the token fee and drops the fee logs, on a transaction %s',
|
|
2393
|
+
async (_, prefetched, receiptType) => {
|
|
2394
|
+
const { context, nodeApi } = mockCeloBlock({ prefetched, receiptType })
|
|
2395
|
+
|
|
2396
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
2397
|
+
|
|
2398
|
+
expect(tx.fees).toBe(3176n)
|
|
2399
|
+
expect(tx.feesAsset).toEqual({ type: 'erc20', assetReference: USDT })
|
|
2400
|
+
expect(tx.feesPayer).toBe(PAYER)
|
|
2401
|
+
expect(tx.operations).toEqual(userOperations)
|
|
2402
|
+
expect(nodeApi.getFeeCurrencies).toHaveBeenCalledWith(12345)
|
|
2403
|
+
}
|
|
2404
|
+
)
|
|
2405
|
+
|
|
2406
|
+
it('keeps the native fee and the fee logs when the caller does not ask for the fee asset', async () => {
|
|
2407
|
+
const { context, nodeApi } = mockCeloBlock()
|
|
2408
|
+
|
|
2409
|
+
const [tx] = (await getBlock(context, 12345)).transactions
|
|
2410
|
+
|
|
2411
|
+
expect(tx.fees).toBe(NATIVE_FEES)
|
|
2412
|
+
expect(tx).not.toHaveProperty('feesAsset')
|
|
2413
|
+
expect(tx.operations).toHaveLength(transfers.length * 2)
|
|
2414
|
+
expect(nodeApi.getFeeCurrencies).not.toHaveBeenCalled()
|
|
2415
|
+
})
|
|
2416
|
+
|
|
2417
|
+
it('keeps the native fee of a CIP-64 transaction that pays in the native coin', async () => {
|
|
2418
|
+
const { context } = mockCeloBlock({ feeCurrency: null })
|
|
2419
|
+
|
|
2420
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
2421
|
+
|
|
2422
|
+
expect(tx.fees).toBe(NATIVE_FEES)
|
|
2423
|
+
expect(tx).not.toHaveProperty('feesAsset')
|
|
2424
|
+
expect(tx.operations).toHaveLength(transfers.length * 2)
|
|
2425
|
+
})
|
|
2426
|
+
|
|
2427
|
+
it('does not read fee currencies on another chain', async () => {
|
|
2428
|
+
const { context, nodeApi } = mockCeloBlock({ chainId: CHAIN_ID.ETHEREUM })
|
|
2429
|
+
|
|
2430
|
+
const [tx] = (await getBlock(context, 12345, { feesAsset: true })).transactions
|
|
2431
|
+
|
|
2432
|
+
expect(tx.fees).toBe(NATIVE_FEES)
|
|
2433
|
+
expect(tx).not.toHaveProperty('feesAsset')
|
|
2434
|
+
expect(nodeApi.getFeeCurrencies).not.toHaveBeenCalled()
|
|
2435
|
+
})
|
|
2436
|
+
|
|
2437
|
+
it('rejects a block with a transaction paid in an unsupported fee currency', async () => {
|
|
2438
|
+
const { context } = mockCeloBlock({ feeCurrency: address2 })
|
|
2439
|
+
|
|
2440
|
+
await expect(getBlock(context, 12345, { feesAsset: true })).rejects.toThrow(
|
|
2441
|
+
UnsupportedFeeCurrencyError
|
|
2442
|
+
)
|
|
2443
|
+
})
|
|
2444
|
+
})
|
|
2198
2445
|
})
|
|
2199
2446
|
|
|
2200
2447
|
describe('dropRootTraceDuplicates', () => {
|
|
@@ -318,7 +318,8 @@ type TransactionFields = {
|
|
|
318
318
|
hash: string
|
|
319
319
|
blockNumber: number | null
|
|
320
320
|
blockHash: string | null
|
|
321
|
-
|
|
321
|
+
/** Absent when the node omits it, as some Celo nodes do for older deposit transactions */
|
|
322
|
+
nonce?: number
|
|
322
323
|
gasLimit: bigint
|
|
323
324
|
value: bigint
|
|
324
325
|
from: string
|
|
@@ -357,7 +358,9 @@ async function getTransactionFromRawRpc(
|
|
|
357
358
|
? null
|
|
358
359
|
: Number(rawQuantity(blockNumber, 'blockNumber')),
|
|
359
360
|
blockHash: typeof raw.blockHash === 'string' ? raw.blockHash : null,
|
|
360
|
-
nonce
|
|
361
|
+
...(raw.nonce === undefined || raw.nonce === null
|
|
362
|
+
? {}
|
|
363
|
+
: { nonce: Number(rawQuantity(raw.nonce, 'nonce')) }),
|
|
361
364
|
gasLimit: rawQuantity(raw.gas, 'gas'),
|
|
362
365
|
value: rawQuantity(raw.value, 'value'),
|
|
363
366
|
// Checksummed, as ethers gives them
|
|
@@ -380,6 +383,13 @@ async function readTransaction(
|
|
|
380
383
|
try {
|
|
381
384
|
return await api.getTransaction(txHash)
|
|
382
385
|
} catch (error) {
|
|
386
|
+
if (isMissingNonceError(error)) {
|
|
387
|
+
logger('warn', 'EVM getTransaction fallback: the transaction has no nonce', {
|
|
388
|
+
txHash,
|
|
389
|
+
error: error.shortMessage,
|
|
390
|
+
})
|
|
391
|
+
return getTransactionFromRawRpc(api, txHash)
|
|
392
|
+
}
|
|
383
393
|
if (!isSignatureError(error)) throw error
|
|
384
394
|
logger('warn', 'EVM getTransaction fallback: using raw eth_getTransactionByHash response', {
|
|
385
395
|
txHash,
|
|
@@ -421,7 +431,7 @@ async function getTransaction(
|
|
|
421
431
|
hash: tx.hash,
|
|
422
432
|
blockHeight: tx.blockNumber ?? undefined,
|
|
423
433
|
blockHash: tx.blockHash ?? undefined,
|
|
424
|
-
nonce: tx.nonce,
|
|
434
|
+
...(tx.nonce !== undefined ? { nonce: tx.nonce } : {}),
|
|
425
435
|
gasUsed: quantityToDecimal(receipt.gasUsed),
|
|
426
436
|
gasPrice: receiptGasPrice(receipt),
|
|
427
437
|
gasLimit: tx.gasLimit.toString(),
|
|
@@ -684,6 +694,13 @@ async function getBlockByHeight(
|
|
|
684
694
|
})
|
|
685
695
|
return getBlockByHeightFromRawRpc(api, blockHeight, true)
|
|
686
696
|
}
|
|
697
|
+
if (prefetchTxs && isMissingNonceError(error)) {
|
|
698
|
+
logger('warn', 'EVM getBlock fallback: a transaction has no nonce', {
|
|
699
|
+
blockHeight,
|
|
700
|
+
error: error.shortMessage,
|
|
701
|
+
})
|
|
702
|
+
return getBlockByHeightFromRawRpc(api, blockHeight, true)
|
|
703
|
+
}
|
|
687
704
|
throw error
|
|
688
705
|
}
|
|
689
706
|
|
|
@@ -749,6 +766,22 @@ function isSignatureError(error: unknown): boolean {
|
|
|
749
766
|
return error.argument === 'signature'
|
|
750
767
|
}
|
|
751
768
|
|
|
769
|
+
/**
|
|
770
|
+
* Error thrown by ethers when it formats a transaction without `nonce`, which it requires. Some
|
|
771
|
+
* Celo nodes omit the nonce of the deposit transaction of older blocks. Only this field is
|
|
772
|
+
* matched: the raw parsers would not reject every other field ethers does.
|
|
773
|
+
*/
|
|
774
|
+
function isMissingNonceError(error: unknown): error is { shortMessage: string } {
|
|
775
|
+
if (!hasErrorCode(error, 'BAD_DATA') || !isRecord(error)) return false
|
|
776
|
+
const { shortMessage, value } = error
|
|
777
|
+
return (
|
|
778
|
+
typeof shortMessage === 'string' &&
|
|
779
|
+
shortMessage.startsWith('invalid value for value.nonce ') &&
|
|
780
|
+
isRecord(value) &&
|
|
781
|
+
(value.nonce === undefined || value.nonce === null)
|
|
782
|
+
)
|
|
783
|
+
}
|
|
784
|
+
|
|
752
785
|
/**
|
|
753
786
|
* Parse a quantity (eg: amount or block height) return from an RPC.
|
|
754
787
|
*
|
|
@@ -812,7 +845,7 @@ async function getBlockByHeightFromRawRpc(
|
|
|
812
845
|
throw new MalformedNodeResponse(
|
|
813
846
|
'Malformed prefetched transaction hash in eth_getBlockByNumber response'
|
|
814
847
|
)
|
|
815
|
-
if (!('from' in tx) || typeof tx.from !== 'string')
|
|
848
|
+
if (!('from' in tx) || typeof tx.from !== 'string' || !ethers.isAddress(tx.from))
|
|
816
849
|
throw new MalformedNodeResponse(
|
|
817
850
|
'Malformed prefetched transaction from in eth_getBlockByNumber response'
|
|
818
851
|
)
|
|
@@ -820,7 +853,7 @@ async function getBlockByHeightFromRawRpc(
|
|
|
820
853
|
throw new MalformedNodeResponse(
|
|
821
854
|
'Malformed prefetched transaction to in eth_getBlockByNumber response'
|
|
822
855
|
)
|
|
823
|
-
if ('value' in tx
|
|
856
|
+
if (!('value' in tx) || typeof tx.value !== 'string')
|
|
824
857
|
throw new MalformedNodeResponse(
|
|
825
858
|
'Malformed prefetched transaction value in eth_getBlockByNumber response'
|
|
826
859
|
)
|
|
@@ -832,7 +865,12 @@ async function getBlockByHeightFromRawRpc(
|
|
|
832
865
|
throw new MalformedNodeResponse(
|
|
833
866
|
'Malformed prefetched transaction gas in eth_getBlockByNumber response'
|
|
834
867
|
)
|
|
835
|
-
if (
|
|
868
|
+
if (
|
|
869
|
+
'nonce' in tx &&
|
|
870
|
+
tx.nonce !== undefined &&
|
|
871
|
+
tx.nonce !== null &&
|
|
872
|
+
typeof tx.nonce !== 'string'
|
|
873
|
+
)
|
|
836
874
|
throw new MalformedNodeResponse(
|
|
837
875
|
'Malformed prefetched transaction nonce in eth_getBlockByNumber response'
|
|
838
876
|
)
|
|
@@ -848,7 +886,7 @@ async function getBlockByHeightFromRawRpc(
|
|
|
848
886
|
|
|
849
887
|
return {
|
|
850
888
|
hash: tx.hash,
|
|
851
|
-
value: BigInt(tx.value
|
|
889
|
+
value: BigInt(tx.value).toString(),
|
|
852
890
|
from: tx.from,
|
|
853
891
|
to: tx.to ?? undefined,
|
|
854
892
|
...('input' in tx && typeof tx.input === 'string' && isSmartContractInput(tx.input)
|
|
@@ -927,6 +965,34 @@ async function getBlockReceipts(
|
|
|
927
965
|
})
|
|
928
966
|
}
|
|
929
967
|
|
|
968
|
+
async function getFeeCurrencies(
|
|
969
|
+
api: JsonRpcProvider,
|
|
970
|
+
blockHeight: number
|
|
971
|
+
): Promise<Map<string, string | null>> {
|
|
972
|
+
const rawBlock: unknown = await api.send('eth_getBlockByNumber', [
|
|
973
|
+
ethers.toQuantity(blockHeight),
|
|
974
|
+
true,
|
|
975
|
+
])
|
|
976
|
+
if (!isRecord(rawBlock) || !Array.isArray(rawBlock.transactions))
|
|
977
|
+
throw new MalformedNodeResponse('Invalid eth_getBlockByNumber response')
|
|
978
|
+
|
|
979
|
+
const feeCurrencies = new Map<string, string | null>()
|
|
980
|
+
for (const [index, tx] of rawBlock.transactions.entries()) {
|
|
981
|
+
if (!isRecord(tx) || typeof tx.hash !== 'string')
|
|
982
|
+
throw new MalformedNodeResponse(
|
|
983
|
+
`Malformed block transaction at index ${index} in eth_getBlockByNumber response`
|
|
984
|
+
)
|
|
985
|
+
// op-geth omits `feeCurrency` when the fee is paid in the native coin
|
|
986
|
+
const feeCurrency = tx.feeCurrency ?? null
|
|
987
|
+
if (feeCurrency !== null && typeof feeCurrency !== 'string')
|
|
988
|
+
throw new MalformedNodeResponse(
|
|
989
|
+
`Malformed feeCurrency at index ${index} in eth_getBlockByNumber response`
|
|
990
|
+
)
|
|
991
|
+
feeCurrencies.set(tx.hash.toLowerCase(), feeCurrency)
|
|
992
|
+
}
|
|
993
|
+
return feeCurrencies
|
|
994
|
+
}
|
|
995
|
+
|
|
930
996
|
async function traceBlockGeth(
|
|
931
997
|
api: JsonRpcProvider,
|
|
932
998
|
blockHeight: number
|
|
@@ -1143,6 +1209,7 @@ export function createNodeApi(
|
|
|
1143
1209
|
withApi(evmConfig, (api) => getTransaction(api, txHash, logger), nodeConfig),
|
|
1144
1210
|
getBlockReceipts: (blockHeight) =>
|
|
1145
1211
|
withApi(evmConfig, (api) => getBlockReceipts(api, blockHeight, logger), nodeConfig),
|
|
1212
|
+
getFeeCurrencies: make(getFeeCurrencies, evmConfig, nodeConfig),
|
|
1146
1213
|
traceBlockErigon: make(traceBlockErigon, evmConfig, nodeConfig),
|
|
1147
1214
|
traceBlockGeth: make(traceBlockGeth, evmConfig, nodeConfig),
|
|
1148
1215
|
getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig, logger),
|
|
@@ -102,7 +102,8 @@ export type TransactionInfo = {
|
|
|
102
102
|
hash: string
|
|
103
103
|
blockHeight: number | undefined
|
|
104
104
|
blockHash: string | undefined
|
|
105
|
-
|
|
105
|
+
/** Absent when the node omits it, as some Celo nodes do for older deposit transactions */
|
|
106
|
+
nonce?: number
|
|
106
107
|
gasUsed: string
|
|
107
108
|
gasPrice: string
|
|
108
109
|
/** Gas limit set by the sender (decimal), when the source reports it */
|
|
@@ -182,6 +183,12 @@ export type NodeApi = {
|
|
|
182
183
|
// timestamp is in milliseconds
|
|
183
184
|
) => Promise<BlockByHeightResult>
|
|
184
185
|
getBlockReceipts?: (blockHeight: number | 'latest') => Promise<BlockReceiptInfo[]>
|
|
186
|
+
/**
|
|
187
|
+
* The Celo CIP-64 `feeCurrency` of each transaction of a block, by lower-case hash: `null` when
|
|
188
|
+
* the transaction pays its fee in the native coin, which the node shows by omitting the field.
|
|
189
|
+
* Ethers drops the field, so this reads the raw block.
|
|
190
|
+
*/
|
|
191
|
+
getFeeCurrencies?: (blockHeight: number) => Promise<Map<string, string | null>>
|
|
185
192
|
traceBlockErigon?: (blockHeight: number | 'latest') => Promise<TraceBlockItem[]>
|
|
186
193
|
traceBlockGeth?: (blockHeight: number) => Promise<TraceBlockItem[]>
|
|
187
194
|
getOptimismAdditionalFees: (transaction: string) => Promise<BigNumber>
|
|
@@ -56,6 +56,9 @@ export function createFailoverNodeApi(sources: NodeApi[], logger: Logger): NodeA
|
|
|
56
56
|
if (sources.some((api) => api.getBlockReceipts))
|
|
57
57
|
base.getBlockReceipts = (h): Promise<BlockReceiptInfo[]> =>
|
|
58
58
|
tryInOrder('getBlockReceipts', (api) => api.getBlockReceipts?.(h))
|
|
59
|
+
if (sources.some((api) => api.getFeeCurrencies))
|
|
60
|
+
base.getFeeCurrencies = (h): Promise<Map<string, string | null>> =>
|
|
61
|
+
tryInOrder('getFeeCurrencies', (api) => api.getFeeCurrencies?.(h))
|
|
59
62
|
if (sources.some((api) => api.traceBlockErigon))
|
|
60
63
|
base.traceBlockErigon = (h): Promise<TraceBlockItem[]> =>
|
|
61
64
|
tryInOrder('traceBlockErigon', (api) => api.traceBlockErigon?.(h))
|