@ledgerhq/coin-evm 16.8.1 → 17.1.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 +25 -0
- package/lib/adapters/etherscan.d.ts.map +1 -1
- package/lib/adapters/etherscan.js +5 -0
- package/lib/adapters/etherscan.js.map +1 -1
- package/lib/adapters/ledger.d.ts.map +1 -1
- package/lib/adapters/ledger.js +1 -0
- package/lib/adapters/ledger.js.map +1 -1
- package/lib/api/index.d.ts +2 -5
- package/lib/api/index.d.ts.map +1 -1
- package/lib/api/index.js +1 -2
- package/lib/api/index.js.map +1 -1
- package/lib/logic/cip64Fees.d.ts +25 -3
- package/lib/logic/cip64Fees.d.ts.map +1 -1
- package/lib/logic/cip64Fees.js +78 -24
- package/lib/logic/cip64Fees.js.map +1 -1
- package/lib/logic/feeCollectorOperations.d.ts +3 -3
- package/lib/logic/feeCollectorOperations.js +3 -3
- package/lib/logic/getBlock.d.ts +2 -2
- package/lib/logic/getBlock.d.ts.map +1 -1
- package/lib/logic/getBlock.js +5 -11
- package/lib/logic/getBlock.js.map +1 -1
- package/lib/logic/listOperations.d.ts.map +1 -1
- package/lib/logic/listOperations.js +21 -3
- package/lib/logic/listOperations.js.map +1 -1
- package/lib/logic/tokenFeeOperations.d.ts +61 -0
- package/lib/logic/tokenFeeOperations.d.ts.map +1 -0
- package/lib/logic/tokenFeeOperations.js +128 -0
- package/lib/logic/tokenFeeOperations.js.map +1 -0
- package/lib/network/node/rpc.common.d.ts.map +1 -1
- package/lib/network/node/rpc.common.js +18 -0
- package/lib/network/node/rpc.common.js.map +1 -1
- package/lib/network/node/types.d.ts +2 -0
- 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/adapters/etherscan.d.ts.map +1 -1
- package/lib-es/adapters/etherscan.js +5 -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 +1 -0
- package/lib-es/adapters/ledger.js.map +1 -1
- package/lib-es/api/index.d.ts +2 -5
- package/lib-es/api/index.d.ts.map +1 -1
- package/lib-es/api/index.js +1 -2
- package/lib-es/api/index.js.map +1 -1
- package/lib-es/logic/cip64Fees.d.ts +25 -3
- package/lib-es/logic/cip64Fees.d.ts.map +1 -1
- package/lib-es/logic/cip64Fees.js +77 -24
- package/lib-es/logic/cip64Fees.js.map +1 -1
- package/lib-es/logic/feeCollectorOperations.d.ts +3 -3
- package/lib-es/logic/feeCollectorOperations.js +3 -3
- 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 +5 -11
- 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 +21 -3
- package/lib-es/logic/listOperations.js.map +1 -1
- package/lib-es/logic/tokenFeeOperations.d.ts +61 -0
- package/lib-es/logic/tokenFeeOperations.d.ts.map +1 -0
- package/lib-es/logic/tokenFeeOperations.js +122 -0
- package/lib-es/logic/tokenFeeOperations.js.map +1 -0
- package/lib-es/network/node/rpc.common.d.ts.map +1 -1
- package/lib-es/network/node/rpc.common.js +18 -0
- package/lib-es/network/node/rpc.common.js.map +1 -1
- package/lib-es/network/node/types.d.ts +2 -0
- 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/adapters/blockscoutV2.test.ts +2 -0
- package/src/adapters/etherscan.test.ts +21 -0
- package/src/adapters/etherscan.ts +5 -0
- package/src/adapters/ledger.test.ts +8 -0
- package/src/adapters/ledger.ts +1 -0
- package/src/api/index.ts +1 -4
- package/src/api/tests/index.celo.integ.test.ts +144 -3
- package/src/api/tests/index.optimism.integ.test.ts +1 -0
- package/src/api/tests/index.test.ts +0 -9
- package/src/logic/cip64Fees.ts +99 -26
- package/src/logic/feeCollectorOperations.ts +3 -3
- package/src/logic/getBlock.ts +6 -17
- package/src/logic/listOperations.ts +32 -2
- package/src/logic/tests/cip64Fees.test.ts +128 -4
- package/src/logic/tests/getBlock.test.ts +10 -23
- package/src/logic/tests/listOperations.test.ts +522 -2
- package/src/logic/tests/validateIntent.test.ts +4 -0
- package/src/logic/tokenFeeOperations.ts +169 -0
- package/src/network/node/rpc.common.ts +19 -0
- package/src/network/node/types.ts +2 -0
- package/src/network/node/withNodeSources.ts +3 -0
- package/src/network/tests/explorer/etherscan.test.ts +1 -0
- package/src/network/tests/explorer/ledger.test.ts +4 -0
- package/src/network/tests/node/rpc.test.ts +36 -0
- package/src/network/tests/node/withNodeSources.test.ts +17 -0
- package/src/staking/rewardsFromReceipt.test.ts +1 -0
- package/src/staking/validators/monad.test.ts +1 -0
|
@@ -427,6 +427,7 @@ describe('validateIntent', () => {
|
|
|
427
427
|
hash: '',
|
|
428
428
|
block: { height: 0, hash: '', time: new Date(0) },
|
|
429
429
|
fees: 0n,
|
|
430
|
+
feesAsset: { type: 'native' },
|
|
430
431
|
date: new Date(0),
|
|
431
432
|
failed: false,
|
|
432
433
|
},
|
|
@@ -1600,6 +1601,7 @@ describe('validateIntent', () => {
|
|
|
1600
1601
|
hash: '',
|
|
1601
1602
|
block: { height: 0, hash: '', time: new Date(0) },
|
|
1602
1603
|
fees: 0n,
|
|
1604
|
+
feesAsset: { type: 'native' },
|
|
1603
1605
|
date: new Date(0),
|
|
1604
1606
|
failed: false,
|
|
1605
1607
|
},
|
|
@@ -1655,6 +1657,7 @@ describe('validateIntent', () => {
|
|
|
1655
1657
|
hash: '',
|
|
1656
1658
|
block: { height: 0, hash: '', time: new Date(0) },
|
|
1657
1659
|
fees: 0n,
|
|
1660
|
+
feesAsset: { type: 'native' },
|
|
1658
1661
|
date: new Date(0),
|
|
1659
1662
|
failed: false,
|
|
1660
1663
|
},
|
|
@@ -1735,6 +1738,7 @@ describe('validateIntent', () => {
|
|
|
1735
1738
|
hash: '',
|
|
1736
1739
|
block: { height: 0, hash: '', time: new Date(0) },
|
|
1737
1740
|
fees: 0n,
|
|
1741
|
+
feesAsset: { type: 'native' },
|
|
1738
1742
|
date: new Date(0),
|
|
1739
1743
|
failed: false,
|
|
1740
1744
|
},
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
// SPDX-FileCopyrightText: © 2026 LEDGER SAS
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { EvmConfigInfo } from '../config'
|
|
5
|
+
import type { ERC20Transfer } from '../network/node/types'
|
|
6
|
+
import type { TokenFee } from './cip64Fees'
|
|
7
|
+
import type { MemoNotSupported, Operation } from '@ledgerhq/coin-module-framework/api/types'
|
|
8
|
+
import type { Logger } from '@ledgerhq/coin-module-framework/config'
|
|
9
|
+
import { promiseAllBatched } from '@ledgerhq/coin-module-framework/promises'
|
|
10
|
+
import { makeLRUCache } from '@ledgerhq/live-network/cache'
|
|
11
|
+
import { UnsupportedFeeCurrencyError } from '../errors'
|
|
12
|
+
import { getNodeApi } from '../network/node'
|
|
13
|
+
import { readCeloTransactionFee } from './cip64Fees'
|
|
14
|
+
|
|
15
|
+
type Op = Operation<MemoNotSupported>
|
|
16
|
+
|
|
17
|
+
/** The token fee of a transaction, with the account that paid it. */
|
|
18
|
+
export type TransactionTokenFee = Pick<TokenFee, 'fees' | 'feesAsset' | 'feeTransfers'> & {
|
|
19
|
+
feesPayer: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** How a Celo transaction paid its fee, with the account that paid it when not natively. */
|
|
23
|
+
type CeloFeeRead =
|
|
24
|
+
| { kind: 'native' }
|
|
25
|
+
| { kind: 'token'; tokenFee: TransactionTokenFee }
|
|
26
|
+
| { kind: 'unsupported'; feeCurrency: string; feesPayer: string }
|
|
27
|
+
|
|
28
|
+
// Transactions read in parallel, as getBlock does for transactions it fetches one by one
|
|
29
|
+
const MAX_TRANSACTION_CONCURRENCY = 2
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* How a Celo transaction paid its fee. A mined transaction keeps its fee, so each one is read
|
|
33
|
+
* once per chain. A failed read is not kept.
|
|
34
|
+
*/
|
|
35
|
+
export const fetchCeloTransactionFee = makeLRUCache(
|
|
36
|
+
async (config: EvmConfigInfo, logger: Logger, hash: string): Promise<CeloFeeRead> => {
|
|
37
|
+
const nodeApi = getNodeApi(config, logger)
|
|
38
|
+
const transaction = await nodeApi.getTransaction(hash)
|
|
39
|
+
const fee = await readCeloTransactionFee(nodeApi, transaction)
|
|
40
|
+
switch (fee.kind) {
|
|
41
|
+
case 'native':
|
|
42
|
+
return fee
|
|
43
|
+
case 'unsupported':
|
|
44
|
+
return { ...fee, feesPayer: transaction.from }
|
|
45
|
+
case 'token': {
|
|
46
|
+
const { fees, feesAsset, feeTransfers } = fee.tokenFee
|
|
47
|
+
return {
|
|
48
|
+
kind: 'token',
|
|
49
|
+
tokenFee: { fees, feesAsset, feeTransfers, feesPayer: transaction.from },
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
(config, _logger, hash) => `${config.chainId}:${hash.toLowerCase()}`,
|
|
55
|
+
{ max: 10_000, ttl: 24 * 60 * 60 * 1000 }
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The token fees of the transactions of a Celo history page, by lower-case hash. The explorer
|
|
60
|
+
* gives neither the transaction type nor the fee currency, so each transaction is read from the
|
|
61
|
+
* node. Transactions paid in the native coin are left out.
|
|
62
|
+
*
|
|
63
|
+
* A fee currency with unknown fee logs fails the page only when the account paid the fee. Anyone
|
|
64
|
+
* can send the account a transaction paid in such a currency, and its fee is not the account's,
|
|
65
|
+
* so that transaction keeps its explorer fee and fee rows.
|
|
66
|
+
*
|
|
67
|
+
* @param address the account of the page
|
|
68
|
+
* @param hashes hashes of the transactions of the page
|
|
69
|
+
* @param ownHashes lower-case hashes the explorer shows the account sent
|
|
70
|
+
* @throws UnsupportedFeeCurrencyError when the account paid a fee in a currency with unknown fee
|
|
71
|
+
* logs
|
|
72
|
+
* @throws any other failure to read a transaction or its fee, which a retry may recover: a fee
|
|
73
|
+
* reported in the wrong asset is worse than no page
|
|
74
|
+
*/
|
|
75
|
+
export async function readCeloTokenFees(
|
|
76
|
+
config: EvmConfigInfo,
|
|
77
|
+
logger: Logger,
|
|
78
|
+
address: string,
|
|
79
|
+
hashes: Iterable<string>,
|
|
80
|
+
ownHashes: ReadonlySet<string>
|
|
81
|
+
): Promise<Map<string, TransactionTokenFee>> {
|
|
82
|
+
const unique = [...new Set([...hashes].map((hash) => hash.toLowerCase()))]
|
|
83
|
+
const reads = await promiseAllBatched(MAX_TRANSACTION_CONCURRENCY, unique, (hash) =>
|
|
84
|
+
fetchCeloTransactionFee(config, logger, hash)
|
|
85
|
+
)
|
|
86
|
+
const byHash = new Map<string, TransactionTokenFee>()
|
|
87
|
+
unique.forEach((hash, index) => {
|
|
88
|
+
const read = reads[index]
|
|
89
|
+
if (read?.kind === 'token') byHash.set(hash, read.tokenFee)
|
|
90
|
+
if (read?.kind !== 'unsupported') return
|
|
91
|
+
const { feeCurrency, feesPayer } = read
|
|
92
|
+
if (ownHashes.has(hash) || feesPayer.toLowerCase() === address.toLowerCase()) {
|
|
93
|
+
throw new UnsupportedFeeCurrencyError(`Unsupported Celo fee currency ${feeCurrency}`, {
|
|
94
|
+
hash,
|
|
95
|
+
feeCurrency,
|
|
96
|
+
payer: feesPayer,
|
|
97
|
+
})
|
|
98
|
+
}
|
|
99
|
+
logger('warn', 'Celo fee currency not supported, keeping the explorer fee', {
|
|
100
|
+
hash,
|
|
101
|
+
feeCurrency,
|
|
102
|
+
})
|
|
103
|
+
})
|
|
104
|
+
return byHash
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const transferKey = (
|
|
108
|
+
hash: string,
|
|
109
|
+
token: string,
|
|
110
|
+
from: string,
|
|
111
|
+
to: string,
|
|
112
|
+
value: bigint
|
|
113
|
+
): string => [hash, token, from, to, value.toString()].join('\t').toLowerCase()
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Removes the token operations that move a fee, one per fee transfer. The explorer gives no log
|
|
117
|
+
* index, so a fee transfer matches an operation by hash, token, sender, recipient and amount. A
|
|
118
|
+
* transfer of the transaction identical to a fee transfer may be removed in its place, which
|
|
119
|
+
* leaves the same operations.
|
|
120
|
+
*
|
|
121
|
+
* @param operations token operations of the account from the explorer
|
|
122
|
+
* @param tokenFees token fees by lower-case hash
|
|
123
|
+
*/
|
|
124
|
+
export function removeFeeTransfers(
|
|
125
|
+
operations: readonly Op[],
|
|
126
|
+
tokenFees: ReadonlyMap<string, TransactionTokenFee>
|
|
127
|
+
): Op[] {
|
|
128
|
+
const remaining = new Map<string, number>()
|
|
129
|
+
for (const [hash, { feeTransfers }] of tokenFees) {
|
|
130
|
+
for (const transfer of feeTransfers) {
|
|
131
|
+
const key = feeTransferKey(hash, transfer)
|
|
132
|
+
remaining.set(key, (remaining.get(key) ?? 0) + 1)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return operations.filter((op) => {
|
|
137
|
+
if (op.asset.type !== 'erc20' || !('assetReference' in op.asset)) return true
|
|
138
|
+
const [from] = op.senders
|
|
139
|
+
const [to] = op.recipients
|
|
140
|
+
if (from === undefined || to === undefined || op.asset.assetReference === undefined) return true
|
|
141
|
+
const key = transferKey(op.tx.hash, op.asset.assetReference, from, to, op.value)
|
|
142
|
+
const count = remaining.get(key) ?? 0
|
|
143
|
+
if (count === 0) return true
|
|
144
|
+
remaining.set(key, count - 1)
|
|
145
|
+
return false
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function feeTransferKey(hash: string, transfer: ERC20Transfer): string {
|
|
150
|
+
return transferKey(
|
|
151
|
+
hash,
|
|
152
|
+
transfer.asset.assetReference,
|
|
153
|
+
transfer.from,
|
|
154
|
+
transfer.to,
|
|
155
|
+
BigInt(transfer.value)
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Gives an operation the token fee of its transaction: amount, asset and payer.
|
|
161
|
+
*
|
|
162
|
+
* @param tokenFees token fees by lower-case hash
|
|
163
|
+
*/
|
|
164
|
+
export function withTokenFee(op: Op, tokenFees: ReadonlyMap<string, TransactionTokenFee>): Op {
|
|
165
|
+
const tokenFee = tokenFees.get(op.tx.hash.toLowerCase())
|
|
166
|
+
if (tokenFee === undefined) return op
|
|
167
|
+
const { fees, feesAsset, feesPayer } = tokenFee
|
|
168
|
+
return { ...op, tx: { ...op.tx, fees, feesAsset, feesPayer } }
|
|
169
|
+
}
|
|
@@ -993,6 +993,24 @@ async function getFeeCurrencies(
|
|
|
993
993
|
return feeCurrencies
|
|
994
994
|
}
|
|
995
995
|
|
|
996
|
+
async function getFeeCurrency(api: JsonRpcProvider, txHash: string): Promise<string | null> {
|
|
997
|
+
const rawTx: unknown = await api.send('eth_getTransactionByHash', [txHash])
|
|
998
|
+
if (rawTx === null || rawTx === undefined) {
|
|
999
|
+
throw new NodeTransactionNotFound('Transaction not found', { txHash })
|
|
1000
|
+
}
|
|
1001
|
+
if (!isRecord(rawTx) || typeof rawTx.hash !== 'string')
|
|
1002
|
+
throw new MalformedNodeResponse('Invalid eth_getTransactionByHash response')
|
|
1003
|
+
if (rawTx.hash.toLowerCase() !== txHash.toLowerCase())
|
|
1004
|
+
throw new MalformedNodeResponse('eth_getTransactionByHash returned another transaction', {
|
|
1005
|
+
txHash,
|
|
1006
|
+
})
|
|
1007
|
+
// op-geth omits `feeCurrency` when the fee is paid in the native coin
|
|
1008
|
+
const feeCurrency = rawTx.feeCurrency ?? null
|
|
1009
|
+
if (feeCurrency !== null && typeof feeCurrency !== 'string')
|
|
1010
|
+
throw new MalformedNodeResponse('Malformed feeCurrency in eth_getTransactionByHash response')
|
|
1011
|
+
return feeCurrency
|
|
1012
|
+
}
|
|
1013
|
+
|
|
996
1014
|
async function traceBlockGeth(
|
|
997
1015
|
api: JsonRpcProvider,
|
|
998
1016
|
blockHeight: number
|
|
@@ -1210,6 +1228,7 @@ export function createNodeApi(
|
|
|
1210
1228
|
getBlockReceipts: (blockHeight) =>
|
|
1211
1229
|
withApi(evmConfig, (api) => getBlockReceipts(api, blockHeight, logger), nodeConfig),
|
|
1212
1230
|
getFeeCurrencies: make(getFeeCurrencies, evmConfig, nodeConfig),
|
|
1231
|
+
getFeeCurrency: make(getFeeCurrency, evmConfig, nodeConfig),
|
|
1213
1232
|
traceBlockErigon: make(traceBlockErigon, evmConfig, nodeConfig),
|
|
1214
1233
|
traceBlockGeth: make(traceBlockGeth, evmConfig, nodeConfig),
|
|
1215
1234
|
getGasEstimation: makeGetGasEstimation(evmConfig, nodeConfig, logger),
|
|
@@ -189,6 +189,8 @@ export type NodeApi = {
|
|
|
189
189
|
* Ethers drops the field, so this reads the raw block.
|
|
190
190
|
*/
|
|
191
191
|
getFeeCurrencies?: (blockHeight: number) => Promise<Map<string, string | null>>
|
|
192
|
+
/** The Celo CIP-64 `feeCurrency` of one transaction, as {@link getFeeCurrencies} gives it. */
|
|
193
|
+
getFeeCurrency?: (txHash: string) => Promise<string | null>
|
|
192
194
|
traceBlockErigon?: (blockHeight: number | 'latest') => Promise<TraceBlockItem[]>
|
|
193
195
|
traceBlockGeth?: (blockHeight: number) => Promise<TraceBlockItem[]>
|
|
194
196
|
getOptimismAdditionalFees: (transaction: string) => Promise<BigNumber>
|
|
@@ -59,6 +59,9 @@ export function createFailoverNodeApi(sources: NodeApi[], logger: Logger): NodeA
|
|
|
59
59
|
if (sources.some((api) => api.getFeeCurrencies))
|
|
60
60
|
base.getFeeCurrencies = (h): Promise<Map<string, string | null>> =>
|
|
61
61
|
tryInOrder('getFeeCurrencies', (api) => api.getFeeCurrencies?.(h))
|
|
62
|
+
if (sources.some((api) => api.getFeeCurrency))
|
|
63
|
+
base.getFeeCurrency = (h): Promise<string | null> =>
|
|
64
|
+
tryInOrder('getFeeCurrency', (api) => api.getFeeCurrency?.(h))
|
|
62
65
|
if (sources.some((api) => api.traceBlockErigon))
|
|
63
66
|
base.traceBlockErigon = (h): Promise<TraceBlockItem[]> =>
|
|
64
67
|
tryInOrder('traceBlockErigon', (api) => api.traceBlockErigon?.(h))
|
|
@@ -3022,6 +3022,7 @@ describe('EVM Family', () => {
|
|
|
3022
3022
|
hash: `0x${blockHeight}${i}`,
|
|
3023
3023
|
block: { height: blockHeight, hash: `0xblock${blockHeight}`, time: new Date() },
|
|
3024
3024
|
fees: 10n,
|
|
3025
|
+
feesAsset: { type: 'native' },
|
|
3025
3026
|
feesPayer: '0x456',
|
|
3026
3027
|
date: new Date(),
|
|
3027
3028
|
failed: false,
|
|
@@ -334,6 +334,7 @@ describe('EVM Family', () => {
|
|
|
334
334
|
time: new Date(coinOperation1.block.time),
|
|
335
335
|
},
|
|
336
336
|
fees,
|
|
337
|
+
feesAsset: { type: 'native' },
|
|
337
338
|
date: new Date(coinOperation1.block.time),
|
|
338
339
|
failed: false,
|
|
339
340
|
feesPayer: addr,
|
|
@@ -346,6 +347,7 @@ describe('EVM Family', () => {
|
|
|
346
347
|
time: new Date(coinOperation2.block.time),
|
|
347
348
|
},
|
|
348
349
|
fees,
|
|
350
|
+
feesAsset: { type: 'native' },
|
|
349
351
|
date: new Date(coinOperation2.block.time),
|
|
350
352
|
failed: false,
|
|
351
353
|
feesPayer: addr,
|
|
@@ -358,6 +360,7 @@ describe('EVM Family', () => {
|
|
|
358
360
|
time: new Date(coinOperation3.block.time),
|
|
359
361
|
},
|
|
360
362
|
fees,
|
|
363
|
+
feesAsset: { type: 'native' },
|
|
361
364
|
date: new Date(coinOperation3.block.time),
|
|
362
365
|
failed: false,
|
|
363
366
|
feesPayer: eip55.encode(coinOperation3.from),
|
|
@@ -370,6 +373,7 @@ describe('EVM Family', () => {
|
|
|
370
373
|
time: new Date(coinOperation4.block.time),
|
|
371
374
|
},
|
|
372
375
|
fees,
|
|
376
|
+
feesAsset: { type: 'native' },
|
|
373
377
|
date: new Date(coinOperation4.block.time),
|
|
374
378
|
failed: false,
|
|
375
379
|
feesPayer: eip55.encode(coinOperation4.from),
|
|
@@ -1941,6 +1941,42 @@ describe('EVM Family', () => {
|
|
|
1941
1941
|
})
|
|
1942
1942
|
})
|
|
1943
1943
|
|
|
1944
|
+
describe('getFeeCurrency', () => {
|
|
1945
|
+
it.each([
|
|
1946
|
+
['a fee currency', '0x0e2a3e05bc9a16f5292a6170456a710cb89c6f72'],
|
|
1947
|
+
['an omitted fee currency as native', undefined],
|
|
1948
|
+
['a null fee currency as native', null],
|
|
1949
|
+
])('reads %s from the raw transaction', async (_, feeCurrency) => {
|
|
1950
|
+
const send = mockRawRpc({
|
|
1951
|
+
eth_getTransactionByHash: { hash: '0xaa', type: '0x7b', feeCurrency },
|
|
1952
|
+
})
|
|
1953
|
+
|
|
1954
|
+
expect(await nodeApi.getFeeCurrency!('0xAA')).toBe(feeCurrency ?? null)
|
|
1955
|
+
expect(send).toHaveBeenCalledWith('eth_getTransactionByHash', ['0xAA'])
|
|
1956
|
+
})
|
|
1957
|
+
|
|
1958
|
+
it('rejects an unknown transaction', async () => {
|
|
1959
|
+
mockRawRpc({ eth_getTransactionByHash: null })
|
|
1960
|
+
|
|
1961
|
+
await expect(nodeApi.getFeeCurrency!('0xaa')).rejects.toMatchObject({
|
|
1962
|
+
name: 'NodeTransactionNotFound',
|
|
1963
|
+
})
|
|
1964
|
+
})
|
|
1965
|
+
|
|
1966
|
+
it.each([
|
|
1967
|
+
['a malformed transaction', 'tx'],
|
|
1968
|
+
['a transaction without hash', {}],
|
|
1969
|
+
['another transaction', { hash: '0xbb' }],
|
|
1970
|
+
['a malformed fee currency', { hash: '0xaa', feeCurrency: 1 }],
|
|
1971
|
+
])('rejects %s', async (_, response) => {
|
|
1972
|
+
mockRawRpc({ eth_getTransactionByHash: response })
|
|
1973
|
+
|
|
1974
|
+
await expect(nodeApi.getFeeCurrency!('0xaa')).rejects.toMatchObject({
|
|
1975
|
+
name: 'MalformedNodeResponse',
|
|
1976
|
+
})
|
|
1977
|
+
})
|
|
1978
|
+
})
|
|
1979
|
+
|
|
1944
1980
|
describe('traceBlockErigon', () => {
|
|
1945
1981
|
it('should return trace array when trace_block is supported', async () => {
|
|
1946
1982
|
const traceItem = {
|
|
@@ -71,6 +71,23 @@ describe('withNodeSources', () => {
|
|
|
71
71
|
expect(withNodeSources(api, config, testLogger).getFeeCurrencies).toBeUndefined()
|
|
72
72
|
})
|
|
73
73
|
|
|
74
|
+
it('reads the fee currency of a transaction from the node, which the explorer proxy cannot', async () => {
|
|
75
|
+
const config = createMockEvmConfigInfo({
|
|
76
|
+
chainId: 1,
|
|
77
|
+
node,
|
|
78
|
+
explorer: mkEtherscanExplorer(),
|
|
79
|
+
nodeSources: nodeSourcesFromList(['explorer-proxy', 'node']),
|
|
80
|
+
})
|
|
81
|
+
const withFeeCurrency = mockNodeApi({
|
|
82
|
+
getFeeCurrency: jest.fn().mockResolvedValueOnce('0xfee'),
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const wrapped = withNodeSources(withFeeCurrency, config, testLogger)
|
|
86
|
+
|
|
87
|
+
await expect(wrapped.getFeeCurrency?.('0xabc')).resolves.toBe('0xfee')
|
|
88
|
+
expect(withNodeSources(api, config, testLogger).getFeeCurrency).toBeUndefined()
|
|
89
|
+
})
|
|
90
|
+
|
|
74
91
|
describe('getBlockByHeight', () => {
|
|
75
92
|
it('forwards successful calls unchanged', async () => {
|
|
76
93
|
const config = createMockEvmConfigInfo({
|